enumeration.rst 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733
  1. .. SPDX-License-Identifier: GPL-2.0
  2. =============================
  3. ACPI Based Device Enumeration
  4. =============================
  5. ACPI 5 introduced a set of new resources (UartTSerialBus, I2cSerialBus,
  6. SpiSerialBus, GpioIo and GpioInt) which can be used in enumerating slave
  7. devices behind serial bus controllers.
  8. In addition we are starting to see peripherals integrated in the
  9. SoC/Chipset to appear only in ACPI namespace. These are typically devices
  10. that are accessed through memory-mapped registers.
  11. In order to support this and re-use the existing drivers as much as
  12. possible we decided to do following:
  13. - Devices that have no bus connector resource are represented as
  14. platform devices.
  15. - Devices behind real busses where there is a connector resource
  16. are represented as struct spi_device or struct i2c_client. Note
  17. that standard UARTs are not busses so there is no struct uart_device,
  18. although some of them may be represented by struct serdev_device.
  19. As both ACPI and Device Tree represent a tree of devices (and their
  20. resources) this implementation follows the Device Tree way as much as
  21. possible.
  22. The ACPI implementation enumerates devices behind busses (platform, SPI,
  23. I2C, and in some cases UART), creates the physical devices and binds them
  24. to their ACPI handle in the ACPI namespace.
  25. This means that when ACPI_HANDLE(dev) returns non-NULL the device was
  26. enumerated from ACPI namespace. This handle can be used to extract other
  27. device-specific configuration. There is an example of this below.
  28. Platform bus support
  29. ====================
  30. Since we are using platform devices to represent devices that are not
  31. connected to any physical bus we only need to implement a platform driver
  32. for the device and add supported ACPI IDs. If this same IP-block is used on
  33. some other non-ACPI platform, the driver might work out of the box or needs
  34. some minor changes.
  35. Adding ACPI support for an existing driver should be pretty
  36. straightforward. Here is the simplest example::
  37. static const struct acpi_device_id mydrv_acpi_match[] = {
  38. /* ACPI IDs here */
  39. { }
  40. };
  41. MODULE_DEVICE_TABLE(acpi, mydrv_acpi_match);
  42. static struct platform_driver my_driver = {
  43. ...
  44. .driver = {
  45. .acpi_match_table = mydrv_acpi_match,
  46. },
  47. };
  48. If the driver needs to perform more complex initialization like getting and
  49. configuring GPIOs it can get its ACPI handle and extract this information
  50. from ACPI tables.
  51. ACPI device objects
  52. ===================
  53. Generally speaking, there are two categories of devices in a system in which
  54. ACPI is used as an interface between the platform firmware and the OS: Devices
  55. that can be discovered and enumerated natively, through a protocol defined for
  56. the specific bus that they are on (for example, configuration space in PCI),
  57. without the platform firmware assistance, and devices that need to be described
  58. by the platform firmware so that they can be discovered. Still, for any device
  59. known to the platform firmware, regardless of which category it falls into,
  60. there can be a corresponding ACPI device object in the ACPI Namespace in which
  61. case the Linux kernel will create a struct acpi_device object based on it for
  62. that device.
  63. Those struct acpi_device objects are never used for binding drivers to natively
  64. discoverable devices, because they are represented by other types of device
  65. objects (for example, struct pci_dev for PCI devices) that are bound to by
  66. device drivers (the corresponding struct acpi_device object is then used as
  67. an additional source of information on the configuration of the given device).
  68. Moreover, the core ACPI device enumeration code creates struct platform_device
  69. objects for the majority of devices that are discovered and enumerated with the
  70. help of the platform firmware and those platform device objects can be bound to
  71. by platform drivers in direct analogy with the natively enumerable devices
  72. case. Therefore it is logically inconsistent and so generally invalid to bind
  73. drivers to struct acpi_device objects, including drivers for devices that are
  74. discovered with the help of the platform firmware.
  75. Historically, ACPI drivers that bound directly to struct acpi_device objects
  76. were implemented for some devices enumerated with the help of the platform
  77. firmware, but this is not recommended for any new drivers. As explained above,
  78. platform device objects are created for those devices as a rule (with a few
  79. exceptions that are not relevant here) and so platform drivers should be used
  80. for handling them, even though the corresponding ACPI device objects are the
  81. only source of device configuration information in that case.
  82. For every device having a corresponding struct acpi_device object, the pointer
  83. to it is returned by the ACPI_COMPANION() macro, so it is always possible to
  84. get to the device configuration information stored in the ACPI device object
  85. this way. Accordingly, struct acpi_device can be regarded as a part of the
  86. interface between the kernel and the ACPI Namespace, whereas device objects of
  87. other types (for example, struct pci_dev or struct platform_device) are used
  88. for interacting with the rest of the system.
  89. DMA support
  90. ===========
  91. DMA controllers enumerated via ACPI should be registered in the system to
  92. provide generic access to their resources. For example, a driver that would
  93. like to be accessible to slave devices via generic API call
  94. dma_request_chan() must register itself at the end of the probe function like
  95. this::
  96. err = devm_acpi_dma_controller_register(dev, xlate_func, dw);
  97. /* Handle the error if it's not a case of !CONFIG_ACPI */
  98. and implement custom xlate function if needed (usually acpi_dma_simple_xlate()
  99. is enough) which converts the FixedDMA resource provided by struct
  100. acpi_dma_spec into the corresponding DMA channel. A piece of code for that case
  101. could look like::
  102. #ifdef CONFIG_ACPI
  103. struct filter_args {
  104. /* Provide necessary information for the filter_func */
  105. ...
  106. };
  107. static bool filter_func(struct dma_chan *chan, void *param)
  108. {
  109. /* Choose the proper channel */
  110. ...
  111. }
  112. static struct dma_chan *xlate_func(struct acpi_dma_spec *dma_spec,
  113. struct acpi_dma *adma)
  114. {
  115. dma_cap_mask_t cap;
  116. struct filter_args args;
  117. /* Prepare arguments for filter_func */
  118. ...
  119. return dma_request_channel(cap, filter_func, &args);
  120. }
  121. #else
  122. static struct dma_chan *xlate_func(struct acpi_dma_spec *dma_spec,
  123. struct acpi_dma *adma)
  124. {
  125. return NULL;
  126. }
  127. #endif
  128. dma_request_chan() will call xlate_func() for each registered DMA controller.
  129. In the xlate function the proper channel must be chosen based on
  130. information in struct acpi_dma_spec and the properties of the controller
  131. provided by struct acpi_dma.
  132. Clients must call dma_request_chan() with the string parameter that corresponds
  133. to a specific FixedDMA resource. By default "tx" means the first entry of the
  134. FixedDMA resource array, "rx" means the second entry. The table below shows a
  135. layout::
  136. Device (I2C0)
  137. {
  138. ...
  139. Method (_CRS, 0, NotSerialized)
  140. {
  141. Name (DBUF, ResourceTemplate ()
  142. {
  143. FixedDMA (0x0018, 0x0004, Width32bit, _Y48)
  144. FixedDMA (0x0019, 0x0005, Width32bit, )
  145. })
  146. ...
  147. }
  148. }
  149. So, the FixedDMA with request line 0x0018 is "tx" and next one is "rx" in
  150. this example.
  151. In robust cases the client unfortunately needs to call
  152. acpi_dma_request_slave_chan_by_index() directly and therefore choose the
  153. specific FixedDMA resource by its index.
  154. Named Interrupts
  155. ================
  156. Drivers enumerated via ACPI can have names to interrupts in the ACPI table
  157. which can be used to get the IRQ number in the driver.
  158. The interrupt name can be listed in _DSD as 'interrupt-names'. The names
  159. should be listed as an array of strings which will map to the Interrupt()
  160. resource in the ACPI table corresponding to its index.
  161. The table below shows an example of its usage::
  162. Device (DEV0) {
  163. ...
  164. Name (_CRS, ResourceTemplate() {
  165. ...
  166. Interrupt (ResourceConsumer, Level, ActiveHigh, Exclusive) {
  167. 0x20,
  168. 0x24
  169. }
  170. })
  171. Name (_DSD, Package () {
  172. ToUUID("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"),
  173. Package () {
  174. Package () { "interrupt-names", Package () { "default", "alert" } },
  175. }
  176. ...
  177. })
  178. }
  179. The interrupt name 'default' will correspond to 0x20 in Interrupt()
  180. resource and 'alert' to 0x24. Note that only the Interrupt() resource
  181. is mapped and not GpioInt() or similar.
  182. The driver can call the function - fwnode_irq_get_byname() with the fwnode
  183. and interrupt name as arguments to get the corresponding IRQ number.
  184. SPI serial bus support
  185. ======================
  186. Slave devices behind SPI bus have SpiSerialBus resource attached to them.
  187. This is extracted automatically by the SPI core and the slave devices are
  188. enumerated once spi_register_master() is called by the bus driver.
  189. Here is what the ACPI namespace for a SPI slave might look like::
  190. Device (EEP0)
  191. {
  192. Name (_ADR, 1)
  193. Name (_CID, Package () {
  194. "ATML0025",
  195. "AT25",
  196. })
  197. ...
  198. Method (_CRS, 0, NotSerialized)
  199. {
  200. SPISerialBus(1, PolarityLow, FourWireMode, 8,
  201. ControllerInitiated, 1000000, ClockPolarityLow,
  202. ClockPhaseFirst, "\\_SB.PCI0.SPI1",)
  203. }
  204. ...
  205. The SPI device drivers only need to add ACPI IDs in a similar way to
  206. the platform device drivers. Below is an example where we add ACPI support
  207. to at25 SPI eeprom driver (this is meant for the above ACPI snippet)::
  208. static const struct acpi_device_id at25_acpi_match[] = {
  209. { "AT25", 0 },
  210. { }
  211. };
  212. MODULE_DEVICE_TABLE(acpi, at25_acpi_match);
  213. static struct spi_driver at25_driver = {
  214. .driver = {
  215. ...
  216. .acpi_match_table = at25_acpi_match,
  217. },
  218. };
  219. Note that this driver actually needs more information like page size of the
  220. eeprom, etc. This information can be passed via _DSD method like::
  221. Device (EEP0)
  222. {
  223. ...
  224. Name (_DSD, Package ()
  225. {
  226. ToUUID("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"),
  227. Package ()
  228. {
  229. Package () { "size", 1024 },
  230. Package () { "pagesize", 32 },
  231. Package () { "address-width", 16 },
  232. }
  233. })
  234. }
  235. Then the at25 SPI driver can get this configuration by calling device property
  236. APIs during ->probe() phase like::
  237. err = device_property_read_u32(dev, "size", &size);
  238. if (err)
  239. ...error handling...
  240. err = device_property_read_u32(dev, "pagesize", &page_size);
  241. if (err)
  242. ...error handling...
  243. err = device_property_read_u32(dev, "address-width", &addr_width);
  244. if (err)
  245. ...error handling...
  246. I2C serial bus support
  247. ======================
  248. The slaves behind I2C bus controller only need to add the ACPI IDs like
  249. with the platform and SPI drivers. The I2C core automatically enumerates
  250. any slave devices behind the controller device once the adapter is
  251. registered.
  252. Below is an example of how to add ACPI support to the existing mpu3050
  253. input driver::
  254. static const struct acpi_device_id mpu3050_acpi_match[] = {
  255. { "MPU3050", 0 },
  256. { }
  257. };
  258. MODULE_DEVICE_TABLE(acpi, mpu3050_acpi_match);
  259. static struct i2c_driver mpu3050_i2c_driver = {
  260. .driver = {
  261. .name = "mpu3050",
  262. .pm = &mpu3050_pm,
  263. .of_match_table = mpu3050_of_match,
  264. .acpi_match_table = mpu3050_acpi_match,
  265. },
  266. .probe = mpu3050_probe,
  267. .remove = mpu3050_remove,
  268. .id_table = mpu3050_ids,
  269. };
  270. module_i2c_driver(mpu3050_i2c_driver);
  271. Reference to PWM device
  272. =======================
  273. Sometimes a device can be a consumer of PWM channel. Obviously OS would like
  274. to know which one. To provide this mapping the special property has been
  275. introduced, i.e.::
  276. Device (DEV)
  277. {
  278. Name (_DSD, Package ()
  279. {
  280. ToUUID("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"),
  281. Package () {
  282. Package () { "compatible", Package () { "pwm-leds" } },
  283. Package () { "label", "alarm-led" },
  284. Package () { "pwms",
  285. Package () {
  286. "\\_SB.PCI0.PWM", // <PWM device reference>
  287. 0, // <PWM index>
  288. 600000000, // <PWM period>
  289. 0, // <PWM flags>
  290. }
  291. }
  292. }
  293. })
  294. ...
  295. }
  296. In the above example the PWM-based LED driver references to the PWM channel 0
  297. of \_SB.PCI0.PWM device with initial period setting equal to 600 ms (note that
  298. value is given in nanoseconds).
  299. GPIO support
  300. ============
  301. ACPI 5 introduced two new resources to describe GPIO connections: GpioIo
  302. and GpioInt. These resources can be used to pass GPIO numbers used by
  303. the device to the driver. ACPI 5.1 extended this with _DSD (Device
  304. Specific Data) which made it possible to name the GPIOs among other things.
  305. For example::
  306. Device (DEV)
  307. {
  308. Method (_CRS, 0, NotSerialized)
  309. {
  310. Name (SBUF, ResourceTemplate()
  311. {
  312. // Used to power on/off the device
  313. GpioIo (Exclusive, PullNone, 0, 0, IoRestrictionOutputOnly,
  314. "\\_SB.PCI0.GPI0", 0, ResourceConsumer) { 85 }
  315. // Interrupt for the device
  316. GpioInt (Edge, ActiveHigh, ExclusiveAndWake, PullNone, 0,
  317. "\\_SB.PCI0.GPI0", 0, ResourceConsumer) { 88 }
  318. }
  319. Return (SBUF)
  320. }
  321. // ACPI 5.1 _DSD used for naming the GPIOs
  322. Name (_DSD, Package ()
  323. {
  324. ToUUID("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"),
  325. Package ()
  326. {
  327. Package () { "power-gpios", Package () { ^DEV, 0, 0, 0 } },
  328. Package () { "irq-gpios", Package () { ^DEV, 1, 0, 0 } },
  329. }
  330. })
  331. ...
  332. }
  333. These GPIO numbers are controller relative and path "\\_SB.PCI0.GPI0"
  334. specifies the path to the controller. In order to use these GPIOs in Linux
  335. we need to translate them to the corresponding Linux GPIO descriptors.
  336. There is a standard GPIO API for that and it is documented in
  337. Documentation/admin-guide/gpio/.
  338. In the above example we can get the corresponding two GPIO descriptors with
  339. a code like this::
  340. #include <linux/gpio/consumer.h>
  341. ...
  342. struct gpio_desc *irq_desc, *power_desc;
  343. irq_desc = gpiod_get(dev, "irq");
  344. if (IS_ERR(irq_desc))
  345. /* handle error */
  346. power_desc = gpiod_get(dev, "power");
  347. if (IS_ERR(power_desc))
  348. /* handle error */
  349. /* Now we can use the GPIO descriptors */
  350. There are also devm_* versions of these functions which release the
  351. descriptors once the device is released.
  352. See Documentation/firmware-guide/acpi/gpio-properties.rst for more information
  353. about the _DSD binding related to GPIOs.
  354. RS-485 support
  355. ==============
  356. ACPI _DSD (Device Specific Data) can be used to describe RS-485 capability
  357. of UART.
  358. For example::
  359. Device (DEV)
  360. {
  361. ...
  362. // ACPI 5.1 _DSD used for RS-485 capabilities
  363. Name (_DSD, Package ()
  364. {
  365. ToUUID("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"),
  366. Package ()
  367. {
  368. Package () {"rs485-rts-active-low", Zero},
  369. Package () {"rs485-rx-active-high", Zero},
  370. Package () {"rs485-rx-during-tx", Zero},
  371. }
  372. })
  373. ...
  374. MFD devices
  375. ===========
  376. The MFD devices register their children as platform devices. For the child
  377. devices there needs to be an ACPI handle that they can use to reference
  378. parts of the ACPI namespace that relate to them. In the Linux MFD subsystem
  379. we provide two ways:
  380. - The children share the parent ACPI handle.
  381. - The MFD cell can specify the ACPI id of the device.
  382. For the first case, the MFD drivers do not need to do anything. The
  383. resulting child platform device will have its ACPI_COMPANION() set to point
  384. to the parent device.
  385. If the ACPI namespace has a device that we can match using an ACPI id or ACPI
  386. adr, the cell should be set like::
  387. static struct mfd_cell_acpi_match my_subdevice_cell_acpi_match = {
  388. .pnpid = "XYZ0001",
  389. .adr = 0,
  390. };
  391. static struct mfd_cell my_subdevice_cell = {
  392. .name = "my_subdevice",
  393. /* set the resources relative to the parent */
  394. .acpi_match = &my_subdevice_cell_acpi_match,
  395. };
  396. The ACPI id "XYZ0001" is then used to lookup an ACPI device directly under
  397. the MFD device and if found, that ACPI companion device is bound to the
  398. resulting child platform device.
  399. Device Tree namespace link device ID
  400. ====================================
  401. The Device Tree protocol uses device identification based on the "compatible"
  402. property whose value is a string or an array of strings recognized as device
  403. identifiers by drivers and the driver core. The set of all those strings may be
  404. regarded as a device identification namespace analogous to the ACPI/PNP device
  405. ID namespace. Consequently, in principle it should not be necessary to allocate
  406. a new (and arguably redundant) ACPI/PNP device ID for a devices with an existing
  407. identification string in the Device Tree (DT) namespace, especially if that ID
  408. is only needed to indicate that a given device is compatible with another one,
  409. presumably having a matching driver in the kernel already.
  410. In ACPI, the device identification object called _CID (Compatible ID) is used to
  411. list the IDs of devices the given one is compatible with, but those IDs must
  412. belong to one of the namespaces prescribed by the ACPI specification (see
  413. Section 6.1.2 of ACPI 6.0 for details) and the DT namespace is not one of them.
  414. Moreover, the specification mandates that either a _HID or an _ADR identification
  415. object be present for all ACPI objects representing devices (Section 6.1 of ACPI
  416. 6.0). For non-enumerable bus types that object must be _HID and its value must
  417. be a device ID from one of the namespaces prescribed by the specification too.
  418. The special DT namespace link device ID, PRP0001, provides a means to use the
  419. existing DT-compatible device identification in ACPI and to satisfy the above
  420. requirements following from the ACPI specification at the same time. Namely,
  421. if PRP0001 is returned by _HID, the ACPI subsystem will look for the
  422. "compatible" property in the device object's _DSD and will use the value of that
  423. property to identify the corresponding device in analogy with the original DT
  424. device identification algorithm. If the "compatible" property is not present
  425. or its value is not valid, the device will not be enumerated by the ACPI
  426. subsystem. Otherwise, it will be enumerated automatically as a platform device
  427. (except when an I2C or SPI link from the device to its parent is present, in
  428. which case the ACPI core will leave the device enumeration to the parent's
  429. driver) and the identification strings from the "compatible" property value will
  430. be used to find a driver for the device along with the device IDs listed by _CID
  431. (if present).
  432. Analogously, if PRP0001 is present in the list of device IDs returned by _CID,
  433. the identification strings listed by the "compatible" property value (if present
  434. and valid) will be used to look for a driver matching the device, but in that
  435. case their relative priority with respect to the other device IDs listed by
  436. _HID and _CID depends on the position of PRP0001 in the _CID return package.
  437. Specifically, the device IDs returned by _HID and preceding PRP0001 in the _CID
  438. return package will be checked first. Also in that case the bus type the device
  439. will be enumerated to depends on the device ID returned by _HID.
  440. For example, the following ACPI sample might be used to enumerate an lm75-type
  441. I2C temperature sensor and match it to the driver using the Device Tree
  442. namespace link::
  443. Device (TMP0)
  444. {
  445. Name (_HID, "PRP0001")
  446. Name (_DSD, Package () {
  447. ToUUID("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"),
  448. Package () {
  449. Package () { "compatible", "ti,tmp75" },
  450. }
  451. })
  452. Method (_CRS, 0, Serialized)
  453. {
  454. Name (SBUF, ResourceTemplate ()
  455. {
  456. I2cSerialBusV2 (0x48, ControllerInitiated,
  457. 400000, AddressingMode7Bit,
  458. "\\_SB.PCI0.I2C1", 0x00,
  459. ResourceConsumer, , Exclusive,)
  460. })
  461. Return (SBUF)
  462. }
  463. }
  464. It is valid to define device objects with a _HID returning PRP0001 and without
  465. the "compatible" property in the _DSD or a _CID as long as one of their
  466. ancestors provides a _DSD with a valid "compatible" property. Such device
  467. objects are then simply regarded as additional "blocks" providing hierarchical
  468. configuration information to the driver of the composite ancestor device.
  469. However, PRP0001 can only be returned from either _HID or _CID of a device
  470. object if all of the properties returned by the _DSD associated with it (either
  471. the _DSD of the device object itself or the _DSD of its ancestor in the
  472. "composite device" case described above) can be used in the ACPI environment.
  473. Otherwise, the _DSD itself is regarded as invalid and therefore the "compatible"
  474. property returned by it is meaningless.
  475. Refer to Documentation/firmware-guide/acpi/DSD-properties-rules.rst for more
  476. information.
  477. PCI hierarchy representation
  478. ============================
  479. Sometimes it could be useful to enumerate a PCI device, knowing its position on
  480. the PCI bus.
  481. For example, some systems use PCI devices soldered directly on the mother board,
  482. in a fixed position (ethernet, Wi-Fi, serial ports, etc.). In this conditions it
  483. is possible to refer to these PCI devices knowing their position on the PCI bus
  484. topology.
  485. To identify a PCI device, a complete hierarchical description is required, from
  486. the chipset root port to the final device, through all the intermediate
  487. bridges/switches of the board.
  488. For example, let's assume we have a system with a PCIe serial port, an
  489. Exar XR17V3521, soldered on the main board. This UART chip also includes
  490. 16 GPIOs and we want to add the property ``gpio-line-names`` [1]_ to these pins.
  491. In this case, the ``lspci`` output for this component is::
  492. 07:00.0 Serial controller: Exar Corp. XR17V3521 Dual PCIe UART (rev 03)
  493. The complete ``lspci`` output (manually reduced in length) is::
  494. 00:00.0 Host bridge: Intel Corp... Host Bridge (rev 0d)
  495. ...
  496. 00:13.0 PCI bridge: Intel Corp... PCI Express Port A #1 (rev fd)
  497. 00:13.1 PCI bridge: Intel Corp... PCI Express Port A #2 (rev fd)
  498. 00:13.2 PCI bridge: Intel Corp... PCI Express Port A #3 (rev fd)
  499. 00:14.0 PCI bridge: Intel Corp... PCI Express Port B #1 (rev fd)
  500. 00:14.1 PCI bridge: Intel Corp... PCI Express Port B #2 (rev fd)
  501. ...
  502. 05:00.0 PCI bridge: Pericom Semiconductor Device 2404 (rev 05)
  503. 06:01.0 PCI bridge: Pericom Semiconductor Device 2404 (rev 05)
  504. 06:02.0 PCI bridge: Pericom Semiconductor Device 2404 (rev 05)
  505. 06:03.0 PCI bridge: Pericom Semiconductor Device 2404 (rev 05)
  506. 07:00.0 Serial controller: Exar Corp. XR17V3521 Dual PCIe UART (rev 03) <-- Exar
  507. ...
  508. The bus topology is::
  509. -[0000:00]-+-00.0
  510. ...
  511. +-13.0-[01]----00.0
  512. +-13.1-[02]----00.0
  513. +-13.2-[03]--
  514. +-14.0-[04]----00.0
  515. +-14.1-[05-09]----00.0-[06-09]--+-01.0-[07]----00.0 <-- Exar
  516. | +-02.0-[08]----00.0
  517. | \-03.0-[09]--
  518. ...
  519. \-1f.1
  520. To describe this Exar device on the PCI bus, we must start from the ACPI name
  521. of the chipset bridge (also called "root port") with address::
  522. Bus: 0 - Device: 14 - Function: 1
  523. To find this information, it is necessary to disassemble the BIOS ACPI tables,
  524. in particular the DSDT (see also [2]_)::
  525. mkdir ~/tables/
  526. cd ~/tables/
  527. acpidump > acpidump
  528. acpixtract -a acpidump
  529. iasl -e ssdt?.* -d dsdt.dat
  530. Now, in the dsdt.dsl, we have to search the device whose address is related to
  531. 0x14 (device) and 0x01 (function). In this case we can find the following
  532. device::
  533. Scope (_SB.PCI0)
  534. {
  535. ... other definitions follow ...
  536. Device (RP02)
  537. {
  538. Method (_ADR, 0, NotSerialized) // _ADR: Address
  539. {
  540. If ((RPA2 != Zero))
  541. {
  542. Return (RPA2) /* \RPA2 */
  543. }
  544. Else
  545. {
  546. Return (0x00140001)
  547. }
  548. }
  549. ... other definitions follow ...
  550. and the _ADR method [3]_ returns exactly the device/function couple that
  551. we are looking for. With this information and analyzing the above ``lspci``
  552. output (both the devices list and the devices tree), we can write the following
  553. ACPI description for the Exar PCIe UART, also adding the list of its GPIO line
  554. names::
  555. Scope (_SB.PCI0.RP02)
  556. {
  557. Device (BRG1) //Bridge
  558. {
  559. Name (_ADR, 0x0000)
  560. Device (BRG2) //Bridge
  561. {
  562. Name (_ADR, 0x00010000)
  563. Device (EXAR)
  564. {
  565. Name (_ADR, 0x0000)
  566. Name (_DSD, Package ()
  567. {
  568. ToUUID("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"),
  569. Package ()
  570. {
  571. Package ()
  572. {
  573. "gpio-line-names",
  574. Package ()
  575. {
  576. "mode_232",
  577. "mode_422",
  578. "mode_485",
  579. "misc_1",
  580. "misc_2",
  581. "misc_3",
  582. "",
  583. "",
  584. "aux_1",
  585. "aux_2",
  586. "aux_3",
  587. }
  588. }
  589. }
  590. })
  591. }
  592. }
  593. }
  594. }
  595. The location "_SB.PCI0.RP02" is obtained by the above investigation in the
  596. dsdt.dsl table, whereas the device names "BRG1", "BRG2" and "EXAR" are
  597. created analyzing the position of the Exar UART in the PCI bus topology.
  598. References
  599. ==========
  600. .. [1] Documentation/firmware-guide/acpi/gpio-properties.rst
  601. .. [2] Documentation/admin-guide/acpi/initrd_table_override.rst
  602. .. [3] ACPI Specifications, Version 6.3 - Paragraph 6.1.1 _ADR Address)
  603. https://uefi.org/sites/default/files/resources/ACPI_6_3_May16.pdf,
  604. referenced 2020-11-18