Fwd: Removing Giant from a driver

John-Mark Gurney gurney_j at resnet.uoregon.edu
Fri Oct 20 14:37:25 PDT 2006

usleepless at gmail.com wrote this message on Sun, Oct 15, 2006 at 11:04 +0200:
> i have been tweaking the pvr250 driver to support pvr150s/500s. now i
> want to remove Giant from the code.
> problem is, i am not sure what to do. i have created a mutex which
> replaces the spltty and splx calls. but this crashes my box :-)
> the original code looks like this:
>        /*
>         * Allocate a DMA tag for the scatter / gather list.
>         */
>        error = bus_dma_tag_create(sc->parent_dmat, 1, 0,
>                                   BUS_SPACE_MAXADDR_32BIT,
>                                   BUS_SPACE_MAXADDR, NULL, NULL,
>                                   CXM_SG_BUFFERS
>                                   * sizeof(struct cxm_sg_entry), 1,
>                                   BUS_SPACE_MAXSIZE_32BIT, 0,
> #if __FreeBSD_version >= 501102
>                                   busdma_lock_mutex, &Giant,
> #endif
>                                   &sc->enc_sg.dmat);
> what should it look like?

You should be creating a mutex (using mtx_init) at attach time, and
pass that mutex instead of Giant...

> and how will i prevent the interrupt routine from interfering with
> userland operations? can i place a "mtx_lock()" call in the interrupt
> routine?

Correct....  Fast interrupt handlers cannot use a sleeping mutex, but
I doubt this driver is using a fast interrupt handler...

> is there a howto somewhere?

There are man pages on how to use the various locking primitives, but
it is assumed that you have knowlege of concurrent programming...  You
can take a look at books on pthreads and other related matierals for
info on using locks...

If you figure out the licensing issues w/ the firmware, I'll import
the driver into FreeBSD...

  John-Mark Gurney				Voice: +1 415 225 5579

     "All that I will do, has been done, All that I have, has not."

More information about the freebsd-hackers mailing list