none
Memory mapping Port resources in prepare hardware RRS feed

  • Question

  • In PrepareHardware Function

    case CmResourceTypePort: {

          Kdprint("Resource %u: Port 0x%0x, Length %u.\n",i, partialResourceDesc->u.Port.Start.LowPart, partialResourceDesc->u.Port.Length);

           devContext->BaseAddress =(PUCHAR)UlongToPtr(partialResourceDesc->u.Port.Start.LowPart);// Port mapping I/O

    devContext->BaseAddress = ( PUCHAR)MmMapIoSpace(partialResourceDesc->u.Port.Start.LowPart,

    partialResourceDesc->u.Port.Length,

    MmNonCached);//Memory mapping I/O 

    }

    Is it legal to memory map the "CmResourceTypePort" resources assigned to device by BIOS.


    vidyasagar196

    Friday, November 13, 2015 9:50 AM

Answers

  • To expand on my post above.  If the CmResourceTypePort does not have a CM_RESOURCE_PORT_MEMORY flag then it should not be mapped at all.  Just use the WRITE_PORT_XXX and READ_PORT_XXX calls with the port number.  Many developers do not check the flag and just use the port, but over the years there have been systems such as Itanium and even some X86 based systems that made the ports memory, and required mapping.   To be completely safe you should check the flags, but you will find a lot of driver examples that do not.


    Don Burn Windows Driver Consulting Website: http://www.windrvr.com

    Friday, November 13, 2015 1:26 PM

All replies

  • A Windows driver does not know what was assigned by the BIOS. Windows passes it the resources in START_DEVICE. This is what it should use.

    -- pa

    Friday, November 13, 2015 10:48 AM
  • ok., Then what about memory mapping those resources which we get from START_DEVICE(as you said)...?

    vidyasagar196

    Friday, November 13, 2015 11:43 AM
  • If you take a look at https://msdn.microsoft.com/en-us/library/windows/hardware/ff541977(v=vs.85).aspxyou will see that there are flags CM_RESOURCE_PORT_MEMORY and CM_RESOURCE_PORT_IO that indicates whether the port is in memory or I/O space.  You should be checking that and only mapping the resource if this flag indicates it is in memory. 


    Don Burn Windows Driver Consulting Website: http://www.windrvr.com

    Friday, November 13, 2015 12:08 PM
  • To expand on my post above.  If the CmResourceTypePort does not have a CM_RESOURCE_PORT_MEMORY flag then it should not be mapped at all.  Just use the WRITE_PORT_XXX and READ_PORT_XXX calls with the port number.  Many developers do not check the flag and just use the port, but over the years there have been systems such as Itanium and even some X86 based systems that made the ports memory, and required mapping.   To be completely safe you should check the flags, but you will find a lot of driver examples that do not.


    Don Burn Windows Driver Consulting Website: http://www.windrvr.com

    Friday, November 13, 2015 1:26 PM
  • Thanks Don.,


    vidyasagar196

    Friday, November 13, 2015 1:31 PM
  • Thanks Don

    vidyasagar196

    Friday, November 13, 2015 1:36 PM