- Send the SCM reply packet with the final status after completing the requested...
[reactos.git] / reactos / drivers / bus / acpi / ospm / busmgr / bmrequest.c
1 /******************************************************************************
2 *
3 * Module Name: bmrequest.c
4 * $Revision: 1.1 $
5 *
6 *****************************************************************************/
7
8 /*
9 * Copyright (C) 2000, 2001 Andrew Grover
10 *
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.
15 *
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.
20 *
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
24 */
25
26
27 #include <acpi.h>
28
29 #define _COMPONENT ACPI_BUS_MANAGER
30 MODULE_NAME ("bmrequest")
31
32
33 /****************************************************************************
34 * External Functions
35 ****************************************************************************/
36
37 /****************************************************************************
38 *
39 * FUNCTION: bm_generate_request
40 *
41 * PARAMETERS: <TBD>
42 *
43 * RETURN: <TBD>
44 *
45 * DESCRIPTION: <TBD>
46 *
47 ****************************************************************************/
48
49 ACPI_STATUS
50 bm_generate_request (
51 BM_NODE *node,
52 BM_REQUEST *request)
53 {
54 ACPI_STATUS status = AE_OK;
55
56 FUNCTION_TRACE("bm_generate_request");
57
58 if (!node || !request) {
59 return_ACPI_STATUS(AE_BAD_PARAMETER);
60 }
61
62 DEBUG_PRINT(ACPI_INFO, ("Sending request [0x%02x] to device [0x%02x].\n", request->command, node->device.handle));
63
64 if (!(node->device.flags & BM_FLAGS_DRIVER_CONTROL) ||
65 !(node->driver.request)) {
66 DEBUG_PRINT(ACPI_WARN, ("No driver installed for device [0x%02x].\n", node->device.handle));
67 return_ACPI_STATUS(AE_NOT_EXIST);
68 }
69
70 status = node->driver.request(request, node->driver.context);
71
72 return_ACPI_STATUS(status);
73 }
74
75
76 /****************************************************************************
77 *
78 * FUNCTION: bm_request
79 *
80 * PARAMETERS: <TBD>
81 *
82 * RETURN: <TBD>
83 *
84 * DESCRIPTION: <TBD>
85 *
86 ****************************************************************************/
87
88 ACPI_STATUS
89 bm_request (
90 BM_REQUEST *request)
91 {
92 ACPI_STATUS status = AE_OK;
93 BM_NODE *node = NULL;
94 BM_DEVICE *device = NULL;
95
96 FUNCTION_TRACE("bm_request");
97
98 /*
99 * Must have a valid request structure.
100 */
101 if (!request) {
102 return_ACPI_STATUS(AE_BAD_PARAMETER);
103 }
104
105 DEBUG_PRINT(ACPI_INFO, ("Received request for device [0x%02x] command [0x%08x].\n", request->handle, request->command));
106
107 /*
108 * Resolve the node.
109 */
110 status = bm_get_node(request->handle, 0, &node);
111 if (ACPI_FAILURE(status)) {
112 return_ACPI_STATUS(status);
113 }
114
115 device = &(node->device);
116
117 /*
118 * Device-Specific Request?
119 * ------------------------
120 * If a device-specific command (>=0x80) forward this request to
121 * the appropriate driver.
122 */
123 if (request->command & BM_COMMAND_DEVICE_SPECIFIC) {
124 status = bm_generate_request(node, request);
125 return_ACPI_STATUS(status);
126 }
127
128 /*
129 * Bus-Specific Requests:
130 * ----------------------
131 */
132 switch (request->command) {
133
134 case BM_COMMAND_GET_POWER_STATE:
135 status = bm_get_power_state(node);
136 if (ACPI_FAILURE(status)) {
137 break;
138 }
139 status = bm_copy_to_buffer(&(request->buffer),
140 &(device->power.state), sizeof(BM_POWER_STATE));
141 break;
142
143 case BM_COMMAND_SET_POWER_STATE:
144 {
145 BM_POWER_STATE *power_state = NULL;
146
147 status = bm_cast_buffer(&(request->buffer),
148 (void**)&power_state, sizeof(BM_POWER_STATE));
149 if (ACPI_FAILURE(status)) {
150 break;
151 }
152 status = bm_set_power_state(node, *power_state);
153 }
154 break;
155
156 default:
157 status = AE_SUPPORT;
158 request->status = AE_SUPPORT;
159 break;
160 }
161
162 return_ACPI_STATUS(status);
163 }