Changeset 3d14a45 in rtems for cpukit/libblock


Ignore:
Timestamp:
01/21/07 18:25:31 (17 years ago)
Author:
Thomas Doerfler <Thomas.Doerfler@…>
Branches:
4.10, 4.11, 4.8, 4.9, 5, master
Children:
6200dc9
Parents:
bc2083c1
Message:

mproved gen5200 MSCAN driver
fixed synchronization bug between ata.c and bdbuf.c

Location:
cpukit/libblock
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • cpukit/libblock/Makefile.am

    rbc2083c1 r3d14a45  
    99noinst_LIBRARIES = libblock.a
    1010libblock_a_SOURCES = src/bdbuf.c src/blkdev.c src/diskdevs.c src/ramdisk.c \
    11     src/ide_part_table.c include/rtems/bdbuf.h include/rtems/blkdev.h \
     11    src/ide_part_table.c src/show_bdbuf.c \
     12    include/rtems/bdbuf.h include/rtems/blkdev.h \
    1213    include/rtems/diskdevs.h include/rtems/ramdisk.h \
    1314    include/rtems/ide_part_table.h
  • cpukit/libblock/include/rtems/bdbuf.h

    rbc2083c1 r3d14a45  
    99 * Author: Victor V. Vengerov <vvv@oktet.ru>
    1010 *
    11  * @(#) $Id$
     11 * @(#) bdbuf.h,v 1.9 2005/02/02 00:06:18 joel Exp
    1212 */
    1313
     
    7575
    7676
     77/*
     78 * the following data structures are internal to the bdbuf layer,
     79 * but it is convenient to have them visible from the outside for inspection
     80 */
     81/*
     82 * The groups of the blocks with the same size are collected in the
     83 * bd_pool. Note that a several of the buffer's groups with the
     84 * same size can exists.
     85 */
     86typedef struct bdbuf_pool
     87{
     88    bdbuf_buffer *tree;         /* Buffer descriptor lookup AVL tree root */
     89
     90    Chain_Control free;         /* Free buffers list */
     91    Chain_Control lru;          /* Last recently used list */
     92
     93    int           blksize;      /* The size of the blocks (in bytes) */
     94    int           nblks;        /* Number of blocks in this pool */
     95    rtems_id      bufget_sema;  /* Buffer obtain counting semaphore */
     96    void         *mallocd_bufs; /* Pointer to the malloc'd buffer memory,
     97                                   or NULL, if buffer memory provided in
     98                                   buffer configuration */
     99    bdbuf_buffer *bdbufs;       /* Pointer to table of buffer descriptors
     100                                   allocated for this buffer pool. */
     101} bdbuf_pool;
     102
     103/* Buffering layer context definition */
     104struct bdbuf_context {
     105    bdbuf_pool    *pool;         /* Table of buffer pools */
     106    int            npools;       /* Number of entries in pool table */
     107
     108    Chain_Control  mod;          /* Modified buffers list */
     109    rtems_id       flush_sema;   /* Buffer flush semaphore; counting
     110                                    semaphore; incremented when buffer
     111                                    flushed to the disk; decremented when
     112                                    buffer modified */
     113    rtems_id       swapout_task; /* Swapout task ID */
     114};
     115  /*
     116   * the context of the buffering layer, visible for inspection
     117   */
     118extern struct bdbuf_context rtems_bdbuf_ctx;
    77119
    78120/* bdbuf_config structure describes block configuration (size,
  • cpukit/libblock/src/bdbuf.c

    rbc2083c1 r3d14a45  
    88 *         Alexander Kukuta <kam@oktet.ru>
    99 *
    10  * @(#) $Id$
     10 * @(#) bdbuf.c,v 1.14 2004/04/17 08:15:17 ralf Exp
    1111 */
    1212
     
    5757static rtems_status_code bdbuf_release(bdbuf_buffer *bd_buf);
    5858/*
    59  * The groups of the blocks with the same size are collected in the
    60  * bd_pool. Note that a several of the buffer's groups with the
    61  * same size can exists.
    62  */
    63 typedef struct bdbuf_pool
    64 {
    65     bdbuf_buffer *tree;         /* Buffer descriptor lookup AVL tree root */
    66 
    67     Chain_Control free;         /* Free buffers list */
    68     Chain_Control lru;          /* Last recently used list */
    69 
    70     int           blksize;      /* The size of the blocks (in bytes) */
    71     int           nblks;        /* Number of blocks in this pool */
    72     rtems_id      bufget_sema;  /* Buffer obtain counting semaphore */
    73     void         *mallocd_bufs; /* Pointer to the malloc'd buffer memory,
    74                                    or NULL, if buffer memory provided in
    75                                    buffer configuration */
    76     bdbuf_buffer *bdbufs;       /* Pointer to table of buffer descriptors
    77                                    allocated for this buffer pool. */
    78 } bdbuf_pool;
    79 
    80 /* Buffering layer context definition */
    81 struct bdbuf_context {
    82     bdbuf_pool    *pool;         /* Table of buffer pools */
    83     int            npools;       /* Number of entries in pool table */
    84 
    85     Chain_Control  mod;          /* Modified buffers list */
    86     rtems_id       flush_sema;   /* Buffer flush semaphore; counting
    87                                     semaphore; incremented when buffer
    88                                     flushed to the disk; decremented when
    89                                     buffer modified */
    90     rtems_id       swapout_task; /* Swapout task ID */
    91 };
    92 /*
    9359 * maximum number of blocks that might be chained together to one
    9460 * write driver call
     
    10975} blkdev_request1;
    11076
    111 /* The static context of buffering layer */
    112 static struct bdbuf_context bd_ctx;
     77/* The context of buffering layer */
     78struct bdbuf_context rtems_bdbuf_ctx;
    11379
    11480#define SAFE
     
    712678bdbuf_initialize_pool(rtems_bdbuf_config *config, int pool)
    713679{
    714     bdbuf_pool *p = bd_ctx.pool + pool;
     680    bdbuf_pool *p = rtems_bdbuf_ctx.pool + pool;
    715681    unsigned char *bufs;
    716682    bdbuf_buffer *b;
     
    788754bdbuf_release_pool(rtems_bdpool_id pool)
    789755{
    790     bdbuf_pool *p = bd_ctx.pool + pool;
     756    bdbuf_pool *p = rtems_bdbuf_ctx.pool + pool;
    791757    rtems_semaphore_delete(p->bufget_sema);
    792758    free(p->bdbufs);
     
    819785        return RTEMS_INVALID_SIZE;
    820786
    821     bd_ctx.npools = size;
     787    rtems_bdbuf_ctx.npools = size;
    822788
    823789    /*
    824790     * Allocate memory for buffer pool descriptors
    825791     */
    826     bd_ctx.pool = calloc(size, sizeof(bdbuf_pool));
    827     if (bd_ctx.pool == NULL)
     792    rtems_bdbuf_ctx.pool = calloc(size, sizeof(bdbuf_pool));
     793    if (rtems_bdbuf_ctx.pool == NULL)
    828794    {
    829795        return RTEMS_NO_MEMORY;
    830796    }
    831797
    832     Chain_Initialize_empty(&bd_ctx.mod);
     798    Chain_Initialize_empty(&rtems_bdbuf_ctx.mod);
    833799
    834800    /* Initialize buffer pools and roll out if something failed */
     
    852818        RTEMS_FIFO | RTEMS_COUNTING_SEMAPHORE | RTEMS_NO_INHERIT_PRIORITY |
    853819        RTEMS_NO_PRIORITY_CEILING | RTEMS_LOCAL, 0,
    854         &bd_ctx.flush_sema);
     820        &rtems_bdbuf_ctx.flush_sema);
    855821    if (rc != RTEMS_SUCCESSFUL)
    856822    {
    857823        for (i = 0; i < size; i++)
    858824            bdbuf_release_pool(i);
    859         free(bd_ctx.pool);
     825        free(rtems_bdbuf_ctx.pool);
    860826        return rc;
    861827    }
     
    870836        RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT,
    871837        RTEMS_DEFAULT_ATTRIBUTES,
    872         &bd_ctx.swapout_task);
     838        &rtems_bdbuf_ctx.swapout_task);
    873839    if (rc != RTEMS_SUCCESSFUL)
    874840    {
    875         rtems_semaphore_delete(bd_ctx.flush_sema);
     841        rtems_semaphore_delete(rtems_bdbuf_ctx.flush_sema);
    876842        for (i = 0; i < size; i++)
    877843            bdbuf_release_pool(i);
    878         free(bd_ctx.pool);
     844        free(rtems_bdbuf_ctx.pool);
    879845        return rc;
    880846    }
    881847
    882     rc = rtems_task_start(bd_ctx.swapout_task, bdbuf_swapout_task, 0);
     848    rc = rtems_task_start(rtems_bdbuf_ctx.swapout_task, bdbuf_swapout_task, 0);
    883849    if (rc != RTEMS_SUCCESSFUL)
    884850    {
    885         rtems_task_delete(bd_ctx.swapout_task);
    886         rtems_semaphore_delete(bd_ctx.flush_sema);
     851        rtems_task_delete(rtems_bdbuf_ctx.swapout_task);
     852        rtems_semaphore_delete(rtems_bdbuf_ctx.flush_sema);
    887853        for (i = 0; i < size; i++)
    888854            bdbuf_release_pool(i);
    889         free(bd_ctx.pool);
     855        free(rtems_bdbuf_ctx.pool);
    890856        return rc;
    891857    }
     
    934900
    935901    device = dd->dev;
    936     bd_pool = bd_ctx.pool + dd->pool;
     902    bd_pool = rtems_bdbuf_ctx.pool + dd->pool;
    937903    blksize = dd->block_size;
    938904
     
    1022988            if (bd_buf->modified)
    1023989            {
    1024                 rc = rtems_semaphore_obtain(bd_ctx.flush_sema,
     990                rc = rtems_semaphore_obtain(rtems_bdbuf_ctx.flush_sema,
    1025991                                            RTEMS_NO_WAIT, 0);
    1026992            }
     
    14771443        return RTEMS_INTERNAL_ERROR;
    14781444
    1479     bd_pool = bd_ctx.pool + bd_buf->pool;
     1445    bd_pool = rtems_bdbuf_ctx.pool + bd_buf->pool;
    14801446
    14811447    bd_buf->use_count--;
     
    14881454            /* Buffer was modified. Insert buffer to the modified buffers
    14891455             * list and initiate flushing. */
    1490             Chain_Append(&bd_ctx.mod, &bd_buf->link);
     1456            Chain_Append(&rtems_bdbuf_ctx.mod, &bd_buf->link);
    14911457
    14921458            /* Release the flush_sema */
    1493             rc = rtems_semaphore_release(bd_ctx.flush_sema);
     1459            rc = rtems_semaphore_release(rtems_bdbuf_ctx.flush_sema);
    14941460        }
    14951461        else
     
    16601626        return RTEMS_INVALID_ID;
    16611627
    1662     pool = bd_ctx.pool + dd->pool;
     1628    pool = rtems_bdbuf_ctx.pool + dd->pool;
    16631629
    16641630    DISABLE_PREEMPTION(key);
     
    17191685           */
    17201686          if (nxt_bd_buf == NULL) {
    1721             rc = rtems_semaphore_obtain(bd_ctx.flush_sema,
     1687            rc = rtems_semaphore_obtain(rtems_bdbuf_ctx.flush_sema,
    17221688                                        (req.req.count == 0)
    17231689                                        ? RTEMS_WAIT
     
    17251691                                        0);
    17261692            if (rc == RTEMS_SUCCESSFUL) {
    1727               nxt_bd_buf = (bdbuf_buffer *)Chain_Get(&bd_ctx.mod);
     1693              nxt_bd_buf = (bdbuf_buffer *)Chain_Get(&rtems_bdbuf_ctx.mod);
    17281694          if (nxt_bd_buf != NULL) {
    17291695                nxt_bd_buf->in_progress = TRUE;
     
    17651731           */
    17661732          if (bd_buf != NULL) {
    1767             bd_pool = bd_ctx.pool + bd_buf->pool;
     1733            bd_pool = rtems_bdbuf_ctx.pool + bd_buf->pool;
    17681734            if (req.req.count == 0) {
    17691735              /*
     
    18191785              if (bd_buf->modified)
    18201786                {
    1821                   Chain_Append(&bd_ctx.mod, &bd_buf->link);
    1822                   rc = rtems_semaphore_release(bd_ctx.flush_sema);
     1787                  Chain_Append(&rtems_bdbuf_ctx.mod, &bd_buf->link);
     1788                  rc = rtems_semaphore_release(rtems_bdbuf_ctx.flush_sema);
    18231789                }
    18241790              else
     
    18611827        return RTEMS_INVALID_SIZE;
    18621828
    1863     for (i = 0, p = bd_ctx.pool; i < bd_ctx.npools; i++, p++)
     1829    for (i = 0, p = rtems_bdbuf_ctx.pool; i < rtems_bdbuf_ctx.npools; i++, p++)
    18641830    {
    18651831        if ((p->blksize >= block_size) &&
     
    19041870                          int *blocks)
    19051871{
    1906     if (pool >= bd_ctx.npools)
     1872    if (pool >= rtems_bdbuf_ctx.npools)
    19071873        return RTEMS_INVALID_NUMBER;
    19081874
    19091875    if (block_size != NULL)
    19101876    {
    1911         *block_size = bd_ctx.pool[pool].blksize;
     1877        *block_size = rtems_bdbuf_ctx.pool[pool].blksize;
    19121878    }
    19131879
    19141880    if (blocks != NULL)
    19151881    {
    1916         *blocks = bd_ctx.pool[pool].nblks;
     1882        *blocks = rtems_bdbuf_ctx.pool[pool].nblks;
    19171883    }
    19181884
Note: See TracChangeset for help on using the changeset viewer.