Merge branch 'for-next' of git://git.o-hand.com/linux-mfd
[deliverable/linux.git] / Documentation / filesystems / sysfs-pci.txt
CommitLineData
1da177e4 1Accessing PCI device resources through sysfs
5d135dff 2--------------------------------------------
1da177e4
LT
3
4sysfs, usually mounted at /sys, provides access to PCI resources on platforms
5that support it. For example, a given bus might look like this:
6
7 /sys/devices/pci0000:17
8 |-- 0000:17:00.0
9 | |-- class
10 | |-- config
1da177e4
LT
11 | |-- device
12 | |-- irq
13 | |-- local_cpus
14 | |-- resource
15 | |-- resource0
16 | |-- resource1
17 | |-- resource2
18 | |-- rom
19 | |-- subsystem_device
20 | |-- subsystem_vendor
21 | `-- vendor
0b405a0f 22 `-- ...
1da177e4
LT
23
24The topmost element describes the PCI domain and bus number. In this case,
25the domain number is 0000 and the bus number is 17 (both values are in hex).
26This bus contains a single function device in slot 0. The domain and bus
27numbers are reproduced for convenience. Under the device directory are several
28files, each with their own function.
29
30 file function
31 ---- --------
32 class PCI class (ascii, ro)
33 config PCI config space (binary, rw)
1da177e4
LT
34 device PCI device (ascii, ro)
35 irq IRQ number (ascii, ro)
36 local_cpus nearby CPU mask (cpumask, ro)
37 resource PCI resource host addresses (ascii, ro)
38 resource0..N PCI resource N, if present (binary, mmap)
45aec1ae 39 resource0_wc..N_wc PCI WC map resource N, if prefetchable (binary, mmap)
1da177e4
LT
40 rom PCI ROM resource, if present (binary, ro)
41 subsystem_device PCI subsystem device (ascii, ro)
42 subsystem_vendor PCI subsystem vendor (ascii, ro)
43 vendor PCI vendor (ascii, ro)
44
45 ro - read only file
46 rw - file is readable and writable
47 mmap - file is mmapable
48 ascii - file contains ascii text
49 binary - file contains binary data
50 cpumask - file contains a cpumask type
51
5d135dff
JB
52The read only files are informational, writes to them will be ignored, with
53the exception of the 'rom' file. Writable files can be used to perform
54actions on the device (e.g. changing config space, detaching a device).
55mmapable files are available via an mmap of the file at offset 0 and can be
56used to do actual device programming from userspace. Note that some platforms
57don't support mmapping of certain resources, so be sure to check the return
58value from any attempted mmap.
59
60The 'rom' file is special in that it provides read-only access to the device's
61ROM file, if available. It's disabled by default, however, so applications
62should write the string "1" to the file to enable it before attempting a read
63call, and disable it following the access by writing "0" to the file.
1da177e4
LT
64
65Accessing legacy resources through sysfs
5d135dff 66----------------------------------------
1da177e4
LT
67
68Legacy I/O port and ISA memory resources are also provided in sysfs if the
1b3c3714 69underlying platform supports them. They're located in the PCI class hierarchy,
1da177e4
LT
70e.g.
71
72 /sys/class/pci_bus/0000:17/
73 |-- bridge -> ../../../devices/pci0000:17
74 |-- cpuaffinity
75 |-- legacy_io
76 `-- legacy_mem
77
78The legacy_io file is a read/write file that can be used by applications to
79do legacy port I/O. The application should open the file, seek to the desired
80port (e.g. 0x3e8) and do a read or a write of 1, 2 or 4 bytes. The legacy_mem
81file should be mmapped with an offset corresponding to the memory offset
82desired, e.g. 0xa0000 for the VGA frame buffer. The application can then
83simply dereference the returned pointer (after checking for errors of course)
84to access legacy memory space.
85
86Supporting PCI access on new platforms
5d135dff 87--------------------------------------
1da177e4
LT
88
89In order to support PCI resource mapping as described above, Linux platform
90code must define HAVE_PCI_MMAP and provide a pci_mmap_page_range function.
91Platforms are free to only support subsets of the mmap functionality, but
92useful return codes should be provided.
93
94Legacy resources are protected by the HAVE_PCI_LEGACY define. Platforms
95wishing to support legacy functionality should define it and provide
0b405a0f 96pci_legacy_read, pci_legacy_write and pci_mmap_legacy_page_range functions.
This page took 0.605515 seconds and 5 git commands to generate.