malloc(9) -> kmem(9)
This commit is contained in:
parent
e05111c27e
commit
32841112b8
|
@ -1,4 +1,4 @@
|
||||||
/* $NetBSD: isa_dma.c,v 1.12 2016/02/26 18:16:51 christos Exp $ */
|
/* $NetBSD: isa_dma.c,v 1.13 2021/01/04 18:23:10 thorpej Exp $ */
|
||||||
|
|
||||||
#define ISA_DMA_STATS
|
#define ISA_DMA_STATS
|
||||||
|
|
||||||
|
@ -33,14 +33,14 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <sys/cdefs.h>
|
#include <sys/cdefs.h>
|
||||||
__KERNEL_RCSID(0, "$NetBSD: isa_dma.c,v 1.12 2016/02/26 18:16:51 christos Exp $");
|
__KERNEL_RCSID(0, "$NetBSD: isa_dma.c,v 1.13 2021/01/04 18:23:10 thorpej Exp $");
|
||||||
|
|
||||||
#include <sys/param.h>
|
#include <sys/param.h>
|
||||||
#include <sys/systm.h>
|
#include <sys/systm.h>
|
||||||
#include <sys/kernel.h>
|
#include <sys/kernel.h>
|
||||||
#include <sys/syslog.h>
|
#include <sys/syslog.h>
|
||||||
#include <sys/device.h>
|
#include <sys/device.h>
|
||||||
#include <sys/malloc.h>
|
#include <sys/kmem.h>
|
||||||
#include <sys/proc.h>
|
#include <sys/proc.h>
|
||||||
#include <sys/mbuf.h>
|
#include <sys/mbuf.h>
|
||||||
|
|
||||||
|
@ -150,28 +150,11 @@ u_long isa_dma_stats_nbouncebufs;
|
||||||
#define STAT_DECR(v)
|
#define STAT_DECR(v)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*
|
static int
|
||||||
* Create an ISA DMA map.
|
isadma_bounce_cookieflags(bus_dma_tag_t const t, bus_dmamap_t const map,
|
||||||
*/
|
int const flags)
|
||||||
int
|
|
||||||
_isa_bus_dmamap_create(bus_dma_tag_t t, bus_size_t size, int nsegments, bus_size_t maxsegsz, bus_size_t boundary, int flags, bus_dmamap_t *dmamp)
|
|
||||||
{
|
{
|
||||||
struct atari_isa_dma_cookie *cookie;
|
int cookieflags = 0;
|
||||||
bus_dmamap_t map;
|
|
||||||
int error, cookieflags;
|
|
||||||
void *cookiestore;
|
|
||||||
size_t cookiesize;
|
|
||||||
|
|
||||||
/* Call common function to create the basic map. */
|
|
||||||
error = _bus_dmamap_create(t, size, nsegments, maxsegsz, boundary,
|
|
||||||
flags, dmamp);
|
|
||||||
if (error)
|
|
||||||
return (error);
|
|
||||||
|
|
||||||
map = *dmamp;
|
|
||||||
map->_dm_cookie = NULL;
|
|
||||||
|
|
||||||
cookiesize = sizeof(struct atari_isa_dma_cookie);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* ISA only has 24-bits of address space. This means
|
* ISA only has 24-bits of address space. This means
|
||||||
|
@ -200,41 +183,94 @@ _isa_bus_dmamap_create(bus_dma_tag_t t, bus_size_t size, int nsegments, bus_size
|
||||||
/* Bouncing not necessary due to memory size. */
|
/* Bouncing not necessary due to memory size. */
|
||||||
map->_dm_bounce_thresh = 0;
|
map->_dm_bounce_thresh = 0;
|
||||||
}
|
}
|
||||||
cookieflags = 0;
|
|
||||||
if (map->_dm_bounce_thresh != 0 ||
|
if (map->_dm_bounce_thresh != 0 ||
|
||||||
((map->_dm_size / PAGE_SIZE) + 1) > map->_dm_segcnt) {
|
((map->_dm_size / PAGE_SIZE) + 1) > map->_dm_segcnt) {
|
||||||
cookieflags |= ID_MIGHT_NEED_BOUNCE;
|
cookieflags |= ID_MIGHT_NEED_BOUNCE;
|
||||||
|
}
|
||||||
|
return cookieflags;
|
||||||
|
}
|
||||||
|
|
||||||
|
static size_t
|
||||||
|
isadma_bounce_cookiesize(bus_dmamap_t const map, int cookieflags)
|
||||||
|
{
|
||||||
|
size_t cookiesize = sizeof(struct atari_isa_dma_cookie);
|
||||||
|
|
||||||
|
if (cookieflags & ID_MIGHT_NEED_BOUNCE) {
|
||||||
cookiesize += (sizeof(bus_dma_segment_t) * map->_dm_segcnt);
|
cookiesize += (sizeof(bus_dma_segment_t) * map->_dm_segcnt);
|
||||||
}
|
}
|
||||||
|
return cookiesize;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
isadma_bounce_cookie_alloc(bus_dma_tag_t const t, bus_dmamap_t const map,
|
||||||
|
int const flags)
|
||||||
|
{
|
||||||
|
struct atari_isa_dma_cookie *cookie;
|
||||||
|
int cookieflags = isadma_bounce_cookieflags(t, map, flags);
|
||||||
|
|
||||||
|
if ((cookie = kmem_zalloc(isadma_bounce_cookiesize(map, cookieflags),
|
||||||
|
(flags & BUS_DMA_NOWAIT) ? KM_NOSLEEP : KM_SLEEP)) == NULL) {
|
||||||
|
return ENOMEM;
|
||||||
|
}
|
||||||
|
|
||||||
|
cookie->id_flags = cookieflags;
|
||||||
|
map->_dm_cookie = cookie;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
isadma_bounce_cookie_free(bus_dmamap_t const map)
|
||||||
|
{
|
||||||
|
struct atari_isa_dma_cookie *cookie = map->_dm_cookie;
|
||||||
|
|
||||||
|
if (cookie != NULL) {
|
||||||
|
kmem_free(map->_dm_cookie,
|
||||||
|
isadma_bounce_cookiesize(map, cookie->id_flags));
|
||||||
|
map->_dm_cookie = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Create an ISA DMA map.
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
_isa_bus_dmamap_create(bus_dma_tag_t t, bus_size_t size, int nsegments, bus_size_t maxsegsz, bus_size_t boundary, int flags, bus_dmamap_t *dmamp)
|
||||||
|
{
|
||||||
|
struct atari_isa_dma_cookie *cookie;
|
||||||
|
bus_dmamap_t map;
|
||||||
|
int error;
|
||||||
|
|
||||||
|
/* Call common function to create the basic map. */
|
||||||
|
error = _bus_dmamap_create(t, size, nsegments, maxsegsz, boundary,
|
||||||
|
flags, dmamp);
|
||||||
|
if (error)
|
||||||
|
return (error);
|
||||||
|
|
||||||
|
map = *dmamp;
|
||||||
|
map->_dm_cookie = NULL;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Allocate our cookie.
|
* Allocate our cookie.
|
||||||
*/
|
*/
|
||||||
if ((cookiestore = malloc(cookiesize, M_DMAMAP,
|
if ((error = isadma_bounce_cookie_alloc(t, map, flags)) != 0) {
|
||||||
(flags & BUS_DMA_NOWAIT) ? M_NOWAIT : M_WAITOK)) == NULL) {
|
|
||||||
error = ENOMEM;
|
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
memset(cookiestore, 0, cookiesize);
|
cookie = map->_dm_cookie;
|
||||||
cookie = (struct atari_isa_dma_cookie *)cookiestore;
|
|
||||||
cookie->id_flags = cookieflags;
|
|
||||||
map->_dm_cookie = cookie;
|
|
||||||
|
|
||||||
if (cookieflags & ID_MIGHT_NEED_BOUNCE) {
|
if (cookie->id_flags & ID_MIGHT_NEED_BOUNCE) {
|
||||||
/*
|
/*
|
||||||
* Allocate the bounce pages now if the caller
|
* Allocate the bounce pages now if the caller
|
||||||
* wishes us to do so.
|
* wishes us to do so.
|
||||||
*/
|
*/
|
||||||
if ((flags & BUS_DMA_ALLOCNOW) == 0)
|
if (flags & BUS_DMA_ALLOCNOW) {
|
||||||
goto out;
|
|
||||||
|
|
||||||
error = _isa_dma_alloc_bouncebuf(t, map, size, flags);
|
error = _isa_dma_alloc_bouncebuf(t, map, size, flags);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
out:
|
out:
|
||||||
if (error) {
|
if (error) {
|
||||||
if (map->_dm_cookie != NULL)
|
isadma_bounce_cookie_free(map);
|
||||||
free(map->_dm_cookie, M_DMAMAP);
|
|
||||||
_bus_dmamap_destroy(t, map);
|
_bus_dmamap_destroy(t, map);
|
||||||
}
|
}
|
||||||
return (error);
|
return (error);
|
||||||
|
@ -254,7 +290,7 @@ _isa_bus_dmamap_destroy(bus_dma_tag_t t, bus_dmamap_t map)
|
||||||
if (cookie->id_flags & ID_HAS_BOUNCE)
|
if (cookie->id_flags & ID_HAS_BOUNCE)
|
||||||
_isa_dma_free_bouncebuf(t, map);
|
_isa_dma_free_bouncebuf(t, map);
|
||||||
|
|
||||||
free(cookie, M_DMAMAP);
|
isadma_bounce_cookie_free(map);
|
||||||
_bus_dmamap_destroy(t, map);
|
_bus_dmamap_destroy(t, map);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue