win-pvdrivers

changeset 486:efb43e8b47ec

new config method
author James Harper <james.harper@bendigoit.com.au>
date Mon Dec 08 23:32:47 2008 +1100 (2008-12-08)
parents 0c0efefd40f4
children 8a0a695cdd97
files xenpci/evtchn.c xenpci/xenpci.c xenpci/xenpci.h xenpci/xenpci_pdo.c
line diff
     1.1 --- a/xenpci/evtchn.c	Sun Dec 07 11:51:12 2008 +1100
     1.2 +++ b/xenpci/evtchn.c	Mon Dec 08 23:32:47 2008 +1100
     1.3 @@ -134,17 +134,20 @@ to CPU != 0, but we should always use vc
     1.4        switch (ev_action->type)
     1.5        {
     1.6        case EVT_ACTION_TYPE_NORMAL:
     1.7 +        //KdPrint((__DRIVER_NAME "     EVT_ACTION_TYPE_NORMAL\n"));
     1.8          ev_action->ServiceRoutine(NULL, ev_action->ServiceContext);
     1.9          break;
    1.10        case EVT_ACTION_TYPE_IRQ:
    1.11 +        //KdPrint((__DRIVER_NAME "     EVT_ACTION_TYPE_IRQ\n"));
    1.12          synch_set_bit(evt_bit, (volatile xen_long_t *)&xpdd->evtchn_pending_pvt[evt_word]);
    1.13          deferred = TRUE;
    1.14          break;
    1.15        case EVT_ACTION_TYPE_DPC:
    1.16 +        //KdPrint((__DRIVER_NAME "     EVT_ACTION_TYPE_DPC\n"));
    1.17          KeInsertQueueDpc(&ev_action->Dpc, NULL, NULL);
    1.18          break;
    1.19        case EVT_ACTION_TYPE_SUSPEND:
    1.20 -        KdPrint((__DRIVER_NAME "     EVT_ACTION_TYPE_SUSPEND\n"));
    1.21 +        //KdPrint((__DRIVER_NAME "     EVT_ACTION_TYPE_SUSPEND\n"));
    1.22          for (i = 0; i < ARRAY_SIZE(xpdd->evtchn_pending_pvt); i++)
    1.23          {
    1.24            if (xpdd->ev_actions[i].type == EVT_ACTION_TYPE_IRQ)
     2.1 --- a/xenpci/xenpci.c	Sun Dec 07 11:51:12 2008 +1100
     2.2 +++ b/xenpci/xenpci.c	Mon Dec 08 23:32:47 2008 +1100
     2.3 @@ -224,6 +224,8 @@ XenPci_AddDevice(PDRIVER_OBJECT DriverOb
     2.4    return status;
     2.5  }
     2.6  
     2.7 +DECLARE_UNICODE_STRING_SIZE(service_path, 512);
     2.8 +
     2.9  NTSTATUS DDKAPI
    2.10  DriverEntry(PDRIVER_OBJECT DriverObject, PUNICODE_STRING RegistryPath)
    2.11  {
    2.12 @@ -235,6 +237,8 @@ DriverEntry(PDRIVER_OBJECT DriverObject,
    2.13  
    2.14    //InitializeListHead(&ShutdownMsgList);
    2.15    //KeInitializeSpinLock(&ShutdownMsgLock);
    2.16 +  
    2.17 +  RtlUnicodeStringCopy(&service_path, RegistryPath);
    2.18  
    2.19    DriverObject->DriverExtension->AddDevice = XenPci_AddDevice;
    2.20    DriverObject->MajorFunction[IRP_MJ_PNP] = XenPci_Pnp;
     3.1 --- a/xenpci/xenpci.h	Sun Dec 07 11:51:12 2008 +1100
     3.2 +++ b/xenpci/xenpci.h	Mon Dec 08 23:32:47 2008 +1100
     3.3 @@ -68,6 +68,8 @@ DEFINE_GUID( GUID_XENPCI_DEVCLASS, 0xC82
     3.4  #define EVT_ACTION_TYPE_IRQ     3
     3.5  #define EVT_ACTION_TYPE_SUSPEND 4
     3.6  
     3.7 +extern UNICODE_STRING service_path;
     3.8 +
     3.9  typedef struct _ev_action_t {
    3.10    PKSERVICE_ROUTINE ServiceRoutine;
    3.11    PVOID ServiceContext;
    3.12 @@ -245,7 +247,7 @@ typedef struct {
    3.13    ULONG shutdown_cons;
    3.14    ULONG shutdown_start; /* the start of the most recent message on the ring */
    3.15    PIRP shutdown_irp;
    3.16 -  
    3.17 +
    3.18    BOOLEAN log_interrupts;
    3.19  } XENPCI_DEVICE_DATA, *PXENPCI_DEVICE_DATA;
    3.20  
     4.1 --- a/xenpci/xenpci_pdo.c	Sun Dec 07 11:51:12 2008 +1100
     4.2 +++ b/xenpci/xenpci_pdo.c	Mon Dec 08 23:32:47 2008 +1100
     4.3 @@ -974,16 +974,32 @@ XenConfig_MakeConfigPage(PDEVICE_OBJECT 
     4.4    ANSI_STRING value;
     4.5    PUCHAR ptr;
     4.6    int i;
     4.7 -
     4.8 +  DECLARE_UNICODE_STRING_SIZE(service_path_xenconfig, 512);
     4.9 +  PDRIVER_OBJECT fdo_driver_object;
    4.10 +  PUCHAR fdo_driver_extension;
    4.11 +  
    4.12    mdl = AllocateUncachedPage();
    4.13    ptr = MmGetMdlVirtualAddress(mdl);
    4.14  
    4.15 +  fdo_driver_object = IoGetAttachedDeviceReference(device_object)->DriverObject;
    4.16 +  KdPrint((__DRIVER_NAME "     fdo_driver_object = %p\n", fdo_driver_object));
    4.17 +  if (fdo_driver_object)
    4.18 +  {
    4.19 +    fdo_driver_extension = IoGetDriverObjectExtension(fdo_driver_object, UlongToPtr(XEN_INIT_DRIVER_EXTENSION_MAGIC));
    4.20 +    KdPrint((__DRIVER_NAME "     fdo_driver_extension = %p\n", fdo_driver_extension));
    4.21 +    if (fdo_driver_extension)
    4.22 +    {
    4.23 +      memcpy(ptr, fdo_driver_extension, PAGE_SIZE);
    4.24 +      return mdl;
    4.25 +    }
    4.26 +  }
    4.27 +
    4.28    status = IoOpenDeviceRegistryKey(device_object, PLUGPLAY_REGKEY_DEVICE, KEY_READ, &hwkey_handle);
    4.29  
    4.30    if (!NT_SUCCESS(status))
    4.31    {
    4.32 -    KdPrint((__DRIVER_NAME "    cannot get hardware key\n"));
    4.33 -    ADD_XEN_INIT_REQ(&ptr, XEN_INIT_TYPE_END, NULL, NULL);          
    4.34 +    KdPrint((__DRIVER_NAME "     cannot get device key\n"));
    4.35 +    ADD_XEN_INIT_REQ(&ptr, XEN_INIT_TYPE_END, NULL, NULL);
    4.36      return mdl;
    4.37    }
    4.38    RtlInitUnicodeString(&xenkey_name, L"XenConfig");
    4.39 @@ -991,10 +1007,39 @@ XenConfig_MakeConfigPage(PDEVICE_OBJECT 
    4.40    status = ZwOpenKey(&xenkey_handle, KEY_READ, &oa);
    4.41    if (!NT_SUCCESS(status))
    4.42    {
    4.43 -    // close key_handle
    4.44 -    KdPrint((__DRIVER_NAME "    cannot get XenConfig key\n"));
    4.45 -    ADD_XEN_INIT_REQ(&ptr, XEN_INIT_TYPE_END, NULL, NULL);          
    4.46 -    return mdl;
    4.47 +    KdPrint((__DRIVER_NAME "     cannot get XenConfig key for device\n"));
    4.48 +    fdo_driver_object = IoGetAttachedDeviceReference(device_object)->DriverObject;
    4.49 +    KdPrint((__DRIVER_NAME "     fdo_driver_object = %p\n", fdo_driver_object));
    4.50 +    fdo_driver_extension = IoGetDriverObjectExtension(fdo_driver_object, UlongToPtr(666));
    4.51 +    KdPrint((__DRIVER_NAME "     fdo_driver_extension = %p\n", fdo_driver_extension));
    4.52 +    KdPrint((__DRIVER_NAME "     fdo_driver_extension = %s\n", fdo_driver_extension));
    4.53 +#if 0
    4.54 +    RtlUnicodeStringPrintf(&service_path_xenconfig, L"%wZ\\XenConfig", &service_path);
    4.55 +    KdPrint((__DRIVER_NAME "     %wZ\n", &service_path_xenconfig));
    4.56 +    InitializeObjectAttributes(&oa, &service_path_xenconfig, 0, NULL, NULL);
    4.57 +#endif
    4.58 +    
    4.59 +    KdPrint((__DRIVER_NAME "     %wZ\n", &service_path));
    4.60 +    InitializeObjectAttributes(&oa, &service_path, 0, NULL, NULL);
    4.61 +    status = ZwOpenKey(&xenkey_handle, KEY_READ, &oa);
    4.62 +    if (!NT_SUCCESS(status))
    4.63 +    {
    4.64 +      // close key_handle
    4.65 +      KdPrint((__DRIVER_NAME "    cannot get XenConfig for service (%08x)\n"));
    4.66 +      ADD_XEN_INIT_REQ(&ptr, XEN_INIT_TYPE_END, NULL, NULL);
    4.67 +      return mdl;
    4.68 +    }
    4.69 +/*
    4.70 +    RtlInitUnicodeString(&xenkey_name, L"XenConfig");
    4.71 +    InitializeObjectAttributes(&oa, &xenkey_name, 0, service_handle, NULL);
    4.72 +    status = ZwOpenKey(&xenkey_handle, KEY_READ, &oa);
    4.73 +    if (!NT_SUCCESS(status))
    4.74 +    {    
    4.75 +      KdPrint((__DRIVER_NAME "    cannot get XenConfig key for driver\n"));
    4.76 +      ADD_XEN_INIT_REQ(&ptr, XEN_INIT_TYPE_END, NULL, NULL);          
    4.77 +      return mdl;
    4.78 +    }
    4.79 +*/
    4.80    }
    4.81    // XenConfig key exists, so we go ahead and make fake memory resources
    4.82    RtlInitUnicodeString(&type_name, L"type");