of_addr.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * Taken from Linux v4.9 drivers/of/address.c
  4. *
  5. * Modified for U-Boot
  6. * Copyright (c) 2017 Google, Inc
  7. */
  8. #ifndef _DM_OF_ADDR_H
  9. #define _DM_OF_ADDR_H
  10. /**
  11. * of_translate_address() - translate a device-tree address to a CPU address
  12. *
  13. * Translate an address from the device-tree into a CPU physical address,
  14. * this walks up the tree and applies the various bus mappings on the way.
  15. *
  16. * Note: We consider that crossing any level with #size-cells == 0 to mean
  17. * that translation is impossible (that is we are not dealing with a value
  18. * that can be mapped to a cpu physical address). This is not really specified
  19. * that way, but this is traditionally the way IBM at least do things
  20. *
  21. * @np: node to check
  22. * @in_addr: pointer to input address
  23. * @return translated address or OF_BAD_ADDR on error
  24. */
  25. u64 of_translate_address(const struct device_node *no, const __be32 *in_addr);
  26. /**
  27. * of_translate_dma_address() - translate a device-tree DMA address to a CPU
  28. * address
  29. *
  30. * Translate a DMA address from the device-tree into a CPU physical address,
  31. * this walks up the tree and applies the various bus mappings on the way.
  32. *
  33. * Note: We consider that crossing any level with #size-cells == 0 to mean
  34. * that translation is impossible (that is we are not dealing with a value
  35. * that can be mapped to a cpu physical address). This is not really specified
  36. * that way, but this is traditionally the way IBM at least do things
  37. *
  38. * @np: node to check
  39. * @in_addr: pointer to input DMA address
  40. * @return translated DMA address or OF_BAD_ADDR on error
  41. */
  42. u64 of_translate_dma_address(const struct device_node *no, const __be32 *in_addr);
  43. /**
  44. * of_get_address() - obtain an address from a node
  45. *
  46. * Extract an address from a node, returns the region size and the address
  47. * space flags too. The PCI version uses a BAR number instead of an absolute
  48. * index.
  49. *
  50. * @np: Node to check
  51. * @index: Index of address to read (0 = first)
  52. * @size: place to put size on success
  53. * @flags: place to put flags on success
  54. * @return pointer to address which can be read
  55. */
  56. const __be32 *of_get_address(const struct device_node *no, int index,
  57. u64 *size, unsigned int *flags);
  58. struct resource;
  59. /**
  60. * of_address_to_resource() - translate device tree address to resource
  61. *
  62. * Note that if your address is a PIO address, the conversion will fail if
  63. * the physical address can't be internally converted to an IO token with
  64. * pci_address_to_pio(), that is because it's either called to early or it
  65. * can't be matched to any host bridge IO space
  66. *
  67. * @np: node to check
  68. * @index: index of address to read (0 = first)
  69. * @r: place to put resource information
  70. * @return 0 if OK, -ve on error
  71. */
  72. int of_address_to_resource(const struct device_node *no, int index,
  73. struct resource *r);
  74. #endif