* The second open will now fail, too, in case the hardware could not be initialized
correctly. * Got rid of this superfluous cookie stuff - either the VFS behaves correctly, or we're screwed anyway. * Made adding debugger commands optional depending on if DEBUG_COMMANDS is defined or not. * Minor other cleanup. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@21322 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -34,9 +34,6 @@
|
||||
#define DEVICE_NAME "intel_extreme"
|
||||
#define INTEL_ACCELERANT_NAME "intel_extreme.accelerant"
|
||||
|
||||
#define INTEL_COOKIE_MAGIC 'intl'
|
||||
#define INTEL_FREE_COOKIE_MAGIC 'itlf'
|
||||
|
||||
// info about PLL on graphics card
|
||||
struct pll_info {
|
||||
uint32 reference_frequency;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2006, Haiku, Inc. All Rights Reserved.
|
||||
* Copyright 2006-2007, Haiku, Inc. All Rights Reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
@@ -24,6 +24,8 @@
|
||||
#include <string.h>
|
||||
|
||||
|
||||
#define DEBUG_COMMANDS
|
||||
|
||||
#define TRACE_DEVICE
|
||||
#ifdef TRACE_DEVICE
|
||||
# define TRACE(x) dprintf x
|
||||
@@ -56,16 +58,7 @@ device_hooks gDeviceHooks = {
|
||||
};
|
||||
|
||||
|
||||
static status_t
|
||||
check_device_info(struct intel_info *info)
|
||||
{
|
||||
if (!info || info->cookie_magic != INTEL_COOKIE_MAGIC)
|
||||
return B_BAD_VALUE;
|
||||
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
#ifdef DEBUG_COMMANDS
|
||||
static int
|
||||
getset_register(int argc, char **argv)
|
||||
{
|
||||
@@ -96,6 +89,7 @@ getset_register(int argc, char **argv)
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif // DEBUG_COMMANDS
|
||||
|
||||
|
||||
// #pragma mark - Device Hooks
|
||||
@@ -119,40 +113,38 @@ device_open(const char *name, uint32 /*flags*/, void **_cookie)
|
||||
if (!thisName)
|
||||
return B_BAD_VALUE;
|
||||
}
|
||||
|
||||
intel_info *info = gDeviceInfo[id];
|
||||
*_cookie = info;
|
||||
|
||||
acquire_lock(&gLock);
|
||||
|
||||
status_t status = B_OK;
|
||||
|
||||
// TODO: the second open will succeed even though the first one failed!
|
||||
if (info->open_count++ == 0) {
|
||||
if (info->open_count == 0) {
|
||||
// this device has been opened for the first time, so
|
||||
// we allocate needed resources and initialize the structure
|
||||
status = intel_extreme_init(*info);
|
||||
if (status == B_OK) {
|
||||
info->init_status = intel_extreme_init(*info);
|
||||
if (info->init_status == B_OK) {
|
||||
#ifdef DEBUG_COMMANDS
|
||||
add_debugger_command("ie_reg", getset_register,
|
||||
"dumps or sets the specified intel_extreme register");
|
||||
#endif
|
||||
|
||||
info->open_count++;
|
||||
}
|
||||
}
|
||||
|
||||
release_lock(&gLock);
|
||||
|
||||
return status;
|
||||
if (info->init_status == B_OK)
|
||||
*_cookie = info;
|
||||
|
||||
return info->init_status;
|
||||
}
|
||||
|
||||
|
||||
static status_t
|
||||
device_close(void *data)
|
||||
device_close(void */*data*/)
|
||||
{
|
||||
TRACE((DEVICE_NAME ": close\n"));
|
||||
struct intel_info *info;
|
||||
|
||||
if (check_device_info(info = (intel_info *)data) != B_OK)
|
||||
return B_BAD_VALUE;
|
||||
|
||||
info->cookie_magic = INTEL_FREE_COOKIE_MAGIC;
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
@@ -161,33 +153,29 @@ static status_t
|
||||
device_free(void *data)
|
||||
{
|
||||
struct intel_info *info = (intel_info *)data;
|
||||
status_t retval = B_NO_ERROR;
|
||||
|
||||
if (info == NULL || info->cookie_magic != INTEL_FREE_COOKIE_MAGIC)
|
||||
retval = B_BAD_VALUE;
|
||||
|
||||
acquire_lock(&gLock);
|
||||
|
||||
if (info->open_count-- == 1) {
|
||||
// release info structure
|
||||
info->cookie_magic = 0;
|
||||
remove_debugger_command("ie_reg", getset_register);
|
||||
info->init_status = B_NO_INIT;
|
||||
intel_extreme_uninit(*info);
|
||||
|
||||
#ifdef DEBUG_COMMANDS
|
||||
remove_debugger_command("ie_reg", getset_register);
|
||||
#endif
|
||||
}
|
||||
|
||||
release_lock(&gLock);
|
||||
|
||||
return retval;
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
static status_t
|
||||
device_ioctl(void *data, uint32 op, void *buffer, size_t bufferLength)
|
||||
{
|
||||
struct intel_info *info;
|
||||
|
||||
if (check_device_info(info = (intel_info *)data) != B_OK)
|
||||
return B_BAD_VALUE;
|
||||
struct intel_info *info = (intel_info *)data;
|
||||
|
||||
switch (op) {
|
||||
case B_GET_ACCELERANT_SIGNATURE:
|
||||
@@ -210,7 +198,8 @@ device_ioctl(void *data, uint32 op, void *buffer, size_t bufferLength)
|
||||
// needed for cloning
|
||||
case INTEL_GET_DEVICE_NAME:
|
||||
#ifdef __HAIKU__
|
||||
if (user_strlcpy((char *)buffer, gDeviceNames[info->id], B_PATH_NAME_LENGTH) < B_OK)
|
||||
if (user_strlcpy((char *)buffer, gDeviceNames[info->id],
|
||||
B_PATH_NAME_LENGTH) < B_OK)
|
||||
return B_BAD_ADDRESS;
|
||||
#else
|
||||
strncpy((char *)buffer, gDeviceNames[info->id], B_PATH_NAME_LENGTH);
|
||||
@@ -223,7 +212,8 @@ device_ioctl(void *data, uint32 op, void *buffer, size_t bufferLength)
|
||||
{
|
||||
intel_allocate_graphics_memory allocMemory;
|
||||
#ifdef __HAIKU__
|
||||
if (user_memcpy(&allocMemory, buffer, sizeof(intel_allocate_graphics_memory)) < B_OK)
|
||||
if (user_memcpy(&allocMemory, buffer,
|
||||
sizeof(intel_allocate_graphics_memory)) < B_OK)
|
||||
return B_BAD_ADDRESS;
|
||||
#else
|
||||
memcpy(&allocMemory, buffer, sizeof(intel_allocate_graphics_memory));
|
||||
@@ -237,7 +227,8 @@ device_ioctl(void *data, uint32 op, void *buffer, size_t bufferLength)
|
||||
if (status == B_OK) {
|
||||
// copy result
|
||||
#ifdef __HAIKU__
|
||||
if (user_memcpy(buffer, &allocMemory, sizeof(intel_allocate_graphics_memory)) < B_OK)
|
||||
if (user_memcpy(buffer, &allocMemory,
|
||||
sizeof(intel_allocate_graphics_memory)) < B_OK)
|
||||
return B_BAD_ADDRESS;
|
||||
#else
|
||||
memcpy(buffer, &allocMemory, sizeof(intel_allocate_graphics_memory));
|
||||
@@ -250,7 +241,8 @@ device_ioctl(void *data, uint32 op, void *buffer, size_t bufferLength)
|
||||
{
|
||||
intel_free_graphics_memory freeMemory;
|
||||
#ifdef __HAIKU__
|
||||
if (user_memcpy(&freeMemory, buffer, sizeof(intel_free_graphics_memory)) < B_OK)
|
||||
if (user_memcpy(&freeMemory, buffer,
|
||||
sizeof(intel_free_graphics_memory)) < B_OK)
|
||||
return B_BAD_ADDRESS;
|
||||
#else
|
||||
memcpy(&freeMemory, buffer, sizeof(intel_free_graphics_memory));
|
||||
|
||||
@@ -76,7 +76,8 @@ get_next_intel_extreme(int32 *_cookie, pci_info &info, uint32 &type)
|
||||
continue;
|
||||
|
||||
// check device
|
||||
for (uint32 i = 0; i < sizeof(kSupportedDevices) / sizeof(kSupportedDevices[0]); i++) {
|
||||
for (uint32 i = 0; i < sizeof(kSupportedDevices)
|
||||
/ sizeof(kSupportedDevices[0]); i++) {
|
||||
if (info.device_id == kSupportedDevices[i].device_id) {
|
||||
type = i;
|
||||
*_cookie = index + 1;
|
||||
@@ -169,6 +170,7 @@ init_driver(void)
|
||||
// initialize the structure for later use
|
||||
|
||||
memset(gDeviceInfo[found], 0, sizeof(intel_info));
|
||||
gDeviceInfo[found]->init_status = B_NO_INIT;
|
||||
gDeviceInfo[found]->id = found;
|
||||
gDeviceInfo[found]->pci = info;
|
||||
gDeviceInfo[found]->registers = (uint8 *)info->u.h0.base_registers[0];
|
||||
|
||||
@@ -20,6 +20,14 @@
|
||||
#include <errno.h>
|
||||
|
||||
|
||||
#define TRACE_DEVICE
|
||||
#ifdef TRACE_DEVICE
|
||||
# define TRACE(x) dprintf x
|
||||
#else
|
||||
# define TRACE(x) ;
|
||||
#endif
|
||||
|
||||
|
||||
class AreaKeeper {
|
||||
public:
|
||||
AreaKeeper();
|
||||
@@ -492,11 +500,7 @@ intel_extreme_init(intel_info &info)
|
||||
|
||||
init_interrupt_handler(info);
|
||||
|
||||
info.cookie_magic = INTEL_COOKIE_MAGIC;
|
||||
// this makes the cookie valid to be used
|
||||
|
||||
dprintf(DEVICE_NAME "intel_extreme_init() completed successfully!\n");
|
||||
|
||||
TRACE((DEVICE_NAME "intel_extreme_init() completed successfully!\n"));
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
@@ -504,7 +508,7 @@ intel_extreme_init(intel_info &info)
|
||||
void
|
||||
intel_extreme_uninit(intel_info &info)
|
||||
{
|
||||
dprintf(DEVICE_NAME": intel_extreme_uninit()\n");
|
||||
TRACE((DEVICE_NAME": intel_extreme_uninit()\n"));
|
||||
|
||||
if (!info.fake_interrupts && info.shared_info->vblank_sem > 0) {
|
||||
// disable interrupt generation
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2006, Haiku, Inc. All Rights Reserved.
|
||||
* Copyright 2006-2007, Haiku, Inc. All Rights Reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
@@ -17,8 +17,8 @@
|
||||
|
||||
|
||||
struct intel_info {
|
||||
uint32 cookie_magic;
|
||||
int32 open_count;
|
||||
status_t init_status;
|
||||
int32 id;
|
||||
pci_info *pci;
|
||||
uint8 *registers;
|
||||
|
||||
Reference in New Issue
Block a user