xref: /netbsd/share/man/man9/cardbus.9 (revision c4a72b64)
1.\"     $NetBSD: cardbus.9,v 1.6 2002/10/14 13:43:17 wiz Exp $
2.\"
3.\" Copyright (c) 2001 The NetBSD Foundation, Inc.
4.\" All rights reserved.
5.\"
6.\" This code is derived from software contributed to The NetBSD Foundation
7.\" by Gregory McGarry.
8.\"
9.\" Redistribution and use in source and binary forms, with or without
10.\" modification, are permitted provided that the following conditions
11.\" are met:
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.
17.\" 3. All advertising materials mentioning features or use of this software
18.\"    must display the following acknowledgement:
19.\"        This product includes software developed by the NetBSD
20.\"        Foundation, Inc. and its contributors.
21.\" 4. Neither the name of The NetBSD Foundation nor the names of its
22.\"    contributors may be used to endorse or promote products derived
23.\"    from this software without specific prior written permission.
24.\"
25.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
26.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
27.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
29.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35.\" POSSIBILITY OF SUCH DAMAGE.
36.\"
37.Dd June 20, 2001
38.Dt CARDBUS 9
39.Os
40.Sh NAME
41.Nm Cardbus ,
42.Nm cardbus_attach_card ,
43.Nm cardbus_detach_card ,
44.Nm cardbus_function_enable ,
45.Nm cardbus_function_disable ,
46.Nm cardbus_mapreg_map ,
47.Nm cardbus_mapreg_unmap ,
48.Nm cardbus_get_capability ,
49.Nm cardbus_make_tag ,
50.Nm cardbus_free_tag ,
51.Nm cardbus_conf_read ,
52.Nm cardbus_conf_write ,
53.Nm cardbus_intr_establish ,
54.Nm cardbus_intr_disestablish ,
55.Nm CARDBUS_VENDOR ,
56.Nm CARDBUS_PRODUCT ,
57.Nm Cardbus_function_enable ,
58.Nm Cardbus_function_disable ,
59.Nm Cardbus_mapreg_map ,
60.Nm Cardbus_mapreg_unmap ,
61.Nm Cardbus_make_tag ,
62.Nm Cardbus_free_tag ,
63.Nm Cardbus_conf_read ,
64.Nm Cardbus_conf_write
65.Nd support for Cardbus PC-Card devices
66.Sh SYNOPSIS
67.Fd #include \*[Lt]machine/bus.h\*[Gt]
68.Fd #include \*[Lt]dev/cardbus/cardbusvar.h\*[Gt]
69.Fd #include \*[Lt]dev/cardbus/cardbusdevs.h\*[Gt]
70.Ft int
71.Fn cardbus_attach_card "struct cardbus_softc *csc"
72.Ft void
73.Fn cardbus_detach_card "struct cardbus_softc *csc"
74.Ft int
75.Fn cardbus_function_enable "struct cardbus_softc *csc" "int function"
76.Ft int
77.Fn cardbus_function_disable "struct cardbus_softc *csc" "int function"
78.Ft int
79.Fo cardbus_mapreg_map
80.Fa "struct cardbus_softc *csc" "int cf" "int reg"
81.Fa "cardbusreg_t type" "int busflags" "bus_space_tag_t *tagp"
82.Fa "bus_space_handle_t *handlep" "bus_addr_t *basep" "bus_size_t *sizep"
83.Fc
84.Ft int
85.Fn cardbus_mapreg_unmap "struct cardbus_softc *csc" "int cf" \
86"int reg" "bus_space_tag_t tag" "bus_space_handle_t handle" \
87"bus_size_t size"
88.Ft int
89.Fn cardbus_get_capability "cardbus_chipset_tag_t cc" \
90"cardbus_function_tag_t cf" "cardbustag_t tag" "int capid" \
91"int *offsetp" "cardbusreg_t *valuep"
92.Ft cardbustag_t
93.Fn cardbus_make_tag "cardbus_chipset_tag_t cc" "int cf" "int bus" \
94"int device" "int function"
95.Ft void
96.Fn cardbus_free_tag "cardbus_chipset_tag_t cc" "int cf" \
97"cardbustag_t tag"
98.Ft cardbusreg_t
99.Fn cardbus_conf_read "cardbus_chipset_tag_t cc" "int cf" \
100"cardbustag_t tag" "int offs"
101.Ft void
102.Fn cardbus_conf_write "cardbus_chipset_tag_t cc" "int cf" \
103"cardbustag_t tag" "int offs" "busreg_t val"
104.Ft void *
105.Fn cardbus_intr_establish "cardbus_chipset_tag_t cc" \
106"cardbus_function_tag_t cf" "cardbus_intr_handle_t irq" "int level" \
107"int (*handler)(void *)" "void *arg"
108.Ft void
109.Fn cardbus_intr_disestablish "cardbus_chipset_tag_t cc" \
110"cardbus_function_tag_t cf" "void *ih"
111.Ft int
112.Fn CARDBUS_VENDOR "cardbusreg_t id"
113.Ft int
114.Fn CARDBUS_PRODUCT "cardbusreg_t id"
115.Ft int
116.Fn Cardbus_function_enable "cardbus_devfunc_t ct"
117.Ft int
118.Fn Cardbus_function_disable "cardbus_devfunc_t ct"
119.Ft int
120.Fn Cardbus_mapreg_map "cardbus_devfunc_t ct" "int reg" \
121"cardbusreg_t type" "int busflags" "bus_space_tag_t *tagp" \
122"bus_space_handle_t *handlep" "bus_addr_t *basep" "bus_size_t *sizep"
123.Ft int
124.Fn Cardbus_mapreg_unmap "cardbus_devfunc_t ct" \
125"int reg" "bus_space_tag_t tag" "bus_space_handle_t handle" \
126"bus_size_t size"
127.Ft cardbustag_t
128.Fn Cardbus_make_tag "cardbus_devfunc_t ct "
129.Ft void
130.Fn Cardbus_free_tag "cardbus_devfunc_t ct" "cardbustag_t tag"
131.Ft cardbusreg_t
132.Fn Cardbus_conf_read "cardbus_devfunc_t ct" "cardbustag_t tag" \
133"int offs"
134.Ft void
135.Fn Cardbus_conf_write "cardbus_devfunc_t ct" "cardbustag_t tag" \
136"int offs" "busreg_t val"
137.Sh DESCRIPTION
138The machine-independent
139.Nm
140subsystem provides support for Cardbus devices.
141.Pp
142The Cardbus interface is an improvement to the PC-Card interface
143supported by
144.Xr pcmcia 9 .
145It introduces several new capabilities such as 32-bit addressing,
14633MHz operation, busmaster operation and 3.3 volt low-voltage power.
147It remains compatible with all features of the PC-Card standard.
148.Pp
149The Cardbus interface signaling protocol is derived from the PCI
150signaling protocol.
151There are some differences between PCI and Cardbus, however operations
152are identical for most functions implemented.
153Since a 32-bit Cardbus interface is also defined for 16-bit PC-Cards,
154the same Card Services client to be used to manage both Cardbus and
155PCMCIA PC-Cards.
156By interrogating the card upon detection of an insertion event,
157.Nx
158determines whether the card requires
159.Nm
160support or not, and then applies the appropriate power and signaling
161protocol requirements.
162.Sh DATA TYPES
163Drivers attached to the Cardbus bus will make use of the following
164data types:
165.Bl -tag -width compact
166.It struct cardbus_attach_args
167Devices have their identity recorded in this structure.
168It contains the following members:
169.Bd -literal
170	cardbus_devfunc_t ca_ct;
171	bus_space_tag_t ca_iot;       /* Cardbus I/O space tag */
172	bus_space_tag_t ca_memt;      /* Cardbus MEM space tag */
173	bus_dma_tag_t ca_dmat;        /* DMA tag */
174	u_int ca_device;
175	cardbustag_t ca_tag;
176	cardbusreg_t ca_id;
177	cardbusreg_t ca_class;
178	cardbus_intr_line_t ca_intrline; /* interrupt info */
179	struct cardbus_cis_info ca_cis;
180.Ed
181.El
182.Sh FUNCTIONS
183.Bl -tag -width compact
184.It Fn cardbus_attach_card "csc"
185Attaches the card on the slot by turning on the power, read and
186analyse the tuple and sets configuration index.
187This function returns the number of recognised device functions.
188If no device functions are recognised it returns zero.
189.It Fn cardbus_detach_card "csc"
190Detaches the card on the slot by release resources and turning off the
191power.
192This function must not be called under interrupt context.
193.It Fn cardbus_function_enable "csc" "function"
194Enables device function
195.Fa function
196on the card.
197Power will be applied if it hasn't already.
198.It Fn cardbus_function_disable "csc" "function"
199Disables device function
200.Fa function
201on the card.
202When no device functions are enabled, the turn is turned off.
203.It Fo cardbus_mapreg_map
204.Fa "csc" "cf" "reg" "type" "busflags"
205.Fa "tagp" "handlep" "basep" "sizep"
206.Fc
207Maps bus-space on the value of Base Address Register (BAR) indexed by
208.Fa reg
209for device function
210.Fa cf .
211The bus-space configuration is returned in
212.Fa tagp ,
213.Fa handlep ,
214.Fa basep ,
215and
216.Fa sizep .
217.It Fn cardbus_mapreg_unmap "csc" "cf" "reg" "tag" "handle" "bus_size_t size"
218Releases bus-space region for device function
219.Fa cf
220specified by
221.Fa tag ,
222.Fa handle
223and
224.Fa size .
225.Fa reg
226is the offset of the BAR register.
227.It Fn cardbus_get_capability "cc" "cf" "tag" "capid" "offsetp" "valuep"
228Find the PCI capability for the device function
229.Fa cf
230specified by
231.Fa capid .
232Returns the capability in
233.Fa offsetp
234and
235.Fa valuep .
236.It Fn cardbus_make_tag "cc" "cf" "bus" "device" "function"
237Make a tag to access config space of a Cardbus card.
238It works the same as
239.Fn pci_make_tag .
240.It Fn cardbus_free_tag "cc" "cf" "tag"
241Release a tag used to access the config space of a Cardbus card.
242It works the same as
243.Fn pci_free_tag .
244.It Fn cardbus_conf_read "cc" "cf" "tag" "offs"
245Read the config space of a Cardbus card.
246It works the same as
247.Fn pci_conf_read .
248.It Fn cardbus_conf_write "cc" "cf" "tag" "offs" "val"
249Write to the config space of a Cardbus card.
250It works same as
251.Fn pci_conf_write .
252.It Fn cardbus_intr_establish "cc" "cf" "irq" "level" "handler" "arg"
253Establish an interrupt handler for device function
254.Fa cf .
255The priority of the interrupt is specified by
256.Fa level .
257When the interrupt occurs the function
258.Fa handler
259is called with argument
260.Fa arg .
261The return value is a handle for the interrupt handler.
262.Fn cardbus_intr_establish
263returns an opaque handle to an event descriptor if it succeeds, and
264returns NULL on failure.
265.It Fn cardbus_intr_disestablish "cc" "cf" "ih"
266Dis-establish the interrupt handler for device function
267.Fa cf
268with handle
269.Fa ih .
270The handle was returned from
271.Fn cardbus_intr_establish .
272.It Fn CARDBUS_VENDOR "id"
273Return the Cardbus vendor id for device
274.Fa id .
275.It Fn CARDBUS_PRODUCT "id"
276Return the Cardbus product id for device
277.Fa id .
278.El
279.Pp
280The
281.Fn Cardbus_*
282functions are convenience functions taking a
283.Fa cardbus_devfunc_t
284argument and perform the same operation as their namesake described
285above.
286.Sh AUTOCONFIGURATION
287During autoconfiguration, a
288.Nm
289driver will receive a pointer to
290.Fa struct isapnp_attach_args
291describing the device attaches to the Cardbus bus.
292Drivers match the device using the
293.Fa ca_id
294member using
295.Fn CARDBUS_VENDOR
296and
297.Fn CARDBUS_PRODUCT .
298.Pp
299During the driver attach step, drivers should initially map the device
300I/O and memory resources using
301.Fn cardbus_mapreg_map
302or
303.Fn Cardbus_mapreg_map .
304Upon successful allocation of resources, power can be
305applied to the device with
306.Fn cardbus_function_enable
307or
308.Fn Cardbus_function_enable .
309so that device-specific interrogation can be performed.
310Finally, power should be removed from the device using
311.Fn cardbus_function_disable
312or
313.Fn Cardbus_function_disable .
314.Pp
315Since Cardbus devices support dynamic configuration, drivers should
316make use of
317.Fn powerhook_establish 9 .
318Power can be applied and the interrupt handler should be established
319through this interface.
320.Sh DMA SUPPORT
321No additional support is provided for Cardbus DMA beyond the
322facilities provided by the
323.Xr bus_dma 9
324interface.
325.Sh CODE REFERENCES
326This section describes places within the
327.Nx
328source tree where actual code implementing or utilising the
329machine-independent Cardbus subsystem can be found.
330All pathnames are relative to
331.Pa /usr/src .
332.Pp
333The Cardbus subsystem itself is implemented within the files
334.Pa sys/dev/cardbus/cardbus.c ,
335.Pa sys/dev/cardbus/cardbus_map.c
336and
337.Pa sys/dev/cardbus/cardslot.c .
338The database of known devices exists within the file
339.Pa sys/dev/cardbus/cardbus_data.h
340and is generated automatically from the file
341.Pa sys/dev/cardbus/cardbusdevs .
342New vendor and product identifiers should be added to this file.
343The database can be regenerated using the Makefile
344.Pa sys/dev/cardbus/Makefile.cardbusdevs .
345.Sh SEE ALSO
346.Xr cardbus 4 ,
347.Xr pcmcia 4 ,
348.Xr autoconf 9 ,
349.Xr bus_dma 9 ,
350.Xr bus_space 9 ,
351.Xr driver 9 ,
352.Xr pci 9 ,
353.Xr pcmcia 9
354.Sh HISTORY
355The machine-independent
356.Nm
357subsystem appeared in
358.Nx 1.5 .
359