Subversion Repositories HelenOS

Rev

Rev 4545 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 4545 Rev 4557
Line 40... Line 40...
40
#include <ddi.h>
40
#include <ddi.h>
41
#include <ipc/ipc.h>
41
#include <ipc/ipc.h>
42
#include <ipc/bd.h>
42
#include <ipc/bd.h>
43
#include <async.h>
43
#include <async.h>
44
#include <as.h>
44
#include <as.h>
45
#include <futex.h>
45
#include <fibril_sync.h>
46
#include <devmap.h>
46
#include <devmap.h>
47
#include <sys/types.h>
47
#include <sys/types.h>
48
#include <errno.h>
48
#include <errno.h>
49
 
49
 
50
#define NAME "gxe_bd"
50
#define NAME "gxe_bd"
Line 89... Line 89...
89
static uintptr_t dev_physical = 0x13000000;
89
static uintptr_t dev_physical = 0x13000000;
90
static gxe_bd_t *dev;
90
static gxe_bd_t *dev;
91
 
91
 
92
static dev_handle_t dev_handle[MAX_DISKS];
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
static int gxe_bd_init(void);
96
static int gxe_bd_init(void);
97
static void gxe_bd_connection(ipc_callid_t iid, ipc_call_t *icall);
97
static void gxe_bd_connection(ipc_callid_t iid, ipc_call_t *icall);
98
static int gx_bd_rdwr(int disk_id, ipcarg_t method, off_t offset, size_t size,
98
static int gx_bd_rdwr(int disk_id, ipcarg_t method, off_t offset, size_t size,
99
    void *buf);
99
    void *buf);
Line 143... Line 143...
143
            devmap_hangup_phone(DEVMAP_DRIVER);
143
            devmap_hangup_phone(DEVMAP_DRIVER);
144
            printf(NAME ": Unable to register device %s.\n",
144
            printf(NAME ": Unable to register device %s.\n",
145
                name);
145
                name);
146
            return rc;
146
            return rc;
147
        }
147
        }
-
 
148
        fibril_mutex_initialize(&dev_lock[i]);
148
    }
149
    }
149
 
150
 
150
    return EOK;
151
    return EOK;
151
}
152
}
152
 
153
 
Line 254... Line 255...
254
{
255
{
255
    uint32_t status;
256
    uint32_t status;
256
    size_t i;
257
    size_t i;
257
    uint32_t w;
258
    uint32_t w;
258
 
259
 
259
    futex_down(&dev_futex);
260
    fibril_mutex_lock(&dev_lock[disk_id]);
260
    pio_write_32(&dev->offset_lo, (uint32_t) offset);
261
    pio_write_32(&dev->offset_lo, (uint32_t) offset);
261
    pio_write_32(&dev->offset_hi, offset >> 32);
262
    pio_write_32(&dev->offset_hi, offset >> 32);
262
    pio_write_32(&dev->disk_id, disk_id);
263
    pio_write_32(&dev->disk_id, disk_id);
263
    pio_write_32(&dev->control, CTL_READ_START);
264
    pio_write_32(&dev->control, CTL_READ_START);
264
 
265
 
265
    status = pio_read_32(&dev->status);
266
    status = pio_read_32(&dev->status);
266
    if (status == STATUS_FAILURE) {
267
    if (status == STATUS_FAILURE) {
-
 
268
        fibril_mutex_unlock(&dev_lock[disk_id]);
267
        return EIO;
269
        return EIO;
268
    }
270
    }
269
 
271
 
270
    for (i = 0; i < size; i++) {
272
    for (i = 0; i < size; i++) {
271
        ((uint8_t *) buf)[i] = w = pio_read_8(&dev->buffer[i]);
273
        ((uint8_t *) buf)[i] = w = pio_read_8(&dev->buffer[i]);
272
    }
274
    }
273
 
275
 
274
    futex_up(&dev_futex);
276
    fibril_mutex_unlock(&dev_lock[disk_id]);
275
    return EOK;
277
    return EOK;
276
}
278
}
277
 
279
 
278
static int gxe_bd_write_block(int disk_id, uint64_t offset, size_t size,
280
static int gxe_bd_write_block(int disk_id, uint64_t offset, size_t size,
279
    const void *buf)
281
    const void *buf)
Line 283... Line 285...
283
 
285
 
284
    for (i = 0; i < size; i++) {
286
    for (i = 0; i < size; i++) {
285
        pio_write_8(&dev->buffer[i], ((const uint8_t *) buf)[i]);
287
        pio_write_8(&dev->buffer[i], ((const uint8_t *) buf)[i]);
286
    }
288
    }
287
 
289
 
288
    futex_down(&dev_futex);
290
    fibril_mutex_lock(&dev_lock[disk_id]);
289
    pio_write_32(&dev->offset_lo, (uint32_t) offset);
291
    pio_write_32(&dev->offset_lo, (uint32_t) offset);
290
    pio_write_32(&dev->offset_hi, offset >> 32);
292
    pio_write_32(&dev->offset_hi, offset >> 32);
291
    pio_write_32(&dev->disk_id, disk_id);
293
    pio_write_32(&dev->disk_id, disk_id);
292
    pio_write_32(&dev->control, CTL_WRITE_START);
294
    pio_write_32(&dev->control, CTL_WRITE_START);
293
 
295
 
294
    status = pio_read_32(&dev->status);
296
    status = pio_read_32(&dev->status);
295
    if (status == STATUS_FAILURE) {
297
    if (status == STATUS_FAILURE) {
-
 
298
        fibril_mutex_unlock(&dev_lock[disk_id]);
296
        return EIO;
299
        return EIO;
297
    }
300
    }
298
 
301
 
299
    futex_up(&dev_futex);
302
    fibril_mutex_unlock(&dev_lock[disk_id]);
300
    return EOK;
303
    return EOK;
301
}
304
}
302
 
305
 
303
/**
306
/**
304
 * @}
307
 * @}