* embedded_controller_support() now actually checks all entries of the

supporting ID array (just that it only contains one entry).
* Fixed missing malloc() result check in embedded_controller_init_driver().
* Style fixes.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@36529 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2010-04-29 15:09:38 +00:00
parent 7b8344c61e
commit d3a302aae8
5 changed files with 248 additions and 260 deletions
@@ -1,4 +1,4 @@
/*-
/*
* Copyright (c) 2009 Clemens Zeidler
* Copyright (c) 2003-2007 Nate Lawson
* Copyright (c) 2000 Michael Smith
@@ -27,6 +27,7 @@
* SUCH DAMAGE.
*/
#include "acpi_embedded_controller.h"
#include <stdio.h>
@@ -40,6 +41,7 @@
#include "SmallResourceData.h"
#define ACPI_EC_DRIVER_NAME "drivers/power/acpi_embedded_controller/driver_v1"
#define ACPI_EC_DEVICE_NAME "drivers/power/acpi_embedded_controller/device_v1"
@@ -59,9 +61,9 @@ bus_space_read_1(int address)
void
bus_space_write_1(int address, uint8 v)
bus_space_write_1(int address, uint8 value)
{
gPCIManager->write_io_8(address, v);
gPCIManager->write_io_8(address, value);
}
@@ -74,12 +76,9 @@ acpi_GetInteger(acpi_device_module_info* acpi, acpi_device& acpiCookie,
buf.pointer = &object;
buf.length = sizeof(acpi_object_type);
/*
* Assume that what we've been pointed at is an Integer object, or
* a method that will return an Integer.
*/
// Assume that what we've been pointed at is an Integer object, or
// a method that will return an Integer.
status_t status = acpi->evaluate_method(acpiCookie, path, NULL, &buf);
if (status == B_OK) {
if (object.object_type == ACPI_TYPE_INTEGER)
*number = object.data.integer;
@@ -98,23 +97,18 @@ acpi_GetReference(acpi_module_info* acpi, acpi_handle scope,
return NULL;
switch (obj->object_type) {
case ACPI_TYPE_LOCAL_REFERENCE:
case ACPI_TYPE_ANY:
return obj->data.reference.handle;
case ACPI_TYPE_STRING:
{
/*
* The String object usually contains a fully-qualified path, so
* scope can be NULL.
*
* XXX This may not always be the case.
*/
// The String object usually contains a fully-qualified path, so
// scope can be NULL.
// TODO: This may not always be the case.
acpi_handle handle;
if (acpi->get_handle(scope, obj->data.string.string, &handle)
== B_OK)
== B_OK)
return handle;
}
}
@@ -130,7 +124,7 @@ acpi_PkgInt(acpi_object_type* res, int idx, int* dst)
if (obj == NULL || obj->object_type != ACPI_TYPE_INTEGER)
return B_BAD_VALUE;
*dst = obj->data.integer;
return B_OK;
}
@@ -148,6 +142,9 @@ acpi_PkgInt32(acpi_object_type* res, int idx, uint32* dst)
}
// #pragma mark -
static status_t
embedded_controller_open(void* initCookie, const char* path, int flags,
void** cookie)
@@ -198,6 +195,7 @@ embedded_controller_free(void* cookie)
// #pragma mark - driver module API
int32
acpi_get_type(device_node* dev)
{
@@ -220,21 +218,30 @@ acpi_get_type(device_node* dev)
static float
embedded_controller_support(device_node* dev)
{
static const char* ec_ids[] = { "PNP0C09", NULL };
TRACE("embedded_controller_support()\n");
/* Check that this is a device. */
TRACE("before acpi_get_type...");
// Check that this is a device
if (acpi_get_type(dev) != ACPI_TYPE_DEVICE)
return 0.0;
const char* name;
if (gDeviceManager->get_attr_string(dev, ACPI_DEVICE_HID_ITEM, &name, false)
!= B_OK || strcmp(name, ec_ids[0]))
!= B_OK)
return 0.0;
TRACE("after\n");
TRACE("supported device found %s\n", name);
return 0.6;
// Test all known IDs
static const char* kEmbeddedControllerIDs[] = { "PNP0C09" };
for (size_t i = 0; i < sizeof(kEmbeddedControllerIDs)
/ sizeof(kEmbeddedControllerIDs[0]); i++) {
if (!strcmp(name, kEmbeddedControllerIDs[i])) {
TRACE("supported device found %s\n", name);
return 0.6;
}
}
return 0.0;
}
@@ -258,7 +265,10 @@ embedded_controller_init_driver(device_node* dev, void** _driverCookie)
TRACE("init driver\n");
acpi_ec_cookie* sc;
sc = (acpi_ec_cookie*) malloc(sizeof(acpi_ec_cookie));
sc = (acpi_ec_cookie*)malloc(sizeof(acpi_ec_cookie));
if (sc == NULL)
return B_NO_MEMORY;
memset(sc, 0, sizeof(acpi_ec_cookie));
*_driverCookie = sc;
@@ -268,7 +278,7 @@ embedded_controller_init_driver(device_node* dev, void** _driverCookie)
mutex_init(&sc->ec_lock, "ec lock");
device_node* parent = gDeviceManager->get_parent_node(dev);
gDeviceManager->get_driver(parent, (driver_module_info**)&sc->ec_acpi,
(void**) &sc->ec_handle);
(void**)&sc->ec_handle);
gDeviceManager->put_node(parent);
SmallResourceData resourceData(sc->ec_acpi, sc->ec_handle, "_CRS");
@@ -279,19 +289,16 @@ embedded_controller_init_driver(device_node* dev, void** _driverCookie)
io_port portData;
if (get_module(B_ACPI_MODULE_NAME, (module_info**)&sc->ec_acpi_module)
!= B_OK)
!= B_OK)
return B_ERROR;
acpi_data buf;
buf.pointer = NULL;
buf.length = ACPI_ALLOCATE_BUFFER;
/*
* Read the unit ID to check for duplicate attach and the
* global lock value to see if we should acquire it when
* accessing the EC.
*/
// Read the unit ID to check for duplicate attach and the
// global lock value to see if we should acquire it when
// accessing the EC.
status_t status = acpi_GetInteger(sc->ec_acpi, sc->ec_handle, "_UID",
&sc->ec_uid);
if (status != B_OK)
@@ -300,11 +307,9 @@ embedded_controller_init_driver(device_node* dev, void** _driverCookie)
if (status != B_OK)
sc->ec_glk = 0;
/*
* Evaluate the _GPE method to find the GPE bit used by the EC to
* signal status (SCI). If it's a package, it contains a reference
* and GPE bit, similar to _PRW.
*/
// Evaluate the _GPE method to find the GPE bit used by the EC to
// signal status (SCI). If it's a package, it contains a reference
// and GPE bit, similar to _PRW.
status = sc->ec_acpi->evaluate_method(sc->ec_handle, "_GPE", NULL, &buf);
if (status != B_OK) {
TRACE("can't evaluate _GPE\n");
@@ -312,7 +317,7 @@ embedded_controller_init_driver(device_node* dev, void** _driverCookie)
}
acpi_object_type* obj;
obj = (acpi_object_type*) buf.pointer;
obj = (acpi_object_type*)buf.pointer;
if (obj == NULL)
goto error;
@@ -327,7 +332,7 @@ embedded_controller_init_driver(device_node* dev, void** _driverCookie)
sc->ec_gpehandle = acpi_GetReference(sc->ec_acpi_module, NULL,
&obj->data.package.objects[0]);
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;
break;
default:
@@ -337,7 +342,7 @@ embedded_controller_init_driver(device_node* dev, void** _driverCookie)
sc->ec_suspending = FALSE;
/* Attach bus resources for data and command/status ports. */
// Attach bus resources for data and command/status ports.
if (resourceData.ReadIOPort(&portData) != B_OK)
goto error;
@@ -348,10 +353,8 @@ embedded_controller_init_driver(device_node* dev, void** _driverCookie)
sc->ec_csr_pci_address = portData.minimumBase;
/*
* Install a handler for this EC's GPE bit. We want edge-triggered
* behavior.
*/
// Install a handler for this EC's GPE bit. We want edge-triggered
// behavior.
TRACE("attaching GPE handler\n");
status = sc->ec_acpi_module->install_gpe_handler(sc->ec_gpehandle,
sc->ec_gpebit, ACPI_GPE_EDGE_TRIGGERED, &EcGpeHandler, sc);
@@ -360,7 +363,7 @@ embedded_controller_init_driver(device_node* dev, void** _driverCookie)
goto error;
}
/* Install address space handler */
// Install address space handler
TRACE("attaching address space handler\n");
status = sc->ec_acpi->install_address_space_handler(sc->ec_handle,
ACPI_ADR_SPACE_EC, &EcSpaceHandler, &EcSpaceSetup, sc);
@@ -369,7 +372,7 @@ embedded_controller_init_driver(device_node* dev, void** _driverCookie)
goto error;
}
/* Enable runtime GPEs for the handler. */
// Enable runtime GPEs for the handler.
status = sc->ec_acpi_module->set_gpe_type(sc->ec_gpehandle, sc->ec_gpebit,
ACPI_GPE_TYPE_RUNTIME);
if (status != B_OK) {
@@ -386,8 +389,7 @@ embedded_controller_init_driver(device_node* dev, void** _driverCookie)
return 0;
error:
if (buf.pointer)
free(buf.pointer);
free(buf.pointer);
sc->ec_acpi_module->remove_gpe_handler(sc->ec_gpehandle, sc->ec_gpebit,
&EcGpeHandler);
@@ -401,7 +403,7 @@ error:
static void
embedded_controller_uninit_driver(void* driverCookie)
{
acpi_ec_cookie* sc = (struct acpi_ec_cookie*) driverCookie;
acpi_ec_cookie* sc = (struct acpi_ec_cookie*)driverCookie;
mutex_destroy(&sc->ec_lock);
free(sc);
put_module(B_ACPI_MODULE_NAME);
@@ -411,7 +413,7 @@ embedded_controller_uninit_driver(void* driverCookie)
static status_t
embedded_controller_register_child_devices(void* _cookie)
{
device_node* node = ((acpi_ec_cookie*) _cookie)->ec_dev;
device_node* node = ((acpi_ec_cookie*)_cookie)->ec_dev;
int pathID = gDeviceManager->create_id(ACPI_EC_PATHID_GENERATOR);
if (pathID < 0) {
@@ -436,7 +438,7 @@ embedded_controller_init_device(void* driverCookie, void** cookie)
static void
embedded_controller_uninit_device(void* _cookie)
{
acpi_ec_cookie *device = (acpi_ec_cookie*)_cookie;
acpi_ec_cookie* device = (acpi_ec_cookie*)_cookie;
free(device);
}
@@ -482,27 +484,28 @@ struct device_module_info embedded_controller_device_module = {
};
// #pragma mark -
static void
EcGpeQueryHandler(void* context)
{
struct acpi_ec_cookie* sc = (struct acpi_ec_cookie*) context;
struct acpi_ec_cookie* sc = (struct acpi_ec_cookie*)context;
ASSERT(context != NULL);//, ("EcGpeQueryHandler called with NULL"));
/* Serialize user access with EcSpaceHandler(). */
// Serialize user access with EcSpaceHandler().
status_t status = EcLock(sc);
if (status != B_OK) {
TRACE("GpeQuery lock error.\n");
return;
}
/*
* Send a query command to the EC to find out which _Qxx call it
* wants to make. This command clears the SCI bit and also the
* interrupt source since we are edge-triggered. To prevent the GPE
* that may arise from running the query from causing another query
* to be queued, we clear the pending flag only after running it.
*/
// Send a query command to the EC to find out which _Qxx call it
// wants to make. This command clears the SCI bit and also the
// interrupt source since we are edge-triggered. To prevent the GPE
// that may arise from running the query from causing another query
// to be queued, we clear the pending flag only after running it.
status = EcCommand(sc, EC_COMMAND_QUERY);
sc->ec_sci_pending = FALSE;
if (status != B_OK) {
@@ -512,19 +515,17 @@ EcGpeQueryHandler(void* context)
}
uint8 data = EC_GET_DATA(sc);
/*
* We have to unlock before running the _Qxx method below since that
* method may attempt to read/write from EC address space, causing
* recursive acquisition of the lock.
*/
// We have to unlock before running the _Qxx method below since that
// method may attempt to read/write from EC address space, causing
// recursive acquisition of the lock.
EcUnlock(sc);
/* Ignore the value for "no outstanding event". (13.3.5) */
// Ignore the value for "no outstanding event". (13.3.5)
TRACE("query ok,%s running _Q%02X\n", data ? "" : " not", data);
if (data == 0)
return;
/* Evaluate _Qxx to respond to the controller. */
// Evaluate _Qxx to respond to the controller.
char qxx[5];
snprintf(qxx, sizeof(qxx), "_Q%02X", data);
AcpiUtStrupr(qxx);
@@ -535,37 +536,32 @@ EcGpeQueryHandler(void* context)
}
/*
* The GPE handler is called when IBE/OBF or SCI events occur. We are
* called from an unknown lock context.
*/
/*! The GPE handler is called when IBE/OBF or SCI events occur. We are
called from an unknown lock context.
*/
static uint32
EcGpeHandler(void* context)
{
struct acpi_ec_cookie *sc = (acpi_ec_cookie*)context;
struct acpi_ec_cookie* sc = (acpi_ec_cookie*)context;
ASSERT(context != NULL);//, ("EcGpeHandler called with NULL"));
TRACE("gpe handler start\n");
/*
* Notify EcWaitEvent() that the status register is now fresh. If we
* didn't do this, it wouldn't be possible to distinguish an old IBE
* from a new one, for example when doing a write transaction (writing
* address and then data values.)
*/
// Notify EcWaitEvent() that the status register is now fresh. If we
// didn't do this, it wouldn't be possible to distinguish an old IBE
// from a new one, for example when doing a write transaction (writing
// address and then data values.)
atomic_add(&sc->ec_gencount, 1);
sc->ec_condition_var.NotifyAll();
/*
* If the EC_SCI bit of the status register is set, queue a query handler.
* It will run the query and _Qxx method later, under the lock.
*/
// If the EC_SCI bit of the status register is set, queue a query handler.
// It will run the query and _Qxx method later, under the lock.
EC_STATUS EcStatus = EC_GET_CSR(sc);
if ((EcStatus & EC_EVENT_SCI) && !sc->ec_sci_pending) {
TRACE("gpe queueing query handler\n");
ACPI_STATUS s = AcpiOsExecute(OSL_GPE_HANDLER, EcGpeQueryHandler,
ACPI_STATUS status = AcpiOsExecute(OSL_GPE_HANDLER, EcGpeQueryHandler,
context);
if (s == AE_OK)
if (status == AE_OK)
sc->ec_sci_pending = TRUE;
else
dprintf("EcGpeHandler: queuing GPE query handler failed\n");
@@ -578,10 +574,8 @@ static acpi_status
EcSpaceSetup(acpi_handle region, uint32 function, void* context,
void** regionContext)
{
/*
* If deactivating a region, always set the output to NULL. Otherwise,
* just pass the context through.
*/
// If deactivating a region, always set the output to NULL. Otherwise,
// just pass the context through.
if (function == ACPI_REGION_DEACTIVATE)
*regionContext = NULL;
else
@@ -596,10 +590,9 @@ EcSpaceHandler(uint32 function, acpi_physical_address address, uint32 width,
int* value, void* context, void* regionContext)
{
TRACE("enter EcSpaceHandler\n");
struct acpi_ec_cookie* sc = (struct acpi_ec_cookie *) context;
struct acpi_ec_cookie* sc = (struct acpi_ec_cookie*)context;
uint8 ecData;
if (width % 8 != 0 || value == NULL || context == NULL)
return AE_BAD_PARAMETER;
if (address + (width / 8) - 1 > 0xFF)
@@ -622,12 +615,12 @@ EcSpaceHandler(uint32 function, acpi_physical_address address, uint32 width,
}
} */
/* Serialize with EcGpeQueryHandler() at transaction granularity. */
// Serialize with EcGpeQueryHandler() at transaction granularity.
status = EcLock(sc);
if (status != B_OK)
return AE_NOT_ACQUIRED;
/* Perform the transaction(s), based on width. */
// Perform the transaction(s), based on width.
for (uint32 i = 0; i < width; i += 8, ecAddr++) {
switch (function) {
case ACPI_READ:
@@ -636,7 +629,7 @@ EcSpaceHandler(uint32 function, acpi_physical_address address, uint32 width,
*value |= ((int) ecData) << i;
break;
case ACPI_WRITE:
ecData = (uint8) ((*value) >> i);
ecData = (uint8)((*value) >> i);
status = EcWrite(sc, ecAddr, &ecData);
break;
default:
@@ -644,9 +637,8 @@ EcSpaceHandler(uint32 function, acpi_physical_address address, uint32 width,
status = AE_BAD_PARAMETER;
break;
}
if (status != AE_OK) {
if (status != AE_OK)
break;
}
}
EcUnlock(sc);
@@ -673,27 +665,25 @@ EcCheckStatus(struct acpi_ec_cookie* sc, const char* msg, EC_EVENT event)
static acpi_status
EcWaitEvent(struct acpi_ec_cookie* sc, EC_EVENT event, int32 gen_count)
EcWaitEvent(struct acpi_ec_cookie* sc, EC_EVENT event, int32 generationCount)
{
acpi_status status = AE_NO_HARDWARE_RESPONSE;
int32 count, i;
// int need_poll = cold || rebooting || ec_polled_mode || sc->ec_suspending;
int need_poll = ec_polled_mode || sc->ec_suspending;
int needPoll = ec_polled_mode || sc->ec_suspending;
/*
* The main CPU should be much faster than the EC. So the status should
* be "not ready" when we start waiting. But if the main CPU is really
* slow, it's possible we see the current "ready" response. Since that
* can't be distinguished from the previous response in polled mode,
* this is a potential issue. We really should have interrupts enabled
* during boot so there is no ambiguity in polled mode.
*
* If this occurs, we add an additional delay before actually entering
* the status checking loop, hopefully to allow the EC to go to work
* and produce a non-stale status.
*/
if (need_poll) {
// The main CPU should be much faster than the EC. So the status should
// be "not ready" when we start waiting. But if the main CPU is really
// slow, it's possible we see the current "ready" response. Since that
// can't be distinguished from the previous response in polled mode,
// this is a potential issue. We really should have interrupts enabled
// during boot so there is no ambiguity in polled mode.
//
// If this occurs, we add an additional delay before actually entering
// the status checking loop, hopefully to allow the EC to go to work
// and produce a non-stale status.
if (needPoll) {
static int once;
if (EcCheckStatus(sc, "pre-check", event) == B_OK) {
@@ -705,11 +695,12 @@ EcWaitEvent(struct acpi_ec_cookie* sc, EC_EVENT event, int32 gen_count)
}
}
/* Wait for event by polling or GPE (interrupt). */
if (need_poll) {
// Wait for event by polling or GPE (interrupt).
if (needPoll) {
count = (ec_timeout * 1000) / EC_POLL_DELAY;
if (count == 0)
count = 1;
for (i = 0; i < count; i++) {
status = EcCheckStatus(sc, "poll", event);
if (status == AE_OK)
@@ -717,38 +708,32 @@ EcWaitEvent(struct acpi_ec_cookie* sc, EC_EVENT event, int32 gen_count)
spin(EC_POLL_DELAY);
}
} else {
bigtime_t slp_ival = system_time() + ec_timeout * 1000;
bigtime_t sleepInterval = system_time() + ec_timeout * 1000;
/*
* Wait for the GPE to signal the status changed, checking the
* status register each time we get one. It's possible to get a
* GPE for an event we're not interested in here (i.e., SCI for
* EC query).
*/
// Wait for the GPE to signal the status changed, checking the
// status register each time we get one. It's possible to get a
// GPE for an event we're not interested in here (i.e., SCI for
// EC query).
status_t waitStatus = B_NO_ERROR;
while (waitStatus != B_TIMED_OUT) {
if (gen_count != sc->ec_gencount) {
/*
* Record new generation count. It's possible the GPE was
* just to notify us that a query is needed and we need to
* wait for a second GPE to signal the completion of the
* event we are actually waiting for.
*/
gen_count = sc->ec_gencount;
if (generationCount != sc->ec_gencount) {
// Record new generation count. It's possible the GPE was
// just to notify us that a query is needed and we need to
// wait for a second GPE to signal the completion of the
// event we are actually waiting for.
generationCount = sc->ec_gencount;
status = EcCheckStatus(sc, "sleep", event);
if (status == AE_OK)
break;
}
waitStatus = sc->ec_condition_var.Wait(B_ABSOLUTE_TIMEOUT,
slp_ival);
sleepInterval);
}
/*
* We finished waiting for the GPE and it never arrived. Try to
* read the register once and trust whatever value we got. This is
* the best we can do at this point. Then, force polled mode on
* since this system doesn't appear to generate GPEs.
*/
// We finished waiting for the GPE and it never arrived. Try to
// read the register once and trust whatever value we got. This is
// the best we can do at this point. Then, force polled mode on
// since this system doesn't appear to generate GPEs.
if (status != AE_OK) {
status = EcCheckStatus(sc, "sleep_end", event);
TRACE("wait timed out (%sresponse), forcing polled mode\n",
@@ -766,11 +751,11 @@ EcWaitEvent(struct acpi_ec_cookie* sc, EC_EVENT event, int32 gen_count)
static acpi_status
EcCommand(struct acpi_ec_cookie* sc, EC_COMMAND cmd)
{
/* Don't use burst mode if user disabled it. */
// Don't use burst mode if user disabled it.
if (!ec_burst_mode && cmd == EC_COMMAND_BURST_ENABLE)
return AE_ERROR;
/* Decide what to wait for based on command type. */
// Decide what to wait for based on command type.
EC_EVENT event;
switch (cmd) {
case EC_COMMAND_READ:
@@ -787,13 +772,13 @@ EcCommand(struct acpi_ec_cookie* sc, EC_COMMAND cmd)
return AE_BAD_PARAMETER;
}
/* Run the command and wait for the chosen event. */
// Run the command and wait for the chosen event.
TRACE("running command %#x\n", cmd);
u_int gen_count = sc->ec_gencount;
EC_SET_CSR(sc, cmd);
acpi_status status = EcWaitEvent(sc, event, gen_count);
if (status == AE_OK) {
/* If we succeeded, burst flag should now be present. */
// If we succeeded, burst flag should now be present.
if (cmd == EC_COMMAND_BURST_ENABLE) {
EC_STATUS ec_status = EC_GET_CSR(sc);
if ((ec_status & EC_FLAG_BURST_MODE) == 0)
@@ -811,7 +796,7 @@ EcRead(struct acpi_ec_cookie* sc, uint8 address, uint8* readData)
{
TRACE("read from %#x\n", address);
/* If we can't start burst mode, continue anyway. */
// If we can't start burst mode, continue anyway.
acpi_status status = EcCommand(sc, EC_COMMAND_BURST_ENABLE);
if (status == AE_OK) {
uint8 data = EC_GET_DATA(sc);
@@ -825,10 +810,10 @@ EcRead(struct acpi_ec_cookie* sc, uint8 address, uint8* readData)
if (status != AE_OK)
return status;
u_int gen_count = sc->ec_gencount;
u_int generationCount = sc->ec_gencount;
EC_SET_DATA(sc, address);
status = EcWaitEvent(sc, EC_EVENT_OUTPUT_BUFFER_FULL, gen_count);
status = EcWaitEvent(sc, EC_EVENT_OUTPUT_BUFFER_FULL, generationCount);
if (status != AE_OK) {
TRACE("EcRead: failed waiting to get data\n");
return status;
@@ -864,17 +849,17 @@ EcWrite(struct acpi_ec_cookie* sc, uint8 address, uint8* writeData)
if (status != AE_OK)
return status;
u_int gen_count = sc->ec_gencount;
u_int generationCount = sc->ec_gencount;
EC_SET_DATA(sc, address);
status = EcWaitEvent(sc, EC_EVENT_INPUT_BUFFER_EMPTY, gen_count);
status = EcWaitEvent(sc, EC_EVENT_INPUT_BUFFER_EMPTY, generationCount);
if (status != AE_OK) {
TRACE("EcRead: failed waiting for sent address\n");
return status;
}
gen_count = sc->ec_gencount;
generationCount = sc->ec_gencount;
EC_SET_DATA(sc, *writeData);
status = EcWaitEvent(sc, EC_EVENT_INPUT_BUFFER_EMPTY, gen_count);
status = EcWaitEvent(sc, EC_EVENT_INPUT_BUFFER_EMPTY, generationCount);
if (status != AE_OK) {
TRACE("EcWrite: failed waiting for sent data\n");
return status;
@@ -29,6 +29,7 @@
#ifndef ACPI_EMBEDDED_CONTROLLER_H
#define ACPI_EMBEDDED_CONTROLLER_H
#include <ctype.h>
#include <ACPI.h>
@@ -39,12 +40,13 @@
#include <lock.h>
extern "C" {
#include "acpi.h"
#include "accommon.h"
#include "acnamesp.h"
#include "acpi_priv.h"
# include "acpi.h"
# include "accommon.h"
# include "acnamesp.h"
# include "acpi_priv.h"
}
// #define TRACE_EMBEDDED_CONTROLLER
#ifdef TRACE_EMBEDDED_CONTROLLER
# define TRACE(x...) dprintf("EC: " x)
@@ -145,7 +147,7 @@ struct acpi_ec_cookie {
acpi_handle ec_gpehandle;
uint8 ec_gpebit;
int ec_data_pci_address;
int ec_data_pci_address;
int ec_csr_pci_address;
int ec_glk;
@@ -159,7 +161,6 @@ struct acpi_ec_cookie {
};
/*
* XXX njl
* I couldn't find it in the spec but other implementations also use a
@@ -186,6 +187,7 @@ static int ec_polled_mode = 0;
static int ec_timeout = EC_TIMEOUT;
static status_t
EcLock(struct acpi_ec_cookie *sc)
{
@@ -205,7 +207,7 @@ EcLock(struct acpi_ec_cookie *sc)
static void
EcUnlock(struct acpi_ec_cookie *sc)
{
mutex_unlock(&sc->ec_lock);
mutex_unlock(&sc->ec_lock);
if (sc->ec_glk)
sc->ec_acpi_module->release_global_lock(sc->ec_glkhandle);
}
@@ -5,6 +5,7 @@
* Distributed under the terms of the MIT License.
*/
#include <stdlib.h>
#include <string.h>
@@ -21,24 +22,24 @@
# define TRACE(x) ;
#endif
device_manager_info *gDeviceManager = NULL;
pci_module_info *gPCIManager = NULL;
device_manager_info* gDeviceManager = NULL;
pci_module_info* gPCIManager = NULL;
dpc_module_info* gDPC = NULL;
module_dependency module_dependencies[] = {
{B_DEVICE_MANAGER_MODULE_NAME, (module_info **)&gDeviceManager},
{B_PCI_MODULE_NAME, (module_info **)&gPCIManager},
{B_DPC_MODULE_NAME, (module_info **)&gDPC},
{B_DEVICE_MANAGER_MODULE_NAME, (module_info**)&gDeviceManager},
{B_PCI_MODULE_NAME, (module_info**)&gPCIManager},
{B_DPC_MODULE_NAME, (module_info**)&gDPC},
{}
};
static float
acpi_module_supports_device(device_node *parent)
acpi_module_supports_device(device_node* parent)
{
const char *bus;
// make sure parent is really device root
const char* bus;
if (gDeviceManager->get_attr_string(parent, B_DEVICE_BUS, &bus, false))
return B_ERROR;
@@ -50,9 +51,8 @@ acpi_module_supports_device(device_node *parent)
static status_t
acpi_module_register_device(device_node *parent)
acpi_module_register_device(device_node* parent)
{
device_attr attrs[] = {
{ B_DEVICE_PRETTY_NAME, B_STRING_TYPE, { string: "ACPI" }},
@@ -60,27 +60,27 @@ acpi_module_register_device(device_node *parent)
{}
};
io_resource *resources = NULL;
return gDeviceManager->register_node(parent, ACPI_ROOT_MODULE_NAME, attrs, resources, NULL);
return gDeviceManager->register_node(parent, ACPI_ROOT_MODULE_NAME, attrs,
NULL, NULL);
}
static status_t
acpi_enumerate_child_devices(device_node *node, const char *root)
acpi_enumerate_child_devices(device_node* node, const char* root)
{
char result[255];
void *counter = NULL;
device_node *parent = NULL;
void* counter = NULL;
device_node* parent = NULL;
TRACE(("acpi_enumerate_child_devices: recursing from %s\n", root));
// get a reference on the parent
parent = gDeviceManager->get_parent_node(node);
while (get_next_entry(ACPI_TYPE_ANY, root, result, sizeof(result), &counter) == B_OK) {
while (get_next_entry(ACPI_TYPE_ANY, root, result,
sizeof(result), &counter) == B_OK) {
uint32 type = get_object_type(result);
device_node *deviceNode;
device_node* deviceNode;
switch (type) {
case ACPI_TYPE_POWER:
@@ -113,8 +113,7 @@ acpi_enumerate_child_devices(device_node *node, const char *root)
if (gDeviceManager->register_node(node, ACPI_DEVICE_MODULE_NAME, attrs,
NULL, &deviceNode) == B_OK)
acpi_enumerate_child_devices(deviceNode, result);
acpi_enumerate_child_devices(deviceNode, result);
break;
}
default:
@@ -129,22 +128,21 @@ acpi_enumerate_child_devices(device_node *node, const char *root)
static status_t
acpi_module_register_child_devices(void *cookie)
acpi_module_register_child_devices(void* cookie)
{
status_t err;
device_node *node = cookie;
device_node* node = cookie;
err = gDeviceManager->publish_device(node, "acpi/namespace", ACPI_NS_DUMP_DEVICE_MODULE_NAME);
if (err != B_OK) {
return err;
}
status_t status = gDeviceManager->publish_device(node, "acpi/namespace",
ACPI_NS_DUMP_DEVICE_MODULE_NAME);
if (status != B_OK)
return status;
return acpi_enumerate_child_devices(node, "\\");
}
static status_t
acpi_module_init(device_node *node, void **_cookie)
acpi_module_init(device_node* node, void** _cookie)
{
*_cookie = node;
return B_OK;
@@ -152,7 +150,7 @@ acpi_module_init(device_node *node, void **_cookie)
static void
acpi_module_uninit(void *cookie)
acpi_module_uninit(void* cookie)
{
}
@@ -163,7 +161,7 @@ acpi_module_std_ops(int32 op, ...)
switch (op) {
case B_MODULE_INIT:
{
module_info *module;
module_info* module;
return get_module(B_ACPI_MODULE_NAME, &module);
// this serializes our module initialization
}
@@ -221,12 +219,13 @@ static struct acpi_root_info sACPIRootModule = {
evaluate_method,
};
_EXPORT module_info *modules[] = {
(module_info *)&gACPIModule,
(module_info *)&sACPIRootModule,
(module_info *)&acpi_ns_dump_module,
(module_info *)&gACPIDeviceModule,
(module_info*) &embedded_controller_driver_module,
(module_info*) &embedded_controller_device_module,
module_info* modules[] = {
(module_info*)&gACPIModule,
(module_info*)&sACPIRootModule,
(module_info*)&acpi_ns_dump_module,
(module_info*)&gACPIDeviceModule,
(module_info*)&embedded_controller_driver_module,
(module_info*)&embedded_controller_device_module,
NULL
};
@@ -6,8 +6,8 @@
#ifndef __ACPI_PRIV_H__
#define __ACPI_PRIV_H__
#include <sys/cdefs.h>
__BEGIN_DECLS
#include <device_manager.h>
#include <KernelExport.h>
@@ -24,15 +24,17 @@ __BEGIN_DECLS
#define ACPI_NS_DUMP_DEVICE_MODULE_NAME "bus_managers/acpi/namespace/device_v1"
extern device_manager_info *gDeviceManager;
extern pci_module_info *gPCIManager;
__BEGIN_DECLS
extern device_manager_info* gDeviceManager;
extern pci_module_info* gPCIManager;
// information about one ACPI device
typedef struct acpi_device_cookie {
char *path; // path
char* path; // path
acpi_handle handle;
uint32 type; // type
device_node *node;
device_node* node;
char name[32]; // name (for fast log)
} acpi_device_cookie;
@@ -41,11 +43,11 @@ typedef struct acpi_device_cookie {
typedef struct acpi_root_info {
driver_module_info info;
status_t (*get_handle)(acpi_handle parent, char *pathname,
acpi_handle *retHandle);
status_t (*get_handle)(acpi_handle parent, char* pathname,
acpi_handle* retHandle);
/* Global Lock */
status_t (*acquire_global_lock)(uint16 timeout, uint32 *handle);
status_t (*acquire_global_lock)(uint16 timeout, uint32* handle);
status_t (*release_global_lock)(uint32 handle);
/* Notify Handler */
@@ -63,62 +65,60 @@ typedef struct acpi_root_info {
status_t (*set_gpe_type)(acpi_handle handle, uint32 gpeNumber,
uint8 type);
status_t (*install_gpe_handler)(acpi_handle handle, uint32 gpeNumber,
uint32 type, acpi_event_handler handler, void *data);
uint32 type, acpi_event_handler handler, void* data);
status_t (*remove_gpe_handler)(acpi_handle handle, uint32 gpeNumber,
acpi_event_handler address);
/* Address Space Handler */
status_t (*install_address_space_handler)(acpi_handle handle,
uint32 spaceId,
acpi_adr_space_handler handler,
acpi_adr_space_setup setup, void *data);
uint32 spaceID, acpi_adr_space_handler handler,
acpi_adr_space_setup setup, void* data);
status_t (*remove_address_space_handler)(acpi_handle handle,
uint32 spaceId,
acpi_adr_space_handler handler);
uint32 spaceID, acpi_adr_space_handler handler);
/* Fixed Event Management */
void (*enable_fixed_event) (uint32 event);
void (*disable_fixed_event) (uint32 event);
void (*enable_fixed_event)(uint32 event);
void (*disable_fixed_event)(uint32 event);
uint32 (*fixed_event_status) (uint32 event);
uint32 (*fixed_event_status)(uint32 event);
/* Returns 1 if event set, 0 otherwise */
void (*reset_fixed_event) (uint32 event);
void (*reset_fixed_event)(uint32 event);
status_t (*install_fixed_event_handler)(uint32 event,
interrupt_handler *handler, void *data);
interrupt_handler* handler, void* data);
status_t (*remove_fixed_event_handler)(uint32 event,
interrupt_handler *handler);
interrupt_handler* handler);
/* Namespace Access */
status_t (*get_next_entry)(uint32 object_type, const char *base,
char *result, size_t len, void **counter);
status_t (*get_device)(const char *hid, uint32 index, char *result,
status_t (*get_next_entry)(uint32 object_type, const char* base,
char* result, size_t len, void** counter);
status_t (*get_device)(const char* hid, uint32 index, char* result,
size_t resultLength);
status_t (*get_device_hid)(const char *path, char *hid, size_t hidLength);
uint32 (*get_object_type)(const char *path);
status_t (*get_object)(const char *path,
acpi_object_type **_returnValue);
status_t (*get_object_typed)(const char *path,
acpi_object_type **_returnValue, uint32 objectType);
status_t (*get_device_hid)(const char* path, char* hid,
size_t hidLength);
uint32 (*get_object_type)(const char* path);
status_t (*get_object)(const char* path,
acpi_object_type** _returnValue);
status_t (*get_object_typed)(const char* path,
acpi_object_type** _returnValue, uint32 objectType);
status_t (*ns_handle_to_pathname)(acpi_handle targetHandle,
acpi_data *buffer);
acpi_data* buffer);
/* Control method execution and data acquisition */
status_t (*evaluate_object)(const char* object,
acpi_object_type *returnValue, size_t bufferLength);
status_t (*evaluate_method)(acpi_handle handle, const char *method,
acpi_objects *args, acpi_data *returnValue);
acpi_object_type* returnValue, size_t bufferLength);
status_t (*evaluate_method)(acpi_handle handle, const char* method,
acpi_objects* args, acpi_data* returnValue);
/* Resource info */
status_t (*get_irq_routing_table)(acpi_handle busDeviceHandle,
acpi_data *retBuffer);
acpi_data* returnValue);
} acpi_root_info;
@@ -132,26 +132,26 @@ extern struct device_module_info embedded_controller_device_module;
extern acpi_device_module_info gACPIDeviceModule;
status_t get_handle(acpi_handle parent, char *pathname, acpi_handle *retHandle);
status_t get_handle(acpi_handle parent, char* pathname, acpi_handle* retHandle);
status_t acquire_global_lock(uint16 timeout, uint32 *handle);
status_t acquire_global_lock(uint16 timeout, uint32* handle);
status_t release_global_lock(uint32 handle);
status_t install_notify_handler(acpi_handle device, uint32 handlerType,
acpi_notify_handler handler, void *context);
acpi_notify_handler handler, void* context);
status_t remove_notify_handler(acpi_handle device, uint32 handlerType,
acpi_notify_handler handler);
status_t enable_gpe(acpi_handle handle, uint32 gpeNumber, uint32 flags);
status_t set_gpe_type(acpi_handle handle, uint32 gpeNumber, uint8 type);
status_t install_gpe_handler(acpi_handle handle, uint32 gpeNumber, uint32 type,
acpi_event_handler handler, void *data);
acpi_event_handler handler, void* data);
status_t remove_gpe_handler(acpi_handle handle, uint32 gpeNumber,
acpi_event_handler address);
status_t install_address_space_handler(acpi_handle handle, uint32 spaceId,
acpi_adr_space_handler handler, acpi_adr_space_setup setup, void *data);
status_t remove_address_space_handler(acpi_handle handle, uint32 spaceId,
status_t install_address_space_handler(acpi_handle handle, uint32 spaceID,
acpi_adr_space_handler handler, acpi_adr_space_setup setup, void* data);
status_t remove_address_space_handler(acpi_handle handle, uint32 spaceID,
acpi_adr_space_handler handler);
void enable_fixed_event(uint32 event);
@@ -160,29 +160,30 @@ void disable_fixed_event(uint32 event);
uint32 fixed_event_status(uint32 event);
void reset_fixed_event(uint32 event);
status_t install_fixed_event_handler(uint32 event, interrupt_handler *handler,
void *data);
status_t remove_fixed_event_handler(uint32 event, interrupt_handler *handler);
status_t install_fixed_event_handler(uint32 event, interrupt_handler* handler,
void* data);
status_t remove_fixed_event_handler(uint32 event, interrupt_handler* handler);
status_t get_next_entry(uint32 object_type, const char *base, char *result,
size_t length, void **counter);
status_t get_device(const char *hid, uint32 index, char *result,
status_t get_next_entry(uint32 object_type, const char* base, char* result,
size_t length, void** _counter);
status_t get_device(const char* hid, uint32 index, char* result,
size_t resultLength);
status_t get_device_hid(const char *path, char *hid, size_t hidLength);
uint32 get_object_type(const char *path);
status_t get_object(const char *path, acpi_object_type **return_value);
status_t get_object_typed(const char *path, acpi_object_type **return_value,
status_t get_device_hid(const char* path, char* hid, size_t hidLength);
uint32 get_object_type(const char* path);
status_t get_object(const char* path, acpi_object_type** _returnValue);
status_t get_object_typed(const char* path, acpi_object_type** _returnValue,
uint32 object_type);
status_t ns_handle_to_pathname(acpi_handle targetHandle, acpi_data *buffer);
status_t ns_handle_to_pathname(acpi_handle targetHandle, acpi_data* buffer);
status_t evaluate_object(const char* object, acpi_object_type *returnValue,
status_t evaluate_object(const char* object, acpi_object_type* returnValue,
size_t bufferLength);
status_t evaluate_method(acpi_handle handle, const char *method,
acpi_objects *args, acpi_data *returnValue);
status_t evaluate_method(acpi_handle handle, const char* method,
acpi_objects* args, acpi_data* returnValue);
status_t get_irq_routing_table(acpi_handle busDeviceHandle,
acpi_data *retBuffer);
acpi_data* returnValue);
__END_DECLS
#endif /* __ACPI_PRIV_H__ */
+12 -11
View File
@@ -1,3 +1,7 @@
/*
* Copyright 2010, Clemens Zeidler, haiku@clemens-zeidler.de.
* Distributed under the terms of the MIT License.
*/
#ifndef IRQ_ROUTING_TABLE_H
#define IRQ_ROUTING_TABLE_H
@@ -9,8 +13,7 @@
#include "util/Vector.h"
struct irq_routing_entry
{
struct irq_routing_entry {
int device_address;
int8 pin;
@@ -26,8 +29,7 @@ struct irq_routing_entry
typedef Vector<irq_routing_entry> IRQRoutingTable;
struct irq_descriptor
{
struct irq_descriptor {
irq_descriptor();
// bit 0 is interrupt 0, bit 2 is interrupt 2, and so on
int16 irq;
@@ -39,15 +41,14 @@ struct irq_descriptor
};
/* Similar to bus_managers/acpi/include/acrestyp.h definition */
typedef struct acpi_prt
{
// Similar to bus_managers/acpi/include/acrestyp.h definition
typedef struct acpi_prt {
uint32 length;
uint32 pin;
int address; /* here for 64-bit alignment */
int address; // here for 64-bit alignment
uint32 sourceIndex;
char source[4]; /* pad to 64 bits so sizeof() works in
all cases */
char source[4]; // pad to 64 bits so sizeof() works in
// all cases
} acpi_pci_routing_table;
@@ -68,4 +69,4 @@ status_t read_possible_irq(acpi_module_info* acpi, acpi_handle device,
status_t set_acpi_irq(acpi_module_info* acpi, acpi_handle device,
irq_descriptor* descriptor);
#endif
#endif // IRQ_ROUTING_TABLE_H