spec

Software for Diffraction

ioports

I/O port access for PCs

INTRODUCTION

Access to I/O ports associated with ISA or PCI cards can be configured on the Interface screen of the configuration editor along the following lines:

IO PORT                 ADDR  <>MODE  NUM
    YES                0x300    Read    1
    YES               0xC100   Write    2
    YES                0x310     R/W    4

The NUM field indicates how many consecutive locations (in bytes) can be accessed. Write-only mode is available for the unusual situation where read access to an I/O location has adverse consequences such as freezing the host PC.

The config file entry syntax is:

PC_PORT_*#* = hex_base_address number_of_ports read_write_flag

where read_write_flag is 0 for read-only, 1 for write-only and 2 for read-write mode.

It is not necessary to configure I/O ports associated with controllers that have built-in support in spec.

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 PC Platforms

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 changed back to root for the duration of the iopl() system call. Also, I/O privilege is turned off for any spawned processed.

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".

Finally, root access is enabled for the open() call of the device node associated with any configured USB devices. With recent spec releases on modern Linux distributions, that access shouldn't be needed as the udev rules installed by spec should have created general read/write access to the associated USB device nodes.

During the rest of the time, spec users will not have root privileges.

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.