Changes in uspace/drv/char/ns8250/ns8250.c [56fd7cf:c92e30f] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/char/ns8250/ns8250.c
r56fd7cf rc92e30f 58 58 #include <ops/char_dev.h> 59 59 60 #include <devman.h> 60 61 #include <ns.h> 62 #include <ipc/devman.h> 61 63 #include <ipc/services.h> 62 64 #include <ipc/irc.h> … … 125 127 #define NS8250_MSR_SIGNALS (NS8250_MSR_CTS | NS8250_MSR_DSR \ 126 128 | NS8250_MSR_RI | NS8250_MSR_DCD) 129 130 /** Obtain soft-state structure from function node */ 131 #define NS8250(fnode) ((ns8250_t *) ((fnode)->dev->driver_data)) 132 133 /** Obtain soft-state structure from device node */ 134 #define NS8250_FROM_DEV(dnode) ((ns8250_t *) ((dnode)->driver_data)) 127 135 128 136 /** The number of bits of one data unit send by the serial port. */ … … 179 187 } ns8250_t; 180 188 181 /** Obtain soft-state structure from device node */182 static ns8250_t *dev_ns8250(ddf_dev_t *dev)183 {184 return ddf_dev_data_get(dev);185 }186 187 /** Obtain soft-state structure from function node */188 static ns8250_t *fun_ns8250(ddf_fun_t *fun)189 {190 return dev_ns8250(ddf_fun_get_dev(fun));191 }192 193 189 /** Find out if there is some incomming data available on the serial port. 194 190 * … … 245 241 static int ns8250_read(ddf_fun_t *fun, char *buf, size_t count) 246 242 { 247 ns8250_t *ns = fun_ns8250(fun);243 ns8250_t *ns = NS8250(fun); 248 244 int ret = 0; 249 245 … … 283 279 static int ns8250_write(ddf_fun_t *fun, char *buf, size_t count) 284 280 { 285 ns8250_t *ns = fun_ns8250(fun);281 ns8250_t *ns = NS8250(fun); 286 282 size_t idx; 287 283 … … 321 317 static void ns8250_dev_cleanup(ns8250_t *ns) 322 318 { 319 if (ns->dev->parent_sess) { 320 async_hangup(ns->dev->parent_sess); 321 ns->dev->parent_sess = NULL; 322 } 323 323 } 324 324 … … 330 330 static bool ns8250_pio_enable(ns8250_t *ns) 331 331 { 332 ddf_msg(LVL_DEBUG, "ns8250_pio_enable %s", ddf_dev_get_name(ns->dev));332 ddf_msg(LVL_DEBUG, "ns8250_pio_enable %s", ns->dev->name); 333 333 334 334 /* Gain control over port's registers. */ … … 336 336 (void **) &ns->port)) { 337 337 ddf_msg(LVL_ERROR, "Cannot map the port %#" PRIx32 338 " for device %s.", ns->io_addr, ddf_dev_get_name(ns->dev));338 " for device %s.", ns->io_addr, ns->dev->name); 339 339 return false; 340 340 } … … 352 352 static bool ns8250_dev_probe(ns8250_t *ns) 353 353 { 354 ddf_msg(LVL_DEBUG, "ns8250_dev_probe %s", ddf_dev_get_name(ns->dev));354 ddf_msg(LVL_DEBUG, "ns8250_dev_probe %s", ns->dev->name); 355 355 356 356 bool res = true; … … 372 372 if (!res) { 373 373 ddf_msg(LVL_DEBUG, "Device %s is not present.", 374 ddf_dev_get_name(ns->dev));374 ns->dev->name); 375 375 } 376 376 … … 385 385 static int ns8250_dev_initialize(ns8250_t *ns) 386 386 { 387 async_sess_t *parent_sess; 387 ddf_msg(LVL_DEBUG, "ns8250_dev_initialize %s", ns->dev->name); 388 388 389 int ret = EOK; 389 390 ddf_msg(LVL_DEBUG, "ns8250_dev_initialize %s", ddf_dev_get_name(ns->dev));391 390 392 391 hw_resource_list_t hw_resources; … … 394 393 395 394 /* Connect to the parent's driver. */ 396 parent_sess = ddf_dev_parent_sess_create(ns->dev, EXCHANGE_SERIALIZE); 397 if (parent_sess == NULL) { 395 ns->dev->parent_sess = devman_parent_device_connect(EXCHANGE_SERIALIZE, 396 ns->dev->handle, IPC_FLAG_BLOCKING); 397 if (!ns->dev->parent_sess) { 398 398 ddf_msg(LVL_ERROR, "Failed to connect to parent driver of " 399 "device %s.", ddf_dev_get_name(ns->dev));399 "device %s.", ns->dev->name); 400 400 ret = ENOENT; 401 401 goto failed; … … 403 403 404 404 /* Get hw resources. */ 405 ret = hw_res_get_resource_list( parent_sess, &hw_resources);405 ret = hw_res_get_resource_list(ns->dev->parent_sess, &hw_resources); 406 406 if (ret != EOK) { 407 407 ddf_msg(LVL_ERROR, "Failed to get HW resources for device " 408 "%s.", ddf_dev_get_name(ns->dev));408 "%s.", ns->dev->name); 409 409 goto failed; 410 410 } … … 422 422 irq = true; 423 423 ddf_msg(LVL_NOTE, "Device %s was asigned irq = 0x%x.", 424 ddf_dev_get_name(ns->dev), ns->irq);424 ns->dev->name, ns->irq); 425 425 break; 426 426 … … 429 429 if (res->res.io_range.size < REG_COUNT) { 430 430 ddf_msg(LVL_ERROR, "I/O range assigned to " 431 "device %s is too small.", ddf_dev_get_name(ns->dev));431 "device %s is too small.", ns->dev->name); 432 432 ret = ELIMIT; 433 433 goto failed; … … 435 435 ioport = true; 436 436 ddf_msg(LVL_NOTE, "Device %s was asigned I/O address = " 437 "0x%x.", ddf_dev_get_name(ns->dev), ns->io_addr);437 "0x%x.", ns->dev->name, ns->io_addr); 438 438 break; 439 439 … … 445 445 if (!irq || !ioport) { 446 446 ddf_msg(LVL_ERROR, "Missing HW resource(s) for device %s.", 447 ddf_dev_get_name(ns->dev));447 ns->dev->name); 448 448 ret = ENOENT; 449 449 goto failed; … … 613 613 *parity = ((val >> NS8250_LCR_PARITY) & 7); 614 614 615 /* Silence warnings */616 *word_length = 0;617 618 615 switch (val & 3) { 619 616 case WORD_LENGTH_5: … … 758 755 if (!buf_push_back(&ns->input_buffer, val)) { 759 756 ddf_msg(LVL_WARN, "Buffer overflow on " 760 "%s.", ddf_dev_get_name(ns->dev));757 "%s.", ns->dev->name); 761 758 break; 762 759 } else { 763 760 ddf_msg(LVL_DEBUG2, "Character %c saved " 764 761 "to the buffer of %s.", 765 val, ddf_dev_get_name(ns->dev));762 val, ns->dev->name); 766 763 if (buf_was_empty) 767 764 fibril_condvar_broadcast(&ns->input_buffer_available); … … 785 782 ipc_call_t *icall) 786 783 { 787 ns8250_t *ns = dev_ns8250(dev);784 ns8250_t *ns = NS8250_FROM_DEV(dev); 788 785 789 786 uint8_t iir = pio_read_8(&ns->regs->iid); … … 791 788 uint8_t lsr = pio_read_8(&ns->regs->lsr); 792 789 if (lsr & NS8250_LSR_OE) { 793 ddf_msg(LVL_WARN, "Overrun error on %s", ddf_dev_get_name(ns->dev));790 ddf_msg(LVL_WARN, "Overrun error on %s", ns->dev->name); 794 791 } 795 792 } … … 831 828 832 829 ddf_msg(LVL_DEBUG, "ns8250_dev_add %s (handle = %d)", 833 d df_dev_get_name(dev), (int) ddf_dev_get_handle(dev));830 dev->name, (int) dev->handle); 834 831 835 832 /* Allocate soft-state for the device */ … … 886 883 887 884 /* Set device operations. */ 888 ddf_fun_set_ops(fun, &ns8250_dev_ops);885 fun->ops = &ns8250_dev_ops; 889 886 rc = ddf_fun_bind(fun); 890 887 if (rc != EOK) { … … 898 895 899 896 ddf_msg(LVL_NOTE, "Device %s successfully initialized.", 900 d df_dev_get_name(dev));897 dev->name); 901 898 902 899 return EOK; … … 911 908 static int ns8250_dev_remove(ddf_dev_t *dev) 912 909 { 913 ns8250_t *ns = dev_ns8250(dev);910 ns8250_t *ns = NS8250_FROM_DEV(dev); 914 911 int rc; 915 912 … … 945 942 static int ns8250_open(ddf_fun_t *fun) 946 943 { 947 ns8250_t *ns = fun_ns8250(fun);944 ns8250_t *ns = NS8250(fun); 948 945 int res; 949 946 … … 971 968 static void ns8250_close(ddf_fun_t *fun) 972 969 { 973 ns8250_t *data = fun_ns8250(fun);970 ns8250_t *data = (ns8250_t *) fun->dev->driver_data; 974 971 975 972 fibril_mutex_lock(&data->mutex); … … 996 993 unsigned int *word_length, unsigned int* stop_bits) 997 994 { 998 ns8250_t *data = dev_ns8250(dev);995 ns8250_t *data = (ns8250_t *) dev->driver_data; 999 996 ns8250_regs_t *regs = data->regs; 1000 997 … … 1027 1024 stop_bits); 1028 1025 1029 ns8250_t *data = dev_ns8250(dev);1026 ns8250_t *data = (ns8250_t *) dev->driver_data; 1030 1027 ns8250_regs_t *regs = data->regs; 1031 1028 int ret; … … 1056 1053 switch (method) { 1057 1054 case SERIAL_GET_COM_PROPS: 1058 ns8250_get_props( ddf_fun_get_dev(fun), &baud_rate, &parity, &word_length,1055 ns8250_get_props(fun->dev, &baud_rate, &parity, &word_length, 1059 1056 &stop_bits); 1060 1057 async_answer_4(callid, EOK, baud_rate, parity, word_length, … … 1067 1064 word_length = IPC_GET_ARG3(*call); 1068 1065 stop_bits = IPC_GET_ARG4(*call); 1069 ret = ns8250_set_props( ddf_fun_get_dev(fun), baud_rate, parity, word_length,1066 ret = ns8250_set_props(fun->dev, baud_rate, parity, word_length, 1070 1067 stop_bits); 1071 1068 async_answer_0(callid, ret);
Note:
See TracChangeset
for help on using the changeset viewer.