ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

acpienum.c
Go to the documentation of this file.
00001 /* $Id: acpienum.c 21698 2006-04-22 05:55:17Z tretiakov $
00002  *
00003  * PROJECT:         ReactOS ACPI bus driver
00004  * FILE:            acpi/ospm/acpienum.c
00005  * PURPOSE:         ACPI namespace enumerator
00006  * PROGRAMMERS:     Casper S. Hornstrup (chorns@users.sourceforge.net)
00007  * UPDATE HISTORY:
00008  *      01-05-2001  CSH  Created
00009  */
00010 #include <acpi.h>
00011 #include <acpisys.h>
00012 #include <acpi_bus.h>
00013 #include <acpi_drivers.h>
00014 #include <list.h>
00015 
00016 #define NDEBUG
00017 #include <debug.h>
00018 
00019 #define HAS_CHILDREN(d)     ((d)->children.next != &((d)->children))
00020 #define HAS_SIBLINGS(d)     (((d)->parent) && ((d)->node.next != &(d)->parent->children))
00021 #define NODE_TO_DEVICE(n)   (list_entry(n, struct acpi_device, node))
00022 
00023 extern struct acpi_device       *acpi_root;
00024 
00025 NTSTATUS
00026 Bus_PlugInDevice (
00027     struct acpi_device *Device,
00028     PFDO_DEVICE_DATA            FdoData
00029     )
00030 {
00031     PDEVICE_OBJECT      pdo;
00032     PPDO_DEVICE_DATA    pdoData;
00033     NTSTATUS            status;
00034     ULONG               index;
00035     WCHAR               temp[256];
00036     PLIST_ENTRY         entry; 
00037 
00038     PAGED_CODE ();
00039 
00040     //Don't enumerate the root device
00041     if (Device->handle == ACPI_ROOT_OBJECT)
00042         return STATUS_SUCCESS;
00043 
00044     /* Check we didnt add this already */
00045     for (entry = FdoData->ListOfPDOs.Flink;
00046         entry != &FdoData->ListOfPDOs; entry = entry->Flink)
00047     {
00048         struct acpi_device *CurrentDevice;
00049 
00050         pdoData = CONTAINING_RECORD (entry, PDO_DEVICE_DATA, Link);
00051 
00052         //dont duplicate devices
00053         if (pdoData->AcpiHandle == Device->handle)
00054             return STATUS_SUCCESS;
00055 
00056         //check everything but fixed feature devices
00057         if (pdoData->AcpiHandle)
00058             acpi_bus_get_device(pdoData->AcpiHandle, &CurrentDevice);
00059         else
00060             continue;
00061 
00062         //check if the HID matches
00063         if (!strcmp(Device->pnp.hardware_id, CurrentDevice->pnp.hardware_id))
00064         {
00065             //check if UID exists for both and matches
00066             if (Device->flags.unique_id && CurrentDevice->flags.unique_id &&
00067                 !strcmp(Device->pnp.unique_id, CurrentDevice->pnp.unique_id))
00068             {
00069                 /* We have a UID on both but they're the same so we have to ignore it */
00070                 DPRINT1("Detected duplicate device: %hs %hs\n", Device->pnp.hardware_id, Device->pnp.unique_id);
00071                 return STATUS_SUCCESS;
00072             }
00073             else if (!Device->flags.unique_id && !CurrentDevice->flags.unique_id)
00074             {
00075                 /* No UID so we can only legally have 1 of these devices */
00076                 DPRINT1("Detected duplicate device: %hs\n", Device->pnp.hardware_id);
00077                 return STATUS_SUCCESS;
00078             }
00079         }
00080     }
00081 
00082     DPRINT("Exposing PDO\n"
00083            "======AcpiHandle:   %p\n"
00084            "======HardwareId:     %s\n",
00085            Device->handle,
00086            Device->pnp.hardware_id);
00087 
00088 
00089     //
00090     // Create the PDO
00091     //
00092 
00093     DPRINT("FdoData->NextLowerDriver = 0x%p\n", FdoData->NextLowerDriver);
00094 
00095     status = IoCreateDevice(FdoData->Common.Self->DriverObject,
00096                               sizeof(PDO_DEVICE_DATA),
00097                               NULL,
00098                               FILE_DEVICE_CONTROLLER,
00099                               FILE_AUTOGENERATED_DEVICE_NAME,
00100                               FALSE,
00101                               &pdo);
00102 
00103     if (!NT_SUCCESS (status)) {
00104         return status;
00105     }
00106 
00107     pdoData = (PPDO_DEVICE_DATA) pdo->DeviceExtension;
00108     pdoData->AcpiHandle = Device->handle;
00109 
00110     //
00111     // Copy the hardware IDs
00112     //
00113         index = 0;
00114         index += swprintf(&temp[index],
00115                             L"ACPI\\%hs",
00116                             Device->pnp.hardware_id);
00117         index++;
00118 
00119         index += swprintf(&temp[index],
00120                             L"*%hs",
00121                             Device->pnp.hardware_id);
00122         index++;
00123         temp[++index] = UNICODE_NULL;
00124 
00125         pdoData->HardwareIDs  = ExAllocatePoolWithTag(NonPagedPool, index*sizeof(WCHAR), 'IPCA');
00126 
00127 
00128     if (!pdoData->HardwareIDs) {
00129         IoDeleteDevice(pdo);
00130         return STATUS_INSUFFICIENT_RESOURCES;
00131     }
00132 
00133     RtlCopyMemory (pdoData->HardwareIDs, temp, index*sizeof(WCHAR));
00134     Bus_InitializePdo (pdo, FdoData);
00135 
00136     //
00137     // Device Relation changes if a new pdo is created. So let
00138     // the PNP system now about that. This forces it to send bunch of pnp
00139     // queries and cause the function driver to be loaded.
00140     //
00141 
00142     //IoInvalidateDeviceRelations (FdoData->UnderlyingPDO, BusRelations);
00143 
00144     return status;
00145 }
00146 
00147 
00148 /* looks alot like acpi_bus_walk doesnt it */
00149 NTSTATUS
00150 ACPIEnumerateDevices(PFDO_DEVICE_DATA DeviceExtension)
00151 {
00152     ULONG Count = 0;
00153     struct acpi_device *Device = acpi_root;
00154 
00155     while(Device)
00156     {
00157         if (Device->status.present && Device->status.enabled &&
00158             Device->flags.hardware_id)
00159         {
00160             Bus_PlugInDevice(Device, DeviceExtension);
00161             Count++;
00162         }
00163 
00164         if (HAS_CHILDREN(Device)) {
00165             Device = NODE_TO_DEVICE(Device->children.next);
00166             continue;
00167         }
00168         if (HAS_SIBLINGS(Device)) {
00169             Device = NODE_TO_DEVICE(Device->node.next);
00170             continue;
00171         }
00172         while ((Device = Device->parent)) {
00173             if (HAS_SIBLINGS(Device)) {
00174                 Device = NODE_TO_DEVICE(Device->node.next);
00175                 break;
00176             }
00177         }
00178     }
00179     DPRINT("acpi device count: %d\n", Count);
00180     return STATUS_SUCCESS;
00181 }
00182 
00183 /* EOF */

Generated on Sun May 27 2012 04:27:24 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.