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