Move watching part from the driver cookie to a device cookie.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@31680 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -33,21 +33,8 @@ static device_manager_info *sDeviceManager;
|
|||||||
static ConditionVariable sBatteryCondition;
|
static ConditionVariable sBatteryCondition;
|
||||||
|
|
||||||
|
|
||||||
status_t ReadBatteryStatus(acpi_battery_cookie* cookie,
|
|
||||||
acpi_battery_info* status);
|
|
||||||
|
|
||||||
int32 acpi_battery_handler(void *data);
|
|
||||||
|
|
||||||
int32
|
|
||||||
acpi_battery_handler(void *data)
|
|
||||||
{
|
|
||||||
|
|
||||||
return B_HANDLED_INTERRUPT;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
ReadBatteryStatus(acpi_battery_cookie* cookie, acpi_battery_info* batteryStatus)
|
ReadBatteryStatus(battery_driver_cookie* cookie, acpi_battery_info* batteryStatus)
|
||||||
{
|
{
|
||||||
status_t status = B_ERROR;
|
status_t status = B_ERROR;
|
||||||
|
|
||||||
@@ -81,7 +68,7 @@ exit:
|
|||||||
}
|
}
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
ReadBatteryInfo(acpi_battery_cookie* cookie,
|
ReadBatteryInfo(battery_driver_cookie* cookie,
|
||||||
acpi_extended_battery_info* batteryInfo)
|
acpi_extended_battery_info* batteryInfo)
|
||||||
{
|
{
|
||||||
status_t status = B_ERROR;
|
status_t status = B_ERROR;
|
||||||
@@ -138,7 +125,7 @@ exit:
|
|||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
EstimatedRuntime(acpi_battery_cookie* cookie, acpi_battery_info* info)
|
EstimatedRuntime(battery_driver_cookie* cookie, acpi_battery_info* info)
|
||||||
{
|
{
|
||||||
status_t status = B_ERROR;
|
status_t status = B_ERROR;
|
||||||
|
|
||||||
@@ -177,7 +164,7 @@ EstimatedRuntime(acpi_battery_cookie* cookie, acpi_battery_info* info)
|
|||||||
void
|
void
|
||||||
battery_notify_handler(acpi_handle device, uint32 value, void *context)
|
battery_notify_handler(acpi_handle device, uint32 value, void *context)
|
||||||
{
|
{
|
||||||
TRACE("battery_notify_handler\n");
|
TRACE("battery_notify_handler event 0x%x\n", int(value));
|
||||||
sBatteryCondition.NotifyAll();
|
sBatteryCondition.NotifyAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -204,7 +191,14 @@ TraceBatteryInfo(acpi_extended_battery_info* batteryInfo)
|
|||||||
static status_t
|
static status_t
|
||||||
acpi_battery_open(void *initCookie, const char *path, int flags, void** cookie)
|
acpi_battery_open(void *initCookie, const char *path, int flags, void** cookie)
|
||||||
{
|
{
|
||||||
acpi_battery_cookie *device = (acpi_battery_cookie*)initCookie;
|
battery_device_cookie *device;
|
||||||
|
device = (battery_device_cookie*)calloc(1, sizeof(battery_device_cookie));
|
||||||
|
if (device == NULL)
|
||||||
|
return B_NO_MEMORY;
|
||||||
|
|
||||||
|
device->driver_cookie = (battery_driver_cookie*)initCookie;
|
||||||
|
device->stop_watching = 0;
|
||||||
|
|
||||||
*cookie = device;
|
*cookie = device;
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
@@ -214,6 +208,9 @@ acpi_battery_open(void *initCookie, const char *path, int flags, void** cookie)
|
|||||||
static status_t
|
static status_t
|
||||||
acpi_battery_close(void* cookie)
|
acpi_battery_close(void* cookie)
|
||||||
{
|
{
|
||||||
|
battery_device_cookie* device = (battery_device_cookie*)cookie;
|
||||||
|
free(device);
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -224,13 +221,13 @@ acpi_battery_read(void* _cookie, off_t position, void *buffer, size_t* numBytes)
|
|||||||
if (*numBytes < 1)
|
if (*numBytes < 1)
|
||||||
return B_IO_ERROR;
|
return B_IO_ERROR;
|
||||||
|
|
||||||
acpi_battery_cookie *device = (acpi_battery_cookie *)_cookie;
|
battery_device_cookie *device = (battery_device_cookie*)_cookie;
|
||||||
|
|
||||||
acpi_battery_info batteryStatus;
|
acpi_battery_info batteryStatus;
|
||||||
ReadBatteryStatus(device, &batteryStatus);
|
ReadBatteryStatus(device->driver_cookie, &batteryStatus);
|
||||||
|
|
||||||
acpi_extended_battery_info batteryInfo;
|
acpi_extended_battery_info batteryInfo;
|
||||||
ReadBatteryInfo(device, &batteryInfo);
|
ReadBatteryInfo(device->driver_cookie, &batteryInfo);
|
||||||
|
|
||||||
if (position == 0) {
|
if (position == 0) {
|
||||||
size_t max_len = *numBytes;
|
size_t max_len = *numBytes;
|
||||||
@@ -288,7 +285,7 @@ status_t
|
|||||||
acpi_battery_control(void* _cookie, uint32 op, void* arg, size_t len)
|
acpi_battery_control(void* _cookie, uint32 op, void* arg, size_t len)
|
||||||
{
|
{
|
||||||
TRACE("acpi_battery: acpi_battery_control op %u\n", int(op));
|
TRACE("acpi_battery: acpi_battery_control op %u\n", int(op));
|
||||||
acpi_battery_cookie* device = (acpi_battery_cookie*)_cookie;
|
battery_device_cookie* device = (battery_device_cookie*)_cookie;
|
||||||
status_t err = B_ERROR;
|
status_t err = B_ERROR;
|
||||||
|
|
||||||
uint32* magicId;
|
uint32* magicId;
|
||||||
@@ -307,14 +304,14 @@ acpi_battery_control(void* _cookie, uint32 op, void* arg, size_t len)
|
|||||||
if (len < sizeof(acpi_battery_info))
|
if (len < sizeof(acpi_battery_info))
|
||||||
return B_IO_ERROR;
|
return B_IO_ERROR;
|
||||||
batteryInfo = (acpi_battery_info*)arg;
|
batteryInfo = (acpi_battery_info*)arg;
|
||||||
err = ReadBatteryStatus(device, batteryInfo);
|
err = ReadBatteryStatus(device->driver_cookie, batteryInfo);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case GET_EXTENDED_BATTERY_INFO:
|
case GET_EXTENDED_BATTERY_INFO:
|
||||||
if (len < sizeof(acpi_extended_battery_info))
|
if (len < sizeof(acpi_extended_battery_info))
|
||||||
return B_IO_ERROR;
|
return B_IO_ERROR;
|
||||||
extBatteryInfo = (acpi_extended_battery_info*)arg;
|
extBatteryInfo = (acpi_extended_battery_info*)arg;
|
||||||
err = ReadBatteryInfo(device, extBatteryInfo);
|
err = ReadBatteryInfo(device->driver_cookie, extBatteryInfo);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case WATCH_BATTERY:
|
case WATCH_BATTERY:
|
||||||
@@ -393,16 +390,15 @@ acpi_battery_register_device(device_node *node)
|
|||||||
static status_t
|
static status_t
|
||||||
acpi_battery_init_driver(device_node *node, void **driverCookie)
|
acpi_battery_init_driver(device_node *node, void **driverCookie)
|
||||||
{
|
{
|
||||||
acpi_battery_cookie *device;
|
battery_driver_cookie *device;
|
||||||
device = (acpi_battery_cookie *)calloc(1, sizeof(acpi_battery_cookie));
|
device = (battery_driver_cookie *)calloc(1, sizeof(battery_driver_cookie));
|
||||||
if (device == NULL)
|
if (device == NULL)
|
||||||
return B_NO_MEMORY;
|
return B_NO_MEMORY;
|
||||||
|
|
||||||
*driverCookie = device;
|
*driverCookie = device;
|
||||||
|
|
||||||
device->node = node;
|
device->node = node;
|
||||||
device->stop_watching = 0;
|
|
||||||
|
|
||||||
device_node *parent;
|
device_node *parent;
|
||||||
parent = sDeviceManager->get_parent_node(node);
|
parent = sDeviceManager->get_parent_node(node);
|
||||||
sDeviceManager->get_driver(parent, (driver_module_info **)&device->acpi,
|
sDeviceManager->get_driver(parent, (driver_module_info **)&device->acpi,
|
||||||
@@ -411,7 +407,7 @@ acpi_battery_init_driver(device_node *node, void **driverCookie)
|
|||||||
|
|
||||||
// install notify handler
|
// install notify handler
|
||||||
device->acpi->install_notify_handler(device->acpi_cookie,
|
device->acpi->install_notify_handler(device->acpi_cookie,
|
||||||
ACPI_ALL_NOTIFY, battery_notify_handler, NULL);
|
ACPI_ALL_NOTIFY, battery_notify_handler, device);
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
@@ -421,7 +417,7 @@ static void
|
|||||||
acpi_battery_uninit_driver(void *driverCookie)
|
acpi_battery_uninit_driver(void *driverCookie)
|
||||||
{
|
{
|
||||||
TRACE("acpi_battery_uninit_driver\n");
|
TRACE("acpi_battery_uninit_driver\n");
|
||||||
acpi_battery_cookie *device = (acpi_battery_cookie*)driverCookie;
|
battery_driver_cookie *device = (battery_driver_cookie*)driverCookie;
|
||||||
|
|
||||||
device->acpi->remove_notify_handler(device->acpi_cookie,
|
device->acpi->remove_notify_handler(device->acpi_cookie,
|
||||||
ACPI_ALL_NOTIFY, battery_notify_handler);
|
ACPI_ALL_NOTIFY, battery_notify_handler);
|
||||||
@@ -433,7 +429,7 @@ acpi_battery_uninit_driver(void *driverCookie)
|
|||||||
static status_t
|
static status_t
|
||||||
acpi_battery_register_child_devices(void *cookie)
|
acpi_battery_register_child_devices(void *cookie)
|
||||||
{
|
{
|
||||||
acpi_battery_cookie *device = (acpi_battery_cookie*)cookie;
|
battery_driver_cookie *device = (battery_driver_cookie*)cookie;
|
||||||
|
|
||||||
int pathID = sDeviceManager->create_id(ACPI_BATTERY_PATHID_GENERATOR);
|
int pathID = sDeviceManager->create_id(ACPI_BATTERY_PATHID_GENERATOR);
|
||||||
if (pathID < 0) {
|
if (pathID < 0) {
|
||||||
@@ -460,7 +456,7 @@ acpi_battery_init_device(void *driverCookie, void **cookie)
|
|||||||
static void
|
static void
|
||||||
acpi_battery_uninit_device(void *_cookie)
|
acpi_battery_uninit_device(void *_cookie)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -24,17 +24,19 @@
|
|||||||
|
|
||||||
#define ACPI_NAME_BATTERY "PNP0C0A"
|
#define ACPI_NAME_BATTERY "PNP0C0A"
|
||||||
|
|
||||||
|
struct battery_driver_cookie {
|
||||||
struct acpi_battery_cookie {
|
device_node* node;
|
||||||
// this three variables are not needed yet but helpfull when extend this
|
acpi_device_module_info* acpi;
|
||||||
// driver to use acpi
|
acpi_device acpi_cookie;
|
||||||
device_node *node;
|
|
||||||
acpi_device_module_info *acpi;
|
|
||||||
acpi_device acpi_cookie;
|
|
||||||
|
|
||||||
vint32 stop_watching;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
struct battery_device_cookie {
|
||||||
|
battery_driver_cookie* driver_cookie;
|
||||||
|
vint32 stop_watching;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/* Notify types */
|
/* Notify types */
|
||||||
|
|
||||||
#define ACPI_SYSTEM_NOTIFY 0x1
|
#define ACPI_SYSTEM_NOTIFY 0x1
|
||||||
|
|||||||
Reference in New Issue
Block a user