Changeset 12956e57 in mainline
- Timestamp:
- 2009-06-20T19:31:19Z (16 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 2dfd9fa
- Parents:
- ac47b7c2
- Location:
- uspace/srv/bd
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/bd/ata_bd/ata_bd.c
rac47b7c2 r12956e57 38 38 * Currently based on the (now obsolete) ANSI X3.221-1994 (ATA-1) standard. 39 39 * 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. 40 43 */ 41 44 … … 47 50 #include <async.h> 48 51 #include <as.h> 49 #include <f utex.h>52 #include <fibril_sync.h> 50 53 #include <devmap.h> 51 54 #include <sys/types.h> … … 65 68 static ata_ctl_t *ctl; 66 69 67 static dev_handle_t dev_handle[MAX_DISKS]; 68 69 static atomic_t dev_futex = FUTEX_INITIALIZER; 70 70 /** Per-disk state. */ 71 71 static disk_t disk[MAX_DISKS]; 72 72 … … 90 90 printf(NAME ": ATA disk driver\n"); 91 91 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); 94 93 95 94 if (ata_bd_init() != EOK) … … 121 120 122 121 snprintf(name, 16, "disk%d", i); 123 rc = devmap_device_register(name, &d ev_handle[i]);122 rc = devmap_device_register(name, &disk[i].dev_handle); 124 123 if (rc != EOK) { 125 124 devmap_hangup_phone(DEVMAP_DRIVER); … … 182 181 } 183 182 184 printf("\n\nStatus = 0x%x\n", pio_read_8(&cmd->status));185 186 183 d->blocks = d->cylinders * d->heads * d->sectors; 187 184 … … 190 187 191 188 d->present = true; 189 fibril_mutex_initialize(&d->lock); 192 190 193 191 return EOK; … … 244 242 disk_id = -1; 245 243 for (i = 0; i < MAX_DISKS; i++) 246 if (d ev_handle[i]== dh)244 if (disk[i].dev_handle == dh) 247 245 disk_id = i; 248 246 … … 356 354 (h & 0x0f); 357 355 358 f utex_down(&dev_futex);356 fibril_mutex_lock(&d->lock); 359 357 360 358 /* Program a Read Sectors operation. */ … … 378 376 } 379 377 380 f utex_up(&dev_futex);378 fibril_mutex_unlock(&d->lock); 381 379 return EOK; 382 380 } … … 410 408 (h & 0x0f); 411 409 412 f utex_down(&dev_futex);410 fibril_mutex_lock(&d->lock); 413 411 414 412 /* Program a Read Sectors operation. */ … … 431 429 } 432 430 433 f utex_up(&dev_futex);431 fibril_mutex_unlock(&d->lock); 434 432 return EOK; 435 433 } -
uspace/srv/bd/ata_bd/ata_bd.h
rac47b7c2 r12956e57 37 37 38 38 #include <sys/types.h> 39 #include <fibril_sync.h> 39 40 40 41 enum { … … 140 141 unsigned sectors; 141 142 uint64_t blocks; 143 144 fibril_mutex_t lock; 145 dev_handle_t dev_handle; 142 146 } disk_t; 143 147 -
uspace/srv/bd/file_bd/file_bd.c
rac47b7c2 r12956e57 45 45 #include <async.h> 46 46 #include <as.h> 47 #include <f utex.h>47 #include <fibril_sync.h> 48 48 #include <devmap.h> 49 49 #include <sys/types.h> … … 57 57 58 58 static dev_handle_t dev_handle; 59 static atomic_t dev_futex = FUTEX_INITIALIZER;59 static fibril_mutex_t dev_lock; 60 60 61 61 static int file_bd_init(const char *fname); … … 106 106 if (img == NULL) 107 107 return EINVAL; 108 109 fibril_mutex_initialize(&dev_lock); 108 110 109 111 return EOK; … … 170 172 size_t n_rd; 171 173 172 printf("file_bd_read\n"); 173 futex_down(&dev_futex); 174 175 printf("seek\n"); 174 fibril_mutex_lock(&dev_lock); 175 176 176 fseek(img, blk_idx * size, SEEK_SET); 177 printf("read\n");178 177 n_rd = fread(buf, 1, size, img); 179 printf("done\n");180 181 printf("done\n");182 178 183 179 if (ferror(img)) { 184 f utex_up(&dev_futex);180 fibril_mutex_unlock(&dev_lock); 185 181 return EIO; /* Read error */ 186 182 } 187 183 188 f utex_up(&dev_futex);184 fibril_mutex_unlock(&dev_lock); 189 185 190 186 if (n_rd < size) … … 198 194 size_t n_wr; 199 195 200 f utex_down(&dev_futex);196 fibril_mutex_lock(&dev_lock); 201 197 202 198 fseek(img, blk_idx * size, SEEK_SET); … … 204 200 205 201 if (ferror(img) || n_wr < size) { 206 f utex_up(&dev_futex);202 fibril_mutex_unlock(&dev_lock); 207 203 return EIO; /* Write error */ 208 204 } 209 205 210 f utex_up(&dev_futex);206 fibril_mutex_unlock(&dev_lock); 211 207 212 208 return EOK; -
uspace/srv/bd/gxe_bd/gxe_bd.c
rac47b7c2 r12956e57 43 43 #include <async.h> 44 44 #include <as.h> 45 #include <f utex.h>45 #include <fibril_sync.h> 46 46 #include <devmap.h> 47 47 #include <sys/types.h> … … 92 92 static dev_handle_t dev_handle[MAX_DISKS]; 93 93 94 static atomic_t dev_futex = FUTEX_INITIALIZER;94 static fibril_mutex_t dev_lock[MAX_DISKS]; 95 95 96 96 static int gxe_bd_init(void); … … 146 146 return rc; 147 147 } 148 fibril_mutex_initialize(&dev_lock[i]); 148 149 } 149 150 … … 257 258 uint32_t w; 258 259 259 f utex_down(&dev_futex);260 fibril_mutex_lock(&dev_lock[disk_id]); 260 261 pio_write_32(&dev->offset_lo, (uint32_t) offset); 261 262 pio_write_32(&dev->offset_hi, offset >> 32); … … 265 266 status = pio_read_32(&dev->status); 266 267 if (status == STATUS_FAILURE) { 268 fibril_mutex_unlock(&dev_lock[disk_id]); 267 269 return EIO; 268 270 } … … 272 274 } 273 275 274 f utex_up(&dev_futex);276 fibril_mutex_unlock(&dev_lock[disk_id]); 275 277 return EOK; 276 278 } … … 286 288 } 287 289 288 f utex_down(&dev_futex);290 fibril_mutex_lock(&dev_lock[disk_id]); 289 291 pio_write_32(&dev->offset_lo, (uint32_t) offset); 290 292 pio_write_32(&dev->offset_hi, offset >> 32); … … 294 296 status = pio_read_32(&dev->status); 295 297 if (status == STATUS_FAILURE) { 298 fibril_mutex_unlock(&dev_lock[disk_id]); 296 299 return EIO; 297 300 } 298 301 299 f utex_up(&dev_futex);302 fibril_mutex_unlock(&dev_lock[disk_id]); 300 303 return EOK; 301 304 }
Note:
See TracChangeset
for help on using the changeset viewer.