15c5185aeSSamuel J. Greear /*
25c5185aeSSamuel J. Greear * Copyright (c) 2010 by The DragonFly Project and Samuel J. Greear.
35c5185aeSSamuel J. Greear * All rights reserved.
45c5185aeSSamuel J. Greear *
55c5185aeSSamuel J. Greear * This code is derived from software contributed to The DragonFly Project
65c5185aeSSamuel J. Greear * by Samuel J. Greear <sjg@thesjg.com>
75c5185aeSSamuel J. Greear *
85c5185aeSSamuel J. Greear * Redistribution and use in source and binary forms, with or without
95c5185aeSSamuel J. Greear * modification, are permitted provided that the following conditions
105c5185aeSSamuel J. Greear * are met:
115c5185aeSSamuel J. Greear *
125c5185aeSSamuel J. Greear * 1. Redistributions of source code must retain the above copyright
135c5185aeSSamuel J. Greear * notice, this list of conditions and the following disclaimer.
145c5185aeSSamuel J. Greear * 2. Redistributions in binary form must reproduce the above copyright
155c5185aeSSamuel J. Greear * notice, this list of conditions and the following disclaimer in
165c5185aeSSamuel J. Greear * the documentation and/or other materials provided with the
175c5185aeSSamuel J. Greear * distribution.
185c5185aeSSamuel J. Greear * 3. Neither the name of The DragonFly Project nor the names of its
195c5185aeSSamuel J. Greear * contributors may be used to endorse or promote products derived
205c5185aeSSamuel J. Greear * from this software without specific, prior written permission.
215c5185aeSSamuel J. Greear *
225c5185aeSSamuel J. Greear * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
235c5185aeSSamuel J. Greear * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
245c5185aeSSamuel J. Greear * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
255c5185aeSSamuel J. Greear * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
265c5185aeSSamuel J. Greear * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
275c5185aeSSamuel J. Greear * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
285c5185aeSSamuel J. Greear * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
295c5185aeSSamuel J. Greear * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
305c5185aeSSamuel J. Greear * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
315c5185aeSSamuel J. Greear * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
325c5185aeSSamuel J. Greear * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
335c5185aeSSamuel J. Greear * SUCH DAMAGE.
345c5185aeSSamuel J. Greear */
355c5185aeSSamuel J. Greear
365c5185aeSSamuel J. Greear #ifndef _CPU_LWBUF_H_
375c5185aeSSamuel J. Greear #define _CPU_LWBUF_H_
385c5185aeSSamuel J. Greear
395c5185aeSSamuel J. Greear #ifndef _SYS_TYPES_H_
405c5185aeSSamuel J. Greear #include <sys/types.h>
415c5185aeSSamuel J. Greear #endif
425c5185aeSSamuel J. Greear #ifndef _SYS_GLOBALDATA_H_
435c5185aeSSamuel J. Greear #include <sys/globaldata.h>
445c5185aeSSamuel J. Greear #endif
455c5185aeSSamuel J. Greear #ifndef _VM_PMAP_H_
465c5185aeSSamuel J. Greear #include <vm/pmap.h>
475c5185aeSSamuel J. Greear #endif
4846751036SSamuel J. Greear #ifndef _VM_VM_PAGE_H_
4946751036SSamuel J. Greear #include <vm/vm_page.h>
5046751036SSamuel J. Greear #endif
515c5185aeSSamuel J. Greear #include <machine/atomic.h>
527a683a24SMatthew Dillon #ifndef _MACHINE_VMPARAM_H_
537a683a24SMatthew Dillon #include <machine/vmparam.h>
547a683a24SMatthew Dillon #endif
555c5185aeSSamuel J. Greear
565c5185aeSSamuel J. Greear #if !defined(_KERNEL) && !defined(_KERNEL_STRUCTURES)
575c5185aeSSamuel J. Greear #error "This file should not be included by userland programs."
585c5185aeSSamuel J. Greear #endif
595c5185aeSSamuel J. Greear
605c5185aeSSamuel J. Greear struct lwbuf {
615c5185aeSSamuel J. Greear vm_page_t m; /* currently mapped page */
625c5185aeSSamuel J. Greear vm_offset_t kva; /* va of mapping */
635c5185aeSSamuel J. Greear };
645c5185aeSSamuel J. Greear
655c5185aeSSamuel J. Greear static __inline vm_page_t
lwbuf_page(struct lwbuf * lwb)667a683a24SMatthew Dillon lwbuf_page(struct lwbuf *lwb)
677a683a24SMatthew Dillon {
685c5185aeSSamuel J. Greear return (lwb->m);
695c5185aeSSamuel J. Greear }
705c5185aeSSamuel J. Greear
715c5185aeSSamuel J. Greear static __inline vm_offset_t
lwbuf_kva(struct lwbuf * lwb)727a683a24SMatthew Dillon lwbuf_kva(struct lwbuf *lwb)
737a683a24SMatthew Dillon {
745c5185aeSSamuel J. Greear return (lwb->kva);
755c5185aeSSamuel J. Greear }
765c5185aeSSamuel J. Greear
777a683a24SMatthew Dillon static __inline struct lwbuf *
lwbuf_alloc(vm_page_t m,struct lwbuf * lwb_cache)787a683a24SMatthew Dillon lwbuf_alloc(vm_page_t m, struct lwbuf *lwb_cache)
797a683a24SMatthew Dillon {
807a683a24SMatthew Dillon struct lwbuf *lwb = lwb_cache;
817a683a24SMatthew Dillon
827a683a24SMatthew Dillon lwb->m = m;
837a683a24SMatthew Dillon lwb->kva = PHYS_TO_DMAP(VM_PAGE_TO_PHYS(lwb->m));
847a683a24SMatthew Dillon
857a683a24SMatthew Dillon return (lwb);
867a683a24SMatthew Dillon }
877a683a24SMatthew Dillon
887a683a24SMatthew Dillon static __inline void
lwbuf_free(struct lwbuf * lwb)897a683a24SMatthew Dillon lwbuf_free(struct lwbuf *lwb)
907a683a24SMatthew Dillon {
917a683a24SMatthew Dillon lwb->m = NULL; /* safety */
927a683a24SMatthew Dillon }
937a683a24SMatthew Dillon
945c5185aeSSamuel J. Greear #define lwbuf_set_global(lwb)
955c5185aeSSamuel J. Greear
96*68ad1455SMatthew Dillon /* tell the kernel that lwbufs are cheap */
97*68ad1455SMatthew Dillon #define LWBUF_IS_OPTIMAL
98*68ad1455SMatthew Dillon
995c5185aeSSamuel J. Greear #if defined(_KERNEL)
1005c5185aeSSamuel J. Greear
1015c5185aeSSamuel J. Greear #endif
1025c5185aeSSamuel J. Greear
1035c5185aeSSamuel J. Greear #endif /* !_CPU_LWBUF_H_ */
104