xhci-ext-caps.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. /*
  2. * xHCI host controller driver
  3. *
  4. * Copyright (C) 2008 Intel Corp.
  5. *
  6. * Author: Sarah Sharp
  7. * Some code borrowed from the Linux EHCI driver.
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2 as
  11. * published by the Free Software Foundation.
  12. *
  13. * This program is distributed in the hope that it will be useful, but
  14. * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  15. * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  16. * for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software Foundation,
  20. * Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21. */
  22. /* Up to 16 ms to halt an HC */
  23. #define XHCI_MAX_HALT_USEC (16*1000)
  24. /* HC not running - set to 1 when run/stop bit is cleared. */
  25. #define XHCI_STS_HALT (1<<0)
  26. /* HCCPARAMS offset from PCI base address */
  27. #define XHCI_HCC_PARAMS_OFFSET 0x10
  28. /* HCCPARAMS contains the first extended capability pointer */
  29. #define XHCI_HCC_EXT_CAPS(p) (((p)>>16)&0xffff)
  30. /* Command and Status registers offset from the Operational Registers address */
  31. #define XHCI_CMD_OFFSET 0x00
  32. #define XHCI_STS_OFFSET 0x04
  33. #define XHCI_MAX_EXT_CAPS 50
  34. /* Capability Register */
  35. /* bits 7:0 - how long is the Capabilities register */
  36. #define XHCI_HC_LENGTH(p) (((p)>>00)&0x00ff)
  37. /* Extended capability register fields */
  38. #define XHCI_EXT_CAPS_ID(p) (((p)>>0)&0xff)
  39. #define XHCI_EXT_CAPS_NEXT(p) (((p)>>8)&0xff)
  40. #define XHCI_EXT_CAPS_VAL(p) ((p)>>16)
  41. /* Extended capability IDs - ID 0 reserved */
  42. #define XHCI_EXT_CAPS_LEGACY 1
  43. #define XHCI_EXT_CAPS_PROTOCOL 2
  44. #define XHCI_EXT_CAPS_PM 3
  45. #define XHCI_EXT_CAPS_VIRT 4
  46. #define XHCI_EXT_CAPS_ROUTE 5
  47. /* IDs 6-9 reserved */
  48. #define XHCI_EXT_CAPS_DEBUG 10
  49. /* USB Legacy Support Capability - section 7.1.1 */
  50. #define XHCI_HC_BIOS_OWNED (1 << 16)
  51. #define XHCI_HC_OS_OWNED (1 << 24)
  52. /* USB Legacy Support Capability - section 7.1.1 */
  53. /* Add this offset, plus the value of xECP in HCCPARAMS to the base address */
  54. #define XHCI_LEGACY_SUPPORT_OFFSET (0x00)
  55. /* USB Legacy Support Control and Status Register - section 7.1.2 */
  56. /* Add this offset, plus the value of xECP in HCCPARAMS to the base address */
  57. #define XHCI_LEGACY_CONTROL_OFFSET (0x04)
  58. /* bits 1:3, 5:12, and 17:19 need to be preserved; bits 21:28 should be zero */
  59. #define XHCI_LEGACY_DISABLE_SMI ((0x7 << 1) + (0xff << 5) + (0x7 << 17))
  60. #define XHCI_LEGACY_SMI_EVENTS (0x7 << 29)
  61. /* command register values to disable interrupts and halt the HC */
  62. /* start/stop HC execution - do not write unless HC is halted*/
  63. #define XHCI_CMD_RUN (1 << 0)
  64. /* Event Interrupt Enable - get irq when EINT bit is set in USBSTS register */
  65. #define XHCI_CMD_EIE (1 << 2)
  66. /* Host System Error Interrupt Enable - get irq when HSEIE bit set in USBSTS */
  67. #define XHCI_CMD_HSEIE (1 << 3)
  68. /* Enable Wrap Event - '1' means xHC generates an event when MFINDEX wraps. */
  69. #define XHCI_CMD_EWE (1 << 10)
  70. #define XHCI_IRQS (XHCI_CMD_EIE | XHCI_CMD_HSEIE | XHCI_CMD_EWE)
  71. /* true: Controller Not Ready to accept doorbell or op reg writes after reset */
  72. #define XHCI_STS_CNR (1 << 11)
  73. #include <linux/io.h>
  74. /**
  75. * Return the next extended capability pointer register.
  76. *
  77. * @base PCI register base address.
  78. *
  79. * @ext_offset Offset of the 32-bit register that contains the extended
  80. * capabilites pointer. If searching for the first extended capability, pass
  81. * in XHCI_HCC_PARAMS_OFFSET. If searching for the next extended capability,
  82. * pass in the offset of the current extended capability register.
  83. *
  84. * Returns 0 if there is no next extended capability register or returns the register offset
  85. * from the PCI registers base address.
  86. */
  87. static inline int xhci_find_next_cap_offset(void __iomem *base, int ext_offset)
  88. {
  89. u32 next;
  90. next = readl(base + ext_offset);
  91. if (ext_offset == XHCI_HCC_PARAMS_OFFSET) {
  92. /* Find the first extended capability */
  93. next = XHCI_HCC_EXT_CAPS(next);
  94. ext_offset = 0;
  95. } else {
  96. /* Find the next extended capability */
  97. next = XHCI_EXT_CAPS_NEXT(next);
  98. }
  99. if (!next)
  100. return 0;
  101. /*
  102. * Address calculation from offset of extended capabilities
  103. * (or HCCPARAMS) register - see section 5.3.6 and section 7.
  104. */
  105. return ext_offset + (next << 2);
  106. }
  107. /**
  108. * Find the offset of the extended capabilities with capability ID id.
  109. *
  110. * @base PCI MMIO registers base address.
  111. * @ext_offset Offset from base of the first extended capability to look at,
  112. * or the address of HCCPARAMS.
  113. * @id Extended capability ID to search for.
  114. *
  115. * This uses an arbitrary limit of XHCI_MAX_EXT_CAPS extended capabilities
  116. * to make sure that the list doesn't contain a loop.
  117. */
  118. static inline int xhci_find_ext_cap_by_id(void __iomem *base, int ext_offset, int id)
  119. {
  120. u32 val;
  121. int limit = XHCI_MAX_EXT_CAPS;
  122. while (ext_offset && limit > 0) {
  123. val = readl(base + ext_offset);
  124. if (XHCI_EXT_CAPS_ID(val) == id)
  125. break;
  126. ext_offset = xhci_find_next_cap_offset(base, ext_offset);
  127. limit--;
  128. }
  129. if (limit > 0)
  130. return ext_offset;
  131. return 0;
  132. }