1 /* $OpenBSD: pci_machdep.h,v 1.13 2024/05/20 23:13:33 jsg Exp $ */
2
3 /*
4 * Copyright (c) 2003-2004 Opsycon AB (www.opsycon.se / www.opsycon.com)
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
16 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
19 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 * SUCH DAMAGE.
26 *
27 */
28 #include <sys/systm.h>
29
30 typedef struct mips_pci_chipset *pci_chipset_tag_t;
31
32 typedef u_int64_t pcitag_t;
33 #define PCITAG_NODE(x) ((x) >> 32)
34 #define PCITAG_OFFSET(x) ((x) & 0xffffffff)
35
36 typedef u_long pci_intr_handle_t;
37
38 struct pci_attach_args;
39
40 /*
41 * mips-specific PCI structure and type definitions.
42 * NOT TO BE USED DIRECTLY BY MACHINE INDEPENDENT CODE.
43 */
44 struct mips_pci_chipset {
45 void *pc_conf_v;
46 void (*pc_attach_hook)(struct device *,
47 struct device *, struct pcibus_attach_args *);
48 int (*pc_bus_maxdevs)(void *, int);
49 pcitag_t (*pc_make_tag)(void *, int, int, int);
50 void (*pc_decompose_tag)(void *, pcitag_t, int *,
51 int *, int *);
52 int (*pc_conf_size)(void *, pcitag_t);
53 pcireg_t (*pc_conf_read)(void *, pcitag_t, int);
54 void (*pc_conf_write)(void *, pcitag_t, int, pcireg_t);
55
56 void *pc_intr_v;
57 int (*pc_intr_map)(struct pci_attach_args *,
58 pci_intr_handle_t *);
59 const char *(*pc_intr_string)(void *, pci_intr_handle_t);
60 void *(*pc_intr_establish)(void *, pci_intr_handle_t,
61 int, int (*)(void *), void *, char *);
62 void (*pc_intr_disestablish)(void *, void *);
63 };
64
65 /*
66 * Functions provided to machine-independent PCI code.
67 */
68 //#define DEBUG_PCI_CONF
69
70 #define pci_attach_hook(p, s, pba) \
71 (*(pba)->pba_pc->pc_attach_hook)((p), (s), (pba))
72 #define pci_bus_maxdevs(c, b) \
73 (*(c)->pc_bus_maxdevs)((c)->pc_conf_v, (b))
74 #define pci_make_tag(c, b, d, f) \
75 (*(c)->pc_make_tag)((c)->pc_conf_v, (b), (d), (f))
76 #define pci_decompose_tag(c, t, bp, dp, fp) \
77 (*(c)->pc_decompose_tag)((c)->pc_conf_v, (t), (bp), (dp), (fp))
78
79 #define pci_conf_size(c, t) \
80 (*(c)->pc_conf_size)((c)->pc_conf_v, (t))
81
82 #ifdef DEBUG_PCI_CONF
83 static inline pcireg_t
pci_conf_read_db(void * cookie,pcitag_t tag,int reg,const char * file,const char * func,int line)84 pci_conf_read_db(void *cookie, pcitag_t tag, int reg,
85 const char *file, const char *func, int line)
86 {
87 struct mips_pci_chipset *pc = cookie;
88 pcireg_t val;
89
90 val = (*(pc)->pc_conf_read)(pc->pc_conf_v, tag, reg);
91 printf("%s:%s:%d:pci_conf_read(%llx,%x) = %x\n", file, func, line,
92 tag, reg, val);
93 return val;
94 }
95
96 static inline void
pci_conf_write_db(void * cookie,pcitag_t tag,int reg,pcireg_t val,const char * file,const char * func,int line)97 pci_conf_write_db(void *cookie, pcitag_t tag, int reg, pcireg_t val,
98 const char *file, const char *func, int line)
99 {
100 struct mips_pci_chipset *pc = cookie;
101
102 printf("%s:%s:%d:pci_conf_write(%llx,%x,%x)\n", file, func, line,
103 tag, reg, val);
104 (*(pc)->pc_conf_write)(pc->pc_conf_v, tag, reg, val);
105 }
106
107
108 #define pci_conf_read(c, t, r) \
109 pci_conf_read_db(c, t, r, __FILE__, __FUNCTION__, __LINE__)
110 #define pci_conf_write(c, t, r, v) \
111 pci_conf_write_db(c, t, r, v, __FILE__, __FUNCTION__, __LINE__)
112 #else
113 #define pci_conf_read(c, t, r) \
114 (*(c)->pc_conf_read)((c)->pc_conf_v, (t), (r))
115 #define pci_conf_write(c, t, r, v) \
116 (*(c)->pc_conf_write)((c)->pc_conf_v, (t), (r), (v))
117 #endif
118 #define pci_intr_map(c, ihp) \
119 (*(c)->pa_pc->pc_intr_map)((c), (ihp))
120 #define pci_intr_map_msi(c, ihp) (-1)
121 #define pci_intr_map_msix(c, vec, ihp) (-1)
122 #define pci_intr_string(c, ih) \
123 (*(c)->pc_intr_string)((c)->pc_intr_v, (ih))
124 #define pci_intr_establish(c, ih, l, h, a, nm) \
125 (*(c)->pc_intr_establish)((c)->pc_intr_v, (ih), (l), (h), (a), (nm))
126 #define pci_intr_disestablish(c, iv) \
127 (*(c)->pc_intr_disestablish)((c)->pc_intr_v, (iv))
128 #define pci_probe_device_hook(c, a) (0)
129
130 #define pci_min_powerstate(c, t) (PCI_PMCSR_STATE_D3)
131 #define pci_set_powerstate_md(c, t, s, p)
132
133 #define pci_dev_postattach(a, b)
134