The /dev/misc/config driver which provides userland access to the

Configuration Manager, once this is implemented.
Needed for the "listdev" command and the Devices preferences application.
Not tested!


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@2339 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler 2002-12-31 16:19:09 +00:00
parent 53284a9fdb
commit ea8ace93a1
4 changed files with 208 additions and 0 deletions

View File

@ -3,6 +3,7 @@ SubDir OBOS_TOP src add-ons kernel drivers ;
SubInclude OBOS_TOP src add-ons kernel drivers arch ;
SubInclude OBOS_TOP src add-ons kernel drivers audio ;
SubInclude OBOS_TOP src add-ons kernel drivers common ;
SubInclude OBOS_TOP src add-ons kernel drivers misc ;
SubInclude OBOS_TOP src add-ons kernel drivers random ;
SubInclude OBOS_TOP src add-ons kernel drivers net ;

View File

@ -0,0 +1,3 @@
SubDir OBOS_TOP src add-ons kernel drivers misc ;
KernelObjects config.c : -fno-pic ;

View File

@ -0,0 +1,166 @@
/* config driver
** provides userland access to the device configuration manager
**
** Copyright 2002, Axel Doerfler. All rights reserved.
** Distributed under the terms of the OpenBeOS License.
*/
//#include <Errors.h>
#include <Drivers.h>
#include <drivers/config_manager.h>
#include <string.h>
#include "config_driver.h"
#define DEVICE_NAME "misc/config"
struct config_manager_for_driver_module_info *gConfigManager;
// Device interface
static status_t
config_open(const char *name, uint32 flags, void **_cookie)
{
*_cookie = NULL;
return B_OK;
}
static status_t
config_close(void *cookie)
{
return B_OK;
}
static status_t
config_free_cookie(void *cookie)
{
return B_OK;
}
static status_t
config_ioctl(void *cookie, uint32 op, void *buffer, size_t len)
{
struct cm_ioctl_data *params = (struct cm_ioctl_data *)buffer;
// simple check for validity of the argument
if (params == NULL || params->magic != op)
return B_BAD_VALUE;
switch (op) {
case CM_GET_NEXT_DEVICE_INFO:
gConfigManager->get_next_device_info(params->bus, &params->cookie,
(struct device_info *)params->data, params->data_len);
break;
case CM_GET_DEVICE_INFO_FOR:
gConfigManager->get_device_info_for(params->cookie,
(struct device_info *)params->data, params->data_len);
break;
case CM_GET_SIZE_OF_CURRENT_CONFIGURATION_FOR:
gConfigManager->get_size_of_current_configuration_for(params->cookie);
break;
case CM_GET_CURRENT_CONFIGURATION_FOR:
gConfigManager->get_current_configuration_for(params->cookie,
(struct device_configuration *)params->data, params->data_len);
break;
case CM_GET_SIZE_OF_POSSIBLE_CONFIGURATIONS_FOR:
gConfigManager->get_size_of_possible_configurations_for(params->cookie);
break;
case CM_GET_POSSIBLE_CONFIGURATIONS_FOR:
gConfigManager->get_possible_configurations_for(params->cookie,
(struct possible_device_configurations *)params->data, params->data_len);
break;
case CM_COUNT_RESOURCE_DESCRIPTORS_OF_TYPE:
gConfigManager->count_resource_descriptors_of_type(params->config, params->type);
break;
case CM_GET_NTH_RESOURCE_DESCRIPTOR_OF_TYPE:
gConfigManager->get_nth_resource_descriptor_of_type(params->config, params->n,
params->type, (resource_descriptor *)params->data, params->data_len);
break;
}
return B_NOT_ALLOWED;
}
static ssize_t
config_read(void * cookie, off_t pos, void *buf, size_t *len)
{
return 0;
}
static ssize_t
config_write(void * cookie, off_t pos, const void *buf, size_t *len)
{
return 0;
}
// #pragma mark -
// Driver interface
status_t
init_hardware()
{
return B_OK;
}
const char **
publish_devices(void)
{
static const char *devices[] = {
DEVICE_NAME,
NULL
};
return devices;
}
device_hooks *
find_device(const char *name)
{
static device_hooks hooks = {
&config_open,
&config_close,
&config_free_cookie,
&config_ioctl,
&config_read,
&config_write,
/* Leave select/deselect/readv/writev undefined. The kernel will
* use its own default implementation. The basic hooks above this
* line MUST be defined, however. */
NULL,
NULL,
NULL,
NULL
};
if (!strcmp(name, DEVICE_NAME))
return &hooks;
return NULL;
}
status_t
init_driver()
{
return get_module(B_CONFIG_MANAGER_FOR_DRIVER_MODULE_NAME, (module_info **)&gConfigManager);
}
void
uninit_driver()
{
if (gConfigManager != NULL)
put_module(B_CONFIG_MANAGER_FOR_DRIVER_MODULE_NAME);
}

View File

@ -0,0 +1,38 @@
#ifndef _CONFIG_MANAGER_DRIVER_H_
#define _CONFIG_MANAGER_DRIVER_H_
/*
** Distributed under the terms of the OpenBeOS License.
*/
/* definitions for the /dev/misc/config driver which provides access
* to the config_manager via calls to ioctl().
*
* ToDo: This file should probably located in a publicly accessable place?!
*/
/* the magic is the ioctl */
#define CM_GET_NEXT_DEVICE_INFO 'GNDI'
#define CM_GET_DEVICE_INFO_FOR 'GDIF'
#define CM_GET_SIZE_OF_CURRENT_CONFIGURATION_FOR 'GSCC'
#define CM_GET_CURRENT_CONFIGURATION_FOR 'GCCF'
#define CM_GET_SIZE_OF_POSSIBLE_CONFIGURATIONS_FOR 'GSPC'
#define CM_GET_POSSIBLE_CONFIGURATIONS_FOR 'GPCF'
#define CM_COUNT_RESOURCE_DESCRIPTORS_OF_TYPE 'CRDT'
#define CM_GET_NTH_RESOURCE_DESCRIPTOR_OF_TYPE 'GNRD'
struct cm_ioctl_data {
uint32 magic;
bus_type bus;
uint64 cookie;
void *config;
uint32 n;
uint32 type;
void *data;
uint32 data_len;
};
#define CM_DEVICE_NAME "misc/config"
#endif /* _CONFIG_MANAGER_DRIVER_H_ */