1 #include <sys/cdefs.h>
2 __KERNEL_RCSID(0, "$NetBSD: pci_stub.c,v 1.8 2018/06/24 11:51:15 jdolecek Exp $");
3
4 #ifdef _KERNEL_OPT
5 #include "opt_pci.h"
6 #endif
7
8 #include <sys/param.h>
9 #include <sys/systm.h>
10 #include <sys/kmem.h>
11
12 #include <dev/pci/pcireg.h>
13 #include <dev/pci/pcivar.h>
14 #include <dev/pci/pcidevs.h>
15
16 int default_pci_bus_devorder(pci_chipset_tag_t, int, uint8_t *, int);
17 int default_pci_chipset_tag_create(pci_chipset_tag_t, uint64_t,
18 const struct pci_overrides *, void *, pci_chipset_tag_t *);
19 void default_pci_chipset_tag_destroy(pci_chipset_tag_t);
20 void *default_pci_intr_establish_xname(pci_chipset_tag_t, pci_intr_handle_t,
21 int, int (*)(void *), void *, const char *);
22
23 __strict_weak_alias(pci_bus_devorder, default_pci_bus_devorder);
24 __strict_weak_alias(pci_chipset_tag_create, default_pci_chipset_tag_create);
25 __strict_weak_alias(pci_chipset_tag_destroy, default_pci_chipset_tag_destroy);
26 __strict_weak_alias(pci_intr_establish_xname,
27 default_pci_intr_establish_xname);
28
29 int
default_pci_bus_devorder(pci_chipset_tag_t pc,int bus,uint8_t * devs,int maxdevs)30 default_pci_bus_devorder(pci_chipset_tag_t pc, int bus, uint8_t *devs,
31 int maxdevs)
32 {
33 int i, n;
34
35 n = MIN(pci_bus_maxdevs(pc, bus), maxdevs);
36 for (i = 0; i < n; i++)
37 devs[i] = i;
38
39 return n;
40 }
41
42 void
default_pci_chipset_tag_destroy(pci_chipset_tag_t pc)43 default_pci_chipset_tag_destroy(pci_chipset_tag_t pc)
44 {
45 }
46
47 int
default_pci_chipset_tag_create(pci_chipset_tag_t opc,const uint64_t present,const struct pci_overrides * ov,void * ctx,pci_chipset_tag_t * pcp)48 default_pci_chipset_tag_create(pci_chipset_tag_t opc, const uint64_t present,
49 const struct pci_overrides *ov, void *ctx, pci_chipset_tag_t *pcp)
50 {
51 return EOPNOTSUPP;
52 }
53
54 void *
default_pci_intr_establish_xname(pci_chipset_tag_t pc,pci_intr_handle_t ih,int level,int (* func)(void *),void * arg,const char * __nouse)55 default_pci_intr_establish_xname(pci_chipset_tag_t pc, pci_intr_handle_t ih,
56 int level, int (*func)(void *), void *arg, const char *__nouse)
57 {
58
59 return pci_intr_establish(pc, ih, level, func, arg);
60 }
61
62 #ifndef __HAVE_PCI_MSI_MSIX
63 pci_intr_type_t
pci_intr_type(pci_chipset_tag_t pc,pci_intr_handle_t ih)64 pci_intr_type(pci_chipset_tag_t pc, pci_intr_handle_t ih)
65 {
66
67 return PCI_INTR_TYPE_INTX;
68 }
69
70 int
pci_intr_alloc(const struct pci_attach_args * pa,pci_intr_handle_t ** ihps,int * counts,pci_intr_type_t max_type)71 pci_intr_alloc(const struct pci_attach_args *pa, pci_intr_handle_t **ihps,
72 int *counts, pci_intr_type_t max_type)
73 {
74
75 if (counts != NULL && counts[PCI_INTR_TYPE_INTX] == 0)
76 return EINVAL;
77
78 return pci_intx_alloc(pa, ihps);
79 }
80
81 void
pci_intr_release(pci_chipset_tag_t pc,pci_intr_handle_t * pih,int count)82 pci_intr_release(pci_chipset_tag_t pc, pci_intr_handle_t *pih, int count)
83 {
84
85 kmem_free(pih, sizeof(*pih));
86 }
87
88 int
pci_intx_alloc(const struct pci_attach_args * pa,pci_intr_handle_t ** ihp)89 pci_intx_alloc(const struct pci_attach_args *pa, pci_intr_handle_t **ihp)
90 {
91 pci_intr_handle_t *pih;
92
93 if (ihp == NULL)
94 return EINVAL;
95
96 pih = kmem_alloc(sizeof(*pih), KM_SLEEP);
97 if (pci_intr_map(pa, pih)) {
98 kmem_free(pih, sizeof(*pih));
99 return EINVAL;
100 }
101
102 *ihp = pih;
103 return 0;
104 }
105
106 int
pci_msi_alloc(const struct pci_attach_args * pa,pci_intr_handle_t ** ihps,int * count)107 pci_msi_alloc(const struct pci_attach_args *pa, pci_intr_handle_t **ihps,
108 int *count)
109 {
110
111 return EOPNOTSUPP;
112 }
113
114 int
pci_msi_alloc_exact(const struct pci_attach_args * pa,pci_intr_handle_t ** ihps,int count)115 pci_msi_alloc_exact(const struct pci_attach_args *pa, pci_intr_handle_t **ihps,
116 int count)
117 {
118
119 return EOPNOTSUPP;
120 }
121
122 int
pci_msix_alloc(const struct pci_attach_args * pa,pci_intr_handle_t ** ihps,int * count)123 pci_msix_alloc(const struct pci_attach_args *pa, pci_intr_handle_t **ihps,
124 int *count)
125 {
126
127 return EOPNOTSUPP;
128 }
129
130 int
pci_msix_alloc_exact(const struct pci_attach_args * pa,pci_intr_handle_t ** ihps,int count)131 pci_msix_alloc_exact(const struct pci_attach_args *pa, pci_intr_handle_t **ihps,
132 int count)
133 {
134
135 return EOPNOTSUPP;
136 }
137
138 int
pci_msix_alloc_map(const struct pci_attach_args * pa,pci_intr_handle_t ** ihps,u_int * table_indexes,int count)139 pci_msix_alloc_map(const struct pci_attach_args *pa, pci_intr_handle_t **ihps,
140 u_int *table_indexes, int count)
141 {
142
143 return EOPNOTSUPP;
144 }
145 #endif /* __HAVE_PCI_MSI_MSIX */
146