Changes in uspace/drv/char/ns8250/ns8250.c [5b68e0c:1dc4a5e] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/char/ns8250/ns8250.c
r5b68e0c r1dc4a5e 111 111 /** The fibril mutex for synchronizing the access to the device. */ 112 112 fibril_mutex_t mutex; 113 /** True if device is removed. */114 bool removed;115 113 } ns8250_t; 114 115 /** Create per-device soft-state structure. 116 * 117 * @return Pointer to soft-state structure. 118 */ 119 static ns8250_t *ns8250_new(void) 120 { 121 ns8250_t *ns; 122 123 ns = (ns8250_t *) calloc(1, sizeof(ns8250_t)); 124 if (ns == NULL) 125 return NULL; 126 127 fibril_mutex_initialize(&ns->mutex); 128 return ns; 129 } 130 131 /** Delete soft-state structure. 132 * 133 * @param ns The driver data structure. 134 */ 135 static void ns8250_delete(ns8250_t *ns) 136 { 137 assert(ns != NULL); 138 free(ns); 139 } 116 140 117 141 /** Find out if there is some incomming data available on the serial port. … … 221 245 222 246 static int ns8250_add_device(ddf_dev_t *dev); 223 static int ns8250_dev_remove(ddf_dev_t *dev);224 247 225 248 /** The serial port device driver's standard operations. */ 226 249 static driver_ops_t ns8250_ops = { 227 .add_device = &ns8250_add_device, 228 .dev_remove = &ns8250_dev_remove 250 .add_device = &ns8250_add_device 229 251 }; 230 252 … … 616 638 } 617 639 618 /** Deinitialize the serial port device.619 *620 * @param ns Serial port device621 */622 static void ns8250_port_cleanup(ns8250_t *ns)623 {624 /* Disable FIFO */625 pio_write_8(ns->port + 2, 0x00);626 /* Disable DTR, RTS, OUT1, OUT2 (int. enable) */627 pio_write_8(ns->port + 4, 0x00);628 /* Disable all interrupts from the port */629 ns8250_port_interrupts_disable(ns->port);630 }631 632 640 /** Read the data from the serial port device and store them to the input 633 641 * buffer. … … 713 721 714 722 /* Allocate soft-state for the device */ 715 ns = ddf_dev_data_alloc(dev, sizeof(ns8250_t));723 ns = ns8250_new(); 716 724 if (ns == NULL) { 717 725 rc = ENOMEM; … … 719 727 } 720 728 721 fibril_mutex_initialize(&ns->mutex);722 729 ns->dev = dev; 730 dev->driver_data = ns; 723 731 724 732 rc = ns8250_dev_initialize(ns); … … 784 792 if (need_cleanup) 785 793 ns8250_dev_cleanup(ns); 794 if (ns != NULL) 795 ns8250_delete(ns); 786 796 return rc; 787 }788 789 static int ns8250_dev_remove(ddf_dev_t *dev)790 {791 ns8250_t *ns = NS8250_FROM_DEV(dev);792 int rc;793 794 fibril_mutex_lock(&ns->mutex);795 if (ns->client_connected) {796 fibril_mutex_unlock(&ns->mutex);797 return EBUSY;798 }799 ns->removed = true;800 fibril_mutex_unlock(&ns->mutex);801 802 rc = ddf_fun_unbind(ns->fun);803 if (rc != EOK) {804 ddf_msg(LVL_ERROR, "Failed to unbind function.");805 return rc;806 }807 808 ddf_fun_destroy(ns->fun);809 810 ns8250_port_cleanup(ns);811 ns8250_unregister_interrupt_handler(ns);812 ns8250_dev_cleanup(ns);813 return EOK;814 797 } 815 798 … … 823 806 static int ns8250_open(ddf_fun_t *fun) 824 807 { 825 ns8250_t * ns = NS8250(fun);808 ns8250_t *data = (ns8250_t *) fun->dev->driver_data; 826 809 int res; 827 810 828 fibril_mutex_lock(& ns->mutex);829 if ( ns->client_connected) {811 fibril_mutex_lock(&data->mutex); 812 if (data->client_connected) { 830 813 res = ELIMIT; 831 } else if (ns->removed) {832 res = ENXIO;833 814 } else { 834 815 res = EOK; 835 ns->client_connected = true;836 } 837 fibril_mutex_unlock(& ns->mutex);816 data->client_connected = true; 817 } 818 fibril_mutex_unlock(&data->mutex); 838 819 839 820 return res;
Note:
See TracChangeset
for help on using the changeset viewer.