- Make ACPI use PCH. Cuts down compile time to 9 seconds on gcc.
[reactos.git] / reactos / drivers / bus / acpi / ospm / acpisys.c
1 /* $Id$
2 *
3 * PROJECT: ReactOS ACPI bus driver
4 * FILE: acpi/ospm/acpisys.c
5 * PURPOSE: Driver entry
6 * PROGRAMMERS: Casper S. Hornstrup (chorns@users.sourceforge.net)
7 * UPDATE HISTORY:
8 * 01-05-2001 CSH Created
9 */
10 #include <acpi.h>
11
12 #define NDEBUG
13 #include <debug.h>
14
15 NTSTATUS
16 STDCALL
17 DriverEntry(
18 IN PDRIVER_OBJECT DriverObject,
19 IN PUNICODE_STRING RegistryPath
20 );
21
22 #ifdef ALLOC_PRAGMA
23
24 // Make the initialization routines discardable, so that they
25 // don't waste space
26
27 #pragma alloc_text(init, DriverEntry)
28
29 #endif /* ALLOC_PRAGMA */
30
31
32 NTSTATUS
33 STDCALL
34 ACPIDispatchDeviceControl(
35 IN PDEVICE_OBJECT DeviceObject,
36 IN PIRP Irp)
37 {
38 PIO_STACK_LOCATION IrpSp;
39 NTSTATUS Status;
40
41 DPRINT("Called. IRP is at (0x%X)\n", Irp);
42
43 Irp->IoStatus.Information = 0;
44
45 IrpSp = IoGetCurrentIrpStackLocation(Irp);
46 switch (IrpSp->Parameters.DeviceIoControl.IoControlCode) {
47 default:
48 DPRINT("Unknown IOCTL 0x%X\n", IrpSp->Parameters.DeviceIoControl.IoControlCode);
49 Status = STATUS_NOT_IMPLEMENTED;
50 break;
51 }
52
53 if (Status != STATUS_PENDING) {
54 Irp->IoStatus.Status = Status;
55
56 DPRINT("Completing IRP at 0x%X\n", Irp);
57
58 IoCompleteRequest(Irp, IO_NO_INCREMENT);
59 }
60
61 DPRINT("Leaving. Status 0x%X\n", Status);
62
63 return Status;
64 }
65
66
67 NTSTATUS
68 STDCALL
69 ACPIPnpControl(
70 IN PDEVICE_OBJECT DeviceObject,
71 IN PIRP Irp)
72 /*
73 * FUNCTION: Handle Plug and Play IRPs
74 * ARGUMENTS:
75 * DeviceObject = Pointer to PDO or FDO
76 * Irp = Pointer to IRP that should be handled
77 * RETURNS:
78 * Status
79 */
80 {
81 PCOMMON_DEVICE_EXTENSION DeviceExtension;
82 NTSTATUS Status;
83
84 DPRINT("Called\n");
85
86 DeviceExtension = (PCOMMON_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
87
88 if (DeviceExtension->IsFDO) {
89 Status = FdoPnpControl(DeviceObject, Irp);
90 } else {
91 Status = PdoPnpControl(DeviceObject, Irp);
92 }
93
94 return Status;
95 }
96
97
98 NTSTATUS
99 STDCALL
100 ACPIPowerControl(
101 IN PDEVICE_OBJECT DeviceObject,
102 IN PIRP Irp)
103 {
104 PCOMMON_DEVICE_EXTENSION DeviceExtension;
105 NTSTATUS Status;
106
107 DPRINT("Called\n");
108
109 DeviceExtension = (PCOMMON_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
110
111 if (DeviceExtension->IsFDO) {
112 Status = FdoPowerControl(DeviceObject, Irp);
113 } else {
114 Status = PdoPowerControl(DeviceObject, Irp);
115 }
116
117 return Status;
118 }
119
120
121 NTSTATUS
122 STDCALL
123 ACPIAddDevice(
124 IN PDRIVER_OBJECT DriverObject,
125 IN PDEVICE_OBJECT PhysicalDeviceObject)
126 {
127 PFDO_DEVICE_EXTENSION DeviceExtension;
128 PDEVICE_OBJECT Fdo;
129 NTSTATUS Status;
130
131 DPRINT("Called\n");
132
133 if (PhysicalDeviceObject == NULL)
134 return STATUS_SUCCESS;
135
136 Status = IoCreateDevice(DriverObject,
137 sizeof(FDO_DEVICE_EXTENSION),
138 NULL,
139 FILE_DEVICE_ACPI,
140 FILE_DEVICE_SECURE_OPEN,
141 TRUE,
142 &Fdo);
143 if (!NT_SUCCESS(Status))
144 {
145 DPRINT("IoCreateDevice() failed with status 0x%X\n", Status);
146 return Status;
147 }
148
149 DeviceExtension = (PFDO_DEVICE_EXTENSION)Fdo->DeviceExtension;
150
151 DeviceExtension->Pdo = PhysicalDeviceObject;
152 DeviceExtension->Common.IsFDO = TRUE;
153
154 DeviceExtension->Common.Ldo =
155 IoAttachDeviceToDeviceStack(Fdo, PhysicalDeviceObject);
156
157 DeviceExtension->State = dsStopped;
158
159 Fdo->Flags &= ~DO_DEVICE_INITIALIZING;
160
161 DPRINT("Done AddDevice\n");
162
163 return STATUS_SUCCESS;
164 }
165
166
167 NTSTATUS
168 STDCALL
169 DriverEntry(
170 IN PDRIVER_OBJECT DriverObject,
171 IN PUNICODE_STRING RegistryPath)
172 {
173 DPRINT("Advanced Configuration and Power Interface Bus Driver\n");
174
175 DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = (PDRIVER_DISPATCH) ACPIDispatchDeviceControl;
176 DriverObject->MajorFunction[IRP_MJ_PNP] = (PDRIVER_DISPATCH) ACPIPnpControl;
177 DriverObject->MajorFunction[IRP_MJ_POWER] = (PDRIVER_DISPATCH) ACPIPowerControl;
178 DriverObject->DriverExtension->AddDevice = ACPIAddDevice;
179
180 return STATUS_SUCCESS;
181 }
182
183 /* EOF */