1 | #ifndef __SOUND_PCM_SGBUF_H
|
---|
2 | #define __SOUND_PCM_SGBUF_H
|
---|
3 |
|
---|
4 | /*
|
---|
5 | * Scatter-Gather PCM access
|
---|
6 | *
|
---|
7 | * Copyright (c) by Takashi Iwai <tiwai@suse.de>
|
---|
8 | *
|
---|
9 | * This program is free software; you can redistribute it and/or modify
|
---|
10 | * it under the terms of the GNU General Public License as published by
|
---|
11 | * the Free Software Foundation; either version 2 of the License, or
|
---|
12 | * (at your option) any later version.
|
---|
13 | *
|
---|
14 | * This program is distributed in the hope that it will be useful,
|
---|
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
17 | * GNU General Public License for more details.
|
---|
18 | *
|
---|
19 | * You should have received a copy of the GNU General Public License
|
---|
20 | * along with this program; if not, write to the Free Software
|
---|
21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
---|
22 | *
|
---|
23 | */
|
---|
24 | /*
|
---|
25 | * buffer device info
|
---|
26 | */
|
---|
27 | struct snd_dma_device {
|
---|
28 | int type; /* SNDRV_MEM_TYPE_XXX */
|
---|
29 | union {
|
---|
30 | struct pci_dev *pci; /* for PCI and PCI-SG types */
|
---|
31 | unsigned int flags; /* GFP_XXX for continous and ISA types */
|
---|
32 | #ifdef CONFIG_SBUS
|
---|
33 | struct sbus_dev *sbus; /* for SBUS type */
|
---|
34 | #endif
|
---|
35 | } dev;
|
---|
36 | unsigned int id; /* a unique ID */
|
---|
37 | };
|
---|
38 |
|
---|
39 | /*
|
---|
40 | * buffer types
|
---|
41 | */
|
---|
42 | #define SNDRV_DMA_TYPE_UNKNOWN 0 /* not defined */
|
---|
43 | #define SNDRV_DMA_TYPE_CONTINUOUS 1 /* continuous no-DMA memory */
|
---|
44 | #define SNDRV_DMA_TYPE_ISA 2 /* ISA continuous */
|
---|
45 | #define SNDRV_DMA_TYPE_PCI 3 /* PCI continuous */
|
---|
46 | #define SNDRV_DMA_TYPE_SBUS 4 /* SBUS continuous */
|
---|
47 | #define SNDRV_DMA_TYPE_PCI_SG 5 /* PCI SG-buffer */
|
---|
48 |
|
---|
49 | #ifdef CONFIG_PCI
|
---|
50 | /*
|
---|
51 | * compose a snd_dma_device struct for the PCI device
|
---|
52 | */
|
---|
53 | static inline void snd_dma_device_pci(struct snd_dma_device *dev, struct pci_dev *pci, unsigned int id)
|
---|
54 | {
|
---|
55 | memset(dev, 0, sizeof(*dev));
|
---|
56 | dev->type = SNDRV_DMA_TYPE_PCI;
|
---|
57 | dev->dev.pci = pci;
|
---|
58 | dev->id = id;
|
---|
59 | }
|
---|
60 | #endif
|
---|
61 |
|
---|
62 |
|
---|
63 | /*
|
---|
64 | * info for buffer allocation
|
---|
65 | */
|
---|
66 | struct snd_dma_buffer {
|
---|
67 | unsigned char *area; /* virtual pointer */
|
---|
68 | dma_addr_t addr; /* physical address */
|
---|
69 | size_t bytes; /* buffer size in bytes */
|
---|
70 | void *private_data; /* private for allocator; don't touch */
|
---|
71 | };
|
---|
72 |
|
---|
73 | struct snd_sg_page {
|
---|
74 | void *buf;
|
---|
75 | dma_addr_t addr;
|
---|
76 | };
|
---|
77 |
|
---|
78 | struct snd_sg_buf {
|
---|
79 | int size; /* allocated byte size (= runtime->dma_bytes) */
|
---|
80 | int pages; /* allocated pages */
|
---|
81 | int tblsize; /* allocated table size */
|
---|
82 | struct snd_sg_page *table;
|
---|
83 | struct pci_dev *pci;
|
---|
84 | };
|
---|
85 |
|
---|
86 | typedef struct snd_sg_buf snd_pcm_sgbuf_t; /* for magic cast */
|
---|
87 |
|
---|
88 | /*
|
---|
89 | * return the pages matching with the given byte size
|
---|
90 | */
|
---|
91 | static inline unsigned int snd_pcm_sgbuf_pages(size_t size)
|
---|
92 | {
|
---|
93 | return (size + PAGE_SIZE - 1) >> PAGE_SHIFT;
|
---|
94 | }
|
---|
95 |
|
---|
96 | /*
|
---|
97 | * return the physical address at the corresponding offset
|
---|
98 | */
|
---|
99 | static inline dma_addr_t snd_pcm_sgbuf_get_addr(struct snd_sg_buf *sgbuf, size_t offset)
|
---|
100 | {
|
---|
101 | return sgbuf->table[offset >> PAGE_SHIFT].addr + offset % PAGE_SIZE;
|
---|
102 | }
|
---|
103 |
|
---|
104 | int snd_pcm_sgbuf_init(snd_pcm_substream_t *substream, struct pci_dev *pci, int tblsize);
|
---|
105 | int snd_pcm_sgbuf_delete(snd_pcm_substream_t *substream);
|
---|
106 | int snd_pcm_sgbuf_alloc(snd_pcm_substream_t *substream, size_t size);
|
---|
107 | int snd_pcm_sgbuf_free(snd_pcm_substream_t *substream);
|
---|
108 |
|
---|
109 | int snd_pcm_sgbuf_ops_copy_playback(snd_pcm_substream_t *substream, int channel, snd_pcm_uframes_t hwoff, void *buf, snd_pcm_uframes_t count);
|
---|
110 | int snd_pcm_sgbuf_ops_copy_capture(snd_pcm_substream_t *substream, int channel, snd_pcm_uframes_t hwoff, void *buf, snd_pcm_uframes_t count);
|
---|
111 | int snd_pcm_sgbuf_ops_silence(snd_pcm_substream_t *substream, int channel, snd_pcm_uframes_t hwoff, snd_pcm_uframes_t count);
|
---|
112 | void *snd_pcm_sgbuf_ops_page(snd_pcm_substream_t *substream, unsigned long offset);
|
---|
113 |
|
---|
114 |
|
---|
115 | #endif /* __SOUND_PCM_SGBUF_H */
|
---|