2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (c) 2012 EMC Corp.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 #ifndef _SYS_MEMDESC_H_
32 #define _SYS_MEMDESC_H_
35 struct bus_dma_segment;
41 * struct memdesc encapsulates various memory descriptors and provides
42 * abstract access to them.
48 struct bus_dma_segment *md_list;
54 size_t md_opaque; /* type specific data. */
55 uint32_t md_type; /* Type of memory. */
58 #define MEMDESC_VADDR 1 /* Contiguous virtual address. */
59 #define MEMDESC_PADDR 2 /* Contiguous physical address. */
60 #define MEMDESC_VLIST 3 /* scatter/gather list of kva addresses. */
61 #define MEMDESC_PLIST 4 /* scatter/gather list of physical addresses. */
62 #define MEMDESC_BIO 5 /* Pointer to a bio (block io). */
63 #define MEMDESC_UIO 6 /* Pointer to a uio (any io). */
64 #define MEMDESC_MBUF 7 /* Pointer to a mbuf (network io). */
65 #define MEMDESC_CCB 8 /* Cam control block. (scsi/ata io). */
67 static inline struct memdesc
68 memdesc_vaddr(void *vaddr, size_t len)
72 mem.u.md_vaddr = vaddr;
74 mem.md_type = MEMDESC_VADDR;
79 static inline struct memdesc
80 memdesc_paddr(vm_paddr_t paddr, size_t len)
84 mem.u.md_paddr = paddr;
86 mem.md_type = MEMDESC_PADDR;
91 static inline struct memdesc
92 memdesc_vlist(struct bus_dma_segment *vlist, int sglist_cnt)
96 mem.u.md_list = vlist;
97 mem.md_opaque = sglist_cnt;
98 mem.md_type = MEMDESC_VLIST;
103 static inline struct memdesc
104 memdesc_plist(struct bus_dma_segment *plist, int sglist_cnt)
108 mem.u.md_list = plist;
109 mem.md_opaque = sglist_cnt;
110 mem.md_type = MEMDESC_PLIST;
115 static inline struct memdesc
116 memdesc_bio(struct bio *bio)
121 mem.md_type = MEMDESC_BIO;
126 static inline struct memdesc
127 memdesc_uio(struct uio *uio)
132 mem.md_type = MEMDESC_UIO;
137 static inline struct memdesc
138 memdesc_mbuf(struct mbuf *mbuf)
142 mem.u.md_mbuf = mbuf;
143 mem.md_type = MEMDESC_MBUF;
148 static inline struct memdesc
149 memdesc_ccb(union ccb *ccb)
154 mem.md_type = MEMDESC_CCB;
158 #endif /* _SYS_MEMDESC_H_ */