#! /bin/bash

EXTRA_OPTS=/etc/pcmcia/config.opts.extra
cat <<- EOT > $EXTRA_OPTS
	# This file is automatically generated by $0
	# To activate these additional memory and I/O ranges open config.opts
	# and uncomment the line "source ./config.opts.extra"
	#
EOT

# Look for all PCI CardBus bridges
while read a b c d; do
	case $c in 0607*) CB_BRIDGES="$CB_BRIDGES $a";; esac
done < <(lspci -n)

# Extract memory and I/O ranges of all CardBus bridges
for a in $CB_BRIDGES; do lspci -vs $a; done | sed -n \
 -e 's=^.*emory.*: \([0-9a-f]*\)-\([0-9a-f]*\).*$=include memory 0x\1-0x\2=p' \
 -e 's=^.*I/O.*: \([0-9a-f]*\)-\([0-9a-f]*\).*$=include port 0x\1-0x\2=p' \
 >> $EXTRA_OPTS
