Subversion Repositories HelenOS

Rev

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

Rev 4440 Rev 4442
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 83... Line 87...
83
static size_t comm_size;
87
static size_t comm_size;
84
 
88
 
85
static uintptr_t dev_physical = 0x13000000;
89
static uintptr_t dev_physical = 0x13000000;
86
static gxe_bd_t *dev;
90
static gxe_bd_t *dev;
87
 
91
 
88
static uint32_t disk_id = 0;
92
static dev_handle_t dev_handle[MAX_DISKS];
89
 
93
 
90
static atomic_t dev_futex = FUTEX_INITIALIZER;
94
static atomic_t dev_futex = FUTEX_INITIALIZER;
91
 
95
 
92
static int gxe_bd_init(void);
96
static int gxe_bd_init(void);
93
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);
94
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);
95
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);
96
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);
97
 
104
 
98
int main(int argc, char **argv)
105
int main(int argc, char **argv)
99
{
106
{
100
    printf(NAME ": GXemul disk driver\n");
107
    printf(NAME ": GXemul disk driver\n");
101
 
108
 
Line 109... Line 116...
109
    return 0;
116
    return 0;
110
}
117
}
111
 
118
 
112
static int gxe_bd_init(void)
119
static int gxe_bd_init(void)
113
{
120
{
114
    dev_handle_t dev_handle;
-
 
115
    void *vaddr;
121
    void *vaddr;
116
    int rc;
122
    int rc, i;
-
 
123
    char name[16];
117
 
124
 
118
    rc = devmap_driver_register(NAME, gxe_bd_connection);
125
    rc = devmap_driver_register(NAME, gxe_bd_connection);
119
    if (rc < 0) {
126
    if (rc < 0) {
120
        printf(NAME ": Unable to register driver.\n");
127
        printf(NAME ": Unable to register driver.\n");
121
        return rc;
128
        return rc;
Line 127... Line 134...
127
        return rc;
134
        return rc;
128
    }
135
    }
129
 
136
 
130
    dev = vaddr;
137
    dev = vaddr;
131
 
138
 
-
 
139
    for (i = 0; i < MAX_DISKS; i++) {
-
 
140
        snprintf(name, 16, "disk%d", i);
132
    rc = devmap_device_register("disk0", &dev_handle);
141
        rc = devmap_device_register(name, &dev_handle[i]);
133
    if (rc != EOK) {
142
        if (rc != EOK) {
134
        devmap_hangup_phone(DEVMAP_DRIVER);
143
            devmap_hangup_phone(DEVMAP_DRIVER);
135
        printf(NAME ": Unable to register device.\n");
144
            printf(NAME ": Unable to register device %s.\n",
-
 
145
                name);
136
        return rc;
146
            return rc;
-
 
147
        }
137
    }
148
    }
138
 
149
 
139
    return EOK;
150
    return EOK;
140
}
151
}
141
 
152
 
Line 143... Line 154...
143
{
154
{
144
    void *fs_va = NULL;
155
    void *fs_va = NULL;
145
    ipc_callid_t callid;
156
    ipc_callid_t callid;
146
    ipc_call_t call;
157
    ipc_call_t call;
147
    ipcarg_t method;
158
    ipcarg_t method;
-
 
159
    dev_handle_t dh;
148
    int flags;
160
    int flags;
149
    int retval;
161
    int retval;
150
    off_t idx;
162
    off_t idx;
151
    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
    }
152
 
179
 
153
    /* Answer the IPC_M_CONNECT_ME_TO call. */
180
    /* Answer the IPC_M_CONNECT_ME_TO call. */
154
    ipc_answer_0(iid, EOK);
181
    ipc_answer_0(iid, EOK);
155
 
182
 
156
    if (!ipc_share_out_receive(&callid, &comm_size, &flags)) {
183
    if (!ipc_share_out_receive(&callid, &comm_size, &flags)) {
Line 180... Line 207...
180
            size = IPC_GET_ARG2(call);
207
            size = IPC_GET_ARG2(call);
181
            if (size > comm_size) {
208
            if (size > comm_size) {
182
                retval = EINVAL;
209
                retval = EINVAL;
183
                break;
210
                break;
184
            }
211
            }
185
            retval = gx_bd_rdwr(method, idx * size, size, fs_va);
212
            retval = gx_bd_rdwr(disk_id, method, idx * size,
-
 
213
                size, fs_va);
186
            break;
214
            break;
187
        default:
215
        default:
188
            retval = EINVAL;
216
            retval = EINVAL;
189
            break;
217
            break;
190
        }
218
        }
191
        ipc_answer_0(callid, retval);
219
        ipc_answer_0(callid, retval);
192
    }
220
    }
193
}
221
}
194
 
222
 
195
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)
196
{
225
{
197
    int rc;
226
    int rc;
198
    size_t now;
227
    size_t now;
199
 
228
 
200
    while (size > 0) {
229
    while (size > 0) {
201
        now = size < block_size ? size : block_size;
230
        now = size < block_size ? size : block_size;
202
 
231
 
203
        if (method == BD_READ_BLOCK)
232
        if (method == BD_READ_BLOCK)
204
            rc = gxe_bd_read_block(offset, now, buf);
233
            rc = gxe_bd_read_block(disk_id, offset, now, buf);
205
        else
234
        else
206
            rc = gxe_bd_write_block(offset, now, buf);
235
            rc = gxe_bd_write_block(disk_id, offset, now, buf);
207
 
236
 
208
        if (rc != EOK)
237
        if (rc != EOK)
209
            return rc;
238
            return rc;
210
 
239
 
211
        buf += block_size;
240
        buf += block_size;
Line 218... Line 247...
218
    }
247
    }
219
 
248
 
220
    return EOK;
249
    return EOK;
221
}
250
}
222
 
251
 
223
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)
224
{
254
{
225
    uint32_t status;
255
    uint32_t status;
226
    size_t i;
256
    size_t i;
227
    uint32_t w;
257
    uint32_t w;
228
 
258
 
Line 243... Line 273...
243
 
273
 
244
    futex_up(&dev_futex);
274
    futex_up(&dev_futex);
245
    return EOK;
275
    return EOK;
246
}
276
}
247
 
277
 
248
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)
249
{
280
{
250
    uint32_t status;
281
    uint32_t status;
251
    size_t i;
282
    size_t i;
252
    uint32_t w;
-
 
253
 
283
 
254
    for (i = 0; i < size; i++) {
284
    for (i = 0; i < size; i++) {
255
        pio_write_8(&dev->buffer[i], ((const uint8_t *) buf)[i]);
285
        pio_write_8(&dev->buffer[i], ((const uint8_t *) buf)[i]);
256
    }
286
    }
257
 
287