Changeset 0ea8f83 in mainline


Ignore:
Timestamp:
2011-11-11T19:44:07Z (12 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
d98d136
Parents:
751d17a2
Message:

sb16: DMA buffer uses separate memory area.

Location:
uspace/drv/audio/sb16
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/audio/sb16/dma.h

    r751d17a2 r0ea8f83  
    6565 * @return Address of the aligned and big enough memory place, NULL on failure.
    6666 */
    67 static inline void * malloc24(size_t size)
     67static inline void *dma_create_buffer24(size_t size)
    6868{
    69         /* This works only reliably when the host has less than 16MB of memory
    70          * as physical address needs to fit into 24 bits */
    71 
    72         /* If we need more than one page there is no guarantee that the
    73          * memory will be continuous */
    74         if (size > PAGE_SIZE)
     69        void *free_address = as_get_mappable_page(size);
     70        if (free_address == 0)
    7571                return NULL;
    76         return memalign(DMA_ALIGNENT, size);
     72        void *address =
     73            as_area_create(free_address, size, AS_AREA_READ | AS_AREA_WRITE);
     74        if (address != free_address)
     75                return NULL;
     76        bzero(address, size);
     77        return address;
    7778}
    7879/*----------------------------------------------------------------------------*/
    7980/** DMA mallocator simulator
    8081 *
    81  * @param[in] addr Address of the place allocated by malloc24
     82 * @param[in] addr Address of the place allocated by dma_create_buffer24
    8283 */
    83 static inline void free24(void *addr)
    84         { free(addr); }
     84static inline void dma_destroy_buffer(void *page)
     85{
     86        if (page)
     87                as_area_destroy(page);
     88}
     89
    8590
    8691#endif
  • uspace/drv/audio/sb16/dsp.c

    r751d17a2 r0ea8f83  
    4343#include "dsp.h"
    4444
    45 #define BUFFER_SIZE (PAGE_SIZE / 4)
     45#define BUFFER_SIZE (PAGE_SIZE)
    4646#define PLAY_BLOCK_SIZE (BUFFER_SIZE / 2)
    4747
     
    108108{
    109109        assert(dsp);
    110         uint8_t *buffer = malloc24(BUFFER_SIZE);
     110        uint8_t *buffer = dma_create_buffer24(BUFFER_SIZE);
    111111        if (buffer == NULL) {
    112112                ddf_log_error("Failed to allocate buffer.\n");
     
    118118        /* Set 16 bit channel */
    119119        const int ret = dma_setup_channel(SB_DMA_CHAN_16, pa, BUFFER_SIZE,
    120             DMA_MODE_READ | DMA_MODE_AUTO | DMA_MODE_SINGLE);
     120            DMA_MODE_READ | DMA_MODE_AUTO | DMA_MODE_ON_DEMAND);
    121121        if (ret == EOK) {
    122122                dsp->buffer.data = buffer;
     
    127127                ddf_log_error("Failed to setup DMA16 channel %s.\n",
    128128                    str_error(ret));
    129                 free24(buffer);
     129                dma_destroy_buffer(buffer);
    130130        }
    131131        return ret;
     
    134134static inline void sb_clear_buffer(sb_dsp_t *dsp)
    135135{
    136         free24(dsp->buffer.data);
     136        dma_destroy_buffer(dsp->buffer.data);
    137137        dsp->buffer.data = NULL;
    138138        dsp->buffer.position = NULL;
Note: See TracChangeset for help on using the changeset viewer.