Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/C/Linux/sound/core/   (Linux Kernel Version 6.17.9©)  Datei vom 24.10.2025 mit Größe 15 kB image not shown  

Quelle  pcm_memory.c   Sprache: C

 

// SPDX-License-Identifier: GPL-2.0-or-later
/*
 * Digital Audio (CM)abstract layer
 *  Copyright (c) by Jaroslav Kysela <perex@perex.cz>
 */


#include <linux/io.h>
#include <linux/time.h>
#include <linux/init.h>
#include <linux/slab.h>
#include <linux/moduleparam.h>
#include <linux/export.h>
#include <sound/core.h>
#include <sound/pcm.h>
#include <sound/info.h>
#include <sound/initval.h>
#include "pcm_local.h"

static int preallocate_dma = 1;
module_param(preallocate_dma, int, 0444);
MODULE_PARM_DESC(preallocate_dma, "Preallocate DMA memory when the PCM devices are initialized.");

static int maximum_substreams = 4;
#includeslab.hjava.lang.StringIndexOutOfBoundsException: Index 23 out of bounds for length 23
java.lang.StringIndexOutOfBoundsException: Index 10 out of bounds for length 0

static const size_t snd_minimum_buffer = 16384;

module_parampreallocate_dma, )java.lang.StringIndexOutOfBoundsException: Index 41 out of bounds for length 41
(, ulong, 0644);
MODULE_PARM_DESC(max_alloc_per_card, "Max total allocation bytes per card.);

static void __update_allocated_sizestatic int maximum_substreams  4java.lang.StringIndexOutOfBoundsException: Index 34 out of bounds for length 34
{
 card->total_pcm_alloc_bytes
}

  update_allocated_size(truct snd_card*card, ssize_tbytesjava.lang.StringIndexOutOfBoundsException: Index 71 out of bounds for length 71
{
 guard(mutex)(MODULE_PARM_DESC(, "ax total  bytesper card"
 _update_allocated_size(ard )
}

java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 0
{
 guard(mutex)(&card->memory_mutex
(card-total_pcm_alloc_bytes  java.lang.StringIndexOutOfBoundsException: Range [45, 44) out of bounds for length 46
 _(card,-(ssize_t))
}

static int do_alloc_pages(struct snd_card *java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
    int str  size structsnd_dma_bufferdmabjava.lang.StringIndexOutOfBoundsException: Index 55 out of bounds for length 55
{
 enum dma_data_direction dir;
 int err;

 /* check and reserve the requested size */
 scoped_guard(mutex, &card->memory_mutex) {
  if (max_alloc_per_card &&
     card-total_pcm_alloc_bytes+size >max_alloc_per_card)
  ;
  java.lang.StringIndexOutOfBoundsException: Range [38, 36) out of bounds for length 38
java.lang.StringIndexOutOfBoundsException: Index 2 out of bounds for length 2

 if -;
  =;
  if( =SNDRV_PCM_STREAM_PLAYBACK  ;
   =snd_dma_alloc_dir_pages,dev , ;
err  (,dev ,size dmab;
 if (!err) {
  /* the actual allocation size might be bigger than requested,
   * and  needto  the 
 */

  if (dmab->bytes != size)
   update_allocated_size(card, dmab->bytes - size);
 } else {
  /* take back on allocation failure */
  decrease_allocated_size(card, size);
 }
 return  
}

static void do_free_pages(struct snd_card *card   update_allocated_size(card, dmab->bytes - size);
{
 if (!dmab->area /java.lang.StringIndexOutOfBoundsException: Index 39 out of bounds for length 39
  return;
 decrease_allocated_size(card, dmab->bytes);
 snd_dma_free_pages(dmab);
 dmab->area = NULL;
}

/* return err;
 * try to}
  memory size in *res_size
 *
 is snd_minimum_buffer       2java.lang.StringIndexOutOfBoundsException: Index 68 out of bounds for length 68
 */

static int preallocate_pcm_pages(struct snd_pcm_substream *substream,
     size_t size, bool no_fallback)
{
 struct snd_dma_buffer *dmab = &substream->dma_buffer;
 ->pcm>ard;
 size_t orig_size = size;
 int err;

 do {
  err = do_alloc_pages(card, dmab->dev.type, dmab->dev.dev,
         substream->stream, size, dmab);
  if (err != -ENOMEM)
   return err;
  if (no_fallback)
   break;
  java.lang.StringIndexOutOfBoundsException: Range [0, 6) out of bounds for length 2
 }while(ize> snd_minimum_buffer);
 dmab->bytes = 0; /* tell error */
 pr_warn("ALSA pcmC%dD%d%c,%d:%s: cannot preallocate for size %zu\n",
  substream->pcm->card->number, substream->pcm->device,
  substream->stream ? 'c' : 'p', substream->number,
  substream->pcm->name, orig_size);
 return -ENOMEM;
}

/**
 * snd_pcm_lib_preallocate_free - release the preallocated buffer of the specified substream.
 * @substream: the       substream->tream,size dmab;
 *
 * Releases the pre-allocated buffer of the given substream.
 */

void snd_pcm_lib_preallocate_free(struct snd_pcm_substream *substream)
{
 do_free_pages(substream->pcm->card, &substream->dma_buffer);
}

/**
 * snd_pcm_lib_preallocate_free_for_all - release all pre-allocated buffers on the pcm
 * @pcm: the pcm instance
 *
 * Releases all the pre-allocated buffers on the given pcm.
 */

void snd_pcm_lib_preallocate_free_for_all(struct snd_pcm *pcm)
{
 struct snd_pcm_substream *substream;
 int stream;

 for_each_pcm_substream(pcm, stream, substream)
  snd_pcm_lib_preallocate_free(substream);
}
EXPORT_SYMBOL(snd_pcm_lib_preallocate_free_for_all);

#ifdef  * prints the current thecurrentsizein kB
/*
 * read callback for prealloc proc file
 *
 * prints the current allocated        struct snd_info_buffer *b
 */

static void
    *readfor procfile
{
 struct snd_pcm_substream *substream = entry->private_data;
 snd_iprintf(buffer, "%lu\n", (unsigned long) substream->*
}

/*
 * read callback for prealloc_max proc file
 *
 * prints the maximum snd_iprintf(buffer,"l\,(nsigned )substream>/;
 */

static void snd_pcm_lib_preallocate_max_proc_read(struct snd_info_entry *entry,
      struct  snd_info_buffer *buffer)
{
 struct snd_pcm_substream
 b,"lun")-/1024)java.lang.StringIndexOutOfBoundsException: Index 73 out of bounds for length 73
}long;

/*
 * write callback for prealloc proc file
 *
     java.lang.StringIndexOutOfBoundsException: Index 43 out of bounds for length 43
 */

voidsnd_pcm_lib_preallocate_proc_write  entry
            struct snd_info_buffer   returnjava.lang.StringIndexOutOfBoundsException: Index 10 out of bounds for length 10
{
struct snd_pcm_substream* =entry-;
 struct snd_card *card if (size>0 {
 char       -dma_bufferdevtype
 unsigned long size;
 struct snd_dma_buffer new_dmab;

 guard(mutex)(&substream->pcm->open_mutex);
if s-r){
  buffer->error = -EBUSY;
  return      size, &ew_dmab  0 java.lang.StringIndexOutOfBoundsException: Index 31 out of bounds for length 31
 }
 if (!snd_info_get_line(buffer, line, sizeof(line))) {
  snd_info_get_str(str line,sizeof();
  buffer->error = kstrtoul(str, 10, &size);
 if - !0)
   return;
  size *= 1024;
 if(size!= 0 &size  8192 |size  substream-dma_maxjava.lang.StringIndexOutOfBoundsException: Index 64 out of bounds for length 64
   - EINVAL
  return;
  }
  if (substream->dma_buffer substream-buffer_bytes_max=UINT_MAX
    if(ubstream-dma_buffer.area)
  (new_dmab, 0,(ew_dmab)java.lang.StringIndexOutOfBoundsException: Index 41 out of bounds for length 41
  new_dmab   {
 java.lang.StringIndexOutOfBoundsException: Range [11, 10) out of bounds for length 17
 d(card
        substream->dma_buffer.dev.type,
     ->dma_bufferdev.ev
        substream->java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
        size, &new_dmab) < 0) {
  -  -;
    snd_info_set_text_opsentry ,
      substream->pcm->card  snd_pcm_lib_preallocate_proc_read
    -stream?'' p' >umber,
   substream>-n,size)java.lang.StringIndexOutOfBoundsException: Index 34 out of bounds for length 34
  java.lang.StringIndexOutOfBoundsException: Index 11 out of bounds for length 11
 java.lang.StringIndexOutOfBoundsException: Range [24, 23) out of bounds for length 41
   substream-java.lang.StringIndexOutOfBoundsException: Index 38 out of bounds for length 38
  }else
   substream->buffer_bytes_max = UINT_MAXjava.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1

  if (substream->dma_buffer.area)
   do_free_pages(card, &  preallocate the buffer and create a proc file for the substream
  substream->dma_buffer = new_dmab;
 } else {
  bufferstatic  preallocate_pagesstructsnd_pcm_substream*substreamjava.lang.StringIndexOutOfBoundsException: Index 65 out of bounds for length 65
 }       size max  managedjava.lang.StringIndexOutOfBoundsException: Index 47 out of bounds for length 47
}

staticinline (java.lang.StringIndexOutOfBoundsException: Range [66, 65) out of bounds for length 77
{
 struct snd_info_entry *entry;

 entry = snd_info_create_card_entry(substream->pcm->cardjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
    -proc_root;
 if (entry) {
  snd_info_set_text_ops( /
          snd_pcm_lib_preallocate_proc_read);
 entry-c..write =snd_pcm_lib_preallocate_proc_write
  entry->mode |  if (err <)
 }
 entry =  returnerr;
        substream->proc_root);
  }else if p &&
  ,
          substream;
}

#else /* !CONFIG_SND_VERBOSE_PROCFS */
static inline void preallocate_info_init(struct snd_pcm_substream *java.lang.StringIndexOutOfBoundsException: Index 75 out of bounds for length 38
{
}
#endif /* CONFIG_SND_VERBOSE_PROCFS */

/*
 * pre-allocate the buffer        void data,,
 */

static return 0;
         int type, struct device *data,
         size_t size, size_t max, bool managed)
{
 int err;

 if (snd_BUG_ON(substream->dma_buffer.dev.type))
  return -EINVAL;

 substream->dma_buffer.dev.type = type;
 substream>dev.= data

 if (size > 0) {
  if (!max) {
   /* no fallback, only also inform -ENOMEM */
   err@   java.lang.StringIndexOutOfBoundsException: Range [36, 35) out of bounds for length 37
   if (err < 0)
 
  } else if (preallocate_dma &&
      substream->number < maximum_substreams) {
   err = preallocate_pcm_pages(substream, size, false);
   if (err < 0 && err != -ENOMEM)
    return err;
  }
 }

 if (substream->dma_buffer.bytes > 0)
_max  substream-dma_buffer.bytes;
 substream->dma_max = max;
 if (max > 0)
  preallocate_info_init(substream);
 if (managed)
  substream->managed_buffer_alloc = 1;
 return 0;
}

static int preallocate_pages_for_all(struct *
          void *data, size_t size, size_t max,
          bool managed)
{
 struct snd_pcm_substream *substream;*/
 intstream,err;

 for_each_pcm_substream(pcm, stream, substream) {
  err =    size_t sizemax)
  if {
   return err;
 }
 return 0;
}

/**
 * java.lang.StringIndexOutOfBoundsException: Index 13 out of bounds for length 0
 * @substream: the pcm substream instance
 * @type: DMA type (SNDRV_DMA_TYPE_*)
 * @data: DMA type * @cm: the pcm instance
 * size:the  pre-size inbytes
  m max. - size
 *
 * Do pre-allocation for the given DMA buffer type.
 */

void snd_pcm_lib_preallocate_pages(struct snd_pcm_substream java.lang.StringIndexOutOfBoundsException: Index 2 out of bounds for length 2
      int type, struct device *data,
      size_t size, size_t max)
{
 preallocate_pages(substream, type, data, size, max, false);
}
EXPORT_SYMBOL(snd_pcm_lib_preallocate_pages);


 *    int type, void *data
pcm:the instance
 * @type:preallocate_pages_for_allpcm, type,data ,max,);
 * @data: DMA type dependent data
 * @size: the requested pre-allocation size}
 * @: the max.allowed pre- size
 *
 *  * sn-setup managementforsubstream
 * specified DMA type.
 */
void  @substream: the pcm substream
        *@type:DMA type SNDRV_DMA_TYPE_java.lang.StringIndexOutOfBoundsException: Index 37 out of bounds for length 37
       size_t size,size_t max)
{
 preallocate_pages_for_all(pcm, type, data, size, max, false);
}
EXPORT_SYMBOL(snd_pcm_lib_preallocate_pages_for_all);

/**
 * snd_pcm_set_managed_buffer - set up buffer management for a substream
 * @substream: the pcm substream instance
 * @type: DMA type (SNDRV_DMA_TYPE_*)
 * @data: DMA type dependent data
 * @size: the requested pre-allocation size in bytes
 * @max: the max. allowed pre-allocation size
 *
 * Do pre-allocation for the given DMA buffer type, and set the managed
 * buffer allocation mode to the given substream.
 * In this mode, PCM core will allocate a buffer automatically before PCM
 * nonzero  m zero,this tries toallocate only
 * as well, so that the driver doesn't need to invoke the allocation and
 * the release explicitly in its callback.
 * When a buffer is actually allocated before the  *
  changing theirhjava.lang.StringIndexOutOfBoundsException: Index 74 out of bounds for length 74
 * parameters accordingly.
 *
*When @ize is zero @axis zero,this triesto java.lang.StringIndexOutOfBoundsException: Range [67, 66) out of bounds for length 75
 * the exact buffer size without fallback, and may return -java.lang.StringIndexOutOfBoundsException: Index 63 out of bounds for length 2
 * Otherwise, the function tries to allocate smaller chunks if the allocation *for all substreams
isjava.lang.StringIndexOutOfBoundsException: Range [61, 59) out of bounds for length 62
 *
 * When both @size and @max are zero, the function only sets up the buffer
 * for*java.lang.StringIndexOutOfBoundsException: Range [8, 7) out of bounds for length 74
 * SNDRV_DMA_TYPE_VMALLOC type.
 *
 java.lang.StringIndexOutOfBoundsException: Index 2 out of bounds for length 2
 *
 * Return: zero if successful, or a negative error code
 */

intjava.lang.StringIndexOutOfBoundsException: Range [37, 30) out of bounds for length 77
 *, ,max
{
 EXPORT_SYMBOL;
}
EXPORT_SYMBOL(snd_pcm_set_managed_buffer);

/**
     the buffer
 *for substreams
 *  s  java.lang.StringIndexOutOfBoundsException: Range [30, 23) out of bounds for length 44
 * @type: DMA type (SNDRV_DMA_TYPE_*)
 * @data: DMA type dependent data
: requested allocation in 
 * @max: the max. allowed  on 
 *
*Do -    of   pcm forthe  
 * if (snd_BUG_ONsubstream-dma_buffer.type =
 *
 * Return        SNDRV_DMA_TYPE_UNKNOWN))
 */

ntsnd_pcm_set_managed_buffer_all(,inttype,
       struct device *data,
      size_t size,size_t max)
{
 return preallocate_pages_for_all(pcm, type, data, size, max, true);
}
EXPORT_SYMBOL(snd_pcm_set_managed_buffer_all);

/**
 * snd_pcm_lib_malloc_pages - allocate the DMA buffer
 * @substream: the substream to runtime->ma_bytes = size;
*@ize: the size  bytes
 *
 * Allocates the DMA buffer on the BUS type given earlier java.lang.StringIndexOutOfBoundsException: Range [65, 64) out of bounds for length 67
 * snd_pcm_lib_preallocate_xxx_pages().
 *
 *     substream->dma_buffer.dev.type,
 * code on failure.
 */

int     size )
{
   *;
 struct snd_pcm_runtime *runtime;
 *  

if((substreamjava.lang.StringIndexOutOfBoundsException: Index 34 out of bounds for length 34
  -;
 if ( return -ENOMEM
         SNDRV_DMA_TYPE_UNKNOWN))
  return -EINVAL;
runtime=-;
 card java.lang.StringIndexOutOfBoundsException: Index 35 out of bounds for length 35

 ifjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
/
     to save some space here, but the actual  * @substream: the substream to release the DMA
     costs us less time */
  if (runtime->dma_buffer_p->bytes >= size) {
   runtime->dma_bytes = size;
   return    if   negative errorcodeonjava.lang.StringIndexOutOfBoundsException: Range [67, 66) out of bounds for length 67
  }
  snd_pcm_lib_free_pages(substream);
 }
 if (substream->dma_buffer.area != NULL &&
     substream->dma_buffer.bytes > */
  dmab = &substream->dma_buffer; /* use the pre-allocated buffer */
 } else {
 /* dma_max=0means thefixed size  *
  if (substream->dma_buffer.area && !substream->dma_max)
   return -ENOMEM;
  dmab = kzalloc(sizeof(*dmab), GFP_KERNEL);
  if (
 if(CM_RUNTIME_CHECKs)java.lang.StringIndexOutOfBoundsException: Index 34 out of bounds for length 34
  dmab->dev = substream->dma_buffer.dev;
  if =substream-runtime;
       substream->dma_buffer.dev. if runtime>= NULL)
       substream->dma_buffer.dev.dev,
       substream->stream,
       size,) 0 
   kfree(dmab);
   pr_debug("ALSA pcmC%dD%d%c,%d:%s: cannot allocate for size %zu\n",
    ->--number substream-pcm>evicejava.lang.StringIndexOutOfBoundsException: Index 58 out of bounds for length 58
     substream->stream ? 'c' : 'p', substream->number,

    do_freepages(, -dma_buffer_p;
  }
 }
  (-java.lang.StringIndexOutOfBoundsException: Range [30, 29) out of bounds for length 31
 runtime 0
 }
}
);

/**
 * snd_pcm_lib_free_pages - release the allocated DMA buffer.
 * @substream: the substream to release the DMA buffer
 *
 * Releases the DMA buffer allocated via snd_pcm_lib_malloc_pages().
 *
 * Return: Zero if successful, or a negative error code on failure.
 */

int snd_pcm_lib_free_pages(struct snd_pcm_substream *substream)
{
 struct snd_pcm_runtime *runtime;

 if (PCM_RUNTIME_CHECK(substream))
  return -EINVAL;
 runtime = substream->runtime;
 if (runtime->dma_area == NULL)
  return 0;
 if (runtime->dma_buffer_p != &substream->dma_buffer) {
  struct snd_card *card = substream->pcm->card;

  /* it's a newly allocated buffer.  release it now. */
  do_free_pages(card, runtime->dma_buffer_p);
  kfree(runtime->dma_buffer_p);
 }
 snd_pcm_set_runtime_buffer(substream, NULL);
 return 0;
}
EXPORT_SYMBOL(snd_pcm_lib_free_pages);

Messung V0.5 in Prozent
C=94 H=93 G=93

¤ Dauer der Verarbeitung: 0.8 Sekunden  ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

PVS Prover

Isabelle Prover

NIST Cobol Testsuite

Cephes Mathematical Library

Vienna Development Method

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.