Subversion Repositories HelenOS

Rev

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

Rev 4439 Rev 4537
Line 56... Line 56...
56
 
56
 
57
enum {
57
enum {
58
    STATUS_FAILURE  = 0
58
    STATUS_FAILURE  = 0
59
};
59
};
60
 
60
 
-
 
61
enum {
-
 
62
    MAX_DISKS   = 2
-
 
63
};
-
 
64
 
61
typedef struct {
65
typedef struct {
62
    uint32_t offset_lo;
66
    uint32_t offset_lo;
63
    uint32_t pad0;
67
    uint32_t pad0;
64
    uint32_t offset_hi;
68
    uint32_t offset_hi;
65
    uint32_t pad1;
69
    uint32_t pad1;
Line 70... Line 74...
70
    uint32_t control;
74
    uint32_t control;
71
    uint32_t pad3[3];
75
    uint32_t pad3[3];
72
 
76
 
73
    uint32_t status;
77
    uint32_t status;
74
 
78
 
75
/*  FIXME: Need to fix pio_enable() to support >= page_size areas.
-
 
76
 
-
 
77
    uint32_t pad4[3];
79
    uint32_t pad4[3];
78
    uint32_t pad5[0x3fc0];
80
    uint8_t pad5[0x3fc0];
79
 
81
 
80
    uint8_t buffer[512];*/
82
    uint8_t buffer[512];
81
} gxe_bd_t;
83
} gxe_bd_t;
82
 
84
 
83
typedef struct {
-
 
84
    uint8_t buffer[512];
-
 
85
} gxe_buf_t;
-
 
86
 
85
 
87
static const size_t block_size = 512;
86
static const size_t block_size = 512;
88
static size_t comm_size;
87
static size_t comm_size;
89
 
88
 
90
static uintptr_t dev_physical = 0x13000000;
89
static uintptr_t dev_physical = 0x13000000;
91
static gxe_bd_t *dev;
90
static gxe_bd_t *dev;
92
static gxe_buf_t *devbuf;
-
 
93
 
91
 
94
static uint32_t disk_id = 0;
92
static dev_handle_t dev_handle[MAX_DISKS];
95
 
93
 
96
static atomic_t dev_futex = FUTEX_INITIALIZER;
94
static atomic_t dev_futex = FUTEX_INITIALIZER;
97
 
95
 
98
static int gxe_bd_init(void);
96
static int gxe_bd_init(void);
99
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);
100
static int gx_bd_rdwr(ipcarg_t method, off_t offset, off_t size, void *buf);
98
static int gx_bd_rdwr(int disk_id, ipcarg_t method, off_t offset, off_t size,
-
 
99
    void *buf);
101
static int gxe_bd_read_block(uint64_t offset, size_t size, void *buf);
100
static int gxe_bd_read_block(int disk_id, uint64_t offset, size_t size,
-
 
101
    void *buf);
102
static int gxe_bd_write_block(uint64_t offset, size_t size, const void *buf);
102
static int gxe_bd_write_block(int disk_id, uint64_t offset, size_t size,
-
 
103
    const void *buf);
103
 
104
 
104
int main(int argc, char **argv)
105
int main(int argc, char **argv)
105
{
106
{
106
    printf(NAME ": GXemul disk driver\n");
107
    printf(NAME ": GXemul disk driver\n");
107
 
108
 
Line 115... Line 116...
115
    return 0;
116
    return 0;
116
}
117
}
117
 
118
 
118
static int gxe_bd_init(void)
119
static int gxe_bd_init(void)
119
{
120
{
120
    dev_handle_t dev_handle;
-
 
121
    void *vaddr;
121
    void *vaddr;
122
    int rc;
122
    int rc, i;
-
 
123
    char name[16];
123
 
124
 
124
    rc = devmap_driver_register(NAME, gxe_bd_connection);
125
    rc = devmap_driver_register(NAME, gxe_bd_connection);
125
    if (rc < 0) {
126
    if (rc < 0) {
126
        printf(NAME ": Unable to register driver.\n");
127
        printf(NAME ": Unable to register driver.\n");
127
        return rc;
128
        return rc;
Line 133... Line 134...
133
        return rc;
134
        return rc;
134
    }
135
    }
135
 
136
 
136
    dev = vaddr;
137
    dev = vaddr;
137
 
138
 
138
    rc = pio_enable((void *) dev_physical + 0x4000, sizeof(gxe_buf_t), &vaddr);
-
 
139
    if (rc != EOK) {
139
    for (i = 0; i < MAX_DISKS; i++) {
140
        printf(NAME ": Could not initialize device I/O space.\n");
140
        snprintf(name, 16, "disk%d", i);
141
        return rc;
-
 
142
    }
-
 
143
 
-
 
144
    devbuf = vaddr;
-
 
145
 
-
 
146
    rc = devmap_device_register("disk0", &dev_handle);
141
        rc = devmap_device_register(name, &dev_handle[i]);
147
    if (rc != EOK) {
142
        if (rc != EOK) {
148
        devmap_hangup_phone(DEVMAP_DRIVER);
143
            devmap_hangup_phone(DEVMAP_DRIVER);
149
        printf(NAME ": Unable to register device.\n");
144
            printf(NAME ": Unable to register device %s.\n",
-
 
145
                name);
150
        return rc;
146
            return rc;
-
 
147
        }
151
    }
148
    }
152
 
149
 
153
    return EOK;
150
    return EOK;
154
}
151
}
155
 
152
 
Line 157... Line 154...
157
{
154
{
158
    void *fs_va = NULL;
155
    void *fs_va = NULL;
159
    ipc_callid_t callid;
156
    ipc_callid_t callid;
160
    ipc_call_t call;
157
    ipc_call_t call;
161
    ipcarg_t method;
158
    ipcarg_t method;
-
 
159
    dev_handle_t dh;
162
    int flags;
160
    int flags;
163
    int retval;
161
    int retval;
164
    off_t idx;
162
    off_t idx;
165
    off_t size;
163
    off_t size;
-
 
164
    int disk_id, i;
-
 
165
 
-
 
166
    /* Get the device handle. */
-
 
167
    dh = IPC_GET_ARG1(*icall);
-
 
168
 
-
 
169
    /* Determine which disk device is the client connecting to. */
-
 
170
    disk_id = -1;
-
 
171
    for (i = 0; i < MAX_DISKS; i++)
-
 
172
        if (dev_handle[i] == dh)
-
 
173
            disk_id = i;
-
 
174
 
-
 
175
    if (disk_id < 0) {
-
 
176
        ipc_answer_0(iid, EINVAL);
-
 
177
        return;
-
 
178
    }
166
 
179
 
167
    /* Answer the IPC_M_CONNECT_ME_TO call. */
180
    /* Answer the IPC_M_CONNECT_ME_TO call. */
168
    ipc_answer_0(iid, EOK);
181
    ipc_answer_0(iid, EOK);
169
 
182
 
170
    if (!ipc_share_out_receive(&callid, &comm_size, &flags)) {
183
    if (!ipc_share_out_receive(&callid, &comm_size, &flags)) {
Line 194... Line 207...
194
            size = IPC_GET_ARG2(call);
207
            size = IPC_GET_ARG2(call);
195
            if (size > comm_size) {
208
            if (size > comm_size) {
196
                retval = EINVAL;
209
                retval = EINVAL;
197
                break;
210
                break;
198
            }
211
            }
199
            retval = gx_bd_rdwr(method, idx * size, size, fs_va);
212
            retval = gx_bd_rdwr(disk_id, method, idx * size,
-
 
213
                size, fs_va);
200
            break;
214
            break;
201
        default:
215
        default:
202
            retval = EINVAL;
216
            retval = EINVAL;
203
            break;
217
            break;
204
        }
218
        }
205
        ipc_answer_0(callid, retval);
219
        ipc_answer_0(callid, retval);
206
    }
220
    }
207
}
221
}
208
 
222
 
209
static int gx_bd_rdwr(ipcarg_t method, off_t offset, off_t size, void *buf)
223
static int gx_bd_rdwr(int disk_id, ipcarg_t method, off_t offset, off_t size,
-
 
224
    void *buf)
210
{
225
{
211
    int rc;
226
    int rc;
212
    size_t now;
227
    size_t now;
213
 
228
 
214
    while (size > 0) {
229
    while (size > 0) {
215
        now = size < block_size ? size : block_size;
230
        now = size < block_size ? size : block_size;
216
 
231
 
217
        if (method == BD_READ_BLOCK)
232
        if (method == BD_READ_BLOCK)
218
            rc = gxe_bd_read_block(offset, now, buf);
233
            rc = gxe_bd_read_block(disk_id, offset, now, buf);
219
        else
234
        else
220
            rc = gxe_bd_write_block(offset, now, buf);
235
            rc = gxe_bd_write_block(disk_id, offset, now, buf);
221
 
236
 
222
        if (rc != EOK)
237
        if (rc != EOK)
223
            return rc;
238
            return rc;
224
 
239
 
225
        buf += block_size;
240
        buf += block_size;
Line 232... Line 247...
232
    }
247
    }
233
 
248
 
234
    return EOK;
249
    return EOK;
235
}
250
}
236
 
251
 
237
static int gxe_bd_read_block(uint64_t offset, size_t size, void *buf)
252
static int gxe_bd_read_block(int disk_id, uint64_t offset, size_t size,
-
 
253
    void *buf)
238
{
254
{
239
    uint32_t status;
255
    uint32_t status;
240
    size_t i;
256
    size_t i;
241
    uint32_t w;
257
    uint32_t w;
242
 
258
 
Line 250... Line 266...
250
    if (status == STATUS_FAILURE) {
266
    if (status == STATUS_FAILURE) {
251
        return EIO;
267
        return EIO;
252
    }
268
    }
253
 
269
 
254
    for (i = 0; i < size; i++) {
270
    for (i = 0; i < size; i++) {
255
        ((uint8_t *) buf)[i] = w =
-
 
256
            pio_read_8(&devbuf->buffer[i]);
271
        ((uint8_t *) buf)[i] = w = pio_read_8(&dev->buffer[i]);
257
    }
272
    }
258
 
273
 
259
    futex_up(&dev_futex);
274
    futex_up(&dev_futex);
260
    return EOK;
275
    return EOK;
261
}
276
}
262
 
277
 
263
static int gxe_bd_write_block(uint64_t offset, size_t size, const void *buf)
278
static int gxe_bd_write_block(int disk_id, uint64_t offset, size_t size,
-
 
279
    const void *buf)
264
{
280
{
265
    uint32_t status;
281
    uint32_t status;
266
    size_t i;
282
    size_t i;
267
    uint32_t w;
-
 
268
 
283
 
269
    for (i = 0; i < size; i++) {
284
    for (i = 0; i < size; i++) {
270
        pio_write_8(&devbuf->buffer[i], ((const uint8_t *) buf)[i]);
285
        pio_write_8(&dev->buffer[i], ((const uint8_t *) buf)[i]);
271
    }
286
    }
272
 
287
 
273
    futex_down(&dev_futex);
288
    futex_down(&dev_futex);
274
    pio_write_32(&dev->offset_lo, (uint32_t) offset);
289
    pio_write_32(&dev->offset_lo, (uint32_t) offset);
275
    pio_write_32(&dev->offset_hi, offset >> 32);
290
    pio_write_32(&dev->offset_hi, offset >> 32);