Changeset ed54cbf in mainline


Ignore:
Timestamp:
2012-08-19T12:54:35Z (12 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
b881226
Parents:
b28dabe
Message:

isa: Add and use helper functions. Add comments.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/bus/isa/i8237.c

    rb28dabe red54cbf  
    273273};
    274274
    275 /* Initialize I/O access to DMA controller I/O ports.
     275/** Initialize I/O access to DMA controller I/O ports.
    276276 *
    277277 * @param controller DMA Controller structure to initialize.
    278278 *
    279279 * @return Error code.
    280  *
    281280 */
    282281static inline int dma_controller_init(dma_controller_t *controller)
     
    305304       
    306305        return EOK;
     306}
     307
     308/** Helper function. Channels 4,5,6, and 7 are 8 bit DMA.
     309 * @pram channel DMA channel.
     310 * @reutrn True, if channel is 4,5,6, or 7, false otherwise.
     311 */
     312static inline bool is_dma16(unsigned channel)
     313{
     314        return (channel >= 4) && (channel < 8);
     315}
     316
     317/** Helper function. Channels 0,1,2, and 3 are 8 bit DMA.
     318 * @pram channel DMA channel.
     319 * @reutrn True, if channel is 0,1,2, or 3, false otherwise.
     320 */
     321static inline bool is_dma8(unsigned channel)
     322{
     323        return (channel < 4);
    307324}
    308325
     
    325342    uint8_t mode)
    326343{
     344        if (!is_dma8(channel) && !is_dma16(channel))
     345                return ENOENT;
     346
    327347        if ((channel == 0) || (channel == 4))
    328348                return ENOTSUP;
    329        
    330         if (channel > 7)
    331                 return ENOENT;
    332349       
    333350        /* DMA is limited to 24bit addresses. */
     
    336353       
    337354        /* 8 bit channels use only 4 bits from the page register. */
    338         if ((channel > 0) && (channel < 4) && (pa >= (1 << 20)))
     355        if (is_dma8(channel) && (pa >= (1 << 20)))
    339356                return EINVAL;
    340357
     
    353370        }
    354371       
     372        ddf_msg(LVL_DEBUG, "Unspoiled address: %p and size: %zu.", pa, size);
     373       
    355374        /* 16 bit transfers are a bit special */
    356         ddf_msg(LVL_DEBUG, "Unspoiled address: %p and size: %zu.", pa, size);
    357         if (channel > 4) {
     375        if (is_dma16(channel)) {
    358376                /* Size must be aligned to 16 bits */
    359377                if ((size & 1) != 0) {
     
    361379                        return EINVAL;
    362380                }
    363                
     381                /* Size is in 2byte words */
    364382                size >>= 1;
    365                
    366383                /* Address is fun: lower 16 bits need to be shifted by 1 */
    367384                pa = ((pa & 0xffff) >> 1) | (pa & 0xff0000);
     
    429446}
    430447
    431 extern int dma_channel_remain(unsigned channel, uint16_t *size)
     448/** Query remaining buffer size.
     449 *
     450 * @param channel DMA Channel 1, 2, 3 for 8 bit transfers,
     451 *                    5, 6, 7 for 16 bit.
     452 * @param size    Place to store number of bytes pending in the assigned buffer.
     453 *
     454 * @return Error code.
     455 */
     456int dma_channel_remain(unsigned channel, uint16_t *size)
    432457{
    433458        assert(size);
     459        if (!is_dma8(channel) && !is_dma16(channel))
     460                return ENOENT;
     461       
    434462        if ((channel == 0) || (channel == 4))
    435463                return ENOTSUP;
    436        
    437         if (channel > 7)
    438                 return ENOENT;
    439464       
    440465        fibril_mutex_lock(&guard);
     
    461486        const int remain = (value_high << 8 | value_low) + 1;
    462487        /* 16 bit DMA size is in words */
    463         *size =  channel >= 4 ? remain << 1 : remain;
     488        *size =  is_dma16(channel) ? remain << 1 : remain;
    464489        return EOK;
    465490}
Note: See TracChangeset for help on using the changeset viewer.