2002-10-07 23:03:17 +00:00
|
|
|
/* $NetBSD: pcmcia_cis.c,v 1.17 2000/02/10 09:01:52 chopps Exp $ */
|
1999-10-26 06:52:31 +00:00
|
|
|
/* $FreeBSD$ */
|
|
|
|
|
2005-01-06 01:43:34 +00:00
|
|
|
/*-
|
2017-11-27 14:52:40 +00:00
|
|
|
* SPDX-License-Identifier: BSD-4-Clause
|
|
|
|
*
|
1999-10-26 06:52:31 +00:00
|
|
|
* Copyright (c) 1997 Marc Horowitz. All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by Marc Horowitz.
|
|
|
|
* 4. The name of the author may not be used to endorse or promote products
|
|
|
|
* derived from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/module.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/queue.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
|
|
|
#include <sys/bus.h>
|
|
|
|
#include <machine/bus.h>
|
|
|
|
#include <sys/rman.h>
|
|
|
|
#include <machine/resource.h>
|
|
|
|
|
|
|
|
#include <dev/pccard/pccardreg.h>
|
|
|
|
#include <dev/pccard/pccardvar.h>
|
2005-09-20 06:45:38 +00:00
|
|
|
#include <dev/pccard/pccardvarp.h>
|
2003-10-07 03:33:54 +00:00
|
|
|
#include <dev/pccard/pccard_cis.h>
|
1999-10-26 06:52:31 +00:00
|
|
|
|
2000-04-13 06:42:58 +00:00
|
|
|
#include "card_if.h"
|
|
|
|
|
2002-03-07 08:03:53 +00:00
|
|
|
extern int pccard_cis_debug;
|
|
|
|
|
2000-04-13 06:42:58 +00:00
|
|
|
#define PCCARDCISDEBUG
|
1999-10-26 06:52:31 +00:00
|
|
|
#ifdef PCCARDCISDEBUG
|
2003-08-20 05:44:55 +00:00
|
|
|
#define DPRINTF(arg) do { if (pccard_cis_debug) printf arg; } while (0)
|
|
|
|
#define DEVPRINTF(arg) do { if (pccard_cis_debug) device_printf arg; } while (0)
|
1999-10-26 06:52:31 +00:00
|
|
|
#else
|
|
|
|
#define DPRINTF(arg)
|
2000-01-10 06:58:17 +00:00
|
|
|
#define DEVPRINTF(arg)
|
1999-10-26 06:52:31 +00:00
|
|
|
#endif
|
|
|
|
|
2004-04-12 20:56:34 +00:00
|
|
|
#define PCCARD_CIS_SIZE 4096
|
1999-10-26 06:52:31 +00:00
|
|
|
|
|
|
|
struct cis_state {
|
|
|
|
int count;
|
|
|
|
int gotmfc;
|
|
|
|
struct pccard_config_entry temp_cfe;
|
|
|
|
struct pccard_config_entry *default_cfe;
|
|
|
|
struct pccard_card *card;
|
|
|
|
struct pccard_function *pf;
|
|
|
|
};
|
|
|
|
|
2005-07-01 15:52:50 +00:00
|
|
|
static int pccard_parse_cis_tuple(const struct pccard_tuple *, void *);
|
|
|
|
static int decode_funce(const struct pccard_tuple *, struct pccard_function *);
|
1999-10-26 06:52:31 +00:00
|
|
|
|
|
|
|
void
|
2000-01-10 06:58:17 +00:00
|
|
|
pccard_read_cis(struct pccard_softc *sc)
|
1999-10-26 06:52:31 +00:00
|
|
|
{
|
|
|
|
struct cis_state state;
|
|
|
|
|
2002-10-07 23:03:17 +00:00
|
|
|
bzero(&state, sizeof state);
|
1999-10-26 06:52:31 +00:00
|
|
|
state.card = &sc->card;
|
|
|
|
state.card->error = 0;
|
|
|
|
state.card->cis1_major = -1;
|
|
|
|
state.card->cis1_minor = -1;
|
|
|
|
state.card->cis1_info[0] = NULL;
|
|
|
|
state.card->cis1_info[1] = NULL;
|
|
|
|
state.card->cis1_info[2] = NULL;
|
|
|
|
state.card->cis1_info[3] = NULL;
|
2001-11-11 20:15:47 +00:00
|
|
|
state.card->manufacturer = PCMCIA_VENDOR_INVALID;
|
|
|
|
state.card->product = PCMCIA_PRODUCT_INVALID;
|
1999-10-26 06:52:31 +00:00
|
|
|
STAILQ_INIT(&state.card->pf_head);
|
|
|
|
state.pf = NULL;
|
|
|
|
|
2006-08-09 00:05:54 +00:00
|
|
|
/*
|
|
|
|
* XXX The following shouldn't be needed, but some slow cards
|
|
|
|
* XXX seem to need it still. Need to investigate if there's
|
|
|
|
* XXX a way to tell if the card is 'ready' or not rather than
|
|
|
|
* XXX sleeping like this. We're called just after the power
|
|
|
|
* XXX up of the socket. The standard timing diagrams don't
|
|
|
|
* XXX seem to indicate that a delay is required. The old
|
|
|
|
* XXX delay was 1s. This delay is .1s.
|
|
|
|
*/
|
2007-02-27 17:23:29 +00:00
|
|
|
pause("pccard", hz / 10);
|
2005-09-13 17:56:36 +00:00
|
|
|
if (pccard_scan_cis(device_get_parent(sc->dev), sc->dev,
|
|
|
|
pccard_parse_cis_tuple, &state) == -1)
|
1999-10-26 06:52:31 +00:00
|
|
|
state.card->error++;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2005-09-13 17:56:36 +00:00
|
|
|
pccard_scan_cis(device_t bus, device_t dev, pccard_scan_t fct, void *arg)
|
1999-10-26 06:52:31 +00:00
|
|
|
{
|
2000-01-10 06:58:17 +00:00
|
|
|
struct resource *res;
|
|
|
|
int rid;
|
1999-10-26 06:52:31 +00:00
|
|
|
struct pccard_tuple tuple;
|
|
|
|
int longlink_present;
|
|
|
|
int longlink_common;
|
2003-03-18 02:38:33 +00:00
|
|
|
u_long longlink_addr; /* Type suspect */
|
1999-10-26 06:52:31 +00:00
|
|
|
int mfc_count;
|
|
|
|
int mfc_index;
|
2003-08-20 05:44:55 +00:00
|
|
|
#ifdef PCCARDCISDEBUG
|
|
|
|
int cis_none_cnt = 10; /* Only report 10 CIS_NONEs */
|
|
|
|
#endif
|
1999-10-26 06:52:31 +00:00
|
|
|
struct {
|
|
|
|
int common;
|
|
|
|
u_long addr;
|
|
|
|
} mfc[256 / 5];
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
|
|
|
|
/* allocate some memory */
|
|
|
|
|
2004-04-12 20:56:34 +00:00
|
|
|
/*
|
|
|
|
* Some reports from the field suggest that a 64k memory boundary
|
|
|
|
* helps card CIS being able to be read. Try it here and see what
|
|
|
|
* the results actually are. I'm not sure I understand why this
|
|
|
|
* would make cards work better, but it is easy enough to test.
|
|
|
|
*/
|
2000-01-10 06:58:17 +00:00
|
|
|
rid = 0;
|
2016-02-27 03:38:01 +00:00
|
|
|
res = bus_alloc_resource_anywhere(dev, SYS_RES_MEMORY, &rid,
|
2004-04-12 20:56:34 +00:00
|
|
|
PCCARD_CIS_SIZE, RF_ACTIVE | rman_make_alignment_flags(64*1024));
|
2000-01-10 06:58:17 +00:00
|
|
|
if (res == NULL) {
|
|
|
|
device_printf(dev, "can't alloc memory to read attributes\n");
|
1999-10-26 06:52:31 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2005-09-13 17:56:36 +00:00
|
|
|
CARD_SET_RES_FLAGS(bus, dev, SYS_RES_MEMORY, rid, PCCARD_A_MEM_ATTR);
|
2000-01-10 06:58:17 +00:00
|
|
|
tuple.memt = rman_get_bustag(res);
|
|
|
|
tuple.memh = rman_get_bushandle(res);
|
2000-04-19 08:31:21 +00:00
|
|
|
tuple.ptr = 0;
|
1999-10-26 06:52:31 +00:00
|
|
|
|
Use uintmax_t (typedef'd to rman_res_t type) for rman ranges.
On some architectures, u_long isn't large enough for resource definitions.
Particularly, powerpc and arm allow 36-bit (or larger) physical addresses, but
type `long' is only 32-bit. This extends rman's resources to uintmax_t. With
this change, any resource can feasibly be placed anywhere in physical memory
(within the constraints of the driver).
Why uintmax_t and not something machine dependent, or uint64_t? Though it's
possible for uintmax_t to grow, it's highly unlikely it will become 128-bit on
32-bit architectures. 64-bit architectures should have plenty of RAM to absorb
the increase on resource sizes if and when this occurs, and the number of
resources on memory-constrained systems should be sufficiently small as to not
pose a drastic overhead. That being said, uintmax_t was chosen for source
clarity. If it's specified as uint64_t, all printf()-like calls would either
need casts to uintmax_t, or be littered with PRI*64 macros. Casts to uintmax_t
aren't horrible, but it would also bake into the API for
resource_list_print_type() either a hidden assumption that entries get cast to
uintmax_t for printing, or these calls would need the PRI*64 macros. Since
source code is meant to be read more often than written, I chose the clearest
path of simply using uintmax_t.
Tested on a PowerPC p5020-based board, which places all device resources in
0xfxxxxxxxx, and has 8GB RAM.
Regression tested on qemu-system-i386
Regression tested on qemu-system-mips (malta profile)
Tested PAE and devinfo on virtualbox (live CD)
Special thanks to bz for his testing on ARM.
Reviewed By: bz, jhb (previous)
Relnotes: Yes
Sponsored by: Alex Perez/Inertial Computing
Differential Revision: https://reviews.freebsd.org/D4544
2016-03-18 01:28:41 +00:00
|
|
|
DPRINTF(("cis mem map %#x (resource: %#jx)\n",
|
2003-08-18 03:07:09 +00:00
|
|
|
(unsigned int) tuple.memh, rman_get_start(res)));
|
2000-01-10 06:58:17 +00:00
|
|
|
|
1999-10-26 06:52:31 +00:00
|
|
|
tuple.mult = 2;
|
|
|
|
|
|
|
|
longlink_present = 1;
|
|
|
|
longlink_common = 1;
|
|
|
|
longlink_addr = 0;
|
|
|
|
|
|
|
|
mfc_count = 0;
|
|
|
|
mfc_index = 0;
|
|
|
|
|
2000-01-10 06:58:17 +00:00
|
|
|
DEVPRINTF((dev, "CIS tuple chain:\n"));
|
1999-10-26 06:52:31 +00:00
|
|
|
|
|
|
|
while (1) {
|
|
|
|
while (1) {
|
2003-08-18 03:07:09 +00:00
|
|
|
/*
|
|
|
|
* Perform boundary check for insane cards.
|
|
|
|
* If CIS is too long, simulate CIS end.
|
|
|
|
* (This check may not be sufficient for
|
|
|
|
* malicious cards.)
|
|
|
|
*/
|
|
|
|
if (tuple.mult * tuple.ptr >= PCCARD_CIS_SIZE - 1
|
|
|
|
- 32 /* ad hoc value */ ) {
|
|
|
|
printf("CIS is too long -- truncating\n");
|
2003-10-07 03:33:54 +00:00
|
|
|
tuple.code = CISTPL_END;
|
2003-08-18 03:07:09 +00:00
|
|
|
} else {
|
|
|
|
/* get the tuple code */
|
|
|
|
tuple.code = pccard_cis_read_1(&tuple, tuple.ptr);
|
|
|
|
}
|
1999-10-26 06:52:31 +00:00
|
|
|
|
|
|
|
/* two special-case tuples */
|
|
|
|
|
2003-10-07 03:33:54 +00:00
|
|
|
if (tuple.code == CISTPL_NULL) {
|
2003-08-20 05:44:55 +00:00
|
|
|
#ifdef PCCARDCISDEBUG
|
|
|
|
if (cis_none_cnt > 0)
|
|
|
|
DPRINTF(("CISTPL_NONE\n 00\n"));
|
|
|
|
else if (cis_none_cnt == 0)
|
|
|
|
DPRINTF(("TOO MANY CIS_NONE\n"));
|
|
|
|
cis_none_cnt--;
|
|
|
|
#endif
|
2005-09-20 06:45:38 +00:00
|
|
|
if ((*fct)(&tuple, arg)) {
|
|
|
|
ret = 1;
|
|
|
|
goto done;
|
|
|
|
}
|
1999-10-26 06:52:31 +00:00
|
|
|
tuple.ptr++;
|
|
|
|
continue;
|
2003-10-07 03:33:54 +00:00
|
|
|
} else if (tuple.code == CISTPL_END) {
|
1999-10-26 06:52:31 +00:00
|
|
|
DPRINTF(("CISTPL_END\n ff\n"));
|
|
|
|
/* Call the function for the END tuple, since
|
|
|
|
the CIS semantics depend on it */
|
Add a much-requested feature: The ability for pccard attachments to
scan the CIS for interesting tuples. 95% of what can be obtained from
the CIS is harvested by the pccard layer and presented to the user in
standard function calls. However, there are special needs at times
where the standard stuff doesn't suffice. This is for those special
cases.
CARD_SCAN_CIS(device_get_parent(dev), function, argp)
scans the CIS of the card, passing each tuple to function with
the tuple and argp as its arguments. Returning 0 continues the scan,
while returning 1 terminates the scan. The value of the last
invocation of function is returned from this function.
int (*pccard_scan_t)(struct pccard_tuple *tuple, void *argp)
function called for each tuple. Elements of the CIS tuple can be
read with pccard_tuple_read_{1,2,3,4,n}(). You are reading
the actual tuple memory each time, in case your card has
registers in the CIS.
# I suppose these things should be documented in pccard(4) or something like
# that.
# I plan on unifying cardbus CIS support in a similar way.
Approved by: re (scottl)
2005-07-01 03:40:28 +00:00
|
|
|
if ((*fct)(&tuple, arg)) {
|
1999-10-26 06:52:31 +00:00
|
|
|
ret = 1;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
tuple.ptr++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* now all the normal tuples */
|
|
|
|
|
|
|
|
tuple.length = pccard_cis_read_1(&tuple, tuple.ptr + 1);
|
|
|
|
switch (tuple.code) {
|
2003-10-07 03:33:54 +00:00
|
|
|
case CISTPL_LONGLINK_A:
|
|
|
|
case CISTPL_LONGLINK_C:
|
2005-09-20 06:45:38 +00:00
|
|
|
if ((*fct)(&tuple, arg)) {
|
|
|
|
ret = 1;
|
|
|
|
goto done;
|
|
|
|
}
|
1999-10-26 06:52:31 +00:00
|
|
|
if (tuple.length < 4) {
|
|
|
|
DPRINTF(("CISTPL_LONGLINK_%s too "
|
|
|
|
"short %d\n",
|
|
|
|
longlink_common ? "C" : "A",
|
|
|
|
tuple.length));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
longlink_present = 1;
|
|
|
|
longlink_common = (tuple.code ==
|
2003-10-07 03:33:54 +00:00
|
|
|
CISTPL_LONGLINK_C) ? 1 : 0;
|
1999-10-26 06:52:31 +00:00
|
|
|
longlink_addr = pccard_tuple_read_4(&tuple, 0);
|
2009-02-05 23:51:11 +00:00
|
|
|
DPRINTF(("CISTPL_LONGLINK_%s %#lx\n",
|
1999-10-26 06:52:31 +00:00
|
|
|
longlink_common ? "C" : "A",
|
|
|
|
longlink_addr));
|
|
|
|
break;
|
2003-10-07 03:33:54 +00:00
|
|
|
case CISTPL_NO_LINK:
|
2005-09-20 06:45:38 +00:00
|
|
|
if ((*fct)(&tuple, arg)) {
|
|
|
|
ret = 1;
|
|
|
|
goto done;
|
|
|
|
}
|
1999-10-26 06:52:31 +00:00
|
|
|
longlink_present = 0;
|
|
|
|
DPRINTF(("CISTPL_NO_LINK\n"));
|
|
|
|
break;
|
2003-10-07 03:33:54 +00:00
|
|
|
case CISTPL_CHECKSUM:
|
2005-09-20 06:45:38 +00:00
|
|
|
if ((*fct)(&tuple, arg)) {
|
|
|
|
ret = 1;
|
|
|
|
goto done;
|
|
|
|
}
|
1999-10-26 06:52:31 +00:00
|
|
|
if (tuple.length < 5) {
|
|
|
|
DPRINTF(("CISTPL_CHECKSUM too "
|
|
|
|
"short %d\n", tuple.length));
|
|
|
|
break;
|
|
|
|
} {
|
|
|
|
int16_t offset;
|
|
|
|
u_long addr, length;
|
|
|
|
u_int cksum, sum;
|
|
|
|
int i;
|
|
|
|
|
2002-02-19 05:01:43 +00:00
|
|
|
offset = (uint16_t)
|
1999-10-26 06:52:31 +00:00
|
|
|
pccard_tuple_read_2(&tuple, 0);
|
|
|
|
length = pccard_tuple_read_2(&tuple, 2);
|
|
|
|
cksum = pccard_tuple_read_1(&tuple, 4);
|
|
|
|
|
|
|
|
addr = tuple.ptr + offset;
|
|
|
|
|
2009-02-05 23:51:11 +00:00
|
|
|
DPRINTF(("CISTPL_CHECKSUM addr=%#lx "
|
|
|
|
"len=%#lx cksum=%#x",
|
1999-10-26 06:52:31 +00:00
|
|
|
addr, length, cksum));
|
|
|
|
|
|
|
|
/*
|
|
|
|
* XXX do more work to deal with
|
|
|
|
* distant regions
|
|
|
|
*/
|
|
|
|
if ((addr >= PCCARD_CIS_SIZE) ||
|
|
|
|
((addr + length) >=
|
2002-10-07 23:03:17 +00:00
|
|
|
PCCARD_CIS_SIZE)) {
|
1999-10-26 06:52:31 +00:00
|
|
|
DPRINTF((" skipped, "
|
|
|
|
"too distant\n"));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
sum = 0;
|
|
|
|
for (i = 0; i < length; i++)
|
|
|
|
sum +=
|
|
|
|
bus_space_read_1(tuple.memt,
|
|
|
|
tuple.memh,
|
|
|
|
addr + tuple.mult * i);
|
|
|
|
if (cksum != (sum & 0xff)) {
|
2009-02-05 23:51:11 +00:00
|
|
|
DPRINTF((" failed sum=%#x\n",
|
1999-10-26 06:52:31 +00:00
|
|
|
sum));
|
2000-01-10 06:58:17 +00:00
|
|
|
device_printf(dev,
|
|
|
|
"CIS checksum failed\n");
|
1999-10-26 06:52:31 +00:00
|
|
|
#if 0
|
|
|
|
/*
|
|
|
|
* XXX Some working cards have
|
|
|
|
* XXX bad checksums!!
|
|
|
|
*/
|
|
|
|
ret = -1;
|
|
|
|
#endif
|
|
|
|
} else {
|
|
|
|
DPRINTF((" ok\n"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2003-10-07 03:33:54 +00:00
|
|
|
case CISTPL_LONGLINK_MFC:
|
1999-10-26 06:52:31 +00:00
|
|
|
if (tuple.length < 1) {
|
|
|
|
DPRINTF(("CISTPL_LONGLINK_MFC too "
|
|
|
|
"short %d\n", tuple.length));
|
|
|
|
break;
|
|
|
|
}
|
2002-10-07 23:03:17 +00:00
|
|
|
if (((tuple.length - 1) % 5) != 0) {
|
|
|
|
DPRINTF(("CISTPL_LONGLINK_MFC bogus "
|
|
|
|
"length %d\n", tuple.length));
|
|
|
|
break;
|
|
|
|
}
|
1999-10-26 06:52:31 +00:00
|
|
|
/*
|
|
|
|
* this is kind of ad hoc, as I don't have
|
|
|
|
* any real documentation
|
|
|
|
*/
|
|
|
|
{
|
2002-10-07 23:03:17 +00:00
|
|
|
int i, tmp_count;
|
1999-10-26 06:52:31 +00:00
|
|
|
|
2002-10-07 23:03:17 +00:00
|
|
|
/*
|
|
|
|
* put count into tmp var so that
|
|
|
|
* if we have to bail (because it's
|
|
|
|
* a bogus count) it won't be
|
|
|
|
* remembered for later use.
|
|
|
|
*/
|
|
|
|
tmp_count =
|
1999-10-26 06:52:31 +00:00
|
|
|
pccard_tuple_read_1(&tuple, 0);
|
2002-10-07 23:03:17 +00:00
|
|
|
|
1999-10-26 06:52:31 +00:00
|
|
|
DPRINTF(("CISTPL_LONGLINK_MFC %d",
|
2002-10-07 23:03:17 +00:00
|
|
|
tmp_count));
|
|
|
|
|
|
|
|
/*
|
|
|
|
* make _sure_ it's the right size;
|
|
|
|
* if too short, it may be a weird
|
|
|
|
* (unknown/undefined) format
|
|
|
|
*/
|
|
|
|
if (tuple.length != (tmp_count*5 + 1)) {
|
|
|
|
DPRINTF((" bogus length %d\n",
|
|
|
|
tuple.length));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* sanity check for a programming
|
|
|
|
* error which is difficult to find
|
|
|
|
* when debugging.
|
|
|
|
*/
|
|
|
|
if (tmp_count >
|
|
|
|
howmany(sizeof mfc, sizeof mfc[0]))
|
|
|
|
panic("CISTPL_LONGLINK_MFC mfc "
|
|
|
|
"count would blow stack");
|
|
|
|
mfc_count = tmp_count;
|
1999-10-26 06:52:31 +00:00
|
|
|
for (i = 0; i < mfc_count; i++) {
|
|
|
|
mfc[i].common =
|
|
|
|
(pccard_tuple_read_1(&tuple,
|
|
|
|
1 + 5 * i) ==
|
|
|
|
PCCARD_MFC_MEM_COMMON) ?
|
|
|
|
1 : 0;
|
|
|
|
mfc[i].addr =
|
|
|
|
pccard_tuple_read_4(&tuple,
|
|
|
|
1 + 5 * i + 1);
|
2009-02-05 23:51:11 +00:00
|
|
|
DPRINTF((" %s:%#lx",
|
1999-10-26 06:52:31 +00:00
|
|
|
mfc[i].common ? "common" :
|
|
|
|
"attr", mfc[i].addr));
|
|
|
|
}
|
|
|
|
DPRINTF(("\n"));
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* for LONGLINK_MFC, fall through to the
|
|
|
|
* function. This tuple has structural and
|
|
|
|
* semantic content.
|
|
|
|
*/
|
|
|
|
default:
|
|
|
|
{
|
Add a much-requested feature: The ability for pccard attachments to
scan the CIS for interesting tuples. 95% of what can be obtained from
the CIS is harvested by the pccard layer and presented to the user in
standard function calls. However, there are special needs at times
where the standard stuff doesn't suffice. This is for those special
cases.
CARD_SCAN_CIS(device_get_parent(dev), function, argp)
scans the CIS of the card, passing each tuple to function with
the tuple and argp as its arguments. Returning 0 continues the scan,
while returning 1 terminates the scan. The value of the last
invocation of function is returned from this function.
int (*pccard_scan_t)(struct pccard_tuple *tuple, void *argp)
function called for each tuple. Elements of the CIS tuple can be
read with pccard_tuple_read_{1,2,3,4,n}(). You are reading
the actual tuple memory each time, in case your card has
registers in the CIS.
# I suppose these things should be documented in pccard(4) or something like
# that.
# I plan on unifying cardbus CIS support in a similar way.
Approved by: re (scottl)
2005-07-01 03:40:28 +00:00
|
|
|
if ((*fct)(&tuple, arg)) {
|
1999-10-26 06:52:31 +00:00
|
|
|
ret = 1;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
} /* switch */
|
|
|
|
#ifdef PCCARDCISDEBUG
|
|
|
|
/* print the tuple */
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2009-02-05 23:51:11 +00:00
|
|
|
DPRINTF((" %#02x %#02x", tuple.code,
|
1999-10-26 06:52:31 +00:00
|
|
|
tuple.length));
|
|
|
|
|
|
|
|
for (i = 0; i < tuple.length; i++) {
|
2009-02-05 23:51:11 +00:00
|
|
|
DPRINTF((" %#02x",
|
1999-10-26 06:52:31 +00:00
|
|
|
pccard_tuple_read_1(&tuple, i)));
|
|
|
|
if ((i % 16) == 13)
|
|
|
|
DPRINTF(("\n"));
|
|
|
|
}
|
2001-12-04 13:48:16 +00:00
|
|
|
|
1999-10-26 06:52:31 +00:00
|
|
|
if ((i % 16) != 14)
|
|
|
|
DPRINTF(("\n"));
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
/* skip to the next tuple */
|
|
|
|
tuple.ptr += 2 + tuple.length;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* the chain is done. Clean up and move onto the next one,
|
|
|
|
* if any. The loop is here in the case that there is an MFC
|
|
|
|
* card with no longlink (which defaults to existing, == 0).
|
|
|
|
* In general, this means that if one pointer fails, it will
|
|
|
|
* try the next one, instead of just bailing.
|
|
|
|
*/
|
|
|
|
while (1) {
|
|
|
|
if (longlink_present) {
|
2005-09-13 17:56:36 +00:00
|
|
|
CARD_SET_RES_FLAGS(bus, dev, SYS_RES_MEMORY,
|
|
|
|
rid, longlink_common ?
|
2002-03-29 08:05:39 +00:00
|
|
|
PCCARD_A_MEM_COM : PCCARD_A_MEM_ATTR);
|
2009-02-05 23:51:11 +00:00
|
|
|
DPRINTF(("cis mem map %#x\n",
|
1999-10-26 06:52:31 +00:00
|
|
|
(unsigned int) tuple.memh));
|
|
|
|
tuple.mult = longlink_common ? 1 : 2;
|
2002-03-29 08:05:39 +00:00
|
|
|
tuple.ptr = longlink_addr;
|
1999-10-26 06:52:31 +00:00
|
|
|
longlink_present = 0;
|
|
|
|
longlink_common = 1;
|
|
|
|
longlink_addr = 0;
|
|
|
|
} else if (mfc_count && (mfc_index < mfc_count)) {
|
2005-09-13 17:56:36 +00:00
|
|
|
CARD_SET_RES_FLAGS(bus, dev, SYS_RES_MEMORY,
|
|
|
|
rid, mfc[mfc_index].common ?
|
|
|
|
PCCARD_A_MEM_COM : PCCARD_A_MEM_ATTR);
|
2009-02-05 23:51:11 +00:00
|
|
|
DPRINTF(("cis mem map %#x\n",
|
1999-10-26 06:52:31 +00:00
|
|
|
(unsigned int) tuple.memh));
|
|
|
|
/* set parse state, and point at the next one */
|
|
|
|
tuple.mult = mfc[mfc_index].common ? 1 : 2;
|
2002-03-29 08:05:39 +00:00
|
|
|
tuple.ptr = mfc[mfc_index].addr;
|
1999-10-26 06:52:31 +00:00
|
|
|
mfc_index++;
|
|
|
|
} else {
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* make sure that the link is valid */
|
|
|
|
tuple.code = pccard_cis_read_1(&tuple, tuple.ptr);
|
2003-10-07 03:33:54 +00:00
|
|
|
if (tuple.code != CISTPL_LINKTARGET) {
|
1999-10-26 06:52:31 +00:00
|
|
|
DPRINTF(("CISTPL_LINKTARGET expected, "
|
2009-02-05 23:51:11 +00:00
|
|
|
"code %#02x observed\n", tuple.code));
|
1999-10-26 06:52:31 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
tuple.length = pccard_cis_read_1(&tuple, tuple.ptr + 1);
|
|
|
|
if (tuple.length < 3) {
|
|
|
|
DPRINTF(("CISTPL_LINKTARGET too short %d\n",
|
|
|
|
tuple.length));
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if ((pccard_tuple_read_1(&tuple, 0) != 'C') ||
|
|
|
|
(pccard_tuple_read_1(&tuple, 1) != 'I') ||
|
|
|
|
(pccard_tuple_read_1(&tuple, 2) != 'S')) {
|
|
|
|
DPRINTF(("CISTPL_LINKTARGET magic "
|
|
|
|
"%02x%02x%02x incorrect\n",
|
|
|
|
pccard_tuple_read_1(&tuple, 0),
|
|
|
|
pccard_tuple_read_1(&tuple, 1),
|
|
|
|
pccard_tuple_read_1(&tuple, 2)));
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
tuple.ptr += 2 + tuple.length;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
done:
|
2000-01-10 06:58:17 +00:00
|
|
|
bus_release_resource(dev, SYS_RES_MEMORY, rid, res);
|
1999-10-26 06:52:31 +00:00
|
|
|
|
|
|
|
return (ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* XXX this is incredibly verbose. Not sure what trt is */
|
|
|
|
|
|
|
|
void
|
|
|
|
pccard_print_cis(device_t dev)
|
|
|
|
{
|
2000-08-19 19:22:04 +00:00
|
|
|
struct pccard_softc *sc = PCCARD_SOFTC(dev);
|
1999-10-26 06:52:31 +00:00
|
|
|
struct pccard_card *card = &sc->card;
|
|
|
|
struct pccard_function *pf;
|
|
|
|
struct pccard_config_entry *cfe;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
device_printf(dev, "CIS version ");
|
|
|
|
if (card->cis1_major == 4) {
|
|
|
|
if (card->cis1_minor == 0)
|
|
|
|
printf("PCCARD 1.0\n");
|
|
|
|
else if (card->cis1_minor == 1)
|
|
|
|
printf("PCCARD 2.0 or 2.1\n");
|
|
|
|
} else if (card->cis1_major >= 5)
|
|
|
|
printf("PC Card Standard %d.%d\n", card->cis1_major, card->cis1_minor);
|
|
|
|
else
|
|
|
|
printf("unknown (major=%d, minor=%d)\n",
|
|
|
|
card->cis1_major, card->cis1_minor);
|
|
|
|
|
|
|
|
device_printf(dev, "CIS info: ");
|
|
|
|
for (i = 0; i < 4; i++) {
|
|
|
|
if (card->cis1_info[i] == NULL)
|
|
|
|
break;
|
|
|
|
if (i)
|
|
|
|
printf(", ");
|
|
|
|
printf("%s", card->cis1_info[i]);
|
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
|
2009-02-05 23:51:11 +00:00
|
|
|
device_printf(dev, "Manufacturer code %#x, product %#x\n",
|
1999-10-26 06:52:31 +00:00
|
|
|
card->manufacturer, card->product);
|
|
|
|
|
|
|
|
STAILQ_FOREACH(pf, &card->pf_head, pf_list) {
|
|
|
|
device_printf(dev, "function %d: ", pf->number);
|
|
|
|
|
|
|
|
switch (pf->function) {
|
|
|
|
case PCCARD_FUNCTION_UNSPEC:
|
|
|
|
printf("unspecified");
|
|
|
|
break;
|
|
|
|
case PCCARD_FUNCTION_MULTIFUNCTION:
|
|
|
|
printf("multi-function");
|
|
|
|
break;
|
|
|
|
case PCCARD_FUNCTION_MEMORY:
|
|
|
|
printf("memory");
|
|
|
|
break;
|
|
|
|
case PCCARD_FUNCTION_SERIAL:
|
|
|
|
printf("serial port");
|
|
|
|
break;
|
|
|
|
case PCCARD_FUNCTION_PARALLEL:
|
|
|
|
printf("parallel port");
|
|
|
|
break;
|
|
|
|
case PCCARD_FUNCTION_DISK:
|
|
|
|
printf("fixed disk");
|
|
|
|
break;
|
|
|
|
case PCCARD_FUNCTION_VIDEO:
|
|
|
|
printf("video adapter");
|
|
|
|
break;
|
|
|
|
case PCCARD_FUNCTION_NETWORK:
|
|
|
|
printf("network adapter");
|
|
|
|
break;
|
|
|
|
case PCCARD_FUNCTION_AIMS:
|
|
|
|
printf("auto incrementing mass storage");
|
|
|
|
break;
|
|
|
|
case PCCARD_FUNCTION_SCSI:
|
|
|
|
printf("SCSI bridge");
|
|
|
|
break;
|
|
|
|
case PCCARD_FUNCTION_SECURITY:
|
|
|
|
printf("Security services");
|
|
|
|
break;
|
|
|
|
case PCCARD_FUNCTION_INSTRUMENT:
|
|
|
|
printf("Instrument");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
printf("unknown (%d)", pf->function);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2009-02-05 23:51:11 +00:00
|
|
|
printf(", ccr addr %#x mask %#x\n", pf->ccr_base, pf->ccr_mask);
|
1999-10-26 06:52:31 +00:00
|
|
|
|
|
|
|
STAILQ_FOREACH(cfe, &pf->cfe_head, cfe_list) {
|
|
|
|
device_printf(dev, "function %d, config table entry "
|
|
|
|
"%d: ", pf->number, cfe->number);
|
|
|
|
|
|
|
|
switch (cfe->iftype) {
|
|
|
|
case PCCARD_IFTYPE_MEMORY:
|
|
|
|
printf("memory card");
|
|
|
|
break;
|
|
|
|
case PCCARD_IFTYPE_IO:
|
|
|
|
printf("I/O card");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
printf("card type unknown");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2009-02-05 23:51:11 +00:00
|
|
|
printf("; irq mask %#x", cfe->irqmask);
|
1999-10-26 06:52:31 +00:00
|
|
|
|
|
|
|
if (cfe->num_iospace) {
|
2009-02-05 23:51:11 +00:00
|
|
|
printf("; iomask %#lx, iospace", cfe->iomask);
|
1999-10-26 06:52:31 +00:00
|
|
|
|
1999-11-28 05:49:27 +00:00
|
|
|
for (i = 0; i < cfe->num_iospace; i++) {
|
Use uintmax_t (typedef'd to rman_res_t type) for rman ranges.
On some architectures, u_long isn't large enough for resource definitions.
Particularly, powerpc and arm allow 36-bit (or larger) physical addresses, but
type `long' is only 32-bit. This extends rman's resources to uintmax_t. With
this change, any resource can feasibly be placed anywhere in physical memory
(within the constraints of the driver).
Why uintmax_t and not something machine dependent, or uint64_t? Though it's
possible for uintmax_t to grow, it's highly unlikely it will become 128-bit on
32-bit architectures. 64-bit architectures should have plenty of RAM to absorb
the increase on resource sizes if and when this occurs, and the number of
resources on memory-constrained systems should be sufficiently small as to not
pose a drastic overhead. That being said, uintmax_t was chosen for source
clarity. If it's specified as uint64_t, all printf()-like calls would either
need casts to uintmax_t, or be littered with PRI*64 macros. Casts to uintmax_t
aren't horrible, but it would also bake into the API for
resource_list_print_type() either a hidden assumption that entries get cast to
uintmax_t for printing, or these calls would need the PRI*64 macros. Since
source code is meant to be read more often than written, I chose the clearest
path of simply using uintmax_t.
Tested on a PowerPC p5020-based board, which places all device resources in
0xfxxxxxxxx, and has 8GB RAM.
Regression tested on qemu-system-i386
Regression tested on qemu-system-mips (malta profile)
Tested PAE and devinfo on virtualbox (live CD)
Special thanks to bz for his testing on ARM.
Reviewed By: bz, jhb (previous)
Relnotes: Yes
Sponsored by: Alex Perez/Inertial Computing
Differential Revision: https://reviews.freebsd.org/D4544
2016-03-18 01:28:41 +00:00
|
|
|
printf(" %#jx", cfe->iospace[i].start);
|
1999-11-28 05:49:27 +00:00
|
|
|
if (cfe->iospace[i].length)
|
Use uintmax_t (typedef'd to rman_res_t type) for rman ranges.
On some architectures, u_long isn't large enough for resource definitions.
Particularly, powerpc and arm allow 36-bit (or larger) physical addresses, but
type `long' is only 32-bit. This extends rman's resources to uintmax_t. With
this change, any resource can feasibly be placed anywhere in physical memory
(within the constraints of the driver).
Why uintmax_t and not something machine dependent, or uint64_t? Though it's
possible for uintmax_t to grow, it's highly unlikely it will become 128-bit on
32-bit architectures. 64-bit architectures should have plenty of RAM to absorb
the increase on resource sizes if and when this occurs, and the number of
resources on memory-constrained systems should be sufficiently small as to not
pose a drastic overhead. That being said, uintmax_t was chosen for source
clarity. If it's specified as uint64_t, all printf()-like calls would either
need casts to uintmax_t, or be littered with PRI*64 macros. Casts to uintmax_t
aren't horrible, but it would also bake into the API for
resource_list_print_type() either a hidden assumption that entries get cast to
uintmax_t for printing, or these calls would need the PRI*64 macros. Since
source code is meant to be read more often than written, I chose the clearest
path of simply using uintmax_t.
Tested on a PowerPC p5020-based board, which places all device resources in
0xfxxxxxxxx, and has 8GB RAM.
Regression tested on qemu-system-i386
Regression tested on qemu-system-mips (malta profile)
Tested PAE and devinfo on virtualbox (live CD)
Special thanks to bz for his testing on ARM.
Reviewed By: bz, jhb (previous)
Relnotes: Yes
Sponsored by: Alex Perez/Inertial Computing
Differential Revision: https://reviews.freebsd.org/D4544
2016-03-18 01:28:41 +00:00
|
|
|
printf("-%#jx",
|
1999-11-28 05:49:27 +00:00
|
|
|
cfe->iospace[i].start +
|
|
|
|
cfe->iospace[i].length - 1);
|
|
|
|
}
|
1999-10-26 06:52:31 +00:00
|
|
|
}
|
|
|
|
if (cfe->num_memspace) {
|
|
|
|
printf("; memspace");
|
|
|
|
|
1999-11-28 05:49:27 +00:00
|
|
|
for (i = 0; i < cfe->num_memspace; i++) {
|
Use uintmax_t (typedef'd to rman_res_t type) for rman ranges.
On some architectures, u_long isn't large enough for resource definitions.
Particularly, powerpc and arm allow 36-bit (or larger) physical addresses, but
type `long' is only 32-bit. This extends rman's resources to uintmax_t. With
this change, any resource can feasibly be placed anywhere in physical memory
(within the constraints of the driver).
Why uintmax_t and not something machine dependent, or uint64_t? Though it's
possible for uintmax_t to grow, it's highly unlikely it will become 128-bit on
32-bit architectures. 64-bit architectures should have plenty of RAM to absorb
the increase on resource sizes if and when this occurs, and the number of
resources on memory-constrained systems should be sufficiently small as to not
pose a drastic overhead. That being said, uintmax_t was chosen for source
clarity. If it's specified as uint64_t, all printf()-like calls would either
need casts to uintmax_t, or be littered with PRI*64 macros. Casts to uintmax_t
aren't horrible, but it would also bake into the API for
resource_list_print_type() either a hidden assumption that entries get cast to
uintmax_t for printing, or these calls would need the PRI*64 macros. Since
source code is meant to be read more often than written, I chose the clearest
path of simply using uintmax_t.
Tested on a PowerPC p5020-based board, which places all device resources in
0xfxxxxxxxx, and has 8GB RAM.
Regression tested on qemu-system-i386
Regression tested on qemu-system-mips (malta profile)
Tested PAE and devinfo on virtualbox (live CD)
Special thanks to bz for his testing on ARM.
Reviewed By: bz, jhb (previous)
Relnotes: Yes
Sponsored by: Alex Perez/Inertial Computing
Differential Revision: https://reviews.freebsd.org/D4544
2016-03-18 01:28:41 +00:00
|
|
|
printf(" %#jx",
|
1999-11-28 05:49:27 +00:00
|
|
|
cfe->memspace[i].cardaddr);
|
|
|
|
if (cfe->memspace[i].length)
|
Use uintmax_t (typedef'd to rman_res_t type) for rman ranges.
On some architectures, u_long isn't large enough for resource definitions.
Particularly, powerpc and arm allow 36-bit (or larger) physical addresses, but
type `long' is only 32-bit. This extends rman's resources to uintmax_t. With
this change, any resource can feasibly be placed anywhere in physical memory
(within the constraints of the driver).
Why uintmax_t and not something machine dependent, or uint64_t? Though it's
possible for uintmax_t to grow, it's highly unlikely it will become 128-bit on
32-bit architectures. 64-bit architectures should have plenty of RAM to absorb
the increase on resource sizes if and when this occurs, and the number of
resources on memory-constrained systems should be sufficiently small as to not
pose a drastic overhead. That being said, uintmax_t was chosen for source
clarity. If it's specified as uint64_t, all printf()-like calls would either
need casts to uintmax_t, or be littered with PRI*64 macros. Casts to uintmax_t
aren't horrible, but it would also bake into the API for
resource_list_print_type() either a hidden assumption that entries get cast to
uintmax_t for printing, or these calls would need the PRI*64 macros. Since
source code is meant to be read more often than written, I chose the clearest
path of simply using uintmax_t.
Tested on a PowerPC p5020-based board, which places all device resources in
0xfxxxxxxxx, and has 8GB RAM.
Regression tested on qemu-system-i386
Regression tested on qemu-system-mips (malta profile)
Tested PAE and devinfo on virtualbox (live CD)
Special thanks to bz for his testing on ARM.
Reviewed By: bz, jhb (previous)
Relnotes: Yes
Sponsored by: Alex Perez/Inertial Computing
Differential Revision: https://reviews.freebsd.org/D4544
2016-03-18 01:28:41 +00:00
|
|
|
printf("-%#jx",
|
1999-11-28 05:49:27 +00:00
|
|
|
cfe->memspace[i].cardaddr +
|
|
|
|
cfe->memspace[i].length - 1);
|
|
|
|
if (cfe->memspace[i].hostaddr)
|
Use uintmax_t (typedef'd to rman_res_t type) for rman ranges.
On some architectures, u_long isn't large enough for resource definitions.
Particularly, powerpc and arm allow 36-bit (or larger) physical addresses, but
type `long' is only 32-bit. This extends rman's resources to uintmax_t. With
this change, any resource can feasibly be placed anywhere in physical memory
(within the constraints of the driver).
Why uintmax_t and not something machine dependent, or uint64_t? Though it's
possible for uintmax_t to grow, it's highly unlikely it will become 128-bit on
32-bit architectures. 64-bit architectures should have plenty of RAM to absorb
the increase on resource sizes if and when this occurs, and the number of
resources on memory-constrained systems should be sufficiently small as to not
pose a drastic overhead. That being said, uintmax_t was chosen for source
clarity. If it's specified as uint64_t, all printf()-like calls would either
need casts to uintmax_t, or be littered with PRI*64 macros. Casts to uintmax_t
aren't horrible, but it would also bake into the API for
resource_list_print_type() either a hidden assumption that entries get cast to
uintmax_t for printing, or these calls would need the PRI*64 macros. Since
source code is meant to be read more often than written, I chose the clearest
path of simply using uintmax_t.
Tested on a PowerPC p5020-based board, which places all device resources in
0xfxxxxxxxx, and has 8GB RAM.
Regression tested on qemu-system-i386
Regression tested on qemu-system-mips (malta profile)
Tested PAE and devinfo on virtualbox (live CD)
Special thanks to bz for his testing on ARM.
Reviewed By: bz, jhb (previous)
Relnotes: Yes
Sponsored by: Alex Perez/Inertial Computing
Differential Revision: https://reviews.freebsd.org/D4544
2016-03-18 01:28:41 +00:00
|
|
|
printf("@%#jx",
|
1999-11-28 05:49:27 +00:00
|
|
|
cfe->memspace[i].hostaddr);
|
|
|
|
}
|
1999-10-26 06:52:31 +00:00
|
|
|
}
|
|
|
|
if (cfe->maxtwins)
|
|
|
|
printf("; maxtwins %d", cfe->maxtwins);
|
|
|
|
|
|
|
|
printf(";");
|
|
|
|
|
|
|
|
if (cfe->flags & PCCARD_CFE_MWAIT_REQUIRED)
|
|
|
|
printf(" mwait_required");
|
|
|
|
if (cfe->flags & PCCARD_CFE_RDYBSY_ACTIVE)
|
|
|
|
printf(" rdybsy_active");
|
|
|
|
if (cfe->flags & PCCARD_CFE_WP_ACTIVE)
|
|
|
|
printf(" wp_active");
|
|
|
|
if (cfe->flags & PCCARD_CFE_BVD_ACTIVE)
|
|
|
|
printf(" bvd_active");
|
|
|
|
if (cfe->flags & PCCARD_CFE_IO8)
|
|
|
|
printf(" io8");
|
|
|
|
if (cfe->flags & PCCARD_CFE_IO16)
|
|
|
|
printf(" io16");
|
|
|
|
if (cfe->flags & PCCARD_CFE_IRQSHARE)
|
|
|
|
printf(" irqshare");
|
|
|
|
if (cfe->flags & PCCARD_CFE_IRQPULSE)
|
|
|
|
printf(" irqpulse");
|
|
|
|
if (cfe->flags & PCCARD_CFE_IRQLEVEL)
|
|
|
|
printf(" irqlevel");
|
|
|
|
if (cfe->flags & PCCARD_CFE_POWERDOWN)
|
|
|
|
printf(" powerdown");
|
|
|
|
if (cfe->flags & PCCARD_CFE_READONLY)
|
|
|
|
printf(" readonly");
|
|
|
|
if (cfe->flags & PCCARD_CFE_AUDIO)
|
|
|
|
printf(" audio");
|
|
|
|
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (card->error)
|
|
|
|
device_printf(dev, "%d errors found while parsing CIS\n",
|
|
|
|
card->error);
|
|
|
|
}
|
|
|
|
|
Add a much-requested feature: The ability for pccard attachments to
scan the CIS for interesting tuples. 95% of what can be obtained from
the CIS is harvested by the pccard layer and presented to the user in
standard function calls. However, there are special needs at times
where the standard stuff doesn't suffice. This is for those special
cases.
CARD_SCAN_CIS(device_get_parent(dev), function, argp)
scans the CIS of the card, passing each tuple to function with
the tuple and argp as its arguments. Returning 0 continues the scan,
while returning 1 terminates the scan. The value of the last
invocation of function is returned from this function.
int (*pccard_scan_t)(struct pccard_tuple *tuple, void *argp)
function called for each tuple. Elements of the CIS tuple can be
read with pccard_tuple_read_{1,2,3,4,n}(). You are reading
the actual tuple memory each time, in case your card has
registers in the CIS.
# I suppose these things should be documented in pccard(4) or something like
# that.
# I plan on unifying cardbus CIS support in a similar way.
Approved by: re (scottl)
2005-07-01 03:40:28 +00:00
|
|
|
static int
|
2005-07-01 15:52:50 +00:00
|
|
|
pccard_parse_cis_tuple(const struct pccard_tuple *tuple, void *arg)
|
1999-10-26 06:52:31 +00:00
|
|
|
{
|
|
|
|
/* most of these are educated guesses */
|
|
|
|
static struct pccard_config_entry init_cfe = {
|
|
|
|
-1, PCCARD_CFE_RDYBSY_ACTIVE | PCCARD_CFE_WP_ACTIVE |
|
|
|
|
PCCARD_CFE_BVD_ACTIVE, PCCARD_IFTYPE_MEMORY,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct cis_state *state = arg;
|
|
|
|
|
|
|
|
switch (tuple->code) {
|
2003-10-07 03:33:54 +00:00
|
|
|
case CISTPL_END:
|
1999-10-26 06:52:31 +00:00
|
|
|
/* if we've seen a LONGLINK_MFC, and this is the first
|
|
|
|
* END after it, reset the function list.
|
|
|
|
*
|
|
|
|
* XXX This might also be the right place to start a
|
|
|
|
* new function, but that assumes that a function
|
|
|
|
* definition never crosses any longlink, and I'm not
|
|
|
|
* sure about that. This is probably safe for MFC
|
|
|
|
* cards, but what we have now isn't broken, so I'd
|
|
|
|
* rather not change it.
|
|
|
|
*/
|
|
|
|
if (state->gotmfc == 1) {
|
|
|
|
struct pccard_function *pf, *pfnext;
|
|
|
|
|
|
|
|
for (pf = STAILQ_FIRST(&state->card->pf_head);
|
|
|
|
pf != NULL; pf = pfnext) {
|
|
|
|
pfnext = STAILQ_NEXT(pf, pf_list);
|
|
|
|
free(pf, M_DEVBUF);
|
|
|
|
}
|
|
|
|
|
|
|
|
STAILQ_INIT(&state->card->pf_head);
|
|
|
|
|
|
|
|
state->count = 0;
|
|
|
|
state->gotmfc = 2;
|
|
|
|
state->pf = NULL;
|
|
|
|
}
|
|
|
|
break;
|
2003-10-07 03:33:54 +00:00
|
|
|
case CISTPL_LONGLINK_MFC:
|
1999-10-26 06:52:31 +00:00
|
|
|
/*
|
|
|
|
* this tuple's structure was dealt with in scan_cis. here,
|
|
|
|
* record the fact that the MFC tuple was seen, so that
|
|
|
|
* functions declared before the MFC link can be cleaned
|
|
|
|
* up.
|
|
|
|
*/
|
|
|
|
state->gotmfc = 1;
|
|
|
|
break;
|
|
|
|
#ifdef PCCARDCISDEBUG
|
2003-10-07 03:33:54 +00:00
|
|
|
case CISTPL_DEVICE:
|
|
|
|
case CISTPL_DEVICE_A:
|
1999-10-26 06:52:31 +00:00
|
|
|
{
|
|
|
|
u_int reg, dtype, dspeed;
|
|
|
|
|
|
|
|
reg = pccard_tuple_read_1(tuple, 0);
|
|
|
|
dtype = reg & PCCARD_DTYPE_MASK;
|
|
|
|
dspeed = reg & PCCARD_DSPEED_MASK;
|
|
|
|
|
|
|
|
DPRINTF(("CISTPL_DEVICE%s type=",
|
2003-10-07 03:33:54 +00:00
|
|
|
(tuple->code == CISTPL_DEVICE) ? "" : "_A"));
|
1999-10-26 06:52:31 +00:00
|
|
|
switch (dtype) {
|
|
|
|
case PCCARD_DTYPE_NULL:
|
|
|
|
DPRINTF(("null"));
|
|
|
|
break;
|
|
|
|
case PCCARD_DTYPE_ROM:
|
|
|
|
DPRINTF(("rom"));
|
|
|
|
break;
|
|
|
|
case PCCARD_DTYPE_OTPROM:
|
|
|
|
DPRINTF(("otprom"));
|
|
|
|
break;
|
|
|
|
case PCCARD_DTYPE_EPROM:
|
|
|
|
DPRINTF(("eprom"));
|
|
|
|
break;
|
|
|
|
case PCCARD_DTYPE_EEPROM:
|
|
|
|
DPRINTF(("eeprom"));
|
|
|
|
break;
|
|
|
|
case PCCARD_DTYPE_FLASH:
|
|
|
|
DPRINTF(("flash"));
|
|
|
|
break;
|
|
|
|
case PCCARD_DTYPE_SRAM:
|
|
|
|
DPRINTF(("sram"));
|
|
|
|
break;
|
|
|
|
case PCCARD_DTYPE_DRAM:
|
|
|
|
DPRINTF(("dram"));
|
|
|
|
break;
|
|
|
|
case PCCARD_DTYPE_FUNCSPEC:
|
|
|
|
DPRINTF(("funcspec"));
|
|
|
|
break;
|
|
|
|
case PCCARD_DTYPE_EXTEND:
|
|
|
|
DPRINTF(("extend"));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
DPRINTF(("reserved"));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
DPRINTF((" speed="));
|
|
|
|
switch (dspeed) {
|
|
|
|
case PCCARD_DSPEED_NULL:
|
|
|
|
DPRINTF(("null"));
|
|
|
|
break;
|
|
|
|
case PCCARD_DSPEED_250NS:
|
|
|
|
DPRINTF(("250ns"));
|
|
|
|
break;
|
|
|
|
case PCCARD_DSPEED_200NS:
|
|
|
|
DPRINTF(("200ns"));
|
|
|
|
break;
|
|
|
|
case PCCARD_DSPEED_150NS:
|
|
|
|
DPRINTF(("150ns"));
|
|
|
|
break;
|
|
|
|
case PCCARD_DSPEED_100NS:
|
|
|
|
DPRINTF(("100ns"));
|
|
|
|
break;
|
|
|
|
case PCCARD_DSPEED_EXT:
|
|
|
|
DPRINTF(("ext"));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
DPRINTF(("reserved"));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
DPRINTF(("\n"));
|
|
|
|
break;
|
|
|
|
#endif
|
2003-10-07 03:33:54 +00:00
|
|
|
case CISTPL_VERS_1:
|
1999-10-26 06:52:31 +00:00
|
|
|
if (tuple->length < 6) {
|
|
|
|
DPRINTF(("CISTPL_VERS_1 too short %d\n",
|
|
|
|
tuple->length));
|
|
|
|
break;
|
|
|
|
} {
|
|
|
|
int start, i, ch, count;
|
|
|
|
|
|
|
|
state->card->cis1_major = pccard_tuple_read_1(tuple, 0);
|
|
|
|
state->card->cis1_minor = pccard_tuple_read_1(tuple, 1);
|
|
|
|
|
|
|
|
for (count = 0, start = 0, i = 0;
|
|
|
|
(count < 4) && ((i + 4) < 256); i++) {
|
|
|
|
ch = pccard_tuple_read_1(tuple, 2 + i);
|
|
|
|
if (ch == 0xff)
|
|
|
|
break;
|
|
|
|
state->card->cis1_info_buf[i] = ch;
|
|
|
|
if (ch == 0) {
|
|
|
|
state->card->cis1_info[count] =
|
|
|
|
state->card->cis1_info_buf + start;
|
|
|
|
start = i + 1;
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
DPRINTF(("CISTPL_VERS_1\n"));
|
|
|
|
}
|
|
|
|
break;
|
2003-10-07 03:33:54 +00:00
|
|
|
case CISTPL_MANFID:
|
1999-10-26 06:52:31 +00:00
|
|
|
if (tuple->length < 4) {
|
|
|
|
DPRINTF(("CISTPL_MANFID too short %d\n",
|
|
|
|
tuple->length));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
state->card->manufacturer = pccard_tuple_read_2(tuple, 0);
|
|
|
|
state->card->product = pccard_tuple_read_2(tuple, 2);
|
2002-02-20 14:30:46 +00:00
|
|
|
/*
|
2002-10-07 06:35:04 +00:00
|
|
|
* This is for xe driver. But not limited to that driver.
|
2002-02-20 14:30:46 +00:00
|
|
|
* In PC Card Standard,
|
|
|
|
* Manufacturer ID: 2byte.
|
2002-10-07 06:35:04 +00:00
|
|
|
* Product ID: typically 2bytes, but there's no limit on its
|
|
|
|
* size. prodext is a two byte field, so maybe we should
|
|
|
|
* also handle the '6' case. So far no cards have surfaced
|
|
|
|
* with a length of '6'.
|
2002-02-20 14:30:46 +00:00
|
|
|
*/
|
2005-07-13 14:59:06 +00:00
|
|
|
if (tuple->length == 5 )
|
2002-02-20 14:30:46 +00:00
|
|
|
state->card->prodext = pccard_tuple_read_1(tuple, 4);
|
1999-10-26 06:52:31 +00:00
|
|
|
DPRINTF(("CISTPL_MANFID\n"));
|
|
|
|
break;
|
2003-10-07 03:33:54 +00:00
|
|
|
case CISTPL_FUNCID:
|
1999-10-26 06:52:31 +00:00
|
|
|
if (tuple->length < 1) {
|
|
|
|
DPRINTF(("CISTPL_FUNCID too short %d\n",
|
|
|
|
tuple->length));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if ((state->pf == NULL) || (state->gotmfc == 2)) {
|
|
|
|
state->pf = malloc(sizeof(*state->pf), M_DEVBUF,
|
2000-10-29 16:29:05 +00:00
|
|
|
M_NOWAIT | M_ZERO);
|
1999-10-26 06:52:31 +00:00
|
|
|
state->pf->number = state->count++;
|
|
|
|
state->pf->last_config_index = -1;
|
|
|
|
STAILQ_INIT(&state->pf->cfe_head);
|
|
|
|
|
|
|
|
STAILQ_INSERT_TAIL(&state->card->pf_head, state->pf,
|
|
|
|
pf_list);
|
|
|
|
}
|
|
|
|
state->pf->function = pccard_tuple_read_1(tuple, 0);
|
|
|
|
|
|
|
|
DPRINTF(("CISTPL_FUNCID\n"));
|
|
|
|
break;
|
2003-10-07 03:33:54 +00:00
|
|
|
case CISTPL_FUNCE:
|
2001-09-02 06:37:41 +00:00
|
|
|
if (state->pf == NULL || state->pf->function <= 0) {
|
|
|
|
DPRINTF(("CISTPL_FUNCE is not followed by "
|
|
|
|
"valid CISTPL_FUNCID\n"));
|
|
|
|
break;
|
|
|
|
}
|
2005-07-01 15:52:50 +00:00
|
|
|
if (tuple->length >= 2)
|
2001-09-02 06:37:41 +00:00
|
|
|
decode_funce(tuple, state->pf);
|
|
|
|
DPRINTF(("CISTPL_FUNCE\n"));
|
|
|
|
break;
|
2003-10-07 03:33:54 +00:00
|
|
|
case CISTPL_CONFIG:
|
1999-10-26 06:52:31 +00:00
|
|
|
if (tuple->length < 3) {
|
|
|
|
DPRINTF(("CISTPL_CONFIG too short %d\n",
|
|
|
|
tuple->length));
|
|
|
|
break;
|
|
|
|
} {
|
|
|
|
u_int reg, rasz, rmsz, rfsz;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
reg = pccard_tuple_read_1(tuple, 0);
|
|
|
|
rasz = 1 + ((reg & PCCARD_TPCC_RASZ_MASK) >>
|
|
|
|
PCCARD_TPCC_RASZ_SHIFT);
|
|
|
|
rmsz = 1 + ((reg & PCCARD_TPCC_RMSZ_MASK) >>
|
|
|
|
PCCARD_TPCC_RMSZ_SHIFT);
|
|
|
|
rfsz = ((reg & PCCARD_TPCC_RFSZ_MASK) >>
|
|
|
|
PCCARD_TPCC_RFSZ_SHIFT);
|
|
|
|
|
|
|
|
if (tuple->length < (rasz + rmsz + rfsz)) {
|
|
|
|
DPRINTF(("CISTPL_CONFIG (%d,%d,%d) too "
|
|
|
|
"short %d\n", rasz, rmsz, rfsz,
|
|
|
|
tuple->length));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (state->pf == NULL) {
|
|
|
|
state->pf = malloc(sizeof(*state->pf),
|
2000-10-29 16:29:05 +00:00
|
|
|
M_DEVBUF, M_NOWAIT | M_ZERO);
|
1999-10-26 06:52:31 +00:00
|
|
|
state->pf->number = state->count++;
|
|
|
|
state->pf->last_config_index = -1;
|
|
|
|
STAILQ_INIT(&state->pf->cfe_head);
|
|
|
|
|
|
|
|
STAILQ_INSERT_TAIL(&state->card->pf_head,
|
|
|
|
state->pf, pf_list);
|
|
|
|
|
|
|
|
state->pf->function = PCCARD_FUNCTION_UNSPEC;
|
|
|
|
}
|
|
|
|
state->pf->last_config_index =
|
|
|
|
pccard_tuple_read_1(tuple, 1);
|
|
|
|
|
|
|
|
state->pf->ccr_base = 0;
|
|
|
|
for (i = 0; i < rasz; i++)
|
|
|
|
state->pf->ccr_base |=
|
|
|
|
((pccard_tuple_read_1(tuple, 2 + i)) <<
|
|
|
|
(i * 8));
|
|
|
|
|
|
|
|
state->pf->ccr_mask = 0;
|
|
|
|
for (i = 0; i < rmsz; i++)
|
|
|
|
state->pf->ccr_mask |=
|
|
|
|
((pccard_tuple_read_1(tuple,
|
|
|
|
2 + rasz + i)) << (i * 8));
|
|
|
|
|
|
|
|
/* skip the reserved area and subtuples */
|
|
|
|
|
|
|
|
/* reset the default cfe for each cfe list */
|
|
|
|
state->temp_cfe = init_cfe;
|
|
|
|
state->default_cfe = &state->temp_cfe;
|
|
|
|
}
|
|
|
|
DPRINTF(("CISTPL_CONFIG\n"));
|
|
|
|
break;
|
2003-10-07 03:33:54 +00:00
|
|
|
case CISTPL_CFTABLE_ENTRY:
|
1999-10-26 06:52:31 +00:00
|
|
|
{
|
2008-06-01 20:55:34 +00:00
|
|
|
int idx, i;
|
1999-10-26 06:52:31 +00:00
|
|
|
u_int reg, reg2;
|
|
|
|
u_int intface, def, num;
|
|
|
|
u_int power, timing, iospace, irq, memspace, misc;
|
|
|
|
struct pccard_config_entry *cfe;
|
|
|
|
|
|
|
|
idx = 0;
|
|
|
|
|
2008-06-01 20:55:34 +00:00
|
|
|
reg = pccard_tuple_read_1(tuple, idx++);
|
1999-10-26 06:52:31 +00:00
|
|
|
intface = reg & PCCARD_TPCE_INDX_INTFACE;
|
|
|
|
def = reg & PCCARD_TPCE_INDX_DEFAULT;
|
|
|
|
num = reg & PCCARD_TPCE_INDX_NUM_MASK;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* this is a little messy. Some cards have only a
|
|
|
|
* cfentry with the default bit set. So, as we go
|
|
|
|
* through the list, we add new indexes to the queue,
|
|
|
|
* and keep a pointer to the last one with the
|
|
|
|
* default bit set. if we see a record with the same
|
|
|
|
* index, as the default, we stash the default and
|
|
|
|
* replace the queue entry. otherwise, we just add
|
|
|
|
* new entries to the queue, pointing the default ptr
|
|
|
|
* at them if the default bit is set. if we get to
|
|
|
|
* the end with the default pointer pointing at a
|
|
|
|
* record which hasn't had a matching index, that's
|
|
|
|
* ok; it just becomes a cfentry like any other.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* if the index in the cis differs from the default
|
|
|
|
* cis, create new entry in the queue and start it
|
|
|
|
* with the current default
|
|
|
|
*/
|
|
|
|
if (num != state->default_cfe->number) {
|
|
|
|
cfe = (struct pccard_config_entry *)
|
|
|
|
malloc(sizeof(*cfe), M_DEVBUF, M_NOWAIT);
|
2005-03-26 21:34:12 +00:00
|
|
|
if (cfe == NULL) {
|
|
|
|
DPRINTF(("no memory for config entry\n"));
|
|
|
|
goto abort_cfe;
|
|
|
|
}
|
1999-10-26 06:52:31 +00:00
|
|
|
*cfe = *state->default_cfe;
|
|
|
|
|
|
|
|
STAILQ_INSERT_TAIL(&state->pf->cfe_head,
|
|
|
|
cfe, cfe_list);
|
|
|
|
|
|
|
|
cfe->number = num;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* if the default bit is set in the cis, then
|
|
|
|
* point the new default at whatever is being
|
|
|
|
* filled in
|
|
|
|
*/
|
|
|
|
if (def)
|
|
|
|
state->default_cfe = cfe;
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* the cis index matches the default index,
|
|
|
|
* fill in the default cfentry. It is
|
|
|
|
* assumed that the cfdefault index is in the
|
|
|
|
* queue. For it to be otherwise, the cis
|
|
|
|
* index would have to be -1 (initial
|
|
|
|
* condition) which is not possible, or there
|
|
|
|
* would have to be a preceding cis entry
|
|
|
|
* which had the same cis index and had the
|
|
|
|
* default bit unset. Neither condition
|
|
|
|
* should happen. If it does, this cfentry
|
|
|
|
* is lost (written into temp space), which
|
|
|
|
* is an acceptable failure mode.
|
|
|
|
*/
|
|
|
|
|
|
|
|
cfe = state->default_cfe;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* if the cis entry does not have the default
|
|
|
|
* bit set, copy the default out of the way
|
|
|
|
* first.
|
|
|
|
*/
|
|
|
|
if (!def) {
|
|
|
|
state->temp_cfe = *state->default_cfe;
|
|
|
|
state->default_cfe = &state->temp_cfe;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (intface) {
|
2008-06-01 20:55:34 +00:00
|
|
|
reg = pccard_tuple_read_1(tuple, idx++);
|
2002-10-07 23:03:17 +00:00
|
|
|
cfe->flags &= ~(PCCARD_CFE_MWAIT_REQUIRED
|
|
|
|
| PCCARD_CFE_RDYBSY_ACTIVE
|
|
|
|
| PCCARD_CFE_WP_ACTIVE
|
|
|
|
| PCCARD_CFE_BVD_ACTIVE);
|
1999-10-26 06:52:31 +00:00
|
|
|
if (reg & PCCARD_TPCE_IF_MWAIT)
|
|
|
|
cfe->flags |= PCCARD_CFE_MWAIT_REQUIRED;
|
|
|
|
if (reg & PCCARD_TPCE_IF_RDYBSY)
|
|
|
|
cfe->flags |= PCCARD_CFE_RDYBSY_ACTIVE;
|
|
|
|
if (reg & PCCARD_TPCE_IF_WP)
|
|
|
|
cfe->flags |= PCCARD_CFE_WP_ACTIVE;
|
|
|
|
if (reg & PCCARD_TPCE_IF_BVD)
|
|
|
|
cfe->flags |= PCCARD_CFE_BVD_ACTIVE;
|
|
|
|
cfe->iftype = reg & PCCARD_TPCE_IF_IFTYPE;
|
|
|
|
}
|
2008-06-01 20:55:34 +00:00
|
|
|
reg = pccard_tuple_read_1(tuple, idx++);
|
1999-10-26 06:52:31 +00:00
|
|
|
|
|
|
|
power = reg & PCCARD_TPCE_FS_POWER_MASK;
|
|
|
|
timing = reg & PCCARD_TPCE_FS_TIMING;
|
|
|
|
iospace = reg & PCCARD_TPCE_FS_IOSPACE;
|
|
|
|
irq = reg & PCCARD_TPCE_FS_IRQ;
|
|
|
|
memspace = reg & PCCARD_TPCE_FS_MEMSPACE_MASK;
|
|
|
|
misc = reg & PCCARD_TPCE_FS_MISC;
|
|
|
|
|
|
|
|
if (power) {
|
|
|
|
/* skip over power, don't save */
|
|
|
|
/* for each parameter selection byte */
|
|
|
|
for (i = 0; i < power; i++) {
|
2008-06-01 20:55:34 +00:00
|
|
|
reg = pccard_tuple_read_1(tuple, idx++);
|
|
|
|
for (; reg; reg >>= 1)
|
|
|
|
{
|
|
|
|
/* set bit -> read */
|
|
|
|
if ((reg & 1) == 0)
|
|
|
|
continue;
|
|
|
|
/* skip over bytes */
|
|
|
|
do {
|
|
|
|
reg2 = pccard_tuple_read_1(tuple, idx++);
|
|
|
|
/*
|
|
|
|
* until non-extension
|
|
|
|
* byte
|
|
|
|
*/
|
|
|
|
} while (reg2 & 0x80);
|
1999-10-26 06:52:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (timing) {
|
|
|
|
/* skip over timing, don't save */
|
2008-06-01 20:55:34 +00:00
|
|
|
reg = pccard_tuple_read_1(tuple, idx++);
|
1999-10-26 06:52:31 +00:00
|
|
|
|
|
|
|
if ((reg & PCCARD_TPCE_TD_RESERVED_MASK) !=
|
|
|
|
PCCARD_TPCE_TD_RESERVED_MASK)
|
|
|
|
idx++;
|
|
|
|
if ((reg & PCCARD_TPCE_TD_RDYBSY_MASK) !=
|
|
|
|
PCCARD_TPCE_TD_RDYBSY_MASK)
|
|
|
|
idx++;
|
|
|
|
if ((reg & PCCARD_TPCE_TD_WAIT_MASK) !=
|
|
|
|
PCCARD_TPCE_TD_WAIT_MASK)
|
|
|
|
idx++;
|
|
|
|
}
|
|
|
|
if (iospace) {
|
|
|
|
if (tuple->length <= idx) {
|
|
|
|
DPRINTF(("ran out of space before TCPE_IO\n"));
|
|
|
|
goto abort_cfe;
|
|
|
|
}
|
|
|
|
|
2008-06-01 20:55:34 +00:00
|
|
|
reg = pccard_tuple_read_1(tuple, idx++);
|
2002-10-07 23:03:17 +00:00
|
|
|
cfe->flags &=
|
|
|
|
~(PCCARD_CFE_IO8 | PCCARD_CFE_IO16);
|
1999-10-26 06:52:31 +00:00
|
|
|
if (reg & PCCARD_TPCE_IO_BUSWIDTH_8BIT)
|
|
|
|
cfe->flags |= PCCARD_CFE_IO8;
|
|
|
|
if (reg & PCCARD_TPCE_IO_BUSWIDTH_16BIT)
|
|
|
|
cfe->flags |= PCCARD_CFE_IO16;
|
|
|
|
cfe->iomask =
|
|
|
|
reg & PCCARD_TPCE_IO_IOADDRLINES_MASK;
|
|
|
|
|
|
|
|
if (reg & PCCARD_TPCE_IO_HASRANGE) {
|
2008-06-01 20:55:34 +00:00
|
|
|
reg = pccard_tuple_read_1(tuple, idx++);
|
1999-10-26 06:52:31 +00:00
|
|
|
cfe->num_iospace = 1 + (reg &
|
|
|
|
PCCARD_TPCE_IO_RANGE_COUNT);
|
|
|
|
|
|
|
|
if (cfe->num_iospace >
|
|
|
|
(sizeof(cfe->iospace) /
|
|
|
|
sizeof(cfe->iospace[0]))) {
|
|
|
|
DPRINTF(("too many io "
|
|
|
|
"spaces %d",
|
|
|
|
cfe->num_iospace));
|
|
|
|
state->card->error++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
for (i = 0; i < cfe->num_iospace; i++) {
|
|
|
|
switch (reg & PCCARD_TPCE_IO_RANGE_ADDRSIZE_MASK) {
|
|
|
|
case PCCARD_TPCE_IO_RANGE_ADDRSIZE_ONE:
|
|
|
|
cfe->iospace[i].start =
|
2008-06-01 20:55:34 +00:00
|
|
|
pccard_tuple_read_1(tuple, idx++);
|
1999-10-26 06:52:31 +00:00
|
|
|
break;
|
|
|
|
case PCCARD_TPCE_IO_RANGE_ADDRSIZE_TWO:
|
|
|
|
cfe->iospace[i].start =
|
|
|
|
pccard_tuple_read_2(tuple, idx);
|
|
|
|
idx += 2;
|
|
|
|
break;
|
|
|
|
case PCCARD_TPCE_IO_RANGE_ADDRSIZE_FOUR:
|
|
|
|
cfe->iospace[i].start =
|
|
|
|
pccard_tuple_read_4(tuple, idx);
|
|
|
|
idx += 4;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
switch (reg &
|
|
|
|
PCCARD_TPCE_IO_RANGE_LENGTHSIZE_MASK) {
|
|
|
|
case PCCARD_TPCE_IO_RANGE_LENGTHSIZE_ONE:
|
|
|
|
cfe->iospace[i].length =
|
2008-06-01 20:55:34 +00:00
|
|
|
pccard_tuple_read_1(tuple, idx++);
|
1999-10-26 06:52:31 +00:00
|
|
|
break;
|
|
|
|
case PCCARD_TPCE_IO_RANGE_LENGTHSIZE_TWO:
|
|
|
|
cfe->iospace[i].length =
|
|
|
|
pccard_tuple_read_2(tuple, idx);
|
|
|
|
idx += 2;
|
|
|
|
break;
|
|
|
|
case PCCARD_TPCE_IO_RANGE_LENGTHSIZE_FOUR:
|
|
|
|
cfe->iospace[i].length =
|
|
|
|
pccard_tuple_read_4(tuple, idx);
|
|
|
|
idx += 4;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
cfe->iospace[i].length++;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
cfe->num_iospace = 1;
|
|
|
|
cfe->iospace[0].start = 0;
|
|
|
|
cfe->iospace[0].length =
|
|
|
|
(1 << cfe->iomask);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (irq) {
|
|
|
|
if (tuple->length <= idx) {
|
|
|
|
DPRINTF(("ran out of space before TCPE_IR\n"));
|
|
|
|
goto abort_cfe;
|
|
|
|
}
|
|
|
|
|
2008-06-01 20:55:34 +00:00
|
|
|
reg = pccard_tuple_read_1(tuple, idx++);
|
2002-10-07 23:03:17 +00:00
|
|
|
cfe->flags &= ~(PCCARD_CFE_IRQSHARE
|
|
|
|
| PCCARD_CFE_IRQPULSE
|
|
|
|
| PCCARD_CFE_IRQLEVEL);
|
1999-10-26 06:52:31 +00:00
|
|
|
if (reg & PCCARD_TPCE_IR_SHARE)
|
|
|
|
cfe->flags |= PCCARD_CFE_IRQSHARE;
|
|
|
|
if (reg & PCCARD_TPCE_IR_PULSE)
|
|
|
|
cfe->flags |= PCCARD_CFE_IRQPULSE;
|
|
|
|
if (reg & PCCARD_TPCE_IR_LEVEL)
|
|
|
|
cfe->flags |= PCCARD_CFE_IRQLEVEL;
|
|
|
|
|
|
|
|
if (reg & PCCARD_TPCE_IR_HASMASK) {
|
|
|
|
/*
|
|
|
|
* it's legal to ignore the
|
|
|
|
* special-interrupt bits, so I will
|
|
|
|
*/
|
|
|
|
|
|
|
|
cfe->irqmask =
|
|
|
|
pccard_tuple_read_2(tuple, idx);
|
|
|
|
idx += 2;
|
|
|
|
} else {
|
|
|
|
cfe->irqmask =
|
|
|
|
(1 << (reg & PCCARD_TPCE_IR_IRQ));
|
|
|
|
}
|
2008-08-27 04:36:27 +00:00
|
|
|
} else {
|
|
|
|
cfe->irqmask = 0xffff;
|
1999-10-26 06:52:31 +00:00
|
|
|
}
|
|
|
|
if (memspace) {
|
|
|
|
if (tuple->length <= idx) {
|
|
|
|
DPRINTF(("ran out of space before TCPE_MS\n"));
|
|
|
|
goto abort_cfe;
|
|
|
|
}
|
|
|
|
|
2005-02-17 21:05:04 +00:00
|
|
|
if (memspace == PCCARD_TPCE_FS_MEMSPACE_LENGTH) {
|
1999-10-26 06:52:31 +00:00
|
|
|
cfe->num_memspace = 1;
|
|
|
|
cfe->memspace[0].length = 256 *
|
|
|
|
pccard_tuple_read_2(tuple, idx);
|
|
|
|
idx += 2;
|
|
|
|
cfe->memspace[0].cardaddr = 0;
|
|
|
|
cfe->memspace[0].hostaddr = 0;
|
|
|
|
} else if (memspace ==
|
|
|
|
PCCARD_TPCE_FS_MEMSPACE_LENGTHADDR) {
|
|
|
|
cfe->num_memspace = 1;
|
|
|
|
cfe->memspace[0].length = 256 *
|
|
|
|
pccard_tuple_read_2(tuple, idx);
|
|
|
|
idx += 2;
|
|
|
|
cfe->memspace[0].cardaddr = 256 *
|
|
|
|
pccard_tuple_read_2(tuple, idx);
|
|
|
|
idx += 2;
|
|
|
|
cfe->memspace[0].hostaddr = cfe->memspace[0].cardaddr;
|
|
|
|
} else {
|
|
|
|
int lengthsize;
|
|
|
|
int cardaddrsize;
|
|
|
|
int hostaddrsize;
|
|
|
|
|
2008-06-01 20:55:34 +00:00
|
|
|
reg = pccard_tuple_read_1(tuple, idx++);
|
1999-11-29 06:42:55 +00:00
|
|
|
cfe->num_memspace = (reg &
|
|
|
|
PCCARD_TPCE_MS_COUNT) + 1;
|
1999-10-26 06:52:31 +00:00
|
|
|
if (cfe->num_memspace >
|
|
|
|
(sizeof(cfe->memspace) /
|
|
|
|
sizeof(cfe->memspace[0]))) {
|
|
|
|
DPRINTF(("too many mem "
|
|
|
|
"spaces %d",
|
|
|
|
cfe->num_memspace));
|
|
|
|
state->card->error++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
lengthsize =
|
|
|
|
((reg & PCCARD_TPCE_MS_LENGTH_SIZE_MASK) >>
|
|
|
|
PCCARD_TPCE_MS_LENGTH_SIZE_SHIFT);
|
|
|
|
cardaddrsize =
|
|
|
|
((reg & PCCARD_TPCE_MS_CARDADDR_SIZE_MASK) >>
|
|
|
|
PCCARD_TPCE_MS_CARDADDR_SIZE_SHIFT);
|
|
|
|
hostaddrsize =
|
|
|
|
(reg & PCCARD_TPCE_MS_HOSTADDR) ? cardaddrsize : 0;
|
|
|
|
|
|
|
|
if (lengthsize == 0) {
|
|
|
|
DPRINTF(("cfe memspace "
|
2009-03-11 08:14:44 +00:00
|
|
|
"lengthsize == 0\n"));
|
1999-10-26 06:52:31 +00:00
|
|
|
}
|
|
|
|
for (i = 0; i < cfe->num_memspace; i++) {
|
|
|
|
if (lengthsize) {
|
|
|
|
cfe->memspace[i].length =
|
|
|
|
256 * pccard_tuple_read_n(tuple, lengthsize,
|
|
|
|
idx);
|
|
|
|
idx += lengthsize;
|
|
|
|
} else {
|
|
|
|
cfe->memspace[i].length = 0;
|
|
|
|
}
|
|
|
|
if (cfe->memspace[i].length == 0) {
|
2009-03-11 08:14:44 +00:00
|
|
|
DPRINTF(("cfe->memspace[%d].length == 0\n",
|
1999-10-26 06:52:31 +00:00
|
|
|
i));
|
|
|
|
}
|
|
|
|
if (cardaddrsize) {
|
|
|
|
cfe->memspace[i].cardaddr =
|
|
|
|
256 * pccard_tuple_read_n(tuple, cardaddrsize,
|
|
|
|
idx);
|
|
|
|
idx += cardaddrsize;
|
|
|
|
} else {
|
|
|
|
cfe->memspace[i].cardaddr = 0;
|
|
|
|
}
|
|
|
|
if (hostaddrsize) {
|
|
|
|
cfe->memspace[i].hostaddr =
|
|
|
|
256 * pccard_tuple_read_n(tuple, hostaddrsize,
|
|
|
|
idx);
|
|
|
|
idx += hostaddrsize;
|
|
|
|
} else {
|
|
|
|
cfe->memspace[i].hostaddr = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2005-02-17 21:05:04 +00:00
|
|
|
} else
|
|
|
|
cfe->num_memspace = 0;
|
1999-10-26 06:52:31 +00:00
|
|
|
if (misc) {
|
|
|
|
if (tuple->length <= idx) {
|
|
|
|
DPRINTF(("ran out of space before TCPE_MI\n"));
|
|
|
|
goto abort_cfe;
|
|
|
|
}
|
|
|
|
|
2008-06-01 20:55:34 +00:00
|
|
|
reg = pccard_tuple_read_1(tuple, idx++);
|
2002-10-07 23:03:17 +00:00
|
|
|
cfe->flags &= ~(PCCARD_CFE_POWERDOWN
|
|
|
|
| PCCARD_CFE_READONLY
|
|
|
|
| PCCARD_CFE_AUDIO);
|
1999-10-26 06:52:31 +00:00
|
|
|
if (reg & PCCARD_TPCE_MI_PWRDOWN)
|
2002-10-07 23:03:17 +00:00
|
|
|
cfe->flags |= PCCARD_CFE_POWERDOWN;
|
1999-10-26 06:52:31 +00:00
|
|
|
if (reg & PCCARD_TPCE_MI_READONLY)
|
2002-10-07 23:03:17 +00:00
|
|
|
cfe->flags |= PCCARD_CFE_READONLY;
|
1999-10-26 06:52:31 +00:00
|
|
|
if (reg & PCCARD_TPCE_MI_AUDIO)
|
2002-10-07 23:03:17 +00:00
|
|
|
cfe->flags |= PCCARD_CFE_AUDIO;
|
1999-10-26 06:52:31 +00:00
|
|
|
cfe->maxtwins = reg & PCCARD_TPCE_MI_MAXTWINS;
|
|
|
|
|
|
|
|
while (reg & PCCARD_TPCE_MI_EXT) {
|
2008-06-01 20:55:34 +00:00
|
|
|
reg = pccard_tuple_read_1(tuple, idx++);
|
1999-10-26 06:52:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/* skip all the subtuples */
|
|
|
|
}
|
|
|
|
|
|
|
|
abort_cfe:
|
|
|
|
DPRINTF(("CISTPL_CFTABLE_ENTRY\n"));
|
|
|
|
break;
|
|
|
|
default:
|
2009-02-05 23:51:11 +00:00
|
|
|
DPRINTF(("unhandled CISTPL %#x\n", tuple->code));
|
1999-10-26 06:52:31 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
2001-09-02 06:37:41 +00:00
|
|
|
|
|
|
|
static int
|
2005-07-01 15:52:50 +00:00
|
|
|
decode_funce(const struct pccard_tuple *tuple, struct pccard_function *pf)
|
2001-09-02 06:37:41 +00:00
|
|
|
{
|
2005-01-21 02:11:48 +00:00
|
|
|
int i;
|
|
|
|
int len;
|
2001-09-02 06:37:41 +00:00
|
|
|
int type = pccard_tuple_read_1(tuple, 0);
|
|
|
|
|
|
|
|
switch (pf->function) {
|
|
|
|
case PCCARD_FUNCTION_DISK:
|
|
|
|
if (type == PCCARD_TPLFE_TYPE_DISK_DEVICE_INTERFACE) {
|
|
|
|
pf->pf_funce_disk_interface
|
|
|
|
= pccard_tuple_read_1(tuple, 1);
|
2009-02-06 07:49:03 +00:00
|
|
|
pf->pf_funce_disk_power
|
|
|
|
= pccard_tuple_read_1(tuple, 2);
|
2001-09-02 06:37:41 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case PCCARD_FUNCTION_NETWORK:
|
|
|
|
if (type == PCCARD_TPLFE_TYPE_LAN_NID) {
|
2005-01-21 02:11:48 +00:00
|
|
|
len = pccard_tuple_read_1(tuple, 1);
|
2001-09-02 06:37:41 +00:00
|
|
|
if (tuple->length < 2 + len || len > 8) {
|
|
|
|
/* tuple length not enough or nid too long */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
for (i = 0; i < len; i++) {
|
|
|
|
pf->pf_funce_lan_nid[i]
|
|
|
|
= pccard_tuple_read_1(tuple, i + 2);
|
|
|
|
}
|
|
|
|
pf->pf_funce_lan_nidlen = len;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|