blob: 81759706aa270b8f8fee109a6cceb08e59ad7d9f [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
Kyösti Mälkki318066f2014-02-12 14:18:50 +020018#if CONFIG_PCI
19
Uwe Hermanne4870472010-11-04 23:23:47 +000020#include <stdint.h>
Stefan Reinauer57879c92012-07-31 16:47:25 -070021#include <stddef.h>
Kyösti Mälkkie8792be2014-02-26 15:19:04 +020022#include <rules.h>
Kyösti Mälkki2161c1d2014-02-11 19:56:57 +020023#include <arch/io.h>
Eric Biederman52685572003-05-19 19:16:21 +000024#include <device/pci_def.h>
Eric Biederman5899fd82003-04-24 06:25:08 +000025#include <device/resource.h>
26#include <device/device.h>
27#include <device/pci_ops.h>
Li-Ta Lo883b8792005-01-10 23:16:22 +000028#include <device/pci_rom.h>
Eric Biederman5899fd82003-04-24 06:25:08 +000029
Kyösti Mälkkief844012013-06-25 23:17:43 +030030#ifndef __SIMPLE_DEVICE__
31
Eric Biedermanb78c1972004-10-14 20:54:17 +000032/* Common pci operations without a standard interface */
33struct pci_operations {
Li-Ta Lo04930692004-11-25 17:37:19 +000034 /* set the Subsystem IDs for the PCI device */
Eric Biedermanb78c1972004-10-14 20:54:17 +000035 void (*set_subsystem)(device_t dev, unsigned vendor, unsigned device);
36};
37
Eric Biedermana9e632c2004-11-18 22:38:08 +000038/* Common pci bus operations */
39struct pci_bus_operations {
Yinghai Lud4b278c2006-10-04 20:46:15 +000040 uint8_t (*read8) (struct bus *pbus, int bus, int devfn, int where);
41 uint16_t (*read16) (struct bus *pbus, int bus, int devfn, int where);
42 uint32_t (*read32) (struct bus *pbus, int bus, int devfn, int where);
43 void (*write8) (struct bus *pbus, int bus, int devfn, int where, uint8_t val);
44 void (*write16) (struct bus *pbus, int bus, int devfn, int where, uint16_t val);
45 void (*write32) (struct bus *pbus, int bus, int devfn, int where, uint32_t val);
Eric Biedermana9e632c2004-11-18 22:38:08 +000046};
47
Eric Biederman5899fd82003-04-24 06:25:08 +000048struct pci_driver {
Uwe Hermann312673c2009-10-27 21:49:33 +000049 const struct device_operations *ops;
Eric Biederman5899fd82003-04-24 06:25:08 +000050 unsigned short vendor;
51 unsigned short device;
Vadim Bendebury8049fc92012-04-24 12:53:19 -070052 const unsigned short *devices;
Eric Biederman5899fd82003-04-24 06:25:08 +000053};
54
Eric Biedermanb78c1972004-10-14 20:54:17 +000055#define __pci_driver __attribute__ ((used,__section__(".rodata.pci_driver")))
Li-Ta Loe5266692004-03-23 21:28:05 +000056/** start of compile time generated pci driver array */
Eric Biederman5899fd82003-04-24 06:25:08 +000057extern struct pci_driver pci_drivers[];
Li-Ta Loe5266692004-03-23 21:28:05 +000058/** end of compile time generated pci driver array */
Eric Biederman5899fd82003-04-24 06:25:08 +000059extern struct pci_driver epci_drivers[];
60
61
Yinghai Lu13f1c2a2005-07-08 02:49:49 +000062extern struct device_operations default_pci_ops_dev;
63extern struct device_operations default_pci_ops_bus;
Eric Biederman5899fd82003-04-24 06:25:08 +000064
Eric Biedermane9a271e32003-09-02 03:36:25 +000065void pci_dev_read_resources(device_t dev);
66void pci_bus_read_resources(device_t dev);
67void pci_dev_set_resources(device_t dev);
68void pci_dev_enable_resources(device_t dev);
69void pci_bus_enable_resources(device_t dev);
Yinghai Lu13f1c2a2005-07-08 02:49:49 +000070void pci_bus_reset(struct bus *bus);
71device_t pci_probe_dev(device_t dev, struct bus *bus, unsigned devfn);
72unsigned int do_pci_scan_bridge(device_t bus, unsigned int max,
Stefan Reinauer14e22772010-04-27 06:56:47 +000073 unsigned int (*do_scan_bus)(struct bus *bus,
Yinghai Lu13f1c2a2005-07-08 02:49:49 +000074 unsigned min_devfn, unsigned max_devfn, unsigned int max));
Eric Biedermane9a271e32003-09-02 03:36:25 +000075unsigned int pci_scan_bridge(device_t bus, unsigned int max);
76unsigned int pci_scan_bus(struct bus *bus, unsigned min_devfn, unsigned max_devfn, unsigned int max);
Yinghai Lu13f1c2a2005-07-08 02:49:49 +000077uint8_t pci_moving_config8(struct device *dev, unsigned reg);
78uint16_t pci_moving_config16(struct device *dev, unsigned reg);
79uint32_t pci_moving_config32(struct device *dev, unsigned reg);
Eric Biedermanb78c1972004-10-14 20:54:17 +000080struct resource *pci_get_resource(struct device *dev, unsigned long index);
Eric Biedermandbec2d42004-10-21 10:44:08 +000081void pci_dev_set_subsystem(device_t dev, unsigned vendor, unsigned device);
Myles Watson43bb9cd2008-12-18 18:24:11 +000082void pci_dev_init(struct device *dev);
Kyösti Mälkkic73acdb2013-06-15 17:16:56 +030083unsigned int pci_match_simple_dev(device_t dev, pci_devfn_t sdev);
Stefan Reinauer4d933dd2009-07-21 21:36:41 +000084
Mike Loptien0f5cf5e2014-05-12 21:46:31 -060085const char * pin_to_str(int pin);
86int get_pci_irq_pins(device_t dev, device_t *parent_bdg);
Myles Watson43bb9cd2008-12-18 18:24:11 +000087void pci_assign_irqs(unsigned bus, unsigned slot,
88 const unsigned char pIntAtoD[4]);
Eric Biederman5899fd82003-04-24 06:25:08 +000089
90#define PCI_IO_BRIDGE_ALIGN 4096
91#define PCI_MEM_BRIDGE_ALIGN (1024*1024)
92
Eric Biedermana9e632c2004-11-18 22:38:08 +000093static inline const struct pci_operations *ops_pci(device_t dev)
Eric Biedermanb78c1972004-10-14 20:54:17 +000094{
Eric Biedermana9e632c2004-11-18 22:38:08 +000095 const struct pci_operations *pops;
Eric Biedermanb78c1972004-10-14 20:54:17 +000096 pops = 0;
97 if (dev && dev->ops) {
98 pops = dev->ops->ops_pci;
99 }
100 return pops;
101}
102
Kyösti Mälkkief844012013-06-25 23:17:43 +0300103#endif /* ! __SIMPLE_DEVICE__ */
Kyösti Mälkki318066f2014-02-12 14:18:50 +0200104
Kyösti Mälkki2161c1d2014-02-11 19:56:57 +0200105unsigned pci_find_next_capability(device_t dev, unsigned cap, unsigned last);
106unsigned pci_find_capability(device_t dev, unsigned cap);
Kyösti Mälkki4c686f22014-02-14 12:45:09 +0200107void pci_early_bridge_init(void);
108int pci_early_device_probe(u8 bus, u8 dev, u32 mmio_base);
Kyösti Mälkki2161c1d2014-02-11 19:56:57 +0200109
Kyösti Mälkki318066f2014-02-12 14:18:50 +0200110#endif /* CONFIG_PCI */
111
Eric Biederman5899fd82003-04-24 06:25:08 +0000112#endif /* PCI_H */