xref: /netbsd-src/sys/arch/amiga/include/pci_machdep.h (revision e58a356cba5da26ec5dfa3e7b91db913ffb59130)
1 /*	$NetBSD: pci_machdep.h,v 1.8 2014/03/29 19:28:26 christos 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 #define __HAVE_PCI_CONF_HOOK
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 extern struct m68k_bus_dma_tag pci_bus_dma_tag;
54 
55 /*
56  * amiga-specific PCI structure and type definitions.
57  * NOT TO BE USED DIRECTLY BY MACHINE INDEPENDENT CODE.
58  */
59 struct amiga_pci_chipset {
60 	void		*pc_conf_v;
61 	void		(*pc_attach_hook)(device_t, device_t,
62 			    struct pcibus_attach_args *);
63 	int		(*pc_bus_maxdevs)(pci_chipset_tag_t, int);
64 	pcitag_t	(*pc_make_tag)(pci_chipset_tag_t, int, int, int);
65 	void		(*pc_decompose_tag)(pci_chipset_tag_t, pcitag_t, int *,
66 			    int *, int *);
67 			pcireg_t(*pc_conf_read)(pci_chipset_tag_t, pcitag_t,
68 			    int);
69 	void		(*pc_conf_write)(pci_chipset_tag_t, pcitag_t, int,
70 			    pcireg_t);
71 	int		(*pc_conf_hook)(pci_chipset_tag_t, int, int, int,
72 			    pcireg_t);
73 	void		*pc_intr_v;
74 	int		(*pc_intr_map)(const struct pci_attach_args *,
75 			    pci_intr_handle_t *);
76 	const char	*(*pc_intr_string)(pci_chipset_tag_t,
77 			    pci_intr_handle_t, char *, size_t);
78 	void		*(*pc_intr_establish)(pci_chipset_tag_t,
79 			    pci_intr_handle_t, int, int (*) (void *), void *);
80 	void		(*pc_intr_disestablish)(pci_chipset_tag_t, void *);
81 	void		(*pc_conf_interrupt)(pci_chipset_tag_t, int, int, int,
82 			    int, int *);
83 
84 	/* PCI configuration address register */
85 	bus_space_tag_t pci_conf_addresst;
86 	bus_space_handle_t pci_conf_addressh;
87 
88 	/* PCI configuration data register */
89 	bus_space_tag_t pci_conf_datat;
90 	bus_space_handle_t pci_conf_datah;
91 
92 	void		*cookie; /* used in some implementations */
93 };
94 
95 
96 /*
97  * Functions provided to machine-independent PCI code.
98  */
99 #define	pci_attach_hook(p, s, pba)					\
100 	(*(pba)->pba_pc->pc_attach_hook)((p), (s), (pba))
101 #define	pci_bus_maxdevs(c, b)						\
102 	(*(c)->pc_bus_maxdevs)((c)->pc_conf_v, (b))
103 #define	pci_make_tag(c, b, d, f)					\
104 	(*(c)->pc_make_tag)((c)->pc_conf_v, (b), (d), (f))
105 #define	pci_decompose_tag(c, t, bp, dp, fp)				\
106 	(*(c)->pc_decompose_tag)((c)->pc_conf_v, (t), (bp), (dp), (fp))
107 #define	pci_conf_read(c, t, r)						\
108 	(*(c)->pc_conf_read)((c)->pc_conf_v, (t), (r))
109 #define	pci_conf_write(c, t, r, v)					\
110 	(*(c)->pc_conf_write)((c)->pc_conf_v, (t), (r), (v))
111 #define	pci_intr_map(pa, ihp)						\
112 	(*(pa)->pa_pc->pc_intr_map)((pa), (ihp))
113 #define	pci_intr_string(c, ih, buf, len)				\
114 	(*(c)->pc_intr_string)((c)->pc_intr_v, (ih), (buf), (len))
115 #define	pci_intr_evcnt(c, ih)						\
116 	(*(c)->pc_intr_evcnt)((c)->pc_intr_v, (ih))
117 #define	pci_intr_establish(c, ih, l, h, a)				\
118 	(*(c)->pc_intr_establish)((c)->pc_intr_v, (ih), (l), (h), (a))
119 #define	pci_intr_disestablish(c, iv)					\
120 	(*(c)->pc_intr_disestablish)((c)->pc_intr_v, (iv))
121 #define	pci_conf_interrupt(c, b, d, f, s, i)				\
122 	(*(c)->pc_conf_interrupt)((c), (b), (d), (f), (s), (i))
123 #define	pci_conf_hook(c, b, d, f, i)				\
124 	(*(c)->pc_conf_hook)((c), (b), (d), (f), (i))
125 
126 #endif
127 
128 pcitag_t	amiga_pci_make_tag(pci_chipset_tag_t pc, int bus, int device,
129 		    int function);
130 void		amiga_pci_decompose_tag(pci_chipset_tag_t pc, pcitag_t tag,
131 		    int *bp, int *dp, int *fp);
132 void *		amiga_pci_intr_establish(pci_chipset_tag_t pc, pci_intr_handle_t
133 		    ih, int level, int (*ih_fun)(void *), void *ih_arg);
134 void		amiga_pci_intr_disestablish(pci_chipset_tag_t pc, void *cookie);
135 const char *	amiga_pci_intr_string(pci_chipset_tag_t pc,
136 		    pci_intr_handle_t ih, char *, size_t);
137 int		amiga_pci_conf_hook(pci_chipset_tag_t pct, int bus, int dev,
138 		    int func, pcireg_t id);
139 void		amiga_pci_conf_interrupt(pci_chipset_tag_t pc, int bus,
140 		    int dev, int func, int swiz, int *iline);
141 
142