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 */
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran/*
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu * Copyright (c) 2009-2010, Intel Corporation.
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran * All rights reserved.
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran */
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran#include <sys/types.h>
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran#include <sys/atomic.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>
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran#include <sys/acpidev_impl.h>
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoranstatic ACPI_STATUS acpidev_scope_probe(acpidev_walk_info_t *infop);
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoranstatic acpidev_filter_result_t acpidev_scope_filter(acpidev_walk_info_t *infop,
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran char *devname, int maxlen);
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoranstatic ACPI_STATUS acpidev_scope_init(acpidev_walk_info_t *infop);
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran/*
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran * Default class driver for ACPI scope objects.
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran * This class driver is used to handle predefined ACPI SCOPE objects
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran * under the ACPI root object, such as _PR_, _SB_ and _TZ_ etc.
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran * The default policy for ACPI SCOPE objects is SKIP.
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran */
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoranacpidev_class_t acpidev_class_scope = {
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran 0, /* adc_refcnt */
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran ACPIDEV_CLASS_REV1, /* adc_version */
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran ACPIDEV_CLASS_ID_SCOPE, /* adc_class_id */
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran "ACPI Scope", /* adc_class_name */
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran ACPIDEV_TYPE_SCOPE, /* adc_dev_type */
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran NULL, /* adc_private */
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran NULL, /* adc_pre_probe */
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran NULL, /* adc_post_probe */
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran acpidev_scope_probe, /* adc_probe */
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran acpidev_scope_filter, /* adc_filter */
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran acpidev_scope_init, /* adc_init */
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran NULL, /* adc_fini */
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran};
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoranacpidev_class_list_t *acpidev_class_list_scope = NULL;
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran/*
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran * All SCOPE objects share a global pseudo unit address space across the system.
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran */
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoranstatic uint32_t acpidev_scope_unitaddr = 0;
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran/* Filter rule table for ACPI SCOPE objects. */
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoranstatic acpidev_filter_rule_t acpidev_scope_filters[] = {
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran { /* For safety, _SB_ is hardcoded as DEVICE by acpica */
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran NULL,
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran 0,
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran ACPIDEV_FILTER_DEFAULT,
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran &acpidev_class_list_device,
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran 1,
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran 1,
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran ACPIDEV_OBJECT_NAME_SB,
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran ACPIDEV_NODE_NAME_MODULE_SBD,
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran },
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran { /* Handle _PR_ object. */
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran NULL,
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran 0,
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran ACPIDEV_FILTER_SCAN,
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran &acpidev_class_list_scope,
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran 1,
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran 1,
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran ACPIDEV_OBJECT_NAME_PR,
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran ACPIDEV_NODE_NAME_PROCESSOR,
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran },
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran { /* Ignore all other scope objects. */
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran NULL,
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran 0,
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran ACPIDEV_FILTER_SKIP,
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran NULL,
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran 1,
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran INT_MAX,
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran NULL,
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran NULL,
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran }
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran};
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoranstatic ACPI_STATUS
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoranacpidev_scope_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 if (infop->awi_info->Type != ACPI_TYPE_LOCAL_SCOPE) {
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 flags |= ACPIDEV_PROCESS_FLAG_CREATE;
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 flags |= ACPIDEV_PROCESS_FLAG_SYNCSTATUS |
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu ACPIDEV_PROCESS_FLAG_HOLDBRANCH;
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu break;
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu default:
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu ACPIDEV_DEBUG(CE_WARN, "!acpidev: unknown operation type %u "
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran "in acpidev_scope_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 scope 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 acpidev_filter_result_t
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoranacpidev_scope_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_scope_filters),
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran devname, maxlen);
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran } else {
a31148363f598def767ac48c5d82e1572e44b935Gerry Liu ACPIDEV_DEBUG(CE_WARN, "!acpidev: unknown operation type %u "
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran "in acpidev_scope_filter().", infop->awi_op_type);
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran res = ACPIDEV_FILTER_FAILED;
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran }
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran return (res);
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran}
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoranstatic ACPI_STATUS
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoranacpidev_scope_init(acpidev_walk_info_t *infop)
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran{
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran char unitaddr[32];
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran char *compatible[] = {
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran ACPIDEV_HID_SCOPE,
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran ACPIDEV_TYPE_SCOPE,
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 if (ACPI_FAILURE(acpidev_set_compatible(infop,
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran ACPIDEV_ARRAY_PARAM(compatible)))) {
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran return (AE_ERROR);
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran }
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran (void) snprintf(unitaddr, sizeof (unitaddr), "%u",
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran atomic_inc_32_nv(&acpidev_scope_unitaddr) - 1);
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran if (ACPI_FAILURE(acpidev_set_unitaddr(infop, NULL, 0, unitaddr))) {
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran return (AE_ERROR);
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran }
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran return (AE_OK);
b72d5b75fd6f5bb08d29f65652d60058fc3a2608Michael Corcoran}