fix dos endlines
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@28606 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -1,448 +1,448 @@
|
|||||||
/* ++++++++++
|
/* ++++++++++
|
||||||
ACPI namespace dump.
|
ACPI namespace dump.
|
||||||
Nothing special here, just tree enumeration and type identification.
|
Nothing special here, just tree enumeration and type identification.
|
||||||
+++++ */
|
+++++ */
|
||||||
|
|
||||||
#include <Drivers.h>
|
#include <Drivers.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "acpi_priv.h"
|
#include "acpi_priv.h"
|
||||||
|
|
||||||
#include <util/kernel_cpp.h>
|
#include <util/kernel_cpp.h>
|
||||||
#include <util/ring_buffer.h>
|
#include <util/ring_buffer.h>
|
||||||
|
|
||||||
class RingBuffer {
|
class RingBuffer {
|
||||||
public:
|
public:
|
||||||
RingBuffer(size_t size = 1024);
|
RingBuffer(size_t size = 1024);
|
||||||
~RingBuffer();
|
~RingBuffer();
|
||||||
ssize_t Read(void *buffer, size_t length);
|
ssize_t Read(void *buffer, size_t length);
|
||||||
ssize_t Write(const void *buffer, size_t length);
|
ssize_t Write(const void *buffer, size_t length);
|
||||||
size_t WritableAmount() const;
|
size_t WritableAmount() const;
|
||||||
size_t ReadableAmount() const;
|
size_t ReadableAmount() const;
|
||||||
|
|
||||||
bool Lock();
|
bool Lock();
|
||||||
void Unlock();
|
void Unlock();
|
||||||
private:
|
private:
|
||||||
ring_buffer *fBuffer;
|
ring_buffer *fBuffer;
|
||||||
sem_id fLock;
|
sem_id fLock;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
typedef struct acpi_ns_device_info {
|
typedef struct acpi_ns_device_info {
|
||||||
device_node *node;
|
device_node *node;
|
||||||
acpi_root_info *acpi;
|
acpi_root_info *acpi;
|
||||||
void *acpi_cookie;
|
void *acpi_cookie;
|
||||||
thread_id thread;
|
thread_id thread;
|
||||||
sem_id read_sem;
|
sem_id read_sem;
|
||||||
RingBuffer *buffer;
|
RingBuffer *buffer;
|
||||||
} acpi_ns_device_info;
|
} acpi_ns_device_info;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// called with the buffer lock held
|
// called with the buffer lock held
|
||||||
static bool
|
static bool
|
||||||
make_space(acpi_ns_device_info *device, size_t space)
|
make_space(acpi_ns_device_info *device, size_t space)
|
||||||
{
|
{
|
||||||
size_t available = device->buffer->WritableAmount();
|
size_t available = device->buffer->WritableAmount();
|
||||||
if (space <= available)
|
if (space <= available)
|
||||||
return true;
|
return true;
|
||||||
bool released = false;
|
bool released = false;
|
||||||
do {
|
do {
|
||||||
device->buffer->Unlock();
|
device->buffer->Unlock();
|
||||||
|
|
||||||
if (!released) {
|
if (!released) {
|
||||||
if (release_sem_etc(device->read_sem, 1, B_RELEASE_IF_WAITING_ONLY) == B_OK)
|
if (release_sem_etc(device->read_sem, 1, B_RELEASE_IF_WAITING_ONLY) == B_OK)
|
||||||
released = true;
|
released = true;
|
||||||
}
|
}
|
||||||
snooze(10000);
|
snooze(10000);
|
||||||
|
|
||||||
if (!device->buffer->Lock())
|
if (!device->buffer->Lock())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
} while (device->buffer->WritableAmount() < space);
|
} while (device->buffer->WritableAmount() < space);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
dump_acpi_namespace(acpi_ns_device_info *device, char *root, int indenting)
|
dump_acpi_namespace(acpi_ns_device_info *device, char *root, int indenting)
|
||||||
{
|
{
|
||||||
char result[255];
|
char result[255];
|
||||||
char output[320];
|
char output[320];
|
||||||
char tabs[255];
|
char tabs[255];
|
||||||
char hid[16];
|
char hid[16];
|
||||||
int i;
|
int i;
|
||||||
size_t written = 0;
|
size_t written = 0;
|
||||||
hid[0] = '\0';
|
hid[0] = '\0';
|
||||||
tabs[0] = '\0';
|
tabs[0] = '\0';
|
||||||
for (i = 0; i < indenting; i++)
|
for (i = 0; i < indenting; i++)
|
||||||
strlcat(tabs, "| ", sizeof(tabs));
|
strlcat(tabs, "| ", sizeof(tabs));
|
||||||
|
|
||||||
strlcat(tabs, "|--- ", sizeof(tabs));
|
strlcat(tabs, "|--- ", sizeof(tabs));
|
||||||
|
|
||||||
int depth = sizeof(char) * 5 * indenting + sizeof(char); // index into result where the device name will be.
|
int depth = sizeof(char) * 5 * indenting + sizeof(char); // index into result where the device name will be.
|
||||||
|
|
||||||
void *counter = NULL;
|
void *counter = NULL;
|
||||||
while (device->acpi->get_next_entry(ACPI_TYPE_ANY, root, result, 255, &counter) == B_OK) {
|
while (device->acpi->get_next_entry(ACPI_TYPE_ANY, root, result, 255, &counter) == B_OK) {
|
||||||
uint32 type = device->acpi->get_object_type(result);
|
uint32 type = device->acpi->get_object_type(result);
|
||||||
snprintf(output, sizeof(output), "%s%s", tabs, result + depth);
|
snprintf(output, sizeof(output), "%s%s", tabs, result + depth);
|
||||||
switch(type) {
|
switch(type) {
|
||||||
case ACPI_TYPE_INTEGER:
|
case ACPI_TYPE_INTEGER:
|
||||||
snprintf(output, sizeof(output), "%s INTEGER", output);
|
snprintf(output, sizeof(output), "%s INTEGER", output);
|
||||||
break;
|
break;
|
||||||
case ACPI_TYPE_STRING:
|
case ACPI_TYPE_STRING:
|
||||||
snprintf(output, sizeof(output), "%s STRING", output);
|
snprintf(output, sizeof(output), "%s STRING", output);
|
||||||
break;
|
break;
|
||||||
case ACPI_TYPE_BUFFER:
|
case ACPI_TYPE_BUFFER:
|
||||||
snprintf(output, sizeof(output), "%s BUFFER", output);
|
snprintf(output, sizeof(output), "%s BUFFER", output);
|
||||||
break;
|
break;
|
||||||
case ACPI_TYPE_PACKAGE:
|
case ACPI_TYPE_PACKAGE:
|
||||||
snprintf(output, sizeof(output), "%s PACKAGE", output);
|
snprintf(output, sizeof(output), "%s PACKAGE", output);
|
||||||
break;
|
break;
|
||||||
case ACPI_TYPE_FIELD_UNIT:
|
case ACPI_TYPE_FIELD_UNIT:
|
||||||
snprintf(output, sizeof(output), "%s FIELD UNIT", output);
|
snprintf(output, sizeof(output), "%s FIELD UNIT", output);
|
||||||
break;
|
break;
|
||||||
case ACPI_TYPE_DEVICE:
|
case ACPI_TYPE_DEVICE:
|
||||||
device->acpi->get_device_hid(result, hid);
|
device->acpi->get_device_hid(result, hid);
|
||||||
snprintf(output, sizeof(output), "%s DEVICE (%s)", output, hid);
|
snprintf(output, sizeof(output), "%s DEVICE (%s)", output, hid);
|
||||||
break;
|
break;
|
||||||
case ACPI_TYPE_EVENT:
|
case ACPI_TYPE_EVENT:
|
||||||
snprintf(output, sizeof(output), "%s EVENT", output);
|
snprintf(output, sizeof(output), "%s EVENT", output);
|
||||||
break;
|
break;
|
||||||
case ACPI_TYPE_METHOD:
|
case ACPI_TYPE_METHOD:
|
||||||
snprintf(output, sizeof(output), "%s METHOD", output);
|
snprintf(output, sizeof(output), "%s METHOD", output);
|
||||||
break;
|
break;
|
||||||
case ACPI_TYPE_MUTEX:
|
case ACPI_TYPE_MUTEX:
|
||||||
snprintf(output, sizeof(output), "%s MUTEX", output);
|
snprintf(output, sizeof(output), "%s MUTEX", output);
|
||||||
break;
|
break;
|
||||||
case ACPI_TYPE_REGION:
|
case ACPI_TYPE_REGION:
|
||||||
snprintf(output, sizeof(output), "%s REGION", output);
|
snprintf(output, sizeof(output), "%s REGION", output);
|
||||||
break;
|
break;
|
||||||
case ACPI_TYPE_POWER:
|
case ACPI_TYPE_POWER:
|
||||||
snprintf(output, sizeof(output), "%s POWER", output);
|
snprintf(output, sizeof(output), "%s POWER", output);
|
||||||
break;
|
break;
|
||||||
case ACPI_TYPE_PROCESSOR:
|
case ACPI_TYPE_PROCESSOR:
|
||||||
snprintf(output, sizeof(output), "%s PROCESSOR", output);
|
snprintf(output, sizeof(output), "%s PROCESSOR", output);
|
||||||
break;
|
break;
|
||||||
case ACPI_TYPE_THERMAL:
|
case ACPI_TYPE_THERMAL:
|
||||||
snprintf(output, sizeof(output), "%s THERMAL", output);
|
snprintf(output, sizeof(output), "%s THERMAL", output);
|
||||||
break;
|
break;
|
||||||
case ACPI_TYPE_BUFFER_FIELD:
|
case ACPI_TYPE_BUFFER_FIELD:
|
||||||
snprintf(output, sizeof(output), "%s BUFFER_FIELD", output);
|
snprintf(output, sizeof(output), "%s BUFFER_FIELD", output);
|
||||||
break;
|
break;
|
||||||
case ACPI_TYPE_ANY:
|
case ACPI_TYPE_ANY:
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
written = 0;
|
written = 0;
|
||||||
RingBuffer &ringBuffer = *device->buffer;
|
RingBuffer &ringBuffer = *device->buffer;
|
||||||
size_t toWrite = strlen(output);
|
size_t toWrite = strlen(output);
|
||||||
if (toWrite > 0) {
|
if (toWrite > 0) {
|
||||||
strlcat(output, "\n", sizeof(output));
|
strlcat(output, "\n", sizeof(output));
|
||||||
toWrite++;
|
toWrite++;
|
||||||
if (ringBuffer.Lock()) {
|
if (ringBuffer.Lock()) {
|
||||||
if (ringBuffer.WritableAmount() < toWrite) {
|
if (ringBuffer.WritableAmount() < toWrite) {
|
||||||
//dprintf("not enough space\n");
|
//dprintf("not enough space\n");
|
||||||
if (!make_space(device, toWrite)) {
|
if (!make_space(device, toWrite)) {
|
||||||
panic("couldn't make space");
|
panic("couldn't make space");
|
||||||
exit_thread(0);
|
exit_thread(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
written = ringBuffer.Write(output, toWrite);
|
written = ringBuffer.Write(output, toWrite);
|
||||||
//dprintf("written %ld bytes\n", written);
|
//dprintf("written %ld bytes\n", written);
|
||||||
ringBuffer.Unlock();
|
ringBuffer.Unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
dump_acpi_namespace(device, result, indenting + 1);
|
dump_acpi_namespace(device, result, indenting + 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int32
|
static int32
|
||||||
acpi_namespace_dump(void *arg)
|
acpi_namespace_dump(void *arg)
|
||||||
{
|
{
|
||||||
acpi_ns_device_info *device = (acpi_ns_device_info*)(arg);
|
acpi_ns_device_info *device = (acpi_ns_device_info*)(arg);
|
||||||
dump_acpi_namespace(device, NULL, 0);
|
dump_acpi_namespace(device, NULL, 0);
|
||||||
|
|
||||||
delete_sem(device->read_sem);
|
delete_sem(device->read_sem);
|
||||||
device->read_sem = -1;
|
device->read_sem = -1;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
/* ----------
|
/* ----------
|
||||||
acpi_namespace_open - handle open() calls
|
acpi_namespace_open - handle open() calls
|
||||||
----- */
|
----- */
|
||||||
|
|
||||||
static status_t
|
static status_t
|
||||||
acpi_namespace_open(void *_cookie, const char* path, int flags, void** cookie)
|
acpi_namespace_open(void *_cookie, const char* path, int flags, void** cookie)
|
||||||
{
|
{
|
||||||
acpi_ns_device_info *device = (acpi_ns_device_info *)_cookie;
|
acpi_ns_device_info *device = (acpi_ns_device_info *)_cookie;
|
||||||
|
|
||||||
dprintf("\nacpi_ns_dump: device_open\n");
|
dprintf("\nacpi_ns_dump: device_open\n");
|
||||||
|
|
||||||
*cookie = device;
|
*cookie = device;
|
||||||
|
|
||||||
RingBuffer *ringBuffer = new RingBuffer(1024);
|
RingBuffer *ringBuffer = new RingBuffer(1024);
|
||||||
if (ringBuffer == NULL)
|
if (ringBuffer == NULL)
|
||||||
return B_NO_MEMORY;
|
return B_NO_MEMORY;
|
||||||
|
|
||||||
device->read_sem = create_sem(0, "read_sem");
|
device->read_sem = create_sem(0, "read_sem");
|
||||||
if (device->read_sem < B_OK) {
|
if (device->read_sem < B_OK) {
|
||||||
delete ringBuffer;
|
delete ringBuffer;
|
||||||
return device->read_sem;
|
return device->read_sem;
|
||||||
}
|
}
|
||||||
|
|
||||||
device->thread = spawn_kernel_thread(acpi_namespace_dump, "acpi dumper",
|
device->thread = spawn_kernel_thread(acpi_namespace_dump, "acpi dumper",
|
||||||
B_NORMAL_PRIORITY, device);
|
B_NORMAL_PRIORITY, device);
|
||||||
if (device->thread < 0) {
|
if (device->thread < 0) {
|
||||||
delete ringBuffer;
|
delete ringBuffer;
|
||||||
delete_sem(device->read_sem);
|
delete_sem(device->read_sem);
|
||||||
return device->thread;
|
return device->thread;
|
||||||
}
|
}
|
||||||
|
|
||||||
device->buffer = ringBuffer;
|
device->buffer = ringBuffer;
|
||||||
|
|
||||||
resume_thread(device->thread);
|
resume_thread(device->thread);
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* ----------
|
/* ----------
|
||||||
acpi_namespace_read - handle read() calls
|
acpi_namespace_read - handle read() calls
|
||||||
----- */
|
----- */
|
||||||
static status_t
|
static status_t
|
||||||
acpi_namespace_read(void *_cookie, off_t position, void *buf, size_t* num_bytes)
|
acpi_namespace_read(void *_cookie, off_t position, void *buf, size_t* num_bytes)
|
||||||
{
|
{
|
||||||
acpi_ns_device_info *device = (acpi_ns_device_info *)_cookie;
|
acpi_ns_device_info *device = (acpi_ns_device_info *)_cookie;
|
||||||
size_t bytesRead = 0;
|
size_t bytesRead = 0;
|
||||||
size_t readable = 0;
|
size_t readable = 0;
|
||||||
//dprintf("acpi_namespace_read(cookie: %p, position: %lld, buffer: %p, size: %ld)\n",
|
//dprintf("acpi_namespace_read(cookie: %p, position: %lld, buffer: %p, size: %ld)\n",
|
||||||
// _cookie, position, buf, *num_bytes);
|
// _cookie, position, buf, *num_bytes);
|
||||||
|
|
||||||
RingBuffer &ringBuffer = *device->buffer;
|
RingBuffer &ringBuffer = *device->buffer;
|
||||||
|
|
||||||
if (ringBuffer.Lock()) {
|
if (ringBuffer.Lock()) {
|
||||||
readable = ringBuffer.ReadableAmount();
|
readable = ringBuffer.ReadableAmount();
|
||||||
|
|
||||||
//dprintf("%ld bytes readable\n", readable);
|
//dprintf("%ld bytes readable\n", readable);
|
||||||
if (readable <= 0) {
|
if (readable <= 0) {
|
||||||
//dprintf("acquiring read sem...\n");
|
//dprintf("acquiring read sem...\n");
|
||||||
ringBuffer.Unlock();
|
ringBuffer.Unlock();
|
||||||
status_t status = acquire_sem_etc(device->read_sem, 1, B_CAN_INTERRUPT, 0);
|
status_t status = acquire_sem_etc(device->read_sem, 1, B_CAN_INTERRUPT, 0);
|
||||||
if (status == B_INTERRUPTED) {
|
if (status == B_INTERRUPTED) {
|
||||||
//dprintf("read: acquire_sem returned %s\n", strerror(status));
|
//dprintf("read: acquire_sem returned %s\n", strerror(status));
|
||||||
*num_bytes = 0;
|
*num_bytes = 0;
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
//dprintf("read sem acquired\n");
|
//dprintf("read sem acquired\n");
|
||||||
if (!ringBuffer.Lock()) {
|
if (!ringBuffer.Lock()) {
|
||||||
dprintf("read: couldn't acquire lock. bailing\n");
|
dprintf("read: couldn't acquire lock. bailing\n");
|
||||||
*num_bytes = 0;
|
*num_bytes = 0;
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//dprintf("readable %ld\n", ringBuffer.ReadableAmount());
|
//dprintf("readable %ld\n", ringBuffer.ReadableAmount());
|
||||||
bytesRead = ringBuffer.Read(buf, *num_bytes);
|
bytesRead = ringBuffer.Read(buf, *num_bytes);
|
||||||
ringBuffer.Unlock();
|
ringBuffer.Unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
//dprintf("read: read %ld bytes\n", bytesRead);
|
//dprintf("read: read %ld bytes\n", bytesRead);
|
||||||
if (bytesRead < 0) {
|
if (bytesRead < 0) {
|
||||||
*num_bytes = 0;
|
*num_bytes = 0;
|
||||||
return bytesRead;
|
return bytesRead;
|
||||||
}
|
}
|
||||||
|
|
||||||
*num_bytes = bytesRead;
|
*num_bytes = bytesRead;
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* ----------
|
/* ----------
|
||||||
acpi_namespace_write - handle write() calls
|
acpi_namespace_write - handle write() calls
|
||||||
----- */
|
----- */
|
||||||
|
|
||||||
static status_t
|
static status_t
|
||||||
acpi_namespace_write(void* cookie, off_t position, const void* buffer, size_t* num_bytes)
|
acpi_namespace_write(void* cookie, off_t position, const void* buffer, size_t* num_bytes)
|
||||||
{
|
{
|
||||||
dprintf("acpi_ns_dump: device_write\n");
|
dprintf("acpi_ns_dump: device_write\n");
|
||||||
*num_bytes = 0; /* tell caller nothing was written */
|
*num_bytes = 0; /* tell caller nothing was written */
|
||||||
return B_IO_ERROR;
|
return B_IO_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* ----------
|
/* ----------
|
||||||
acpi_namespace_control - handle ioctl calls
|
acpi_namespace_control - handle ioctl calls
|
||||||
----- */
|
----- */
|
||||||
|
|
||||||
static status_t
|
static status_t
|
||||||
acpi_namespace_control(void* cookie, uint32 op, void* arg, size_t len)
|
acpi_namespace_control(void* cookie, uint32 op, void* arg, size_t len)
|
||||||
{
|
{
|
||||||
dprintf("acpi_ns_dump: device_control\n");
|
dprintf("acpi_ns_dump: device_control\n");
|
||||||
return B_BAD_VALUE;
|
return B_BAD_VALUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* ----------
|
/* ----------
|
||||||
acpi_namespace_close - handle close() calls
|
acpi_namespace_close - handle close() calls
|
||||||
----- */
|
----- */
|
||||||
|
|
||||||
static status_t
|
static status_t
|
||||||
acpi_namespace_close(void* cookie)
|
acpi_namespace_close(void* cookie)
|
||||||
{
|
{
|
||||||
acpi_ns_device_info *device = (acpi_ns_device_info *)cookie;
|
acpi_ns_device_info *device = (acpi_ns_device_info *)cookie;
|
||||||
dprintf("acpi_ns_dump: device_close\n");
|
dprintf("acpi_ns_dump: device_close\n");
|
||||||
|
|
||||||
if (device->read_sem >= 0)
|
if (device->read_sem >= 0)
|
||||||
delete_sem(device->read_sem);
|
delete_sem(device->read_sem);
|
||||||
|
|
||||||
kill_thread(device->thread);
|
kill_thread(device->thread);
|
||||||
|
|
||||||
delete device->buffer;
|
delete device->buffer;
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* -----
|
/* -----
|
||||||
acpi_namespace_free - called after the last device is closed, and after
|
acpi_namespace_free - called after the last device is closed, and after
|
||||||
all i/o is complete.
|
all i/o is complete.
|
||||||
----- */
|
----- */
|
||||||
static status_t
|
static status_t
|
||||||
acpi_namespace_free(void* cookie)
|
acpi_namespace_free(void* cookie)
|
||||||
{
|
{
|
||||||
dprintf("acpi_ns_dump: device_free\n");
|
dprintf("acpi_ns_dump: device_free\n");
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// #pragma mark - device module API
|
// #pragma mark - device module API
|
||||||
|
|
||||||
|
|
||||||
static status_t
|
static status_t
|
||||||
acpi_namespace_init_device(void *_cookie, void **cookie)
|
acpi_namespace_init_device(void *_cookie, void **cookie)
|
||||||
{
|
{
|
||||||
device_node *node = (device_node *)_cookie;
|
device_node *node = (device_node *)_cookie;
|
||||||
status_t err;
|
status_t err;
|
||||||
|
|
||||||
acpi_ns_device_info *device = (acpi_ns_device_info *)calloc(1, sizeof(*device));
|
acpi_ns_device_info *device = (acpi_ns_device_info *)calloc(1, sizeof(*device));
|
||||||
if (device == NULL)
|
if (device == NULL)
|
||||||
return B_NO_MEMORY;
|
return B_NO_MEMORY;
|
||||||
|
|
||||||
device->node = node;
|
device->node = node;
|
||||||
err = gDeviceManager->get_driver(node, (driver_module_info **)&device->acpi,
|
err = gDeviceManager->get_driver(node, (driver_module_info **)&device->acpi,
|
||||||
(void **)&device->acpi_cookie);
|
(void **)&device->acpi_cookie);
|
||||||
if (err != B_OK) {
|
if (err != B_OK) {
|
||||||
free(device);
|
free(device);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
*cookie = device;
|
*cookie = device;
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
acpi_namespace_uninit_device(void *_cookie)
|
acpi_namespace_uninit_device(void *_cookie)
|
||||||
{
|
{
|
||||||
acpi_ns_device_info *device = (acpi_ns_device_info *)_cookie;
|
acpi_ns_device_info *device = (acpi_ns_device_info *)_cookie;
|
||||||
free(device);
|
free(device);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct device_module_info acpi_ns_dump_module = {
|
struct device_module_info acpi_ns_dump_module = {
|
||||||
{
|
{
|
||||||
ACPI_NS_DUMP_DEVICE_MODULE_NAME,
|
ACPI_NS_DUMP_DEVICE_MODULE_NAME,
|
||||||
0,
|
0,
|
||||||
NULL
|
NULL
|
||||||
},
|
},
|
||||||
|
|
||||||
acpi_namespace_init_device,
|
acpi_namespace_init_device,
|
||||||
acpi_namespace_uninit_device,
|
acpi_namespace_uninit_device,
|
||||||
NULL,
|
NULL,
|
||||||
|
|
||||||
acpi_namespace_open,
|
acpi_namespace_open,
|
||||||
acpi_namespace_close,
|
acpi_namespace_close,
|
||||||
acpi_namespace_free,
|
acpi_namespace_free,
|
||||||
acpi_namespace_read,
|
acpi_namespace_read,
|
||||||
acpi_namespace_write,
|
acpi_namespace_write,
|
||||||
NULL,
|
NULL,
|
||||||
acpi_namespace_control,
|
acpi_namespace_control,
|
||||||
|
|
||||||
NULL,
|
NULL,
|
||||||
NULL
|
NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
RingBuffer::RingBuffer(size_t size)
|
RingBuffer::RingBuffer(size_t size)
|
||||||
{
|
{
|
||||||
fBuffer = create_ring_buffer(size);
|
fBuffer = create_ring_buffer(size);
|
||||||
fLock = create_sem(1, "ring buffer lock");
|
fLock = create_sem(1, "ring buffer lock");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
RingBuffer::~RingBuffer()
|
RingBuffer::~RingBuffer()
|
||||||
{
|
{
|
||||||
delete_sem(fLock);
|
delete_sem(fLock);
|
||||||
delete_ring_buffer(fBuffer);
|
delete_ring_buffer(fBuffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
ssize_t
|
ssize_t
|
||||||
RingBuffer::Read(void *buffer, size_t size)
|
RingBuffer::Read(void *buffer, size_t size)
|
||||||
{
|
{
|
||||||
return ring_buffer_read(fBuffer, (uint8*)buffer, size);
|
return ring_buffer_read(fBuffer, (uint8*)buffer, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
ssize_t
|
ssize_t
|
||||||
RingBuffer::Write(const void *buffer, size_t size)
|
RingBuffer::Write(const void *buffer, size_t size)
|
||||||
{
|
{
|
||||||
return ring_buffer_write(fBuffer, (uint8*)buffer, size);
|
return ring_buffer_write(fBuffer, (uint8*)buffer, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
size_t
|
size_t
|
||||||
RingBuffer::ReadableAmount() const
|
RingBuffer::ReadableAmount() const
|
||||||
{
|
{
|
||||||
return ring_buffer_readable(fBuffer);
|
return ring_buffer_readable(fBuffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
size_t
|
size_t
|
||||||
RingBuffer::WritableAmount() const
|
RingBuffer::WritableAmount() const
|
||||||
{
|
{
|
||||||
return ring_buffer_writable(fBuffer);
|
return ring_buffer_writable(fBuffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
RingBuffer::Lock()
|
RingBuffer::Lock()
|
||||||
{
|
{
|
||||||
//status_t status = acquire_sem_etc(fLock, 1, B_CAN_INTERRUPT, 0);
|
//status_t status = acquire_sem_etc(fLock, 1, B_CAN_INTERRUPT, 0);
|
||||||
status_t status = acquire_sem(fLock);
|
status_t status = acquire_sem(fLock);
|
||||||
return status == B_OK;
|
return status == B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
RingBuffer::Unlock()
|
RingBuffer::Unlock()
|
||||||
{
|
{
|
||||||
release_sem(fLock);
|
release_sem(fLock);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user