Defines | Functions

/home/sindre/dev_uclinux/suzaku_shared/hwos_sw/libhwos/hdev.h File Reference

[Hardware OS Device Driver Interface] Keep track of device drivers in the HWOS. More...

#include "hstructures.h"

Go to the source code of this file.

Defines

#define HDEV_PATH_SIZE   40
 Longest allowed path for device file.

Functions

int hdev_size ()
 Size of the device list.
struct hdevhdev_get_by_major (int major)
 Get device by major number.
struct hdevhdev_add (int major, char *device_path)
 Add a device description.
int hdev_remove (struct hdev *device)
 Remove a device from the HWOS.
int hdev_get_major (struct hdev *device)
 Get major number for device.
int hdev_remove_by_major (int major)
 Remove device by major number.
int hdev_remove_all ()
 Remove all devices in the system.
struct hdevhdev_get_first ()
 Get first device in list.
struct hdevhdev_get_last ()
 Get last device in list.
struct hdevhdev_get_next (struct hdev *device)
 Get next device in list.
struct hdevhdev_get_prev (struct hdev *device)
 Get previous device in list.

Detailed Description

[Hardware OS Device Driver Interface] Keep track of device drivers in the HWOS.

This functionality is not really used in this version of the HWOS. The module can function as a base for further development. It is probably a good idea to perform the actual creation of a device driver in hdev_add (now it only adds a description to a list).

Based on devicelist by Vegard Endresen. Sindre Hansen (2011): Rewritten.

Definition in file hdev.h.


Function Documentation

struct hdev* hdev_add ( int  major,
char *  device_path 
) [read]

Add a device description.

This adds a description of a character device with a path and a major number.

Parameters:
major The major number of the device.
device_path Path of the device.
Returns:
A pointer to a struct representing the device on success. NULL on failure.

Definition at line 148 of file hdev.c.

{
        if (hdev_get_by_major(major) != NULL)
                return NULL;

        struct hdev* device = calloc(1, sizeof(struct hdev));

        set_major_(device, major);
        set_path_(device, device_path);

        if (hdev_size() == 0)
                set_first_(device);

        set_prev_(device, hdev_get_last());
        set_next_(device, NULL);
        set_next_(hdev_get_last(), device);     

        set_last_(device);

        increment_size_();
        
        return device;
}

struct hdev* hdev_get_by_major ( int  major  )  [read]

Get device by major number.

Returns:
Number of elements in the device list.

Definition at line 126 of file hdev.c.

{
        if (hdev_size() == 0)
                return NULL;

        struct hdev* device = hdev_get_first();

        if (hdev_get_major(device) == major)
                return device;
        
        // TODO: What if get_next never returns NULL?
        while (hdev_get_next(device) != NULL) {
                device = hdev_get_next(device);
                if (hdev_get_major(device) == major)
                        return device;
        }

        // Nothing found => return NULL.
        return NULL;
}

struct hdev* hdev_get_first (  )  [read]

Get first device in list.

Returns:
Pointer to the device on success. NULL on failure.

Definition at line 219 of file hdev.c.

{
        return firstd; 
}

struct hdev* hdev_get_last (  )  [read]

Get last device in list.

Returns:
Pointer to the device on success. NULL on failure.

Definition at line 225 of file hdev.c.

{
        return lastd; 
}

int hdev_get_major ( struct hdev device  ) 

Get major number for device.

Parameters:
device Pointer to the device.
Returns:
Major number (positive integer) on success. Negative on failure.

Definition at line 117 of file hdev.c.

{
        if (device == NULL)
                return -1;

        return device->major; 
}

struct hdev* hdev_get_next ( struct hdev device  )  [read]

Get next device in list.

Parameters:
device Pointer to the device that has the next field.
Returns:
Pointer to the device on success. NULL on failure.

Definition at line 231 of file hdev.c.

{
        if (device == NULL)
                return NULL;

        return device->next;
}

struct hdev* hdev_get_prev ( struct hdev device  )  [read]

Get previous device in list.

Parameters:
device Pointer to the device that has the previous field.
Returns:
Pointer to the device on success. NULL on failure.

Definition at line 240 of file hdev.c.

{
        if (device == NULL)
                return NULL;

        return device->prev;
}

int hdev_remove ( struct hdev device  ) 

Remove a device from the HWOS.

Parameters:
device Pointer to the struct representing the device.
Returns:
0 on success. Negative on failure.

Definition at line 173 of file hdev.c.

{
        if (device == NULL)
                return -1;

        set_prev_(hdev_get_next(device), hdev_get_prev(device));
        set_next_(hdev_get_prev(device), hdev_get_next(device));
        
        if (hdev_get_last() == device)
                set_last_(hdev_get_prev(device));

        if (hdev_get_first() == device)
                set_first_(hdev_get_next(device));

        free(device);
        decrement_size_();

        return 0;
}

int hdev_remove_all (  ) 

Remove all devices in the system.

Returns:
0 on success. Negative on failure.

Definition at line 201 of file hdev.c.

{
        struct hdev* device = hdev_get_first();

        int number_removed = 0;
        while (hdev_get_next(device) != NULL) {
                device = hdev_get_next(device);
                if (hdev_remove(hdev_get_prev(device)) == 0)
                        number_removed += 1;
        }

        if (hdev_remove(device) == 0)
                number_removed += 1;

        return number_removed;
}

int hdev_remove_by_major ( int  major  ) 

Remove device by major number.

Parameters:
major Major number.
Returns:
0 on success. Negative on failure.

Definition at line 194 of file hdev.c.

{
        struct hdev* device = hdev_get_by_major(major);
        return hdev_remove(device);
}

int hdev_size (  ) 

Size of the device list.

Returns:
Number of elements in the device list.

Definition at line 111 of file hdev.c.

{
        return dev_cnt;
}

 All Data Structures Files Functions Variables Enumerations Enumerator Defines