1
2
3
4
5
6
7
8
9
10
11
12
13
14
15#ifndef PCI_H
16#define PCI_H
17
18#include <device/pci_def.h>
19#include <device/resource.h>
20#include <device/device.h>
21#include <device/pci_ops.h>
22#include <device/pci_rom.h>
23
24
25struct pci_operations {
26
27 void (*set_subsystem)(device_t dev, unsigned vendor, unsigned device);
28};
29
30
31struct pci_bus_operations {
32 uint8_t (*read8) (struct bus *pbus, int bus, int devfn, int where);
33 uint16_t (*read16) (struct bus *pbus, int bus, int devfn, int where);
34 uint32_t (*read32) (struct bus *pbus, int bus, int devfn, int where);
35 void (*write8) (struct bus *pbus, int bus, int devfn, int where, uint8_t val);
36 void (*write16) (struct bus *pbus, int bus, int devfn, int where, uint16_t val);
37 void (*write32) (struct bus *pbus, int bus, int devfn, int where, uint32_t val);
38};
39
40struct pci_driver {
41 const struct device_operations *ops;
42 unsigned short vendor;
43 unsigned short device;
44};
45
46#define __pci_driver __attribute__ ((used,__section__(".rodata.pci_driver")))
47
48extern struct pci_driver pci_drivers[];
49
50extern struct pci_driver epci_drivers[];
51
52
53extern struct device_operations default_pci_ops_dev;
54extern struct device_operations default_pci_ops_bus;
55
56void pci_dev_read_resources(device_t dev);
57void pci_bus_read_resources(device_t dev);
58void pci_dev_set_resources(device_t dev);
59void pci_dev_enable_resources(device_t dev);
60void pci_bus_enable_resources(device_t dev);
61void pci_bus_reset(struct bus *bus);
62device_t pci_probe_dev(device_t dev, struct bus *bus, unsigned devfn);
63unsigned int do_pci_scan_bridge(device_t bus, unsigned int max,
64 unsigned int (*do_scan_bus)(struct bus *bus,
65 unsigned min_devfn, unsigned max_devfn, unsigned int max));
66unsigned int pci_scan_bridge(device_t bus, unsigned int max);
67unsigned int pci_scan_bus(struct bus *bus, unsigned min_devfn, unsigned max_devfn, unsigned int max);
68uint8_t pci_moving_config8(struct device *dev, unsigned reg);
69uint16_t pci_moving_config16(struct device *dev, unsigned reg);
70uint32_t pci_moving_config32(struct device *dev, unsigned reg);
71unsigned pci_find_next_capability(device_t dev, unsigned cap, unsigned last);
72unsigned pci_find_capability(device_t dev, unsigned cap);
73struct resource *pci_get_resource(struct device *dev, unsigned long index);
74void pci_dev_set_subsystem(device_t dev, unsigned vendor, unsigned device);
75void pci_dev_init(struct device *dev);
76
77void pci_assign_irqs(unsigned bus, unsigned slot,
78 const unsigned char pIntAtoD[4]);
79
80#define PCI_IO_BRIDGE_ALIGN 4096
81#define PCI_MEM_BRIDGE_ALIGN (1024*1024)
82
83static inline const struct pci_operations *ops_pci(device_t dev)
84{
85 const struct pci_operations *pops;
86 pops = 0;
87 if (dev && dev->ops) {
88 pops = dev->ops->ops_pci;
89 }
90 return pops;
91}
92
93static inline const struct pci_bus_operations *ops_pci_bus(struct bus *bus)
94{
95 const struct pci_bus_operations *bops;
96 bops = 0;
97 if (bus && bus->dev && bus->dev->ops) {
98 bops = bus->dev->ops->ops_pci_bus;
99 }
100 if (!bops)
101 bops = pci_remember_direct();
102 return bops;
103}
104
105#endif
106