of_addr.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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_get_address() - obtain an address from a node
  28. *
  29. * Extract an address from a node, returns the region size and the address
  30. * space flags too. The PCI version uses a BAR number instead of an absolute
  31. * index.
  32. *
  33. * @np: Node to check
  34. * @index: Index of address to read (0 = first)
  35. * @size: place to put size on success
  36. * @flags: place to put flags on success
  37. * @return pointer to address which can be read
  38. */
  39. const __be32 *of_get_address(const struct device_node *no, int index,
  40. u64 *size, unsigned int *flags);
  41. struct resource;
  42. /**
  43. * of_address_to_resource() - translate device tree address to resource
  44. *
  45. * Note that if your address is a PIO address, the conversion will fail if
  46. * the physical address can't be internally converted to an IO token with
  47. * pci_address_to_pio(), that is because it's either called to early or it
  48. * can't be matched to any host bridge IO space
  49. *
  50. * @np: node to check
  51. * @index: index of address to read (0 = first)
  52. * @r: place to put resource information
  53. * @return 0 if OK, -ve on error
  54. */
  55. int of_address_to_resource(const struct device_node *no, int index,
  56. struct resource *r);
  57. #endif