blob: 51d52835fdc49c1aa1259003d533d05920d0d673 [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
Uwe Hermanne4870472010-11-04 23:23:47 +000018#include <stdint.h>
Eric Biederman52685572003-05-19 19:16:21 +000019#include <device/pci_def.h>
Eric Biederman5899fd82003-04-24 06:25:08 +000020#include <device/resource.h>
21#include <device/device.h>
22#include <device/pci_ops.h>
Li-Ta Lo883b8792005-01-10 23:16:22 +000023#include <device/pci_rom.h>
Eric Biederman5899fd82003-04-24 06:25:08 +000024
Eric Biedermanb78c1972004-10-14 20:54:17 +000025/* Common pci operations without a standard interface */
26struct pci_operations {
Li-Ta Lo04930692004-11-25 17:37:19 +000027 /* set the Subsystem IDs for the PCI device */
Eric Biedermanb78c1972004-10-14 20:54:17 +000028 void (*set_subsystem)(device_t dev, unsigned vendor, unsigned device);
29};
30
Eric Biedermana9e632c2004-11-18 22:38:08 +000031/* Common pci bus operations */
32struct pci_bus_operations {
Yinghai Lud4b278c2006-10-04 20:46:15 +000033 uint8_t (*read8) (struct bus *pbus, int bus, int devfn, int where);
34 uint16_t (*read16) (struct bus *pbus, int bus, int devfn, int where);
35 uint32_t (*read32) (struct bus *pbus, int bus, int devfn, int where);
36 void (*write8) (struct bus *pbus, int bus, int devfn, int where, uint8_t val);
37 void (*write16) (struct bus *pbus, int bus, int devfn, int where, uint16_t val);
38 void (*write32) (struct bus *pbus, int bus, int devfn, int where, uint32_t val);
Eric Biedermana9e632c2004-11-18 22:38:08 +000039};
40
Eric Biederman5899fd82003-04-24 06:25:08 +000041struct pci_driver {
Uwe Hermann312673c2009-10-27 21:49:33 +000042 const struct device_operations *ops;
Eric Biederman5899fd82003-04-24 06:25:08 +000043 unsigned short vendor;
44 unsigned short device;
Vadim Bendebury8049fc92012-04-24 12:53:19 -070045 const unsigned short *devices;
Eric Biederman5899fd82003-04-24 06:25:08 +000046};
47
Eric Biedermanb78c1972004-10-14 20:54:17 +000048#define __pci_driver __attribute__ ((used,__section__(".rodata.pci_driver")))
Li-Ta Loe5266692004-03-23 21:28:05 +000049/** start of compile time generated pci driver array */
Eric Biederman5899fd82003-04-24 06:25:08 +000050extern struct pci_driver pci_drivers[];
Li-Ta Loe5266692004-03-23 21:28:05 +000051/** end of compile time generated pci driver array */
Eric Biederman5899fd82003-04-24 06:25:08 +000052extern struct pci_driver epci_drivers[];
53
54
Yinghai Lu13f1c2a2005-07-08 02:49:49 +000055extern struct device_operations default_pci_ops_dev;
56extern struct device_operations default_pci_ops_bus;
Eric Biederman5899fd82003-04-24 06:25:08 +000057
Eric Biedermane9a271e32003-09-02 03:36:25 +000058void pci_dev_read_resources(device_t dev);
59void pci_bus_read_resources(device_t dev);
60void pci_dev_set_resources(device_t dev);
61void pci_dev_enable_resources(device_t dev);
62void pci_bus_enable_resources(device_t dev);
Yinghai Lu13f1c2a2005-07-08 02:49:49 +000063void pci_bus_reset(struct bus *bus);
64device_t pci_probe_dev(device_t dev, struct bus *bus, unsigned devfn);
65unsigned int do_pci_scan_bridge(device_t bus, unsigned int max,
Stefan Reinauer14e22772010-04-27 06:56:47 +000066 unsigned int (*do_scan_bus)(struct bus *bus,
Yinghai Lu13f1c2a2005-07-08 02:49:49 +000067 unsigned min_devfn, unsigned max_devfn, unsigned int max));
Eric Biedermane9a271e32003-09-02 03:36:25 +000068unsigned int pci_scan_bridge(device_t bus, unsigned int max);
69unsigned int pci_scan_bus(struct bus *bus, unsigned min_devfn, unsigned max_devfn, unsigned int max);
Yinghai Lu13f1c2a2005-07-08 02:49:49 +000070uint8_t pci_moving_config8(struct device *dev, unsigned reg);
71uint16_t pci_moving_config16(struct device *dev, unsigned reg);
72uint32_t pci_moving_config32(struct device *dev, unsigned reg);
73unsigned pci_find_next_capability(device_t dev, unsigned cap, unsigned last);
74unsigned pci_find_capability(device_t dev, unsigned cap);
Eric Biedermanb78c1972004-10-14 20:54:17 +000075struct resource *pci_get_resource(struct device *dev, unsigned long index);
Eric Biedermandbec2d42004-10-21 10:44:08 +000076void pci_dev_set_subsystem(device_t dev, unsigned vendor, unsigned device);
Myles Watson43bb9cd2008-12-18 18:24:11 +000077void pci_dev_init(struct device *dev);
Stefan Reinauer4d933dd2009-07-21 21:36:41 +000078
Myles Watson43bb9cd2008-12-18 18:24:11 +000079void pci_assign_irqs(unsigned bus, unsigned slot,
80 const unsigned char pIntAtoD[4]);
Eric Biederman5899fd82003-04-24 06:25:08 +000081
82#define PCI_IO_BRIDGE_ALIGN 4096
83#define PCI_MEM_BRIDGE_ALIGN (1024*1024)
84
Eric Biedermana9e632c2004-11-18 22:38:08 +000085static inline const struct pci_operations *ops_pci(device_t dev)
Eric Biedermanb78c1972004-10-14 20:54:17 +000086{
Eric Biedermana9e632c2004-11-18 22:38:08 +000087 const struct pci_operations *pops;
Eric Biedermanb78c1972004-10-14 20:54:17 +000088 pops = 0;
89 if (dev && dev->ops) {
90 pops = dev->ops->ops_pci;
91 }
92 return pops;
93}
94
Eric Biedermana9e632c2004-11-18 22:38:08 +000095static inline const struct pci_bus_operations *ops_pci_bus(struct bus *bus)
96{
97 const struct pci_bus_operations *bops;
98 bops = 0;
99 if (bus && bus->dev && bus->dev->ops) {
100 bops = bus->dev->ops->ops_pci_bus;
101 }
Carl-Daniel Hailfinger00003ae2009-09-22 00:09:41 +0000102 if (!bops)
Ronald G. Minnich97de28d2012-07-02 09:41:10 -0700103 bops = pci_config_default();
Eric Biedermana9e632c2004-11-18 22:38:08 +0000104 return bops;
105}
106
Patrick Georgi87fcffa2011-02-03 09:14:40 +0000107unsigned mainboard_pci_subsystem_vendor_id(struct device *dev);
108unsigned mainboard_pci_subsystem_device_id(struct device *dev);
109
Eric Biederman5899fd82003-04-24 06:25:08 +0000110#endif /* PCI_H */