Skip to contentSkip to conversation

Add programs to work with CIS files

PATCH In review Dmitry Eremin-Solenikov 3 participants 8 messages Sep 24, 2010 – Sep 25, 2010

lore
Share & tools
lore
#0 lore raw

cover Add programs to work with CIS files

linux-firmware.git has several CIS files - special files fixing bugs in description of PCMCIA hardware. Those files are binary, but they can be (and most probably were in the past) generated from simple text files by the use of special compiler (developed by pcmcia-cs project). This patch serie adds text sources of CIS files and two programs to convert between text and binary representations of CIS files.

#1 lore raw

PATCH 1/5 Import cistpl.h header from linux kernel

For mkcis and dump_cis programs we need a <pcmcia/cistpl.h> header from the linux kernel.

---
 mkcis/cistpl.h |  580 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 580 insertions(+), 0 deletions(-)
 create mode 100644 mkcis/cistpl.h
mkcis/cistpl.h new file +580 -0
new file mode 100644
index 0000000..1c5088c
@@ -0,0 +1,580 @@
+/*
+ * cistpl.h
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * The initial developer of the original code is David A. Hinds
+ * <[email protected]>.  Portions created by David A. Hinds
+ * are Copyright (C) 1999 David A. Hinds.  All Rights Reserved.
+ *
+ * (C) 1999             David A. Hinds
+ */
+
+#ifndef _LINUX_CISTPL_H
+#define _LINUX_CISTPL_H
+
+typedef unsigned char cisdata_t;
+
+#define CISTPL_NULL		0x00
+#define CISTPL_DEVICE		0x01
+#define CISTPL_LONGLINK_CB	0x02
+#define CISTPL_INDIRECT		0x03
+#define CISTPL_CONFIG_CB	0x04
+#define CISTPL_CFTABLE_ENTRY_CB	0x05
+#define CISTPL_LONGLINK_MFC	0x06
+#define CISTPL_BAR		0x07
+#define CISTPL_PWR_MGMNT	0x08
+#define CISTPL_EXTDEVICE	0x09
+#define CISTPL_CHECKSUM		0x10
+#define CISTPL_LONGLINK_A	0x11
+#define CISTPL_LONGLINK_C	0x12
+#define CISTPL_LINKTARGET	0x13
+#define CISTPL_NO_LINK		0x14
+#define CISTPL_VERS_1		0x15
+#define CISTPL_ALTSTR		0x16
+#define CISTPL_DEVICE_A		0x17
+#define CISTPL_JEDEC_C		0x18
+#define CISTPL_JEDEC_A		0x19
+#define CISTPL_CONFIG		0x1a
+#define CISTPL_CFTABLE_ENTRY	0x1b
+#define CISTPL_DEVICE_OC	0x1c
+#define CISTPL_DEVICE_OA	0x1d
+#define CISTPL_DEVICE_GEO	0x1e
+#define CISTPL_DEVICE_GEO_A	0x1f
+#define CISTPL_MANFID		0x20
+#define CISTPL_FUNCID		0x21
+#define CISTPL_FUNCE		0x22
+#define CISTPL_SWIL		0x23
+#define CISTPL_END		0xff
+/* Layer 2 tuples */
+#define CISTPL_VERS_2		0x40
+#define CISTPL_FORMAT		0x41
+#define CISTPL_GEOMETRY		0x42
+#define CISTPL_BYTEORDER	0x43
+#define CISTPL_DATE		0x44
+#define CISTPL_BATTERY		0x45
+#define CISTPL_FORMAT_A		0x47
+/* Layer 3 tuples */
+#define CISTPL_ORG		0x46
+#define CISTPL_SPCL		0x90
+
+typedef struct cistpl_longlink_t {
+    u_int	addr;
+} cistpl_longlink_t;
+
+typedef struct cistpl_checksum_t {
+    u_short	addr;
+    u_short	len;
+    u_char	sum;
+} cistpl_checksum_t;
+
+#define CISTPL_MAX_FUNCTIONS	8
+#define CISTPL_MFC_ATTR		0x00
+#define CISTPL_MFC_COMMON	0x01
+
+typedef struct cistpl_longlink_mfc_t {
+    u_char	nfn;
+    struct {
+	u_char	space;
+	u_int	addr;
+    } fn[CISTPL_MAX_FUNCTIONS];
+} cistpl_longlink_mfc_t;
+
+#define CISTPL_MAX_ALTSTR_STRINGS	4
+
+typedef struct cistpl_altstr_t {
+    u_char	ns;
+    u_char	ofs[CISTPL_MAX_ALTSTR_STRINGS];
+    char	str[254];
+} cistpl_altstr_t;
+
+#define CISTPL_DTYPE_NULL	0x00
+#define CISTPL_DTYPE_ROM	0x01
+#define CISTPL_DTYPE_OTPROM	0x02
+#define CISTPL_DTYPE_EPROM	0x03
+#define CISTPL_DTYPE_EEPROM	0x04
+#define CISTPL_DTYPE_FLASH	0x05
+#define CISTPL_DTYPE_SRAM	0x06
+#define CISTPL_DTYPE_DRAM	0x07
+#define CISTPL_DTYPE_FUNCSPEC	0x0d
+#define CISTPL_DTYPE_EXTEND	0x0e
+
+#define CISTPL_MAX_DEVICES	4
+
+typedef struct cistpl_device_t {
+    u_char	ndev;
+    struct {
+	u_char 	type;
+	u_char	wp;
+	u_int	speed;
+	u_int	size;
+    } dev[CISTPL_MAX_DEVICES];
+} cistpl_device_t;
+
+#define CISTPL_DEVICE_MWAIT	0x01
+#define CISTPL_DEVICE_3VCC	0x02
+
+typedef struct cistpl_device_o_t {
+    u_char		flags;
+    cistpl_device_t	device;
+} cistpl_device_o_t;
+
+#define CISTPL_VERS_1_MAX_PROD_STRINGS	4
+
+typedef struct cistpl_vers_1_t {
+    u_char	major;
+    u_char	minor;
+    u_char	ns;
+    u_char	ofs[CISTPL_VERS_1_MAX_PROD_STRINGS];
+    char	str[254];
+} cistpl_vers_1_t;
+
+typedef struct cistpl_jedec_t {
+    u_char	nid;
+    struct {
+	u_char	mfr;
+	u_char	info;
+    } id[CISTPL_MAX_DEVICES];
+} cistpl_jedec_t;
+
+typedef struct cistpl_manfid_t {
+    u_short	manf;
+    u_short	card;
+} cistpl_manfid_t;
+
+#define CISTPL_FUNCID_MULTI	0x00
+#define CISTPL_FUNCID_MEMORY	0x01
+#define CISTPL_FUNCID_SERIAL	0x02
+#define CISTPL_FUNCID_PARALLEL	0x03
+#define CISTPL_FUNCID_FIXED	0x04
+#define CISTPL_FUNCID_VIDEO	0x05
+#define CISTPL_FUNCID_NETWORK	0x06
+#define CISTPL_FUNCID_AIMS	0x07
+#define CISTPL_FUNCID_SCSI	0x08
+
+#define CISTPL_SYSINIT_POST	0x01
+#define CISTPL_SYSINIT_ROM	0x02
+
+typedef struct cistpl_funcid_t {
+    u_char	func;
+    u_char	sysinit;
+} cistpl_funcid_t;
+
+typedef struct cistpl_funce_t {
+    u_char	type;
+    u_char	data[0];
+} cistpl_funce_t;
+
+/*======================================================================
+
+    Modem Function Extension Tuples
+
+======================================================================*/
+
+#define CISTPL_FUNCE_SERIAL_IF		0x00
+#define CISTPL_FUNCE_SERIAL_CAP		0x01
+#define CISTPL_FUNCE_SERIAL_SERV_DATA	0x02
+#define CISTPL_FUNCE_SERIAL_SERV_FAX	0x03
+#define CISTPL_FUNCE_SERIAL_SERV_VOICE	0x04
+#define CISTPL_FUNCE_SERIAL_CAP_DATA	0x05
+#define CISTPL_FUNCE_SERIAL_CAP_FAX	0x06
+#define CISTPL_FUNCE_SERIAL_CAP_VOICE	0x07
+#define CISTPL_FUNCE_SERIAL_IF_DATA	0x08
+#define CISTPL_FUNCE_SERIAL_IF_FAX	0x09
+#define CISTPL_FUNCE_SERIAL_IF_VOICE	0x0a
+
+/* UART identification */
+#define CISTPL_SERIAL_UART_8250		0x00
+#define CISTPL_SERIAL_UART_16450	0x01
+#define CISTPL_SERIAL_UART_16550	0x02
+#define CISTPL_SERIAL_UART_8251		0x03
+#define CISTPL_SERIAL_UART_8530		0x04
+#define CISTPL_SERIAL_UART_85230	0x05
+
+/* UART capabilities */
+#define CISTPL_SERIAL_UART_SPACE	0x01
+#define CISTPL_SERIAL_UART_MARK		0x02
+#define CISTPL_SERIAL_UART_ODD		0x04
+#define CISTPL_SERIAL_UART_EVEN		0x08
+#define CISTPL_SERIAL_UART_5BIT		0x01
+#define CISTPL_SERIAL_UART_6BIT		0x02
+#define CISTPL_SERIAL_UART_7BIT		0x04
+#define CISTPL_SERIAL_UART_8BIT		0x08
+#define CISTPL_SERIAL_UART_1STOP	0x10
+#define CISTPL_SERIAL_UART_MSTOP	0x20
+#define CISTPL_SERIAL_UART_2STOP	0x40
+
+typedef struct cistpl_serial_t {
+    u_char	uart_type;
+    u_char	uart_cap_0;
+    u_char	uart_cap_1;
+} cistpl_serial_t;
+
+typedef struct cistpl_modem_cap_t {
+    u_char	flow;
+    u_char	cmd_buf;
+    u_char	rcv_buf_0, rcv_buf_1, rcv_buf_2;
+    u_char	xmit_buf_0, xmit_buf_1, xmit_buf_2;
+} cistpl_modem_cap_t;
+
+#define CISTPL_SERIAL_MOD_103		0x01
+#define CISTPL_SERIAL_MOD_V21		0x02
+#define CISTPL_SERIAL_MOD_V23		0x04
+#define CISTPL_SERIAL_MOD_V22		0x08
+#define CISTPL_SERIAL_MOD_212A		0x10
+#define CISTPL_SERIAL_MOD_V22BIS	0x20
+#define CISTPL_SERIAL_MOD_V26		0x40
+#define CISTPL_SERIAL_MOD_V26BIS	0x80
+#define CISTPL_SERIAL_MOD_V27BIS	0x01
+#define CISTPL_SERIAL_MOD_V29		0x02
+#define CISTPL_SERIAL_MOD_V32		0x04
+#define CISTPL_SERIAL_MOD_V32BIS	0x08
+#define CISTPL_SERIAL_MOD_V34		0x10
+
+#define CISTPL_SERIAL_ERR_MNP2_4	0x01
+#define CISTPL_SERIAL_ERR_V42_LAPM	0x02
+
+#define CISTPL_SERIAL_CMPR_V42BIS	0x01
+#define CISTPL_SERIAL_CMPR_MNP5		0x02
+
+#define CISTPL_SERIAL_CMD_AT1		0x01
+#define CISTPL_SERIAL_CMD_AT2		0x02
+#define CISTPL_SERIAL_CMD_AT3		0x04
+#define CISTPL_SERIAL_CMD_MNP_AT	0x08
+#define CISTPL_SERIAL_CMD_V25BIS	0x10
+#define CISTPL_SERIAL_CMD_V25A		0x20
+#define CISTPL_SERIAL_CMD_DMCL		0x40
+
+typedef struct cistpl_data_serv_t {
+    u_char	max_data_0;
+    u_char	max_data_1;
+    u_char	modulation_0;
+    u_char	modulation_1;
+    u_char	error_control;
+    u_char	compression;
+    u_char	cmd_protocol;
+    u_char	escape;
+    u_char	encrypt;
+    u_char	misc_features;
+    u_char	ccitt_code[0];
+} cistpl_data_serv_t;
+
+typedef struct cistpl_fax_serv_t {
+    u_char	max_data_0;
+    u_char	max_data_1;
+    u_char	modulation;
+    u_char	encrypt;
+    u_char	features_0;
+    u_char	features_1;
+    u_char	ccitt_code[0];
+} cistpl_fax_serv_t;
+
+typedef struct cistpl_voice_serv_t {
+    u_char	max_data_0;
+    u_char	max_data_1;
+} cistpl_voice_serv_t;
+
+/*======================================================================
+
+    LAN Function Extension Tuples
+
+======================================================================*/
+
+#define CISTPL_FUNCE_LAN_TECH		0x01
+#define CISTPL_FUNCE_LAN_SPEED		0x02
+#define CISTPL_FUNCE_LAN_MEDIA		0x03
+#define CISTPL_FUNCE_LAN_NODE_ID	0x04
+#define CISTPL_FUNCE_LAN_CONNECTOR	0x05
+
+/* LAN technologies */
+#define CISTPL_LAN_TECH_ARCNET		0x01
+#define CISTPL_LAN_TECH_ETHERNET	0x02
+#define CISTPL_LAN_TECH_TOKENRING	0x03
+#define CISTPL_LAN_TECH_LOCALTALK	0x04
+#define CISTPL_LAN_TECH_FDDI		0x05
+#define CISTPL_LAN_TECH_ATM		0x06
+#define CISTPL_LAN_TECH_WIRELESS	0x07
+
+typedef struct cistpl_lan_tech_t {
+    u_char	tech;
+} cistpl_lan_tech_t;
+
+typedef struct cistpl_lan_speed_t {
+    u_int	speed;
+} cistpl_lan_speed_t;
+
+/* LAN media definitions */
+#define CISTPL_LAN_MEDIA_UTP		0x01
+#define CISTPL_LAN_MEDIA_STP		0x02
+#define CISTPL_LAN_MEDIA_THIN_COAX	0x03
+#define CISTPL_LAN_MEDIA_THICK_COAX	0x04
+#define CISTPL_LAN_MEDIA_FIBER		0x05
+#define CISTPL_LAN_MEDIA_900MHZ		0x06
+#define CISTPL_LAN_MEDIA_2GHZ		0x07
+#define CISTPL_LAN_MEDIA_5GHZ		0x08
+#define CISTPL_LAN_MEDIA_DIFF_IR	0x09
+#define CISTPL_LAN_MEDIA_PTP_IR		0x0a
+
+typedef struct cistpl_lan_media_t {
+    u_char	media;
+} cistpl_lan_media_t;
+
+typedef struct cistpl_lan_node_id_t {
+    u_char	nb;
+    u_char	id[16];
+} cistpl_lan_node_id_t;
+
+typedef struct cistpl_lan_connector_t {
+    u_char	code;
+} cistpl_lan_connector_t;
+
+/*======================================================================
+
+    IDE Function Extension Tuples
+
+======================================================================*/
+
+#define CISTPL_IDE_INTERFACE		0x01
+
+typedef struct cistpl_ide_interface_t {
+    u_char	interface;
+} cistpl_ide_interface_t;
+
+/* First feature byte */
+#define CISTPL_IDE_SILICON		0x04
+#define CISTPL_IDE_UNIQUE		0x08
+#define CISTPL_IDE_DUAL			0x10
+
+/* Second feature byte */
+#define CISTPL_IDE_HAS_SLEEP		0x01
+#define CISTPL_IDE_HAS_STANDBY		0x02
+#define CISTPL_IDE_HAS_IDLE		0x04
+#define CISTPL_IDE_LOW_POWER		0x08
+#define CISTPL_IDE_REG_INHIBIT		0x10
+#define CISTPL_IDE_HAS_INDEX		0x20
+#define CISTPL_IDE_IOIS16		0x40
+
+typedef struct cistpl_ide_feature_t {
+    u_char	feature1;
+    u_char	feature2;
+} cistpl_ide_feature_t;
+
+#define CISTPL_FUNCE_IDE_IFACE		0x01
+#define CISTPL_FUNCE_IDE_MASTER		0x02
+#define CISTPL_FUNCE_IDE_SLAVE		0x03
+
+/*======================================================================
+
+    Configuration Table Entries
+
+======================================================================*/
+
+#define CISTPL_BAR_SPACE	0x07
+#define CISTPL_BAR_SPACE_IO	0x10
+#define CISTPL_BAR_PREFETCH	0x20
+#define CISTPL_BAR_CACHEABLE	0x40
+#define CISTPL_BAR_1MEG_MAP	0x80
+
+typedef struct cistpl_bar_t {
+    u_char	attr;
+    u_int	size;
+} cistpl_bar_t;
+
+typedef struct cistpl_config_t {
+    u_char	last_idx;
+    u_int	base;
+    u_int	rmask[4];
+    u_char	subtuples;
+} cistpl_config_t;
+
+/* These are bits in the 'present' field, and indices in 'param' */
+#define CISTPL_POWER_VNOM	0
+#define CISTPL_POWER_VMIN	1
+#define CISTPL_POWER_VMAX	2
+#define CISTPL_POWER_ISTATIC	3
+#define CISTPL_POWER_IAVG	4
+#define CISTPL_POWER_IPEAK	5
+#define CISTPL_POWER_IDOWN	6
+
+#define CISTPL_POWER_HIGHZ_OK	0x01
+#define CISTPL_POWER_HIGHZ_REQ	0x02
+
+typedef struct cistpl_power_t {
+    u_char	present;
+    u_char	flags;
+    u_int	param[7];
+} cistpl_power_t;
+
+typedef struct cistpl_timing_t {
+    u_int	wait, waitscale;
+    u_int	ready, rdyscale;
+    u_int	reserved, rsvscale;
+} cistpl_timing_t;
+
+#define CISTPL_IO_LINES_MASK	0x1f
+#define CISTPL_IO_8BIT		0x20
+#define CISTPL_IO_16BIT		0x40
+#define CISTPL_IO_RANGE		0x80
+
+#define CISTPL_IO_MAX_WIN	16
+
+typedef struct cistpl_io_t {
+    u_char	flags;
+    u_char	nwin;
+    struct {
+	u_int	base;
+	u_int	len;
+    } win[CISTPL_IO_MAX_WIN];
+} cistpl_io_t;
+
+typedef struct cistpl_irq_t {
+    u_int	IRQInfo1;
+    u_int	IRQInfo2;
+} cistpl_irq_t;
+
+#define CISTPL_MEM_MAX_WIN	8
+
+typedef struct cistpl_mem_t {
+    u_char	flags;
+    u_char	nwin;
+    struct {
+	u_int	len;
+	u_int	card_addr;
+	u_int	host_addr;
+    } win[CISTPL_MEM_MAX_WIN];
+} cistpl_mem_t;
+
+#define CISTPL_CFTABLE_DEFAULT		0x0001
+#define CISTPL_CFTABLE_BVDS		0x0002
+#define CISTPL_CFTABLE_WP		0x0004
+#define CISTPL_CFTABLE_RDYBSY		0x0008
+#define CISTPL_CFTABLE_MWAIT		0x0010
+#define CISTPL_CFTABLE_AUDIO		0x0800
+#define CISTPL_CFTABLE_READONLY		0x1000
+#define CISTPL_CFTABLE_PWRDOWN		0x2000
+
+typedef struct cistpl_cftable_entry_t {
+    u_char		index;
+    u_short		flags;
+    u_char		interface;
+    cistpl_power_t	vcc, vpp1, vpp2;
+    cistpl_timing_t	timing;
+    cistpl_io_t		io;
+    cistpl_irq_t	irq;
+    cistpl_mem_t	mem;
+    u_char		subtuples;
+} cistpl_cftable_entry_t;
+
+#define CISTPL_CFTABLE_MASTER		0x000100
+#define CISTPL_CFTABLE_INVALIDATE	0x000200
+#define CISTPL_CFTABLE_VGA_PALETTE	0x000400
+#define CISTPL_CFTABLE_PARITY		0x000800
+#define CISTPL_CFTABLE_WAIT		0x001000
+#define CISTPL_CFTABLE_SERR		0x002000
+#define CISTPL_CFTABLE_FAST_BACK	0x004000
+#define CISTPL_CFTABLE_BINARY_AUDIO	0x010000
+#define CISTPL_CFTABLE_PWM_AUDIO	0x020000
+
+typedef struct cistpl_cftable_entry_cb_t {
+    u_char		index;
+    u_int		flags;
+    cistpl_power_t	vcc, vpp1, vpp2;
+    u_char		io;
+    cistpl_irq_t	irq;
+    u_char		mem;
+    u_char		subtuples;
+} cistpl_cftable_entry_cb_t;
+
+typedef struct cistpl_device_geo_t {
+    u_char		ngeo;
+    struct {
+	u_char		buswidth;
+	u_int		erase_block;
+	u_int		read_block;
+	u_int		write_block;
+	u_int		partition;
+	u_int		interleave;
+    } geo[CISTPL_MAX_DEVICES];
+} cistpl_device_geo_t;
+
+typedef struct cistpl_vers_2_t {
+    u_char	vers;
+    u_char	comply;
+    u_short	dindex;
+    u_char	vspec8, vspec9;
+    u_char	nhdr;
+    u_char	vendor, info;
+    char	str[244];
+} cistpl_vers_2_t;
+
+typedef struct cistpl_org_t {
+    u_char	data_org;
+    char	desc[30];
+} cistpl_org_t;
+
+#define CISTPL_ORG_FS		0x00
+#define CISTPL_ORG_APPSPEC	0x01
+#define CISTPL_ORG_XIP		0x02
+
+typedef struct cistpl_format_t {
+    u_char	type;
+    u_char	edc;
+    u_int	offset;
+    u_int	length;
+} cistpl_format_t;
+
+#define CISTPL_FORMAT_DISK	0x00
+#define CISTPL_FORMAT_MEM	0x01
+
+#define CISTPL_EDC_NONE		0x00
+#define CISTPL_EDC_CKSUM	0x01
+#define CISTPL_EDC_CRC		0x02
+#define CISTPL_EDC_PCC		0x03
+
+typedef union cisparse_t {
+    cistpl_device_t		device;
+    cistpl_checksum_t		checksum;
+    cistpl_longlink_t		longlink;
+    cistpl_longlink_mfc_t	longlink_mfc;
+    cistpl_vers_1_t		version_1;
+    cistpl_altstr_t		altstr;
+    cistpl_jedec_t		jedec;
+    cistpl_manfid_t		manfid;
+    cistpl_funcid_t		funcid;
+    cistpl_funce_t		funce;
+    cistpl_bar_t		bar;
+    cistpl_config_t		config;
+    cistpl_cftable_entry_t	cftable_entry;
+    cistpl_cftable_entry_cb_t	cftable_entry_cb;
+    cistpl_device_geo_t		device_geo;
+    cistpl_vers_2_t		vers_2;
+    cistpl_org_t		org;
+    cistpl_format_t		format;
+} cisparse_t;
+
+typedef struct tuple_t {
+    u_int	Attributes;
+    cisdata_t 	DesiredTuple;
+    u_int	Flags;		/* internal use */
+    u_int	LinkOffset;	/* internal use */
+    u_int	CISOffset;	/* internal use */
+    cisdata_t	TupleCode;
+    cisdata_t	TupleLink;
+    cisdata_t	TupleOffset;
+    cisdata_t	TupleDataMax;
+    cisdata_t	TupleDataLen;
+    cisdata_t	*TupleData;
+} tuple_t;
+
+/* Special cisdata_t value */
+#define RETURN_FIRST_TUPLE	0xff
+
+/* Attributes for tuple calls */
+#define TUPLE_RETURN_LINK	0x01
+#define TUPLE_RETURN_COMMON	0x02
+
+#define CISTPL_MAX_CIS_SIZE	0x200
+
+#endif /* LINUX_CISTPL_H */
Signature · 1 line
1.7.1
#2 lore raw

PATCH 2/5 Add mkcis - a program that can create .cis from text description

In reply to Dmitry Eremin-Solenikov

For CIS files (describing hardware on PCMCIA and some other busses) binary file isn't the 'preferred for for modification' in most cases. pcmcia-cs project have developed pack_cis program which can be used (and was used most probably) to generate .cis files from simple text descriptions. Import this code under the name of mkcis.

---
 mkcis/mkcis-lexer.l      |  228 +++++
 mkcis/mkcis-lexer.lex.c  | 2547 ++++++++++++++++++++++++++++++++++++++++++++++
 mkcis/mkcis-parser.tab.c | 2338 ++++++++++++++++++++++++++++++++++++++++++
 mkcis/mkcis-parser.tab.h |  127 +++
 mkcis/mkcis-parser.y     |  383 +++++++
 mkcis/mkcis.c            |  471 +++++++++
 mkcis/mkcis.h            |   49 +
 7 files changed, 6143 insertions(+), 0 deletions(-)
 create mode 100644 mkcis/mkcis-lexer.l
 create mode 100644 mkcis/mkcis-lexer.lex.c
 create mode 100644 mkcis/mkcis-parser.tab.c
 create mode 100644 mkcis/mkcis-parser.tab.h
 create mode 100644 mkcis/mkcis-parser.y
 create mode 100644 mkcis/mkcis.c
 create mode 100644 mkcis/mkcis.h
mkcis/mkcis-lexer.l new file +228 -0
new file mode 100644
index 0000000..d802e3e
@@ -0,0 +1,228 @@
+%{
+/*
+ * lex_cis.l 1.13 2000/06/12 21:34:19
+ *
+ * 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
+ * at http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
+ * the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * The initial developer of the original code is David A. Hinds
+ * <[email protected]>.  Portions created by David A. Hinds
+ * are Copyright (C) 1999 David A. Hinds.  All Rights Reserved.
+ *
+ * Alternatively, the contents of this file may be used under the
+ * terms of the GNU Public License version 2 (the "GPL"), in which
+ * case the provisions of the GPL are applicable instead of the
+ * above.  If you wish to allow the use of your version of this file
+ * only under the terms of the GPL and not to allow others to use
+ * your version of this file under the MPL, indicate your decision by
+ * deleting the provisions above and replace them with the notice and
+ * 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.
+ */
+
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <syslog.h>
+
+#include <cistpl.h>
+
+#include "mkcis.h"
+
+#define YY_NO_INPUT
+#include "mkcis-parser.tab.h"
+
+/* For assembling nice error messages */
+int current_lineno;
+
+static int lex_number(char *);
+static int lex_units(char *, int, int);
+static int lex_float(char *);
+static int lex_string(char *);
+
+%}
+%option nounput
+
+
+int	[0-9]+
+hex	0x[0-9a-fA-F]+
+flt	[0-9]+\.[0-9]*
+str	\"([^"]|\\.)*\"
+
+%%
+
+\n		current_lineno++;
+[ \t]*		/* skip */ ;
+[ ]*[#;].*	/* skip */ ;
+
+funcid		return FUNCID;
+mfc		return MFC;
+manfid		return MANFID;
+vers_1		return VERS_1;
+checksum	return CHECKSUM;
+
+dev_info	return DEV_INFO;
+attr_dev_info	return ATTR_DEV_INFO;
+no_info		return NO_INFO;
+NULL		return lex_number("0");
+ROM		return lex_number("1");
+EPROM		return lex_number("3");
+EEPROM		return lex_number("4");
+FLASH		return lex_number("5");
+SRAM		return lex_number("6");
+DRAM		return lex_number("7");
+fn_specific	return lex_number("13");
+
+config		return CONFIG;
+base		return BASE;
+mask		return MASK;
+last_index	return LAST_INDEX;
+\[post\]	return POST;
+\[rom\]		return ROM;
+
+cftable_entry	return CFTABLE;
+\[default\]	return DEFAULT;
+\[bvd\]		return BVD;
+\[wp\]		return WP;
+\[rdybsy\]	return RDYBSY;
+\[mwait\]	return MWAIT;
+\[audio\]	return AUDIO;
+\[readonly\]	return READONLY;
+\[pwrdown\]	return PWRDOWN;
+
+Vcc		return VCC;
+Vpp1		return VPP1;
+Vpp2		return VPP2;
+Vnom		return VNOM;
+Vmin		return VMIN;
+Vmax		return VMAX;
+Istatic		return ISTATIC;
+Iavg		return IAVG;
+Ipeak		return IPEAK;
+Idown		return IDOWN;
+
+io		return IO;
+memory		return MEM;
+\[8bit\]	return BIT8;
+\[16bit\]	return BIT16;
+\[lines		return LINES;
+\[range\]	return RANGE;
+
+irq		return IRQ_NO;
+\[level\]	return LEVEL;
+\[pulse\]	return PULSE;
+\[shared\]	return SHARED;
+
+timing		return TIMING;
+wait		return WAIT;
+ready		return READY;
+reserved	return RESERVED;
+
+multi_function	return lex_number("0");
+memory_card	return lex_number("1");
+serial_port	return lex_number("2");
+parallel_port	return lex_number("3");
+fixed_disk	return lex_number("4");
+video_adapter	return lex_number("5");
+network_adapter	return lex_number("6");
+aims_card	return lex_number("7");
+scsi_adapter	return lex_number("8");
+
+{int}		return lex_number(yytext);
+{hex}		return lex_number(yytext);
+
+{int}b		return lex_units(yytext, 1, SIZE);
+{int}kb		return lex_units(yytext, 1024, SIZE);
+{int}mb		return lex_units(yytext, 1024*1024, SIZE);
+
+{flt}s		return lex_units(yytext, 1000000000, TIME);
+{flt}ms		return lex_units(yytext, 1000000, TIME);
+{flt}us		return lex_units(yytext, 1000, TIME);
+{flt}ns		return lex_units(yytext, 1, TIME);
+{int}s		return lex_units(yytext, 1000000000, TIME);
+{int}ms		return lex_units(yytext, 1000000, TIME);
+{int}us		return lex_units(yytext, 1000, TIME);
+{int}ns		return lex_units(yytext, 1, TIME);
+
+{flt}V		return lex_units(yytext, 100000, VOLTAGE);
+{flt}mV		return lex_units(yytext, 100, VOLTAGE);
+{flt}uV		return lex_units(yytext, 0.1, VOLTAGE);
+{int}V		return lex_units(yytext, 100000, VOLTAGE);
+{int}mV		return lex_units(yytext, 100, VOLTAGE);
+{int}uV		return lex_units(yytext, 0.1, VOLTAGE);
+
+{flt}A		return lex_units(yytext, 10000000, CURRENT);
+{flt}mA		return lex_units(yytext, 10000, CURRENT);
+{flt}uA		return lex_units(yytext, 10, CURRENT);
+{int}A		return lex_units(yytext, 10000000, CURRENT);
+{int}mA		return lex_units(yytext, 10000, CURRENT);
+{int}uA		return lex_units(yytext, 10, CURRENT);
+
+{flt}		return lex_float(yytext);
+
+{str}		return lex_string(yytext);
+
+.		return yytext[0];
+
+%%
+
+#ifndef yywrap
+int yywrap() { return 1; }
+#endif
+
+/*======================================================================
+
+    Stuff to parse basic data types
+
+======================================================================*/
+
+static int lex_number(char *s)
+{
+    yylval.num = strtoul(s, NULL, 0);
+    return NUMBER;
+}
+
+static int lex_float(char *s)
+{
+    yylval.flt = strtod(s, NULL);
+    return FLOAT;
+}
+
+static int lex_units(char *s, int scale, int token)
+{
+    float f;
+    sscanf(s, "%f", &f);
+    yylval.num = scale*f + 0.5;
+    return token;
+}
+
+static int lex_string(char *s)
+{
+    int n = strlen(s);
+    yylval.str = malloc(n-1);
+    strncpy(yylval.str, s+1, n-2);
+    yylval.str[n-2] = '\0';
+    return STRING;
+}
+
+/*======================================================================
+
+    The main parser entry point
+
+======================================================================*/
+
+void parse_cis(FILE *f)
+{
+    current_lineno = 1;
+    yyrestart(f);
+    yyparse();
+}
+
mkcis/mkcis-lexer.lex.c new file +2547 -0

2,547 lines not on this page · raw message

mkcis/mkcis-parser.tab.c new file +2338 -0

225 lines not on this page · raw message

mkcis/mkcis-parser.tab.h new file +127 -0

127 lines not on this page · raw message

mkcis/mkcis-parser.y new file +383 -0

383 lines not on this page · raw message

mkcis/mkcis.c new file +471 -0

471 lines not on this page · raw message

mkcis/mkcis.h new file +49 -0

49 lines not on this page · raw message

The rest of this diff is not shown. View the raw message.

Signature · 1 line
1.7.1

Part of the diff is not shown here. View the raw message.

#3 lore raw

PATCH 3/5 Add files with text descriptions for CIS files

In reply to Dmitry Eremin-Solenikov

Now as we support generation of cis files from .ct, import new .ct from original pcmcia-cs project. They correspond to the binary cis files.

---
 cis/3CCFEM556.ct  |   22 ++++++++++++++++++++++
 cis/3CXEM556.ct   |   22 ++++++++++++++++++++++
 cis/COMpad2.ct    |   20 ++++++++++++++++++++
 cis/COMpad4.ct    |   14 ++++++++++++++
 cis/DP83903.ct    |   24 ++++++++++++++++++++++++
 cis/E-CARD.ct     |    9 +++++++++
 cis/LA-PCM.ct     |   44 ++++++++++++++++++++++++++++++++++++++++++++
 cis/MT5634ZLX.ct  |   18 ++++++++++++++++++
 cis/NE2K.ct       |   10 ++++++++++
 cis/PCMLM28.ct    |   37 +++++++++++++++++++++++++++++++++++++
 cis/PE-200.ct     |   11 +++++++++++
 cis/PE520.ct      |   11 +++++++++++
 cis/RS-COM-2P.ct  |   14 ++++++++++++++
 cis/SW_555_SER.ct |   19 +++++++++++++++++++
 cis/SW_7xx_SER.ct |   21 +++++++++++++++++++++
 cis/SW_8xx_SER.ct |   20 ++++++++++++++++++++
 cis/tamarack.ct   |   17 +++++++++++++++++
 17 files changed, 333 insertions(+), 0 deletions(-)
 create mode 100644 cis/3CCFEM556.ct
 create mode 100644 cis/3CXEM556.ct
 create mode 100644 cis/COMpad2.ct
 create mode 100644 cis/COMpad4.ct
 create mode 100644 cis/DP83903.ct
 create mode 100644 cis/E-CARD.ct
 create mode 100644 cis/LA-PCM.ct
 create mode 100644 cis/MT5634ZLX.ct
 create mode 100644 cis/NE2K.ct
 create mode 100644 cis/PCMLM28.ct
 create mode 100644 cis/PE-200.ct
 create mode 100644 cis/PE520.ct
 create mode 100644 cis/RS-COM-2P.ct
 create mode 100644 cis/SW_555_SER.ct
 create mode 100644 cis/SW_7xx_SER.ct
 create mode 100644 cis/SW_8xx_SER.ct
 create mode 100644 cis/tamarack.ct
cis/3CCFEM556.ct new file +22 -0
new file mode 100644
index 0000000..be627d0
@@ -0,0 +1,22 @@
+#
+# This card is MFC-compliant, but identifies itself as single function
+#
+vers_1 5.0, "3Com", "Megahertz 3CCFEM556", "LAN + 56k Modem"
+manfid 0x0101, 0x0556
+funcid 0
+
+mfc {
+  funcid network_adapter
+  config base 0x1000 mask 0x267 last_index 0x07
+  cftable_entry 0x07
+    Vcc Vnom 5V
+    irq mask 0xffff [level]
+    io  0x0000-0x000f [8bit] [16bit]
+}, {
+  funcid serial_port
+  config base 0x1100 mask 0x277 last_index 0x27
+  cftable_entry 0x27
+    Vcc Vnom 5V
+    irq mask 0xffff [level]
+    io  0x0000-0x0007 [8bit]
+}
cis/3CXEM556.ct new file +22 -0
new file mode 100644
index 0000000..819f08f
@@ -0,0 +1,22 @@
+#
+# This card is MFC-compliant, but identifies itself as single function
+#
+vers_1 5.0, "3Com", "Megahertz 3CXEM556", "LAN + 56k Modem"
+manfid 0x0101, 0x0035
+funcid 0
+
+mfc {
+  funcid network_adapter
+  config base 0x0800 mask 0x63 last_index 0x07
+  cftable_entry 0x07
+    Vcc Vnom 5V
+    irq mask 0xffff [level]
+    io  0x0000-0x000f [8bit] [16bit]
+}, {
+  funcid serial_port
+  config base 0x900 mask 0x63 last_index 0x27
+  cftable_entry 0x27
+    Vcc Vnom 5V
+    irq mask 0xffff [level]
+    io  0x0000-0x0007 [8bit]
+}
cis/COMpad2.ct new file +20 -0
new file mode 100644
index 0000000..bfc2374
@@ -0,0 +1,20 @@
+#
+# Replacement CIS for Advantech COMpad-32/85
+#
+dev_info
+  NULL 0ns, 512b
+vers_1 4.1, "ADVANTECH", "COMpad-32/85", "1.0"
+funcid serial_port [post]
+config base 0x0100 mask 0x0003 last_index 0x05
+cftable_entry 0x01 [default]
+  [mwait]
+  io 0x02e8-0x02ef, 0x03e8-0x03ef [lines=10] [8bit] [range]
+  irq mask 0x9eb8 [level]
+cftable_entry 0x02
+  io 0x0330-0x033f [lines=10] [8bit] [range]
+cftable_entry 0x03
+  io 0x0340-0x034f [lines=10] [8bit] [range]
+cftable_entry 0x04
+  io 0x0350-0x035f [lines=10] [8bit] [range]
+cftable_entry 0x05
+  io 0x0360-0x036f [lines=10] [8bit] [range]
cis/COMpad4.ct new file +14 -0
new file mode 100644
index 0000000..325991c
@@ -0,0 +1,14 @@
+#
+# Replacement CIS for Advantech COMpad-32/85B-4
+#
+dev_info
+  NULL 0ns, 512b
+vers_1 4.1, "ADVANTECH", "COMpad-32/85B-4"
+funcid serial_port [post]
+config base 0x0100 mask 0x0001 last_index 0x02
+cftable_entry 0x01 [default]
+  [mwait]
+  io 0x0240-0x025f [lines=10] [8bit] [range]
+  irq mask 0x9eb8 [level]
+cftable_entry 0x02
+  io 0x0340-0x035f [lines=10] [8bit] [range]
cis/DP83903.ct new file +24 -0
new file mode 100644
index 0000000..ce86f45
@@ -0,0 +1,24 @@
+#
+# This CIS is for cards based on the National Semiconductor
+# DP83903 Multiple Function Interface Chip
+#
+vers_1 4.1, "Multifunction Card", "", "", "NSC MF LAN/Modem"
+manfid 0x0175, 0x0000
+funcid 0
+
+mfc {
+  funcid network_adapter
+  config base 0x1020 mask 0x277 last_index 0x17
+  cftable_entry 0x17
+    Vcc Vnom 5V
+    irq mask 0xffff [level]
+    io  0x0000-0x001f [8bit] [16bit]
+    memory 0x0000-0x3fff @ 0x0000
+}, {
+  funcid serial_port
+  config base 0x1040 mask 0x0277 last_index 0x07
+  cftable_entry 0x07
+    Vcc Vnom 5V
+    irq mask 0xffff [level]
+    io  0x0000-0x0007 [8bit]
+}
cis/E-CARD.ct new file +9 -0
new file mode 100644
index 0000000..fb09b71
@@ -0,0 +1,9 @@
+#
+# Replacement CIS for old, broken Linksys cards
+#
+vers_1 4.1, "LINKSYS", "E-CARD"
+config base 0x0008 mask 0x000b last_index 0x00
+cftable_entry 0x1 [default]
+  Vcc Vnom 5V
+  irq mask 0xffff [level]
+  io 0x0000-0x000f, 0x0010-0x001f [8bit] [16bit]
cis/LA-PCM.ct new file +44 -0

44 lines not on this page · raw message

cis/MT5634ZLX.ct new file +18 -0
new file mode 100644
index 0000000..52249b3
@@ -0,0 +1,18 @@
+#
+# Replacement CIS for Multitech MT5634ZLX modems
+#
+dev_info no_info
+vers_1 4.1, "MultiTech", "PCMCIA 56K DataFax"
+manfid 0x0200, 0x0001
+funcid serial_port
+config base 0xff80 mask 0x0067 last_index 0x27
+cftable_entry 0x0f [default]
+  [rdybsy] [audio] [pwrdown]
+  Vcc Vnom 5V Vpp1 Vnom 5V Vpp2 Vnom 5V
+  io 0x03f8-0x03ff [lines=10] [8bit]
+cftable_entry 0x17
+  io 0x02f8-0x02ff [lines=10] [8bit]
+cftable_entry 0x1f
+  io 0x03e8-0x03ef [lines=10] [8bit]
+cftable_entry 0x27
+  io 0x02e8-0x02ef [lines=10] [8bit]
cis/NE2K.ct new file +10 -0
new file mode 100644
index 0000000..d1d47f3
@@ -0,0 +1,10 @@
+#
+# Replacement CIS for various busted NE2000-compatible cards
+#
+vers_1 4.1, "PCMCIA", "Ethernet"
+funcid network_adapter
+config base 0x03f8 mask 0x03 last_index 0x20
+cftable_entry 0x20 [default]
+  Vcc Vnom 5V
+  irq mask 0xffff [level]
+  io 0x0000-0x001f [8bit] [16bit]
cis/PCMLM28.ct new file +37 -0
new file mode 100644
index 0000000..39c6d16
@@ -0,0 +1,37 @@
+#
+# The on-card CIS says it is MFC-compliant, but it is not
+#
+vers_1 4.1, "LINKSYS", "PCMLM28"
+manfid 0x0143, 0xc0ab
+funcid 0
+config base 0x03f8 mask 0x03 last_index 0x2f
+
+cftable_entry 0x24 [default]
+  Vcc Vnom 5V
+  irq mask 0xffff [level]
+  io 0x0300-0x031f, 0x02f8-0x02ff [8bit] [16bit]
+
+cftable_entry 0x25
+  io 0x0320-0x033f, 0x02f8-0x02ff [8bit] [16bit]
+cftable_entry 0x26
+  io 0x0340-0x035f, 0x02f8-0x02ff [8bit] [16bit]
+cftable_entry 0x27
+  io 0x0360-0x037f, 0x02f8-0x02ff [8bit] [16bit]
+
+cftable_entry 0x28
+  io 0x0300-0x031f, 0x03e8-0x03ef [8bit] [16bit]
+cftable_entry 0x29
+  io 0x0320-0x033f, 0x03e8-0x03ef [8bit] [16bit]
+cftable_entry 0x2a
+  io 0x0340-0x035f, 0x03e8-0x03ef [8bit] [16bit]
+cftable_entry 0x2b
+  io 0x0360-0x037f, 0x03e8-0x03ef [8bit] [16bit]
+
+cftable_entry 0x2c
+  io 0x0300-0x031f, 0x02e8-0x02ef [8bit] [16bit]
+cftable_entry 0x2d
+  io 0x0320-0x033f, 0x02e8-0x02ef [8bit] [16bit]
+cftable_entry 0x2e
+  io 0x0340-0x035f, 0x02e8-0x02ef [8bit] [16bit]
+cftable_entry 0x2f
+  io 0x0360-0x037f, 0x02e8-0x02ef [8bit] [16bit]
cis/PE-200.ct new file +11 -0
new file mode 100644
index 0000000..7db7494
@@ -0,0 +1,11 @@
+#
+# Replacement CIS for PE-200 ethernet card
+#
+vers_1 4.1, "PMX   ", "PE-200", "ETHERNET", "R01"
+funcid network_adapter [post] [rom]
+config base 0x0100 mask 0x0001 last_index 0x01
+cftable_entry 0x1 [default]
+  [mwait]
+  Vcc Vnom 5V
+  irq mask 0xffff [level]
+  io 0x0000-0x000f, 0x0010-0x001f [8bit] [16bit]
cis/PE520.ct new file +11 -0
new file mode 100644
index 0000000..fb411ab
@@ -0,0 +1,11 @@
+#
+# Replacement CIS for LanPro EP-4000A ethernet card
+#
+vers_1 4.1, "KTI", "PE520 PLUS", "PCMCIA Ethernet"
+manfid 0x0161, 0x0010
+funcid network_adapter
+config base 0x0fd0 mask 0x0b last_index 0x01
+cftable_entry 0x01 [default]
+  Vcc Vnom 5V
+  irq mask 0xffff [level]
+  io 0x0000-0x001f [8bit] [16bit]
cis/RS-COM-2P.ct new file +14 -0
new file mode 100644
index 0000000..2e385cb
@@ -0,0 +1,14 @@
+#
+# Replacement CIS for dual-serial-port IO card
+#
+vers_1 4.1, "PCMCIA", "RS-COM 2P"
+funcid serial_port [post]
+config base 0x0100 mask 0x0001 last_index 0x03
+cftable_entry 0x01 [default]
+  [mwait]
+  io 0x03e8-0x03ef, 0x02e8-0x02ef [lines=10] [8bit] [range]
+  irq mask 0x9eb8 [level]
+cftable_entry 0x02
+  io 0x0250-0x0257, 0x0258-0x025f [lines=10] [8bit] [range]
+cftable_entry 0x03
+  io 0x0260-0x0267, 0x0268-0x026f [lines=10] [8bit] [range]
cis/SW_555_SER.ct new file +19 -0
new file mode 100644
index 0000000..7519505
@@ -0,0 +1,19 @@
+dev_info
+  no_info
+attr_dev_info
+  EEPROM 250ns, 512b
+manfid 0x013f, 0x0710
+funcid serial_port
+vers_1 7.0, "Sierra Wireless", "AirCard 555", "A555", "Rev 1"
+config base 0x0700 mask 0x0073 last_index 0x03
+cftable_entry 0x20 [default]
+  io 0x03f8-0x03ff [lines=3] [8bit] [range]
+  irq mask 0x3fbc [level]
+cftable_entry 0x21
+  io 0x02f8-0x02ff [lines=3] [8bit] [range]
+cftable_entry 0x22
+  io 0x03e8-0x03ef [lines=3] [8bit] [range]
+cftable_entry 0x23
+  io 0x02e8-0x02ef [lines=3] [8bit] [range]
+cftable_entry 0x24
+  io 0x0000-0x0007 [lines=3] [8bit]
cis/SW_7xx_SER.ct new file +21 -0
new file mode 100644
index 0000000..2991617
@@ -0,0 +1,21 @@
+dev_info
+  no_info
+attr_dev_info
+  EEPROM 250ns, 512b
+manfid 0x0192, 0x0710
+funcid serial_port
+vers_1 7.0, "Sierra Wireless", "AC710/AC750", "GPRS Network Adapter",
+  "R1"
+config base 0x0700 mask 0x0073 last_index 0x03
+cftable_entry 0x20 [default]
+  Vcc Istatic 45mA Iavg 50mA Ipeak 55mA Idown 20mA
+  io 0x03f8-0x03ff [lines=3] [8bit] [range]
+  irq mask 0x86bc [level]
+cftable_entry 0x21
+  io 0x02f8-0x02ff [lines=3] [8bit] [range]
+cftable_entry 0x22
+  io 0x03e8-0x03ef [lines=3] [8bit] [range]
+cftable_entry 0x23
+  io 0x02e8-0x02ef [lines=3] [8bit] [range]
+cftable_entry 0x24
+  io 0x0000-0x0007 [lines=3] [8bit]
cis/SW_8xx_SER.ct new file +20 -0
new file mode 100644
index 0000000..7dbdd57
@@ -0,0 +1,20 @@
+dev_info
+  no_info
+attr_dev_info
+  EEPROM 250ns, 512b
+manfid 0x0192, 0x0710
+funcid serial_port
+vers_1 7.0, "Sierra Wireless", "AC850", "3G Network Adapter", "R1"
+config base 0x0700 mask 0x0073 last_index 0x03
+cftable_entry 0x20 [default]
+  Vcc Istatic 45mA Iavg 50mA Ipeak 55mA Idown 20mA
+  io 0x48f8-0x48ff [lines=3] [8bit] [range]
+  irq mask 0x86bc [level]
+cftable_entry 0x21
+  io 0x47f8-0x47ff [lines=3] [8bit] [range]
+cftable_entry 0x22
+  io 0x48e8-0x48ef [lines=3] [8bit] [range]
+cftable_entry 0x23
+  io 0x47e8-0x47ef [lines=3] [8bit] [range]
+cftable_entry 0x24
+  io 0x0000-0x0007 [lines=3] [8bit]
cis/tamarack.ct new file +17 -0
new file mode 100644
index 0000000..8802694
@@ -0,0 +1,17 @@
+#
+# Replacement CIS for Surecom, Tamarack NE2000 cards
+#
+dev_info
+  fn_specific 100ns, 512b
+attr_dev_info
+  EEPROM 250ns, 512b
+vers_1 4.1, "TAMARACK", "Ethernet", "A", "004743118001"
+funcid network_adapter
+config base 0x03f8 mask 0x0003 last_index 0x20
+cftable_entry 0x20 [default]
+  [mwait]
+  Vcc Vnom 5V Vmin 4500mV Vmax 5500mV Istatic 100mA
+    Iavg 170mA Ipeak 200mA
+  timing wait 15us
+  io 0x0000-0x000f, 0x0010-0x001f [lines=5] [8bit] [16bit]
+  irq mask 0xffff [level]
Signature · 1 line
1.7.1
#4 lore raw

PATCH 4/5 Add an utility to parse CIS files to readable form

In reply to Dmitry Eremin-Solenikov

Import from pcmcia-cs project a dump_cis utility. It reads machine-readable CIS file and output text representation (which can be processed by mkcis utility).

---
 mkcis/dump_cis.c | 1992 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 1992 insertions(+), 0 deletions(-)
 create mode 100644 mkcis/dump_cis.c
mkcis/dump_cis.c new file +1992 -0
new file mode 100644
index 0000000..4de8641
@@ -0,0 +1,1992 @@
+/***********************************************************************
+ *     PC Card CIS dump utility
+ *
+ *     dump_cis.c from pcmcia-cs
+ *
+ *     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 at http://www.mozilla.org/MPL/
+ *
+ *     Software distributed under the License is distributed on an "AS
+ *     IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
+ *     implied. See the License for the specific language governing
+ *     rights and limitations under the License.
+ *
+ *     The initial developer of the original code is David A. Hinds
+ *     <[email protected]>.  Portions created by David A. Hinds
+ *     are Copyright (C) 1999 David A. Hinds.  All Rights Reserved.
+ *
+ *     Alternatively, the contents of this file may be used under the
+ *     terms of the GNU Public License version 2 (the "GPL"), in which
+ *     case the provisions of the GPL are applicable instead of the
+ *     above.  If you wish to allow the use of your version of this file
+ *     only under the terms of the GPL and not to allow others to use
+ *     your version of this file under the MPL, indicate your decision
+ *     by deleting the provisions above and replace them with the notice
+ *     and 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.
+ ***********************************************************************/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <endian.h>
+
+#ifndef le16toh
+#  include <byteswap.h>
+#  if __BYTE_ORDER == __LITTLE_ENDIAN
+#	define le16toh(x) (x)
+#	define le32toh(x) (x)
+#  else
+#	define le16toh(x) bswap_16(x)
+#	define le32toh(x) bswap_32(x)
+#  endif
+#endif
+
+#include <sys/types.h>
+#include <unistd.h>
+#include <fcntl.h>
+
+#include <cistpl.h>
+
+/* Bits in IRQInfo1 field */
+#define IRQ_MASK				0x0f
+#define IRQ_NMI_ID				0x01
+#define IRQ_IOCK_ID				0x02
+#define IRQ_BERR_ID				0x04
+#define IRQ_VEND_ID				0x08
+#define IRQ_INFO2_VALID				0x10
+#define IRQ_LEVEL_ID				0x20
+#define IRQ_PULSE_ID				0x40
+#define IRQ_SHARE_ID				0x80
+
+typedef struct tuple_parse_t {
+	tuple_t tuple;
+	cisdata_t data[255];
+	cisparse_t parse;
+} tuple_parse_t;
+
+static int get_tuple_buf(int fd, tuple_t * tuple, int first);
+static int parse_tuple(tuple_t * tuple, cisparse_t * parse);
+
+static int verbose;
+static char indent[10] = "  ";
+
+/*====================================================================*/
+
+static void print_tuple(tuple_parse_t * tup)
+{
+	int i;
+	printf("%soffset 0x%2.2x, tuple 0x%2.2x, link 0x%2.2x\n",
+	       indent, tup->tuple.CISOffset, tup->tuple.TupleCode,
+	       tup->tuple.TupleLink);
+	for (i = 0; i < tup->tuple.TupleDataLen; i++) {
+		if ((i % 16) == 0)
+			printf("%s  ", indent);
+		printf("%2.2x ", (u_char) tup->data[i]);
+		if ((i % 16) == 15)
+			putchar('\n');
+	}
+	if ((i % 16) != 0)
+		putchar('\n');
+}
+
+/*====================================================================*/
+
+static void print_funcid(cistpl_funcid_t * fn)
+{
+	printf("%sfuncid ", indent);
+	switch (fn->func) {
+	case CISTPL_FUNCID_MULTI:
+		printf("multi_function");
+		break;
+	case CISTPL_FUNCID_MEMORY:
+		printf("memory_card");
+		break;
+	case CISTPL_FUNCID_SERIAL:
+		printf("serial_port");
+		break;
+	case CISTPL_FUNCID_PARALLEL:
+		printf("parallel_port");
+		break;
+	case CISTPL_FUNCID_FIXED:
+		printf("fixed_disk");
+		break;
+	case CISTPL_FUNCID_VIDEO:
+		printf("video_adapter");
+		break;
+	case CISTPL_FUNCID_NETWORK:
+		printf("network_adapter");
+		break;
+	case CISTPL_FUNCID_AIMS:
+		printf("aims_card");
+		break;
+	case CISTPL_FUNCID_SCSI:
+		printf("scsi_adapter");
+		break;
+	default:
+		printf("unknown");
+		break;
+	}
+	if (fn->sysinit & CISTPL_SYSINIT_POST)
+		printf(" [post]");
+	if (fn->sysinit & CISTPL_SYSINIT_ROM)
+		printf(" [rom]");
+	putchar('\n');
+}
+
+/*====================================================================*/
+
+static void print_size(u_int size)
+{
+	if (size < 1024)
+		printf("%ub", size);
+	else if (size < 1024 * 1024)
+		printf("%ukb", size / 1024);
+	else
+		printf("%umb", size / (1024 * 1024));
+}
+
+static void print_unit(u_int v, char *unit, char tag)
+{
+	int n;
+	for (n = 0; (v % 1000) == 0; n++)
+		v /= 1000;
+	printf("%u", v);
+	if (n < strlen(unit))
+		putchar(unit[n]);
+	putchar(tag);
+}
+
+static void print_time(u_int tm, u_long scale)
+{
+	print_unit(tm * scale, "num", 's');
+}
+
+static void print_volt(u_int vi)
+{
+	print_unit(vi * 10, "um", 'V');
+}
+
+static void print_current(u_int ii)
+{
+	print_unit(ii / 10, "um", 'A');
+}
+
+static void print_speed(u_int b)
+{
+	if (b < 1000)
+		printf("%u bits/sec", b);
+	else if (b < 1000000)
+		printf("%u kb/sec", b / 1000);
+	else
+		printf("%u mb/sec", b / 1000000);
+}
+
+/*====================================================================*/
+
+static const char *dtype[] = {
+	"NULL", "ROM", "OTPROM", "EPROM", "EEPROM", "FLASH", "SRAM",
+	"DRAM", "rsvd", "rsvd", "rsvd", "rsvd", "rsvd", "fn_specific",
+	"extended", "rsvd"
+};
+
+static void print_device(cistpl_device_t * dev)
+{
+	int i;
+	for (i = 0; i < dev->ndev; i++) {
+		printf("%s  %s ", indent, dtype[dev->dev[i].type]);
+		printf("%uns, ", dev->dev[i].speed);
+		print_size(dev->dev[i].size);
+		putchar('\n');
+	}
+	if (dev->ndev == 0)
+		printf("%s  no_info\n", indent);
+}
+
+/*====================================================================*/
+
+static void print_power(char *tag, cistpl_power_t * power)
+{
+	int i, n;
+	for (i = n = 0; i < 8; i++)
+		if (power->present & (1 << i))
+			n++;
+	i = 0;
+	printf("%s  %s", indent, tag);
+	if (power->present & (1 << CISTPL_POWER_VNOM)) {
+		printf(" Vnom ");
+		i++;
+		print_volt(power->param[CISTPL_POWER_VNOM]);
+	}
+	if (power->present & (1 << CISTPL_POWER_VMIN)) {
+		printf(" Vmin ");
+		i++;
+		print_volt(power->param[CISTPL_POWER_VMIN]);
+	}
+	if (power->present & (1 << CISTPL_POWER_VMAX)) {
+		printf(" Vmax ");
+		i++;
+		print_volt(power->param[CISTPL_POWER_VMAX]);
+	}
+	if (power->present & (1 << CISTPL_POWER_ISTATIC)) {
+		printf(" Istatic ");
+		i++;
+		print_current(power->param[CISTPL_POWER_ISTATIC]);
+	}
+	if (power->present & (1 << CISTPL_POWER_IAVG)) {
+		if (++i == 5)
+			printf("\n%s   ", indent);
+		printf(" Iavg ");
+		print_current(power->param[CISTPL_POWER_IAVG]);
+	}
+	if (power->present & (1 << CISTPL_POWER_IPEAK)) {
+		if (++i == 5)
+			printf("\n%s ", indent);
+		printf(" Ipeak ");
+		print_current(power->param[CISTPL_POWER_IPEAK]);
+	}
+	if (power->present & (1 << CISTPL_POWER_IDOWN)) {
+		if (++i == 5)
+			printf("\n%s ", indent);
+		printf(" Idown ");
+		print_current(power->param[CISTPL_POWER_IDOWN]);
+	}
+	if (power->flags & CISTPL_POWER_HIGHZ_OK) {
+		if (++i == 5)
+			printf("\n%s ", indent);
+		printf(" [highz OK]");
+	}
+	if (power->flags & CISTPL_POWER_HIGHZ_REQ) {
+		printf(" [highz]");
+	}
+	putchar('\n');
+}
+
+/*====================================================================*/
+
+static void print_cftable_entry(cistpl_cftable_entry_t * entry)
+{
+	int i;
+
+	printf("%scftable_entry 0x%2.2x%s\n", indent, entry->index,
+	       (entry->flags & CISTPL_CFTABLE_DEFAULT) ? " [default]" : "");
+
+	if (entry->flags & ~CISTPL_CFTABLE_DEFAULT) {
+		printf("%s ", indent);
+		if (entry->flags & CISTPL_CFTABLE_BVDS)
+			printf(" [bvd]");
+		if (entry->flags & CISTPL_CFTABLE_WP)
+			printf(" [wp]");
+		if (entry->flags & CISTPL_CFTABLE_RDYBSY)
+			printf(" [rdybsy]");
+		if (entry->flags & CISTPL_CFTABLE_MWAIT)
+			printf(" [mwait]");
+		if (entry->flags & CISTPL_CFTABLE_AUDIO)
+			printf(" [audio]");
+		if (entry->flags & CISTPL_CFTABLE_READONLY)
+			printf(" [readonly]");
+		if (entry->flags & CISTPL_CFTABLE_PWRDOWN)
+			printf(" [pwrdown]");
+		putchar('\n');
+	}
+
+	if (entry->vcc.present)
+		print_power("Vcc", &entry->vcc);
+	if (entry->vpp1.present)
+		print_power("Vpp1", &entry->vpp1);
+	if (entry->vpp2.present)
+		print_power("Vpp2", &entry->vpp2);
+
+	if ((entry->timing.wait != 0) || (entry->timing.ready != 0) ||
+	    (entry->timing.reserved != 0)) {
+		printf("%s  timing", indent);
+		if (entry->timing.wait != 0) {
+			printf(" wait ");
+			print_time(entry->timing.wait, entry->timing.waitscale);
+		}
+		if (entry->timing.ready != 0) {
+			printf(" ready ");
+			print_time(entry->timing.ready, entry->timing.rdyscale);
+		}
+		if (entry->timing.reserved != 0) {
+			printf(" reserved ");
+			print_time(entry->timing.reserved,
+				   entry->timing.rsvscale);
+		}
+		putchar('\n');
+	}
+
+	if (entry->io.nwin) {
+		cistpl_io_t *io = &entry->io;
+		printf("%s  io", indent);
+		for (i = 0; i < io->nwin; i++) {
+			if (i)
+				putchar(',');
+			printf(" 0x%4.4x-0x%4.4x", io->win[i].base,
+			       io->win[i].base + io->win[i].len - 1);
+		}
+		printf(" [lines=%d]", io->flags & CISTPL_IO_LINES_MASK);
+		if (io->flags & CISTPL_IO_8BIT)
+			printf(" [8bit]");
+		if (io->flags & CISTPL_IO_16BIT)
+			printf(" [16bit]");
+		if (io->flags & CISTPL_IO_RANGE)
+			printf(" [range]");
+		putchar('\n');
+	}
+
+	if (entry->irq.IRQInfo1) {
+		printf("%s  irq ", indent);
+		if (entry->irq.IRQInfo1 & IRQ_INFO2_VALID)
+			printf("mask 0x%04x", entry->irq.IRQInfo2);
+		else
+			printf("%u", entry->irq.IRQInfo1 & IRQ_MASK);
+		if (entry->irq.IRQInfo1 & IRQ_LEVEL_ID)
+			printf(" [level]");
+		if (entry->irq.IRQInfo1 & IRQ_PULSE_ID)
+			printf(" [pulse]");
+		if (entry->irq.IRQInfo1 & IRQ_SHARE_ID)
+			printf(" [shared]");
+		putchar('\n');
+	}
+
+	if (entry->mem.nwin) {
+		cistpl_mem_t *mem = &entry->mem;
+		printf("%s  memory", indent);
+		for (i = 0; i < mem->nwin; i++) {
+			if (i)
+				putchar(',');
+			printf(" 0x%4.4x-0x%4.4x @ 0x%4.4x",
+			       mem->win[i].card_addr,
+			       mem->win[i].card_addr + mem->win[i].len - 1,
+			       mem->win[i].host_addr);
+		}
+		putchar('\n');
+	}
+
+	if (verbose && entry->subtuples)
+		printf("%s  %d bytes in subtuples\n", indent, entry->subtuples);
+
+}
+
+/*====================================================================*/
+
+static void print_cftable_entry_cb(cistpl_cftable_entry_cb_t * entry)
+{
+	int i;
+
+	printf("%scftable_entry_cb 0x%2.2x%s\n", indent, entry->index,
+	       (entry->flags & CISTPL_CFTABLE_DEFAULT) ? " [default]" : "");
+
+	if (entry->flags & ~CISTPL_CFTABLE_DEFAULT) {
+		printf("%s ", indent);
+		if (entry->flags & CISTPL_CFTABLE_MASTER)
+			printf(" [master]");
+		if (entry->flags & CISTPL_CFTABLE_INVALIDATE)
+			printf(" [invalidate]");
+		if (entry->flags & CISTPL_CFTABLE_VGA_PALETTE)
+			printf(" [vga palette]");
+		if (entry->flags & CISTPL_CFTABLE_PARITY)
+			printf(" [parity]");
+		if (entry->flags & CISTPL_CFTABLE_WAIT)
+			printf(" [wait]");
+		if (entry->flags & CISTPL_CFTABLE_SERR)
+			printf(" [serr]");
+		if (entry->flags & CISTPL_CFTABLE_FAST_BACK)
+			printf(" [fast back]");
+		if (entry->flags & CISTPL_CFTABLE_BINARY_AUDIO)
+			printf(" [binary audio]");
+		if (entry->flags & CISTPL_CFTABLE_PWM_AUDIO)
+			printf(" [pwm audio]");
+		putchar('\n');
+	}
+
+	if (entry->vcc.present)
+		print_power("Vcc", &entry->vcc);
+	if (entry->vpp1.present)
+		print_power("Vpp1", &entry->vpp1);
+	if (entry->vpp2.present)
+		print_power("Vpp2", &entry->vpp2);
+
+	if (entry->io) {
+		printf("%s  io_base", indent);
+		for (i = 0; i < 8; i++)
+			if (entry->io & (1 << i))
+				printf(" %d", i);
+		putchar('\n');
+	}
+
+	if (entry->irq.IRQInfo1) {
+		printf("%s  irq ", indent);
+		if (entry->irq.IRQInfo1 & IRQ_INFO2_VALID)
+			printf("mask 0x%4.4x", entry->irq.IRQInfo2);
+		else
+			printf("%u", entry->irq.IRQInfo1 & IRQ_MASK);
+		if (entry->irq.IRQInfo1 & IRQ_LEVEL_ID)
+			printf(" [level]");
+		if (entry->irq.IRQInfo1 & IRQ_PULSE_ID)
+			printf(" [pulse]");
+		if (entry->irq.IRQInfo1 & IRQ_SHARE_ID)
+			printf(" [shared]");
+		putchar('\n');
+	}
+
+	if (entry->mem) {
+		printf("%s  mem_base", indent);
+		for (i = 0; i < 8; i++)
+			if (entry->mem & (1 << i))
+				printf(" %d", i);
+		putchar('\n');
+	}
+
+	if (verbose && entry->subtuples)
+		printf("%s  %d bytes in subtuples\n", indent, entry->subtuples);
+
+}
+
+/*====================================================================*/
+
+static void print_jedec(cistpl_jedec_t * j)
+{
+	int i;
+	for (i = 0; i < j->nid; i++) {
+		if (i != 0)
+			putchar(',');
+		printf(" 0x%02x 0x%02x", j->id[i].mfr, j->id[i].info);
+	}
+	putchar('\n');
+}
+
+/*====================================================================*/
+
+static void print_device_geo(cistpl_device_geo_t * geo)
+{
+	int i;
+	for (i = 0; i < geo->ngeo; i++) {
+		printf("%s  width %d erase 0x%x read 0x%x write 0x%x "
+		       "partition 0x%x interleave 0x%x\n", indent,
+		       geo->geo[i].buswidth, geo->geo[i].erase_block,
+		       geo->geo[i].read_block, geo->geo[i].write_block,
+		       geo->geo[i].partition, geo->geo[i].interleave);
+	}
+}
+
+/*====================================================================*/
+
+static void print_org(cistpl_org_t * org)
+{
+	printf("%sdata_org ", indent);
+	switch (org->data_org) {
+	case CISTPL_ORG_FS:
+		printf("[filesystem]");
+		break;
+	case CISTPL_ORG_APPSPEC:
+		printf("[app_specific]");
+		break;
+	case CISTPL_ORG_XIP:
+		printf("[code]");
+		break;
+	default:
+		if (org->data_org < 0x80)
+			printf("[reserved]");
+		else
+			printf("[vendor_specific]");
+	}
+	printf(", \"%s\"\n", org->desc);
+}
+
+/*====================================================================*/
+
+static char *data_mod[] = {
+	"Bell103", "V.21", "V.23", "V.22", "Bell212A", "V.22bis",
+	"V.26", "V.26bis", "V.27bis", "V.29", "V.32", "V.32bis",
+	"V.34", "rfu", "rfu", "rfu"
+};
+
+static char *fax_mod[] = {
+	"V.21-C2", "V.27ter", "V.29", "V.17", "V.33", "rfu", "rfu", "rfu"
+};
+
+static char *fax_features[] = {
+	"T.3", "T.4", "T.6", "error", "voice", "poll", "file", "passwd"
+};
+
+static char *cmd_protocol[] = {
+	"AT1", "AT2", "AT3", "MNP_AT", "V.25bis", "V.25A", "DMCL"
+};
+
+static char *uart[] = {
+	"8250", "16450", "16550", "8251", "8530", "85230"
+};
+static char *parity[] = { "space", "mark", "odd", "even" };
+static char *stop[] = { "1", "1.5", "2" };
+
+static char *flow[] = {
+	"XON/XOFF xmit", "XON/XOFF rcv", "hw xmit", "hw rcv", "transparent"
+};
+
+static void print_serial(cistpl_funce_t * funce)
+{
+	cistpl_serial_t *s;
+	cistpl_data_serv_t *ds;
+	cistpl_fax_serv_t *fs;
+	cistpl_modem_cap_t *cp;
+	int i, j;
+
+	switch (funce->type & 0x0f) {
+	case CISTPL_FUNCE_SERIAL_IF:
+	case CISTPL_FUNCE_SERIAL_IF_DATA:
+	case CISTPL_FUNCE_SERIAL_IF_FAX:
+	case CISTPL_FUNCE_SERIAL_IF_VOICE:
+		s = (cistpl_serial_t *) (funce->data);
+		printf("%sserial_interface", indent);
+		if ((funce->type & 0x0f) == CISTPL_FUNCE_SERIAL_IF_DATA)
+			printf("_data");
+		else if ((funce->type & 0x0f) == CISTPL_FUNCE_SERIAL_IF_FAX)
+			printf("_fax");
+		else if ((funce->type & 0x0f) == CISTPL_FUNCE_SERIAL_IF_VOICE)
+			printf("_voice");
+		printf("\n%s  uart %s", indent,
+		       (s->uart_type < 6) ? uart[s->uart_type] : "reserved");
+		if (s->uart_cap_0) {
+			printf(" [");
+			for (i = 0; i < 4; i++)
+				if (s->uart_cap_0 & (1 << i))
+					printf("%s%s", parity[i],
+					       (s->uart_cap_0 >=
+						(2 << i)) ? "/" : "]");
+		}
+		if (s->uart_cap_1) {
+			int m = s->uart_cap_1 & 0x0f;
+			int n = s->uart_cap_1 >> 4;
+			printf(" [");
+			for (i = 0; i < 4; i++)
+				if (m & (1 << i))
+					printf("%d%s", i + 5,
+					       (m >= (2 << i)) ? "/" : "");
+			printf("] [");
+			for (i = 0; i < 3; i++)
+				if (n & (1 << i))
+					printf("%s%s", stop[i],
+					       (n >= (2 << i)) ? "/" : "]");
+		}
+		printf("\n");
+		break;
+	case CISTPL_FUNCE_SERIAL_CAP:
+	case CISTPL_FUNCE_SERIAL_CAP_DATA:
+	case CISTPL_FUNCE_SERIAL_CAP_FAX:
+	case CISTPL_FUNCE_SERIAL_CAP_VOICE:
+		cp = (cistpl_modem_cap_t *) (funce->data);
+		printf("%sserial_modem_cap", indent);
+		if ((funce->type & 0x0f) == CISTPL_FUNCE_SERIAL_CAP_DATA)
+			printf("_data");
+		else if ((funce->type & 0x0f) == CISTPL_FUNCE_SERIAL_CAP_FAX)
+			printf("_fax");
+		else if ((funce->type & 0x0f) == CISTPL_FUNCE_SERIAL_CAP_VOICE)
+			printf("_voice");
+		if (cp->flow) {
+			printf("\n%s  flow", indent);
+			for (i = 0; i < 5; i++)
+				if (cp->flow & (1 << i))
+					printf(" [%s]", flow[i]);
+		}
+		printf("\n%s  cmd_buf %d rcv_buf %d xmit_buf %d\n",
+		       indent, 4 * (cp->cmd_buf + 1),
+		       cp->rcv_buf_0 + (cp->rcv_buf_1 << 8) +
+		       (cp->rcv_buf_2 << 16),
+		       cp->xmit_buf_0 + (cp->xmit_buf_1 << 8) +
+		       (cp->xmit_buf_2 << 16));
+		break;
+	case CISTPL_FUNCE_SERIAL_SERV_DATA:
+		ds = (cistpl_data_serv_t *) (funce->data);
+		printf("%sserial_data_services\n", indent);
+		printf("%s  data_rate %d\n", indent,
+		       75 * ((ds->max_data_0 << 8) + ds->max_data_1));
+		printf("%s  modulation", indent);
+		for (i = j = 0; i < 16; i++)
+			if (((ds->modulation_1 << 8) +
+			     ds->modulation_0) & (1 << i)) {
+				if (++j % 6 == 0)
+					printf("\n%s   ", indent);
+				printf(" [%s]", data_mod[i]);
+			}
+		printf("\n");
+		if (ds->error_control) {
+			printf("%s  error_control", indent);
+			if (ds->error_control & CISTPL_SERIAL_ERR_MNP2_4)
+				printf(" [MNP2-4]");
+			if (ds->error_control & CISTPL_SERIAL_ERR_V42_LAPM)
+				printf(" [V.42/LAPM]");
+			printf("\n");
+		}
+		if (ds->compression) {
+			printf("%s  compression", indent);
+			if (ds->compression & CISTPL_SERIAL_CMPR_V42BIS)
+				printf(" [V.42bis]");
+			if (ds->compression & CISTPL_SERIAL_CMPR_MNP5)
+				printf(" [MNP5]");
+			printf("\n");
+		}
+		if (ds->cmd_protocol) {
+			printf("%s  cmd_protocol", indent);
+			for (i = 0; i < 7; i++)
+				if (ds->cmd_protocol & (1 << i))
+					printf(" [%s]", cmd_protocol[i]);
+			printf("\n");
+		}
+		break;
+
+	case CISTPL_FUNCE_SERIAL_SERV_FAX:
+		fs = (cistpl_fax_serv_t *) (funce->data);
+		printf("%sserial_fax_services [class=%d]\n",
+		       indent, funce->type >> 4);
+		printf("%s  data_rate %d\n", indent,
+		       75 * ((fs->max_data_0 << 8) + fs->max_data_1));
+		printf("%s  modulation", indent);
+		for (i = 0; i < 8; i++)
+			if (fs->modulation & (1 << i))
+				printf(" [%s]", fax_mod[i]);
+		printf("\n");
+		if (fs->features_0) {
+			printf("%s  features", indent);
+			for (i = 0; i < 8; i++)
+				if (fs->features_0 & (1 << i))
+					printf(" [%s]", fax_features[i]);
+			printf("\n");
+		}
+		break;
+	}
+}
+
+/*====================================================================*/
+
+static void print_fixed(cistpl_funce_t * funce)
+{
+	cistpl_ide_interface_t *i;
+	cistpl_ide_feature_t *f;
+
+	switch (funce->type) {
+	case CISTPL_FUNCE_IDE_IFACE:
+		i = (cistpl_ide_interface_t *) (funce->data);
+		printf("%sdisk_interface ", indent);
+		if (i->interface == CISTPL_IDE_INTERFACE)
+			printf("[ide]\n");
+		else
+			printf("[undefined]\n");
+		break;
+	case CISTPL_FUNCE_IDE_MASTER:
+	case CISTPL_FUNCE_IDE_SLAVE:
+		f = (cistpl_ide_feature_t *) (funce->data);
+		printf("%sdisk_features", indent);
+		if (f->feature1 & CISTPL_IDE_SILICON)
+			printf(" [silicon]");
+		else
+			printf(" [rotating]");
+		if (f->feature1 & CISTPL_IDE_UNIQUE)
+			printf(" [unique]");
+		if (f->feature1 & CISTPL_IDE_DUAL)
+			printf(" [dual]");
+		else
+			printf(" [single]");
+		if (f->feature1 && f->feature2)
+			printf("\n%s ", indent);
+		if (f->feature2 & CISTPL_IDE_HAS_SLEEP)
+			printf(" [sleep]");
+		if (f->feature2 & CISTPL_IDE_HAS_STANDBY)
+			printf(" [standby]");
+		if (f->feature2 & CISTPL_IDE_HAS_IDLE)
+			printf(" [idle]");
+		if (f->feature2 & CISTPL_IDE_LOW_POWER)
+			printf(" [low power]");
+		if (f->feature2 & CISTPL_IDE_REG_INHIBIT)
+			printf(" [reg inhibit]");
+		if (f->feature2 & CISTPL_IDE_HAS_INDEX)
+			printf(" [index]");
+		if (f->feature2 & CISTPL_IDE_IOIS16)
+			printf(" [iois16]");
+		putchar('\n');
+		break;
+	}
+}
+
+/*====================================================================*/
+
+static const char *tech[] = {
+	"undefined", "ARCnet", "ethernet", "token_ring", "localtalk",
+	"FDDI/CDDI", "ATM", "wireless"
+};
+
+static const char *media[] = {
+	"undefined", "unshielded_twisted_pair", "shielded_twisted_pair",
+	"thin_coax", "thick_coax", "fiber", "900_MHz", "2.4_GHz",
+	"5.4_GHz", "diffuse_infrared", "point_to_point_infrared"
+};
+
+static void print_network(cistpl_funce_t * funce)
+{
+	cistpl_lan_tech_t *t;
+	cistpl_lan_speed_t *s;
+	cistpl_lan_media_t *m;
+	cistpl_lan_node_id_t *n;
+	cistpl_lan_connector_t *c;
+	int i;
+
+	switch (funce->type) {
+	case CISTPL_FUNCE_LAN_TECH:
+		t = (cistpl_lan_tech_t *) (funce->data);
+		printf("%slan_technology %s\n", indent, tech[t->tech]);
+		break;
+	case CISTPL_FUNCE_LAN_SPEED:
+		s = (cistpl_lan_speed_t *) (funce->data);
+		printf("%slan_speed ", indent);
+		print_speed(s->speed);
+		putchar('\n');
+		break;
+	case CISTPL_FUNCE_LAN_MEDIA:
+		m = (cistpl_lan_media_t *) (funce->data);
+		printf("%slan_media %s\n", indent, media[m->media]);
+		break;
+	case CISTPL_FUNCE_LAN_NODE_ID:
+		n = (cistpl_lan_node_id_t *) (funce->data);
+		printf("%slan_node_id", indent);
+		for (i = 0; i < n->nb; i++)
+			printf(" %02x", n->id[i]);
+		putchar('\n');
+		break;
+	case CISTPL_FUNCE_LAN_CONNECTOR:
+		c = (cistpl_lan_connector_t *) (funce->data);
+		printf("%slan_connector ", indent);
+		if (c->code == 0)
+			printf("Open connector standard\n");
+		else
+			printf("Closed connector standard\n");
+		break;
+	}
+}
+
+/*====================================================================*/
+
+static void print_vers_1(cistpl_vers_1_t * v1)
+{
+	int i, n;
+	char s[32];
+	sprintf(s, "%svers_1 %d.%d", indent, v1->major, v1->minor);
+	printf("%s", s);
+	n = strlen(s);
+	for (i = 0; i < v1->ns; i++) {
+		if (n + strlen(v1->str + v1->ofs[i]) + 4 > 72) {
+			n = strlen(indent) + 2;
+			printf(",\n%s  ", indent);
+		} else {
+			printf(", ");
+			n += 2;
+		}
+		printf("\"%s\"", v1->str + v1->ofs[i]);
+		n += strlen(v1->str + v1->ofs[i]) + 2;
+	}
+	putchar('\n');
+}
+
+/*====================================================================*/
+
+static void print_vers_2(cistpl_vers_2_t * v2)
+{
+	printf("%sversion 0x%2.2x, compliance 0x%2.2x, dindex 0x%4.4x\n",
+	       indent, v2->vers, v2->comply, v2->dindex);
+	printf("%s  vspec8 0x%2.2x, vspec9 0x%2.2x, nhdr %d\n",
+	       indent, v2->vspec8, v2->vspec9, v2->nhdr);
+	printf("%s  vendor \"%s\"\n", indent, v2->str + v2->vendor);
+	printf("%s  info \"%s\"\n", indent, v2->str + v2->info);
+}
+
+/*====================================================================*/
+
+#ifdef CISTPL_FORMAT_DISK
+static void print_format(cistpl_format_t * fmt)
+{
+	if (fmt->type == CISTPL_FORMAT_DISK)
+		printf("%s  [disk]", indent);
+	else if (fmt->type == CISTPL_FORMAT_MEM)
+		printf("%s  [memory]", indent);
+	else
+		printf("%s  [type 0x%02x]\n", indent, fmt->type);
+	if (fmt->edc == CISTPL_EDC_NONE)
+		printf(" [no edc]");
+	else if (fmt->edc == CISTPL_EDC_CKSUM)
+		printf(" [cksum]");
+	else if (fmt->edc == CISTPL_EDC_CRC)
+		printf(" [crc]");
+	else if (fmt->edc == CISTPL_EDC_PCC)
+		printf(" [pcc]");
+	else
+		printf(" [edc 0x%02x]", fmt->edc);
+	printf(" offset 0x%04x length ", fmt->offset);
+	print_size(fmt->length);
+	putchar('\n');
+}
+#endif
+
+/*====================================================================*/
+
+static void print_config(int code, cistpl_config_t * cfg)
+{
+	printf("%sconfig%s base 0x%4.4x", indent,
+	       (code == CISTPL_CONFIG_CB) ? "_cb" : "", cfg->base);
+	if (code == CISTPL_CONFIG)
+		printf(" mask 0x%4.4x", cfg->rmask[0]);
+	printf(" last_index 0x%2.2x\n", cfg->last_idx);
+	if (verbose && cfg->subtuples)
+		printf("%s  %d bytes in subtuples\n", indent, cfg->subtuples);
+}
+
+/*====================================================================*/
+
+static int nfn = 0, cur = 0;
+
+static void print_parse(tuple_parse_t * tup)
+{
+	static int func = 0;
+	int i;
+
+	switch (tup->tuple.TupleCode) {
+	case CISTPL_DEVICE:
+	case CISTPL_DEVICE_A:
+		if (tup->tuple.TupleCode == CISTPL_DEVICE)
+			printf("%sdev_info\n", indent);
+		else
+			printf("%sattr_dev_info\n", indent);
+		print_device(&tup->parse.device);
+		break;
+	case CISTPL_CHECKSUM:
+		printf("%schecksum 0x%04x-0x%04x = 0x%02x\n",
+		       indent, tup->parse.checksum.addr,
+		       tup->parse.checksum.addr + tup->parse.checksum.len - 1,
+		       tup->parse.checksum.sum);
+		break;
+	case CISTPL_LONGLINK_A:
+		if (verbose)
+			printf("%slong_link_attr 0x%04x\n", indent,
+			       tup->parse.longlink.addr);
+		break;
+	case CISTPL_LONGLINK_C:
+		if (verbose)
+			printf("%slong_link 0x%04x\n", indent,
+			       tup->parse.longlink.addr);
+		break;
+	case CISTPL_LONGLINK_MFC:
+		if (verbose) {
+			printf("%smfc_long_link\n", indent);
+			for (i = 0; i < tup->parse.longlink_mfc.nfn; i++)
+				printf("%s function %d: %s 0x%04x\n", indent, i,
+				       tup->parse.longlink_mfc.fn[i].space ?
+				       "common" : "attr",
+				       tup->parse.longlink_mfc.fn[i].addr);
+		}
+
+		printf("%smfc {\n", indent);
+		nfn = tup->parse.longlink_mfc.nfn;
+		cur = 0;
+		strcat(indent, "  ");
+		while (cur < nfn) {
+			tuple_parse_t tuple_parse = *tup;
+			tuple_parse.tuple.CISOffset =
+			    tup->parse.longlink_mfc.fn[cur].addr;
+			tuple_parse.tuple.TupleLink = 0;
+
+			while (1) {
+				if (get_tuple_buf(-1, &tuple_parse.tuple, 0))
+					break;
+				if (verbose)
+					print_tuple(&tuple_parse);
+				if (parse_tuple
+				    (&tuple_parse.tuple,
+				     &tuple_parse.parse) == 0)
+					print_parse(&tuple_parse);
+				else
+					printf("%sparse error\n", indent);
+				if (verbose)
+					putchar('\n');
+				if (tuple_parse.tuple.TupleCode == CISTPL_END)
+					break;
+			}
+		}
+		break;
+	case CISTPL_NO_LINK:
+		if (verbose)
+			printf("%sno_long_link\n", indent);
+		break;
+#ifdef CISTPL_INDIRECT
+	case CISTPL_INDIRECT:
+		if (verbose)
+			printf("%sindirect_access\n", indent);
+		break;
+#endif
+	case CISTPL_LINKTARGET:
+		if (verbose)
+			printf("%slink_target\n", indent);
+
+		if (cur++)
+			printf("%s}, {\n", indent + 2);
+		break;
+	case CISTPL_VERS_1:
+		print_vers_1(&tup->parse.version_1);
+		break;
+	case CISTPL_ALTSTR:
+		break;
+	case CISTPL_JEDEC_A:
+	case CISTPL_JEDEC_C:
+		if (tup->tuple.TupleCode == CISTPL_JEDEC_C)
+			printf("%scommon_jedec", indent);
+		else
+			printf("%sattr_jedec", indent);
+		print_jedec(&tup->parse.jedec);
+		break;
+	case CISTPL_DEVICE_GEO:
+	case CISTPL_DEVICE_GEO_A:
+		if (tup->tuple.TupleCode == CISTPL_DEVICE_GEO)
+			printf("%scommon_geometry\n", indent);
+		else
+			printf("%sattr_geometry\n", indent);
+		print_device_geo(&tup->parse.device_geo);
+		break;
+	case CISTPL_MANFID:
+		printf("%smanfid 0x%4.4x, 0x%4.4x\n", indent,
+		       tup->parse.manfid.manf, tup->parse.manfid.card);
+		break;
+	case CISTPL_FUNCID:
+		print_funcid(&tup->parse.funcid);
+		func = tup->parse.funcid.func;
+		break;
+	case CISTPL_FUNCE:
+		switch (func) {
+		case CISTPL_FUNCID_SERIAL:
+			print_serial(&tup->parse.funce);
+			break;
+		case CISTPL_FUNCID_FIXED:
+			print_fixed(&tup->parse.funce);
+			break;
+		case CISTPL_FUNCID_NETWORK:
+			print_network(&tup->parse.funce);
+			break;
+		}
+		break;
+	case CISTPL_BAR:
+		printf("%sBAR %d size ", indent,
+		       tup->parse.bar.attr & CISTPL_BAR_SPACE);
+		print_size(tup->parse.bar.size);
+		if (tup->parse.bar.attr & CISTPL_BAR_SPACE_IO)
+			printf(" [io]");
+		else
+			printf(" [mem]");
+		if (tup->parse.bar.attr & CISTPL_BAR_PREFETCH)
+			printf(" [prefetch]");
+		if (tup->parse.bar.attr & CISTPL_BAR_CACHEABLE)
+			printf(" [cacheable]");
+		if (tup->parse.bar.attr & CISTPL_BAR_1MEG_MAP)
+			printf(" [<1mb]");
+		putchar('\n');
+		break;
+	case CISTPL_CONFIG:
+	case CISTPL_CONFIG_CB:
+		print_config(tup->tuple.TupleCode, &tup->parse.config);
+		break;
+	case CISTPL_CFTABLE_ENTRY:
+		print_cftable_entry(&tup->parse.cftable_entry);
+		break;
+	case CISTPL_CFTABLE_ENTRY_CB:
+		print_cftable_entry_cb(&tup->parse.cftable_entry_cb);
+		break;
+	case CISTPL_VERS_2:
+		print_vers_2(&tup->parse.vers_2);
+		break;
+	case CISTPL_ORG:
+		print_org(&tup->parse.org);
+		break;
+#ifdef CISTPL_FORMAT_DISK
+	case CISTPL_FORMAT:
+	case CISTPL_FORMAT_A:
+		if (tup->tuple.TupleCode == CISTPL_FORMAT)
+			printf("%scommon_format\n", indent);
+		else
+			printf("%sattr_format\n", indent);
+		print_format(&tup->parse.format);
+#endif
+	}
+}
+
+/*====================================================================*/
+
+static int get_tuple_buf(int fd, tuple_t * tuple, int first)
+{
+	u_int ofs;
+	static int nb = 0;
+	static u_char buf[1024];
+
+	if (first) {
+		nb = read(fd, buf, sizeof(buf));
+		tuple->TupleLink = tuple->CISOffset = 0;
+	}
+	ofs = tuple->CISOffset + tuple->TupleLink;
+	if (ofs >= nb)
+		return -1;
+	tuple->TupleCode = buf[ofs++];
+	tuple->TupleDataLen = tuple->TupleLink = buf[ofs++];
+	tuple->CISOffset = ofs;
+	memcpy(tuple->TupleData, buf + ofs, tuple->TupleLink);
+	return 0;
+}
+
+/*======================================================================
+
+	Parsing routines for individual tuples
+
+======================================================================*/
+
+static const u_char mantissa[] = {
+	10, 12, 13, 15, 20, 25, 30, 35,
+	40, 45, 50, 55, 60, 70, 80, 90
+};
+
+static const u_int exponent[] = {
+	1, 10, 100, 1000, 10000, 100000, 1000000, 10000000
+};
+
+/* Convert an extended speed byte to a time in nanoseconds */
+#define SPEED_CVT(v) \
+	(mantissa[(((v)>>3)&15)-1] * exponent[(v)&7] / 10)
+/* Convert a power byte to a current in 0.1 microamps */
+#define POWER_CVT(v) \
+	(mantissa[((v)>>3)&15] * exponent[(v)&7] / 10)
+#define POWER_SCALE(v)				(exponent[(v)&7])
+
+static int parse_device(tuple_t * tuple, cistpl_device_t * device)
+{
+	int i;
+	u_char scale;
+	u_char *p, *q;
+
+	p = (u_char *) tuple->TupleData;
+	q = p + tuple->TupleDataLen;
+
+	device->ndev = 0;
+	for (i = 0; i < CISTPL_MAX_DEVICES; i++) {
+
+		if (*p == 0xff)
+			break;
+		device->dev[i].type = (*p >> 4);
+		device->dev[i].wp = (*p & 0x08) ? 1 : 0;
+		switch (*p & 0x07) {
+		case 0:
+			device->dev[i].speed = 0;
+			break;
+		case 1:
+			device->dev[i].speed = 250;
+			break;
+		case 2:
+			device->dev[i].speed = 200;
+			break;
+		case 3:
+			device->dev[i].speed = 150;
+			break;
+		case 4:
+			device->dev[i].speed = 100;
+			break;
+		case 7:
+			if (++p == q)
+				return -1;
+			if (p == q)
+				return -1;
+			device->dev[i].speed = SPEED_CVT(*p);
+			while (*p & 0x80)
+				if (++p == q)
+					return -1;
+			break;
+		default:
+			return -1;
+		}
+
+		if (++p == q)
+			return -1;
+		if (*p == 0xff)
+			break;
+		scale = *p & 7;
+		if (scale == 7)
+			return -1;
+		device->dev[i].size = ((*p >> 3) + 1) * (512 << (scale * 2));
+		device->ndev++;
+		if (++p == q)
+			break;
+	}
+
+	return 0;
+}
+
+/*====================================================================*/
+
+static int parse_checksum(tuple_t * tuple, cistpl_checksum_t * csum)
+{
+	u_char *p;
+	if (tuple->TupleDataLen < 5)
+		return -1;
+	p = (u_char *) tuple->TupleData;
+	csum->addr = tuple->CISOffset + (short)le16toh(*(u_short *) p) - 2;
+	csum->len = le16toh(*(u_short *) (p + 2));
+	csum->sum = *(p + 4);
+	return 0;
+}
+
+/*====================================================================*/
+
+static int parse_longlink(tuple_t * tuple, cistpl_longlink_t * link)
+{
+	if (tuple->TupleDataLen < 4)
+		return -1;
+	link->addr = le32toh(*(u_int *) tuple->TupleData);
+	return 0;
+}
+
+/*====================================================================*/
+
+static int parse_longlink_mfc(tuple_t * tuple, cistpl_longlink_mfc_t * link)
+{
+	u_char *p;
+	int i;
+
+	p = (u_char *) tuple->TupleData;
+
+	link->nfn = *p;
+	p++;
+	if (tuple->TupleDataLen <= link->nfn * 5)
+		return -1;
+	for (i = 0; i < link->nfn; i++) {
+		link->fn[i].space = *p;
+		p++;
+		link->fn[i].addr = le32toh(*(u_int *) p);
+		p += 4;
+	}
+	return 0;
+}
+
+/*====================================================================*/
+
+static int parse_strings(u_char * p, u_char * q, int max,
+			 char *s, u_char * ofs, u_char * found)
+{
+	int i, j, ns;
+
+	if (p == q)
+		return -1;
+	ns = 0;
+	j = 0;
+	for (i = 0; i < max; i++) {
+		if (*p == 0xff)
+			break;
+		ofs[i] = j;
+		ns++;
+		for (;;) {
+			s[j++] = (*p == 0xff) ? '\0' : *p;
+			if ((*p == '\0') || (*p == 0xff))
+				break;
+			if (++p == q)
+				return -1;
+		}
+		if ((*p == 0xff) || (++p == q))
+			break;
+	}
+	if (found) {
+		*found = ns;
+		return 0;
+	} else {
+		return (ns == max) ? 0 : -1;
+	}
+}
+
+/*====================================================================*/
+
+static int parse_vers_1(tuple_t * tuple, cistpl_vers_1_t * vers_1)
+{
+	u_char *p, *q;
+
+	p = (u_char *) tuple->TupleData;
+	q = p + tuple->TupleDataLen;
+
+	vers_1->major = *p;
+	p++;
+	vers_1->minor = *p;
+	p++;
+	if (p >= q)
+		return -1;
+
+	return parse_strings(p, q, CISTPL_VERS_1_MAX_PROD_STRINGS,
+			     vers_1->str, vers_1->ofs, &vers_1->ns);
+}
+
+/*====================================================================*/
+
+static int parse_altstr(tuple_t * tuple, cistpl_altstr_t * altstr)
+{
+	u_char *p, *q;
+
+	p = (u_char *) tuple->TupleData;
+	q = p + tuple->TupleDataLen;
+
+	return parse_strings(p, q, CISTPL_MAX_ALTSTR_STRINGS,
+			     altstr->str, altstr->ofs, &altstr->ns);
+}
+
+/*====================================================================*/
+
+static int parse_jedec(tuple_t * tuple, cistpl_jedec_t * jedec)
+{
+	u_char *p, *q;
+	int nid;
+
+	p = (u_char *) tuple->TupleData;
+	q = p + tuple->TupleDataLen;
+
+	for (nid = 0; nid < CISTPL_MAX_DEVICES; nid++) {
+		if (p > q - 2)
+			break;
+		jedec->id[nid].mfr = p[0];
+		jedec->id[nid].info = p[1];
+		p += 2;
+	}
+	jedec->nid = nid;
+	return 0;
+}
+
+/*====================================================================*/
+
+static int parse_manfid(tuple_t * tuple, cistpl_manfid_t * m)
+{
+	u_short *p;
+	if (tuple->TupleDataLen < 4)
+		return -1;
+	p = (u_short *) tuple->TupleData;
+	m->manf = le16toh(p[0]);
+	m->card = le16toh(p[1]);
+	return 0;
+}
+
+/*====================================================================*/
+
+static int parse_funcid(tuple_t * tuple, cistpl_funcid_t * f)
+{
+	u_char *p;
+	if (tuple->TupleDataLen < 2)
+		return -1;
+	p = (u_char *) tuple->TupleData;
+	f->func = p[0];
+	f->sysinit = p[1];
+	return 0;
+}
+
+/*====================================================================*/
+
+static int parse_funce(tuple_t * tuple, cistpl_funce_t * f)
+{
+	u_char *p;
+	int i;
+	if (tuple->TupleDataLen < 1)
+		return -1;
+	p = (u_char *) tuple->TupleData;
+	f->type = p[0];
+	for (i = 1; i < tuple->TupleDataLen; i++)
+		f->data[i - 1] = p[i];
+	return 0;
+}
+
+/*====================================================================*/
+
+static int parse_config(tuple_t * tuple, cistpl_config_t * config)
+{
+	int rasz, rmsz, i;
+	u_char *p;
+
+	p = (u_char *) tuple->TupleData;
+	rasz = *p & 0x03;
+	rmsz = (*p & 0x3c) >> 2;
+	if (tuple->TupleDataLen < rasz + rmsz + 4)
+		return -1;
+	config->last_idx = *(++p);
+	p++;
+	config->base = 0;
+	for (i = 0; i <= rasz; i++)
+		config->base += p[i] << (8 * i);
+	p += rasz + 1;
+	for (i = 0; i < 4; i++)
+		config->rmask[i] = 0;
+	for (i = 0; i <= rmsz; i++)
+		config->rmask[i >> 2] += p[i] << (8 * (i % 4));
+	config->subtuples = tuple->TupleDataLen - (rasz + rmsz + 4);
+	return 0;
+}
+
+/*======================================================================
+
+	The following routines are all used to parse the nightmarish
+	config table entries.
+
+======================================================================*/
+
+static u_char *parse_power(u_char * p, u_char * q, cistpl_power_t * pwr)
+{
+	int i;
+	u_int scale;
+
+	if (p == q)
+		return NULL;
+	pwr->present = *p;
+	pwr->flags = 0;
+	p++;
+	for (i = 0; i < 7; i++)
+		if (pwr->present & (1 << i)) {
+			if (p == q)
+				return NULL;
+			pwr->param[i] = POWER_CVT(*p);
+			scale = POWER_SCALE(*p);
+			while (*p & 0x80) {
+				if (++p == q)
+					return NULL;
+				if ((*p & 0x7f) < 100)
+					pwr->param[i] +=
+					    (*p & 0x7f) * scale / 100;
+				else if (*p == 0x7d)
+					pwr->flags |= CISTPL_POWER_HIGHZ_OK;
+				else if (*p == 0x7e)
+					pwr->param[i] = 0;
+				else if (*p == 0x7f)
+					pwr->flags |= CISTPL_POWER_HIGHZ_REQ;
+				else
+					return NULL;
+			}
+			p++;
+		}
+	return p;
+}
+
+/*====================================================================*/
+
+static u_char *parse_timing(u_char * p, u_char * q, cistpl_timing_t * timing)
+{
+	u_char scale;
+
+	if (p == q)
+		return NULL;
+	scale = *p;
+	if ((scale & 3) != 3) {
+		if (++p == q)
+			return NULL;
+		timing->wait = SPEED_CVT(*p);
+		timing->waitscale = exponent[scale & 3];
+	} else
+		timing->wait = 0;
+	scale >>= 2;
+	if ((scale & 7) != 7) {
+		if (++p == q)
+			return NULL;
+		timing->ready = SPEED_CVT(*p);
+		timing->rdyscale = exponent[scale & 7];
+	} else
+		timing->ready = 0;
+	scale >>= 3;
+	if (scale != 7) {
+		if (++p == q)
+			return NULL;
+		timing->reserved = SPEED_CVT(*p);
+		timing->rsvscale = exponent[scale];
+	} else
+		timing->reserved = 0;
+	p++;
+	return p;
+}
+
+/*====================================================================*/
+
+static u_char *parse_io(u_char * p, u_char * q, cistpl_io_t * io)
+{
+	int i, j, bsz, lsz;
+
+	if (p == q)
+		return NULL;
+	io->flags = *p;
+
+	if (!(*p & 0x80)) {
+		io->nwin = 1;
+		io->win[0].base = 0;
+		io->win[0].len = (1 << (io->flags & CISTPL_IO_LINES_MASK));
+		return p + 1;
+	}
+
+	if (++p == q)
+		return NULL;
+	io->nwin = (*p & 0x0f) + 1;
+	bsz = (*p & 0x30) >> 4;
+	if (bsz == 3)
+		bsz++;
+	lsz = (*p & 0xc0) >> 6;
+	if (lsz == 3)
+		lsz++;
+	p++;
+
+	for (i = 0; i < io->nwin; i++) {
+		io->win[i].base = 0;
+		io->win[i].len = 1;
+		for (j = 0; j < bsz; j++, p++) {
+			if (p == q)
+				return NULL;
+			io->win[i].base += *p << (j * 8);
+		}
+		for (j = 0; j < lsz; j++, p++) {
+			if (p == q)
+				return NULL;
+			io->win[i].len += *p << (j * 8);
+		}
+	}
+	return p;
+}
+
+/*====================================================================*/
+
+static u_char *parse_mem(u_char * p, u_char * q, cistpl_mem_t * mem)
+{
+	int i, j, asz, lsz, has_ha;
+	u_int len, ca, ha;
+
+	if (p == q)
+		return NULL;
+
+	mem->nwin = (*p & 0x07) + 1;
+	lsz = (*p & 0x18) >> 3;
+	asz = (*p & 0x60) >> 5;
+	has_ha = (*p & 0x80);
+	if (++p == q)
+		return NULL;
+
+	for (i = 0; i < mem->nwin; i++) {
+		len = ca = ha = 0;
+		for (j = 0; j < lsz; j++, p++) {
+			if (p == q)
+				return NULL;
+			len += *p << (j * 8);
+		}
+		for (j = 0; j < asz; j++, p++) {
+			if (p == q)
+				return NULL;
+			ca += *p << (j * 8);
+		}
+		if (has_ha)
+			for (j = 0; j < asz; j++, p++) {
+				if (p == q)
+					return NULL;
+				ha += *p << (j * 8);
+			}
+		mem->win[i].len = len << 8;
+		mem->win[i].card_addr = ca << 8;
+		mem->win[i].host_addr = ha << 8;
+	}
+	return p;
+}
+
+/*====================================================================*/
+
+static u_char *parse_irq(u_char * p, u_char * q, cistpl_irq_t * irq)
+{
+	if (p == q)
+		return NULL;
+	irq->IRQInfo1 = *p;
+	p++;
+	if (irq->IRQInfo1 & IRQ_INFO2_VALID) {
+		if (p + 2 > q)
+			return NULL;
+		irq->IRQInfo2 = (p[1] << 8) + p[0];
+		p += 2;
+	}
+	return p;
+}
+
+/*====================================================================*/
+
+static int parse_cftable_entry(tuple_t * tuple, cistpl_cftable_entry_t * entry)
+{
+	u_char *p, *q, features;
+
+	p = tuple->TupleData;
+	q = p + tuple->TupleDataLen;
+	entry->index = *p & 0x3f;
+	entry->flags = 0;
+	if (*p & 0x40)
+		entry->flags |= CISTPL_CFTABLE_DEFAULT;
+	if (*p & 0x80) {
+		if (++p == q)
+			return -1;
+		if (*p & 0x10)
+			entry->flags |= CISTPL_CFTABLE_BVDS;
+		if (*p & 0x20)
+			entry->flags |= CISTPL_CFTABLE_WP;
+		if (*p & 0x40)
+			entry->flags |= CISTPL_CFTABLE_RDYBSY;
+		if (*p & 0x80)
+			entry->flags |= CISTPL_CFTABLE_MWAIT;
+		entry->interface = *p & 0x0f;
+	} else
+		entry->interface = 0;
+
+	/* Process optional features */
+	if (++p == q)
+		return -1;
+	features = *p;
+	p++;
+
+	/* Power options */
+	if ((features & 3) > 0) {
+		p = parse_power(p, q, &entry->vcc);
+		if (p == NULL)
+			return -1;
+	} else
+		entry->vcc.present = 0;
+	if ((features & 3) > 1) {
+		p = parse_power(p, q, &entry->vpp1);
+		if (p == NULL)
+			return -1;
+	} else
+		entry->vpp1.present = 0;
+	if ((features & 3) > 2) {
+		p = parse_power(p, q, &entry->vpp2);
+		if (p == NULL)
+			return -1;
+	} else
+		entry->vpp2.present = 0;
+
+	/* Timing options */
+	if (features & 0x04) {
+		p = parse_timing(p, q, &entry->timing);
+		if (p == NULL)
+			return -1;
+	} else {
+		entry->timing.wait = 0;
+		entry->timing.ready = 0;
+		entry->timing.reserved = 0;
+	}
+
+	/* I/O window options */
+	if (features & 0x08) {
+		p = parse_io(p, q, &entry->io);
+		if (p == NULL)
+			return -1;
+	} else
+		entry->io.nwin = 0;
+
+	/* Interrupt options */
+	if (features & 0x10) {
+		p = parse_irq(p, q, &entry->irq);
+		if (p == NULL)
+			return -1;
+	} else
+		entry->irq.IRQInfo1 = 0;
+
+	switch (features & 0x60) {
+	case 0x00:
+		entry->mem.nwin = 0;
+		break;
+	case 0x20:
+		entry->mem.nwin = 1;
+		entry->mem.win[0].len = le16toh(*(u_short *) p) << 8;
+		entry->mem.win[0].card_addr = 0;
+		entry->mem.win[0].host_addr = 0;
+		p += 2;
+		if (p > q)
+			return -1;
+		break;
+	case 0x40:
+		entry->mem.nwin = 1;
+		entry->mem.win[0].len = le16toh(*(u_short *) p) << 8;
+		entry->mem.win[0].card_addr =
+		    le16toh(*(u_short *) (p + 2)) << 8;
+		entry->mem.win[0].host_addr = 0;
+		p += 4;
+		if (p > q)
+			return -1;
+		break;
+	case 0x60:
+		p = parse_mem(p, q, &entry->mem);
+		if (p == NULL)
+			return -1;
+		break;
+	}
+
+	/* Misc features */
+	if (features & 0x80) {
+		if (p == q)
+			return -1;
+		entry->flags |= (*p << 8);
+		while (*p & 0x80)
+			if (++p == q)
+				return -1;
+		p++;
+	}
+
+	entry->subtuples = q - p;
+
+	return 0;
+}
+
+/*====================================================================*/
+
+static int parse_bar(tuple_t * tuple, cistpl_bar_t * bar)
+{
+	u_char *p;
+	if (tuple->TupleDataLen < 6)
+		return -1;
+	p = (u_char *) tuple->TupleData;
+	bar->attr = *p;
+	p += 2;
+	bar->size = le32toh(*(u_int *) p);
+	return 0;
+}
+
+static int parse_config_cb(tuple_t * tuple, cistpl_config_t * config)
+{
+	u_char *p;
+
+	p = (u_char *) tuple->TupleData;
+	if ((*p != 3) || (tuple->TupleDataLen < 6))
+		return -1;
+	config->last_idx = *(++p);
+	p++;
+	config->base = le32toh(*(u_int *) p);
+	config->subtuples = tuple->TupleDataLen - 6;
+	return 0;
+}
+
+static int parse_cftable_entry_cb(tuple_t * tuple,
+				  cistpl_cftable_entry_cb_t * entry)
+{
+	u_char *p, *q, features;
+
+	p = tuple->TupleData;
+	q = p + tuple->TupleDataLen;
+	entry->index = *p & 0x3f;
+	entry->flags = 0;
+	if (*p & 0x40)
+		entry->flags |= CISTPL_CFTABLE_DEFAULT;
+
+	/* Process optional features */
+	if (++p == q)
+		return -1;
+	features = *p;
+	p++;
+
+	/* Power options */
+	if ((features & 3) > 0) {
+		p = parse_power(p, q, &entry->vcc);
+		if (p == NULL)
+			return -1;
+	} else
+		entry->vcc.present = 0;
+	if ((features & 3) > 1) {
+		p = parse_power(p, q, &entry->vpp1);
+		if (p == NULL)
+			return -1;
+	} else
+		entry->vpp1.present = 0;
+	if ((features & 3) > 2) {
+		p = parse_power(p, q, &entry->vpp2);
+		if (p == NULL)
+			return -1;
+	} else
+		entry->vpp2.present = 0;
+
+	/* I/O window options */
+	if (features & 0x08) {
+		if (p == q)
+			return -1;
+		entry->io = *p;
+		p++;
+	} else
+		entry->io = 0;
+
+	/* Interrupt options */
+	if (features & 0x10) {
+		p = parse_irq(p, q, &entry->irq);
+		if (p == NULL)
+			return -1;
+	} else
+		entry->irq.IRQInfo1 = 0;
+
+	if (features & 0x20) {
+		if (p == q)
+			return -1;
+		entry->mem = *p;
+		p++;
+	} else
+		entry->mem = 0;
+
+	/* Misc features */
+	if (features & 0x80) {
+		if (p == q)
+			return -1;
+		entry->flags |= (*p << 8);
+		if (*p & 0x80) {
+			if (++p == q)
+				return -1;
+			entry->flags |= (*p << 16);
+		}
+		while (*p & 0x80)
+			if (++p == q)
+				return -1;
+		p++;
+	}
+
+	entry->subtuples = q - p;
+
+	return 0;
+}
+
+/*====================================================================*/
+
+static int parse_device_geo(tuple_t * tuple, cistpl_device_geo_t * geo)
+{
+	u_char *p, *q;
+	int n;
+
+	p = (u_char *) tuple->TupleData;
+	q = p + tuple->TupleDataLen;
+
+	for (n = 0; n < CISTPL_MAX_DEVICES; n++) {
+		if (p > q - 6)
+			break;
+		geo->geo[n].buswidth = p[0];
+		geo->geo[n].erase_block = 1 << (p[1] - 1);
+		geo->geo[n].read_block = 1 << (p[2] - 1);
+		geo->geo[n].write_block = 1 << (p[3] - 1);
+		geo->geo[n].partition = 1 << (p[4] - 1);
+		geo->geo[n].interleave = 1 << (p[5] - 1);
+		p += 6;
+	}
+	geo->ngeo = n;
+	return 0;
+}
+
+/*====================================================================*/
+
+static int parse_vers_2(tuple_t * tuple, cistpl_vers_2_t * v2)
+{
+	u_char *p, *q;
+
+	if (tuple->TupleDataLen < 10)
+		return -1;
+
+	p = tuple->TupleData;
+	q = p + tuple->TupleDataLen;
+
+	v2->vers = p[0];
+	v2->comply = p[1];
+	v2->dindex = le16toh(*(u_short *) (p + 2));
+	v2->vspec8 = p[6];
+	v2->vspec9 = p[7];
+	v2->nhdr = p[8];
+	p += 9;
+	return parse_strings(p, q, 2, v2->str, &v2->vendor, NULL);
+}
+
+/*====================================================================*/
+
+static int parse_org(tuple_t * tuple, cistpl_org_t * org)
+{
+	u_char *p, *q;
+	int i;
+
+	p = tuple->TupleData;
+	q = p + tuple->TupleDataLen;
+	if (p == q)
+		return -1;
+	org->data_org = *p;
+	if (++p == q)
+		return -1;
+	for (i = 0; i < 30; i++) {
+		org->desc[i] = *p;
+		if (*p == '\0')
+			break;
+		if (++p == q)
+			return -1;
+	}
+	return 0;
+}
+
+/*====================================================================*/
+
+static int parse_format(tuple_t * tuple, cistpl_format_t * fmt)
+{
+	u_char *p;
+
+	if (tuple->TupleDataLen < 10)
+		return -1;
+
+	p = tuple->TupleData;
+
+	fmt->type = p[0];
+	fmt->edc = p[1];
+	fmt->offset = le32toh(*(u_int *) (p + 2));
+	fmt->length = le32toh(*(u_int *) (p + 6));
+
+	return 0;
+}
+
+/*====================================================================*/
+
+static int parse_tuple(tuple_t * tuple, cisparse_t * parse)
+{
+	int ret = 0;
+
+	if (tuple->TupleDataLen > tuple->TupleDataMax)
+		return -1;
+	switch (tuple->TupleCode) {
+	case CISTPL_DEVICE:
+	case CISTPL_DEVICE_A:
+		ret = parse_device(tuple, &parse->device);
+		break;
+	case CISTPL_BAR:
+		ret = parse_bar(tuple, &parse->bar);
+		break;
+	case CISTPL_CONFIG_CB:
+		ret = parse_config_cb(tuple, &parse->config);
+		break;
+	case CISTPL_CFTABLE_ENTRY_CB:
+		ret = parse_cftable_entry_cb(tuple, &parse->cftable_entry_cb);
+		break;
+	case CISTPL_CHECKSUM:
+		ret = parse_checksum(tuple, &parse->checksum);
+		break;
+	case CISTPL_LONGLINK_A:
+	case CISTPL_LONGLINK_C:
+		ret = parse_longlink(tuple, &parse->longlink);
+		break;
+	case CISTPL_LONGLINK_MFC:
+		ret = parse_longlink_mfc(tuple, &parse->longlink_mfc);
+		break;
+	case CISTPL_VERS_1:
+		ret = parse_vers_1(tuple, &parse->version_1);
+		break;
+	case CISTPL_ALTSTR:
+		ret = parse_altstr(tuple, &parse->altstr);
+		break;
+	case CISTPL_JEDEC_A:
+	case CISTPL_JEDEC_C:
+		ret = parse_jedec(tuple, &parse->jedec);
+		break;
+	case CISTPL_MANFID:
+		ret = parse_manfid(tuple, &parse->manfid);
+		break;
+	case CISTPL_FUNCID:
+		ret = parse_funcid(tuple, &parse->funcid);
+		break;
+	case CISTPL_FUNCE:
+		ret = parse_funce(tuple, &parse->funce);
+		break;
+	case CISTPL_CONFIG:
+		ret = parse_config(tuple, &parse->config);
+		break;
+	case CISTPL_CFTABLE_ENTRY:
+		ret = parse_cftable_entry(tuple, &parse->cftable_entry);
+		break;
+	case CISTPL_DEVICE_GEO:
+	case CISTPL_DEVICE_GEO_A:
+		ret = parse_device_geo(tuple, &parse->device_geo);
+		break;
+	case CISTPL_VERS_2:
+		ret = parse_vers_2(tuple, &parse->vers_2);
+		break;
+	case CISTPL_ORG:
+		ret = parse_org(tuple, &parse->org);
+		break;
+	case CISTPL_FORMAT:
+	case CISTPL_FORMAT_A:
+		ret = parse_format(tuple, &parse->format);
+		break;
+	case CISTPL_NO_LINK:
+	case CISTPL_LINKTARGET:
+		ret = 0;
+		break;
+	case CISTPL_END:
+		ret = 0;
+		break;
+	default:
+		ret = -1;
+		break;
+	}
+	return ret;
+}
+
+/*====================================================================*/
+
+#define MAX_SOCKS 8
+
+int main(int argc, char *argv[])
+{
+	int i, fd;
+	tuple_parse_t tuple_parse;
+	int optch, errflg, first;
+	char *infile = NULL;
+
+	errflg = 0;
+	while ((optch = getopt(argc, argv, "vi:")) != -1) {
+		switch (optch) {
+		case 'v':
+			verbose = 1;
+			break;
+		default:
+			errflg = 1;
+			break;
+		}
+	}
+	if (errflg || (optind > argc - 1)) {
+		fprintf(stderr, "usage: %s [-v] infile\n", argv[0]);
+		exit(EXIT_FAILURE);
+	}
+
+	for (i = 0; optind + i < argc; i++) {
+		infile = argv[optind + i];
+
+		nfn = cur = 0;
+		indent[0] = '\0';
+		fd = open(infile, O_RDONLY);
+		if (fd < 0) {
+			perror("open()");
+			return -1;
+		}
+
+		if (!verbose && (i > 0))
+			putchar('\n');
+
+		tuple_parse.tuple.TupleDataMax = sizeof(tuple_parse.data);
+		tuple_parse.tuple.Attributes =
+		    TUPLE_RETURN_LINK | TUPLE_RETURN_COMMON;
+		tuple_parse.tuple.DesiredTuple = RETURN_FIRST_TUPLE;
+		tuple_parse.tuple.TupleOffset = 0;
+		tuple_parse.tuple.TupleData = tuple_parse.data;
+
+		for (first = 1;; first = 0) {
+			if (get_tuple_buf(fd, &tuple_parse.tuple, first) != 0)
+				break;
+			if (verbose)
+				print_tuple(&tuple_parse);
+			if (parse_tuple(&tuple_parse.tuple, &tuple_parse.parse))
+				printf("%sparse error\n", indent);
+			else
+				print_parse(&tuple_parse);
+			if (verbose)
+				putchar('\n');
+			if (tuple_parse.tuple.TupleCode == CISTPL_END)
+				break;
+		}
+
+		if (!verbose && (nfn > 0))
+			printf("%s}\n", indent + 2);
+	}
+
+	return 0;
+}
Signature · 1 line
1.7.1
#5 lore raw

Re: [PATCH 4/5] Add an utility to parse CIS files to readable form

Quoted 5 lines · Dmitry Eremin-Solenikov

Import from pcmcia-cs project a dump_cis utility. It reads machine-readable CIS file and output text representation (which can be processed by mkcis utility).

pcmciautils also include dump_cis ("make debugtools"). As this version is probably better maintained, we probably should not introduce a split here?

Regards,

Wolfram

Signature · 2 lines
Pengutronix e.K.                           | Wolfram Sang                |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
#6 lore raw

Re: [PATCH 4/5] Add an utility to parse CIS files to readable form

Hey,

Quoted 9 lines · Wolfram Sang
Quoted 5 lines · Dmitry Eremin-Solenikov

Import from pcmcia-cs project a dump_cis utility. It reads machine-readable CIS file and output text representation (which can be processed by mkcis utility).

pcmciautils also include dump_cis ("make debugtools"). As this version is probably better maintained, we probably should not introduce a split here?

dump_cis did not receive a single meaningful change, and I do not expect one, so I wouldn't fear a split/fork here.

Best,
Dominik

#7 lore raw

PATCH 5/5 Build infrastructure for mkcis and dump_cis programs

In reply to Dmitry Eremin-Solenikov

Add Makefile and .gitignore for mkcis/dump_cis programs.

---
 mkcis/.gitignore |    4 ++++
 mkcis/Makefile   |   29 +++++++++++++++++++++++++++++
 2 files changed, 33 insertions(+), 0 deletions(-)
 create mode 100644 mkcis/.gitignore
 create mode 100644 mkcis/Makefile
mkcis/.gitignore new file +4 -0
new file mode 100644
index 0000000..8d19f6d
@@ -0,0 +1,4 @@
+*.o
+mkcis
+dump_cis
+
mkcis/Makefile new file +29 -0
new file mode 100644
index 0000000..b7faa6f
@@ -0,0 +1,29 @@
+CFLAGS = -Wall -I.
+LDFLAGS = -lm
+
+# Uncomment to regenerate flex/bison output
+# GENERATE_PARSER = 1
+
+BISON = bison
+FLEX = flex
+
+all: mkcis dump_cis
+
+dump_cis: dump_cis.o
+
+mkcis: mkcis.o mkcis-lexer.lex.o mkcis-parser.tab.o
+
+clean:
+	-rm -f mkcis dump_cis *.o
+
+mkcis-lexer.lex.o: mkcis-parser.tab.h
+
+ifeq ($(GENERATE_PARSER),1)
+mkcis-parser.tab.h: mkcis-parser.tab.c
+
+mkcis-parser.tab.c: mkcis-parser.y
+	$(BISON) -d -o $@ $<
+
+mkcis-lexer.lex.c: mkcis-lexer.l
+	$(FLEX) -o $@ $<
+endif
Signature · 1 line
1.7.1