acpi_verbose.c revision 1.2
1/*	$NetBSD: acpi_verbose.c,v 1.2 2010/06/05 06:07:12 jruoho Exp $ */
2
3/*-
4 * Copyright (c) 2003, 2007 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Charles M. Hannum of By Noon Software, Inc.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 *    notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 *    notice, this list of conditions and the following disclaimer in the
17 *    documentation and/or other materials provided with the distribution.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 */
31
32/*
33 * Copyright 2001, 2003 Wasabi Systems, Inc.
34 * All rights reserved.
35 *
36 * Written by Jason R. Thorpe for Wasabi Systems, Inc.
37 *
38 * Redistribution and use in source and binary forms, with or without
39 * modification, are permitted provided that the following conditions
40 * are met:
41 * 1. Redistributions of source code must retain the above copyright
42 *    notice, this list of conditions and the following disclaimer.
43 * 2. Redistributions in binary form must reproduce the above copyright
44 *    notice, this list of conditions and the following disclaimer in the
45 *    documentation and/or other materials provided with the distribution.
46 * 3. All advertising materials mentioning features or use of this software
47 *    must display the following acknowledgement:
48 *	This product includes software developed for the NetBSD Project by
49 *	Wasabi Systems, Inc.
50 * 4. The name of Wasabi Systems, Inc. may not be used to endorse
51 *    or promote products derived from this software without specific prior
52 *    written permission.
53 *
54 * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
55 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
56 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
57 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
58 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
59 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
60 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
61 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
62 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
63 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
64 * POSSIBILITY OF SUCH DAMAGE.
65 */
66
67#include <sys/cdefs.h>
68__KERNEL_RCSID(0, "$NetBSD: acpi_verbose.c,v 1.2 2010/06/05 06:07:12 jruoho Exp $");
69
70#include <sys/param.h>
71#include <sys/device.h>
72#include <sys/kernel.h>
73#include <sys/systm.h>
74#include <sys/module.h>
75
76#include <dev/acpi/acpireg.h>
77#include <dev/acpi/acpivar.h>
78#include <dev/acpi/acpidevs_data.h>
79
80void	acpi_print_devnodes_real(struct acpi_softc *);
81void	acpi_print_tree_real(struct acpi_devnode *, uint32_t);
82void	acpi_print_dev_real(const char *);
83
84MODULE(MODULE_CLASS_MISC, acpiverbose, NULL);
85
86__weak_alias(acpi_wmidump_real, acpi_null);
87
88static int
89acpiverbose_modcmd(modcmd_t cmd, void *arg)
90{
91	switch (cmd) {
92	case MODULE_CMD_INIT:
93		acpi_print_devnodes = acpi_print_devnodes_real;
94		acpi_print_tree = acpi_print_tree_real;
95		acpi_print_dev = acpi_print_dev_real;
96		acpi_wmidump = acpi_wmidump_real;
97		return 0;
98	case MODULE_CMD_FINI:
99		acpi_print_devnodes = (void *)acpi_null;
100		acpi_print_tree = (void *)acpi_null;
101		acpi_print_dev = (void *)acpi_null;
102		acpi_wmidump = (void *)acpi_null;
103		return 0;
104	default:
105		return ENOTTY;
106	}
107}
108
109void
110acpi_print_devnodes_real(struct acpi_softc *sc)
111{
112	struct acpi_devnode *ad;
113	ACPI_DEVICE_INFO *di;
114
115	SIMPLEQ_FOREACH(ad, &sc->ad_head, ad_list) {
116
117		di = ad->ad_devinfo;
118		aprint_normal_dev(sc->sc_dev, "%-5s ", ad->ad_name);
119
120		aprint_normal("HID %-10s ",
121		    ((di->Valid & ACPI_VALID_HID) != 0) ?
122		    di->HardwareId.String: "-");
123
124		aprint_normal("UID %-4s ",
125		    ((di->Valid & ACPI_VALID_UID) != 0) ?
126		    di->UniqueId.String : "-");
127
128		if ((di->Valid & ACPI_VALID_STA) != 0)
129			aprint_normal("STA 0x%08X ", di->CurrentStatus);
130		else
131			aprint_normal("STA %10s ", "-");
132
133		if ((di->Valid & ACPI_VALID_ADR) != 0)
134			aprint_normal("ADR 0x%016" PRIX64"", di->Address);
135		else
136			aprint_normal("ADR -");
137
138		aprint_normal("\n");
139	}
140	aprint_normal("\n");
141}
142
143void
144acpi_print_tree_real(struct acpi_devnode *ad, uint32_t level)
145{
146	struct acpi_devnode *child;
147	uint32_t i;
148
149	for (i = 0; i < level; i++)
150		aprint_normal("    ");
151
152	aprint_normal("%-5s [%02u] [%c%c] ", ad->ad_name, ad->ad_type,
153	    ((ad->ad_flags & ACPI_DEVICE_POWER)  != 0) ? 'P' : ' ',
154	    ((ad->ad_flags & ACPI_DEVICE_WAKEUP) != 0) ? 'W' : ' ');
155
156	if (ad->ad_pciinfo != NULL) {
157
158		aprint_normal("(PCI) @ 0x%02X:0x%02X:0x%02X:0x%02X ",
159		    ad->ad_pciinfo->ap_segment, ad->ad_pciinfo->ap_bus,
160		    ad->ad_pciinfo->ap_device, ad->ad_pciinfo->ap_function);
161
162		if ((ad->ad_devinfo->Flags & ACPI_PCI_ROOT_BRIDGE) != 0)
163			aprint_normal("[R] ");
164
165		if (ad->ad_pciinfo->ap_bridge != false)
166			aprint_normal("[B] -> 0x%02X",
167			    ad->ad_pciinfo->ap_downbus);
168	}
169
170	aprint_normal("\n");
171
172	SIMPLEQ_FOREACH(child, &ad->ad_child_head, ad_child_list)
173	    acpi_print_tree(child, level + 1);
174}
175
176void acpi_print_dev_real(const char *pnpstr)
177{
178	int i;
179
180	for (i = 0; i < __arraycount(acpi_knowndevs); i++) {
181		if (strcmp(acpi_knowndevs[i].pnp, pnpstr) == 0) {
182			aprint_normal("[%s] ", acpi_knowndevs[i].str);
183		}
184	}
185}
186