Subversion Repositories HelenOS

Rev

Rev 4537 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 4537 Rev 4668
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
#include <task.h>
49
 
50
 
50
#define NAME "gxe_bd"
51
#define NAME "gxe_bd"
51
 
52
 
52
enum {
53
enum {
53
    CTL_READ_START  = 0,
54
    CTL_READ_START  = 0,
Line 89... Line 90...
89
static uintptr_t dev_physical = 0x13000000;
90
static uintptr_t dev_physical = 0x13000000;
90
static gxe_bd_t *dev;
91
static gxe_bd_t *dev;
91
 
92
 
92
static dev_handle_t dev_handle[MAX_DISKS];
93
static dev_handle_t dev_handle[MAX_DISKS];
93
 
94
 
94
static atomic_t dev_futex = FUTEX_INITIALIZER;
95
static fibril_mutex_t dev_lock[MAX_DISKS];
95
 
96
 
96
static int gxe_bd_init(void);
97
static int gxe_bd_init(void);
97
static void gxe_bd_connection(ipc_callid_t iid, ipc_call_t *icall);
98
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, off_t size,
99
static int gx_bd_rdwr(int disk_id, ipcarg_t method, off_t offset, size_t size,
99
    void *buf);
100
    void *buf);
100
static int gxe_bd_read_block(int disk_id, uint64_t offset, size_t size,
101
static int gxe_bd_read_block(int disk_id, uint64_t offset, size_t size,
101
    void *buf);
102
    void *buf);
102
static int gxe_bd_write_block(int disk_id, uint64_t offset, size_t size,
103
static int gxe_bd_write_block(int disk_id, uint64_t offset, size_t size,
103
    const void *buf);
104
    const void *buf);
Line 108... Line 109...
108
 
109
 
109
    if (gxe_bd_init() != EOK)
110
    if (gxe_bd_init() != EOK)
110
        return -1;
111
        return -1;
111
 
112
 
112
    printf(NAME ": Accepting connections\n");
113
    printf(NAME ": Accepting connections\n");
-
 
114
    task_retval(0);
113
    async_manager();
115
    async_manager();
114
 
116
 
115
    /* Not reached */
117
    /* Not reached */
116
    return 0;
118
    return 0;
117
}
119
}
Line 143... Line 145...
143
            devmap_hangup_phone(DEVMAP_DRIVER);
145
            devmap_hangup_phone(DEVMAP_DRIVER);
144
            printf(NAME ": Unable to register device %s.\n",
146
            printf(NAME ": Unable to register device %s.\n",
145
                name);
147
                name);
146
            return rc;
148
            return rc;
147
        }
149
        }
-
 
150
        fibril_mutex_initialize(&dev_lock[i]);
148
    }
151
    }
149
 
152
 
150
    return EOK;
153
    return EOK;
151
}
154
}
152
 
155
 
Line 158... Line 161...
158
    ipcarg_t method;
161
    ipcarg_t method;
159
    dev_handle_t dh;
162
    dev_handle_t dh;
160
    int flags;
163
    int flags;
161
    int retval;
164
    int retval;
162
    off_t idx;
165
    off_t idx;
163
    off_t size;
166
    size_t size;
164
    int disk_id, i;
167
    int disk_id, i;
165
 
168
 
166
    /* Get the device handle. */
169
    /* Get the device handle. */
167
    dh = IPC_GET_ARG1(*icall);
170
    dh = IPC_GET_ARG1(*icall);
168
 
171
 
Line 218... Line 221...
218
        }
221
        }
219
        ipc_answer_0(callid, retval);
222
        ipc_answer_0(callid, retval);
220
    }
223
    }
221
}
224
}
222
 
225
 
223
static int gx_bd_rdwr(int disk_id, ipcarg_t method, off_t offset, off_t size,
226
static int gx_bd_rdwr(int disk_id, ipcarg_t method, off_t offset, size_t size,
224
    void *buf)
227
    void *buf)
225
{
228
{
226
    int rc;
229
    int rc;
227
    size_t now;
230
    size_t now;
228
 
231
 
Line 254... Line 257...
254
{
257
{
255
    uint32_t status;
258
    uint32_t status;
256
    size_t i;
259
    size_t i;
257
    uint32_t w;
260
    uint32_t w;
258
 
261
 
259
    futex_down(&dev_futex);
262
    fibril_mutex_lock(&dev_lock[disk_id]);
260
    pio_write_32(&dev->offset_lo, (uint32_t) offset);
263
    pio_write_32(&dev->offset_lo, (uint32_t) offset);
261
    pio_write_32(&dev->offset_hi, offset >> 32);
264
    pio_write_32(&dev->offset_hi, offset >> 32);
262
    pio_write_32(&dev->disk_id, disk_id);
265
    pio_write_32(&dev->disk_id, disk_id);
263
    pio_write_32(&dev->control, CTL_READ_START);
266
    pio_write_32(&dev->control, CTL_READ_START);
264
 
267
 
265
    status = pio_read_32(&dev->status);
268
    status = pio_read_32(&dev->status);
266
    if (status == STATUS_FAILURE) {
269
    if (status == STATUS_FAILURE) {
-
 
270
        fibril_mutex_unlock(&dev_lock[disk_id]);
267
        return EIO;
271
        return EIO;
268
    }
272
    }
269
 
273
 
270
    for (i = 0; i < size; i++) {
274
    for (i = 0; i < size; i++) {
271
        ((uint8_t *) buf)[i] = w = pio_read_8(&dev->buffer[i]);
275
        ((uint8_t *) buf)[i] = w = pio_read_8(&dev->buffer[i]);
272
    }
276
    }
273
 
277
 
274
    futex_up(&dev_futex);
278
    fibril_mutex_unlock(&dev_lock[disk_id]);
275
    return EOK;
279
    return EOK;
276
}
280
}
277
 
281
 
278
static int gxe_bd_write_block(int disk_id, uint64_t offset, size_t size,
282
static int gxe_bd_write_block(int disk_id, uint64_t offset, size_t size,
279
    const void *buf)
283
    const void *buf)
Line 283... Line 287...
283
 
287
 
284
    for (i = 0; i < size; i++) {
288
    for (i = 0; i < size; i++) {
285
        pio_write_8(&dev->buffer[i], ((const uint8_t *) buf)[i]);
289
        pio_write_8(&dev->buffer[i], ((const uint8_t *) buf)[i]);
286
    }
290
    }
287
 
291
 
288
    futex_down(&dev_futex);
292
    fibril_mutex_lock(&dev_lock[disk_id]);
289
    pio_write_32(&dev->offset_lo, (uint32_t) offset);
293
    pio_write_32(&dev->offset_lo, (uint32_t) offset);
290
    pio_write_32(&dev->offset_hi, offset >> 32);
294
    pio_write_32(&dev->offset_hi, offset >> 32);
291
    pio_write_32(&dev->disk_id, disk_id);
295
    pio_write_32(&dev->disk_id, disk_id);
292
    pio_write_32(&dev->control, CTL_WRITE_START);
296
    pio_write_32(&dev->control, CTL_WRITE_START);
293
 
297
 
294
    status = pio_read_32(&dev->status);
298
    status = pio_read_32(&dev->status);
295
    if (status == STATUS_FAILURE) {
299
    if (status == STATUS_FAILURE) {
-
 
300
        fibril_mutex_unlock(&dev_lock[disk_id]);
296
        return EIO;
301
        return EIO;
297
    }
302
    }
298
 
303
 
299
    futex_up(&dev_futex);
304
    fibril_mutex_unlock(&dev_lock[disk_id]);
300
    return EOK;
305
    return EOK;
301
}
306
}
302
 
307
 
303
/**
308
/**
304
 * @}
309
 * @}