p2sb.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * Copyright 2019 Google LLC
  4. * Written by Simon Glass <sjg@chromium.org>
  5. */
  6. #ifndef __p2sb_h
  7. #define __p2sb_h
  8. /* Port Id lives in bits 23:16 and register offset lives in 15:0 of address */
  9. #define PCR_PORTID_SHIFT 16
  10. #if !defined(__ACPI__)
  11. /* These registers contain IOAPIC and HPET devfn */
  12. #define PCH_P2SB_IBDF 0x6c
  13. #define PCH_P2SB_HBDF 0x70
  14. /**
  15. * struct p2sb_child_platdata - Information about each child of a p2sb device
  16. *
  17. * @pid: Port ID for this child
  18. */
  19. struct p2sb_child_platdata {
  20. uint pid;
  21. };
  22. /**
  23. * struct p2sb_uc_priv - information for the uclass about each device
  24. *
  25. * This must be set up by the driver when it is probed
  26. *
  27. * @mmio_base: Base address of P2SB region
  28. */
  29. struct p2sb_uc_priv {
  30. uint mmio_base;
  31. };
  32. /**
  33. * struct p2sb_ops - Operations for the P2SB
  34. */
  35. struct p2sb_ops {
  36. /**
  37. * set_hide() - Set/clear the 'hide' bit on the p2sb
  38. *
  39. * This device can be hidden from the PCI bus if needed. This method
  40. * can be called before the p2sb is probed.
  41. *
  42. * @dev: P2SB device
  43. * @hide: true to hide the device, false to show it
  44. * @return 0 if OK, -ve on error
  45. */
  46. int (*set_hide)(struct udevice *dev, bool hide);
  47. };
  48. #define p2sb_get_ops(dev) ((struct p2sb_ops *)(dev)->driver->ops)
  49. /**
  50. * p2sb_set_hide() - Set/clear the 'hide' bit on the p2sb
  51. *
  52. * This device can be hidden from the PCI bus if needed. This method
  53. * can be called before the p2sb is probed.
  54. *
  55. * @dev: P2SB device
  56. * @hide: true to hide the device, false to show it
  57. * @return 0 if OK, -ve on error
  58. */
  59. int p2sb_set_hide(struct udevice *dev, bool hide);
  60. /**
  61. * pcr_read32/16/8() - Read from a PCR device
  62. *
  63. * Reads data from a PCR device within the P2SB
  64. *
  65. * @dev: Device to read from
  66. * @offset: Offset within device to read
  67. * @return value read
  68. */
  69. uint pcr_read32(struct udevice *dev, uint offset);
  70. uint pcr_read16(struct udevice *dev, uint offset);
  71. uint pcr_read8(struct udevice *dev, uint offset);
  72. /**
  73. * pcr_read32/16/8() - Write to a PCR device
  74. *
  75. * Writes data to a PCR device within the P2SB
  76. *
  77. * @dev: Device to write to
  78. * @offset: Offset within device to write
  79. * @data: Data to write
  80. */
  81. void pcr_write32(struct udevice *dev, uint offset, uint data);
  82. void pcr_write16(struct udevice *dev, uint offset, uint data);
  83. void pcr_write8(struct udevice *dev, uint offset, uint data);
  84. /**
  85. * pcr_clrsetbits32/16/8() - Update a PCR device
  86. *
  87. * Updates dat in a PCR device within the P2SB
  88. *
  89. * This reads from the device, clears and set bits, then writes back.
  90. *
  91. * new_data = (old_data & ~clr) | set
  92. *
  93. * @dev: Device to update
  94. * @offset: Offset within device to update
  95. * @clr: Bits to clear after reading
  96. * @set: Bits to set before writing
  97. */
  98. void pcr_clrsetbits32(struct udevice *dev, uint offset, uint clr, uint set);
  99. void pcr_clrsetbits16(struct udevice *dev, uint offset, uint clr, uint set);
  100. void pcr_clrsetbits8(struct udevice *dev, uint offset, uint clr, uint set);
  101. static inline void pcr_setbits32(struct udevice *dev, uint offset, uint set)
  102. {
  103. return pcr_clrsetbits32(dev, offset, 0, set);
  104. }
  105. static inline void pcr_setbits16(struct udevice *dev, uint offset, uint set)
  106. {
  107. return pcr_clrsetbits16(dev, offset, 0, set);
  108. }
  109. static inline void pcr_setbits8(struct udevice *dev, uint offset, uint set)
  110. {
  111. return pcr_clrsetbits8(dev, offset, 0, set);
  112. }
  113. static inline void pcr_clrbits32(struct udevice *dev, uint offset, uint clr)
  114. {
  115. return pcr_clrsetbits32(dev, offset, clr, 0);
  116. }
  117. static inline void pcr_clrbits16(struct udevice *dev, uint offset, uint clr)
  118. {
  119. return pcr_clrsetbits16(dev, offset, clr, 0);
  120. }
  121. static inline void pcr_clrbits8(struct udevice *dev, uint offset, uint clr)
  122. {
  123. return pcr_clrsetbits8(dev, offset, clr, 0);
  124. }
  125. /**
  126. * p2sb_set_port_id() - Set the port ID for a p2sb child device
  127. *
  128. * This must be called in a device's bind() method when OF_PLATDATA is used
  129. * since the uclass cannot access the device's of-platdata.
  130. *
  131. * @dev: Child device (whose parent is UCLASS_P2SB)
  132. * @portid: Port ID of child device
  133. * @return 0 if OK, -ENODEV is the p2sb device could not be found
  134. */
  135. int p2sb_set_port_id(struct udevice *dev, int portid);
  136. /**
  137. * p2sb_get_port_id() - Get the port ID for a p2sb child device
  138. *
  139. * @dev: Child device (whose parent is UCLASS_P2SB)
  140. * @return Port ID of that child
  141. */
  142. int p2sb_get_port_id(struct udevice *dev);
  143. /**
  144. * pcr_reg_address() Convert an offset in p2sb space to an absolute address
  145. *
  146. * @dev: Child device (whose parent is UCLASS_P2SB)
  147. * @offset: Offset within that child's address space
  148. * @return pointer to that offset within the child's address space
  149. */
  150. void *pcr_reg_address(struct udevice *dev, uint offset);
  151. #endif /* !__ACPI__ */
  152. #endif