1 .\" $NetBSD: pcmcia.9,v 1.16 2008/04/30 13:10:58 martin Exp $
3 .\" Copyright (c) 2001 The NetBSD Foundation, Inc.
4 .\" All rights reserved.
6 .\" This code is derived from software contributed to The NetBSD Foundation
7 .\" by Gregory McGarry.
9 .\" Redistribution and use in source and binary forms, with or without
10 .\" modification, are permitted provided that the following conditions
12 .\" 1. Redistributions of source code must retain the above copyright
13 .\" notice, this list of conditions and the following disclaimer.
14 .\" 2. Redistributions in binary form must reproduce the above copyright
15 .\" notice, this list of conditions and the following disclaimer in the
16 .\" documentation and/or other materials provided with the distribution.
18 .\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
19 .\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
20 .\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 .\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
22 .\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 .\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 .\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 .\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 .\" POSSIBILITY OF SUCH DAMAGE.
35 .Nm pcmcia_function_init ,
36 .Nm pcmcia_function_enable ,
37 .Nm pcmcia_function_disable ,
42 .Nm pcmcia_mem_alloc ,
45 .Nm pcmcia_mem_unmap ,
46 .Nm pcmcia_intr_establish ,
47 .Nm pcmcia_intr_disestablish ,
48 .Nm pcmcia_cis_read_1 ,
49 .Nm pcmcia_cis_read_2 ,
50 .Nm pcmcia_cis_read_3 ,
51 .Nm pcmcia_cis_read_4 ,
52 .Nm pcmcia_cis_read_n ,
54 .Nd support for PCMCIA PC-Card devices
57 .In dev/pcmcia/pcmciareg.h
58 .In dev/pcmcia/pcmciavar.h
59 .In dev/pcmcia/pcmciadevs.h
61 .Fn pcmcia_function_init "struct pcmcia_function *pf" \
62 "struct pcmcia_config_entry *cfe"
64 .Fn pcmcia_function_enable "struct pcmcia_function *pf"
66 .Fn pcmcia_function_disable "struct pcmcia_function *pf"
68 .Fn pcmcia_io_alloc "struct pcmcia_function *pf" "bus_addr_t start" \
69 "bus_size_t size" "bus_size_t align" "struct pcmcia_io_handle *pciop"
71 .Fn pcmcia_io_free "struct pcmcia_function *pf" \
72 "struct pcmcia_io_handle *pcihp"
74 .Fn pcmcia_io_map "struct pcmcia_function *pf" "int width" \
75 "struct pcmcia_io_handle *pcihp" "int *windowp"
77 .Fn pcmcia_io_unmap "struct pcmcia_function *pf" "int window"
79 .Fn pcmcia_mem_alloc "struct pcmcia_function *pf" "bus_size_t size" \
80 "struct pcmcia_mem_handle *pcmhp"
82 .Fn pcmcia_mem_free "struct pcmcia_function *pf" \
83 "struct pcmcia_mem_handle *pcmhp"
85 .Fn pcmcia_mem_map "struct pcmcia_function *pf" "int width" \
86 "bus_addr_t card_addr" "bus_size_t size" "struct pcmcia_mem_handle *pcmhp" \
87 "bus_size_t *offsetp" "int *windowp"
89 .Fn pcmcia_mem_unmap "struct pcmcia_function *pf" "int window"
91 .Fn pcmcia_intr_establish "struct pcmcia_function *pf" "int level" \
92 "int (*handler)(void *)" "void *arg"
94 .Fn pcmcia_intr_disestablish "struct pcmcia_function *pf" "void *ih"
96 .Fn pcmcia_cis_read_1 "struct pcmcia_tuple *tuple" "int index"
98 .Fn pcmcia_cis_read_2 "struct pcmcia_tuple *tuple" "int index"
100 .Fn pcmcia_cis_read_3 "struct pcmcia_tuple *tuple" "int index"
102 .Fn pcmcia_cis_read_4 "struct pcmcia_tuple *tuple" "int index"
104 .Fn pcmcia_cis_read_n "struct pcmcia_tuple *tuple" "int number" "int index"
106 .Fn pcmcia_scan_cis "struct device *dev" \
107 "int (*func)(struct pcmcia_tuple *, void *)" "void *arg"
109 The machine-independent
111 subsystem provides support for PC-Card devices defined by the Personal
112 Computer Memory Card International Assocation (PCMCIA).
115 bus supports insertion and removal of cards while a system is
116 powered-on (ie, dynamic reconfiguration).
117 The socket must be powered-off when a card is not present.
118 To the user, this appears as though the socket is "hot" during
119 insertion and removal events.
121 A PCMCIA controller interfaces the PCMCIA bus with the ISA or PCI
122 busses on the host system.
123 The controller is responsible for detecting and enabling devices and
124 for allocating and mapping resources such as memory and interrupts
125 to devices on the PCMCIA bus.
127 Each device has a table called the Card Information Structure (CIS)
128 which contains configuration information.
129 The tuples in the CIS are used by the controller to uniquely identify
131 Additional information may be present in the CIS, such as the ethernet
132 MAC address, that can be accessed and used within a device driver.
134 Devices on the PCMCIA bus are uniquely identified by a 32-bit
135 manufacturer ID and a 32-bit product ID.
136 Additionally, devices can perform multiple functions (such as ethernet
137 and modem) and these functions are identified by a function ID.
139 PCMCIA devices do not support DMA, however memory on the device can be
140 mapped into the address space of the host.
142 Drivers attached to the
144 bus will make use of the following data types:
145 .Bl -tag -width compact
146 .It Fa struct pcmcia_card
147 Devices (cards) have their identity recorded in this structure.
148 It contains the following members:
151 int32_t manufacturer;
154 SIMPLEQ_HEAD(, pcmcia_function) pf_head;
156 .It Fa struct pcmcia_function
157 Identifies the function of the devices.
158 A device can have multiple functions.
159 Consider it an opaque type for identifying a particular function
161 .It struct pcmcia_config_entry
162 Contains information about the resources requested by the device.
163 It contains the following members:
182 SIMPLEQ_ENTRY(pcmcia_config_entry) cfe_list;
184 .It Fa struct pcmcia_tuple
185 A handle for identifying an entry in the CIS.
186 .It Fa struct pcmcia_io_handle
187 A handle for mapping and allocating I/O address spaces.
188 It contains the tag and handle for accessing the bus-space.
189 .It Fa struct pcmcia_mem_handle
190 A handle for mapping and allocating memory address spaces.
191 It contains the tag and handle for accessing the bus-space.
192 .It Fa struct pcmcia_attach_args
193 A structure used to inform the driver of the
195 It contains the following members:
197 int32_t manufacturer;
199 struct pcmcia_card *card;
200 struct pcmcia_function *pf;
204 .Bl -tag -width compact
205 .It Fn pcmcia_function_init "pf" "cfe"
206 Initialise the machine-independent
208 state with the config entry
210 .It Fn pcmcia_function_enable "pf"
211 Provide power to the socket containing the device specified by
214 .It Fn pcmcia_function_disable "pf"
215 Remove power from the socket containing the device specified by
218 .It Fn pcmcia_io_alloc "pf" "start" "size" "align" "pciop"
219 Request I/O space for device function
225 Alignment is specified by
227 A handle for the I/O space is returned in
229 .It Fn pcmcia_io_free "pf" "pcihp"
230 Release I/O space with handle
234 .It Fn pcmcia_io_map "pf" "width" "pcihp" "windowp"
235 Map device I/O for device function
237 to the I/O space with handle
239 The width of data access is specified by
241 Valid values for the width are:
242 .Bl -tag -width PCMCIA_WIDTH_AUTO
243 .It PCMCIA_WIDTH_AUTO
244 Use the largest I/O width reported by the device.
246 Force 8-bit I/O width.
247 .It PCMCIA_WIDTH_IO16
248 Force 16-bit I/O width.
251 A handle for the mapped I/O window is returned in
253 .It Fn pcmcia_io_unmap "pf" "window"
258 .It Fn pcmcia_mem_alloc "pf" "size" "pcmhp"
259 Request memory space for device function
263 A handle for the memory space is returned in
265 .It Fn pcmcia_mem_free "pf" "pcmhp"
266 Release memory space with handle
270 .It Fn pcmcia_mem_map "pf" "width" "card_addr" "size" "pcmhp" "offsetp" \
272 Map device memory for device function
274 to the memory space with handle
276 The address of the device memory starts at
280 The width of data access is specified by
282 Valid values for the width are:
283 .Bl -tag -width PCMCIA_WIDTH_MEM16
284 .It PCMCIA_WIDTH_MEM8
285 Force 8-bit memory width.
286 .It PCMCIA_WIDTH_MEM16
287 Force 16-bit memory width.
290 A handle for the mapped memory window is returned in
292 and a bus-space offset into the memory window is returned in
294 .It Fn pcmcia_mem_unmap "pf" "window"
295 Unmap the memory window
299 .It Fn pcmcia_intr_establish "pf" "level" "handler" "arg"
300 Establish an interrupt handler for device function
302 The priority of the interrupt is specified by
304 When the interrupt occurs the function
306 is called with argument
308 The return value is a handle for the interrupt handler.
309 .Fn pcmcia_intr_establish
310 returns an opaque handle to an event descriptor if it succeeds, and
311 returns NULL on failure.
312 .It Fn pcmcia_intr_disestablish "pf" "ih"
313 Dis-establish the interrupt handler for device function
317 The handle was returned from
318 .Fn pcmcia_intr_establish .
319 .It Fn pcmcia_cis_read_1 "tuple" "index"
320 Read one byte from tuple
325 .It Fn pcmcia_cis_read_2 "tuple" "index"
326 Read two bytes from tuple
331 .It Fn pcmcia_cis_read_3 "tuple" "index"
332 Read three bytes from tuple
337 .It Fn pcmcia_cis_read_4 "tuple" "index"
338 Read four bytes from tuple
343 .It Fn pcmcia_cis_read_n "tuple" "number" "index"
351 .It Fn pcmcia_scan_cis "dev" "func" "arg"
352 Scan the CIS for device
354 For each tuple in the CIS, function
356 is called with the tuple and the argument
359 should return 0 if the tuple it was called with is the one it was
360 looking for, or 1 otherwise.
362 .Sh AUTOCONFIGURATION
363 During autoconfiguration, a
365 driver will receive a pointer to
366 .Fa struct pcmcia_attach_args
367 describing the device attached to the PCMCIA bus.
368 Drivers match the device using the
374 During the driver attach step, drivers will use the pcmcia function
376 The driver should traverse the list of config entries searching for a
377 useful configuration.
378 This config entry is passed to
379 .Fn pcmcia_function_init
380 to initialise the machine-independent interface.
381 I/O and memory resources should be initialised using
385 using the specified resources in the config entry.
386 These resources can then be mapped into processor bus space using
391 Upon successful allocation of resources, power can be applied to the
393 .Fn pcmcia_function_enable
394 so that device-specific interrogation can be performed.
395 Finally, power should be removed from the device using
396 .Fn pcmcia_function_disable .
398 Since PCMCIA devices support dynamic configuration, drivers should
400 .Fn powerhook_establish 9 .
401 Power can be applied and the interrupt handler should be established
402 through this interface.
404 PCMCIA devices do not support DMA.
406 This section describes places within the
408 source tree where actual code implementing or using the
409 machine-independent PCMCIA subsystem can be found.
410 All pathnames are relative to
413 The PCMCIA subsystem itself is implemented within the file
414 .Pa sys/dev/pcmcia/pcmcia.c .
415 The database of known devices exists within the file
416 .Pa sys/dev/pcmcia/pcmciadevs_data.h
417 and is generated automatically from the file
418 .Pa sys/dev/pcmcia/pcmciadevs .
419 New manufacturer and product identifiers should be added to this file.
420 The database can be regenerated using the Makefile
421 .Pa sys/dev/pcmcia/Makefile.pcmciadevs .
431 .%A Personal Computer Memory Card International Association (PCMCIA)
432 .%T "PC Card 95 Standard"
436 The machine-independent PCMCIA subsystem appeared in