kiorpc.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*
  2. * Copyright 2012 Tilera Corporation. All Rights Reserved.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License
  6. * as published by the Free Software Foundation, version 2.
  7. *
  8. * This program is distributed in the hope that it will be useful, but
  9. * WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
  11. * NON INFRINGEMENT. See the GNU General Public License for
  12. * more details.
  13. *
  14. * TILE-Gx IORPC support for kernel I/O drivers.
  15. */
  16. #include <linux/mmzone.h>
  17. #include <linux/module.h>
  18. #include <linux/io.h>
  19. #include <gxio/iorpc_globals.h>
  20. #include <gxio/kiorpc.h>
  21. #ifdef DEBUG_IORPC
  22. #define TRACE(FMT, ...) pr_info(SIMPLE_MSG_LINE FMT, ## __VA_ARGS__)
  23. #else
  24. #define TRACE(...)
  25. #endif
  26. /* Create kernel-VA-space MMIO mapping for an on-chip IO device. */
  27. void __iomem *iorpc_ioremap(int hv_fd, resource_size_t offset,
  28. unsigned long size)
  29. {
  30. pgprot_t mmio_base, prot = { 0 };
  31. unsigned long pfn;
  32. int err;
  33. /* Look up the shim's lotar and base PA. */
  34. err = __iorpc_get_mmio_base(hv_fd, &mmio_base);
  35. if (err) {
  36. TRACE("get_mmio_base() failure: %d\n", err);
  37. return NULL;
  38. }
  39. /* Make sure the HV driver approves of our offset and size. */
  40. err = __iorpc_check_mmio_offset(hv_fd, offset, size);
  41. if (err) {
  42. TRACE("check_mmio_offset() failure: %d\n", err);
  43. return NULL;
  44. }
  45. /*
  46. * mmio_base contains a base pfn and homing coordinates. Turn
  47. * it into an MMIO pgprot and offset pfn.
  48. */
  49. prot = hv_pte_set_lotar(prot, hv_pte_get_lotar(mmio_base));
  50. pfn = pte_pfn(mmio_base) + PFN_DOWN(offset);
  51. return ioremap_prot(PFN_PHYS(pfn), size, prot);
  52. }
  53. EXPORT_SYMBOL(iorpc_ioremap);