1122780Salc/*-
2122780Salc * Copyright (c) 2003 Alan L. Cox <alc@cs.rice.edu>
3122780Salc * All rights reserved.
4122780Salc *
5122780Salc * Redistribution and use in source and binary forms, with or without
6122780Salc * modification, are permitted provided that the following conditions
7122780Salc * are met:
8122780Salc * 1. Redistributions of source code must retain the above copyright
9122780Salc *    notice, this list of conditions and the following disclaimer.
10122780Salc * 2. Redistributions in binary form must reproduce the above copyright
11122780Salc *    notice, this list of conditions and the following disclaimer in the
12122780Salc *    documentation and/or other materials provided with the distribution.
13122780Salc *
14122780Salc * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15122780Salc * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16122780Salc * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17122780Salc * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18122780Salc * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19122780Salc * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20122780Salc * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21122780Salc * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22122780Salc * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23122780Salc * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24122780Salc * SUCH DAMAGE.
25122780Salc *
26122780Salc * $FreeBSD: releng/10.3/sys/powerpc/include/sf_buf.h 255318 2013-09-06 17:44:13Z glebius $
27122780Salc */
28122780Salc
29122780Salc#ifndef _MACHINE_SF_BUF_H_
30122780Salc#define _MACHINE_SF_BUF_H_
31122780Salc
32128395Salc#include <vm/vm.h>
33128395Salc#include <vm/vm_param.h>
34128395Salc#include <vm/vm_page.h>
35190681Snwhitehorn#include <machine/md_var.h>
36176770Sraj#include <sys/queue.h>
37122780Salc
38176770Srajstruct vm_page;
39176770Sraj
40176770Srajstruct sf_buf {
41176770Sraj	LIST_ENTRY(sf_buf) list_entry;	/* list of buffers */
42176770Sraj	TAILQ_ENTRY(sf_buf) free_entry;	/* list of buffers */
43176770Sraj	struct		vm_page *m;	/* currently mapped page */
44176770Sraj	vm_offset_t	kva;		/* va of mapping */
45176770Sraj	int		ref_count;	/* usage of this mapping */
46176770Sraj};
47176770Sraj
48255318Sglebiusstruct sf_buf * sf_buf_alloc(struct vm_page *m, int flags);
49255318Sglebiusvoid sf_buf_free(struct sf_buf *sf);
50255318Sglebius
51190681Snwhitehorn/*
52190681Snwhitehorn * On 32-bit OEA, the only purpose for which sf_buf is used is to implement
53190681Snwhitehorn * an opaque pointer required by the machine-independent parts of the kernel.
54190681Snwhitehorn * That pointer references the vm_page that is "mapped" by the sf_buf.  The
55190681Snwhitehorn * actual mapping is provided by the direct virtual-to-physical mapping.
56190681Snwhitehorn *
57190681Snwhitehorn * On OEA64 and Book-E, we need to do something a little more complicated. Use
58190681Snwhitehorn * the runtime-detected hw_direct_map to pick between the two cases. Our
59190681Snwhitehorn * friends in vm_machdep.c will do the same to ensure nothing gets confused.
60190681Snwhitehorn */
61190681Snwhitehorn
62176770Srajstatic __inline vm_offset_t
63176770Srajsf_buf_kva(struct sf_buf *sf)
64176770Sraj{
65190681Snwhitehorn	if (hw_direct_map)
66190681Snwhitehorn		return (VM_PAGE_TO_PHYS((vm_page_t)sf));
67176770Sraj
68176770Sraj	return (sf->kva);
69176770Sraj}
70176770Sraj
71176770Srajstatic __inline struct vm_page *
72176770Srajsf_buf_page(struct sf_buf *sf)
73176770Sraj{
74190681Snwhitehorn	if (hw_direct_map)
75190681Snwhitehorn		return ((vm_page_t)sf);
76176770Sraj
77176770Sraj	return (sf->m);
78176770Sraj}
79176770Sraj
80122780Salc#endif /* !_MACHINE_SF_BUF_H_ */
81