Changeset 7e55bed7 in mainline
- Timestamp:
- 2017-10-02T21:07:11Z (8 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- e27e36e
- Parents:
- 943aaf1b
- Location:
- uspace/srv/hw/bus/cuda_adb
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/hw/bus/cuda_adb/cuda_adb.c
r943aaf1b r7e55bed7 55 55 56 56 static void cuda_connection(ipc_callid_t, ipc_call_t *, void *); 57 static int cuda_init(cuda_ instance_t *);57 static int cuda_init(cuda_t *); 58 58 static void cuda_irq_handler(ipc_callid_t, ipc_call_t *, void *); 59 59 60 static void cuda_irq_listen(cuda_ instance_t *);61 static void cuda_irq_receive(cuda_ instance_t *);62 static void cuda_irq_rcv_end(cuda_ instance_t *, void *, size_t *);63 static void cuda_irq_send_start(cuda_ instance_t *);64 static void cuda_irq_send(cuda_ instance_t *);65 66 static void cuda_packet_handle(cuda_ instance_t *, uint8_t *, size_t);67 static void cuda_send_start(cuda_ instance_t *);68 static void cuda_autopoll_set(cuda_ instance_t *, bool);69 70 static void adb_packet_handle(cuda_ instance_t *, uint8_t *, size_t, bool);60 static void cuda_irq_listen(cuda_t *); 61 static void cuda_irq_receive(cuda_t *); 62 static void cuda_irq_rcv_end(cuda_t *, void *, size_t *); 63 static void cuda_irq_send_start(cuda_t *); 64 static void cuda_irq_send(cuda_t *); 65 66 static void cuda_packet_handle(cuda_t *, uint8_t *, size_t); 67 static void cuda_send_start(cuda_t *); 68 static void cuda_autopoll_set(cuda_t *, bool); 69 70 static void adb_packet_handle(cuda_t *, uint8_t *, size_t, bool); 71 71 72 72 static irq_pio_range_t cuda_ranges[] = { 73 73 { 74 74 .base = 0, 75 .size = sizeof(cuda_ t)75 .size = sizeof(cuda_regs_t) 76 76 } 77 77 }; … … 110 110 { 111 111 service_id_t service_id; 112 cuda_ instance_t cinst;112 cuda_t cinst; 113 113 int rc; 114 114 int i; 115 115 116 116 printf(NAME ": VIA-CUDA Apple Desktop Bus driver\n"); 117 117 118 118 for (i = 0; i < ADB_MAX_ADDR; ++i) { 119 119 cinst.adb_dev[i].client_sess = NULL; … … 145 145 cinst.adb_dev[9].service_id = service_id; 146 146 147 if (cuda_init(&cinst) < 0) {147 if (cuda_init(&cinst) != EOK) { 148 148 printf("cuda_init() failed\n"); 149 149 return 1; … … 163 163 sysarg_t method; 164 164 service_id_t dsid; 165 cuda_ instance_t *cuda = (cuda_instance_t *) arg;165 cuda_t *cuda = (cuda_t *) arg; 166 166 int dev_addr, i; 167 167 … … 187 187 callid = async_get_call(&call); 188 188 method = IPC_GET_IMETHOD(call); 189 189 190 190 if (!method) { 191 191 /* The other side has hung up. */ … … 193 193 return; 194 194 } 195 195 196 196 async_sess_t *sess = 197 197 async_callback_receive_start(EXCHANGE_SERIALIZE, &call); … … 199 199 if (cuda->adb_dev[dev_addr].client_sess == NULL) { 200 200 cuda->adb_dev[dev_addr].client_sess = sess; 201 201 202 202 /* 203 203 * A hack so that we send the data to the session … … 208 208 cuda->adb_dev[i].client_sess = sess; 209 209 } 210 210 211 211 async_answer_0(callid, EOK); 212 212 } else … … 217 217 } 218 218 219 static int cuda_init(cuda_instance_t *cuda) 220 { 219 static int cuda_init(cuda_t *cuda) 220 { 221 int rc; 222 221 223 if (sysinfo_get_value("cuda.address.physical", &(cuda->cuda_physical)) != EOK) 222 return -1;223 224 return EIO; 225 224 226 void *vaddr; 225 if (pio_enable((void *) cuda->cuda_physical, sizeof(cuda_t), &vaddr) != 0) 226 return -1; 227 227 rc = pio_enable((void *) cuda->cuda_physical, sizeof(cuda_regs_t), 228 &vaddr); 229 if (rc != EOK) 230 return rc; 231 228 232 cuda->regs = vaddr; 229 233 cuda->xstate = cx_listen; … … 237 241 238 242 cuda_irq_code.ranges[0].base = (uintptr_t) cuda->cuda_physical; 239 cuda_irq_code.cmds[0].addr = (void *) &((cuda_t *) cuda->cuda_physical)->ifr; 243 cuda_irq_code.cmds[0].addr = (void *) &((cuda_regs_t *) 244 cuda->cuda_physical)->ifr; 240 245 async_irq_subscribe(10, cuda_irq_handler, cuda, &cuda_irq_code); 241 246 … … 247 252 cuda_autopoll_set(cuda, true); 248 253 249 return 0;254 return EOK; 250 255 } 251 256 … … 253 258 { 254 259 uint8_t rbuf[CUDA_RCV_BUF_SIZE]; 255 cuda_ instance_t *cuda = (cuda_instance_t *)arg;260 cuda_t *cuda = (cuda_t *)arg; 256 261 size_t len; 257 262 bool handle; … … 280 285 break; 281 286 } 282 287 283 288 /* Lower IFR.SR_INT so that CUDA can generate next int by raising it. */ 284 289 pio_write_8(&cuda->regs->ifr, SR_INT); … … 297 302 * @param cuda CUDA instance 298 303 */ 299 static void cuda_irq_listen(cuda_ instance_t *cuda)304 static void cuda_irq_listen(cuda_t *cuda) 300 305 { 301 306 uint8_t b = pio_read_8(&cuda->regs->b); 302 307 303 308 if ((b & TREQ) != 0) { 304 309 printf("cuda_irq_listen: no TREQ?!\n"); 305 310 return; 306 311 } 307 312 308 313 pio_write_8(&cuda->regs->b, b & ~TIP); 309 314 cuda->xstate = cx_receive; … … 316 321 * @param cuda CUDA instance 317 322 */ 318 static void cuda_irq_receive(cuda_ instance_t *cuda)323 static void cuda_irq_receive(cuda_t *cuda) 319 324 { 320 325 uint8_t data = pio_read_8(&cuda->regs->sr); 321 326 if (cuda->bidx < CUDA_RCV_BUF_SIZE) 322 327 cuda->rcv_buf[cuda->bidx++] = data; 323 328 324 329 uint8_t b = pio_read_8(&cuda->regs->b); 325 330 326 331 if ((b & TREQ) == 0) { 327 332 pio_write_8(&cuda->regs->b, b ^ TACK); … … 341 346 * @param len Place to store length of received packet 342 347 */ 343 static void cuda_irq_rcv_end(cuda_ instance_t *cuda, void *buf, size_t *len)348 static void cuda_irq_rcv_end(cuda_t *cuda, void *buf, size_t *len) 344 349 { 345 350 uint8_t b = pio_read_8(&cuda->regs->b); 346 351 347 352 if ((b & TREQ) == 0) { 348 353 cuda->xstate = cx_receive; … … 352 357 cuda_send_start(cuda); 353 358 } 354 359 355 360 memcpy(buf, cuda->rcv_buf, cuda->bidx); 356 361 *len = cuda->bidx; … … 364 369 * @param cuda CUDA instance 365 370 */ 366 static void cuda_irq_send_start(cuda_ instance_t *cuda)371 static void cuda_irq_send_start(cuda_t *cuda) 367 372 { 368 373 uint8_t b; … … 394 399 * @param cuda CUDA instance 395 400 */ 396 static void cuda_irq_send(cuda_ instance_t *cuda)401 static void cuda_irq_send(cuda_t *cuda) 397 402 { 398 403 if (cuda->bidx < cuda->snd_bytes) { … … 416 421 } 417 422 418 static void cuda_packet_handle(cuda_ instance_t *cuda, uint8_t *data, size_t len)423 static void cuda_packet_handle(cuda_t *cuda, uint8_t *data, size_t len) 419 424 { 420 425 if (data[0] != PT_ADB) … … 426 431 } 427 432 428 static void adb_packet_handle(cuda_ instance_t *cuda, uint8_t *data,429 size_t size,bool autopoll)433 static void adb_packet_handle(cuda_t *cuda, uint8_t *data, size_t size, 434 bool autopoll) 430 435 { 431 436 uint8_t dev_addr; … … 466 471 } 467 472 468 static void cuda_autopoll_set(cuda_ instance_t *cuda, bool enable)473 static void cuda_autopoll_set(cuda_t *cuda, bool enable) 469 474 { 470 475 cuda->snd_buf[0] = PT_CUDA; … … 477 482 } 478 483 479 static void cuda_send_start(cuda_ instance_t *cuda)484 static void cuda_send_start(cuda_t *cuda) 480 485 { 481 486 assert(cuda->xstate == cx_listen); -
uspace/srv/hw/bus/cuda_adb/cuda_adb.h
r943aaf1b r7e55bed7 39 39 #include <async.h> 40 40 #include <fibril_synch.h> 41 #include < stddef.h>41 #include <loc.h> 42 42 #include <stdint.h> 43 43 #include "cuda_hw.h" … … 61 61 62 62 typedef struct { 63 struct cuda *regs;63 struct cuda_regs *regs; 64 64 uintptr_t cuda_physical; 65 65 … … 72 72 73 73 adb_dev_t adb_dev[ADB_MAX_ADDR]; 74 } cuda_ instance_t;74 } cuda_t; 75 75 76 76 #endif -
uspace/srv/hw/bus/cuda_adb/cuda_hw.h
r943aaf1b r7e55bed7 39 39 #include <stdint.h> 40 40 41 typedef struct cuda {41 typedef struct cuda_regs { 42 42 uint8_t b; 43 43 uint8_t pad0[0x1ff]; … … 87 87 uint8_t anh; 88 88 uint8_t pad15[0x1ff]; 89 } cuda_ t;89 } cuda_regs_t; 90 90 91 91 /** B register fields */
Note:
See TracChangeset
for help on using the changeset viewer.