pax_global_header00006660000000000000000000000064115517710440014517gustar00rootroot0000000000000052 comment=26b1a2f41a859db31d73e9cf48e40d267095d482 pcmciautils-018/000077500000000000000000000000001155177104400137065ustar00rootroot00000000000000pcmciautils-018/.gitignore000066400000000000000000000004741155177104400157030ustar00rootroot00000000000000build/ccdv pccardctl pcmcia-check-broken-cis pcmcia-socket-startup src/lex_config.o src/pccardctl.o src/pcmcia-check-broken-cis.o src/read-cis.o src/startup.o src/yacc_config.c src/yacc_config.h src/yacc_config.o udev/60-pcmcia.rules # debug tools cbdump dump_cis debug/cbdump.o debug/dump_cis.o debug/parse_cis.o pcmciautils-018/COPYING000066400000000000000000000431101155177104400147400ustar00rootroot00000000000000 GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc. 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Library General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) year name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Library General Public License instead of this License. pcmciautils-018/Makefile000066400000000000000000000244101155177104400153470ustar00rootroot00000000000000# Makefile for pcmciautils # # Copyright (C) 2005 Dominik Brodowski # # Based largely on the Makefile for udev by: # # Copyright (C) 2003,2004 Greg Kroah-Hartman # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; version 2 of the License. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # default: all help: @echo "Common targets ('*' is default):" @echo "* all - build the standard set of utilities" @echo " debugtools - build the debugging utilities" # Set this to 'false' if you do not need the socket-startup script # # You don't need it if the socket driver does not select # PCCARD_NONSTATIC -- that is the case for many embedded systems -- # and for yenta_socket if the cardbus bridge is either below a # PCI-PCI bridge, or where the PCI bus is not equivalent to the host # bus (e.g. on PPC) STARTUP ?= true # Set this to true if you want to use 'udev' instead of 'hotplug' # to invoke the necessary pcmciautils commands. UDEV ?= true # Set the following to `true' to log the debug # and make a unstripped, unoptimized binary. # Leave this set to `false' for production use. DEBUG ?= false # Set this to true if you want to statically link the binaries # to be compiled. STATIC ?= false # make the build silent. Set this to something else to make it noisy again. V ?= false PCCARDCTL = pccardctl LSPCMCIA = lspcmcia PCMCIA_CHECK_BROKEN_CIS = pcmcia-check-broken-cis PCMCIA_SOCKET_STARTUP = pcmcia-socket-startup CBDUMP = cbdump CISDUMP = dump_cis VERSION = 018 #INSTALL_DIR = /usr/local/sbin RELEASE_NAME = pcmciautils-$(VERSION) #DESTDIR = KERNEL_DIR = /lib/modules/${shell uname -r}/build # override this to make pcmciautils look in a different location for its files prefix = exec_prefix = ${prefix} etcdir = ${prefix}/etc sbindir = ${exec_prefix}/sbin mandir = ${prefix}/usr/share/man udevdir = ${prefix}/lib/udev INSTALL = /usr/bin/install -c INSTALL_PROGRAM = ${INSTALL} INSTALL_DATA = ${INSTALL} -m 644 INSTALL_SCRIPT = ${INSTALL_PROGRAM} SYMLINK = ln -sf # place to put our hotplug scripts nodes hotplugdir = ${etcdir}/hotplug # place to put our udev rules to udevrulesdir = ${udevdir}/rules.d # place to put our udev helper binaries (pcmcia-socket-startup, pcmcia-check-broken-cis) to udevhelperdir = ${udevdir} # udevhelperdir = ${sbindir} # place where PCMICIA config is put to pcmciaconfdir = ${etcdir}/pcmcia # set up PWD so that older versions of make will work with our build. PWD = $(shell pwd) # If you are running a cross compiler, you may want to set this # to something more interesting, like "arm-linux-". If you want # to compile vs uClibc, that can be done here as well. CROSS = #/usr/i386-linux-uclibc/usr/bin/i386-uclibc- CC = $(CROSS)gcc LD = $(CROSS)gcc AR = $(CROSS)ar STRIP = $(CROSS)strip RANLIB = $(CROSS)ranlib HOSTCC = gcc export CROSS CC AR STRIP RANLIB CFLAGS LDFLAGS LIB_OBJS ARCH_LIB_OBJS CRT0 # code taken from uClibc to determine the current arch ARCH := ${shell $(CC) -dumpmachine | sed -e s'/-.*//' -e 's/i.86/i386/' -e 's/sparc.*/sparc/' \ -e 's/arm.*/arm/g' -e 's/m68k.*/m68k/' -e 's/powerpc/ppc/g'} # code taken from uClibc to determine the gcc include dir GCCINCDIR := ${shell LC_ALL=C $(CC) -print-search-dirs | sed -ne "s/install: \(.*\)/\1include/gp"} # code taken from uClibc to determine the libgcc.a filename GCC_LIB := $(shell $(CC) -print-libgcc-file-name ) # use '-Os' optimization if available, else use -O2 OPTIMIZATION := ${shell if $(CC) -Os -S -o /dev/null -xc /dev/null >/dev/null 2>&1; \ then echo "-Os"; else echo "-O2" ; fi} # check if compiler option is supported cc-supports = ${shell if $(CC) ${1} -S -o /dev/null -xc /dev/null > /dev/null 2>&1; then echo "$(1)"; fi;} WARNINGS := -Wall -Wchar-subscripts -Wpointer-arith -Wsign-compare WARNINGS += $(call cc-supports,-Wno-pointer-sign) WARNINGS += $(call cc-supports,-Wdeclaration-after-statement) WARNINGS += -Wshadow CFLAGS += -pipe -DPCMCIAUTILS_VERSION=\"$(VERSION)\" YFLAGS := -d HEADERS = \ src/cistpl.h \ src/startup.h \ src/yacc_config.h OBJS = \ src/lex_config.l \ src/pccardctl.c \ src/pcmcia-check-broken-cis.c \ src/read-cis.c \ src/startup.c \ src/startup.h \ src/yacc_config.h \ src/yacc_config.y CFLAGS += -I$(PWD)/src CFLAGS += $(WARNINGS) -I$(GCCINCDIR) LIB_OBJS = -lc -lsysfs LIB_PLAIN_OBJS = -lc LIB_PCI_OBJS = -lc -lpci ifeq ($(strip $(STATIC)),true) LIB_OBJS = -lsysfs LIB_PLAIN_OBJS = LIB_PCI_OBJS = -lpci LDFLAGS += -static else LDFLAGS += -Wl,-warn-common endif ifeq ($(strip $(V)),false) QUIET=@$(PWD)/build/ccdv HOST_PROGS=build/ccdv else QUIET= HOST_PROGS= endif # if DEBUG is enabled, then we do not strip or optimize ifeq ($(strip $(DEBUG)),true) CFLAGS += -O1 -g -DDEBUG -D_GNU_SOURCE STRIPCMD = /bin/true -Since_we_are_debugging else CFLAGS += $(OPTIMIZATION) -fomit-frame-pointer -D_GNU_SOURCE STRIPCMD = $(STRIP) -s --remove-section=.note --remove-section=.comment endif # HOTPLUG or UDEV? ifeq ($(strip $(UDEV)),false) INSTALL_TARGETS = install-hotplug UNINSTALL_TARGETS = uninstall-hotplug else INSTALL_TARGETS = install-udev UNINSTALL_TARGETS = uninstall-udev endif # if STARTUP is disabled, we can skip a few things ifeq ($(strip $(STARTUP)),false) PCMCIA_SOCKET_STARTUP_BUILD = else PCMCIA_SOCKET_STARTUP_BUILD = $(PCMCIA_SOCKET_STARTUP) INSTALL_TARGETS += install-config install-socket-tools UNINSTALL_TARGETS += uninstall-socket-tools ifeq ($(strip $(UDEV)),false) INSTALL_TARGETS += install-socket-hotplug UNINSTALL_TARGETS += uninstall-socket-hotplug endif endif #udev rules collection UDEV_RULES_FILE = udev/60-pcmcia.rules UDEV_RULES = udev/rules-start udev/rules-modprobe udev/rules-base ifneq ($(strip $(STARTUP)),false) UDEV_RULES += udev/rules-nonstaticsocket endif UDEV_RULES += udev/rules-end all: ccdv $(PCCARDCTL) $(PCMCIA_CHECK_BROKEN_CIS) $(PCMCIA_SOCKET_STARTUP_BUILD) udevrules ccdv: build/ccdv build/ccdv: build/ccdv.c @echo "Building ccdv" @$(HOSTCC) -O1 $< -o $@ %.o : %.c ccdv $(QUIET) $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $< %.c %.h : %.y $(YACC) $(YFLAGS) $< mv y.tab.c $*.c mv y.tab.h $*.h $(PCCARDCTL): $(LIBC) src/$(PCCARDCTL).o src/$(PCCARDCTL).c $(OBJS) $(HEADERS) $(QUIET) $(LD) $(LDFLAGS) -o $@ $(CRT0) src/$(PCCARDCTL).o $(LIB_OBJS) $(ARCH_LIB_OBJS) $(QUIET) $(STRIPCMD) $@ $(PCMCIA_CHECK_BROKEN_CIS): $(LIBC) src/$(PCMCIA_CHECK_BROKEN_CIS).o src/read-cis.o $(OBJS) $(HEADERS) $(QUIET) $(LD) $(LDFLAGS) -o $@ $(CRT0) src/$(PCMCIA_CHECK_BROKEN_CIS).o src/read-cis.o $(LIB_PLAIN_OBJS) $(ARCH_LIB_OBJS) $(QUIET) $(STRIPCMD) $@ $(PCMCIA_SOCKET_STARTUP): $(LIBC) src/startup.o src/yacc_config.o src/lex_config.o $(OBJS) $(HEADERS) $(QUIET) $(LD) $(LDFLAGS) -o $@ $(CRT0) src/startup.o src/yacc_config.o src/lex_config.o $(LIB_OBJS) $(ARCH_LIB_OBJS) $(QUIET) $(STRIPCMD) $@ yacc_config.o lex_config.o: %.o: %.c $(CC) -c -MD -O -pipe $(CPPFLAGS) $< debugtools: ccdv $(CBDUMP) $(CISDUMP) $(CBDUMP): $(LIBC) debug/cbdump.o $(QUIET) $(LD) $(LDFLAGS) -o $@ $(CRT0) debug/$(CBDUMP).o $(LIB_PCI_OBJS) $(ARCH_LIB_OBJS) $(QUIET) $(STRIPCMD) $@ $(CISDUMP): $(LIBC) src/read-cis.o debug/parse_cis.o debug/dump_cis.o $(QUIET) $(LD) $(LDFLAGS) -o $@ $(CRT0) debug/$(CISDUMP).o src/read-cis.o debug/parse_cis.o $(LIB_OBJS) $(ARCH_LIB_OBJS) $(QUIET) $(STRIPCMD) $@ udevrules: cat $(UDEV_RULES) | sed -e "s#__UDEVHELPERDIR__#${udevhelperdir}#g" > $(UDEV_RULES_FILE) clean: -find . \( -not -type d \) -and \( -name '*~' -o -name '*.[oas]' \) -type f -print \ | xargs rm -f -rm -f $(PCCARDCTL) $(PCMCIA_CHECK_BROKEN_CIS) $(PCMCIA_SOCKET_STARTUP) -rm -f $(CBDUMP) $(CISDUMP) -rm -f src/yacc_config.c src/yacc_config.d src/lex_config.c src/lex_config.d src/yacc_config.h -rm -f udev/60-pcmcia.rules -rm -f build/ccdv install-hotplug: $(INSTALL) -d $(DESTDIR)$(hotplugdir) $(INSTALL_PROGRAM) -D hotplug/pcmcia.agent $(DESTDIR)$(hotplugdir)/pcmcia.agent $(INSTALL_PROGRAM) -D hotplug/pcmcia.rc $(DESTDIR)$(hotplugdir)/pcmcia.rc uninstall-hotplug: - rm -f $(DESTDIR)$(hotplugdir)/pcmcia.agent $(DESTDIR)$(hotplugdir)/pcmcia.rc install-socket-hotplug: $(INSTALL_PROGRAM) -D hotplug/pcmcia_socket.agent $(DESTDIR)$(hotplugdir)/pcmcia_socket.agent $(INSTALL_PROGRAM) -D hotplug/pcmcia_socket.rc $(DESTDIR)$(hotplugdir)/pcmcia_socket.rc uninstall-socket-hotplug: - rm -f $(DESTDIR)$(hotplugdir)/pcmcia_socket.agent $(DESTDIR)$(hotplugdir)/pcmcia_socket.rc install-socket-tools: $(INSTALL_PROGRAM) -D $(PCMCIA_SOCKET_STARTUP) $(DESTDIR)$(udevhelperdir)/$(PCMCIA_SOCKET_STARTUP) uninstall-socket-tools: - rm -f $(DESTDIR)$(udevhelperdir)/$(PCMCIA_SOCKET_STARTUP) install-tools: $(INSTALL) -d $(DESTDIR)$(sbindir) $(INSTALL_PROGRAM) -D $(PCCARDCTL) $(DESTDIR)$(sbindir)/$(PCCARDCTL) $(SYMLINK) $(PCCARDCTL) $(DESTDIR)$(sbindir)/$(LSPCMCIA) $(INSTALL_PROGRAM) -D $(PCMCIA_CHECK_BROKEN_CIS) $(DESTDIR)$(udevhelperdir)/$(PCMCIA_CHECK_BROKEN_CIS) uninstall-tools: - rm -f $(DESTDIR)$(sbindir)/$(PCCARDCTL) - rm -f $(DESTDIR)$(sbindir)/$(LSPCMCIA) - rm -f $(DESTDIR)$(udevhelperdir)/$(PCMCIA_CHECK_BROKEN_CIS) install-config: $(INSTALL) -d $(DESTDIR)$(pcmciaconfdir) $(INSTALL_DATA) -D config/config.opts $(DESTDIR)$(pcmciaconfdir)/config.opts if [ -f config/config.opts.$(ARCH) ]; then \ $(INSTALL_DATA) -D config/config.opts.$(ARCH) $(DESTDIR)$(pcmciaconfdir)/config.opts; \ fi uninstall-config: # - rm -f $(DESTDIR)$(pcmciaconfdir)/config.opts install-udev: $(INSTALL_DATA) -D $(UDEV_RULES_FILE) $(DESTDIR)$(udevrulesdir)/60-pcmcia.rules uninstall-udev: - rm -f $(DESTDIR)$(udevrulesdir)/60-pcmcia.rules install-man: $(INSTALL_DATA) -D man/man8/pccardctl.8 $(DESTDIR)$(mandir)/man8/pccardctl.8 $(SYMLINK) pccardctl.8 $(DESTDIR)$(mandir)/man8/lspcmcia.8 uninstall-man: - rm $(DESTDIR)$(mandir)/man8/pccardctl.8 - rm $(DESTDIR)$(mandir)/man8/lspcmcia.8 install: install-tools install-man $(INSTALL_TARGETS) uninstall: uninstall-tools uninstall-man $(UNINSTALL_TARGETS) pcmciautils-018/build/000077500000000000000000000000001155177104400150055ustar00rootroot00000000000000pcmciautils-018/build/ccdv.c000066400000000000000000000230421155177104400160710ustar00rootroot00000000000000/* ccdv.c * * Copyright (C) 2002-2003, by Mike Gleason, NcFTP Software. * All Rights Reserved. * * Licensed under the GNU Public License. */ #include #include #include #include #include #include #include #include #include #define SETCOLOR_SUCCESS (gANSIEscapes ? "\033\1331;32m" : "") #define SETCOLOR_FAILURE (gANSIEscapes ? "\033\1331;31m" : "") #define SETCOLOR_WARNING (gANSIEscapes ? "\033\1331;33m" : "") #define SETCOLOR_NORMAL (gANSIEscapes ? "\033\1330;39m" : "") #define TEXT_BLOCK_SIZE 8192 #define INDENT 2 #define TERMS "vt100:vt102:vt220:vt320:xterm:xterm-color:ansi:linux:scoterm:scoansi:dtterm:cons25:cygwin" size_t gNBufUsed = 0, gNBufAllocated = 0; char *gBuf = NULL; int gCCPID; char gAction[200] = ""; char gTarget[200] = ""; char gAr[32] = ""; char gArLibraryTarget[64] = ""; int gDumpCmdArgs = 0; char gArgsStr[1000]; int gColumns = 80; int gANSIEscapes = 0; int gExitStatus = 95; static void DumpFormattedOutput(void) { char *cp; char spaces[8 + 1] = " "; char *saved; int curcol; int i; curcol = 0; saved = NULL; for (cp = gBuf + ((gDumpCmdArgs == 0) ? strlen(gArgsStr) : 0); ; cp++) { if (*cp == '\0') { if (saved != NULL) { cp = saved; saved = NULL; } else break; } if (*cp == '\r') continue; if (*cp == '\t') { saved = cp + 1; cp = spaces + 8 - (8 - ((curcol - INDENT - 1) % 8)); } if (curcol == 0) { for (i = INDENT; --i >= 0; ) putchar(' '); curcol = INDENT; } putchar(*cp); if (++curcol == (gColumns - 1)) { putchar('\n'); curcol = 0; } else if (*cp == '\n') curcol = 0; } free(gBuf); } /* DumpFormattedOutput */ /* Difftime(), only for timeval structures. */ static void TimeValSubtract(struct timeval *tdiff, struct timeval *t1, struct timeval *t0) { tdiff->tv_sec = t1->tv_sec - t0->tv_sec; tdiff->tv_usec = t1->tv_usec - t0->tv_usec; if (tdiff->tv_usec < 0) { tdiff->tv_sec--; tdiff->tv_usec += 1000000; } } /* TimeValSubtract */ static void Wait(void) { int pid2, status; do { status = 0; pid2 = (int) waitpid(gCCPID, &status, 0); } while (((pid2 >= 0) && (! WIFEXITED(status))) || ((pid2 < 0) && (errno == EINTR))); if (WIFEXITED(status)) gExitStatus = WEXITSTATUS(status); } /* Wait */ static int SlurpProgress(int fd) { char s1[71]; char *newbuf; int nready; size_t ntoread; ssize_t nread; struct timeval now, tnext, tleft; fd_set ss; fd_set ss2; const char *trail = "/-\\|", *trailcp; trailcp = trail; snprintf(s1, sizeof(s1), "%s%s%s... ", gAction, gTarget[0] ? " " : "", gTarget); printf("\r%-70s%-9s", s1, ""); fflush(stdout); gettimeofday(&now, NULL); tnext = now; tnext.tv_sec++; tleft.tv_sec = 1; tleft.tv_usec = 0; FD_ZERO(&ss2); FD_SET(fd, &ss2); for(;;) { if (gNBufUsed == (gNBufAllocated - 1)) { if ((newbuf = (char *) realloc(gBuf, gNBufAllocated + TEXT_BLOCK_SIZE)) == NULL) { perror("ccdv: realloc"); return (-1); } gNBufAllocated += TEXT_BLOCK_SIZE; gBuf = newbuf; } for (;;) { ss = ss2; nready = select(fd + 1, &ss, NULL, NULL, &tleft); if (nready == 1) break; if (nready < 0) { if (errno != EINTR) { perror("ccdv: select"); return (-1); } continue; } gettimeofday(&now, NULL); if ((now.tv_sec > tnext.tv_sec) || ((now.tv_sec == tnext.tv_sec) && (now.tv_usec >= tnext.tv_usec))) { tnext = now; tnext.tv_sec++; tleft.tv_sec = 1; tleft.tv_usec = 0; printf("\r%-71s%c%-7s", s1, *trailcp, ""); fflush(stdout); if (*++trailcp == '\0') trailcp = trail; } else { TimeValSubtract(&tleft, &tnext, &now); } } ntoread = (gNBufAllocated - gNBufUsed - 1); nread = read(fd, gBuf + gNBufUsed, ntoread); if (nread < 0) { if (errno == EINTR) continue; perror("ccdv: read"); return (-1); } else if (nread == 0) { break; } gNBufUsed += nread; gBuf[gNBufUsed] = '\0'; } snprintf(s1, sizeof(s1), "%s%s%s: ", gAction, gTarget[0] ? " " : "", gTarget); Wait(); if (gExitStatus == 0) { printf("\r%-70s", s1); printf("[%s%s%s]", ((gNBufUsed - strlen(gArgsStr)) < 4) ? SETCOLOR_SUCCESS : SETCOLOR_WARNING, "OK", SETCOLOR_NORMAL); printf("%-5s\n", " "); } else { printf("\r%-70s", s1); printf("[%s%s%s]", SETCOLOR_FAILURE, "ERROR", SETCOLOR_NORMAL); printf("%-2s\n", " "); gDumpCmdArgs = 1; /* print cmd when there are errors */ } fflush(stdout); return (0); } /* SlurpProgress */ static int SlurpAll(int fd) { char *newbuf; size_t ntoread; ssize_t nread; printf("%s%s%s.\n", gAction, gTarget[0] ? " " : "", gTarget); fflush(stdout); for(;;) { if (gNBufUsed == (gNBufAllocated - 1)) { if ((newbuf = (char *) realloc(gBuf, gNBufAllocated + TEXT_BLOCK_SIZE)) == NULL) { perror("ccdv: realloc"); return (-1); } gNBufAllocated += TEXT_BLOCK_SIZE; gBuf = newbuf; } ntoread = (gNBufAllocated - gNBufUsed - 1); nread = read(fd, gBuf + gNBufUsed, ntoread); if (nread < 0) { if (errno == EINTR) continue; perror("ccdv: read"); return (-1); } else if (nread == 0) { break; } gNBufUsed += nread; gBuf[gNBufUsed] = '\0'; } Wait(); gDumpCmdArgs = (gExitStatus != 0); /* print cmd when there are errors */ return (0); } /* SlurpAll */ static const char *Basename(const char *path) { const char *cp; cp = strrchr(path, '/'); if (cp == NULL) return (path); return (cp + 1); } /* Basename */ static const char * Extension(const char *path) { const char *cp = path; cp = strrchr(path, '.'); if (cp == NULL) return (""); // printf("Extension='%s'\n", cp); return (cp); } /* Extension */ static void Usage(void) { fprintf(stderr, "Usage: ccdv /path/to/cc CFLAGS...\n\n"); fprintf(stderr, "I wrote this to reduce the deluge Make output to make finding actual problems\n"); fprintf(stderr, "easier. It is intended to be invoked from Makefiles, like this. Instead of:\n\n"); fprintf(stderr, "\t.c.o:\n"); fprintf(stderr, "\t\t$(CC) $(CFLAGS) $(DEFS) $(CPPFLAGS) $< -c\n"); fprintf(stderr, "\nRewrite your rule so it looks like:\n\n"); fprintf(stderr, "\t.c.o:\n"); fprintf(stderr, "\t\t@ccdv $(CC) $(CFLAGS) $(DEFS) $(CPPFLAGS) $< -c\n\n"); fprintf(stderr, "ccdv 1.1.0 is Free under the GNU Public License. Enjoy!\n"); fprintf(stderr, " -- Mike Gleason, NcFTP Software \n"); exit(96); } /* Usage */ int main(int argc, char **argv) { int pipe1[2]; int devnull; char emerg[256]; int fd; int nread; int i; int cc = 0, pch = 0; const char *quote; if (argc < 2) Usage(); snprintf(gAction, sizeof(gAction), "Running %s", Basename(argv[1])); memset(gArgsStr, 0, sizeof(gArgsStr)); for (i = 1; i < argc; i++) { // printf("argv[%d]='%s'\n", i, argv[i]); quote = (strchr(argv[i], ' ') != NULL) ? "\"" : ""; snprintf(gArgsStr + strlen(gArgsStr), sizeof(gArgsStr) - strlen(gArgsStr), "%s%s%s%s%s", (i == 1) ? "" : " ", quote, argv[i], quote, (i == (argc - 1)) ? "\n" : ""); if ((strcmp(argv[i], "-o") == 0) && ((i + 1) < argc)) { if (strcasecmp(Extension(argv[i + 1]), ".o") != 0) { strcpy(gAction, "Linking"); snprintf(gTarget, sizeof(gTarget), "%s", Basename(argv[i + 1])); } } else if (strchr("-+", (int) argv[i][0]) != NULL) { continue; } else if (strncasecmp(Extension(argv[i]), ".c", 2) == 0) { cc++; snprintf(gTarget, sizeof(gTarget), "%s", Basename(argv[i])); // printf("gTarget='%s'\n", gTarget); } else if ((strncasecmp(Extension(argv[i]), ".h", 2) == 0) && (cc == 0)) { pch++; snprintf(gTarget, sizeof(gTarget), "%s", Basename(argv[i])); } else if ((i == 1) && (strcmp(Basename(argv[i]), "ar") == 0)) { snprintf(gAr, sizeof(gAr), "%s", Basename(argv[i])); } else if ((gArLibraryTarget[0] == '\0') && (strcasecmp(Extension(argv[i]), ".a") == 0)) { snprintf(gArLibraryTarget, sizeof(gArLibraryTarget), "%s", Basename(argv[i])); } } if ((gAr[0] != '\0') && (gArLibraryTarget[0] != '\0')) { strcpy(gAction, "Creating library"); snprintf(gTarget, sizeof(gTarget), "%s", gArLibraryTarget); } else if (pch > 0) { strcpy(gAction, "Precompiling"); } else if (cc > 0) { strcpy(gAction, "Compiling"); } if (pipe(pipe1) < 0) { perror("ccdv: pipe"); exit(97); } (void) close(0); devnull = open("/dev/null", O_RDWR, 00666); if ((devnull != 0) && (dup2(devnull, 0) == 0)) close(devnull); gCCPID = (int) fork(); if (gCCPID < 0) { (void) close(pipe1[0]); (void) close(pipe1[1]); perror("ccdv: fork"); exit(98); } else if (gCCPID == 0) { /* Child */ (void) close(pipe1[0]); /* close read end */ if (pipe1[1] != 1) { /* use write end on stdout */ (void) dup2(pipe1[1], 1); (void) close(pipe1[1]); } (void) dup2(1, 2); /* use write end on stderr */ execvp(argv[1], argv + 1); perror(argv[1]); exit(99); } /* parent */ (void) close(pipe1[1]); /* close write end */ fd = pipe1[0]; /* use read end */ gColumns = (getenv("COLUMNS") != NULL) ? atoi(getenv("COLUMNS")) : 80; gANSIEscapes = (getenv("TERM") != NULL) && (strstr(TERMS, getenv("TERM")) != NULL); gBuf = (char *) malloc(TEXT_BLOCK_SIZE); if (gBuf == NULL) goto panic; gNBufUsed = 0; gNBufAllocated = TEXT_BLOCK_SIZE; if (strlen(gArgsStr) < (gNBufAllocated - 1)) { strcpy(gBuf, gArgsStr); gNBufUsed = strlen(gArgsStr); } if (isatty(1)) { if (SlurpProgress(fd) < 0) goto panic; } else { if (SlurpAll(fd) < 0) goto panic; } DumpFormattedOutput(); exit(gExitStatus); panic: gDumpCmdArgs = 1; /* print cmd when there are errors */ DumpFormattedOutput(); while ((nread = read(fd, emerg, (size_t) sizeof(emerg))) > 0) (void) write(2, emerg, (size_t) nread); Wait(); exit(gExitStatus); } /* main */ pcmciautils-018/config/000077500000000000000000000000001155177104400151535ustar00rootroot00000000000000pcmciautils-018/config/config.opts000066400000000000000000000021351155177104400173300ustar00rootroot00000000000000# # Local PCMCIA Configuration File # #---------------------------------------------------------------------- # # System resources available for PCMCIA cards # # NOTE: these settings have no effect on resources assigned to a # CardBus bridge device itself; this file only affects resources # assigned to cards. Also, interrupt settings here will only affect # ISA bus interrupts assigned to 16-bit cards. PCI interrupts # generally can't be reconfigured. # # With the kernel PCMCIA subsystem, these settings also have no effect # at all on resources used for 32-bit CardBus cards. Those are set by # the PCI hotplug subsystem. # include port 0x100-0x3af include port 0x3e0-0x4ff include port 0x820-0x8ff include port 0xc00-0xcf7 include memory 0xc0000-0xfffff include memory 0xa0000000-0xa0ffffff include memory 0x60000000-0x60ffffff # These may hurt on FSC. # include port 0x3c0-0x3d2 # Exclude 0x3d3 as Radeon IGP MCE's if you touch these ports # include port 0x3d4-0x3df # High port numbers do not always work... # include port 0x1000-0x17ff # Extra port range for IBM Token Ring include port 0xa00-0xaff pcmciautils-018/config/config.opts.hppa000066400000000000000000000021011155177104400202500ustar00rootroot00000000000000# # Local PCMCIA Configuration File # #---------------------------------------------------------------------- # # System resources available for PCMCIA cards # # NOTE: these settings have no effect on resources assigned to a # CardBus bridge device itself; this file only affects resources # assigned to cards. Also, interrupt settings here will only affect # ISA bus interrupts assigned to 16-bit cards. PCI interrupts # generally can't be reconfigured. # # With the kernel PCMCIA subsystem, these settings also have no effect # at all on resources used for 32-bit CardBus cards. Those are set by # the PCI hotplug subsystem. # # Allow all the dino/cujo port ranges (usually we get the first one) # NOTE: the address range for this is a signed short (hence the upper # limit is 0x7fff). If the PCMCIA card isn't on the dino/cujo bus # which has been assigned this range, you're out of luck. In # particular, PCMCIA won't work in a box with an EISA subsystem # because that claims 0-0xffff. include port 0x0-0x7fff # Allow all parisc I/O space include memory 0xf0000000-0xffffffff pcmciautils-018/config/config.opts.ppc000066400000000000000000000013221155177104400201060ustar00rootroot00000000000000# # Local PCMCIA Configuration File # #---------------------------------------------------------------------- # # System resources available for PCMCIA cards # # NOTE: these settings have no effect on resources assigned to a # CardBus bridge device itself; this file only affects resources # assigned to cards. Also, interrupt settings here will only affect # ISA bus interrupts assigned to 16-bit cards. PCI interrupts # generally can't be reconfigured. # # With the kernel PCMCIA subsystem, these settings also have no effect # at all on resources used for 32-bit CardBus cards. Those are set by # the PCI hotplug subsystem. # include port 0x100-0x4ff include port 0x1000-0x17ff include memory 0x80000000-0x80ffffff pcmciautils-018/debug/000077500000000000000000000000001155177104400147745ustar00rootroot00000000000000pcmciautils-018/debug/cbdump.c000066400000000000000000000147541155177104400164250ustar00rootroot00000000000000/* * cbdump.c - dump cardbus bridge registers * * Copyright (C) 2003 Russell King. * * 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. * * Build instructions: * * gcc -O2 -o cbdump cbdump.c -lpci */ #include #include #include #include #include struct dump_data { const char *name; unsigned char offset; unsigned char size; }; static void __dump_memory(void *mem, const struct dump_data *d, int num) { int i; for (i = 0; i < num; i++, d++) { u32 val = 0xa5a5a5a5; void *p = (void *) ((unsigned long) mem + d->offset); switch (d->size) { case 1: val = *(u8 *)p; break; case 2: val = *(u16 *)p; break; case 4: val = *(u32 *)p; break; } printf(" %-31s[%02x] : 0x%0*x\n", d->name, d->offset, d->size * 2, val); } } #define dump_memory(m,d) \ __dump_memory(m,d,sizeof(d)/sizeof(struct dump_data)) static void __dump_config(struct pci_dev *dev, const struct dump_data *d, int num) { int i; for (i = 0; i < num; i++, d++) { u32 val = 0xa5a5a5a5; switch (d->size) { case 1: val = pci_read_byte(dev, d->offset); break; case 2: val = pci_read_word(dev, d->offset); break; case 4: val = pci_read_long(dev, d->offset); break; } printf(" %-31s[%02x] : 0x%0*x\n", d->name, d->offset, d->size * 2, val); } } #define dump_config(m,d) \ __dump_config(m,d,sizeof(d)/sizeof(struct dump_data)) static const struct dump_data cb_data[] = { { "CB_SOCKET_EVENT", 0x00, 4 }, { "CB_SOCKET_MASK", 0x04, 4 }, { "CB_SOCKET_STATE", 0x08, 4 }, { "CB_SOCKET_FORCE", 0x0c, 4 }, { "CB_SOCKET_CONTROL", 0x10, 4 }, { "CB_SOCKET_POWER", 0x20, 4 }, }; static void dump_cb(void *mem) { printf(" -- cardbus registers\n"); dump_memory(mem, cb_data); } static const struct dump_data exca_data[] = { { "I365_IDENT", 0x00, 1 }, { "I365_STATUS", 0x01, 1 }, { "I365_POWER", 0x02, 1 }, { "I365_INTCTL", 0x03, 1 }, { "I365_CSC", 0x04, 1 }, { "I365_CSCINT", 0x05, 1 }, { "I365_ADDRWIN", 0x06, 1 }, { "I365_IOCTL", 0x07, 1 }, { "I365_GENCTL", 0x16, 2 }, { "I365_GBLCTL", 0x1e, 2 }, { "I365_IO0_START", 0x08, 2 }, { "I365_IO0_STOP", 0x0a, 2 }, { "I365_IO1_START", 0x0c, 2 }, { "I365_IO1_STOP", 0x0e, 2 }, { "I365_MEM0_START", 0x10, 2 }, { "I365_MEM0_STOP", 0x12, 2 }, { "I365_MEM0_OFF", 0x14, 2 }, { "I365_MEM0_PAGE", 0x40, 1 }, { "I365_MEM1_START", 0x18, 2 }, { "I365_MEM1_STOP", 0x1a, 2 }, { "I365_MEM1_OFF", 0x1c, 2 }, { "I365_MEM1_PAGE", 0x41, 1 }, { "I365_MEM2_START", 0x20, 2 }, { "I365_MEM2_STOP", 0x22, 2 }, { "I365_MEM2_OFF", 0x24, 2 }, { "I365_MEM2_PAGE", 0x42, 1 }, { "I365_MEM3_START", 0x28, 2 }, { "I365_MEM3_STOP", 0x2a, 2 }, { "I365_MEM3_OFF", 0x2c, 2 }, { "I365_MEM3_PAGE", 0x43, 1 }, { "I365_MEM4_START", 0x30, 2 }, { "I365_MEM4_STOP", 0x32, 2 }, { "I365_MEM4_OFF", 0x34, 2 }, { "I365_MEM4_PAGE", 0x44, 1 }, }; static void dump_exca(void *mem) { printf(" -- exca registers\n"); dump_memory((void *) ((unsigned long) mem + 0x800), exca_data); } static void dump_memspace(struct pci_dev *dev, u32 mem) { void *base; int fd; fd = open("/dev/mem", O_RDONLY); if (fd == -1) { perror("open /dev/mem"); return; } base = mmap(NULL, 4096, PROT_READ, MAP_SHARED|MAP_FILE, fd, mem); if (base == (void *)-1) { perror("mmap /dev/mem"); close(fd); return; } close(fd); dump_cb(base); dump_exca(base); munmap(base, 4096); } static struct dump_data cb_general_data[] = { { "Vendor ID", PCI_VENDOR_ID, 2 }, { "Device ID", PCI_DEVICE_ID, 2 }, { "PCI command", PCI_COMMAND, 2 }, { "Base address", PCI_BASE_ADDRESS_0, 4 }, { "Memory Base 0", PCI_CB_MEMORY_BASE_0, 4 }, { "Memory Limit 0", PCI_CB_MEMORY_LIMIT_0, 4 }, { "Memory Base 1", PCI_CB_MEMORY_BASE_1, 4 }, { "Memory Limit 1", PCI_CB_MEMORY_LIMIT_1, 4 }, { "IO Base 0", PCI_CB_IO_BASE_0, 4 }, { "IO Limit 0", PCI_CB_IO_LIMIT_0, 4 }, { "IO Base 1", PCI_CB_IO_BASE_1, 4 }, { "IO Limit 1", PCI_CB_IO_LIMIT_1, 4 }, { "Bridge control", PCI_CB_BRIDGE_CONTROL, 2 }, { "Subsystem vendor ID", PCI_CB_SUBSYSTEM_VENDOR_ID, 2 }, { "Subsystem device ID", PCI_CB_SUBSYSTEM_ID, 2 }, { "Legacy mode base", PCI_CB_LEGACY_MODE_BASE, 2 }, }; static const struct dump_data ti_data[] = { { "System control", 0x80, 4 }, { "IRQ Mux", 0x8c, 4 }, { "Retry", 0x90, 1 }, { "Card control", 0x91, 1 }, { "Device control", 0x92, 1 }, { "Diagnostic", 0x93, 1 }, }; static const struct dump_data rl5c475_data[] = { { "System configuration", 0x80, 2 }, { "Misc Control", 0x82, 2 }, { "16-bit Interface Control", 0x84, 2 }, { "16-bit I/O Timing 0", 0x88, 2 }, { "16-bit Memory Timing 0", 0x8a, 2 }, { "DMA Slave", 0x90, 2 }, }; static const struct dump_data rl5c476II_data[] = { { "Misc Control 2", 0xa0, 2 }, { "Misc Control 3", 0xa2, 2 }, { "Misc Control 4", 0xa4, 2 }, { "GPIO 1", 0xaa, 1 }, }; static void dump_cardbus(struct pci_dev *dev) { char class[256]; char name[256]; u32 base; printf("%02x:%02x.%x %s: %s\n", dev->bus, dev->dev, dev->func, pci_lookup_name(dev->access, class, sizeof(class), PCI_LOOKUP_CLASS, pci_read_word(dev, PCI_CLASS_DEVICE), 0, 0, 0), pci_lookup_name(dev->access, name, sizeof(name), PCI_LOOKUP_VENDOR | PCI_LOOKUP_DEVICE, dev->vendor_id, dev->device_id, 0, 0)); base = pci_read_long(dev, PCI_BASE_ADDRESS_0); printf(" -- generic cardbus config registers\n"); dump_config(dev, cb_general_data); if (dev->vendor_id == 0x104c) { /* TI */ printf(" -- TI specific config registers\n"); dump_config(dev, ti_data); } if ((dev->vendor_id == 0x1180) && (dev->device_id == 0x0475)) { /* Ricoh RL5c475 */ printf(" -- Ricoh RL5c475 specific config registers\n"); dump_config(dev, rl5c475_data); } if ((dev->vendor_id == 0x1180) && (dev->device_id == 0x0476)) { /* Ricoh RL5c476II */ printf(" -- Ricoh RL5c476II specific config registers\n"); dump_config(dev, rl5c475_data); dump_config(dev, rl5c476II_data); } dump_memspace(dev, base); printf("\n"); } int main(int argc, char *argv[]) { struct pci_access *pa; struct pci_dev *dev; pa = pci_alloc(); if (!pa) { perror("pci_alloc"); return 1; } pa->writeable = 0; pa->buscentric = 0; pci_init(pa); pci_scan_bus(pa); for (dev = pa->devices; dev; dev = dev->next) { unsigned int header; header = pci_read_word(dev, PCI_HEADER_TYPE); header &= ~0x80; if (header == PCI_HEADER_TYPE_CARDBUS) dump_cardbus(dev); } pci_cleanup(pa); return 0; } pcmciautils-018/debug/dump_cis.c000066400000000000000000000602001155177104400167410ustar00rootroot00000000000000/* * cistpl.c -- 16-bit PCMCIA Card Information Structure parser * * 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 * . Portions created by David A. Hinds * are Copyright (C) 1999 David A. Hinds. All Rights Reserved. * * (C) 1999 David A. Hinds */ #include #include #include #include #include "../src/cistpl.h" #define MAX_SOCKETS 8 static int verbose = 1; static void print_tuple(tuple_t *tup) { int i; printf("offset 0x%2.2x, tuple 0x%2.2x, link 0x%2.2x\n", tup->CISOffset, tup->TupleCode, tup->TupleLink); for (i = 0; i < tup->TupleDataLen; i++) { if (!(i % 16)) printf(" "); printf("%2.2x ", (unsigned char) tup->TupleData[i]); if ((i % 16) == 15) printf("\n"); } if ((i % 16) != 0) putchar('\n'); } #define IRQ_INFO2_VALID 0x10 #define IRQ_MASK 0x0f #define IRQ_LEVEL_ID 0x20 #define IRQ_PULSE_ID 0x40 #define IRQ_SHARE_ID 0x80 static void print_funcid(cistpl_funcid_t *fn) { printf("funcid "); 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) { unsigned 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 ", dtype[dev->dev[i].type]); printf("%uns, ", dev->dev[i].speed); print_size(dev->dev[i].size); putchar('\n'); } if (dev->ndev == 0) printf(" no_info\n"); } static void print_power(char *tag, cistpl_power_t *power) { int i, n; for (i = n = 0; i < 8; i++) if (power->present & (1<present & (1<param[CISTPL_POWER_VNOM]); } if (power->present & (1<param[CISTPL_POWER_VMIN]); } if (power->present & (1<param[CISTPL_POWER_VMAX]); } if (power->present & (1<param[CISTPL_POWER_ISTATIC]); } if (power->present & (1<param[CISTPL_POWER_IAVG]); } if (power->present & (1<param[CISTPL_POWER_IPEAK]); } if (power->present & (1<param[CISTPL_POWER_IDOWN]); } if (power->flags & CISTPL_POWER_HIGHZ_OK) { if (++i == 5) printf("\n"); 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("cftable_entry 0x%2.2x%s\n", entry->index, (entry->flags & CISTPL_CFTABLE_DEFAULT) ? " [default]" : ""); if (entry->flags & ~CISTPL_CFTABLE_DEFAULT) { 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(" timing"); 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(" io"); 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(" irq "); 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(" memory"); 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(" %d bytes in subtuples\n", entry->subtuples); } /*====================================================================*/ static void print_cftable_entry_cb(cistpl_cftable_entry_cb_t *entry) { int i; printf("cftable_entry_cb 0x%2.2x%s\n", entry->index, (entry->flags & CISTPL_CFTABLE_DEFAULT) ? " [default]" : ""); if (entry->flags & ~CISTPL_CFTABLE_DEFAULT) { printf(" "); 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(" io_base"); for (i = 0; i < 8; i++) if (entry->io & (1<irq.IRQInfo1) { printf(" irq "); 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(" mem_base"); for (i = 0; i < 8; i++) if (entry->mem & (1<subtuples) printf(" %d bytes in subtuples\n", 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(" width %d erase 0x%x read 0x%x write 0x%x " "partition 0x%x interleave 0x%x\n", 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("data_org "); 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("serial_interface"); 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 uart %s", (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<uart_cap_0 >= (2<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<= (2<= (2<data); printf("serial_modem_cap"); 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 flow"); for (i = 0; i < 5; i++) if (cp->flow & (1<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("serial_data_services\n"); printf(" data_rate %d\n", 75*((ds->max_data_0<<8) + ds->max_data_1)); printf(" modulation"); for (i = j = 0; i < 16; i++) if (((ds->modulation_1<<8) + ds->modulation_0) & (1<error_control) { printf(" error_control"); 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(" compression"); 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(" cmd_protocol"); for (i = 0; i < 7; i++) if (ds->cmd_protocol & (1<data); printf("serial_fax_services [class=%d]\n", funce->type>>4); printf(" data_rate %d\n", 75*((fs->max_data_0<<8) + fs->max_data_1)); printf(" modulation"); for (i = 0; i < 8; i++) if (fs->modulation & (1<features_0) { printf(" features"); for (i = 0; i < 8; i++) if (fs->features_0 & (1<type) { case CISTPL_FUNCE_IDE_IFACE: i = (cistpl_ide_interface_t *)(funce->data); printf("disk_interface "); 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("disk_features"); 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 "); 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("lan_technology %s\n", tech[t->tech]); break; case CISTPL_FUNCE_LAN_SPEED: s = (cistpl_lan_speed_t *)(funce->data); printf("lan_speed "); print_speed(s->speed); putchar('\n'); break; case CISTPL_FUNCE_LAN_MEDIA: m = (cistpl_lan_media_t *)(funce->data); printf("lan_media %s\n", media[m->media]); break; case CISTPL_FUNCE_LAN_NODE_ID: n = (cistpl_lan_node_id_t *)(funce->data); printf("lan_node_id"); 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("lan_connector "); 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, "vers_1 %d.%d", 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 += 2; printf(",\n "); } 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("version 0x%2.2x, compliance 0x%2.2x, dindex 0x%4.4x\n", v2->vers, v2->comply, v2->dindex); printf(" vspec8 0x%2.2x, vspec9 0x%2.2x, nhdr %d\n", v2->vspec8, v2->vspec9, v2->nhdr); printf(" vendor \"%s\"\n", v2->str+v2->vendor); printf(" info \"%s\"\n", v2->str+v2->info); } static void print_format(cistpl_format_t *fmt) { if (fmt->type == CISTPL_FORMAT_DISK) printf(" [disk]"); else if (fmt->type == CISTPL_FORMAT_MEM) printf(" [memory]"); else printf(" [type 0x%02x]\n", 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'); } static void print_config(int code, cistpl_config_t *cfg) { printf("config%s base 0x%4.4x", (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(" %d bytes in subtuples\n", cfg->subtuples); } static int nfn = 0, cur = 0; static void print_parse(tuple_t *tuple, cisparse_t *parse) { static int func = 0; int i; switch (tuple->TupleCode) { case CISTPL_DEVICE: case CISTPL_DEVICE_A: if (tuple->TupleCode == CISTPL_DEVICE) printf("dev_info\n"); else printf("attr_dev_info\n"); print_device(&parse->device); break; case CISTPL_CHECKSUM: printf("checksum 0x%04x-0x%04x = 0x%02x\n", parse->checksum.addr, parse->checksum.addr+parse->checksum.len-1, parse->checksum.sum); break; case CISTPL_LONGLINK_A: if (verbose) printf("long_link_attr 0x%04x\n", parse->longlink.addr); break; case CISTPL_LONGLINK_C: if (verbose) printf("long_link 0x%04x\n", parse->longlink.addr); break; case CISTPL_LONGLINK_MFC: if (verbose) { printf("mfc_long_link\n"); for (i = 0; i < parse->longlink_mfc.nfn; i++) printf(" function %d: %s 0x%04x\n", i, parse->longlink_mfc.fn[i].space ? "common" : "attr", parse->longlink_mfc.fn[i].addr); } else { printf("mfc {\n"); nfn = parse->longlink_mfc.nfn; cur = 0; } break; case CISTPL_NO_LINK: if (verbose) printf("no_long_link\n"); break; case CISTPL_INDIRECT: if (verbose) printf("indirect_access\n"); break; case CISTPL_LINKTARGET: if (verbose) printf("link_target\n"); else { if (cur++) printf("}, {\n"); } break; case CISTPL_VERS_1: print_vers_1(&parse->version_1); break; case CISTPL_ALTSTR: break; case CISTPL_JEDEC_A: case CISTPL_JEDEC_C: if (tuple->TupleCode == CISTPL_JEDEC_C) printf("common_jedec"); else printf("attr_jedec"); print_jedec(&parse->jedec); break; case CISTPL_DEVICE_GEO: case CISTPL_DEVICE_GEO_A: if (tuple->TupleCode == CISTPL_DEVICE_GEO) printf("common_geometry\n"); else printf("attr_geometry\n"); print_device_geo(&parse->device_geo); break; case CISTPL_MANFID: printf("manfid 0x%4.4x, 0x%4.4x\n", parse->manfid.manf, parse->manfid.card); break; case CISTPL_FUNCID: print_funcid(&parse->funcid); func = parse->funcid.func; break; case CISTPL_FUNCE: switch (func) { case CISTPL_FUNCID_SERIAL: print_serial(&parse->funce); break; case CISTPL_FUNCID_FIXED: print_fixed(&parse->funce); break; case CISTPL_FUNCID_NETWORK: print_network(&parse->funce); break; } break; case CISTPL_BAR: printf("BAR %d size ", parse->bar.attr & CISTPL_BAR_SPACE); print_size(parse->bar.size); if (parse->bar.attr & CISTPL_BAR_SPACE_IO) printf(" [io]"); else printf(" [mem]"); if (parse->bar.attr & CISTPL_BAR_PREFETCH) printf(" [prefetch]"); if (parse->bar.attr & CISTPL_BAR_CACHEABLE) printf(" [cacheable]"); if (parse->bar.attr & CISTPL_BAR_1MEG_MAP) printf(" [<1mb]"); putchar('\n'); break; case CISTPL_CONFIG: case CISTPL_CONFIG_CB: print_config(tuple->TupleCode, &parse->config); break; case CISTPL_CFTABLE_ENTRY: print_cftable_entry(&parse->cftable_entry); break; case CISTPL_CFTABLE_ENTRY_CB: print_cftable_entry_cb(&parse->cftable_entry_cb); break; case CISTPL_VERS_2: print_vers_2(&parse->vers_2); break; case CISTPL_ORG: print_org(&parse->org); break; case CISTPL_FORMAT: case CISTPL_FORMAT_A: if (tuple->TupleCode == CISTPL_FORMAT) printf("common_format\n"); else printf("attr_format\n"); print_format(&parse->format); } } static int parse_cis_one_socket(unsigned int socket_no, FILE *fd) { int ret = 0; tuple_t tuple; unsigned char buf[256]; cisparse_t parse; memset(&tuple, 0, sizeof(tuple_t)); ret = read_out_cis(socket_no, fd); if (ret) return (ret); printf("Socket %u\n", socket_no); tuple.Attributes = TUPLE_RETURN_LINK | TUPLE_RETURN_COMMON; tuple.DesiredTuple = RETURN_FIRST_TUPLE; ret = pcmcia_get_first_tuple(BIND_FN_ALL, &tuple); if (ret) return (ret); while(tuple.TupleCode != CISTPL_END) { tuple.TupleData = buf; tuple.TupleOffset = 0; tuple.TupleDataMax = 255; pcmcia_get_tuple_data(&tuple); if (verbose) print_tuple(&tuple); ret = pccard_parse_tuple(&tuple, &parse); if (ret) printf("invalid tuple\n"); else { print_parse(&tuple, &parse); printf("\n"); } ret = pcmcia_get_next_tuple(BIND_FN_ALL, &tuple); if (ret) break; } return (ret); } int main(int argc, char** argv) { unsigned int socket_no = MAX_SOCKETS; int ret = -ENODEV, i; FILE *fd = NULL; if (argc == 2) { ret = sscanf(argv[1], "%u", &socket_no); if (ret != 1) socket_no = MAX_SOCKETS; } else if (argc == 3) { if (!strncmp("-f", argv[1], 2)) { if (!strncmp("-", argv[2], 1)) fd = stdin; else fd = fopen(argv[2], "r"); if (!fd) return -EINVAL; return parse_cis_one_socket(MAX_SOCKETS + 1, fd); } } if ((socket_no != MAX_SOCKETS) || fd) { return parse_cis_one_socket(socket_no, fd); } else { for (i=0; i. Portions created by David A. Hinds * are Copyright (C) 1999 David A. Hinds. All Rights Reserved. * * (C) 1999 David A. Hinds */ /* Parsing routines for individual tuples */ #include #include #include #include #include #include #include "../src/cistpl.h" #define IRQ_INFO2_VALID 0x10 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]) #if __BYTE_ORDER == __BIG_ENDIAN # define le32_to_cpu(value) bswap_32(value) # define le16_to_cpu(value) bswap_16(value) #else # define le32_to_cpu(value) (value) # define le16_to_cpu(value) (value) #endif 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 -EINVAL; device->dev[i].speed = SPEED_CVT(*p); while (*p & 0x80) if (++p == q) return -EINVAL; break; default: return -EINVAL; } if (++p == q) return -EINVAL; if (*p == 0xff) break; scale = *p & 7; if (scale == 7) return -EINVAL; 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 -EINVAL; p = (u_char *)tuple->TupleData; csum->addr = tuple->CISOffset+(short)le16_to_cpu(*(u_short *)p)-2; csum->len = le16_to_cpu(*(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 -EINVAL; link->addr = le32_to_cpu(*(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 -EINVAL; for (i = 0; i < link->nfn; i++) { link->fn[i].space = *p; p++; link->fn[i].addr = le32_to_cpu(*(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 -EINVAL; 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 -EINVAL; } if ((*p == 0xff) || (++p == q)) break; } if (found) { *found = ns; return 0; } else { return (ns == max) ? 0 : -EINVAL; } } /*====================================================================*/ 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 -EINVAL; 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 -EINVAL; p = (u_short *)tuple->TupleData; m->manf = le16_to_cpu(p[0]); m->card = le16_to_cpu(p[1]); return 0; } /*====================================================================*/ static int parse_funcid(tuple_t *tuple, cistpl_funcid_t *f) { u_char *p; if (tuple->TupleDataLen < 2) return -EINVAL; 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 -EINVAL; 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 -EINVAL; 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<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 -EINVAL; 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 -EINVAL; features = *p; p++; /* Power options */ if ((features & 3) > 0) { p = parse_power(p, q, &entry->vcc); if (p == NULL) return -EINVAL; } else entry->vcc.present = 0; if ((features & 3) > 1) { p = parse_power(p, q, &entry->vpp1); if (p == NULL) return -EINVAL; } else entry->vpp1.present = 0; if ((features & 3) > 2) { p = parse_power(p, q, &entry->vpp2); if (p == NULL) return -EINVAL; } else entry->vpp2.present = 0; /* Timing options */ if (features & 0x04) { p = parse_timing(p, q, &entry->timing); if (p == NULL) return -EINVAL; } 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 -EINVAL; } else entry->io.nwin = 0; /* Interrupt options */ if (features & 0x10) { p = parse_irq(p, q, &entry->irq); if (p == NULL) return -EINVAL; } 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 = le16_to_cpu(*(u_short *)p) << 8; entry->mem.win[0].card_addr = 0; entry->mem.win[0].host_addr = 0; p += 2; if (p > q) return -EINVAL; break; case 0x40: entry->mem.nwin = 1; entry->mem.win[0].len = le16_to_cpu(*(u_short *)p) << 8; entry->mem.win[0].card_addr = le16_to_cpu(*(u_short *)(p+2)) << 8; entry->mem.win[0].host_addr = 0; p += 4; if (p > q) return -EINVAL; break; case 0x60: p = parse_mem(p, q, &entry->mem); if (p == NULL) return -EINVAL; break; } /* Misc features */ if (features & 0x80) { if (p == q) return -EINVAL; entry->flags |= (*p << 8); while (*p & 0x80) if (++p == q) return -EINVAL; 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 -EINVAL; p = (u_char *)tuple->TupleData; bar->attr = *p; p += 2; bar->size = le32_to_cpu(*(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 -EINVAL; config->last_idx = *(++p); p++; config->base = le32_to_cpu(*(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 -EINVAL; features = *p; p++; /* Power options */ if ((features & 3) > 0) { p = parse_power(p, q, &entry->vcc); if (p == NULL) return -EINVAL; } else entry->vcc.present = 0; if ((features & 3) > 1) { p = parse_power(p, q, &entry->vpp1); if (p == NULL) return -EINVAL; } else entry->vpp1.present = 0; if ((features & 3) > 2) { p = parse_power(p, q, &entry->vpp2); if (p == NULL) return -EINVAL; } else entry->vpp2.present = 0; /* I/O window options */ if (features & 0x08) { if (p == q) return -EINVAL; entry->io = *p; p++; } else entry->io = 0; /* Interrupt options */ if (features & 0x10) { p = parse_irq(p, q, &entry->irq); if (p == NULL) return -EINVAL; } else entry->irq.IRQInfo1 = 0; if (features & 0x20) { if (p == q) return -EINVAL; entry->mem = *p; p++; } else entry->mem = 0; /* Misc features */ if (features & 0x80) { if (p == q) return -EINVAL; entry->flags |= (*p << 8); if (*p & 0x80) { if (++p == q) return -EINVAL; entry->flags |= (*p << 16); } while (*p & 0x80) if (++p == q) return -EINVAL; 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 -EINVAL; p = tuple->TupleData; q = p + tuple->TupleDataLen; v2->vers = p[0]; v2->comply = p[1]; v2->dindex = le16_to_cpu(*(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 -EINVAL; org->data_org = *p; if (++p == q) return -EINVAL; for (i = 0; i < 30; i++) { org->desc[i] = *p; if (*p == '\0') break; if (++p == q) return -EINVAL; } return 0; } /*====================================================================*/ static int parse_format(tuple_t *tuple, cistpl_format_t *fmt) { u_char *p; if (tuple->TupleDataLen < 10) return -EINVAL; p = tuple->TupleData; fmt->type = p[0]; fmt->edc = p[1]; fmt->offset = le32_to_cpu(*(u_int *)(p+2)); fmt->length = le32_to_cpu(*(u_int *)(p+6)); return 0; } /*====================================================================*/ int pccard_parse_tuple(tuple_t *tuple, cisparse_t *parse) { int ret = 0; if (tuple->TupleDataLen > tuple->TupleDataMax) return -EINVAL; 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; default: ret = -EINVAL; break; } return ret; } pcmciautils-018/doc/000077500000000000000000000000001155177104400144535ustar00rootroot00000000000000pcmciautils-018/doc/cardmgr-to-pcmciautils.txt000066400000000000000000000134021155177104400215660ustar00rootroot00000000000000PCMCIA: cardmgr to pcmciautils HowTo ==================================== written by Daniel Ritz This howto describes in short how to change your system to work with the new pcmciautils instead of the old cardmgr. Prerequisites ------------- - kernel 2.6.13-rc1 and newer - pcmciautils, preferably 010 or newer - you read the mini-howto.txt Introduction ------------ Kernels since 2.6.13-rc1 do not require the cardmgr daemon anymore. In those newer kernel the pcmcia bus acts almost as any other bus with full /sbin/hotplug support. Old style cardmgr setups should still work if the kernel is configured correctly. But be aware that the ioctl for PCMCIA will be removed in the near future. The change to be /sbin/hotplug capable means that the normal /etc/init.d/pcmcia script is not required any more and in fact only hurts as it starts cardmgr. To use the new pcmciautils it is a requirement that cardmgr is not started. The STARTUP option ------------------ When reading the pcmciautils howto you see that STARTUP option mentioned. What does it do again? It controls the setup of a dynamic resource database needed for some sockets. The resource database tells the PCMCIA layer what IO port and what IO memory are usable for PCMCIA cards. In case the database is dynamic, it needs to be setup before any cards can be used. The /etc/pcmcia/config.opts file contains the neccessary configuration. In old setups it is cardmgr that parses that file and tells the kernel what resources to use. In case of pcmciautils it's the pcmcia-socket-startup tool which is built and installed when the STARTUP option is set. The tool itself is run from the hotplug script pcmcia_socket.agent whenever a new socket is registered with the pcmcia module. This means that pcmcia-socket-startup does not need to be run manually. Compiling and installing pcmciautils ------------------------------------ You should have read the pcmciautils howto already. Again in short: - make a backup copy of your /etc/pcmcia/config.opts - determine whether you need UDEV set or not. if unsure: don't set it - determine whether you need STARTUP set or not - make - make install (as root) - put your original /etc/pcmcia/config.opts back to where it was Stop cardmgr from starting -------------------------- We don't want cardmgr. For setups with a PCI PCMCIA/Cardbus controller the easiest thing to do is to make sure /etc/init.d/pcmcia does nothing. Either make sure it does not start up, or (if you want to use older kernels as well) add the following snippet to the beginning of /etc/init.d/pcmcia (after the #!/bin/sh line of course): KVERREL=`uname -r` KVER=${KVERREL%%-*} KVER_MAJOR=${KVER%.*} KVER_MINOR=${KVER##*.} if [ "$KVER_MAJOR" == "2.6" ]; then # kernel 2.6.13-rc1 and higher have pcmcia via /sbin/hotplug if [ $KVER_MINOR -ge 13 ]; then # uncomment the following line if the driver for your # controller is not auto-loaded. or if you want to be # able to say /etc/init.d/pcmcia stop #/etc/init.d/pcmcia-new $1 exit 0 fi fi this will make sure the init script does nothing for newer kernel and works normally on older kernels. if you have a socket controller where the module cannot be loaded automatically by hotplug, uncomment the line in the above code snipped and make sure you have the /etc/init.d/pcmcia-new script around which should look like this: #!/bin/sh # set this to the driver to use, one of: # yenta_socket, i82365, i82092, pd6729, tcic, etc. DRIVER=yenta_socket DRIVER_OPTS= case "$1" in start) modprobe $DRIVER $DRIVER_OPTS > /dev/null 2>&1 modprobe pcmcia > /dev/null 2>&1 # just in case it's not auto-loaded ;; stop) pccardctl eject MODULES=`lsmod | grep "pcmcia " | awk '{print $4}' | tr , ' '` for i in $MODULES ; do rmmod $i > /dev/null 2>&1 done rmmod pcmcia > /dev/null 2>&1 rmmod $DRIVER > /dev/null 2>&1 rmmod rsrc_nonstatic > /dev/null 2>&1 rmmod pcmcia_core > /dev/null 2>&1 ;; esac ( you can find this script in doc/pcmcia-new.sh ) make sure you set the DRIVER (and maybe DRIVER_OPTS) variable to the right socket driver. If yenta_socket doesn't work look up the config file from your distro. look at the PCIC variable and PCIC_OPTS. - Red Hat (and Conectiva, Mandriva, etc.) have it in /etc/sysconfig/pcmcia - Debian (and probably Ubuntu) has it in /etc/pcmcia.conf - Others: sorry, don't know If you don't know where to find it, you should look at the init script. Maybe it's even in there directly. The file system right for the script should be right as well: chmod 755 /etc/init.d/pcmcia-new Auto-load pcmcia module ----------------------- To have support for 16-bit cards you need the pcmcia module loaded. Since the other modules do not depend on this one it is not loaded automatically. To make sure the pcmcia module is loaded right after pcmcia_core, add the following line to /etc/modprobe.conf install pcmcia_core /sbin/modprobe --ignore-install pcmcia_core; /sbin/modprobe pcmcia Hotplug ------- Make sure hotplug works correctly. Most distros have a /etc/init.d/hotplug script which should be loaded at boot time. For most laptops the the socket driver is yenta_socket. If it is not loaded after boot it means that hotplug is not working correctly. Reasons for the driver not loaded include the /etc/hotplub/blacklist file or some other list that prevents the driver being loaded. eg. Conectiva Linux 10 does not load PCI modules per default, but only modules that are listed in /etc/hotplug/pci.whitelist. If your socket driver can be loaded via hotplug (PCI socket or detected by PnP or whatever) and everything is ok, yenta_socket (or another socket driver), pcmcia, pcmcia_core and rsrc_nonstatic (not for all socket drivers) should be loaded after booting. Modules for inserted pcmcia cards should be loaded as well. pcmciautils-018/doc/mini-howto.txt000066400000000000000000000161121155177104400173070ustar00rootroot00000000000000Linux Kernel 2.6 PCMCIA - mini-HOWTO ==================================== Last update: 08 November 2005. Table of contents: * [1]Introduction * [2]Setup + [3]Determine the socket driver to use + [4]Resource database + [5]Dependencies + [6]Install pcmciautils + [7]The difficult cases: CIS overrides * [8]Usage 1. Introduction --------------- So, you'd like to get PCMCIA working on Linux kernel 2.6.13-rc1 or later? This short document intends to help you doing so; for additional questions please search the web, especially the help forums of your distribution, or ask on the [9]Linux-PCMCIA mailinglist. Also, the help texts in the Linux kernel configuration for the PCMCIA subsystem might point you into the correct direction -- so please read them. 2. Setup -------- Fortunately, several distributions have already included up-to-date pcmciautils and PCMCIA support into their products. Therefore, you may be able to rely on your distribution to set up the system correctly. 2.1. Determine the socket driver to use --------------------------------------- At first, you need to determine which PCMCIA socket driver you need to use. On most modern notebooks, this is yenta-socket. Else, check the kernel configuration menu for the appropriate driver. Then, make sure it is either built into the kernel, or it is loaded during bootup. Previously, this was oftern handled by the pcmcia-cs startup script. As you won't use this package any longer, you can't rely on it any more to load the socket driver! 2.2. Resource database? ----------------------- Then, you need to find out whether you need a resource database. This contains the ioport and iomem region which PCMCIA cards may use. Fortunately, less and less systems require setting such a database up. 2.2.1. The lucky ones --------------------- Sockets which are governed by these drivers do not need a resource database: * hd64465 * Au1x00 * SA1100 * SA1111 * PXA2xx * M32R_PCC * M32R_CFC * VRC4171 * VRC4173 2.2.2. The unlucky ones ----------------------- These sockets always need a resource database: * i82365 * tcic 2.2.3. The complicated ones --------------------------- For the remaining socket drivers, * yenta-socket * pd6729 * i82092 you need to investigate a bit further. However, if you think that this is too complicated for you, just try it out without a resource database. If it doesn't work, you can still add the resource database later on. First you need to know if the system is of the x86 or x86_64 architecture. If you don't know what this means, check wheter you have an apple printed on the backside of your notebook -- then the answer is no, else it is most probably yes. 2.2.3.1. x86 and x86_64 architectures ------------------------------------- Now you need to determine the PCI bus the device is on: search for the device using the lspci command. Then you'll see a number like 0000:02:03.0 in front of the device. If the second "block" (which is 02 in this example), is zero, you need a resource database, if it is not zero, you do not need it. 2.2.3.2. other architectures ---------------------------- On other architectures (including ppc and ppc64) you do not need a resource database for such sockets. 2.3. Dependencies ----------------- To use any of the PCMCIAutils tools, you need sysfsutils 1.3.0 or newer. However, if you do not need a resource database, you do not run a modular kernel and you are lucky, you might not need any userspace tools at all. If you use a modular kernel, you also need module-init-tools 3.2-pre4 or later. In addition, you either need the basic hotplug scripts installed, or a working udev environment. 2.4. Installing pcmciautils --------------------------- Get the latest revision of pcmciautils. Then, you need to configure it. Therefore, open the file "Makefile" with an editor of your choice, and modify it accordingly: If you do not need a resource database, modify the line which starts with STARTUP to read STARTUP = false If you want to use udev instead of hotplug to manage the activation of pcmciautils, modify the line which starts with UDEV to read UDEV = true Issue the famous make command next. Then, if you already had PCMCIA running well, make a backup copy of /etc/pcmcia/config.opts. Then issue make install. If you need a resource database, you should use the version of /etc/pcmcia/config.opts you had up and running before (so restore the backup copy you just made). Else you can try to use the version which is distributed within pcmciautils and installed by default; however you might need to modify it for the specific needs of the architecture, socket and system you are using. 2.5. The difficult cases: CIS overrides --------------------------------------- If the PCMCIA card you use needs a "CIS" override (sort of a "firmware" override) to work correctly, get the proper file out of [10]pcmcia-cs or from other sources, rename it from ".dat" to ".cis" and store it into /lib/firmware/. 3. Usage -------- 3.1. devices ------------ Plug the cards in, watch them appear in /sys/bus/pcmcia/devices/, use them. Don't forget to unmount block devices before ejecting a PCMCIA card! If you relied on the startup scripts in /etc/pcmcia/*, you should switch to the generic hotplug scripts in one of its variants (hotplug, hotplug-ng, and so on) or to udev rules. Most distributions already include this capability; if not, you might need to adapt them slightly depending on your distribution and configuration. Also check the udev documentation, for example if you want to name interfaces differently from the kernel's default setting. 3.2. pccardctl (replaces cardctl) --------------------------------- And what about the command cardctl you might be used to? It is replaced by several new ways to achieve the same aims; if you want to update pccardctl to handle them all, please send patches to the [11]Linux-PCMCIA mailinglist. cardctl info pccardctl info cardctl ident pccardctl ident cardctl insert pccardctl insert cardctl eject pccardctl eject cardctl suspend pccardctl suspend [>=2.6.15] cardctl resume pccardctl resume [>=2.6.15] cardctl suspend echo -n "3" > /sys/class/pcmcia_socket/pcmcia_socket*/d evice/power/state cardctl resume echo -n "0" > /sys/class/pcmcia_socket/pcmcia_socket*/d evice/power/state cardctl status cat /sys/class/pcmcia/pcmcia_socket/*/* cardctl config cat /sys/bus/pcmcia/devices/*/* cardctl scheme -- not implemented, as incompatible to cardbus. Use other utilities (udev, nameif, ...) to achieve the same aims -- pcmciautils-018/doc/pcmcia-new.sh000066400000000000000000000015531155177104400170360ustar00rootroot00000000000000#!/bin/sh # # this is an examle of the /etc/init.d/pcmcia-new init script as described in # cardmgr-to-pcmciautils.txt # # # set this to the driver to use, one of: # yenta_socket, i82365, i82092, pd6729, tcic, etc. # DRIVER=yenta_socket DRIVER_OPTS= # in case modprobe and rmmod are not in PATH: set MODUTILS_PATH to the right # path an uncomment the following two lines: #MODUTILS_PATH= #export PATH=$MODUTILS_PATH:$PATH case "$1" in start) modprobe $DRIVER $DRIVER_OPTS > /dev/null 2>&1 modprobe pcmcia > /dev/null 2>&1 # just in case it's not auto-loaded ;; stop) pccardctl eject MODULES=`lsmod | grep "pcmcia " | awk '{print $4}' | tr , ' '` for i in $MODULES ; do rmmod $i > /dev/null 2>&1 done rmmod pcmcia > /dev/null 2>&1 rmmod $DRIVER > /dev/null 2>&1 rmmod rsrc_nonstatic > /dev/null 2>&1 rmmod pcmcia_core > /dev/null 2>&1 ;; esac pcmciautils-018/hotplug/000077500000000000000000000000001155177104400153705ustar00rootroot00000000000000pcmciautils-018/hotplug/pcmcia.agent000077500000000000000000000020231155177104400176440ustar00rootroot00000000000000#!/bin/sh # # PCMCIA-specific hotplug policy agent # # $Id$ # #DEBUG=yes; export DEBUG SYSFS=/sys cd /etc/hotplug . ./hotplug.functions if [ "$ACTION" = "" ]; then mesg Bad PCMCIA agent invocation, no action exit 1 fi debug_mesg $SOCKET_NO $DEVICE_NO $MODALIAS $DEVPATH case $ACTION in add) modprobe $MODALIAS # check whether the CIS is completely broken if [ ! -h $SYSFS$DEVPATH/driver ]; then CISFILE=$(pcmcia-check-broken-cis $SOCKET_NO) debug_mesg $CISFILE; if [ ! -z $CISFILE ]; then if [ -f /lib/firmware/$CISFILE ]; then cat /lib/firmware/$CISFILE > $SYSFS/class/pcmcia_socket/pcmcia_socket$(SOCKET_NO)/cis fi; fi; fi; # allow a match solely based on the "function ID" field if [ ! -h $SYSFS$DEVPATH/driver ]; then if [ -w $SYSFS$DEVPATH/allow_func_id_match ]; then debug_mesg allowing func_id based match for PCMCIA device $SOCKET_NO.$DEVICE_NO echo -n "42" > $SYSFS$DEVPATH/allow_func_id_match; fi; fi; ;; remove) ;; *) debug_mesg "PCMCIA '$ACTION' event not supported" ;; esac pcmciautils-018/hotplug/pcmcia.rc000077500000000000000000000016541155177104400171630ustar00rootroot00000000000000#!/bin/sh # vim: syntax=sh # # pcmcia.rc recover lost boot-time pcmcia_socket hotplug events # # $Id: $ # PATH=/sbin:/bin:/usr/sbin:/usr/bin #DEBUG=yes; export DEBUG cd /etc/hotplug . ./hotplug.functions pcmcia_boot_events () { if [ -d /sys/bus/pcmcia/devices/ ]; then # 2.6 kernels cd /sys/bus/pcmcia/devices/ for PCMCIA_DEVICE in *; do if [ $PCMCIA_DEVICE == \* ]; then continue; fi; MODALIAS=$(cat $PCMCIA_DEVICE/modalias) debug_mesg $MODALIAS $PCMCIA_DEVICE if [ -z $MODALIAS ]; then continue; fi; ACTION=add export MODALIAS ACTION /sbin/hotplug pcmcia done; fi; return 0 } # See how we were called. case "$1" in start) pcmcia_boot_events ;; stop) # echo $"pcmcia stop -- ignored" ;; restart) # always invoke by absolute path, else PATH=$PATH: $0 stop && $0 start ;; *) echo $"Usage: $0 {start|stop|restart}" exit 1 esac pcmciautils-018/hotplug/pcmcia_socket.agent000077500000000000000000000011521155177104400212160ustar00rootroot00000000000000#!/bin/sh # # PCMCIA-socket-specific hotplug policy agent # # $Id$ # #DEBUG=yes; export DEBUG cd /etc/hotplug . ./hotplug.functions if [ "$ACTION" = "" ]; then mesg Bad PCMCIA socket agent invocation, no action exit 1 fi debug_mesg socket number: $SOCKET_NO case $ACTION in add) sleep 1; pcmcia-socket-startup $SOCKET_NO DONE_FILE=/sys/class/pcmcia_socket/pcmcia_socket$SOCKET_NO/available_resources_setup_done if [ -f $DONE_FILE ]; then if [ -w $DONE_FILE ]; then echo -n "42" > $DONE_FILE fi; fi; ;; remove) ;; *) debug_mesg "PCMCIA socket '$ACTION' event not supported" ;; esac pcmciautils-018/hotplug/pcmcia_socket.rc000077500000000000000000000015361155177104400205320ustar00rootroot00000000000000#!/bin/sh # vim: syntax=sh # # pcmcia.rc recover lost boot-time pcmcia_socket hotplug events # # $Id: $ # PATH=/sbin:/bin:/usr/sbin:/usr/bin #DEBUG=yes; export DEBUG cd /etc/hotplug . ./hotplug.functions pcmcia_boot_events () { if [ -d /sys/class/pcmcia_socket/ ]; then # 2.6 kernels cd /sys/class/pcmcia_socket/ for PCMCIA_SOCKET in *; do if [ $PCMCIA_SOCKET == \* ]; then continue; fi; SOCKET_NO=$(echo $PCMCIA_SOCKET | cut -b14-) ACTION=add export SOCKET_NO ACTION /sbin/hotplug pcmcia_socket done; fi; return 0 } # See how we were called. case "$1" in start) pcmcia_boot_events ;; stop) # echo $"pcmcia stop -- ignored" ;; restart) # always invoke by absolute path, else PATH=$PATH: $0 stop && $0 start ;; *) echo $"Usage: $0 {start|stop|restart}" exit 1 esac pcmciautils-018/man/000077500000000000000000000000001155177104400144615ustar00rootroot00000000000000pcmciautils-018/man/man8/000077500000000000000000000000001155177104400153245ustar00rootroot00000000000000pcmciautils-018/man/man8/pccardctl.8000066400000000000000000000043341155177104400173600ustar00rootroot00000000000000.\" Copyright (C) 1998 David A. Hinds -- dahinds@users.sourceforge.net .\" Copyright (C) 2005 by Daniel Ritz .\" .TH PCCARDCTL 8 "2005/10/22" "pcmciautils" .SH NAME pccardctl \- PCMCIA card control utility .br lspcmcia \- display extended PCMCIA debugging information .SH SYNOPSIS \fBpccardctl\fR [\fB\-V\fR] [\fB\-v ...\fR] \fIcommand\fR [\fIsocket\fR] .br \fBlspcmcia\fR [\fB\-V\fR] [\fB\-v ...\fR] [\fIsocket\fR] .SH DESCRIPTION \fBpccardctl\fR is used to monitor and control the state of PCMCIA sockets. If a socket number is specified, the command will be applied to just one socket; otherwise, all sockets will be affected. .PP If \fBpccardctl\fR is executed by root, all commands are available. If it is executed by an unpriviledged user, only the informational commands are accessible. .PP \fBlspcmcia\fR is an alias for \fBpccardctl ls\fR, provided for convenience. .PP .SH COMMANDS .TP \w'abcd'u .B status Display the current socket status flags. .TP .B config Display the socket configuration, including power settings, interrupt and I/O window settings, and configuration registers. \-\-not yet implemented .TP .B ident Display card identification information, including product identification strings, manufacturer ID codes, and function ID codes. Not yet implemented for cardbus cards. Use lspci instead. .TP .B info Much like the \fBident\fR command, but its output is formatted as a series of Bourne-stype shell variable definitions for use in scripts. Not yet implemented for cardbus cards. .TP .B ls Display extended debugging information about the PCMCIA sockets and devices present in the system. .TP .B suspend Shut down and then disable power for a socket. .TP .B resume Restore power to a socket, and re-configure for use. .TP .TP .B eject Notify all client drivers that this card will be ejected, then cut power to the socket. .TP .B insert Notify all client drivers that this card has just been inserted. .SH OPTIONS .TP .B \-V Show version information and exit. .TP .B \-v Increase the verbosity of the .B ls command. Giving this option twice increases verbosity further. .SH AUTHOR Daniel Ritz \- daniel.ritz@gmx.ch .br based upon the original cardctl man page by .br David Hinds \- dahinds@users.sourceforge.net pcmciautils-018/src/000077500000000000000000000000001155177104400144755ustar00rootroot00000000000000pcmciautils-018/src/cistpl.h000066400000000000000000000366221155177104400161550ustar00rootroot00000000000000/* * 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 * . 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 #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 { unsigned int addr; } cistpl_longlink_t; typedef struct cistpl_checksum_t { unsigned short addr; unsigned short len; unsigned 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 { unsigned char nfn; struct { unsigned char space; unsigned int addr; } fn[CISTPL_MAX_FUNCTIONS]; } cistpl_longlink_mfc_t; #define CISTPL_MAX_ALTSTR_STRINGS 4 typedef struct cistpl_altstr_t { unsigned char ns; unsigned 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 { unsigned char ndev; struct { unsigned char type; unsigned char wp; unsigned int speed; unsigned 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 { unsigned char flags; cistpl_device_t device; } cistpl_device_o_t; #define CISTPL_VERS_1_MAX_PROD_STRINGS 4 typedef struct cistpl_vers_1_t { unsigned char major; unsigned char minor; unsigned char ns; unsigned char ofs[CISTPL_VERS_1_MAX_PROD_STRINGS]; char str[254]; } cistpl_vers_1_t; typedef struct cistpl_jedec_t { unsigned char nid; struct { unsigned char mfr; unsigned char info; } id[CISTPL_MAX_DEVICES]; } cistpl_jedec_t; typedef struct cistpl_manfid_t { unsigned short manf; unsigned 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 { unsigned char func; unsigned char sysinit; } cistpl_funcid_t; typedef struct cistpl_funce_t { unsigned char type; unsigned 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 { unsigned char uart_type; unsigned char uart_cap_0; unsigned char uart_cap_1; } cistpl_serial_t; typedef struct cistpl_modem_cap_t { unsigned char flow; unsigned char cmd_buf; unsigned char rcv_buf_0, rcv_buf_1, rcv_buf_2; unsigned 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 { unsigned char max_data_0; unsigned char max_data_1; unsigned char modulation_0; unsigned char modulation_1; unsigned char error_control; unsigned char compression; unsigned char cmd_protocol; unsigned char escape; unsigned char encrypt; unsigned char misc_features; unsigned char ccitt_code[0]; } cistpl_data_serv_t; typedef struct cistpl_fax_serv_t { unsigned char max_data_0; unsigned char max_data_1; unsigned char modulation; unsigned char encrypt; unsigned char features_0; unsigned char features_1; unsigned char ccitt_code[0]; } cistpl_fax_serv_t; typedef struct cistpl_voice_serv_t { unsigned char max_data_0; unsigned 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 { unsigned char tech; } cistpl_lan_tech_t; typedef struct cistpl_lan_speed_t { unsigned 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 { unsigned char media; } cistpl_lan_media_t; typedef struct cistpl_lan_node_id_t { unsigned char nb; unsigned char id[16]; } cistpl_lan_node_id_t; typedef struct cistpl_lan_connector_t { unsigned char code; } cistpl_lan_connector_t; /*====================================================================== IDE Function Extension Tuples ======================================================================*/ #define CISTPL_IDE_INTERFACE 0x01 typedef struct cistpl_ide_interface_t { unsigned 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 { unsigned char feature1; unsigned 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 { unsigned char attr; unsigned int size; } cistpl_bar_t; typedef struct cistpl_config_t { unsigned char last_idx; unsigned int base; unsigned int rmask[4]; unsigned 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 { unsigned char present; unsigned char flags; unsigned int param[7]; } cistpl_power_t; typedef struct cistpl_timing_t { unsigned int wait, waitscale; unsigned int ready, rdyscale; unsigned 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 { unsigned char flags; unsigned char nwin; struct { unsigned int base; unsigned int len; } win[CISTPL_IO_MAX_WIN]; } cistpl_io_t; typedef struct cistpl_irq_t { unsigned int IRQInfo1; unsigned int IRQInfo2; } cistpl_irq_t; #define CISTPL_MEM_MAX_WIN 8 typedef struct cistpl_mem_t { unsigned char flags; unsigned char nwin; struct { unsigned int len; unsigned int card_addr; unsigned 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 { unsigned char index; unsigned short flags; unsigned char interface; cistpl_power_t vcc, vpp1, vpp2; cistpl_timing_t timing; cistpl_io_t io; cistpl_irq_t irq; cistpl_mem_t mem; unsigned 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 { unsigned char index; unsigned int flags; cistpl_power_t vcc, vpp1, vpp2; unsigned char io; cistpl_irq_t irq; unsigned char mem; unsigned char subtuples; } cistpl_cftable_entry_cb_t; typedef struct cistpl_device_geo_t { unsigned char ngeo; struct { unsigned char buswidth; unsigned int erase_block; unsigned int read_block; unsigned int write_block; unsigned int partition; unsigned int interleave; } geo[CISTPL_MAX_DEVICES]; } cistpl_device_geo_t; typedef struct cistpl_vers_2_t { unsigned char vers; unsigned char comply; unsigned short dindex; unsigned char vspec8, vspec9; unsigned char nhdr; unsigned char vendor, info; char str[244]; } cistpl_vers_2_t; typedef struct cistpl_org_t { unsigned 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 { unsigned char type; unsigned char edc; unsigned int offset; unsigned 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_flags { unsigned int link_space:4; unsigned int has_link:1; unsigned int mfc_fn:3; unsigned int space:4; } tuple_flags; typedef struct tuple_t { unsigned int Attributes; unsigned char DesiredTuple; tuple_flags Flags; /* internal use */ unsigned int LinkOffset; /* internal use */ unsigned int CISOffset; /* internal use */ unsigned char TupleCode; unsigned char TupleLink; unsigned char TupleOffset; unsigned char TupleDataMax; unsigned char TupleDataLen; unsigned char *TupleData; } tuple_t; /* Special unsigned char value */ #define RETURN_FIRST_TUPLE 0xff /* Attributes for tuple calls */ #define TUPLE_RETURN_LINK 0x01 #define TUPLE_RETURN_COMMON 0x02 /* For ValidateCIS */ typedef struct cisinfo_t { unsigned int Chains; } cisinfo_t; #define CISTPL_MAX_CIS_SIZE 0x200 /* For ReplaceCIS */ typedef struct cisdump_t { unsigned int Length; unsigned char Data[CISTPL_MAX_CIS_SIZE]; } cisdump_t; #define BIND_FN_ALL 0xff int read_out_cis(unsigned int socket_no, FILE *fd); int pcmcia_get_first_tuple(unsigned int function, tuple_t *tuple); int pcmcia_get_next_tuple(unsigned int function, tuple_t *tuple); int pcmcia_get_tuple_data(tuple_t *tuple); int pccard_parse_tuple(tuple_t *tuple, cisparse_t *parse); #endif /* LINUX_CISTPL_H */ pcmciautils-018/src/lex_config.l000066400000000000000000000110561155177104400167720ustar00rootroot00000000000000/* Special state for handling include files */ %x src %option noinput nounput %{ /* * Startup tool for non statically mapped PCMCIA sockets * * (C) 2005 Dominik Brodowski * * The initial developer of the original code is David A. Hinds * . Portions created by David A. Hinds * are Copyright (C) 1999 David A. Hinds. All Rights Reserved. * * License: GPL v2 */ #undef src #include #include #include #include #include #ifdef HAS_WORDEXP #include #else #include #endif #define src 1 #include "yacc_config.h" /* For assembling nice error messages */ char *current_file; int current_lineno; int yyparse(void); static int lex_number(char *s); static int lex_string(char *s); static void do_source(char *fn); static int do_eof(void); %} int [0-9]+ hex 0x[0-9a-fA-F]+ str \"([^"]|\\.)*\" %% source[ \t]+ BEGIN(src); return SOURCE; [^\n]+ do_source(yytext); BEGIN(INITIAL); <> if (do_eof()) yyterminate(); \n current_lineno++; [ \t]* /* skip */ ; [ ]*[#;].* /* skip */ ; exclude return EXCLUDE; include return INCLUDE; irq return IRQ_NO; port return PORT; memory return MEMORY; module /* skip */ ; {int} return lex_number(yytext); {hex} return lex_number(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_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; } /*====================================================================== Code to support nesting of configuration files ======================================================================*/ #define MAX_SOURCE_DEPTH 4 struct source_stack { YY_BUFFER_STATE buffer; char *filename; int lineno, fileno; FILE *file; #ifdef HAS_WORDEXP wordexp_t word; #else glob_t glob; #endif } source_stack[MAX_SOURCE_DEPTH]; static int source_stack_ptr = 0; static int parse_env = 0; static int get_glob(void) { struct source_stack *s = &source_stack[source_stack_ptr]; #ifdef HAS_WORDEXP while (s->fileno < s->word.we_wordc) { char *fn = s->word.we_wordv[s->fileno]; #else while (s->fileno < (signed int) s->glob.gl_pathc) { char *fn = s->glob.gl_pathv[s->fileno]; #endif s->file = fopen(fn, "r"); if (s->file == NULL) { if (strpbrk(fn, "?*[") == NULL) syslog(LOG_ERR, "could not open '%s': %m", fn); s->fileno++; } else { current_lineno = 1; current_file = strdup(fn); yy_switch_to_buffer(yy_create_buffer(s->file, YY_BUF_SIZE)); source_stack_ptr++; s->fileno++; return 0; } } return -1; } static void do_source(char *fn) { struct source_stack *s = &source_stack[source_stack_ptr]; if (source_stack_ptr >= MAX_SOURCE_DEPTH) { syslog(LOG_ERR, "source depth limit exceeded"); return; } #ifdef HAS_WORDEXP wordexp(fn, &s->word, 0); #else glob(fn, GLOB_NOCHECK, NULL, &s->glob); #endif s->fileno = 0; s->buffer = YY_CURRENT_BUFFER; s->lineno = current_lineno; s->filename = current_file; get_glob(); } static int do_eof(void) { struct source_stack *s = &source_stack[--source_stack_ptr]; if (source_stack_ptr < 0) { if (parse_env == 0) { char *t = getenv("PCMCIA_OPTS"); if (t == NULL) return -1; parse_env = 1; source_stack_ptr = 0; current_file = "PCMCIA_OPTS"; current_lineno = 1; yy_scan_string(t); return 0; } else return -1; } fclose(s->file); free(current_file); yy_delete_buffer(YY_CURRENT_BUFFER); if (get_glob() != 0) { yy_switch_to_buffer(s->buffer); current_lineno = s->lineno; current_file = s->filename; } return 0; } /*====================================================================== The main entry point... returns -1 if the file can't be accessed. ======================================================================*/ int parse_configfile(char *fn) { FILE *f; f = fopen(fn, "r"); if (!f) { syslog(LOG_ERR, "could not open '%s': %m", fn); return -1; } current_lineno = 1; current_file = fn; source_stack_ptr = 0; yyrestart(f); yyparse(); fclose(f); return 0; } pcmciautils-018/src/pccardctl.c000066400000000000000000000441151155177104400166050ustar00rootroot00000000000000/* * (C) 2004-2005 Dominik Brodowski * * Partly based on cardctl.c from pcmcia-cs-3.2.7/cardmgr/, which states * in its header: * * The initial developer of the original code is David A. Hinds * . Portions created by David A. Hinds * are Copyright (C) 1999 David A. Hinds. All Rights Reserved. * * Licensed under the terms of the GNU GPL License version 2. */ #include #include #include #include #include #include #include #include #include #include #define MAX_SOCKET 8 static const char * const fn[] = { "multifunction", "memory", "serial", "parallel", "fixed disk", "video", "network", "AIMS", "SCSI" }; /* crc32hash.c - derived from linux/lib/crc32.c, GNU GPL v2 */ static unsigned int crc32(unsigned char const *p, unsigned int len) { int i; unsigned int crc = 0; while (len--) { crc ^= *p++; for (i = 0; i < 8; i++) crc = (crc >> 1) ^ ((crc & 1) ? 0xedb88320 : 0); } return crc; } static int pccardctl_power_socket(unsigned long socket_no, unsigned int power) { int ret; char file[SYSFS_PATH_MAX]; struct sysfs_attribute *attr; snprintf(file, SYSFS_PATH_MAX, "/sys/class/pcmcia_socket/pcmcia_socket%lu/card_pm_state", socket_no); attr = sysfs_open_attribute(file); if (!attr) return -ENODEV; ret = sysfs_write_attribute(attr, power ? "off" : "on", power ? 3 : 2); sysfs_close_attribute(attr); return ret; } static int pccardctl_echo_one(unsigned long socket_no, const char *in_file) { int ret; char file[SYSFS_PATH_MAX]; struct sysfs_attribute *attr; snprintf(file, SYSFS_PATH_MAX, "/sys/class/pcmcia_socket/pcmcia_socket%lu/%s", socket_no, in_file); attr = sysfs_open_attribute(file); if (!attr) return -ENODEV; ret = sysfs_write_attribute(attr, "42", 2); sysfs_close_attribute(attr); return ret; } static int pccardctl_socket_exists(unsigned long socket_no) { char file[SYSFS_PATH_MAX]; snprintf(file, SYSFS_PATH_MAX, "/sys/class/pcmcia_socket/pcmcia_socket%lu/card_insert", socket_no); return !(sysfs_path_is_file(file)); } static int read_out_file(char *file, char **output) { struct sysfs_attribute *attr = sysfs_open_attribute(file); int ret; char *result = NULL; *output = NULL; if (!attr) return -EIO; ret = sysfs_read_attribute(attr); if (ret || !attr->value || !attr->len || (attr->len > SYSFS_PATH_MAX)) goto close_out; result = malloc(attr->len + 1); if (result) { memcpy(result, attr->value, attr->len); result[attr->len] = '\0'; if (result[attr->len - 1] == '\n') result[attr->len - 1] = '\0'; *output = result; } else ret = -ENOMEM; close_out: sysfs_close_attribute(attr); return ret; } static int pccardctl_get_string_socket(unsigned long socket_no, const char *in_file, char **output) { char file[SYSFS_PATH_MAX]; snprintf(file, SYSFS_PATH_MAX, "/sys/class/pcmcia_socket/pcmcia_socket%lu/%s", socket_no, in_file); return read_out_file(file, output); } static int pccardctl_get_string(unsigned long socket_no, const char *in_file, char **output) { char file[SYSFS_PATH_MAX]; snprintf(file, SYSFS_PATH_MAX, "/sys/bus/pcmcia/devices/%lu.0/%s", socket_no, in_file); return read_out_file(file, output); } static int pccardctl_get_one_f(unsigned long socket_no, unsigned int dev, const char *in_file, unsigned int *result) { char *value; char file[SYSFS_PATH_MAX]; int ret; snprintf(file, SYSFS_PATH_MAX, "/sys/bus/pcmcia/devices/%lu.%u/%s", socket_no, dev, in_file); ret = read_out_file(file, &value); if (ret || !value) return -EINVAL; if (sscanf(value, "0x%X", result) != 1) return -EIO; return 0; } static int pccardctl_get_one(unsigned long socket_no, const char *in_file, unsigned int *result) { return pccardctl_get_one_f(socket_no, 0, in_file, result); } static int pccardctl_get_power_device(unsigned long socket_no, unsigned int func) { char *value; char file[SYSFS_PATH_MAX]; snprintf(file, SYSFS_PATH_MAX, "/sys/bus/pcmcia/devices/%lu.%u/pm_state", socket_no, func); read_out_file(file, &value); if (value) { if (!strncmp(value, "off", 3)) return 1; return 0; } return -ENODEV; } static int pccardctl_get_power_socket(unsigned long socket_no) { char *value; char file[SYSFS_PATH_MAX]; snprintf(file, SYSFS_PATH_MAX, "/sys/class/pcmcia_socket/pcmcia_socket%lu/card_pm_state", socket_no); read_out_file(file, &value); if (value) { if (!strncmp(value, "off", 3)) return 1; return 0; } return -ENODEV; } static int pccardctl_ident(unsigned long socket_no) { char *prod_id[4]; int valid_prod_id = 0; int i; unsigned int manf_id, card_id; if (!pccardctl_socket_exists(socket_no)) return -ENODEV; for (i = 1; i <= 4; i++) { char file[SYSFS_PATH_MAX]; snprintf(file, SYSFS_PATH_MAX, "prod_id%u", i); pccardctl_get_string(socket_no, file, &prod_id[i-1]); if (prod_id[i-1]) valid_prod_id++; } if (valid_prod_id) { printf(" product info: "); for (i = 0; i < 4; i++) { printf("%s\"%s\"", (i > 0) ? ", " : "", prod_id[i] ? prod_id[i] : ""); if (prod_id[i]) free(prod_id[i]); } printf("\n"); } else printf(" no product info available\n"); if (!pccardctl_get_one(socket_no, "manf_id", &manf_id)) if (!pccardctl_get_one(socket_no, "card_id", &card_id)) printf(" manfid: 0x%04x, 0x%04x\n", manf_id, card_id); if (!pccardctl_get_one(socket_no, "func_id", &manf_id)) { const char *s = "unknown"; if (manf_id < sizeof(fn)/sizeof(*fn)) s = fn[manf_id]; printf(" function: %d (%s)\n", manf_id, s); } return 0; } static int pccardctl_info(unsigned long socket_no) { int i; unsigned int manf_id, card_id, func_id; char *prod_id; if (!pccardctl_socket_exists(socket_no)) return -ENODEV; for (i = 1; i <= 4; i++) { char file[SYSFS_PATH_MAX]; snprintf(file, SYSFS_PATH_MAX, "prod_id%u", i); pccardctl_get_string(socket_no, file, &prod_id); printf("PRODID_%d=\"%s\"\n", i, (prod_id) ? prod_id : ""); free(prod_id); prod_id = NULL; } printf("MANFID=%04x,%04x\n", (!pccardctl_get_one(socket_no, "manf_id", &manf_id)) ? manf_id : 0, (!pccardctl_get_one(socket_no, "card_id", &card_id)) ? card_id : 0); printf("FUNCID=%d\n", (!pccardctl_get_one(socket_no, "func_id", &func_id)) ? func_id : 255); return 0; } static int pccardctl_status(unsigned long socket_no) { char *card_type; char *card_voltage; int susp; int is_cardbus = 0; int i, ret; if (!pccardctl_socket_exists(socket_no)) return -ENODEV; pccardctl_get_string_socket(socket_no, "card_type", &card_type); if (!card_type) { printf(" no card\n"); return 0; } pccardctl_get_string_socket(socket_no, "card_voltage", &card_voltage); strncmp(card_type, "16", 2) ? is_cardbus = 0 : 1; printf(" %s %s %s", card_voltage, card_type, is_cardbus ? "CardBus card" : "PC Card"); susp = pccardctl_get_power_socket(socket_no); if (susp > 0) printf(" [suspended]"); printf("\n"); if (is_cardbus) return 0; for (i = 0; i < 4; i++) { int function; char drv[SYSFS_PATH_MAX]; char file[SYSFS_PATH_MAX]; if (pccardctl_get_one_f(socket_no, i, "function", &function)) continue; printf(" Subdevice %u (function %u)", i, function); snprintf(file, SYSFS_PATH_MAX, "/sys/bus/pcmcia/devices/%lu.%u/driver", socket_no, i); ret = readlink(file, drv, sizeof(drv) - 1); if (ret <= 0) printf(" [unbound]"); else if (ret > 0) { drv[ret] = '\0'; printf(" bound to driver \"%s\"", basename(drv)); } susp = pccardctl_get_power_device(socket_no, i); if (susp > 0) printf(" [suspended]"); printf("\n"); } return 0; } static void print_header(void) { printf("pcmciautils %s\n", PCMCIAUTILS_VERSION); printf("Copyright (C) 2004-2005 Dominik Brodowski, " "(C) 1999 David A. Hinds\n"); printf("Report errors and bugs to ," "please.\n"); } static char *cmdname[] = { "ls", /* needs to be first */ "insert", "eject", "suspend", "resume", "reset", "info", "status", "config", "ident", }; static void print_help(void) { unsigned int i; printf("Usage: pccardctl COMMAND\n"); printf("Supported commands are:\n"); for (i = 0; i < sizeof(cmdname)/sizeof(cmdname[0]); i++) printf("\t%s\n", cmdname[i]); } static void print_unknown_arg(void) { print_header(); printf("invalid or unknown argument\n"); print_help(); } static struct option pccardctl_opts[] = { { .name = "version", .has_arg = no_argument, .flag = NULL, .val = 'V'}, { .name = "help", .has_arg = no_argument, .flag = NULL, .val = 'h'}, { .name = "verbose", .has_arg = no_argument, .flag = NULL, .val = 'v'}, { 0, 0, 0, 0 } }; static void lspcmcia_socket_available_resources(unsigned long socket_no, char *which) { char file[SYSFS_PATH_MAX]; struct sysfs_attribute *attr; int ret, length, first = 0; char *sep; char *result = NULL; snprintf(file, SYSFS_PATH_MAX, "/sys/class/pcmcia_socket/pcmcia_socket%lu/available_resources_%s", socket_no, which); attr = sysfs_open_attribute(file); if (!attr) return; ret = sysfs_read_attribute(attr); if (ret) goto close_out; printf("\t\t\tAvailable %s:\t", which[0] == 'i' ? "ioports" : "iomem"); if (!attr->value || !attr->len || (attr->len < 5)) goto close_out; result = malloc(attr->len + 1); if (result) { memcpy(result, attr->value, attr->len); result[attr->len] = '\0'; if (result[attr->len - 1] == '\n') result[attr->len - 1] = '\0'; } else goto close_out; ret = 0; do { sep = strchr(&result[ret], '\n'); if (sep) { length = sep - &result[ret]; if (length > SYSFS_PATH_MAX) break; memcpy(file, &result[ret], length); file[length] = '\0'; printf("%s\n\t\t\t\t\t\t", file); first++; ret += length + 1; } } while (sep); if (result) { printf("%s\n", &result[ret]); first++; } close_out: if (!first) printf("--none--\n"); sysfs_close_attribute(attr); return; } static void lspcmcia_socket(unsigned long socket_no, int verbose, char *driver) { char *card_voltage, *card_vpp, *card_vcc, *ready; int pm_state; pm_state = pccardctl_get_power_socket(socket_no); pccardctl_get_string_socket(socket_no, "available_resources_setup_done", &ready); printf("\tConfiguration:\tstate: %s\tready: %s\n", pm_state ? "suspended" : "on", ready ? ready : "unknown"); pccardctl_get_string_socket(socket_no, "card_voltage", &card_voltage); pccardctl_get_string_socket(socket_no, "card_vpp", &card_vpp); pccardctl_get_string_socket(socket_no, "card_vcc", &card_vcc); if (card_voltage && card_vpp && card_vcc) printf("\t\t\tVoltage: %s Vcc: %s Vpp: %s\n", card_voltage, card_vcc, card_vpp); if (verbose > 1) { char *irq_mask_s; int i, irqs = 0; unsigned int irq_mask; pccardctl_get_string_socket(socket_no, "card_irq_mask", &irq_mask_s); if (irq_mask_s && sscanf(irq_mask_s, "0x%X", &irq_mask) == 1) { printf("\t\t\tAvailable IRQs: "); for (i = 0; i < 32; i++) { if (!(irq_mask & (1 << i))) continue; if (irqs) printf(", "); printf("%d", i); irqs++; } if (!irqs) printf("none"); printf("\n"); } lspcmcia_socket_available_resources(socket_no, "io"); lspcmcia_socket_available_resources(socket_no, "mem"); } return; } static void lspcmcia_device_resources(unsigned long socket_no, int fun) { char file[SYSFS_PATH_MAX]; struct sysfs_attribute *attr; int ret, length; char *sep; char *result = NULL; snprintf(file, SYSFS_PATH_MAX, "/sys/bus/pcmcia/devices/%lu.%u/resources", socket_no, fun); attr = sysfs_open_attribute(file); if (!attr) return; ret = sysfs_read_attribute(attr); if (ret) goto close_out; if (!attr->value || !attr->len || (attr->len < 5)) goto close_out; result = malloc(attr->len + 1); if (result) { memcpy(result, attr->value, attr->len); result[attr->len] = '\0'; if (result[attr->len - 1] == '\n') result[attr->len - 1] = '\0'; } else goto close_out; ret = 0; printf("\t\t\t"); do { sep = strchr(&result[ret], '\n'); if (sep) { length = sep - &result[ret]; if (length > SYSFS_PATH_MAX) break; memcpy(file, &result[ret], length); file[length] = '\0'; printf("%s\n\t\t\t", file); ret += length + 1; } } while (sep); if (result) printf("%s\n", &result[ret]); close_out: sysfs_close_attribute(attr); return; } static int lspcmcia(unsigned long socket_no, int verbose) { char file[SYSFS_PATH_MAX]; char drv_s[SYSFS_PATH_MAX]; char dev_s[SYSFS_PATH_MAX]; char *drv; char *dev; char *res; int ret, i; if (!pccardctl_socket_exists(socket_no)) return -ENODEV; snprintf(file, SYSFS_PATH_MAX, "/sys/class/pcmcia_socket/pcmcia_socket%lu/device", socket_no); ret = readlink(file, dev_s, sizeof(dev_s) - 1); if (ret > 0) { dev_s[ret] = '\0'; dev = basename(dev_s); } else { snprintf(file, SYSFS_PATH_MAX, "/sys/class/pcmcia_socket/pcmcia_socket%lu", socket_no); ret = readlink(file, dev_s, sizeof(dev_s) - 1); if (ret <= 0) return -ENODEV; dev_s[ret] = '\0'; dev = basename(dirname(dev_s)); } snprintf(file, SYSFS_PATH_MAX, "/sys/class/pcmcia_socket/pcmcia_socket%lu/device/driver", socket_no); ret = readlink(file, drv_s, sizeof(drv_s) - 1); if (ret <= 0) { snprintf(file, SYSFS_PATH_MAX, "/sys/class/pcmcia_socket/pcmcia_socket%lu/../driver", socket_no); ret = readlink(file, drv_s, sizeof(drv_s) - 1); if (ret <= 0) return -ENODEV; } drv_s[ret] = '\0'; drv = basename(drv_s); printf("Socket %lu Bridge: \t[%s] \t(bus ID: %s)\n", socket_no, drv, dev); if (verbose) lspcmcia_socket(socket_no, verbose, drv); pccardctl_get_string_socket(socket_no, "card_type", &res); if (!res) return 0; if (!strncmp(res, "32", 2)) { printf(" CardBus card -- see \"lspci\" " "for more information\n"); return 0; } for (i = 0; i < 4; i++) { int function; if (pccardctl_get_one_f(socket_no, i, "function", &function)) continue; printf("Socket %lu Device %d:\t", socket_no, i); snprintf(file, SYSFS_PATH_MAX, "/sys/bus/pcmcia/devices/%lu.%u/driver", socket_no, i); ret = readlink(file, drv_s, sizeof(drv_s) - 1); if (ret <= 0) printf("[-- no driver --]\t"); else if (ret > 0) { drv_s[ret] = '\0'; printf("[%s]\t\t", basename(drv_s)); } printf("(bus ID: %lu.%d)\n", socket_no, i); if (verbose) { int j; unsigned int manf_id, card_id; int pm_state = pccardctl_get_power_device(socket_no, i); printf("\tConfiguration:\tstate: %s\n", pm_state ? "suspended" : "on"); lspcmcia_device_resources(socket_no, i); printf("\tProduct Name: "); for (j = 1; j <= 4; j++) { snprintf(file, SYSFS_PATH_MAX, "prod_id%d", j); pccardctl_get_string(socket_no, file, &res); if (res) printf("%s ", res); } printf("\n"); printf("\tIdentification:\t"); if (!pccardctl_get_one(socket_no, "manf_id", &manf_id)) if (!pccardctl_get_one(socket_no, "card_id", &card_id)) printf("manf_id: 0x%04x\t" "card_id: 0x%04x\n\t\t\t", manf_id, card_id); if (!pccardctl_get_one(socket_no, "func_id", &manf_id)) { const char *s = "unknown"; if (manf_id < sizeof(fn)/sizeof(*fn)) s = fn[manf_id]; printf("function: %d (%s)\n\t\t\t", manf_id, s); } for (j = 1; j <= 4; j++) { snprintf(file, SYSFS_PATH_MAX, "prod_id%d", j); pccardctl_get_string(socket_no, file, &res); if (res) printf("prod_id(%u): \"%s\" " "(0x%08x)\n", j, res, crc32(res, strlen(res))); else printf("prod_id(%u): --- (---)\n", j); if (j < 4) printf("\t\t\t"); } } } return 0; } enum { PCCARDCTL_LSPCMCIA, /* needs to be first */ PCCARDCTL_INSERT, PCCARDCTL_EJECT, PCCARDCTL_SUSPEND, PCCARDCTL_RESUME, PCCARDCTL_RESET, PCCARDCTL_INFO, PCCARDCTL_STATUS, PCCARDCTL_CONFIG, PCCARDCTL_IDENT, NCMD }; int main(int argc, char **argv) { extern char *optarg; extern int optind, opterr, optopt; int ret = 0; int verbose = 0; unsigned int cont = 1; unsigned long socket = 0; unsigned int socket_is_set = 0; char *s; unsigned int cmd; do { ret = getopt_long(argc, argv, "Vhvc:f:s:", pccardctl_opts, NULL); switch (ret) { case -1: cont = 0; break; case 'V': print_header(); return 0; case 'v': verbose++; break; case 'h': print_header(); print_help(); return 0; case 'c': case 's': case 'f': /* ignored */ fprintf(stderr, "ignoring parameter '%c'\n", ret); break; default: print_unknown_arg(); return -EINVAL; } } while (cont); if (strcmp(basename(argv[0]), "lspcmcia") == 0) { cmd = 0; goto check_socket; } if ((argc == optind) || (argc > (optind + 2))) { print_unknown_arg(); return -EINVAL; } /* determine command */ for (cmd = 0; cmd < NCMD; cmd++) if (strcmp(argv[optind], cmdname[cmd]) == 0) break; if (cmd == NCMD) { print_unknown_arg(); return -EINVAL; } check_socket: if (argc == optind+2) { socket_is_set = 1; socket = strtol(argv[optind+1], &s, 0); if ((*argv[optind+1] == '\0') || (*s != '\0') || (socket >= MAX_SOCKET)) { print_unknown_arg(); return -EINVAL; } } for (cont = 0; cont < MAX_SOCKET; cont++) { if (socket_is_set && (socket != cont)) continue; if (!socket_is_set && !pccardctl_socket_exists(cont)) continue; if (!socket_is_set && (cmd > PCCARDCTL_INFO)) printf("Socket %d:\n", cont); ret = 0; switch (cmd) { case PCCARDCTL_LSPCMCIA: ret = lspcmcia(cont, verbose); break; case PCCARDCTL_INSERT: ret = pccardctl_echo_one(cont, "card_insert"); break; case PCCARDCTL_EJECT: ret = pccardctl_echo_one(cont, "card_eject"); break; case PCCARDCTL_INFO: ret = pccardctl_info(cont); break; case PCCARDCTL_IDENT: ret = pccardctl_ident(cont); break; case PCCARDCTL_SUSPEND: ret = pccardctl_power_socket(cont, 1); break; case PCCARDCTL_RESET: ret = pccardctl_power_socket(cont, 1); if (ret && socket_is_set) return ret; /* fall through */ case PCCARDCTL_RESUME: ret = pccardctl_power_socket(cont, 0); break; case PCCARDCTL_STATUS: ret = pccardctl_status(cont); break; default: fprintf(stderr, "command '%s' not yet handled by pccardctl\n", cmdname[cmd]); return -EAGAIN; } if (ret && socket_is_set) return ret; } return 0; } pcmciautils-018/src/pcmcia-check-broken-cis.c000066400000000000000000000107621155177104400212100ustar00rootroot00000000000000/* * pcmcia-check-broken-cis.c * * 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 * . Portions created by David A. Hinds * are Copyright (C) 1999 David A. Hinds. All Rights Reserved. * * (C) 1999 David A. Hinds * (C) 2005 Dominik Brodowski */ #include #include #include #include #include #include #include #include #include #include #include "cistpl.h" #define FIRMWARE_PATH "/lib/firmware" #define CIS_PATH "/etc/pcmcia/cis" #define SOCKET_PATH "/sys/class/pcmcia_socket/pcmcia_socket%d/cis" struct needs_cis { unsigned long code; unsigned long ofs; char *info; char *cisfile; }; #define NEEDS_CIS_ENTRY(_code, _ofs, _info, _cisfile) \ { .code = _code, .ofs = _ofs, .info = _info, .cisfile = _cisfile, } static const struct needs_cis cis_table[] = { /* "D-Link DE-650 Ethernet" */ NEEDS_CIS_ENTRY(0x40, 0x0009, "D-Link PC Ethernet Card", "D-Link.cis"), /* "Linksys Ethernet E-CARD PC Ethernet Card */ NEEDS_CIS_ENTRY(0x40, 0x0009, "E-CARD PC Ethernet Card", "E-CARD.cis"), { }, }; static int device_has_driver() { char *devpath, *path; struct stat sbuf; devpath = getenv("DEVPATH"); if (!devpath) return -ENODEV; path = alloca(strlen(devpath) + 15); sprintf(path, "/sys/%s/driver", devpath); if (!stat(path, &sbuf)) return 1; return 0; } static char *read_cis(char *cis_file, int *size) { char *cis_path; char *ret; int rc, cis_fd; struct stat sbuf; cis_path = alloca(strlen(FIRMWARE_PATH) + strlen(cis_file) + 2); sprintf(cis_path, "%s/%s", FIRMWARE_PATH, cis_file); cis_fd = open(cis_path, O_RDONLY); if (cis_fd == -1) { cis_path = alloca(strlen(CIS_PATH) + strlen(cis_file) + 2); sprintf(cis_path, "%s/%s", CIS_PATH, cis_file); if (cis_fd == -1) { rc = errno; errno = rc; return NULL; } } fstat(cis_fd, &sbuf); ret = malloc(sbuf.st_size); if (!ret) { rc = errno; close(cis_fd); errno = rc; return NULL; } if (read(cis_fd, ret, sbuf.st_size) != sbuf.st_size) { rc = errno; free(ret); close(cis_fd); errno = rc; return NULL; } close(cis_fd); *size = sbuf.st_size; return ret; } static int write_cis(char *cis, int socket_no, int size) { char *cis_path; int cis_fd, count, rc; cis_path = alloca(strlen(SOCKET_PATH) + 2); sprintf(cis_path, SOCKET_PATH, socket_no); cis_fd = open(cis_path, O_RDWR); if (cis_fd == -1) return errno; count = 0; while (count < size) { int c; c = write(cis_fd, cis+count, size-count); if (c <= 0) { rc = errno; close(cis_fd); return rc; } count += c; } close(cis_fd); return 0; } static int repair_cis(char *cis_file, int socket_no) { char *cis; int rc, size; if (device_has_driver()) return 0; cis = read_cis(cis_file, &size); if (!cis) return errno; rc = write_cis(cis, socket_no, size); free(cis); return rc; } static void usage(const char *progname) { fprintf(stderr, "Usage: %s [-r|--repair] \n", progname); exit(1); } static struct option options[] = { { "repair", 0, NULL, 'r' }, { NULL, 0, NULL, 0 } }; int main(int argc, char **argv) { int ret; char *socket; unsigned int socket_no; const struct needs_cis *entry = NULL; tuple_t tuple; unsigned char buf[256]; int opt; int repair = 0; while ((opt = getopt_long(argc, argv, "r", options, NULL)) != -1) { switch (opt) { case 'r': repair = 1; break; default: usage(argv[0]); } } socket = getenv("SOCKET_NO"); if (socket) socket_no = (unsigned int) strtoul(socket, NULL, 0); else { if (argc < optind + 1) usage(argv[0]); socket_no = strtoul(argv[optind], NULL, 0); } ret = read_out_cis(socket_no, NULL); if (ret) return ret; entry = &cis_table[0]; while (entry) { if (!entry->cisfile) return 0; tuple.DesiredTuple = entry->code; tuple.Attributes = TUPLE_RETURN_COMMON; tuple.TupleData = buf; tuple.TupleDataMax = 255; pcmcia_get_first_tuple(BIND_FN_ALL, &tuple); tuple.TupleOffset = entry->ofs; pcmcia_get_tuple_data(&tuple); if (strncmp((char *) tuple.TupleData, entry->info, strlen(entry->info)) != 0) { entry++; continue; } if (repair) { return repair_cis(entry->cisfile, socket_no); } else { printf("%s", entry->cisfile); return 1; } }; return 0; } pcmciautils-018/src/read-cis.c000066400000000000000000000145701155177104400163370ustar00rootroot00000000000000/* * read-cis.c * * 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 * . Portions created by David A. Hinds * are Copyright (C) 1999 David A. Hinds. All Rights Reserved. * * (C) 1999 David A. Hinds */ #include #include #include #include #include #include #include "cistpl.h" #define MAX_TUPLES 0x200 #define PATH_TO_SOCKET "/sys/class/pcmcia_socket/" /* Bits in attr field */ #define IS_ATTR 1 #define IS_INDIRECT 8 static unsigned int functions; static unsigned char cis_copy[MAX_TUPLES]; static unsigned int cis_length = MAX_TUPLES; static void read_cis(int attr, unsigned int addr, unsigned int len, void *ptr) { if (cis_length > addr+len) memcpy(ptr, cis_copy + addr, len); else memset(ptr, 0xff, len); return; } static int follow_link(tuple_t *tuple) { unsigned char link[5]; unsigned int ofs; if (tuple->Flags.mfc_fn) { /* Get indirect link from the MFC tuple */ read_cis(tuple->Flags.link_space, tuple->LinkOffset, 5, link); ofs = *(u_int *)(link+1); tuple->Flags.space = (link[0] == CISTPL_MFC_ATTR); /* Move to the next indirect link */ tuple->LinkOffset += 5; tuple->Flags.mfc_fn--; } else if (tuple->Flags.has_link) { ofs = tuple->LinkOffset; tuple->Flags.space = tuple->Flags.link_space; tuple->Flags.has_link = 0; } else { return -1; } if (tuple->Flags.space) { /* This is ugly, but a common CIS error is to code the long link offset incorrectly, so we check the right spot... */ read_cis(tuple->Flags.space, ofs, 5, link); if ((link[0] == CISTPL_LINKTARGET) && (link[1] >= 3) && (strncmp(link+2, "CIS", 3) == 0)) return ofs; /* Then, we try the wrong spot... */ ofs = ofs >> 1; } read_cis(tuple->Flags.space, ofs, 5, link); if ((link[0] == CISTPL_LINKTARGET) && (link[1] >= 3) && (strncmp(link+2, "CIS", 3) == 0)) return ofs; return -1; } int pcmcia_get_next_tuple(unsigned int function, tuple_t *tuple) { unsigned char link[2], tmp; int ofs, i, attr; link[1] = tuple->TupleLink; ofs = tuple->CISOffset + tuple->TupleLink; attr = tuple->Flags.space; for (i = 0; i < MAX_TUPLES; i++) { if (link[1] == 0xff) { link[0] = CISTPL_END; } else { read_cis(attr, ofs, 2, link); if (link[0] == CISTPL_NULL) { ofs++; continue; } } /* End of chain? Follow long link if possible */ if (link[0] == CISTPL_END) { ofs = follow_link(tuple); if (ofs < 0) return -ENODEV; attr = tuple->Flags.space; read_cis(attr, ofs, 2, link); } /* Is this a link tuple? Make a note of it */ if ((link[0] == CISTPL_LONGLINK_A) || (link[0] == CISTPL_LONGLINK_C) || (link[0] == CISTPL_LONGLINK_MFC) || (link[0] == CISTPL_LINKTARGET) || (link[0] == CISTPL_INDIRECT) || (link[0] == CISTPL_NO_LINK)) { switch (link[0]) { case CISTPL_LONGLINK_A: tuple->Flags.has_link = 1; tuple->Flags.link_space = attr | IS_ATTR; read_cis(attr, ofs+2, 4, &tuple->LinkOffset); break; case CISTPL_LONGLINK_C: tuple->Flags.has_link = 1; tuple->Flags.link_space = attr & ~IS_ATTR; read_cis(attr, ofs+2, 4, &tuple->LinkOffset); break; case CISTPL_INDIRECT: tuple->Flags.has_link = 1; tuple->Flags.link_space = IS_ATTR | IS_INDIRECT; tuple->LinkOffset = 0; break; case CISTPL_LONGLINK_MFC: tuple->LinkOffset = ofs + 3; tuple->Flags.link_space = attr; if (function == BIND_FN_ALL) { /* Follow all the MFC links */ read_cis(attr, ofs+2, 1, &tmp); tuple->Flags.mfc_fn = tmp; } else { /* Follow exactly one of the links */ tuple->Flags.mfc_fn = 1; tuple->LinkOffset += function * 5; } break; case CISTPL_NO_LINK: tuple->Flags.has_link = 0; break; } if ((tuple->Attributes & TUPLE_RETURN_LINK) && (tuple->DesiredTuple == RETURN_FIRST_TUPLE)) break; } else if (tuple->DesiredTuple == RETURN_FIRST_TUPLE) break; if (link[0] == tuple->DesiredTuple) break; ofs += link[1] + 2; } if (i == MAX_TUPLES) return -ENODEV; tuple->TupleCode = link[0]; tuple->TupleLink = link[1]; tuple->CISOffset = ofs + 2; return 0; } int pcmcia_get_first_tuple(unsigned int function, tuple_t *tuple) { tuple->TupleLink = 0; tuple->Flags.link_space = tuple->Flags.mfc_fn = 0; /* Assume presence of a LONGLINK_C to address 0 */ tuple->CISOffset = tuple->LinkOffset = 0; tuple->Flags.space = tuple->Flags.has_link = 1; if ((functions > 1) && !(tuple->Attributes & TUPLE_RETURN_COMMON)) { unsigned char req = tuple->DesiredTuple; tuple->DesiredTuple = CISTPL_LONGLINK_MFC; if (!pcmcia_get_next_tuple(function, tuple)) { tuple->DesiredTuple = CISTPL_LINKTARGET; if (pcmcia_get_next_tuple(function, tuple)) return -ENODEV; } else tuple->CISOffset = tuple->TupleLink = 0; tuple->DesiredTuple = req; } return pcmcia_get_next_tuple(function, tuple); } #define _MIN(a, b) (((a) < (b)) ? (a) : (b)) int pcmcia_get_tuple_data(tuple_t *tuple) { unsigned int len; if (tuple->TupleLink < tuple->TupleOffset) return -ENODEV; len = tuple->TupleLink - tuple->TupleOffset; tuple->TupleDataLen = tuple->TupleLink; if (len == 0) return 0; read_cis(tuple->Flags.space, tuple->CISOffset + tuple->TupleOffset, _MIN(len, tuple->TupleDataMax), tuple->TupleData); return 0; } int read_out_cis(unsigned int socket_no, FILE *fd) { char file[SYSFS_PATH_MAX]; int ret, i; tuple_t tuple; unsigned char buf[256]; snprintf(file, SYSFS_PATH_MAX, PATH_TO_SOCKET "pcmcia_socket%d/cis", socket_no); if (!fd) { fd = fopen(file, "r"); if (!fd) return -EIO; } for (i = 0; i < MAX_TUPLES; i++) { ret = fgetc(fd); if (ret == EOF) { cis_length = i + 1; break; } cis_copy[i] = (unsigned char) ret; } fclose(fd); if (cis_length < 4) return -EINVAL; functions = 1; tuple.DesiredTuple = CISTPL_LONGLINK_MFC; tuple.Attributes = TUPLE_RETURN_COMMON; ret = pcmcia_get_first_tuple(BIND_FN_ALL, &tuple); if (ret) functions = 1; tuple.TupleData = buf; tuple.TupleOffset = 0; tuple.TupleDataMax = 255; ret = pcmcia_get_tuple_data(&tuple); if (ret) return -EBADF; functions = tuple.TupleData[0]; return 0; } pcmciautils-018/src/startup.c000066400000000000000000000115621155177104400163500ustar00rootroot00000000000000/* * Startup tool for non statically mapped PCMCIA sockets * * (C) 2005 Dominik Brodowski * * The initial developer of the original code is David A. Hinds * . Portions created by David A. Hinds * are Copyright (C) 1999 David A. Hinds. All Rights Reserved. * * License: GPL v2 */ #include #include #include #include #include #include #include #include "startup.h" /* uncomment for debug output */ #ifdef DEBUG #define dprintf printf #else #define dprintf(...) do { } while (0); #endif /* Linked list of resource adjustments */ struct adjust_list_t *root_adjust; /* path for config file, device scripts */ static char *configpath = "/etc/pcmcia"; enum { RESOURCE_MEM, RESOURCE_IO, MAX_RESOURCE_FILES }; static const char *resource_files[MAX_RESOURCE_FILES] = { [RESOURCE_MEM] = "available_resources_mem", [RESOURCE_IO] = "available_resources_io", }; #define PATH_TO_SOCKET "/sys/class/pcmcia_socket/" static int add_available_resource(unsigned int socket_no, unsigned int type, unsigned int action, unsigned long start, unsigned long end) { char file[SYSFS_PATH_MAX]; char content[SYSFS_PATH_MAX]; struct sysfs_attribute *attr; int ret; size_t len; if (type >= MAX_RESOURCE_FILES) return -EINVAL; if (end <= start) return -EINVAL; dprintf("%d %d %d 0x%lx 0x%lx\n", socket_no, type, action, start, end); snprintf(file, SYSFS_PATH_MAX, PATH_TO_SOCKET "pcmcia_socket%u/%s", socket_no, resource_files[type]); switch (action) { case ADD_MANAGED_RESOURCE: len = snprintf(content, SYSFS_PATH_MAX, "0x%08lx - 0x%08lx", start, end); break; case REMOVE_MANAGED_RESOURCE: len = snprintf(content, SYSFS_PATH_MAX, "- 0x%08lx - 0x%08lx", start, end); break; default: return -EINVAL; } dprintf("content is %s\n", content); dprintf("file is %s\n", file); attr = sysfs_open_attribute(file); if (!attr) return -ENODEV; dprintf("open, len %zu\n", len); ret = sysfs_write_attribute(attr, content, len); dprintf("ret is %d\n", ret); sysfs_close_attribute(attr); return ret; } static int setup_done(unsigned int socket_no) { int ret; char file[SYSFS_PATH_MAX]; struct sysfs_attribute *attr; snprintf(file, SYSFS_PATH_MAX, PATH_TO_SOCKET "pcmcia_socket%u/available_resources_setup_done", socket_no); attr = sysfs_open_attribute(file); if (!attr) return -ENODEV; ret = sysfs_write_attribute(attr, "42", 2); sysfs_close_attribute(attr); return ret; } static int disallow_irq(unsigned int socket_no, unsigned int irq) { char file[SYSFS_PATH_MAX]; char content[SYSFS_PATH_MAX]; struct sysfs_attribute *attr; unsigned int mask = 0xfff; unsigned int new_mask; int ret; size_t len; if (irq >= 32) return -EINVAL; len = snprintf(file, SYSFS_PATH_MAX, PATH_TO_SOCKET "pcmcia_socket%u/card_irq_mask", socket_no); dprintf("file is %s\n", file); attr = sysfs_open_attribute(file); if (!attr) return -ENODEV; dprintf("open, len %zu\n", len); ret = sysfs_read_attribute(attr); if (ret) { ret = -EINVAL; goto out; } if (!attr->value || (attr->len < 6)) { ret = -EIO; goto out; } ret = sscanf(attr->value, "0x%x\n", &mask); new_mask = 1 << irq; mask &= ~new_mask; len = snprintf(content, SYSFS_PATH_MAX, "0x%04x", mask); dprintf("content is %s\n", content); ret = sysfs_write_attribute(attr, content, len); out: sysfs_close_attribute(attr); return ret; } static void load_config(void) { if (chdir(configpath) != 0) { syslog(LOG_ERR, "chdir to %s failed: %m", configpath); exit(EXIT_FAILURE); } parse_configfile("config.opts"); return; } static void adjust_resources(unsigned int socket_no) { adjust_list_t *al; for (al = root_adjust; al; al = al->next) { switch (al->adj.Resource) { case RES_MEMORY_RANGE: add_available_resource(socket_no, RESOURCE_MEM, al->adj.Action, al->adj.resource.memory.Base, al->adj.resource.memory.Base + al->adj.resource.memory.Size - 1); break; case RES_IO_RANGE: add_available_resource(socket_no, RESOURCE_IO, al->adj.Action, al->adj.resource.io.BasePort, al->adj.resource.io.BasePort + al->adj.resource.io.NumPorts - 1); break; case RES_IRQ: if (al->adj.Action == REMOVE_MANAGED_RESOURCE) disallow_irq(socket_no, al->adj.resource.irq.IRQ); break; } } } int main(int argc, char *argv[]) { char *socket_no; unsigned long socket, i; unsigned int all_sockets = 0; socket_no = getenv("SOCKET_NO"); if (socket_no) socket = strtoul(socket_no, NULL, 0); else if (argc == 2) socket = strtoul(argv[1], NULL, 0); else if (argc == 1) { socket = 0; all_sockets = 1; } else return -EINVAL; load_config(); for (i = 0; i < MAX_SOCKS; i++) { if ((socket != i) && (!all_sockets)) continue; adjust_resources(i); setup_done(i); } return 0; } pcmciautils-018/src/startup.h000066400000000000000000000020751155177104400163540ustar00rootroot00000000000000/* * Startup tool for non statically mapped PCMCIA sockets * * The initial developer of the original code is David A. Hinds * . Portions created by David A. Hinds * are Copyright (C) 1999 David A. Hinds. All Rights Reserved. * * License: GPL v2 * */ #define MAX_SOCKS 8 #define MAX_BINDINGS 4 #define MAX_MODULES 4 /* for AdjustResourceInfo */ typedef struct adjust_t { unsigned int Action; unsigned int Resource; unsigned int Attributes; union { struct memory { unsigned long Base; unsigned long Size; } memory; struct io { unsigned long BasePort; unsigned long NumPorts; unsigned int IOAddrLines; } io; struct irq { unsigned int IRQ; } irq; } resource; } adjust_t; typedef struct adjust_list_t { adjust_t adj; struct adjust_list_t *next; } adjust_list_t; extern adjust_list_t *root_adjust; int parse_configfile(char *fn); #define RES_MEMORY_RANGE 1 #define RES_IO_RANGE 2 #define RES_IRQ 3 #define RES_RESERVED 0x10 #define REMOVE_MANAGED_RESOURCE 1 #define ADD_MANAGED_RESOURCE 2 pcmciautils-018/src/yacc_config.y000066400000000000000000000054701155177104400171410ustar00rootroot00000000000000%{ /* * Startup tool for non statically mapped PCMCIA sockets - config file parsing * * (C) 2005 Dominik Brodowski * * The initial developer of the original code is David A. Hinds * . Portions created by David A. Hinds * are Copyright (C) 1999 David A. Hinds. All Rights Reserved. * * License: GPL v2 */ #include #include #include #include #include #include #include "startup.h" /* If bison: generate nicer error messages */ #define YYERROR_VERBOSE 1 /* from lex_config, for nice error messages */ extern char *current_file; extern int current_lineno; void yyerror(char *msg, ...); int yylex(void); %} %token DEVICE CARD ANONYMOUS TUPLE MANFID VERSION FUNCTION PCI %token BIND CIS TO NEEDS_MTD MODULE OPTS CLASS %token REGION JEDEC DTYPE DEFAULT MTD %token INCLUDE EXCLUDE RESERVE IRQ_NO PORT MEMORY %token STRING NUMBER SOURCE %union { char *str; u_long num; struct adjust_list_t *adjust; } %type STRING %type NUMBER %type adjust resource %% list: /* nothing */ | list adjust { adjust_list_t **tail = &root_adjust; while (*tail != NULL) tail = &(*tail)->next; *tail = $2; } ; adjust: INCLUDE resource { $2->adj.Action = ADD_MANAGED_RESOURCE; $$ = $2; } | EXCLUDE resource { $2->adj.Action = REMOVE_MANAGED_RESOURCE; $$ = $2; } | RESERVE resource { $2->adj.Action = ADD_MANAGED_RESOURCE; $2->adj.Attributes |= RES_RESERVED; $$ = $2; } | adjust ',' resource { $3->adj.Action = $1->adj.Action; $3->adj.Attributes = $1->adj.Attributes; $3->next = $1; $$ = $3; } ; resource: IRQ_NO NUMBER { $$ = calloc(sizeof(adjust_list_t), 1); $$->adj.Resource = RES_IRQ; $$->adj.resource.irq.IRQ = $2; } | PORT NUMBER '-' NUMBER { if (($4 < $2) || ($4 > 0xffff)) { yyerror("invalid port range 0x%x-0x%x", $2, $4); YYERROR; } $$ = calloc(sizeof(adjust_list_t), 1); $$->adj.Resource = RES_IO_RANGE; $$->adj.resource.io.BasePort = $2; $$->adj.resource.io.NumPorts = $4 - $2 + 1; } | MEMORY NUMBER '-' NUMBER { if ($4 < $2) { yyerror("invalid address range 0x%x-0x%x", $2, $4); YYERROR; } $$ = calloc(sizeof(adjust_list_t), 1); $$->adj.Resource = RES_MEMORY_RANGE; $$->adj.resource.memory.Base = $2; $$->adj.resource.memory.Size = $4 - $2 + 1; } ; %% void yyerror(char *msg, ...) { va_list ap; char str[256]; va_start(ap, msg); sprintf(str, "error in file '%s' line %d: ", current_file, current_lineno); vsprintf(str+strlen(str), msg, ap); #if YYDEBUG fprintf(stderr, "%s\n", str); #else syslog(LOG_ERR, "%s", str); #endif va_end(ap); } pcmciautils-018/udev/000077500000000000000000000000001155177104400146515ustar00rootroot00000000000000pcmciautils-018/udev/rules-base000066400000000000000000000012341155177104400166360ustar00rootroot00000000000000 # Very few CIS firmware entries (which we use for matching) # are so broken that we need to read out random bytes of it # instead of the manufactor, card or product ID. Then the # matching is done in userspace. SUBSYSTEM=="pcmcia", ENV{MODALIAS}=="?*", \ RUN+="__UDEVHELPERDIR__/pcmcia-check-broken-cis" # However, the "weak" matching by func_id is only allowed _after_ modprobe # returns, so that "strong" matches have a higher priority. SUBSYSTEM=="pcmcia", ENV{MODALIAS}=="?*", ATTR{allow_func_id_match}="1" # PCMCIA sockets: # # modprobe the pcmcia bus module so that 16-bit PCMCIA devices work SUBSYSTEM=="pcmcia_socket", \ RUN+="/sbin/modprobe -b pcmcia" pcmciautils-018/udev/rules-end000066400000000000000000000000311155177104400164640ustar00rootroot00000000000000 LABEL="pcmciautils_end" pcmciautils-018/udev/rules-modprobe000066400000000000000000000002241155177104400175310ustar00rootroot00000000000000# modprobe $env{MODALIAS} loads all possibly appropriate modules SUBSYSTEM=="pcmcia", ENV{MODALIAS}=="?*", \ RUN+="/sbin/modprobe $env{MODALIAS}" pcmciautils-018/udev/rules-nonstaticsocket000066400000000000000000000002611155177104400211360ustar00rootroot00000000000000 # if this is a PCMCIA socket which needs a resource database, # pcmcia-socket-startup sets it up SUBSYSTEM=="pcmcia_socket", \ RUN+="__UDEVHELPERDIR__/pcmcia-socket-startup" pcmciautils-018/udev/rules-start000066400000000000000000000000721155177104400170600ustar00rootroot00000000000000# PCMCIA devices: # ACTION!="add", GOTO="pcmciautils_end"