malloc(9) -> kmem(9)
This commit is contained in:
parent
b70d869915
commit
6f97a7c12d
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: bus_dma.c,v 1.70 2020/10/11 00:33:30 thorpej Exp $ */
|
||||
/* $NetBSD: bus_dma.c,v 1.71 2020/11/18 02:04:29 thorpej Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1997, 1998 The NetBSD Foundation, Inc.
|
||||
@ -32,13 +32,13 @@
|
||||
|
||||
#include <sys/cdefs.h> /* RCS ID & Copyright macro defns */
|
||||
|
||||
__KERNEL_RCSID(0, "$NetBSD: bus_dma.c,v 1.70 2020/10/11 00:33:30 thorpej Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: bus_dma.c,v 1.71 2020/11/18 02:04:29 thorpej Exp $");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/systm.h>
|
||||
#include <sys/kernel.h>
|
||||
#include <sys/device.h>
|
||||
#include <sys/malloc.h>
|
||||
#include <sys/kmem.h>
|
||||
#include <sys/proc.h>
|
||||
#include <sys/mbuf.h>
|
||||
|
||||
@ -59,6 +59,14 @@ extern paddr_t avail_start, avail_end; /* from pmap.c */
|
||||
#define DMA_COUNT_DECL(cnt) _DMA_COUNT_DECL(dma_direct, cnt)
|
||||
#define DMA_COUNT(cnt) _DMA_COUNT(dma_direct, cnt)
|
||||
|
||||
static size_t
|
||||
_bus_dmamap_mapsize(int const nsegments)
|
||||
{
|
||||
KASSERT(nsegments > 0);
|
||||
return sizeof(struct alpha_bus_dmamap) +
|
||||
(sizeof(bus_dma_segment_t) * (nsegments - 1));
|
||||
}
|
||||
|
||||
/*
|
||||
* Common function for DMA map creation. May be called by bus-specific
|
||||
* DMA map creation functions.
|
||||
@ -69,7 +77,6 @@ _bus_dmamap_create(bus_dma_tag_t t, bus_size_t size, int nsegments,
|
||||
{
|
||||
struct alpha_bus_dmamap *map;
|
||||
void *mapstore;
|
||||
size_t mapsize;
|
||||
|
||||
/*
|
||||
* Allocate and initialize the DMA map. The end of the map
|
||||
@ -83,13 +90,10 @@ _bus_dmamap_create(bus_dma_tag_t t, bus_size_t size, int nsegments,
|
||||
* The bus_dmamap_t includes one bus_dma_segment_t, hence
|
||||
* the (nsegments - 1).
|
||||
*/
|
||||
mapsize = sizeof(struct alpha_bus_dmamap) +
|
||||
(sizeof(bus_dma_segment_t) * (nsegments - 1));
|
||||
if ((mapstore = malloc(mapsize, M_DMAMAP,
|
||||
(flags & BUS_DMA_NOWAIT) ? M_NOWAIT : M_WAITOK)) == NULL)
|
||||
if ((mapstore = kmem_zalloc(_bus_dmamap_mapsize(nsegments),
|
||||
(flags & BUS_DMA_NOWAIT) ? KM_NOSLEEP : KM_SLEEP)) == NULL)
|
||||
return (ENOMEM);
|
||||
|
||||
memset(mapstore, 0, mapsize);
|
||||
map = (struct alpha_bus_dmamap *)mapstore;
|
||||
map->_dm_size = size;
|
||||
map->_dm_segcnt = nsegments;
|
||||
@ -116,7 +120,7 @@ void
|
||||
_bus_dmamap_destroy(bus_dma_tag_t t, bus_dmamap_t map)
|
||||
{
|
||||
|
||||
free(map, M_DMAMAP);
|
||||
kmem_free(map, _bus_dmamap_mapsize(map->_dm_segcnt));
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: eisa_machdep.c,v 1.12 2014/03/29 19:28:25 christos Exp $ */
|
||||
/* $NetBSD: eisa_machdep.c,v 1.13 2020/11/18 02:04:29 thorpej Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2000 The NetBSD Foundation, Inc.
|
||||
@ -31,12 +31,12 @@
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
|
||||
__KERNEL_RCSID(0, "$NetBSD: eisa_machdep.c,v 1.12 2014/03/29 19:28:25 christos Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: eisa_machdep.c,v 1.13 2020/11/18 02:04:29 thorpej Exp $");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/systm.h>
|
||||
#include <sys/device.h>
|
||||
#include <sys/malloc.h>
|
||||
#include <sys/kmem.h>
|
||||
#include <sys/queue.h>
|
||||
|
||||
#include <machine/intr.h>
|
||||
@ -157,10 +157,7 @@ eisa_parse_mem(struct ecu_func *ecuf, uint8_t *dp)
|
||||
int i;
|
||||
|
||||
for (i = 0; i < ECUF_MEM_ENTRY_CNT; i++) {
|
||||
ecum = malloc(sizeof(*ecum), M_DEVBUF, M_ZERO|M_WAITOK);
|
||||
if (ecum == NULL)
|
||||
panic("%s: can't allocate memory for ecum", __func__);
|
||||
|
||||
ecum = kmem_zalloc(sizeof(*ecum), KM_SLEEP);
|
||||
ecum->ecum_mem.ecm_isram = dp[0] & 0x1;
|
||||
ecum->ecum_mem.ecm_unitsize = dp[1] & 0x3;
|
||||
ecum->ecum_mem.ecm_decode = (dp[1] >> 2) & 0x3;
|
||||
@ -191,10 +188,7 @@ eisa_parse_irq(struct ecu_func *ecuf, uint8_t *dp)
|
||||
int i;
|
||||
|
||||
for (i = 0; i < ECUF_IRQ_ENTRY_CNT; i++) {
|
||||
ecui = malloc(sizeof(*ecui), M_DEVBUF, M_ZERO|M_WAITOK);
|
||||
if (ecui == NULL)
|
||||
panic("%s: can't allocate memory for ecui", __func__);
|
||||
|
||||
ecui = kmem_zalloc(sizeof(*ecui), KM_SLEEP);
|
||||
ecui->ecui_irq.eci_irq = dp[0] & 0xf;
|
||||
ecui->ecui_irq.eci_ist = (dp[0] & 0x20) ? IST_LEVEL : IST_EDGE;
|
||||
ecui->ecui_irq.eci_shared = (dp[0] & 0x40) ? 1 : 0;
|
||||
@ -219,10 +213,7 @@ eisa_parse_dma(struct ecu_func *ecuf, uint8_t *dp)
|
||||
int i;
|
||||
|
||||
for (i = 0; i < ECUF_DMA_ENTRY_CNT; i++) {
|
||||
ecud = malloc(sizeof(*ecud), M_DEVBUF, M_ZERO|M_WAITOK);
|
||||
if (ecud == NULL)
|
||||
panic("%s: can't allocate memory for ecud", __func__);
|
||||
|
||||
ecud = kmem_zalloc(sizeof(*ecud), KM_SLEEP);
|
||||
ecud->ecud_dma.ecd_drq = dp[0] & 0x7;
|
||||
ecud->ecud_dma.ecd_shared = dp[0] & 0x40;
|
||||
ecud->ecud_dma.ecd_size = (dp[1] >> 2) & 0x3;
|
||||
@ -248,10 +239,7 @@ eisa_parse_io(struct ecu_func *ecuf, uint8_t *dp)
|
||||
int i;
|
||||
|
||||
for (i = 0; i < ECUF_IO_ENTRY_CNT; i++) {
|
||||
ecuio = malloc(sizeof(*ecuio), M_DEVBUF, M_ZERO|M_WAITOK);
|
||||
if (ecuio == NULL)
|
||||
panic("%s: can't allocate memory for ecuio", __func__);
|
||||
|
||||
ecuio = kmem_zalloc(sizeof(*ecuio), KM_SLEEP);
|
||||
ecuio->ecuio_io.ecio_addr = dp[1] | (dp[2] << 8);
|
||||
ecuio->ecuio_io.ecio_size = (dp[0] & 0x1f) + 1;
|
||||
ecuio->ecuio_io.ecio_shared = (dp[0] & 0x40) ? 1 : 0;
|
||||
@ -370,11 +358,7 @@ eisa_init(eisa_chipset_tag_t ec)
|
||||
printf("SLOT %d: offset 0x%08x eisaid %s\n",
|
||||
i, offset, eisaid);
|
||||
#endif
|
||||
ecud = malloc(sizeof(*ecud), M_DEVBUF, M_ZERO|M_WAITOK);
|
||||
if (ecud == NULL)
|
||||
panic("%s: can't allocate memory for ecud",
|
||||
__func__);
|
||||
|
||||
ecud = kmem_zalloc(sizeof(*ecud), KM_SLEEP);
|
||||
SIMPLEQ_INIT(&ecud->ecud_funcs);
|
||||
|
||||
ecud->ecud_slot = i;
|
||||
@ -388,12 +372,8 @@ eisa_init(eisa_chipset_tag_t ec)
|
||||
* Now traverse the valid slots and read the info.
|
||||
*/
|
||||
|
||||
cdata = malloc(CBUFSIZE, M_TEMP, M_ZERO|M_WAITOK);
|
||||
if (cdata == NULL)
|
||||
panic("%s: can't allocate memory for cdata", __func__);
|
||||
data = malloc(CBUFSIZE, M_TEMP, M_ZERO|M_WAITOK);
|
||||
if (data == NULL)
|
||||
panic("%s: can't allocate memory for data", __func__);
|
||||
cdata = kmem_zalloc(CBUFSIZE, KM_SLEEP);
|
||||
data = kmem_zalloc(CBUFSIZE, KM_SLEEP);
|
||||
|
||||
SIMPLEQ_FOREACH(ecud, &ecu_data_list, ecud_list) {
|
||||
cfgaddr = eisa_config_addr + ecud->ecud_offset;
|
||||
@ -501,10 +481,7 @@ eisa_init(eisa_chipset_tag_t ec)
|
||||
continue;
|
||||
}
|
||||
|
||||
ecuf = malloc(sizeof(*ecuf), M_DEVBUF, M_WAITOK);
|
||||
if (ecuf == NULL)
|
||||
panic("%s: can't allocate memory for ecuf",
|
||||
__func__);
|
||||
ecuf = kmem_zalloc(sizeof(*ecuf), KM_SLEEP);
|
||||
ecuf_init(ecuf);
|
||||
ecuf->ecuf_funcno = func;
|
||||
SIMPLEQ_INSERT_TAIL(&ecud->ecud_funcs, ecuf,
|
||||
@ -557,8 +534,8 @@ eisa_init(eisa_chipset_tag_t ec)
|
||||
}
|
||||
}
|
||||
|
||||
free(cdata, M_TEMP);
|
||||
free(data, M_TEMP);
|
||||
kmem_free(cdata, CBUFSIZE);
|
||||
kmem_free(data, CBUFSIZE);
|
||||
}
|
||||
|
||||
static struct ecu_data *
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: isadma_bounce.c,v 1.13 2016/02/29 15:28:35 christos Exp $ */
|
||||
/* $NetBSD: isadma_bounce.c,v 1.14 2020/11/18 02:04:29 thorpej Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1996, 1997, 1998, 2000 The NetBSD Foundation, Inc.
|
||||
@ -32,13 +32,13 @@
|
||||
|
||||
#include <sys/cdefs.h> /* RCS ID & Copyright macro defns */
|
||||
|
||||
__KERNEL_RCSID(0, "$NetBSD: isadma_bounce.c,v 1.13 2016/02/29 15:28:35 christos Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: isadma_bounce.c,v 1.14 2020/11/18 02:04:29 thorpej Exp $");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/systm.h>
|
||||
#include <sys/syslog.h>
|
||||
#include <sys/device.h>
|
||||
#include <sys/malloc.h>
|
||||
#include <sys/kmem.h>
|
||||
#include <sys/proc.h>
|
||||
#include <sys/mbuf.h>
|
||||
|
||||
@ -91,28 +91,19 @@ int isadma_bounce_alloc_bouncebuf(bus_dma_tag_t, bus_dmamap_t,
|
||||
void isadma_bounce_free_bouncebuf(bus_dma_tag_t, bus_dmamap_t);
|
||||
|
||||
/*
|
||||
* Create an ISA DMA map.
|
||||
* Returns true if the system memory configuration exceeds the
|
||||
* capabilities of ISA DMA.
|
||||
*/
|
||||
int
|
||||
isadma_bounce_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)
|
||||
static bool
|
||||
isadma_bounce_check_range(bus_dma_tag_t const t)
|
||||
{
|
||||
struct isadma_bounce_cookie *cookie;
|
||||
bus_dmamap_t map;
|
||||
int error, cookieflags;
|
||||
void *cookiestore;
|
||||
size_t cookiesize;
|
||||
return avail_end > (t->_wbase + t->_wsize);
|
||||
}
|
||||
|
||||
/* 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(*cookie);
|
||||
static int
|
||||
isadma_bounce_cookieflags(bus_dma_tag_t const t, bus_dmamap_t const map)
|
||||
{
|
||||
int cookieflags = 0;
|
||||
|
||||
/*
|
||||
* ISA only has 24-bits of address space. This means
|
||||
@ -133,42 +124,97 @@ isadma_bounce_dmamap_create(bus_dma_tag_t t, bus_size_t size, int nsegments,
|
||||
* the caller can't handle that many segments (e.g. the
|
||||
* ISA DMA controller), we may have to bounce it as well.
|
||||
*/
|
||||
cookieflags = 0;
|
||||
if (avail_end > (t->_wbase + t->_wsize) ||
|
||||
if (isadma_bounce_check_range(t) ||
|
||||
((map->_dm_size / PAGE_SIZE) + 1) > map->_dm_segcnt) {
|
||||
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 isadma_bounce_cookie);
|
||||
|
||||
if (cookieflags & ID_MIGHT_NEED_BOUNCE) {
|
||||
cookiesize += (sizeof(bus_dma_segment_t) *
|
||||
(map->_dm_segcnt - 1));
|
||||
}
|
||||
return cookiesize;
|
||||
}
|
||||
|
||||
static int
|
||||
isadma_bounce_cookie_alloc(bus_dma_tag_t const t, bus_dmamap_t const map,
|
||||
int const flags)
|
||||
{
|
||||
struct isadma_bounce_cookie *cookie;
|
||||
int cookieflags = isadma_bounce_cookieflags(t, map);
|
||||
|
||||
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 isadma_bounce_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
|
||||
isadma_bounce_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 isadma_bounce_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.
|
||||
*/
|
||||
if ((cookiestore = malloc(cookiesize, M_DMAMAP,
|
||||
(flags & BUS_DMA_NOWAIT) ? M_NOWAIT : M_WAITOK)) == NULL) {
|
||||
error = ENOMEM;
|
||||
if ((error = isadma_bounce_cookie_alloc(t, map, flags)) != 0) {
|
||||
goto out;
|
||||
}
|
||||
memset(cookiestore, 0, cookiesize);
|
||||
cookie = (struct isadma_bounce_cookie *)cookiestore;
|
||||
cookie->id_flags = cookieflags;
|
||||
map->_dm_cookie = cookie;
|
||||
cookie = map->_dm_cookie;
|
||||
|
||||
if (cookieflags & ID_MIGHT_NEED_BOUNCE) {
|
||||
if (cookie->id_flags & ID_MIGHT_NEED_BOUNCE) {
|
||||
/*
|
||||
* Allocate the bounce pages now if the caller
|
||||
* wishes us to do so.
|
||||
*/
|
||||
if ((flags & BUS_DMA_ALLOCNOW) == 0)
|
||||
goto out;
|
||||
|
||||
error = isadma_bounce_alloc_bouncebuf(t, map, size, flags);
|
||||
if (flags & BUS_DMA_ALLOCNOW) {
|
||||
error = isadma_bounce_alloc_bouncebuf(t, map, size,
|
||||
flags);
|
||||
}
|
||||
}
|
||||
|
||||
out:
|
||||
if (error) {
|
||||
if (map->_dm_cookie != NULL)
|
||||
free(map->_dm_cookie, M_DMAMAP);
|
||||
isadma_bounce_cookie_free(map);
|
||||
_bus_dmamap_destroy(t, map);
|
||||
}
|
||||
return (error);
|
||||
@ -188,7 +234,7 @@ isadma_bounce_dmamap_destroy(bus_dma_tag_t t, bus_dmamap_t map)
|
||||
if (cookie->id_flags & ID_HAS_BOUNCE)
|
||||
isadma_bounce_free_bouncebuf(t, map);
|
||||
|
||||
free(cookie, M_DMAMAP);
|
||||
isadma_bounce_cookie_free(map);
|
||||
_bus_dmamap_destroy(t, map);
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: pckbc_jensenio.c,v 1.14 2020/09/25 03:40:11 thorpej Exp $ */
|
||||
/* $NetBSD: pckbc_jensenio.c,v 1.15 2020/11/18 02:04:29 thorpej Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1999 The NetBSD Foundation, Inc.
|
||||
@ -31,14 +31,14 @@
|
||||
|
||||
#include <sys/cdefs.h> /* RCS ID & Copyright macro defns */
|
||||
|
||||
__KERNEL_RCSID(0, "$NetBSD: pckbc_jensenio.c,v 1.14 2020/09/25 03:40:11 thorpej Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: pckbc_jensenio.c,v 1.15 2020/11/18 02:04:29 thorpej Exp $");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/systm.h>
|
||||
#include <sys/kernel.h>
|
||||
#include <sys/proc.h>
|
||||
#include <sys/device.h>
|
||||
#include <sys/malloc.h>
|
||||
#include <sys/kmem.h>
|
||||
#include <sys/errno.h>
|
||||
#include <sys/queue.h>
|
||||
#include <sys/intr.h>
|
||||
@ -111,8 +111,7 @@ pckbc_jensenio_attach(device_t parent, device_t self, void *aux)
|
||||
1, 0, &ioh_c) != 0)
|
||||
panic("pckbc_jensenio_attach: couldn't map");
|
||||
|
||||
t = malloc(sizeof(struct pckbc_internal), M_DEVBUF, M_WAITOK);
|
||||
memset(t, 0, sizeof(struct pckbc_internal));
|
||||
t = kmem_zalloc(sizeof(struct pckbc_internal), KM_SLEEP);
|
||||
t->t_iot = ja->ja_iot;
|
||||
t->t_ioh_d = ioh_d;
|
||||
t->t_ioh_c = ioh_c;
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: dwlpx_dma.c,v 1.27 2020/10/11 00:33:31 thorpej Exp $ */
|
||||
/* $NetBSD: dwlpx_dma.c,v 1.28 2020/11/18 02:04:29 thorpej Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1997, 1998 The NetBSD Foundation, Inc.
|
||||
@ -32,13 +32,13 @@
|
||||
|
||||
#include <sys/cdefs.h> /* RCS ID & Copyright macro defns */
|
||||
|
||||
__KERNEL_RCSID(0, "$NetBSD: dwlpx_dma.c,v 1.27 2020/10/11 00:33:31 thorpej Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: dwlpx_dma.c,v 1.28 2020/11/18 02:04:29 thorpej Exp $");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/systm.h>
|
||||
#include <sys/kernel.h>
|
||||
#include <sys/device.h>
|
||||
#include <sys/malloc.h>
|
||||
#include <sys/kmem.h>
|
||||
|
||||
#define _ALPHA_BUS_DMA_PRIVATE
|
||||
#include <sys/bus.h>
|
||||
@ -209,9 +209,7 @@ dwlpx_dma_init(struct dwlpx_config *ccp)
|
||||
* Window base: 1GB
|
||||
* SGVA base: 0
|
||||
*/
|
||||
#define EXNAMELEN 16
|
||||
exname = malloc(EXNAMELEN, M_DEVBUF, M_WAITOK);
|
||||
snprintf(exname, EXNAMELEN, "%s_sgmap_a",
|
||||
exname = kmem_asprintf("%s_sgmap_a",
|
||||
device_xname(ccp->cc_sc->dwlpx_dev));
|
||||
alpha_sgmap_init(t, &ccp->cc_sgmap, exname, DWLPx_SG_MAPPED_BASE,
|
||||
0, DWLPx_SG_MAPPED_SIZE(lim), sizeof(uint32_t),
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: mcpcia.c,v 1.29 2012/02/06 02:14:14 matt Exp $ */
|
||||
/* $NetBSD: mcpcia.c,v 1.30 2020/11/18 02:04:29 thorpej Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1999 The NetBSD Foundation, Inc.
|
||||
@ -67,12 +67,12 @@
|
||||
|
||||
#include <sys/cdefs.h> /* RCS ID & Copyright macro defns */
|
||||
|
||||
__KERNEL_RCSID(0, "$NetBSD: mcpcia.c,v 1.29 2012/02/06 02:14:14 matt Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: mcpcia.c,v 1.30 2020/11/18 02:04:29 thorpej Exp $");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/systm.h>
|
||||
#include <sys/device.h>
|
||||
#include <sys/malloc.h>
|
||||
#include <sys/kmem.h>
|
||||
|
||||
#include <machine/autoconf.h>
|
||||
#include <machine/rpb.h>
|
||||
@ -150,9 +150,7 @@ mcpciaattach(device_t parent, device_t self, void *aux)
|
||||
ma->ma_gid == mcpcia_console_configuration.cc_gid)
|
||||
ccp = &mcpcia_console_configuration;
|
||||
else {
|
||||
ccp = malloc(sizeof(struct mcpcia_config), M_DEVBUF, M_WAITOK);
|
||||
memset(ccp, 0, sizeof(struct mcpcia_config));
|
||||
|
||||
ccp = kmem_zalloc(sizeof(struct mcpcia_config), KM_SLEEP);
|
||||
ccp->cc_mid = ma->ma_mid;
|
||||
ccp->cc_gid = ma->ma_gid;
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: sio.c,v 1.53 2020/09/22 15:24:02 thorpej Exp $ */
|
||||
/* $NetBSD: sio.c,v 1.54 2020/11/18 02:04:29 thorpej Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2000 The NetBSD Foundation, Inc.
|
||||
@ -63,13 +63,13 @@
|
||||
|
||||
#include <sys/cdefs.h> /* RCS ID & Copyright macro defns */
|
||||
|
||||
__KERNEL_RCSID(0, "$NetBSD: sio.c,v 1.53 2020/09/22 15:24:02 thorpej Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: sio.c,v 1.54 2020/11/18 02:04:29 thorpej Exp $");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/systm.h>
|
||||
#include <sys/kernel.h>
|
||||
#include <sys/device.h>
|
||||
#include <sys/malloc.h>
|
||||
#include <sys/kmem.h>
|
||||
|
||||
#include <machine/intr.h>
|
||||
#include <sys/bus.h>
|
||||
@ -254,8 +254,7 @@ sio_bridge_callback(device_t self)
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
sc->sc_ic = malloc(sizeof(*sc->sc_ic), M_DEVBUF, M_WAITOK);
|
||||
memset(sc->sc_ic, 0, sizeof(*sc->sc_ic));
|
||||
sc->sc_ic = kmem_zalloc(sizeof(*sc->sc_ic), KM_SLEEP);
|
||||
}
|
||||
|
||||
sc->sc_ic->ic_v = NULL;
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: pckbc_sableio.c,v 1.13 2020/09/22 15:24:02 thorpej Exp $ */
|
||||
/* $NetBSD: pckbc_sableio.c,v 1.14 2020/11/18 02:04:30 thorpej Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1999 The NetBSD Foundation, Inc.
|
||||
@ -31,14 +31,14 @@
|
||||
|
||||
#include <sys/cdefs.h> /* RCS ID & Copyright macro defns */
|
||||
|
||||
__KERNEL_RCSID(0, "$NetBSD: pckbc_sableio.c,v 1.13 2020/09/22 15:24:02 thorpej Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: pckbc_sableio.c,v 1.14 2020/11/18 02:04:30 thorpej Exp $");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/systm.h>
|
||||
#include <sys/kernel.h>
|
||||
#include <sys/proc.h>
|
||||
#include <sys/device.h>
|
||||
#include <sys/malloc.h>
|
||||
#include <sys/kmem.h>
|
||||
#include <sys/errno.h>
|
||||
#include <sys/queue.h>
|
||||
#include <sys/intr.h>
|
||||
@ -112,8 +112,7 @@ pckbc_sableio_attach(device_t parent, device_t self, void *aux)
|
||||
1, 0, &ioh_c) != 0)
|
||||
panic("pckbc_sableio_attach: couldn't map");
|
||||
|
||||
t = malloc(sizeof(struct pckbc_internal), M_DEVBUF, M_WAITOK);
|
||||
memset(t, 0, sizeof(struct pckbc_internal));
|
||||
t = kmem_zalloc(sizeof(struct pckbc_internal), KM_SLEEP);
|
||||
t->t_iot = sa->sa_iot;
|
||||
t->t_ioh_d = ioh_d;
|
||||
t->t_ioh_c = ioh_c;
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: ioasic.c,v 1.47 2019/11/10 21:16:22 chs Exp $ */
|
||||
/* $NetBSD: ioasic.c,v 1.48 2020/11/18 02:04:30 thorpej Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1997, 1998 The NetBSD Foundation, Inc.
|
||||
@ -61,13 +61,13 @@
|
||||
|
||||
#include <sys/cdefs.h> /* RCS ID & Copyright macro defns */
|
||||
|
||||
__KERNEL_RCSID(0, "$NetBSD: ioasic.c,v 1.47 2019/11/10 21:16:22 chs Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: ioasic.c,v 1.48 2020/11/18 02:04:30 thorpej Exp $");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/kernel.h>
|
||||
#include <sys/systm.h>
|
||||
#include <sys/device.h>
|
||||
#include <sys/malloc.h>
|
||||
#include <sys/kmem.h>
|
||||
|
||||
#include <machine/autoconf.h>
|
||||
#include <sys/bus.h>
|
||||
@ -192,12 +192,10 @@ ioasicattach(device_t parent, device_t self, void *aux)
|
||||
*/
|
||||
pevcnt = tc_intr_evcnt(parent, ta->ta_cookie);
|
||||
for (i = 0; i < IOASIC_NCOOKIES; i++) {
|
||||
static const size_t len = 12;
|
||||
ioasicintrs[i].iai_func = ioasic_intrnull;
|
||||
ioasicintrs[i].iai_arg = (void *)i;
|
||||
|
||||
cp = malloc(len, M_DEVBUF, M_WAITOK);
|
||||
snprintf(cp, len, "slot %lu", i);
|
||||
cp = kmem_asprintf("slot %lu", i);
|
||||
evcnt_attach_dynamic(&ioasicintrs[i].iai_evcnt,
|
||||
EVCNT_TYPE_INTR, pevcnt, device_xname(self), cp);
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: tc_3000_300.c,v 1.37 2020/09/25 03:40:11 thorpej Exp $ */
|
||||
/* $NetBSD: tc_3000_300.c,v 1.38 2020/11/18 02:04:30 thorpej Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1994, 1995, 1996 Carnegie-Mellon University.
|
||||
@ -29,12 +29,12 @@
|
||||
|
||||
#include <sys/cdefs.h> /* RCS ID & Copyright macro defns */
|
||||
|
||||
__KERNEL_RCSID(0, "$NetBSD: tc_3000_300.c,v 1.37 2020/09/25 03:40:11 thorpej Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: tc_3000_300.c,v 1.38 2020/11/18 02:04:30 thorpej Exp $");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/systm.h>
|
||||
#include <sys/device.h>
|
||||
#include <sys/malloc.h>
|
||||
#include <sys/kmem.h>
|
||||
#include <sys/cpu.h>
|
||||
|
||||
#include <machine/autoconf.h>
|
||||
@ -108,12 +108,10 @@ tc_3000_300_intr_setup(void)
|
||||
* Set up interrupt handlers.
|
||||
*/
|
||||
for (i = 0; i < TC_3000_300_NCOOKIES; i++) {
|
||||
static const size_t len = 12;
|
||||
tc_3000_300_intr[i].tci_func = tc_3000_300_intrnull;
|
||||
tc_3000_300_intr[i].tci_arg = (void *)i;
|
||||
|
||||
cp = malloc(len, M_DEVBUF, M_WAITOK);
|
||||
snprintf(cp, len, "slot %lu", i);
|
||||
cp = kmem_asprintf("slot %lu", i);
|
||||
evcnt_attach_dynamic(&tc_3000_300_intr[i].tci_evcnt,
|
||||
EVCNT_TYPE_INTR, NULL, "tc", cp);
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: tc_3000_500.c,v 1.36 2020/09/25 03:40:11 thorpej Exp $ */
|
||||
/* $NetBSD: tc_3000_500.c,v 1.37 2020/11/18 02:04:30 thorpej Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1994, 1995, 1996 Carnegie-Mellon University.
|
||||
@ -29,12 +29,12 @@
|
||||
|
||||
#include <sys/cdefs.h> /* RCS ID & Copyright macro defns */
|
||||
|
||||
__KERNEL_RCSID(0, "$NetBSD: tc_3000_500.c,v 1.36 2020/09/25 03:40:11 thorpej Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: tc_3000_500.c,v 1.37 2020/11/18 02:04:30 thorpej Exp $");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/systm.h>
|
||||
#include <sys/device.h>
|
||||
#include <sys/malloc.h>
|
||||
#include <sys/kmem.h>
|
||||
#include <sys/cpu.h>
|
||||
|
||||
#include <machine/autoconf.h>
|
||||
@ -132,12 +132,10 @@ tc_3000_500_intr_setup(void)
|
||||
* Set up interrupt handlers.
|
||||
*/
|
||||
for (i = 0; i < TC_3000_500_NCOOKIES; i++) {
|
||||
static const size_t len = 12;
|
||||
tc_3000_500_intr[i].tci_func = tc_3000_500_intrnull;
|
||||
tc_3000_500_intr[i].tci_arg = (void *)i;
|
||||
|
||||
cp = malloc(len, M_DEVBUF, M_WAITOK);
|
||||
snprintf(cp, len, "slot %lu", i);
|
||||
cp = kmem_asprintf("slot %lu", i);
|
||||
evcnt_attach_dynamic(&tc_3000_500_intr[i].tci_evcnt,
|
||||
EVCNT_TYPE_INTR, NULL, "tc", cp);
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: tc_dma_3000_500.c,v 1.22 2020/10/11 00:33:30 thorpej Exp $ */
|
||||
/* $NetBSD: tc_dma_3000_500.c,v 1.23 2020/11/18 02:04:30 thorpej Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1997, 1998 The NetBSD Foundation, Inc.
|
||||
@ -32,13 +32,13 @@
|
||||
|
||||
#include <sys/cdefs.h> /* RCS ID & Copyright macro defns */
|
||||
|
||||
__KERNEL_RCSID(0, "$NetBSD: tc_dma_3000_500.c,v 1.22 2020/10/11 00:33:30 thorpej Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: tc_dma_3000_500.c,v 1.23 2020/11/18 02:04:30 thorpej Exp $");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/systm.h>
|
||||
#include <sys/device.h>
|
||||
#include <sys/kernel.h>
|
||||
#include <sys/malloc.h>
|
||||
#include <sys/kmem.h>
|
||||
|
||||
#define _ALPHA_BUS_DMA_PRIVATE
|
||||
#include <sys/bus.h>
|
||||
@ -86,7 +86,7 @@ tc_dma_init_3000_500(int nslots)
|
||||
|
||||
/* Allocate per-slot DMA info. */
|
||||
sisize = nslots * sizeof(struct tc_dma_slot_info);
|
||||
tc_dma_slot_info = malloc(sisize, M_DEVBUF, M_WAITOK | M_ZERO);
|
||||
tc_dma_slot_info = kmem_zalloc(sisize, KM_SLEEP);
|
||||
|
||||
/* Default all slots to direct-mapped. */
|
||||
for (i = 0; i < nslots; i++)
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: bus_dma.c,v 1.34 2015/06/11 08:22:08 matt Exp $ */
|
||||
/* $NetBSD: bus_dma.c,v 1.35 2020/11/18 02:14:13 thorpej Exp $ */
|
||||
/* NetBSD: bus_dma.c,v 1.20 2000/01/10 03:24:36 simonb Exp */
|
||||
|
||||
/*-
|
||||
@ -32,13 +32,14 @@
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: bus_dma.c,v 1.34 2015/06/11 08:22:08 matt Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: bus_dma.c,v 1.35 2020/11/18 02:14:13 thorpej Exp $");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/systm.h>
|
||||
#include <sys/mbuf.h>
|
||||
#include <sys/device.h>
|
||||
#include <sys/proc.h>
|
||||
#include <sys/kmem.h>
|
||||
|
||||
#include <uvm/uvm.h>
|
||||
|
||||
@ -74,6 +75,14 @@ _bus_dma_tag_init(bus_dma_tag_t t)
|
||||
t->_dmamem_mmap = _bus_dmamem_mmap;
|
||||
}
|
||||
|
||||
static size_t
|
||||
_bus_dmamap_mapsize(int const nsegments)
|
||||
{
|
||||
KASSERT(nsegments > 0);
|
||||
return sizeof(struct arc_bus_dmamap) +
|
||||
(sizeof(bus_dma_segment_t) * (nsegments - 1));
|
||||
}
|
||||
|
||||
/*
|
||||
* Common function for DMA map creation. May be called by bus-specific
|
||||
* DMA map creation functions.
|
||||
@ -84,7 +93,6 @@ _bus_dmamap_create(bus_dma_tag_t t, bus_size_t size, int nsegments,
|
||||
{
|
||||
struct arc_bus_dmamap *map;
|
||||
void *mapstore;
|
||||
size_t mapsize;
|
||||
|
||||
/*
|
||||
* Allocate and initialize the DMA map. The end of the map
|
||||
@ -98,10 +106,8 @@ _bus_dmamap_create(bus_dma_tag_t t, bus_size_t size, int nsegments,
|
||||
* The bus_dmamap_t includes one bus_dma_segment_t, hence
|
||||
* the (nsegments - 1).
|
||||
*/
|
||||
mapsize = sizeof(struct arc_bus_dmamap) +
|
||||
(sizeof(bus_dma_segment_t) * (nsegments - 1));
|
||||
if ((mapstore = malloc(mapsize, M_DMAMAP,
|
||||
((flags & BUS_DMA_NOWAIT) ? M_NOWAIT : M_WAITOK) | M_ZERO)) == NULL)
|
||||
if ((mapstore = kmem_zalloc(_bus_dmamap_mapsize(nsegments),
|
||||
(flags & BUS_DMA_NOWAIT) ? KM_NOSLEEP : KM_SLEEP)) == NULL)
|
||||
return ENOMEM;
|
||||
|
||||
map = (struct arc_bus_dmamap *)mapstore;
|
||||
@ -127,7 +133,7 @@ void
|
||||
_bus_dmamap_destroy(bus_dma_tag_t t, bus_dmamap_t map)
|
||||
{
|
||||
|
||||
free(map, M_DMAMAP);
|
||||
kmem_free(map, _bus_dmamap_mapsize(map->_dm_segcnt));
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: p_dti_arcstation.c,v 1.19 2020/06/13 20:01:27 ad Exp $ */
|
||||
/* $NetBSD: p_dti_arcstation.c,v 1.20 2020/11/18 02:14:13 thorpej Exp $ */
|
||||
/* $OpenBSD: machdep.c,v 1.36 1999/05/22 21:22:19 weingart Exp $ */
|
||||
|
||||
/*
|
||||
@ -39,7 +39,7 @@
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: p_dti_arcstation.c,v 1.19 2020/06/13 20:01:27 ad Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: p_dti_arcstation.c,v 1.20 2020/11/18 02:14:13 thorpej Exp $");
|
||||
|
||||
#define __INTR_PRIVATE
|
||||
#include <sys/param.h>
|
||||
@ -165,7 +165,7 @@ btl_dti_arcstation_bouncemem(u_int *basep, u_int *sizep)
|
||||
|
||||
*sizep = TYNE_S_BOUNCE; /* Good enough? XXX */
|
||||
#if 0
|
||||
*basep = (u_int) malloc(*sizep, M_DEVBUF, M_WAITOK);
|
||||
*basep = (u_int) kmem_alloc(*sizep, KM_SLEEP);
|
||||
#else
|
||||
*basep = (u_int) rpc44_buffer | 0xa0000000;
|
||||
#endif
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: isabus.c,v 1.50 2019/11/10 21:16:22 chs Exp $ */
|
||||
/* $NetBSD: isabus.c,v 1.51 2020/11/18 02:14:13 thorpej Exp $ */
|
||||
/* $OpenBSD: isabus.c,v 1.15 1998/03/16 09:38:46 pefo Exp $ */
|
||||
/* NetBSD: isa.c,v 1.33 1995/06/28 04:30:51 cgd Exp */
|
||||
|
||||
@ -120,7 +120,7 @@ WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: isabus.c,v 1.50 2019/11/10 21:16:22 chs Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: isabus.c,v 1.51 2020/11/18 02:14:13 thorpej Exp $");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/proc.h>
|
||||
@ -129,7 +129,7 @@ __KERNEL_RCSID(0, "$NetBSD: isabus.c,v 1.50 2019/11/10 21:16:22 chs Exp $");
|
||||
#include <sys/time.h>
|
||||
#include <sys/kernel.h>
|
||||
#include <sys/device.h>
|
||||
#include <sys/malloc.h>
|
||||
#include <sys/kmem.h>
|
||||
#include <sys/extent.h>
|
||||
|
||||
#include <uvm/uvm_extern.h>
|
||||
@ -340,7 +340,7 @@ isabr_intr_establish(isa_chipset_tag_t ic, int irq, int type, int level,
|
||||
struct isa_intrhand **p, *q, *ih;
|
||||
static struct isa_intrhand fakehand = {NULL, fakeintr};
|
||||
|
||||
ih = malloc(sizeof *ih, M_DEVBUF, M_WAITOK);
|
||||
ih = kmem_alloc(sizeof *ih, KM_SLEEP);
|
||||
|
||||
if (!LEGAL_IRQ(irq) || type == IST_NONE)
|
||||
panic("intr_establish: bogus irq or type");
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: isadma_bounce.c,v 1.15 2016/02/26 18:14:38 christos Exp $ */
|
||||
/* $NetBSD: isadma_bounce.c,v 1.16 2020/11/18 02:14:13 thorpej Exp $ */
|
||||
/* NetBSD: isadma_bounce.c,v 1.2 2000/06/01 05:49:36 thorpej Exp */
|
||||
|
||||
/*-
|
||||
@ -33,13 +33,13 @@
|
||||
|
||||
#include <sys/cdefs.h> /* RCS ID & Copyright macro defns */
|
||||
|
||||
__KERNEL_RCSID(0, "$NetBSD: isadma_bounce.c,v 1.15 2016/02/26 18:14:38 christos Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: isadma_bounce.c,v 1.16 2020/11/18 02:14:13 thorpej Exp $");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/systm.h>
|
||||
#include <sys/syslog.h>
|
||||
#include <sys/device.h>
|
||||
#include <sys/malloc.h>
|
||||
#include <sys/kmem.h>
|
||||
#include <sys/proc.h>
|
||||
#include <sys/mbuf.h>
|
||||
|
||||
@ -108,6 +108,89 @@ static int isadma_bounce_alloc_bouncebuf(bus_dma_tag_t, bus_dmamap_t,
|
||||
bus_size_t, int);
|
||||
static void isadma_bounce_free_bouncebuf(bus_dma_tag_t, bus_dmamap_t);
|
||||
|
||||
/*
|
||||
* Returns true if the system memory configuration exceeds the
|
||||
* capabilities of ISA DMA.
|
||||
*/
|
||||
static bool
|
||||
isadma_bounce_check_range(bus_dma_tag_t const t)
|
||||
{
|
||||
return pmap_limits.avail_end > ISA_DMA_BOUNCE_THRESHOLD;
|
||||
}
|
||||
|
||||
static int
|
||||
isadma_bounce_cookieflags(bus_dma_tag_t const t, bus_dmamap_t const map)
|
||||
{
|
||||
int cookieflags = 0;
|
||||
|
||||
/*
|
||||
* ISA only has 24-bits of address space. This means
|
||||
* we can't DMA to pages over 16M. In order to DMA to
|
||||
* arbitrary buffers, we use "bounce buffers" - pages
|
||||
* in memory below the 16M boundary. On DMA reads,
|
||||
* DMA happens to the bounce buffers, and is copied into
|
||||
* the caller's buffer. On writes, data is copied into
|
||||
* but bounce buffer, and the DMA happens from those
|
||||
* pages. To software using the DMA mapping interface,
|
||||
* this looks simply like a data cache.
|
||||
*
|
||||
* If we have more than 16M of RAM in the system, we may
|
||||
* need bounce buffers. We check and remember that here.
|
||||
*
|
||||
* ...or, there is an opposite case. The most segments
|
||||
* a transfer will require is (maxxfer / PAGE_SIZE) + 1. If
|
||||
* the caller can't handle that many segments (e.g. the
|
||||
* ISA DMA controller), we may have to bounce it as well.
|
||||
*/
|
||||
if (isadma_bounce_check_range(t) ||
|
||||
((map->_dm_size / PAGE_SIZE) + 1) > map->_dm_segcnt) {
|
||||
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 isadma_bounce_cookie);
|
||||
|
||||
if (cookieflags & ID_MIGHT_NEED_BOUNCE) {
|
||||
cookiesize += (sizeof(bus_dma_segment_t) *
|
||||
(map->_dm_segcnt - 1));
|
||||
}
|
||||
return cookiesize;
|
||||
}
|
||||
|
||||
static int
|
||||
isadma_bounce_cookie_alloc(bus_dma_tag_t const t, bus_dmamap_t const map,
|
||||
int const flags)
|
||||
{
|
||||
struct isadma_bounce_cookie *cookie;
|
||||
int cookieflags = isadma_bounce_cookieflags(t, map);
|
||||
|
||||
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 isadma_bounce_cookie *cookie = map->_dm_cookie;
|
||||
|
||||
if (cookie != NULL) {
|
||||
kmem_free(map->_dm_cookie,
|
||||
isadma_bounce_cookiesize(map, cookie->id_flags));
|
||||
map->_dm_cookie = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
isadma_bounce_tag_init(bus_dma_tag_t t)
|
||||
{
|
||||
@ -137,9 +220,7 @@ isadma_bounce_dmamap_create(bus_dma_tag_t t, bus_size_t size, int nsegments,
|
||||
{
|
||||
struct isadma_bounce_cookie *cookie;
|
||||
bus_dmamap_t map;
|
||||
int error, cookieflags;
|
||||
void *cookiestore;
|
||||
size_t cookiesize;
|
||||
int error;
|
||||
|
||||
/* Call common function to create the basic map. */
|
||||
error = _bus_dmamap_create(t, size, nsegments, maxsegsz, boundary,
|
||||
@ -150,63 +231,28 @@ isadma_bounce_dmamap_create(bus_dma_tag_t t, bus_size_t size, int nsegments,
|
||||
map = *dmamp;
|
||||
map->_dm_cookie = NULL;
|
||||
|
||||
cookiesize = sizeof(*cookie);
|
||||
|
||||
/*
|
||||
* ISA only has 24-bits of address space. This means
|
||||
* we can't DMA to pages over 16M. In order to DMA to
|
||||
* arbitrary buffers, we use "bounce buffers" - pages
|
||||
* in memory below the 16M boundary. On DMA reads,
|
||||
* DMA happens to the bounce buffers, and is copied into
|
||||
* the caller's buffer. On writes, data is copied into
|
||||
* but bounce buffer, and the DMA happens from those
|
||||
* pages. To software using the DMA mapping interface,
|
||||
* this looks simply like a data cache.
|
||||
*
|
||||
* If we have more than 16M of RAM in the system, we may
|
||||
* need bounce buffers. We check and remember that here.
|
||||
*
|
||||
* ...or, there is an opposite case. The most segments
|
||||
* a transfer will require is (maxxfer / PAGE_SIZE) + 1. If
|
||||
* the caller can't handle that many segments (e.g. the
|
||||
* ISA DMA controller), we may have to bounce it as well.
|
||||
*/
|
||||
cookieflags = 0;
|
||||
if (pmap_limits.avail_end > ISA_DMA_BOUNCE_THRESHOLD ||
|
||||
((map->_dm_size / PAGE_SIZE) + 1) > map->_dm_segcnt) {
|
||||
cookieflags |= ID_MIGHT_NEED_BOUNCE;
|
||||
cookiesize += (sizeof(bus_dma_segment_t) *
|
||||
(map->_dm_segcnt - 1));
|
||||
}
|
||||
|
||||
/*
|
||||
* Allocate our cookie.
|
||||
*/
|
||||
if ((cookiestore = malloc(cookiesize, M_DMAMAP,
|
||||
(flags & BUS_DMA_NOWAIT) ? M_NOWAIT : M_WAITOK)) == NULL) {
|
||||
error = ENOMEM;
|
||||
if ((error = isadma_bounce_cookie_alloc(t, map, flags)) != 0) {
|
||||
goto out;
|
||||
}
|
||||
memset(cookiestore, 0, cookiesize);
|
||||
cookie = (struct isadma_bounce_cookie *)cookiestore;
|
||||
cookie->id_flags = cookieflags;
|
||||
map->_dm_cookie = cookie;
|
||||
cookie = map->_dm_cookie;
|
||||
|
||||
if (cookieflags & ID_MIGHT_NEED_BOUNCE) {
|
||||
if (cookie->id_flags & ID_MIGHT_NEED_BOUNCE) {
|
||||
/*
|
||||
* Allocate the bounce pages now if the caller
|
||||
* wishes us to do so.
|
||||
*/
|
||||
if ((flags & BUS_DMA_ALLOCNOW) == 0)
|
||||
goto out;
|
||||
|
||||
error = isadma_bounce_alloc_bouncebuf(t, map, size, flags);
|
||||
if (flags & BUS_DMA_ALLOCNOW) {
|
||||
error = isadma_bounce_alloc_bouncebuf(t, map, size,
|
||||
flags);
|
||||
}
|
||||
}
|
||||
|
||||
out:
|
||||
if (error) {
|
||||
if (map->_dm_cookie != NULL)
|
||||
free(map->_dm_cookie, M_DMAMAP);
|
||||
isadma_bounce_cookie_free(map);
|
||||
_bus_dmamap_destroy(t, map);
|
||||
}
|
||||
return error;
|
||||
@ -226,7 +272,7 @@ isadma_bounce_dmamap_destroy(bus_dma_tag_t t, bus_dmamap_t map)
|
||||
if (cookie->id_flags & ID_HAS_BOUNCE)
|
||||
isadma_bounce_free_bouncebuf(t, map);
|
||||
|
||||
free(cookie, M_DMAMAP);
|
||||
isadma_bounce_cookie_free(map);
|
||||
_bus_dmamap_destroy(t, map);
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: bus_dma_jazz.c,v 1.17 2011/07/01 19:25:41 dyoung Exp $ */
|
||||
/* $NetBSD: bus_dma_jazz.c,v 1.18 2020/11/18 02:14:13 thorpej Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2003 Izumi Tsutsui. All rights reserved.
|
||||
@ -51,13 +51,14 @@
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: bus_dma_jazz.c,v 1.17 2011/07/01 19:25:41 dyoung Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: bus_dma_jazz.c,v 1.18 2020/11/18 02:14:13 thorpej Exp $");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/systm.h>
|
||||
#include <sys/mbuf.h>
|
||||
#include <sys/device.h>
|
||||
#include <sys/proc.h>
|
||||
#include <sys/kmem.h>
|
||||
|
||||
#include <uvm/uvm_extern.h>
|
||||
|
||||
@ -171,8 +172,8 @@ jazz_bus_dmamap_create(bus_dma_tag_t t, bus_size_t size, int nsegments,
|
||||
return _bus_dmamap_create(t, size, nsegments, maxsegsz,
|
||||
boundary, flags, dmamp);
|
||||
|
||||
tlbmap = malloc(sizeof(struct jazz_tlbmap), M_DMAMAP,
|
||||
(flags & BUS_DMA_NOWAIT) ? M_NOWAIT : M_WAITOK);
|
||||
tlbmap = kmem_alloc(sizeof(struct jazz_tlbmap),
|
||||
(flags & BUS_DMA_NOWAIT) ? KM_NOSLEEP : KM_SLEEP);
|
||||
if (tlbmap == NULL)
|
||||
return ENOMEM;
|
||||
|
||||
@ -180,7 +181,7 @@ jazz_bus_dmamap_create(bus_dma_tag_t t, bus_size_t size, int nsegments,
|
||||
tlbmap->ptebase =
|
||||
jazz_dmatlb_alloc(npte, boundary, flags, &tlbmap->vaddr);
|
||||
if (tlbmap->ptebase == NULL) {
|
||||
free(tlbmap, M_DMAMAP);
|
||||
kmem_free(tlbmap, sizeof(struct jazz_tlbmap));
|
||||
return ENOMEM;
|
||||
}
|
||||
|
||||
@ -188,7 +189,7 @@ jazz_bus_dmamap_create(bus_dma_tag_t t, bus_size_t size, int nsegments,
|
||||
flags, dmamp);
|
||||
if (error != 0) {
|
||||
jazz_dmatlb_free(tlbmap->vaddr, npte);
|
||||
free(tlbmap, M_DMAMAP);
|
||||
kmem_free(tlbmap, sizeof(struct jazz_tlbmap));
|
||||
return error;
|
||||
}
|
||||
map = *dmamp;
|
||||
@ -213,7 +214,7 @@ jazz_bus_dmamap_destroy(bus_dma_tag_t t, bus_dmamap_t map)
|
||||
npte = jazz_dma_page_round(map->dm_maxsegsz) /
|
||||
JAZZ_DMA_PAGE_SIZE + 1;
|
||||
jazz_dmatlb_free(tlbmap->vaddr, npte);
|
||||
free(tlbmap, M_DMAMAP);
|
||||
kmem_free(tlbmap, sizeof(struct jazz_tlbmap));
|
||||
}
|
||||
|
||||
_bus_dmamap_destroy(t, map);
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: pckbc_jazzio.c,v 1.18 2008/03/15 13:23:24 cube Exp $ */
|
||||
/* $NetBSD: pckbc_jazzio.c,v 1.19 2020/11/18 02:14:13 thorpej Exp $ */
|
||||
/* NetBSD: pckbc_isa.c,v 1.2 2000/03/23 07:01:35 thorpej Exp */
|
||||
|
||||
/*
|
||||
@ -27,14 +27,14 @@
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: pckbc_jazzio.c,v 1.18 2008/03/15 13:23:24 cube Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: pckbc_jazzio.c,v 1.19 2020/11/18 02:14:13 thorpej Exp $");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/systm.h>
|
||||
#include <sys/kernel.h>
|
||||
#include <sys/proc.h>
|
||||
#include <sys/device.h>
|
||||
#include <sys/malloc.h>
|
||||
#include <sys/kmem.h>
|
||||
#include <sys/errno.h>
|
||||
#include <sys/queue.h>
|
||||
#include <sys/bus.h>
|
||||
@ -144,8 +144,8 @@ pckbc_jazzio_attach(device_t parent, device_t self, void *aux)
|
||||
bus_space_map(iot, PICA_KBCMDP, 1, 0, &ioh_c))
|
||||
panic("pckbc_attach: couldn't map");
|
||||
|
||||
t = malloc(sizeof(struct pckbc_internal), M_DEVBUF,
|
||||
M_WAITOK | M_ZERO);
|
||||
t = kmem_zalloc(sizeof(struct pckbc_internal),
|
||||
KM_SLEEP);
|
||||
t->t_iot = iot;
|
||||
t->t_ioh_d = ioh_d;
|
||||
t->t_ioh_c = ioh_c;
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: necpb.c,v 1.45 2020/07/07 03:38:45 thorpej Exp $ */
|
||||
/* $NetBSD: necpb.c,v 1.46 2020/11/18 02:14:13 thorpej Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1997, 1998 The NetBSD Foundation, Inc.
|
||||
@ -61,7 +61,7 @@
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: necpb.c,v 1.45 2020/07/07 03:38:45 thorpej Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: necpb.c,v 1.46 2020/11/18 02:14:13 thorpej Exp $");
|
||||
|
||||
#include "opt_pci.h"
|
||||
|
||||
@ -71,7 +71,7 @@ __KERNEL_RCSID(0, "$NetBSD: necpb.c,v 1.45 2020/07/07 03:38:45 thorpej Exp $");
|
||||
#include <sys/systm.h>
|
||||
#include <sys/errno.h>
|
||||
#include <sys/device.h>
|
||||
#include <sys/malloc.h>
|
||||
#include <sys/kmem.h>
|
||||
#include <sys/extent.h>
|
||||
|
||||
#include <uvm/uvm_extern.h>
|
||||
@ -416,7 +416,7 @@ necpb_intr_establish(pci_chipset_tag_t pc, pci_intr_handle_t ih, int level,
|
||||
if (ih >= 4)
|
||||
panic("%s: bogus handle", __func__);
|
||||
|
||||
n = malloc(sizeof(struct necpb_intrhand), M_DEVBUF, M_WAITOK);
|
||||
n = kmem_alloc(sizeof(*n), KM_SLEEP);
|
||||
n->ih_func = func;
|
||||
n->ih_arg = arg;
|
||||
n->ih_next = NULL;
|
||||
@ -470,7 +470,7 @@ necpb_intr_disestablish(pci_chipset_tag_t pc, void *cookie)
|
||||
|
||||
evcnt_detach(&n->ih_evcnt);
|
||||
|
||||
free(n, M_DEVBUF);
|
||||
kmem_free(n, sizeof(*n));
|
||||
}
|
||||
|
||||
/*
|
||||
|
Loading…
Reference in New Issue
Block a user