A Straightforward Example

The following pseudocode is a device_attach routine for a fictitious device that requires DMA. This pseudocode should demonstrate how to use bus_dmamem_alloc.

static int foo_attach(device_t dev) { struct foo_softc *sc = device_get_softc(dev); int size = BAZ_SIZE; int error; bzero(sc, sizeof(*sc)); if (bus_dma_tag_create(bus_get_dma_tag(dev), /* parent */ 1, /* alignment */ 0, /* boundary */ BUS_SPACE_MAXADDR, /* lowaddr */ BUS_SPACE_MAXADDR, /* highaddr */ NULL, /* filter */ NULL, /* filterarg */ BUS_SPACE_MAXSIZE_32BIT, /* maxsize */ BUS_SPACE_UNRESTRICTED, /* nsegments */ BUS_SPACE_MAXSIZE_32BIT, /* maxsegsize */ 0, /* flags */ NULL, /* lockfunc */ NULL, /* lockfuncarg */ &sc->foo_parent_dma_tag)) { device_printf(dev, ...

Get FreeBSD Device Drivers now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.