Changeset e0f9950 in mainline


Ignore:
Timestamp:
2011-10-21T13:59:19Z (12 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
1a11a16
Parents:
aa5ae788
Message:

sb16: Enable interrupts during initialization.

Fix possible double free on error paths.
Minor dma changes.

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

Legend:

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

    raa5ae788 re0f9950  
    6060}
    6161/*----------------------------------------------------------------------------*/
    62 /** Physical mallocator simulator
     62/** DMA mallocator simulator
    6363 *
    6464 * @param[in] size Size of the required memory space
    65  * @return Address of the alligned and big enough memory place, NULL on failure.
     65 * @return Address of the aligned and big enough memory place, NULL on failure.
    6666 */
    6767static inline void * malloc24(size_t size)
     
    7979}
    8080/*----------------------------------------------------------------------------*/
    81 /** Physical mallocator simulator
     81/** DMA mallocator simulator
    8282 *
    83  * @param[in] addr Address of the place allocated by malloc32
     83 * @param[in] addr Address of the place allocated by malloc24
    8484 */
    8585static inline void free24(void *addr)
  • uspace/drv/audio/sb16/dma_controller.c

    raa5ae788 re0f9950  
    157157} dma_controller_t;
    158158
    159 dma_controller_t controller_8237 = {
     159static const dma_controller_t controller_8237 = {
    160160        .channel = {
    161161            { (uint8_t*)0x00, (uint8_t*)0x01, (uint8_t*)0x87 },
     
    172172};
    173173
    174 static inline dma_controller_t *dma_controller_init()
     174static inline const dma_controller_t *dma_controller_init()
    175175{
    176176        int ret = pio_enable(DMA_CONTROLLER_PAGE_BASE, sizeof(dma_page_regs_t),
     
    193193}
    194194/*----------------------------------------------------------------------------*/
    195 static int dma_setup_channel_8bit(dma_controller_t *controller,
     195static int dma_setup_channel_8bit(const dma_controller_t *controller,
    196196    unsigned channel, uint32_t pa, uint16_t size)
    197197{
     
    237237}
    238238/*----------------------------------------------------------------------------*/
    239 static int dma_setup_channel_16bit(dma_controller_t *controller,
     239static int dma_setup_channel_16bit(const dma_controller_t *controller,
    240240    unsigned channel, uintptr_t pa, size_t size)
    241241{
     
    283283int dma_setup_channel(unsigned channel, uintptr_t pa, size_t size)
    284284{
    285         static dma_controller_t *controller = NULL;
     285        static const dma_controller_t *controller = NULL;
    286286        if (!controller)
    287287                controller = dma_controller_init();
  • uspace/drv/audio/sb16/main.c

    raa5ae788 re0f9950  
    5151static int sb_get_res(const ddf_dev_t *device, uintptr_t *sb_regs,
    5252    size_t *sb_regs_size, uintptr_t *mpu_regs, size_t *mpu_regs_size, int *irq);
     53static int sb_enable_interrupts(ddf_dev_t *device);
    5354/*----------------------------------------------------------------------------*/
    5455static driver_ops_t sb_driver_ops = {
     
    8990static int sb_add_device(ddf_dev_t *device)
    9091{
    91 #define CHECK_RET_FREE_RETURN(ret, msg...) \
     92#define CHECK_RET_RETURN(ret, msg...) \
    9293if (ret != EOK) { \
    93         free(soft_state); \
    9494        ddf_log_error(msg); \
    9595        return ret; \
     
    9898        assert(device);
    9999
    100         sb16_drv_t *soft_state = malloc(sizeof(sb16_drv_t));
     100        sb16_drv_t *soft_state = ddf_dev_data_alloc(device, sizeof(sb16_drv_t));
    101101        int ret = soft_state ? EOK : ENOMEM;
    102         CHECK_RET_FREE_RETURN(ret, "Failed to allocate sb16 structure.\n");
     102        CHECK_RET_RETURN(ret, "Failed to allocate sb16 structure.\n");
    103103
    104104        uintptr_t sb_regs = 0, mpu_regs = 0;
     
    108108        ret = sb_get_res(device, &sb_regs, &sb_regs_size, &mpu_regs,
    109109            &mpu_regs_size, &irq);
    110         CHECK_RET_FREE_RETURN(ret,
     110        CHECK_RET_RETURN(ret,
    111111            "Failed to get resources: %s.\n", str_error(ret));
    112112
    113113        irq_code_t *irq_code = sb16_irq_code();
    114114        ret = register_interrupt_handler(device, irq, irq_handler, irq_code);
    115         CHECK_RET_FREE_RETURN(ret,
     115        CHECK_RET_RETURN(ret,
    116116            "Failed to register irq handler: %s.\n", str_error(ret));
     117
    117118
    118119        ddf_fun_t *dsp_fun = NULL, *mixer_fun = NULL;
     
    124125        if (mixer_fun) \
    125126                ddf_fun_destroy(mixer_fun); \
    126         free(soft_state); \
    127127        unregister_interrupt_handler(device, irq); \
    128128        return ret; \
    129129} else (void)0
     130
     131        ret = sb_enable_interrupts(device);
     132        CHECK_RET_UNREG_DEST_RETURN(ret, "Failed to enable interrupts: %s.\n",
     133            str_error(ret));
     134
    130135        dsp_fun = ddf_fun_create(device, fun_exposed, "dsp");
    131136        ret = dsp_fun ? EOK : ENOMEM;
     
    144149        CHECK_RET_UNREG_DEST_RETURN(ret,
    145150            "Failed to bind dsp function: %s.\n", str_error(ret));
    146         dsp_fun->driver_data = soft_state;
    147151
    148152        ret = ddf_fun_bind(mixer_fun);
    149153        CHECK_RET_UNREG_DEST_RETURN(ret,
    150154            "Failed to bind mixer function: %s.\n", str_error(ret));
     155
     156        /* Everything's OK assign driver_data. */
    151157        mixer_fun->driver_data = soft_state;
    152 
     158        dsp_fun->driver_data = soft_state;
    153159
    154160        ret = sb16_init_mpu(soft_state, (void*)mpu_regs, mpu_regs_size);
     
    224230        return EOK;
    225231}
     232/*----------------------------------------------------------------------------*/
     233int sb_enable_interrupts(ddf_dev_t *device)
     234{
     235        async_sess_t *parent_sess =
     236            devman_parent_device_connect(EXCHANGE_SERIALIZE, device->handle,
     237            IPC_FLAG_BLOCKING);
     238        if (!parent_sess)
     239                return ENOMEM;
     240
     241        bool enabled = hw_res_enable_interrupt(parent_sess);
     242        async_hangup(parent_sess);
     243
     244        return enabled ? EOK : EIO;
     245}
    226246/**
    227247 * @}
    228248 */
    229 
Note: See TracChangeset for help on using the changeset viewer.