1/* $NetBSD: pcmciachip.h,v 1.17 2011/07/26 22:24:36 dyoung 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 <sys/bus.h>
36
37struct pcmcia_function;
38struct pcmcia_mem_handle;
39struct pcmcia_io_handle;
40
41/* interfaces for pcmcia to call the chipset */
42
43typedef const struct pcmcia_chip_functions *pcmcia_chipset_tag_t;
44typedef void *pcmcia_chipset_handle_t;
45typedef int pcmcia_mem_handle_t;
46
47#define PCMCIA_MEM_ATTR 1
48#define PCMCIA_MEM_COMMON 2
49
50#define PCMCIA_WIDTH_MEM8 8
51#define PCMCIA_WIDTH_MEM16 16
52
53#define PCMCIA_WIDTH_MEM_MASK 24
54
55#define PCMCIA_WIDTH_AUTO 0
56#define PCMCIA_WIDTH_IO8 1
57#define PCMCIA_WIDTH_IO16 2
58
59struct pcmcia_chip_functions {
60 /* memory space allocation */
61 int (*mem_alloc)(pcmcia_chipset_handle_t, bus_size_t,
62 struct pcmcia_mem_handle *);
63 void (*mem_free)(pcmcia_chipset_handle_t,
64 struct pcmcia_mem_handle *);
65
66 /* memory space window mapping */
67 int (*mem_map)(pcmcia_chipset_handle_t, int, bus_addr_t,
68 bus_size_t, struct pcmcia_mem_handle *,
69 bus_size_t *, int *);
70 void (*mem_unmap)(pcmcia_chipset_handle_t, int);
71
72 /* I/O space allocation */
73 int (*io_alloc)(pcmcia_chipset_handle_t, bus_addr_t,
74 bus_size_t, bus_size_t, struct pcmcia_io_handle *);
75 void (*io_free)(pcmcia_chipset_handle_t,
76 struct pcmcia_io_handle *);
77
78 /* I/O space window mapping */
79 int (*io_map)(pcmcia_chipset_handle_t, int, bus_addr_t,
80 bus_size_t, struct pcmcia_io_handle *, int *);
81 void (*io_unmap)(pcmcia_chipset_handle_t, int);
82
83 /* interrupt glue */
84 void *(*intr_establish)(pcmcia_chipset_handle_t,
85 struct pcmcia_function *, int, int (*)(void *), void *);
86 void (*intr_disestablish)(pcmcia_chipset_handle_t, void *);
87
88 /* card enable/disable */
89 void (*socket_enable)(pcmcia_chipset_handle_t);
90 void (*socket_disable)(pcmcia_chipset_handle_t);
91 void (*socket_settype)(pcmcia_chipset_handle_t, int);
92
93 /* card detection */
94 int (*card_detect)(pcmcia_chipset_handle_t);
95};
96
97/* Memory space functions. */
98#define pcmcia_chip_mem_alloc(tag, handle, size, pcmhp) \
99 ((*(tag)->mem_alloc)((handle), (size), (pcmhp)))
100
101#define pcmcia_chip_mem_free(tag, handle, pcmhp) \
102 ((*(tag)->mem_free)((handle), (pcmhp)))
103
104#define pcmcia_chip_mem_map(tag, handle, kind, card_addr, size, pcmhp, \
105 offsetp, windowp) \
106 ((*(tag)->mem_map)((handle), (kind), (card_addr), (size), (pcmhp), \
107 (offsetp), (windowp)))
108
109#define pcmcia_chip_mem_unmap(tag, handle, window) \
110 ((*(tag)->mem_unmap)((handle), (window)))
111
112/* I/O space functions. */
113#define pcmcia_chip_io_alloc(tag, handle, start, size, align, pcihp) \
114 ((*(tag)->io_alloc)((handle), (start), (size), (align), (pcihp)))
115
116#define pcmcia_chip_io_free(tag, handle, pcihp) \
117 ((*(tag)->io_free)((handle), (pcihp)))
118
119#define pcmcia_chip_io_map(tag, handle, width, card_addr, size, pcihp, \
120 windowp) \
121 ((*(tag)->io_map)((handle), (width), (card_addr), (size), (pcihp), \
122 (windowp)))
123
124#define pcmcia_chip_io_unmap(tag, handle, window) \
125 ((*(tag)->io_unmap)((handle), (window)))
126
127/* Interrupt functions. */
128#define pcmcia_chip_intr_establish(tag, handle, pf, ipl, fct, arg) \
129 ((*(tag)->intr_establish)((handle), (pf), (ipl), (fct), (arg)))
130
131#define pcmcia_chip_intr_disestablish(tag, handle, ih) \
132 ((*(tag)->intr_disestablish)((handle), (ih)))
133
134/* Socket functions. */
135#define pcmcia_chip_socket_enable(tag, handle) \
136 ((*(tag)->socket_enable)((handle)))
137#define pcmcia_chip_socket_disable(tag, handle) \
138 ((*(tag)->socket_disable)((handle)))
139#define pcmcia_chip_socket_settype(tag, handle, type) \
140 ((*(tag)->socket_settype)((handle), (type)))
141
142struct pcmciabus_attach_args {
143 const char *paa_busname; /* Bus name */
144 pcmcia_chipset_tag_t pct;
145 pcmcia_chipset_handle_t pch;
146};
147
148/* interfaces for the chipset to call pcmcia */
149
150int pcmcia_card_attach(device_t);
151void pcmcia_card_detach(device_t, int);
152void pcmcia_card_deactivate(device_t);
153
154#endif /* _PCMCIA_PCMCIACHIP_H_ */
155