blob: 4e712f9f7b7f9c71785224f2aeff105cff1b642c [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);
Kenji Chen31c6e632014-10-04 01:14:44 +080036 void (*set_L1_ss_latency)(device_t dev, unsigned int off);
Eric Biedermanb78c1972004-10-14 20:54:17 +000037};
38
Eric Biedermana9e632c2004-11-18 22:38:08 +000039/* Common pci bus operations */
40struct pci_bus_operations {
Yinghai Lud4b278c2006-10-04 20:46:15 +000041 uint8_t (*read8) (struct bus *pbus, int bus, int devfn, int where);
42 uint16_t (*read16) (struct bus *pbus, int bus, int devfn, int where);
43 uint32_t (*read32) (struct bus *pbus, int bus, int devfn, int where);
44 void (*write8) (struct bus *pbus, int bus, int devfn, int where, uint8_t val);
45 void (*write16) (struct bus *pbus, int bus, int devfn, int where, uint16_t val);
46 void (*write32) (struct bus *pbus, int bus, int devfn, int where, uint32_t val);
Eric Biedermana9e632c2004-11-18 22:38:08 +000047};
48
Eric Biederman5899fd82003-04-24 06:25:08 +000049struct pci_driver {
Uwe Hermann312673c2009-10-27 21:49:33 +000050 const struct device_operations *ops;
Eric Biederman5899fd82003-04-24 06:25:08 +000051 unsigned short vendor;
52 unsigned short device;
Vadim Bendebury8049fc92012-04-24 12:53:19 -070053 const unsigned short *devices;
Eric Biederman5899fd82003-04-24 06:25:08 +000054};
55
Eric Biedermanb78c1972004-10-14 20:54:17 +000056#define __pci_driver __attribute__ ((used,__section__(".rodata.pci_driver")))
Li-Ta Loe5266692004-03-23 21:28:05 +000057/** start of compile time generated pci driver array */
Eric Biederman5899fd82003-04-24 06:25:08 +000058extern struct pci_driver pci_drivers[];
Li-Ta Loe5266692004-03-23 21:28:05 +000059/** end of compile time generated pci driver array */
Eric Biederman5899fd82003-04-24 06:25:08 +000060extern struct pci_driver epci_drivers[];
61
62
Yinghai Lu13f1c2a2005-07-08 02:49:49 +000063extern struct device_operations default_pci_ops_dev;
64extern struct device_operations default_pci_ops_bus;
Eric Biederman5899fd82003-04-24 06:25:08 +000065
Eric Biedermane9a271e32003-09-02 03:36:25 +000066void pci_dev_read_resources(device_t dev);
67void pci_bus_read_resources(device_t dev);
68void pci_dev_set_resources(device_t dev);
69void pci_dev_enable_resources(device_t dev);
70void pci_bus_enable_resources(device_t dev);
Yinghai Lu13f1c2a2005-07-08 02:49:49 +000071void pci_bus_reset(struct bus *bus);
72device_t pci_probe_dev(device_t dev, struct bus *bus, unsigned devfn);
73unsigned int do_pci_scan_bridge(device_t bus, unsigned int max,
Stefan Reinauer14e22772010-04-27 06:56:47 +000074 unsigned int (*do_scan_bus)(struct bus *bus,
Yinghai Lu13f1c2a2005-07-08 02:49:49 +000075 unsigned min_devfn, unsigned max_devfn, unsigned int max));
Eric Biedermane9a271e32003-09-02 03:36:25 +000076unsigned int pci_scan_bridge(device_t bus, unsigned int max);
77unsigned int pci_scan_bus(struct bus *bus, unsigned min_devfn, unsigned max_devfn, unsigned int max);
Yinghai Lu13f1c2a2005-07-08 02:49:49 +000078uint8_t pci_moving_config8(struct device *dev, unsigned reg);
79uint16_t pci_moving_config16(struct device *dev, unsigned reg);
80uint32_t pci_moving_config32(struct device *dev, unsigned reg);
Eric Biedermanb78c1972004-10-14 20:54:17 +000081struct resource *pci_get_resource(struct device *dev, unsigned long index);
Eric Biedermandbec2d42004-10-21 10:44:08 +000082void pci_dev_set_subsystem(device_t dev, unsigned vendor, unsigned device);
Myles Watson43bb9cd2008-12-18 18:24:11 +000083void pci_dev_init(struct device *dev);
Kyösti Mälkkic73acdb2013-06-15 17:16:56 +030084unsigned int pci_match_simple_dev(device_t dev, pci_devfn_t sdev);
Stefan Reinauer4d933dd2009-07-21 21:36:41 +000085
Mike Loptien0f5cf5e2014-05-12 21:46:31 -060086const char * pin_to_str(int pin);
87int get_pci_irq_pins(device_t dev, device_t *parent_bdg);
Myles Watson43bb9cd2008-12-18 18:24:11 +000088void pci_assign_irqs(unsigned bus, unsigned slot,
89 const unsigned char pIntAtoD[4]);
Eric Biederman5899fd82003-04-24 06:25:08 +000090
91#define PCI_IO_BRIDGE_ALIGN 4096
92#define PCI_MEM_BRIDGE_ALIGN (1024*1024)
93
Eric Biedermana9e632c2004-11-18 22:38:08 +000094static inline const struct pci_operations *ops_pci(device_t dev)
Eric Biedermanb78c1972004-10-14 20:54:17 +000095{
Eric Biedermana9e632c2004-11-18 22:38:08 +000096 const struct pci_operations *pops;
Eric Biedermanb78c1972004-10-14 20:54:17 +000097 pops = 0;
98 if (dev && dev->ops) {
99 pops = dev->ops->ops_pci;
100 }
101 return pops;
102}
103
Kyösti Mälkkief844012013-06-25 23:17:43 +0300104#endif /* ! __SIMPLE_DEVICE__ */
Kyösti Mälkki318066f2014-02-12 14:18:50 +0200105
Edward O'Callaghanc2956e72014-07-09 04:55:16 +1000106#ifdef __PRE_RAM__
107unsigned pci_find_next_capability(pci_devfn_t dev, unsigned cap, unsigned last);
108unsigned pci_find_capability(pci_devfn_t dev, unsigned cap);
109#else /* !__PRE_RAM__ */
Kyösti Mälkki2161c1d2014-02-11 19:56:57 +0200110unsigned pci_find_next_capability(device_t dev, unsigned cap, unsigned last);
111unsigned pci_find_capability(device_t dev, unsigned cap);
Edward O'Callaghanc2956e72014-07-09 04:55:16 +1000112#endif /* __PRE_RAM__ */
113
Kyösti Mälkki4c686f22014-02-14 12:45:09 +0200114void pci_early_bridge_init(void);
115int pci_early_device_probe(u8 bus, u8 dev, u32 mmio_base);
Kyösti Mälkki2161c1d2014-02-11 19:56:57 +0200116
Kyösti Mälkki318066f2014-02-12 14:18:50 +0200117#endif /* CONFIG_PCI */
118
Eric Biederman5899fd82003-04-24 06:25:08 +0000119#endif /* PCI_H */