xref: /dflybsd-src/sys/cpu/x86_64/misc/lwbuf.c (revision 86d7f5d305c6adaa56ff4582ece9859d73106103)
186d7f5d3SJohn Marino /*
286d7f5d3SJohn Marino  * Copyright (c) 2010 by The DragonFly Project and Samuel J. Greear.
386d7f5d3SJohn Marino  * All rights reserved.
486d7f5d3SJohn Marino  *
586d7f5d3SJohn Marino  * This code is derived from software contributed to The DragonFly Project
686d7f5d3SJohn Marino  * by Samuel J. Greear <sjg@thesjg.com>
786d7f5d3SJohn Marino  *
886d7f5d3SJohn Marino  * Redistribution and use in source and binary forms, with or without
986d7f5d3SJohn Marino  * modification, are permitted provided that the following conditions
1086d7f5d3SJohn Marino  * are met:
1186d7f5d3SJohn Marino  *
1286d7f5d3SJohn Marino  * 1. Redistributions of source code must retain the above copyright
1386d7f5d3SJohn Marino  *    notice, this list of conditions and the following disclaimer.
1486d7f5d3SJohn Marino  * 2. Redistributions in binary form must reproduce the above copyright
1586d7f5d3SJohn Marino  *    notice, this list of conditions and the following disclaimer in
1686d7f5d3SJohn Marino  *    the documentation and/or other materials provided with the
1786d7f5d3SJohn Marino  *    distribution.
1886d7f5d3SJohn Marino  * 3. Neither the name of The DragonFly Project nor the names of its
1986d7f5d3SJohn Marino  *    contributors may be used to endorse or promote products derived
2086d7f5d3SJohn Marino  *    from this software without specific, prior written permission.
2186d7f5d3SJohn Marino  *
2286d7f5d3SJohn Marino  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
2386d7f5d3SJohn Marino  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
2486d7f5d3SJohn Marino  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
2586d7f5d3SJohn Marino  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE
2686d7f5d3SJohn Marino  * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
2786d7f5d3SJohn Marino  * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
2886d7f5d3SJohn Marino  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
2986d7f5d3SJohn Marino  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
3086d7f5d3SJohn Marino  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
3186d7f5d3SJohn Marino  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
3286d7f5d3SJohn Marino  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3386d7f5d3SJohn Marino  * SUCH DAMAGE.
3486d7f5d3SJohn Marino  */
3586d7f5d3SJohn Marino 
3686d7f5d3SJohn Marino #include <sys/types.h>
3786d7f5d3SJohn Marino #include <sys/kernel.h>
3886d7f5d3SJohn Marino #include <sys/objcache.h>
3986d7f5d3SJohn Marino #include <sys/systm.h>
4086d7f5d3SJohn Marino #include <vm/vm.h>
4186d7f5d3SJohn Marino #include <vm/pmap.h>
4286d7f5d3SJohn Marino #include <vm/vm_extern.h>
4386d7f5d3SJohn Marino #include <vm/vm_kern.h>
4486d7f5d3SJohn Marino #include <vm/vm_page.h>
4586d7f5d3SJohn Marino #include <cpu/lwbuf.h>
4686d7f5d3SJohn Marino #include <machine/param.h>
4786d7f5d3SJohn Marino 
4886d7f5d3SJohn Marino #if 0
4986d7f5d3SJohn Marino /*
5086d7f5d3SJohn Marino  * NO LONGER USED - See inlines
5186d7f5d3SJohn Marino  */
5286d7f5d3SJohn Marino 
5386d7f5d3SJohn Marino static void lwbuf_init(void *);
5486d7f5d3SJohn Marino SYSINIT(sock_lwb, SI_BOOT2_MACHDEP, SI_ORDER_ANY, lwbuf_init, NULL);
5586d7f5d3SJohn Marino 
5686d7f5d3SJohn Marino static struct objcache *lwbuf_cache;
5786d7f5d3SJohn Marino 
5886d7f5d3SJohn Marino MALLOC_DEFINE(M_LWBUF, "lwbuf", "Lightweight buffers");
5986d7f5d3SJohn Marino struct objcache_malloc_args lwbuf_malloc_args = { sizeof(struct lwbuf), M_LWBUF };
6086d7f5d3SJohn Marino 
6186d7f5d3SJohn Marino 
6286d7f5d3SJohn Marino static boolean_t
6386d7f5d3SJohn Marino lwbuf_cache_ctor(void *obj, void *pdata, int ocflags)
6486d7f5d3SJohn Marino {
6586d7f5d3SJohn Marino     struct lwbuf *lwb = (struct lwbuf *)obj;
6686d7f5d3SJohn Marino 
6786d7f5d3SJohn Marino     lwb->m = NULL;
6886d7f5d3SJohn Marino     lwb->kva = 0;
6986d7f5d3SJohn Marino 
7086d7f5d3SJohn Marino     return (TRUE);
7186d7f5d3SJohn Marino }
7286d7f5d3SJohn Marino 
7386d7f5d3SJohn Marino static void
7486d7f5d3SJohn Marino lwbuf_init(void *arg)
7586d7f5d3SJohn Marino {
7686d7f5d3SJohn Marino     lwbuf_cache = objcache_create("lwbuf", 0, 0,
7786d7f5d3SJohn Marino 	lwbuf_cache_ctor, NULL, NULL,
7886d7f5d3SJohn Marino 	objcache_malloc_alloc, objcache_malloc_free,
7986d7f5d3SJohn Marino 	&lwbuf_malloc_args);
8086d7f5d3SJohn Marino }
8186d7f5d3SJohn Marino 
8286d7f5d3SJohn Marino #endif
8386d7f5d3SJohn Marino 
8486d7f5d3SJohn Marino #if 0
8586d7f5d3SJohn Marino /*
8686d7f5d3SJohn Marino  * NO LONGER USED - See inlines
8786d7f5d3SJohn Marino  */
8886d7f5d3SJohn Marino 
8986d7f5d3SJohn Marino struct lwbuf *
9086d7f5d3SJohn Marino lwbuf_alloc(vm_page_t m, struct lwbuf *lwb_cache)
9186d7f5d3SJohn Marino {
9286d7f5d3SJohn Marino     struct lwbuf *lwb = lwb_cache;
9386d7f5d3SJohn Marino 
9486d7f5d3SJohn Marino     lwb->m = m;
9586d7f5d3SJohn Marino     lwb->kva = PHYS_TO_DMAP(VM_PAGE_TO_PHYS(lwb->m));
9686d7f5d3SJohn Marino 
9786d7f5d3SJohn Marino     return (lwb);
9886d7f5d3SJohn Marino }
9986d7f5d3SJohn Marino 
10086d7f5d3SJohn Marino void
10186d7f5d3SJohn Marino lwbuf_free(struct lwbuf *lwb)
10286d7f5d3SJohn Marino {
10386d7f5d3SJohn Marino     lwb->m = NULL;	/* safety */
10486d7f5d3SJohn Marino }
10586d7f5d3SJohn Marino 
10686d7f5d3SJohn Marino #endif
107