blob: a215a2a028859fee48c735057a18a0766080cc8f [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>
Stefan Reinauer57879c92012-07-31 16:47:25 -070019#include <stddef.h>
Eric Biederman52685572003-05-19 19:16:21 +000020#include <device/pci_def.h>
Eric Biederman5899fd82003-04-24 06:25:08 +000021#include <device/resource.h>
22#include <device/device.h>
Stefan Reinauer57879c92012-07-31 16:47:25 -070023#ifndef __PRE_RAM__
Eric Biederman5899fd82003-04-24 06:25:08 +000024#include <device/pci_ops.h>
Li-Ta Lo883b8792005-01-10 23:16:22 +000025#include <device/pci_rom.h>
Eric Biederman5899fd82003-04-24 06:25:08 +000026
Eric Biedermanb78c1972004-10-14 20:54:17 +000027/* Common pci operations without a standard interface */
28struct pci_operations {
Li-Ta Lo04930692004-11-25 17:37:19 +000029 /* set the Subsystem IDs for the PCI device */
Eric Biedermanb78c1972004-10-14 20:54:17 +000030 void (*set_subsystem)(device_t dev, unsigned vendor, unsigned device);
31};
32
Eric Biedermana9e632c2004-11-18 22:38:08 +000033/* Common pci bus operations */
34struct pci_bus_operations {
Yinghai Lud4b278c2006-10-04 20:46:15 +000035 uint8_t (*read8) (struct bus *pbus, int bus, int devfn, int where);
36 uint16_t (*read16) (struct bus *pbus, int bus, int devfn, int where);
37 uint32_t (*read32) (struct bus *pbus, int bus, int devfn, int where);
38 void (*write8) (struct bus *pbus, int bus, int devfn, int where, uint8_t val);
39 void (*write16) (struct bus *pbus, int bus, int devfn, int where, uint16_t val);
40 void (*write32) (struct bus *pbus, int bus, int devfn, int where, uint32_t val);
Eric Biedermana9e632c2004-11-18 22:38:08 +000041};
42
Eric Biederman5899fd82003-04-24 06:25:08 +000043struct pci_driver {
Uwe Hermann312673c2009-10-27 21:49:33 +000044 const struct device_operations *ops;
Eric Biederman5899fd82003-04-24 06:25:08 +000045 unsigned short vendor;
46 unsigned short device;
Vadim Bendebury8049fc92012-04-24 12:53:19 -070047 const unsigned short *devices;
Eric Biederman5899fd82003-04-24 06:25:08 +000048};
49
Eric Biedermanb78c1972004-10-14 20:54:17 +000050#define __pci_driver __attribute__ ((used,__section__(".rodata.pci_driver")))
Li-Ta Loe5266692004-03-23 21:28:05 +000051/** start of compile time generated pci driver array */
Eric Biederman5899fd82003-04-24 06:25:08 +000052extern struct pci_driver pci_drivers[];
Li-Ta Loe5266692004-03-23 21:28:05 +000053/** end of compile time generated pci driver array */
Eric Biederman5899fd82003-04-24 06:25:08 +000054extern struct pci_driver epci_drivers[];
55
56
Yinghai Lu13f1c2a2005-07-08 02:49:49 +000057extern struct device_operations default_pci_ops_dev;
58extern struct device_operations default_pci_ops_bus;
Eric Biederman5899fd82003-04-24 06:25:08 +000059
Eric Biedermane9a271e32003-09-02 03:36:25 +000060void pci_dev_read_resources(device_t dev);
61void pci_bus_read_resources(device_t dev);
62void pci_dev_set_resources(device_t dev);
63void pci_dev_enable_resources(device_t dev);
64void pci_bus_enable_resources(device_t dev);
Yinghai Lu13f1c2a2005-07-08 02:49:49 +000065void pci_bus_reset(struct bus *bus);
66device_t pci_probe_dev(device_t dev, struct bus *bus, unsigned devfn);
67unsigned int do_pci_scan_bridge(device_t bus, unsigned int max,
Stefan Reinauer14e22772010-04-27 06:56:47 +000068 unsigned int (*do_scan_bus)(struct bus *bus,
Yinghai Lu13f1c2a2005-07-08 02:49:49 +000069 unsigned min_devfn, unsigned max_devfn, unsigned int max));
Eric Biedermane9a271e32003-09-02 03:36:25 +000070unsigned int pci_scan_bridge(device_t bus, unsigned int max);
71unsigned int pci_scan_bus(struct bus *bus, unsigned min_devfn, unsigned max_devfn, unsigned int max);
Yinghai Lu13f1c2a2005-07-08 02:49:49 +000072uint8_t pci_moving_config8(struct device *dev, unsigned reg);
73uint16_t pci_moving_config16(struct device *dev, unsigned reg);
74uint32_t pci_moving_config32(struct device *dev, unsigned reg);
75unsigned pci_find_next_capability(device_t dev, unsigned cap, unsigned last);
76unsigned pci_find_capability(device_t dev, unsigned cap);
Eric Biedermanb78c1972004-10-14 20:54:17 +000077struct resource *pci_get_resource(struct device *dev, unsigned long index);
Eric Biedermandbec2d42004-10-21 10:44:08 +000078void pci_dev_set_subsystem(device_t dev, unsigned vendor, unsigned device);
Myles Watson43bb9cd2008-12-18 18:24:11 +000079void pci_dev_init(struct device *dev);
Stefan Reinauer4d933dd2009-07-21 21:36:41 +000080
Myles Watson43bb9cd2008-12-18 18:24:11 +000081void pci_assign_irqs(unsigned bus, unsigned slot,
82 const unsigned char pIntAtoD[4]);
Eric Biederman5899fd82003-04-24 06:25:08 +000083
84#define PCI_IO_BRIDGE_ALIGN 4096
85#define PCI_MEM_BRIDGE_ALIGN (1024*1024)
86
Eric Biedermana9e632c2004-11-18 22:38:08 +000087static inline const struct pci_operations *ops_pci(device_t dev)
Eric Biedermanb78c1972004-10-14 20:54:17 +000088{
Eric Biedermana9e632c2004-11-18 22:38:08 +000089 const struct pci_operations *pops;
Eric Biedermanb78c1972004-10-14 20:54:17 +000090 pops = 0;
91 if (dev && dev->ops) {
92 pops = dev->ops->ops_pci;
93 }
94 return pops;
95}
96
Eric Biedermana9e632c2004-11-18 22:38:08 +000097static inline const struct pci_bus_operations *ops_pci_bus(struct bus *bus)
98{
99 const struct pci_bus_operations *bops;
100 bops = 0;
101 if (bus && bus->dev && bus->dev->ops) {
102 bops = bus->dev->ops->ops_pci_bus;
103 }
Carl-Daniel Hailfinger00003ae2009-09-22 00:09:41 +0000104 if (!bops)
Ronald G. Minnich97de28d2012-07-02 09:41:10 -0700105 bops = pci_config_default();
Eric Biedermana9e632c2004-11-18 22:38:08 +0000106 return bops;
107}
108
Patrick Georgi87fcffa2011-02-03 09:14:40 +0000109unsigned mainboard_pci_subsystem_vendor_id(struct device *dev);
110unsigned mainboard_pci_subsystem_device_id(struct device *dev);
111
Stefan Reinauer57879c92012-07-31 16:47:25 -0700112#endif
Eric Biederman5899fd82003-04-24 06:25:08 +0000113#endif /* PCI_H */