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/


HalAllocateCommonBuffer

OSR_Community_UserOSR_Community_User Member Posts: 110,217
We have developed a kernel mode driver to control the boards that have also developed by our company. The board is an audio switch matrix that uses the ISA bus. It is also able to use DMA transfers by using the hardware of a computer. The DMA transfers are used to generate and save audio in real time by using the driver that we designed following the CommonBuffer Slave DMA model.

We use the following parameters to call HalGetAdapter:

DmaDescription.Version = DEVICE_DESCRIPTION_VERSION1;
DmaDescription.Master = FALSE;
DmaDescription.ScatterGather = FALSE;
DmaDescription.DemandMode = TRUE;
DmaDescription.AutoInitialize = TRUE;
DmaDescription.IgnoreCount = FALSE;
DmaDescription.Dma32BitAddresses = FALSE;
DmaDescription.InterfaceType = Isa;
DmaDescription.BusNumber = 0;
DmaDescription.DmaChannel = 0, 1, 6 or 7;
DmaDescription.MaximumLength = CommonBufferSize;
DmaDescription.DmaWidth = Width8Bits or Width16Bits;
DmaDescription.DmaSpeed = MaximumDmaSpeed;

AdapterObject = HalGetAdapter(&DmaDescription, &MaxMapRegisterCount);

Where CommonBuffersize is one of 32, 64 or 128KB.

In order to obtain the necessary memory buffers for the continuous transfer and after obtaining the Adapter Object, we use the HalAllocateCommonBuffer as follows:

DMACommonBuffer = HalAllocateCommonBuffer(AdapterObject, CommonBufferSize, &DMAPA, TRUE or FALSE);

It is there where we find the problems. Although all functions are executed when the driver initialites (in DriverEntry), HalAllocateCommonBuffer always fails for 64KB or 128KB buffers. It also fails for 32 KB buffers in several cases.

This is a big problem for us since our system is supposed to support 2 boards by using DMA simultaneously in different channels. We are now

Comments

  • OSR_Community_UserOSR_Community_User Member Posts: 110,217
    Try setting DmaDescription.MaximumLength to a number larger than
    CommonBufferSize, such as the largest POSSIBLE DMA transfer size. Note that
    SCSI drivers set this to something like 0xFFFFFFF.

    By defining your max length to the same size as your common buffer, you
    immediately run out of resources (map registers) as soon as you allocate a
    buffer. The value you set in MaximumLength gives you the TOTAL number of map
    registers available for ALL DMA transfers on that device. Setting it to
    something like 4Meg gives you 1025 map registers. If CommonBuffersSize is
    128K, then you would need 33 map registers to satisfy that request, leaving
    you resources available for starting another DMA transfer.

    -----Original Message-----
    From: Juli?n Rodr?guez Bajo [mailto:[email protected]]
    Sent: Friday, June 09, 2000 3:19 AM
    To: NT Developers Interest List
    Subject: [ntdev] HalAllocateCommonBuffer

    We have developed a kernel mode driver to control the boards
    that have also developed by our company. The board is an audio switch
    matrix that uses the ISA bus. It is also able to use DMA transfers by using
    the hardware of a computer. The DMA transfers are used to generate and save
    audio in real time by using the driver that we designed following the
    CommonBuffer Slave DMA model.

    We use the following parameters to call HalGetAdapter:

    DmaDescription.Version =
    DEVICE_DESCRIPTION_VERSION1;
    DmaDescription.Master =
    FALSE;
    DmaDescription.ScatterGather =
    FALSE;
    DmaDescription.DemandMode =
    TRUE;
    DmaDescription.AutoInitialize
    = TRUE;
    DmaDescription.IgnoreCount =
    FALSE;
    DmaDescription.Dma32BitAddresses =
    FALSE;
    DmaDescription.InterfaceType =
    Isa;
    DmaDescription.BusNumber = 0;
    DmaDescription.DmaChannel = 0,
    1, 6 or 7;
    DmaDescription.MaximumLength =
    CommonBufferSize;
    DmaDescription.DmaWidth =
    Width8Bits or Width16Bits;
    DmaDescription.DmaSpeed =
    MaximumDmaSpeed;

    AdapterObject = HalGetAdapter(&DmaDescription,
    &MaxMapRegisterCount);

    Where CommonBuffersize is one of 32, 64 or 128KB.

    In order to obtain the necessary memory buffers for the
    continuous transfer and after obtaining the Adapter Object, we use the
    HalAllocateCommonBuffer as follows:

    DMACommonBuffer =
    HalAllocateCommonBuffer(AdapterObject, CommonBufferSize, &DMAPA, TRUE or
    FALSE);

    It is there where we find the problems. Although all
    functions are executed when the driver initialites (in DriverEntry),
    HalAllocateCommonBuffer always fails for 64KB or 128KB buffers. It also
    fails for 32 KB buffers in several cases.

    This is a big problem for us since our system is supposed to
    support 2 boards by using DMA simultaneously in different channels. We are
    now

    ---
    You are currently subscribed to ntdev as:
    [email protected]
    To unsubscribe send a blank email to
    $subst('Email.Unsub')
  • OSR_Community_UserOSR_Community_User Member Posts: 110,217
    > Try setting DmaDescription.MaximumLength to a number larger than
    > CommonBufferSize, such as the largest POSSIBLE DMA transfer size. Note
    that
    > SCSI drivers set this to something like 0xFFFFFFF.
    >
    > By defining your max length to the same size as your common buffer, you
    > immediately run out of resources (map registers) as soon as you allocate a
    > buffer. The value you set in MaximumLength gives you the TOTAL number
    > of map registers available for ALL DMA transfers on that device. Setting
    it to
    > something like 4Meg gives you 1025 map registers. If CommonBuffersSize is
    > 128K, then you would need 33 map registers to satisfy that request,
    leaving
    > you resources available for starting another DMA transfer.


    I try this, but no success.

    I find that HalGetAdapter allways returns 16 in MaxMapRegisters param,
    either
    I use 128K, 1MB, 2MB or any value in DmaDescription.MaximumLength.

    Thanks for your reply.
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!
Kernel Debugging 13-17 May 2024 Live, Online
Developing Minifilters 1-5 Apr 2024 Live, Online
Internals & Software Drivers 11-15 Mar 2024 Live, Online
Writing WDF Drivers 26 Feb - 1 Mar 2024 Live, Online