source: GPL/alsa-kernel/include/sound/memalloc.h@ 18

Last change on this file since 18 was 18, checked in by vladest, 20 years ago

initial import

File size: 5.7 KB
Line 
1/*
2 * Copyright (c) by Jaroslav Kysela <perex@suse.cz>
3 * Takashi Iwai <tiwai@suse.de>
4 *
5 * Generic memory allocators
6 *
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 *
22 */
23
24#ifndef __SOUND_MEMALLOC_H
25#define __SOUND_MEMALLOC_H
26
27#include <linux/pci.h>
28#ifdef CONFIG_SBUS
29#include <asm/sbus.h>
30#endif
31
32#if 0
33typedef struct device {
34 struct pci_dev *pci; /* for PCI and PCI-SG types */
35 unsigned int flags; /* GFP_XXX for continous and ISA types */
36#ifdef CONFIG_SBUS
37 struct sbus_dev *sbus; /* for SBUS type */
38#endif
39} device;
40#endif
41/*
42 * buffer device info
43 */
44struct snd_dma_device {
45 int type; /* SNDRV_DMA_TYPE_XXX */
46 struct device *dev;
47};
48
49#ifndef snd_dma_pci_data
50#define snd_dma_pci_data(pci) (&(pci)->dev)
51#define snd_dma_isa_data() NULL
52#define snd_dma_sbus_data(sbus) ((struct device *)(sbus))
53#define snd_dma_continuous_data(x) ((struct device *)(unsigned long)(x))
54#endif
55
56/*
57 * buffer types
58 */
59#define SNDRV_DMA_TYPE_UNKNOWN 0 /* not defined */
60#define SNDRV_DMA_TYPE_CONTINUOUS 1 /* continuous no-DMA memory */
61#define SNDRV_DMA_TYPE_DEV 2 /* generic device continuous */
62#define SNDRV_DMA_TYPE_DEV_SG 3 /* generic device SG-buffer */
63#define SNDRV_DMA_TYPE_SBUS 4 /* SBUS continuous */
64#define SNDRV_DMA_TYPE_PCI_SG 5 /* PCI SG-buffer */
65
66#define __GFP_NOWARN 0
67
68/*
69 * info for buffer allocation
70 */
71struct snd_dma_buffer {
72 struct snd_dma_device dev; /* device type */
73 unsigned char *area; /* virtual pointer */
74 dma_addr_t addr; /* physical address */
75 size_t bytes; /* buffer size in bytes */
76 void *private_data; /* private for allocator; don't touch */
77};
78
79/* allocate/release a buffer */
80int snd_dma_alloc_pages(int type, struct device *dev, size_t size,
81 struct snd_dma_buffer *dmab);
82int snd_dma_alloc_pages_fallback(int type, struct device *dev, size_t size,
83 struct snd_dma_buffer *dmab);
84void snd_dma_free_pages(struct snd_dma_buffer *dmab);
85
86/* buffer-preservation managements */
87#define snd_dma_pci_buf_id(pci) (((unsigned int)(pci)->vendor << 16) | (pci)->device)
88size_t snd_dma_get_reserved_buf(struct snd_dma_buffer *dmab, unsigned int id);
89int snd_dma_reserve_buf(struct snd_dma_buffer *dmab, unsigned int id);
90
91/*
92 * Generic memory allocators
93 */
94
95/*
96 * continuous pages
97 */
98void *snd_malloc_pages(unsigned long size, unsigned int gfp_flags);
99void snd_free_pages(void *ptr, unsigned long size);
100
101#ifdef CONFIG_PCI
102/*
103 * PCI continuous pages
104 */
105void *snd_malloc_pci_pages(struct pci_dev *pci, size_t size, dma_addr_t *dma_addr);
106void *snd_malloc_pci_pages_fallback(struct pci_dev *pci, size_t size, dma_addr_t *dma_addr, size_t *res_size);
107void snd_free_pci_pages(struct pci_dev *pci, size_t size, void *ptr, dma_addr_t dma_addr);
108/* one page allocation */
109void *snd_malloc_pci_page(struct pci_dev *pci, dma_addr_t *dma_addr);
110#define snd_free_pci_page(pci,ptr,addr) snd_free_pci_pages(pci,PAGE_SIZE,ptr,addr)
111#endif
112
113#ifdef CONFIG_SBUS
114/*
115 * SBUS continuous pages
116 */
117void *snd_malloc_sbus_pages(struct sbus_dev *sdev, size_t size, dma_addr_t *dma_addr);
118void *snd_malloc_sbus_pages_fallback(struct sbus_dev *sdev, size_t size, dma_addr_t *dma_addr, size_t *res_size);
119void snd_free_sbus_pages(struct sbus_dev *sdev, size_t size, void *ptr, dma_addr_t dma_addr);
120#endif
121
122#ifdef CONFIG_ISA
123/*
124 * ISA continuous pages
125 */
126void *snd_malloc_isa_pages(size_t size, dma_addr_t *dma_addr);
127void *snd_malloc_isa_pages_fallback(size_t size, dma_addr_t *dma_addr, size_t *res_size);
128void snd_free_isa_pages(size_t size, void *ptr, dma_addr_t addr);
129#ifdef CONFIG_PCI
130#define snd_malloc_isa_pages(size, dma_addr) snd_malloc_pci_pages(NULL, size, dma_addr)
131#define snd_malloc_isa_pages_fallback(size, dma_addr, res_size) snd_malloc_pci_pages_fallback(NULL, size, dma_addr, res_size)
132#define snd_free_isa_pages(size, ptr, dma_addr) snd_free_pci_pages(NULL, size, ptr, dma_addr)
133#else /* !CONFIG_PCI */
134#define snd_free_isa_pages(size, ptr, dma_addr) snd_free_pages(ptr, size)
135#endif /* CONFIG_PCI */
136#endif /* CONFIG_ISA */
137
138#ifdef CONFIG_PCI
139/*
140 * Scatter-Gather PCI pages
141 */
142struct snd_sg_page {
143 void *buf;
144 dma_addr_t addr;
145};
146
147struct snd_sg_buf {
148 int size; /* allocated byte size */
149 int pages; /* allocated pages */
150 int tblsize; /* allocated table size */
151 struct snd_sg_page *table; /* address table */
152 struct page **page_table; /* page table (for vmap/vunmap) */
153 struct pci_dev *pci;
154};
155
156/*
157 * return the pages matching with the given byte size
158 */
159static inline unsigned int snd_sgbuf_aligned_pages(size_t size)
160{
161 return (size + PAGE_SIZE - 1) >> PAGE_SHIFT;
162}
163
164/*
165 * return the physical address at the corresponding offset
166 */
167static inline dma_addr_t snd_sgbuf_get_addr(struct snd_sg_buf *sgbuf, size_t offset)
168{
169 return sgbuf->table[offset >> PAGE_SHIFT].addr + offset % PAGE_SIZE;
170}
171#endif /* CONFIG_PCI */
172
173#endif /* __SOUND_MEMALLOC_H */
Note: See TracBrowser for help on using the repository browser.