xref: /netbsd-src/sys/arch/amiga/include/pci_machdep.h (revision a5847cc334d9a7029f6352b847e9e8d71a0f9e0c)
1 /*	$NetBSD: pci_machdep.h,v 1.3 2011/09/19 19:15:29 rkujawa Exp $ */
2 
3 /*-
4  * Copyright (c) 2011 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to The NetBSD Foundation
8  * by Radoslaw Kujawa.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 #ifndef _AMIGA_PCI_MACHDEP_H_
33 #define _AMIGA_PCI_MACHDEP_H_
34 
35 #include <sys/bus.h>
36 
37 #include <machine/intr.h>
38 
39 #include <m68k/bus_dma.h>
40 
41 /*
42  * Forward declarations.
43  */
44 struct pci_attach_args;
45 
46 /*
47  * Types provided to machine-independent PCI code
48  */
49 typedef struct	amiga_pci_chipset *pci_chipset_tag_t;
50 typedef u_long	pcitag_t;
51 typedef u_long	pci_intr_handle_t;
52 
53 /*
54  * amiga-specific PCI structure and type definitions.
55  * NOT TO BE USED DIRECTLY BY MACHINE INDEPENDENT CODE.
56  */
57 struct amiga_pci_chipset {
58 	void		*pc_conf_v;
59 	void		(*pc_attach_hook)(device_t, device_t,
60 			    struct pcibus_attach_args *);
61 	int		(*pc_bus_maxdevs)(pci_chipset_tag_t, int);
62 	pcitag_t	(*pc_make_tag)(pci_chipset_tag_t, int, int, int);
63 	void		(*pc_decompose_tag)(pci_chipset_tag_t, pcitag_t, int *,
64 			    int *, int *);
65 			pcireg_t(*pc_conf_read)(pci_chipset_tag_t, pcitag_t,
66 			    int);
67 	void		(*pc_conf_write)(pci_chipset_tag_t, pcitag_t, int,
68 			    pcireg_t);
69 	int		(*pc_conf_hook)(pci_chipset_tag_t, int, int, int,
70 			    pcireg_t);
71 	void		*pc_intr_v;
72 	int		(*pc_intr_map)(const struct pci_attach_args *,
73 			    pci_intr_handle_t *);
74 	const char	*(*pc_intr_string)(pci_chipset_tag_t,
75 			    pci_intr_handle_t);
76 	void		*(*pc_intr_establish)(pci_chipset_tag_t,
77 			    pci_intr_handle_t, int, int (*) (void *), void *);
78 	void		(*pc_intr_disestablish)(pci_chipset_tag_t, void *);
79 	void		(*pc_conf_interrupt)(pci_chipset_tag_t, int, int, int,
80 			    int, int *);
81 
82 	/* PCI configuration address register */
83 	bus_space_tag_t pci_conf_addresst;
84 	bus_space_handle_t pci_conf_addressh;
85 
86 	/* PCI configuration data register */
87 	bus_space_tag_t pci_conf_datat;
88 	bus_space_handle_t pci_conf_datah;
89 };
90 
91 
92 /*
93  * Functions provided to machine-independent PCI code.
94  */
95 #define	pci_attach_hook(p, s, pba)					\
96 	(*(pba)->pba_pc->pc_attach_hook)((p), (s), (pba))
97 #define	pci_bus_maxdevs(c, b)						\
98 	(*(c)->pc_bus_maxdevs)((c)->pc_conf_v, (b))
99 #define	pci_make_tag(c, b, d, f)					\
100 	(*(c)->pc_make_tag)((c)->pc_conf_v, (b), (d), (f))
101 #define	pci_decompose_tag(c, t, bp, dp, fp)				\
102 	(*(c)->pc_decompose_tag)((c)->pc_conf_v, (t), (bp), (dp), (fp))
103 #define	pci_conf_read(c, t, r)						\
104 	(*(c)->pc_conf_read)((c)->pc_conf_v, (t), (r))
105 #define	pci_conf_write(c, t, r, v)					\
106 	(*(c)->pc_conf_write)((c)->pc_conf_v, (t), (r), (v))
107 #define	pci_intr_map(pa, ihp)						\
108 	(*(pa)->pa_pc->pc_intr_map)((pa), (ihp))
109 #define	pci_intr_string(c, ih)						\
110 	(*(c)->pc_intr_string)((c)->pc_intr_v, (ih))
111 #define	pci_intr_evcnt(c, ih)						\
112 	(*(c)->pc_intr_evcnt)((c)->pc_intr_v, (ih))
113 #define	pci_intr_establish(c, ih, l, h, a)				\
114 	(*(c)->pc_intr_establish)((c)->pc_intr_v, (ih), (l), (h), (a))
115 #define	pci_intr_disestablish(c, iv)					\
116 	(*(c)->pc_intr_disestablish)((c)->pc_intr_v, (iv))
117 #define	pci_conf_interrupt(c, b, d, f, s, i)				\
118 	(*(c)->pc_conf_interrupt)((c), (b), (d), (f), (s), (i))
119 #define	pci_conf_hook(c, b, d, f, i)				\
120 	(*(c)->pc_conf_hook)((c), (b), (d), (f), (i))
121 
122 #endif
123 
124 pcitag_t	amiga_pci_make_tag(pci_chipset_tag_t pc, int bus, int device,
125 		    int function);
126 void		amiga_pci_decompose_tag(pci_chipset_tag_t pc, pcitag_t tag,
127 		    int *bp, int *dp, int *fp);
128 void *		amiga_pci_intr_establish(pci_chipset_tag_t pc, pci_intr_handle_t
129 		    ih, int level, int (*ih_fun)(void *), void *ih_arg);
130 void		amiga_pci_intr_disestablish(pci_chipset_tag_t pc, void *cookie);
131 const char *	amiga_pci_intr_string(pci_chipset_tag_t pc,
132 		    pci_intr_handle_t ih);
133 int		amiga_pci_conf_hook(pci_chipset_tag_t pct, int bus, int dev,
134 		    int func, pcireg_t id);
135 void		amiga_pci_conf_interrupt(pci_chipset_tag_t pc, int bus,
136 		    int dev, int func, int swiz, int *iline);
137 
138