From 64e8045b622170b7380ae17279553b6f6a2391bb Mon Sep 17 00:00:00 2001 From: imp Date: Fri, 1 Jul 2005 03:40:28 +0000 Subject: [PATCH] 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) --- sys/dev/pccard/card_if.m | 9 +++++++++ sys/dev/pccard/pccard.c | 1 + sys/dev/pccard/pccard_cis.c | 11 +++++------ sys/dev/pccard/pccardvar.h | 5 +++-- 4 files changed, 18 insertions(+), 8 deletions(-) diff --git a/sys/dev/pccard/card_if.m b/sys/dev/pccard/card_if.m index bd003e4a4e24..51977cc5dcc1 100644 --- a/sys/dev/pccard/card_if.m +++ b/sys/dev/pccard/card_if.m @@ -169,3 +169,12 @@ METHOD struct pccard_product * do_product_lookup { METHOD int compat_match { device_t dev; } + +# +# Scanning function for accessing the CIS of a card in its driver. +# +METHOD int cis_scan { + device_t bus; + pccard_scan_t fnp; + void *argp; +}; diff --git a/sys/dev/pccard/pccard.c b/sys/dev/pccard/pccard.c index 9f98fd0ffa87..911ccdbc192c 100644 --- a/sys/dev/pccard/pccard.c +++ b/sys/dev/pccard/pccard.c @@ -1325,6 +1325,7 @@ static device_method_t pccard_methods[] = { DEVMETHOD(card_compat_do_probe, pccard_compat_do_probe), DEVMETHOD(card_compat_do_attach, pccard_compat_do_attach), DEVMETHOD(card_do_product_lookup, pccard_do_product_lookup), + DEVMETHOD(card_cis_scan, pccard_scan_cis), { 0, 0 } }; diff --git a/sys/dev/pccard/pccard_cis.c b/sys/dev/pccard/pccard_cis.c index ce5a01feda78..7c7898e151fa 100644 --- a/sys/dev/pccard/pccard_cis.c +++ b/sys/dev/pccard/pccard_cis.c @@ -71,7 +71,7 @@ struct cis_state { struct pccard_function *pf; }; -int pccard_parse_cis_tuple(struct pccard_tuple *, void *); +static int pccard_parse_cis_tuple(struct pccard_tuple *, void *); static int decode_funce(struct pccard_tuple *, struct pccard_function *); void @@ -103,8 +103,7 @@ pccard_read_cis(struct pccard_softc *sc) } int -pccard_scan_cis(device_t dev, int (*fct)(struct pccard_tuple *, void *), - void *arg) +pccard_scan_cis(device_t dev, pccard_scan_t fct, void *arg) { struct resource *res; int rid; @@ -193,7 +192,7 @@ pccard_scan_cis(device_t dev, int (*fct)(struct pccard_tuple *, void *), DPRINTF(("CISTPL_END\n ff\n")); /* Call the function for the END tuple, since the CIS semantics depend on it */ - if ((*fct) (&tuple, arg)) { + if ((*fct)(&tuple, arg)) { ret = 1; goto done; } @@ -353,7 +352,7 @@ pccard_scan_cis(device_t dev, int (*fct)(struct pccard_tuple *, void *), */ default: { - if ((*fct) (&tuple, arg)) { + if ((*fct)(&tuple, arg)) { ret = 1; goto done; } @@ -616,7 +615,7 @@ pccard_print_cis(device_t dev) card->error); } -int +static int pccard_parse_cis_tuple(struct pccard_tuple *tuple, void *arg) { /* most of these are educated guesses */ diff --git a/sys/dev/pccard/pccardvar.h b/sys/dev/pccard/pccardvar.h index c4bd0e3f4f55..3df9fcc66540 100644 --- a/sys/dev/pccard/pccardvar.h +++ b/sys/dev/pccard/pccardvar.h @@ -221,6 +221,8 @@ struct pccard_tuple { bus_space_handle_t memh; }; +typedef int (*pccard_scan_t)(struct pccard_tuple *, void *); + struct pccard_product { const char *pp_name; /* NULL if end of table */ #define PCCARD_VENDOR_ANY (0xffffffff) @@ -250,8 +252,7 @@ pccard_product_lookup(device_t dev, const struct pccard_product *tab, void pccard_read_cis(struct pccard_softc *); void pccard_check_cis_quirks(device_t); void pccard_print_cis(device_t); -int pccard_scan_cis(device_t, - int (*) (struct pccard_tuple *, void *), void *); +int pccard_scan_cis(device_t, pccard_scan_t, void *); #define pccard_cis_read_1(tuple, idx0) \ (bus_space_read_1((tuple)->memt, (tuple)->memh, (tuple)->mult*(idx0)))