Changeset 84adbf0 in mainline
- Timestamp:
- 2009-05-29T03:19:29Z (15 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 4bda76b
- Parents:
- 6b2f4c1
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/bd/gxe_bd/gxe_bd.c
r6b2f4c1 r84adbf0 59 59 }; 60 60 61 enum { 62 MAX_DISKS = 2 63 }; 64 61 65 typedef struct { 62 66 uint32_t offset_lo; … … 86 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 94 static atomic_t dev_futex = FUTEX_INITIALIZER; … … 92 96 static int gxe_bd_init(void); 93 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); 95 static int gxe_bd_read_block(uint64_t offset, size_t size, void *buf); 96 static int gxe_bd_write_block(uint64_t offset, size_t size, const void *buf); 98 static int gx_bd_rdwr(int disk_id, ipcarg_t method, off_t offset, off_t size, 99 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(int disk_id, uint64_t offset, size_t size, 103 const void *buf); 97 104 98 105 int main(int argc, char **argv) … … 112 119 static int gxe_bd_init(void) 113 120 { 114 dev_handle_t dev_handle;115 121 void *vaddr; 116 int rc; 122 int rc, i; 123 char name[16]; 117 124 118 125 rc = devmap_driver_register(NAME, gxe_bd_connection); … … 130 137 dev = vaddr; 131 138 132 rc = devmap_device_register("disk0", &dev_handle); 133 if (rc != EOK) { 134 devmap_hangup_phone(DEVMAP_DRIVER); 135 printf(NAME ": Unable to register device.\n"); 136 return rc; 139 for (i = 0; i < MAX_DISKS; i++) { 140 snprintf(name, 16, "disk%d", i); 141 rc = devmap_device_register(name, &dev_handle[i]); 142 if (rc != EOK) { 143 devmap_hangup_phone(DEVMAP_DRIVER); 144 printf(NAME ": Unable to register device %s.\n", 145 name); 146 return rc; 147 } 137 148 } 138 149 … … 146 157 ipc_call_t call; 147 158 ipcarg_t method; 159 dev_handle_t dh; 148 160 int flags; 149 161 int retval; 150 162 off_t idx; 151 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 180 /* Answer the IPC_M_CONNECT_ME_TO call. */ … … 183 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 214 break; 187 215 default: … … 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 226 int rc; … … 202 231 203 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 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 237 if (rc != 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 255 uint32_t status; … … 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 281 uint32_t status; 251 282 size_t i; 252 uint32_t w;253 283 254 284 for (i = 0; i < size; i++) {
Note:
See TracChangeset
for help on using the changeset viewer.