2 * Copyright (c) 2012 EMC Corp.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 #ifndef _SYS_MEMDESC_H_
30 #define _SYS_MEMDESC_H_
33 struct bus_dma_segment;
39 * struct memdesc encapsulates various memory descriptors and provides
40 * abstract access to them.
46 struct bus_dma_segment *md_list;
52 size_t md_opaque; /* type specific data. */
53 uint32_t md_type; /* Type of memory. */
56 #define MEMDESC_VADDR 1 /* Contiguous virtual address. */
57 #define MEMDESC_PADDR 2 /* Contiguous physical address. */
58 #define MEMDESC_VLIST 3 /* scatter/gather list of kva addresses. */
59 #define MEMDESC_PLIST 4 /* scatter/gather list of physical addresses. */
60 #define MEMDESC_BIO 5 /* Pointer to a bio (block io). */
61 #define MEMDESC_UIO 6 /* Pointer to a uio (any io). */
62 #define MEMDESC_MBUF 7 /* Pointer to a mbuf (network io). */
63 #define MEMDESC_CCB 8 /* Cam control block. (scsi/ata io). */
65 static inline struct memdesc
66 memdesc_vaddr(void *vaddr, size_t len)
70 mem.u.md_vaddr = vaddr;
72 mem.md_type = MEMDESC_VADDR;
77 static inline struct memdesc
78 memdesc_paddr(vm_paddr_t paddr, size_t len)
82 mem.u.md_paddr = paddr;
84 mem.md_type = MEMDESC_PADDR;
89 static inline struct memdesc
90 memdesc_vlist(struct bus_dma_segment *vlist, int sglist_cnt)
94 mem.u.md_list = vlist;
95 mem.md_opaque = sglist_cnt;
96 mem.md_type = MEMDESC_VLIST;
101 static inline struct memdesc
102 memdesc_plist(struct bus_dma_segment *plist, int sglist_cnt)
106 mem.u.md_list = plist;
107 mem.md_opaque = sglist_cnt;
108 mem.md_type = MEMDESC_PLIST;
113 static inline struct memdesc
114 memdesc_bio(struct bio *bio)
119 mem.md_type = MEMDESC_BIO;
124 static inline struct memdesc
125 memdesc_uio(struct uio *uio)
130 mem.md_type = MEMDESC_UIO;
135 static inline struct memdesc
136 memdesc_mbuf(struct mbuf *mbuf)
140 mem.u.md_mbuf = mbuf;
141 mem.md_type = MEMDESC_MBUF;
146 static inline struct memdesc
147 memdesc_ccb(union ccb *ccb)
152 mem.md_type = MEMDESC_CCB;
156 #endif /* _SYS_MEMDESC_H_ */