diff options
Diffstat (limited to 'drivers/char')
32 files changed, 1915 insertions, 463 deletions
diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig index e023682be2c4..3141dd3b6e53 100644 --- a/drivers/char/Kconfig +++ b/drivers/char/Kconfig | |||
@@ -666,6 +666,14 @@ config VIRTIO_CONSOLE | |||
666 | help | 666 | help |
667 | Virtio console for use with lguest and other hypervisors. | 667 | Virtio console for use with lguest and other hypervisors. |
668 | 668 | ||
669 | Also serves as a general-purpose serial device for data | ||
670 | transfer between the guest and host. Character devices at | ||
671 | /dev/vportNpn will be created when corresponding ports are | ||
672 | found, where N is the device number and n is the port number | ||
673 | within that device. If specified by the host, a sysfs | ||
674 | attribute called 'name' will be populated with a name for | ||
675 | the port which can be used by udev scripts to create a | ||
676 | symlink to the device. | ||
669 | 677 | ||
670 | config HVCS | 678 | config HVCS |
671 | tristate "IBM Hypervisor Virtual Console Server support" | 679 | tristate "IBM Hypervisor Virtual Console Server support" |
diff --git a/drivers/char/agp/intel-agp.c b/drivers/char/agp/intel-agp.c index 3999a5f25f38..8a713f1e9653 100644 --- a/drivers/char/agp/intel-agp.c +++ b/drivers/char/agp/intel-agp.c | |||
@@ -8,6 +8,7 @@ | |||
8 | #include <linux/kernel.h> | 8 | #include <linux/kernel.h> |
9 | #include <linux/pagemap.h> | 9 | #include <linux/pagemap.h> |
10 | #include <linux/agp_backend.h> | 10 | #include <linux/agp_backend.h> |
11 | #include <asm/smp.h> | ||
11 | #include "agp.h" | 12 | #include "agp.h" |
12 | 13 | ||
13 | /* | 14 | /* |
@@ -815,12 +816,6 @@ static void intel_i830_setup_flush(void) | |||
815 | intel_i830_fini_flush(); | 816 | intel_i830_fini_flush(); |
816 | } | 817 | } |
817 | 818 | ||
818 | static void | ||
819 | do_wbinvd(void *null) | ||
820 | { | ||
821 | wbinvd(); | ||
822 | } | ||
823 | |||
824 | /* The chipset_flush interface needs to get data that has already been | 819 | /* The chipset_flush interface needs to get data that has already been |
825 | * flushed out of the CPU all the way out to main memory, because the GPU | 820 | * flushed out of the CPU all the way out to main memory, because the GPU |
826 | * doesn't snoop those buffers. | 821 | * doesn't snoop those buffers. |
@@ -837,12 +832,10 @@ static void intel_i830_chipset_flush(struct agp_bridge_data *bridge) | |||
837 | 832 | ||
838 | memset(pg, 0, 1024); | 833 | memset(pg, 0, 1024); |
839 | 834 | ||
840 | if (cpu_has_clflush) { | 835 | if (cpu_has_clflush) |
841 | clflush_cache_range(pg, 1024); | 836 | clflush_cache_range(pg, 1024); |
842 | } else { | 837 | else if (wbinvd_on_all_cpus() != 0) |
843 | if (on_each_cpu(do_wbinvd, NULL, 1) != 0) | 838 | printk(KERN_ERR "Timed out waiting for cache flush.\n"); |
844 | printk(KERN_ERR "Timed out waiting for cache flush.\n"); | ||
845 | } | ||
846 | } | 839 | } |
847 | 840 | ||
848 | /* The intel i830 automatically initializes the agp aperture during POST. | 841 | /* The intel i830 automatically initializes the agp aperture during POST. |
diff --git a/drivers/char/cyclades.c b/drivers/char/cyclades.c index 4254457d3911..b861c08263a4 100644 --- a/drivers/char/cyclades.c +++ b/drivers/char/cyclades.c | |||
@@ -158,13 +158,11 @@ static unsigned int cy_isa_addresses[] = { | |||
158 | 158 | ||
159 | #define NR_ISA_ADDRS ARRAY_SIZE(cy_isa_addresses) | 159 | #define NR_ISA_ADDRS ARRAY_SIZE(cy_isa_addresses) |
160 | 160 | ||
161 | #ifdef MODULE | ||
162 | static long maddr[NR_CARDS]; | 161 | static long maddr[NR_CARDS]; |
163 | static int irq[NR_CARDS]; | 162 | static int irq[NR_CARDS]; |
164 | 163 | ||
165 | module_param_array(maddr, long, NULL, 0); | 164 | module_param_array(maddr, long, NULL, 0); |
166 | module_param_array(irq, int, NULL, 0); | 165 | module_param_array(irq, int, NULL, 0); |
167 | #endif | ||
168 | 166 | ||
169 | #endif /* CONFIG_ISA */ | 167 | #endif /* CONFIG_ISA */ |
170 | 168 | ||
@@ -598,12 +596,6 @@ static void cyy_chip_tx(struct cyclades_card *cinfo, unsigned int chip, | |||
598 | save_car = readb(base_addr + (CyCAR << index)); | 596 | save_car = readb(base_addr + (CyCAR << index)); |
599 | cy_writeb(base_addr + (CyCAR << index), save_xir); | 597 | cy_writeb(base_addr + (CyCAR << index), save_xir); |
600 | 598 | ||
601 | /* validate the port# (as configured and open) */ | ||
602 | if (channel + chip * 4 >= cinfo->nports) { | ||
603 | cy_writeb(base_addr + (CySRER << index), | ||
604 | readb(base_addr + (CySRER << index)) & ~CyTxRdy); | ||
605 | goto end; | ||
606 | } | ||
607 | info = &cinfo->ports[channel + chip * 4]; | 599 | info = &cinfo->ports[channel + chip * 4]; |
608 | tty = tty_port_tty_get(&info->port); | 600 | tty = tty_port_tty_get(&info->port); |
609 | if (tty == NULL) { | 601 | if (tty == NULL) { |
@@ -3316,13 +3308,10 @@ static int __init cy_detect_isa(void) | |||
3316 | unsigned short cy_isa_irq, nboard; | 3308 | unsigned short cy_isa_irq, nboard; |
3317 | void __iomem *cy_isa_address; | 3309 | void __iomem *cy_isa_address; |
3318 | unsigned short i, j, cy_isa_nchan; | 3310 | unsigned short i, j, cy_isa_nchan; |
3319 | #ifdef MODULE | ||
3320 | int isparam = 0; | 3311 | int isparam = 0; |
3321 | #endif | ||
3322 | 3312 | ||
3323 | nboard = 0; | 3313 | nboard = 0; |
3324 | 3314 | ||
3325 | #ifdef MODULE | ||
3326 | /* Check for module parameters */ | 3315 | /* Check for module parameters */ |
3327 | for (i = 0; i < NR_CARDS; i++) { | 3316 | for (i = 0; i < NR_CARDS; i++) { |
3328 | if (maddr[i] || i) { | 3317 | if (maddr[i] || i) { |
@@ -3332,7 +3321,6 @@ static int __init cy_detect_isa(void) | |||
3332 | if (!maddr[i]) | 3321 | if (!maddr[i]) |
3333 | break; | 3322 | break; |
3334 | } | 3323 | } |
3335 | #endif | ||
3336 | 3324 | ||
3337 | /* scan the address table probing for Cyclom-Y/ISA boards */ | 3325 | /* scan the address table probing for Cyclom-Y/ISA boards */ |
3338 | for (i = 0; i < NR_ISA_ADDRS; i++) { | 3326 | for (i = 0; i < NR_ISA_ADDRS; i++) { |
@@ -3353,11 +3341,10 @@ static int __init cy_detect_isa(void) | |||
3353 | iounmap(cy_isa_address); | 3341 | iounmap(cy_isa_address); |
3354 | continue; | 3342 | continue; |
3355 | } | 3343 | } |
3356 | #ifdef MODULE | 3344 | |
3357 | if (isparam && i < NR_CARDS && irq[i]) | 3345 | if (isparam && i < NR_CARDS && irq[i]) |
3358 | cy_isa_irq = irq[i]; | 3346 | cy_isa_irq = irq[i]; |
3359 | else | 3347 | else |
3360 | #endif | ||
3361 | /* find out the board's irq by probing */ | 3348 | /* find out the board's irq by probing */ |
3362 | cy_isa_irq = detect_isa_irq(cy_isa_address); | 3349 | cy_isa_irq = detect_isa_irq(cy_isa_address); |
3363 | if (cy_isa_irq == 0) { | 3350 | if (cy_isa_irq == 0) { |
@@ -4208,3 +4195,4 @@ module_exit(cy_cleanup_module); | |||
4208 | MODULE_LICENSE("GPL"); | 4195 | MODULE_LICENSE("GPL"); |
4209 | MODULE_VERSION(CY_VERSION); | 4196 | MODULE_VERSION(CY_VERSION); |
4210 | MODULE_ALIAS_CHARDEV_MAJOR(CYCLADES_MAJOR); | 4197 | MODULE_ALIAS_CHARDEV_MAJOR(CYCLADES_MAJOR); |
4198 | MODULE_FIRMWARE("cyzfirm.bin"); | ||
diff --git a/drivers/char/hvc_beat.c b/drivers/char/hvc_beat.c index 0afc8b82212e..5fe4631e2a61 100644 --- a/drivers/char/hvc_beat.c +++ b/drivers/char/hvc_beat.c | |||
@@ -84,7 +84,7 @@ static int hvc_beat_put_chars(uint32_t vtermno, const char *buf, int cnt) | |||
84 | return cnt; | 84 | return cnt; |
85 | } | 85 | } |
86 | 86 | ||
87 | static struct hv_ops hvc_beat_get_put_ops = { | 87 | static const struct hv_ops hvc_beat_get_put_ops = { |
88 | .get_chars = hvc_beat_get_chars, | 88 | .get_chars = hvc_beat_get_chars, |
89 | .put_chars = hvc_beat_put_chars, | 89 | .put_chars = hvc_beat_put_chars, |
90 | }; | 90 | }; |
@@ -99,7 +99,7 @@ static int hvc_beat_config(char *p) | |||
99 | 99 | ||
100 | static int __init hvc_beat_console_init(void) | 100 | static int __init hvc_beat_console_init(void) |
101 | { | 101 | { |
102 | if (hvc_beat_useit && machine_is_compatible("Beat")) { | 102 | if (hvc_beat_useit && of_machine_is_compatible("Beat")) { |
103 | hvc_instantiate(0, 0, &hvc_beat_get_put_ops); | 103 | hvc_instantiate(0, 0, &hvc_beat_get_put_ops); |
104 | } | 104 | } |
105 | return 0; | 105 | return 0; |
diff --git a/drivers/char/hvc_console.c b/drivers/char/hvc_console.c index 416d3423150d..465185fc0f52 100644 --- a/drivers/char/hvc_console.c +++ b/drivers/char/hvc_console.c | |||
@@ -125,7 +125,7 @@ static struct hvc_struct *hvc_get_by_index(int index) | |||
125 | * console interfaces but can still be used as a tty device. This has to be | 125 | * console interfaces but can still be used as a tty device. This has to be |
126 | * static because kmalloc will not work during early console init. | 126 | * static because kmalloc will not work during early console init. |
127 | */ | 127 | */ |
128 | static struct hv_ops *cons_ops[MAX_NR_HVC_CONSOLES]; | 128 | static const struct hv_ops *cons_ops[MAX_NR_HVC_CONSOLES]; |
129 | static uint32_t vtermnos[MAX_NR_HVC_CONSOLES] = | 129 | static uint32_t vtermnos[MAX_NR_HVC_CONSOLES] = |
130 | {[0 ... MAX_NR_HVC_CONSOLES - 1] = -1}; | 130 | {[0 ... MAX_NR_HVC_CONSOLES - 1] = -1}; |
131 | 131 | ||
@@ -146,7 +146,7 @@ static void hvc_console_print(struct console *co, const char *b, | |||
146 | return; | 146 | return; |
147 | 147 | ||
148 | /* This console adapter was removed so it is not usable. */ | 148 | /* This console adapter was removed so it is not usable. */ |
149 | if (vtermnos[index] < 0) | 149 | if (vtermnos[index] == -1) |
150 | return; | 150 | return; |
151 | 151 | ||
152 | while (count > 0 || i > 0) { | 152 | while (count > 0 || i > 0) { |
@@ -247,7 +247,7 @@ static void destroy_hvc_struct(struct kref *kref) | |||
247 | * vty adapters do NOT get an hvc_instantiate() callback since they | 247 | * vty adapters do NOT get an hvc_instantiate() callback since they |
248 | * appear after early console init. | 248 | * appear after early console init. |
249 | */ | 249 | */ |
250 | int hvc_instantiate(uint32_t vtermno, int index, struct hv_ops *ops) | 250 | int hvc_instantiate(uint32_t vtermno, int index, const struct hv_ops *ops) |
251 | { | 251 | { |
252 | struct hvc_struct *hp; | 252 | struct hvc_struct *hp; |
253 | 253 | ||
@@ -748,8 +748,9 @@ static const struct tty_operations hvc_ops = { | |||
748 | .chars_in_buffer = hvc_chars_in_buffer, | 748 | .chars_in_buffer = hvc_chars_in_buffer, |
749 | }; | 749 | }; |
750 | 750 | ||
751 | struct hvc_struct __devinit *hvc_alloc(uint32_t vtermno, int data, | 751 | struct hvc_struct *hvc_alloc(uint32_t vtermno, int data, |
752 | struct hv_ops *ops, int outbuf_size) | 752 | const struct hv_ops *ops, |
753 | int outbuf_size) | ||
753 | { | 754 | { |
754 | struct hvc_struct *hp; | 755 | struct hvc_struct *hp; |
755 | int i; | 756 | int i; |
diff --git a/drivers/char/hvc_console.h b/drivers/char/hvc_console.h index 10950ca706d8..54381eba4e4a 100644 --- a/drivers/char/hvc_console.h +++ b/drivers/char/hvc_console.h | |||
@@ -55,7 +55,7 @@ struct hvc_struct { | |||
55 | int outbuf_size; | 55 | int outbuf_size; |
56 | int n_outbuf; | 56 | int n_outbuf; |
57 | uint32_t vtermno; | 57 | uint32_t vtermno; |
58 | struct hv_ops *ops; | 58 | const struct hv_ops *ops; |
59 | int irq_requested; | 59 | int irq_requested; |
60 | int data; | 60 | int data; |
61 | struct winsize ws; | 61 | struct winsize ws; |
@@ -76,11 +76,12 @@ struct hv_ops { | |||
76 | }; | 76 | }; |
77 | 77 | ||
78 | /* Register a vterm and a slot index for use as a console (console_init) */ | 78 | /* Register a vterm and a slot index for use as a console (console_init) */ |
79 | extern int hvc_instantiate(uint32_t vtermno, int index, struct hv_ops *ops); | 79 | extern int hvc_instantiate(uint32_t vtermno, int index, |
80 | const struct hv_ops *ops); | ||
80 | 81 | ||
81 | /* register a vterm for hvc tty operation (module_init or hotplug add) */ | 82 | /* register a vterm for hvc tty operation (module_init or hotplug add) */ |
82 | extern struct hvc_struct * __devinit hvc_alloc(uint32_t vtermno, int data, | 83 | extern struct hvc_struct * hvc_alloc(uint32_t vtermno, int data, |
83 | struct hv_ops *ops, int outbuf_size); | 84 | const struct hv_ops *ops, int outbuf_size); |
84 | /* remove a vterm from hvc tty operation (module_exit or hotplug remove) */ | 85 | /* remove a vterm from hvc tty operation (module_exit or hotplug remove) */ |
85 | extern int hvc_remove(struct hvc_struct *hp); | 86 | extern int hvc_remove(struct hvc_struct *hp); |
86 | 87 | ||
diff --git a/drivers/char/hvc_iseries.c b/drivers/char/hvc_iseries.c index 936d05bf37fa..fd0242676a2a 100644 --- a/drivers/char/hvc_iseries.c +++ b/drivers/char/hvc_iseries.c | |||
@@ -197,7 +197,7 @@ done: | |||
197 | return sent; | 197 | return sent; |
198 | } | 198 | } |
199 | 199 | ||
200 | static struct hv_ops hvc_get_put_ops = { | 200 | static const struct hv_ops hvc_get_put_ops = { |
201 | .get_chars = get_chars, | 201 | .get_chars = get_chars, |
202 | .put_chars = put_chars, | 202 | .put_chars = put_chars, |
203 | .notifier_add = notifier_add_irq, | 203 | .notifier_add = notifier_add_irq, |
diff --git a/drivers/char/hvc_iucv.c b/drivers/char/hvc_iucv.c index fe62bd0e17b7..21681a81cc35 100644 --- a/drivers/char/hvc_iucv.c +++ b/drivers/char/hvc_iucv.c | |||
@@ -922,7 +922,7 @@ static int hvc_iucv_pm_restore_thaw(struct device *dev) | |||
922 | 922 | ||
923 | 923 | ||
924 | /* HVC operations */ | 924 | /* HVC operations */ |
925 | static struct hv_ops hvc_iucv_ops = { | 925 | static const struct hv_ops hvc_iucv_ops = { |
926 | .get_chars = hvc_iucv_get_chars, | 926 | .get_chars = hvc_iucv_get_chars, |
927 | .put_chars = hvc_iucv_put_chars, | 927 | .put_chars = hvc_iucv_put_chars, |
928 | .notifier_add = hvc_iucv_notifier_add, | 928 | .notifier_add = hvc_iucv_notifier_add, |
diff --git a/drivers/char/hvc_rtas.c b/drivers/char/hvc_rtas.c index 88590d040046..61c4a61558d9 100644 --- a/drivers/char/hvc_rtas.c +++ b/drivers/char/hvc_rtas.c | |||
@@ -71,7 +71,7 @@ static int hvc_rtas_read_console(uint32_t vtermno, char *buf, int count) | |||
71 | return i; | 71 | return i; |
72 | } | 72 | } |
73 | 73 | ||
74 | static struct hv_ops hvc_rtas_get_put_ops = { | 74 | static const struct hv_ops hvc_rtas_get_put_ops = { |
75 | .get_chars = hvc_rtas_read_console, | 75 | .get_chars = hvc_rtas_read_console, |
76 | .put_chars = hvc_rtas_write_console, | 76 | .put_chars = hvc_rtas_write_console, |
77 | }; | 77 | }; |
diff --git a/drivers/char/hvc_udbg.c b/drivers/char/hvc_udbg.c index bd63ba878a56..b0957e61a7be 100644 --- a/drivers/char/hvc_udbg.c +++ b/drivers/char/hvc_udbg.c | |||
@@ -58,7 +58,7 @@ static int hvc_udbg_get(uint32_t vtermno, char *buf, int count) | |||
58 | return i; | 58 | return i; |
59 | } | 59 | } |
60 | 60 | ||
61 | static struct hv_ops hvc_udbg_ops = { | 61 | static const struct hv_ops hvc_udbg_ops = { |
62 | .get_chars = hvc_udbg_get, | 62 | .get_chars = hvc_udbg_get, |
63 | .put_chars = hvc_udbg_put, | 63 | .put_chars = hvc_udbg_put, |
64 | }; | 64 | }; |
diff --git a/drivers/char/hvc_vio.c b/drivers/char/hvc_vio.c index 10be343d6ae7..27370e99c66f 100644 --- a/drivers/char/hvc_vio.c +++ b/drivers/char/hvc_vio.c | |||
@@ -77,7 +77,7 @@ static int filtered_get_chars(uint32_t vtermno, char *buf, int count) | |||
77 | return got; | 77 | return got; |
78 | } | 78 | } |
79 | 79 | ||
80 | static struct hv_ops hvc_get_put_ops = { | 80 | static const struct hv_ops hvc_get_put_ops = { |
81 | .get_chars = filtered_get_chars, | 81 | .get_chars = filtered_get_chars, |
82 | .put_chars = hvc_put_chars, | 82 | .put_chars = hvc_put_chars, |
83 | .notifier_add = notifier_add_irq, | 83 | .notifier_add = notifier_add_irq, |
diff --git a/drivers/char/hvc_xen.c b/drivers/char/hvc_xen.c index b1a71638c772..60446f82a3fc 100644 --- a/drivers/char/hvc_xen.c +++ b/drivers/char/hvc_xen.c | |||
@@ -122,7 +122,7 @@ static int read_console(uint32_t vtermno, char *buf, int len) | |||
122 | return recv; | 122 | return recv; |
123 | } | 123 | } |
124 | 124 | ||
125 | static struct hv_ops hvc_ops = { | 125 | static const struct hv_ops hvc_ops = { |
126 | .get_chars = read_console, | 126 | .get_chars = read_console, |
127 | .put_chars = write_console, | 127 | .put_chars = write_console, |
128 | .notifier_add = notifier_add_irq, | 128 | .notifier_add = notifier_add_irq, |
diff --git a/drivers/char/hw_random/Kconfig b/drivers/char/hw_random/Kconfig index 87060266ef91..d31483c54883 100644 --- a/drivers/char/hw_random/Kconfig +++ b/drivers/char/hw_random/Kconfig | |||
@@ -114,7 +114,7 @@ config HW_RANDOM_IXP4XX | |||
114 | 114 | ||
115 | config HW_RANDOM_OMAP | 115 | config HW_RANDOM_OMAP |
116 | tristate "OMAP Random Number Generator support" | 116 | tristate "OMAP Random Number Generator support" |
117 | depends on HW_RANDOM && (ARCH_OMAP16XX || ARCH_OMAP24XX) | 117 | depends on HW_RANDOM && (ARCH_OMAP16XX || ARCH_OMAP2) |
118 | default HW_RANDOM | 118 | default HW_RANDOM |
119 | ---help--- | 119 | ---help--- |
120 | This driver provides kernel-side support for the Random Number | 120 | This driver provides kernel-side support for the Random Number |
@@ -186,3 +186,15 @@ config HW_RANDOM_MXC_RNGA | |||
186 | module will be called mxc-rnga. | 186 | module will be called mxc-rnga. |
187 | 187 | ||
188 | If unsure, say Y. | 188 | If unsure, say Y. |
189 | |||
190 | config HW_RANDOM_NOMADIK | ||
191 | tristate "ST-Ericsson Nomadik Random Number Generator support" | ||
192 | depends on HW_RANDOM && PLAT_NOMADIK | ||
193 | ---help--- | ||
194 | This driver provides kernel-side support for the Random Number | ||
195 | Generator hardware found on ST-Ericsson SoCs (8815 and 8500). | ||
196 | |||
197 | To compile this driver as a module, choose M here: the | ||
198 | module will be called nomadik-rng. | ||
199 | |||
200 | If unsure, say Y. | ||
diff --git a/drivers/char/hw_random/Makefile b/drivers/char/hw_random/Makefile index 5eeb1303f0d0..4273308aa1e3 100644 --- a/drivers/char/hw_random/Makefile +++ b/drivers/char/hw_random/Makefile | |||
@@ -18,3 +18,4 @@ obj-$(CONFIG_HW_RANDOM_VIRTIO) += virtio-rng.o | |||
18 | obj-$(CONFIG_HW_RANDOM_TX4939) += tx4939-rng.o | 18 | obj-$(CONFIG_HW_RANDOM_TX4939) += tx4939-rng.o |
19 | obj-$(CONFIG_HW_RANDOM_MXC_RNGA) += mxc-rnga.o | 19 | obj-$(CONFIG_HW_RANDOM_MXC_RNGA) += mxc-rnga.o |
20 | obj-$(CONFIG_HW_RANDOM_OCTEON) += octeon-rng.o | 20 | obj-$(CONFIG_HW_RANDOM_OCTEON) += octeon-rng.o |
21 | obj-$(CONFIG_HW_RANDOM_NOMADIK) += nomadik-rng.o | ||
diff --git a/drivers/char/hw_random/nomadik-rng.c b/drivers/char/hw_random/nomadik-rng.c new file mode 100644 index 000000000000..a8b4c4010144 --- /dev/null +++ b/drivers/char/hw_random/nomadik-rng.c | |||
@@ -0,0 +1,103 @@ | |||
1 | /* | ||
2 | * Nomadik RNG support | ||
3 | * Copyright 2009 Alessandro Rubini | ||
4 | * | ||
5 | * This program is free software; you can redistribute it and/or modify | ||
6 | * it under the terms of the GNU General Public License as published by | ||
7 | * the Free Software Foundation; either version 2 of the License, or | ||
8 | * (at your option) any later version. | ||
9 | */ | ||
10 | |||
11 | #include <linux/kernel.h> | ||
12 | #include <linux/module.h> | ||
13 | #include <linux/init.h> | ||
14 | #include <linux/device.h> | ||
15 | #include <linux/amba/bus.h> | ||
16 | #include <linux/hw_random.h> | ||
17 | #include <linux/io.h> | ||
18 | |||
19 | static int nmk_rng_read(struct hwrng *rng, void *data, size_t max, bool wait) | ||
20 | { | ||
21 | void __iomem *base = (void __iomem *)rng->priv; | ||
22 | |||
23 | /* | ||
24 | * The register is 32 bits and gives 16 random bits (low half). | ||
25 | * A subsequent read will delay the core for 400ns, so we just read | ||
26 | * once and accept the very unlikely very small delay, even if wait==0. | ||
27 | */ | ||
28 | *(u16 *)data = __raw_readl(base + 8) & 0xffff; | ||
29 | return 2; | ||
30 | } | ||
31 | |||
32 | /* we have at most one RNG per machine, granted */ | ||
33 | static struct hwrng nmk_rng = { | ||
34 | .name = "nomadik", | ||
35 | .read = nmk_rng_read, | ||
36 | }; | ||
37 | |||
38 | static int nmk_rng_probe(struct amba_device *dev, struct amba_id *id) | ||
39 | { | ||
40 | void __iomem *base; | ||
41 | int ret; | ||
42 | |||
43 | ret = amba_request_regions(dev, dev->dev.init_name); | ||
44 | if (ret) | ||
45 | return ret; | ||
46 | ret = -ENOMEM; | ||
47 | base = ioremap(dev->res.start, resource_size(&dev->res)); | ||
48 | if (!base) | ||
49 | goto out_release; | ||
50 | nmk_rng.priv = (unsigned long)base; | ||
51 | ret = hwrng_register(&nmk_rng); | ||
52 | if (ret) | ||
53 | goto out_unmap; | ||
54 | return 0; | ||
55 | |||
56 | out_unmap: | ||
57 | iounmap(base); | ||
58 | out_release: | ||
59 | amba_release_regions(dev); | ||
60 | return ret; | ||
61 | } | ||
62 | |||
63 | static int nmk_rng_remove(struct amba_device *dev) | ||
64 | { | ||
65 | void __iomem *base = (void __iomem *)nmk_rng.priv; | ||
66 | hwrng_unregister(&nmk_rng); | ||
67 | iounmap(base); | ||
68 | amba_release_regions(dev); | ||
69 | return 0; | ||
70 | } | ||
71 | |||
72 | static struct amba_id nmk_rng_ids[] = { | ||
73 | { | ||
74 | .id = 0x000805e1, | ||
75 | .mask = 0x000fffff, /* top bits are rev and cfg: accept all */ | ||
76 | }, | ||
77 | {0, 0}, | ||
78 | }; | ||
79 | |||
80 | static struct amba_driver nmk_rng_driver = { | ||
81 | .drv = { | ||
82 | .owner = THIS_MODULE, | ||
83 | .name = "rng", | ||
84 | }, | ||
85 | .probe = nmk_rng_probe, | ||
86 | .remove = nmk_rng_remove, | ||
87 | .id_table = nmk_rng_ids, | ||
88 | }; | ||
89 | |||
90 | static int __init nmk_rng_init(void) | ||
91 | { | ||
92 | return amba_driver_register(&nmk_rng_driver); | ||
93 | } | ||
94 | |||
95 | static void __devexit nmk_rng_exit(void) | ||
96 | { | ||
97 | amba_driver_unregister(&nmk_rng_driver); | ||
98 | } | ||
99 | |||
100 | module_init(nmk_rng_init); | ||
101 | module_exit(nmk_rng_exit); | ||
102 | |||
103 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/char/ip2/ip2main.c b/drivers/char/ip2/ip2main.c index 517271c762e6..911e1da6def2 100644 --- a/drivers/char/ip2/ip2main.c +++ b/drivers/char/ip2/ip2main.c | |||
@@ -208,6 +208,7 @@ static int DumpFifoBuffer( char __user *, int); | |||
208 | 208 | ||
209 | static void ip2_init_board(int, const struct firmware *); | 209 | static void ip2_init_board(int, const struct firmware *); |
210 | static unsigned short find_eisa_board(int); | 210 | static unsigned short find_eisa_board(int); |
211 | static int ip2_setup(char *str); | ||
211 | 212 | ||
212 | /***************/ | 213 | /***************/ |
213 | /* Static Data */ | 214 | /* Static Data */ |
@@ -263,7 +264,7 @@ static int tracewrap; | |||
263 | /* Macros */ | 264 | /* Macros */ |
264 | /**********/ | 265 | /**********/ |
265 | 266 | ||
266 | #if defined(MODULE) && defined(IP2DEBUG_OPEN) | 267 | #ifdef IP2DEBUG_OPEN |
267 | #define DBG_CNT(s) printk(KERN_DEBUG "(%s): [%x] ttyc=%d, modc=%x -> %s\n", \ | 268 | #define DBG_CNT(s) printk(KERN_DEBUG "(%s): [%x] ttyc=%d, modc=%x -> %s\n", \ |
268 | tty->name,(pCh->flags), \ | 269 | tty->name,(pCh->flags), \ |
269 | tty->count,/*GET_USE_COUNT(module)*/0,s) | 270 | tty->count,/*GET_USE_COUNT(module)*/0,s) |
@@ -285,7 +286,10 @@ MODULE_AUTHOR("Doug McNash"); | |||
285 | MODULE_DESCRIPTION("Computone IntelliPort Plus Driver"); | 286 | MODULE_DESCRIPTION("Computone IntelliPort Plus Driver"); |
286 | MODULE_LICENSE("GPL"); | 287 | MODULE_LICENSE("GPL"); |
287 | 288 | ||
289 | #define MAX_CMD_STR 50 | ||
290 | |||
288 | static int poll_only; | 291 | static int poll_only; |
292 | static char cmd[MAX_CMD_STR]; | ||
289 | 293 | ||
290 | static int Eisa_irq; | 294 | static int Eisa_irq; |
291 | static int Eisa_slot; | 295 | static int Eisa_slot; |
@@ -309,6 +313,8 @@ module_param_array(io, int, NULL, 0); | |||
309 | MODULE_PARM_DESC(io, "I/O ports for IntelliPort Cards"); | 313 | MODULE_PARM_DESC(io, "I/O ports for IntelliPort Cards"); |
310 | module_param(poll_only, bool, 0); | 314 | module_param(poll_only, bool, 0); |
311 | MODULE_PARM_DESC(poll_only, "Do not use card interrupts"); | 315 | MODULE_PARM_DESC(poll_only, "Do not use card interrupts"); |
316 | module_param_string(ip2, cmd, MAX_CMD_STR, 0); | ||
317 | MODULE_PARM_DESC(ip2, "Contains module parameter passed with 'ip2='"); | ||
312 | 318 | ||
313 | /* for sysfs class support */ | 319 | /* for sysfs class support */ |
314 | static struct class *ip2_class; | 320 | static struct class *ip2_class; |
@@ -487,7 +493,6 @@ static const struct firmware *ip2_request_firmware(void) | |||
487 | return fw; | 493 | return fw; |
488 | } | 494 | } |
489 | 495 | ||
490 | #ifndef MODULE | ||
491 | /****************************************************************************** | 496 | /****************************************************************************** |
492 | * ip2_setup: | 497 | * ip2_setup: |
493 | * str: kernel command line string | 498 | * str: kernel command line string |
@@ -531,7 +536,6 @@ static int __init ip2_setup(char *str) | |||
531 | return 1; | 536 | return 1; |
532 | } | 537 | } |
533 | __setup("ip2=", ip2_setup); | 538 | __setup("ip2=", ip2_setup); |
534 | #endif /* !MODULE */ | ||
535 | 539 | ||
536 | static int __init ip2_loadmain(void) | 540 | static int __init ip2_loadmain(void) |
537 | { | 541 | { |
@@ -539,14 +543,20 @@ static int __init ip2_loadmain(void) | |||
539 | int err = 0; | 543 | int err = 0; |
540 | i2eBordStrPtr pB = NULL; | 544 | i2eBordStrPtr pB = NULL; |
541 | int rc = -1; | 545 | int rc = -1; |
542 | struct pci_dev *pdev = NULL; | ||
543 | const struct firmware *fw = NULL; | 546 | const struct firmware *fw = NULL; |
547 | char *str; | ||
548 | |||
549 | str = cmd; | ||
544 | 550 | ||
545 | if (poll_only) { | 551 | if (poll_only) { |
546 | /* Hard lock the interrupts to zero */ | 552 | /* Hard lock the interrupts to zero */ |
547 | irq[0] = irq[1] = irq[2] = irq[3] = poll_only = 0; | 553 | irq[0] = irq[1] = irq[2] = irq[3] = poll_only = 0; |
548 | } | 554 | } |
549 | 555 | ||
556 | /* Check module parameter with 'ip2=' has been passed or not */ | ||
557 | if (!poll_only && (!strncmp(str, "ip2=", 4))) | ||
558 | ip2_setup(str); | ||
559 | |||
550 | ip2trace(ITRC_NO_PORT, ITRC_INIT, ITRC_ENTER, 0); | 560 | ip2trace(ITRC_NO_PORT, ITRC_INIT, ITRC_ENTER, 0); |
551 | 561 | ||
552 | /* process command line arguments to modprobe or | 562 | /* process command line arguments to modprobe or |
@@ -612,6 +622,7 @@ static int __init ip2_loadmain(void) | |||
612 | case PCI: | 622 | case PCI: |
613 | #ifdef CONFIG_PCI | 623 | #ifdef CONFIG_PCI |
614 | { | 624 | { |
625 | struct pci_dev *pdev = NULL; | ||
615 | u32 addr; | 626 | u32 addr; |
616 | int status; | 627 | int status; |
617 | 628 | ||
@@ -626,7 +637,7 @@ static int __init ip2_loadmain(void) | |||
626 | 637 | ||
627 | if (pci_enable_device(pdev)) { | 638 | if (pci_enable_device(pdev)) { |
628 | dev_err(&pdev->dev, "can't enable device\n"); | 639 | dev_err(&pdev->dev, "can't enable device\n"); |
629 | break; | 640 | goto out; |
630 | } | 641 | } |
631 | ip2config.type[i] = PCI; | 642 | ip2config.type[i] = PCI; |
632 | ip2config.pci_dev[i] = pci_dev_get(pdev); | 643 | ip2config.pci_dev[i] = pci_dev_get(pdev); |
@@ -638,6 +649,8 @@ static int __init ip2_loadmain(void) | |||
638 | dev_err(&pdev->dev, "I/O address error\n"); | 649 | dev_err(&pdev->dev, "I/O address error\n"); |
639 | 650 | ||
640 | ip2config.irq[i] = pdev->irq; | 651 | ip2config.irq[i] = pdev->irq; |
652 | out: | ||
653 | pci_dev_put(pdev); | ||
641 | } | 654 | } |
642 | #else | 655 | #else |
643 | printk(KERN_ERR "IP2: PCI card specified but PCI " | 656 | printk(KERN_ERR "IP2: PCI card specified but PCI " |
@@ -656,7 +669,6 @@ static int __init ip2_loadmain(void) | |||
656 | break; | 669 | break; |
657 | } /* switch */ | 670 | } /* switch */ |
658 | } /* for */ | 671 | } /* for */ |
659 | pci_dev_put(pdev); | ||
660 | 672 | ||
661 | for (i = 0; i < IP2_MAX_BOARDS; ++i) { | 673 | for (i = 0; i < IP2_MAX_BOARDS; ++i) { |
662 | if (ip2config.addr[i]) { | 674 | if (ip2config.addr[i]) { |
@@ -3197,3 +3209,5 @@ static struct pci_device_id ip2main_pci_tbl[] __devinitdata = { | |||
3197 | }; | 3209 | }; |
3198 | 3210 | ||
3199 | MODULE_DEVICE_TABLE(pci, ip2main_pci_tbl); | 3211 | MODULE_DEVICE_TABLE(pci, ip2main_pci_tbl); |
3212 | |||
3213 | MODULE_FIRMWARE("intelliport2.bin"); | ||
diff --git a/drivers/char/isicom.c b/drivers/char/isicom.c index 300d5bd6cd06..be2e8f9a27c3 100644 --- a/drivers/char/isicom.c +++ b/drivers/char/isicom.c | |||
@@ -113,6 +113,8 @@ | |||
113 | * 64-bit verification | 113 | * 64-bit verification |
114 | */ | 114 | */ |
115 | 115 | ||
116 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt | ||
117 | |||
116 | #include <linux/module.h> | 118 | #include <linux/module.h> |
117 | #include <linux/firmware.h> | 119 | #include <linux/firmware.h> |
118 | #include <linux/kernel.h> | 120 | #include <linux/kernel.h> |
@@ -140,7 +142,6 @@ | |||
140 | #define InterruptTheCard(base) outw(0, (base) + 0xc) | 142 | #define InterruptTheCard(base) outw(0, (base) + 0xc) |
141 | #define ClearInterrupt(base) inw((base) + 0x0a) | 143 | #define ClearInterrupt(base) inw((base) + 0x0a) |
142 | 144 | ||
143 | #define pr_dbg(str...) pr_debug("ISICOM: " str) | ||
144 | #ifdef DEBUG | 145 | #ifdef DEBUG |
145 | #define isicom_paranoia_check(a, b, c) __isicom_paranoia_check((a), (b), (c)) | 146 | #define isicom_paranoia_check(a, b, c) __isicom_paranoia_check((a), (b), (c)) |
146 | #else | 147 | #else |
@@ -249,8 +250,7 @@ static int lock_card(struct isi_board *card) | |||
249 | spin_unlock_irqrestore(&card->card_lock, card->flags); | 250 | spin_unlock_irqrestore(&card->card_lock, card->flags); |
250 | msleep(10); | 251 | msleep(10); |
251 | } | 252 | } |
252 | printk(KERN_WARNING "ISICOM: Failed to lock Card (0x%lx)\n", | 253 | pr_warning("Failed to lock Card (0x%lx)\n", card->base); |
253 | card->base); | ||
254 | 254 | ||
255 | return 0; /* Failed to acquire the card! */ | 255 | return 0; /* Failed to acquire the card! */ |
256 | } | 256 | } |
@@ -379,13 +379,13 @@ static inline int __isicom_paranoia_check(struct isi_port const *port, | |||
379 | char *name, const char *routine) | 379 | char *name, const char *routine) |
380 | { | 380 | { |
381 | if (!port) { | 381 | if (!port) { |
382 | printk(KERN_WARNING "ISICOM: Warning: bad isicom magic for " | 382 | pr_warning("Warning: bad isicom magic for dev %s in %s.\n", |
383 | "dev %s in %s.\n", name, routine); | 383 | name, routine); |
384 | return 1; | 384 | return 1; |
385 | } | 385 | } |
386 | if (port->magic != ISICOM_MAGIC) { | 386 | if (port->magic != ISICOM_MAGIC) { |
387 | printk(KERN_WARNING "ISICOM: Warning: NULL isicom port for " | 387 | pr_warning("Warning: NULL isicom port for dev %s in %s.\n", |
388 | "dev %s in %s.\n", name, routine); | 388 | name, routine); |
389 | return 1; | 389 | return 1; |
390 | } | 390 | } |
391 | 391 | ||
@@ -450,8 +450,8 @@ static void isicom_tx(unsigned long _data) | |||
450 | if (!(inw(base + 0x02) & (1 << port->channel))) | 450 | if (!(inw(base + 0x02) & (1 << port->channel))) |
451 | continue; | 451 | continue; |
452 | 452 | ||
453 | pr_dbg("txing %d bytes, port%d.\n", txcount, | 453 | pr_debug("txing %d bytes, port%d.\n", |
454 | port->channel + 1); | 454 | txcount, port->channel + 1); |
455 | outw((port->channel << isi_card[card].shift_count) | txcount, | 455 | outw((port->channel << isi_card[card].shift_count) | txcount, |
456 | base); | 456 | base); |
457 | residue = NO; | 457 | residue = NO; |
@@ -547,8 +547,8 @@ static irqreturn_t isicom_interrupt(int irq, void *dev_id) | |||
547 | byte_count = header & 0xff; | 547 | byte_count = header & 0xff; |
548 | 548 | ||
549 | if (channel + 1 > card->port_count) { | 549 | if (channel + 1 > card->port_count) { |
550 | printk(KERN_WARNING "ISICOM: isicom_interrupt(0x%lx): " | 550 | pr_warning("%s(0x%lx): %d(channel) > port_count.\n", |
551 | "%d(channel) > port_count.\n", base, channel+1); | 551 | __func__, base, channel+1); |
552 | outw(0x0000, base+0x04); /* enable interrupts */ | 552 | outw(0x0000, base+0x04); /* enable interrupts */ |
553 | spin_unlock(&card->card_lock); | 553 | spin_unlock(&card->card_lock); |
554 | return IRQ_HANDLED; | 554 | return IRQ_HANDLED; |
@@ -582,14 +582,15 @@ static irqreturn_t isicom_interrupt(int irq, void *dev_id) | |||
582 | if (port->status & ISI_DCD) { | 582 | if (port->status & ISI_DCD) { |
583 | if (!(header & ISI_DCD)) { | 583 | if (!(header & ISI_DCD)) { |
584 | /* Carrier has been lost */ | 584 | /* Carrier has been lost */ |
585 | pr_dbg("interrupt: DCD->low.\n" | 585 | pr_debug("%s: DCD->low.\n", |
586 | ); | 586 | __func__); |
587 | port->status &= ~ISI_DCD; | 587 | port->status &= ~ISI_DCD; |
588 | tty_hangup(tty); | 588 | tty_hangup(tty); |
589 | } | 589 | } |
590 | } else if (header & ISI_DCD) { | 590 | } else if (header & ISI_DCD) { |
591 | /* Carrier has been detected */ | 591 | /* Carrier has been detected */ |
592 | pr_dbg("interrupt: DCD->high.\n"); | 592 | pr_debug("%s: DCD->high.\n", |
593 | __func__); | ||
593 | port->status |= ISI_DCD; | 594 | port->status |= ISI_DCD; |
594 | wake_up_interruptible(&port->port.open_wait); | 595 | wake_up_interruptible(&port->port.open_wait); |
595 | } | 596 | } |
@@ -641,17 +642,19 @@ static irqreturn_t isicom_interrupt(int irq, void *dev_id) | |||
641 | break; | 642 | break; |
642 | 643 | ||
643 | case 2: /* Statistics */ | 644 | case 2: /* Statistics */ |
644 | pr_dbg("isicom_interrupt: stats!!!.\n"); | 645 | pr_debug("%s: stats!!!\n", __func__); |
645 | break; | 646 | break; |
646 | 647 | ||
647 | default: | 648 | default: |
648 | pr_dbg("Intr: Unknown code in status packet.\n"); | 649 | pr_debug("%s: Unknown code in status packet.\n", |
650 | __func__); | ||
649 | break; | 651 | break; |
650 | } | 652 | } |
651 | } else { /* Data Packet */ | 653 | } else { /* Data Packet */ |
652 | 654 | ||
653 | count = tty_prepare_flip_string(tty, &rp, byte_count & ~1); | 655 | count = tty_prepare_flip_string(tty, &rp, byte_count & ~1); |
654 | pr_dbg("Intr: Can rx %d of %d bytes.\n", count, byte_count); | 656 | pr_debug("%s: Can rx %d of %d bytes.\n", |
657 | __func__, count, byte_count); | ||
655 | word_count = count >> 1; | 658 | word_count = count >> 1; |
656 | insw(base, rp, word_count); | 659 | insw(base, rp, word_count); |
657 | byte_count -= (word_count << 1); | 660 | byte_count -= (word_count << 1); |
@@ -661,8 +664,8 @@ static irqreturn_t isicom_interrupt(int irq, void *dev_id) | |||
661 | byte_count -= 2; | 664 | byte_count -= 2; |
662 | } | 665 | } |
663 | if (byte_count > 0) { | 666 | if (byte_count > 0) { |
664 | pr_dbg("Intr(0x%lx:%d): Flip buffer overflow! dropping " | 667 | pr_debug("%s(0x%lx:%d): Flip buffer overflow! dropping bytes...\n", |
665 | "bytes...\n", base, channel + 1); | 668 | __func__, base, channel + 1); |
666 | /* drain out unread xtra data */ | 669 | /* drain out unread xtra data */ |
667 | while (byte_count > 0) { | 670 | while (byte_count > 0) { |
668 | inw(base); | 671 | inw(base); |
@@ -888,8 +891,8 @@ static void isicom_shutdown_port(struct isi_port *port) | |||
888 | struct isi_board *card = port->card; | 891 | struct isi_board *card = port->card; |
889 | 892 | ||
890 | if (--card->count < 0) { | 893 | if (--card->count < 0) { |
891 | pr_dbg("isicom_shutdown_port: bad board(0x%lx) count %d.\n", | 894 | pr_debug("%s: bad board(0x%lx) count %d.\n", |
892 | card->base, card->count); | 895 | __func__, card->base, card->count); |
893 | card->count = 0; | 896 | card->count = 0; |
894 | } | 897 | } |
895 | /* last port was closed, shutdown that board too */ | 898 | /* last port was closed, shutdown that board too */ |
@@ -1681,13 +1684,13 @@ static int __init isicom_init(void) | |||
1681 | 1684 | ||
1682 | retval = tty_register_driver(isicom_normal); | 1685 | retval = tty_register_driver(isicom_normal); |
1683 | if (retval) { | 1686 | if (retval) { |
1684 | pr_dbg("Couldn't register the dialin driver\n"); | 1687 | pr_debug("Couldn't register the dialin driver\n"); |
1685 | goto err_puttty; | 1688 | goto err_puttty; |
1686 | } | 1689 | } |
1687 | 1690 | ||
1688 | retval = pci_register_driver(&isicom_driver); | 1691 | retval = pci_register_driver(&isicom_driver); |
1689 | if (retval < 0) { | 1692 | if (retval < 0) { |
1690 | printk(KERN_ERR "ISICOM: Unable to register pci driver.\n"); | 1693 | pr_err("Unable to register pci driver.\n"); |
1691 | goto err_unrtty; | 1694 | goto err_unrtty; |
1692 | } | 1695 | } |
1693 | 1696 | ||
@@ -1717,3 +1720,8 @@ module_exit(isicom_exit); | |||
1717 | MODULE_AUTHOR("MultiTech"); | 1720 | MODULE_AUTHOR("MultiTech"); |
1718 | MODULE_DESCRIPTION("Driver for the ISI series of cards by MultiTech"); | 1721 | MODULE_DESCRIPTION("Driver for the ISI series of cards by MultiTech"); |
1719 | MODULE_LICENSE("GPL"); | 1722 | MODULE_LICENSE("GPL"); |
1723 | MODULE_FIRMWARE("isi608.bin"); | ||
1724 | MODULE_FIRMWARE("isi608em.bin"); | ||
1725 | MODULE_FIRMWARE("isi616em.bin"); | ||
1726 | MODULE_FIRMWARE("isi4608.bin"); | ||
1727 | MODULE_FIRMWARE("isi4616.bin"); | ||
diff --git a/drivers/char/keyboard.c b/drivers/char/keyboard.c index f706b1dffdb3..ada25bb8941e 100644 --- a/drivers/char/keyboard.c +++ b/drivers/char/keyboard.c | |||
@@ -1185,11 +1185,6 @@ static void kbd_keycode(unsigned int keycode, int down, int hw_raw) | |||
1185 | 1185 | ||
1186 | rep = (down == 2); | 1186 | rep = (down == 2); |
1187 | 1187 | ||
1188 | #ifdef CONFIG_MAC_EMUMOUSEBTN | ||
1189 | if (mac_hid_mouse_emulate_buttons(1, keycode, down)) | ||
1190 | return; | ||
1191 | #endif /* CONFIG_MAC_EMUMOUSEBTN */ | ||
1192 | |||
1193 | if ((raw_mode = (kbd->kbdmode == VC_RAW)) && !hw_raw) | 1188 | if ((raw_mode = (kbd->kbdmode == VC_RAW)) && !hw_raw) |
1194 | if (emulate_raw(vc, keycode, !down << 7)) | 1189 | if (emulate_raw(vc, keycode, !down << 7)) |
1195 | if (keycode < BTN_MISC && printk_ratelimit()) | 1190 | if (keycode < BTN_MISC && printk_ratelimit()) |
@@ -1328,6 +1323,21 @@ static void kbd_event(struct input_handle *handle, unsigned int event_type, | |||
1328 | schedule_console_callback(); | 1323 | schedule_console_callback(); |
1329 | } | 1324 | } |
1330 | 1325 | ||
1326 | static bool kbd_match(struct input_handler *handler, struct input_dev *dev) | ||
1327 | { | ||
1328 | int i; | ||
1329 | |||
1330 | if (test_bit(EV_SND, dev->evbit)) | ||
1331 | return true; | ||
1332 | |||
1333 | if (test_bit(EV_KEY, dev->evbit)) | ||
1334 | for (i = KEY_RESERVED; i < BTN_MISC; i++) | ||
1335 | if (test_bit(i, dev->keybit)) | ||
1336 | return true; | ||
1337 | |||
1338 | return false; | ||
1339 | } | ||
1340 | |||
1331 | /* | 1341 | /* |
1332 | * When a keyboard (or other input device) is found, the kbd_connect | 1342 | * When a keyboard (or other input device) is found, the kbd_connect |
1333 | * function is called. The function then looks at the device, and if it | 1343 | * function is called. The function then looks at the device, and if it |
@@ -1339,14 +1349,6 @@ static int kbd_connect(struct input_handler *handler, struct input_dev *dev, | |||
1339 | { | 1349 | { |
1340 | struct input_handle *handle; | 1350 | struct input_handle *handle; |
1341 | int error; | 1351 | int error; |
1342 | int i; | ||
1343 | |||
1344 | for (i = KEY_RESERVED; i < BTN_MISC; i++) | ||
1345 | if (test_bit(i, dev->keybit)) | ||
1346 | break; | ||
1347 | |||
1348 | if (i == BTN_MISC && !test_bit(EV_SND, dev->evbit)) | ||
1349 | return -ENODEV; | ||
1350 | 1352 | ||
1351 | handle = kzalloc(sizeof(struct input_handle), GFP_KERNEL); | 1353 | handle = kzalloc(sizeof(struct input_handle), GFP_KERNEL); |
1352 | if (!handle) | 1354 | if (!handle) |
@@ -1412,6 +1414,7 @@ MODULE_DEVICE_TABLE(input, kbd_ids); | |||
1412 | 1414 | ||
1413 | static struct input_handler kbd_handler = { | 1415 | static struct input_handler kbd_handler = { |
1414 | .event = kbd_event, | 1416 | .event = kbd_event, |
1417 | .match = kbd_match, | ||
1415 | .connect = kbd_connect, | 1418 | .connect = kbd_connect, |
1416 | .disconnect = kbd_disconnect, | 1419 | .disconnect = kbd_disconnect, |
1417 | .start = kbd_start, | 1420 | .start = kbd_start, |
diff --git a/drivers/char/moxa.c b/drivers/char/moxa.c index 63ee3bbc1ce4..166495d6a1d7 100644 --- a/drivers/char/moxa.c +++ b/drivers/char/moxa.c | |||
@@ -164,24 +164,25 @@ static unsigned int moxaFuncTout = HZ / 2; | |||
164 | static unsigned int moxaLowWaterChk; | 164 | static unsigned int moxaLowWaterChk; |
165 | static DEFINE_MUTEX(moxa_openlock); | 165 | static DEFINE_MUTEX(moxa_openlock); |
166 | static DEFINE_SPINLOCK(moxa_lock); | 166 | static DEFINE_SPINLOCK(moxa_lock); |
167 | /* Variables for insmod */ | 167 | |
168 | #ifdef MODULE | ||
169 | static unsigned long baseaddr[MAX_BOARDS]; | 168 | static unsigned long baseaddr[MAX_BOARDS]; |
170 | static unsigned int type[MAX_BOARDS]; | 169 | static unsigned int type[MAX_BOARDS]; |
171 | static unsigned int numports[MAX_BOARDS]; | 170 | static unsigned int numports[MAX_BOARDS]; |
172 | #endif | ||
173 | 171 | ||
174 | MODULE_AUTHOR("William Chen"); | 172 | MODULE_AUTHOR("William Chen"); |
175 | MODULE_DESCRIPTION("MOXA Intellio Family Multiport Board Device Driver"); | 173 | MODULE_DESCRIPTION("MOXA Intellio Family Multiport Board Device Driver"); |
176 | MODULE_LICENSE("GPL"); | 174 | MODULE_LICENSE("GPL"); |
177 | #ifdef MODULE | 175 | MODULE_FIRMWARE("c218tunx.cod"); |
176 | MODULE_FIRMWARE("cp204unx.cod"); | ||
177 | MODULE_FIRMWARE("c320tunx.cod"); | ||
178 | |||
178 | module_param_array(type, uint, NULL, 0); | 179 | module_param_array(type, uint, NULL, 0); |
179 | MODULE_PARM_DESC(type, "card type: C218=2, C320=4"); | 180 | MODULE_PARM_DESC(type, "card type: C218=2, C320=4"); |
180 | module_param_array(baseaddr, ulong, NULL, 0); | 181 | module_param_array(baseaddr, ulong, NULL, 0); |
181 | MODULE_PARM_DESC(baseaddr, "base address"); | 182 | MODULE_PARM_DESC(baseaddr, "base address"); |
182 | module_param_array(numports, uint, NULL, 0); | 183 | module_param_array(numports, uint, NULL, 0); |
183 | MODULE_PARM_DESC(numports, "numports (ignored for C218)"); | 184 | MODULE_PARM_DESC(numports, "numports (ignored for C218)"); |
184 | #endif | 185 | |
185 | module_param(ttymajor, int, 0); | 186 | module_param(ttymajor, int, 0); |
186 | 187 | ||
187 | /* | 188 | /* |
@@ -1024,6 +1025,8 @@ static int __init moxa_init(void) | |||
1024 | { | 1025 | { |
1025 | unsigned int isabrds = 0; | 1026 | unsigned int isabrds = 0; |
1026 | int retval = 0; | 1027 | int retval = 0; |
1028 | struct moxa_board_conf *brd = moxa_boards; | ||
1029 | unsigned int i; | ||
1027 | 1030 | ||
1028 | printk(KERN_INFO "MOXA Intellio family driver version %s\n", | 1031 | printk(KERN_INFO "MOXA Intellio family driver version %s\n", |
1029 | MOXA_VERSION); | 1032 | MOXA_VERSION); |
@@ -1051,10 +1054,7 @@ static int __init moxa_init(void) | |||
1051 | } | 1054 | } |
1052 | 1055 | ||
1053 | /* Find the boards defined from module args. */ | 1056 | /* Find the boards defined from module args. */ |
1054 | #ifdef MODULE | 1057 | |
1055 | { | ||
1056 | struct moxa_board_conf *brd = moxa_boards; | ||
1057 | unsigned int i; | ||
1058 | for (i = 0; i < MAX_BOARDS; i++) { | 1058 | for (i = 0; i < MAX_BOARDS; i++) { |
1059 | if (!baseaddr[i]) | 1059 | if (!baseaddr[i]) |
1060 | break; | 1060 | break; |
@@ -1087,8 +1087,6 @@ static int __init moxa_init(void) | |||
1087 | isabrds++; | 1087 | isabrds++; |
1088 | } | 1088 | } |
1089 | } | 1089 | } |
1090 | } | ||
1091 | #endif | ||
1092 | 1090 | ||
1093 | #ifdef CONFIG_PCI | 1091 | #ifdef CONFIG_PCI |
1094 | retval = pci_register_driver(&moxa_pci_driver); | 1092 | retval = pci_register_driver(&moxa_pci_driver); |
diff --git a/drivers/char/mxser.c b/drivers/char/mxser.c index 3d923065d9a2..e0c5d2a69046 100644 --- a/drivers/char/mxser.c +++ b/drivers/char/mxser.c | |||
@@ -895,8 +895,7 @@ static int mxser_activate(struct tty_port *port, struct tty_struct *tty) | |||
895 | if (inb(info->ioaddr + UART_LSR) == 0xff) { | 895 | if (inb(info->ioaddr + UART_LSR) == 0xff) { |
896 | spin_unlock_irqrestore(&info->slock, flags); | 896 | spin_unlock_irqrestore(&info->slock, flags); |
897 | if (capable(CAP_SYS_ADMIN)) { | 897 | if (capable(CAP_SYS_ADMIN)) { |
898 | if (tty) | 898 | set_bit(TTY_IO_ERROR, &tty->flags); |
899 | set_bit(TTY_IO_ERROR, &tty->flags); | ||
900 | return 0; | 899 | return 0; |
901 | } else | 900 | } else |
902 | return -ENODEV; | 901 | return -ENODEV; |
diff --git a/drivers/char/nozomi.c b/drivers/char/nozomi.c index 2ad7d37afbd0..a3f32a15fde4 100644 --- a/drivers/char/nozomi.c +++ b/drivers/char/nozomi.c | |||
@@ -136,10 +136,6 @@ static int debug; | |||
136 | #define RECEIVE_BUF_MAX 4 | 136 | #define RECEIVE_BUF_MAX 4 |
137 | 137 | ||
138 | 138 | ||
139 | /* Define all types of vendors and devices to support */ | ||
140 | #define VENDOR1 0x1931 /* Vendor Option */ | ||
141 | #define DEVICE1 0x000c /* HSDPA card */ | ||
142 | |||
143 | #define R_IIR 0x0000 /* Interrupt Identity Register */ | 139 | #define R_IIR 0x0000 /* Interrupt Identity Register */ |
144 | #define R_FCR 0x0000 /* Flow Control Register */ | 140 | #define R_FCR 0x0000 /* Flow Control Register */ |
145 | #define R_IER 0x0004 /* Interrupt Enable Register */ | 141 | #define R_IER 0x0004 /* Interrupt Enable Register */ |
@@ -371,6 +367,8 @@ struct port { | |||
371 | struct mutex tty_sem; | 367 | struct mutex tty_sem; |
372 | wait_queue_head_t tty_wait; | 368 | wait_queue_head_t tty_wait; |
373 | struct async_icount tty_icount; | 369 | struct async_icount tty_icount; |
370 | |||
371 | struct nozomi *dc; | ||
374 | }; | 372 | }; |
375 | 373 | ||
376 | /* Private data one for each card in the system */ | 374 | /* Private data one for each card in the system */ |
@@ -405,7 +403,7 @@ struct buffer { | |||
405 | 403 | ||
406 | /* Global variables */ | 404 | /* Global variables */ |
407 | static const struct pci_device_id nozomi_pci_tbl[] __devinitconst = { | 405 | static const struct pci_device_id nozomi_pci_tbl[] __devinitconst = { |
408 | {PCI_DEVICE(VENDOR1, DEVICE1)}, | 406 | {PCI_DEVICE(0x1931, 0x000c)}, /* Nozomi HSDPA */ |
409 | {}, | 407 | {}, |
410 | }; | 408 | }; |
411 | 409 | ||
@@ -414,6 +412,8 @@ MODULE_DEVICE_TABLE(pci, nozomi_pci_tbl); | |||
414 | static struct nozomi *ndevs[NOZOMI_MAX_CARDS]; | 412 | static struct nozomi *ndevs[NOZOMI_MAX_CARDS]; |
415 | static struct tty_driver *ntty_driver; | 413 | static struct tty_driver *ntty_driver; |
416 | 414 | ||
415 | static const struct tty_port_operations noz_tty_port_ops; | ||
416 | |||
417 | /* | 417 | /* |
418 | * find card by tty_index | 418 | * find card by tty_index |
419 | */ | 419 | */ |
@@ -853,8 +853,6 @@ static int receive_data(enum port_type index, struct nozomi *dc) | |||
853 | goto put; | 853 | goto put; |
854 | } | 854 | } |
855 | 855 | ||
856 | tty_buffer_request_room(tty, size); | ||
857 | |||
858 | while (size > 0) { | 856 | while (size > 0) { |
859 | read_mem32((u32 *) buf, addr + offset, RECEIVE_BUF_MAX); | 857 | read_mem32((u32 *) buf, addr + offset, RECEIVE_BUF_MAX); |
860 | 858 | ||
@@ -1473,9 +1471,11 @@ static int __devinit nozomi_card_init(struct pci_dev *pdev, | |||
1473 | 1471 | ||
1474 | for (i = 0; i < MAX_PORT; i++) { | 1472 | for (i = 0; i < MAX_PORT; i++) { |
1475 | struct device *tty_dev; | 1473 | struct device *tty_dev; |
1476 | 1474 | struct port *port = &dc->port[i]; | |
1477 | mutex_init(&dc->port[i].tty_sem); | 1475 | port->dc = dc; |
1478 | tty_port_init(&dc->port[i].port); | 1476 | mutex_init(&port->tty_sem); |
1477 | tty_port_init(&port->port); | ||
1478 | port->port.ops = &noz_tty_port_ops; | ||
1479 | tty_dev = tty_register_device(ntty_driver, dc->index_start + i, | 1479 | tty_dev = tty_register_device(ntty_driver, dc->index_start + i, |
1480 | &pdev->dev); | 1480 | &pdev->dev); |
1481 | 1481 | ||
@@ -1600,67 +1600,74 @@ static void set_dtr(const struct tty_struct *tty, int dtr) | |||
1600 | * ---------------------------------------------------------------------------- | 1600 | * ---------------------------------------------------------------------------- |
1601 | */ | 1601 | */ |
1602 | 1602 | ||
1603 | /* Called when the userspace process opens the tty, /dev/noz*. */ | 1603 | static int ntty_install(struct tty_driver *driver, struct tty_struct *tty) |
1604 | static int ntty_open(struct tty_struct *tty, struct file *file) | ||
1605 | { | 1604 | { |
1606 | struct port *port = get_port_by_tty(tty); | 1605 | struct port *port = get_port_by_tty(tty); |
1607 | struct nozomi *dc = get_dc_by_tty(tty); | 1606 | struct nozomi *dc = get_dc_by_tty(tty); |
1608 | unsigned long flags; | 1607 | int ret; |
1609 | |||
1610 | if (!port || !dc || dc->state != NOZOMI_STATE_READY) | 1608 | if (!port || !dc || dc->state != NOZOMI_STATE_READY) |
1611 | return -ENODEV; | 1609 | return -ENODEV; |
1612 | 1610 | ret = tty_init_termios(tty); | |
1613 | if (mutex_lock_interruptible(&port->tty_sem)) | 1611 | if (ret == 0) { |
1614 | return -ERESTARTSYS; | 1612 | tty_driver_kref_get(driver); |
1615 | 1613 | driver->ttys[tty->index] = tty; | |
1616 | port->port.count++; | ||
1617 | dc->open_ttys++; | ||
1618 | |||
1619 | /* Enable interrupt downlink for channel */ | ||
1620 | if (port->port.count == 1) { | ||
1621 | tty->driver_data = port; | ||
1622 | tty_port_tty_set(&port->port, tty); | ||
1623 | DBG1("open: %d", port->token_dl); | ||
1624 | spin_lock_irqsave(&dc->spin_mutex, flags); | ||
1625 | dc->last_ier = dc->last_ier | port->token_dl; | ||
1626 | writew(dc->last_ier, dc->reg_ier); | ||
1627 | spin_unlock_irqrestore(&dc->spin_mutex, flags); | ||
1628 | } | 1614 | } |
1629 | mutex_unlock(&port->tty_sem); | 1615 | return ret; |
1630 | return 0; | ||
1631 | } | 1616 | } |
1632 | 1617 | ||
1633 | /* Called when the userspace process close the tty, /dev/noz*. Also | 1618 | static void ntty_cleanup(struct tty_struct *tty) |
1634 | called immediately if ntty_open fails in which case tty->driver_data | 1619 | { |
1635 | will be NULL an we exit by the first return */ | 1620 | tty->driver_data = NULL; |
1621 | } | ||
1636 | 1622 | ||
1637 | static void ntty_close(struct tty_struct *tty, struct file *file) | 1623 | static int ntty_activate(struct tty_port *tport, struct tty_struct *tty) |
1638 | { | 1624 | { |
1639 | struct nozomi *dc = get_dc_by_tty(tty); | 1625 | struct port *port = container_of(tport, struct port, port); |
1640 | struct port *nport = tty->driver_data; | 1626 | struct nozomi *dc = port->dc; |
1641 | struct tty_port *port = &nport->port; | ||
1642 | unsigned long flags; | 1627 | unsigned long flags; |
1643 | 1628 | ||
1644 | if (!dc || !nport) | 1629 | DBG1("open: %d", port->token_dl); |
1645 | return; | 1630 | spin_lock_irqsave(&dc->spin_mutex, flags); |
1631 | dc->last_ier = dc->last_ier | port->token_dl; | ||
1632 | writew(dc->last_ier, dc->reg_ier); | ||
1633 | dc->open_ttys++; | ||
1634 | spin_unlock_irqrestore(&dc->spin_mutex, flags); | ||
1635 | printk("noz: activated %d: %p\n", tty->index, tport); | ||
1636 | return 0; | ||
1637 | } | ||
1646 | 1638 | ||
1647 | /* Users cannot interrupt a close */ | 1639 | static int ntty_open(struct tty_struct *tty, struct file *filp) |
1648 | mutex_lock(&nport->tty_sem); | 1640 | { |
1641 | struct port *port = get_port_by_tty(tty); | ||
1642 | return tty_port_open(&port->port, tty, filp); | ||
1643 | } | ||
1649 | 1644 | ||
1650 | WARN_ON(!port->count); | 1645 | static void ntty_shutdown(struct tty_port *tport) |
1646 | { | ||
1647 | struct port *port = container_of(tport, struct port, port); | ||
1648 | struct nozomi *dc = port->dc; | ||
1649 | unsigned long flags; | ||
1651 | 1650 | ||
1651 | DBG1("close: %d", port->token_dl); | ||
1652 | spin_lock_irqsave(&dc->spin_mutex, flags); | ||
1653 | dc->last_ier &= ~(port->token_dl); | ||
1654 | writew(dc->last_ier, dc->reg_ier); | ||
1652 | dc->open_ttys--; | 1655 | dc->open_ttys--; |
1653 | port->count--; | 1656 | spin_unlock_irqrestore(&dc->spin_mutex, flags); |
1657 | printk("noz: shutdown %p\n", tport); | ||
1658 | } | ||
1654 | 1659 | ||
1655 | if (port->count == 0) { | 1660 | static void ntty_close(struct tty_struct *tty, struct file *filp) |
1656 | DBG1("close: %d", nport->token_dl); | 1661 | { |
1657 | tty_port_tty_set(port, NULL); | 1662 | struct port *port = tty->driver_data; |
1658 | spin_lock_irqsave(&dc->spin_mutex, flags); | 1663 | if (port) |
1659 | dc->last_ier &= ~(nport->token_dl); | 1664 | tty_port_close(&port->port, tty, filp); |
1660 | writew(dc->last_ier, dc->reg_ier); | 1665 | } |
1661 | spin_unlock_irqrestore(&dc->spin_mutex, flags); | 1666 | |
1662 | } | 1667 | static void ntty_hangup(struct tty_struct *tty) |
1663 | mutex_unlock(&nport->tty_sem); | 1668 | { |
1669 | struct port *port = tty->driver_data; | ||
1670 | tty_port_hangup(&port->port); | ||
1664 | } | 1671 | } |
1665 | 1672 | ||
1666 | /* | 1673 | /* |
@@ -1680,15 +1687,7 @@ static int ntty_write(struct tty_struct *tty, const unsigned char *buffer, | |||
1680 | if (!dc || !port) | 1687 | if (!dc || !port) |
1681 | return -ENODEV; | 1688 | return -ENODEV; |
1682 | 1689 | ||
1683 | if (unlikely(!mutex_trylock(&port->tty_sem))) { | 1690 | mutex_lock(&port->tty_sem); |
1684 | /* | ||
1685 | * must test lock as tty layer wraps calls | ||
1686 | * to this function with BKL | ||
1687 | */ | ||
1688 | dev_err(&dc->pdev->dev, "Would have deadlocked - " | ||
1689 | "return EAGAIN\n"); | ||
1690 | return -EAGAIN; | ||
1691 | } | ||
1692 | 1691 | ||
1693 | if (unlikely(!port->port.count)) { | 1692 | if (unlikely(!port->port.count)) { |
1694 | DBG1(" "); | 1693 | DBG1(" "); |
@@ -1728,25 +1727,23 @@ exit: | |||
1728 | * This method is called by the upper tty layer. | 1727 | * This method is called by the upper tty layer. |
1729 | * #according to sources N_TTY.c it expects a value >= 0 and | 1728 | * #according to sources N_TTY.c it expects a value >= 0 and |
1730 | * does not check for negative values. | 1729 | * does not check for negative values. |
1730 | * | ||
1731 | * If the port is unplugged report lots of room and let the bits | ||
1732 | * dribble away so we don't block anything. | ||
1731 | */ | 1733 | */ |
1732 | static int ntty_write_room(struct tty_struct *tty) | 1734 | static int ntty_write_room(struct tty_struct *tty) |
1733 | { | 1735 | { |
1734 | struct port *port = tty->driver_data; | 1736 | struct port *port = tty->driver_data; |
1735 | int room = 0; | 1737 | int room = 4096; |
1736 | const struct nozomi *dc = get_dc_by_tty(tty); | 1738 | const struct nozomi *dc = get_dc_by_tty(tty); |
1737 | 1739 | ||
1738 | if (!dc || !port) | 1740 | if (dc) { |
1739 | return 0; | 1741 | mutex_lock(&port->tty_sem); |
1740 | if (!mutex_trylock(&port->tty_sem)) | 1742 | if (port->port.count) |
1741 | return 0; | 1743 | room = port->fifo_ul.size - |
1742 | 1744 | kfifo_len(&port->fifo_ul); | |
1743 | if (!port->port.count) | 1745 | mutex_unlock(&port->tty_sem); |
1744 | goto exit; | 1746 | } |
1745 | |||
1746 | room = port->fifo_ul.size - kfifo_len(&port->fifo_ul); | ||
1747 | |||
1748 | exit: | ||
1749 | mutex_unlock(&port->tty_sem); | ||
1750 | return room; | 1747 | return room; |
1751 | } | 1748 | } |
1752 | 1749 | ||
@@ -1906,10 +1903,16 @@ exit_in_buffer: | |||
1906 | return rval; | 1903 | return rval; |
1907 | } | 1904 | } |
1908 | 1905 | ||
1906 | static const struct tty_port_operations noz_tty_port_ops = { | ||
1907 | .activate = ntty_activate, | ||
1908 | .shutdown = ntty_shutdown, | ||
1909 | }; | ||
1910 | |||
1909 | static const struct tty_operations tty_ops = { | 1911 | static const struct tty_operations tty_ops = { |
1910 | .ioctl = ntty_ioctl, | 1912 | .ioctl = ntty_ioctl, |
1911 | .open = ntty_open, | 1913 | .open = ntty_open, |
1912 | .close = ntty_close, | 1914 | .close = ntty_close, |
1915 | .hangup = ntty_hangup, | ||
1913 | .write = ntty_write, | 1916 | .write = ntty_write, |
1914 | .write_room = ntty_write_room, | 1917 | .write_room = ntty_write_room, |
1915 | .unthrottle = ntty_unthrottle, | 1918 | .unthrottle = ntty_unthrottle, |
@@ -1917,6 +1920,8 @@ static const struct tty_operations tty_ops = { | |||
1917 | .chars_in_buffer = ntty_chars_in_buffer, | 1920 | .chars_in_buffer = ntty_chars_in_buffer, |
1918 | .tiocmget = ntty_tiocmget, | 1921 | .tiocmget = ntty_tiocmget, |
1919 | .tiocmset = ntty_tiocmset, | 1922 | .tiocmset = ntty_tiocmset, |
1923 | .install = ntty_install, | ||
1924 | .cleanup = ntty_cleanup, | ||
1920 | }; | 1925 | }; |
1921 | 1926 | ||
1922 | /* Module initialization */ | 1927 | /* Module initialization */ |
diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c index fdbcc9fd6d31..5eb83c3ca20d 100644 --- a/drivers/char/nvram.c +++ b/drivers/char/nvram.c | |||
@@ -336,14 +336,12 @@ static int nvram_ioctl(struct inode *inode, struct file *file, | |||
336 | 336 | ||
337 | static int nvram_open(struct inode *inode, struct file *file) | 337 | static int nvram_open(struct inode *inode, struct file *file) |
338 | { | 338 | { |
339 | lock_kernel(); | ||
340 | spin_lock(&nvram_state_lock); | 339 | spin_lock(&nvram_state_lock); |
341 | 340 | ||
342 | if ((nvram_open_cnt && (file->f_flags & O_EXCL)) || | 341 | if ((nvram_open_cnt && (file->f_flags & O_EXCL)) || |
343 | (nvram_open_mode & NVRAM_EXCL) || | 342 | (nvram_open_mode & NVRAM_EXCL) || |
344 | ((file->f_mode & FMODE_WRITE) && (nvram_open_mode & NVRAM_WRITE))) { | 343 | ((file->f_mode & FMODE_WRITE) && (nvram_open_mode & NVRAM_WRITE))) { |
345 | spin_unlock(&nvram_state_lock); | 344 | spin_unlock(&nvram_state_lock); |
346 | unlock_kernel(); | ||
347 | return -EBUSY; | 345 | return -EBUSY; |
348 | } | 346 | } |
349 | 347 | ||
@@ -354,7 +352,6 @@ static int nvram_open(struct inode *inode, struct file *file) | |||
354 | nvram_open_cnt++; | 352 | nvram_open_cnt++; |
355 | 353 | ||
356 | spin_unlock(&nvram_state_lock); | 354 | spin_unlock(&nvram_state_lock); |
357 | unlock_kernel(); | ||
358 | 355 | ||
359 | return 0; | 356 | return 0; |
360 | } | 357 | } |
diff --git a/drivers/char/pcmcia/cm4000_cs.c b/drivers/char/pcmcia/cm4000_cs.c index 2db4c0a29b05..c9bc896d68af 100644 --- a/drivers/char/pcmcia/cm4000_cs.c +++ b/drivers/char/pcmcia/cm4000_cs.c | |||
@@ -1047,7 +1047,7 @@ release_io: | |||
1047 | static ssize_t cmm_write(struct file *filp, const char __user *buf, | 1047 | static ssize_t cmm_write(struct file *filp, const char __user *buf, |
1048 | size_t count, loff_t *ppos) | 1048 | size_t count, loff_t *ppos) |
1049 | { | 1049 | { |
1050 | struct cm4000_dev *dev = (struct cm4000_dev *) filp->private_data; | 1050 | struct cm4000_dev *dev = filp->private_data; |
1051 | unsigned int iobase = dev->p_dev->io.BasePort1; | 1051 | unsigned int iobase = dev->p_dev->io.BasePort1; |
1052 | unsigned short s; | 1052 | unsigned short s; |
1053 | unsigned char tmp; | 1053 | unsigned char tmp; |
diff --git a/drivers/char/serial167.c b/drivers/char/serial167.c index 452370af95de..986aa606a6b6 100644 --- a/drivers/char/serial167.c +++ b/drivers/char/serial167.c | |||
@@ -658,8 +658,7 @@ static irqreturn_t cd2401_rx_interrupt(int irq, void *dev_id) | |||
658 | info->mon.char_max = char_count; | 658 | info->mon.char_max = char_count; |
659 | info->mon.char_last = char_count; | 659 | info->mon.char_last = char_count; |
660 | #endif | 660 | #endif |
661 | len = tty_buffer_request_room(tty, char_count); | 661 | while (char_count--) { |
662 | while (len--) { | ||
663 | data = base_addr[CyRDR]; | 662 | data = base_addr[CyRDR]; |
664 | tty_insert_flip_char(tty, data, TTY_NORMAL); | 663 | tty_insert_flip_char(tty, data, TTY_NORMAL); |
665 | #ifdef CYCLOM_16Y_HACK | 664 | #ifdef CYCLOM_16Y_HACK |
diff --git a/drivers/char/specialix.c b/drivers/char/specialix.c index 268e17f9ec3f..07ac14d949ce 100644 --- a/drivers/char/specialix.c +++ b/drivers/char/specialix.c | |||
@@ -646,8 +646,6 @@ static void sx_receive(struct specialix_board *bp) | |||
646 | dprintk(SX_DEBUG_RX, "port: %p: count: %d\n", port, count); | 646 | dprintk(SX_DEBUG_RX, "port: %p: count: %d\n", port, count); |
647 | port->hits[count > 8 ? 9 : count]++; | 647 | port->hits[count > 8 ? 9 : count]++; |
648 | 648 | ||
649 | tty_buffer_request_room(tty, count); | ||
650 | |||
651 | while (count--) | 649 | while (count--) |
652 | tty_insert_flip_char(tty, sx_in(bp, CD186x_RDR), TTY_NORMAL); | 650 | tty_insert_flip_char(tty, sx_in(bp, CD186x_RDR), TTY_NORMAL); |
653 | tty_flip_buffer_push(tty); | 651 | tty_flip_buffer_push(tty); |
diff --git a/drivers/char/synclink.c b/drivers/char/synclink.c index 4846b73ef28d..0658fc548222 100644 --- a/drivers/char/synclink.c +++ b/drivers/char/synclink.c | |||
@@ -2031,7 +2031,7 @@ static int mgsl_put_char(struct tty_struct *tty, unsigned char ch) | |||
2031 | if (mgsl_paranoia_check(info, tty->name, "mgsl_put_char")) | 2031 | if (mgsl_paranoia_check(info, tty->name, "mgsl_put_char")) |
2032 | return 0; | 2032 | return 0; |
2033 | 2033 | ||
2034 | if (!tty || !info->xmit_buf) | 2034 | if (!info->xmit_buf) |
2035 | return 0; | 2035 | return 0; |
2036 | 2036 | ||
2037 | spin_lock_irqsave(&info->irq_spinlock, flags); | 2037 | spin_lock_irqsave(&info->irq_spinlock, flags); |
@@ -2121,7 +2121,7 @@ static int mgsl_write(struct tty_struct * tty, | |||
2121 | if (mgsl_paranoia_check(info, tty->name, "mgsl_write")) | 2121 | if (mgsl_paranoia_check(info, tty->name, "mgsl_write")) |
2122 | goto cleanup; | 2122 | goto cleanup; |
2123 | 2123 | ||
2124 | if (!tty || !info->xmit_buf) | 2124 | if (!info->xmit_buf) |
2125 | goto cleanup; | 2125 | goto cleanup; |
2126 | 2126 | ||
2127 | if ( info->params.mode == MGSL_MODE_HDLC || | 2127 | if ( info->params.mode == MGSL_MODE_HDLC || |
diff --git a/drivers/char/synclink_gt.c b/drivers/char/synclink_gt.c index 8678f0c8699d..4561ce2fba6d 100644 --- a/drivers/char/synclink_gt.c +++ b/drivers/char/synclink_gt.c | |||
@@ -468,7 +468,7 @@ static unsigned int free_tbuf_count(struct slgt_info *info); | |||
468 | static unsigned int tbuf_bytes(struct slgt_info *info); | 468 | static unsigned int tbuf_bytes(struct slgt_info *info); |
469 | static void reset_tbufs(struct slgt_info *info); | 469 | static void reset_tbufs(struct slgt_info *info); |
470 | static void tdma_reset(struct slgt_info *info); | 470 | static void tdma_reset(struct slgt_info *info); |
471 | static void tx_load(struct slgt_info *info, const char *buf, unsigned int count); | 471 | static bool tx_load(struct slgt_info *info, const char *buf, unsigned int count); |
472 | 472 | ||
473 | static void get_signals(struct slgt_info *info); | 473 | static void get_signals(struct slgt_info *info); |
474 | static void set_signals(struct slgt_info *info); | 474 | static void set_signals(struct slgt_info *info); |
@@ -813,59 +813,32 @@ static int write(struct tty_struct *tty, | |||
813 | int ret = 0; | 813 | int ret = 0; |
814 | struct slgt_info *info = tty->driver_data; | 814 | struct slgt_info *info = tty->driver_data; |
815 | unsigned long flags; | 815 | unsigned long flags; |
816 | unsigned int bufs_needed; | ||
817 | 816 | ||
818 | if (sanity_check(info, tty->name, "write")) | 817 | if (sanity_check(info, tty->name, "write")) |
819 | goto cleanup; | 818 | return -EIO; |
819 | |||
820 | DBGINFO(("%s write count=%d\n", info->device_name, count)); | 820 | DBGINFO(("%s write count=%d\n", info->device_name, count)); |
821 | 821 | ||
822 | if (!info->tx_buf) | 822 | if (!info->tx_buf || (count > info->max_frame_size)) |
823 | goto cleanup; | 823 | return -EIO; |
824 | 824 | ||
825 | if (count > info->max_frame_size) { | 825 | if (!count || tty->stopped || tty->hw_stopped) |
826 | ret = -EIO; | 826 | return 0; |
827 | goto cleanup; | ||
828 | } | ||
829 | 827 | ||
830 | if (!count) | 828 | spin_lock_irqsave(&info->lock, flags); |
831 | goto cleanup; | ||
832 | 829 | ||
833 | if (!info->tx_active && info->tx_count) { | 830 | if (info->tx_count) { |
834 | /* send accumulated data from send_char() */ | 831 | /* send accumulated data from send_char() */ |
835 | tx_load(info, info->tx_buf, info->tx_count); | 832 | if (!tx_load(info, info->tx_buf, info->tx_count)) |
836 | goto start; | 833 | goto cleanup; |
834 | info->tx_count = 0; | ||
837 | } | 835 | } |
838 | bufs_needed = (count/DMABUFSIZE); | ||
839 | if (count % DMABUFSIZE) | ||
840 | ++bufs_needed; | ||
841 | if (bufs_needed > free_tbuf_count(info)) | ||
842 | goto cleanup; | ||
843 | 836 | ||
844 | ret = info->tx_count = count; | 837 | if (tx_load(info, buf, count)) |
845 | tx_load(info, buf, count); | 838 | ret = count; |
846 | goto start; | ||
847 | |||
848 | start: | ||
849 | if (info->tx_count && !tty->stopped && !tty->hw_stopped) { | ||
850 | spin_lock_irqsave(&info->lock,flags); | ||
851 | if (!info->tx_active) | ||
852 | tx_start(info); | ||
853 | else if (!(rd_reg32(info, TDCSR) & BIT0)) { | ||
854 | /* transmit still active but transmit DMA stopped */ | ||
855 | unsigned int i = info->tbuf_current; | ||
856 | if (!i) | ||
857 | i = info->tbuf_count; | ||
858 | i--; | ||
859 | /* if DMA buf unsent must try later after tx idle */ | ||
860 | if (desc_count(info->tbufs[i])) | ||
861 | ret = 0; | ||
862 | } | ||
863 | if (ret > 0) | ||
864 | update_tx_timer(info); | ||
865 | spin_unlock_irqrestore(&info->lock,flags); | ||
866 | } | ||
867 | 839 | ||
868 | cleanup: | 840 | cleanup: |
841 | spin_unlock_irqrestore(&info->lock, flags); | ||
869 | DBGINFO(("%s write rc=%d\n", info->device_name, ret)); | 842 | DBGINFO(("%s write rc=%d\n", info->device_name, ret)); |
870 | return ret; | 843 | return ret; |
871 | } | 844 | } |
@@ -882,7 +855,7 @@ static int put_char(struct tty_struct *tty, unsigned char ch) | |||
882 | if (!info->tx_buf) | 855 | if (!info->tx_buf) |
883 | return 0; | 856 | return 0; |
884 | spin_lock_irqsave(&info->lock,flags); | 857 | spin_lock_irqsave(&info->lock,flags); |
885 | if (!info->tx_active && (info->tx_count < info->max_frame_size)) { | 858 | if (info->tx_count < info->max_frame_size) { |
886 | info->tx_buf[info->tx_count++] = ch; | 859 | info->tx_buf[info->tx_count++] = ch; |
887 | ret = 1; | 860 | ret = 1; |
888 | } | 861 | } |
@@ -981,10 +954,8 @@ static void flush_chars(struct tty_struct *tty) | |||
981 | DBGINFO(("%s flush_chars start transmit\n", info->device_name)); | 954 | DBGINFO(("%s flush_chars start transmit\n", info->device_name)); |
982 | 955 | ||
983 | spin_lock_irqsave(&info->lock,flags); | 956 | spin_lock_irqsave(&info->lock,flags); |
984 | if (!info->tx_active && info->tx_count) { | 957 | if (info->tx_count && tx_load(info, info->tx_buf, info->tx_count)) |
985 | tx_load(info, info->tx_buf,info->tx_count); | 958 | info->tx_count = 0; |
986 | tx_start(info); | ||
987 | } | ||
988 | spin_unlock_irqrestore(&info->lock,flags); | 959 | spin_unlock_irqrestore(&info->lock,flags); |
989 | } | 960 | } |
990 | 961 | ||
@@ -997,10 +968,9 @@ static void flush_buffer(struct tty_struct *tty) | |||
997 | return; | 968 | return; |
998 | DBGINFO(("%s flush_buffer\n", info->device_name)); | 969 | DBGINFO(("%s flush_buffer\n", info->device_name)); |
999 | 970 | ||
1000 | spin_lock_irqsave(&info->lock,flags); | 971 | spin_lock_irqsave(&info->lock, flags); |
1001 | if (!info->tx_active) | 972 | info->tx_count = 0; |
1002 | info->tx_count = 0; | 973 | spin_unlock_irqrestore(&info->lock, flags); |
1003 | spin_unlock_irqrestore(&info->lock,flags); | ||
1004 | 974 | ||
1005 | tty_wakeup(tty); | 975 | tty_wakeup(tty); |
1006 | } | 976 | } |
@@ -1033,12 +1003,10 @@ static void tx_release(struct tty_struct *tty) | |||
1033 | if (sanity_check(info, tty->name, "tx_release")) | 1003 | if (sanity_check(info, tty->name, "tx_release")) |
1034 | return; | 1004 | return; |
1035 | DBGINFO(("%s tx_release\n", info->device_name)); | 1005 | DBGINFO(("%s tx_release\n", info->device_name)); |
1036 | spin_lock_irqsave(&info->lock,flags); | 1006 | spin_lock_irqsave(&info->lock, flags); |
1037 | if (!info->tx_active && info->tx_count) { | 1007 | if (info->tx_count && tx_load(info, info->tx_buf, info->tx_count)) |
1038 | tx_load(info, info->tx_buf, info->tx_count); | 1008 | info->tx_count = 0; |
1039 | tx_start(info); | 1009 | spin_unlock_irqrestore(&info->lock, flags); |
1040 | } | ||
1041 | spin_unlock_irqrestore(&info->lock,flags); | ||
1042 | } | 1010 | } |
1043 | 1011 | ||
1044 | /* | 1012 | /* |
@@ -1506,27 +1474,25 @@ static netdev_tx_t hdlcdev_xmit(struct sk_buff *skb, | |||
1506 | 1474 | ||
1507 | DBGINFO(("%s hdlc_xmit\n", dev->name)); | 1475 | DBGINFO(("%s hdlc_xmit\n", dev->name)); |
1508 | 1476 | ||
1477 | if (!skb->len) | ||
1478 | return NETDEV_TX_OK; | ||
1479 | |||
1509 | /* stop sending until this frame completes */ | 1480 | /* stop sending until this frame completes */ |
1510 | netif_stop_queue(dev); | 1481 | netif_stop_queue(dev); |
1511 | 1482 | ||
1512 | /* copy data to device buffers */ | ||
1513 | info->tx_count = skb->len; | ||
1514 | tx_load(info, skb->data, skb->len); | ||
1515 | |||
1516 | /* update network statistics */ | 1483 | /* update network statistics */ |
1517 | dev->stats.tx_packets++; | 1484 | dev->stats.tx_packets++; |
1518 | dev->stats.tx_bytes += skb->len; | 1485 | dev->stats.tx_bytes += skb->len; |
1519 | 1486 | ||
1520 | /* done with socket buffer, so free it */ | ||
1521 | dev_kfree_skb(skb); | ||
1522 | |||
1523 | /* save start time for transmit timeout detection */ | 1487 | /* save start time for transmit timeout detection */ |
1524 | dev->trans_start = jiffies; | 1488 | dev->trans_start = jiffies; |
1525 | 1489 | ||
1526 | spin_lock_irqsave(&info->lock,flags); | 1490 | spin_lock_irqsave(&info->lock, flags); |
1527 | tx_start(info); | 1491 | tx_load(info, skb->data, skb->len); |
1528 | update_tx_timer(info); | 1492 | spin_unlock_irqrestore(&info->lock, flags); |
1529 | spin_unlock_irqrestore(&info->lock,flags); | 1493 | |
1494 | /* done with socket buffer, so free it */ | ||
1495 | dev_kfree_skb(skb); | ||
1530 | 1496 | ||
1531 | return NETDEV_TX_OK; | 1497 | return NETDEV_TX_OK; |
1532 | } | 1498 | } |
@@ -2180,7 +2146,7 @@ static void isr_serial(struct slgt_info *info) | |||
2180 | 2146 | ||
2181 | if (info->params.mode == MGSL_MODE_ASYNC) { | 2147 | if (info->params.mode == MGSL_MODE_ASYNC) { |
2182 | if (status & IRQ_TXIDLE) { | 2148 | if (status & IRQ_TXIDLE) { |
2183 | if (info->tx_count) | 2149 | if (info->tx_active) |
2184 | isr_txeom(info, status); | 2150 | isr_txeom(info, status); |
2185 | } | 2151 | } |
2186 | if (info->rx_pio && (status & IRQ_RXDATA)) | 2152 | if (info->rx_pio && (status & IRQ_RXDATA)) |
@@ -2276,13 +2242,42 @@ static void isr_tdma(struct slgt_info *info) | |||
2276 | } | 2242 | } |
2277 | } | 2243 | } |
2278 | 2244 | ||
2245 | /* | ||
2246 | * return true if there are unsent tx DMA buffers, otherwise false | ||
2247 | * | ||
2248 | * if there are unsent buffers then info->tbuf_start | ||
2249 | * is set to index of first unsent buffer | ||
2250 | */ | ||
2251 | static bool unsent_tbufs(struct slgt_info *info) | ||
2252 | { | ||
2253 | unsigned int i = info->tbuf_current; | ||
2254 | bool rc = false; | ||
2255 | |||
2256 | /* | ||
2257 | * search backwards from last loaded buffer (precedes tbuf_current) | ||
2258 | * for first unsent buffer (desc_count > 0) | ||
2259 | */ | ||
2260 | |||
2261 | do { | ||
2262 | if (i) | ||
2263 | i--; | ||
2264 | else | ||
2265 | i = info->tbuf_count - 1; | ||
2266 | if (!desc_count(info->tbufs[i])) | ||
2267 | break; | ||
2268 | info->tbuf_start = i; | ||
2269 | rc = true; | ||
2270 | } while (i != info->tbuf_current); | ||
2271 | |||
2272 | return rc; | ||
2273 | } | ||
2274 | |||
2279 | static void isr_txeom(struct slgt_info *info, unsigned short status) | 2275 | static void isr_txeom(struct slgt_info *info, unsigned short status) |
2280 | { | 2276 | { |
2281 | DBGISR(("%s txeom status=%04x\n", info->device_name, status)); | 2277 | DBGISR(("%s txeom status=%04x\n", info->device_name, status)); |
2282 | 2278 | ||
2283 | slgt_irq_off(info, IRQ_TXDATA + IRQ_TXIDLE + IRQ_TXUNDER); | 2279 | slgt_irq_off(info, IRQ_TXDATA + IRQ_TXIDLE + IRQ_TXUNDER); |
2284 | tdma_reset(info); | 2280 | tdma_reset(info); |
2285 | reset_tbufs(info); | ||
2286 | if (status & IRQ_TXUNDER) { | 2281 | if (status & IRQ_TXUNDER) { |
2287 | unsigned short val = rd_reg16(info, TCR); | 2282 | unsigned short val = rd_reg16(info, TCR); |
2288 | wr_reg16(info, TCR, (unsigned short)(val | BIT2)); /* set reset bit */ | 2283 | wr_reg16(info, TCR, (unsigned short)(val | BIT2)); /* set reset bit */ |
@@ -2297,8 +2292,12 @@ static void isr_txeom(struct slgt_info *info, unsigned short status) | |||
2297 | info->icount.txok++; | 2292 | info->icount.txok++; |
2298 | } | 2293 | } |
2299 | 2294 | ||
2295 | if (unsent_tbufs(info)) { | ||
2296 | tx_start(info); | ||
2297 | update_tx_timer(info); | ||
2298 | return; | ||
2299 | } | ||
2300 | info->tx_active = false; | 2300 | info->tx_active = false; |
2301 | info->tx_count = 0; | ||
2302 | 2301 | ||
2303 | del_timer(&info->tx_timer); | 2302 | del_timer(&info->tx_timer); |
2304 | 2303 | ||
@@ -3949,7 +3948,7 @@ static void tx_start(struct slgt_info *info) | |||
3949 | info->tx_enabled = true; | 3948 | info->tx_enabled = true; |
3950 | } | 3949 | } |
3951 | 3950 | ||
3952 | if (info->tx_count) { | 3951 | if (desc_count(info->tbufs[info->tbuf_start])) { |
3953 | info->drop_rts_on_tx_done = false; | 3952 | info->drop_rts_on_tx_done = false; |
3954 | 3953 | ||
3955 | if (info->params.mode != MGSL_MODE_ASYNC) { | 3954 | if (info->params.mode != MGSL_MODE_ASYNC) { |
@@ -4772,25 +4771,36 @@ static unsigned int tbuf_bytes(struct slgt_info *info) | |||
4772 | } | 4771 | } |
4773 | 4772 | ||
4774 | /* | 4773 | /* |
4775 | * load transmit DMA buffer(s) with data | 4774 | * load data into transmit DMA buffer ring and start transmitter if needed |
4775 | * return true if data accepted, otherwise false (buffers full) | ||
4776 | */ | 4776 | */ |
4777 | static void tx_load(struct slgt_info *info, const char *buf, unsigned int size) | 4777 | static bool tx_load(struct slgt_info *info, const char *buf, unsigned int size) |
4778 | { | 4778 | { |
4779 | unsigned short count; | 4779 | unsigned short count; |
4780 | unsigned int i; | 4780 | unsigned int i; |
4781 | struct slgt_desc *d; | 4781 | struct slgt_desc *d; |
4782 | 4782 | ||
4783 | if (size == 0) | 4783 | /* check required buffer space */ |
4784 | return; | 4784 | if (DIV_ROUND_UP(size, DMABUFSIZE) > free_tbuf_count(info)) |
4785 | return false; | ||
4785 | 4786 | ||
4786 | DBGDATA(info, buf, size, "tx"); | 4787 | DBGDATA(info, buf, size, "tx"); |
4787 | 4788 | ||
4789 | /* | ||
4790 | * copy data to one or more DMA buffers in circular ring | ||
4791 | * tbuf_start = first buffer for this data | ||
4792 | * tbuf_current = next free buffer | ||
4793 | * | ||
4794 | * Copy all data before making data visible to DMA controller by | ||
4795 | * setting descriptor count of the first buffer. | ||
4796 | * This prevents an active DMA controller from reading the first DMA | ||
4797 | * buffers of a frame and stopping before the final buffers are filled. | ||
4798 | */ | ||
4799 | |||
4788 | info->tbuf_start = i = info->tbuf_current; | 4800 | info->tbuf_start = i = info->tbuf_current; |
4789 | 4801 | ||
4790 | while (size) { | 4802 | while (size) { |
4791 | d = &info->tbufs[i]; | 4803 | d = &info->tbufs[i]; |
4792 | if (++i == info->tbuf_count) | ||
4793 | i = 0; | ||
4794 | 4804 | ||
4795 | count = (unsigned short)((size > DMABUFSIZE) ? DMABUFSIZE : size); | 4805 | count = (unsigned short)((size > DMABUFSIZE) ? DMABUFSIZE : size); |
4796 | memcpy(d->buf, buf, count); | 4806 | memcpy(d->buf, buf, count); |
@@ -4808,11 +4818,27 @@ static void tx_load(struct slgt_info *info, const char *buf, unsigned int size) | |||
4808 | else | 4818 | else |
4809 | set_desc_eof(*d, 0); | 4819 | set_desc_eof(*d, 0); |
4810 | 4820 | ||
4811 | set_desc_count(*d, count); | 4821 | /* set descriptor count for all but first buffer */ |
4822 | if (i != info->tbuf_start) | ||
4823 | set_desc_count(*d, count); | ||
4812 | d->buf_count = count; | 4824 | d->buf_count = count; |
4825 | |||
4826 | if (++i == info->tbuf_count) | ||
4827 | i = 0; | ||
4813 | } | 4828 | } |
4814 | 4829 | ||
4815 | info->tbuf_current = i; | 4830 | info->tbuf_current = i; |
4831 | |||
4832 | /* set first buffer count to make new data visible to DMA controller */ | ||
4833 | d = &info->tbufs[info->tbuf_start]; | ||
4834 | set_desc_count(*d, d->buf_count); | ||
4835 | |||
4836 | /* start transmitter if needed and update transmit timeout */ | ||
4837 | if (!info->tx_active) | ||
4838 | tx_start(info); | ||
4839 | update_tx_timer(info); | ||
4840 | |||
4841 | return true; | ||
4816 | } | 4842 | } |
4817 | 4843 | ||
4818 | static int register_test(struct slgt_info *info) | 4844 | static int register_test(struct slgt_info *info) |
@@ -4934,9 +4960,7 @@ static int loopback_test(struct slgt_info *info) | |||
4934 | spin_lock_irqsave(&info->lock,flags); | 4960 | spin_lock_irqsave(&info->lock,flags); |
4935 | async_mode(info); | 4961 | async_mode(info); |
4936 | rx_start(info); | 4962 | rx_start(info); |
4937 | info->tx_count = count; | ||
4938 | tx_load(info, buf, count); | 4963 | tx_load(info, buf, count); |
4939 | tx_start(info); | ||
4940 | spin_unlock_irqrestore(&info->lock, flags); | 4964 | spin_unlock_irqrestore(&info->lock, flags); |
4941 | 4965 | ||
4942 | /* wait for receive complete */ | 4966 | /* wait for receive complete */ |
diff --git a/drivers/char/tty_buffer.c b/drivers/char/tty_buffer.c index 66fa4e10d76b..af8d97715728 100644 --- a/drivers/char/tty_buffer.c +++ b/drivers/char/tty_buffer.c | |||
@@ -231,9 +231,10 @@ int tty_buffer_request_room(struct tty_struct *tty, size_t size) | |||
231 | EXPORT_SYMBOL_GPL(tty_buffer_request_room); | 231 | EXPORT_SYMBOL_GPL(tty_buffer_request_room); |
232 | 232 | ||
233 | /** | 233 | /** |
234 | * tty_insert_flip_string - Add characters to the tty buffer | 234 | * tty_insert_flip_string_fixed_flag - Add characters to the tty buffer |
235 | * @tty: tty structure | 235 | * @tty: tty structure |
236 | * @chars: characters | 236 | * @chars: characters |
237 | * @flag: flag value for each character | ||
237 | * @size: size | 238 | * @size: size |
238 | * | 239 | * |
239 | * Queue a series of bytes to the tty buffering. All the characters | 240 | * Queue a series of bytes to the tty buffering. All the characters |
@@ -242,18 +243,19 @@ EXPORT_SYMBOL_GPL(tty_buffer_request_room); | |||
242 | * Locking: Called functions may take tty->buf.lock | 243 | * Locking: Called functions may take tty->buf.lock |
243 | */ | 244 | */ |
244 | 245 | ||
245 | int tty_insert_flip_string(struct tty_struct *tty, const unsigned char *chars, | 246 | int tty_insert_flip_string_fixed_flag(struct tty_struct *tty, |
246 | size_t size) | 247 | const unsigned char *chars, char flag, size_t size) |
247 | { | 248 | { |
248 | int copied = 0; | 249 | int copied = 0; |
249 | do { | 250 | do { |
250 | int space = tty_buffer_request_room(tty, size - copied); | 251 | int goal = min(size - copied, TTY_BUFFER_PAGE); |
252 | int space = tty_buffer_request_room(tty, goal); | ||
251 | struct tty_buffer *tb = tty->buf.tail; | 253 | struct tty_buffer *tb = tty->buf.tail; |
252 | /* If there is no space then tb may be NULL */ | 254 | /* If there is no space then tb may be NULL */ |
253 | if (unlikely(space == 0)) | 255 | if (unlikely(space == 0)) |
254 | break; | 256 | break; |
255 | memcpy(tb->char_buf_ptr + tb->used, chars, space); | 257 | memcpy(tb->char_buf_ptr + tb->used, chars, space); |
256 | memset(tb->flag_buf_ptr + tb->used, TTY_NORMAL, space); | 258 | memset(tb->flag_buf_ptr + tb->used, flag, space); |
257 | tb->used += space; | 259 | tb->used += space; |
258 | copied += space; | 260 | copied += space; |
259 | chars += space; | 261 | chars += space; |
@@ -262,7 +264,7 @@ int tty_insert_flip_string(struct tty_struct *tty, const unsigned char *chars, | |||
262 | } while (unlikely(size > copied)); | 264 | } while (unlikely(size > copied)); |
263 | return copied; | 265 | return copied; |
264 | } | 266 | } |
265 | EXPORT_SYMBOL(tty_insert_flip_string); | 267 | EXPORT_SYMBOL(tty_insert_flip_string_fixed_flag); |
266 | 268 | ||
267 | /** | 269 | /** |
268 | * tty_insert_flip_string_flags - Add characters to the tty buffer | 270 | * tty_insert_flip_string_flags - Add characters to the tty buffer |
@@ -283,7 +285,8 @@ int tty_insert_flip_string_flags(struct tty_struct *tty, | |||
283 | { | 285 | { |
284 | int copied = 0; | 286 | int copied = 0; |
285 | do { | 287 | do { |
286 | int space = tty_buffer_request_room(tty, size - copied); | 288 | int goal = min(size - copied, TTY_BUFFER_PAGE); |
289 | int space = tty_buffer_request_room(tty, goal); | ||
287 | struct tty_buffer *tb = tty->buf.tail; | 290 | struct tty_buffer *tb = tty->buf.tail; |
288 | /* If there is no space then tb may be NULL */ | 291 | /* If there is no space then tb may be NULL */ |
289 | if (unlikely(space == 0)) | 292 | if (unlikely(space == 0)) |
diff --git a/drivers/char/tty_ldisc.c b/drivers/char/tty_ldisc.c index 3f653f7d849f..500e740ec5e4 100644 --- a/drivers/char/tty_ldisc.c +++ b/drivers/char/tty_ldisc.c | |||
@@ -706,12 +706,13 @@ static void tty_reset_termios(struct tty_struct *tty) | |||
706 | /** | 706 | /** |
707 | * tty_ldisc_reinit - reinitialise the tty ldisc | 707 | * tty_ldisc_reinit - reinitialise the tty ldisc |
708 | * @tty: tty to reinit | 708 | * @tty: tty to reinit |
709 | * @ldisc: line discipline to reinitialize | ||
709 | * | 710 | * |
710 | * Switch the tty back to N_TTY line discipline and leave the | 711 | * Switch the tty to a line discipline and leave the ldisc |
711 | * ldisc state closed | 712 | * state closed |
712 | */ | 713 | */ |
713 | 714 | ||
714 | static void tty_ldisc_reinit(struct tty_struct *tty) | 715 | static void tty_ldisc_reinit(struct tty_struct *tty, int ldisc) |
715 | { | 716 | { |
716 | struct tty_ldisc *ld; | 717 | struct tty_ldisc *ld; |
717 | 718 | ||
@@ -721,10 +722,10 @@ static void tty_ldisc_reinit(struct tty_struct *tty) | |||
721 | /* | 722 | /* |
722 | * Switch the line discipline back | 723 | * Switch the line discipline back |
723 | */ | 724 | */ |
724 | ld = tty_ldisc_get(N_TTY); | 725 | ld = tty_ldisc_get(ldisc); |
725 | BUG_ON(IS_ERR(ld)); | 726 | BUG_ON(IS_ERR(ld)); |
726 | tty_ldisc_assign(tty, ld); | 727 | tty_ldisc_assign(tty, ld); |
727 | tty_set_termios_ldisc(tty, N_TTY); | 728 | tty_set_termios_ldisc(tty, ldisc); |
728 | } | 729 | } |
729 | 730 | ||
730 | /** | 731 | /** |
@@ -745,6 +746,8 @@ static void tty_ldisc_reinit(struct tty_struct *tty) | |||
745 | void tty_ldisc_hangup(struct tty_struct *tty) | 746 | void tty_ldisc_hangup(struct tty_struct *tty) |
746 | { | 747 | { |
747 | struct tty_ldisc *ld; | 748 | struct tty_ldisc *ld; |
749 | int reset = tty->driver->flags & TTY_DRIVER_RESET_TERMIOS; | ||
750 | int err = 0; | ||
748 | 751 | ||
749 | /* | 752 | /* |
750 | * FIXME! What are the locking issues here? This may me overdoing | 753 | * FIXME! What are the locking issues here? This may me overdoing |
@@ -772,25 +775,32 @@ void tty_ldisc_hangup(struct tty_struct *tty) | |||
772 | wake_up_interruptible_poll(&tty->read_wait, POLLIN); | 775 | wake_up_interruptible_poll(&tty->read_wait, POLLIN); |
773 | /* | 776 | /* |
774 | * Shutdown the current line discipline, and reset it to | 777 | * Shutdown the current line discipline, and reset it to |
775 | * N_TTY. | 778 | * N_TTY if need be. |
779 | * | ||
780 | * Avoid racing set_ldisc or tty_ldisc_release | ||
776 | */ | 781 | */ |
777 | if (tty->driver->flags & TTY_DRIVER_RESET_TERMIOS) { | 782 | mutex_lock(&tty->ldisc_mutex); |
778 | /* Avoid racing set_ldisc or tty_ldisc_release */ | 783 | tty_ldisc_halt(tty); |
779 | mutex_lock(&tty->ldisc_mutex); | 784 | /* At this point we have a closed ldisc and we want to |
780 | tty_ldisc_halt(tty); | 785 | reopen it. We could defer this to the next open but |
781 | if (tty->ldisc) { /* Not yet closed */ | 786 | it means auditing a lot of other paths so this is |
782 | /* Switch back to N_TTY */ | 787 | a FIXME */ |
783 | tty_ldisc_reinit(tty); | 788 | if (tty->ldisc) { /* Not yet closed */ |
784 | /* At this point we have a closed ldisc and we want to | 789 | if (reset == 0) { |
785 | reopen it. We could defer this to the next open but | 790 | tty_ldisc_reinit(tty, tty->termios->c_line); |
786 | it means auditing a lot of other paths so this is | 791 | err = tty_ldisc_open(tty, tty->ldisc); |
787 | a FIXME */ | 792 | } |
793 | /* If the re-open fails or we reset then go to N_TTY. The | ||
794 | N_TTY open cannot fail */ | ||
795 | if (reset || err) { | ||
796 | tty_ldisc_reinit(tty, N_TTY); | ||
788 | WARN_ON(tty_ldisc_open(tty, tty->ldisc)); | 797 | WARN_ON(tty_ldisc_open(tty, tty->ldisc)); |
789 | tty_ldisc_enable(tty); | ||
790 | } | 798 | } |
791 | mutex_unlock(&tty->ldisc_mutex); | 799 | tty_ldisc_enable(tty); |
792 | tty_reset_termios(tty); | ||
793 | } | 800 | } |
801 | mutex_unlock(&tty->ldisc_mutex); | ||
802 | if (reset) | ||
803 | tty_reset_termios(tty); | ||
794 | } | 804 | } |
795 | 805 | ||
796 | /** | 806 | /** |
diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c index a035ae39a359..213373b5f17f 100644 --- a/drivers/char/virtio_console.c +++ b/drivers/char/virtio_console.c | |||
@@ -1,18 +1,6 @@ | |||
1 | /*D:300 | 1 | /* |
2 | * The Guest console driver | 2 | * Copyright (C) 2006, 2007, 2009 Rusty Russell, IBM Corporation |
3 | * | 3 | * Copyright (C) 2009, 2010 Red Hat, Inc. |
4 | * Writing console drivers is one of the few remaining Dark Arts in Linux. | ||
5 | * Fortunately for us, the path of virtual consoles has been well-trodden by | ||
6 | * the PowerPC folks, who wrote "hvc_console.c" to generically support any | ||
7 | * virtual console. We use that infrastructure which only requires us to write | ||
8 | * the basic put_chars and get_chars functions and call the right register | ||
9 | * functions. | ||
10 | :*/ | ||
11 | |||
12 | /*M:002 The console can be flooded: while the Guest is processing input the | ||
13 | * Host can send more. Buffering in the Host could alleviate this, but it is a | ||
14 | * difficult problem in general. :*/ | ||
15 | /* Copyright (C) 2006, 2007 Rusty Russell, IBM Corporation | ||
16 | * | 4 | * |
17 | * This program is free software; you can redistribute it and/or modify | 5 | * This program is free software; you can redistribute it and/or modify |
18 | * it under the terms of the GNU General Public License as published by | 6 | * it under the terms of the GNU General Public License as published by |
@@ -28,142 +16,694 @@ | |||
28 | * along with this program; if not, write to the Free Software | 16 | * along with this program; if not, write to the Free Software |
29 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
30 | */ | 18 | */ |
19 | #include <linux/cdev.h> | ||
20 | #include <linux/debugfs.h> | ||
21 | #include <linux/device.h> | ||
31 | #include <linux/err.h> | 22 | #include <linux/err.h> |
23 | #include <linux/fs.h> | ||
32 | #include <linux/init.h> | 24 | #include <linux/init.h> |
25 | #include <linux/list.h> | ||
26 | #include <linux/poll.h> | ||
27 | #include <linux/sched.h> | ||
28 | #include <linux/spinlock.h> | ||
33 | #include <linux/virtio.h> | 29 | #include <linux/virtio.h> |
34 | #include <linux/virtio_console.h> | 30 | #include <linux/virtio_console.h> |
31 | #include <linux/wait.h> | ||
32 | #include <linux/workqueue.h> | ||
35 | #include "hvc_console.h" | 33 | #include "hvc_console.h" |
36 | 34 | ||
37 | /*D:340 These represent our input and output console queues, and the virtio | 35 | /* |
38 | * operations for them. */ | 36 | * This is a global struct for storing common data for all the devices |
39 | static struct virtqueue *in_vq, *out_vq; | 37 | * this driver handles. |
40 | static struct virtio_device *vdev; | 38 | * |
39 | * Mainly, it has a linked list for all the consoles in one place so | ||
40 | * that callbacks from hvc for get_chars(), put_chars() work properly | ||
41 | * across multiple devices and multiple ports per device. | ||
42 | */ | ||
43 | struct ports_driver_data { | ||
44 | /* Used for registering chardevs */ | ||
45 | struct class *class; | ||
46 | |||
47 | /* Used for exporting per-port information to debugfs */ | ||
48 | struct dentry *debugfs_dir; | ||
49 | |||
50 | /* Number of devices this driver is handling */ | ||
51 | unsigned int index; | ||
52 | |||
53 | /* | ||
54 | * This is used to keep track of the number of hvc consoles | ||
55 | * spawned by this driver. This number is given as the first | ||
56 | * argument to hvc_alloc(). To correctly map an initial | ||
57 | * console spawned via hvc_instantiate to the console being | ||
58 | * hooked up via hvc_alloc, we need to pass the same vtermno. | ||
59 | * | ||
60 | * We also just assume the first console being initialised was | ||
61 | * the first one that got used as the initial console. | ||
62 | */ | ||
63 | unsigned int next_vtermno; | ||
64 | |||
65 | /* All the console devices handled by this driver */ | ||
66 | struct list_head consoles; | ||
67 | }; | ||
68 | static struct ports_driver_data pdrvdata; | ||
69 | |||
70 | DEFINE_SPINLOCK(pdrvdata_lock); | ||
71 | |||
72 | /* This struct holds information that's relevant only for console ports */ | ||
73 | struct console { | ||
74 | /* We'll place all consoles in a list in the pdrvdata struct */ | ||
75 | struct list_head list; | ||
76 | |||
77 | /* The hvc device associated with this console port */ | ||
78 | struct hvc_struct *hvc; | ||
79 | |||
80 | /* | ||
81 | * This number identifies the number that we used to register | ||
82 | * with hvc in hvc_instantiate() and hvc_alloc(); this is the | ||
83 | * number passed on by the hvc callbacks to us to | ||
84 | * differentiate between the other console ports handled by | ||
85 | * this driver | ||
86 | */ | ||
87 | u32 vtermno; | ||
88 | }; | ||
89 | |||
90 | struct port_buffer { | ||
91 | char *buf; | ||
92 | |||
93 | /* size of the buffer in *buf above */ | ||
94 | size_t size; | ||
95 | |||
96 | /* used length of the buffer */ | ||
97 | size_t len; | ||
98 | /* offset in the buf from which to consume data */ | ||
99 | size_t offset; | ||
100 | }; | ||
101 | |||
102 | /* | ||
103 | * This is a per-device struct that stores data common to all the | ||
104 | * ports for that device (vdev->priv). | ||
105 | */ | ||
106 | struct ports_device { | ||
107 | /* | ||
108 | * Workqueue handlers where we process deferred work after | ||
109 | * notification | ||
110 | */ | ||
111 | struct work_struct control_work; | ||
112 | struct work_struct config_work; | ||
113 | |||
114 | struct list_head ports; | ||
115 | |||
116 | /* To protect the list of ports */ | ||
117 | spinlock_t ports_lock; | ||
118 | |||
119 | /* To protect the vq operations for the control channel */ | ||
120 | spinlock_t cvq_lock; | ||
121 | |||
122 | /* The current config space is stored here */ | ||
123 | struct virtio_console_config config; | ||
124 | |||
125 | /* The virtio device we're associated with */ | ||
126 | struct virtio_device *vdev; | ||
127 | |||
128 | /* | ||
129 | * A couple of virtqueues for the control channel: one for | ||
130 | * guest->host transfers, one for host->guest transfers | ||
131 | */ | ||
132 | struct virtqueue *c_ivq, *c_ovq; | ||
133 | |||
134 | /* Array of per-port IO virtqueues */ | ||
135 | struct virtqueue **in_vqs, **out_vqs; | ||
136 | |||
137 | /* Used for numbering devices for sysfs and debugfs */ | ||
138 | unsigned int drv_index; | ||
139 | |||
140 | /* Major number for this device. Ports will be created as minors. */ | ||
141 | int chr_major; | ||
142 | }; | ||
143 | |||
144 | /* This struct holds the per-port data */ | ||
145 | struct port { | ||
146 | /* Next port in the list, head is in the ports_device */ | ||
147 | struct list_head list; | ||
148 | |||
149 | /* Pointer to the parent virtio_console device */ | ||
150 | struct ports_device *portdev; | ||
151 | |||
152 | /* The current buffer from which data has to be fed to readers */ | ||
153 | struct port_buffer *inbuf; | ||
154 | |||
155 | /* | ||
156 | * To protect the operations on the in_vq associated with this | ||
157 | * port. Has to be a spinlock because it can be called from | ||
158 | * interrupt context (get_char()). | ||
159 | */ | ||
160 | spinlock_t inbuf_lock; | ||
161 | |||
162 | /* The IO vqs for this port */ | ||
163 | struct virtqueue *in_vq, *out_vq; | ||
164 | |||
165 | /* File in the debugfs directory that exposes this port's information */ | ||
166 | struct dentry *debugfs_file; | ||
167 | |||
168 | /* | ||
169 | * The entries in this struct will be valid if this port is | ||
170 | * hooked up to an hvc console | ||
171 | */ | ||
172 | struct console cons; | ||
173 | |||
174 | /* Each port associates with a separate char device */ | ||
175 | struct cdev cdev; | ||
176 | struct device *dev; | ||
177 | |||
178 | /* A waitqueue for poll() or blocking read operations */ | ||
179 | wait_queue_head_t waitqueue; | ||
180 | |||
181 | /* The 'name' of the port that we expose via sysfs properties */ | ||
182 | char *name; | ||
183 | |||
184 | /* The 'id' to identify the port with the Host */ | ||
185 | u32 id; | ||
186 | |||
187 | /* Is the host device open */ | ||
188 | bool host_connected; | ||
189 | |||
190 | /* We should allow only one process to open a port */ | ||
191 | bool guest_connected; | ||
192 | }; | ||
193 | |||
194 | /* This is the very early arch-specified put chars function. */ | ||
195 | static int (*early_put_chars)(u32, const char *, int); | ||
196 | |||
197 | static struct port *find_port_by_vtermno(u32 vtermno) | ||
198 | { | ||
199 | struct port *port; | ||
200 | struct console *cons; | ||
201 | unsigned long flags; | ||
202 | |||
203 | spin_lock_irqsave(&pdrvdata_lock, flags); | ||
204 | list_for_each_entry(cons, &pdrvdata.consoles, list) { | ||
205 | if (cons->vtermno == vtermno) { | ||
206 | port = container_of(cons, struct port, cons); | ||
207 | goto out; | ||
208 | } | ||
209 | } | ||
210 | port = NULL; | ||
211 | out: | ||
212 | spin_unlock_irqrestore(&pdrvdata_lock, flags); | ||
213 | return port; | ||
214 | } | ||
215 | |||
216 | static struct port *find_port_by_id(struct ports_device *portdev, u32 id) | ||
217 | { | ||
218 | struct port *port; | ||
219 | unsigned long flags; | ||
220 | |||
221 | spin_lock_irqsave(&portdev->ports_lock, flags); | ||
222 | list_for_each_entry(port, &portdev->ports, list) | ||
223 | if (port->id == id) | ||
224 | goto out; | ||
225 | port = NULL; | ||
226 | out: | ||
227 | spin_unlock_irqrestore(&portdev->ports_lock, flags); | ||
228 | |||
229 | return port; | ||
230 | } | ||
231 | |||
232 | static struct port *find_port_by_vq(struct ports_device *portdev, | ||
233 | struct virtqueue *vq) | ||
234 | { | ||
235 | struct port *port; | ||
236 | unsigned long flags; | ||
237 | |||
238 | spin_lock_irqsave(&portdev->ports_lock, flags); | ||
239 | list_for_each_entry(port, &portdev->ports, list) | ||
240 | if (port->in_vq == vq || port->out_vq == vq) | ||
241 | goto out; | ||
242 | port = NULL; | ||
243 | out: | ||
244 | spin_unlock_irqrestore(&portdev->ports_lock, flags); | ||
245 | return port; | ||
246 | } | ||
247 | |||
248 | static bool is_console_port(struct port *port) | ||
249 | { | ||
250 | if (port->cons.hvc) | ||
251 | return true; | ||
252 | return false; | ||
253 | } | ||
254 | |||
255 | static inline bool use_multiport(struct ports_device *portdev) | ||
256 | { | ||
257 | /* | ||
258 | * This condition can be true when put_chars is called from | ||
259 | * early_init | ||
260 | */ | ||
261 | if (!portdev->vdev) | ||
262 | return 0; | ||
263 | return portdev->vdev->features[0] & (1 << VIRTIO_CONSOLE_F_MULTIPORT); | ||
264 | } | ||
41 | 265 | ||
42 | /* This is our input buffer, and how much data is left in it. */ | 266 | static void free_buf(struct port_buffer *buf) |
43 | static unsigned int in_len; | 267 | { |
44 | static char *in, *inbuf; | 268 | kfree(buf->buf); |
269 | kfree(buf); | ||
270 | } | ||
271 | |||
272 | static struct port_buffer *alloc_buf(size_t buf_size) | ||
273 | { | ||
274 | struct port_buffer *buf; | ||
45 | 275 | ||
46 | /* The operations for our console. */ | 276 | buf = kmalloc(sizeof(*buf), GFP_KERNEL); |
47 | static struct hv_ops virtio_cons; | 277 | if (!buf) |
278 | goto fail; | ||
279 | buf->buf = kzalloc(buf_size, GFP_KERNEL); | ||
280 | if (!buf->buf) | ||
281 | goto free_buf; | ||
282 | buf->len = 0; | ||
283 | buf->offset = 0; | ||
284 | buf->size = buf_size; | ||
285 | return buf; | ||
286 | |||
287 | free_buf: | ||
288 | kfree(buf); | ||
289 | fail: | ||
290 | return NULL; | ||
291 | } | ||
292 | |||
293 | /* Callers should take appropriate locks */ | ||
294 | static void *get_inbuf(struct port *port) | ||
295 | { | ||
296 | struct port_buffer *buf; | ||
297 | struct virtqueue *vq; | ||
298 | unsigned int len; | ||
48 | 299 | ||
49 | /* The hvc device */ | 300 | vq = port->in_vq; |
50 | static struct hvc_struct *hvc; | 301 | buf = vq->vq_ops->get_buf(vq, &len); |
302 | if (buf) { | ||
303 | buf->len = len; | ||
304 | buf->offset = 0; | ||
305 | } | ||
306 | return buf; | ||
307 | } | ||
51 | 308 | ||
52 | /*D:310 The put_chars() callback is pretty straightforward. | 309 | /* |
310 | * Create a scatter-gather list representing our input buffer and put | ||
311 | * it in the queue. | ||
53 | * | 312 | * |
54 | * We turn the characters into a scatter-gather list, add it to the output | 313 | * Callers should take appropriate locks. |
55 | * queue and then kick the Host. Then we sit here waiting for it to finish: | 314 | */ |
56 | * inefficient in theory, but in practice implementations will do it | 315 | static int add_inbuf(struct virtqueue *vq, struct port_buffer *buf) |
57 | * immediately (lguest's Launcher does). */ | ||
58 | static int put_chars(u32 vtermno, const char *buf, int count) | ||
59 | { | 316 | { |
60 | struct scatterlist sg[1]; | 317 | struct scatterlist sg[1]; |
318 | int ret; | ||
319 | |||
320 | sg_init_one(sg, buf->buf, buf->size); | ||
321 | |||
322 | ret = vq->vq_ops->add_buf(vq, sg, 0, 1, buf); | ||
323 | vq->vq_ops->kick(vq); | ||
324 | return ret; | ||
325 | } | ||
326 | |||
327 | /* Discard any unread data this port has. Callers lockers. */ | ||
328 | static void discard_port_data(struct port *port) | ||
329 | { | ||
330 | struct port_buffer *buf; | ||
331 | struct virtqueue *vq; | ||
61 | unsigned int len; | 332 | unsigned int len; |
333 | int ret; | ||
62 | 334 | ||
63 | /* This is a convenient routine to initialize a single-elem sg list */ | 335 | vq = port->in_vq; |
64 | sg_init_one(sg, buf, count); | 336 | if (port->inbuf) |
337 | buf = port->inbuf; | ||
338 | else | ||
339 | buf = vq->vq_ops->get_buf(vq, &len); | ||
65 | 340 | ||
66 | /* add_buf wants a token to identify this buffer: we hand it any | 341 | ret = 0; |
67 | * non-NULL pointer, since there's only ever one buffer. */ | 342 | while (buf) { |
68 | if (out_vq->vq_ops->add_buf(out_vq, sg, 1, 0, (void *)1) >= 0) { | 343 | if (add_inbuf(vq, buf) < 0) { |
69 | /* Tell Host to go! */ | 344 | ret++; |
70 | out_vq->vq_ops->kick(out_vq); | 345 | free_buf(buf); |
71 | /* Chill out until it's done with the buffer. */ | 346 | } |
72 | while (!out_vq->vq_ops->get_buf(out_vq, &len)) | 347 | buf = vq->vq_ops->get_buf(vq, &len); |
73 | cpu_relax(); | ||
74 | } | 348 | } |
349 | port->inbuf = NULL; | ||
350 | if (ret) | ||
351 | dev_warn(port->dev, "Errors adding %d buffers back to vq\n", | ||
352 | ret); | ||
353 | } | ||
75 | 354 | ||
76 | /* We're expected to return the amount of data we wrote: all of it. */ | 355 | static bool port_has_data(struct port *port) |
77 | return count; | 356 | { |
357 | unsigned long flags; | ||
358 | bool ret; | ||
359 | |||
360 | spin_lock_irqsave(&port->inbuf_lock, flags); | ||
361 | if (port->inbuf) { | ||
362 | ret = true; | ||
363 | goto out; | ||
364 | } | ||
365 | port->inbuf = get_inbuf(port); | ||
366 | if (port->inbuf) { | ||
367 | ret = true; | ||
368 | goto out; | ||
369 | } | ||
370 | ret = false; | ||
371 | out: | ||
372 | spin_unlock_irqrestore(&port->inbuf_lock, flags); | ||
373 | return ret; | ||
78 | } | 374 | } |
79 | 375 | ||
80 | /* Create a scatter-gather list representing our input buffer and put it in the | 376 | static ssize_t send_control_msg(struct port *port, unsigned int event, |
81 | * queue. */ | 377 | unsigned int value) |
82 | static void add_inbuf(void) | ||
83 | { | 378 | { |
84 | struct scatterlist sg[1]; | 379 | struct scatterlist sg[1]; |
85 | sg_init_one(sg, inbuf, PAGE_SIZE); | 380 | struct virtio_console_control cpkt; |
381 | struct virtqueue *vq; | ||
382 | int len; | ||
383 | |||
384 | if (!use_multiport(port->portdev)) | ||
385 | return 0; | ||
386 | |||
387 | cpkt.id = port->id; | ||
388 | cpkt.event = event; | ||
389 | cpkt.value = value; | ||
390 | |||
391 | vq = port->portdev->c_ovq; | ||
86 | 392 | ||
87 | /* We should always be able to add one buffer to an empty queue. */ | 393 | sg_init_one(sg, &cpkt, sizeof(cpkt)); |
88 | if (in_vq->vq_ops->add_buf(in_vq, sg, 0, 1, inbuf) < 0) | 394 | if (vq->vq_ops->add_buf(vq, sg, 1, 0, &cpkt) >= 0) { |
89 | BUG(); | 395 | vq->vq_ops->kick(vq); |
90 | in_vq->vq_ops->kick(in_vq); | 396 | while (!vq->vq_ops->get_buf(vq, &len)) |
397 | cpu_relax(); | ||
398 | } | ||
399 | return 0; | ||
91 | } | 400 | } |
92 | 401 | ||
93 | /*D:350 get_chars() is the callback from the hvc_console infrastructure when | 402 | static ssize_t send_buf(struct port *port, void *in_buf, size_t in_count) |
94 | * an interrupt is received. | ||
95 | * | ||
96 | * Most of the code deals with the fact that the hvc_console() infrastructure | ||
97 | * only asks us for 16 bytes at a time. We keep in_offset and in_used fields | ||
98 | * for partially-filled buffers. */ | ||
99 | static int get_chars(u32 vtermno, char *buf, int count) | ||
100 | { | 403 | { |
101 | /* If we don't have an input queue yet, we can't get input. */ | 404 | struct scatterlist sg[1]; |
102 | BUG_ON(!in_vq); | 405 | struct virtqueue *out_vq; |
406 | ssize_t ret; | ||
407 | unsigned int len; | ||
408 | |||
409 | out_vq = port->out_vq; | ||
410 | |||
411 | sg_init_one(sg, in_buf, in_count); | ||
412 | ret = out_vq->vq_ops->add_buf(out_vq, sg, 1, 0, in_buf); | ||
413 | |||
414 | /* Tell Host to go! */ | ||
415 | out_vq->vq_ops->kick(out_vq); | ||
416 | |||
417 | if (ret < 0) { | ||
418 | len = 0; | ||
419 | goto fail; | ||
420 | } | ||
421 | |||
422 | /* | ||
423 | * Wait till the host acknowledges it pushed out the data we | ||
424 | * sent. Also ensure we return to userspace the number of | ||
425 | * bytes that were successfully consumed by the host. | ||
426 | */ | ||
427 | while (!out_vq->vq_ops->get_buf(out_vq, &len)) | ||
428 | cpu_relax(); | ||
429 | fail: | ||
430 | /* We're expected to return the amount of data we wrote */ | ||
431 | return len; | ||
432 | } | ||
433 | |||
434 | /* | ||
435 | * Give out the data that's requested from the buffer that we have | ||
436 | * queued up. | ||
437 | */ | ||
438 | static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count, | ||
439 | bool to_user) | ||
440 | { | ||
441 | struct port_buffer *buf; | ||
442 | unsigned long flags; | ||
443 | |||
444 | if (!out_count || !port_has_data(port)) | ||
445 | return 0; | ||
446 | |||
447 | buf = port->inbuf; | ||
448 | out_count = min(out_count, buf->len - buf->offset); | ||
449 | |||
450 | if (to_user) { | ||
451 | ssize_t ret; | ||
452 | |||
453 | ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count); | ||
454 | if (ret) | ||
455 | return -EFAULT; | ||
456 | } else { | ||
457 | memcpy(out_buf, buf->buf + buf->offset, out_count); | ||
458 | } | ||
459 | |||
460 | buf->offset += out_count; | ||
461 | |||
462 | if (buf->offset == buf->len) { | ||
463 | /* | ||
464 | * We're done using all the data in this buffer. | ||
465 | * Re-queue so that the Host can send us more data. | ||
466 | */ | ||
467 | spin_lock_irqsave(&port->inbuf_lock, flags); | ||
468 | port->inbuf = NULL; | ||
469 | |||
470 | if (add_inbuf(port->in_vq, buf) < 0) | ||
471 | dev_warn(port->dev, "failed add_buf\n"); | ||
472 | |||
473 | spin_unlock_irqrestore(&port->inbuf_lock, flags); | ||
474 | } | ||
475 | /* Return the number of bytes actually copied */ | ||
476 | return out_count; | ||
477 | } | ||
103 | 478 | ||
104 | /* No buffer? Try to get one. */ | 479 | /* The condition that must be true for polling to end */ |
105 | if (!in_len) { | 480 | static bool wait_is_over(struct port *port) |
106 | in = in_vq->vq_ops->get_buf(in_vq, &in_len); | 481 | { |
107 | if (!in) | 482 | return port_has_data(port) || !port->host_connected; |
483 | } | ||
484 | |||
485 | static ssize_t port_fops_read(struct file *filp, char __user *ubuf, | ||
486 | size_t count, loff_t *offp) | ||
487 | { | ||
488 | struct port *port; | ||
489 | ssize_t ret; | ||
490 | |||
491 | port = filp->private_data; | ||
492 | |||
493 | if (!port_has_data(port)) { | ||
494 | /* | ||
495 | * If nothing's connected on the host just return 0 in | ||
496 | * case of list_empty; this tells the userspace app | ||
497 | * that there's no connection | ||
498 | */ | ||
499 | if (!port->host_connected) | ||
108 | return 0; | 500 | return 0; |
501 | if (filp->f_flags & O_NONBLOCK) | ||
502 | return -EAGAIN; | ||
503 | |||
504 | ret = wait_event_interruptible(port->waitqueue, | ||
505 | wait_is_over(port)); | ||
506 | if (ret < 0) | ||
507 | return ret; | ||
508 | } | ||
509 | /* | ||
510 | * We could've received a disconnection message while we were | ||
511 | * waiting for more data. | ||
512 | * | ||
513 | * This check is not clubbed in the if() statement above as we | ||
514 | * might receive some data as well as the host could get | ||
515 | * disconnected after we got woken up from our wait. So we | ||
516 | * really want to give off whatever data we have and only then | ||
517 | * check for host_connected. | ||
518 | */ | ||
519 | if (!port_has_data(port) && !port->host_connected) | ||
520 | return 0; | ||
521 | |||
522 | return fill_readbuf(port, ubuf, count, true); | ||
523 | } | ||
524 | |||
525 | static ssize_t port_fops_write(struct file *filp, const char __user *ubuf, | ||
526 | size_t count, loff_t *offp) | ||
527 | { | ||
528 | struct port *port; | ||
529 | char *buf; | ||
530 | ssize_t ret; | ||
531 | |||
532 | port = filp->private_data; | ||
533 | |||
534 | count = min((size_t)(32 * 1024), count); | ||
535 | |||
536 | buf = kmalloc(count, GFP_KERNEL); | ||
537 | if (!buf) | ||
538 | return -ENOMEM; | ||
539 | |||
540 | ret = copy_from_user(buf, ubuf, count); | ||
541 | if (ret) { | ||
542 | ret = -EFAULT; | ||
543 | goto free_buf; | ||
109 | } | 544 | } |
110 | 545 | ||
111 | /* You want more than we have to give? Well, try wanting less! */ | 546 | ret = send_buf(port, buf, count); |
112 | if (in_len < count) | 547 | free_buf: |
113 | count = in_len; | 548 | kfree(buf); |
549 | return ret; | ||
550 | } | ||
551 | |||
552 | static unsigned int port_fops_poll(struct file *filp, poll_table *wait) | ||
553 | { | ||
554 | struct port *port; | ||
555 | unsigned int ret; | ||
556 | |||
557 | port = filp->private_data; | ||
558 | poll_wait(filp, &port->waitqueue, wait); | ||
559 | |||
560 | ret = 0; | ||
561 | if (port->inbuf) | ||
562 | ret |= POLLIN | POLLRDNORM; | ||
563 | if (port->host_connected) | ||
564 | ret |= POLLOUT; | ||
565 | if (!port->host_connected) | ||
566 | ret |= POLLHUP; | ||
567 | |||
568 | return ret; | ||
569 | } | ||
570 | |||
571 | static int port_fops_release(struct inode *inode, struct file *filp) | ||
572 | { | ||
573 | struct port *port; | ||
574 | |||
575 | port = filp->private_data; | ||
576 | |||
577 | /* Notify host of port being closed */ | ||
578 | send_control_msg(port, VIRTIO_CONSOLE_PORT_OPEN, 0); | ||
579 | |||
580 | spin_lock_irq(&port->inbuf_lock); | ||
581 | port->guest_connected = false; | ||
582 | |||
583 | discard_port_data(port); | ||
584 | |||
585 | spin_unlock_irq(&port->inbuf_lock); | ||
586 | |||
587 | return 0; | ||
588 | } | ||
589 | |||
590 | static int port_fops_open(struct inode *inode, struct file *filp) | ||
591 | { | ||
592 | struct cdev *cdev = inode->i_cdev; | ||
593 | struct port *port; | ||
594 | |||
595 | port = container_of(cdev, struct port, cdev); | ||
596 | filp->private_data = port; | ||
597 | |||
598 | /* | ||
599 | * Don't allow opening of console port devices -- that's done | ||
600 | * via /dev/hvc | ||
601 | */ | ||
602 | if (is_console_port(port)) | ||
603 | return -ENXIO; | ||
604 | |||
605 | /* Allow only one process to open a particular port at a time */ | ||
606 | spin_lock_irq(&port->inbuf_lock); | ||
607 | if (port->guest_connected) { | ||
608 | spin_unlock_irq(&port->inbuf_lock); | ||
609 | return -EMFILE; | ||
610 | } | ||
114 | 611 | ||
115 | /* Copy across to their buffer and increment offset. */ | 612 | port->guest_connected = true; |
116 | memcpy(buf, in, count); | 613 | spin_unlock_irq(&port->inbuf_lock); |
117 | in += count; | ||
118 | in_len -= count; | ||
119 | 614 | ||
120 | /* Finished? Re-register buffer so Host will use it again. */ | 615 | /* Notify host of port being opened */ |
121 | if (in_len == 0) | 616 | send_control_msg(filp->private_data, VIRTIO_CONSOLE_PORT_OPEN, 1); |
122 | add_inbuf(); | ||
123 | 617 | ||
124 | return count; | 618 | return 0; |
125 | } | 619 | } |
126 | /*:*/ | ||
127 | 620 | ||
128 | /*D:320 Console drivers are initialized very early so boot messages can go out, | 621 | /* |
129 | * so we do things slightly differently from the generic virtio initialization | 622 | * The file operations that we support: programs in the guest can open |
130 | * of the net and block drivers. | 623 | * a console device, read from it, write to it, poll for data and |
624 | * close it. The devices are at | ||
625 | * /dev/vport<device number>p<port number> | ||
626 | */ | ||
627 | static const struct file_operations port_fops = { | ||
628 | .owner = THIS_MODULE, | ||
629 | .open = port_fops_open, | ||
630 | .read = port_fops_read, | ||
631 | .write = port_fops_write, | ||
632 | .poll = port_fops_poll, | ||
633 | .release = port_fops_release, | ||
634 | }; | ||
635 | |||
636 | /* | ||
637 | * The put_chars() callback is pretty straightforward. | ||
131 | * | 638 | * |
132 | * At this stage, the console is output-only. It's too early to set up a | 639 | * We turn the characters into a scatter-gather list, add it to the |
133 | * virtqueue, so we let the drivers do some boutique early-output thing. */ | 640 | * output queue and then kick the Host. Then we sit here waiting for |
134 | int __init virtio_cons_early_init(int (*put_chars)(u32, const char *, int)) | 641 | * it to finish: inefficient in theory, but in practice |
642 | * implementations will do it immediately (lguest's Launcher does). | ||
643 | */ | ||
644 | static int put_chars(u32 vtermno, const char *buf, int count) | ||
135 | { | 645 | { |
136 | virtio_cons.put_chars = put_chars; | 646 | struct port *port; |
137 | return hvc_instantiate(0, 0, &virtio_cons); | 647 | |
648 | port = find_port_by_vtermno(vtermno); | ||
649 | if (!port) | ||
650 | return 0; | ||
651 | |||
652 | if (unlikely(early_put_chars)) | ||
653 | return early_put_chars(vtermno, buf, count); | ||
654 | |||
655 | return send_buf(port, (void *)buf, count); | ||
138 | } | 656 | } |
139 | 657 | ||
140 | /* | 658 | /* |
141 | * virtio console configuration. This supports: | 659 | * get_chars() is the callback from the hvc_console infrastructure |
142 | * - console resize | 660 | * when an interrupt is received. |
661 | * | ||
662 | * We call out to fill_readbuf that gets us the required data from the | ||
663 | * buffers that are queued up. | ||
143 | */ | 664 | */ |
144 | static void virtcons_apply_config(struct virtio_device *dev) | 665 | static int get_chars(u32 vtermno, char *buf, int count) |
145 | { | 666 | { |
667 | struct port *port; | ||
668 | |||
669 | port = find_port_by_vtermno(vtermno); | ||
670 | if (!port) | ||
671 | return 0; | ||
672 | |||
673 | /* If we don't have an input queue yet, we can't get input. */ | ||
674 | BUG_ON(!port->in_vq); | ||
675 | |||
676 | return fill_readbuf(port, buf, count, false); | ||
677 | } | ||
678 | |||
679 | static void resize_console(struct port *port) | ||
680 | { | ||
681 | struct virtio_device *vdev; | ||
146 | struct winsize ws; | 682 | struct winsize ws; |
147 | 683 | ||
148 | if (virtio_has_feature(dev, VIRTIO_CONSOLE_F_SIZE)) { | 684 | vdev = port->portdev->vdev; |
149 | dev->config->get(dev, | 685 | if (virtio_has_feature(vdev, VIRTIO_CONSOLE_F_SIZE)) { |
150 | offsetof(struct virtio_console_config, cols), | 686 | vdev->config->get(vdev, |
151 | &ws.ws_col, sizeof(u16)); | 687 | offsetof(struct virtio_console_config, cols), |
152 | dev->config->get(dev, | 688 | &ws.ws_col, sizeof(u16)); |
153 | offsetof(struct virtio_console_config, rows), | 689 | vdev->config->get(vdev, |
154 | &ws.ws_row, sizeof(u16)); | 690 | offsetof(struct virtio_console_config, rows), |
155 | hvc_resize(hvc, ws); | 691 | &ws.ws_row, sizeof(u16)); |
692 | hvc_resize(port->cons.hvc, ws); | ||
156 | } | 693 | } |
157 | } | 694 | } |
158 | 695 | ||
159 | /* | 696 | /* We set the configuration at this point, since we now have a tty */ |
160 | * we support only one console, the hvc struct is a global var | ||
161 | * We set the configuration at this point, since we now have a tty | ||
162 | */ | ||
163 | static int notifier_add_vio(struct hvc_struct *hp, int data) | 697 | static int notifier_add_vio(struct hvc_struct *hp, int data) |
164 | { | 698 | { |
699 | struct port *port; | ||
700 | |||
701 | port = find_port_by_vtermno(hp->vtermno); | ||
702 | if (!port) | ||
703 | return -EINVAL; | ||
704 | |||
165 | hp->irq_requested = 1; | 705 | hp->irq_requested = 1; |
166 | virtcons_apply_config(vdev); | 706 | resize_console(port); |
167 | 707 | ||
168 | return 0; | 708 | return 0; |
169 | } | 709 | } |
@@ -173,79 +713,797 @@ static void notifier_del_vio(struct hvc_struct *hp, int data) | |||
173 | hp->irq_requested = 0; | 713 | hp->irq_requested = 0; |
174 | } | 714 | } |
175 | 715 | ||
176 | static void hvc_handle_input(struct virtqueue *vq) | 716 | /* The operations for console ports. */ |
717 | static const struct hv_ops hv_ops = { | ||
718 | .get_chars = get_chars, | ||
719 | .put_chars = put_chars, | ||
720 | .notifier_add = notifier_add_vio, | ||
721 | .notifier_del = notifier_del_vio, | ||
722 | .notifier_hangup = notifier_del_vio, | ||
723 | }; | ||
724 | |||
725 | /* | ||
726 | * Console drivers are initialized very early so boot messages can go | ||
727 | * out, so we do things slightly differently from the generic virtio | ||
728 | * initialization of the net and block drivers. | ||
729 | * | ||
730 | * At this stage, the console is output-only. It's too early to set | ||
731 | * up a virtqueue, so we let the drivers do some boutique early-output | ||
732 | * thing. | ||
733 | */ | ||
734 | int __init virtio_cons_early_init(int (*put_chars)(u32, const char *, int)) | ||
177 | { | 735 | { |
178 | if (hvc_poll(hvc)) | 736 | early_put_chars = put_chars; |
737 | return hvc_instantiate(0, 0, &hv_ops); | ||
738 | } | ||
739 | |||
740 | int init_port_console(struct port *port) | ||
741 | { | ||
742 | int ret; | ||
743 | |||
744 | /* | ||
745 | * The Host's telling us this port is a console port. Hook it | ||
746 | * up with an hvc console. | ||
747 | * | ||
748 | * To set up and manage our virtual console, we call | ||
749 | * hvc_alloc(). | ||
750 | * | ||
751 | * The first argument of hvc_alloc() is the virtual console | ||
752 | * number. The second argument is the parameter for the | ||
753 | * notification mechanism (like irq number). We currently | ||
754 | * leave this as zero, virtqueues have implicit notifications. | ||
755 | * | ||
756 | * The third argument is a "struct hv_ops" containing the | ||
757 | * put_chars() get_chars(), notifier_add() and notifier_del() | ||
758 | * pointers. The final argument is the output buffer size: we | ||
759 | * can do any size, so we put PAGE_SIZE here. | ||
760 | */ | ||
761 | port->cons.vtermno = pdrvdata.next_vtermno; | ||
762 | |||
763 | port->cons.hvc = hvc_alloc(port->cons.vtermno, 0, &hv_ops, PAGE_SIZE); | ||
764 | if (IS_ERR(port->cons.hvc)) { | ||
765 | ret = PTR_ERR(port->cons.hvc); | ||
766 | dev_err(port->dev, | ||
767 | "error %d allocating hvc for port\n", ret); | ||
768 | port->cons.hvc = NULL; | ||
769 | return ret; | ||
770 | } | ||
771 | spin_lock_irq(&pdrvdata_lock); | ||
772 | pdrvdata.next_vtermno++; | ||
773 | list_add_tail(&port->cons.list, &pdrvdata.consoles); | ||
774 | spin_unlock_irq(&pdrvdata_lock); | ||
775 | port->guest_connected = true; | ||
776 | |||
777 | /* Notify host of port being opened */ | ||
778 | send_control_msg(port, VIRTIO_CONSOLE_PORT_OPEN, 1); | ||
779 | |||
780 | return 0; | ||
781 | } | ||
782 | |||
783 | static ssize_t show_port_name(struct device *dev, | ||
784 | struct device_attribute *attr, char *buffer) | ||
785 | { | ||
786 | struct port *port; | ||
787 | |||
788 | port = dev_get_drvdata(dev); | ||
789 | |||
790 | return sprintf(buffer, "%s\n", port->name); | ||
791 | } | ||
792 | |||
793 | static DEVICE_ATTR(name, S_IRUGO, show_port_name, NULL); | ||
794 | |||
795 | static struct attribute *port_sysfs_entries[] = { | ||
796 | &dev_attr_name.attr, | ||
797 | NULL | ||
798 | }; | ||
799 | |||
800 | static struct attribute_group port_attribute_group = { | ||
801 | .name = NULL, /* put in device directory */ | ||
802 | .attrs = port_sysfs_entries, | ||
803 | }; | ||
804 | |||
805 | static int debugfs_open(struct inode *inode, struct file *filp) | ||
806 | { | ||
807 | filp->private_data = inode->i_private; | ||
808 | return 0; | ||
809 | } | ||
810 | |||
811 | static ssize_t debugfs_read(struct file *filp, char __user *ubuf, | ||
812 | size_t count, loff_t *offp) | ||
813 | { | ||
814 | struct port *port; | ||
815 | char *buf; | ||
816 | ssize_t ret, out_offset, out_count; | ||
817 | |||
818 | out_count = 1024; | ||
819 | buf = kmalloc(out_count, GFP_KERNEL); | ||
820 | if (!buf) | ||
821 | return -ENOMEM; | ||
822 | |||
823 | port = filp->private_data; | ||
824 | out_offset = 0; | ||
825 | out_offset += snprintf(buf + out_offset, out_count, | ||
826 | "name: %s\n", port->name ? port->name : ""); | ||
827 | out_offset += snprintf(buf + out_offset, out_count - out_offset, | ||
828 | "guest_connected: %d\n", port->guest_connected); | ||
829 | out_offset += snprintf(buf + out_offset, out_count - out_offset, | ||
830 | "host_connected: %d\n", port->host_connected); | ||
831 | out_offset += snprintf(buf + out_offset, out_count - out_offset, | ||
832 | "is_console: %s\n", | ||
833 | is_console_port(port) ? "yes" : "no"); | ||
834 | out_offset += snprintf(buf + out_offset, out_count - out_offset, | ||
835 | "console_vtermno: %u\n", port->cons.vtermno); | ||
836 | |||
837 | ret = simple_read_from_buffer(ubuf, count, offp, buf, out_offset); | ||
838 | kfree(buf); | ||
839 | return ret; | ||
840 | } | ||
841 | |||
842 | static const struct file_operations port_debugfs_ops = { | ||
843 | .owner = THIS_MODULE, | ||
844 | .open = debugfs_open, | ||
845 | .read = debugfs_read, | ||
846 | }; | ||
847 | |||
848 | /* Remove all port-specific data. */ | ||
849 | static int remove_port(struct port *port) | ||
850 | { | ||
851 | struct port_buffer *buf; | ||
852 | |||
853 | spin_lock_irq(&port->portdev->ports_lock); | ||
854 | list_del(&port->list); | ||
855 | spin_unlock_irq(&port->portdev->ports_lock); | ||
856 | |||
857 | if (is_console_port(port)) { | ||
858 | spin_lock_irq(&pdrvdata_lock); | ||
859 | list_del(&port->cons.list); | ||
860 | spin_unlock_irq(&pdrvdata_lock); | ||
861 | hvc_remove(port->cons.hvc); | ||
862 | } | ||
863 | if (port->guest_connected) | ||
864 | send_control_msg(port, VIRTIO_CONSOLE_PORT_OPEN, 0); | ||
865 | |||
866 | sysfs_remove_group(&port->dev->kobj, &port_attribute_group); | ||
867 | device_destroy(pdrvdata.class, port->dev->devt); | ||
868 | cdev_del(&port->cdev); | ||
869 | |||
870 | /* Remove unused data this port might have received. */ | ||
871 | discard_port_data(port); | ||
872 | |||
873 | /* Remove buffers we queued up for the Host to send us data in. */ | ||
874 | while ((buf = port->in_vq->vq_ops->detach_unused_buf(port->in_vq))) | ||
875 | free_buf(buf); | ||
876 | |||
877 | kfree(port->name); | ||
878 | |||
879 | debugfs_remove(port->debugfs_file); | ||
880 | |||
881 | kfree(port); | ||
882 | return 0; | ||
883 | } | ||
884 | |||
885 | /* Any private messages that the Host and Guest want to share */ | ||
886 | static void handle_control_message(struct ports_device *portdev, | ||
887 | struct port_buffer *buf) | ||
888 | { | ||
889 | struct virtio_console_control *cpkt; | ||
890 | struct port *port; | ||
891 | size_t name_size; | ||
892 | int err; | ||
893 | |||
894 | cpkt = (struct virtio_console_control *)(buf->buf + buf->offset); | ||
895 | |||
896 | port = find_port_by_id(portdev, cpkt->id); | ||
897 | if (!port) { | ||
898 | /* No valid header at start of buffer. Drop it. */ | ||
899 | dev_dbg(&portdev->vdev->dev, | ||
900 | "Invalid index %u in control packet\n", cpkt->id); | ||
901 | return; | ||
902 | } | ||
903 | |||
904 | switch (cpkt->event) { | ||
905 | case VIRTIO_CONSOLE_CONSOLE_PORT: | ||
906 | if (!cpkt->value) | ||
907 | break; | ||
908 | if (is_console_port(port)) | ||
909 | break; | ||
910 | |||
911 | init_port_console(port); | ||
912 | /* | ||
913 | * Could remove the port here in case init fails - but | ||
914 | * have to notify the host first. | ||
915 | */ | ||
916 | break; | ||
917 | case VIRTIO_CONSOLE_RESIZE: | ||
918 | if (!is_console_port(port)) | ||
919 | break; | ||
920 | port->cons.hvc->irq_requested = 1; | ||
921 | resize_console(port); | ||
922 | break; | ||
923 | case VIRTIO_CONSOLE_PORT_OPEN: | ||
924 | port->host_connected = cpkt->value; | ||
925 | wake_up_interruptible(&port->waitqueue); | ||
926 | break; | ||
927 | case VIRTIO_CONSOLE_PORT_NAME: | ||
928 | /* | ||
929 | * Skip the size of the header and the cpkt to get the size | ||
930 | * of the name that was sent | ||
931 | */ | ||
932 | name_size = buf->len - buf->offset - sizeof(*cpkt) + 1; | ||
933 | |||
934 | port->name = kmalloc(name_size, GFP_KERNEL); | ||
935 | if (!port->name) { | ||
936 | dev_err(port->dev, | ||
937 | "Not enough space to store port name\n"); | ||
938 | break; | ||
939 | } | ||
940 | strncpy(port->name, buf->buf + buf->offset + sizeof(*cpkt), | ||
941 | name_size - 1); | ||
942 | port->name[name_size - 1] = 0; | ||
943 | |||
944 | /* | ||
945 | * Since we only have one sysfs attribute, 'name', | ||
946 | * create it only if we have a name for the port. | ||
947 | */ | ||
948 | err = sysfs_create_group(&port->dev->kobj, | ||
949 | &port_attribute_group); | ||
950 | if (err) | ||
951 | dev_err(port->dev, | ||
952 | "Error %d creating sysfs device attributes\n", | ||
953 | err); | ||
954 | |||
955 | break; | ||
956 | case VIRTIO_CONSOLE_PORT_REMOVE: | ||
957 | /* | ||
958 | * Hot unplug the port. We don't decrement nr_ports | ||
959 | * since we don't want to deal with extra complexities | ||
960 | * of using the lowest-available port id: We can just | ||
961 | * pick up the nr_ports number as the id and not have | ||
962 | * userspace send it to us. This helps us in two | ||
963 | * ways: | ||
964 | * | ||
965 | * - We don't need to have a 'port_id' field in the | ||
966 | * config space when a port is hot-added. This is a | ||
967 | * good thing as we might queue up multiple hotplug | ||
968 | * requests issued in our workqueue. | ||
969 | * | ||
970 | * - Another way to deal with this would have been to | ||
971 | * use a bitmap of the active ports and select the | ||
972 | * lowest non-active port from that map. That | ||
973 | * bloats the already tight config space and we | ||
974 | * would end up artificially limiting the | ||
975 | * max. number of ports to sizeof(bitmap). Right | ||
976 | * now we can support 2^32 ports (as the port id is | ||
977 | * stored in a u32 type). | ||
978 | * | ||
979 | */ | ||
980 | remove_port(port); | ||
981 | break; | ||
982 | } | ||
983 | } | ||
984 | |||
985 | static void control_work_handler(struct work_struct *work) | ||
986 | { | ||
987 | struct ports_device *portdev; | ||
988 | struct virtqueue *vq; | ||
989 | struct port_buffer *buf; | ||
990 | unsigned int len; | ||
991 | |||
992 | portdev = container_of(work, struct ports_device, control_work); | ||
993 | vq = portdev->c_ivq; | ||
994 | |||
995 | spin_lock(&portdev->cvq_lock); | ||
996 | while ((buf = vq->vq_ops->get_buf(vq, &len))) { | ||
997 | spin_unlock(&portdev->cvq_lock); | ||
998 | |||
999 | buf->len = len; | ||
1000 | buf->offset = 0; | ||
1001 | |||
1002 | handle_control_message(portdev, buf); | ||
1003 | |||
1004 | spin_lock(&portdev->cvq_lock); | ||
1005 | if (add_inbuf(portdev->c_ivq, buf) < 0) { | ||
1006 | dev_warn(&portdev->vdev->dev, | ||
1007 | "Error adding buffer to queue\n"); | ||
1008 | free_buf(buf); | ||
1009 | } | ||
1010 | } | ||
1011 | spin_unlock(&portdev->cvq_lock); | ||
1012 | } | ||
1013 | |||
1014 | static void in_intr(struct virtqueue *vq) | ||
1015 | { | ||
1016 | struct port *port; | ||
1017 | unsigned long flags; | ||
1018 | |||
1019 | port = find_port_by_vq(vq->vdev->priv, vq); | ||
1020 | if (!port) | ||
1021 | return; | ||
1022 | |||
1023 | spin_lock_irqsave(&port->inbuf_lock, flags); | ||
1024 | if (!port->inbuf) | ||
1025 | port->inbuf = get_inbuf(port); | ||
1026 | |||
1027 | /* | ||
1028 | * Don't queue up data when port is closed. This condition | ||
1029 | * can be reached when a console port is not yet connected (no | ||
1030 | * tty is spawned) and the host sends out data to console | ||
1031 | * ports. For generic serial ports, the host won't | ||
1032 | * (shouldn't) send data till the guest is connected. | ||
1033 | */ | ||
1034 | if (!port->guest_connected) | ||
1035 | discard_port_data(port); | ||
1036 | |||
1037 | spin_unlock_irqrestore(&port->inbuf_lock, flags); | ||
1038 | |||
1039 | wake_up_interruptible(&port->waitqueue); | ||
1040 | |||
1041 | if (is_console_port(port) && hvc_poll(port->cons.hvc)) | ||
179 | hvc_kick(); | 1042 | hvc_kick(); |
180 | } | 1043 | } |
181 | 1044 | ||
182 | /*D:370 Once we're further in boot, we get probed like any other virtio device. | 1045 | static void control_intr(struct virtqueue *vq) |
183 | * At this stage we set up the output virtqueue. | 1046 | { |
184 | * | 1047 | struct ports_device *portdev; |
185 | * To set up and manage our virtual console, we call hvc_alloc(). Since we | 1048 | |
186 | * never remove the console device we never need this pointer again. | 1049 | portdev = vq->vdev->priv; |
1050 | schedule_work(&portdev->control_work); | ||
1051 | } | ||
1052 | |||
1053 | static void config_intr(struct virtio_device *vdev) | ||
1054 | { | ||
1055 | struct ports_device *portdev; | ||
1056 | |||
1057 | portdev = vdev->priv; | ||
1058 | if (use_multiport(portdev)) { | ||
1059 | /* Handle port hot-add */ | ||
1060 | schedule_work(&portdev->config_work); | ||
1061 | } | ||
1062 | /* | ||
1063 | * We'll use this way of resizing only for legacy support. | ||
1064 | * For newer userspace (VIRTIO_CONSOLE_F_MULTPORT+), use | ||
1065 | * control messages to indicate console size changes so that | ||
1066 | * it can be done per-port | ||
1067 | */ | ||
1068 | resize_console(find_port_by_id(portdev, 0)); | ||
1069 | } | ||
1070 | |||
1071 | static unsigned int fill_queue(struct virtqueue *vq, spinlock_t *lock) | ||
1072 | { | ||
1073 | struct port_buffer *buf; | ||
1074 | unsigned int ret; | ||
1075 | int err; | ||
1076 | |||
1077 | ret = 0; | ||
1078 | do { | ||
1079 | buf = alloc_buf(PAGE_SIZE); | ||
1080 | if (!buf) | ||
1081 | break; | ||
1082 | |||
1083 | spin_lock_irq(lock); | ||
1084 | err = add_inbuf(vq, buf); | ||
1085 | if (err < 0) { | ||
1086 | spin_unlock_irq(lock); | ||
1087 | free_buf(buf); | ||
1088 | break; | ||
1089 | } | ||
1090 | ret++; | ||
1091 | spin_unlock_irq(lock); | ||
1092 | } while (err > 0); | ||
1093 | |||
1094 | return ret; | ||
1095 | } | ||
1096 | |||
1097 | static int add_port(struct ports_device *portdev, u32 id) | ||
1098 | { | ||
1099 | char debugfs_name[16]; | ||
1100 | struct port *port; | ||
1101 | struct port_buffer *buf; | ||
1102 | dev_t devt; | ||
1103 | int err; | ||
1104 | |||
1105 | port = kmalloc(sizeof(*port), GFP_KERNEL); | ||
1106 | if (!port) { | ||
1107 | err = -ENOMEM; | ||
1108 | goto fail; | ||
1109 | } | ||
1110 | |||
1111 | port->portdev = portdev; | ||
1112 | port->id = id; | ||
1113 | |||
1114 | port->name = NULL; | ||
1115 | port->inbuf = NULL; | ||
1116 | port->cons.hvc = NULL; | ||
1117 | |||
1118 | port->host_connected = port->guest_connected = false; | ||
1119 | |||
1120 | port->in_vq = portdev->in_vqs[port->id]; | ||
1121 | port->out_vq = portdev->out_vqs[port->id]; | ||
1122 | |||
1123 | cdev_init(&port->cdev, &port_fops); | ||
1124 | |||
1125 | devt = MKDEV(portdev->chr_major, id); | ||
1126 | err = cdev_add(&port->cdev, devt, 1); | ||
1127 | if (err < 0) { | ||
1128 | dev_err(&port->portdev->vdev->dev, | ||
1129 | "Error %d adding cdev for port %u\n", err, id); | ||
1130 | goto free_port; | ||
1131 | } | ||
1132 | port->dev = device_create(pdrvdata.class, &port->portdev->vdev->dev, | ||
1133 | devt, port, "vport%up%u", | ||
1134 | port->portdev->drv_index, id); | ||
1135 | if (IS_ERR(port->dev)) { | ||
1136 | err = PTR_ERR(port->dev); | ||
1137 | dev_err(&port->portdev->vdev->dev, | ||
1138 | "Error %d creating device for port %u\n", | ||
1139 | err, id); | ||
1140 | goto free_cdev; | ||
1141 | } | ||
1142 | |||
1143 | spin_lock_init(&port->inbuf_lock); | ||
1144 | init_waitqueue_head(&port->waitqueue); | ||
1145 | |||
1146 | /* Fill the in_vq with buffers so the host can send us data. */ | ||
1147 | err = fill_queue(port->in_vq, &port->inbuf_lock); | ||
1148 | if (!err) { | ||
1149 | dev_err(port->dev, "Error allocating inbufs\n"); | ||
1150 | err = -ENOMEM; | ||
1151 | goto free_device; | ||
1152 | } | ||
1153 | |||
1154 | /* | ||
1155 | * If we're not using multiport support, this has to be a console port | ||
1156 | */ | ||
1157 | if (!use_multiport(port->portdev)) { | ||
1158 | err = init_port_console(port); | ||
1159 | if (err) | ||
1160 | goto free_inbufs; | ||
1161 | } | ||
1162 | |||
1163 | spin_lock_irq(&portdev->ports_lock); | ||
1164 | list_add_tail(&port->list, &port->portdev->ports); | ||
1165 | spin_unlock_irq(&portdev->ports_lock); | ||
1166 | |||
1167 | /* | ||
1168 | * Tell the Host we're set so that it can send us various | ||
1169 | * configuration parameters for this port (eg, port name, | ||
1170 | * caching, whether this is a console port, etc.) | ||
1171 | */ | ||
1172 | send_control_msg(port, VIRTIO_CONSOLE_PORT_READY, 1); | ||
1173 | |||
1174 | if (pdrvdata.debugfs_dir) { | ||
1175 | /* | ||
1176 | * Finally, create the debugfs file that we can use to | ||
1177 | * inspect a port's state at any time | ||
1178 | */ | ||
1179 | sprintf(debugfs_name, "vport%up%u", | ||
1180 | port->portdev->drv_index, id); | ||
1181 | port->debugfs_file = debugfs_create_file(debugfs_name, 0444, | ||
1182 | pdrvdata.debugfs_dir, | ||
1183 | port, | ||
1184 | &port_debugfs_ops); | ||
1185 | } | ||
1186 | return 0; | ||
1187 | |||
1188 | free_inbufs: | ||
1189 | while ((buf = port->in_vq->vq_ops->detach_unused_buf(port->in_vq))) | ||
1190 | free_buf(buf); | ||
1191 | free_device: | ||
1192 | device_destroy(pdrvdata.class, port->dev->devt); | ||
1193 | free_cdev: | ||
1194 | cdev_del(&port->cdev); | ||
1195 | free_port: | ||
1196 | kfree(port); | ||
1197 | fail: | ||
1198 | return err; | ||
1199 | } | ||
1200 | |||
1201 | /* | ||
1202 | * The workhandler for config-space updates. | ||
187 | * | 1203 | * |
188 | * Finally we put our input buffer in the input queue, ready to receive. */ | 1204 | * This is called when ports are hot-added. |
189 | static int __devinit virtcons_probe(struct virtio_device *dev) | 1205 | */ |
1206 | static void config_work_handler(struct work_struct *work) | ||
1207 | { | ||
1208 | struct virtio_console_config virtconconf; | ||
1209 | struct ports_device *portdev; | ||
1210 | struct virtio_device *vdev; | ||
1211 | int err; | ||
1212 | |||
1213 | portdev = container_of(work, struct ports_device, config_work); | ||
1214 | |||
1215 | vdev = portdev->vdev; | ||
1216 | vdev->config->get(vdev, | ||
1217 | offsetof(struct virtio_console_config, nr_ports), | ||
1218 | &virtconconf.nr_ports, | ||
1219 | sizeof(virtconconf.nr_ports)); | ||
1220 | |||
1221 | if (portdev->config.nr_ports == virtconconf.nr_ports) { | ||
1222 | /* | ||
1223 | * Port 0 got hot-added. Since we already did all the | ||
1224 | * other initialisation for it, just tell the Host | ||
1225 | * that the port is ready if we find the port. In | ||
1226 | * case the port was hot-removed earlier, we call | ||
1227 | * add_port to add the port. | ||
1228 | */ | ||
1229 | struct port *port; | ||
1230 | |||
1231 | port = find_port_by_id(portdev, 0); | ||
1232 | if (!port) | ||
1233 | add_port(portdev, 0); | ||
1234 | else | ||
1235 | send_control_msg(port, VIRTIO_CONSOLE_PORT_READY, 1); | ||
1236 | return; | ||
1237 | } | ||
1238 | if (virtconconf.nr_ports > portdev->config.max_nr_ports) { | ||
1239 | dev_warn(&vdev->dev, | ||
1240 | "More ports specified (%u) than allowed (%u)", | ||
1241 | portdev->config.nr_ports + 1, | ||
1242 | portdev->config.max_nr_ports); | ||
1243 | return; | ||
1244 | } | ||
1245 | if (virtconconf.nr_ports < portdev->config.nr_ports) | ||
1246 | return; | ||
1247 | |||
1248 | /* Hot-add ports */ | ||
1249 | while (virtconconf.nr_ports - portdev->config.nr_ports) { | ||
1250 | err = add_port(portdev, portdev->config.nr_ports); | ||
1251 | if (err) | ||
1252 | break; | ||
1253 | portdev->config.nr_ports++; | ||
1254 | } | ||
1255 | } | ||
1256 | |||
1257 | static int init_vqs(struct ports_device *portdev) | ||
190 | { | 1258 | { |
191 | vq_callback_t *callbacks[] = { hvc_handle_input, NULL}; | 1259 | vq_callback_t **io_callbacks; |
192 | const char *names[] = { "input", "output" }; | 1260 | char **io_names; |
193 | struct virtqueue *vqs[2]; | 1261 | struct virtqueue **vqs; |
1262 | u32 i, j, nr_ports, nr_queues; | ||
194 | int err; | 1263 | int err; |
195 | 1264 | ||
196 | vdev = dev; | 1265 | nr_ports = portdev->config.max_nr_ports; |
1266 | nr_queues = use_multiport(portdev) ? (nr_ports + 1) * 2 : 2; | ||
197 | 1267 | ||
198 | /* This is the scratch page we use to receive console input */ | 1268 | vqs = kmalloc(nr_queues * sizeof(struct virtqueue *), GFP_KERNEL); |
199 | inbuf = kmalloc(PAGE_SIZE, GFP_KERNEL); | 1269 | if (!vqs) { |
200 | if (!inbuf) { | ||
201 | err = -ENOMEM; | 1270 | err = -ENOMEM; |
202 | goto fail; | 1271 | goto fail; |
203 | } | 1272 | } |
1273 | io_callbacks = kmalloc(nr_queues * sizeof(vq_callback_t *), GFP_KERNEL); | ||
1274 | if (!io_callbacks) { | ||
1275 | err = -ENOMEM; | ||
1276 | goto free_vqs; | ||
1277 | } | ||
1278 | io_names = kmalloc(nr_queues * sizeof(char *), GFP_KERNEL); | ||
1279 | if (!io_names) { | ||
1280 | err = -ENOMEM; | ||
1281 | goto free_callbacks; | ||
1282 | } | ||
1283 | portdev->in_vqs = kmalloc(nr_ports * sizeof(struct virtqueue *), | ||
1284 | GFP_KERNEL); | ||
1285 | if (!portdev->in_vqs) { | ||
1286 | err = -ENOMEM; | ||
1287 | goto free_names; | ||
1288 | } | ||
1289 | portdev->out_vqs = kmalloc(nr_ports * sizeof(struct virtqueue *), | ||
1290 | GFP_KERNEL); | ||
1291 | if (!portdev->out_vqs) { | ||
1292 | err = -ENOMEM; | ||
1293 | goto free_invqs; | ||
1294 | } | ||
1295 | |||
1296 | /* | ||
1297 | * For backward compat (newer host but older guest), the host | ||
1298 | * spawns a console port first and also inits the vqs for port | ||
1299 | * 0 before others. | ||
1300 | */ | ||
1301 | j = 0; | ||
1302 | io_callbacks[j] = in_intr; | ||
1303 | io_callbacks[j + 1] = NULL; | ||
1304 | io_names[j] = "input"; | ||
1305 | io_names[j + 1] = "output"; | ||
1306 | j += 2; | ||
204 | 1307 | ||
1308 | if (use_multiport(portdev)) { | ||
1309 | io_callbacks[j] = control_intr; | ||
1310 | io_callbacks[j + 1] = NULL; | ||
1311 | io_names[j] = "control-i"; | ||
1312 | io_names[j + 1] = "control-o"; | ||
1313 | |||
1314 | for (i = 1; i < nr_ports; i++) { | ||
1315 | j += 2; | ||
1316 | io_callbacks[j] = in_intr; | ||
1317 | io_callbacks[j + 1] = NULL; | ||
1318 | io_names[j] = "input"; | ||
1319 | io_names[j + 1] = "output"; | ||
1320 | } | ||
1321 | } | ||
205 | /* Find the queues. */ | 1322 | /* Find the queues. */ |
206 | /* FIXME: This is why we want to wean off hvc: we do nothing | 1323 | err = portdev->vdev->config->find_vqs(portdev->vdev, nr_queues, vqs, |
207 | * when input comes in. */ | 1324 | io_callbacks, |
208 | err = vdev->config->find_vqs(vdev, 2, vqs, callbacks, names); | 1325 | (const char **)io_names); |
209 | if (err) | 1326 | if (err) |
1327 | goto free_outvqs; | ||
1328 | |||
1329 | j = 0; | ||
1330 | portdev->in_vqs[0] = vqs[0]; | ||
1331 | portdev->out_vqs[0] = vqs[1]; | ||
1332 | j += 2; | ||
1333 | if (use_multiport(portdev)) { | ||
1334 | portdev->c_ivq = vqs[j]; | ||
1335 | portdev->c_ovq = vqs[j + 1]; | ||
1336 | |||
1337 | for (i = 1; i < nr_ports; i++) { | ||
1338 | j += 2; | ||
1339 | portdev->in_vqs[i] = vqs[j]; | ||
1340 | portdev->out_vqs[i] = vqs[j + 1]; | ||
1341 | } | ||
1342 | } | ||
1343 | kfree(io_callbacks); | ||
1344 | kfree(io_names); | ||
1345 | kfree(vqs); | ||
1346 | |||
1347 | return 0; | ||
1348 | |||
1349 | free_names: | ||
1350 | kfree(io_names); | ||
1351 | free_callbacks: | ||
1352 | kfree(io_callbacks); | ||
1353 | free_outvqs: | ||
1354 | kfree(portdev->out_vqs); | ||
1355 | free_invqs: | ||
1356 | kfree(portdev->in_vqs); | ||
1357 | free_vqs: | ||
1358 | kfree(vqs); | ||
1359 | fail: | ||
1360 | return err; | ||
1361 | } | ||
1362 | |||
1363 | static const struct file_operations portdev_fops = { | ||
1364 | .owner = THIS_MODULE, | ||
1365 | }; | ||
1366 | |||
1367 | /* | ||
1368 | * Once we're further in boot, we get probed like any other virtio | ||
1369 | * device. | ||
1370 | * | ||
1371 | * If the host also supports multiple console ports, we check the | ||
1372 | * config space to see how many ports the host has spawned. We | ||
1373 | * initialize each port found. | ||
1374 | */ | ||
1375 | static int __devinit virtcons_probe(struct virtio_device *vdev) | ||
1376 | { | ||
1377 | struct ports_device *portdev; | ||
1378 | u32 i; | ||
1379 | int err; | ||
1380 | bool multiport; | ||
1381 | |||
1382 | portdev = kmalloc(sizeof(*portdev), GFP_KERNEL); | ||
1383 | if (!portdev) { | ||
1384 | err = -ENOMEM; | ||
1385 | goto fail; | ||
1386 | } | ||
1387 | |||
1388 | /* Attach this portdev to this virtio_device, and vice-versa. */ | ||
1389 | portdev->vdev = vdev; | ||
1390 | vdev->priv = portdev; | ||
1391 | |||
1392 | spin_lock_irq(&pdrvdata_lock); | ||
1393 | portdev->drv_index = pdrvdata.index++; | ||
1394 | spin_unlock_irq(&pdrvdata_lock); | ||
1395 | |||
1396 | portdev->chr_major = register_chrdev(0, "virtio-portsdev", | ||
1397 | &portdev_fops); | ||
1398 | if (portdev->chr_major < 0) { | ||
1399 | dev_err(&vdev->dev, | ||
1400 | "Error %d registering chrdev for device %u\n", | ||
1401 | portdev->chr_major, portdev->drv_index); | ||
1402 | err = portdev->chr_major; | ||
210 | goto free; | 1403 | goto free; |
1404 | } | ||
211 | 1405 | ||
212 | in_vq = vqs[0]; | 1406 | multiport = false; |
213 | out_vq = vqs[1]; | 1407 | portdev->config.nr_ports = 1; |
1408 | portdev->config.max_nr_ports = 1; | ||
1409 | if (virtio_has_feature(vdev, VIRTIO_CONSOLE_F_MULTIPORT)) { | ||
1410 | multiport = true; | ||
1411 | vdev->features[0] |= 1 << VIRTIO_CONSOLE_F_MULTIPORT; | ||
214 | 1412 | ||
215 | /* Start using the new console output. */ | 1413 | vdev->config->get(vdev, offsetof(struct virtio_console_config, |
216 | virtio_cons.get_chars = get_chars; | 1414 | nr_ports), |
217 | virtio_cons.put_chars = put_chars; | 1415 | &portdev->config.nr_ports, |
218 | virtio_cons.notifier_add = notifier_add_vio; | 1416 | sizeof(portdev->config.nr_ports)); |
219 | virtio_cons.notifier_del = notifier_del_vio; | 1417 | vdev->config->get(vdev, offsetof(struct virtio_console_config, |
220 | virtio_cons.notifier_hangup = notifier_del_vio; | 1418 | max_nr_ports), |
221 | 1419 | &portdev->config.max_nr_ports, | |
222 | /* The first argument of hvc_alloc() is the virtual console number, so | 1420 | sizeof(portdev->config.max_nr_ports)); |
223 | * we use zero. The second argument is the parameter for the | 1421 | if (portdev->config.nr_ports > portdev->config.max_nr_ports) { |
224 | * notification mechanism (like irq number). We currently leave this | 1422 | dev_warn(&vdev->dev, |
225 | * as zero, virtqueues have implicit notifications. | 1423 | "More ports (%u) specified than allowed (%u). Will init %u ports.", |
226 | * | 1424 | portdev->config.nr_ports, |
227 | * The third argument is a "struct hv_ops" containing the put_chars() | 1425 | portdev->config.max_nr_ports, |
228 | * get_chars(), notifier_add() and notifier_del() pointers. | 1426 | portdev->config.max_nr_ports); |
229 | * The final argument is the output buffer size: we can do any size, | 1427 | |
230 | * so we put PAGE_SIZE here. */ | 1428 | portdev->config.nr_ports = portdev->config.max_nr_ports; |
231 | hvc = hvc_alloc(0, 0, &virtio_cons, PAGE_SIZE); | 1429 | } |
232 | if (IS_ERR(hvc)) { | 1430 | } |
233 | err = PTR_ERR(hvc); | 1431 | |
234 | goto free_vqs; | 1432 | /* Let the Host know we support multiple ports.*/ |
1433 | vdev->config->finalize_features(vdev); | ||
1434 | |||
1435 | err = init_vqs(portdev); | ||
1436 | if (err < 0) { | ||
1437 | dev_err(&vdev->dev, "Error %d initializing vqs\n", err); | ||
1438 | goto free_chrdev; | ||
1439 | } | ||
1440 | |||
1441 | spin_lock_init(&portdev->ports_lock); | ||
1442 | INIT_LIST_HEAD(&portdev->ports); | ||
1443 | |||
1444 | if (multiport) { | ||
1445 | spin_lock_init(&portdev->cvq_lock); | ||
1446 | INIT_WORK(&portdev->control_work, &control_work_handler); | ||
1447 | INIT_WORK(&portdev->config_work, &config_work_handler); | ||
1448 | |||
1449 | err = fill_queue(portdev->c_ivq, &portdev->cvq_lock); | ||
1450 | if (!err) { | ||
1451 | dev_err(&vdev->dev, | ||
1452 | "Error allocating buffers for control queue\n"); | ||
1453 | err = -ENOMEM; | ||
1454 | goto free_vqs; | ||
1455 | } | ||
235 | } | 1456 | } |
236 | 1457 | ||
237 | /* Register the input buffer the first time. */ | 1458 | for (i = 0; i < portdev->config.nr_ports; i++) |
238 | add_inbuf(); | 1459 | add_port(portdev, i); |
1460 | |||
1461 | /* Start using the new console output. */ | ||
1462 | early_put_chars = NULL; | ||
239 | return 0; | 1463 | return 0; |
240 | 1464 | ||
241 | free_vqs: | 1465 | free_vqs: |
242 | vdev->config->del_vqs(vdev); | 1466 | vdev->config->del_vqs(vdev); |
1467 | kfree(portdev->in_vqs); | ||
1468 | kfree(portdev->out_vqs); | ||
1469 | free_chrdev: | ||
1470 | unregister_chrdev(portdev->chr_major, "virtio-portsdev"); | ||
243 | free: | 1471 | free: |
244 | kfree(inbuf); | 1472 | kfree(portdev); |
245 | fail: | 1473 | fail: |
246 | return err; | 1474 | return err; |
247 | } | 1475 | } |
248 | 1476 | ||
1477 | static void virtcons_remove(struct virtio_device *vdev) | ||
1478 | { | ||
1479 | struct ports_device *portdev; | ||
1480 | struct port *port, *port2; | ||
1481 | struct port_buffer *buf; | ||
1482 | unsigned int len; | ||
1483 | |||
1484 | portdev = vdev->priv; | ||
1485 | |||
1486 | cancel_work_sync(&portdev->control_work); | ||
1487 | cancel_work_sync(&portdev->config_work); | ||
1488 | |||
1489 | list_for_each_entry_safe(port, port2, &portdev->ports, list) | ||
1490 | remove_port(port); | ||
1491 | |||
1492 | unregister_chrdev(portdev->chr_major, "virtio-portsdev"); | ||
1493 | |||
1494 | while ((buf = portdev->c_ivq->vq_ops->get_buf(portdev->c_ivq, &len))) | ||
1495 | free_buf(buf); | ||
1496 | |||
1497 | while ((buf = portdev->c_ivq->vq_ops->detach_unused_buf(portdev->c_ivq))) | ||
1498 | free_buf(buf); | ||
1499 | |||
1500 | vdev->config->del_vqs(vdev); | ||
1501 | kfree(portdev->in_vqs); | ||
1502 | kfree(portdev->out_vqs); | ||
1503 | |||
1504 | kfree(portdev); | ||
1505 | } | ||
1506 | |||
249 | static struct virtio_device_id id_table[] = { | 1507 | static struct virtio_device_id id_table[] = { |
250 | { VIRTIO_ID_CONSOLE, VIRTIO_DEV_ANY_ID }, | 1508 | { VIRTIO_ID_CONSOLE, VIRTIO_DEV_ANY_ID }, |
251 | { 0 }, | 1509 | { 0 }, |
@@ -253,6 +1511,7 @@ static struct virtio_device_id id_table[] = { | |||
253 | 1511 | ||
254 | static unsigned int features[] = { | 1512 | static unsigned int features[] = { |
255 | VIRTIO_CONSOLE_F_SIZE, | 1513 | VIRTIO_CONSOLE_F_SIZE, |
1514 | VIRTIO_CONSOLE_F_MULTIPORT, | ||
256 | }; | 1515 | }; |
257 | 1516 | ||
258 | static struct virtio_driver virtio_console = { | 1517 | static struct virtio_driver virtio_console = { |
@@ -262,14 +1521,41 @@ static struct virtio_driver virtio_console = { | |||
262 | .driver.owner = THIS_MODULE, | 1521 | .driver.owner = THIS_MODULE, |
263 | .id_table = id_table, | 1522 | .id_table = id_table, |
264 | .probe = virtcons_probe, | 1523 | .probe = virtcons_probe, |
265 | .config_changed = virtcons_apply_config, | 1524 | .remove = virtcons_remove, |
1525 | .config_changed = config_intr, | ||
266 | }; | 1526 | }; |
267 | 1527 | ||
268 | static int __init init(void) | 1528 | static int __init init(void) |
269 | { | 1529 | { |
1530 | int err; | ||
1531 | |||
1532 | pdrvdata.class = class_create(THIS_MODULE, "virtio-ports"); | ||
1533 | if (IS_ERR(pdrvdata.class)) { | ||
1534 | err = PTR_ERR(pdrvdata.class); | ||
1535 | pr_err("Error %d creating virtio-ports class\n", err); | ||
1536 | return err; | ||
1537 | } | ||
1538 | |||
1539 | pdrvdata.debugfs_dir = debugfs_create_dir("virtio-ports", NULL); | ||
1540 | if (!pdrvdata.debugfs_dir) { | ||
1541 | pr_warning("Error %ld creating debugfs dir for virtio-ports\n", | ||
1542 | PTR_ERR(pdrvdata.debugfs_dir)); | ||
1543 | } | ||
1544 | INIT_LIST_HEAD(&pdrvdata.consoles); | ||
1545 | |||
270 | return register_virtio_driver(&virtio_console); | 1546 | return register_virtio_driver(&virtio_console); |
271 | } | 1547 | } |
1548 | |||
1549 | static void __exit fini(void) | ||
1550 | { | ||
1551 | unregister_virtio_driver(&virtio_console); | ||
1552 | |||
1553 | class_destroy(pdrvdata.class); | ||
1554 | if (pdrvdata.debugfs_dir) | ||
1555 | debugfs_remove_recursive(pdrvdata.debugfs_dir); | ||
1556 | } | ||
272 | module_init(init); | 1557 | module_init(init); |
1558 | module_exit(fini); | ||
273 | 1559 | ||
274 | MODULE_DEVICE_TABLE(virtio, id_table); | 1560 | MODULE_DEVICE_TABLE(virtio, id_table); |
275 | MODULE_DESCRIPTION("Virtio console driver"); | 1561 | MODULE_DESCRIPTION("Virtio console driver"); |
diff --git a/drivers/char/vme_scc.c b/drivers/char/vme_scc.c index 994e1a58b987..8b24729fec89 100644 --- a/drivers/char/vme_scc.c +++ b/drivers/char/vme_scc.c | |||
@@ -136,7 +136,7 @@ static const struct tty_port_operations scc_port_ops = { | |||
136 | * vme_scc_init() and support functions | 136 | * vme_scc_init() and support functions |
137 | *---------------------------------------------------------------------------*/ | 137 | *---------------------------------------------------------------------------*/ |
138 | 138 | ||
139 | static int scc_init_drivers(void) | 139 | static int __init scc_init_drivers(void) |
140 | { | 140 | { |
141 | int error; | 141 | int error; |
142 | 142 | ||
@@ -172,7 +172,7 @@ static int scc_init_drivers(void) | |||
172 | /* ports[] array is indexed by line no (i.e. [0] for ttyS0, [1] for ttyS1). | 172 | /* ports[] array is indexed by line no (i.e. [0] for ttyS0, [1] for ttyS1). |
173 | */ | 173 | */ |
174 | 174 | ||
175 | static void scc_init_portstructs(void) | 175 | static void __init scc_init_portstructs(void) |
176 | { | 176 | { |
177 | struct scc_port *port; | 177 | struct scc_port *port; |
178 | int i; | 178 | int i; |
@@ -195,7 +195,7 @@ static void scc_init_portstructs(void) | |||
195 | 195 | ||
196 | 196 | ||
197 | #ifdef CONFIG_MVME147_SCC | 197 | #ifdef CONFIG_MVME147_SCC |
198 | static int mvme147_scc_init(void) | 198 | static int __init mvme147_scc_init(void) |
199 | { | 199 | { |
200 | struct scc_port *port; | 200 | struct scc_port *port; |
201 | int error; | 201 | int error; |
@@ -298,7 +298,7 @@ fail: | |||
298 | 298 | ||
299 | 299 | ||
300 | #ifdef CONFIG_MVME162_SCC | 300 | #ifdef CONFIG_MVME162_SCC |
301 | static int mvme162_scc_init(void) | 301 | static int __init mvme162_scc_init(void) |
302 | { | 302 | { |
303 | struct scc_port *port; | 303 | struct scc_port *port; |
304 | int error; | 304 | int error; |
@@ -404,7 +404,7 @@ fail: | |||
404 | 404 | ||
405 | 405 | ||
406 | #ifdef CONFIG_BVME6000_SCC | 406 | #ifdef CONFIG_BVME6000_SCC |
407 | static int bvme6000_scc_init(void) | 407 | static int __init bvme6000_scc_init(void) |
408 | { | 408 | { |
409 | struct scc_port *port; | 409 | struct scc_port *port; |
410 | int error; | 410 | int error; |
@@ -503,7 +503,7 @@ fail_free_b_rx: | |||
503 | #endif | 503 | #endif |
504 | 504 | ||
505 | 505 | ||
506 | static int vme_scc_init(void) | 506 | static int __init vme_scc_init(void) |
507 | { | 507 | { |
508 | int res = -ENODEV; | 508 | int res = -ENODEV; |
509 | 509 | ||
diff --git a/drivers/char/vt_ioctl.c b/drivers/char/vt_ioctl.c index 6aa10284104a..87778dcf8727 100644 --- a/drivers/char/vt_ioctl.c +++ b/drivers/char/vt_ioctl.c | |||
@@ -888,7 +888,7 @@ int vt_ioctl(struct tty_struct *tty, struct file * file, | |||
888 | ret = -EFAULT; | 888 | ret = -EFAULT; |
889 | goto out; | 889 | goto out; |
890 | } | 890 | } |
891 | if (tmp.mode != VT_AUTO && tmp.mode != VT_PROCESS) { | 891 | if (tmp.mode != VT_AUTO && tmp.mode != VT_PROCESS && tmp.mode != VT_PROCESS_AUTO) { |
892 | ret = -EINVAL; | 892 | ret = -EINVAL; |
893 | goto out; | 893 | goto out; |
894 | } | 894 | } |
@@ -1622,7 +1622,7 @@ static void complete_change_console(struct vc_data *vc) | |||
1622 | * telling it that it has acquired. Also check if it has died and | 1622 | * telling it that it has acquired. Also check if it has died and |
1623 | * clean up (similar to logic employed in change_console()) | 1623 | * clean up (similar to logic employed in change_console()) |
1624 | */ | 1624 | */ |
1625 | if (vc->vt_mode.mode == VT_PROCESS) { | 1625 | if (vc->vt_mode.mode == VT_PROCESS || vc->vt_mode.mode == VT_PROCESS_AUTO) { |
1626 | /* | 1626 | /* |
1627 | * Send the signal as privileged - kill_pid() will | 1627 | * Send the signal as privileged - kill_pid() will |
1628 | * tell us if the process has gone or something else | 1628 | * tell us if the process has gone or something else |
@@ -1682,7 +1682,7 @@ void change_console(struct vc_data *new_vc) | |||
1682 | * vt to auto control. | 1682 | * vt to auto control. |
1683 | */ | 1683 | */ |
1684 | vc = vc_cons[fg_console].d; | 1684 | vc = vc_cons[fg_console].d; |
1685 | if (vc->vt_mode.mode == VT_PROCESS) { | 1685 | if (vc->vt_mode.mode == VT_PROCESS || vc->vt_mode.mode == VT_PROCESS_AUTO) { |
1686 | /* | 1686 | /* |
1687 | * Send the signal as privileged - kill_pid() will | 1687 | * Send the signal as privileged - kill_pid() will |
1688 | * tell us if the process has gone or something else | 1688 | * tell us if the process has gone or something else |
@@ -1693,27 +1693,28 @@ void change_console(struct vc_data *new_vc) | |||
1693 | */ | 1693 | */ |
1694 | vc->vt_newvt = new_vc->vc_num; | 1694 | vc->vt_newvt = new_vc->vc_num; |
1695 | if (kill_pid(vc->vt_pid, vc->vt_mode.relsig, 1) == 0) { | 1695 | if (kill_pid(vc->vt_pid, vc->vt_mode.relsig, 1) == 0) { |
1696 | if(vc->vt_mode.mode == VT_PROCESS) | ||
1697 | /* | ||
1698 | * It worked. Mark the vt to switch to and | ||
1699 | * return. The process needs to send us a | ||
1700 | * VT_RELDISP ioctl to complete the switch. | ||
1701 | */ | ||
1702 | return; | ||
1703 | } else { | ||
1696 | /* | 1704 | /* |
1697 | * It worked. Mark the vt to switch to and | 1705 | * The controlling process has died, so we revert back to |
1698 | * return. The process needs to send us a | 1706 | * normal operation. In this case, we'll also change back |
1699 | * VT_RELDISP ioctl to complete the switch. | 1707 | * to KD_TEXT mode. I'm not sure if this is strictly correct |
1708 | * but it saves the agony when the X server dies and the screen | ||
1709 | * remains blanked due to KD_GRAPHICS! It would be nice to do | ||
1710 | * this outside of VT_PROCESS but there is no single process | ||
1711 | * to account for and tracking tty count may be undesirable. | ||
1700 | */ | 1712 | */ |
1701 | return; | 1713 | reset_vc(vc); |
1702 | } | 1714 | } |
1703 | 1715 | ||
1704 | /* | 1716 | /* |
1705 | * The controlling process has died, so we revert back to | 1717 | * Fall through to normal (VT_AUTO and VT_PROCESS_AUTO) handling of the switch... |
1706 | * normal operation. In this case, we'll also change back | ||
1707 | * to KD_TEXT mode. I'm not sure if this is strictly correct | ||
1708 | * but it saves the agony when the X server dies and the screen | ||
1709 | * remains blanked due to KD_GRAPHICS! It would be nice to do | ||
1710 | * this outside of VT_PROCESS but there is no single process | ||
1711 | * to account for and tracking tty count may be undesirable. | ||
1712 | */ | ||
1713 | reset_vc(vc); | ||
1714 | |||
1715 | /* | ||
1716 | * Fall through to normal (VT_AUTO) handling of the switch... | ||
1717 | */ | 1718 | */ |
1718 | } | 1719 | } |
1719 | 1720 | ||