Welcome | spec | C-PLOT | Support | Downloads | Users | Contact
Contents -> ioports  
spec Help pages

NAME

ioports - I/O port access for PCs and HP E/ISA

BUILT-IN FUNCTIONS

port_get(a)
Reads one byte from the PC I/O port with the address a. Ports must be selected in the config file.

port_getw(a)
As above, but reads a 16-bit word.

port_put(a, b)
Write the byte b to the PC I/O port with the address a. Writable ports must be selected in the config file.

port_putw(a, b)
As above, but writes a 16-bit word.

Configuring I/O Port Access On Linux

To access I/O ports on Linux PC platforms, required both for the generic access provided by the above functions and also for many of the PC data acquisition and control boards that spec supports, spec uses the iopl() system call to raise the I/O privilege level of the spec process. That system calls requires root privilege. In order that users don't have to be the root user to run spec, spec is instead installed as a set-user-id-root process. That means a long listing (ls -l) of the spec executable looks something like:

-r-sr-xr-x 3 root  sys  3552546 Jun  6  2:45 spec
where the file is owned by root and there is an s instead of an x in the first set of permissions.

As soon as spec starts out, the effective user-id of the spec process is changed to that of the real user. The effective user-id is only changed back to root for the duration of the iopl() system call and at one other time. During the rest of the time, spec users will not have root privileges.

The other time the root access is used by spec is to open /dev/mem for memory mapped devices such as the Oregon Micro System PC-58 motor controller and the Bit3 Model 403 VME controller. Just as with iopl(), root access is only turned on for the duration of the open() system call for "/dev/mem".

The spec installation program will create the installed spec executables with the correct owner and modes if the Install script is run by the root user.

Configuring I/O Port Access On HP

The HP 700 platforms with E/ISA slots can be used with most PC cards that spec supports. However, the platform administrator will have to do some work to make the cards available. On HP-UX 10.x platforms, the eisa and iomap kernel drivers may need to be configured into the kernel. The configuration and creation of a new kernel can be easily done with HP's system administration tool SAM. On HP-UX 9.x platforms, those drivers seem to be included in the default kernel configuration. In addition, for each E/ISA card to be used, the eisa_config utility needs to be run to add information from hardware description files to the E/ISA non- volatile memory. For the purposes of spec, the configuration files need only contain which I/O port addresses and/or which memory addresses are to be used. A sample configuration file and information concerning which ports are used by which boards is included in the file aux/README.hp in the spec distribution.

To access the I/O ports and/or memory on the PC cards, spec must open special devices associated with the iomap driver. The spec distribution includes a utility called hp_ports that gets installed in the spec auxiliary file directory and gets run automatically by the spec process to create any of these needed special devices. spec will create a directory called /dev/ioports/ and will place the special files in that directory.

HP-UX uses a somewhat peculiar method for mapping the 64 Kbyte I/O port space on the E/ISA bus to HP memory. Each 4K page of HP memory maps 512 I/O ports. However, the mapped I/O ports do not occupy consecutive addresses. The addresses are scrambled as follows:

ISA 16-bit address:             HHHH HHMM MMMM MLLL
                                     |-- 4K page--|
CPU memory location:        MMM MMMM xxHH HHHH xLLL
The 4K page is selected by the 7 Middle bits of the ISA address, That means a total of 128 pages are used. Since each page has 3 unused bits, there are 512 I/O ports per 4K page. Note that each eight consecutive ports are on the same 4K page, but the following eight ports will be on a different page.

Although one special device could be created that accesses all 64K of the I/O ports, spec creates a different special device for each page, in order to take advantage of the purpose of the address scrambling, which is to allow different processes to access different cards at nearby addresses without conflict. spec names the special devices according to the lowest mapped I/O address, for instance /dev/ioports/0x280 or /dev/ioports/0x300.

Access to memory on the E/ISA cards is also taken care of through special devices in /dev/ioports which are also automatically created by spec's hp_ports utility. The naming convention uses the base address of the memory as in /dev/ioports/0xE000 for addresses starting at 0xE0000.

For all iomap devices the minor device number encodes both the starting address and the number of 4K pages to be mapped. The minor number for iomap devices is of the form:

0xAAAASM
The starting physical address to be mapped is 0xFAAAA000, where AAAA is the high order 16 bits of the minor number. The number of 4K pages to be mapped in is M * 2**S. The E/ISA I/O ports start at physical address 0xFC000000 and the ISA 20-bit memory starts at physical address 0xFC080000.

Note that on release 9.x of HP-UX, the major device number of the iomap devices is 10 in the standard kernel. On HP-UX 10.x the major device number is assigned dynamically. On 10.x systems, the hp_ports utility uses the /sbin/mksf command to make the special devices. That utility determines the appropriate major device number.

The hp_ports utility is installed by spec as a set-user-id-root process if spec's Install script is run by the root user.

[Help File Index]


... Meeting the software needs of scientists since 1985 ...

Return to CSS home page ...
Last Formatted May 12, 2012
Last Updated 02/28/01
Send comments, queries, suggestions to info@certif.com

© 1995-2003 Certified Scientific Software. All rights reserved