Update of /cvsroot/alsa/alsa-kernel/include
In directory sc8-pr-cvs1:/tmp/cvs-serv30086/include

Modified Files:
        core.h driver.h pcm.h sndmagic.h 
Added Files:
        memalloc.h 
Removed Files:
        pcm_sgbuf.h 
Log Message:
more unified DMA allocation
- memory allocator is put into a separte independent module, snd-alloc-pages.
  it can be kept after other snd* modules unloaded, so that the big
  continuous pages can be held after reload.
- use size_t for the size type.



--- NEW FILE: memalloc.h ---
/*
 *  Copyright (c) by Jaroslav Kysela <[EMAIL PROTECTED]>
 *                   Takashi Iwai <[EMAIL PROTECTED]>
 * 
 *  Generic memory allocators
 *
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation; either version 2 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program; if not, write to the Free Software
 *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 *
 */

#ifndef __SOUND_MEMALLOC_H
#define __SOUND_MEMALLOC_H

#include <linux/pci.h>
#ifdef CONFIG_SBUS
#include <asm/sbus.h>
#endif

/*
 * buffer device info
 */
struct snd_dma_device {
        int type;                       /* SNDRV_MEM_TYPE_XXX */
        union {
                struct pci_dev *pci;    /* for PCI and PCI-SG types */
                unsigned int flags;     /* GFP_XXX for continous and ISA types */
#ifdef CONFIG_SBUS
                struct sbus_dev *sbus;  /* for SBUS type */
#endif
        } dev;
        unsigned int id;                /* a unique ID */
};

/*
 * buffer types
 */
#define SNDRV_DMA_TYPE_UNKNOWN          0       /* not defined */
#define SNDRV_DMA_TYPE_CONTINUOUS       1       /* continuous no-DMA memory */
#define SNDRV_DMA_TYPE_ISA              2       /* ISA continuous */
#define SNDRV_DMA_TYPE_PCI              3       /* PCI continuous */
#define SNDRV_DMA_TYPE_SBUS             4       /* SBUS continuous */
#define SNDRV_DMA_TYPE_PCI_SG           5       /* PCI SG-buffer */

#ifdef CONFIG_PCI
/*
 * compose a snd_dma_device struct for the PCI device
 */
static inline void snd_dma_device_pci(struct snd_dma_device *dev, struct pci_dev *pci, 
unsigned int id)
{
        memset(dev, 0, sizeof(*dev));
        dev->type = SNDRV_DMA_TYPE_PCI;
        dev->dev.pci = pci;
        dev->id = id;
}
#endif


/*
 * info for buffer allocation
 */
struct snd_dma_buffer {
        unsigned char *area;    /* virtual pointer */
        dma_addr_t addr;        /* physical address */
        size_t bytes;           /* buffer size in bytes */
        void *private_data;     /* private for allocator; don't touch */
};

/* allocate/release a buffer */
int snd_dma_alloc_pages(const struct snd_dma_device *dev, size_t size, struct 
snd_dma_buffer *dmab);
void snd_dma_free_pages(const struct snd_dma_device *dev, struct snd_dma_buffer *dmab);

/* buffer-preservation managements */
size_t snd_dma_get_reserved(const struct snd_dma_device *dev, struct snd_dma_buffer 
*dmab);
int snd_dma_free_reserved(const struct snd_dma_device *dev);
int snd_dma_set_reserved(const struct snd_dma_device *dev, struct snd_dma_buffer 
*dmab);


/*
 * Generic memory allocators
 */

/*
 * continuous pages
 */
void *snd_malloc_pages(size_t size, unsigned int gfp_flags);
void *snd_malloc_pages_fallback(size_t size, unsigned int gfp_flags, size_t *res_size);
void snd_free_pages(void *ptr, size_t size);

#ifdef CONFIG_PCI
/*
 * PCI continuous pages
 */
void *snd_malloc_pci_pages(struct pci_dev *pci, size_t size, dma_addr_t *dma_addr);
void *snd_malloc_pci_pages_fallback(struct pci_dev *pci, size_t size, dma_addr_t 
*dma_addr, size_t *res_size);
void snd_free_pci_pages(struct pci_dev *pci, size_t size, void *ptr, dma_addr_t 
dma_addr);
/* one page allocation */
void *snd_malloc_pci_page(struct pci_dev *pci, dma_addr_t *dma_addr);
#define snd_free_pci_page(pci,ptr,addr) snd_free_pci_pages(pci,PAGE_SIZE,ptr,addr)
#endif

#ifdef CONFIG_SBUS
/*
 * SBUS continuous pages
 */
void *snd_malloc_sbus_pages(struct sbus_dev *sdev, size_t size, dma_addr_t *dma_addr);
void *snd_malloc_sbus_pages_fallback(struct sbus_dev *sdev, size_t size, dma_addr_t 
*dma_addr, size_t *res_size);
void snd_free_sbus_pages(struct sbus_dev *sdev, size_t size, void *ptr, dma_addr_t 
dma_addr);
#endif

#ifdef CONFIG_ISA
/*
 * ISA continuous pages
 */
void *snd_malloc_isa_pages(size_t size, dma_addr_t *dma_addr);
void *snd_malloc_isa_pages_fallback(size_t size, dma_addr_t *dma_addr, size_t 
*res_size);
void snd_free_isa_pages(size_t size, void *ptr, dma_addr_t addr);
#ifdef CONFIG_PCI
#define snd_malloc_isa_pages(size, dma_addr) snd_malloc_pci_pages(NULL, size, dma_addr)
#define snd_malloc_isa_pages_fallback(size, dma_addr, res_size) 
snd_malloc_pci_pages_fallback(NULL, size, dma_addr, res_size)
#define snd_free_isa_pages(size, ptr, dma_addr) snd_free_pci_pages(NULL, size, ptr, 
dma_addr)
#else /* !CONFIG_PCI */
#define snd_free_isa_pages(size, ptr, dma_addr) snd_free_pages(ptr, size)
#endif /* CONFIG_PCI */
#endif /* CONFIG_ISA */

#ifdef CONFIG_PCI
/*
 * Scatter-Gather PCI pages
 */
struct snd_sg_page {
        void *buf;
        dma_addr_t addr;
};

struct snd_sg_buf {
        int size;       /* allocated byte size */
        int pages;      /* allocated pages */
        int tblsize;    /* allocated table size */
        struct snd_sg_page *table;      /* address table */
        struct page **page_table;       /* page table (for vmap/vunmap) */
        struct pci_dev *pci;
};

void *snd_malloc_sgbuf_pages(struct pci_dev *pci, size_t size, struct snd_dma_buffer 
*dmab);
int snd_free_sgbuf_pages(struct snd_dma_buffer *dmab);

/*
 * return the pages matching with the given byte size
 */
static inline unsigned int snd_sgbuf_aligned_pages(size_t size)
{
        return (size + PAGE_SIZE - 1) >> PAGE_SHIFT;
}

/*
 * return the physical address at the corresponding offset
 */
static inline dma_addr_t snd_sgbuf_get_addr(struct snd_sg_buf *sgbuf, size_t offset)
{
        return sgbuf->table[offset >> PAGE_SHIFT].addr + offset % PAGE_SIZE;
}
#endif /* CONFIG_PCI */


/*
 * wrappers
 */
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 4, 0)
#ifdef CONFIG_PCI
#if defined(__i386__) || defined(__ppc__) || defined(__x86_64__)
#define HACK_PCI_ALLOC_CONSISTENT
/* a hack for 2.4/5 kernels for better allocation of large buffers */
void *snd_pci_hack_alloc_consistent(struct pci_dev *hwdev, size_t size,
                                    dma_addr_t *dma_handle);
#endif /* arch */
#endif /* CONFIG_PCI */
#endif /* LINUX >= 2.4.0 */


#endif /* __SOUND_MEMALLOC_H */

Index: core.h
===================================================================
RCS file: /cvsroot/alsa/alsa-kernel/include/core.h,v
retrieving revision 1.34
retrieving revision 1.35
diff -u -r1.34 -r1.35
--- core.h      31 Jan 2003 12:41:14 -0000      1.34
+++ core.h      28 Feb 2003 14:29:22 -0000      1.35
@@ -275,32 +275,6 @@
 #endif
 void *snd_kcalloc(size_t size, int flags);
 char *snd_kmalloc_strdup(const char *string, int flags);
-void *snd_malloc_pages(unsigned long size, unsigned int dma_flags);
-void *snd_malloc_pages_fallback(unsigned long size, unsigned int dma_flags, unsigned 
long *res_size);
-void snd_free_pages(void *ptr, unsigned long size);
-#ifdef CONFIG_PCI
-void *snd_malloc_pci_pages(struct pci_dev *pci, unsigned long size, dma_addr_t 
*dma_addr);
-void *snd_malloc_pci_pages_fallback(struct pci_dev *pci, unsigned long size, 
dma_addr_t *dma_addr, unsigned long *res_size);
-void snd_free_pci_pages(struct pci_dev *pci, unsigned long size, void *ptr, 
dma_addr_t dma_addr);
-void *snd_malloc_pci_page(struct pci_dev *pci, dma_addr_t *dma_addr);
-#define snd_free_pci_page(pci,ptr,addr) snd_free_pci_pages(pci,PAGE_SIZE,ptr,addr)
-#endif
-#ifdef CONFIG_SBUS
-void *snd_malloc_sbus_pages(struct sbus_dev *sdev, unsigned long size, dma_addr_t 
*dma_addr);
-void *snd_malloc_sbus_pages_fallback(struct sbus_dev *sdev, unsigned long size, 
dma_addr_t *dma_addr, unsigned long *res_size);
-void snd_free_sbus_pages(struct sbus_dev *sdev, unsigned long size, void *ptr, 
dma_addr_t dma_addr);
-#endif
-#ifdef CONFIG_ISA
-#ifdef CONFIG_PCI
-#define snd_malloc_isa_pages(size, dma_addr) snd_malloc_pci_pages(NULL, size, 
dma_addr)
-#define snd_malloc_isa_pages_fallback(size, dma_addr, res_size) 
snd_malloc_pci_pages_fallback(NULL, size, dma_addr, res_size)
-#define snd_free_isa_pages(size, ptr, dma_addr) snd_free_pci_pages(NULL, size, ptr, 
dma_addr)
-#else /* !CONFIG_PCI */
-void *snd_malloc_isa_pages(unsigned long size, dma_addr_t *dma_addr);
-void *snd_malloc_isa_pages_fallback(unsigned long size, dma_addr_t *dma_addr, 
unsigned long *res_size);
-#define snd_free_isa_pages(size, ptr, dma_addr) snd_free_pages(ptr, size)
-#endif /* CONFIG_PCI */
-#endif /* CONFIG_ISA */
 int copy_to_user_fromio(void *dst, unsigned long src, size_t count);
 int copy_from_user_toio(unsigned long dst, const void *src, size_t count);
 

Index: driver.h
===================================================================
RCS file: /cvsroot/alsa/alsa-kernel/include/driver.h,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- driver.h    21 Jun 2002 12:15:21 -0000      1.14
+++ driver.h    28 Feb 2003 14:29:23 -0000      1.15
@@ -49,20 +49,6 @@
  *  ==========================================================================
  */
 
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 4, 0)
-#if defined(__i386__) || defined(__ppc__) || defined(__x86_64__)
-/*
- * Here a dirty hack for 2.4 kernels.. See sound/core/memory.c.
- */
-#define HACK_PCI_ALLOC_CONSISTENT
-#include <linux/pci.h>
-void *snd_pci_hack_alloc_consistent(struct pci_dev *hwdev, size_t size,
-                                   dma_addr_t *dma_handle);
-#undef pci_alloc_consistent
-#define pci_alloc_consistent snd_pci_hack_alloc_consistent
-#endif /* i386 or ppc */
-#endif /* 2.4.0 */
-
 #ifdef CONFIG_SND_DEBUG_MEMORY
 #include <linux/slab.h>
 #include <linux/vmalloc.h>

Index: pcm.h
===================================================================
RCS file: /cvsroot/alsa/alsa-kernel/include/pcm.h,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -r1.25 -r1.26
--- pcm.h       17 Feb 2003 10:27:43 -0000      1.25
+++ pcm.h       28 Feb 2003 14:29:24 -0000      1.26
@@ -24,6 +24,7 @@
  */
 
 #include <sound/asound.h>
+#include <sound/memalloc.h>
 #include <linux/poll.h>
 #include <linux/bitops.h>
 
@@ -49,6 +50,7 @@
 typedef struct sndrv_pcm_mmap_status snd_pcm_mmap_status_t;
 typedef struct sndrv_pcm_mmap_control snd_pcm_mmap_control_t;
 typedef struct sndrv_mask snd_mask_t;
+typedef struct snd_sg_buf snd_pcm_sgbuf_t;
 
 #define _snd_pcm_substream_chip(substream) ((substream)->private_data)
 #define snd_pcm_substream_chip(substream) snd_magic_cast1(chip_t, 
_snd_pcm_substream_chip(substream), return -ENXIO)
@@ -121,13 +123,6 @@
 #define SNDRV_PCM_TRIGGER_SUSPEND      5
 #define SNDRV_PCM_TRIGGER_RESUME       6
 
-#define SNDRV_PCM_DMA_TYPE_UNKNOWN     0       /* not defined */
-#define SNDRV_PCM_DMA_TYPE_CONTINUOUS  1       /* continuous no-DMA memory */
-#define SNDRV_PCM_DMA_TYPE_ISA         2       /* ISA continuous */
-#define SNDRV_PCM_DMA_TYPE_PCI         3       /* PCI continuous */
-#define SNDRV_PCM_DMA_TYPE_SBUS                4       /* SBUS continuous */
-#define SNDRV_PCM_DMA_TYPE_PCI_SG      5       /* PCI SG-buffer */
-
 /* If you change this don't forget to change rates[] table in pcm_native.c */
 #define SNDRV_PCM_RATE_5512            (1<<0)          /* 5512Hz */
 #define SNDRV_PCM_RATE_8000            (1<<1)          /* 8000Hz */
@@ -282,13 +277,6 @@
        unsigned int mask;
 } snd_pcm_hw_constraint_list_t;
 
-struct snd_pcm_dma_buffer {
-       unsigned char *area;
-       dma_addr_t addr;
-       unsigned long bytes;
-       void *private_data; /* for allocator */
-};
-
 struct _snd_pcm_runtime {
        /* -- Status -- */
        snd_pcm_substream_t *trigger_master;
@@ -362,7 +350,7 @@
        /* -- DMA -- */           
        unsigned char *dma_area;        /* DMA area */
        dma_addr_t dma_addr;            /* physical bus address (not accessible from 
main CPU) */
-       unsigned long dma_bytes;        /* size of DMA area */
+       size_t dma_bytes;       /* size of DMA area */
        void *dma_private;              /* private DMA data for the memory allocator */
 
 #if defined(CONFIG_SND_PCM_OSS) || defined(CONFIG_SND_PCM_OSS_MODULE)
@@ -379,10 +367,9 @@
        char name[32];                  /* substream name */
        int stream;                     /* stream (direction) */
        size_t buffer_bytes_max;        /* limit ring buffer size */
-       int dma_type;                   
-       struct snd_pcm_dma_buffer dma_buffer;
+       struct snd_dma_device dma_device;
+       struct snd_dma_buffer dma_buffer;
        size_t dma_max;
-       void *dma_private;
        /* -- hardware operations -- */
        snd_pcm_ops_t *ops;
        /* -- runtime information -- */
@@ -880,7 +867,18 @@
                                              snd_pcm_t *pcm,
                                              size_t size,
                                              size_t max);
+int snd_pcm_lib_preallocate_sg_pages(struct pci_dev *pci,
+                                    snd_pcm_substream_t *substream,
+                                    size_t size, size_t max);
+int snd_pcm_lib_preallocate_sg_pages_for_all(struct pci_dev *pci,
+                                            snd_pcm_t *pcm,
+                                            size_t size, size_t max);
+#define snd_pcm_substream_sgbuf(substream) ((substream)->runtime->dma_private)
+#define snd_pcm_sgbuf_pages(size) snd_sgbuf_aligned_pages(size)
+#define snd_pcm_sgbuf_get_addr(sgbuf,ofs) snd_sgbuf_get_addr(sgbuf,ofs)
+struct page *snd_pcm_sgbuf_ops_page(snd_pcm_substream_t *substream, unsigned long 
offset);
 #endif
+
 #ifdef CONFIG_SBUS
 int snd_pcm_lib_preallocate_sbus_pages(struct sbus_dev *sdev,
                                       snd_pcm_substream_t *substream,

Index: sndmagic.h
===================================================================
RCS file: /cvsroot/alsa/alsa-kernel/include/sndmagic.h,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- sndmagic.h  31 Jan 2003 15:19:43 -0000      1.15
+++ sndmagic.h  28 Feb 2003 14:29:24 -0000      1.16
@@ -108,7 +108,7 @@
 #define snd_pcm_proc_private_t_magic           0xa15a0104
 #define snd_pcm_oss_file_t_magic               0xa15a0105
 #define snd_mixer_oss_t_magic                  0xa15a0106
-#define snd_pcm_sgbuf_t_magic                  0xa15a0107
+// #define snd_pcm_sgbuf_t_magic                       0xa15a0107
 
 #define snd_info_private_data_t_magic          0xa15a0201
 #define snd_info_entry_t_magic                 0xa15a0202

--- pcm_sgbuf.h DELETED ---



-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
_______________________________________________
Alsa-cvslog mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/alsa-cvslog

Reply via email to