1 /* $OpenBSD: pci_machdep.h,v 1.2 2010/02/05 20:53:26 miod Exp $ */
4 * Copyright (c) 2003-2004 Opsycon AB (www.opsycon.se / www.opsycon.com)
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
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.
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
28 #include <sys/systm.h>
30 typedef struct mips_pci_chipset *pci_chipset_tag_t;
31 typedef u_long pcitag_t;
32 typedef u_long pci_intr_handle_t;
34 struct pci_attach_args;
37 * mips-specific PCI structure and type definitions.
38 * NOT TO BE USED DIRECTLY BY MACHINE INDEPENDENT CODE.
40 struct mips_pci_chipset {
42 void (*pc_attach_hook)(struct device *,
43 struct device *, struct pcibus_attach_args *);
44 int (*pc_bus_maxdevs)(void *, int);
45 pcitag_t (*pc_make_tag)(void *, int, int, int);
46 void (*pc_decompose_tag)(void *, pcitag_t, int *,
48 pcireg_t (*pc_conf_read)(void *, pcitag_t, int);
49 void (*pc_conf_write)(void *, pcitag_t, int, pcireg_t);
52 int (*pc_intr_map)(struct pci_attach_args *, pci_intr_handle_t *);
53 const char *(*pc_intr_string)(void *, pci_intr_handle_t);
54 void *(*pc_intr_establish)(void *, pci_intr_handle_t,
55 int, int (*)(void *), void *, char *);
56 void (*pc_intr_disestablish)(void *, void *);
60 * Functions provided to machine-independent PCI code.
62 //#define DEBUG_PCI_CONF
64 #define pci_attach_hook(p, s, pba) \
65 (*(pba)->pba_pc->pc_attach_hook)((p), (s), (pba))
66 #define pci_bus_maxdevs(c, b) \
67 (*(c)->pc_bus_maxdevs)((c)->pc_conf_v, (b))
68 #define pci_make_tag(c, b, d, f) \
69 (*(c)->pc_make_tag)((c)->pc_conf_v, (b), (d), (f))
70 #define pci_decompose_tag(c, t, bp, dp, fp) \
71 (*(c)->pc_decompose_tag)((c)->pc_conf_v, (t), (bp), (dp), (fp))
74 static inline pcireg_t pci_conf_read_db(void * c, pcitag_t t, int r,
75 char* f,char* func,int l)
78 struct mips_pci_chipset *pc = c;
79 v = (*(pc)->pc_conf_read)(pc->pc_conf_v, t, r);
80 printf("%s:%s:%d:pci_conf_read(%x,%x) = %x\n",f,func,l,t,r,v);
84 static inline void pci_conf_write_db(void * c, pcitag_t t, int r, pcireg_t v,
85 char* f,char* func,int l)
87 struct mips_pci_chipset *pc = c;
88 printf("%s:%s:%d:pci_conf_write(%x,%x,%x)\n",f,func,l,t,r,v);
89 (*(pc)->pc_conf_write)(pc->pc_conf_v, t, r, v);
93 #define pci_conf_read(c, t, r) pci_conf_read_db(c, t, r,__FILE__,__FUNCTION__,__LINE__)
94 #define pci_conf_write(c, t, r, v) pci_conf_write_db(c, t, r, v,__FILE__,__FUNCTION__,__LINE__)
96 #define pci_conf_read(c, t, r) \
97 (*(c)->pc_conf_read)((c)->pc_conf_v, (t), (r))
98 #define pci_conf_write(c, t, r, v) \
99 (*(c)->pc_conf_write)((c)->pc_conf_v, (t), (r), (v))
101 #define pci_intr_map(c, ihp) \
102 (*(c)->pa_pc->pc_intr_map)((c), (ihp))
103 #define pci_intr_string(c, ih) \
104 (*(c)->pc_intr_string)((c)->pc_intr_v, (ih))
105 #define pci_intr_establish(c, ih, l, h, a, nm) \
106 (*(c)->pc_intr_establish)((c)->pc_intr_v, (ih), (l), (h), (a), (nm))
107 #define pci_intr_disestablish(c, iv) \
108 (*(c)->pc_intr_disestablish)((c)->pc_intr_v, (iv))
110 /* PCI view of CPU memory */
111 extern paddr_t loongson_dma_base;
114 * Functions used during early system configuration.
117 pcitag_t pci_make_tag_early(int, int, int);
118 pcireg_t pci_conf_read_early(pcitag_t, int);