FreeBSD kernel amd64 PCI device code
pcib_private.h
Go to the documentation of this file.
1/*-
2 * SPDX-License-Identifier: BSD-3-Clause
3 *
4 * Copyright (c) 1994,1995 Stefan Esser, Wolfgang StanglMeier
5 * Copyright (c) 2000 Michael Smith <msmith@freebsd.org>
6 * Copyright (c) 2000 BSDi
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. The name of the author may not be used to endorse or promote products
18 * derived from this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * SUCH DAMAGE.
31 *
32 * $FreeBSD$
33 */
34
35#ifndef __PCIB_PRIVATE_H__
36#define __PCIB_PRIVATE_H__
37
38#include <sys/taskqueue.h>
39
40#ifdef NEW_PCIB
41/*
42 * Data structure and routines that Host to PCI bridge drivers can use
43 * to restrict allocations for child devices to ranges decoded by the
44 * bridge.
45 */
46struct pcib_host_resources {
47 device_t hr_pcib;
48 struct resource_list hr_rl;
49};
50
51int pcib_host_res_init(device_t pcib,
52 struct pcib_host_resources *hr);
53int pcib_host_res_free(device_t pcib,
54 struct pcib_host_resources *hr);
55int pcib_host_res_decodes(struct pcib_host_resources *hr, int type,
56 rman_res_t start, rman_res_t end, u_int flags);
57struct resource *pcib_host_res_alloc(struct pcib_host_resources *hr,
58 device_t dev, int type, int *rid, rman_res_t start,
59 rman_res_t end, rman_res_t count, u_int flags);
60int pcib_host_res_adjust(struct pcib_host_resources *hr,
61 device_t dev, int type, struct resource *r, rman_res_t start,
62 rman_res_t end);
63#endif
64
65/*
66 * Export portions of generic PCI:PCI bridge support so that it can be
67 * used by subclasses.
68 */
69DECLARE_CLASS(pcib_driver);
70
71#ifdef NEW_PCIB
72#define WIN_IO 0x1
73#define WIN_MEM 0x2
74#define WIN_PMEM 0x4
75
76struct pcib_window {
77 pci_addr_t base; /* base address */
78 pci_addr_t limit; /* topmost address */
79 struct rman rman;
80 struct resource **res;
81 int count; /* size of 'res' array */
82 int reg; /* resource id from parent */
83 int valid;
84 int mask; /* WIN_* bitmask of this window */
85 int step; /* log_2 of window granularity */
86 const char *name;
87};
88#endif
89
91 u_int sec;
92 u_int sub;
93#if defined(NEW_PCIB) && defined(PCI_RES_BUS)
94 device_t dev;
95 struct rman rman;
96 struct resource *res;
97 const char *name;
98 int sub_reg;
99#endif
100};
101
102/*
103 * Bridge-specific data.
104 */
106{
107 device_t dev;
108 device_t child;
109 uint32_t flags; /* flags */
110#define PCIB_SUBTRACTIVE 0x1
111#define PCIB_DISABLE_MSI 0x2
112#define PCIB_DISABLE_MSIX 0x4
113#define PCIB_ENABLE_ARI 0x8
114#define PCIB_HOTPLUG 0x10
115#define PCIB_HOTPLUG_CMD_PENDING 0x20
116#define PCIB_DETACH_PENDING 0x40
117#define PCIB_DETACHING 0x80
118 u_int domain; /* domain number */
119 u_int pribus; /* primary bus number */
120 struct pcib_secbus bus; /* secondary bus numbers */
121#ifdef NEW_PCIB
122 struct pcib_window io; /* I/O port window */
123 struct pcib_window mem; /* memory window */
124 struct pcib_window pmem; /* prefetchable memory window */
125#else
126 pci_addr_t pmembase; /* base address of prefetchable memory */
127 pci_addr_t pmemlimit; /* topmost address of prefetchable memory */
128 pci_addr_t membase; /* base address of memory window */
129 pci_addr_t memlimit; /* topmost address of memory window */
130 uint32_t iobase; /* base address of port window */
131 uint32_t iolimit; /* topmost address of port window */
132#endif
133 uint16_t bridgectl; /* bridge control register */
137 struct resource *pcie_irq;
139 struct task pcie_hp_task;
140 struct timeout_task pcie_ab_task;
141 struct timeout_task pcie_cc_task;
142 struct timeout_task pcie_dll_task;
143 struct mtx *pcie_hp_lock;
144};
145
146#define PCIB_HP_LOCK(sc) mtx_lock((sc)->pcie_hp_lock)
147#define PCIB_HP_UNLOCK(sc) mtx_unlock((sc)->pcie_hp_lock)
148#define PCIB_HP_LOCK_ASSERT(sc) mtx_assert((sc)->pcie_hp_lock, MA_OWNED)
149
150#define PCIB_SUPPORTED_ARI_VER 1
151
152typedef uint32_t pci_read_config_fn(int b, int s, int f, int reg, int width);
153
155 int slot, int func, uint8_t *busnum);
156#if defined(NEW_PCIB) && defined(PCI_RES_BUS)
157struct resource *pci_domain_alloc_bus(int domain, device_t dev, int *rid,
158 rman_res_t start, rman_res_t end, rman_res_t count, u_int flags);
159int pci_domain_adjust_bus(int domain, device_t dev,
160 struct resource *r, rman_res_t start, rman_res_t end);
161int pci_domain_release_bus(int domain, device_t dev, int rid,
162 struct resource *r);
163struct resource *pcib_alloc_subbus(struct pcib_secbus *bus, device_t child,
164 int *rid, rman_res_t start, rman_res_t end, rman_res_t count,
165 u_int flags);
166void pcib_free_secbus(device_t dev, struct pcib_secbus *bus);
167void pcib_setup_secbus(device_t dev, struct pcib_secbus *bus,
168 int min_count);
169#endif
170int pcib_attach(device_t dev);
171int pcib_attach_child(device_t dev);
172void pcib_attach_common(device_t dev);
173void pcib_bridge_init(device_t dev);
174#ifdef NEW_PCIB
175const char *pcib_child_name(device_t child);
176#endif
177int pcib_child_present(device_t dev, device_t child);
178int pcib_detach(device_t dev);
179int pcib_read_ivar(device_t dev, device_t child, int which, uintptr_t *result);
180int pcib_write_ivar(device_t dev, device_t child, int which, uintptr_t value);
181struct resource *pcib_alloc_resource(device_t dev, device_t child, int type, int *rid,
182 rman_res_t start, rman_res_t end,
183 rman_res_t count, u_int flags);
184#ifdef NEW_PCIB
185int pcib_adjust_resource(device_t bus, device_t child, int type,
186 struct resource *r, rman_res_t start, rman_res_t end);
187int pcib_release_resource(device_t dev, device_t child, int type, int rid,
188 struct resource *r);
189#endif
190int pcib_maxslots(device_t dev);
191int pcib_maxfuncs(device_t dev);
192int pcib_route_interrupt(device_t pcib, device_t dev, int pin);
193int pcib_alloc_msi(device_t pcib, device_t dev, int count, int maxcount, int *irqs);
194int pcib_release_msi(device_t pcib, device_t dev, int count, int *irqs);
195int pcib_alloc_msix(device_t pcib, device_t dev, int *irq);
196int pcib_release_msix(device_t pcib, device_t dev, int irq);
197int pcib_map_msi(device_t pcib, device_t dev, int irq, uint64_t *addr, uint32_t *data);
198int pcib_get_id(device_t pcib, device_t dev, enum pci_id_type type,
199 uintptr_t *id);
200void pcib_decode_rid(device_t pcib, uint16_t rid, int *bus,
201 int *slot, int *func);
202int pcib_request_feature(device_t dev, enum pci_feature feature);
203int pcib_request_feature_allow(device_t pcib, device_t dev, enum pci_feature feature);
204
205#endif
u_int reg
Definition: pci_dw_if.m:42
int width
Definition: pci_dw_if.m:43
bool start
Definition: pci_dw_if.m:64
uint32_t value
Definition: pci_dw_if.m:55
pci_feature
Definition: pci_if.m:64
uint16_t data
Definition: pci_if.m:198
METHOD u_int32_t read_config
Definition: pci_if.m:71
device_t child
Definition: pci_if.m:73
enum pci_id_type type
Definition: pci_if.m:249
uint16_t rid
Definition: pci_if.m:278
const char * name
Definition: pci_if.m:267
int * count
Definition: pci_if.m:185
pci_id_type
Definition: pci_if.m:59
u_int func
Definition: pcib_if.m:81
int * irqs
Definition: pcib_if.m:125
u_int bus
Definition: pcib_if.m:79
int maxcount
Definition: pcib_if.m:124
device_t dev
Definition: pcib_if.m:109
uint64_t * addr
Definition: pcib_if.m:165
enum pci_feature feature
Definition: pcib_if.m:222
INTERFACE pcib
Definition: pcib_if.m:34
u_int slot
Definition: pcib_if.m:80
int * irq
Definition: pcib_if.m:145
int pin
Definition: pcib_if.m:110
int host_pcib_get_busno(pci_read_config_fn read_config, int bus, int slot, int func, uint8_t *busnum)
Definition: pci_subr.c:53
int pcib_maxslots(device_t dev)
Definition: pci_pci.c:2629
void pcib_bridge_init(device_t dev)
Definition: pci_pci.c:1818
void pcib_attach_common(device_t dev)
Definition: pci_pci.c:1537
int pcib_child_present(device_t dev, device_t child)
Definition: pci_pci.c:1833
int pcib_attach(device_t dev)
Definition: pci_pci.c:1755
uint32_t pci_read_config_fn(int b, int s, int f, int reg, int width)
Definition: pcib_private.h:152
DECLARE_CLASS(pcib_driver)
int pcib_alloc_msix(device_t pcib, device_t dev, int *irq)
Definition: pci_pci.c:2797
int pcib_release_msix(device_t pcib, device_t dev, int irq)
Definition: pci_pci.c:2810
int pcib_alloc_msi(device_t pcib, device_t dev, int count, int maxcount, int *irqs)
Definition: pci_pci.c:2773
int pcib_release_msi(device_t pcib, device_t dev, int count, int *irqs)
Definition: pci_pci.c:2787
struct resource * pcib_alloc_resource(device_t dev, device_t child, int type, int *rid, rman_res_t start, rman_res_t end, rman_res_t count, u_int flags)
Definition: pci_pci.c:2439
int pcib_route_interrupt(device_t pcib, device_t dev, int pin)
Definition: pci_pci.c:2739
int pcib_request_feature_allow(device_t pcib, device_t dev, enum pci_feature feature)
Definition: pci_pci.c:2944
void pcib_decode_rid(device_t pcib, uint16_t rid, int *bus, int *slot, int *func)
Definition: pcib_support.c:74
int pcib_write_ivar(device_t dev, device_t child, int which, uintptr_t value)
Definition: pci_pci.c:1865
int pcib_maxfuncs(device_t dev)
Definition: pcib_support.c:52
int pcib_attach_child(device_t dev)
Definition: pci_pci.c:1733
int pcib_map_msi(device_t pcib, device_t dev, int irq, uint64_t *addr, uint32_t *data)
Definition: pci_pci.c:2820
int pcib_read_ivar(device_t dev, device_t child, int which, uintptr_t *result)
Definition: pci_pci.c:1849
int pcib_get_id(device_t pcib, device_t dev, enum pci_id_type type, uintptr_t *id)
Definition: pcib_support.c:58
int pcib_request_feature(device_t dev, enum pci_feature feature)
Definition: pci_pci.c:2963
int pcib_detach(device_t dev)
Definition: pci_pci.c:1763
uint64_t pci_addr_t
Definition: pcivar.h:42
struct timeout_task pcie_dll_task
Definition: pcib_private.h:142
pci_addr_t memlimit
Definition: pcib_private.h:129
struct pcib_secbus bus
Definition: pcib_private.h:120
uint16_t bridgectl
Definition: pcib_private.h:133
struct resource * pcie_irq
Definition: pcib_private.h:137
uint32_t flags
Definition: pcib_private.h:109
pci_addr_t membase
Definition: pcib_private.h:128
struct mtx * pcie_hp_lock
Definition: pcib_private.h:143
uint32_t iolimit
Definition: pcib_private.h:131
uint16_t pcie_link_sta
Definition: pcib_private.h:134
uint32_t iobase
Definition: pcib_private.h:130
pci_addr_t pmembase
Definition: pcib_private.h:126
struct timeout_task pcie_cc_task
Definition: pcib_private.h:141
device_t dev
Definition: pcib_private.h:107
pci_addr_t pmemlimit
Definition: pcib_private.h:127
struct timeout_task pcie_ab_task
Definition: pcib_private.h:140
device_t child
Definition: pcib_private.h:108
u_int pribus
Definition: pcib_private.h:119
uint32_t pcie_slot_cap
Definition: pcib_private.h:136
struct task pcie_hp_task
Definition: pcib_private.h:139
u_int domain
Definition: pcib_private.h:118
uint16_t pcie_slot_sta
Definition: pcib_private.h:135
void * pcie_ihand
Definition: pcib_private.h:138