pcmciachip.h revision 1.7 1 /* $NetBSD: pcmciachip.h,v 1.7 2004/06/20 18:09:46 thorpej Exp $ */
2
3 /*
4 * Copyright (c) 1997 Marc Horowitz. All rights reserved.
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 * 3. All advertising materials mentioning features or use of this software
15 * must display the following acknowledgement:
16 * This product includes software developed by Marc Horowitz.
17 * 4. The name of the author may not be used to endorse or promote products
18 * derived from this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */
31
32 #ifndef _PCMCIA_PCMCIACHIP_H_
33 #define _PCMCIA_PCMCIACHIP_H_
34
35 #include <machine/bus.h>
36 #ifdef _KERNEL_OPT
37 #include "locators.h"
38 #endif
39
40 struct pcmcia_function;
41 struct pcmcia_mem_handle;
42 struct pcmcia_io_handle;
43
44 /* interfaces for pcmcia to call the chipset */
45
46 typedef struct pcmcia_chip_functions *pcmcia_chipset_tag_t;
47 typedef void *pcmcia_chipset_handle_t;
48 typedef int pcmcia_mem_handle_t;
49
50 #define PCMCIA_MEM_ATTR 1
51 #define PCMCIA_MEM_COMMON 2
52
53 #define PCMCIA_WIDTH_MEM8 8
54 #define PCMCIA_WIDTH_MEM16 16
55
56 #define PCMCIA_WIDTH_MEM_MASK 24
57
58 #define PCMCIA_WIDTH_AUTO 0
59 #define PCMCIA_WIDTH_IO8 1
60 #define PCMCIA_WIDTH_IO16 2
61
62 struct pcmcia_chip_functions {
63 /* memory space allocation */
64 int (*mem_alloc) __P((pcmcia_chipset_handle_t, bus_size_t,
65 struct pcmcia_mem_handle *));
66 void (*mem_free) __P((pcmcia_chipset_handle_t,
67 struct pcmcia_mem_handle *));
68
69 /* memory space window mapping */
70 int (*mem_map) __P((pcmcia_chipset_handle_t, int, bus_addr_t,
71 bus_size_t, struct pcmcia_mem_handle *,
72 bus_size_t *, int *));
73 void (*mem_unmap) __P((pcmcia_chipset_handle_t, int));
74
75 /* I/O space allocation */
76 int (*io_alloc) __P((pcmcia_chipset_handle_t, bus_addr_t,
77 bus_size_t, bus_size_t, struct pcmcia_io_handle *));
78 void (*io_free) __P((pcmcia_chipset_handle_t,
79 struct pcmcia_io_handle *));
80
81 /* I/O space window mapping */
82 int (*io_map) __P((pcmcia_chipset_handle_t, int, bus_addr_t,
83 bus_size_t, struct pcmcia_io_handle *, int *));
84 void (*io_unmap) __P((pcmcia_chipset_handle_t, int));
85
86 /* interrupt glue */
87 void *(*intr_establish) __P((pcmcia_chipset_handle_t,
88 struct pcmcia_function *, int, int (*)(void *), void *));
89 void (*intr_disestablish) __P((pcmcia_chipset_handle_t, void *));
90
91 /* card enable/disable */
92 void (*socket_enable) __P((pcmcia_chipset_handle_t));
93 void (*socket_disable) __P((pcmcia_chipset_handle_t));
94
95 /* card detection */
96 int (*card_detect) __P((pcmcia_chipset_handle_t));
97 };
98
99 /* Memory space functions. */
100 #define pcmcia_chip_mem_alloc(tag, handle, size, pcmhp) \
101 ((*(tag)->mem_alloc)((handle), (size), (pcmhp)))
102
103 #define pcmcia_chip_mem_free(tag, handle, pcmhp) \
104 ((*(tag)->mem_free)((handle), (pcmhp)))
105
106 #define pcmcia_chip_mem_map(tag, handle, kind, card_addr, size, pcmhp, \
107 offsetp, windowp) \
108 ((*(tag)->mem_map)((handle), (kind), (card_addr), (size), (pcmhp), \
109 (offsetp), (windowp)))
110
111 #define pcmcia_chip_mem_unmap(tag, handle, window) \
112 ((*(tag)->mem_unmap)((handle), (window)))
113
114 /* I/O space functions. */
115 #define pcmcia_chip_io_alloc(tag, handle, start, size, align, pcihp) \
116 ((*(tag)->io_alloc)((handle), (start), (size), (align), (pcihp)))
117
118 #define pcmcia_chip_io_free(tag, handle, pcihp) \
119 ((*(tag)->io_free)((handle), (pcihp)))
120
121 #define pcmcia_chip_io_map(tag, handle, width, card_addr, size, pcihp, \
122 windowp) \
123 ((*(tag)->io_map)((handle), (width), (card_addr), (size), (pcihp), \
124 (windowp)))
125
126 #define pcmcia_chip_io_unmap(tag, handle, window) \
127 ((*(tag)->io_unmap)((handle), (window)))
128
129 /* Interrupt functions. */
130 #define pcmcia_chip_intr_establish(tag, handle, pf, ipl, fct, arg) \
131 ((*(tag)->intr_establish)((handle), (pf), (ipl), (fct), (arg)))
132
133 #define pcmcia_chip_intr_disestablish(tag, handle, ih) \
134 ((*(tag)->intr_disestablish)((handle), (ih)))
135
136 /* Socket functions. */
137 #define pcmcia_chip_socket_enable(tag, handle) \
138 ((*(tag)->socket_enable)((handle)))
139 #define pcmcia_chip_socket_disable(tag, handle) \
140 ((*(tag)->socket_disable)((handle)))
141
142 struct pcmciabus_attach_args {
143 char *paa_busname; /* Bus name */
144 pcmcia_chipset_tag_t pct;
145 pcmcia_chipset_handle_t pch;
146 bus_addr_t iobase; /* start i/o space allocation here */
147 bus_size_t iosize; /* size of the i/o space range */
148 };
149
150 #define pcmciabuscf_controller cf_loc[PCMCIABUSCF_CONTROLLER]
151 #define pcmciabuscf_socket cf_loc[PCMCIABUSCF_SOCKET]
152
153 /* interfaces for the chipset to call pcmcia */
154
155 int pcmcia_card_attach __P((struct device *));
156 void pcmcia_card_detach __P((struct device *, int));
157 void pcmcia_card_deactivate __P((struct device *));
158 int pcmcia_card_gettype __P((struct device *));
159
160 #endif /* _PCMCIA_PCMCIACHIP_H_ */
161