b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran/*
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran * CDDL HEADER START
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran *
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran * The contents of this file are subject to the terms of the
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran * Common Development and Distribution License (the "License").
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran * You may not use this file except in compliance with the License.
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran *
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran * or http://www.opensolaris.org/os/licensing.
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran * See the License for the specific language governing permissions
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran * and limitations under the License.
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran *
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran * When distributing Covered Code, include this CDDL HEADER in each
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran * If applicable, add the following below this CDDL HEADER, with the
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran * fields enclosed by brackets "[]" replaced with your own identifying
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran * information: Portions Copyright [yyyy] [name of copyright owner]
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran *
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran * CDDL HEADER END
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran */
571909175b4f9a1ef15ec4afead6d6d463dbe760Dana Myers/*
571909175b4f9a1ef15ec4afead6d6d463dbe760Dana Myers * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
571909175b4f9a1ef15ec4afead6d6d463dbe760Dana Myers * Use is subject to license terms.
571909175b4f9a1ef15ec4afead6d6d463dbe760Dana Myers */
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran/*
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * Copyright (c) 2009-2010, Intel Corporation.
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran * All rights reserved.
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran */
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran/*
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran * There are three types of container objects defined in the ACPI Spec as below.
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran * PNP0A05: Generic Container Device
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran * A device whose settings are totally controlled by its ACPI resource
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran * information, and otherwise needs no device or bus-specific driver support.
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran * This was originally known as Generic ISA Bus Device.
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran * This ID should only be used for containers that do not produce resources
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran * for consumption by child devices. Any system resources claimed by a PNP0A05
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran * device's _CRS object must be consumed by the container itself.
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran * PNP0A06: Generic Container Device
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran * This device behaves exactly the same as the PNP0A05 device.
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran * This was originally known as Extended I/O Bus.
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran * This ID should only be used for containers that do not produce resources
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran * for consumption by child devices. Any system resources claimed by a PNP0A06
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran * device's _CRS object must be consumed by the container itself.
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran * ACPI0004: Module Device.
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran * This device is a container object that acts as a bus node in a namespace.
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran * A Module Device without any of the _CRS, _PRS and _SRS methods behaves
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran * the same way as the Generic Container Devices (PNP0A05 or PNP0A06).
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran * If the Module Device contains a _CRS method, only the resources
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran * described in the _CRS are available for consumption by its child devices.
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran * Also, the Module Device can support _PRS and _SRS methods if _CRS is
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran * supported.
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran */
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran#include <sys/types.h>
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran#include <sys/atomic.h>
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu#include <sys/note.h>
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran#include <sys/sunddi.h>
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran#include <sys/sunndi.h>
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran#include <sys/acpi/acpi.h>
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran#include <sys/acpica.h>
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran#include <sys/acpidev.h>
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu#include <sys/acpidev_dr.h>
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran#include <sys/acpidev_impl.h>
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoranstatic ACPI_STATUS acpidev_container_probe(acpidev_walk_info_t *infop);
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoranstatic acpidev_filter_result_t acpidev_container_filter(
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran acpidev_walk_info_t *infop, char *devname, int maxlen);
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoranstatic ACPI_STATUS acpidev_container_init(acpidev_walk_info_t *infop);
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoranstatic acpidev_filter_result_t acpidev_container_filter_func(
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran acpidev_walk_info_t *infop, ACPI_HANDLE hdl, acpidev_filter_rule_t *rulep,
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran char *devname, int devnamelen);
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran/*
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran * Default class driver for ACPI container objects.
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran */
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoranacpidev_class_t acpidev_class_container = {
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran 0, /* adc_refcnt */
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran ACPIDEV_CLASS_REV1, /* adc_version */
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran ACPIDEV_CLASS_ID_CONTAINER, /* adc_class_id */
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran "ACPI Container", /* adc_class_name */
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran ACPIDEV_TYPE_CONTAINER, /* adc_dev_type */
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran NULL, /* adc_private */
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran NULL, /* adc_pre_probe */
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran NULL, /* adc_post_probe */
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran acpidev_container_probe, /* adc_probe */
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran acpidev_container_filter, /* adc_filter */
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran acpidev_container_init, /* adc_init */
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran NULL, /* adc_fini */
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran};
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoranstatic char *acpidev_container_device_ids[] = {
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran ACPIDEV_HID_MODULE,
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran ACPIDEV_HID_CONTAINER1,
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran ACPIDEV_HID_CONTAINER2,
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran};
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoranstatic char *acpidev_container_uid_formats[] = {
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran "CPUSCK%x",
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran};
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran/* Filter rule table for container objects. */
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoranstatic acpidev_filter_rule_t acpidev_container_filters[] = {
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran { /* Ignore all container objects under ACPI root object */
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran NULL,
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran 0,
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran ACPIDEV_FILTER_SKIP,
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran NULL,
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran 1,
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran 1,
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran NULL,
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran NULL,
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran },
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran { /* Create node and scan child for all other container objects */
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran acpidev_container_filter_func,
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran 0,
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran ACPIDEV_FILTER_DEFAULT,
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran &acpidev_class_list_device,
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran 2,
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran INT_MAX,
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran NULL,
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran ACPIDEV_NODE_NAME_CONTAINER,
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran }
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran};
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoranstatic ACPI_STATUS
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoranacpidev_container_probe(acpidev_walk_info_t *infop)
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran{
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu ACPI_STATUS rc = AE_OK;
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran int flags;
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran ASSERT(infop != NULL);
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran ASSERT(infop->awi_hdl != NULL);
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran ASSERT(infop->awi_info != NULL);
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran if (infop->awi_info->Type != ACPI_TYPE_DEVICE ||
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran acpidev_match_device_id(infop->awi_info,
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran ACPIDEV_ARRAY_PARAM(acpidev_container_device_ids)) == 0) {
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran return (AE_OK);
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran }
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu flags = ACPIDEV_PROCESS_FLAG_SCAN;
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu switch (infop->awi_op_type) {
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu case ACPIDEV_OP_BOOT_PROBE:
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu if (acpica_get_devcfg_feature(ACPI_DEVCFG_CONTAINER)) {
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu flags |= ACPIDEV_PROCESS_FLAG_CREATE;
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu acpidev_dr_check(infop);
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu }
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu break;
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu case ACPIDEV_OP_BOOT_REPROBE:
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu break;
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu case ACPIDEV_OP_HOTPLUG_PROBE:
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu if (acpica_get_devcfg_feature(ACPI_DEVCFG_CONTAINER)) {
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu flags |= ACPIDEV_PROCESS_FLAG_CREATE |
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu ACPIDEV_PROCESS_FLAG_SYNCSTATUS |
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu ACPIDEV_PROCESS_FLAG_HOLDBRANCH;
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu }
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu break;
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu default:
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu ACPIDEV_DEBUG(CE_WARN, "!acpidev: unknown operation type %u in "
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran "acpidev_container_probe().", infop->awi_op_type);
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran rc = AE_BAD_PARAMETER;
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu break;
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu }
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu if (rc == AE_OK) {
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu rc = acpidev_process_object(infop, flags);
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran }
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran if (ACPI_FAILURE(rc) && rc != AE_NOT_EXIST && rc != AE_ALREADY_EXISTS) {
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran cmn_err(CE_WARN,
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran "!acpidev: failed to process container object %s.",
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran infop->awi_name);
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran } else {
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran rc = AE_OK;
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran }
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran return (rc);
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran}
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoranstatic ACPI_STATUS
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoranacpidev_container_search_dev(ACPI_HANDLE hdl, UINT32 lvl, void *ctx,
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran void **retval)
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran{
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu _NOTE(ARGUNUSED(hdl, retval));
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran int *fp = (int *)ctx;
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran *fp = lvl;
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran return (AE_CTRL_TERMINATE);
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran}
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoranstatic acpidev_filter_result_t
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoranacpidev_container_filter_func(acpidev_walk_info_t *infop, ACPI_HANDLE hdl,
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran acpidev_filter_rule_t *rulep, char *devname, int devnamelen)
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran{
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran ACPI_BUFFER buf;
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran void *retval;
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran int proc_lvl, cpu_lvl, module_lvl;
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran acpidev_filter_result_t res;
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran static char *cpu_hids[] = {
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran ACPIDEV_HID_CPU,
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran };
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran static char *module_hids[] = {
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran ACPIDEV_HID_MODULE,
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran };
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran res = acpidev_filter_default(infop, hdl, rulep, devname, devnamelen);
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran /* Return if we don't need to generate a device name. */
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran if (devname == NULL || res == ACPIDEV_FILTER_FAILED ||
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran res == ACPIDEV_FILTER_SKIP) {
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran return (res);
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran }
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran /* Try to figure out the most specific device name for the object. */
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran retval = NULL;
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran proc_lvl = INT_MAX;
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran cpu_lvl = INT_MAX;
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran module_lvl = INT_MAX;
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran /* Search for ACPI Processor object. */
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran (void) AcpiWalkNamespace(ACPI_TYPE_PROCESSOR, hdl, 2,
571909175b4f9a1ef15ec4afead6d6d463dbe760Dana Myers acpidev_container_search_dev, NULL, &proc_lvl, &retval);
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran /* Search for CPU Device object. */
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran (void) acpidev_get_device_by_id(hdl, ACPIDEV_ARRAY_PARAM(cpu_hids), 2,
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran B_FALSE, acpidev_container_search_dev, &cpu_lvl, &retval);
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran /* Search for Module Device object. */
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran (void) acpidev_get_device_by_id(hdl, ACPIDEV_ARRAY_PARAM(module_hids),
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran 2, B_FALSE, acpidev_container_search_dev, &module_lvl, &retval);
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran buf.Pointer = devname;
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran buf.Length = devnamelen;
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran if (cpu_lvl > proc_lvl) {
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran cpu_lvl = proc_lvl;
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran }
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran if (cpu_lvl == 1) {
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran /* CPU as child, most likely a physical CPU. */
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu (void) strlcpy(devname, ACPIDEV_NODE_NAME_MODULE_CPU,
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran devnamelen);
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran } else if (cpu_lvl == 2 && module_lvl == 1) {
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran /* CPU as grandchild, most likely a system board. */
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu (void) strlcpy(devname, ACPIDEV_NODE_NAME_MODULE_SBD,
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran devnamelen);
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran } else if (ACPI_FAILURE(AcpiGetName(infop->awi_hdl,
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran ACPI_SINGLE_NAME, &buf))) {
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran /*
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran * Failed to get ACPI object name; use ACPI object name
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran * as the default name.
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran */
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu (void) strlcpy(devname, ACPIDEV_NODE_NAME_CONTAINER,
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran devnamelen);
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran }
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran return (res);
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran}
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoranstatic acpidev_filter_result_t
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoranacpidev_container_filter(acpidev_walk_info_t *infop, char *devname, int maxlen)
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran{
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran acpidev_filter_result_t res;
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran ASSERT(infop != NULL);
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran if (infop->awi_op_type == ACPIDEV_OP_BOOT_PROBE ||
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran infop->awi_op_type == ACPIDEV_OP_BOOT_REPROBE ||
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran infop->awi_op_type == ACPIDEV_OP_HOTPLUG_PROBE) {
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran res = acpidev_filter_device(infop, infop->awi_hdl,
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran ACPIDEV_ARRAY_PARAM(acpidev_container_filters),
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran devname, maxlen);
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran } else {
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran res = ACPIDEV_FILTER_FAILED;
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran }
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran return (res);
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran}
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoranstatic ACPI_STATUS
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoranacpidev_container_init(acpidev_walk_info_t *infop)
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran{
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran static char *compatible[] = {
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran ACPIDEV_TYPE_CONTAINER,
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran ACPIDEV_HID_VIRTNEX,
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran ACPIDEV_TYPE_VIRTNEX,
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran };
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran ASSERT(infop != NULL);
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran ASSERT(infop->awi_hdl != NULL);
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran ASSERT(infop->awi_dip != NULL);
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran if (ACPI_FAILURE(acpidev_set_compatible(infop,
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran ACPIDEV_ARRAY_PARAM(compatible)))) {
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran return (AE_ERROR);
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran }
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran if (ACPI_FAILURE(acpidev_set_unitaddr(infop,
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran ACPIDEV_ARRAY_PARAM(acpidev_container_uid_formats), NULL))) {
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran return (AE_ERROR);
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran }
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran return (AE_OK);
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran}