blob: cf69167bd171b0b6203642ef7c3530f06fae79a5 [file] [log] [blame]
Simon Glassff3e0772015-03-05 12:25:25 -07001PCI with Driver Model
2=====================
3
4How busses are scanned
5----------------------
6
7Any config read will end up at pci_read_config(). This uses
8uclass_get_device_by_seq() to get the PCI bus for a particular bus number.
Bin Meng947eb432015-07-27 00:33:43 -07009Bus number 0 will need to be requested first, and the alias in the device
Simon Glassff3e0772015-03-05 12:25:25 -070010tree file will point to the correct device:
11
12
13 aliases {
14 pci0 = &pci;
15 };
16
17 pci: pci-controller {
18 compatible = "sandbox,pci";
19 ...
20 };
21
22
23If there is no alias the devices will be numbered sequentially in the device
24tree.
25
Bin Meng947eb432015-07-27 00:33:43 -070026The call to uclass_get_device() will cause the PCI bus to be probed.
Simon Glassff3e0772015-03-05 12:25:25 -070027This does a scan of the bus to locate available devices. These devices are
28bound to their appropriate driver if available. If there is no driver, then
29they are bound to a generic PCI driver which does nothing.
30
31After probing a bus, the available devices will appear in the device tree
32under that bus.
33
34Note that this is all done on a lazy basis, as needed, so until something is
Bin Meng947eb432015-07-27 00:33:43 -070035touched on PCI (eg: a call to pci_find_devices()) it will not be probed.
Simon Glassff3e0772015-03-05 12:25:25 -070036
37PCI devices can appear in the device tree. If they do this serves to specify
38the driver to use for the device. In this case they will be bound at
39start-up.
40
41
42Sandbox
43-------
44
45With sandbox we need a device emulator for each device on the bus since there
46is no real PCI bus. This works by looking in the device tree node for a
47driver. For example:
48
49
50 pci@1f,0 {
51 compatible = "pci-generic";
52 reg = <0xf800 0 0 0 0>;
53 emul@1f,0 {
54 compatible = "sandbox,swap-case";
55 };
56 };
57
58This means that there is a 'sandbox,swap-case' driver at that bus position.
59Note that the first cell in the 'reg' value is the bus/device/function. See
60PCI_BDF() for the encoding (it is also specified in the IEEE Std 1275-1994
61PCI bus binding document, v2.1)
62
63When this bus is scanned we will end up with something like this:
64
65`- * pci-controller @ 05c660c8, 0
66 `- pci@1f,0 @ 05c661c8, 63488
67 `- emul@1f,0 @ 05c662c8
68
69When accesses go to the pci@1f,0 device they are forwarded to its child, the
70emulator.