blob: 8dc7c46d3530c26acc7a69700136dbcf46732c54 [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 */
Lee Leahy0ca2a062017-03-06 18:01:04 -080035 void (*set_subsystem)(device_t dev, unsigned int vendor,
36 unsigned int device);
Kenji Chen31c6e632014-10-04 01:14:44 +080037 void (*set_L1_ss_latency)(device_t dev, unsigned int off);
Eric Biedermanb78c1972004-10-14 20:54:17 +000038};
39
Eric Biedermana9e632c2004-11-18 22:38:08 +000040/* Common pci bus operations */
41struct pci_bus_operations {
Yinghai Lud4b278c2006-10-04 20:46:15 +000042 uint8_t (*read8) (struct bus *pbus, int bus, int devfn, int where);
43 uint16_t (*read16) (struct bus *pbus, int bus, int devfn, int where);
44 uint32_t (*read32) (struct bus *pbus, int bus, int devfn, int where);
45 void (*write8) (struct bus *pbus, int bus, int devfn, int where, uint8_t val);
46 void (*write16) (struct bus *pbus, int bus, int devfn, int where, uint16_t val);
47 void (*write32) (struct bus *pbus, int bus, int devfn, int where, uint32_t val);
Eric Biedermana9e632c2004-11-18 22:38:08 +000048};
49
Eric Biederman5899fd82003-04-24 06:25:08 +000050struct pci_driver {
Uwe Hermann312673c2009-10-27 21:49:33 +000051 const struct device_operations *ops;
Eric Biederman5899fd82003-04-24 06:25:08 +000052 unsigned short vendor;
53 unsigned short device;
Vadim Bendebury8049fc92012-04-24 12:53:19 -070054 const unsigned short *devices;
Eric Biederman5899fd82003-04-24 06:25:08 +000055};
56
Eric Biedermanb78c1972004-10-14 20:54:17 +000057#define __pci_driver __attribute__ ((used,__section__(".rodata.pci_driver")))
Li-Ta Loe5266692004-03-23 21:28:05 +000058/** start of compile time generated pci driver array */
Aaron Durbin03758152015-09-03 17:23:08 -050059extern struct pci_driver _pci_drivers[];
Li-Ta Loe5266692004-03-23 21:28:05 +000060/** end of compile time generated pci driver array */
Aaron Durbin03758152015-09-03 17:23:08 -050061extern struct pci_driver _epci_drivers[];
Eric Biederman5899fd82003-04-24 06:25:08 +000062
63
Yinghai Lu13f1c2a2005-07-08 02:49:49 +000064extern struct device_operations default_pci_ops_dev;
65extern struct device_operations default_pci_ops_bus;
Eric Biederman5899fd82003-04-24 06:25:08 +000066
Eric Biedermane9a271e32003-09-02 03:36:25 +000067void pci_dev_read_resources(device_t dev);
68void pci_bus_read_resources(device_t dev);
69void pci_dev_set_resources(device_t dev);
70void pci_dev_enable_resources(device_t dev);
71void pci_bus_enable_resources(device_t dev);
Yinghai Lu13f1c2a2005-07-08 02:49:49 +000072void pci_bus_reset(struct bus *bus);
Lee Leahy0ca2a062017-03-06 18:01:04 -080073device_t pci_probe_dev(device_t dev, struct bus *bus, unsigned int devfn);
Kyösti Mälkkide271a82015-03-18 13:09:47 +020074
Kyösti Mälkki580e7222015-03-19 21:04:23 +020075void do_pci_scan_bridge(device_t bus,
Kyösti Mälkkide271a82015-03-18 13:09:47 +020076 void (*do_scan_bus)(struct bus *bus,
Lee Leahy0ca2a062017-03-06 18:01:04 -080077 unsigned int min_devfn, unsigned int max_devfn));
Kyösti Mälkkide271a82015-03-18 13:09:47 +020078
Kyösti Mälkki580e7222015-03-19 21:04:23 +020079void pci_scan_bridge(device_t bus);
Lee Leahy0ca2a062017-03-06 18:01:04 -080080void pci_scan_bus(struct bus *bus, unsigned int min_devfn,
81 unsigned int max_devfn);
Kyösti Mälkkide271a82015-03-18 13:09:47 +020082
Lee Leahy0ca2a062017-03-06 18:01:04 -080083uint8_t pci_moving_config8(struct device *dev, unsigned int reg);
84uint16_t pci_moving_config16(struct device *dev, unsigned int reg);
85uint32_t pci_moving_config32(struct device *dev, unsigned int reg);
Eric Biedermanb78c1972004-10-14 20:54:17 +000086struct resource *pci_get_resource(struct device *dev, unsigned long index);
Lee Leahy0ca2a062017-03-06 18:01:04 -080087void pci_dev_set_subsystem(device_t dev, unsigned int vendor,
88 unsigned int device);
Myles Watson43bb9cd2008-12-18 18:24:11 +000089void pci_dev_init(struct device *dev);
Kyösti Mälkkic73acdb2013-06-15 17:16:56 +030090unsigned int pci_match_simple_dev(device_t dev, pci_devfn_t sdev);
Stefan Reinauer4d933dd2009-07-21 21:36:41 +000091
Mike Loptien0f5cf5e2014-05-12 21:46:31 -060092const char * pin_to_str(int pin);
93int get_pci_irq_pins(device_t dev, device_t *parent_bdg);
Lee Leahy0ca2a062017-03-06 18:01:04 -080094void pci_assign_irqs(unsigned int bus, unsigned int slot,
Myles Watson43bb9cd2008-12-18 18:24:11 +000095 const unsigned char pIntAtoD[4]);
Lee Leahye1ba3da2015-03-31 17:30:01 -070096const char *get_pci_class_name(device_t dev);
97const char *get_pci_subclass_name(device_t dev);
Eric Biederman5899fd82003-04-24 06:25:08 +000098
99#define PCI_IO_BRIDGE_ALIGN 4096
100#define PCI_MEM_BRIDGE_ALIGN (1024*1024)
101
Eric Biedermana9e632c2004-11-18 22:38:08 +0000102static inline const struct pci_operations *ops_pci(device_t dev)
Eric Biedermanb78c1972004-10-14 20:54:17 +0000103{
Eric Biedermana9e632c2004-11-18 22:38:08 +0000104 const struct pci_operations *pops;
Eric Biedermanb78c1972004-10-14 20:54:17 +0000105 pops = 0;
106 if (dev && dev->ops) {
107 pops = dev->ops->ops_pci;
108 }
109 return pops;
110}
111
Kyösti Mälkkief844012013-06-25 23:17:43 +0300112#endif /* ! __SIMPLE_DEVICE__ */
Kyösti Mälkki318066f2014-02-12 14:18:50 +0200113
Antonello Dettori45b3b822016-08-30 22:18:06 +0200114#ifdef __SIMPLE_DEVICE__
Lee Leahy0ca2a062017-03-06 18:01:04 -0800115unsigned int pci_find_next_capability(pci_devfn_t dev, unsigned int cap,
116 unsigned int last);
117unsigned int pci_find_capability(pci_devfn_t dev, unsigned int cap);
Antonello Dettori45b3b822016-08-30 22:18:06 +0200118#else /* !__SIMPLE_DEVICE__ */
Lee Leahy0ca2a062017-03-06 18:01:04 -0800119unsigned int pci_find_next_capability(device_t dev, unsigned int cap,
120 unsigned int last);
121unsigned int pci_find_capability(device_t dev, unsigned int cap);
Antonello Dettori45b3b822016-08-30 22:18:06 +0200122#endif /* __SIMPLE_DEVICE__ */
Edward O'Callaghanc2956e72014-07-09 04:55:16 +1000123
Kyösti Mälkki4c686f22014-02-14 12:45:09 +0200124void pci_early_bridge_init(void);
125int pci_early_device_probe(u8 bus, u8 dev, u32 mmio_base);
Kyösti Mälkki2161c1d2014-02-11 19:56:57 +0200126
Alexandru Gagniuc420caaf2016-01-05 17:00:27 -0800127#ifndef __ROMCC__
128static inline int pci_base_address_is_memory_space(unsigned int attr)
129{
130 return (attr & PCI_BASE_ADDRESS_SPACE) == PCI_BASE_ADDRESS_SPACE_MEMORY;
131}
132#endif
133
Kyösti Mälkki318066f2014-02-12 14:18:50 +0200134#endif /* CONFIG_PCI */
135
Eric Biederman5899fd82003-04-24 06:25:08 +0000136#endif /* PCI_H */