6,7 → 6,10 |
#include <syscall.h> |
|
#include "acpi.h" |
#include "acpi_bus.h" |
|
#define PREFIX "ACPI: " |
|
#define ACPI_BUS_CLASS "system_bus" |
#define ACPI_BUS_HID "KLBSYBUS" |
#define ACPI_BUS_DEVICE_NAME "System Bus" |
16,8 → 19,8 |
|
static LIST_HEAD(acpi_device_list); |
static LIST_HEAD(acpi_bus_id_list); |
DEFINE_MUTEX(acpi_device_lock); |
|
|
struct acpi_device_bus_id |
{ |
char bus_id[15]; |
44,40 → 47,7 |
ACPI_BUS_REMOVAL_TYPE_COUNT |
}; |
|
enum acpi_bus_device_type { |
ACPI_BUS_TYPE_DEVICE = 0, |
ACPI_BUS_TYPE_POWER, |
ACPI_BUS_TYPE_PROCESSOR, |
ACPI_BUS_TYPE_THERMAL, |
ACPI_BUS_TYPE_POWER_BUTTON, |
ACPI_BUS_TYPE_SLEEP_BUTTON, |
ACPI_BUS_DEVICE_TYPE_COUNT |
}; |
|
/* |
* _HID definitions |
* HIDs must conform to ACPI spec(6.1.4) |
* KolibriOS specific HIDs do not apply to this and begin with KOS: |
*/ |
|
#define ACPI_POWER_HID "KLBPOWER" |
#define ACPI_PROCESSOR_OBJECT_HID "KLBCPU" |
#define ACPI_SYSTEM_HID "KLBSYSTM" |
#define ACPI_THERMAL_HID "KLBTHERM" |
#define ACPI_BUTTON_HID_POWERF "KLBPWRBN" |
#define ACPI_BUTTON_HID_SLEEPF "KLBSLPBN" |
#define ACPI_VIDEO_HID "KLBVIDEO" |
#define ACPI_BAY_HID "KLBIOBAY" |
#define ACPI_DOCK_HID "KLBDOCK" |
/* Quirk for broken IBM BIOSes */ |
#define ACPI_SMBUS_IBM_HID "SMBUSIBM" |
|
|
#define STRUCT_TO_INT(s) (*((int*)&s)) |
|
#define ACPI_STA_DEFAULT (ACPI_STA_DEVICE_PRESENT | ACPI_STA_DEVICE_ENABLED | \ |
ACPI_STA_DEVICE_UI | ACPI_STA_DEVICE_FUNCTIONING) |
|
#define PCI_MAX_DEVICES 32 |
#define PCI_MAX_PINS 4 |
|
96,850 → 66,521 |
#define acpi_remap( addr ) MapIoMem((void*)(addr),4096, 0x01) |
|
|
struct acpi_bus_ops |
{ |
u32_t acpi_op_add:1; |
u32_t acpi_op_start:1; |
}; |
struct acpi_device *acpi_root; |
|
struct acpi_device_flags { |
u32 dynamic_status:1; |
u32 bus_address:1; |
u32 removable:1; |
u32 ejectable:1; |
u32 lockable:1; |
u32 suprise_removal_ok:1; |
u32 power_manageable:1; |
u32 performance_manageable:1; |
u32 wake_capable:1; /* Wakeup(_PRW) supported? */ |
u32 force_power_state:1; |
u32 reserved:22; |
}; |
extern struct resource iomem_resource; |
extern struct resource ioport_resource; |
|
struct acpi_device_status { |
u32 present:1; |
u32 enabled:1; |
u32 show_in_ui:1; |
u32 functional:1; |
u32 battery_present:1; |
u32 reserved:27; |
enum pic_mode |
{ |
IO_PIC = 0, |
IO_APIC |
}; |
|
static void set_pic_mode(enum pic_mode mode) |
{ |
ACPI_OBJECT arg1; |
ACPI_OBJECT_LIST args; |
ACPI_STATUS as; |
|
typedef char acpi_bus_id[8]; |
typedef unsigned long acpi_bus_address; |
typedef char acpi_device_name[40]; |
typedef char acpi_device_class[20]; |
arg1.Type = ACPI_TYPE_INTEGER; |
arg1.Integer.Value = mode; |
args.Count = 1; |
args.Pointer = &arg1; |
|
struct acpi_hardware_id { |
struct list_head list; |
char *id; |
}; |
as = AcpiEvaluateObject(ACPI_ROOT_OBJECT, "_PIC", &args, NULL); |
/* |
* We can silently ignore failure as it may not be implemented, ACPI should |
* provide us with correct information anyway |
*/ |
if (ACPI_SUCCESS(as)) |
dbgprintf(PREFIX "machine set to %s mode\n", mode ? "APIC" : "PIC"); |
} |
|
struct acpi_device_pnp |
void print_device_tree(struct acpi_device *device) |
{ |
acpi_bus_id bus_id; /* Object name */ |
acpi_bus_address bus_address; /* _ADR */ |
char *unique_id; /* _UID */ |
struct list_head ids; /* _HID and _CIDs */ |
acpi_device_name device_name; /* Driver-determined */ |
acpi_device_class device_class; /* " */ |
}; |
struct acpi_device *child; |
|
dbgprintf("%s\n", device->pnp.bus_id); |
|
struct acpi_device |
list_for_each_entry(child, &device->children, node) |
{ |
int device_type; |
ACPI_HANDLE handle; /* no handle for fixed hardware */ |
struct acpi_device *parent; |
struct list_head children; |
struct list_head node; |
// struct list_head wakeup_list; |
struct acpi_device_status status; |
struct acpi_device_flags flags; |
struct acpi_device_pnp pnp; |
// struct acpi_device_power power; |
// struct acpi_device_wakeup wakeup; |
// struct acpi_device_perf performance; |
// struct acpi_device_dir dir; |
// struct acpi_device_ops ops; |
// struct acpi_driver *driver; |
void *driver_data; |
// struct device dev; |
struct acpi_bus_ops bus_ops; /* workaround for different code path for hotplug */ |
// enum acpi_bus_removal_type removal_type; /* indicate for different removal type */ |
print_device_tree(child); |
}; |
}; |
|
struct acpi_device *acpi_root; |
|
|
static void |
acpi_util_eval_error(ACPI_HANDLE h, ACPI_STRING p, ACPI_STATUS s) |
/* |
int acpi_pci_bind_root(struct acpi_device *device) |
{ |
#ifdef ACPI_DEBUG_OUTPUT |
char prefix[80] = {'\0'}; |
ACPI_BUFFER buffer = {sizeof(prefix), prefix}; |
AcpiGetName(h, ACPI_FULL_PATHNAME, &buffer); |
ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Evaluate [%s.%s]: %s\n", |
(char *) prefix, p, AcpiFormatException(s))); |
#else |
return; |
#endif |
} |
device->ops.bind = acpi_pci_bind; |
device->ops.unbind = acpi_pci_unbind; |
|
ACPI_STATUS |
acpi_evaluate_integer(ACPI_HANDLE handle, ACPI_STRING pathname, |
ACPI_OBJECT_LIST *arguments, unsigned long long *data) |
{ |
ACPI_STATUS status = AE_OK; |
ACPI_OBJECT element; |
ACPI_BUFFER buffer = { 0, NULL }; |
|
if (!data) |
return AE_BAD_PARAMETER; |
|
buffer.Length = sizeof(ACPI_OBJECT); |
buffer.Pointer = &element; |
status = AcpiEvaluateObject(handle, pathname, arguments, &buffer); |
if (ACPI_FAILURE(status)) { |
acpi_util_eval_error(handle, pathname, status); |
return status; |
return 0; |
} |
*/ |
|
if (element.Type != ACPI_TYPE_INTEGER) { |
acpi_util_eval_error(handle, pathname, AE_BAD_DATA); |
return AE_BAD_DATA; |
} |
static bool pci_use_crs = false; |
|
*data = element.Integer.Value; |
#define IORESOURCE_BUS 0x00001000 |
|
ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Return value [%llu]\n", *data)); |
struct acpi_pci_root { |
struct list_head node; |
struct acpi_device * device; |
struct acpi_pci_id id; |
struct pci_bus *bus; |
u16 segment; |
struct resource secondary; /* downstream bus range */ |
|
return AE_OK; |
} |
}; |
|
void acpi_bus_data_handler(ACPI_HANDLE handle, void *context) |
{ |
static LIST_HEAD(acpi_pci_roots); |
|
/* TBD */ |
#define ACPI_PCI_ROOT_CLASS "pci_bridge" |
#define ACPI_PCI_ROOT_DEVICE_NAME "PCI Root Bridge" |
|
return; |
} |
|
|
int acpi_bus_get_device(ACPI_HANDLE handle, struct acpi_device **device) |
static ACPI_STATUS |
get_root_bridge_busnr_callback(ACPI_RESOURCE *resource, void *data) |
{ |
ACPI_STATUS status = AE_OK; |
struct resource *res = data; |
ACPI_RESOURCE_ADDRESS64 address; |
|
if (!device) |
{ |
return -EINVAL; |
}; |
if (resource->Type != ACPI_RESOURCE_TYPE_ADDRESS16 && |
resource->Type != ACPI_RESOURCE_TYPE_ADDRESS32 && |
resource->Type != ACPI_RESOURCE_TYPE_ADDRESS64) |
return AE_OK; |
|
/* TBD: Support fixed-feature devices */ |
|
status = AcpiGetData(handle, acpi_bus_data_handler, (void **)device); |
if (ACPI_FAILURE(status) || !*device) { |
ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No context for object [%p]\n", |
handle)); |
return -ENODEV; |
AcpiResourceToAddress64(resource, &address); |
if ((address.AddressLength > 0) && |
(address.ResourceType == ACPI_BUS_NUMBER_RANGE)) { |
res->start = address.Minimum; |
res->end = address.Minimum + address.AddressLength - 1; |
} |
return 0; |
} |
|
|
ACPI_STATUS acpi_bus_get_status_handle(ACPI_HANDLE handle, |
unsigned long long *sta) |
{ |
ACPI_STATUS status; |
|
status = acpi_evaluate_integer(handle, "_STA", NULL, sta); |
if (ACPI_SUCCESS(status)) |
{ |
return AE_OK; |
}; |
|
if (status == AE_NOT_FOUND) |
{ |
*sta = ACPI_STA_DEVICE_PRESENT | ACPI_STA_DEVICE_ENABLED | |
ACPI_STA_DEVICE_UI | ACPI_STA_DEVICE_FUNCTIONING; |
return AE_OK; |
} |
return status; |
} |
|
|
|
static int acpi_bus_type_and_status(ACPI_HANDLE handle, int *type, |
unsigned long long *sta) |
static ACPI_STATUS try_get_root_bridge_busnr(ACPI_HANDLE handle, |
struct resource *res) |
{ |
ACPI_STATUS status; |
ACPI_OBJECT_TYPE acpi_type; |
|
status = AcpiGetType(handle, &acpi_type); |
res->start = -1; |
status = |
AcpiWalkResources(handle, METHOD_NAME__CRS, |
get_root_bridge_busnr_callback, res); |
if (ACPI_FAILURE(status)) |
{ |
return -ENODEV; |
}; |
return status; |
if (res->start == -1) |
return AE_ERROR; |
return AE_OK; |
} |
|
switch (acpi_type) |
{ |
case ACPI_TYPE_ANY: /* for ACPI_ROOT_OBJECT */ |
case ACPI_TYPE_DEVICE: |
*type = ACPI_BUS_TYPE_DEVICE; |
status = acpi_bus_get_status_handle(handle, sta); |
if (ACPI_FAILURE(status)) |
{ |
return -ENODEV; |
}; |
break; |
|
case ACPI_TYPE_PROCESSOR: |
*type = ACPI_BUS_TYPE_PROCESSOR; |
status = acpi_bus_get_status_handle(handle, sta); |
if (ACPI_FAILURE(status)) |
struct pci_root_info |
{ |
return -ENODEV; |
struct acpi_device *bridge; |
char *name; |
unsigned int res_num; |
struct resource *res; |
struct pci_bus *bus; |
int busnum; |
}; |
break; |
case ACPI_TYPE_THERMAL: |
*type = ACPI_BUS_TYPE_THERMAL; |
*sta = ACPI_STA_DEFAULT; |
break; |
case ACPI_TYPE_POWER: |
*type = ACPI_BUS_TYPE_POWER; |
*sta = ACPI_STA_DEFAULT; |
break; |
default: |
return -ENODEV; |
} |
|
return 0; |
} |
|
static struct acpi_device *acpi_bus_get_parent(ACPI_HANDLE handle) |
static ACPI_STATUS |
resource_to_addr(ACPI_RESOURCE *resource, ACPI_RESOURCE_ADDRESS64 *addr) |
{ |
ACPI_STATUS status; |
struct acpi_device *device; |
int ret; |
struct acpi_resource_memory24 *memory24; |
struct acpi_resource_memory32 *memory32; |
struct acpi_resource_fixed_memory32 *fixed_memory32; |
|
/* |
* Fixed hardware devices do not appear in the namespace and do not |
* have handles, but we fabricate acpi_devices for them, so we have |
* to deal with them specially. |
*/ |
if (handle == NULL) |
{ |
return acpi_root; |
}; |
|
do |
{ |
status = AcpiGetParent(handle, &handle); |
if (status == AE_NULL_ENTRY) |
{ |
return NULL; |
}; |
if (ACPI_FAILURE(status)) |
{ |
return acpi_root; |
}; |
|
ret = acpi_bus_get_device(handle, &device); |
if (ret == 0) |
{ |
return device; |
}; |
} while (1); |
memset(addr, 0, sizeof(*addr)); |
switch (resource->Type) { |
case ACPI_RESOURCE_TYPE_MEMORY24: |
memory24 = &resource->Data.Memory24; |
addr->ResourceType = ACPI_MEMORY_RANGE; |
addr->Minimum = memory24->Minimum; |
addr->AddressLength = memory24->AddressLength; |
addr->Maximum = addr->Minimum + addr->AddressLength - 1; |
return AE_OK; |
case ACPI_RESOURCE_TYPE_MEMORY32: |
memory32 = &resource->Data.Memory32; |
addr->ResourceType = ACPI_MEMORY_RANGE; |
addr->Minimum = memory32->Minimum; |
addr->AddressLength = memory32->AddressLength; |
addr->Maximum = addr->Minimum + addr->AddressLength - 1; |
return AE_OK; |
case ACPI_RESOURCE_TYPE_FIXED_MEMORY32: |
fixed_memory32 = &resource->Data.FixedMemory32; |
addr->ResourceType = ACPI_MEMORY_RANGE; |
addr->Minimum = fixed_memory32->Address; |
addr->AddressLength = fixed_memory32->AddressLength; |
addr->Maximum = addr->Minimum + addr->AddressLength - 1; |
return AE_OK; |
case ACPI_RESOURCE_TYPE_ADDRESS16: |
case ACPI_RESOURCE_TYPE_ADDRESS32: |
case ACPI_RESOURCE_TYPE_ADDRESS64: |
status = AcpiResourceToAddress64(resource, addr); |
if (ACPI_SUCCESS(status) && |
(addr->ResourceType == ACPI_MEMORY_RANGE || |
addr->ResourceType == ACPI_IO_RANGE) && |
addr->AddressLength > 0) { |
return AE_OK; |
} |
|
|
static void acpi_device_get_busid(struct acpi_device *device) |
{ |
char bus_id[5] = { '?', 0 }; |
struct acpi_buffer buffer = { sizeof(bus_id), bus_id }; |
int i = 0; |
|
/* |
* Bus ID |
* ------ |
* The device's Bus ID is simply the object name. |
* TBD: Shouldn't this value be unique (within the ACPI namespace)? |
*/ |
if (ACPI_IS_ROOT_DEVICE(device)) { |
strcpy(device->pnp.bus_id, "ACPI"); |
return; |
} |
|
switch (device->device_type) |
{ |
case ACPI_BUS_TYPE_POWER_BUTTON: |
strcpy(device->pnp.bus_id, "PWRF"); |
break; |
case ACPI_BUS_TYPE_SLEEP_BUTTON: |
strcpy(device->pnp.bus_id, "SLPF"); |
break; |
default: |
AcpiGetName(device->handle, ACPI_SINGLE_NAME, &buffer); |
/* Clean up trailing underscores (if any) */ |
for (i = 3; i > 1; i--) |
{ |
if (bus_id[i] == '_') |
bus_id[i] = '\0'; |
else |
break; |
} |
strcpy(device->pnp.bus_id, bus_id); |
break; |
return AE_ERROR; |
} |
} |
|
|
static int acpi_bus_get_flags(struct acpi_device *device) |
static ACPI_STATUS |
count_resource(ACPI_RESOURCE *acpi_res, void *data) |
{ |
ACPI_STATUS status = AE_OK; |
ACPI_HANDLE temp = NULL; |
struct pci_root_info *info = data; |
ACPI_RESOURCE_ADDRESS64 addr; |
ACPI_STATUS status; |
|
/* Presence of _STA indicates 'dynamic_status' */ |
status = AcpiGetHandle(device->handle, "_STA", &temp); |
status = resource_to_addr(acpi_res, &addr); |
if (ACPI_SUCCESS(status)) |
device->flags.dynamic_status = 1; |
|
/* Presence of _RMV indicates 'removable' */ |
status = AcpiGetHandle(device->handle, "_RMV", &temp); |
if (ACPI_SUCCESS(status)) |
device->flags.removable = 1; |
|
/* Presence of _EJD|_EJ0 indicates 'ejectable' */ |
status = AcpiGetHandle(device->handle, "_EJD", &temp); |
if (ACPI_SUCCESS(status)) |
device->flags.ejectable = 1; |
else { |
status = AcpiGetHandle(device->handle, "_EJ0", &temp); |
if (ACPI_SUCCESS(status)) |
device->flags.ejectable = 1; |
info->res_num++; |
return AE_OK; |
} |
|
/* Presence of _LCK indicates 'lockable' */ |
status = AcpiGetHandle(device->handle, "_LCK", &temp); |
if (ACPI_SUCCESS(status)) |
device->flags.lockable = 1; |
|
/* Presence of _PS0|_PR0 indicates 'power manageable' */ |
status = AcpiGetHandle(device->handle, "_PS0", &temp); |
if (ACPI_FAILURE(status)) |
status = AcpiGetHandle(device->handle, "_PR0", &temp); |
if (ACPI_SUCCESS(status)) |
device->flags.power_manageable = 1; |
static ACPI_STATUS setup_resource(ACPI_RESOURCE *acpi_res, void *data) |
{ |
struct pci_root_info *info = data; |
struct resource *res; |
struct acpi_resource_address64 addr; |
ACPI_STATUS status; |
unsigned long flags; |
struct resource *root, *conflict; |
u64 start, end; |
|
/* Presence of _PRW indicates wake capable */ |
status = AcpiGetHandle(device->handle, "_PRW", &temp); |
if (ACPI_SUCCESS(status)) |
device->flags.wake_capable = 1; |
status = resource_to_addr(acpi_res, &addr); |
if (!ACPI_SUCCESS(status)) |
return AE_OK; |
|
/* TBD: Performance management */ |
|
return 0; |
if (addr.ResourceType == ACPI_MEMORY_RANGE) |
{ |
root = &iomem_resource; |
flags = IORESOURCE_MEM; |
if (addr.Info.Mem.Caching == ACPI_PREFETCHABLE_MEMORY) |
flags |= IORESOURCE_PREFETCH; |
} |
else if (addr.ResourceType == ACPI_IO_RANGE) |
{ |
root = &ioport_resource; |
flags = IORESOURCE_IO; |
} else |
return AE_OK; |
|
/* |
* acpi_bay_match - see if a device is an ejectable driver bay |
* |
* If an acpi object is ejectable and has one of the ACPI ATA methods defined, |
* then we can safely call it an ejectable drive bay |
*/ |
static int acpi_bay_match(struct acpi_device *device){ |
ACPI_STATUS status; |
ACPI_HANDLE handle; |
ACPI_HANDLE tmp; |
ACPI_HANDLE phandle; |
start = addr.Minimum + addr.TranslationOffset; |
end = addr.Maximum + addr.TranslationOffset; |
|
handle = device->handle; |
res = &info->res[info->res_num]; |
res->name = info->name; |
res->flags = flags; |
res->start = start; |
res->end = end; |
res->child = NULL; |
|
status = AcpiGetHandle(handle, "_EJ0", &tmp); |
if (ACPI_FAILURE(status)) |
return -ENODEV; |
|
if ((ACPI_SUCCESS(AcpiGetHandle(handle, "_GTF", &tmp))) || |
(ACPI_SUCCESS(AcpiGetHandle(handle, "_GTM", &tmp))) || |
(ACPI_SUCCESS(AcpiGetHandle(handle, "_STM", &tmp))) || |
(ACPI_SUCCESS(AcpiGetHandle(handle, "_SDD", &tmp)))) |
return 0; |
|
if (AcpiGetParent(handle, &phandle)) |
return -ENODEV; |
|
if ((ACPI_SUCCESS(AcpiGetHandle(phandle, "_GTF", &tmp))) || |
(ACPI_SUCCESS(AcpiGetHandle(phandle, "_GTM", &tmp))) || |
(ACPI_SUCCESS(AcpiGetHandle(phandle, "_STM", &tmp))) || |
(ACPI_SUCCESS(AcpiGetHandle(phandle, "_SDD", &tmp)))) |
return 0; |
|
return -ENODEV; |
if (!pci_use_crs) { |
printk("host bridge window %pR (ignored)\n", res); |
return AE_OK; |
} |
|
/* |
* acpi_dock_match - see if a device has a _DCK method |
*/ |
static int acpi_dock_match(struct acpi_device *device) |
{ |
ACPI_HANDLE tmp; |
return AcpiGetHandle(device->handle, "_DCK", &tmp); |
#if 0 |
conflict = insert_resource_conflict(root, res); |
if (conflict) { |
dev_err(&info->bridge->dev, |
"address space collision: host bridge window %pR " |
"conflicts with %s %pR\n", |
res, conflict->name, conflict); |
} else { |
pci_bus_add_resource(info->bus, res, 0); |
info->res_num++; |
if (addr.translation_offset) |
dev_info(&info->bridge->dev, "host bridge window %pR " |
"(PCI address [%#llx-%#llx])\n", |
res, res->start - addr.translation_offset, |
res->end - addr.translation_offset); |
else |
dev_info(&info->bridge->dev, |
"host bridge window %pR\n", res); |
} |
|
char *acpi_device_hid(struct acpi_device *device) |
{ |
struct acpi_hardware_id *hid; |
|
hid = list_first_entry(&device->pnp.ids, struct acpi_hardware_id, list); |
return hid->id; |
return AE_OK; |
#endif |
} |
|
|
|
static void acpi_add_id(struct acpi_device *device, const char *dev_id) |
static void |
get_current_resources(struct acpi_device *device, int busnum, |
int domain, struct pci_bus *bus) |
{ |
struct acpi_hardware_id *id; |
struct pci_root_info info; |
size_t size; |
|
id = kmalloc(sizeof(*id), GFP_KERNEL); |
if (!id) |
{ |
return; |
}; |
char buf[64]; |
|
INIT_LIST_HEAD(&id->list); |
// if (pci_use_crs) |
// pci_bus_remove_resources(bus); |
|
id->id = kmalloc(strlen(dev_id) + 1, GFP_KERNEL); |
if (!id->id) { |
kfree(id); |
info.bridge = device; |
info.bus = bus; |
info.res_num = 0; |
AcpiWalkResources(device->handle, METHOD_NAME__CRS, count_resource, |
&info); |
if (!info.res_num) |
return; |
} |
|
strcpy(id->id, dev_id); |
size = sizeof(*info.res) * info.res_num; |
info.res = kmalloc(size, GFP_KERNEL); |
if (!info.res) |
goto res_alloc_fail; |
|
list_add_tail(&id->list, &device->pnp.ids); |
} |
vsprintf(buf,"PCI Bus %04x:%02x", domain, busnum); |
info.name = strdup(buf); |
|
#define ACPI_VIDEO_OUTPUT_SWITCHING 0x0001 |
#define ACPI_VIDEO_DEVICE_POSTING 0x0002 |
#define ACPI_VIDEO_ROM_AVAILABLE 0x0004 |
#define ACPI_VIDEO_BACKLIGHT 0x0008 |
#define ACPI_VIDEO_BACKLIGHT_FORCE_VENDOR 0x0010 |
#define ACPI_VIDEO_BACKLIGHT_FORCE_VIDEO 0x0020 |
#define ACPI_VIDEO_OUTPUT_SWITCHING_FORCE_VENDOR 0x0040 |
#define ACPI_VIDEO_OUTPUT_SWITCHING_FORCE_VIDEO 0x0080 |
#define ACPI_VIDEO_BACKLIGHT_DMI_VENDOR 0x0100 |
#define ACPI_VIDEO_BACKLIGHT_DMI_VIDEO 0x0200 |
#define ACPI_VIDEO_OUTPUT_SWITCHING_DMI_VENDOR 0x0400 |
#define ACPI_VIDEO_OUTPUT_SWITCHING_DMI_VIDEO 0x0800 |
if (!info.name) |
goto name_alloc_fail; |
|
info.res_num = 0; |
AcpiWalkResources(device->handle, METHOD_NAME__CRS, setup_resource, |
&info); |
|
long acpi_is_video_device(struct acpi_device *device) |
{ |
ACPI_HANDLE h_dummy; |
long video_caps = 0; |
return; |
|
if (!device) |
return 0; |
name_alloc_fail: |
kfree(info.res); |
res_alloc_fail: |
return; |
} |
|
/* Is this device able to support video switching ? */ |
if (ACPI_SUCCESS(AcpiGetHandle(device->handle, "_DOD", &h_dummy)) || |
ACPI_SUCCESS(AcpiGetHandle(device->handle, "_DOS", &h_dummy))) |
video_caps |= ACPI_VIDEO_OUTPUT_SWITCHING; |
|
/* Is this device able to retrieve a video ROM ? */ |
if (ACPI_SUCCESS(AcpiGetHandle(device->handle, "_ROM", &h_dummy))) |
video_caps |= ACPI_VIDEO_ROM_AVAILABLE; |
|
/* Is this device able to configure which video head to be POSTed ? */ |
if (ACPI_SUCCESS(AcpiGetHandle(device->handle, "_VPO", &h_dummy)) && |
ACPI_SUCCESS(AcpiGetHandle(device->handle, "_GPD", &h_dummy)) && |
ACPI_SUCCESS(AcpiGetHandle(device->handle, "_SPD", &h_dummy))) |
video_caps |= ACPI_VIDEO_DEVICE_POSTING; |
|
return video_caps; |
} |
struct pci_ops pci_root_ops = { |
.read = NULL, |
.write = NULL, |
}; |
|
|
static void acpi_device_set_id(struct acpi_device *device) |
struct pci_bus* pci_acpi_scan_root(struct acpi_pci_root *root) |
{ |
ACPI_STATUS status; |
ACPI_DEVICE_INFO *info; |
ACPI_DEVICE_ID_LIST *cid_list; |
int i; |
struct acpi_device *device = root->device; |
int domain = root->segment; |
int busnum = root->secondary.start; |
struct pci_bus *bus; |
struct pci_sysdata *sd; |
int node = 0; |
|
switch (device->device_type) |
{ |
case ACPI_BUS_TYPE_DEVICE: |
if (ACPI_IS_ROOT_DEVICE(device)) |
{ |
acpi_add_id(device, ACPI_SYSTEM_HID); |
break; |
if (domain ) { |
printk(KERN_WARNING "pci_bus %04x:%02x: " |
"ignored (multiple domains not supported)\n", |
domain, busnum); |
return NULL; |
} |
|
status = AcpiGetObjectInfo(device->handle, &info); |
if (ACPI_FAILURE(status)) { |
printk(KERN_ERR "%s: Error reading device info\n", __func__); |
return; |
/* Allocate per-root-bus (not per bus) arch-specific data. |
* TODO: leak; this memory is never freed. |
* It's arguable whether it's worth the trouble to care. |
*/ |
sd = kzalloc(sizeof(*sd), GFP_KERNEL); |
if (!sd) { |
printk(KERN_WARNING "pci_bus %04x:%02x: " |
"ignored (out of memory)\n", domain, busnum); |
return NULL; |
} |
|
if (info->Valid & ACPI_VALID_HID) |
acpi_add_id(device, info->HardwareId.String); |
if (info->Valid & ACPI_VALID_CID) |
{ |
cid_list = &info->CompatibleIdList; |
for (i = 0; i < cid_list->Count; i++) |
acpi_add_id(device, cid_list->Ids[i].String); |
sd->domain = domain; |
sd->node = node; |
/* |
* Maybe the desired pci bus has been already scanned. In such case |
* it is unnecessary to scan the pci bus with the given domain,busnum. |
*/ |
bus = pci_find_bus(domain, busnum); |
if (bus) { |
/* |
* If the desired bus exits, the content of bus->sysdata will |
* be replaced by sd. |
*/ |
memcpy(bus->sysdata, sd, sizeof(*sd)); |
kfree(sd); |
} else { |
bus = pci_create_bus(busnum, &pci_root_ops, sd); |
if (bus) { |
get_current_resources(device, busnum, domain, bus); |
// bus->subordinate = pci_scan_child_bus(bus); |
} |
if (info->Valid & ACPI_VALID_ADR) { |
device->pnp.bus_address = info->Address; |
device->flags.bus_address = 1; |
} |
|
kfree(info); |
if (!bus) |
kfree(sd); |
|
/* |
* Some devices don't reliably have _HIDs & _CIDs, so add |
* synthetic HIDs to make sure drivers can find them. |
*/ |
if (acpi_is_video_device(device)) |
acpi_add_id(device, ACPI_VIDEO_HID); |
else if (ACPI_SUCCESS(acpi_bay_match(device))) |
acpi_add_id(device, ACPI_BAY_HID); |
else if (ACPI_SUCCESS(acpi_dock_match(device))) |
acpi_add_id(device, ACPI_DOCK_HID); |
else if (!acpi_device_hid(device) && |
ACPI_IS_ROOT_DEVICE(device->parent)) { |
acpi_add_id(device, ACPI_BUS_HID); /* \_SB, LNXSYBUS */ |
strcpy(device->pnp.device_name, ACPI_BUS_DEVICE_NAME); |
strcpy(device->pnp.device_class, ACPI_BUS_CLASS); |
if (bus && node != -1) { |
printk("on NUMA node %d\n", node); |
} |
|
break; |
case ACPI_BUS_TYPE_POWER: |
acpi_add_id(device, ACPI_POWER_HID); |
break; |
case ACPI_BUS_TYPE_PROCESSOR: |
acpi_add_id(device, ACPI_PROCESSOR_OBJECT_HID); |
break; |
case ACPI_BUS_TYPE_THERMAL: |
acpi_add_id(device, ACPI_THERMAL_HID); |
break; |
case ACPI_BUS_TYPE_POWER_BUTTON: |
acpi_add_id(device, ACPI_BUTTON_HID_POWERF); |
break; |
case ACPI_BUS_TYPE_SLEEP_BUTTON: |
acpi_add_id(device, ACPI_BUTTON_HID_SLEEPF); |
break; |
return bus; |
} |
|
/* |
* We build acpi_devices for some objects that don't have _HID or _CID, |
* e.g., PCI bridges and slots. Drivers can't bind to these objects, |
* but we do use them indirectly by traversing the acpi_device tree. |
* This generic ID isn't useful for driver binding, but it provides |
* the useful property that "every acpi_device has an ID." |
*/ |
if (list_empty(&device->pnp.ids)) |
acpi_add_id(device, "device"); |
} |
|
|
static int acpi_device_set_context(struct acpi_device *device) |
static int acpi_pci_root_add(struct acpi_device *device) |
{ |
unsigned long long segment, bus; |
ACPI_STATUS status; |
int result; |
struct acpi_pci_root *root; |
ACPI_HANDLE handle; |
struct acpi_device *child; |
u32 flags, base_flags; |
|
/* |
* Context |
* ------- |
* Attach this 'struct acpi_device' to the ACPI object. This makes |
* resolutions from handle->device very efficient. Fixed hardware |
* devices have no handles, so we skip them. |
*/ |
if (!device->handle) |
return 0; |
root = kzalloc(sizeof(struct acpi_pci_root), GFP_KERNEL); |
if (!root) |
return -ENOMEM; |
|
status = AcpiAttachData(device->handle, |
acpi_bus_data_handler, device); |
if (ACPI_SUCCESS(status)) |
return 0; |
|
dbgprintf(KERN_ERR "Error attaching device data\n"); |
return -ENODEV; |
segment = 0; |
status = acpi_evaluate_integer(device->handle, METHOD_NAME__SEG, NULL, |
&segment); |
if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) { |
printk(KERN_ERR PREFIX "can't evaluate _SEG\n"); |
result = -ENODEV; |
goto end; |
} |
|
|
static int acpi_device_register(struct acpi_device *device) |
/* Check _CRS first, then _BBN. If no _BBN, default to zero. */ |
root->secondary.flags = IORESOURCE_BUS; |
status = try_get_root_bridge_busnr(device->handle, &root->secondary); |
if (ACPI_FAILURE(status)) |
{ |
int result; |
struct acpi_device_bus_id *acpi_device_bus_id, *new_bus_id; |
int found = 0; |
|
/* |
* Linkage |
* ------- |
* Link this device to its parent and siblings. |
* We need both the start and end of the downstream bus range |
* to interpret _CBA (MMCONFIG base address), so it really is |
* supposed to be in _CRS. If we don't find it there, all we |
* can do is assume [_BBN-0xFF] or [0-0xFF]. |
*/ |
INIT_LIST_HEAD(&device->children); |
INIT_LIST_HEAD(&device->node); |
|
new_bus_id = kzalloc(sizeof(struct acpi_device_bus_id), GFP_KERNEL); |
if (!new_bus_id) { |
dbgprintf(KERN_ERR "Memory allocation error\n"); |
return -ENOMEM; |
root->secondary.end = 0xFF; |
printk(KERN_WARNING PREFIX |
"no secondary bus range in _CRS\n"); |
status = acpi_evaluate_integer(device->handle, METHOD_NAME__BBN, NULL, &bus); |
if (ACPI_SUCCESS(status)) |
root->secondary.start = bus; |
else if (status == AE_NOT_FOUND) |
root->secondary.start = 0; |
else { |
printk(KERN_ERR PREFIX "can't evaluate _BBN\n"); |
result = -ENODEV; |
goto end; |
} |
|
mutex_lock(&acpi_device_lock); |
/* |
* Find suitable bus_id and instance number in acpi_bus_id_list |
* If failed, create one and link it into acpi_bus_id_list |
*/ |
list_for_each_entry(acpi_device_bus_id, &acpi_bus_id_list, node) |
{ |
if (!strcmp(acpi_device_bus_id->bus_id, acpi_device_hid(device))) |
{ |
acpi_device_bus_id->instance_no++; |
found = 1; |
kfree(new_bus_id); |
break; |
} |
} |
if (!found) |
{ |
acpi_device_bus_id = new_bus_id; |
strcpy(acpi_device_bus_id->bus_id, acpi_device_hid(device)); |
acpi_device_bus_id->instance_no = 0; |
list_add_tail(&acpi_device_bus_id->node, &acpi_bus_id_list); |
} |
|
// dev_set_name(&device->dev, "%s:%02x", acpi_device_bus_id->bus_id, acpi_device_bus_id->instance_no); |
INIT_LIST_HEAD(&root->node); |
root->device = device; |
root->segment = segment & 0xFFFF; |
strcpy(acpi_device_name(device), ACPI_PCI_ROOT_DEVICE_NAME); |
strcpy(acpi_device_class(device), ACPI_PCI_ROOT_CLASS); |
device->driver_data = root; |
|
if (device->parent) |
list_add_tail(&device->node, &device->parent->children); |
|
mutex_unlock(&acpi_device_lock); |
|
// device->dev.bus = &acpi_bus_type; |
// device->dev.release = &acpi_device_release; |
// result = device_register(&device->dev); |
// if (result) { |
// dev_err(&device->dev, "Error registering device\n"); |
// goto end; |
// } |
|
|
// device->removal_type = ACPI_BUS_REMOVAL_NORMAL; |
return 0; |
end: |
mutex_lock(&acpi_device_lock); |
if (device->parent) |
list_del(&device->node); |
mutex_unlock(&acpi_device_lock); |
return result; |
} |
|
|
|
static int acpi_add_single_object(struct acpi_device **child, |
ACPI_HANDLE handle, int type, |
unsigned long long sta, |
struct acpi_bus_ops *ops) |
{ |
int result; |
struct acpi_device *device; |
ACPI_BUFFER buffer = { ACPI_ALLOCATE_BUFFER, NULL }; |
|
device = kzalloc(sizeof(struct acpi_device), GFP_KERNEL); |
if (!device) { |
dbgprintf("%s: Memory allocation error\n", __FUNCTION__); |
return -ENOMEM; |
} |
|
INIT_LIST_HEAD(&device->pnp.ids); |
device->device_type = type; |
device->handle = handle; |
device->parent = acpi_bus_get_parent(handle); |
device->bus_ops = *ops; /* workround for not call .start */ |
STRUCT_TO_INT(device->status) = sta; |
|
acpi_device_get_busid(device); |
|
/* |
* Flags |
* ----- |
* Note that we only look for object handles -- cannot evaluate objects |
* until we know the device is present and properly initialized. |
* All supported architectures that use ACPI have support for |
* PCI domains, so we indicate this in _OSC support capabilities. |
*/ |
result = acpi_bus_get_flags(device); |
if (result) |
goto end; |
// flags = base_flags = OSC_PCI_SEGMENT_GROUPS_SUPPORT; |
// acpi_pci_osc_support(root, flags); |
|
/* |
* Initialize Device |
* ----------------- |
* TBD: Synch with Core's enumeration/initialization process. |
* TBD: Need PCI interface for enumeration/configuration of roots. |
*/ |
acpi_device_set_id(device); |
|
/* TBD: Locking */ |
list_add_tail(&root->node, &acpi_pci_roots); |
|
if ((result = acpi_device_set_context(device))) |
goto end; |
printk(KERN_INFO PREFIX "%s [%s] (domain %04x %pR)\n", |
acpi_device_name(device), acpi_device_bid(device), |
root->segment, &root->secondary); |
|
result = acpi_device_register(device); |
|
/* |
* Bind _ADR-Based Devices when hot add |
* Scan the Root Bridge |
* -------------------- |
* Must do this prior to any attempt to bind the root device, as the |
* PCI namespace does not get created until this call is made (and |
* thus the root bridge's pci_dev does not exist). |
*/ |
// if (device->flags.bus_address) { |
// if (device->parent && device->parent->ops.bind) |
// device->parent->ops.bind(device); |
// } |
|
end: |
if (!result) { |
AcpiGetName(handle, ACPI_FULL_PATHNAME, &buffer); |
dbgprintf("Adding [%s]\n", (char *)buffer.Pointer); |
kfree(buffer.Pointer); |
*child = device; |
}; |
return result; |
root->bus = pci_acpi_scan_root(root); |
if (!root->bus) { |
printk(KERN_ERR PREFIX |
"Bus %04x:%02x not present in PCI namespace\n", |
root->segment, (unsigned int)root->secondary.start); |
result = -ENODEV; |
goto end; |
} |
|
|
|
|
static ACPI_STATUS acpi_bus_check_add(ACPI_HANDLE handle, u32 lvl, |
void *context, void **return_value) |
{ |
struct acpi_bus_ops *ops = context; |
int type; |
unsigned long long sta; |
struct acpi_device *device; |
ACPI_STATUS status; |
int result; |
|
result = acpi_bus_type_and_status(handle, &type, &sta); |
|
if (result) |
{ |
return AE_OK; |
}; |
|
if (!(sta & ACPI_STA_DEVICE_PRESENT) && |
!(sta & ACPI_STA_DEVICE_FUNCTIONING)) |
{ |
return AE_CTRL_DEPTH; |
}; |
|
/* |
* We may already have an acpi_device from a previous enumeration. If |
* so, we needn't add it again, but we may still have to start it. |
* Attach ACPI-PCI Context |
* ----------------------- |
* Thus binding the ACPI and PCI devices. |
*/ |
device = NULL; |
acpi_bus_get_device(handle, &device); |
if (ops->acpi_op_add && !device) |
acpi_add_single_object(&device, handle, type, sta, ops); |
// result = acpi_pci_bind_root(device); |
// if (result) |
// goto end; |
|
if (!device) |
{ |
return AE_CTRL_DEPTH; |
}; |
/* |
if (ops->acpi_op_start && !(ops->acpi_op_add)) { |
status = acpi_start_single_object(device); |
if (ACPI_FAILURE(status)) |
return AE_CTRL_DEPTH; |
} |
* PCI Routing Table |
* ----------------- |
* Evaluate and parse _PRT, if exists. |
*/ |
|
if (!*return_value) |
*return_value = device; |
|
return AE_OK; |
} |
|
|
|
static int acpi_bus_scan(ACPI_HANDLE handle, struct acpi_bus_ops *ops, |
struct acpi_device **child) |
{ |
ACPI_STATUS status; |
void *device = NULL; |
|
ENTER(); |
|
status = acpi_bus_check_add(handle, 0, ops, &device); |
|
status = AcpiGetHandle(device->handle, METHOD_NAME__PRT, &handle); |
if (ACPI_SUCCESS(status)) |
AcpiWalkNamespace(ACPI_TYPE_ANY, handle, ACPI_UINT32_MAX, |
acpi_bus_check_add, NULL, ops, &device); |
result = acpi_pci_irq_add_prt(device->handle, root->bus); |
|
if (child) |
*child = device; |
/* |
* Scan and bind all _ADR-Based Devices |
*/ |
// list_for_each_entry(child, &device->children, node) |
// acpi_pci_bridge_scan(child); |
|
LEAVE(); |
return 0; |
|
if (device) |
return 0; |
else |
return -ENODEV; |
end: |
if (!list_empty(&root->node)) |
list_del(&root->node); |
kfree(root); |
return result; |
} |
|
|
|
int acpi_scan() |
static const struct acpi_device_ids root_device_ids[] = |
{ |
int err; |
struct acpi_bus_ops ops; |
|
memset(&ops, 0, sizeof(ops)); |
ops.acpi_op_add = 1; |
ops.acpi_op_start = 1; |
|
err = acpi_bus_scan(ACPI_ROOT_OBJECT, &ops, &acpi_root); |
|
return err; |
{"PNP0A03", 0}, |
{"", 0}, |
}; |
|
void acpi_init_pci(struct acpi_device *device) |
{ |
struct acpi_device *child; |
|
enum pic_mode |
if ( !acpi_match_device_ids(device, root_device_ids) ) |
{ |
IO_PIC = 0, |
IO_APIC |
dbgprintf(PREFIX "PCI root %s\n", device->pnp.bus_id); |
acpi_pci_root_add(device); |
}; |
|
static void set_pic_mode(enum pic_mode mode) |
{ |
ACPI_OBJECT arg1; |
ACPI_OBJECT_LIST args; |
ACPI_STATUS as; |
|
arg1.Type = ACPI_TYPE_INTEGER; |
arg1.Integer.Value = mode; |
args.Count = 1; |
args.Pointer = &arg1; |
|
as = AcpiEvaluateObject(ACPI_ROOT_OBJECT, "_PIC", &args, NULL); |
/* |
* We can silently ignore failure as it may not be implemented, ACPI should |
* provide us with correct information anyway |
*/ |
if (ACPI_SUCCESS(as)) |
dbgprintf("ACPI: machine set to %s mode\n", mode ? "APIC" : "PIC"); |
} |
|
void print_device_tree(struct acpi_device *device) |
{ |
struct acpi_device *child; |
|
dbgprintf("%s\n", device->pnp.bus_id); |
|
list_for_each_entry(child, &device->children, node) |
{ |
print_device_tree(child); |
acpi_init_pci(child); |
}; |
|
}; |
|
|
u32_t drvEntry(int action, char *cmdline) |
{ |
u32_t retval; |
1004,74 → 645,12 |
|
set_pic_mode(IO_APIC); |
|
#if 0 |
scan_devices(); |
acpi_scan(); |
|
{ |
bool retval = false; |
u32_t bus, last_bus; |
// print_device_tree(acpi_root); |
|
if( (last_bus = PciApi(1))==-1) |
return retval; |
acpi_init_pci(acpi_root); |
|
dbgprintf("last bus %x\n", last_bus); |
|
for(bus=0; bus <= last_bus; bus++) |
{ |
u32_t dev; |
|
for(dev = 0; dev < 32; dev++) |
{ |
u32_t fn; |
|
for(fn = 0; fn < 8; fn++) |
{ |
|
u32_t id; |
u32_t irq_bios, irq_acpi; |
u32_t irq_pin; |
u16_t pcicmd; |
u32_t tmp; |
|
u32_t devfn = (dev<<3 )|fn; |
|
id = PciRead32(bus,devfn, PCI_VENDOR_ID); |
|
/* some broken boards return 0 or ~0 if a slot is empty: */ |
if (id == 0xffffffff || id == 0x00000000 || |
id == 0x0000ffff || id == 0xffff0000) |
continue; |
|
pcicmd = PciRead16(bus,devfn, PCI_COMMAND); |
if (! pcicmd & PCI_COMMAND_IO) |
continue; |
|
tmp = PciRead32(bus,devfn, 0x3C); |
|
irq_bios = tmp & 0xFF; |
irq_pin = (tmp >> 8) & 0xFF; |
|
int slot = (fn >> 3) & 0x1f; |
|
irq_acpi = irqtable[ dev * PCI_MAX_PINS +(irq_pin-1) ]; |
|
if( irq_acpi < 0) |
dbgprintf("PCI: no ACPI IRQ routing for " |
"device %d.%d.%d INT%c\n",bus,dev,fn,'A'+irq_pin-1); |
|
dbgprintf("pci device %x_%x bus %d dev %d fn %d," |
"IRQ PIN %d BIOS IRQ %d ACPI IRQ %d\n", |
id & 0xFFFF, id>>16, bus, dev, fn, irq_pin, irq_bios, irq_acpi); |
}; |
} |
}; |
}; |
#endif |
|
acpi_scan(); |
|
print_device_tree(acpi_root); |
|
/* |
ACPI_HANDLE bus_handle; |
ACPI_HANDLE pci_root; |
1182,7 → 761,71 |
|
}; |
|
#if 0 |
scan_devices(); |
|
{ |
bool retval = false; |
u32_t bus, last_bus; |
|
if( (last_bus = PciApi(1))==-1) |
return retval; |
|
dbgprintf("last bus %x\n", last_bus); |
|
for(bus=0; bus <= last_bus; bus++) |
{ |
u32_t dev; |
|
for(dev = 0; dev < 32; dev++) |
{ |
u32_t fn; |
|
for(fn = 0; fn < 8; fn++) |
{ |
|
u32_t id; |
u32_t irq_bios, irq_acpi; |
u32_t irq_pin; |
u16_t pcicmd; |
u32_t tmp; |
|
u32_t devfn = (dev<<3 )|fn; |
|
id = PciRead32(bus,devfn, PCI_VENDOR_ID); |
|
/* some broken boards return 0 or ~0 if a slot is empty: */ |
if (id == 0xffffffff || id == 0x00000000 || |
id == 0x0000ffff || id == 0xffff0000) |
continue; |
|
pcicmd = PciRead16(bus,devfn, PCI_COMMAND); |
if (! pcicmd & PCI_COMMAND_IO) |
continue; |
|
tmp = PciRead32(bus,devfn, 0x3C); |
|
irq_bios = tmp & 0xFF; |
irq_pin = (tmp >> 8) & 0xFF; |
|
int slot = (fn >> 3) & 0x1f; |
|
irq_acpi = irqtable[ dev * PCI_MAX_PINS +(irq_pin-1) ]; |
|
if( irq_acpi < 0) |
dbgprintf("PCI: no ACPI IRQ routing for " |
"device %d.%d.%d INT%c\n",bus,dev,fn,'A'+irq_pin-1); |
|
dbgprintf("pci device %x_%x bus %d dev %d fn %d," |
"IRQ PIN %d BIOS IRQ %d ACPI IRQ %d\n", |
id & 0xFFFF, id>>16, bus, dev, fn, irq_pin, irq_bios, irq_acpi); |
}; |
} |
}; |
}; |
#endif |
|
|
#if 0 |
|
ACPI_STATUS |
1379,3 → 1022,15 |
} |
|
#endif |
|
char* strdup(const char *str) |
{ |
size_t len = strlen (str) + 1; |
char *copy = malloc(len); |
if (copy) |
{ |
memcpy (copy, str, len); |
} |
return copy; |
} |
|