readcis.h revision 59656
110217Sphk/*
215284Snate * Copyright (c) 1995 Andrew McRae.  All rights reserved.
315284Snate *
415284Snate * Redistribution and use in source and binary forms, with or without
515284Snate * modification, are permitted provided that the following conditions
615284Snate * are met:
715284Snate * 1. Redistributions of source code must retain the above copyright
815284Snate *    notice, this list of conditions and the following disclaimer.
915284Snate * 2. Redistributions in binary form must reproduce the above copyright
1015284Snate *    notice, this list of conditions and the following disclaimer in the
1115284Snate *    documentation and/or other materials provided with the distribution.
1215284Snate * 3. The name of the author may not be used to endorse or promote products
1315284Snate *    derived from this software without specific prior written permission.
1415284Snate *
1515284Snate * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
1615284Snate * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
1715284Snate * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
1815284Snate * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
1915284Snate * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
2015284Snate * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2115284Snate * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2215284Snate * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2315284Snate * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
2415284Snate * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2515284Snate *
2650479Speter * $FreeBSD: head/usr.sbin/pccard/pccardd/readcis.h 59656 2000-04-26 15:36:43Z iwasaki $
2710217Sphk */
2815284Snate
2915177Snatestruct tuple {
3010217Sphk	struct tuple *next;
3110217Sphk	unsigned char code;
3215177Snate	int     length;
3310217Sphk	unsigned char *data;
3415177Snate};
3510217Sphk
3615177Snatestruct tuple_list {
3710217Sphk	struct tuple_list *next;
3810217Sphk	struct tuple *tuples;
3915177Snate	off_t   offs;
4015177Snate	int     flags;
4115177Snate};
4210217Sphk
4315177Snatestruct tuple_info {
4415177Snate	char   *name;
4510217Sphk	unsigned char code;
4615177Snate	unsigned char length;		/* 255 means variable length */
4715177Snate};
4815177Snate
4910217Sphk/*
5010217Sphk *	Memory device descriptor.
5110217Sphk */
5215177Snatestruct dev_mem {
5310217Sphk	unsigned char valid;
5410217Sphk	unsigned char type;
5510217Sphk	unsigned char speed;
5610217Sphk	unsigned char wps;
5710217Sphk	unsigned char addr;
5810217Sphk	unsigned char units;
5915177Snate};
6015177Snate
6110217Sphk/*
6210217Sphk *	One I/O structure describing a possible I/O map
6310217Sphk *	of the card.
6410217Sphk */
6515177Snatestruct cis_ioblk {
6610217Sphk	struct cis_ioblk *next;
6710217Sphk	unsigned int addr;
6810217Sphk	unsigned int size;
6915177Snate};
7015177Snate
7110217Sphk/*
7210217Sphk *	A structure storing a memory map for the card.
7310217Sphk */
7415177Snatestruct cis_memblk {
7510217Sphk	struct cis_memblk *next;
7610217Sphk	unsigned int address;
7710217Sphk	unsigned int length;
7810217Sphk	unsigned int host_address;
7915177Snate};
8015177Snate
8110217Sphk/*
8210217Sphk *	One configuration entry for the card.
8310217Sphk */
8415177Snatestruct cis_config {
8510217Sphk	struct cis_config *next;
8610217Sphk	unsigned int pwr:1;		/* Which values are defined. */
8710217Sphk	unsigned int timing:1;
8810217Sphk	unsigned int iospace:1;
8910217Sphk	unsigned int irq:1;
9010217Sphk	unsigned int memspace:1;
9110217Sphk	unsigned int misc_valid:1;
9210217Sphk	unsigned char id;
9310217Sphk	unsigned char io_blks;
9410217Sphk	unsigned char io_addr;
9510217Sphk	unsigned char io_bus;
9610217Sphk	struct cis_ioblk *io;
9710217Sphk	unsigned char irqlevel;
9810217Sphk	unsigned char irq_flags;
9910217Sphk	unsigned irq_mask;
10010217Sphk	unsigned char memwins;
10110217Sphk	struct cis_memblk *mem;
10210217Sphk	unsigned char misc;
10315177Snate};
10415177Snate
10510217Sphk/*
10610217Sphk *	Structure holding all data retrieved from the
10710217Sphk *	CIS block on the card.
10810217Sphk *	The default configuration contains interface defaults
10910217Sphk *	not listed in each separate configuration.
11010217Sphk */
11115177Snatestruct cis {
11210217Sphk	struct tuple_list *tlist;
11359656Siwasaki	char    *manuf;
11459656Siwasaki	char    *vers;
11559656Siwasaki	char    *add_info1;
11659656Siwasaki	char    *add_info2;
11710217Sphk	unsigned char maj_v, min_v;
11810217Sphk	unsigned char last_config;
11910217Sphk	unsigned char ccrs;
12010217Sphk	unsigned long reg_addr;
12159053Siwasaki	unsigned char func_id1, func_id2;
12210217Sphk	struct dev_mem attr_mem;
12310217Sphk	struct dev_mem common_mem;
12410217Sphk	struct cis_config *def_config;
12510217Sphk	struct cis_config *conf;
12659656Siwasaki	unsigned char *lan_nid;
12715177Snate};
12810217Sphk
12959656Siwasaki#define	tpl32(tp)	((*((tp) + 3) << 24) | \
13059656Siwasaki			 (*((tp) + 2) << 16) | \
13159656Siwasaki			 (*((tp) + 1) << 8)  | *(tp))
13259656Siwasaki#define	tpl24(tp)	((*((tp) + 2) << 16) | \
13359656Siwasaki			 (*((tp) + 1) << 8)  | *(tp))
13459656Siwasaki#define	tpl16(tp)	((*((tp) + 1) << 8)  | *(tp))
13559656Siwasaki
13615177Snatevoid   *xmalloc(int);
13759656Siwasakivoid    dump(unsigned char *, int);
13815177Snatevoid    dumpcis(struct cis *);
13915177Snatevoid    freecis(struct cis *);
14016484Snatestruct cis *readcis(int);
14116484Snate
14215177Snatechar   *tuple_name(unsigned char);
14359656Siwasakiu_int   parse_num(int, u_char *, u_char **, int);
144