0a06604e5dcbbef84a1382c0816ae25ba575c127
[coreboot.git] / payloads / libpayload / include / pci / pci.h
1 /*\r
2  * This file is part of the libpayload project.\r
3  *\r
4  * Copyright (C) 2010 coresystems GmbH\r
5  *\r
6  * Redistribution and use in source and binary forms, with or without\r
7  * modification, are permitted provided that the following conditions\r
8  * are met:\r
9  * 1. Redistributions of source code must retain the above copyright\r
10  *    notice, this list of conditions and the following disclaimer.\r
11  * 2. Redistributions in binary form must reproduce the above copyright\r
12  *    notice, this list of conditions and the following disclaimer in the\r
13  *    documentation and/or other materials provided with the distribution.\r
14  * 3. The name of the author may not be used to endorse or promote products\r
15  *    derived from this software without specific prior written permission.\r
16  *\r
17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND\r
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
20  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE\r
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
27  * SUCH DAMAGE.\r
28  */\r
29 \r
30 #ifndef _PCI_PCI_H\r
31 #define _PCI_PCI_H\r
32 \r
33 #include <pci.h>\r
34 \r
35 #define PCI_CLASS_DEVICE        REG_CLASS_DEV\r
36 #define PCI_SUBSYSTEM_VENDOR_ID REG_SUBSYS_VENDOR_ID\r
37 #define PCI_SUBSYSTEM_ID        REG_SUBSYS_ID\r
38 \r
39 struct pci_dev {\r
40         u16 domain;\r
41         u8 bus, dev, func;\r
42         u16 vendor_id, device_id;\r
43         struct pci_dev *next;\r
44 };\r
45 \r
46 /*\r
47  * values to match devices against.\r
48  * "-1" means "don't care", everything else requires an exact match\r
49  */\r
50 struct pci_filter {\r
51         int domain, bus, dev, func;\r
52         int vendor, device;\r
53         struct pci_dev *devices;\r
54 };\r
55 \r
56 struct pci_access {\r
57         struct pci_dev *devices;\r
58 };\r
59 \r
60 u8 pci_read_byte(struct pci_dev *dev, int pos);\r
61 u16 pci_read_word(struct pci_dev *dev, int pos);\r
62 u32 pci_read_long(struct pci_dev *dev, int pos);\r
63 \r
64 int pci_write_byte(struct pci_dev *dev, int pos, u8 data);\r
65 int pci_write_word(struct pci_dev *dev, int pos, u16 data);\r
66 int pci_write_long(struct pci_dev *dev, int pos, u32 data);\r
67 \r
68 struct pci_access *pci_alloc(void);\r
69 void pci_init(struct pci_access*);\r
70 char *pci_filter_parse_slot(struct pci_filter*, const char*);\r
71 int pci_filter_match(struct pci_filter*, struct pci_dev*);\r
72 void pci_filter_init(struct pci_access*, struct pci_filter*);\r
73 void pci_scan_bus(struct pci_access*);\r
74 struct pci_dev *pci_get_dev(struct pci_access*, u16, u8, u8, u8);\r
75 \r
76 #endif\r