Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset 12956e57 in mainline


Ignore:
Timestamp:
2009-06-20T19:31:19Z (13 years ago)
Author:
Jiri Svoboda <jirik.svoboda@…>
Branches:
lfn, master
Children:
2dfd9fa
Parents:
ac47b7c2
Message:

Use fibril synchronization in bd drivers. Use per-disk locks.

Location:
uspace/srv/bd
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/bd/ata_bd/ata_bd.c

    rac47b7c2 r12956e57  
    3838 * Currently based on the (now obsolete) ANSI X3.221-1994 (ATA-1) standard.
    3939 * At this point only reading is possible, not writing.
     40 *
     41 * The driver services a single controller which can have up to two disks
     42 * attached.
    4043 */
    4144
     
    4750#include <async.h>
    4851#include <as.h>
    49 #include <futex.h>
     52#include <fibril_sync.h>
    5053#include <devmap.h>
    5154#include <sys/types.h>
     
    6568static ata_ctl_t *ctl;
    6669
    67 static dev_handle_t dev_handle[MAX_DISKS];
    68 
    69 static atomic_t dev_futex = FUTEX_INITIALIZER;
    70 
     70/** Per-disk state. */
    7171static disk_t disk[MAX_DISKS];
    7272
     
    9090        printf(NAME ": ATA disk driver\n");
    9191
    92         printf("cmd_physical = 0x%x\n", cmd_physical);
    93         printf("ctl_physical = 0x%x\n", ctl_physical);
     92        printf("I/O address 0x%x\n", cmd_physical);
    9493
    9594        if (ata_bd_init() != EOK)
     
    121120
    122121                snprintf(name, 16, "disk%d", i);
    123                 rc = devmap_device_register(name, &dev_handle[i]);
     122                rc = devmap_device_register(name, &disk[i].dev_handle);
    124123                if (rc != EOK) {
    125124                        devmap_hangup_phone(DEVMAP_DRIVER);
     
    182181        }
    183182
    184         printf("\n\nStatus = 0x%x\n", pio_read_8(&cmd->status));
    185 
    186183        d->blocks = d->cylinders * d->heads * d->sectors;
    187184
     
    190187
    191188        d->present = true;
     189        fibril_mutex_initialize(&d->lock);
    192190
    193191        return EOK;
     
    244242        disk_id = -1;
    245243        for (i = 0; i < MAX_DISKS; i++)
    246                 if (dev_handle[i] == dh)
     244                if (disk[i].dev_handle == dh)
    247245                        disk_id = i;
    248246
     
    356354            (h & 0x0f);
    357355
    358         futex_down(&dev_futex);
     356        fibril_mutex_lock(&d->lock);
    359357
    360358        /* Program a Read Sectors operation. */
     
    378376        }
    379377
    380         futex_up(&dev_futex);
     378        fibril_mutex_unlock(&d->lock);
    381379        return EOK;
    382380}
     
    410408            (h & 0x0f);
    411409
    412         futex_down(&dev_futex);
     410        fibril_mutex_lock(&d->lock);
    413411
    414412        /* Program a Read Sectors operation. */
     
    431429        }
    432430
    433         futex_up(&dev_futex);
     431        fibril_mutex_unlock(&d->lock);
    434432        return EOK;
    435433}
  • uspace/srv/bd/ata_bd/ata_bd.h

    rac47b7c2 r12956e57  
    3737
    3838#include <sys/types.h>
     39#include <fibril_sync.h>
    3940
    4041enum {
     
    140141        unsigned sectors;
    141142        uint64_t blocks;
     143
     144        fibril_mutex_t lock;
     145        dev_handle_t dev_handle;
    142146} disk_t;
    143147
  • uspace/srv/bd/file_bd/file_bd.c

    rac47b7c2 r12956e57  
    4545#include <async.h>
    4646#include <as.h>
    47 #include <futex.h>
     47#include <fibril_sync.h>
    4848#include <devmap.h>
    4949#include <sys/types.h>
     
    5757
    5858static dev_handle_t dev_handle;
    59 static atomic_t dev_futex = FUTEX_INITIALIZER;
     59static fibril_mutex_t dev_lock;
    6060
    6161static int file_bd_init(const char *fname);
     
    106106        if (img == NULL)
    107107                return EINVAL;
     108
     109        fibril_mutex_initialize(&dev_lock);
    108110
    109111        return EOK;
     
    170172        size_t n_rd;
    171173
    172         printf("file_bd_read\n");
    173         futex_down(&dev_futex);
    174 
    175         printf("seek\n");
     174        fibril_mutex_lock(&dev_lock);
     175
    176176        fseek(img, blk_idx * size, SEEK_SET);
    177         printf("read\n");
    178177        n_rd = fread(buf, 1, size, img);
    179         printf("done\n");
    180 
    181         printf("done\n");
    182178
    183179        if (ferror(img)) {
    184                 futex_up(&dev_futex);
     180                fibril_mutex_unlock(&dev_lock);
    185181                return EIO;     /* Read error */
    186182        }
    187183
    188         futex_up(&dev_futex);
     184        fibril_mutex_unlock(&dev_lock);
    189185
    190186        if (n_rd < size)
     
    198194        size_t n_wr;
    199195
    200         futex_down(&dev_futex);
     196        fibril_mutex_lock(&dev_lock);
    201197
    202198        fseek(img, blk_idx * size, SEEK_SET);
     
    204200
    205201        if (ferror(img) || n_wr < size) {
    206                 futex_up(&dev_futex);
     202                fibril_mutex_unlock(&dev_lock);
    207203                return EIO;     /* Write error */
    208204        }
    209205
    210         futex_up(&dev_futex);
     206        fibril_mutex_unlock(&dev_lock);
    211207
    212208        return EOK;
  • uspace/srv/bd/gxe_bd/gxe_bd.c

    rac47b7c2 r12956e57  
    4343#include <async.h>
    4444#include <as.h>
    45 #include <futex.h>
     45#include <fibril_sync.h>
    4646#include <devmap.h>
    4747#include <sys/types.h>
     
    9292static dev_handle_t dev_handle[MAX_DISKS];
    9393
    94 static atomic_t dev_futex = FUTEX_INITIALIZER;
     94static fibril_mutex_t dev_lock[MAX_DISKS];
    9595
    9696static int gxe_bd_init(void);
     
    146146                        return rc;
    147147                }
     148                fibril_mutex_initialize(&dev_lock[i]);
    148149        }
    149150
     
    257258        uint32_t w;
    258259
    259         futex_down(&dev_futex);
     260        fibril_mutex_lock(&dev_lock[disk_id]);
    260261        pio_write_32(&dev->offset_lo, (uint32_t) offset);
    261262        pio_write_32(&dev->offset_hi, offset >> 32);
     
    265266        status = pio_read_32(&dev->status);
    266267        if (status == STATUS_FAILURE) {
     268                fibril_mutex_unlock(&dev_lock[disk_id]);
    267269                return EIO;
    268270        }
     
    272274        }
    273275
    274         futex_up(&dev_futex);
     276        fibril_mutex_unlock(&dev_lock[disk_id]);
    275277        return EOK;
    276278}
     
    286288        }
    287289
    288         futex_down(&dev_futex);
     290        fibril_mutex_lock(&dev_lock[disk_id]);
    289291        pio_write_32(&dev->offset_lo, (uint32_t) offset);
    290292        pio_write_32(&dev->offset_hi, offset >> 32);
     
    294296        status = pio_read_32(&dev->status);
    295297        if (status == STATUS_FAILURE) {
     298                fibril_mutex_unlock(&dev_lock[disk_id]);
    296299                return EIO;
    297300        }
    298301
    299         futex_up(&dev_futex);
     302        fibril_mutex_unlock(&dev_lock[disk_id]);
    300303        return EOK;
    301304}
Note: See TracChangeset for help on using the changeset viewer.