diff options
author | Theo de Raadt <deraadt@cvs.openbsd.org> | 2000-04-19 00:10:36 +0000 |
---|---|---|
committer | Theo de Raadt <deraadt@cvs.openbsd.org> | 2000-04-19 00:10:36 +0000 |
commit | 4225f252a321afbf9d199efead577c6a9081055f (patch) | |
tree | 3b38611e642a094870ceeba8caa49f8af384e963 /sys/crypto | |
parent | 22e40391ab28576c053e63b2d852fa85d8cd90bc (diff) |
split out mbuf scatter gather function
Diffstat (limited to 'sys/crypto')
-rw-r--r-- | sys/crypto/crypto.h | 3 | ||||
-rw-r--r-- | sys/crypto/mbuf.c | 110 |
2 files changed, 113 insertions, 0 deletions
diff --git a/sys/crypto/crypto.h b/sys/crypto/crypto.h index f4515fb6abb..9e3d688acab 100644 --- a/sys/crypto/crypto.h +++ b/sys/crypto/crypto.h @@ -157,6 +157,9 @@ extern int crypto_register(u_int32_t, int, void *, void *, void *); extern int crypto_unregister(u_int32_t, int); extern int32_t crypto_get_driverid(void); +struct mbuf; +int mbuf2pages(struct mbuf *, int *, long *, int *, int, int *); + extern struct cryptop *crypto_getreq(int); extern void crypto_freereq(struct cryptop *); #endif /* _KERNEL */ diff --git a/sys/crypto/mbuf.c b/sys/crypto/mbuf.c new file mode 100644 index 00000000000..3ac7ebcc405 --- /dev/null +++ b/sys/crypto/mbuf.c @@ -0,0 +1,110 @@ +/* $OpenBSD: mbuf.c,v 1.1 2000/04/19 00:10:35 deraadt Exp $ */ + +/* + * Copyright (c) 1999 Theo de Raadt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include <sys/param.h> +#include <sys/systm.h> +#include <sys/proc.h> +#include <sys/errno.h> +#include <sys/malloc.h> +#include <sys/kernel.h> +#include <sys/mbuf.h> +#include <vm/vm.h> +#include <vm/vm_extern.h> +#include <vm/pmap.h> +#include <machine/pmap.h> + +#include <crypto/crypto.h> + +int +mbuf2pages(m, np, pp, lp, maxp, nicep) + struct mbuf *m; + int *np; + long *pp; + int *lp; + int maxp; + int *nicep; +{ + struct mbuf *m0; + int npa = 0, tlen = 0; + + /* generate a [pa,len] array from an mbuf */ + for (m0 = m; m; m = m->m_next) { + void *va; + long pg, npg; + int len, off; + + if (m->m_len == 0) + continue; + len = m->m_len; + tlen += len; + va = m->m_data; + + lp[npa] = len; + pp[npa] = vtophys(va); + pg = pp[npa] & ~PAGE_MASK; + off = (long)va & PAGE_MASK; + + while (len + off > PAGE_SIZE) { + va = va + PAGE_SIZE - off; + npg = vtophys(va); + if (npg != pg) { + /* FUCKED UP condition */ + if (++npa > maxp) + return (0); + continue; + } + lp[npa] = PAGE_SIZE - off; + off = 0; + + if (++npa > maxp) + return (0); + + lp[npa] = len - (PAGE_SIZE - off); + len -= lp[npa]; + pp[npa] = vtophys(va); + } + + if (++npa == maxp) + return (0); + } + + if (nicep) { + int nice = 1; + int i; + + /* see if each [pa,len] entry is long-word aligned */ + for (i = 0; i < npa; i++) + if ((lp[i] & 3) || (pp[i] & 3)) + nice = 0; + *nicep = nice; + } + + *np = npa; + return (tlen); +} |