home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / os / linux / 17411 < prev    next >
Encoding:
Text File  |  1992-11-20  |  2.0 KB  |  58 lines

  1. Newsgroups: comp.os.linux
  2. Path: sparky!uunet!super!becker
  3. From: becker@super.org (Donald J. Becker)
  4. Subject: Re: How to use sys_iopl (to change I/O privilege) ?    
  5. Message-ID: <1992Nov21.044057.17271@super.org>
  6. Sender: news@super.org (USENET News System)
  7. Nntp-Posting-Host: metropolis
  8. Organization: IDA Supercomputing Research Center
  9. References: <1992Nov20.145858.119338@watson.ibm.com>
  10. Date: Sat, 21 Nov 1992 04:40:57 GMT
  11. Lines: 45
  12.  
  13. I assume what you want to do is access I/O ports from a user-level program.
  14.  
  15. There are two ways to do this.  The first requires that you are root
  16. or suid root.  (I use this code to test out device drivers without
  17. making a kernel every few minutes.)  Do the following:
  18.  
  19. #include <unistd.h>
  20. ...
  21.     /* For devices between 0x000 and 0x3ff use: */
  22. #define PERM_OFF 0
  23. #define PERM_ON 1
  24.     if (ioperm(PORT_BASE, PORT_LENGTH, PERM_ON)) {
  25.     perror("io-perm");
  26.     return 1;
  27.     }
  28.     /* For devices higher than 0x3ff you must enable the whole I/O
  29.     space. */
  30.     if (iopl(3)) {
  31.     perror("io-perm2");
  32.     return 1;
  33.     }
  34.  
  35. This method has several problems for general use: you must be root or
  36. suid root, there is no enforcement of exclusive or semi-shared access
  37. to a device, and there is no way to get interrupts.
  38.  
  39. The second way is use my not-yet-released generalized device driver.
  40. I originally developed as alternate soundcard driver, but later
  41. extended it.
  42. Its features are:
  43.     o Every I/O port range of interest is assigned a device.
  44.     o A fixed device list is usually compiled-in.
  45.     o The device list is extensible at runtime by 'root'
  46.     o Each device can be set for exclusive, counted, or shared access.
  47.     o Device names are arbitrary, and are made as usual by 'mknod'
  48.     o Access permission is handled by the normal Unix user/group/all
  49.       permission bits
  50.     o Opening the device allows access to that I/O port range.
  51.     o Once open, an ioctl() returns the port base, range and in-use count.
  52. Still to be implemented is:
  53.     o Translating interrupts to signals
  54. -- 
  55. Donald Becker                       becker@super.org
  56. Supercomputing Research Center
  57. 17100 Science Drive, Bowie MD 21114           301-805-7482
  58.