acpi: switch acpi_object from a struct to a union
* this way the size of acpi_object_type matches the size of ACPI_OBJECT for 32-bit and 64-bit builds. * adjust users of the type acpi_object_type.
This commit is contained in:
+36
-29
@@ -11,7 +11,7 @@
|
|||||||
|
|
||||||
|
|
||||||
typedef struct acpi_module_info acpi_module_info;
|
typedef struct acpi_module_info acpi_module_info;
|
||||||
typedef struct acpi_object_type acpi_object_type;
|
typedef union acpi_object_type acpi_object_type;
|
||||||
|
|
||||||
#define B_ACPI_MODULE_NAME "bus_managers/acpi/v1"
|
#define B_ACPI_MODULE_NAME "bus_managers/acpi/v1"
|
||||||
|
|
||||||
@@ -83,36 +83,43 @@ enum {
|
|||||||
|
|
||||||
/* ACPI control method arg type */
|
/* ACPI control method arg type */
|
||||||
|
|
||||||
struct acpi_object_type {
|
union acpi_object_type {
|
||||||
uint32 object_type;
|
uint32 object_type;
|
||||||
union {
|
struct {
|
||||||
|
uint32 object_type;
|
||||||
uint64 integer;
|
uint64 integer;
|
||||||
struct {
|
} integer;
|
||||||
uint32 len;
|
struct {
|
||||||
char *string; /* You have to allocate string space yourself */
|
uint32 object_type;
|
||||||
} string;
|
uint32 len;
|
||||||
struct {
|
char *string; /* You have to allocate string space yourself */
|
||||||
size_t length;
|
} string;
|
||||||
void *buffer;
|
struct {
|
||||||
} buffer;
|
uint32 object_type;
|
||||||
struct {
|
uint32 length;
|
||||||
uint32 count;
|
void *buffer;
|
||||||
acpi_object_type *objects;
|
} buffer;
|
||||||
} package;
|
struct {
|
||||||
struct {
|
uint32 object_type;
|
||||||
uint32 actual_type;
|
uint32 count;
|
||||||
acpi_handle handle;
|
acpi_object_type *objects;
|
||||||
} reference;
|
} package;
|
||||||
struct {
|
struct {
|
||||||
uint32 cpu_id;
|
uint32 object_type;
|
||||||
int pblk_address;
|
uint32 actual_type;
|
||||||
size_t pblk_length;
|
acpi_handle handle;
|
||||||
} processor;
|
} reference;
|
||||||
struct {
|
struct {
|
||||||
uint32 min_power_state;
|
uint32 object_type;
|
||||||
uint32 resource_order;
|
uint32 cpu_id;
|
||||||
} power_resource;
|
acpi_io_address pblk_address;
|
||||||
} data;
|
uint32 pblk_length;
|
||||||
|
} processor;
|
||||||
|
struct {
|
||||||
|
uint32 object_type;
|
||||||
|
uint32 min_power_state;
|
||||||
|
uint32 resource_order;
|
||||||
|
} power_resource;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -81,7 +81,7 @@ acpi_GetInteger(acpi_device_module_info* acpi, acpi_device& acpiCookie,
|
|||||||
status_t status = acpi->evaluate_method(acpiCookie, path, NULL, &buf);
|
status_t status = acpi->evaluate_method(acpiCookie, path, NULL, &buf);
|
||||||
if (status == B_OK) {
|
if (status == B_OK) {
|
||||||
if (object.object_type == ACPI_TYPE_INTEGER)
|
if (object.object_type == ACPI_TYPE_INTEGER)
|
||||||
*number = object.data.integer;
|
*number = object.integer.integer;
|
||||||
else
|
else
|
||||||
status = B_BAD_VALUE;
|
status = B_BAD_VALUE;
|
||||||
}
|
}
|
||||||
@@ -99,7 +99,7 @@ acpi_GetReference(acpi_module_info* acpi, acpi_handle scope,
|
|||||||
switch (obj->object_type) {
|
switch (obj->object_type) {
|
||||||
case ACPI_TYPE_LOCAL_REFERENCE:
|
case ACPI_TYPE_LOCAL_REFERENCE:
|
||||||
case ACPI_TYPE_ANY:
|
case ACPI_TYPE_ANY:
|
||||||
return obj->data.reference.handle;
|
return obj->reference.handle;
|
||||||
|
|
||||||
case ACPI_TYPE_STRING:
|
case ACPI_TYPE_STRING:
|
||||||
{
|
{
|
||||||
@@ -107,7 +107,7 @@ acpi_GetReference(acpi_module_info* acpi, acpi_handle scope,
|
|||||||
// scope can be NULL.
|
// scope can be NULL.
|
||||||
// TODO: This may not always be the case.
|
// TODO: This may not always be the case.
|
||||||
acpi_handle handle;
|
acpi_handle handle;
|
||||||
if (acpi->get_handle(scope, obj->data.string.string, &handle)
|
if (acpi->get_handle(scope, obj->string.string, &handle)
|
||||||
== B_OK)
|
== B_OK)
|
||||||
return handle;
|
return handle;
|
||||||
}
|
}
|
||||||
@@ -120,10 +120,10 @@ acpi_GetReference(acpi_module_info* acpi, acpi_handle scope,
|
|||||||
status_t
|
status_t
|
||||||
acpi_PkgInt(acpi_object_type* res, int idx, int* dst)
|
acpi_PkgInt(acpi_object_type* res, int idx, int* dst)
|
||||||
{
|
{
|
||||||
acpi_object_type* obj = &res->data.package.objects[idx];
|
acpi_object_type* obj = &res->package.objects[idx];
|
||||||
if (obj == NULL || obj->object_type != ACPI_TYPE_INTEGER)
|
if (obj == NULL || obj->object_type != ACPI_TYPE_INTEGER)
|
||||||
return B_BAD_VALUE;
|
return B_BAD_VALUE;
|
||||||
*dst = obj->data.integer;
|
*dst = obj->integer.integer;
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
@@ -336,13 +336,13 @@ embedded_controller_init_driver(device_node* dev, void** _driverCookie)
|
|||||||
switch (obj->object_type) {
|
switch (obj->object_type) {
|
||||||
case ACPI_TYPE_INTEGER:
|
case ACPI_TYPE_INTEGER:
|
||||||
sc->ec_gpehandle = NULL;
|
sc->ec_gpehandle = NULL;
|
||||||
sc->ec_gpebit = obj->data.integer;
|
sc->ec_gpebit = obj->integer.integer;
|
||||||
break;
|
break;
|
||||||
case ACPI_TYPE_PACKAGE:
|
case ACPI_TYPE_PACKAGE:
|
||||||
if (!ACPI_PKG_VALID(obj, 2))
|
if (!ACPI_PKG_VALID(obj, 2))
|
||||||
goto error;
|
goto error;
|
||||||
sc->ec_gpehandle = acpi_GetReference(sc->ec_acpi_module, NULL,
|
sc->ec_gpehandle = acpi_GetReference(sc->ec_acpi_module, NULL,
|
||||||
&obj->data.package.objects[0]);
|
&obj->package.objects[0]);
|
||||||
if (sc->ec_gpehandle == NULL
|
if (sc->ec_gpehandle == NULL
|
||||||
|| acpi_PkgInt32(obj, 1, (uint32*)&sc->ec_gpebit) != B_OK)
|
|| acpi_PkgInt32(obj, 1, (uint32*)&sc->ec_gpebit) != B_OK)
|
||||||
goto error;
|
goto error;
|
||||||
|
|||||||
@@ -128,7 +128,7 @@ typedef uint8 EC_EVENT;
|
|||||||
|
|
||||||
#define ACPI_PKG_VALID(pkg, size) \
|
#define ACPI_PKG_VALID(pkg, size) \
|
||||||
((pkg) != NULL && (pkg)->object_type == ACPI_TYPE_PACKAGE && \
|
((pkg) != NULL && (pkg)->object_type == ACPI_TYPE_PACKAGE && \
|
||||||
(pkg)->data.package.count >= (size))
|
(pkg)->package.count >= (size))
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -76,26 +76,26 @@ ReadBatteryStatus(battery_driver_cookie* cookie,
|
|||||||
|
|
||||||
object = (acpi_object_type*)buffer.pointer;
|
object = (acpi_object_type*)buffer.pointer;
|
||||||
if (object->object_type != ACPI_TYPE_PACKAGE
|
if (object->object_type != ACPI_TYPE_PACKAGE
|
||||||
|| object->data.package.count < 4) {
|
|| object->package.count < 4) {
|
||||||
status = B_ERROR;
|
status = B_ERROR;
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
pointer = object->data.package.objects;
|
pointer = object->package.objects;
|
||||||
batteryStatus->state = (pointer->object_type == ACPI_TYPE_INTEGER)
|
batteryStatus->state = (pointer->object_type == ACPI_TYPE_INTEGER)
|
||||||
? pointer->data.integer : BATTERY_CRITICAL_STATE;
|
? pointer->integer.integer : BATTERY_CRITICAL_STATE;
|
||||||
|
|
||||||
pointer++;
|
pointer++;
|
||||||
batteryStatus->current_rate = (pointer->object_type == ACPI_TYPE_INTEGER)
|
batteryStatus->current_rate = (pointer->object_type == ACPI_TYPE_INTEGER)
|
||||||
? pointer->data.integer : -1;
|
? pointer->integer.integer : -1;
|
||||||
|
|
||||||
pointer++;
|
pointer++;
|
||||||
batteryStatus->capacity = (pointer->object_type == ACPI_TYPE_INTEGER)
|
batteryStatus->capacity = (pointer->object_type == ACPI_TYPE_INTEGER)
|
||||||
? pointer->data.integer : -1;
|
? pointer->integer.integer : -1;
|
||||||
|
|
||||||
pointer++;
|
pointer++;
|
||||||
batteryStatus->voltage = (pointer->object_type == ACPI_TYPE_INTEGER)
|
batteryStatus->voltage = (pointer->object_type == ACPI_TYPE_INTEGER)
|
||||||
? pointer->data.integer : -1;
|
? pointer->integer.integer : -1;
|
||||||
|
|
||||||
/* If key values are all < 0, it is likely that the battery slot is empty
|
/* If key values are all < 0, it is likely that the battery slot is empty
|
||||||
* or the battery is damaged. Set BATTERY_CRITICAL_STATE
|
* or the battery is damaged. Set BATTERY_CRITICAL_STATE
|
||||||
@@ -131,68 +131,68 @@ ReadBatteryInfo(battery_driver_cookie* cookie,
|
|||||||
|
|
||||||
object = (acpi_object_type*)buffer.pointer;
|
object = (acpi_object_type*)buffer.pointer;
|
||||||
if (object->object_type != ACPI_TYPE_PACKAGE
|
if (object->object_type != ACPI_TYPE_PACKAGE
|
||||||
|| object->data.package.count < 13) {
|
|| object->package.count < 13) {
|
||||||
status = B_ERROR;
|
status = B_ERROR;
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
pointer = object->data.package.objects;
|
pointer = object->package.objects;
|
||||||
batteryInfo->power_unit = (pointer->object_type == ACPI_TYPE_INTEGER)
|
batteryInfo->power_unit = (pointer->object_type == ACPI_TYPE_INTEGER)
|
||||||
? pointer->data.integer : -1;
|
? pointer->integer.integer : -1;
|
||||||
|
|
||||||
pointer++;
|
pointer++;
|
||||||
batteryInfo->design_capacity = (pointer->object_type == ACPI_TYPE_INTEGER)
|
batteryInfo->design_capacity = (pointer->object_type == ACPI_TYPE_INTEGER)
|
||||||
? pointer->data.integer : -1;
|
? pointer->integer.integer : -1;
|
||||||
|
|
||||||
pointer++;
|
pointer++;
|
||||||
batteryInfo->last_full_charge = (pointer->object_type == ACPI_TYPE_INTEGER)
|
batteryInfo->last_full_charge = (pointer->object_type == ACPI_TYPE_INTEGER)
|
||||||
? pointer->data.integer : -1;
|
? pointer->integer.integer : -1;
|
||||||
|
|
||||||
pointer++;
|
pointer++;
|
||||||
batteryInfo->technology = (pointer->object_type == ACPI_TYPE_INTEGER)
|
batteryInfo->technology = (pointer->object_type == ACPI_TYPE_INTEGER)
|
||||||
? pointer->data.integer : -1;
|
? pointer->integer.integer : -1;
|
||||||
|
|
||||||
pointer++;
|
pointer++;
|
||||||
batteryInfo->design_voltage = (pointer->object_type == ACPI_TYPE_INTEGER)
|
batteryInfo->design_voltage = (pointer->object_type == ACPI_TYPE_INTEGER)
|
||||||
? pointer->data.integer : -1;
|
? pointer->integer.integer : -1;
|
||||||
|
|
||||||
pointer++;
|
pointer++;
|
||||||
batteryInfo->design_capacity_warning =
|
batteryInfo->design_capacity_warning =
|
||||||
(pointer->object_type == ACPI_TYPE_INTEGER)
|
(pointer->object_type == ACPI_TYPE_INTEGER)
|
||||||
? pointer->data.integer : -1;
|
? pointer->integer.integer : -1;
|
||||||
|
|
||||||
pointer++;
|
pointer++;
|
||||||
batteryInfo->design_capacity_low =
|
batteryInfo->design_capacity_low =
|
||||||
(pointer->object_type == ACPI_TYPE_INTEGER)
|
(pointer->object_type == ACPI_TYPE_INTEGER)
|
||||||
? pointer->data.integer : -1;
|
? pointer->integer.integer : -1;
|
||||||
|
|
||||||
pointer++;
|
pointer++;
|
||||||
batteryInfo->capacity_granularity_1 =
|
batteryInfo->capacity_granularity_1 =
|
||||||
(pointer->object_type == ACPI_TYPE_INTEGER)
|
(pointer->object_type == ACPI_TYPE_INTEGER)
|
||||||
? pointer->data.integer : -1;
|
? pointer->integer.integer : -1;
|
||||||
|
|
||||||
pointer++;
|
pointer++;
|
||||||
batteryInfo->capacity_granularity_2 =
|
batteryInfo->capacity_granularity_2 =
|
||||||
(pointer->object_type == ACPI_TYPE_INTEGER)
|
(pointer->object_type == ACPI_TYPE_INTEGER)
|
||||||
? pointer->data.integer : -1;
|
? pointer->integer.integer : -1;
|
||||||
|
|
||||||
pointer++;
|
pointer++;
|
||||||
strlcpy(batteryInfo->model_number,
|
strlcpy(batteryInfo->model_number,
|
||||||
(pointer->object_type == ACPI_TYPE_STRING)
|
(pointer->object_type == ACPI_TYPE_STRING)
|
||||||
? pointer->data.string.string : "", sizeof(batteryInfo->model_number));
|
? pointer->string.string : "", sizeof(batteryInfo->model_number));
|
||||||
|
|
||||||
pointer++;
|
pointer++;
|
||||||
strlcpy(batteryInfo->serial_number,
|
strlcpy(batteryInfo->serial_number,
|
||||||
(pointer->object_type == ACPI_TYPE_STRING)
|
(pointer->object_type == ACPI_TYPE_STRING)
|
||||||
? pointer->data.string.string : "", sizeof(batteryInfo->serial_number));
|
? pointer->string.string : "", sizeof(batteryInfo->serial_number));
|
||||||
|
|
||||||
pointer++;
|
pointer++;
|
||||||
strlcpy(batteryInfo->type, (pointer->object_type == ACPI_TYPE_STRING)
|
strlcpy(batteryInfo->type, (pointer->object_type == ACPI_TYPE_STRING)
|
||||||
? pointer->data.string.string : "", sizeof(batteryInfo->type));
|
? pointer->string.string : "", sizeof(batteryInfo->type));
|
||||||
|
|
||||||
pointer++;
|
pointer++;
|
||||||
strlcpy(batteryInfo->oem_info, (pointer->object_type == ACPI_TYPE_STRING)
|
strlcpy(batteryInfo->oem_info, (pointer->object_type == ACPI_TYPE_STRING)
|
||||||
? pointer->data.string.string : "", sizeof(batteryInfo->oem_info));
|
? pointer->string.string : "", sizeof(batteryInfo->oem_info));
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
free(buffer.pointer);
|
free(buffer.pointer);
|
||||||
@@ -207,7 +207,7 @@ EstimatedRuntime(battery_driver_cookie* cookie, acpi_battery_info* info)
|
|||||||
|
|
||||||
acpi_object_type argument;
|
acpi_object_type argument;
|
||||||
argument.object_type = ACPI_TYPE_INTEGER;
|
argument.object_type = ACPI_TYPE_INTEGER;
|
||||||
argument.data.integer = info->current_rate;
|
argument.integer.integer = info->current_rate;
|
||||||
|
|
||||||
acpi_objects arguments;
|
acpi_objects arguments;
|
||||||
arguments.count = 1;
|
arguments.count = 1;
|
||||||
@@ -231,7 +231,7 @@ EstimatedRuntime(battery_driver_cookie* cookie, acpi_battery_info* info)
|
|||||||
if (returnObject->object_type != ACPI_TYPE_INTEGER)
|
if (returnObject->object_type != ACPI_TYPE_INTEGER)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
int result = returnObject->data.integer;
|
int result = returnObject->integer.integer;
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -612,7 +612,7 @@ acpi_set_interrupt_model(acpi_module_info* acpiModule, uint32 interruptModel)
|
|||||||
{
|
{
|
||||||
acpi_object_type model;
|
acpi_object_type model;
|
||||||
model.object_type = ACPI_TYPE_INTEGER;
|
model.object_type = ACPI_TYPE_INTEGER;
|
||||||
model.data.integer = interruptModel;
|
model.integer.integer = interruptModel;
|
||||||
|
|
||||||
acpi_objects parameter;
|
acpi_objects parameter;
|
||||||
parameter.count = 1;
|
parameter.count = 1;
|
||||||
|
|||||||
@@ -346,7 +346,7 @@ evaluate_integer(acpi_module_info* acpi, acpi_handle handle,
|
|||||||
if (result.object_type != ACPI_TYPE_INTEGER)
|
if (result.object_type != ACPI_TYPE_INTEGER)
|
||||||
return B_BAD_TYPE;
|
return B_BAD_TYPE;
|
||||||
|
|
||||||
value = result.data.integer;
|
value = result.integer.integer;
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user