ddclose Device Driver Entry Point

Purpose

Closes a previously open device instance.

Syntax

#include <sys/device.h>
#include <sys/types.h>
  
int ddclose ( devno,  chan)
dev_t devno;
chan_t chan;

Parameters

Item Description
devno Specifies the major and minor device numbers of the device instance to close.
chan Specifies the channel number.

Description

The ddclose entry point is called when a previously opened device instance is closed by the close subroutine or fp_close kernel service. The kernel calls the routine under different circumstances for non-multiplexed and multiplexed device drivers.

For non-multiplexed device drivers, the kernel calls the ddclose routine when the last process having the device instance open closes it. This causes the g-node reference count to be decremented to 0 and the g-node to be deallocated.

For multiplexed device drivers, the ddclose routine is called for each close associated with an explicit open. In other words, the device driver's ddclose routine is invoked once for each time its ddopen routine was invoked for the channel.

In some instances, data buffers should be written to the device before returning from the ddclose routine. These are buffers containing data to be written to the device that have been queued by the device driver but not yet written.

Non-multiplexed device drivers should reset the associated device to an idle state and change the device driver device state to closed. This can involve calling the fp_close kernel service to issue a close to an associated open device handler for the device. Returning the device to an idle state prevents the device from generating any more interrupt or direct memory access (DMA) requests. DMA channels and interrupt levels allocated for this device should be freed, until the device is re-opened, to release critical system resources that this device uses.

Multiplexed device drivers should provide the same device quiescing, but not in the ddclose routine. Returning the device to the idle state and freeing its resources should be delayed until the ddmpx routine is called to deallocate the last channel allocated on the device.

In all cases, the device instance is considered closed once the ddclose routine has returned to the caller, even if a nonzero return code is returned.

Execution Environment

The ddclose routine is executed only in the process environment. It should provide the required serialization of its data structures by using the locking kernel services in conjunction with a private lock word defined in the driver.

Return Values

The ddclose entry point can indicate an error condition to the user-mode application program by returning a nonzero return code. This causes the subroutine call to return a value of -1. It also makes the return code available to the user-mode application in the errno global variable. The return code used should be one of the values defined in the /usr/include/sys/errno.h file.

The device is always considered closed even if a nonzero return code is returned.

When applicable, the return values defined in the POSIX 1003.1 standard for the close subroutine should be used.