blob: 2c9797fa6c1a3a55aa9e5036f2f4d45840fa1c8c [file] [log] [blame]
Eric Biederman5899fd82003-04-24 06:25:08 +00001/*
Eric Biederman5899fd82003-04-24 06:25:08 +00002 * PCI defines and function prototypes
3 * Copyright 1994, Drew Eckhardt
4 * Copyright 1997--1999 Martin Mares <mj@atrey.karlin.mff.cuni.cz>
5 *
6 * For more information, please consult the following manuals (look at
7 * http://www.pcisig.com/ for how to get them):
8 *
9 * PCI BIOS Specification
10 * PCI Local Bus Specification
11 * PCI to PCI Bridge Specification
12 * PCI System Design Guide
13 */
14
15#ifndef PCI_H
16#define PCI_H
17
Eric Biederman52685572003-05-19 19:16:21 +000018#include <device/pci_def.h>
Eric Biederman5899fd82003-04-24 06:25:08 +000019#include <device/resource.h>
20#include <device/device.h>
21#include <device/pci_ops.h>
22
23
Eric Biedermanb78c1972004-10-14 20:54:17 +000024/* Common pci operations without a standard interface */
25struct pci_operations {
26 void (*set_subsystem)(device_t dev, unsigned vendor, unsigned device);
27};
28
Eric Biedermana9e632c2004-11-18 22:38:08 +000029/* Common pci bus operations */
30struct pci_bus_operations {
31 uint8_t (*read8) (struct bus *pbus, unsigned char bus, int devfn, int where);
32 uint16_t (*read16) (struct bus *pbus, unsigned char bus, int devfn, int where);
33 uint32_t (*read32) (struct bus *pbus, unsigned char bus, int devfn, int where);
34 void (*write8) (struct bus *pbus, unsigned char bus, int devfn, int where, uint8_t val);
35 void (*write16) (struct bus *pbus, unsigned char bus, int devfn, int where, uint16_t val);
36 void (*write32) (struct bus *pbus, unsigned char bus, int devfn, int where, uint32_t val);
37};
38
Eric Biederman5899fd82003-04-24 06:25:08 +000039struct pci_driver {
40 struct device_operations *ops;
41 unsigned short vendor;
42 unsigned short device;
43};
44
Eric Biedermanb78c1972004-10-14 20:54:17 +000045#define __pci_driver __attribute__ ((used,__section__(".rodata.pci_driver")))
Li-Ta Loe5266692004-03-23 21:28:05 +000046/** start of compile time generated pci driver array */
Eric Biederman5899fd82003-04-24 06:25:08 +000047extern struct pci_driver pci_drivers[];
Li-Ta Loe5266692004-03-23 21:28:05 +000048/** end of compile time generated pci driver array */
Eric Biederman5899fd82003-04-24 06:25:08 +000049extern struct pci_driver epci_drivers[];
50
51
52struct device_operations default_pci_ops_dev;
53struct device_operations default_pci_ops_bus;
Eric Biederman5899fd82003-04-24 06:25:08 +000054
Eric Biedermane9a271e32003-09-02 03:36:25 +000055void pci_dev_read_resources(device_t dev);
56void pci_bus_read_resources(device_t dev);
57void pci_dev_set_resources(device_t dev);
58void pci_dev_enable_resources(device_t dev);
59void pci_bus_enable_resources(device_t dev);
60unsigned int pci_scan_bridge(device_t bus, unsigned int max);
61unsigned int pci_scan_bus(struct bus *bus, unsigned min_devfn, unsigned max_devfn, unsigned int max);
Eric Biedermanb78c1972004-10-14 20:54:17 +000062struct resource *pci_get_resource(struct device *dev, unsigned long index);
Eric Biedermandbec2d42004-10-21 10:44:08 +000063void pci_dev_set_subsystem(device_t dev, unsigned vendor, unsigned device);
Eric Biederman5899fd82003-04-24 06:25:08 +000064
65#define PCI_IO_BRIDGE_ALIGN 4096
66#define PCI_MEM_BRIDGE_ALIGN (1024*1024)
67
Eric Biedermana9e632c2004-11-18 22:38:08 +000068static inline const struct pci_operations *ops_pci(device_t dev)
Eric Biedermanb78c1972004-10-14 20:54:17 +000069{
Eric Biedermana9e632c2004-11-18 22:38:08 +000070 const struct pci_operations *pops;
Eric Biedermanb78c1972004-10-14 20:54:17 +000071 pops = 0;
72 if (dev && dev->ops) {
73 pops = dev->ops->ops_pci;
74 }
75 return pops;
76}
77
Eric Biedermana9e632c2004-11-18 22:38:08 +000078static inline const struct pci_bus_operations *ops_pci_bus(struct bus *bus)
79{
80 const struct pci_bus_operations *bops;
81 bops = 0;
82 if (bus && bus->dev && bus->dev->ops) {
83 bops = bus->dev->ops->ops_pci_bus;
84 }
85 return bops;
86}
87
Eric Biederman5899fd82003-04-24 06:25:08 +000088#endif /* PCI_H */