* Turned the benaphore into a mutex, and removed the now unused lock.h.
* Minor cleanup. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@34205 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -53,7 +53,7 @@ device_open(const char* name, uint32 flags, void** _cookie)
|
|||||||
vesa_info* info = gDeviceInfo[id];
|
vesa_info* info = gDeviceInfo[id];
|
||||||
*_cookie = info;
|
*_cookie = info;
|
||||||
|
|
||||||
acquire_lock(&gLock);
|
mutex_lock(&gLock);
|
||||||
|
|
||||||
status_t status = B_OK;
|
status_t status = B_OK;
|
||||||
|
|
||||||
@@ -66,7 +66,7 @@ device_open(const char* name, uint32 flags, void** _cookie)
|
|||||||
info->id = id;
|
info->id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
release_lock(&gLock);
|
mutex_unlock(&gLock);
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -83,14 +83,14 @@ device_free(void* cookie)
|
|||||||
{
|
{
|
||||||
struct vesa_info* info = (vesa_info*)cookie;
|
struct vesa_info* info = (vesa_info*)cookie;
|
||||||
|
|
||||||
acquire_lock(&gLock);
|
mutex_lock(&gLock);
|
||||||
|
|
||||||
if (info->open_count-- == 1) {
|
if (info->open_count-- == 1) {
|
||||||
// release info structure
|
// release info structure
|
||||||
vesa_uninit(*info);
|
vesa_uninit(*info);
|
||||||
}
|
}
|
||||||
|
|
||||||
release_lock(&gLock);
|
mutex_unlock(&gLock);
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2005-2008, Axel Dörfler, [email protected]. All rights reserved.
|
* Copyright 2005-2009, Axel Dörfler, [email protected].
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -19,6 +19,7 @@
|
|||||||
#include "driver.h"
|
#include "driver.h"
|
||||||
#include "device.h"
|
#include "device.h"
|
||||||
|
|
||||||
|
|
||||||
#define TRACE_DRIVER
|
#define TRACE_DRIVER
|
||||||
#ifdef TRACE_DRIVER
|
#ifdef TRACE_DRIVER
|
||||||
# define TRACE(x) dprintf x
|
# define TRACE(x) dprintf x
|
||||||
@@ -28,49 +29,24 @@
|
|||||||
|
|
||||||
#define MAX_CARDS 1
|
#define MAX_CARDS 1
|
||||||
|
|
||||||
|
|
||||||
int32 api_version = B_CUR_DRIVER_API_VERSION;
|
int32 api_version = B_CUR_DRIVER_API_VERSION;
|
||||||
|
|
||||||
char *gDeviceNames[MAX_CARDS + 1];
|
char* gDeviceNames[MAX_CARDS + 1];
|
||||||
vesa_info *gDeviceInfo[MAX_CARDS];
|
vesa_info* gDeviceInfo[MAX_CARDS];
|
||||||
isa_module_info *gISA;
|
isa_module_info* gISA;
|
||||||
lock gLock;
|
mutex gLock;
|
||||||
|
|
||||||
|
|
||||||
extern "C" {
|
extern "C" const char**
|
||||||
status_t init_hardware(void);
|
|
||||||
status_t init_driver(void);
|
|
||||||
void uninit_driver(void);
|
|
||||||
const char **publish_devices(void);
|
|
||||||
device_hooks *find_device(const char *name);
|
|
||||||
}
|
|
||||||
|
|
||||||
#if 0
|
|
||||||
static status_t
|
|
||||||
get_next_graphics_card(int32 *_cookie, pci_info &info)
|
|
||||||
{
|
|
||||||
int32 index = *_cookie;
|
|
||||||
|
|
||||||
// find devices
|
|
||||||
for (; gPCI->get_nth_pci_info(index, &info) == B_OK; index++) {
|
|
||||||
if (info.class_base == PCI_display) {
|
|
||||||
*_cookie = index + 1;
|
|
||||||
return B_OK;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return B_ENTRY_NOT_FOUND;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
const char **
|
|
||||||
publish_devices(void)
|
publish_devices(void)
|
||||||
{
|
{
|
||||||
TRACE((DEVICE_NAME ": publish_devices()\n"));
|
TRACE((DEVICE_NAME ": publish_devices()\n"));
|
||||||
return (const char **)gDeviceNames;
|
return (const char**)gDeviceNames;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t
|
extern "C" status_t
|
||||||
init_hardware(void)
|
init_hardware(void)
|
||||||
{
|
{
|
||||||
TRACE((DEVICE_NAME ": init_hardware()\n"));
|
TRACE((DEVICE_NAME ": init_hardware()\n"));
|
||||||
@@ -79,28 +55,33 @@ init_hardware(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t
|
extern "C" status_t
|
||||||
init_driver(void)
|
init_driver(void)
|
||||||
{
|
{
|
||||||
TRACE((DEVICE_NAME ": init_driver()\n"));
|
TRACE((DEVICE_NAME ": init_driver()\n"));
|
||||||
|
|
||||||
if ((gDeviceInfo[0] = (vesa_info *)malloc(sizeof(vesa_info))) != NULL)
|
gDeviceInfo[0] = (vesa_info*)malloc(sizeof(vesa_info));
|
||||||
memset(gDeviceInfo[0], 0, sizeof(vesa_info));
|
if (gDeviceInfo[0] == NULL)
|
||||||
else
|
|
||||||
return B_NO_MEMORY;
|
return B_NO_MEMORY;
|
||||||
|
|
||||||
status_t status = get_module(B_ISA_MODULE_NAME, (module_info **)&gISA);
|
memset(gDeviceInfo[0], 0, sizeof(vesa_info));
|
||||||
if (status < B_OK)
|
|
||||||
|
status_t status = get_module(B_ISA_MODULE_NAME, (module_info**)&gISA);
|
||||||
|
if (status != B_OK)
|
||||||
goto err1;
|
goto err1;
|
||||||
|
|
||||||
gDeviceNames[0] = strdup("graphics/vesa");
|
gDeviceNames[0] = strdup("graphics/vesa");
|
||||||
|
if (gDeviceNames[0] == NULL) {
|
||||||
|
status = B_NO_MEMORY;
|
||||||
|
goto err2;
|
||||||
|
}
|
||||||
|
|
||||||
gDeviceNames[1] = NULL;
|
gDeviceNames[1] = NULL;
|
||||||
|
|
||||||
status = init_lock(&gLock, "vesa lock");
|
mutex_init(&gLock, "vesa lock");
|
||||||
if (status == B_OK)
|
return B_OK;
|
||||||
return B_OK;
|
|
||||||
|
|
||||||
free(gDeviceNames[0]);
|
err2:
|
||||||
put_module(B_ISA_MODULE_NAME);
|
put_module(B_ISA_MODULE_NAME);
|
||||||
err1:
|
err1:
|
||||||
free(gDeviceInfo[0]);
|
free(gDeviceInfo[0]);
|
||||||
@@ -108,16 +89,16 @@ err1:
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
extern "C" void
|
||||||
uninit_driver(void)
|
uninit_driver(void)
|
||||||
{
|
{
|
||||||
TRACE((DEVICE_NAME ": uninit_driver()\n"));
|
TRACE((DEVICE_NAME ": uninit_driver()\n"));
|
||||||
|
|
||||||
put_module(B_ISA_MODULE_NAME);
|
put_module(B_ISA_MODULE_NAME);
|
||||||
uninit_lock(&gLock);
|
mutex_destroy(&gLock);
|
||||||
|
|
||||||
// free device related structures
|
// free device related structures
|
||||||
char *name;
|
char* name;
|
||||||
for (int32 index = 0; (name = gDeviceNames[index]) != NULL; index++) {
|
for (int32 index = 0; (name = gDeviceNames[index]) != NULL; index++) {
|
||||||
free(gDeviceInfo[index]);
|
free(gDeviceInfo[index]);
|
||||||
free(name);
|
free(name);
|
||||||
@@ -125,16 +106,17 @@ uninit_driver(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
device_hooks *
|
extern "C" device_hooks*
|
||||||
find_device(const char *name)
|
find_device(const char* name)
|
||||||
{
|
{
|
||||||
int index;
|
int index;
|
||||||
|
|
||||||
TRACE((DEVICE_NAME ": find_device()\n"));
|
TRACE((DEVICE_NAME ": find_device()\n"));
|
||||||
|
|
||||||
for (index = 0; gDeviceNames[index] != NULL; index++)
|
for (index = 0; gDeviceNames[index] != NULL; index++) {
|
||||||
if (!strcmp(name, gDeviceNames[index]))
|
if (!strcmp(name, gDeviceNames[index]))
|
||||||
return &gDeviceHooks;
|
return &gDeviceHooks;
|
||||||
|
}
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,21 +1,22 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2005-2008, Axel Dörfler, [email protected]. All rights reserved.
|
* Copyright 2005-2009, Axel Dörfler, [email protected].
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*/
|
*/
|
||||||
#ifndef DRIVER_H
|
#ifndef DRIVER_H
|
||||||
#define DRIVER_H
|
#define DRIVER_H
|
||||||
|
|
||||||
|
|
||||||
#include <KernelExport.h>
|
|
||||||
#include <ISA.h>
|
#include <ISA.h>
|
||||||
|
#include <KernelExport.h>
|
||||||
|
|
||||||
|
#include <lock.h>
|
||||||
|
|
||||||
#include "vesa_private.h"
|
#include "vesa_private.h"
|
||||||
#include "lock.h"
|
|
||||||
|
|
||||||
|
|
||||||
extern char *gDeviceNames[];
|
extern char* gDeviceNames[];
|
||||||
extern vesa_info *gDeviceInfo[];
|
extern vesa_info* gDeviceInfo[];
|
||||||
extern isa_module_info *gISA;
|
extern isa_module_info* gISA;
|
||||||
extern lock gLock;
|
extern mutex gLock;
|
||||||
|
|
||||||
#endif /* DRIVER_H */
|
#endif /* DRIVER_H */
|
||||||
|
|||||||
@@ -1,54 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2005, Axel Dörfler, [email protected]. All rights reserved.
|
|
||||||
* Distributed under the terms of the MIT License.
|
|
||||||
*/
|
|
||||||
#ifndef LOCK_H
|
|
||||||
#define LOCK_H
|
|
||||||
|
|
||||||
|
|
||||||
#include <OS.h>
|
|
||||||
|
|
||||||
|
|
||||||
typedef struct lock {
|
|
||||||
sem_id sem;
|
|
||||||
vint32 count;
|
|
||||||
} lock;
|
|
||||||
|
|
||||||
|
|
||||||
static inline status_t
|
|
||||||
init_lock(struct lock *lock, const char *name)
|
|
||||||
{
|
|
||||||
lock->sem = create_sem(0, name);
|
|
||||||
lock->count = 0;
|
|
||||||
|
|
||||||
return lock->sem < B_OK ? lock->sem : B_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static inline void
|
|
||||||
uninit_lock(struct lock *lock)
|
|
||||||
{
|
|
||||||
delete_sem(lock->sem);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static inline status_t
|
|
||||||
acquire_lock(struct lock *lock)
|
|
||||||
{
|
|
||||||
if (atomic_add(&lock->count, 1) > 0)
|
|
||||||
return acquire_sem(lock->sem);
|
|
||||||
|
|
||||||
return B_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static inline status_t
|
|
||||||
release_lock(struct lock *lock)
|
|
||||||
{
|
|
||||||
if (atomic_add(&lock->count, -1) > 1)
|
|
||||||
return release_sem(lock->sem);
|
|
||||||
|
|
||||||
return B_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif /* LOCK_H */
|
|
||||||
Reference in New Issue
Block a user