Windows System Software -- Consulting, Training, Development -- Unique Expertise, Guaranteed Results

Home NTDEV

Before Posting...

Please check out the Community Guidelines in the Announcements and Administration Category.

More Info on Driver Writing and Debugging


The free OSR Learning Library has more than 50 articles on a wide variety of topics about writing and debugging device drivers and Minifilters. From introductory level to advanced. All the articles have been recently reviewed and updated, and are written using the clear and definitive style you've come to expect from OSR over the years.


Check out The OSR Learning Library at: https://www.osr.com/osr-learning-library/


Windows 7 - How to read and write using doorbell interface register

PKPK Member Posts: 16
Hello,
I want to use the doorbell interface to read and write from the chip.
For this the Linux driver has a call
/* make sure doorbell is not in use */
if ((readl(&chip->Doorbell) & DOORBELL_USED))

What is the Windows equivalent of the readl() function call?

Thanks

Comments

  • Tim_RobertsTim_Roberts Member - All Emails Posts: 14,299
    [email protected] wrote:
    > I want to use the doorbell interface to read and write from the chip.
    > For this the Linux driver has a call
    > /* make sure doorbell is not in use */
    > if ((readl(&chip->Doorbell) & DOORBELL_USED))
    >
    > What is the Windows equivalent of the readl() function call?

    A few seconds with Google would have answered this question.  "readl"
    reads a 32-bit value from a memory-mapped register.  The statement above
    is essentially equivament to
        if( *chip->Doorbell & DOORBELL_USED)

    The Windows equivalent is READ_REGISTER_ULONG.

    Note that you'll still have to map the registers into memory so you have
    the board's address to begin with.

    --
    Tim Roberts, [email protected]
    Providenza & Boekelheide, Inc.

    Tim Roberts, [email protected]
    Providenza & Boekelheide, Inc.

  • PKPK Member Posts: 16
    Thanks for your response. I am unclear about a lot of things in the problem I am trying to solve and hence asked the question. From your response, I am kind of confused about how to deal with problem of memory mapping.
    In my storport miniport driver, I am able to get the base address register using StorPortGetDeviceBase(). This address is set to point to a buffer that is of size and type of the chip's interface register structure.
    For e.g:
    typedef interface_t
    {
    u32 doorbell;
    U32 WriteSequence;
    U32 HostDiagnostic;
    .....
    ......
    }SystemInterfaceRegs_t;

    SystemInterfaceRegs_t registerBase;

    registerBase = (SystemInterfaceRegs_t )StorPortGetDeviceBase(....); With last parameter = False indicating that the mapped range is in memory space.

    Now, I want to read registerBase.doorBell which I believe is already memory mapped.

    Is the implementation I listed above correct ?
    Where should I be calling in the MmMapIoSpace() call here?

    Thanks.
  • Mark_RoddyMark_Roddy Member - All Emails Posts: 4,526
    You don't call MmMapIoSpace.

    StorPortGetDeviceBase returns: "A mapped, logical base address
    corresponding to the bus-relative address supplied in the IoAddress
    parameter.". You can then use that returned value directly in a call to
    the StorPortReadRegister* routines.

    See the sample driver at

    https://github.com/Microsoft/Windows-driver-samples/blob/aa6e0b36eb932099fa4eb950a6f5e289a23b6d6e/storage/miniports/lsi_u3/src/lsi_u3.c

    Mark Roddy

    On Wed, Feb 7, 2018 at 4:24 PM, [email protected]
    wrote:

    > Thanks for your response. I am unclear about a lot of things in the
    > problem I am trying to solve and hence asked the question. From your
    > response, I am kind of confused about how to deal with problem of memory
    > mapping.
    > In my storport miniport driver, I am able to get the base address register
    > using StorPortGetDeviceBase(). This address is set to point to a buffer
    > that is of size and type of the chip's interface register structure.
    > For e.g:
    > typedef interface_t
    > {
    > u32 doorbell;
    > U32 WriteSequence;
    > U32 HostDiagnostic;
    > .....
    > ......
    > }SystemInterfaceRegs_t;
    >
    > SystemInterfaceRegs_t registerBase;
    >
    > registerBase = (SystemInterfaceRegs_t )StorPortGetDeviceBase(....); With
    > last parameter = False indicating that the mapped range is in memory space.
    >
    > Now, I want to read registerBase.doorBell which I believe is already
    > memory mapped.
    >
    > Is the implementation I listed above correct ?
    > Where should I be calling in the MmMapIoSpace() call here?
    >
    > Thanks.
    >
    >
    >
    >
    >
    >
    >
    > ---
    > NTDEV is sponsored by OSR
    >
    > Visit the list online at: showlists.cfm?list=ntdev>
    >
    > MONTHLY seminars on crash dump analysis, WDF, Windows internals and
    > software drivers!
    > Details at
    >
    > To unsubscribe, visit the List Server section of OSR Online at <
    > http://www.osronline.com/page.cfm?name=ListServer&gt;
    >
  • PKPK Member Posts: 16
    Thanks. I will use StorPortReadRegister* with DeviceExtension and register as registerBase.doorBell
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. Sign in or register to get started.

Upcoming OSR Seminars
OSR has suspended in-person seminars due to the Covid-19 outbreak. But, don't miss your training! Attend via the internet instead!
Internals & Software Drivers 7 February 2022 Live, Online
Kernel Debugging 21 March 2022 Live, Online
Developing Minifilters 23 May 2022 Live, Online
Writing WDF Drivers 12 September 2022 Live, Online