From alex at mplayerhq.hu Thu Aug 18 14:52:49 2005 From: alex at mplayerhq.hu (Alex Beregszaszi) Date: Thu, 18 Aug 2005 14:52:49 +0200 (CEST) Subject: [Uha-devel] CVS: uha/lib - New directory Message-ID: <20050818125249.CBE174918A@mail.mplayerhq.hu> Update of /cvsroot/uha/uha/lib In directory mail:/home/alex/uha/uha/lib Log Message: Directory /cvsroot/uha/uha/lib added to the repository From alex at mplayerhq.hu Thu Aug 18 14:52:50 2005 From: alex at mplayerhq.hu (Alex Beregszaszi) Date: Thu, 18 Aug 2005 14:52:50 +0200 (CEST) Subject: [Uha-devel] CVS: uha/super - New directory Message-ID: <20050818125250.206B34918E@mail.mplayerhq.hu> Update of /cvsroot/uha/uha/super In directory mail:/home/alex/uha/uha/super Log Message: Directory /cvsroot/uha/uha/super added to the repository From alex at mplayerhq.hu Thu Aug 18 14:53:01 2005 From: alex at mplayerhq.hu (Alex Beregszaszi) Date: Thu, 18 Aug 2005 14:53:01 +0200 (CEST) Subject: [Uha-devel] CVS: uha/super/linux - New directory Message-ID: <20050818125301.E2CBF4918B@mail.mplayerhq.hu> Update of /cvsroot/uha/uha/super/linux In directory mail:/home/alex/uha/uha/super/linux Log Message: Directory /cvsroot/uha/uha/super/linux added to the repository From alex at mplayerhq.hu Thu Aug 18 14:53:05 2005 From: alex at mplayerhq.hu (Alex Beregszaszi) Date: Thu, 18 Aug 2005 14:53:05 +0200 (CEST) Subject: [Uha-devel] CVS: uha/super/windows - New directory Message-ID: <20050818125305.4049E4918B@mail.mplayerhq.hu> Update of /cvsroot/uha/uha/super/windows In directory mail:/home/alex/uha/uha/super/windows Log Message: Directory /cvsroot/uha/uha/super/windows added to the repository From alex at mplayerhq.hu Thu Aug 18 14:54:02 2005 From: alex at mplayerhq.hu (Alex Beregszaszi) Date: Thu, 18 Aug 2005 14:54:02 +0200 (CEST) Subject: [Uha-devel] CVS: uha ARCHITECTURE, NONE, 1.1 COPYING, NONE, 1.1 NEWS, NONE, 1.1 README, NONE, 1.1 Message-ID: <20050818125402.401C949192@mail.mplayerhq.hu> Update of /cvsroot/uha/uha In directory mail:/home/alex/uha/uha Added Files: ARCHITECTURE COPYING NEWS README Log Message: initial commit --- NEW FILE: ARCHITECTURE --- UHA project architecture ------------------------ In brief: provides direct hardware access in userland. 1, Services: * Ports: native ports input/output * PCI: general layer for PCI communication * Memory remapping: for using regions via userland privileges * DMA: for speed * MTRR: again for speed * CPU/Cache flush * IRQ handling 2, Architecture: .----------------------. | Userland application | |----------------------| | DHA library | |----------------------| | Platform/OS specific | | privileged driver | |----------------------| | System | `----------------------' 3, Practical uses of this: * providing proprietary drivers for open source systems, without the need of writing a kernel wrapper or a kernel version dependant driver * userland drivers for special purpose 4, Already using it: * VIDIX accelerated video driver project (http://vidix.sf.net/) 5, Possible users: * X DRI/DRM * proprietary SDKs --- NEW FILE: COPYING --- GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc. 675 Mass Ave, Cambridge, MA 02139, 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 Appendix: 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) 19yy 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., 675 Mass Ave, Cambridge, MA 02139, 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) 19yy 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. --- NEW FILE: NEWS --- Version 0.1 * Go public --- NEW FILE: README --- Userland Hardware Access ======================== 1, Intro This library was designed for providing direct hardware access under different operating systems and architectures, so it is platform- and os-independent. It originates from MPlayer's sub-project VIDIX, but later has been forked, developed independently, and now rewritten and merged the forks. 2, Supported systems For the full list of supported OS'es read the sources, anyway here is a 'reported as working' list (these platforms are used daily): * Linux 2.2.x/2.4.x/2.6.x on x86/ppc * FreeBSD on x86 * NetBSD on x86 * Windows NT/2000/XP on x86 3, How to use There are different ways to access the hardware, normally only ROOT can do that. With root privileges libdha will run fine, but there are some others ways to use it as a normal user: 1, set the SUID bit on the binary (in this way it runs with root privileges) 2, use svgalib kernel helper 3, use dhahelper (not yet finished) 4, Notes The main project on the top of libuha is VIDIX. It provides userspace video drivers for Matrox, Ati, 3Dlabs, Trident (and it's still evolving). The original library was based on XFree86 and gfxdump (a utility from the GATOS project) sources. 5, Authors Alex Beregszaszi * uha design * original libdha design * dhahelper Nick Kurshev * original libdha design * forked VIDIX project Sascha Sommer * Windows port Matan Ziv-av * svgalib helper From alex at mplayerhq.hu Thu Aug 18 14:54:02 2005 From: alex at mplayerhq.hu (Alex Beregszaszi) Date: Thu, 18 Aug 2005 14:54:02 +0200 (CEST) Subject: [Uha-devel] CVS: uha/lib HEADER, NONE, 1.1 Makefile, NONE, 1.1 bswap.h, NONE, 1.1 config.h, NONE, 1.1 config.mak, NONE, 1.1 exported.c, NONE, 1.1 iopl.c, NONE, 1.1 linux_proc.c, NONE, 1.1 mtrr.c, NONE, 1.1 pci.c, NONE, 1.1 pci.db, NONE, 1.1 pci.h, NONE, 1.1 pci_db2c.awk, NONE, 1.1 pci_helper.c, NONE, 1.1 pci_helper.h, NONE, 1.1 ports.c, NONE, 1.1 svgahelper.c, NONE, 1.1 uha.h, NONE, 1.1 uha_test.c, NONE, 1.1 Message-ID: <20050818125402.D21244918E@mail.mplayerhq.hu> Update of /cvsroot/uha/uha/lib In directory mail:/home/alex/uha/uha/lib Added Files: HEADER Makefile bswap.h config.h config.mak exported.c iopl.c linux_proc.c mtrr.c pci.c pci.db pci.h pci_db2c.awk pci_helper.c pci_helper.h ports.c svgahelper.c uha.h uha_test.c Log Message: initial commit --- NEW FILE: HEADER --- /* * UHA exported functions * Copyright (c) 2005 Alex Beregszaszi * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ /** * @file exported.c * @brief * UHA exported functions * @author Alex Beregszaszi */ --- NEW FILE: Makefile --- include config.mak NAME = libuha MAJOR_VERSION = 0 MINOR_VERSION = 1 VERSION = $(MAJOR_VERSION).$(MINOR_VERSION) ifeq ($(TARGET_OS),CYGWIN) SHORTNAME = $(NAME).dll else SHORTNAME = $(NAME).so.$(MAJOR_VERSION) SONAME_FLAGS = -Wl,-soname,$(SHORTNAME) VSHORTNAME = $(NAME).so endif ifeq ($(TARGET_WIN32),yes) LIBNAME = $(NAME).a SHORTNAME = $(NAME).a else LIBNAME = $(NAME).so.$(VERSION) endif SRCS = pci_names.c exported.c iopl.c mtrr.c pci.c ports.c svgahelper.c linux_proc.c OBJS = $(SRCS:.c=.o) CFLAGS = $(OPTFLAGS) -fPIC -I. -I.. -g3 LIBS = ifeq ($(TARGET_OS),OpenBSD) ifeq ($(TARGET_ARCH_X86),yes) LIBS += -li386 endif endif # If you want libdha to use svgalib_helper for hardware access, # uncomment this statement, and change the -I to the correct directory # that includes svgalib_helper.o: ifneq ($(wildcard svgalib_helper),) CFLAGS += -DDEV_SVGA=\"/dev/svga\" -DCONFIG_SVGAHELPER -Isvgalib_helper/ endif .SUFFIXES: .c .o # .PHONY: all clean .c.o: pci_names.c $(CC) -c $(CFLAGS) -o $@ $< $(LIBNAME): $(OBJS) ifeq ($(TARGET_WIN32),yes) $(AR) r $(LIBNAME) $(OBJS) else #$(CC) -shared $(SONAME_FLAGS) -o $(LIBNAME) $(OBJS) $(LIBS) $(CC) -shared -Wl,-soname -Wl,$(LIBNAME) -o $(LIBNAME) $(OBJS) $(LIBS) ln -sf $(LIBNAME) $(SHORTNAME) ln -sf $(LIBNAME) $(VSHORTNAME) endif libuha.a: $(AR) r libuha.a $(OBJS) uha_test: uha_test.c $(LIBNAME) libuha.a $(RM) libuha.a $(AR) r libuha.a $(OBJS) $(CC) -o uha_test uha_test.c $(NAME).a all: $(LIBNAME) $(SHORTNAME) uha_test pci_names.c: LC_ALL=C $(AWK) -f pci_db2c.awk pci.db clean: rm -f *.o *.so *.so.* *~ distclean: rm -f Makefile.bak *.o *.so *.so.* test *~ .depend rm -f pci_dev_ids.c pci_ids.h pci_names.c pci_names.h pci_vendors.h dep: depend depend: pci_names.c $(CC) -MM $(CFLAGS) $(SRCS) 1>.depend install: mkdir -p $(LIBDIR) install -m 755 -s -p $(LIBNAME) $(LIBDIR)/$(LIBNAME) rm -f $(LIBDIR)/$(NAME).so ln -sf $(LIBNAME) $(LIBDIR)/$(SHORTNAME) ifeq ($(TARGET_OS),OpenBSD) ldconfig -R else ldconfig endif uninstall: rm -f $(LIBDIR)/$(NAME).so $(LIBDIR)/$(SHORTNAME) $(LIBDIR)/$(LIBNAME) ifeq ($(TARGET_OS),OpenBSD) ldconfig -R else ldconfig endif # # include dependency files if they exist # ifneq ($(wildcard .depend),) include .depend endif --- NEW FILE: bswap.h --- // FIXME // License: GPL // From: MPlayer #ifndef __BSWAP_H__ #define __BSWAP_H__ #ifdef HAVE_BYTESWAP_H #include #else #include #ifdef ARCH_X86_64 # define LEGACY_REGS "=Q" #else # define LEGACY_REGS "=q" #endif #if defined(ARCH_X86) || defined(ARCH_X86_64) static inline uint16_t ByteSwap16(uint16_t x) { __asm("xchgb %b0,%h0" : LEGACY_REGS (x) : "0" (x)); return x; } #define bswap_16(x) ByteSwap16(x) static inline uint32_t ByteSwap32(uint32_t x) { #if __CPU__ > 386 __asm("bswap %0": "=r" (x) : #else __asm("xchgb %b0,%h0\n" " rorl $16,%0\n" " xchgb %b0,%h0": LEGACY_REGS (x) : #endif "0" (x)); return x; } #define bswap_32(x) ByteSwap32(x) static inline uint64_t ByteSwap64(uint64_t x) { #ifdef ARCH_X86_64 __asm("bswap %0": "=r" (x) : "0" (x)); return x; #else register union { __extension__ uint64_t __ll; uint32_t __l[2]; } __x; asm("xchgl %0,%1": "=r"(__x.__l[0]),"=r"(__x.__l[1]): "0"(bswap_32((unsigned long)x)),"1"(bswap_32((unsigned long)(x>>32)))); return __x.__ll; #endif } #define bswap_64(x) ByteSwap64(x) #elif defined(ARCH_SH4) static inline uint16_t ByteSwap16(uint16_t x) { __asm__("swap.b %0,%0":"=r"(x):"0"(x)); return x; } static inline uint32_t ByteSwap32(uint32_t x) { __asm__( "swap.b %0,%0\n" "swap.w %0,%0\n" "swap.b %0,%0\n" :"=r"(x):"0"(x)); return x; } #define bswap_16(x) ByteSwap16(x) #define bswap_32(x) ByteSwap32(x) static inline uint64_t ByteSwap64(uint64_t x) { union { uint64_t ll; struct { uint32_t l,h; } l; } r; r.l.l = bswap_32 (x); r.l.h = bswap_32 (x>>32); return r.ll; } #define bswap_64(x) ByteSwap64(x) #else #define bswap_16(x) (((x) & 0x00ff) << 8 | ((x) & 0xff00) >> 8) // code from bits/byteswap.h (C) 1997, 1998 Free Software Foundation, Inc. #define bswap_32(x) \ ((((x) & 0xff000000) >> 24) | (((x) & 0x00ff0000) >> 8) | \ (((x) & 0x0000ff00) << 8) | (((x) & 0x000000ff) << 24)) static inline uint64_t ByteSwap64(uint64_t x) { union { uint64_t ll; uint32_t l[2]; } w, r; w.ll = x; r.l[0] = bswap_32 (w.l[1]); r.l[1] = bswap_32 (w.l[0]); return r.ll; } #define bswap_64(x) ByteSwap64(x) #endif /* !ARCH_X86 */ #endif /* !HAVE_BYTESWAP_H */ // be2me ... BigEndian to MachineEndian // le2me ... LittleEndian to MachineEndian #ifdef WORDS_BIGENDIAN #define be2me_16(x) (x) #define be2me_32(x) (x) #define be2me_64(x) (x) #define le2me_16(x) bswap_16(x) #define le2me_32(x) bswap_32(x) #define le2me_64(x) bswap_64(x) #else #define be2me_16(x) bswap_16(x) #define be2me_32(x) bswap_32(x) #define be2me_64(x) bswap_64(x) #define le2me_16(x) (x) #define le2me_32(x) (x) #define le2me_64(x) (x) #endif #endif /* __BSWAP_H__ */ --- NEW FILE: config.h --- #ifndef _CONFIG_H #define _CONFIG_H #undef CONFIG_DHAHELPER #endif /* _CONFIG_H */ --- NEW FILE: config.mak --- AR = ar CC = gcc AWK = awk TAGRET_ARCH_X86 = yes TARGET_OS = Linux --- NEW FILE: exported.c --- /* * UHA exported functions * Copyright (c) 2005 Alex Beregszaszi * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ /** * @file exported.c * @brief * UHA exported functions * @author Alex Beregszaszi */ #include "uha.h" /** * allocates memory for the context with malloc */ uha_context *uha_allocate(void) { return malloc(sizeof(uha_context)); } /** * deallocates memory of the context with free * @param the context pointer */ void uha_deallocate(uha_context *c) { free(c); } /** * initializes the context * @param context handler, you need to allocate it */ static int uha_probe(uha_context *c) { int fd, flags = UHA_FLAG_BASIC; #ifdef CONFIG_UHAHELPER if (uha_probe_uhahelper(c) == UHA_OK) flags |= UHA_FLAG_UHAHELPER; #endif #ifdef CONFIG_SVGAHELPER if (uha_probe_svgahelper(c) == UHA_OK) flags |= UHA_FLAG_SVGAHELPER; #endif #ifdef CONFIG_DHAHELPER if (uha_probe_dhahelper(c) == UHA_OK) flags |= UHA_FLAG_DHAHELPER; #endif if (uha_probe_iopl(c) == UHA_OK) flags |= UHA_FLAG_IOPL; return flags; } int uha_dummy_error() { return UHA_ERROR; } int uha_dummy_ok() { return UHA_OK; } int uha_init(uha_context *c) { // init everything with uha_dummy_error c->enable_io = uha_dummy_error; c->flags = uha_probe(c); if (c->flags & UHA_FLAG_IOPL) uha_init_iopl(c); uha_init_ports(c); uha_linux_proc(c); if (uha_probe_pci(c) == UHA_OK) uha_init_pci(c); #ifdef CONFIG_SVGAHELPER if (c->flags & UHA_FLAG_SVGAHELPER) uha_init_svgahelper(c); #endif } /** * deinitializes the context * @param context handler, you need to free it */ int uha_exit(uha_context *c) { } --- NEW FILE: iopl.c --- /* * iopl() support * Copyright (c) 2005 Alex Beregszaszi * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ /** * @file iopl.c * @brief * iopl() support * @author Alex Beregszaszi */ #include "uha.h" #ifdef __linux__ #if defined(__i386__) #include #elif defined(__sparc__) || defined(__powerpc__) #define iopl(x) (0) #elif #include #endif #elif defined(__NetBSD__) || defined(__OpenBSD__) #include #endif static int enable_io(uha_context *c) { #ifdef __linux__ if (!iopl(3)) return UHA_OK; #elif defined(__NetBSD__) || defined(__OpenBSD__) if (!i386_iopl(1)) return UHA_OK; #endif return UHA_ERROR; } static int disable_io(uha_context *c) { #ifdef __linux__ if (!iopl(0)) return UHA_OK; #elif defined(__NetBSD__) || defined(__OpenBSD__) if (!i386_iopl(0)) return UHA_OK; #endif return UHA_ERROR; } int uha_probe_iopl(uha_context *c) { if (enable_io(c) == UHA_OK) { disable_io(c); return UHA_OK; } return UHA_ERROR; } int uha_init_iopl(uha_context *c) { c->enable_io = enable_io; c->disable_io = disable_io; return UHA_OK; } --- NEW FILE: linux_proc.c --- /* * PCI access through Linux /proc * Copyright (c) 2004 Colin Leroy * Copyright (c) 2005 Alex Beregszaszi * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ /** * @file linux_proc.c * @brief * PCI access through Linux /proc * @author Colin Leroy , Alex Beregszaszi */ #include #include #include "uha.h" #include "bswap.h" #ifdef __linux__ static int pci_proc_read32(uha_context *c, int bus, int dev, int func, int cmd) { char path[256]; int fd; uint32_t ret = 0; snprintf(path, 256, "/proc/bus/pci/%02d/%02x.0", bus, dev); if ((fd = open(path, O_RDONLY|O_SYNC)) != -1) if (pread(fd, &ret, 4, cmd) == 4) ret = le2me_32(ret); if (fd > 0) close (fd); return ret; } #endif int uha_linux_proc(uha_context *c) { #ifdef __linux__ c->pci_config_type = 1; // assume... c->pci_read32 = pci_proc_read32; c->pci_write32 = uha_dummy_error; #else c->pci_config_type = -1; #endif return UHA_OK; } --- NEW FILE: mtrr.c --- /* * MTRR support * Copyright (c) 2002 Nick Kurshev * Copyright (c) 2005 Alex Beregszaszi * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ /** * @file mtrr.c * @brief * MTRR support * @author Alex Beregszaszi */ #include "config.h" #include "uha.h" #include #include #include #include #include #include #ifdef CONFIG_DHAHELPER #include "kernelhelper/dhahelper.h" #include "libdha.h" #endif #if defined (__i386__) && defined (__NetBSD__) #include #if __NetBSD_Version__ > 105240000 #include #include #include #include #endif #endif #ifdef CONFIG_DHAHELPER int dhahelper_mtrr_set(unsigned base,unsigned size,int type) { int dhahelper_fd; dhahelper_fd = open("/dev/dhahelper",O_RDWR); if(dhahelper_fd > 0) { int retval; dhahelper_mtrr_t mtrrs; mtrrs.operation = MTRR_OP_ADD; mtrrs.start = base; mtrrs.size = size; mtrrs.type = type; retval = ioctl(dhahelper_fd, DHAHELPER_ACK_IRQ, &mtrrs); close(dhahelper_fd); return retval; } #endif #if defined (__NetBSD__) && (__NetBSD_Version__) > 105240000 static int mtrr_set(uha_context *c, int base, int size, int type) { struct mtrr *mtrrp; int n; mtrrp = malloc(sizeof (struct mtrr)); mtrrp->base = base; mtrrp->len = size; mtrrp->type = type; mtrrp->flags = MTRR_VALID | MTRR_PRIVATE; n = 1; if (i386_set_mtrr(mtrrp, &n) < 0) { free(mtrrp); return errno; } free(mtrrp); return 0; } #elif defined(__linux__) static int mtrr_set(uha_context *c, int base, int size, int type) { FILE * mtrr_fd; char * stype; switch(type) { case MTRR_TYPE_UNCACHABLE: stype = "uncachable"; break; case MTRR_TYPE_WRCOMB: stype = "write-combining"; break; case MTRR_TYPE_WRTHROUGH: stype = "write-through"; break; case MTRR_TYPE_WRPROT: stype = "write-protect"; break; case MTRR_TYPE_WRBACK: stype = "write-back"; break; default: return EINVAL; } mtrr_fd = fopen("/proc/mtrr","wt"); if(mtrr_fd) { char sout[256]; unsigned wr_len; sprintf(sout,"base=0x%08X size=0x%08X type=%s\n",base,size,stype); wr_len = fprintf(mtrr_fd,sout); /*printf("MTRR: %s\n",sout);*/ fclose(mtrr_fd); return wr_len == strlen(sout) ? 0 : EPERM; } } #else static int mtrr_set(uha_context *c) { return UHA_ERROR; } #endif int uha_init_mtrr(uha_context *c) { c->mtrr_set = mtrr_set; return UHA_OK; } --- NEW FILE: pci.c --- /* * PCI access through standard ports * Copyright (c) 2005 Alex Beregszaszi * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ /** * @file pci.c * @brief * PCI access through standard ports * @author Alex Beregszaszi */ #include #include "uha.h" #include "pci.h" static int pci_detect(uha_context *c) { uint8_t tmp1, tmp2; uha_port_write8(c, PCI_MODE2_ENABLE_REG, 0x00); uha_port_write8(c, PCI_MODE2_FORWARD_REG, 0x00); tmp1 = uha_port_read8(c, PCI_MODE2_ENABLE_REG); tmp2 = uha_port_read8(c, PCI_MODE2_FORWARD_REG); if ((tmp1 == 0x00) && (tmp2 == 0x00)) return 2; //< conf type 2 else { uint32_t tmpl1, tmpl2; tmpl1 = uha_port_read32(c, PCI_MODE1_ADDRESS_REG); uha_port_write32(c, PCI_MODE1_ADDRESS_REG, PCI_EN); tmpl2 = uha_port_read32(c, PCI_MODE1_ADDRESS_REG); uha_port_write32(c, PCI_MODE1_ADDRESS_REG, tmpl1); if (tmpl2 == PCI_EN) return 1; //< conf type 1 } return -1; //< no pci } #define pci_mode1_select(c, bus, dev, func, cmd) \ uha_port_write32(c, PCI_MODE1_ADDRESS_REG, \ PCI_EN | (bus<<16) | (dev<<11) | (func<<8) | cmd) static int pci_mode1_read32(uha_context *c, int bus, int dev, int func, int cmd) { pci_mode1_select(c, bus, dev, func, cmd); return uha_port_read32(c, PCI_MODE1_DATA_REG); } static int pci_mode1_write32(uha_context *c, int bus, int dev, int func, int cmd, int value) { pci_mode1_select(c, bus, dev, func, cmd); return uha_port_write32(c, PCI_MODE1_DATA_REG, value); } // FIXME: untested! static int pci_mode2_read32(uha_context *c, int bus, int dev, int func, int cmd) { uint32_t ret; uha_port_write8(c, PCI_MODE2_ENABLE_REG, 0xF1); uha_port_write8(c, PCI_MODE2_FORWARD_REG, bus); ret = uha_port_read32(c, 0xc000+(dev*0x100)); uha_port_write8(c, PCI_MODE2_ENABLE_REG, 0x00); return ret; } static int pci_mode2_write32(uha_context *c, int bus, int dev, int func, int cmd, int value) { uint32_t ret; uha_port_write8(c, PCI_MODE2_ENABLE_REG, 0xF1); uha_port_write8(c, PCI_MODE2_FORWARD_REG, bus); ret = uha_port_write32(c, 0xc000+(dev*0x100), value); uha_port_write8(c, PCI_MODE2_ENABLE_REG, 0x00); return ret; } int uha_probe_pci(uha_context *c) { if (!uha_is_port(c) || !uha_is_io(c)) return UHA_ERROR; uha_enable_io(c); if (pci_detect(c) < 0) return UHA_ERROR; return UHA_OK; } int uha_init_pci(uha_context *c) { c->pci_config_type = pci_detect(c); if (c->pci_config_type == 1) { c->pci_read32 = pci_mode1_read32; c->pci_write32 = pci_mode1_write32; } else if (c->pci_config_type == 2) { // uha_log("PCI Mode2 support untested, take care!\n"); c->pci_read32 = pci_mode2_read32; c->pci_write32 = pci_mode2_write32; } return UHA_OK; } --- NEW FILE: pci.db --- v 0000 Gammagraphx, Inc. 0 v 001a Ascend Communications, Inc. 0 v 0033 Paradyne corp. 0 v 003d Lockheed Martin-Marietta Corp 0 v 0059 Tiger Jet Network Inc. (Wrong ID) 0 Real TJN ID is e159, but they got it wrong several times --mj v 0070 Hauppauge computer works Inc. 0 d 00704000 WinTV PVR-350 0 d 00704001 WinTV PVR-250 (v1) 0 d 00704009 WinTV PVR-250 0 d 00704801 WinTV PVR-250 MCE 0 v 0071 Nebula Electronics Ltd. 0 v 0095 Silicon Image, Inc. (Wrong ID) 0 d 00950680 Ultra ATA/133 IDE RAID CONTROLLER CARD 0 v 0100 Ncipher Corp Ltd 0 v 018a LevelOne 0 018a is not LevelOne but there is a board misprogrammed d 018a0106 FPC-0106TX misprogrammed [RTL81xx] 0 v 021b Compaq Computer Corporation 0 021b is not Compaq but there is a board misprogrammed d 021b8139 HNE-300 (RealTek RTL8139c) [iPaq Networking] 0 v 0280 1 Unknown. Found as an subsystem vendor for Tvia Cyberpro on the Fujitsu-Siemens Activy 3xx [...10234 lines suppressed...] d f1d0cafe Kona SD 1 Updated - Kona and Xena have different PCI IDs d f1d0cfee Xena LS/SD-22-DA/SD-DA 1 d f1d0dcaf Kona HD 1 Updated - Kona and Xena have different PCI IDs d f1d0dfee Xena HD-DA 1 d f1d0efac KONA SD SMPTE 259M I/O 0 d f1d0efac Xena SD-MM/SD-22-MM 1 d f1d0facd KONA HD SMPTE 292M I/O 0 d f1d0facd Xena HD-MM 1 Updated - Kona and Xena have different PCI IDs v fa57 Interagon AS 0 d fa570001 PMC [Pattern Matching Chip] 0 v febd Ultraview Corp. 0 v feda Broadcom Inc (nee Epigram) 0 d fedaa0fa BCM4210 iLine10 HomePNA 2.0 0 d fedaa10e BCM4230 iLine10 HomePNA 2.0 0 v fede Fedetec Inc. 0 IT & Telecom company, develops PCI Trunk cards d fede0003 TABIC PCI v3 0 v fffe VMWare Inc 0 d fffe0405 Virtual SVGA 4.0 0 d fffe0710 Virtual SVGA 0 v ffff Illegal Vendor ID 0 --- NEW FILE: pci.h --- #ifndef _UHA_PCI_H #define _UHA_PCI_H 1 #ifdef __alpha__ #define PCI_EN 0x00000000 #else #define PCI_EN 0x80000000 #endif #define PCI_MODE1_ADDRESS_REG 0xcf8 #define PCI_MODE1_DATA_REG 0xcfc #define PCI_MODE2_ENABLE_REG 0xcf8 #define PCI_MODE2_FORWARD_REG 0xcfa #endif --- NEW FILE: pci_db2c.awk --- # This file converts given pci.db to "C" source and header files # For latest version of pci ids see: http://pciids.sf.net # Copyright 2002 Nick Kurshev # # Usage: awk -f pci_db2c.awk pci.db # # Tested with Gawk v 3.0.x and Mawk 1.3.3 # But it should work with standard Awk implementations (hopefully). # (Nobody tested it with Nawk, but it should work, too). # BEGIN { if(ARGC != 2) { # check for arguments: print "Usage awk -f pci_db2c.awk pci.db (and make sure pci.db file exists first)"; exit(1); } in_file = ARGV[1]; vendor_file = "pci_vendors.h"; ids_file = "pci_ids.h" name_file = "pci_names.c" name_h_file = "pci_names.h" dev_ids_file = "pci_dev_ids.c" line=0; # print out head lines print_head(vendor_file); print_head(ids_file); print_head(name_file); print_head(name_h_file); print_head(dev_ids_file); print "#ifndef PCI_VENDORS_INCLUDED" >vendor_file print "#define PCI_VENDORS_INCLUDED 1">vendor_file print "" >vendor_file print "#ifndef PCI_IDS_INCLUDED" >ids_file print "#define PCI_IDS_INCLUDED 1">ids_file print "" >ids_file print "#include \"pci_vendors.h\"">ids_file print "" >ids_file print "#ifndef PCI_NAMES_INCLUDED" >name_h_file print "#define PCI_NAMES_INCLUDED 1">name_h_file print "" >name_h_file print_name_struct(name_h_file); print "#include ">name_file print "#include \"pci_names.h\"">name_file print "#include \"pci_dev_ids.c\"">name_file print "">name_file print "static struct vendor_id_s vendor_ids[] = {">name_file first_pass=1; init_name_db(); while(getline 0 && field[4] == "0") { init_device_db() svend_name = get_short_vendor_name(field[3]) printf("#define VENDOR_%s\t", svend_name) >vendor_file; if(length(svend_name) < 9) printf("\t") >vendor_file; printf("0x%s /*%s*/\n",field[2], name_field) >vendor_file; printf("{ 0x%s, \"%s\", dev_lst_%s },\n",field[2], name_field, field[2]) >name_file; printf("/* Vendor: %s: %s */\n", field[2], name_field) > ids_file if(first_pass == 1) { first_pass=0; } else { print "{ 0xFFFF, NULL }\n};" >dev_ids_file; } printf("static const struct device_id_s dev_lst_%s[]={\n", field[2])>dev_ids_file } if(field[1] == "d" && length(field[3])>0 && field[4] == "0") { sdev_name = get_short_device_name(field[3]) full_name = sprintf("#define DEVICE_%s_%s", svend_name, sdev_name); printf("%s\t", full_name) >ids_file if(length(full_name) < 9) printf("\t") >ids_file; if(length(full_name) < 17) printf("\t") >ids_file; if(length(full_name) < 25) printf("\t") >ids_file; if(length(full_name) < 32) printf("\t") >ids_file; if(length(full_name) < 40) printf("\t") >ids_file; if(length(full_name) < 48) printf("\t") >ids_file; printf("0x%s /*%s*/\n", substr(field[2], 5), name_field) >ids_file printf("{ 0x%s, \"%s\" },\n", substr(field[2], 5), name_field) >dev_ids_file } if(field[1] == "s" && length(field[3])>0 && field[4] == "0") { subdev_name = get_short_subdevice_name(field[3]) full_name = sprintf("#define SUBDEVICE_%s_%s", svend_name, subdev_name) printf("\t%s\t", full_name) >ids_file if(length(full_name) < 9) printf("\t") >ids_file; if(length(full_name) < 17) printf("\t") >ids_file; if(length(full_name) < 25) printf("\t") >ids_file; if(length(full_name) < 32) printf("\t") >ids_file; if(length(full_name) < 40) printf("\t") >ids_file; printf("0x%s /*%s*/\n", substr(field[2], 9), name_field) >ids_file } } print "Total lines parsed:", line; print "">vendor_file print "#endif/*PCI_VENDORS_INCLUDED*/">vendor_file print "">ids_file print "#endif/*PCI_IDS_INCLUDED*/">ids_file print "">name_h_file print "#endif/*PCI_NAMES_INCLUDED*/">name_h_file print "};">name_file print "{ 0xFFFF, NULL }" >dev_ids_file; print "};">dev_ids_file print_func_bodies(name_file); } function print_head( out_file) { print "/*" >out_file; printf(" * File: %s\n", out_file) >out_file; printf(" * This file was generated automatically. Don't modify it.\n") >out_file; print "*/" >out_file; return; } function print_name_struct(out_file) { print "#ifdef __cplusplus" >out_file print "extern \"C\" {" >out_file print "#endif" >out_file print "">out_file print "struct device_id_s" >out_file print "{" >out_file print "\tunsigned short\tid;" >out_file print "\tconst char *\tname;" >out_file print "};" >out_file print "">out_file print "struct vendor_id_s" >out_file print "{" >out_file print "\tunsigned short\tid;" >out_file print "\tconst char *\tname;" >out_file print "\tconst struct device_id_s *\tdev_list;" >out_file print "};" >out_file print "extern const char *pci_vendor_name(unsigned short id);">out_file print "extern const char *pci_device_name(unsigned short vendor_id, unsigned short device_id);">out_file print "">out_file print "#ifdef __cplusplus" >out_file print "}" >out_file print "#endif" >out_file return } function print_func_bodies(out_file) { print "">out_file print "const char *pci_vendor_name(unsigned short id)" >out_file print "{" >out_file print " unsigned i;" >out_file print " for(i=0;iout_file print " {" >out_file print "\tif(vendor_ids[i].id == id) return vendor_ids[i].name;" >out_file print " }" >out_file print " return NULL;" >out_file print "}">out_file print "" >out_file print "const char *pci_device_name(unsigned short vendor_id, unsigned short device_id)" >out_file print "{" >out_file print " unsigned i, j;" >out_file print " for(i=0;iout_file print " {" >out_file print "\tif(vendor_ids[i].id == vendor_id)" >out_file print "\t{" >out_file print "\t j=0;" >out_file print "\t while(vendor_ids[i].dev_list[j].id != 0xFFFF)" >out_file print "\t {">out_file print "\t\tif(vendor_ids[i].dev_list[j].id == device_id) return vendor_ids[i].dev_list[j].name;">out_file print "\t\tj++;">out_file print "\t };">out_file print "\t break;" >out_file print "\t}" >out_file print " }" >out_file print " return NULL;">out_file print "}">out_file return } function kill_double_quoting(fld) { n=split(fld,phrases, "[\"]"); new_fld = phrases[1] for(i=2;i<=n;i++) new_fld = sprintf("%s\\\"%s", new_fld, phrases[i]) return new_fld } function init_name_db() { vendor_names[1]="" } function init_device_db() { # delete device_names for( i in device_names ) delete device_names[i]; device_names[1]="" # delete subdevice_names for( i in subdevice_names ) delete subdevice_names[i]; subdevice_names[1] = "" } function get_short_vendor_name(from) { n=split(from, name, "[ ]"); new_name = toupper(name[1]); if(length(new_name)<3) new_name = sprintf("%s_%s", new_name, toupper(name[2])); n=split(new_name, name, "[^0-9A-Za-z]"); svendor = name[1]; for(i=2;i<=n;i++) svendor=sprintf("%s%s%s", svendor, length(name[i])?"_":"", name[i]); new_name = svendor; vend_suffix = 2; # check for unique while(new_name in vendor_names) { new_name = sprintf("%s%u", svendor, vend_suffix) vend_suffix = vend_suffix + 1; } # Add new name in array of vendor's names vendor_names[new_name] = new_name return new_name; } function get_short_device_name(from_name) { n=split(from_name, name, "[ ]"); new_name = toupper(name[1]); if(length(name[2])) new_name = sprintf("%s_%s", new_name, toupper(name[2])); if(length(name[3])) new_name = sprintf("%s_%s", new_name, toupper(name[3])); n=split(new_name, name, "[^0-9A-Za-z]"); sdevice = name[1]; for(i=2;i<=n;i++) sdevice=sprintf("%s%s%s", sdevice, length(name[i])?"_":"", name[i]); new_name = sdevice; dev_suffix = 2; # check for unique while(new_name in device_names) { new_name = sprintf("%s%u", sdevice, dev_suffix) dev_suffix = dev_suffix + 1; } # Add new name in array of device names device_names[new_name] = new_name return new_name; } function get_short_subdevice_name(from_name) { n=split(from_name, name, "[ ]"); new_name = toupper(name[1]); if(length(name[2])) new_name = sprintf("%s_%s", new_name, toupper(name[2])); if(length(name[3])) new_name = sprintf("%s_%s", new_name, toupper(name[3])); n=split(new_name, name, "[^0-9A-Za-z]"); ssdevice = name[1]; for(i=2;i<=n;i++) ssdevice=sprintf("%s%s%s", ssdevice, length(name[i])?"_":"", name[i]); new_name = ssdevice; sdev_suffix = 2; # check for unique while(new_name in subdevice_names) { new_name = sprintf("%s%u", ssdevice, sdev_suffix) sdev_suffix = sdev_suffix + 1; } # Add new name in array of subdevice names subdevice_names[new_name] = new_name return new_name; } --- NEW FILE: pci_helper.c --- #include "uha.h" pci_find_device(uha_context *c, int device, int vendor) { uha_context *c = uha_allocate(); uha_init(c); uha_enable_io(c); if (uha_is_pci(c)) { int bus, card, func; for (bus = 0; bus < 4; bus++) for (card = 0; card < 32; card++) for (func = 0; func < 8; func++) { int ret = uha_pci_read32(c, bus, card, func, 0); int vendor = ret & 0xffff, device = (ret >> 16) & 0xffff; if (!vendor && !device) // subfunction not present break; if (vendor != 0xffff && device != 0xffff) printf("device %02x:%02x.%1x: vendor=%x device=%x\n", bus, card, func, vendor, device); } } else { printf("No pci support present - not testing\n"); } uha_exit(c); uha_deallocate(c); } --- NEW FILE: pci_helper.h --- #include typedef struct uha_pci_config_table { union { uint32_t device_vendor; struct { #ifdef WORDS_BIGENDIAN uint16_t device; uint16_t vendor; #else uint16_t vendor; uint16_t device; #endif } u. } a; #define device_vendor a.device_vendor #define vendor a.u.vendor #define device a.u.device union { uint32_t status_command; struct { #ifdef WORDS_BIGENDIAN uint16_t command; uint16_t status; #else uint16_t status; uint16_t command; #endif } u; } b; #define status_command b.status_command #define command b.u.command #define status b.u.status union { uint32_t class_revision; struct { #ifdef WORDS_BIGENDIAN uint8_t base_class; uint8_t sub_class; uint8_t prog_if; uint8_t rev_id; #else uint8_t rev_id; uint8_t prog_if; uint8_t sub_class; uint8_t base_class; #endif } u; } c; #define status_command c.class_revision #define base_class c.u.base_class #define sub_class c.u.sub_class #define prog_if c.u.prog_if #define rev_id c.u.rev_id union { uint32_t header_latency; struct { #ifdef WORDS_BIGENDIAN uint8_t bist; uint8_t header_type; uint8_t latency; uint8_t cl_size; #else uint8_t cl_size; uint8_t latency; uint8_t header_type; uint8_t bist; #endif } u; } d; #define header_latency d.header_latency #define bist d.u.bist #define header_type d.u.header_type #define latency d.u.latency #define cl_size d.u.cl_size //// MISSING uint32_t reserved1; uint32_t reserved2; uint32_t baserom; uint32_t reserved3; uint32_t reserved4; }; --- NEW FILE: ports.c --- /* * Port I/O support * Copyright (c) 2005 Alex Beregszaszi * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ /** * @file ports.c * @brief * Port I/O support * @author Alex Beregszaszi */ #include "uha.h" #if defined(__sparc__) && !defined(ASI_PL) #define ASI_PL 0x88 #endif #if !defined(__i386__) && !defined(__sparc__) #warning "your system is not supported" #endif static int port_write8(uha_context *c, int port, int value) { #if defined(__i386__) __asm__ __volatile__("outb %0, %1" : : "a" ((char)value), "d" ((short)port)); #elif defined(__sparc__) __asm__ __volatile__("stba %0, [%1] %2" : : "r" (value), "r" (port), "i" (ASI_PL)); #endif } static int port_write16(uha_context *c, int port, int value) { #if defined(__i386__) __asm__ __volatile__("outw %0, %1" : : "a" ((short)value), "d" ((short)port)); #elif defined(__sparc__) __asm__ __volatile__("stha %0, [%1] %2" : : "r" (value), "r" (port), "i" (ASI_PL)); #endif } static int port_write32(uha_context *c, int port, int value) { #if defined(__i386__) __asm__ __volatile__("outl %0, %1" : : "a" (value), "d" ((short)port)); #elif defined(__sparc__) __asm__ __volatile__("sta %0, [%1] %2" : : "r" (value), "r" (port), "i" (ASI_PL)); #endif } static int port_read8(uha_context *c, int port) { int ret = 0; #if defined(__i386__) __asm__ __volatile__("inb %1, %0" : "=a" (ret) : "d" ((short)port)); #elif defined(__sparc__) __asm__ __volatile__("lduba [%1] %2, %0" : "=r" (ret) : "r" (port), "i" (ASI_PL)); #endif return ret; } static int port_read16(uha_context *c, int port) { int ret = 0; #if defined(__i386__) __asm__ __volatile__("inw %1, %0" : "=a" (ret) : "d" ((short)port)); #elif defined(__sparc__) __asm__ __volatile__("lduha [%1] %2, %0" : "=r" (ret) : "r" (port), "i" (ASI_PL)); #endif return ret; } static int port_read32(uha_context *c, int port) { int ret = 0; #if defined(__i386__) __asm__ __volatile__("inl %1, %0" : "=a" (ret) : "d" ((short)port)); #elif defined(__sparc__) __asm__ __volatile__("lda [%1] %2, %0" : "=r" (ret) : "r" (port), "i" (ASI_PL)); #endif return ret; } // FIXME uha_probe int uha_init_ports(uha_context *c) { #if !defined(__i386__) && !defined(__sparc__) return UHA_ERROR; #endif c->port_write8 = port_write8; c->port_write16 = port_write16; c->port_write32 = port_write32; c->port_read8 = port_read8; c->port_read16 = port_read16; c->port_read32 = port_read32; return UHA_OK; } --- NEW FILE: svgahelper.c --- /* * svgahelper support * Copyright (c) 2005 Alex Beregszaszi * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ /** * @file svgahelper.c * @brief * svgahelper support * @author Alex Beregszaszi */ #include "uha.h" #ifdef CONFIG_SVGAHELPER #include #include #include #include #ifndef SVGALIB_HELPER_IOC_MAGIC /* svgalib 1.9.18+ compatibility ::atmos */ #define SVGALIB_HELPER_IOCSOUTB SVGAHELPER_OUTB #define SVGALIB_HELPER_IOCSOUTW SVGAHELPER_OUTW #define SVGALIB_HELPER_IOCSOUTL SVGAHELPER_OUTL #define SVGALIB_HELPER_IOCGINB SVGAHELPER_INB #define SVGALIB_HELPER_IOCGINW SVGAHELPER_INW #define SVGALIB_HELPER_IOCGINL SVGAHELPER_INL #define SVGALIB_HELPER_IOCGPCIINB SVGAHELPER_PCIINB #define SVGALIB_HELPER_IOCGPCIINW SVGAHELPER_PCIINW #define SVGALIB_HELPER_IOCGPCIINL SVGAHELPER_PCIINL #endif #define svgahelper_fd c->reserved[0] static int port_write8(uha_context *c, int port, int value) { io_t iov; iov.val = value; iov.port = port; ioctl(svgahelper_fd, SVGALIB_HELPER_IOCSOUTB, &iov); } static int port_write16(uha_context *c, int port, int value) { io_t iov; iov.val = value; iov.port = port; ioctl(svgahelper_fd, SVGALIB_HELPER_IOCSOUTW, &iov); } static int port_write32(uha_context *c, int port, int value) { io_t iov; iov.val = value; iov.port = port; ioctl(svgahelper_fd, SVGALIB_HELPER_IOCSOUTL, &iov); } static int port_read8(uha_context *c, int port) { io_t iov; iov.port = port; ioctl(svgahelper_fd, SVGALIB_HELPER_IOCGINB, &iov); return iov.val; } static int port_read16(uha_context *c, int port) { io_t iov; iov.port = port; ioctl(svgahelper_fd, SVGALIB_HELPER_IOCGINW, &iov); return iov.val; } static int port_read32(uha_context *c, int port) { io_t iov; iov.port = port; ioctl(svgahelper_fd, SVGALIB_HELPER_IOCGINL, &iov); return iov.val; } static int pci_read8(uha_context *c, int bus, int dev, int func, int cmd) { pcic_t p; p.address = cmd; p.pcipos = (bus << 8) | (func << 5) | dev; ioctl(svgahelper_fd, SVGALIB_HELPER_IOCGPCIINB, &p); return p.val; } static int pci_read16(uha_context *c, int bus, int dev, int func, int cmd) { pcic_t p; p.address = cmd; p.pcipos = (bus << 8) | (func << 5) | dev; ioctl(svgahelper_fd, SVGALIB_HELPER_IOCGPCIINW, &p); return p.val; } static int pci_read32(uha_context *c, int bus, int dev, int func, int cmd) { pcic_t p; p.address = cmd; p.pcipos = (bus << 8) | (func << 5) | dev; ioctl(svgahelper_fd, SVGALIB_HELPER_IOCGPCIINL, &p); return p.val; } static void *mem_map(uha_context *c, int base, int size, int write) { #ifdef ARCH_ALPHA base += bus_base(); #endif return mmap(0, size, PROT_READ|(write?PROT_WRITE:0), MAP_SHARED, svgahelper_fd, base); } static void mem_unmap(uha_context *c, void *mem, int size) { munmap(mem, size); } int uha_probe_svgahelper(uha_context *c) { if ((svgahelper_fd = open(DEV_SVGA, O_RDWR)) < 0) return UHA_ERROR; close(svgahelper_fd); return UHA_OK; } int uha_init_svgahelper(uha_context *c) { if ((svgahelper_fd = open(DEV_SVGA, O_RDWR)) < 0) return UHA_ERROR; uha_log("opened svgahelper\n"); c->enable_io = c->disable_io = uha_dummy_ok; c->port_write8 = port_write8; c->port_write16 = port_write16; c->port_write32 = port_write32; c->port_read8 = port_read8; c->port_read16 = port_read16; c->port_read32 = port_read32; c->pci_read8 = pci_read8; c->pci_read16 = pci_read16; c->pci_read32 = pci_read32; c->mem_map = mem_map; c->mem_unmap = mem_unmap; return UHA_OK; } #endif /* CONFIG_SVGAHELPER */ --- NEW FILE: uha.h --- /* * UHA header * Copyright (c) 2005 Alex Beregszaszi * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ /** * @file uha.h * @brief * UHA header * @author Alex Beregszaszi */ #ifndef _UHA_H #define _UHA_H 1 #include "config.h" #define uha_log printf // FIXME #define UHA_ERROR -1 #define UHA_OK 0 #define UHA_FLAG_BASIC 0x0 //< dummy/default #define UHA_FLAG_IOPL 0x1 //< iopl() support #define UHA_FLAG_SVGAHELPER 0x2 #define UHA_FLAG_DHAHELPER 0x4 #define UHA_FLAG_UHAHELPER 0x8 typedef struct uha_context { int flags; // for internal use // slot0: svgahelper // slot1: dhahelper // slot2: uhahelper int reserved[7]; // exported funcs // iopl.c int (*enable_io)(struct uha_context *c); int (*disable_io)(struct uha_context *c); // mtrr.c //< FIXME: mtrr_get ? int (*mtrr_set)(struct uha_context *c, int base, int size, int type); // ports.c int (*port_read8)(struct uha_context *c, int port); int (*port_read16)(struct uha_context *c, int port); int (*port_read32)(struct uha_context *c, int port); int (*port_write8)(struct uha_context *c, int port, int value); int (*port_write16)(struct uha_context *c, int port, int value); int (*port_write32)(struct uha_context *c, int port, int value); // pci.c int (*pci_read8)(struct uha_context *c, int bus, int dev, int func, int cmd); int (*pci_read16)(struct uha_context *c, int bus, int dev, int func, int cmd); int (*pci_read32)(struct uha_context *c, int bus, int dev, int func, int cmd); int (*pci_write8)(struct uha_context *c, int bus, int dev, int func, int cmd, int value); int (*pci_write16)(struct uha_context *c, int bus, int dev, int func, int cmd, int value); int (*pci_write32)(struct uha_context *c, int bus, int dev, int func, int cmd, int value); int pci_config_type; // mem.c // user->kernel, virtual->physical translations int (*mem_map)(struct uha_context *c, int base, int size, int write); int (*mem_unmap)(struct uha_context *c, void *mem, int size); // interrupt.c // irq disable/enable, irq install/wait/uninstall } uha_context; int uha_dummy_ok(); int uha_dummy_error(); int uha_init(uha_context *c); int uha_exit(uha_context *c); #define uha_is_io(c) (c->enable_io && c->disable_io) #define uha_is_mtrr(c) (c->mtrr_set) #define uha_is_port(c) (c->port_read8 && c->port_read16 && c->port_read32 && \ c->port_write8 && c->port_write16 && c->port_write32) #define uha_is_pci_read(c) (c->pci_config_type != -1 && c->pci_read32) #define uha_is_pci_write(c) (c->pci_config_type != -1 && c->pci_write32) #define uha_is_pci(c) (c->pci_config_type != -1 && c->pci_read32 && c->pci_write32) #define uha_is_mem(c) (c->mem_map && c->mem_unmap) #define uha_enable_io(c) c->enable_io(c) #define uha_disable_io(c) c->disable_io(c) #define uha_mtrr_set(c, base, size, type) c->mtrr_set(c, base, size, type) #define uha_port_read8(c, port) c->port_read8(c, port) #define uha_port_read16(c, port) c->port_read16(c, port) #define uha_port_read32(c, port) c->port_read32(c, port) #define uha_port_write8(c, port, value) c->port_write8(c, port, value) #define uha_port_write16(c, port, value) c->port_write16(c, port, value) #define uha_port_write32(c, port, value) c->port_write32(c, port, value) #define uha_pci_read32(c, bus, dev, func, cmd) c->pci_read32(c, bus, dev, func, cmd) #define uha_pci_write32(c, bus, dev, func, cmd, value) c->pci_write32(c, bus, dev, func, cmd, value) #define uha_pci_get_vendor(c, bus, dev, func) c->pci_read32(c, bus, dev, func, 0) #define uha_pci_config_type(c) c->pci_config_type #define uha_mem_map(c, base, size) c->mem_map(c, base, size) #define uha_mem_unmap(c, mem, size) c->mem_unmap(c, mem, size) // FIXME #define MTRR_TYPE_UNCACHABLE 1 #define MTRR_TYPE_WRCOMB 2 #define MTRR_TYPE_WRTHROUGH 3 #define MTRR_TYPE_WRPROT 4 #define MTRR_TYPE_WRBACK 5 #endif /* _UHA_H */ --- NEW FILE: uha_test.c --- #include "uha.h" main() { uha_context *c = uha_allocate(); uha_init(c); uha_enable_io(c); if (uha_is_pci_read(c)) { int bus, card, func = 0; int ret = uha_pci_read32(c, 0, 0, 0, 0); int ret2 = ret|1; uha_pci_write32(c, 0, 0, 0, 0, ret2); int ret3 = uha_pci_read32(c, 0, 0, 0, 0); printf("%x %x -> %x\n", ret, ret2, ret3); for (bus = 0; bus < 4; bus++) for (card = 0; card < 32; card++) // for (func = 0; func < 8; func++) { int ret = uha_pci_read32(c, bus, card, func, 0); int vendor = ret & 0xffff, device = (ret >> 16) & 0xffff; if (!vendor && !device) // subfunction not present break; if (vendor != 0xffff && device != 0xffff) printf("device %02x:%02x.%1x: vendor=%x device=%x\n", bus, card, func, vendor, device); } } else { printf("No pci support present - not testing\n"); } uha_exit(c); uha_deallocate(c); } From alex at mplayerhq.hu Thu Aug 18 14:54:03 2005 From: alex at mplayerhq.hu (Alex Beregszaszi) Date: Thu, 18 Aug 2005 14:54:03 +0200 (CEST) Subject: [Uha-devel] CVS: uha/super/linux Makefile, NONE, 1.1 README, NONE, 1.1 dhahelper.c, NONE, 1.1 dhahelper.h, NONE, 1.1 duha-helper.c, NONE, 1.1 duha-helper.h, NONE, 1.1 test.c, NONE, 1.1 Message-ID: <20050818125403.736C2491A1@mail.mplayerhq.hu> Update of /cvsroot/uha/uha/super/linux In directory mail:/home/alex/uha/uha/super/linux Added Files: Makefile README dhahelper.c dhahelper.h duha-helper.c duha-helper.h test.c Log Message: initial commit --- NEW FILE: Makefile --- KERNEL_VERSION = $(shell uname -r) KERNEL_DIR = /lib/modules/$(KERNEL_VERSION)/build MDIR = /lib/modules/$(KERNEL_VERSION)/misc ifeq ($(findstring 2.6.,$(KERNEL_VERSION)),2.6.) MODULE = dhahelper.ko obj-m = dhahelper.o all: @echo Please ignore warnings about overriding SUBDIRS $(MAKE) -C $(KERNEL_DIR) SUBDIRS=$(PWD) modules else KERNEL_INCLUDES = $(KERNEL_DIR)/include INCLUDES = -I$(KERNEL_INCLUDES) CFLAGS = -O2 -Wall -D__KERNEL__ -DMODULE -fomit-frame-pointer -fno-common -fno-strict-aliasing MODULE = dhahelper.o all: $(MODULE) test dhahelper.o: dhahelper.c dhahelper.h $(CC) $(CFLAGS) $(INCLUDES) -c $(basename $@).c endif test: test.c $(CC) -g -O -Wall $(INCLUDES) -o $@ $@.c install: $(MODULE) test -d $(MDIR) || mkdir -p $(MDIR) install -m 644 $(MODULE) $(MDIR) depmod -a if [ ! -c /dev/.devfsd ]; then \ rm -f /dev/dhahelper; \ mknod -m 600 /dev/dhahelper c 252 0; \ fi nodes: @echo make nodes is obsolete. dep: clean: rm -f *.o *~ *.mod.* *.ko distclean: clean rm -f test --- NEW FILE: README --- dhahelper is small driver to provide some kernel function into userspace. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The main reason you need to use dhahelper is for busmastering. (Btw, lacking of possibility to implement conversion of virtual addresses into physical in userspace caused implementing of so-called DRM drivers for Linux from XFree86 side). Second goal (still is unfinished) - provide possibility to control port and physical memory access through groups and access rights of this driver. (Unix way). Installation: ~~~~~~~~~~~~~ just type in this directory: make all install The device node /dev/dhahelper will be created. The initial permissions of this node are restrictive. See below for information on how to make it available to non-root users. Porting: ~~~~~~~~ This driver was developed only for Linux. So if someone will port that on other unices then any patches are gladly accepted. WARNING: ~~~~~~~~ This driver violates some kernel security rules. To keep this driver from anonymous access I suggest you create a new group (e.g. dha) for /dev/dhahelper and set the permissions to 660 (or ug+rw,o-rw). Then do one of the following: - add trusted users to group dha. - make trusted applications SGID to dha. Good luck! --- NEW FILE: dhahelper.c --- /* Direct Hardware Access kernel helper (C) 2002 Alex Beregszaszi (C) 2002-2003 Nick Kurshev (C) 2002-2004 M?ns Rullg?rd Accessing hardware from userspace as USER (no root needed!) Tested on 2.2.x (2.2.19), 2.4.x (2.4.3,2.4.17) and 2.6.1. License: GPL WARNING! THIS MODULE VIOLATES SEVERAL SECURITY LINES! DON'T USE IT ON PRODUCTION SYSTEMS, ONLY AT HOME, ON A "SINGLE-USER" SYSTEM. NO WARRANTY! IF YOU WANT TO USE IT ON PRODUCTION SYSTEMS THEN PLEASE READ 'README' FILE TO KNOW HOW TO PREVENT ANONYMOUS ACCESS TO THIS MODULE. [...1200 lines suppressed...] #else static void __exit exit_dhahelper(void) #endif { unsigned i; for(i=0;i<256;i++) if(dha_irqs[i].handled) free_irq(i, dha_irqs[i].dev); unregister_dev(); } #ifdef EXPORT_NO_SYMBOLS EXPORT_NO_SYMBOLS; #endif #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0) module_init(init_dhahelper); module_exit(exit_dhahelper); #endif --- NEW FILE: dhahelper.h --- /* Direct Hardware Access kernel helper (C) 2002 Alex Beregszaszi (C) 2002-2003 Nick Kurshev */ #ifndef DHAHELPER_H #define DHAHELPER_H #include /* feel free to change */ #define DEFAULT_MAJOR 252 /* 240-254 LOCAL/EXPERIMENTAL USE */ #define API_VERSION 0x30 /* 3.0*/ typedef struct dhahelper_port_s { #define PORT_OP_READ 1 #define PORT_OP_WRITE 2 int operation; int size; int addr; // FIXME - switch to void* (64bit) int value; } dhahelper_port_t; typedef struct dhahelper_mtrr_s { #define MTRR_OP_ADD 1 #define MTRR_OP_DEL 2 int operation; long start; long size; int type; int privat; } dhahelper_mtrr_t; typedef struct dhahelper_pci_config_s { #define PCI_OP_READ 0 #define PCI_OP_WRITE 1 int operation; int bus; int dev; int func; int cmd; int size; long ret; } dhahelper_pci_config_t; typedef struct dhahelper_vmi_s { void * virtaddr; unsigned long length; unsigned long *realaddr; }dhahelper_vmi_t; typedef struct dhahelper_mem_s { void * addr; unsigned long length; }dhahelper_mem_t; typedef struct dhahelper_irq_s { unsigned num; int bus, dev, func; int ack_region; unsigned long ack_offset; unsigned int ack_data; }dhahelper_irq_t; typedef struct dhahelper_cpu_flush_s { void *va; unsigned long length; }dhahelper_cpu_flush_t; typedef struct dhahelper_pci_device_s { int bus,card,func; /* PCI/AGP bus:card:func */ unsigned short vendor,device; /* Card vendor+device ID */ unsigned long base0,base1,base2,baserom; /* Memory and I/O base addresses */ unsigned long base3,base4,base5; /* Memory and I/O base addresses */ unsigned char irq,ipin,gnt,lat; /* assigned IRQ parameters for this card */ }dhahelper_pci_device_t; #define DHAHELPER_GET_VERSION _IOW('D', 0, int) #define DHAHELPER_PORT _IOWR('D', 1, dhahelper_port_t) #define DHAHELPER_MTRR _IOWR('D', 2, dhahelper_mtrr_t) #define DHAHELPER_PCI_CONFIG _IOWR('D', 3, dhahelper_pci_config_t) #define DHAHELPER_VIRT_TO_PHYS _IOWR('D', 4, dhahelper_vmi_t) #define DHAHELPER_VIRT_TO_BUS _IOWR('D', 5, dhahelper_vmi_t) #define DHAHELPER_ALLOC_PA _IOWR('D', 6, dhahelper_mem_t) #define DHAHELPER_FREE_PA _IOWR('D', 7, dhahelper_mem_t) #define DHAHELPER_LOCK_MEM _IOWR('D', 8, dhahelper_mem_t) #define DHAHELPER_UNLOCK_MEM _IOWR('D', 9, dhahelper_mem_t) #define DHAHELPER_INSTALL_IRQ _IOWR('D', 10, dhahelper_irq_t) #define DHAHELPER_ACK_IRQ _IOWR('D', 11, dhahelper_irq_t) #define DHAHELPER_FREE_IRQ _IOWR('D', 12, dhahelper_irq_t) #define DHAHELPER_CPU_FLUSH _IOWR('D', 13, dhahelper_cpu_flush_t) #define DHAHELPER_PCI_FIND _IOWR('D', 14, dhahelper_pci_device_t) #endif /* DHAHELPER_H */ --- NEW FILE: duha-helper.c --- /* Direct Userland Hardware Access kernel helper (C) 2002-2005 Alex Beregszaszi (C) 2002-2003 Nick Kurshev (C) 2002-2004 M?ns Rullg?rd Accessing hardware from userspace as USER (no root needed!) Tested on 2.2.x (2.2.19), 2.4.x (2.4.3,2.4.17) and 2.6.1. License: GPL WARNING! THIS MODULE VIOLATES SEVERAL SECURITY LINES! DON'T USE IT ON PRODUCTION SYSTEMS, ONLY AT HOME, ON A "SINGLE-USER" SYSTEM. NO WARRANTY! IF YOU WANT TO USE IT ON PRODUCTION SYSTEMS THEN PLEASE READ 'README' FILE TO KNOW HOW TO PREVENT ANONYMOUS ACCESS TO THIS MODULE. [...1200 lines suppressed...] #else static void __exit exit_dhahelper(void) #endif { unsigned i; for(i=0;i<256;i++) if(dha_irqs[i].handled) free_irq(i, dha_irqs[i].dev); unregister_dev(); } #ifdef EXPORT_NO_SYMBOLS EXPORT_NO_SYMBOLS; #endif #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0) module_init(init_dhahelper); module_exit(exit_dhahelper); #endif --- NEW FILE: duha-helper.h --- /* Direct Hardware Access kernel helper (C) 2002 Alex Beregszaszi (C) 2002-2003 Nick Kurshev */ #ifndef DHAHELPER_H #define DHAHELPER_H #include /* feel free to change */ #define DEFAULT_MAJOR 252 /* 240-254 LOCAL/EXPERIMENTAL USE */ #define API_VERSION 0x30 /* 3.0*/ typedef struct dhahelper_port_s { #define PORT_OP_READ 1 #define PORT_OP_WRITE 2 int operation; int size; int addr; // FIXME - switch to void* (64bit) int value; } dhahelper_port_t; typedef struct dhahelper_mtrr_s { #define MTRR_OP_ADD 1 #define MTRR_OP_DEL 2 int operation; long start; long size; int type; int privat; } dhahelper_mtrr_t; typedef struct dhahelper_pci_config_s { #define PCI_OP_READ 0 #define PCI_OP_WRITE 1 int operation; int bus; int dev; int func; int cmd; int size; long ret; } dhahelper_pci_config_t; typedef struct dhahelper_vmi_s { void * virtaddr; unsigned long length; unsigned long *realaddr; }dhahelper_vmi_t; typedef struct dhahelper_mem_s { void * addr; unsigned long length; }dhahelper_mem_t; typedef struct dhahelper_irq_s { unsigned num; int bus, dev, func; int ack_region; unsigned long ack_offset; unsigned int ack_data; }dhahelper_irq_t; typedef struct dhahelper_cpu_flush_s { void *va; unsigned long length; }dhahelper_cpu_flush_t; typedef struct dhahelper_pci_device_s { int bus,card,func; /* PCI/AGP bus:card:func */ unsigned short vendor,device; /* Card vendor+device ID */ unsigned long base0,base1,base2,baserom; /* Memory and I/O base addresses */ unsigned long base3,base4,base5; /* Memory and I/O base addresses */ unsigned char irq,ipin,gnt,lat; /* assigned IRQ parameters for this card */ }dhahelper_pci_device_t; #define DHAHELPER_GET_VERSION _IOW('D', 0, int) #define DHAHELPER_PORT _IOWR('D', 1, dhahelper_port_t) #define DHAHELPER_MTRR _IOWR('D', 2, dhahelper_mtrr_t) #define DHAHELPER_PCI_CONFIG _IOWR('D', 3, dhahelper_pci_config_t) #define DHAHELPER_VIRT_TO_PHYS _IOWR('D', 4, dhahelper_vmi_t) #define DHAHELPER_VIRT_TO_BUS _IOWR('D', 5, dhahelper_vmi_t) #define DHAHELPER_ALLOC_PA _IOWR('D', 6, dhahelper_mem_t) #define DHAHELPER_FREE_PA _IOWR('D', 7, dhahelper_mem_t) #define DHAHELPER_LOCK_MEM _IOWR('D', 8, dhahelper_mem_t) #define DHAHELPER_UNLOCK_MEM _IOWR('D', 9, dhahelper_mem_t) #define DHAHELPER_INSTALL_IRQ _IOWR('D', 10, dhahelper_irq_t) #define DHAHELPER_ACK_IRQ _IOWR('D', 11, dhahelper_irq_t) #define DHAHELPER_FREE_IRQ _IOWR('D', 12, dhahelper_irq_t) #define DHAHELPER_CPU_FLUSH _IOWR('D', 13, dhahelper_cpu_flush_t) #define DHAHELPER_PCI_FIND _IOWR('D', 14, dhahelper_pci_device_t) #endif /* DHAHELPER_H */ --- NEW FILE: test.c --- #include #include #include #include #include #include #include #include #include "dhahelper.h" int main(int argc, char *argv[]) { int fd; int ret; fd = open("/dev/dhahelper", O_RDWR); if(fd < 0){ perror("dev/dhahelper"); exit(1); } ioctl(fd, DHAHELPER_GET_VERSION, &ret); printf("api version: %d\n", ret); if (ret != API_VERSION) printf("incompatible api!\n"); { void *mem; unsigned long size=256; mem = mmap(0,size,PROT_READ|PROT_WRITE,MAP_SHARED,fd,0); printf("allocated to %p\n", mem); if (argc > 1) if (mem != 0) { int i; for (i = 0; i < 256; i++) printf("[%x] ", *(int *)(mem+i)); printf("\n"); } munmap((void *)mem, size); } return(0); } From alex at mplayerhq.hu Thu Aug 18 14:54:03 2005 From: alex at mplayerhq.hu (Alex Beregszaszi) Date: Thu, 18 Aug 2005 14:54:03 +0200 (CEST) Subject: [Uha-devel] CVS: uha/super/windows MAKEFILE, NONE, 1.1 SOURCES, NONE, 1.1 dhahelper.c, NONE, 1.1 dhahelper.h, NONE, 1.1 dhasetup.c, NONE, 1.1 Message-ID: <20050818125403.9F62C4918A@mail.mplayerhq.hu> Update of /cvsroot/uha/uha/super/windows In directory mail:/home/alex/uha/uha/super/windows Added Files: MAKEFILE SOURCES dhahelper.c dhahelper.h dhasetup.c Log Message: initial commit --- NEW FILE: MAKEFILE --- # # DO NOT EDIT THIS FILE!!! Edit .\sources. if you want to add a new source # file to this component. This file merely indirects to the real make file # that is shared by all the driver components of the Windows NT DDK # !INCLUDE $(NTMAKEENV)\makefile.def --- NEW FILE: SOURCES --- TARGETNAME=dhahelper TARGETPATH=. TARGETTYPE=DRIVER NTDEBUG=ntsd SOURCES= dhahelper.c --- NEW FILE: dhahelper.c --- /****************************************************************************** * dhahelper.c: direct hardware access under Windows NT/2000/XP * Copyright (c) 2004 Sascha Sommer . * * 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, USA. * *****************************************************************************/ #include #include "dhahelper.h" #define OutputDebugString DbgPrint #define IOPM_SIZE 0x2000 typedef char IOPM[IOPM_SIZE]; static IOPM *pIOPM = NULL; typedef struct { PMDL Mdl; PVOID SystemVirtualAddress; PVOID UserVirtualAddress; ULONG PhysMemSizeInBytes; }alloc_priv; static alloc_priv* alloclist; static unsigned int alloccount=0; static NTSTATUS dhahelperdispatch(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp); static void dhahelperunload(IN PDRIVER_OBJECT DriverObject); static NTSTATUS UnmapPhysicalMemory(PVOID UserVirtualAddress); static NTSTATUS MapPhysicalMemoryToLinearSpace(PVOID pPhysAddress,ULONG PhysMemSizeInBytes,PVOID *PhysMemLin); void Ke386SetIoAccessMap(int, IOPM *); void Ke386QueryIoAccessMap(int, IOPM *); void Ke386IoSetAccessProcess(PEPROCESS, int); //entry point NTSTATUS DriverEntry (IN PDRIVER_OBJECT DriverObject,IN PUNICODE_STRING RegistryPath){ UNICODE_STRING DeviceNameUnicodeString; UNICODE_STRING DeviceLinkUnicodeString; NTSTATUS ntStatus; PDEVICE_OBJECT DeviceObject = NULL; OutputDebugString ("dhahelper: entering DriverEntry"); RtlInitUnicodeString (&DeviceNameUnicodeString, L"\\Device\\DHAHELPER"); // Create an EXCLUSIVE device object (only 1 thread at a time // can make requests to this device). ntStatus = IoCreateDevice(DriverObject,0,&DeviceNameUnicodeString,FILE_DEVICE_DHAHELPER,0,TRUE,&DeviceObject); if (NT_SUCCESS(ntStatus)){ // Create dispatch points for device control, create, close. DriverObject->MajorFunction[IRP_MJ_CREATE] = DriverObject->MajorFunction[IRP_MJ_CLOSE] = DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = dhahelperdispatch; DriverObject->DriverUnload = dhahelperunload; // Create a symbolic link, e.g. a name that a Win32 app can specify // to open the device. RtlInitUnicodeString (&DeviceLinkUnicodeString, L"\\DosDevices\\DHAHELPER"); ntStatus = IoCreateSymbolicLink(&DeviceLinkUnicodeString,&DeviceNameUnicodeString); if (!NT_SUCCESS(ntStatus)){ // Symbolic link creation failed- note this & then delete the // device object (it's useless if a Win32 app can't get at it). OutputDebugString ("dhahelper: IoCreateSymbolicLink failed"); IoDeleteDevice (DeviceObject); } } else{ OutputDebugString ("dhahelper: IoCreateDevice failed"); } OutputDebugString ("dhahelper: leaving DriverEntry"); return ntStatus; } // Process the IRPs sent to this device static NTSTATUS dhahelperdispatch(IN PDEVICE_OBJECT DeviceObject,IN PIRP Irp){ PIO_STACK_LOCATION IrpStack; ULONG dwInputBufferLength; ULONG dwOutputBufferLength; ULONG dwIoControlCode; PVOID pvIOBuffer; NTSTATUS ntStatus; dhahelper_t dhahelper_priv; OutputDebugString ("dhahelper: entering dhahelperdispatch"); // Init to default settings Irp->IoStatus.Status = STATUS_SUCCESS; Irp->IoStatus.Information = 0; IrpStack = IoGetCurrentIrpStackLocation(Irp); // Get the pointer to the input/output buffer and it's length pvIOBuffer = Irp->AssociatedIrp.SystemBuffer; dwInputBufferLength = IrpStack->Parameters.DeviceIoControl.InputBufferLength; dwOutputBufferLength = IrpStack->Parameters.DeviceIoControl.OutputBufferLength; switch (IrpStack->MajorFunction){ case IRP_MJ_CREATE: OutputDebugString("dhahelper: IRP_MJ_CREATE"); break; case IRP_MJ_CLOSE: OutputDebugString("dhahelper: IRP_MJ_CLOSE"); break; case IRP_MJ_DEVICE_CONTROL: OutputDebugString("dhahelper: IRP_MJ_DEVICE_CONTROL"); dwIoControlCode = IrpStack->Parameters.DeviceIoControl.IoControlCode; switch (dwIoControlCode){ case IOCTL_DHAHELPER_ENABLEDIRECTIO: OutputDebugString("dhahelper: IOCTL_DHAHELPER_ENABLEDIRECTIO"); pIOPM = MmAllocateNonCachedMemory(sizeof(IOPM)); if (pIOPM){ RtlZeroMemory(pIOPM, sizeof(IOPM)); Ke386IoSetAccessProcess(PsGetCurrentProcess(), 1); Ke386SetIoAccessMap(1, pIOPM); } else Irp->IoStatus.Status = STATUS_INSUFFICIENT_RESOURCES; break; case IOCTL_DHAHELPER_DISABLEDIRECTIO: OutputDebugString("dhahelper: IOCTL_DHAHELPER_DISABLEDIRECTIO"); if (pIOPM){ Ke386IoSetAccessProcess(PsGetCurrentProcess(), 0); Ke386SetIoAccessMap(1, pIOPM); MmFreeNonCachedMemory(pIOPM, sizeof(IOPM)); pIOPM = NULL; } break; case IOCTL_DHAHELPER_MAPPHYSTOLIN: OutputDebugString("dhahelper: IOCTL_DHAHELPER_MAPPHYSTOLIN"); if (dwInputBufferLength){ memcpy (&dhahelper_priv, pvIOBuffer, dwInputBufferLength); ntStatus = MapPhysicalMemoryToLinearSpace(dhahelper_priv.base,dhahelper_priv.size,&dhahelper_priv.ptr); if (NT_SUCCESS(ntStatus)){ memcpy (pvIOBuffer, &dhahelper_priv, dwInputBufferLength); Irp->IoStatus.Information = dwInputBufferLength; } Irp->IoStatus.Status = ntStatus; } else Irp->IoStatus.Status = STATUS_INVALID_PARAMETER; break; case IOCTL_DHAHELPER_UNMAPPHYSADDR: OutputDebugString("dhahelper: IOCTL_DHAHELPER_UNMAPPHYSADDR"); if (dwInputBufferLength){ memcpy (&dhahelper_priv, pvIOBuffer, dwInputBufferLength); ntStatus = UnmapPhysicalMemory(dhahelper_priv.ptr); Irp->IoStatus.Status = ntStatus; } else Irp->IoStatus.Status = STATUS_INVALID_PARAMETER; break; default: OutputDebugString("dhahelper: unknown IRP_MJ_DEVICE_CONTROL"); Irp->IoStatus.Status = STATUS_INVALID_PARAMETER; break; } break; } // DON'T get cute and try to use the status field of the irp in the // return status. That IRP IS GONE as soon as you call IoCompleteRequest. ntStatus = Irp->IoStatus.Status; IoCompleteRequest (Irp, IO_NO_INCREMENT); // We never have pending operation so always return the status code. OutputDebugString("dhahelper: leaving dhahelperdispatch"); return ntStatus; } // Delete the associated device and return static void dhahelperunload(IN PDRIVER_OBJECT DriverObject){ UNICODE_STRING DeviceLinkUnicodeString; NTSTATUS ntStatus=STATUS_SUCCESS; OutputDebugString ("dhahelper: entering dhahelperunload"); OutputDebugString ("dhahelper: unmapping remaining memory"); while(alloccount && (ntStatus==STATUS_SUCCESS))ntStatus = UnmapPhysicalMemory(alloclist[alloccount-1].UserVirtualAddress); RtlInitUnicodeString (&DeviceLinkUnicodeString, L"\\DosDevices\\DHAHELPER"); ntStatus = IoDeleteSymbolicLink (&DeviceLinkUnicodeString); if (NT_SUCCESS(ntStatus)){ IoDeleteDevice (DriverObject->DeviceObject); } else { OutputDebugString ("dhahelper: IoDeleteSymbolicLink failed"); } OutputDebugString ("dhahelper: leaving dhahelperunload"); } /************************* memory mapping functions ******************************/ //unlike the functions of other io helpers these functions allow to map adapter memory on windows xp //even if it has alread been mapped by the original driver //the technique used is described in //http://support.microsoft.com/default.aspx?scid=kb;en-us;q189327 //furthermore it keeps a list of mapped areas to free them when the driver gets unloaded //I'm not sure what the limitations of ZwMapViewOfSection are but mapping 128MB videoram (that is probably already mapped by the gfxcard driver) //won't work so it is generally a good idea to map only the memory you really need static NTSTATUS MapPhysicalMemoryToLinearSpace(PVOID pPhysAddress,ULONG PhysMemSizeInBytes,PVOID *PhysMemLin){ alloc_priv* alloclisttmp; PMDL Mdl=NULL; PVOID SystemVirtualAddress=NULL; PVOID UserVirtualAddress=NULL; PHYSICAL_ADDRESS pStartPhysAddress; OutputDebugString ("dhahelper: entering MapPhysicalMemoryToLinearSpace"); pStartPhysAddress.QuadPart = (ULONGLONG)pPhysAddress; __try { SystemVirtualAddress=MmMapIoSpace(pStartPhysAddress,PhysMemSizeInBytes, /*MmWriteCombined*/MmNonCached); if(!SystemVirtualAddress){ OutputDebugString("dhahelper: MmMapIoSpace failed"); return STATUS_INVALID_PARAMETER; } OutputDebugString("dhahelper: SystemVirtualAddress 0x%x",SystemVirtualAddress); Mdl=IoAllocateMdl(SystemVirtualAddress, PhysMemSizeInBytes, FALSE, FALSE,NULL); if(!Mdl){ OutputDebugString("dhahelper: IoAllocateMdl failed"); return STATUS_INSUFFICIENT_RESOURCES; } OutputDebugString("dhahelper: Mdl 0x%x",Mdl); MmBuildMdlForNonPagedPool(Mdl); UserVirtualAddress = (PVOID)(((ULONG)PAGE_ALIGN(MmMapLockedPages(Mdl,UserMode))) + MmGetMdlByteOffset(Mdl)); if(!UserVirtualAddress){ OutputDebugString("dhahelper: MmMapLockedPages failed"); return STATUS_INSUFFICIENT_RESOURCES; } OutputDebugString("dhahelper: UserVirtualAddress 0x%x",UserVirtualAddress); }__except(EXCEPTION_EXECUTE_HANDLER){ NTSTATUS ntStatus; ntStatus = GetExceptionCode(); OutputDebugString("dhahelper: MapPhysicalMemoryToLinearSpace failed due to exception 0x%0x\n", ntStatus); return ntStatus; } OutputDebugString("dhahelper: adding data to internal allocation list"); alloclisttmp=MmAllocateNonCachedMemory((alloccount+1)*sizeof(alloc_priv)); if(!alloclisttmp){ OutputDebugString("dhahelper: not enough memory to create temporary allocation list"); MmUnmapLockedPages(UserVirtualAddress, Mdl); IoFreeMdl(Mdl); return STATUS_INSUFFICIENT_RESOURCES; } if(alloccount){ memcpy(alloclisttmp,alloclist,alloccount * sizeof(alloc_priv)); MmFreeNonCachedMemory(alloclist,alloccount*sizeof(alloc_priv)); } alloclist=alloclisttmp; alloclist[alloccount].Mdl=Mdl; alloclist[alloccount].SystemVirtualAddress=SystemVirtualAddress; alloclist[alloccount].UserVirtualAddress=UserVirtualAddress; alloclist[alloccount].PhysMemSizeInBytes=PhysMemSizeInBytes; ++alloccount; *PhysMemLin=UserVirtualAddress; OutputDebugString("dhahelper: leaving MapPhysicalMemoryToLinearSpace"); return STATUS_SUCCESS; } static NTSTATUS UnmapPhysicalMemory(PVOID UserVirtualAddress){ unsigned int i; unsigned int x=0; unsigned int alloccounttmp=alloccount; OutputDebugString("dhahelper: entering UnmapPhysicalMemory to unmapp 0x%x",UserVirtualAddress); if(!alloccount){ OutputDebugString("dhahelper: UnmapPhysicalMemory: nothing todo -> leaving..."); return STATUS_SUCCESS; } for(i=0;i #include int main(int argc,char* argv[]){ SC_HANDLE hSCManager; SC_HANDLE hService; char path[MAX_PATH]; printf("dhasetup (c) 2004 Sascha Sommer\n"); GetWindowsDirectory(path,MAX_PATH); strcpy(path+strlen(path),"\\system32\\drivers\\dhahelper.sys"); if(argc==1){ printf("Usage:\n"); printf("dhasetup install - Copies dhahelper.sys from the current directory to\n%s and configures it to start at boot.\n", path); printf("dhasetup remove - Removes the dhahelper utility.\n"); return 0; } hSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS); if(!strcmp(argv[1],"install")){ printf("Installing dhahelper...\n"); if(!CopyFile("dhahelper.sys",path,FALSE)){ printf("Copying dhahelper.sys failed.\nEither dhahelper.sys is not in the current directory or you lack sufficient\nprivileges to write to %s.", path); return 1; } // Install the driver hService = CreateService(hSCManager, "DHAHELPER", "DHAHELPER", SERVICE_ALL_ACCESS, SERVICE_KERNEL_DRIVER, SERVICE_SYSTEM_START, SERVICE_ERROR_NORMAL, path, NULL, NULL, NULL, NULL, NULL); if(!hService){ printf("Unable to register DHAHELPER Service (0x%x).\n",GetLastError()); } } else if(!strcmp(argv[1],"remove")){ SERVICE_STATUS ServiceStatus; printf("Removing dhahelper...\n"); hService = OpenService(hSCManager, "DHAHELPER", SERVICE_ALL_ACCESS); ControlService(hService, SERVICE_CONTROL_STOP, &ServiceStatus); DeleteService(hService); DeleteFile(path); } else { printf("unknown parameter: %s\n",argv[1]); } CloseServiceHandle(hService); CloseServiceHandle(hSCManager); printf("Please reboot to let the changes take effect.\n"); return 0; }