# Device Drivers: Plug and Play

The information in this section is alpha and will be changed in R4.

When the BeOS is booted, it automatically configures any Plug and Play peripherals that it finds. Drivers for these peripherals then query the BeOS for configuration information, including IRQs, DMA channels, and IO port ranges. From that point on, the driver need not worry about Plug and Play issues.

A driver queries the BeOS for configuration information through an `ioctl()` call on the special Plug and Play configuration that you access by `open()`'ing the special /pnp/config_mgr file. The `ioctl()` call lets the driver fetch the configuration of a particular device indexed by an integer ranging from `0` to `N-1`, where `N` is the number of plug and play devices installed in the system. The driver typically scans through the list of configurations until it finds the one matching its device as identified by the EISA product id. Typical usage of the Plug and Play `ioctl()` call is illustrated below:

       isa_device_config config;
       status_t ret;
       int i, fd;

       // open plug and play configuration manager
       fd = open("/pnp/config_mgr", O_RDWR);

       for (i=0;;i++) {
          // fetch the configuration of the ith device
          *(uint *)&config = i;

          ret = ioctl(fd, CONFIG_MGR_GET_NTH_ISA_DEVICE_CONFIG,
             &config, sizeof(isa_device_config)
          if (ret == B_OK) {
             printf("Card: %s, Device: %s\\n", config.card_name,
                config.logical_device_name);
          } else
             break;
       }

The `ioct()` call shown here returns an `isa_device_config` structure; the definition of the structure and the flags that you can use to examine its fields are given in /boot/develop/headers/be/device/isapnp.h.

## Functions

### ioctl()

Declared in: posix/unistd.h

          status_t ioctl(int fd, int op, isa_device_config *config, int size_config)

- fd is a file descriptor for the special file "/pnp/config_mgr"

- op is the constant `CONFIG_MGR_GET_NTH_ISA_DEVICE_CONFIG`, defined in <be/device/config_mgr.h>.

- config, on input, should contain in the first `sizeof(long)` bytes the index of the device whose configuration is to be fetched. On output, the memory will be filled with a `isa_device_config` structure containing the configuration information about the device. This structure is detailed in <be/device/isapnp.h>.

- size_config should always be `sizeof(isa_device_config)`.

The function returns `B_NO_ERROR` on success and `B_ERROR` on failure. Failure indicates that the index was out of range.

## Macros

### EQUAL_EISA_PRODUCT_ID()

Declared in: be/device/isapnp.h

          EQUAL_EISA_PRODUCT_ID(EISA_PRODUCT_ID id1, EISA_PRODUCT_ID id2)

Compares two product id's, ignoring the revision value.

### MAKE_EISA_PRODUCT_ID()

Declared in: be/device/isapnp.h

          MAKE_EISA_PRODUCT_ID(EISA_PRODUCT_ID *ptr, char ch0, char ch1, char ch2, uint12 prod_num, uint4 rev)

Properly gloms its parameters into a product id in little-endian format.

The Be Book, in lovely HTML, for BeOS Release 3.

Copyright © 1998 Be, Inc. All rights reserved.

Last modified March 27, 1998.