dump_cis: Work on files only, not devices
Make the input file parameter mandatory and link directly to the CIS
tuple parser. Remove all device access.
Strip out some definitions that were for kernel use only.
Remove now-incorrect version strings.
diff --git a/Makefile b/Makefile
index d2868ec..10667d6 100644
--- a/Makefile
+++ b/Makefile
@@ -7,7 +7,7 @@
all: $(SRCS) $(HDRS) $(TOOLS)
-dump_cis: dump_cis.o
+dump_cis: dump_cis.o cistpl.o
yacc_cis.o: yacc_cis.c
$(CC) -MD $(CFLAGS) $(CPPFLAGS) -c $<
diff --git a/cistpl.c b/cistpl.c
index 404b8e4..6875ac8 100644
--- a/cistpl.c
+++ b/cistpl.c
@@ -2,8 +2,6 @@
PCMCIA Card Information Structure parser
- cistpl.c 1.101 2003/12/15 03:58:03
-
The contents of this file are subject to the Mozilla Public
License Version 1.1 (the "License"); you may not use this file
except in compliance with the License. You may obtain a copy of
@@ -31,31 +29,16 @@
======================================================================*/
-#define __NO_VERSION__
+#include <stddef.h>
-#include <linux/config.h>
-#include <linux/module.h>
-#include <linux/kernel.h>
-#include <linux/string.h>
-#include <linux/major.h>
-#include <linux/errno.h>
-#include <linux/timer.h>
-#include <linux/slab.h>
-#include <linux/mm.h>
-#include <linux/sched.h>
-#include <linux/pci.h>
-#include <linux/ioport.h>
-#include <asm/io.h>
#include <asm/byteorder.h>
+#define le16_to_cpu __le16_to_cpu
+#define le32_to_cpu __le32_to_cpu
#include <pcmcia/cs_types.h>
-#include <pcmcia/bus_ops.h>
-#include <pcmcia/ss.h>
#include <pcmcia/cs.h>
#include <pcmcia/bulkmem.h>
-#include <pcmcia/cisreg.h>
#include <pcmcia/cistpl.h>
-#include "cs_internal.h"
static const u_char mantissa[] = {
10, 12, 13, 15, 20, 25, 30, 35,
@@ -74,552 +57,6 @@
(mantissa[((v)>>3)&15] * exponent[(v)&7] / 10)
#define POWER_SCALE(v) (exponent[(v)&7])
-/* Upper limit on reasonable # of tuples */
-#define MAX_TUPLES 200
-
-/*====================================================================*/
-
-/* Parameters that can be set with 'insmod' */
-
-#define INT_MODULE_PARM(n, v) static int n = v; MODULE_PARM(n, "i")
-
-INT_MODULE_PARM(cis_width, 0); /* 16-bit CIS? */
-
-/*======================================================================
-
- Low-level functions to read and write CIS memory. I think the
- write routine is only useful for writing one-byte registers.
-
-======================================================================*/
-
-/* Bits in attr field */
-#define IS_ATTR 1
-#define IS_INDIRECT 8
-
-static int setup_cis_mem(socket_info_t *s);
-
-static void set_cis_map(socket_info_t *s, pccard_mem_map *mem)
-{
- s->ss_entry(s->sock, SS_SetMemMap, mem);
- if (s->cap.features & SS_CAP_STATIC_MAP) {
- if (s->cis_virt)
- bus_iounmap(s->cap.bus, s->cis_virt);
- s->cis_virt = bus_ioremap(s->cap.bus, mem->sys_start,
- s->cap.map_size);
- }
-}
-
-int read_cis_mem(socket_info_t *s, int attr, u_int addr,
- u_int len, void *ptr)
-{
- pccard_mem_map *mem = &s->cis_mem;
- u_char *sys, *buf = ptr;
-
- DEBUG(3, "cs: read_cis_mem(%d, %#x, %u)\n", attr, addr, len);
- if (setup_cis_mem(s) != 0) {
- memset(ptr, 0xff, len);
- return -1;
- }
- mem->flags = MAP_ACTIVE | ((cis_width) ? MAP_16BIT : 0);
-
- if (attr & IS_INDIRECT) {
- /* Indirect accesses use a bunch of special registers at fixed
- locations in common memory */
- u_char flags = ICTRL0_COMMON|ICTRL0_AUTOINC|ICTRL0_BYTEGRAN;
- if (attr & IS_ATTR) { addr *= 2; flags = ICTRL0_AUTOINC; }
- mem->card_start = 0; mem->flags = MAP_ACTIVE;
- set_cis_map(s, mem);
- sys = s->cis_virt;
- bus_writeb(s->cap.bus, flags, sys+CISREG_ICTRL0);
- bus_writeb(s->cap.bus, addr & 0xff, sys+CISREG_IADDR0);
- bus_writeb(s->cap.bus, (addr>>8) & 0xff, sys+CISREG_IADDR1);
- bus_writeb(s->cap.bus, (addr>>16) & 0xff, sys+CISREG_IADDR2);
- bus_writeb(s->cap.bus, (addr>>24) & 0xff, sys+CISREG_IADDR3);
- for ( ; len > 0; len--, buf++)
- *buf = bus_readb(s->cap.bus, sys+CISREG_IDATA0);
- } else {
- u_int inc = 1;
- if (attr) { mem->flags |= MAP_ATTRIB; inc++; addr *= 2; }
- sys += (addr & (s->cap.map_size-1));
- mem->card_start = addr & ~(s->cap.map_size-1);
- while (len) {
- set_cis_map(s, mem);
- sys = s->cis_virt + (addr & (s->cap.map_size-1));
- for ( ; len > 0; len--, buf++, sys += inc) {
- if (sys == s->cis_virt+s->cap.map_size) break;
- *buf = bus_readb(s->cap.bus, sys);
- }
- mem->card_start += s->cap.map_size;
- addr = 0;
- }
- }
- DEBUG(3, "cs: %#2.2x %#2.2x %#2.2x %#2.2x ...\n",
- *(u_char *)(ptr+0), *(u_char *)(ptr+1),
- *(u_char *)(ptr+2), *(u_char *)(ptr+3));
- return 0;
-}
-
-void write_cis_mem(socket_info_t *s, int attr, u_int addr,
- u_int len, void *ptr)
-{
- pccard_mem_map *mem = &s->cis_mem;
- u_char *sys, *buf = ptr;
-
- DEBUG(3, "cs: write_cis_mem(%d, %#x, %u)\n", attr, addr, len);
- if (setup_cis_mem(s) != 0) return;
- mem->flags = MAP_ACTIVE | ((cis_width) ? MAP_16BIT : 0);
-
- if (attr & IS_INDIRECT) {
- /* Indirect accesses use a bunch of special registers at fixed
- locations in common memory */
- u_char flags = ICTRL0_COMMON|ICTRL0_AUTOINC|ICTRL0_BYTEGRAN;
- if (attr & IS_ATTR) { addr *= 2; flags = ICTRL0_AUTOINC; }
- mem->card_start = 0; mem->flags = MAP_ACTIVE;
- set_cis_map(s, mem);
- sys = s->cis_virt;
- bus_writeb(s->cap.bus, flags, sys+CISREG_ICTRL0);
- bus_writeb(s->cap.bus, addr & 0xff, sys+CISREG_IADDR0);
- bus_writeb(s->cap.bus, (addr>>8) & 0xff, sys+CISREG_IADDR1);
- bus_writeb(s->cap.bus, (addr>>16) & 0xff, sys+CISREG_IADDR2);
- bus_writeb(s->cap.bus, (addr>>24) & 0xff, sys+CISREG_IADDR3);
- for ( ; len > 0; len--, buf++)
- bus_writeb(s->cap.bus, *buf, sys+CISREG_IDATA0);
- } else {
- int inc = 1;
- if (attr & IS_ATTR) { mem->flags |= MAP_ATTRIB; inc++; addr *= 2; }
- mem->card_start = addr & ~(s->cap.map_size-1);
- while (len) {
- set_cis_map(s, mem);
- sys = s->cis_virt + (addr & (s->cap.map_size-1));
- for ( ; len > 0; len--, buf++, sys += inc) {
- if (sys == s->cis_virt+s->cap.map_size) break;
- bus_writeb(s->cap.bus, *buf, sys);
- }
- mem->card_start += s->cap.map_size;
- addr = 0;
- }
- }
-}
-
-/*======================================================================
-
- This is tricky... when we set up CIS memory, we try to validate
- the memory window space allocations.
-
-======================================================================*/
-
-/* Scratch pointer to the socket we use for validation */
-static socket_info_t *vs = NULL;
-
-/* Validation function for cards with a valid CIS */
-static int cis_readable(u_long base)
-{
- cisinfo_t info1, info2;
- int ret;
- vs->cis_mem.sys_start = base;
- vs->cis_mem.sys_stop = base+vs->cap.map_size-1;
- vs->cis_virt = bus_ioremap(vs->cap.bus, base, vs->cap.map_size);
- ret = validate_cis(vs->clients, &info1);
- /* invalidate mapping and CIS cache */
- bus_iounmap(vs->cap.bus, vs->cis_virt); vs->cis_used = 0;
- if ((ret != 0) || (info1.Chains == 0))
- return 0;
- vs->cis_mem.sys_start = base+vs->cap.map_size;
- vs->cis_mem.sys_stop = base+2*vs->cap.map_size-1;
- vs->cis_virt = bus_ioremap(vs->cap.bus, base+vs->cap.map_size,
- vs->cap.map_size);
- ret = validate_cis(vs->clients, &info2);
- bus_iounmap(vs->cap.bus, vs->cis_virt); vs->cis_used = 0;
- return ((ret == 0) && (info1.Chains == info2.Chains));
-}
-
-/* Validation function for simple memory cards */
-static int checksum(u_long base)
-{
- int i, a, b, d;
- vs->cis_mem.sys_start = base;
- vs->cis_mem.sys_stop = base+vs->cap.map_size-1;
- vs->cis_virt = bus_ioremap(vs->cap.bus, base, vs->cap.map_size);
- vs->cis_mem.card_start = 0;
- vs->cis_mem.flags = MAP_ACTIVE;
- vs->ss_entry(vs->sock, SS_SetMemMap, &vs->cis_mem);
- /* Don't bother checking every word... */
- a = 0; b = -1;
- for (i = 0; i < vs->cap.map_size; i += 44) {
- d = bus_readl(vs->cap.bus, vs->cis_virt+i);
- a += d; b &= d;
- }
- bus_iounmap(vs->cap.bus, vs->cis_virt);
- return (b == -1) ? -1 : (a>>1);
-}
-
-static int checksum_match(u_long base)
-{
- int a = checksum(base), b = checksum(base+vs->cap.map_size);
- return ((a == b) && (a >= 0));
-}
-
-static int setup_cis_mem(socket_info_t *s)
-{
- if (!(s->cap.features & SS_CAP_STATIC_MAP) &&
- (s->cis_mem.sys_start == 0)) {
- int low = !(s->cap.features & SS_CAP_PAGE_REGS);
- vs = s;
- validate_mem(cis_readable, checksum_match, low);
- s->cis_mem.sys_start = 0;
- vs = NULL;
- if (find_mem_region(&s->cis_mem.sys_start, s->cap.map_size,
- s->cap.map_size, low, "card services")) {
- printk(KERN_NOTICE "cs: unable to map card memory!\n");
- return -1;
- }
- s->cis_mem.sys_stop = s->cis_mem.sys_start+s->cap.map_size-1;
- s->cis_virt = bus_ioremap(s->cap.bus, s->cis_mem.sys_start,
- s->cap.map_size);
- }
- return 0;
-}
-
-void release_cis_mem(socket_info_t *s)
-{
- if (s->cis_mem.sys_start != 0) {
- s->cis_mem.flags &= ~MAP_ACTIVE;
- s->ss_entry(s->sock, SS_SetMemMap, &s->cis_mem);
- if (!(s->cap.features & SS_CAP_STATIC_MAP))
- release_mem_region(s->cis_mem.sys_start, s->cap.map_size);
- bus_iounmap(s->cap.bus, s->cis_virt);
- s->cis_mem.sys_start = 0;
- s->cis_virt = NULL;
- }
-}
-
-/*======================================================================
-
- This is a wrapper around read_cis_mem, with the same interface,
- but which caches information, for cards whose CIS may not be
- readable all the time.
-
-======================================================================*/
-
-static void read_cis_cache(socket_info_t *s, int attr, u_int addr,
- u_int len, void *ptr)
-{
- int i, ret;
- char *caddr;
-
- if (s->fake_cis) {
- if (s->fake_cis_len > addr+len)
- memcpy(ptr, s->fake_cis+addr, len);
- else
- memset(ptr, 0xff, len);
- return;
- }
- caddr = s->cis_cache;
- for (i = 0; i < s->cis_used; i++) {
- if ((s->cis_table[i].addr == addr) &&
- (s->cis_table[i].len == len) &&
- (s->cis_table[i].attr == attr)) break;
- caddr += s->cis_table[i].len;
- }
- if (i < s->cis_used) {
- memcpy(ptr, caddr, len);
- return;
- }
-#ifdef CONFIG_CARDBUS
- if (s->state & SOCKET_CARDBUS)
- ret = read_cb_mem(s, 0, attr, addr, len, ptr);
- else
-#endif
- ret = read_cis_mem(s, attr, addr, len, ptr);
- /* Copy data into the cache, if there is room */
- if ((ret == 0) && (i < MAX_CIS_TABLE) &&
- (caddr+len < s->cis_cache+MAX_CIS_DATA)) {
- s->cis_table[i].addr = addr;
- s->cis_table[i].len = len;
- s->cis_table[i].attr = attr;
- s->cis_used++;
- memcpy(caddr, ptr, len);
- }
-}
-
-/*======================================================================
-
- This verifies if the CIS of a card matches what is in the CIS
- cache.
-
-======================================================================*/
-
-int verify_cis_cache(socket_info_t *s)
-{
- char *buf, *caddr;
- int i;
-
- buf = kmalloc(256, GFP_KERNEL);
- if (buf == NULL)
- return -1;
- caddr = s->cis_cache;
- for (i = 0; i < s->cis_used; i++) {
-#ifdef CONFIG_CARDBUS
- if (s->state & SOCKET_CARDBUS)
- read_cb_mem(s, 0, s->cis_table[i].attr, s->cis_table[i].addr,
- s->cis_table[i].len, buf);
- else
-#endif
- read_cis_mem(s, s->cis_table[i].attr, s->cis_table[i].addr,
- s->cis_table[i].len, buf);
- if (memcmp(buf, caddr, s->cis_table[i].len) != 0)
- break;
- caddr += s->cis_table[i].len;
- }
- kfree(buf);
- return (i < s->cis_used);
-}
-
-/*======================================================================
-
- For really bad cards, we provide a facility for uploading a
- replacement CIS.
-
-======================================================================*/
-
-int replace_cis(client_handle_t handle, cisdump_t *cis)
-{
- socket_info_t *s;
- if (CHECK_HANDLE(handle))
- return CS_BAD_HANDLE;
- s = SOCKET(handle);
- if (s->fake_cis != NULL) {
- kfree(s->fake_cis);
- s->fake_cis = NULL;
- }
- if (cis->Length > CISTPL_MAX_CIS_SIZE)
- return CS_BAD_SIZE;
- s->fake_cis = kmalloc(cis->Length, GFP_KERNEL);
- if (s->fake_cis == NULL)
- return CS_OUT_OF_RESOURCE;
- s->fake_cis_len = cis->Length;
- memcpy(s->fake_cis, cis->Data, cis->Length);
- return CS_SUCCESS;
-}
-
-/*======================================================================
-
- The high-level CIS tuple services
-
-======================================================================*/
-
-typedef struct tuple_flags {
- u_int link_space:4;
- u_int has_link:1;
- u_int mfc_fn:3;
- u_int space:4;
-} tuple_flags;
-
-#define LINK_SPACE(f) (((tuple_flags *)(&(f)))->link_space)
-#define HAS_LINK(f) (((tuple_flags *)(&(f)))->has_link)
-#define MFC_FN(f) (((tuple_flags *)(&(f)))->mfc_fn)
-#define SPACE(f) (((tuple_flags *)(&(f)))->space)
-
-int get_next_tuple(client_handle_t handle, tuple_t *tuple);
-
-int get_first_tuple(client_handle_t handle, tuple_t *tuple)
-{
- socket_info_t *s;
- if (CHECK_HANDLE(handle))
- return CS_BAD_HANDLE;
- s = SOCKET(handle);
- if (!(s->state & SOCKET_PRESENT))
- return CS_NO_CARD;
- tuple->TupleLink = tuple->Flags = 0;
-#ifdef CONFIG_CARDBUS
- if (s->state & SOCKET_CARDBUS) {
- u_int ptr;
- pcibios_read_config_dword(s->cap.cardbus, 0, 0x28, &ptr);
- tuple->CISOffset = ptr & ~7;
- SPACE(tuple->Flags) = (ptr & 7);
- } else
-#endif
- {
- /* Assume presence of a LONGLINK_C to address 0 */
- tuple->CISOffset = tuple->LinkOffset = 0;
- SPACE(tuple->Flags) = HAS_LINK(tuple->Flags) = 1;
- }
- if (!(s->state & SOCKET_CARDBUS) && (s->functions > 1) &&
- !(tuple->Attributes & TUPLE_RETURN_COMMON)) {
- cisdata_t req = tuple->DesiredTuple;
- tuple->DesiredTuple = CISTPL_LONGLINK_MFC;
- if (get_next_tuple(handle, tuple) == CS_SUCCESS) {
- tuple->DesiredTuple = CISTPL_LINKTARGET;
- if (get_next_tuple(handle, tuple) != CS_SUCCESS)
- return CS_NO_MORE_ITEMS;
- } else
- tuple->CISOffset = tuple->TupleLink = 0;
- tuple->DesiredTuple = req;
- }
- return get_next_tuple(handle, tuple);
-}
-
-static int follow_link(socket_info_t *s, tuple_t *tuple)
-{
- u_char link[5];
- u_int ofs;
-
- if (MFC_FN(tuple->Flags)) {
- /* Get indirect link from the MFC tuple */
- read_cis_cache(s, LINK_SPACE(tuple->Flags),
- tuple->LinkOffset, 5, link);
- ofs = le32_to_cpu(*(u_int *)(link+1));
- SPACE(tuple->Flags) = (link[0] == CISTPL_MFC_ATTR);
- /* Move to the next indirect link */
- tuple->LinkOffset += 5;
- MFC_FN(tuple->Flags)--;
- } else if (HAS_LINK(tuple->Flags)) {
- ofs = tuple->LinkOffset;
- SPACE(tuple->Flags) = LINK_SPACE(tuple->Flags);
- HAS_LINK(tuple->Flags) = 0;
- } else {
- return -1;
- }
- if (!(s->state & SOCKET_CARDBUS) && SPACE(tuple->Flags)) {
- /* This is ugly, but a common CIS error is to code the long
- link offset incorrectly, so we check the right spot... */
- read_cis_cache(s, SPACE(tuple->Flags), ofs, 5, link);
- if ((link[0] == CISTPL_LINKTARGET) && (link[1] >= 3) &&
- (strncmp(link+2, "CIS", 3) == 0))
- return ofs;
- /* Then, we try the wrong spot... */
- ofs = ofs >> 1;
- }
- read_cis_cache(s, SPACE(tuple->Flags), ofs, 5, link);
- if ((link[0] != CISTPL_LINKTARGET) || (link[1] < 3) ||
- (strncmp(link+2, "CIS", 3) != 0))
- return -1;
- return ofs;
-}
-
-int get_next_tuple(client_handle_t handle, tuple_t *tuple)
-{
- socket_info_t *s;
- u_char link[2], tmp;
- int ofs, i, attr;
-
- if (CHECK_HANDLE(handle))
- return CS_BAD_HANDLE;
- s = SOCKET(handle);
- if (!(s->state & SOCKET_PRESENT))
- return CS_NO_CARD;
-
- link[1] = tuple->TupleLink;
- ofs = tuple->CISOffset + tuple->TupleLink;
- attr = SPACE(tuple->Flags);
-
- for (i = 0; i < MAX_TUPLES; i++) {
- if (link[1] == 0xff) {
- link[0] = CISTPL_END;
- } else {
- read_cis_cache(s, attr, ofs, 2, link);
- if (link[0] == CISTPL_NULL) {
- ofs++; continue;
- }
- }
-
- /* End of chain? Follow long link if possible */
- if (link[0] == CISTPL_END) {
- if ((ofs = follow_link(s, tuple)) < 0)
- return CS_NO_MORE_ITEMS;
- attr = SPACE(tuple->Flags);
- read_cis_cache(s, attr, ofs, 2, link);
- }
-
- /* Is this a link tuple? Make a note of it */
- if ((link[0] == CISTPL_LONGLINK_A) ||
- (link[0] == CISTPL_LONGLINK_C) ||
- (link[0] == CISTPL_LONGLINK_MFC) ||
- (link[0] == CISTPL_LINKTARGET) ||
- (link[0] == CISTPL_INDIRECT) ||
- (link[0] == CISTPL_NO_LINK)) {
- switch (link[0]) {
- case CISTPL_LONGLINK_A:
- HAS_LINK(tuple->Flags) = 1;
- LINK_SPACE(tuple->Flags) = attr | IS_ATTR;
- read_cis_cache(s, attr, ofs+2, 4, &tuple->LinkOffset);
- break;
- case CISTPL_LONGLINK_C:
- HAS_LINK(tuple->Flags) = 1;
- LINK_SPACE(tuple->Flags) = attr & ~IS_ATTR;
- read_cis_cache(s, attr, ofs+2, 4, &tuple->LinkOffset);
- break;
- case CISTPL_INDIRECT:
- HAS_LINK(tuple->Flags) = 1;
- LINK_SPACE(tuple->Flags) = IS_ATTR | IS_INDIRECT;
- tuple->LinkOffset = 0;
- break;
- case CISTPL_LONGLINK_MFC:
- tuple->LinkOffset = ofs + 3;
- LINK_SPACE(tuple->Flags) = attr;
- if (handle->Function == BIND_FN_ALL) {
- /* Follow all the MFC links */
- read_cis_cache(s, attr, ofs+2, 1, &tmp);
- MFC_FN(tuple->Flags) = tmp;
- } else {
- /* Follow exactly one of the links */
- MFC_FN(tuple->Flags) = 1;
- tuple->LinkOffset += handle->Function * 5;
- }
- break;
- case CISTPL_NO_LINK:
- HAS_LINK(tuple->Flags) = 0;
- break;
- }
- if ((tuple->Attributes & TUPLE_RETURN_LINK) &&
- (tuple->DesiredTuple == RETURN_FIRST_TUPLE))
- break;
- } else
- if (tuple->DesiredTuple == RETURN_FIRST_TUPLE)
- break;
-
- if (link[0] == tuple->DesiredTuple)
- break;
- ofs += link[1] + 2;
- }
- if (i == MAX_TUPLES) {
- DEBUG(1, "cs: overrun in get_next_tuple for socket %d\n",
- handle->Socket);
- return CS_NO_MORE_ITEMS;
- }
-
- tuple->TupleCode = link[0];
- tuple->TupleLink = link[1];
- tuple->CISOffset = ofs + 2;
- return CS_SUCCESS;
-}
-
-/*====================================================================*/
-
-#define _MIN(a, b) (((a) < (b)) ? (a) : (b))
-
-int get_tuple_data(client_handle_t handle, tuple_t *tuple)
-{
- socket_info_t *s;
- u_int len;
-
- if (CHECK_HANDLE(handle))
- return CS_BAD_HANDLE;
-
- s = SOCKET(handle);
-
- if (tuple->TupleLink < tuple->TupleOffset)
- return CS_NO_MORE_ITEMS;
- len = tuple->TupleLink - tuple->TupleOffset;
- tuple->TupleDataLen = tuple->TupleLink;
- if (len == 0)
- return CS_SUCCESS;
- read_cis_cache(s, SPACE(tuple->Flags),
- tuple->CISOffset + tuple->TupleOffset,
- _MIN(len, tuple->TupleDataMax), tuple->TupleData);
- return CS_SUCCESS;
-}
-
/*======================================================================
Parsing routines for individual tuples
@@ -1136,8 +573,6 @@
/*====================================================================*/
-#ifdef CONFIG_CARDBUS
-
static int parse_bar(tuple_t *tuple, cistpl_bar_t *bar)
{
u_char *p;
@@ -1235,8 +670,6 @@
return CS_SUCCESS;
}
-#endif
-
/*====================================================================*/
static int parse_device_geo(tuple_t *tuple, cistpl_device_geo_t *geo)
@@ -1324,7 +757,7 @@
/*====================================================================*/
-int parse_tuple(client_handle_t handle, tuple_t *tuple, cisparse_t *parse)
+int parse_tuple(tuple_t *tuple, cisparse_t *parse)
{
int ret = CS_SUCCESS;
@@ -1335,7 +768,6 @@
case CISTPL_DEVICE_A:
ret = parse_device(tuple, &parse->device);
break;
-#ifdef CONFIG_CARDBUS
case CISTPL_BAR:
ret = parse_bar(tuple, &parse->bar);
break;
@@ -1345,7 +777,6 @@
case CISTPL_CFTABLE_ENTRY_CB:
ret = parse_cftable_entry_cb(tuple, &parse->cftable_entry_cb);
break;
-#endif
case CISTPL_CHECKSUM:
ret = parse_checksum(tuple, &parse->checksum);
break;
@@ -1405,98 +836,3 @@
}
return ret;
}
-
-/*======================================================================
-
- This is used internally by Card Services to look up CIS stuff.
-
-======================================================================*/
-
-int read_tuple(client_handle_t handle, cisdata_t code, void *parse)
-{
- tuple_t tuple;
- cisdata_t *buf;
- int ret;
-
- buf = kmalloc(255, GFP_KERNEL);
- if (buf == NULL)
- return CS_OUT_OF_RESOURCE;
- tuple.DesiredTuple = code;
- tuple.Attributes = TUPLE_RETURN_COMMON;
- ret = CardServices(GetFirstTuple, handle, &tuple, NULL);
- if (ret != CS_SUCCESS) goto done;
- tuple.TupleData = buf;
- tuple.TupleOffset = 0;
- tuple.TupleDataMax = 255;
- ret = CardServices(GetTupleData, handle, &tuple, NULL);
- if (ret != CS_SUCCESS) goto done;
- ret = CardServices(ParseTuple, handle, &tuple, parse);
-done:
- kfree(buf);
- return ret;
-}
-
-/*======================================================================
-
- This tries to determine if a card has a sensible CIS. It returns
- the number of tuples in the CIS, or 0 if the CIS looks bad. The
- checks include making sure several critical tuples are present and
- valid; seeing if the total number of tuples is reasonable; and
- looking for tuples that use reserved codes.
-
-======================================================================*/
-
-int validate_cis(client_handle_t handle, cisinfo_t *info)
-{
- tuple_t tuple;
- cisparse_t *p;
- int ret, reserved, dev_ok = 0, ident_ok = 0;
-
- if (CHECK_HANDLE(handle))
- return CS_BAD_HANDLE;
- p = kmalloc(sizeof(*p), GFP_KERNEL);
- if (p == NULL)
- return CS_OUT_OF_RESOURCE;
-
- info->Chains = reserved = 0;
- tuple.DesiredTuple = RETURN_FIRST_TUPLE;
- tuple.Attributes = TUPLE_RETURN_COMMON;
- ret = get_first_tuple(handle, &tuple);
- if (ret != CS_SUCCESS)
- goto done;
-
- /* First tuple should be DEVICE; we should really have either that
- or a CFTABLE_ENTRY of some sort */
- if ((tuple.TupleCode == CISTPL_DEVICE) ||
- (read_tuple(handle, CISTPL_CFTABLE_ENTRY, p) == CS_SUCCESS) ||
- (read_tuple(handle, CISTPL_CFTABLE_ENTRY_CB, p) == CS_SUCCESS))
- dev_ok++;
-
- /* All cards should have a MANFID tuple, and/or a VERS_1 or VERS_2
- tuple, for card identification. Certain old D-Link and Linksys
- cards have only a broken VERS_2 tuple; hence the bogus test. */
- if ((read_tuple(handle, CISTPL_MANFID, p) == CS_SUCCESS) ||
- (read_tuple(handle, CISTPL_VERS_1, p) == CS_SUCCESS) ||
- (read_tuple(handle, CISTPL_VERS_2, p) != CS_NO_MORE_ITEMS))
- ident_ok++;
-
- if (!dev_ok && !ident_ok)
- goto done;
-
- for (info->Chains = 1; info->Chains < MAX_TUPLES; info->Chains++) {
- ret = get_next_tuple(handle, &tuple);
- if (ret != CS_SUCCESS) break;
- if (((tuple.TupleCode > 0x23) && (tuple.TupleCode < 0x40)) ||
- ((tuple.TupleCode > 0x47) && (tuple.TupleCode < 0x80)) ||
- ((tuple.TupleCode > 0x90) && (tuple.TupleCode < 0xff)))
- reserved++;
- }
- if ((info->Chains == MAX_TUPLES) || (reserved > 5) ||
- ((!dev_ok || !ident_ok) && (info->Chains > 10)))
- info->Chains = 0;
-
-done:
- kfree(p);
- return CS_SUCCESS;
-}
-
diff --git a/dump_cis.c b/dump_cis.c
index aa5cd9f..5c8fa0b 100644
--- a/dump_cis.c
+++ b/dump_cis.c
@@ -50,54 +50,7 @@
static int verbose = 0;
static char indent[10] = " ";
-/*====================================================================*/
-
-static int major = 0;
-
-static int lookup_dev(char *name)
-{
- FILE *f;
- int n;
- char s[32], t[32];
-
- f = fopen("/proc/devices", "r");
- if (f == NULL)
- return -1;
- while (fgets(s, 32, f) != NULL) {
- if (sscanf(s, "%d %s", &n, t) == 2)
- if (strcmp(name, t) == 0)
- break;
- }
- fclose(f);
- if (strcmp(name, t) == 0)
- return n;
- else
- return -1;
-}
-
-/*====================================================================*/
-
-static int open_sock(int sock)
-{
- static char *paths[] = {
- "/var/lib/pcmcia", "/var/run", "/dev", "/tmp", NULL
- };
- int fd;
- char **p, fn[64];
- dev_t dev = (major<<8) + sock;
-
- for (p = paths; *p; p++) {
- sprintf(fn, "%s/dc%d", *p, getpid());
- if (mknod(fn, (S_IFCHR|S_IREAD|S_IWRITE), dev) == 0) {
- fd = open(fn, O_RDONLY);
- unlink(fn);
- if (fd >= 0)
- return fd;
- if (errno == ENODEV) break;
- }
- }
- return -1;
-} /* open_sock */
+extern int parse_tuple(tuple_t *tup, cisparse_t *parse);
/*====================================================================*/
@@ -985,40 +938,18 @@
return 0;
}
-static int get_tuple(int fd, ds_ioctl_arg_t *arg, int first)
-{
- int cmd = (first) ? DS_GET_FIRST_TUPLE : DS_GET_NEXT_TUPLE;
- if (ioctl(fd, cmd, arg) != 0) {
- if (errno == ENODEV)
- printf("%sno card\n", indent);
- else if (errno != ENODATA)
- printf("%sget tuple: %s\n", indent, strerror(errno));
- return -1;
- }
- if (ioctl(fd, DS_GET_TUPLE_DATA, arg) != 0) {
- printf("%sget tuple data: %s\n", indent, strerror(errno));
- return -1;
- }
- return 0;
-}
-
/*====================================================================*/
-#define MAX_SOCKS 8
-
int main(int argc, char *argv[])
{
- int i, fd, pfd = -1;
+ int fd;
ds_ioctl_arg_t arg;
int optch, errflg, first;
- int force = 0;
char *infile = NULL;
errflg = 0;
while ((optch = getopt(argc, argv, "fvi:")) != -1) {
switch (optch) {
- case 'f':
- force = 1; break;
case 'v':
verbose = 1; break;
case 'i':
@@ -1027,76 +958,39 @@
errflg = 1; break;
}
}
- if (errflg || (optind < argc)) {
- fprintf(stderr, "usage: %s [-v] [-f] [-i infile]\n", argv[0]);
+ if (errflg || !infile || (optind < argc)) {
+ fprintf(stderr, "usage: %s [-v] -i infile\n", argv[0]);
exit(EXIT_FAILURE);
}
- major = lookup_dev("pcmcia");
- if (major < 0) {
- fprintf(stderr, "no pcmcia driver in /proc/devices\n");
- exit(EXIT_FAILURE);
- }
-
- for (i = 0; (i < MAX_SOCKS) && !(i && infile); i++) {
- nfn = cur = 0;
- if (infile) {
- indent[0] = '\0';
- fd = open(infile, O_RDONLY);
- if (fd < 0) {
- perror("open()");
- return -1;
- }
- pfd = open_sock(0);
- } else {
- strcpy(indent, " ");
- fd = pfd = open_sock(i);
- }
- if (pfd < 0)
- break;
- if (!verbose && (i > 0)) putchar('\n');
- if (!infile) printf("Socket %d:\n", i);
-
- if (!force && !infile) {
- if (ioctl(fd, DS_VALIDATE_CIS, &arg) != 0) {
- printf("%svalidate CIS: %s\n", indent, strerror(errno));
- continue;
- }
- if (arg.cisinfo.Chains == 0) {
- printf("%sno CIS present\n", indent);
- continue;
- }
- }
-
- arg.tuple.TupleDataMax = sizeof(arg.tuple_parse.data);
- arg.tuple.Attributes = TUPLE_RETURN_LINK | TUPLE_RETURN_COMMON;
- arg.tuple.DesiredTuple = RETURN_FIRST_TUPLE;
- arg.tuple.TupleOffset = 0;
-
- for (first = 1; ; first = 0) {
- if (infile) {
- if (get_tuple_buf(fd, &arg, first) != 0) break;
- } else {
- if (get_tuple(fd, &arg, first) != 0) break;
- }
- if (verbose) print_tuple(&arg.tuple_parse);
- if (ioctl(pfd, DS_PARSE_TUPLE, &arg) == 0)
- print_parse(&arg.tuple_parse);
- else if (errno != ENOSYS)
- printf("%sparse error: %s\n", indent,
- strerror(errno));
- if (verbose) putchar('\n');
- if (arg.tuple.TupleCode == CISTPL_END)
- break;
- }
-
- if (!verbose && (nfn > 0))
- printf("%s}\n", indent+2);
- }
- if ((i == 0) && (pfd < 0)) {
+ nfn = cur = 0;
+ indent[0] = '\0';
+ fd = open(infile, O_RDONLY);
+ if (fd < 0) {
perror("open()");
return -1;
}
-
+
+ arg.tuple.TupleDataMax = sizeof(arg.tuple_parse.data);
+ arg.tuple.Attributes = TUPLE_RETURN_LINK | TUPLE_RETURN_COMMON;
+ arg.tuple.DesiredTuple = RETURN_FIRST_TUPLE;
+ arg.tuple.TupleOffset = 0;
+ arg.tuple.TupleData = arg.tuple_parse.data;
+
+ for (first = 1; ; first = 0) {
+ if (get_tuple_buf(fd, &arg, first) != 0) break;
+ if (verbose) print_tuple(&arg.tuple_parse);
+ if (parse_tuple(&arg.tuple_parse.tuple, &arg.tuple_parse.parse) == 0)
+ print_parse(&arg.tuple_parse);
+ else
+ printf("%sparse error\n", indent);
+ if (verbose) putchar('\n');
+ if (arg.tuple.TupleCode == CISTPL_END)
+ break;
+ }
+
+ if (!verbose && (nfn > 0))
+ printf("%s}\n", indent+2);
+
return 0;
}
diff --git a/pcmcia/bulkmem.h b/pcmcia/bulkmem.h
index 7748d44..fa05e69 100644
--- a/pcmcia/bulkmem.h
+++ b/pcmcia/bulkmem.h
@@ -1,8 +1,6 @@
/*
* Definitions for bulk memory services
*
- * bulkmem.h 1.13 2001/08/24 12:16:12
- *
* The contents of this file are subject to the Mozilla Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License
@@ -27,7 +25,6 @@
* other provisions required by the GPL. If you do not delete the
* provisions above, a recipient may use your version of this file
* under either the MPL or the GPL.
- * bulkmem.h 1.3 1995/05/27 04:49:49
*/
#ifndef _LINUX_BULKMEM_H
@@ -186,10 +183,4 @@
MTDSetVpp, MTDRDYMask
};
-#ifdef IN_CARD_SERVICES
-extern int MTDHelperEntry(int func, void *a1, void *a2);
-#else
-extern int MTDHelperEntry(int func, ...);
-#endif
-
#endif /* _LINUX_BULKMEM_H */
diff --git a/pcmcia/ds.h b/pcmcia/ds.h
index b372e59..61336fa 100644
--- a/pcmcia/ds.h
+++ b/pcmcia/ds.h
@@ -1,6 +1,4 @@
/*
- * ds.h 1.58 2001/10/04 03:15:22
- *
* The contents of this file are subject to the Mozilla Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License
@@ -30,7 +28,6 @@
#ifndef _LINUX_DS_H
#define _LINUX_DS_H
-#include <pcmcia/driver_ops.h>
#include <pcmcia/bulkmem.h>
typedef struct tuple_parse_t {
@@ -77,72 +74,4 @@
cisdump_t cisdump;
} ds_ioctl_arg_t;
-#define DS_GET_CARD_SERVICES_INFO _IOR ('d', 1, servinfo_t)
-#define DS_ADJUST_RESOURCE_INFO _IOWR('d', 2, adjust_t)
-#define DS_GET_CONFIGURATION_INFO _IOWR('d', 3, config_info_t)
-#define DS_GET_FIRST_TUPLE _IOWR('d', 4, tuple_t)
-#define DS_GET_NEXT_TUPLE _IOWR('d', 5, tuple_t)
-#define DS_GET_TUPLE_DATA _IOWR('d', 6, tuple_parse_t)
-#define DS_PARSE_TUPLE _IOWR('d', 7, tuple_parse_t)
-#define DS_RESET_CARD _IO ('d', 8)
-#define DS_GET_STATUS _IOWR('d', 9, cs_status_t)
-#define DS_ACCESS_CONFIGURATION_REGISTER _IOWR('d', 10, conf_reg_t)
-#define DS_VALIDATE_CIS _IOR ('d', 11, cisinfo_t)
-#define DS_SUSPEND_CARD _IO ('d', 12)
-#define DS_RESUME_CARD _IO ('d', 13)
-#define DS_EJECT_CARD _IO ('d', 14)
-#define DS_INSERT_CARD _IO ('d', 15)
-#define DS_GET_FIRST_REGION _IOWR('d', 16, region_info_t)
-#define DS_GET_NEXT_REGION _IOWR('d', 17, region_info_t)
-#define DS_REPLACE_CIS _IOWR('d', 18, cisdump_t)
-#define DS_GET_FIRST_WINDOW _IOR ('d', 19, win_info_t)
-#define DS_GET_NEXT_WINDOW _IOWR('d', 20, win_info_t)
-#define DS_GET_MEM_PAGE _IOWR('d', 21, win_info_t)
-
-#define DS_BIND_REQUEST _IOWR('d', 60, bind_info_t)
-#define DS_GET_DEVICE_INFO _IOWR('d', 61, bind_info_t)
-#define DS_GET_NEXT_DEVICE _IOWR('d', 62, bind_info_t)
-#define DS_UNBIND_REQUEST _IOW ('d', 63, bind_info_t)
-#define DS_BIND_MTD _IOWR('d', 64, mtd_info_t)
-
-#ifdef __KERNEL__
-
-typedef struct dev_link_t {
- dev_node_t *dev;
- u_int state, open;
- wait_queue_head_t pending;
- struct timer_list release;
- client_handle_t handle;
- io_req_t io;
- irq_req_t irq;
- config_req_t conf;
- window_handle_t win;
- void *priv;
- struct dev_link_t *next;
-} dev_link_t;
-
-/* Flags for device state */
-#define DEV_PRESENT 0x01
-#define DEV_CONFIG 0x02
-#define DEV_STALE_CONFIG 0x04 /* release on close */
-#define DEV_STALE_LINK 0x08 /* detach on release */
-#define DEV_CONFIG_PENDING 0x10
-#define DEV_RELEASE_PENDING 0x20
-#define DEV_SUSPEND 0x40
-#define DEV_BUSY 0x80
-
-#define DEV_OK(l) \
- ((l) && ((l->state & ~DEV_BUSY) == (DEV_CONFIG|DEV_PRESENT)))
-
-int register_pccard_driver(dev_info_t *dev_info,
- dev_link_t *(*attach)(void),
- void (*detach)(dev_link_t *));
-
-int unregister_pccard_driver(dev_info_t *dev_info);
-
-#define register_pcmcia_driver register_pccard_driver
-#define unregister_pcmcia_driver unregister_pccard_driver
-
-#endif /* __KERNEL__ */
-
#endif /* _LINUX_DS_H */