blob: e167752e92aba535274cbaca03be9811112bcf97 [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 */
Aaron Durbin03758152015-09-03 17:23:08 -050058extern struct pci_driver _pci_drivers[];
Li-Ta Loe5266692004-03-23 21:28:05 +000059/** end of compile time generated pci driver array */
Aaron Durbin03758152015-09-03 17:23:08 -050060extern struct pci_driver _epci_drivers[];
Eric Biederman5899fd82003-04-24 06:25:08 +000061
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);
Kyösti Mälkkide271a82015-03-18 13:09:47 +020073
Kyösti Mälkki580e7222015-03-19 21:04:23 +020074void do_pci_scan_bridge(device_t bus,
Kyösti Mälkkide271a82015-03-18 13:09:47 +020075 void (*do_scan_bus)(struct bus *bus,
76 unsigned min_devfn, unsigned max_devfn));
Kyösti Mälkkide271a82015-03-18 13:09:47 +020077
Kyösti Mälkki580e7222015-03-19 21:04:23 +020078void pci_scan_bridge(device_t bus);
Kyösti Mälkkide271a82015-03-18 13:09:47 +020079void pci_scan_bus(struct bus *bus, unsigned min_devfn, unsigned max_devfn);
80
Yinghai Lu13f1c2a2005-07-08 02:49:49 +000081uint8_t pci_moving_config8(struct device *dev, unsigned reg);
82uint16_t pci_moving_config16(struct device *dev, unsigned reg);
83uint32_t pci_moving_config32(struct device *dev, unsigned reg);
Eric Biedermanb78c1972004-10-14 20:54:17 +000084struct resource *pci_get_resource(struct device *dev, unsigned long index);
Eric Biedermandbec2d42004-10-21 10:44:08 +000085void pci_dev_set_subsystem(device_t dev, unsigned vendor, unsigned device);
Myles Watson43bb9cd2008-12-18 18:24:11 +000086void pci_dev_init(struct device *dev);
Kyösti Mälkkic73acdb2013-06-15 17:16:56 +030087unsigned int pci_match_simple_dev(device_t dev, pci_devfn_t sdev);
Stefan Reinauer4d933dd2009-07-21 21:36:41 +000088
Mike Loptien0f5cf5e2014-05-12 21:46:31 -060089const char * pin_to_str(int pin);
90int get_pci_irq_pins(device_t dev, device_t *parent_bdg);
Myles Watson43bb9cd2008-12-18 18:24:11 +000091void pci_assign_irqs(unsigned bus, unsigned slot,
92 const unsigned char pIntAtoD[4]);
Lee Leahye1ba3da2015-03-31 17:30:01 -070093const char *get_pci_class_name(device_t dev);
94const char *get_pci_subclass_name(device_t dev);
Eric Biederman5899fd82003-04-24 06:25:08 +000095
96#define PCI_IO_BRIDGE_ALIGN 4096
97#define PCI_MEM_BRIDGE_ALIGN (1024*1024)
98
Eric Biedermana9e632c2004-11-18 22:38:08 +000099static inline const struct pci_operations *ops_pci(device_t dev)
Eric Biedermanb78c1972004-10-14 20:54:17 +0000100{
Eric Biedermana9e632c2004-11-18 22:38:08 +0000101 const struct pci_operations *pops;
Eric Biedermanb78c1972004-10-14 20:54:17 +0000102 pops = 0;
103 if (dev && dev->ops) {
104 pops = dev->ops->ops_pci;
105 }
106 return pops;
107}
108
Kyösti Mälkkief844012013-06-25 23:17:43 +0300109#endif /* ! __SIMPLE_DEVICE__ */
Kyösti Mälkki318066f2014-02-12 14:18:50 +0200110
Antonello Dettori45b3b822016-08-30 22:18:06 +0200111#ifdef __SIMPLE_DEVICE__
Edward O'Callaghanc2956e72014-07-09 04:55:16 +1000112unsigned pci_find_next_capability(pci_devfn_t dev, unsigned cap, unsigned last);
113unsigned pci_find_capability(pci_devfn_t dev, unsigned cap);
Antonello Dettori45b3b822016-08-30 22:18:06 +0200114#else /* !__SIMPLE_DEVICE__ */
Kyösti Mälkki2161c1d2014-02-11 19:56:57 +0200115unsigned pci_find_next_capability(device_t dev, unsigned cap, unsigned last);
116unsigned pci_find_capability(device_t dev, unsigned cap);
Antonello Dettori45b3b822016-08-30 22:18:06 +0200117#endif /* __SIMPLE_DEVICE__ */
Edward O'Callaghanc2956e72014-07-09 04:55:16 +1000118
Kyösti Mälkki4c686f22014-02-14 12:45:09 +0200119void pci_early_bridge_init(void);
120int pci_early_device_probe(u8 bus, u8 dev, u32 mmio_base);
Kyösti Mälkki2161c1d2014-02-11 19:56:57 +0200121
Alexandru Gagniuc420caaf2016-01-05 17:00:27 -0800122#ifndef __ROMCC__
123static inline int pci_base_address_is_memory_space(unsigned int attr)
124{
125 return (attr & PCI_BASE_ADDRESS_SPACE) == PCI_BASE_ADDRESS_SPACE_MEMORY;
126}
127#endif
128
Kyösti Mälkki318066f2014-02-12 14:18:50 +0200129#endif /* CONFIG_PCI */
130
Eric Biederman5899fd82003-04-24 06:25:08 +0000131#endif /* PCI_H */