pci_alloc_msix: Fail if no MSI-X vectors available
[dragonfly.git] / sys / sys / msfbuf.h
CommitLineData
321f1ae2 1/*
a5d36a1d 2 * Copyright (c) 2004,2005 The DragonFly Project. All rights reserved.
d6a46bb7 3 *
321f1ae2
HP
4 * This code is derived from software contributed to The DragonFly Project
5 * by Hiten Pandya <hmp@backplane.com> and Matthew Dillon
6 * <dillon@backplane.com>.
d6a46bb7
MD
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
d6a46bb7
MD
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in
16 * the documentation and/or other materials provided with the
17 * distribution.
321f1ae2
HP
18 * 3. Neither the name of The DragonFly Project nor the names of its
19 * contributors may be used to endorse or promote products derived
20 * from this software without specific, prior written permission.
d6a46bb7
MD
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
321f1ae2
HP
26 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27 * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
30 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
31 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
32 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * SUCH DAMAGE.
d6a46bb7
MD
34 *
35 * The MSF_BUF API is an augmentation similar to the SFBUF APIs and uses XIO
36 * page array handling. The SFBUF API originally came from:
37 *
38 * Copyright (c) 2003 Alan L. Cox <alc@cs.rice.edu>. All rights reserved.
39 * Copyright (c) 1998 David Greenman. All rights reserved.
40 * src/sys/sys/sfbuf.h,v 1.4 2004/04/01 17:58:06 dillon
41 *
03d6a592 42 * $DragonFly: src/sys/sys/msfbuf.h,v 1.12 2006/05/21 03:43:47 dillon Exp $
d6a46bb7
MD
43 */
44#ifndef _SYS_MSFBUF_H_
45#define _SYS_MSFBUF_H_
46
8f8e7e4d 47#if !defined(_KERNEL) && !defined(_KERNEL_STRUCTURES)
03d6a592 48
8f8e7e4d 49#error "This file should not be included by userland programs."
03d6a592
MD
50
51#else
8f8e7e4d 52
82d586ee
HP
53#ifndef _SYS_QUEUE_H_
54#include <sys/queue.h>
55#endif
56
57#ifndef _SYS_XIO_H_
58#include <sys/xio.h>
59#endif
60
67437519
HP
61#if defined(MALLOC_DECLARE)
62MALLOC_DECLARE(M_MSFBUF);
63#endif
64
d6a46bb7
MD
65/*
66 * MSF_BUFs are used for caching ephermal mappings that span more than
67 * one page.
68 *
69 * The interface returns an msf_buf data structure which has information
70 * about managing the ephermal mapping, its KVA pointer and an embedded
71 * XIO structure which describes the mapping.
72 *
73 * The embedded XIO structure be passed around to the DEV system because
74 * it is ref-counted; thus making it perfectly usable by anything that
75 * can accept an XIO as a transfer unit, most notably the buffer-cache
76 * and the XIO API.
77 *
78 */
79
a5d36a1d
MD
80/*
81 * Type of mapping.
82 *
83 * MSF_TYPE_PGLIST - mapping based on raw list of pages.
84 * MSF_TYPE_XIO - mapping based on an XIO.
85 * MSF_TYPE_UBUF - mapping based on an arbitrary user buffer.
86 * MSF_TYPE_KBUF - mapping based on an arbitrary kernel buffer.
87 */
88enum msf_type { MSF_TYPE_UNKNOWN, MSF_TYPE_PGLIST, MSF_TYPE_XIO,
89 MSF_TYPE_UBUF, MSF_TYPE_KBUF };
90
d6a46bb7 91struct msf_buf {
a5d36a1d
MD
92 TAILQ_ENTRY(msf_buf) free_list; /* free list of buffers */
93 vm_offset_t ms_kva; /* KVA offset */
94 cpumask_t ms_cpumask; /* CPU mask for synchronization */
95 struct xio *ms_xio; /* xio being used */
96 struct xio ms_internal_xio;/* xio embedded */
97 int ms_refcnt; /* map usage tracking */
98 int ms_flags; /* control flags */
99 enum msf_type ms_type; /* type of mapped data */
d6a46bb7
MD
100};
101
a5d36a1d
MD
102/* Flags. */
103#define MSF_ONFREEQ 0x0001 /* currently on the freelist */
104#define MSF_CATCH 0x0004 /* allow interruption */
105#define MSF_CPUPRIVATE 0x0008 /* sync mapping to current cpu only */
106
cfd344cb
HP
107typedef struct msf_buf *msf_t;
108
d6a46bb7
MD
109#if defined(_KERNEL)
110
111/*
112 * Return a KVA offset to the client
113 */
114static __inline
cbd36190 115char *
d6a46bb7
MD
116msf_buf_kva(struct msf_buf *msf)
117{
cbd36190 118 return ((char *)msf->ms_kva + msf->ms_xio->xio_offset);
d6a46bb7
MD
119}
120
258f3612
MD
121static __inline
122int
123msf_buf_bytes(struct msf_buf *msf)
124{
125 return (msf->ms_xio->xio_bytes);
126}
127
d6a46bb7
MD
128/*
129 * Return a reference to the underlying pages of an MSF_BUF
130 */
131static __inline
a5d36a1d 132struct vm_page **
d6a46bb7
MD
133msf_buf_pages(struct msf_buf *msf)
134{
a5d36a1d 135 return (msf->ms_xio->xio_pages);
d6a46bb7
MD
136}
137
d6a46bb7 138/* API function prototypes */
a5d36a1d
MD
139int msf_map_pagelist(struct msf_buf **, struct vm_page **, int, int);
140int msf_map_xio(struct msf_buf **, struct xio *, int);
141int msf_map_ubuf(struct msf_buf **, void *, size_t, int);
142int msf_map_kbuf(struct msf_buf **, void *, size_t, int);
cbd36190
MD
143int msf_uio_iterate(struct uio *uio,
144 int (*callback)(void *info, char *buf, int bytes), void *info);
7808a32c
HP
145void msf_buf_free(struct msf_buf *);
146void msf_buf_ref(struct msf_buf *);
d6a46bb7 147
03d6a592
MD
148#endif /* _KERNEL */
149#endif /* _KERNEL || _KERNEL_STRUCTURES */
150#endif /* _SYS_MSFBUF_H_ */