1 /******************************************************************************
3 * Module Name: bmsearch.c
6 *****************************************************************************/
9 * Copyright (C) 2000, 2001 Andrew Grover
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30 #define _COMPONENT ACPI_BUS_MANAGER
31 MODULE_NAME ("bmsearch")
34 /****************************************************************************
36 ****************************************************************************/
38 /****************************************************************************
40 * FUNCTION: bm_compare
48 ****************************************************************************/
53 BM_DEVICE_ID
*criteria
)
55 if (!device
|| !criteria
) {
56 return AE_BAD_PARAMETER
;
62 * We're only going to match on devices that are present.
63 * TODO: Optimize in bm_search (don't have to call here).
65 if (!BM_DEVICE_PRESENT(device
)) {
72 if (criteria
->type
&& !(criteria
->type
& device
->id
.type
)) {
79 if ((criteria
->hid
[0]) && (0 != STRNCMP(criteria
->hid
,
80 device
->id
.hid
, sizeof(BM_DEVICE_HID
)))) {
87 if ((criteria
->adr
) && (criteria
->adr
!= device
->id
.adr
)) {
95 /****************************************************************************
101 * RETURN: AE_BAD_PARAMETER- invalid input parameter
102 * AE_NOT_EXIST - start_device_handle doesn't exist
103 * AE_NOT_FOUND - no matches to Search_info.criteria found
108 ****************************************************************************/
112 BM_HANDLE device_handle
,
113 BM_DEVICE_ID
*criteria
,
114 BM_HANDLE_LIST
*results
)
116 ACPI_STATUS status
= AE_OK
;
117 BM_NODE
*node
= NULL
;
119 FUNCTION_TRACE("bm_search");
121 if (!criteria
|| !results
) {
122 return_ACPI_STATUS(AE_BAD_PARAMETER
);
128 * Locate Starting Point:
129 * ----------------------
130 * Locate the node in the hierarchy where we'll begin our search.
132 status
= bm_get_node(device_handle
, 0, &node
);
133 if (ACPI_FAILURE(status
)) {
134 return_ACPI_STATUS(status
);
140 * Parse through the node hierarchy looking for matches.
142 while (node
&& (results
->count
<=BM_HANDLES_MAX
)) {
146 * Searches are always performed depth-first.
148 if (node
->scope
.head
) {
149 status
= bm_compare(&(node
->device
), criteria
);
150 if (ACPI_SUCCESS(status
)) {
151 results
->handles
[results
->count
++] =
154 node
= node
->scope
.head
;
160 * Search all peers until scope is exhausted.
163 status
= bm_compare(&(node
->device
), criteria
);
164 if (ACPI_SUCCESS(status
)) {
165 results
->handles
[results
->count
++] =
170 * Locate Next Device:
171 * -------------------
172 * The next node is either a peer at this level
173 * (node->next is valid), or we work are way back
174 * up the tree until we either find a non-parsed
175 * peer or hit the top (node->parent is NULL).
177 while (!node
->next
&& node
->parent
) {
184 if (results
->count
== 0) {
185 return_ACPI_STATUS(AE_NOT_FOUND
);
188 return_ACPI_STATUS(AE_OK
);