aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/char
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/char')
-rw-r--r--drivers/char/ChangeLog775
-rw-r--r--drivers/char/Kconfig25
-rw-r--r--drivers/char/Makefile1
-rw-r--r--drivers/char/agp/Kconfig5
-rw-r--r--drivers/char/agp/amd-k7-agp.c2
-rw-r--r--drivers/char/agp/amd64-agp.c20
-rw-r--r--drivers/char/agp/backend.c14
-rw-r--r--drivers/char/agp/compat_ioctl.c1
-rw-r--r--drivers/char/agp/frontend.c28
-rw-r--r--drivers/char/agp/generic.c1
-rw-r--r--drivers/char/agp/hp-agp.c7
-rw-r--r--drivers/char/agp/intel-agp.c267
-rw-r--r--drivers/char/agp/nvidia-agp.c1
-rw-r--r--drivers/char/agp/sgi-agp.c1
-rw-r--r--drivers/char/agp/uninorth-agp.c78
-rw-r--r--drivers/char/amiserial.c4
-rw-r--r--drivers/char/applicom.c2
-rw-r--r--drivers/char/bfin_jtag_comm.c3
-rw-r--r--drivers/char/briq_panel.c1
-rw-r--r--drivers/char/bsr.c1
-rw-r--r--drivers/char/cs5535_gpio.c3
-rw-r--r--drivers/char/cyclades.c17
-rw-r--r--drivers/char/dsp56k.c1
-rw-r--r--drivers/char/efirtc.c13
-rw-r--r--drivers/char/epca.c3
-rw-r--r--drivers/char/esp.c2533
-rw-r--r--drivers/char/generic_nvram.c9
-rw-r--r--drivers/char/generic_serial.c1
-rw-r--r--drivers/char/hpet.c16
-rw-r--r--drivers/char/hvc_beat.c4
-rw-r--r--drivers/char/hvc_console.c40
-rw-r--r--drivers/char/hvc_console.h9
-rw-r--r--drivers/char/hvc_iseries.c4
-rw-r--r--drivers/char/hvc_iucv.c11
-rw-r--r--drivers/char/hvc_rtas.c2
-rw-r--r--drivers/char/hvc_udbg.c2
-rw-r--r--drivers/char/hvc_vio.c2
-rw-r--r--drivers/char/hvc_xen.c4
-rw-r--r--drivers/char/hvcs.c1
-rw-r--r--drivers/char/hw_random/Kconfig14
-rw-r--r--drivers/char/hw_random/Makefile1
-rw-r--r--drivers/char/hw_random/core.c110
-rw-r--r--drivers/char/hw_random/intel-rng.c1
-rw-r--r--drivers/char/hw_random/n2-drv.c2
-rw-r--r--drivers/char/hw_random/nomadik-rng.c103
-rw-r--r--drivers/char/hw_random/octeon-rng.c1
-rw-r--r--drivers/char/hw_random/tx4939-rng.c1
-rw-r--r--drivers/char/hw_random/virtio-rng.c82
-rw-r--r--drivers/char/ip2/i2hw.h2
-rw-r--r--drivers/char/ip2/ip2main.c26
-rw-r--r--drivers/char/ipmi/ipmi_kcs_sm.c2
-rw-r--r--drivers/char/ipmi/ipmi_msghandler.c10
-rw-r--r--drivers/char/ipmi/ipmi_poweroff.c11
-rw-r--r--drivers/char/ipmi/ipmi_si_intf.c189
-rw-r--r--drivers/char/isicom.c175
-rw-r--r--drivers/char/istallion.c183
-rw-r--r--drivers/char/keyboard.c246
-rw-r--r--drivers/char/lp.c115
-rw-r--r--drivers/char/mbcs.c1
-rw-r--r--drivers/char/mem.c387
-rw-r--r--drivers/char/misc.c33
-rw-r--r--drivers/char/mmtimer.c3
-rw-r--r--drivers/char/moxa.c310
-rw-r--r--drivers/char/mspec.c2
-rw-r--r--drivers/char/mxser.c254
-rw-r--r--drivers/char/n_r3964.c2
-rw-r--r--drivers/char/n_tty.c17
-rw-r--r--drivers/char/nozomi.c202
-rw-r--r--drivers/char/nvram.c23
-rw-r--r--drivers/char/nwflash.c1
-rw-r--r--drivers/char/pc8736x_gpio.c2
-rw-r--r--drivers/char/pcmcia/cm4000_cs.c83
-rw-r--r--drivers/char/pcmcia/cm4040_cs.c52
-rw-r--r--drivers/char/pcmcia/ipwireless/hardware.c8
-rw-r--r--drivers/char/pcmcia/ipwireless/main.c296
-rw-r--r--drivers/char/pcmcia/ipwireless/network.c1
-rw-r--r--drivers/char/pcmcia/ipwireless/tty.c2
-rw-r--r--drivers/char/pcmcia/synclink_cs.c80
-rw-r--r--drivers/char/ppdev.c1
-rw-r--r--drivers/char/ps3flash.c1
-rw-r--r--drivers/char/pty.c19
-rw-r--r--drivers/char/random.c75
-rw-r--r--drivers/char/raw.c2
-rw-r--r--drivers/char/rio/rioinit.c1
-rw-r--r--drivers/char/rio/riointr.c1
-rw-r--r--drivers/char/rio/rioparam.c1
-rw-r--r--drivers/char/rio/rioroute.c1
-rw-r--r--drivers/char/rio/riotty.c1
-rw-r--r--drivers/char/rio/route.h2
-rw-r--r--drivers/char/riscom8.c88
-rw-r--r--drivers/char/rtc.c11
-rw-r--r--drivers/char/scx200_gpio.c2
-rw-r--r--drivers/char/serial167.c6
-rw-r--r--drivers/char/snsc_event.c1
-rw-r--r--drivers/char/sonypi.c61
-rw-r--r--drivers/char/specialix.c3
-rw-r--r--drivers/char/stallion.c132
-rw-r--r--drivers/char/synclink.c4
-rw-r--r--drivers/char/synclink_gt.c186
-rw-r--r--drivers/char/sysrq.c3
-rw-r--r--drivers/char/tb0219.c6
-rw-r--r--drivers/char/toshiba.c12
-rw-r--r--drivers/char/tpm/tpm.c3
-rw-r--r--drivers/char/tpm/tpm_bios.c1
-rw-r--r--drivers/char/tpm/tpm_infineon.c79
-rw-r--r--drivers/char/tpm/tpm_nsc.c1
-rw-r--r--drivers/char/tpm/tpm_tis.c12
-rw-r--r--drivers/char/tty_audit.c2
-rw-r--r--drivers/char/tty_buffer.c17
-rw-r--r--drivers/char/tty_io.c156
-rw-r--r--drivers/char/tty_ioctl.c2
-rw-r--r--drivers/char/tty_ldisc.c73
-rw-r--r--drivers/char/tty_port.c99
-rw-r--r--drivers/char/uv_mmtimer.c18
-rw-r--r--drivers/char/viotape.c1
-rw-r--r--drivers/char/virtio_console.c1622
-rw-r--r--drivers/char/vme_scc.c13
-rw-r--r--drivers/char/vt.c67
-rw-r--r--drivers/char/xilinx_hwicap/xilinx_hwicap.c1
119 files changed, 3984 insertions, 5748 deletions
diff --git a/drivers/char/ChangeLog b/drivers/char/ChangeLog
deleted file mode 100644
index 56b8a2e76ab1..000000000000
--- a/drivers/char/ChangeLog
+++ /dev/null
@@ -1,775 +0,0 @@
12001-08-11 Tim Waugh <twaugh@redhat.com>
2
3 * serial.c (get_pci_port): Deal with awkward Titan cards.
4
51998-08-26 Theodore Ts'o <tytso@rsts-11.mit.edu>
6
7 * serial.c (rs_open): Correctly decrement the module in-use count
8 on errors.
9
10Thu Feb 19 14:24:08 1998 Theodore Ts'o <tytso@rsts-11.mit.edu>
11
12 * tty_io.c (tty_name): Remove the non-reentrant (and non-SMP safe)
13 version of tty_name, and rename the reentrant _tty_name
14 function to be tty_name.
15 (tty_open): Add a warning message stating callout devices
16 are deprecated.
17
18Mon Dec 1 08:24:15 1997 Theodore Ts'o <tytso@rsts-11.mit.edu>
19
20 * tty_io.c (tty_get_baud_rate): Print a warning syslog if the
21 tty->alt_speed kludge is used; this means the system is
22 using the deprecated SPD_HI ioctls.
23
24Mon Nov 24 10:37:49 1997 Theodore Ts'o <tytso@rsts-11.mit.edu>
25
26 * serial.c, esp.c, rocket.c: Change drivers to take advantage of
27 tty_get_baud_rate().
28
29 * tty_io.c (tty_get_baud_rate): New function which computes the
30 correct baud rate for the tty. More factoring out of
31 common code out of the serial driver to the high-level tty
32 functions....
33
34Sat Nov 22 07:53:36 1997 Theodore Ts'o <tytso@rsts-11.mit.edu>
35
36 * serial.c, esp.c, rocket.c: Add tty->driver.break() routine, and
37 allow high-level tty code to handle the break and soft
38 carrier ioctls.
39
40 * tty_ioctl.c (n_tty_ioctl): Support TIOCGSOFTCAR and
41 TIOCSSOFTCAR, so that device drivers don't have to support
42 it.
43
44 * serial.c (autoconfig): Change 16750 test to hopefully eliminate
45 false results by people with strange 16550As being
46 detected as 16750s. Hopefully 16750s will still be
47 detected as 16750, and other weird UARTs won't get poorly
48 autodetected. If this doesn't work, I'll have to disable
49 the auto identification for the 16750.
50
51 * tty_io.c (tty_hangup): Now actually do the tty hangup
52 processing during the timer processing, and disable
53 interrupts while doing the hangup processing. This avoids
54 several nasty race conditions which happened when the
55 hangup processing was done asynchronously.
56 (tty_ioctl): Do break handling in the tty driver if
57 driver's break function is supported.
58 (tty_flip_buffer_push): New exported function which should
59 be used by drivers to push characters in the flip buffer
60 to the tty handler. This may either be done using a task
61 queue function for better CPU efficiency, or directly for
62 low latency operation.
63
64 * serial.c (rs_set_termios): Fix bug rs_set_termios when
65 transitioning away from B0, submitted by Stanislav
66 Voronyi.
67
68Thu Jun 19 20:05:58 1997 Theodore Ts'o <tytso@rsts-11.mit.edu>
69
70 * serial.c (begin_break, end_break, rs_ioctl): Applied patch
71 to support BSD ioctls to set and clear the break
72 condition explicitly.
73
74 * console.c (scrup, scrdown, insert_line, delete_line): Applied
75 fix suggested by Aaron Tiensivu to speed up block scrolls
76 up and down.
77
78 * n_tty.c (opost_block, write_chan): Added a modified "fast
79 console" patch which processes a block of text via
80 "cooking" efficiently.
81
82Wed Jun 18 15:25:50 1997 Theodore Ts'o <tytso@rsts-11.mit.edu>
83
84 * tty_io.c (init_dev, release_dev): Applied fix suggested by Bill
85 Hawes to prevent race conditions in the tty code.
86
87 * n_tty.c (n_tty_chars_in_buffer): Applied fix suggested by Bill
88 Hawes so that n_tty_chars_in_buffer returns the correct
89 value in the case when the tty is in cannonical mode. (To
90 avoid a pty deadlock with telnetd.)
91
92Thu Feb 27 01:53:08 1997 Theodore Ts'o <tytso@rsts-11.mit.edu>
93
94 * serial.c (change_speed): Add support for the termios flag
95 CMSPAR, which allows the user to select stick parity.
96 (i.e, if PARODD is set, the parity bit is always 1; if
97 PARRODD is not set, then the parity bit is always 0).
98
99Wed Feb 26 19:03:10 1997 Theodore Ts'o <tytso@rsts-11.mit.edu>
100
101 * serial.c (cleanup_module): Fix memory leak when using the serial
102 driver as a module; make sure tmp_buf gets freed!
103
104Tue Feb 25 11:01:59 1997 Theodore Ts'o <tytso@rsts-11.mit.edu>
105
106 * serial.c (set_modem_info): Add support for setting and clearing
107 the OUT1 and OUT2 bits. (For special case UART's, usually
108 for half-duplex.)
109 (autoconfig, change_speed): Fix TI 16750 support.
110
111Sun Feb 16 00:14:43 1997 Theodore Ts'o <tytso@rsts-11.mit.edu>
112
113 * tty_io.c (release_dev): Add sanity check to make sure there are
114 no waiters on tty->read_wait or tty->write_wait.
115
116 * serial.c (rs_init): Don't autoconfig a device if the I/O region
117 is already reserved.
118
119 * serial.c (serial_proc_info): Add support for /proc/serial.
120
121Thu Feb 13 00:49:10 1997 Theodore Ts'o <tytso@rsts-11.mit.edu>
122
123 * serial.c (receive_chars): When the UART repotrs an overrun
124 condition, it does so with a valid character. Changed to
125 not throw away the valid character, but instead report the
126 overrun after the valid character.
127
128 * serial.c: Added new #ifdef's for some of the advanced serial
129 driver features. A minimal driver that only supports COM
130 1/2/3/4 without sharing serial interrupts only takes 17k;
131 the full driver takes 32k.
132
133Wed Feb 12 14:50:44 1997 Theodore Ts'o <tytso@rsts-11.mit.edu>
134
135 * vt.c:
136 * pty.c:
137 * tty_ioctl.c:
138 * serial.c: Update routines to use the new 2.1 memory access
139 routines.
140
141Wed Dec 4 07:51:52 1996 Theodore Ts'o <tytso@localhost.mit.edu>
142
143 * serial.c (change_speed): Use save_flags(); cli() and
144 restore_flags() in order to ensure we don't accidentally
145 turn on interrupts when starting up the port.
146 (startup): Move the insertion of serial structure into the
147 IRQ chain earlier into the startup processing. Interrupts
148 should be off this whole time, but we eventually will want
149 to reduce this window.
150
151Thu Nov 21 10:05:22 1996 Theodore Ts'o <tytso@localhost.mit.edu>
152
153 * tty_ioctl.c (tty_wait_until_sent): Always check the driver
154 wait_until_ready routine, even if there are no characters
155 in the xmit buffer. (There may be charactes in the device
156 FIFO.)
157 (n_tty_ioctl): Add new flag tty->flow_stopped which
158 indicates whether the tty is stopped due to a request by
159 the TCXONC ioctl (used by tcflow). If so, don't let an
160 incoming XOFF character restart the tty. The tty can only
161 be restarted by another TCXONC request.
162
163 * tty_io.c (start_tty): Don't allow the tty to be restarted if
164 tty->flow_stopped is true.
165
166 * n_tty.c (n_tty_receive_char): If tty->flow_stopped is true, and
167 IXANY is set, don't eat a character trying to restart the
168 tty.
169
170 * serial.c (startup): Remove need for MCR_noint from the
171 async_struct structure. Only turn on DTR and RTS if the
172 baud rate is not zero.
173 (change_speed): More accurately calculate the timeout
174 value based on the word size. Move responsibility of
175 hangup when speed becomes B0 to rs_set_termios()
176 (set_serial_info): When changing the UART type set the
177 current xmit_fifo_size as well as the permanent
178 xmit_fifo_size.
179 (rs_ioctl): Fix TCSBRK (used by tcdrain) and TCSBRKP
180 ioctls to return EINTR if interrupted by a signal.
181 (rs_set_termios): If the baud rate changes to or from B0,
182 this function is now responsible for setting or clearing
183 DTR and RTS. DTR and RTS are only be changed on the
184 transition to or from the B0 state.
185 (rs_close): Wait for the characters to drain based on
186 info->timeout. At low baud rates (50 bps), it may take a
187 long time for the FIFO to completely drain out!
188 (rs_wait_until_sent): Fixed timeout handling. Now
189 releases control to the scheduler, but checks frequently
190 enough so that the function is sensitive enough to pass
191 the timing requirements of the NIST-PCTS.
192 (block_til_ready): When opening the device, don't turn on
193 DTR and RTS if the baud rate is B0.
194
195Thu Nov 14 00:06:09 1996 Theodore Ts'o <tytso@rsts-11.mit.edu>
196
197 * serial.c (autoconfig): Fix autoconfiguration problems;
198 info->flags wasn't getting initialized from the state
199 structure. Put in more paranoid test for the 16750.
200
201Fri Nov 8 20:19:50 1996 Theodore Ts'o <tytso@rsts-11.mit.edu>
202
203 * n_tty.c (n_tty_flush_buffer): Only call driver->unthrottle() if
204 the tty was previous throttled.
205 (n_tty_set_termios, write_chan): Add changes suggested by
206 Simon P. Allen to allow hardware cooking.
207
208 * tty_ioctl.c (set_termios): If we get a signal while waiting for
209 the tty to drain, return -EINTR.
210
211 * serial.c (change_speed): Add support for CREAD, as required by
212 POSIX.
213
214Sat Nov 2 20:43:10 1996 Theodore Ts'o <tytso@rsts-11.mit.edu>
215
216 * serial.c: Wholesale changes. Added support for the Startech
217 16650 and 16650V2 chips. (WARNING: the new startech
218 16650A may or may not work!) Added support for the
219 TI16750 (not yet tested). Split async_struct into a
220 transient part (async_struct) and a permanent part
221 (serial_state) which contains the configuration
222 information for the ports. Added new driver routines
223 wait_until_sent() and send_xchar() to help with POSIX
224 compliance. Added support for radio clocks which waggle
225 the carrier detect line (CONFIG_HARD_PPS).
226
227 * tty_ioctl.c (tty_wait_until_sent): Added call to new driver
228 function tty->driver.wait_until_sent(), which returns when
229 the tty's device xmit buffers are drained. Needed for
230 full POSIX compliance.
231
232 (send_prio_char): New function, called by the ioctl's
233 TCIOFF and TCION; uses the new driver call send_xchar(),
234 which will send the XON or XOFF character at high priority
235 (and even if tty output is stopped).
236
237Wed Jun 5 18:52:04 1996 Theodore Ts'o <tytso@rsts-11.mit.edu>
238
239 * pty.c (pty_close): When closing a pty, make sure packet mode is
240 cleared.
241
242Sun May 26 09:33:52 1996 Theodore Ts'o <tytso@rsts-11.mit.edu>
243
244 * vesa_blank.c (set_vesa_blanking): Add missing verify_area() call.
245
246 * selection.c (set_selection): Add missing verify_area() call.
247
248 * tty_io.c (tty_ioctl): Add missing verify_area() calls.
249
250 * serial.c (rs_ioctl): Add missing verify_area() calls.
251 (rs_init): Allow initialization of serial driver
252 configuration from a module.
253
254 * random.c (extract_entropy): Add missing verify_area call.
255 Don't limit number of characters returned to
256 32,768. Extract entropy is now no longer a inlined
257 function.
258
259 (random_read): Check return value in case extract_entropy
260 returns an error.
261
262 (secure_tcp_sequence_number): New function which returns a
263 secure TCP sequence number. This is needed to prevent some
264 nasty TCP hijacking attacks.
265
266 (init_std_data): Initialize using gettimeofday() instead of
267 struct timeval xtime.
268
269 (fast_add_entropy_word, add_entropy_word): Rename the
270 inline function add_entropy_word() to
271 fast_add_entropy_word(). Make add_entropy_word() be the
272 non-inlined function which is used in non-timing critical
273 places, in order to save space.
274
275 (initialize_benchmark, begin_benchmark, end_benchmark): New
276 functions defined when RANDOM_BENCHMARK is defined. They
277 allow us to benchmark the speed of the
278 add_timer_randomness() call.
279
280 (int_ln, rotate_left): Add two new inline functions with
281 i386 optimized asm instructions. This speeds up the
282 critical add_entropy_word() and add_timer_randomness()
283 functions, which are called from interrupt handlers.
284
285Tue May 7 22:51:11 1996 <tytso@rsts-11.mit.edu>
286
287 * random.c (add_timer_randomness): Limit the amount randomness
288 that we estimate to 12 bits. (An arbitrary amount).
289
290 (extract_entropy): To make it harder to analyze the hash
291 function, fold the hash function in half using XOR, and
292 use the folded result as the value to emit to the user.
293 Also, add timer randomness each pass through the
294 exact_entropy call, to increase the amount of unknown
295 values during the extraction process.
296
297 (random_ioctl): Use IOR/IOW definitions to define the
298 ioctl values used by the /dev/random driver. Allow the
299 old ioctl values to be used for backwards compatibility
300 (for a limited amount of time).
301
302Wed Apr 24 14:02:04 1996 Theodore Ts'o <tytso@rsts-11.mit.edu>
303
304 * random.c (add_timer_randomness): Use 2nd derivative as well to
305 better estimate entropy.
306
307 (rand_initialize): Explicitly initialize all the pointers
308 to NULL. (Clearing pointers using memset isn't portable.)
309 Initialize the random pool with OS-dependent data.
310
311 (random_write): Add sanity checking to the arguments to
312 random_write(), so that bad arguments won't cause a kernel
313 SEGV.
314
315 (random_read): Update the access time of the device inode
316 when you return data to the user.
317
318 (random_ioctl): Wake up the random_wait channel when there
319 are only WAIT_INPUT_BITS available. Add more paranoia
320 checks to make sure entropy_count doesn't go beyond the
321 bounds of (0, POOLSIZE). Add a few missing verify_area
322 checks. Add support for the RNDCLEARPOOL ioctl, which
323 zaps the random pool.
324
325 (add_timer_randomness): Wake up the random_wait
326 channel only when there are WAIT_INPUT_BITS available.
327
328 (random_select): Allow a random refresh daemon process to
329 select on /dev/random for writing; wake up the daemon when
330 there are less than WAIT_OUTPUT_BITS bits of randomness
331 available.
332
333Tue Apr 23 22:56:07 1996 <tytso@rsts-11.mit.edu>
334
335 * tty_io.c (init_dev): Change return code when user attempts to
336 open master pty which is already open from EAGAIN to EIO,
337 to match with BSD expectations. EIO is more correct
338 anyway, since EAGAIN implies that retrying will be
339 successful --- which it might be.... Eventually!!
340
341 * pty.c (pty_open, pty_close): Fix wait loop so that we don't
342 busy loop while waiting for the master side to open.
343 Fix tty opening/closing logic. TTY_SLAVE_CLOSED was
344 renamed to TTY_OTHER_CLOSED, so that the name is more
345 descriptive. Also fixed code so that the tty flag
346 actually works correctly now....
347
348Mon Apr 1 10:22:01 1996 <tytso@rsts-11.mit.edu>
349
350 * serial.c (rs_close): Cleaned up modularization changes.
351 Remove code which forced line discipline back to N_TTY
352 this is done in the tty upper layers, and there's no
353 reason to do it here. (Making this change also
354 removed the requirement that the serial module access
355 the internal kernel symbol "ldiscs".)
356
357 * tty_io.c (tty_init): Formally register a tty_driver entry for
358 /dev/tty (device 4, 0) and /dev/console (device 5, 0).
359 This guarantees that major device numbers 4 and 5 will be
360 reserved for the tty subsystem (as they have to be because
361 of /dev/tty and /dev/console). Removed tty_regdev, as
362 this interface is no longer necessary.
363
364Sun Mar 17 20:42:47 GMT 1996 <ah@doc.ic.ac.uk>
365
366 * serial.c : modularisation (changes in linux/fs/device.c allow
367 kerneld to automatically load the serial module).
368
369 * Makefile, Config.in : serial modularisation adds.
370
371 * tty_io.c : tty_init_ctty used by to register "cua" driver just
372 for the /dev/tty device (5,0). Added tty_regdev.
373
374 * serial.c (shutdown, rs_ioctl) : when port shuts down wakeup processes
375 waiting on delta_msr_wait. The TIOCMIWAIT ioctl returns EIO
376 if no change was done since the time of call.
377
378Sat Mar 16 14:33:13 1996 <aeb@cwi.nl>
379
380 * tty_io.c (disassociate_ctty): If disassociate_ctty is called by
381 exit, do not perform an implicit vhangup on a pty.
382
383Fri Feb 9 14:15:47 1996 <tytso@rsts-11.mit.edu>
384
385 * serial.c (block_til_ready): Fixed another race condition which
386 happens if a hangup happens during the open.
387
388Wed Jan 10 10:08:00 1996 <tytso@rsts-11.mit.edu>
389
390 * serial.c (block_til_ready): Remove race condition which happened
391 if a hangup condition happened during the setup of the
392 UART, before rs_open() called block_til_ready(). This
393 caused the info->count counter to be erroneously
394 decremented.
395
396 * serial.c (startup, rs_open): Remove race condition that could
397 cause a memory leak of one page. (Fortunately, both race
398 conditions were relatively rare in practice.)
399
400Tue Dec 5 13:21:27 1995 <tytso@rsts-11.mit.edu>
401
402 * serial.c (check_modem_status, rs_ioctl): Support the new
403 ioctl()'s TIOCGICOUNT, TIOCMIWAIT. These allow an
404 application program to wait on a modem serial register
405 status bit change, and to find out how many changes have
406 taken place for the MSR bits.
407
408 (rs_write): Eliminate a race condition which is introduced
409 if it is necessary to wait for the semaphore.
410
411Sat Nov 4 17:14:45 1995 <tytso@rsts-11.mit.edu>
412
413 * tty_io.c (tty_init): Move registration of TTY_MAJOR and
414 TTY_AUX_MAJOR to the end, so that /proc/devices looks
415 prettier.
416
417 * pty.c (pty_init): Use new major numbers for PTY master and slave
418 devices. This allow us to have more than 64 pty's. We
419 register the old pty devices for backwards compatibility.
420 Note that a system should either be using the old pty
421 devices or the new pty devices --- in general, it should
422 try to use both, since they map into the same pty table.
423 The old pty devices are strictly for backwards compatibility.
424
425Wed Oct 11 12:45:24 1995 <tytso@rsts-11.mit.edu>
426
427 * tty_io.c (disassociate_ctty): If disassociate_ctty is called by
428 exit, perform an implicit vhangup on the tty.
429
430 * pty.c (pty_close): When the master pty is closed, send a hangup
431 to the slave pty.
432 (pty_open): Use the flag TTY_SLAVE_CLOSED to test to see
433 if there are any open slave ptys, instead of using
434 tty->link->count. The old method got confused if there
435 were processes that had hung-up file descriptors on the
436 slave tty.
437
438Tue May 2 00:53:25 1995 <tytso@rsx-11.mit.edu>
439
440 * tty_io.c (tty_set_ldisc): Wait until the output buffer is
441 drained before closing the old line discipline --- needed
442 in only one case: XON/XOFF processing.
443
444 * n_tty.c (n_tty_close): Don't bother waiting until the output
445 driver is closed; in general, the line discipline
446 shouldn't care if the hardware is finished
447 transmitting before the line discipline terminates.
448
449 * tty_io.c (release_dev): Shutdown the line discipline after
450 decrementing the tty count variable; but set the
451 TTY_CLOSING flag so that we know that this tty structure
452 isn't long for this world.
453
454 * tty_io.c (init_dev): Add sanity code to check to see if
455 TTY_CLOSING is set on a tty structure; if so, something
456 bad has happened (probably a line discipline close blocked
457 when it shouldn't have; so do a kernel printk and then
458 return an error).
459
460Wed Apr 26 10:23:44 1995 Theodore Y. Ts'o <tytso@localhost>
461
462 * tty_io.c (release_dev): Try to shutdown the line discipline
463 *before* decrementing the tty count variable; this removes
464 a potential race condition which occurs when the line
465 discipline close blocks, and another process then tries
466 open the same serial port.
467
468 * serial.c (rs_hangup): When hanging up, flush the output buffer
469 before shutting down the UART. Otherwise the line
470 discipline close blocks waiting for the characters to get
471 flushed, which never happens until the serial port gets reused.
472
473Wed Apr 12 08:06:16 1995 Theodore Y. Ts'o <tytso@localhost>
474
475 * serial.c (do_serial_hangup, do_softint, check_modem_status,
476 rs_init): Hangups are now scheduled via a separate tqueue
477 structure in the async_struct structure, tqueue_hangup.
478 This task is pushed on to the tq_schedule queue, so that
479 it is processed synchronously by the scheduler.
480
481Sat Feb 18 12:13:51 1995 Theodore Y. Ts'o (tytso@rt-11)
482
483 * tty_io.c (disassociate_ctty, tty_open, tty_ioctl): Clear
484 current->tty_old_pgrp field when a session leader
485 acquires a controlling tty, and after a session leader
486 has disassociated from a controlling tty.
487
488Fri Feb 17 09:34:09 1995 Theodore Y. Ts'o (tytso@rt-11)
489
490 * serial.c (rs_interrupt_single, rs_interrupt, rs_interrupt_multi):
491 Change the number of passes made from 64 to be 256,
492 configurable with the #define RS_ISR_PASS_LIMIT.
493
494 * serial.c (rs_init, set_serial_info, get_serial_info, rs_close):
495 Remove support for closing_wait2. Instead, set
496 tty->closing and rely on the line discipline to prevent
497 echo wars.
498
499 * n_tty.c (n_tty_receive_char): IEXTEN does not need to be
500 enabled in order for IXANY to be active.
501
502 If tty->closing is set, then only process XON and XOFF
503 characters.
504
505Sun Feb 12 23:57:48 1995 Theodore Y. Ts'o (tytso@rt-11)
506
507 * serial.c (rs_timer): Change the interrupt poll time from 60
508 seconds to 10 seconds, configurable with the #define
509 RS_STROBE_TIME.
510
511 * serial.c (rs_interrupt_multi, startup, shutdown, rs_ioctl,
512 set_multiport_struct, get_multiport_struct): Add
513 provisions for a new type of interrupt service routine,
514 which better supports multiple serial ports on a single
515 IRQ.
516
517Sun Feb 5 19:35:11 1995 Theodore Y. Ts'o (tytso@rt-11)
518
519 * tty_ioctl.c (n_tty_ioctl, set_termios, tty_wait_until_sent):
520 * serial.c (rs_ioctl, rs_close):
521 * cyclades.c (cy_ioctl, cy_close):
522 * n_tty.c (n_tty_close): Rename wait_until_sent to
523 tty_wait_until_sent, so that it's a better name to export
524 in ksyms.c.
525
526Sat Feb 4 23:36:20 1995 Theodore Y. Ts'o (tytso@rt-11)
527
528 * serial.c (rs_close): Added missing check for closing_wait2 being
529 ASYNC_CLOSING_WAIT_NONE.
530
531Thu Jan 26 09:02:49 1995 Theodore Y. Ts'o (tytso@rt-11)
532
533 * serial.c (rs_init, set_serial_info, get_serial_info,
534 rs_close): Support close_wait in the serial driver.
535 This is helpful for slow devices (like serial
536 plotters) so that their outputs don't get flushed upon
537 device close. This has to be configurable because
538 normally we don't want ports to be hung up for long
539 periods of time during a close when they are not
540 connected to a device, or the device is powered off.
541
542 The default is to wait 30 seconds; in the case of a
543 very slow device, the close_wait timeout should be
544 lengthened. If it is set to 0, the kernel will wait
545 forever for all of the data to be transmitted.
546
547Thu Jan 17 01:17:20 1995 Theodore Y. Ts'o (tytso@rt-11)
548
549 * serial.c (startup, change_speed, rs_init): Add support to detect
550 the StarTech 16650 chip. Treat it as a 16450 for now,
551 because of its FIFO bugs.
552
553Thu Jan 5 21:21:57 1995 <dahinds@users.sourceforge.net>
554
555 * serial.c: (receive_char): Added counter to prevent infinite loop
556 when a PCMCIA serial device is ejected.
557
558Thu Dec 29 17:53:48 1994 <tytso@rsx-11.mit.edu>
559
560 * tty_io.c (check_tty_count): New procedure which checks
561 tty->count to make sure that it matches with the number of
562 open file descriptors which point at the structure. If
563 the number doesn't match, it prints a warning message.
564
565Wed Dec 28 15:41:51 1994 <tytso@rsx-11.mit.edu>
566
567 * tty_io.c (do_tty_hangup, disassociate_ctty): At hangup time,
568 save the tty's current foreground process group in the
569 session leader's task structure. When the session leader
570 terminates, send a SIGHUP, SIGCONT to that process group.
571 This is not required by POSIX, but it's not prohibited
572 either, and it appears to be the least intrusive way
573 to fix a problem that dialup servers have with
574 orphaned process groups caused by modem hangups.
575
576Thu Dec 8 14:52:11 1994 <tytso@rsx-11.mit.edu>
577
578 * serial.c (rs_ioctl): Don't allow most ioctl's if the serial port
579 isn't initialized.
580
581 * serial.c (rs_close): Don't clear the IER if the serial port
582 isn't initialized.
583
584 * serial.c (block_til_ready): Don't try to block on the dialin
585 port if the serial port isn't initialized.
586
587Wed Dec 7 10:48:30 1994 Si Park (si@wimpol.demon.co.uk)
588 * tty_io.c (tty_register_driver): Fix bug when linking onto
589 the tty_drivers list. We now test that there are elements
590 already on the list before setting the back link from the
591 first element to the new driver.
592
593 * tty_io.c (tty_unregister_driver): Fix bug in unlinking the
594 specified driver from the tty_drivers list. We were not
595 setting the back link correctly. This used to result in
596 a dangling back link pointer and cause panics on the next
597 call to get_tty_driver().
598
599Tue Nov 29 10:21:09 1994 Theodore Y. Ts'o (tytso@rt-11)
600
601 * tty_io.c (tty_unregister_driver): Fix bug in
602 tty_unregister_driver where the pointer to the refcount is
603 tested, instead of the refcount itself. This caused
604 tty_unregister_driver to always return EBUSY.
605
606Sat Nov 26 11:59:24 1994 Theodore Y. Ts'o (tytso@rt-11)
607
608 * tty_io.c (tty_ioctl): Add support for the new ioctl
609 TIOCTTYGSTRUCT, which allow a kernel debugging program
610 direct read access to the tty and tty_driver structures.
611
612Fri Nov 25 17:26:22 1994 Theodore Y. Ts'o (tytso@rt-11)
613
614 * serial.c (rs_set_termios): Don't wake up processes blocked in
615 open when the CLOCAL flag changes, since a blocking
616 open only samples the CLOCAL flag once when it blocks,
617 and doesn't check it again. (n.b. FreeBSD has a
618 different behavior for blocking opens; it's not clear
619 whether Linux or FreeBSD's interpretation is correct.
620 POSIX doesn't give clear guidance on this issue, so
621 this may change in the future....)
622
623 * serial.c (block_til_ready): Use the correct termios structure to
624 check the CLOCAL flag. If the cuaXX device is active,
625 then check the saved termios for the ttySXX device.
626 Otherwise, use the currently active termios structure.
627
628Sun Nov 6 21:05:44 1994 Theodore Y. Ts'o (tytso@rt-11)
629
630 * serial.c (change_speed): Add support for direct access of
631 57,600 and 115,200 bps.
632
633Wed Nov 2 10:32:36 1994 Theodore Y. Ts'o (tytso@rt-11)
634
635 * n_tty.c (n_tty_receive_room): Only allow excess characters
636 through if we are in ICANON mode *and* there are other no
637 pending lines in the buffer. Otherwise cut and paste over
638 4k breaks.
639
640Sat Oct 29 18:17:34 1994 Theodore Y. Ts'o (tytso@rt-11)
641
642 * serial.c (rs_ioctl, get_lsr_info): Added patch suggested by Arne
643 Riiber so that user mode programs can tell when the
644 transmitter shift register is empty.
645
646Thu Oct 27 23:14:29 1994 Theodore Y. Ts'o (tytso@rt-11)
647
648 * tty_ioctl.c (wait_until_sent): Added debugging printk statements
649 (under the #ifdef TTY_DEBUG_WAIT_UNTIL_SENT)
650
651 * serial.c (rs_interrupt, rs_interrupt_single, receive_chars,
652 change_speed, rs_close): rs_close now disables receiver
653 interrupts when closing the serial port. This allows the
654 serial port to close quickly when Linux and a modem (or a
655 mouse) are engaged in an echo war; when closing the serial
656 port, we now first stop listening to incoming characters,
657 and *then* wait for the transmit buffer to drain.
658
659 In order to make this change, the info->read_status_mask
660 is now used to control what bits of the line status
661 register are looked at in the interrupt routine in all
662 cases; previously it was only used in receive_chars to
663 select a few of the status bits.
664
665Mon Oct 24 23:36:21 1994 Theodore Y. Ts'o (tytso@rt-11)
666
667 * serial.c (rs_close): Add a timeout to the transmitter flush
668 loop; this is just a sanity check in case we have flaky
669 (or non-existent-but-configured-by-the-user) hardware.
670
671Fri Oct 21 09:37:23 1994 Theodore Y. Ts'o (tytso@rt-11)
672
673 * tty_io.c (tty_fasync): When asynchronous I/O is enabled, if the
674 process or process group has not be specified yet, set it
675 to be the tty's process group, or if that is not yet set,
676 to the current process's pid.
677
678Thu Oct 20 23:17:28 1994 Theodore Y. Ts'o (tytso@rt-11)
679
680 * n_tty.c (n_tty_receive_room): If we are doing input
681 canonicalization, let as many characters through as
682 possible, so that the excess characters can be "beeped".
683
684Tue Oct 18 10:02:43 1994 Theodore Y. Ts'o (tytso@rt-11)
685
686 * serial.c (rs_start): Removed an incorrect '!' that was
687 preventing transmit interrupts from being re-enabled in
688 rs_start(). Fortunately in most cases it would be
689 re-enabled elsewhere, but this still should be fixed
690 correctly.
691
692Sun Oct 9 23:46:03 1994 Theodore Y. Ts'o (tytso@rt-11)
693
694 * tty_io.c (do_tty_hangup): If the tty driver flags
695 TTY_DRIVER_RESET_TERMIOS is set, then reset the termios
696 settings back to the driver's initial configuration. This
697 allows the termios settings to be reset even if a process
698 has hung up file descriptors keeping a pty's termios from
699 being freed and reset.
700
701 * tty_io.c (release_dev): Fix memory leak. The pty's other
702 termios structure should also be freed.
703
704 * serial.c (rs_close, shutdown): Change how we wait for the
705 transmitter to completely drain before shutting down the
706 serial port. We now do it by scheduling in another
707 process instead of busy looping with the interrupts turned
708 on. This may eliminate some race condition problems that
709 some people seem to be reporting.
710
711Sun Sep 25 14:18:14 1994 Theodore Y. Ts'o (tytso@rt-11)
712
713 * tty_io.c (release_dev): When freeing a tty make sure that both
714 the tty and the o_tty (if present) aren't a process's
715 controlling tty. (Previously, we only checked the tty.)
716
717 * serial.c (change_speed): Only enable the Modem Status
718 Interrupt for a port if CLOCAL is not set or CRTSCTS
719 is set. If we're not checking the carrier detect and
720 CTS line, there's no point in enabling the modem
721 status interrupt. This will save spurious interrupts
722 from slowing down systems who have terminals that
723 don't support either line. (Of course, if you want
724 only one of CD and CTS support, you will need a
725 properly wired serial cable.)
726
727Thu Sep 22 08:32:48 1994 Theodore Y. Ts'o (tytso@rt-11)
728
729 * tty_io.c (do_SAK): Return if tty is null.
730
731 * tty_io.c (_tty_name): Return "NULL tty" if the passed in tty is
732 NULL.
733
734Sat Sep 17 13:19:25 1994 Theodore Y. Ts'o (tytso@rt-11)
735
736 * tty_ioctl.c (n_tty_ioctl): Fix TIOCGLCKTRMIOS and
737 TIOCSLCKTRMIOS, which were totally broken. Remove
738 extra indirection from argument; it should be a struct
739 termios *, not a struct termios **.
740 &real_tty->termios_locked should have been
741 real_tty->termios_locked. This caused us to be
742 reading and writing the termios_locked structure to
743 random places in kernel memory.
744
745 * tty_io.c (release_dev): Oops! Forgot to delete a critical kfree
746 of the locked_termios. This leaves the locked_termios
747 structure pointed at a freed object.
748
749Fri Sep 16 08:13:25 1994 Theodore Y. Ts'o (tytso@rt-11)
750
751 * tty_io.c (tty_open): Don't check for an exclusive open until
752 after the device specific open routine has been called.
753 Otherwise, the serial device ref counting will be screwed
754 up.
755
756 * serial.c (rs_open, block_til_ready): Don't set termios structure
757 until after block_til_ready has returned successfully.
758 Modify block_til_ready to check the normal_termios
759 structure directly, so it doesn't rely on termios being
760 set before it's called.
761
762Thu Sep 15 23:34:01 1994 Theodore Y. Ts'o (tytso@rt-11)
763
764 * serial.c (rs_close): Turn off interrupts during rs_close() to
765 prevent a race condition with the hangup code (which
766 runs during a software interrupt).
767
768 * tty_io.c (release_dev): Don't free the locked_termios structure;
769 its state must be retained across device opens.
770
771
772 * tty_io.c (tty_unregister_driver): Added function to unregister a
773 tty driver. (For loadable device drivers.)
774
775
diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
index 6aad99ec4e0f..3141dd3b6e53 100644
--- a/drivers/char/Kconfig
+++ b/drivers/char/Kconfig
@@ -201,19 +201,6 @@ config DIGIEPCA
201 To compile this driver as a module, choose M here: the 201 To compile this driver as a module, choose M here: the
202 module will be called epca. 202 module will be called epca.
203 203
204config ESPSERIAL
205 tristate "Hayes ESP serial port support"
206 depends on SERIAL_NONSTANDARD && ISA && ISA_DMA_API && BROKEN
207 help
208 This is a driver which supports Hayes ESP serial ports. Both single
209 port cards and multiport cards are supported. Make sure to read
210 <file:Documentation/hayes-esp.txt>.
211
212 To compile this driver as a module, choose M here: the
213 module will be called esp.
214
215 If unsure, say N.
216
217config MOXA_INTELLIO 204config MOXA_INTELLIO
218 tristate "Moxa Intellio support" 205 tristate "Moxa Intellio support"
219 depends on SERIAL_NONSTANDARD && (ISA || EISA || PCI) 206 depends on SERIAL_NONSTANDARD && (ISA || EISA || PCI)
@@ -515,7 +502,7 @@ config BRIQ_PANEL
515 502
516config BFIN_OTP 503config BFIN_OTP
517 tristate "Blackfin On-Chip OTP Memory Support" 504 tristate "Blackfin On-Chip OTP Memory Support"
518 depends on BLACKFIN && (BF52x || BF54x) 505 depends on BLACKFIN && (BF51x || BF52x || BF54x)
519 default y 506 default y
520 help 507 help
521 If you say Y here, you will get support for a character device 508 If you say Y here, you will get support for a character device
@@ -679,10 +666,18 @@ config VIRTIO_CONSOLE
679 help 666 help
680 Virtio console for use with lguest and other hypervisors. 667 Virtio console for use with lguest and other hypervisors.
681 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.
682 677
683config HVCS 678config HVCS
684 tristate "IBM Hypervisor Virtual Console Server support" 679 tristate "IBM Hypervisor Virtual Console Server support"
685 depends on PPC_PSERIES 680 depends on PPC_PSERIES && HVC_CONSOLE
686 help 681 help
687 Partitionable IBM Power5 ppc64 machines allow hosting of 682 Partitionable IBM Power5 ppc64 machines allow hosting of
688 firmware virtual consoles from one Linux partition by 683 firmware virtual consoles from one Linux partition by
diff --git a/drivers/char/Makefile b/drivers/char/Makefile
index 19a79dd79eee..f957edf7e45d 100644
--- a/drivers/char/Makefile
+++ b/drivers/char/Makefile
@@ -18,7 +18,6 @@ obj-$(CONFIG_CONSOLE_TRANSLATIONS) += consolemap.o consolemap_deftbl.o
18obj-$(CONFIG_HW_CONSOLE) += vt.o defkeymap.o 18obj-$(CONFIG_HW_CONSOLE) += vt.o defkeymap.o
19obj-$(CONFIG_AUDIT) += tty_audit.o 19obj-$(CONFIG_AUDIT) += tty_audit.o
20obj-$(CONFIG_MAGIC_SYSRQ) += sysrq.o 20obj-$(CONFIG_MAGIC_SYSRQ) += sysrq.o
21obj-$(CONFIG_ESPSERIAL) += esp.o
22obj-$(CONFIG_MVME147_SCC) += generic_serial.o vme_scc.o 21obj-$(CONFIG_MVME147_SCC) += generic_serial.o vme_scc.o
23obj-$(CONFIG_MVME162_SCC) += generic_serial.o vme_scc.o 22obj-$(CONFIG_MVME162_SCC) += generic_serial.o vme_scc.o
24obj-$(CONFIG_BVME6000_SCC) += generic_serial.o vme_scc.o 23obj-$(CONFIG_BVME6000_SCC) += generic_serial.o vme_scc.o
diff --git a/drivers/char/agp/Kconfig b/drivers/char/agp/Kconfig
index ccb1fa89de29..4b66c69eaf57 100644
--- a/drivers/char/agp/Kconfig
+++ b/drivers/char/agp/Kconfig
@@ -56,9 +56,8 @@ config AGP_AMD
56 X on AMD Irongate, 761, and 762 chipsets. 56 X on AMD Irongate, 761, and 762 chipsets.
57 57
58config AGP_AMD64 58config AGP_AMD64
59 tristate "AMD Opteron/Athlon64 on-CPU GART support" if !GART_IOMMU 59 tristate "AMD Opteron/Athlon64 on-CPU GART support"
60 depends on AGP && X86 60 depends on AGP && X86 && K8_NB
61 default y if GART_IOMMU
62 help 61 help
63 This option gives you AGP support for the GLX component of 62 This option gives you AGP support for the GLX component of
64 X using the on-CPU northbridge of the AMD Athlon64/Opteron CPUs. 63 X using the on-CPU northbridge of the AMD Athlon64/Opteron CPUs.
diff --git a/drivers/char/agp/amd-k7-agp.c b/drivers/char/agp/amd-k7-agp.c
index 73dbf40c874d..a7637d72cef6 100644
--- a/drivers/char/agp/amd-k7-agp.c
+++ b/drivers/char/agp/amd-k7-agp.c
@@ -6,9 +6,9 @@
6#include <linux/pci.h> 6#include <linux/pci.h>
7#include <linux/init.h> 7#include <linux/init.h>
8#include <linux/agp_backend.h> 8#include <linux/agp_backend.h>
9#include <linux/gfp.h>
10#include <linux/page-flags.h> 9#include <linux/page-flags.h>
11#include <linux/mm.h> 10#include <linux/mm.h>
11#include <linux/slab.h>
12#include "agp.h" 12#include "agp.h"
13 13
14#define AMD_MMBASE 0x14 14#define AMD_MMBASE 0x14
diff --git a/drivers/char/agp/amd64-agp.c b/drivers/char/agp/amd64-agp.c
index 2fb2e6cc322a..fd50ead59c79 100644
--- a/drivers/char/agp/amd64-agp.c
+++ b/drivers/char/agp/amd64-agp.c
@@ -728,6 +728,7 @@ int __init agp_amd64_init(void)
728 728
729 if (agp_off) 729 if (agp_off)
730 return -EINVAL; 730 return -EINVAL;
731
731 err = pci_register_driver(&agp_amd64_pci_driver); 732 err = pci_register_driver(&agp_amd64_pci_driver);
732 if (err < 0) 733 if (err < 0)
733 return err; 734 return err;
@@ -764,19 +765,28 @@ int __init agp_amd64_init(void)
764 return err; 765 return err;
765} 766}
766 767
768static int __init agp_amd64_mod_init(void)
769{
770#ifndef MODULE
771 if (gart_iommu_aperture)
772 return agp_bridges_found ? 0 : -ENODEV;
773#endif
774 return agp_amd64_init();
775}
776
767static void __exit agp_amd64_cleanup(void) 777static void __exit agp_amd64_cleanup(void)
768{ 778{
779#ifndef MODULE
780 if (gart_iommu_aperture)
781 return;
782#endif
769 if (aperture_resource) 783 if (aperture_resource)
770 release_resource(aperture_resource); 784 release_resource(aperture_resource);
771 pci_unregister_driver(&agp_amd64_pci_driver); 785 pci_unregister_driver(&agp_amd64_pci_driver);
772} 786}
773 787
774/* On AMD64 the PCI driver needs to initialize this driver early 788module_init(agp_amd64_mod_init);
775 for the IOMMU, so it has to be called via a backdoor. */
776#ifndef CONFIG_GART_IOMMU
777module_init(agp_amd64_init);
778module_exit(agp_amd64_cleanup); 789module_exit(agp_amd64_cleanup);
779#endif
780 790
781MODULE_AUTHOR("Dave Jones <davej@redhat.com>, Andi Kleen"); 791MODULE_AUTHOR("Dave Jones <davej@redhat.com>, Andi Kleen");
782module_param(agp_try_unsupported, bool, 0); 792module_param(agp_try_unsupported, bool, 0);
diff --git a/drivers/char/agp/backend.c b/drivers/char/agp/backend.c
index a56ca080e108..ee4f855611b6 100644
--- a/drivers/char/agp/backend.c
+++ b/drivers/char/agp/backend.c
@@ -30,6 +30,7 @@
30#include <linux/module.h> 30#include <linux/module.h>
31#include <linux/pci.h> 31#include <linux/pci.h>
32#include <linux/init.h> 32#include <linux/init.h>
33#include <linux/slab.h>
33#include <linux/pagemap.h> 34#include <linux/pagemap.h>
34#include <linux/miscdevice.h> 35#include <linux/miscdevice.h>
35#include <linux/pm.h> 36#include <linux/pm.h>
@@ -285,18 +286,22 @@ int agp_add_bridge(struct agp_bridge_data *bridge)
285{ 286{
286 int error; 287 int error;
287 288
288 if (agp_off) 289 if (agp_off) {
289 return -ENODEV; 290 error = -ENODEV;
291 goto err_put_bridge;
292 }
290 293
291 if (!bridge->dev) { 294 if (!bridge->dev) {
292 printk (KERN_DEBUG PFX "Erk, registering with no pci_dev!\n"); 295 printk (KERN_DEBUG PFX "Erk, registering with no pci_dev!\n");
293 return -EINVAL; 296 error = -EINVAL;
297 goto err_put_bridge;
294 } 298 }
295 299
296 /* Grab reference on the chipset driver. */ 300 /* Grab reference on the chipset driver. */
297 if (!try_module_get(bridge->driver->owner)) { 301 if (!try_module_get(bridge->driver->owner)) {
298 dev_info(&bridge->dev->dev, "can't lock chipset driver\n"); 302 dev_info(&bridge->dev->dev, "can't lock chipset driver\n");
299 return -EINVAL; 303 error = -EINVAL;
304 goto err_put_bridge;
300 } 305 }
301 306
302 error = agp_backend_initialize(bridge); 307 error = agp_backend_initialize(bridge);
@@ -326,6 +331,7 @@ frontend_err:
326 agp_backend_cleanup(bridge); 331 agp_backend_cleanup(bridge);
327err_out: 332err_out:
328 module_put(bridge->driver->owner); 333 module_put(bridge->driver->owner);
334err_put_bridge:
329 agp_put_bridge(bridge); 335 agp_put_bridge(bridge);
330 return error; 336 return error;
331} 337}
diff --git a/drivers/char/agp/compat_ioctl.c b/drivers/char/agp/compat_ioctl.c
index 58c57cb2518c..9d2c97a69cdd 100644
--- a/drivers/char/agp/compat_ioctl.c
+++ b/drivers/char/agp/compat_ioctl.c
@@ -30,6 +30,7 @@
30#include <linux/pci.h> 30#include <linux/pci.h>
31#include <linux/fs.h> 31#include <linux/fs.h>
32#include <linux/agpgart.h> 32#include <linux/agpgart.h>
33#include <linux/slab.h>
33#include <asm/uaccess.h> 34#include <asm/uaccess.h>
34#include "agp.h" 35#include "agp.h"
35#include "compat_ioctl.h" 36#include "compat_ioctl.h"
diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
index a96f3197e60f..43412c03969e 100644
--- a/drivers/char/agp/frontend.c
+++ b/drivers/char/agp/frontend.c
@@ -676,25 +676,25 @@ static int agp_open(struct inode *inode, struct file *file)
676 int minor = iminor(inode); 676 int minor = iminor(inode);
677 struct agp_file_private *priv; 677 struct agp_file_private *priv;
678 struct agp_client *client; 678 struct agp_client *client;
679 int rc = -ENXIO;
680
681 lock_kernel();
682 mutex_lock(&(agp_fe.agp_mutex));
683 679
684 if (minor != AGPGART_MINOR) 680 if (minor != AGPGART_MINOR)
685 goto err_out; 681 return -ENXIO;
682
683 mutex_lock(&(agp_fe.agp_mutex));
686 684
687 priv = kzalloc(sizeof(struct agp_file_private), GFP_KERNEL); 685 priv = kzalloc(sizeof(struct agp_file_private), GFP_KERNEL);
688 if (priv == NULL) 686 if (priv == NULL) {
689 goto err_out_nomem; 687 mutex_unlock(&(agp_fe.agp_mutex));
688 return -ENOMEM;
689 }
690 690
691 set_bit(AGP_FF_ALLOW_CLIENT, &priv->access_flags); 691 set_bit(AGP_FF_ALLOW_CLIENT, &priv->access_flags);
692 priv->my_pid = current->pid; 692 priv->my_pid = current->pid;
693 693
694 if (capable(CAP_SYS_RAWIO)) { 694 if (capable(CAP_SYS_RAWIO))
695 /* Root priv, can be controller */ 695 /* Root priv, can be controller */
696 set_bit(AGP_FF_ALLOW_CONTROLLER, &priv->access_flags); 696 set_bit(AGP_FF_ALLOW_CONTROLLER, &priv->access_flags);
697 } 697
698 client = agp_find_client_by_pid(current->pid); 698 client = agp_find_client_by_pid(current->pid);
699 699
700 if (client != NULL) { 700 if (client != NULL) {
@@ -704,16 +704,10 @@ static int agp_open(struct inode *inode, struct file *file)
704 file->private_data = (void *) priv; 704 file->private_data = (void *) priv;
705 agp_insert_file_private(priv); 705 agp_insert_file_private(priv);
706 DBG("private=%p, client=%p", priv, client); 706 DBG("private=%p, client=%p", priv, client);
707 mutex_unlock(&(agp_fe.agp_mutex));
708 unlock_kernel();
709 return 0;
710 707
711err_out_nomem:
712 rc = -ENOMEM;
713err_out:
714 mutex_unlock(&(agp_fe.agp_mutex)); 708 mutex_unlock(&(agp_fe.agp_mutex));
715 unlock_kernel(); 709
716 return rc; 710 return 0;
717} 711}
718 712
719 713
diff --git a/drivers/char/agp/generic.c b/drivers/char/agp/generic.c
index c50543966eb2..fb86708e47ed 100644
--- a/drivers/char/agp/generic.c
+++ b/drivers/char/agp/generic.c
@@ -38,6 +38,7 @@
38#include <linux/dma-mapping.h> 38#include <linux/dma-mapping.h>
39#include <linux/mm.h> 39#include <linux/mm.h>
40#include <linux/sched.h> 40#include <linux/sched.h>
41#include <linux/slab.h>
41#include <asm/io.h> 42#include <asm/io.h>
42#include <asm/cacheflush.h> 43#include <asm/cacheflush.h>
43#include <asm/pgtable.h> 44#include <asm/pgtable.h>
diff --git a/drivers/char/agp/hp-agp.c b/drivers/char/agp/hp-agp.c
index 9047b2714653..056b289a1e89 100644
--- a/drivers/char/agp/hp-agp.c
+++ b/drivers/char/agp/hp-agp.c
@@ -15,6 +15,7 @@
15#include <linux/init.h> 15#include <linux/init.h>
16#include <linux/agp_backend.h> 16#include <linux/agp_backend.h>
17#include <linux/log2.h> 17#include <linux/log2.h>
18#include <linux/slab.h>
18 19
19#include <asm/acpi-ext.h> 20#include <asm/acpi-ext.h>
20 21
@@ -488,9 +489,8 @@ zx1_gart_probe (acpi_handle obj, u32 depth, void *context, void **ret)
488 handle = obj; 489 handle = obj;
489 do { 490 do {
490 status = acpi_get_object_info(handle, &info); 491 status = acpi_get_object_info(handle, &info);
491 if (ACPI_SUCCESS(status)) { 492 if (ACPI_SUCCESS(status) && (info->valid & ACPI_VALID_HID)) {
492 /* TBD check _CID also */ 493 /* TBD check _CID also */
493 info->hardware_id.string[sizeof(info->hardware_id.length)-1] = '\0';
494 match = (strcmp(info->hardware_id.string, "HWP0001") == 0); 494 match = (strcmp(info->hardware_id.string, "HWP0001") == 0);
495 kfree(info); 495 kfree(info);
496 if (match) { 496 if (match) {
@@ -509,6 +509,9 @@ zx1_gart_probe (acpi_handle obj, u32 depth, void *context, void **ret)
509 handle = parent; 509 handle = parent;
510 } while (ACPI_SUCCESS(status)); 510 } while (ACPI_SUCCESS(status));
511 511
512 if (ACPI_FAILURE(status))
513 return AE_OK; /* found no enclosing IOC */
514
512 if (hp_zx1_setup(sba_hpa + HP_ZX1_IOC_OFFSET, lba_hpa)) 515 if (hp_zx1_setup(sba_hpa + HP_ZX1_IOC_OFFSET, lba_hpa))
513 return AE_OK; 516 return AE_OK;
514 517
diff --git a/drivers/char/agp/intel-agp.c b/drivers/char/agp/intel-agp.c
index 3cb56a049e24..aa4248efc5d8 100644
--- a/drivers/char/agp/intel-agp.c
+++ b/drivers/char/agp/intel-agp.c
@@ -4,12 +4,17 @@
4 4
5#include <linux/module.h> 5#include <linux/module.h>
6#include <linux/pci.h> 6#include <linux/pci.h>
7#include <linux/slab.h>
7#include <linux/init.h> 8#include <linux/init.h>
8#include <linux/kernel.h> 9#include <linux/kernel.h>
9#include <linux/pagemap.h> 10#include <linux/pagemap.h>
10#include <linux/agp_backend.h> 11#include <linux/agp_backend.h>
12#include <asm/smp.h>
11#include "agp.h" 13#include "agp.h"
12 14
15int intel_agp_enabled;
16EXPORT_SYMBOL(intel_agp_enabled);
17
13/* 18/*
14 * If we have Intel graphics, we're not going to have anything other than 19 * If we have Intel graphics, we're not going to have anything other than
15 * an Intel IOMMU. So make the correct use of the PCI DMA API contingent 20 * an Intel IOMMU. So make the correct use of the PCI DMA API contingent
@@ -36,10 +41,10 @@
36#define PCI_DEVICE_ID_INTEL_82965GME_IG 0x2A12 41#define PCI_DEVICE_ID_INTEL_82965GME_IG 0x2A12
37#define PCI_DEVICE_ID_INTEL_82945GME_HB 0x27AC 42#define PCI_DEVICE_ID_INTEL_82945GME_HB 0x27AC
38#define PCI_DEVICE_ID_INTEL_82945GME_IG 0x27AE 43#define PCI_DEVICE_ID_INTEL_82945GME_IG 0x27AE
39#define PCI_DEVICE_ID_INTEL_IGDGM_HB 0xA010 44#define PCI_DEVICE_ID_INTEL_PINEVIEW_M_HB 0xA010
40#define PCI_DEVICE_ID_INTEL_IGDGM_IG 0xA011 45#define PCI_DEVICE_ID_INTEL_PINEVIEW_M_IG 0xA011
41#define PCI_DEVICE_ID_INTEL_IGDG_HB 0xA000 46#define PCI_DEVICE_ID_INTEL_PINEVIEW_HB 0xA000
42#define PCI_DEVICE_ID_INTEL_IGDG_IG 0xA001 47#define PCI_DEVICE_ID_INTEL_PINEVIEW_IG 0xA001
43#define PCI_DEVICE_ID_INTEL_G33_HB 0x29C0 48#define PCI_DEVICE_ID_INTEL_G33_HB 0x29C0
44#define PCI_DEVICE_ID_INTEL_G33_IG 0x29C2 49#define PCI_DEVICE_ID_INTEL_G33_IG 0x29C2
45#define PCI_DEVICE_ID_INTEL_Q35_HB 0x29B0 50#define PCI_DEVICE_ID_INTEL_Q35_HB 0x29B0
@@ -50,20 +55,24 @@
50#define PCI_DEVICE_ID_INTEL_B43_IG 0x2E42 55#define PCI_DEVICE_ID_INTEL_B43_IG 0x2E42
51#define PCI_DEVICE_ID_INTEL_GM45_HB 0x2A40 56#define PCI_DEVICE_ID_INTEL_GM45_HB 0x2A40
52#define PCI_DEVICE_ID_INTEL_GM45_IG 0x2A42 57#define PCI_DEVICE_ID_INTEL_GM45_IG 0x2A42
53#define PCI_DEVICE_ID_INTEL_IGD_E_HB 0x2E00 58#define PCI_DEVICE_ID_INTEL_EAGLELAKE_HB 0x2E00
54#define PCI_DEVICE_ID_INTEL_IGD_E_IG 0x2E02 59#define PCI_DEVICE_ID_INTEL_EAGLELAKE_IG 0x2E02
55#define PCI_DEVICE_ID_INTEL_Q45_HB 0x2E10 60#define PCI_DEVICE_ID_INTEL_Q45_HB 0x2E10
56#define PCI_DEVICE_ID_INTEL_Q45_IG 0x2E12 61#define PCI_DEVICE_ID_INTEL_Q45_IG 0x2E12
57#define PCI_DEVICE_ID_INTEL_G45_HB 0x2E20 62#define PCI_DEVICE_ID_INTEL_G45_HB 0x2E20
58#define PCI_DEVICE_ID_INTEL_G45_IG 0x2E22 63#define PCI_DEVICE_ID_INTEL_G45_IG 0x2E22
59#define PCI_DEVICE_ID_INTEL_G41_HB 0x2E30 64#define PCI_DEVICE_ID_INTEL_G41_HB 0x2E30
60#define PCI_DEVICE_ID_INTEL_G41_IG 0x2E32 65#define PCI_DEVICE_ID_INTEL_G41_IG 0x2E32
61#define PCI_DEVICE_ID_INTEL_IGDNG_D_HB 0x0040 66#define PCI_DEVICE_ID_INTEL_IRONLAKE_D_HB 0x0040
62#define PCI_DEVICE_ID_INTEL_IGDNG_D_IG 0x0042 67#define PCI_DEVICE_ID_INTEL_IRONLAKE_D_IG 0x0042
63#define PCI_DEVICE_ID_INTEL_IGDNG_M_HB 0x0044 68#define PCI_DEVICE_ID_INTEL_IRONLAKE_M_HB 0x0044
64#define PCI_DEVICE_ID_INTEL_IGDNG_MA_HB 0x0062 69#define PCI_DEVICE_ID_INTEL_IRONLAKE_MA_HB 0x0062
65#define PCI_DEVICE_ID_INTEL_IGDNG_MC2_HB 0x006a 70#define PCI_DEVICE_ID_INTEL_IRONLAKE_MC2_HB 0x006a
66#define PCI_DEVICE_ID_INTEL_IGDNG_M_IG 0x0046 71#define PCI_DEVICE_ID_INTEL_IRONLAKE_M_IG 0x0046
72#define PCI_DEVICE_ID_INTEL_SANDYBRIDGE_HB 0x0100
73#define PCI_DEVICE_ID_INTEL_SANDYBRIDGE_IG 0x0102
74#define PCI_DEVICE_ID_INTEL_SANDYBRIDGE_M_HB 0x0104
75#define PCI_DEVICE_ID_INTEL_SANDYBRIDGE_M_IG 0x0106
67 76
68/* cover 915 and 945 variants */ 77/* cover 915 and 945 variants */
69#define IS_I915 (agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_E7221_HB || \ 78#define IS_I915 (agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_E7221_HB || \
@@ -83,22 +92,26 @@
83#define IS_G33 (agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_G33_HB || \ 92#define IS_G33 (agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_G33_HB || \
84 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_Q35_HB || \ 93 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_Q35_HB || \
85 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_Q33_HB || \ 94 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_Q33_HB || \
86 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_IGDGM_HB || \ 95 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_PINEVIEW_M_HB || \
87 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_IGDG_HB) 96 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_PINEVIEW_HB)
97
98#define IS_PINEVIEW (agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_PINEVIEW_M_HB || \
99 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_PINEVIEW_HB)
88 100
89#define IS_IGD (agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_IGDGM_HB || \ 101#define IS_SNB (agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_SANDYBRIDGE_HB || \
90 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_IGDG_HB) 102 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_SANDYBRIDGE_M_HB)
91 103
92#define IS_G4X (agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_IGD_E_HB || \ 104#define IS_G4X (agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_EAGLELAKE_HB || \
93 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_Q45_HB || \ 105 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_Q45_HB || \
94 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_G45_HB || \ 106 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_G45_HB || \
95 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_GM45_HB || \ 107 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_GM45_HB || \
96 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_G41_HB || \ 108 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_G41_HB || \
97 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_B43_HB || \ 109 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_B43_HB || \
98 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_IGDNG_D_HB || \ 110 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_IRONLAKE_D_HB || \
99 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_IGDNG_M_HB || \ 111 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_IRONLAKE_M_HB || \
100 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_IGDNG_MA_HB || \ 112 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_IRONLAKE_MA_HB || \
101 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_IGDNG_MC2_HB) 113 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_IRONLAKE_MC2_HB || \
114 IS_SNB)
102 115
103extern int agp_memory_reserved; 116extern int agp_memory_reserved;
104 117
@@ -147,6 +160,29 @@ extern int agp_memory_reserved;
147#define INTEL_I7505_AGPCTRL 0x70 160#define INTEL_I7505_AGPCTRL 0x70
148#define INTEL_I7505_MCHCFG 0x50 161#define INTEL_I7505_MCHCFG 0x50
149 162
163#define SNB_GMCH_CTRL 0x50
164#define SNB_GMCH_GMS_STOLEN_MASK 0xF8
165#define SNB_GMCH_GMS_STOLEN_32M (1 << 3)
166#define SNB_GMCH_GMS_STOLEN_64M (2 << 3)
167#define SNB_GMCH_GMS_STOLEN_96M (3 << 3)
168#define SNB_GMCH_GMS_STOLEN_128M (4 << 3)
169#define SNB_GMCH_GMS_STOLEN_160M (5 << 3)
170#define SNB_GMCH_GMS_STOLEN_192M (6 << 3)
171#define SNB_GMCH_GMS_STOLEN_224M (7 << 3)
172#define SNB_GMCH_GMS_STOLEN_256M (8 << 3)
173#define SNB_GMCH_GMS_STOLEN_288M (9 << 3)
174#define SNB_GMCH_GMS_STOLEN_320M (0xa << 3)
175#define SNB_GMCH_GMS_STOLEN_352M (0xb << 3)
176#define SNB_GMCH_GMS_STOLEN_384M (0xc << 3)
177#define SNB_GMCH_GMS_STOLEN_416M (0xd << 3)
178#define SNB_GMCH_GMS_STOLEN_448M (0xe << 3)
179#define SNB_GMCH_GMS_STOLEN_480M (0xf << 3)
180#define SNB_GMCH_GMS_STOLEN_512M (0x10 << 3)
181#define SNB_GTT_SIZE_0M (0 << 8)
182#define SNB_GTT_SIZE_1M (1 << 8)
183#define SNB_GTT_SIZE_2M (2 << 8)
184#define SNB_GTT_SIZE_MASK (3 << 8)
185
150static const struct aper_size_info_fixed intel_i810_sizes[] = 186static const struct aper_size_info_fixed intel_i810_sizes[] =
151{ 187{
152 {64, 16384, 4}, 188 {64, 16384, 4},
@@ -178,6 +214,7 @@ static struct _intel_private {
178 * popup and for the GTT. 214 * popup and for the GTT.
179 */ 215 */
180 int gtt_entries; /* i830+ */ 216 int gtt_entries; /* i830+ */
217 int gtt_total_size;
181 union { 218 union {
182 void __iomem *i9xx_flush_page; 219 void __iomem *i9xx_flush_page;
183 void *i8xx_flush_page; 220 void *i8xx_flush_page;
@@ -268,7 +305,7 @@ static void intel_agp_insert_sg_entries(struct agp_memory *mem,
268 j++; 305 j++;
269 } 306 }
270 } else { 307 } else {
271 /* sg may merge pages, but we have to seperate 308 /* sg may merge pages, but we have to separate
272 * per-page addr for GTT */ 309 * per-page addr for GTT */
273 unsigned int len, m; 310 unsigned int len, m;
274 311
@@ -292,6 +329,13 @@ static void intel_agp_insert_sg_entries(struct agp_memory *mem,
292 off_t pg_start, int mask_type) 329 off_t pg_start, int mask_type)
293{ 330{
294 int i, j; 331 int i, j;
332 u32 cache_bits = 0;
333
334 if (agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_SANDYBRIDGE_HB ||
335 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_SANDYBRIDGE_M_HB)
336 {
337 cache_bits = I830_PTE_SYSTEM_CACHED;
338 }
295 339
296 for (i = 0, j = pg_start; i < mem->page_count; i++, j++) { 340 for (i = 0, j = pg_start; i < mem->page_count; i++, j++) {
297 writel(agp_bridge->driver->mask_memory(agp_bridge, 341 writel(agp_bridge->driver->mask_memory(agp_bridge,
@@ -612,7 +656,7 @@ static struct aper_size_info_fixed intel_i830_sizes[] =
612static void intel_i830_init_gtt_entries(void) 656static void intel_i830_init_gtt_entries(void)
613{ 657{
614 u16 gmch_ctrl; 658 u16 gmch_ctrl;
615 int gtt_entries; 659 int gtt_entries = 0;
616 u8 rdct; 660 u8 rdct;
617 int local = 0; 661 int local = 0;
618 static const int ddt[4] = { 0, 16, 32, 64 }; 662 static const int ddt[4] = { 0, 16, 32, 64 };
@@ -653,7 +697,7 @@ static void intel_i830_init_gtt_entries(void)
653 size = 512; 697 size = 512;
654 } 698 }
655 size += 4; /* add in BIOS popup space */ 699 size += 4; /* add in BIOS popup space */
656 } else if (IS_G33 && !IS_IGD) { 700 } else if (IS_G33 && !IS_PINEVIEW) {
657 /* G33's GTT size defined in gmch_ctrl */ 701 /* G33's GTT size defined in gmch_ctrl */
658 switch (gmch_ctrl & G33_PGETBL_SIZE_MASK) { 702 switch (gmch_ctrl & G33_PGETBL_SIZE_MASK) {
659 case G33_PGETBL_SIZE_1M: 703 case G33_PGETBL_SIZE_1M:
@@ -669,7 +713,7 @@ static void intel_i830_init_gtt_entries(void)
669 size = 512; 713 size = 512;
670 } 714 }
671 size += 4; 715 size += 4;
672 } else if (IS_G4X || IS_IGD) { 716 } else if (IS_G4X || IS_PINEVIEW) {
673 /* On 4 series hardware, GTT stolen is separate from graphics 717 /* On 4 series hardware, GTT stolen is separate from graphics
674 * stolen, ignore it in stolen gtt entries counting. However, 718 * stolen, ignore it in stolen gtt entries counting. However,
675 * 4KB of the stolen memory doesn't get mapped to the GTT. 719 * 4KB of the stolen memory doesn't get mapped to the GTT.
@@ -704,6 +748,63 @@ static void intel_i830_init_gtt_entries(void)
704 gtt_entries = 0; 748 gtt_entries = 0;
705 break; 749 break;
706 } 750 }
751 } else if (agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_SANDYBRIDGE_HB ||
752 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_SANDYBRIDGE_M_HB) {
753 /*
754 * SandyBridge has new memory control reg at 0x50.w
755 */
756 u16 snb_gmch_ctl;
757 pci_read_config_word(intel_private.pcidev, SNB_GMCH_CTRL, &snb_gmch_ctl);
758 switch (snb_gmch_ctl & SNB_GMCH_GMS_STOLEN_MASK) {
759 case SNB_GMCH_GMS_STOLEN_32M:
760 gtt_entries = MB(32) - KB(size);
761 break;
762 case SNB_GMCH_GMS_STOLEN_64M:
763 gtt_entries = MB(64) - KB(size);
764 break;
765 case SNB_GMCH_GMS_STOLEN_96M:
766 gtt_entries = MB(96) - KB(size);
767 break;
768 case SNB_GMCH_GMS_STOLEN_128M:
769 gtt_entries = MB(128) - KB(size);
770 break;
771 case SNB_GMCH_GMS_STOLEN_160M:
772 gtt_entries = MB(160) - KB(size);
773 break;
774 case SNB_GMCH_GMS_STOLEN_192M:
775 gtt_entries = MB(192) - KB(size);
776 break;
777 case SNB_GMCH_GMS_STOLEN_224M:
778 gtt_entries = MB(224) - KB(size);
779 break;
780 case SNB_GMCH_GMS_STOLEN_256M:
781 gtt_entries = MB(256) - KB(size);
782 break;
783 case SNB_GMCH_GMS_STOLEN_288M:
784 gtt_entries = MB(288) - KB(size);
785 break;
786 case SNB_GMCH_GMS_STOLEN_320M:
787 gtt_entries = MB(320) - KB(size);
788 break;
789 case SNB_GMCH_GMS_STOLEN_352M:
790 gtt_entries = MB(352) - KB(size);
791 break;
792 case SNB_GMCH_GMS_STOLEN_384M:
793 gtt_entries = MB(384) - KB(size);
794 break;
795 case SNB_GMCH_GMS_STOLEN_416M:
796 gtt_entries = MB(416) - KB(size);
797 break;
798 case SNB_GMCH_GMS_STOLEN_448M:
799 gtt_entries = MB(448) - KB(size);
800 break;
801 case SNB_GMCH_GMS_STOLEN_480M:
802 gtt_entries = MB(480) - KB(size);
803 break;
804 case SNB_GMCH_GMS_STOLEN_512M:
805 gtt_entries = MB(512) - KB(size);
806 break;
807 }
707 } else { 808 } else {
708 switch (gmch_ctrl & I855_GMCH_GMS_MASK) { 809 switch (gmch_ctrl & I855_GMCH_GMS_MASK) {
709 case I855_GMCH_GMS_STOLEN_1M: 810 case I855_GMCH_GMS_STOLEN_1M:
@@ -814,12 +915,6 @@ static void intel_i830_setup_flush(void)
814 intel_i830_fini_flush(); 915 intel_i830_fini_flush();
815} 916}
816 917
817static void
818do_wbinvd(void *null)
819{
820 wbinvd();
821}
822
823/* The chipset_flush interface needs to get data that has already been 918/* The chipset_flush interface needs to get data that has already been
824 * flushed out of the CPU all the way out to main memory, because the GPU 919 * flushed out of the CPU all the way out to main memory, because the GPU
825 * doesn't snoop those buffers. 920 * doesn't snoop those buffers.
@@ -836,12 +931,10 @@ static void intel_i830_chipset_flush(struct agp_bridge_data *bridge)
836 931
837 memset(pg, 0, 1024); 932 memset(pg, 0, 1024);
838 933
839 if (cpu_has_clflush) { 934 if (cpu_has_clflush)
840 clflush_cache_range(pg, 1024); 935 clflush_cache_range(pg, 1024);
841 } else { 936 else if (wbinvd_on_all_cpus() != 0)
842 if (on_each_cpu(do_wbinvd, NULL, 1) != 0) 937 printk(KERN_ERR "Timed out waiting for cache flush.\n");
843 printk(KERN_ERR "Timed out waiting for cache flush.\n");
844 }
845} 938}
846 939
847/* The intel i830 automatically initializes the agp aperture during POST. 940/* The intel i830 automatically initializes the agp aperture during POST.
@@ -1114,6 +1207,9 @@ static void intel_i9xx_setup_flush(void)
1114 if (intel_private.ifp_resource.start) 1207 if (intel_private.ifp_resource.start)
1115 return; 1208 return;
1116 1209
1210 if (IS_SNB)
1211 return;
1212
1117 /* setup a resource for this object */ 1213 /* setup a resource for this object */
1118 intel_private.ifp_resource.name = "Intel Flush Page"; 1214 intel_private.ifp_resource.name = "Intel Flush Page";
1119 intel_private.ifp_resource.flags = IORESOURCE_MEM; 1215 intel_private.ifp_resource.flags = IORESOURCE_MEM;
@@ -1153,7 +1249,7 @@ static int intel_i915_configure(void)
1153 readl(intel_private.registers+I810_PGETBL_CTL); /* PCI Posting. */ 1249 readl(intel_private.registers+I810_PGETBL_CTL); /* PCI Posting. */
1154 1250
1155 if (agp_bridge->driver->needs_scratch_page) { 1251 if (agp_bridge->driver->needs_scratch_page) {
1156 for (i = intel_private.gtt_entries; i < current_size->num_entries; i++) { 1252 for (i = intel_private.gtt_entries; i < intel_private.gtt_total_size; i++) {
1157 writel(agp_bridge->scratch_page, intel_private.gtt+i); 1253 writel(agp_bridge->scratch_page, intel_private.gtt+i);
1158 } 1254 }
1159 readl(intel_private.gtt+i-1); /* PCI Posting. */ 1255 readl(intel_private.gtt+i-1); /* PCI Posting. */
@@ -1308,6 +1404,8 @@ static int intel_i915_create_gatt_table(struct agp_bridge_data *bridge)
1308 if (!intel_private.gtt) 1404 if (!intel_private.gtt)
1309 return -ENOMEM; 1405 return -ENOMEM;
1310 1406
1407 intel_private.gtt_total_size = gtt_map_size / 4;
1408
1311 temp &= 0xfff80000; 1409 temp &= 0xfff80000;
1312 1410
1313 intel_private.registers = ioremap(temp, 128 * 4096); 1411 intel_private.registers = ioremap(temp, 128 * 4096);
@@ -1350,19 +1448,40 @@ static unsigned long intel_i965_mask_memory(struct agp_bridge_data *bridge,
1350 1448
1351static void intel_i965_get_gtt_range(int *gtt_offset, int *gtt_size) 1449static void intel_i965_get_gtt_range(int *gtt_offset, int *gtt_size)
1352{ 1450{
1451 u16 snb_gmch_ctl;
1452
1353 switch (agp_bridge->dev->device) { 1453 switch (agp_bridge->dev->device) {
1354 case PCI_DEVICE_ID_INTEL_GM45_HB: 1454 case PCI_DEVICE_ID_INTEL_GM45_HB:
1355 case PCI_DEVICE_ID_INTEL_IGD_E_HB: 1455 case PCI_DEVICE_ID_INTEL_EAGLELAKE_HB:
1356 case PCI_DEVICE_ID_INTEL_Q45_HB: 1456 case PCI_DEVICE_ID_INTEL_Q45_HB:
1357 case PCI_DEVICE_ID_INTEL_G45_HB: 1457 case PCI_DEVICE_ID_INTEL_G45_HB:
1358 case PCI_DEVICE_ID_INTEL_G41_HB: 1458 case PCI_DEVICE_ID_INTEL_G41_HB:
1359 case PCI_DEVICE_ID_INTEL_B43_HB: 1459 case PCI_DEVICE_ID_INTEL_B43_HB:
1360 case PCI_DEVICE_ID_INTEL_IGDNG_D_HB: 1460 case PCI_DEVICE_ID_INTEL_IRONLAKE_D_HB:
1361 case PCI_DEVICE_ID_INTEL_IGDNG_M_HB: 1461 case PCI_DEVICE_ID_INTEL_IRONLAKE_M_HB:
1362 case PCI_DEVICE_ID_INTEL_IGDNG_MA_HB: 1462 case PCI_DEVICE_ID_INTEL_IRONLAKE_MA_HB:
1363 case PCI_DEVICE_ID_INTEL_IGDNG_MC2_HB: 1463 case PCI_DEVICE_ID_INTEL_IRONLAKE_MC2_HB:
1364 *gtt_offset = *gtt_size = MB(2); 1464 *gtt_offset = *gtt_size = MB(2);
1365 break; 1465 break;
1466 case PCI_DEVICE_ID_INTEL_SANDYBRIDGE_HB:
1467 case PCI_DEVICE_ID_INTEL_SANDYBRIDGE_M_HB:
1468 *gtt_offset = MB(2);
1469
1470 pci_read_config_word(intel_private.pcidev, SNB_GMCH_CTRL, &snb_gmch_ctl);
1471 switch (snb_gmch_ctl & SNB_GTT_SIZE_MASK) {
1472 default:
1473 case SNB_GTT_SIZE_0M:
1474 printk(KERN_ERR "Bad GTT size mask: 0x%04x.\n", snb_gmch_ctl);
1475 *gtt_size = MB(0);
1476 break;
1477 case SNB_GTT_SIZE_1M:
1478 *gtt_size = MB(1);
1479 break;
1480 case SNB_GTT_SIZE_2M:
1481 *gtt_size = MB(2);
1482 break;
1483 }
1484 break;
1366 default: 1485 default:
1367 *gtt_offset = *gtt_size = KB(512); 1486 *gtt_offset = *gtt_size = KB(512);
1368 } 1487 }
@@ -1395,6 +1514,8 @@ static int intel_i965_create_gatt_table(struct agp_bridge_data *bridge)
1395 if (!intel_private.gtt) 1514 if (!intel_private.gtt)
1396 return -ENOMEM; 1515 return -ENOMEM;
1397 1516
1517 intel_private.gtt_total_size = gtt_size / 4;
1518
1398 intel_private.registers = ioremap(temp, 128 * 4096); 1519 intel_private.registers = ioremap(temp, 128 * 4096);
1399 if (!intel_private.registers) { 1520 if (!intel_private.registers) {
1400 iounmap(intel_private.gtt); 1521 iounmap(intel_private.gtt);
@@ -1696,8 +1817,6 @@ static int intel_845_configure(void)
1696 pci_write_config_byte(agp_bridge->dev, INTEL_I845_AGPM, temp2 | (1 << 1)); 1817 pci_write_config_byte(agp_bridge->dev, INTEL_I845_AGPM, temp2 | (1 << 1));
1697 /* clear any possible error conditions */ 1818 /* clear any possible error conditions */
1698 pci_write_config_word(agp_bridge->dev, INTEL_I845_ERRSTS, 0x001c); 1819 pci_write_config_word(agp_bridge->dev, INTEL_I845_ERRSTS, 0x001c);
1699
1700 intel_i830_setup_flush();
1701 return 0; 1820 return 0;
1702} 1821}
1703 1822
@@ -2067,7 +2186,6 @@ static const struct agp_bridge_driver intel_845_driver = {
2067 .agp_destroy_page = agp_generic_destroy_page, 2186 .agp_destroy_page = agp_generic_destroy_page,
2068 .agp_destroy_pages = agp_generic_destroy_pages, 2187 .agp_destroy_pages = agp_generic_destroy_pages,
2069 .agp_type_to_mask_type = agp_generic_type_to_mask_type, 2188 .agp_type_to_mask_type = agp_generic_type_to_mask_type,
2070 .chipset_flush = intel_i830_chipset_flush,
2071}; 2189};
2072 2190
2073static const struct agp_bridge_driver intel_850_driver = { 2191static const struct agp_bridge_driver intel_850_driver = {
@@ -2340,14 +2458,14 @@ static const struct intel_driver_description {
2340 NULL, &intel_g33_driver }, 2458 NULL, &intel_g33_driver },
2341 { PCI_DEVICE_ID_INTEL_Q33_HB, PCI_DEVICE_ID_INTEL_Q33_IG, 0, "Q33", 2459 { PCI_DEVICE_ID_INTEL_Q33_HB, PCI_DEVICE_ID_INTEL_Q33_IG, 0, "Q33",
2342 NULL, &intel_g33_driver }, 2460 NULL, &intel_g33_driver },
2343 { PCI_DEVICE_ID_INTEL_IGDGM_HB, PCI_DEVICE_ID_INTEL_IGDGM_IG, 0, "IGD", 2461 { PCI_DEVICE_ID_INTEL_PINEVIEW_M_HB, PCI_DEVICE_ID_INTEL_PINEVIEW_M_IG, 0, "GMA3150",
2344 NULL, &intel_g33_driver }, 2462 NULL, &intel_g33_driver },
2345 { PCI_DEVICE_ID_INTEL_IGDG_HB, PCI_DEVICE_ID_INTEL_IGDG_IG, 0, "IGD", 2463 { PCI_DEVICE_ID_INTEL_PINEVIEW_HB, PCI_DEVICE_ID_INTEL_PINEVIEW_IG, 0, "GMA3150",
2346 NULL, &intel_g33_driver }, 2464 NULL, &intel_g33_driver },
2347 { PCI_DEVICE_ID_INTEL_GM45_HB, PCI_DEVICE_ID_INTEL_GM45_IG, 0, 2465 { PCI_DEVICE_ID_INTEL_GM45_HB, PCI_DEVICE_ID_INTEL_GM45_IG, 0,
2348 "Mobile Intel® GM45 Express", NULL, &intel_i965_driver }, 2466 "GM45", NULL, &intel_i965_driver },
2349 { PCI_DEVICE_ID_INTEL_IGD_E_HB, PCI_DEVICE_ID_INTEL_IGD_E_IG, 0, 2467 { PCI_DEVICE_ID_INTEL_EAGLELAKE_HB, PCI_DEVICE_ID_INTEL_EAGLELAKE_IG, 0,
2350 "Intel Integrated Graphics Device", NULL, &intel_i965_driver }, 2468 "Eaglelake", NULL, &intel_i965_driver },
2351 { PCI_DEVICE_ID_INTEL_Q45_HB, PCI_DEVICE_ID_INTEL_Q45_IG, 0, 2469 { PCI_DEVICE_ID_INTEL_Q45_HB, PCI_DEVICE_ID_INTEL_Q45_IG, 0,
2352 "Q45/Q43", NULL, &intel_i965_driver }, 2470 "Q45/Q43", NULL, &intel_i965_driver },
2353 { PCI_DEVICE_ID_INTEL_G45_HB, PCI_DEVICE_ID_INTEL_G45_IG, 0, 2471 { PCI_DEVICE_ID_INTEL_G45_HB, PCI_DEVICE_ID_INTEL_G45_IG, 0,
@@ -2356,14 +2474,18 @@ static const struct intel_driver_description {
2356 "B43", NULL, &intel_i965_driver }, 2474 "B43", NULL, &intel_i965_driver },
2357 { PCI_DEVICE_ID_INTEL_G41_HB, PCI_DEVICE_ID_INTEL_G41_IG, 0, 2475 { PCI_DEVICE_ID_INTEL_G41_HB, PCI_DEVICE_ID_INTEL_G41_IG, 0,
2358 "G41", NULL, &intel_i965_driver }, 2476 "G41", NULL, &intel_i965_driver },
2359 { PCI_DEVICE_ID_INTEL_IGDNG_D_HB, PCI_DEVICE_ID_INTEL_IGDNG_D_IG, 0, 2477 { PCI_DEVICE_ID_INTEL_IRONLAKE_D_HB, PCI_DEVICE_ID_INTEL_IRONLAKE_D_IG, 0,
2360 "IGDNG/D", NULL, &intel_i965_driver }, 2478 "HD Graphics", NULL, &intel_i965_driver },
2361 { PCI_DEVICE_ID_INTEL_IGDNG_M_HB, PCI_DEVICE_ID_INTEL_IGDNG_M_IG, 0, 2479 { PCI_DEVICE_ID_INTEL_IRONLAKE_M_HB, PCI_DEVICE_ID_INTEL_IRONLAKE_M_IG, 0,
2362 "IGDNG/M", NULL, &intel_i965_driver }, 2480 "HD Graphics", NULL, &intel_i965_driver },
2363 { PCI_DEVICE_ID_INTEL_IGDNG_MA_HB, PCI_DEVICE_ID_INTEL_IGDNG_M_IG, 0, 2481 { PCI_DEVICE_ID_INTEL_IRONLAKE_MA_HB, PCI_DEVICE_ID_INTEL_IRONLAKE_M_IG, 0,
2364 "IGDNG/MA", NULL, &intel_i965_driver }, 2482 "HD Graphics", NULL, &intel_i965_driver },
2365 { PCI_DEVICE_ID_INTEL_IGDNG_MC2_HB, PCI_DEVICE_ID_INTEL_IGDNG_M_IG, 0, 2483 { PCI_DEVICE_ID_INTEL_IRONLAKE_MC2_HB, PCI_DEVICE_ID_INTEL_IRONLAKE_M_IG, 0,
2366 "IGDNG/MC2", NULL, &intel_i965_driver }, 2484 "HD Graphics", NULL, &intel_i965_driver },
2485 { PCI_DEVICE_ID_INTEL_SANDYBRIDGE_HB, PCI_DEVICE_ID_INTEL_SANDYBRIDGE_IG, 0,
2486 "Sandybridge", NULL, &intel_i965_driver },
2487 { PCI_DEVICE_ID_INTEL_SANDYBRIDGE_M_HB, PCI_DEVICE_ID_INTEL_SANDYBRIDGE_M_IG, 0,
2488 "Sandybridge", NULL, &intel_i965_driver },
2367 { 0, 0, 0, NULL, NULL, NULL } 2489 { 0, 0, 0, NULL, NULL, NULL }
2368}; 2490};
2369 2491
@@ -2373,7 +2495,7 @@ static int __devinit agp_intel_probe(struct pci_dev *pdev,
2373 struct agp_bridge_data *bridge; 2495 struct agp_bridge_data *bridge;
2374 u8 cap_ptr = 0; 2496 u8 cap_ptr = 0;
2375 struct resource *r; 2497 struct resource *r;
2376 int i; 2498 int i, err;
2377 2499
2378 cap_ptr = pci_find_capability(pdev, PCI_CAP_ID_AGP); 2500 cap_ptr = pci_find_capability(pdev, PCI_CAP_ID_AGP);
2379 2501
@@ -2455,13 +2577,20 @@ static int __devinit agp_intel_probe(struct pci_dev *pdev,
2455 &bridge->mode); 2577 &bridge->mode);
2456 } 2578 }
2457 2579
2458 if (bridge->driver->mask_memory == intel_i965_mask_memory) 2580 if (bridge->driver->mask_memory == intel_i965_mask_memory) {
2459 if (pci_set_dma_mask(intel_private.pcidev, DMA_BIT_MASK(36))) 2581 if (pci_set_dma_mask(intel_private.pcidev, DMA_BIT_MASK(36)))
2460 dev_err(&intel_private.pcidev->dev, 2582 dev_err(&intel_private.pcidev->dev,
2461 "set gfx device dma mask 36bit failed!\n"); 2583 "set gfx device dma mask 36bit failed!\n");
2584 else
2585 pci_set_consistent_dma_mask(intel_private.pcidev,
2586 DMA_BIT_MASK(36));
2587 }
2462 2588
2463 pci_set_drvdata(pdev, bridge); 2589 pci_set_drvdata(pdev, bridge);
2464 return agp_add_bridge(bridge); 2590 err = agp_add_bridge(bridge);
2591 if (!err)
2592 intel_agp_enabled = 1;
2593 return err;
2465} 2594}
2466 2595
2467static void __devexit agp_intel_remove(struct pci_dev *pdev) 2596static void __devexit agp_intel_remove(struct pci_dev *pdev)
@@ -2545,8 +2674,8 @@ static struct pci_device_id agp_intel_pci_table[] = {
2545 ID(PCI_DEVICE_ID_INTEL_82945G_HB), 2674 ID(PCI_DEVICE_ID_INTEL_82945G_HB),
2546 ID(PCI_DEVICE_ID_INTEL_82945GM_HB), 2675 ID(PCI_DEVICE_ID_INTEL_82945GM_HB),
2547 ID(PCI_DEVICE_ID_INTEL_82945GME_HB), 2676 ID(PCI_DEVICE_ID_INTEL_82945GME_HB),
2548 ID(PCI_DEVICE_ID_INTEL_IGDGM_HB), 2677 ID(PCI_DEVICE_ID_INTEL_PINEVIEW_M_HB),
2549 ID(PCI_DEVICE_ID_INTEL_IGDG_HB), 2678 ID(PCI_DEVICE_ID_INTEL_PINEVIEW_HB),
2550 ID(PCI_DEVICE_ID_INTEL_82946GZ_HB), 2679 ID(PCI_DEVICE_ID_INTEL_82946GZ_HB),
2551 ID(PCI_DEVICE_ID_INTEL_82G35_HB), 2680 ID(PCI_DEVICE_ID_INTEL_82G35_HB),
2552 ID(PCI_DEVICE_ID_INTEL_82965Q_HB), 2681 ID(PCI_DEVICE_ID_INTEL_82965Q_HB),
@@ -2557,15 +2686,17 @@ static struct pci_device_id agp_intel_pci_table[] = {
2557 ID(PCI_DEVICE_ID_INTEL_Q35_HB), 2686 ID(PCI_DEVICE_ID_INTEL_Q35_HB),
2558 ID(PCI_DEVICE_ID_INTEL_Q33_HB), 2687 ID(PCI_DEVICE_ID_INTEL_Q33_HB),
2559 ID(PCI_DEVICE_ID_INTEL_GM45_HB), 2688 ID(PCI_DEVICE_ID_INTEL_GM45_HB),
2560 ID(PCI_DEVICE_ID_INTEL_IGD_E_HB), 2689 ID(PCI_DEVICE_ID_INTEL_EAGLELAKE_HB),
2561 ID(PCI_DEVICE_ID_INTEL_Q45_HB), 2690 ID(PCI_DEVICE_ID_INTEL_Q45_HB),
2562 ID(PCI_DEVICE_ID_INTEL_G45_HB), 2691 ID(PCI_DEVICE_ID_INTEL_G45_HB),
2563 ID(PCI_DEVICE_ID_INTEL_G41_HB), 2692 ID(PCI_DEVICE_ID_INTEL_G41_HB),
2564 ID(PCI_DEVICE_ID_INTEL_B43_HB), 2693 ID(PCI_DEVICE_ID_INTEL_B43_HB),
2565 ID(PCI_DEVICE_ID_INTEL_IGDNG_D_HB), 2694 ID(PCI_DEVICE_ID_INTEL_IRONLAKE_D_HB),
2566 ID(PCI_DEVICE_ID_INTEL_IGDNG_M_HB), 2695 ID(PCI_DEVICE_ID_INTEL_IRONLAKE_M_HB),
2567 ID(PCI_DEVICE_ID_INTEL_IGDNG_MA_HB), 2696 ID(PCI_DEVICE_ID_INTEL_IRONLAKE_MA_HB),
2568 ID(PCI_DEVICE_ID_INTEL_IGDNG_MC2_HB), 2697 ID(PCI_DEVICE_ID_INTEL_IRONLAKE_MC2_HB),
2698 ID(PCI_DEVICE_ID_INTEL_SANDYBRIDGE_HB),
2699 ID(PCI_DEVICE_ID_INTEL_SANDYBRIDGE_M_HB),
2569 { } 2700 { }
2570}; 2701};
2571 2702
diff --git a/drivers/char/agp/nvidia-agp.c b/drivers/char/agp/nvidia-agp.c
index 7e36d2b4f9d4..10f24e349a26 100644
--- a/drivers/char/agp/nvidia-agp.c
+++ b/drivers/char/agp/nvidia-agp.c
@@ -8,7 +8,6 @@
8#include <linux/pci.h> 8#include <linux/pci.h>
9#include <linux/init.h> 9#include <linux/init.h>
10#include <linux/agp_backend.h> 10#include <linux/agp_backend.h>
11#include <linux/gfp.h>
12#include <linux/page-flags.h> 11#include <linux/page-flags.h>
13#include <linux/mm.h> 12#include <linux/mm.h>
14#include <linux/jiffies.h> 13#include <linux/jiffies.h>
diff --git a/drivers/char/agp/sgi-agp.c b/drivers/char/agp/sgi-agp.c
index 0d426ae39c85..ffa888cd1c88 100644
--- a/drivers/char/agp/sgi-agp.c
+++ b/drivers/char/agp/sgi-agp.c
@@ -14,6 +14,7 @@
14#include <linux/acpi.h> 14#include <linux/acpi.h>
15#include <linux/module.h> 15#include <linux/module.h>
16#include <linux/pci.h> 16#include <linux/pci.h>
17#include <linux/slab.h>
17#include <linux/init.h> 18#include <linux/init.h>
18#include <linux/agp_backend.h> 19#include <linux/agp_backend.h>
19#include <asm/sn/addrs.h> 20#include <asm/sn/addrs.h>
diff --git a/drivers/char/agp/uninorth-agp.c b/drivers/char/agp/uninorth-agp.c
index 703959eba45a..6f48931ac1ce 100644
--- a/drivers/char/agp/uninorth-agp.c
+++ b/drivers/char/agp/uninorth-agp.c
@@ -3,6 +3,7 @@
3 */ 3 */
4#include <linux/module.h> 4#include <linux/module.h>
5#include <linux/pci.h> 5#include <linux/pci.h>
6#include <linux/slab.h>
6#include <linux/init.h> 7#include <linux/init.h>
7#include <linux/pagemap.h> 8#include <linux/pagemap.h>
8#include <linux/agp_backend.h> 9#include <linux/agp_backend.h>
@@ -144,16 +145,13 @@ static int uninorth_configure(void)
144 return 0; 145 return 0;
145} 146}
146 147
147static int uninorth_insert_memory(struct agp_memory *mem, off_t pg_start, 148static int uninorth_insert_memory(struct agp_memory *mem, off_t pg_start, int type)
148 int type)
149{ 149{
150 int i, j, num_entries; 150 int i, num_entries;
151 void *temp; 151 void *temp;
152 u32 *gp;
152 int mask_type; 153 int mask_type;
153 154
154 temp = agp_bridge->current_size;
155 num_entries = A_SIZE_32(temp)->num_entries;
156
157 if (type != mem->type) 155 if (type != mem->type)
158 return -EINVAL; 156 return -EINVAL;
159 157
@@ -163,49 +161,12 @@ static int uninorth_insert_memory(struct agp_memory *mem, off_t pg_start,
163 return -EINVAL; 161 return -EINVAL;
164 } 162 }
165 163
166 if ((pg_start + mem->page_count) > num_entries) 164 if (mem->page_count == 0)
167 return -EINVAL; 165 return 0;
168
169 j = pg_start;
170
171 while (j < (pg_start + mem->page_count)) {
172 if (agp_bridge->gatt_table[j])
173 return -EBUSY;
174 j++;
175 }
176
177 for (i = 0, j = pg_start; i < mem->page_count; i++, j++) {
178 agp_bridge->gatt_table[j] =
179 cpu_to_le32((page_to_phys(mem->pages[i]) & 0xFFFFF000UL) | 0x1UL);
180 flush_dcache_range((unsigned long)__va(page_to_phys(mem->pages[i])),
181 (unsigned long)__va(page_to_phys(mem->pages[i]))+0x1000);
182 }
183 (void)in_le32((volatile u32*)&agp_bridge->gatt_table[pg_start]);
184 mb();
185
186 uninorth_tlbflush(mem);
187 return 0;
188}
189
190static int u3_insert_memory(struct agp_memory *mem, off_t pg_start, int type)
191{
192 int i, num_entries;
193 void *temp;
194 u32 *gp;
195 int mask_type;
196 166
197 temp = agp_bridge->current_size; 167 temp = agp_bridge->current_size;
198 num_entries = A_SIZE_32(temp)->num_entries; 168 num_entries = A_SIZE_32(temp)->num_entries;
199 169
200 if (type != mem->type)
201 return -EINVAL;
202
203 mask_type = agp_bridge->driver->agp_type_to_mask_type(agp_bridge, type);
204 if (mask_type != 0) {
205 /* We know nothing of memory types */
206 return -EINVAL;
207 }
208
209 if ((pg_start + mem->page_count) > num_entries) 170 if ((pg_start + mem->page_count) > num_entries)
210 return -EINVAL; 171 return -EINVAL;
211 172
@@ -213,14 +174,18 @@ static int u3_insert_memory(struct agp_memory *mem, off_t pg_start, int type)
213 for (i = 0; i < mem->page_count; ++i) { 174 for (i = 0; i < mem->page_count; ++i) {
214 if (gp[i]) { 175 if (gp[i]) {
215 dev_info(&agp_bridge->dev->dev, 176 dev_info(&agp_bridge->dev->dev,
216 "u3_insert_memory: entry 0x%x occupied (%x)\n", 177 "uninorth_insert_memory: entry 0x%x occupied (%x)\n",
217 i, gp[i]); 178 i, gp[i]);
218 return -EBUSY; 179 return -EBUSY;
219 } 180 }
220 } 181 }
221 182
222 for (i = 0; i < mem->page_count; i++) { 183 for (i = 0; i < mem->page_count; i++) {
223 gp[i] = (page_to_phys(mem->pages[i]) >> PAGE_SHIFT) | 0x80000000UL; 184 if (is_u3)
185 gp[i] = (page_to_phys(mem->pages[i]) >> PAGE_SHIFT) | 0x80000000UL;
186 else
187 gp[i] = cpu_to_le32((page_to_phys(mem->pages[i]) & 0xFFFFF000UL) |
188 0x1UL);
224 flush_dcache_range((unsigned long)__va(page_to_phys(mem->pages[i])), 189 flush_dcache_range((unsigned long)__va(page_to_phys(mem->pages[i])),
225 (unsigned long)__va(page_to_phys(mem->pages[i]))+0x1000); 190 (unsigned long)__va(page_to_phys(mem->pages[i]))+0x1000);
226 } 191 }
@@ -230,14 +195,23 @@ static int u3_insert_memory(struct agp_memory *mem, off_t pg_start, int type)
230 return 0; 195 return 0;
231} 196}
232 197
233int u3_remove_memory(struct agp_memory *mem, off_t pg_start, int type) 198int uninorth_remove_memory(struct agp_memory *mem, off_t pg_start, int type)
234{ 199{
235 size_t i; 200 size_t i;
236 u32 *gp; 201 u32 *gp;
202 int mask_type;
203
204 if (type != mem->type)
205 return -EINVAL;
237 206
238 if (type != 0 || mem->type != 0) 207 mask_type = agp_bridge->driver->agp_type_to_mask_type(agp_bridge, type);
208 if (mask_type != 0) {
239 /* We know nothing of memory types */ 209 /* We know nothing of memory types */
240 return -EINVAL; 210 return -EINVAL;
211 }
212
213 if (mem->page_count == 0)
214 return 0;
241 215
242 gp = (u32 *) &agp_bridge->gatt_table[pg_start]; 216 gp = (u32 *) &agp_bridge->gatt_table[pg_start];
243 for (i = 0; i < mem->page_count; ++i) 217 for (i = 0; i < mem->page_count; ++i)
@@ -536,7 +510,7 @@ const struct agp_bridge_driver uninorth_agp_driver = {
536 .create_gatt_table = uninorth_create_gatt_table, 510 .create_gatt_table = uninorth_create_gatt_table,
537 .free_gatt_table = uninorth_free_gatt_table, 511 .free_gatt_table = uninorth_free_gatt_table,
538 .insert_memory = uninorth_insert_memory, 512 .insert_memory = uninorth_insert_memory,
539 .remove_memory = agp_generic_remove_memory, 513 .remove_memory = uninorth_remove_memory,
540 .alloc_by_type = agp_generic_alloc_by_type, 514 .alloc_by_type = agp_generic_alloc_by_type,
541 .free_by_type = agp_generic_free_by_type, 515 .free_by_type = agp_generic_free_by_type,
542 .agp_alloc_page = agp_generic_alloc_page, 516 .agp_alloc_page = agp_generic_alloc_page,
@@ -562,8 +536,8 @@ const struct agp_bridge_driver u3_agp_driver = {
562 .agp_enable = uninorth_agp_enable, 536 .agp_enable = uninorth_agp_enable,
563 .create_gatt_table = uninorth_create_gatt_table, 537 .create_gatt_table = uninorth_create_gatt_table,
564 .free_gatt_table = uninorth_free_gatt_table, 538 .free_gatt_table = uninorth_free_gatt_table,
565 .insert_memory = u3_insert_memory, 539 .insert_memory = uninorth_insert_memory,
566 .remove_memory = u3_remove_memory, 540 .remove_memory = uninorth_remove_memory,
567 .alloc_by_type = agp_generic_alloc_by_type, 541 .alloc_by_type = agp_generic_alloc_by_type,
568 .free_by_type = agp_generic_free_by_type, 542 .free_by_type = agp_generic_free_by_type,
569 .agp_alloc_page = agp_generic_alloc_page, 543 .agp_alloc_page = agp_generic_alloc_page,
diff --git a/drivers/char/amiserial.c b/drivers/char/amiserial.c
index 6c32fbf07164..56b27671adc4 100644
--- a/drivers/char/amiserial.c
+++ b/drivers/char/amiserial.c
@@ -2021,8 +2021,6 @@ static int __init rs_init(void)
2021 state->baud_base = amiga_colorclock; 2021 state->baud_base = amiga_colorclock;
2022 state->xmit_fifo_size = 1; 2022 state->xmit_fifo_size = 1;
2023 2023
2024 local_irq_save(flags);
2025
2026 /* set ISRs, and then disable the rx interrupts */ 2024 /* set ISRs, and then disable the rx interrupts */
2027 error = request_irq(IRQ_AMIGA_TBE, ser_tx_int, 0, "serial TX", state); 2025 error = request_irq(IRQ_AMIGA_TBE, ser_tx_int, 0, "serial TX", state);
2028 if (error) 2026 if (error)
@@ -2033,6 +2031,8 @@ static int __init rs_init(void)
2033 if (error) 2031 if (error)
2034 goto fail_free_irq; 2032 goto fail_free_irq;
2035 2033
2034 local_irq_save(flags);
2035
2036 /* turn off Rx and Tx interrupts */ 2036 /* turn off Rx and Tx interrupts */
2037 custom.intena = IF_RBF | IF_TBE; 2037 custom.intena = IF_RBF | IF_TBE;
2038 mb(); 2038 mb();
diff --git a/drivers/char/applicom.c b/drivers/char/applicom.c
index fe2cb2f5db17..a7424bf7eacf 100644
--- a/drivers/char/applicom.c
+++ b/drivers/char/applicom.c
@@ -14,7 +14,7 @@
14/* et passe en argument a acinit, mais est scrute sur le bus pour s'adapter */ 14/* et passe en argument a acinit, mais est scrute sur le bus pour s'adapter */
15/* au nombre de cartes presentes sur le bus. IOCL code 6 affichait V2.4.3 */ 15/* au nombre de cartes presentes sur le bus. IOCL code 6 affichait V2.4.3 */
16/* F.LAFORSE 28/11/95 creation de fichiers acXX.o avec les differentes */ 16/* F.LAFORSE 28/11/95 creation de fichiers acXX.o avec les differentes */
17/* adresses de base des cartes, IOCTL 6 plus complet */ 17/* addresses de base des cartes, IOCTL 6 plus complet */
18/* J.PAGET le 19/08/96 copie de la version V2.6 en V2.8.0 sans modification */ 18/* J.PAGET le 19/08/96 copie de la version V2.6 en V2.8.0 sans modification */
19/* de code autre que le texte V2.6.1 en V2.8.0 */ 19/* de code autre que le texte V2.6.1 en V2.8.0 */
20/*****************************************************************************/ 20/*****************************************************************************/
diff --git a/drivers/char/bfin_jtag_comm.c b/drivers/char/bfin_jtag_comm.c
index 1d7c34c73b20..e397df3ad98e 100644
--- a/drivers/char/bfin_jtag_comm.c
+++ b/drivers/char/bfin_jtag_comm.c
@@ -21,6 +21,7 @@
21#include <linux/module.h> 21#include <linux/module.h>
22#include <linux/mutex.h> 22#include <linux/mutex.h>
23#include <linux/sched.h> 23#include <linux/sched.h>
24#include <linux/slab.h>
24#include <linux/tty.h> 25#include <linux/tty.h>
25#include <linux/tty_driver.h> 26#include <linux/tty_driver.h>
26#include <linux/tty_flip.h> 27#include <linux/tty_flip.h>
@@ -226,7 +227,7 @@ bfin_jc_wait_until_sent(struct tty_struct *tty, int timeout)
226 } 227 }
227} 228}
228 229
229static struct tty_operations bfin_jc_ops = { 230static const struct tty_operations bfin_jc_ops = {
230 .open = bfin_jc_open, 231 .open = bfin_jc_open,
231 .close = bfin_jc_close, 232 .close = bfin_jc_close,
232 .write = bfin_jc_write, 233 .write = bfin_jc_write,
diff --git a/drivers/char/briq_panel.c b/drivers/char/briq_panel.c
index d8cff909001c..555cd93c2ee5 100644
--- a/drivers/char/briq_panel.c
+++ b/drivers/char/briq_panel.c
@@ -14,7 +14,6 @@
14#include <linux/kernel.h> 14#include <linux/kernel.h>
15#include <linux/wait.h> 15#include <linux/wait.h>
16#include <linux/string.h> 16#include <linux/string.h>
17#include <linux/slab.h>
18#include <linux/ioport.h> 17#include <linux/ioport.h>
19#include <linux/delay.h> 18#include <linux/delay.h>
20#include <linux/miscdevice.h> 19#include <linux/miscdevice.h>
diff --git a/drivers/char/bsr.c b/drivers/char/bsr.c
index c02db01f736e..7fef305774de 100644
--- a/drivers/char/bsr.c
+++ b/drivers/char/bsr.c
@@ -27,6 +27,7 @@
27#include <linux/cdev.h> 27#include <linux/cdev.h>
28#include <linux/list.h> 28#include <linux/list.h>
29#include <linux/mm.h> 29#include <linux/mm.h>
30#include <linux/slab.h>
30#include <asm/pgtable.h> 31#include <asm/pgtable.h>
31#include <asm/io.h> 32#include <asm/io.h>
32 33
diff --git a/drivers/char/cs5535_gpio.c b/drivers/char/cs5535_gpio.c
index 04ba906b4880..4d830dc482ef 100644
--- a/drivers/char/cs5535_gpio.c
+++ b/drivers/char/cs5535_gpio.c
@@ -17,7 +17,7 @@
17#include <linux/cdev.h> 17#include <linux/cdev.h>
18#include <linux/ioport.h> 18#include <linux/ioport.h>
19#include <linux/pci.h> 19#include <linux/pci.h>
20#include <linux/smp_lock.h> 20
21#include <asm/uaccess.h> 21#include <asm/uaccess.h>
22#include <asm/io.h> 22#include <asm/io.h>
23 23
@@ -158,7 +158,6 @@ static int cs5535_gpio_open(struct inode *inode, struct file *file)
158{ 158{
159 u32 m = iminor(inode); 159 u32 m = iminor(inode);
160 160
161 cycle_kernel_lock();
162 /* the mask says which pins are usable by this driver */ 161 /* the mask says which pins are usable by this driver */
163 if ((mask & (1 << m)) == 0) 162 if ((mask & (1 << m)) == 0)
164 return -EINVAL; 163 return -EINVAL;
diff --git a/drivers/char/cyclades.c b/drivers/char/cyclades.c
index 4254457d3911..9824b4162904 100644
--- a/drivers/char/cyclades.c
+++ b/drivers/char/cyclades.c
@@ -79,6 +79,7 @@
79#include <linux/bitops.h> 79#include <linux/bitops.h>
80#include <linux/firmware.h> 80#include <linux/firmware.h>
81#include <linux/device.h> 81#include <linux/device.h>
82#include <linux/slab.h>
82 83
83#include <linux/io.h> 84#include <linux/io.h>
84#include <linux/uaccess.h> 85#include <linux/uaccess.h>
@@ -158,13 +159,11 @@ static unsigned int cy_isa_addresses[] = {
158 159
159#define NR_ISA_ADDRS ARRAY_SIZE(cy_isa_addresses) 160#define NR_ISA_ADDRS ARRAY_SIZE(cy_isa_addresses)
160 161
161#ifdef MODULE
162static long maddr[NR_CARDS]; 162static long maddr[NR_CARDS];
163static int irq[NR_CARDS]; 163static int irq[NR_CARDS];
164 164
165module_param_array(maddr, long, NULL, 0); 165module_param_array(maddr, long, NULL, 0);
166module_param_array(irq, int, NULL, 0); 166module_param_array(irq, int, NULL, 0);
167#endif
168 167
169#endif /* CONFIG_ISA */ 168#endif /* CONFIG_ISA */
170 169
@@ -598,12 +597,6 @@ static void cyy_chip_tx(struct cyclades_card *cinfo, unsigned int chip,
598 save_car = readb(base_addr + (CyCAR << index)); 597 save_car = readb(base_addr + (CyCAR << index));
599 cy_writeb(base_addr + (CyCAR << index), save_xir); 598 cy_writeb(base_addr + (CyCAR << index), save_xir);
600 599
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]; 600 info = &cinfo->ports[channel + chip * 4];
608 tty = tty_port_tty_get(&info->port); 601 tty = tty_port_tty_get(&info->port);
609 if (tty == NULL) { 602 if (tty == NULL) {
@@ -3316,13 +3309,10 @@ static int __init cy_detect_isa(void)
3316 unsigned short cy_isa_irq, nboard; 3309 unsigned short cy_isa_irq, nboard;
3317 void __iomem *cy_isa_address; 3310 void __iomem *cy_isa_address;
3318 unsigned short i, j, cy_isa_nchan; 3311 unsigned short i, j, cy_isa_nchan;
3319#ifdef MODULE
3320 int isparam = 0; 3312 int isparam = 0;
3321#endif
3322 3313
3323 nboard = 0; 3314 nboard = 0;
3324 3315
3325#ifdef MODULE
3326 /* Check for module parameters */ 3316 /* Check for module parameters */
3327 for (i = 0; i < NR_CARDS; i++) { 3317 for (i = 0; i < NR_CARDS; i++) {
3328 if (maddr[i] || i) { 3318 if (maddr[i] || i) {
@@ -3332,7 +3322,6 @@ static int __init cy_detect_isa(void)
3332 if (!maddr[i]) 3322 if (!maddr[i])
3333 break; 3323 break;
3334 } 3324 }
3335#endif
3336 3325
3337 /* scan the address table probing for Cyclom-Y/ISA boards */ 3326 /* scan the address table probing for Cyclom-Y/ISA boards */
3338 for (i = 0; i < NR_ISA_ADDRS; i++) { 3327 for (i = 0; i < NR_ISA_ADDRS; i++) {
@@ -3353,11 +3342,10 @@ static int __init cy_detect_isa(void)
3353 iounmap(cy_isa_address); 3342 iounmap(cy_isa_address);
3354 continue; 3343 continue;
3355 } 3344 }
3356#ifdef MODULE 3345
3357 if (isparam && i < NR_CARDS && irq[i]) 3346 if (isparam && i < NR_CARDS && irq[i])
3358 cy_isa_irq = irq[i]; 3347 cy_isa_irq = irq[i];
3359 else 3348 else
3360#endif
3361 /* find out the board's irq by probing */ 3349 /* find out the board's irq by probing */
3362 cy_isa_irq = detect_isa_irq(cy_isa_address); 3350 cy_isa_irq = detect_isa_irq(cy_isa_address);
3363 if (cy_isa_irq == 0) { 3351 if (cy_isa_irq == 0) {
@@ -4208,3 +4196,4 @@ module_exit(cy_cleanup_module);
4208MODULE_LICENSE("GPL"); 4196MODULE_LICENSE("GPL");
4209MODULE_VERSION(CY_VERSION); 4197MODULE_VERSION(CY_VERSION);
4210MODULE_ALIAS_CHARDEV_MAJOR(CYCLADES_MAJOR); 4198MODULE_ALIAS_CHARDEV_MAJOR(CYCLADES_MAJOR);
4199MODULE_FIRMWARE("cyzfirm.bin");
diff --git a/drivers/char/dsp56k.c b/drivers/char/dsp56k.c
index 85832ab924e6..8a1b28a10ef0 100644
--- a/drivers/char/dsp56k.c
+++ b/drivers/char/dsp56k.c
@@ -24,7 +24,6 @@
24 */ 24 */
25 25
26#include <linux/module.h> 26#include <linux/module.h>
27#include <linux/slab.h> /* for kmalloc() and kfree() */
28#include <linux/major.h> 27#include <linux/major.h>
29#include <linux/types.h> 28#include <linux/types.h>
30#include <linux/errno.h> 29#include <linux/errno.h>
diff --git a/drivers/char/efirtc.c b/drivers/char/efirtc.c
index 34d15d548236..53c524e7b829 100644
--- a/drivers/char/efirtc.c
+++ b/drivers/char/efirtc.c
@@ -27,8 +27,6 @@
27 * - Add module support 27 * - Add module support
28 */ 28 */
29 29
30
31#include <linux/smp_lock.h>
32#include <linux/types.h> 30#include <linux/types.h>
33#include <linux/errno.h> 31#include <linux/errno.h>
34#include <linux/miscdevice.h> 32#include <linux/miscdevice.h>
@@ -174,13 +172,12 @@ static long efi_rtc_ioctl(struct file *file, unsigned int cmd,
174 return -EINVAL; 172 return -EINVAL;
175 173
176 case RTC_RD_TIME: 174 case RTC_RD_TIME:
177 lock_kernel();
178 spin_lock_irqsave(&efi_rtc_lock, flags); 175 spin_lock_irqsave(&efi_rtc_lock, flags);
179 176
180 status = efi.get_time(&eft, &cap); 177 status = efi.get_time(&eft, &cap);
181 178
182 spin_unlock_irqrestore(&efi_rtc_lock,flags); 179 spin_unlock_irqrestore(&efi_rtc_lock,flags);
183 unlock_kernel(); 180
184 if (status != EFI_SUCCESS) { 181 if (status != EFI_SUCCESS) {
185 /* should never happen */ 182 /* should never happen */
186 printk(KERN_ERR "efitime: can't read time\n"); 183 printk(KERN_ERR "efitime: can't read time\n");
@@ -202,13 +199,11 @@ static long efi_rtc_ioctl(struct file *file, unsigned int cmd,
202 199
203 convert_to_efi_time(&wtime, &eft); 200 convert_to_efi_time(&wtime, &eft);
204 201
205 lock_kernel();
206 spin_lock_irqsave(&efi_rtc_lock, flags); 202 spin_lock_irqsave(&efi_rtc_lock, flags);
207 203
208 status = efi.set_time(&eft); 204 status = efi.set_time(&eft);
209 205
210 spin_unlock_irqrestore(&efi_rtc_lock,flags); 206 spin_unlock_irqrestore(&efi_rtc_lock,flags);
211 unlock_kernel();
212 207
213 return status == EFI_SUCCESS ? 0 : -EINVAL; 208 return status == EFI_SUCCESS ? 0 : -EINVAL;
214 209
@@ -224,7 +219,6 @@ static long efi_rtc_ioctl(struct file *file, unsigned int cmd,
224 219
225 convert_to_efi_time(&wtime, &eft); 220 convert_to_efi_time(&wtime, &eft);
226 221
227 lock_kernel();
228 spin_lock_irqsave(&efi_rtc_lock, flags); 222 spin_lock_irqsave(&efi_rtc_lock, flags);
229 /* 223 /*
230 * XXX Fixme: 224 * XXX Fixme:
@@ -235,19 +229,16 @@ static long efi_rtc_ioctl(struct file *file, unsigned int cmd,
235 status = efi.set_wakeup_time((efi_bool_t)enabled, &eft); 229 status = efi.set_wakeup_time((efi_bool_t)enabled, &eft);
236 230
237 spin_unlock_irqrestore(&efi_rtc_lock,flags); 231 spin_unlock_irqrestore(&efi_rtc_lock,flags);
238 unlock_kernel();
239 232
240 return status == EFI_SUCCESS ? 0 : -EINVAL; 233 return status == EFI_SUCCESS ? 0 : -EINVAL;
241 234
242 case RTC_WKALM_RD: 235 case RTC_WKALM_RD:
243 236
244 lock_kernel();
245 spin_lock_irqsave(&efi_rtc_lock, flags); 237 spin_lock_irqsave(&efi_rtc_lock, flags);
246 238
247 status = efi.get_wakeup_time((efi_bool_t *)&enabled, (efi_bool_t *)&pending, &eft); 239 status = efi.get_wakeup_time((efi_bool_t *)&enabled, (efi_bool_t *)&pending, &eft);
248 240
249 spin_unlock_irqrestore(&efi_rtc_lock,flags); 241 spin_unlock_irqrestore(&efi_rtc_lock,flags);
250 unlock_kernel();
251 242
252 if (status != EFI_SUCCESS) return -EINVAL; 243 if (status != EFI_SUCCESS) return -EINVAL;
253 244
@@ -277,7 +268,6 @@ static int efi_rtc_open(struct inode *inode, struct file *file)
277 * We do accept multiple open files at the same time as we 268 * We do accept multiple open files at the same time as we
278 * synchronize on the per call operation. 269 * synchronize on the per call operation.
279 */ 270 */
280 cycle_kernel_lock();
281 return 0; 271 return 0;
282} 272}
283 273
@@ -295,6 +285,7 @@ static const struct file_operations efi_rtc_fops = {
295 .unlocked_ioctl = efi_rtc_ioctl, 285 .unlocked_ioctl = efi_rtc_ioctl,
296 .open = efi_rtc_open, 286 .open = efi_rtc_open,
297 .release = efi_rtc_close, 287 .release = efi_rtc_close,
288 .llseek = no_llseek,
298}; 289};
299 290
300static struct miscdevice efi_rtc_dev= { 291static struct miscdevice efi_rtc_dev= {
diff --git a/drivers/char/epca.c b/drivers/char/epca.c
index dde5134713e2..6f5ffe1320f7 100644
--- a/drivers/char/epca.c
+++ b/drivers/char/epca.c
@@ -36,7 +36,6 @@
36#include <linux/ctype.h> 36#include <linux/ctype.h>
37#include <linux/tty.h> 37#include <linux/tty.h>
38#include <linux/tty_flip.h> 38#include <linux/tty_flip.h>
39#include <linux/slab.h>
40#include <linux/smp_lock.h> 39#include <linux/smp_lock.h>
41#include <linux/ioport.h> 40#include <linux/ioport.h>
42#include <linux/interrupt.h> 41#include <linux/interrupt.h>
@@ -935,7 +934,7 @@ static int info_open(struct tty_struct *tty, struct file *filp)
935 return 0; 934 return 0;
936} 935}
937 936
938static struct tty_operations info_ops = { 937static const struct tty_operations info_ops = {
939 .open = info_open, 938 .open = info_open,
940 .ioctl = info_ioctl, 939 .ioctl = info_ioctl,
941}; 940};
diff --git a/drivers/char/esp.c b/drivers/char/esp.c
deleted file mode 100644
index b19d43cd9542..000000000000
--- a/drivers/char/esp.c
+++ /dev/null
@@ -1,2533 +0,0 @@
1/*
2 * esp.c - driver for Hayes ESP serial cards
3 *
4 * --- Notices from serial.c, upon which this driver is based ---
5 *
6 * Copyright (C) 1991, 1992 Linus Torvalds
7 *
8 * Extensively rewritten by Theodore Ts'o, 8/16/92 -- 9/14/92. Now
9 * much more extensible to support other serial cards based on the
10 * 16450/16550A UART's. Added support for the AST FourPort and the
11 * Accent Async board.
12 *
13 * set_serial_info fixed to set the flags, custom divisor, and uart
14 * type fields. Fix suggested by Michael K. Johnson 12/12/92.
15 *
16 * 11/95: TIOCMIWAIT, TIOCGICOUNT by Angelo Haritsis <ah@doc.ic.ac.uk>
17 *
18 * 03/96: Modularised by Angelo Haritsis <ah@doc.ic.ac.uk>
19 *
20 * rs_set_termios fixed to look also for changes of the input
21 * flags INPCK, BRKINT, PARMRK, IGNPAR and IGNBRK.
22 * Bernd Anhäupl 05/17/96.
23 *
24 * --- End of notices from serial.c ---
25 *
26 * Support for the ESP serial card by Andrew J. Robinson
27 * <arobinso@nyx.net> (Card detection routine taken from a patch
28 * by Dennis J. Boylan). Patches to allow use with 2.1.x contributed
29 * by Chris Faylor.
30 *
31 * Most recent changes: (Andrew J. Robinson)
32 * Support for PIO mode. This allows the driver to work properly with
33 * multiport cards.
34 *
35 * Arnaldo Carvalho de Melo <acme@conectiva.com.br> -
36 * several cleanups, use module_init/module_exit, etc
37 *
38 * This module exports the following rs232 io functions:
39 *
40 * int espserial_init(void);
41 */
42
43#include <linux/module.h>
44#include <linux/errno.h>
45#include <linux/signal.h>
46#include <linux/sched.h>
47#include <linux/interrupt.h>
48#include <linux/tty.h>
49#include <linux/tty_flip.h>
50#include <linux/serial.h>
51#include <linux/serialP.h>
52#include <linux/serial_reg.h>
53#include <linux/major.h>
54#include <linux/string.h>
55#include <linux/fcntl.h>
56#include <linux/ptrace.h>
57#include <linux/ioport.h>
58#include <linux/mm.h>
59#include <linux/init.h>
60#include <linux/delay.h>
61#include <linux/bitops.h>
62
63#include <asm/system.h>
64#include <linux/io.h>
65
66#include <asm/dma.h>
67#include <linux/slab.h>
68#include <linux/uaccess.h>
69
70#include <linux/hayesesp.h>
71
72#define NR_PORTS 64 /* maximum number of ports */
73#define NR_PRIMARY 8 /* maximum number of primary ports */
74#define REGION_SIZE 8 /* size of io region to request */
75
76/* The following variables can be set by giving module options */
77static int irq[NR_PRIMARY]; /* IRQ for each base port */
78static unsigned int divisor[NR_PRIMARY]; /* custom divisor for each port */
79static unsigned int dma = ESP_DMA_CHANNEL; /* DMA channel */
80static unsigned int rx_trigger = ESP_RX_TRIGGER;
81static unsigned int tx_trigger = ESP_TX_TRIGGER;
82static unsigned int flow_off = ESP_FLOW_OFF;
83static unsigned int flow_on = ESP_FLOW_ON;
84static unsigned int rx_timeout = ESP_RX_TMOUT;
85static unsigned int pio_threshold = ESP_PIO_THRESHOLD;
86
87MODULE_LICENSE("GPL");
88
89module_param_array(irq, int, NULL, 0);
90module_param_array(divisor, uint, NULL, 0);
91module_param(dma, uint, 0);
92module_param(rx_trigger, uint, 0);
93module_param(tx_trigger, uint, 0);
94module_param(flow_off, uint, 0);
95module_param(flow_on, uint, 0);
96module_param(rx_timeout, uint, 0);
97module_param(pio_threshold, uint, 0);
98
99/* END */
100
101static char *dma_buffer;
102static int dma_bytes;
103static struct esp_pio_buffer *free_pio_buf;
104
105#define DMA_BUFFER_SZ 1024
106
107#define WAKEUP_CHARS 1024
108
109static char serial_name[] __initdata = "ESP serial driver";
110static char serial_version[] __initdata = "2.2";
111
112static struct tty_driver *esp_driver;
113
114/*
115 * Serial driver configuration section. Here are the various options:
116 *
117 * SERIAL_PARANOIA_CHECK
118 * Check the magic number for the esp_structure where
119 * ever possible.
120 */
121
122#undef SERIAL_PARANOIA_CHECK
123#define SERIAL_DO_RESTART
124
125#undef SERIAL_DEBUG_INTR
126#undef SERIAL_DEBUG_OPEN
127#undef SERIAL_DEBUG_FLOW
128
129#if defined(MODULE) && defined(SERIAL_DEBUG_MCOUNT)
130#define DBG_CNT(s) printk(KERN_DEBUG "(%s): [%x] refc=%d, serc=%d, ttyc=%d -> %s\n", \
131 tty->name, info->port.flags, \
132 serial_driver.refcount, \
133 info->port.count, tty->count, s)
134#else
135#define DBG_CNT(s)
136#endif
137
138static struct esp_struct *ports;
139
140static void change_speed(struct esp_struct *info);
141static void rs_wait_until_sent(struct tty_struct *, int);
142
143/*
144 * The ESP card has a clock rate of 14.7456 MHz (that is, 2**ESPC_SCALE
145 * times the normal 1.8432 Mhz clock of most serial boards).
146 */
147#define BASE_BAUD ((1843200 / 16) * (1 << ESPC_SCALE))
148
149/* Standard COM flags (except for COM4, because of the 8514 problem) */
150#define STD_COM_FLAGS (ASYNC_BOOT_AUTOCONF | ASYNC_SKIP_TEST)
151
152static inline int serial_paranoia_check(struct esp_struct *info,
153 char *name, const char *routine)
154{
155#ifdef SERIAL_PARANOIA_CHECK
156 static const char badmagic[] = KERN_WARNING
157 "Warning: bad magic number for serial struct (%s) in %s\n";
158 static const char badinfo[] = KERN_WARNING
159 "Warning: null esp_struct for (%s) in %s\n";
160
161 if (!info) {
162 printk(badinfo, name, routine);
163 return 1;
164 }
165 if (info->magic != ESP_MAGIC) {
166 printk(badmagic, name, routine);
167 return 1;
168 }
169#endif
170 return 0;
171}
172
173static inline unsigned int serial_in(struct esp_struct *info, int offset)
174{
175 return inb(info->io_port + offset);
176}
177
178static inline void serial_out(struct esp_struct *info, int offset,
179 unsigned char value)
180{
181 outb(value, info->io_port+offset);
182}
183
184/*
185 * ------------------------------------------------------------
186 * rs_stop() and rs_start()
187 *
188 * This routines are called before setting or resetting tty->stopped.
189 * They enable or disable transmitter interrupts, as necessary.
190 * ------------------------------------------------------------
191 */
192static void rs_stop(struct tty_struct *tty)
193{
194 struct esp_struct *info = tty->driver_data;
195 unsigned long flags;
196
197 if (serial_paranoia_check(info, tty->name, "rs_stop"))
198 return;
199
200 spin_lock_irqsave(&info->lock, flags);
201 if (info->IER & UART_IER_THRI) {
202 info->IER &= ~UART_IER_THRI;
203 serial_out(info, UART_ESI_CMD1, ESI_SET_SRV_MASK);
204 serial_out(info, UART_ESI_CMD2, info->IER);
205 }
206 spin_unlock_irqrestore(&info->lock, flags);
207}
208
209static void rs_start(struct tty_struct *tty)
210{
211 struct esp_struct *info = tty->driver_data;
212 unsigned long flags;
213
214 if (serial_paranoia_check(info, tty->name, "rs_start"))
215 return;
216
217 spin_lock_irqsave(&info->lock, flags);
218 if (info->xmit_cnt && info->xmit_buf && !(info->IER & UART_IER_THRI)) {
219 info->IER |= UART_IER_THRI;
220 serial_out(info, UART_ESI_CMD1, ESI_SET_SRV_MASK);
221 serial_out(info, UART_ESI_CMD2, info->IER);
222 }
223 spin_unlock_irqrestore(&info->lock, flags);
224}
225
226/*
227 * ----------------------------------------------------------------------
228 *
229 * Here starts the interrupt handling routines. All of the following
230 * subroutines are declared as inline and are folded into
231 * rs_interrupt(). They were separated out for readability's sake.
232 *
233 * Note: rs_interrupt() is a "fast" interrupt, which means that it
234 * runs with interrupts turned off. People who may want to modify
235 * rs_interrupt() should try to keep the interrupt handler as fast as
236 * possible. After you are done making modifications, it is not a bad
237 * idea to do:
238 *
239 * gcc -S -DKERNEL -Wall -Wstrict-prototypes -O6 -fomit-frame-pointer serial.c
240 *
241 * and look at the resulting assemble code in serial.s.
242 *
243 * - Ted Ts'o (tytso@mit.edu), 7-Mar-93
244 * -----------------------------------------------------------------------
245 */
246
247static DEFINE_SPINLOCK(pio_lock);
248
249static inline struct esp_pio_buffer *get_pio_buffer(void)
250{
251 struct esp_pio_buffer *buf;
252 unsigned long flags;
253
254 spin_lock_irqsave(&pio_lock, flags);
255 if (free_pio_buf) {
256 buf = free_pio_buf;
257 free_pio_buf = buf->next;
258 } else {
259 buf = kmalloc(sizeof(struct esp_pio_buffer), GFP_ATOMIC);
260 }
261 spin_unlock_irqrestore(&pio_lock, flags);
262 return buf;
263}
264
265static inline void release_pio_buffer(struct esp_pio_buffer *buf)
266{
267 unsigned long flags;
268 spin_lock_irqsave(&pio_lock, flags);
269 buf->next = free_pio_buf;
270 free_pio_buf = buf;
271 spin_unlock_irqrestore(&pio_lock, flags);
272}
273
274static inline void receive_chars_pio(struct esp_struct *info, int num_bytes)
275{
276 struct tty_struct *tty = info->port.tty;
277 int i;
278 struct esp_pio_buffer *pio_buf;
279 struct esp_pio_buffer *err_buf;
280 unsigned char status_mask;
281
282 pio_buf = get_pio_buffer();
283
284 if (!pio_buf)
285 return;
286
287 err_buf = get_pio_buffer();
288
289 if (!err_buf) {
290 release_pio_buffer(pio_buf);
291 return;
292 }
293
294 status_mask = (info->read_status_mask >> 2) & 0x07;
295
296 for (i = 0; i < num_bytes - 1; i += 2) {
297 *((unsigned short *)(pio_buf->data + i)) =
298 inw(info->io_port + UART_ESI_RX);
299 err_buf->data[i] = serial_in(info, UART_ESI_RWS);
300 err_buf->data[i + 1] = (err_buf->data[i] >> 3) & status_mask;
301 err_buf->data[i] &= status_mask;
302 }
303
304 if (num_bytes & 0x0001) {
305 pio_buf->data[num_bytes - 1] = serial_in(info, UART_ESI_RX);
306 err_buf->data[num_bytes - 1] =
307 (serial_in(info, UART_ESI_RWS) >> 3) & status_mask;
308 }
309
310 /* make sure everything is still ok since interrupts were enabled */
311 tty = info->port.tty;
312
313 if (!tty) {
314 release_pio_buffer(pio_buf);
315 release_pio_buffer(err_buf);
316 info->stat_flags &= ~ESP_STAT_RX_TIMEOUT;
317 return;
318 }
319
320 status_mask = (info->ignore_status_mask >> 2) & 0x07;
321
322 for (i = 0; i < num_bytes; i++) {
323 if (!(err_buf->data[i] & status_mask)) {
324 int flag = 0;
325
326 if (err_buf->data[i] & 0x04) {
327 flag = TTY_BREAK;
328 if (info->port.flags & ASYNC_SAK)
329 do_SAK(tty);
330 } else if (err_buf->data[i] & 0x02)
331 flag = TTY_FRAME;
332 else if (err_buf->data[i] & 0x01)
333 flag = TTY_PARITY;
334 tty_insert_flip_char(tty, pio_buf->data[i], flag);
335 }
336 }
337
338 tty_schedule_flip(tty);
339
340 info->stat_flags &= ~ESP_STAT_RX_TIMEOUT;
341 release_pio_buffer(pio_buf);
342 release_pio_buffer(err_buf);
343}
344
345static void program_isa_dma(int dma, int dir, unsigned long addr, int len)
346{
347 unsigned long flags;
348
349 flags = claim_dma_lock();
350 disable_dma(dma);
351 clear_dma_ff(dma);
352 set_dma_mode(dma, dir);
353 set_dma_addr(dma, addr);
354 set_dma_count(dma, len);
355 enable_dma(dma);
356 release_dma_lock(flags);
357}
358
359static void receive_chars_dma(struct esp_struct *info, int num_bytes)
360{
361 info->stat_flags &= ~ESP_STAT_RX_TIMEOUT;
362 dma_bytes = num_bytes;
363 info->stat_flags |= ESP_STAT_DMA_RX;
364
365 program_isa_dma(dma, DMA_MODE_READ, isa_virt_to_bus(dma_buffer),
366 dma_bytes);
367 serial_out(info, UART_ESI_CMD1, ESI_START_DMA_RX);
368}
369
370static inline void receive_chars_dma_done(struct esp_struct *info,
371 int status)
372{
373 struct tty_struct *tty = info->port.tty;
374 int num_bytes;
375 unsigned long flags;
376
377 flags = claim_dma_lock();
378 disable_dma(dma);
379 clear_dma_ff(dma);
380
381 info->stat_flags &= ~ESP_STAT_DMA_RX;
382 num_bytes = dma_bytes - get_dma_residue(dma);
383 release_dma_lock(flags);
384
385 info->icount.rx += num_bytes;
386
387 if (num_bytes > 0) {
388 tty_insert_flip_string(tty, dma_buffer, num_bytes - 1);
389
390 status &= (0x1c & info->read_status_mask);
391
392 /* Is the status significant or do we throw the last byte ? */
393 if (!(status & info->ignore_status_mask)) {
394 int statflag = 0;
395
396 if (status & 0x10) {
397 statflag = TTY_BREAK;
398 (info->icount.brk)++;
399 if (info->port.flags & ASYNC_SAK)
400 do_SAK(tty);
401 } else if (status & 0x08) {
402 statflag = TTY_FRAME;
403 info->icount.frame++;
404 } else if (status & 0x04) {
405 statflag = TTY_PARITY;
406 info->icount.parity++;
407 }
408 tty_insert_flip_char(tty, dma_buffer[num_bytes - 1],
409 statflag);
410 }
411 tty_schedule_flip(tty);
412 }
413
414 if (dma_bytes != num_bytes) {
415 num_bytes = dma_bytes - num_bytes;
416 dma_bytes = 0;
417 receive_chars_dma(info, num_bytes);
418 } else
419 dma_bytes = 0;
420}
421
422/* Caller must hold info->lock */
423
424static inline void transmit_chars_pio(struct esp_struct *info,
425 int space_avail)
426{
427 int i;
428 struct esp_pio_buffer *pio_buf;
429
430 pio_buf = get_pio_buffer();
431
432 if (!pio_buf)
433 return;
434
435 while (space_avail && info->xmit_cnt) {
436 if (info->xmit_tail + space_avail <= ESP_XMIT_SIZE) {
437 memcpy(pio_buf->data,
438 &(info->xmit_buf[info->xmit_tail]),
439 space_avail);
440 } else {
441 i = ESP_XMIT_SIZE - info->xmit_tail;
442 memcpy(pio_buf->data,
443 &(info->xmit_buf[info->xmit_tail]), i);
444 memcpy(&(pio_buf->data[i]), info->xmit_buf,
445 space_avail - i);
446 }
447
448 info->xmit_cnt -= space_avail;
449 info->xmit_tail = (info->xmit_tail + space_avail) &
450 (ESP_XMIT_SIZE - 1);
451
452 for (i = 0; i < space_avail - 1; i += 2) {
453 outw(*((unsigned short *)(pio_buf->data + i)),
454 info->io_port + UART_ESI_TX);
455 }
456
457 if (space_avail & 0x0001)
458 serial_out(info, UART_ESI_TX,
459 pio_buf->data[space_avail - 1]);
460
461 if (info->xmit_cnt) {
462 serial_out(info, UART_ESI_CMD1, ESI_NO_COMMAND);
463 serial_out(info, UART_ESI_CMD1, ESI_GET_TX_AVAIL);
464 space_avail = serial_in(info, UART_ESI_STAT1) << 8;
465 space_avail |= serial_in(info, UART_ESI_STAT2);
466
467 if (space_avail > info->xmit_cnt)
468 space_avail = info->xmit_cnt;
469 }
470 }
471
472 if (info->xmit_cnt < WAKEUP_CHARS) {
473 if (info->port.tty)
474 tty_wakeup(info->port.tty);
475
476#ifdef SERIAL_DEBUG_INTR
477 printk("THRE...");
478#endif
479
480 if (info->xmit_cnt <= 0) {
481 info->IER &= ~UART_IER_THRI;
482 serial_out(info, UART_ESI_CMD1,
483 ESI_SET_SRV_MASK);
484 serial_out(info, UART_ESI_CMD2, info->IER);
485 }
486 }
487
488 release_pio_buffer(pio_buf);
489}
490
491/* Caller must hold info->lock */
492static inline void transmit_chars_dma(struct esp_struct *info, int num_bytes)
493{
494 dma_bytes = num_bytes;
495
496 if (info->xmit_tail + dma_bytes <= ESP_XMIT_SIZE) {
497 memcpy(dma_buffer, &(info->xmit_buf[info->xmit_tail]),
498 dma_bytes);
499 } else {
500 int i = ESP_XMIT_SIZE - info->xmit_tail;
501 memcpy(dma_buffer, &(info->xmit_buf[info->xmit_tail]),
502 i);
503 memcpy(&(dma_buffer[i]), info->xmit_buf, dma_bytes - i);
504 }
505
506 info->xmit_cnt -= dma_bytes;
507 info->xmit_tail = (info->xmit_tail + dma_bytes) & (ESP_XMIT_SIZE - 1);
508
509 if (info->xmit_cnt < WAKEUP_CHARS) {
510 if (info->port.tty)
511 tty_wakeup(info->port.tty);
512
513#ifdef SERIAL_DEBUG_INTR
514 printk("THRE...");
515#endif
516
517 if (info->xmit_cnt <= 0) {
518 info->IER &= ~UART_IER_THRI;
519 serial_out(info, UART_ESI_CMD1, ESI_SET_SRV_MASK);
520 serial_out(info, UART_ESI_CMD2, info->IER);
521 }
522 }
523
524 info->stat_flags |= ESP_STAT_DMA_TX;
525
526 program_isa_dma(dma, DMA_MODE_WRITE, isa_virt_to_bus(dma_buffer),
527 dma_bytes);
528 serial_out(info, UART_ESI_CMD1, ESI_START_DMA_TX);
529}
530
531static inline void transmit_chars_dma_done(struct esp_struct *info)
532{
533 int num_bytes;
534 unsigned long flags;
535
536 flags = claim_dma_lock();
537 disable_dma(dma);
538 clear_dma_ff(dma);
539
540 num_bytes = dma_bytes - get_dma_residue(dma);
541 info->icount.tx += dma_bytes;
542 release_dma_lock(flags);
543
544 if (dma_bytes != num_bytes) {
545 dma_bytes -= num_bytes;
546 memmove(dma_buffer, dma_buffer + num_bytes, dma_bytes);
547
548 program_isa_dma(dma, DMA_MODE_WRITE,
549 isa_virt_to_bus(dma_buffer), dma_bytes);
550
551 serial_out(info, UART_ESI_CMD1, ESI_START_DMA_TX);
552 } else {
553 dma_bytes = 0;
554 info->stat_flags &= ~ESP_STAT_DMA_TX;
555 }
556}
557
558static void check_modem_status(struct esp_struct *info)
559{
560 int status;
561
562 serial_out(info, UART_ESI_CMD1, ESI_GET_UART_STAT);
563 status = serial_in(info, UART_ESI_STAT2);
564
565 if (status & UART_MSR_ANY_DELTA) {
566 /* update input line counters */
567 if (status & UART_MSR_TERI)
568 info->icount.rng++;
569 if (status & UART_MSR_DDSR)
570 info->icount.dsr++;
571 if (status & UART_MSR_DDCD)
572 info->icount.dcd++;
573 if (status & UART_MSR_DCTS)
574 info->icount.cts++;
575 wake_up_interruptible(&info->port.delta_msr_wait);
576 }
577
578 if ((info->port.flags & ASYNC_CHECK_CD) && (status & UART_MSR_DDCD)) {
579#if (defined(SERIAL_DEBUG_OPEN) || defined(SERIAL_DEBUG_INTR))
580 printk("ttys%d CD now %s...", info->line,
581 (status & UART_MSR_DCD) ? "on" : "off");
582#endif
583 if (status & UART_MSR_DCD)
584 wake_up_interruptible(&info->port.open_wait);
585 else {
586#ifdef SERIAL_DEBUG_OPEN
587 printk("scheduling hangup...");
588#endif
589 tty_hangup(info->port.tty);
590 }
591 }
592}
593
594/*
595 * This is the serial driver's interrupt routine
596 */
597static irqreturn_t rs_interrupt_single(int irq, void *dev_id)
598{
599 struct esp_struct *info;
600 unsigned err_status;
601 unsigned int scratch;
602
603#ifdef SERIAL_DEBUG_INTR
604 printk("rs_interrupt_single(%d)...", irq);
605#endif
606 info = (struct esp_struct *)dev_id;
607 err_status = 0;
608 scratch = serial_in(info, UART_ESI_SID);
609
610 spin_lock(&info->lock);
611
612 if (!info->port.tty) {
613 spin_unlock(&info->lock);
614 return IRQ_NONE;
615 }
616
617 if (scratch & 0x04) { /* error */
618 serial_out(info, UART_ESI_CMD1, ESI_GET_ERR_STAT);
619 err_status = serial_in(info, UART_ESI_STAT1);
620 serial_in(info, UART_ESI_STAT2);
621
622 if (err_status & 0x01)
623 info->stat_flags |= ESP_STAT_RX_TIMEOUT;
624
625 if (err_status & 0x20) /* UART status */
626 check_modem_status(info);
627
628 if (err_status & 0x80) /* Start break */
629 wake_up_interruptible(&info->break_wait);
630 }
631
632 if ((scratch & 0x88) || /* DMA completed or timed out */
633 (err_status & 0x1c) /* receive error */) {
634 if (info->stat_flags & ESP_STAT_DMA_RX)
635 receive_chars_dma_done(info, err_status);
636 else if (info->stat_flags & ESP_STAT_DMA_TX)
637 transmit_chars_dma_done(info);
638 }
639
640 if (!(info->stat_flags & (ESP_STAT_DMA_RX | ESP_STAT_DMA_TX)) &&
641 ((scratch & 0x01) || (info->stat_flags & ESP_STAT_RX_TIMEOUT)) &&
642 (info->IER & UART_IER_RDI)) {
643 int num_bytes;
644
645 serial_out(info, UART_ESI_CMD1, ESI_NO_COMMAND);
646 serial_out(info, UART_ESI_CMD1, ESI_GET_RX_AVAIL);
647 num_bytes = serial_in(info, UART_ESI_STAT1) << 8;
648 num_bytes |= serial_in(info, UART_ESI_STAT2);
649
650 num_bytes = tty_buffer_request_room(info->port.tty, num_bytes);
651
652 if (num_bytes) {
653 if (dma_bytes ||
654 (info->stat_flags & ESP_STAT_USE_PIO) ||
655 (num_bytes <= info->config.pio_threshold))
656 receive_chars_pio(info, num_bytes);
657 else
658 receive_chars_dma(info, num_bytes);
659 }
660 }
661
662 if (!(info->stat_flags & (ESP_STAT_DMA_RX | ESP_STAT_DMA_TX)) &&
663 (scratch & 0x02) && (info->IER & UART_IER_THRI)) {
664 if ((info->xmit_cnt <= 0) || info->port.tty->stopped) {
665 info->IER &= ~UART_IER_THRI;
666 serial_out(info, UART_ESI_CMD1, ESI_SET_SRV_MASK);
667 serial_out(info, UART_ESI_CMD2, info->IER);
668 } else {
669 int num_bytes;
670
671 serial_out(info, UART_ESI_CMD1, ESI_NO_COMMAND);
672 serial_out(info, UART_ESI_CMD1, ESI_GET_TX_AVAIL);
673 num_bytes = serial_in(info, UART_ESI_STAT1) << 8;
674 num_bytes |= serial_in(info, UART_ESI_STAT2);
675
676 if (num_bytes > info->xmit_cnt)
677 num_bytes = info->xmit_cnt;
678
679 if (num_bytes) {
680 if (dma_bytes ||
681 (info->stat_flags & ESP_STAT_USE_PIO) ||
682 (num_bytes <= info->config.pio_threshold))
683 transmit_chars_pio(info, num_bytes);
684 else
685 transmit_chars_dma(info, num_bytes);
686 }
687 }
688 }
689
690 info->last_active = jiffies;
691
692#ifdef SERIAL_DEBUG_INTR
693 printk("end.\n");
694#endif
695 spin_unlock(&info->lock);
696 return IRQ_HANDLED;
697}
698
699/*
700 * -------------------------------------------------------------------
701 * Here ends the serial interrupt routines.
702 * -------------------------------------------------------------------
703 */
704
705/*
706 * ---------------------------------------------------------------
707 * Low level utility subroutines for the serial driver: routines to
708 * figure out the appropriate timeout for an interrupt chain, routines
709 * to initialize and startup a serial port, and routines to shutdown a
710 * serial port. Useful stuff like that.
711 *
712 * Caller should hold lock
713 * ---------------------------------------------------------------
714 */
715
716static void esp_basic_init(struct esp_struct *info)
717{
718 /* put ESPC in enhanced mode */
719 serial_out(info, UART_ESI_CMD1, ESI_SET_MODE);
720
721 if (info->stat_flags & ESP_STAT_NEVER_DMA)
722 serial_out(info, UART_ESI_CMD2, 0x01);
723 else
724 serial_out(info, UART_ESI_CMD2, 0x31);
725
726 /* disable interrupts for now */
727 serial_out(info, UART_ESI_CMD1, ESI_SET_SRV_MASK);
728 serial_out(info, UART_ESI_CMD2, 0x00);
729
730 /* set interrupt and DMA channel */
731 serial_out(info, UART_ESI_CMD1, ESI_SET_IRQ);
732
733 if (info->stat_flags & ESP_STAT_NEVER_DMA)
734 serial_out(info, UART_ESI_CMD2, 0x01);
735 else
736 serial_out(info, UART_ESI_CMD2, (dma << 4) | 0x01);
737
738 serial_out(info, UART_ESI_CMD1, ESI_SET_ENH_IRQ);
739
740 if (info->line % 8) /* secondary port */
741 serial_out(info, UART_ESI_CMD2, 0x0d); /* shared */
742 else if (info->irq == 9)
743 serial_out(info, UART_ESI_CMD2, 0x02);
744 else
745 serial_out(info, UART_ESI_CMD2, info->irq);
746
747 /* set error status mask (check this) */
748 serial_out(info, UART_ESI_CMD1, ESI_SET_ERR_MASK);
749
750 if (info->stat_flags & ESP_STAT_NEVER_DMA)
751 serial_out(info, UART_ESI_CMD2, 0xa1);
752 else
753 serial_out(info, UART_ESI_CMD2, 0xbd);
754
755 serial_out(info, UART_ESI_CMD2, 0x00);
756
757 /* set DMA timeout */
758 serial_out(info, UART_ESI_CMD1, ESI_SET_DMA_TMOUT);
759 serial_out(info, UART_ESI_CMD2, 0xff);
760
761 /* set FIFO trigger levels */
762 serial_out(info, UART_ESI_CMD1, ESI_SET_TRIGGER);
763 serial_out(info, UART_ESI_CMD2, info->config.rx_trigger >> 8);
764 serial_out(info, UART_ESI_CMD2, info->config.rx_trigger);
765 serial_out(info, UART_ESI_CMD2, info->config.tx_trigger >> 8);
766 serial_out(info, UART_ESI_CMD2, info->config.tx_trigger);
767
768 /* Set clock scaling and wait states */
769 serial_out(info, UART_ESI_CMD1, ESI_SET_PRESCALAR);
770 serial_out(info, UART_ESI_CMD2, 0x04 | ESPC_SCALE);
771
772 /* set reinterrupt pacing */
773 serial_out(info, UART_ESI_CMD1, ESI_SET_REINTR);
774 serial_out(info, UART_ESI_CMD2, 0xff);
775}
776
777static int startup(struct esp_struct *info)
778{
779 unsigned long flags;
780 int retval = 0;
781 unsigned int num_chars;
782
783 spin_lock_irqsave(&info->lock, flags);
784
785 if (info->port.flags & ASYNC_INITIALIZED)
786 goto out;
787
788 if (!info->xmit_buf) {
789 info->xmit_buf = (unsigned char *)get_zeroed_page(GFP_ATOMIC);
790 retval = -ENOMEM;
791 if (!info->xmit_buf)
792 goto out;
793 }
794
795#ifdef SERIAL_DEBUG_OPEN
796 printk(KERN_DEBUG "starting up ttys%d (irq %d)...",
797 info->line, info->irq);
798#endif
799
800 /* Flush the RX buffer. Using the ESI flush command may cause */
801 /* wild interrupts, so read all the data instead. */
802
803 serial_out(info, UART_ESI_CMD1, ESI_NO_COMMAND);
804 serial_out(info, UART_ESI_CMD1, ESI_GET_RX_AVAIL);
805 num_chars = serial_in(info, UART_ESI_STAT1) << 8;
806 num_chars |= serial_in(info, UART_ESI_STAT2);
807
808 while (num_chars > 1) {
809 inw(info->io_port + UART_ESI_RX);
810 num_chars -= 2;
811 }
812
813 if (num_chars)
814 serial_in(info, UART_ESI_RX);
815
816 /* set receive character timeout */
817 serial_out(info, UART_ESI_CMD1, ESI_SET_RX_TIMEOUT);
818 serial_out(info, UART_ESI_CMD2, info->config.rx_timeout);
819
820 /* clear all flags except the "never DMA" flag */
821 info->stat_flags &= ESP_STAT_NEVER_DMA;
822
823 if (info->stat_flags & ESP_STAT_NEVER_DMA)
824 info->stat_flags |= ESP_STAT_USE_PIO;
825
826 spin_unlock_irqrestore(&info->lock, flags);
827
828 /*
829 * Allocate the IRQ
830 */
831
832 retval = request_irq(info->irq, rs_interrupt_single, IRQF_SHARED,
833 "esp serial", info);
834
835 if (retval) {
836 if (capable(CAP_SYS_ADMIN)) {
837 if (info->port.tty)
838 set_bit(TTY_IO_ERROR,
839 &info->port.tty->flags);
840 retval = 0;
841 }
842 goto out_unlocked;
843 }
844
845 if (!(info->stat_flags & ESP_STAT_USE_PIO) && !dma_buffer) {
846 dma_buffer = (char *)__get_dma_pages(
847 GFP_KERNEL, get_order(DMA_BUFFER_SZ));
848
849 /* use PIO mode if DMA buf/chan cannot be allocated */
850 if (!dma_buffer)
851 info->stat_flags |= ESP_STAT_USE_PIO;
852 else if (request_dma(dma, "esp serial")) {
853 free_pages((unsigned long)dma_buffer,
854 get_order(DMA_BUFFER_SZ));
855 dma_buffer = NULL;
856 info->stat_flags |= ESP_STAT_USE_PIO;
857 }
858
859 }
860
861 info->MCR = UART_MCR_DTR | UART_MCR_RTS | UART_MCR_OUT2;
862
863 spin_lock_irqsave(&info->lock, flags);
864 serial_out(info, UART_ESI_CMD1, ESI_WRITE_UART);
865 serial_out(info, UART_ESI_CMD2, UART_MCR);
866 serial_out(info, UART_ESI_CMD2, info->MCR);
867
868 /*
869 * Finally, enable interrupts
870 */
871 /* info->IER = UART_IER_MSI | UART_IER_RLSI | UART_IER_RDI; */
872 info->IER = UART_IER_RLSI | UART_IER_RDI | UART_IER_DMA_TMOUT |
873 UART_IER_DMA_TC;
874 serial_out(info, UART_ESI_CMD1, ESI_SET_SRV_MASK);
875 serial_out(info, UART_ESI_CMD2, info->IER);
876
877 if (info->port.tty)
878 clear_bit(TTY_IO_ERROR, &info->port.tty->flags);
879 info->xmit_cnt = info->xmit_head = info->xmit_tail = 0;
880 spin_unlock_irqrestore(&info->lock, flags);
881
882 /*
883 * Set up the tty->alt_speed kludge
884 */
885 if (info->port.tty) {
886 if ((info->port.flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
887 info->port.tty->alt_speed = 57600;
888 if ((info->port.flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
889 info->port.tty->alt_speed = 115200;
890 if ((info->port.flags & ASYNC_SPD_MASK) == ASYNC_SPD_SHI)
891 info->port.tty->alt_speed = 230400;
892 if ((info->port.flags & ASYNC_SPD_MASK) == ASYNC_SPD_WARP)
893 info->port.tty->alt_speed = 460800;
894 }
895
896 /*
897 * set the speed of the serial port
898 */
899 change_speed(info);
900 info->port.flags |= ASYNC_INITIALIZED;
901 return 0;
902
903out:
904 spin_unlock_irqrestore(&info->lock, flags);
905out_unlocked:
906 return retval;
907}
908
909/*
910 * This routine will shutdown a serial port; interrupts are disabled, and
911 * DTR is dropped if the hangup on close termio flag is on.
912 */
913static void shutdown(struct esp_struct *info)
914{
915 unsigned long flags, f;
916
917 if (!(info->port.flags & ASYNC_INITIALIZED))
918 return;
919
920#ifdef SERIAL_DEBUG_OPEN
921 printk("Shutting down serial port %d (irq %d)....", info->line,
922 info->irq);
923#endif
924
925 spin_lock_irqsave(&info->lock, flags);
926 /*
927 * clear delta_msr_wait queue to avoid mem leaks: we may free the irq
928 * here so the queue might never be waken up
929 */
930 wake_up_interruptible(&info->port.delta_msr_wait);
931 wake_up_interruptible(&info->break_wait);
932
933 /* stop a DMA transfer on the port being closed */
934 /* DMA lock is higher priority always */
935 if (info->stat_flags & (ESP_STAT_DMA_RX | ESP_STAT_DMA_TX)) {
936 f = claim_dma_lock();
937 disable_dma(dma);
938 clear_dma_ff(dma);
939 release_dma_lock(f);
940
941 dma_bytes = 0;
942 }
943
944 /*
945 * Free the IRQ
946 */
947 free_irq(info->irq, info);
948
949 if (dma_buffer) {
950 struct esp_struct *current_port = ports;
951
952 while (current_port) {
953 if ((current_port != info) &&
954 (current_port->port.flags & ASYNC_INITIALIZED))
955 break;
956
957 current_port = current_port->next_port;
958 }
959
960 if (!current_port) {
961 free_dma(dma);
962 free_pages((unsigned long)dma_buffer,
963 get_order(DMA_BUFFER_SZ));
964 dma_buffer = NULL;
965 }
966 }
967
968 if (info->xmit_buf) {
969 free_page((unsigned long) info->xmit_buf);
970 info->xmit_buf = NULL;
971 }
972
973 info->IER = 0;
974 serial_out(info, UART_ESI_CMD1, ESI_SET_SRV_MASK);
975 serial_out(info, UART_ESI_CMD2, 0x00);
976
977 if (!info->port.tty || (info->port.tty->termios->c_cflag & HUPCL))
978 info->MCR &= ~(UART_MCR_DTR|UART_MCR_RTS);
979
980 info->MCR &= ~UART_MCR_OUT2;
981 serial_out(info, UART_ESI_CMD1, ESI_WRITE_UART);
982 serial_out(info, UART_ESI_CMD2, UART_MCR);
983 serial_out(info, UART_ESI_CMD2, info->MCR);
984
985 if (info->port.tty)
986 set_bit(TTY_IO_ERROR, &info->port.tty->flags);
987
988 info->port.flags &= ~ASYNC_INITIALIZED;
989 spin_unlock_irqrestore(&info->lock, flags);
990}
991
992/*
993 * This routine is called to set the UART divisor registers to match
994 * the specified baud rate for a serial port.
995 */
996static void change_speed(struct esp_struct *info)
997{
998 unsigned short port;
999 int quot = 0;
1000 unsigned cflag, cval;
1001 int baud, bits;
1002 unsigned char flow1 = 0, flow2 = 0;
1003 unsigned long flags;
1004
1005 if (!info->port.tty || !info->port.tty->termios)
1006 return;
1007 cflag = info->port.tty->termios->c_cflag;
1008 port = info->io_port;
1009
1010 /* byte size and parity */
1011 switch (cflag & CSIZE) {
1012 case CS5: cval = 0x00; bits = 7; break;
1013 case CS6: cval = 0x01; bits = 8; break;
1014 case CS7: cval = 0x02; bits = 9; break;
1015 case CS8: cval = 0x03; bits = 10; break;
1016 default: cval = 0x00; bits = 7; break;
1017 }
1018 if (cflag & CSTOPB) {
1019 cval |= 0x04;
1020 bits++;
1021 }
1022 if (cflag & PARENB) {
1023 cval |= UART_LCR_PARITY;
1024 bits++;
1025 }
1026 if (!(cflag & PARODD))
1027 cval |= UART_LCR_EPAR;
1028#ifdef CMSPAR
1029 if (cflag & CMSPAR)
1030 cval |= UART_LCR_SPAR;
1031#endif
1032 baud = tty_get_baud_rate(info->port.tty);
1033 if (baud == 38400 &&
1034 ((info->port.flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST))
1035 quot = info->custom_divisor;
1036 else {
1037 if (baud == 134) /* Special case since 134 is really 134.5 */
1038 quot = (2*BASE_BAUD / 269);
1039 else if (baud)
1040 quot = BASE_BAUD / baud;
1041 }
1042 /* If the quotient is ever zero, default to 9600 bps */
1043 if (!quot)
1044 quot = BASE_BAUD / 9600;
1045
1046 if (baud) {
1047 /* Actual rate */
1048 baud = BASE_BAUD/quot;
1049 tty_encode_baud_rate(info->port.tty, baud, baud);
1050 }
1051 info->timeout = ((1024 * HZ * bits * quot) / BASE_BAUD) + (HZ / 50);
1052
1053 /* CTS flow control flag and modem status interrupts */
1054 /* info->IER &= ~UART_IER_MSI; */
1055 if (cflag & CRTSCTS) {
1056 info->port.flags |= ASYNC_CTS_FLOW;
1057 /* info->IER |= UART_IER_MSI; */
1058 flow1 = 0x04;
1059 flow2 = 0x10;
1060 } else
1061 info->port.flags &= ~ASYNC_CTS_FLOW;
1062 if (cflag & CLOCAL)
1063 info->port.flags &= ~ASYNC_CHECK_CD;
1064 else
1065 info->port.flags |= ASYNC_CHECK_CD;
1066
1067 /*
1068 * Set up parity check flag
1069 */
1070 info->read_status_mask = UART_LSR_OE | UART_LSR_THRE | UART_LSR_DR;
1071 if (I_INPCK(info->port.tty))
1072 info->read_status_mask |= UART_LSR_FE | UART_LSR_PE;
1073 if (I_BRKINT(info->port.tty) || I_PARMRK(info->port.tty))
1074 info->read_status_mask |= UART_LSR_BI;
1075
1076 info->ignore_status_mask = 0;
1077#if 0
1078 /* This should be safe, but for some broken bits of hardware... */
1079 if (I_IGNPAR(info->port.tty)) {
1080 info->ignore_status_mask |= UART_LSR_PE | UART_LSR_FE;
1081 info->read_status_mask |= UART_LSR_PE | UART_LSR_FE;
1082 }
1083#endif
1084 if (I_IGNBRK(info->port.tty)) {
1085 info->ignore_status_mask |= UART_LSR_BI;
1086 info->read_status_mask |= UART_LSR_BI;
1087 /*
1088 * If we're ignore parity and break indicators, ignore
1089 * overruns too. (For real raw support).
1090 */
1091 if (I_IGNPAR(info->port.tty)) {
1092 info->ignore_status_mask |= UART_LSR_OE | \
1093 UART_LSR_PE | UART_LSR_FE;
1094 info->read_status_mask |= UART_LSR_OE | \
1095 UART_LSR_PE | UART_LSR_FE;
1096 }
1097 }
1098
1099 if (I_IXOFF(info->port.tty))
1100 flow1 |= 0x81;
1101
1102 spin_lock_irqsave(&info->lock, flags);
1103 /* set baud */
1104 serial_out(info, UART_ESI_CMD1, ESI_SET_BAUD);
1105 serial_out(info, UART_ESI_CMD2, quot >> 8);
1106 serial_out(info, UART_ESI_CMD2, quot & 0xff);
1107
1108 /* set data bits, parity, etc. */
1109 serial_out(info, UART_ESI_CMD1, ESI_WRITE_UART);
1110 serial_out(info, UART_ESI_CMD2, UART_LCR);
1111 serial_out(info, UART_ESI_CMD2, cval);
1112
1113 /* Enable flow control */
1114 serial_out(info, UART_ESI_CMD1, ESI_SET_FLOW_CNTL);
1115 serial_out(info, UART_ESI_CMD2, flow1);
1116 serial_out(info, UART_ESI_CMD2, flow2);
1117
1118 /* set flow control characters (XON/XOFF only) */
1119 if (I_IXOFF(info->port.tty)) {
1120 serial_out(info, UART_ESI_CMD1, ESI_SET_FLOW_CHARS);
1121 serial_out(info, UART_ESI_CMD2, START_CHAR(info->port.tty));
1122 serial_out(info, UART_ESI_CMD2, STOP_CHAR(info->port.tty));
1123 serial_out(info, UART_ESI_CMD2, 0x10);
1124 serial_out(info, UART_ESI_CMD2, 0x21);
1125 switch (cflag & CSIZE) {
1126 case CS5:
1127 serial_out(info, UART_ESI_CMD2, 0x1f);
1128 break;
1129 case CS6:
1130 serial_out(info, UART_ESI_CMD2, 0x3f);
1131 break;
1132 case CS7:
1133 case CS8:
1134 serial_out(info, UART_ESI_CMD2, 0x7f);
1135 break;
1136 default:
1137 serial_out(info, UART_ESI_CMD2, 0xff);
1138 break;
1139 }
1140 }
1141
1142 /* Set high/low water */
1143 serial_out(info, UART_ESI_CMD1, ESI_SET_FLOW_LVL);
1144 serial_out(info, UART_ESI_CMD2, info->config.flow_off >> 8);
1145 serial_out(info, UART_ESI_CMD2, info->config.flow_off);
1146 serial_out(info, UART_ESI_CMD2, info->config.flow_on >> 8);
1147 serial_out(info, UART_ESI_CMD2, info->config.flow_on);
1148
1149 spin_unlock_irqrestore(&info->lock, flags);
1150}
1151
1152static int rs_put_char(struct tty_struct *tty, unsigned char ch)
1153{
1154 struct esp_struct *info = tty->driver_data;
1155 unsigned long flags;
1156 int ret = 0;
1157
1158 if (serial_paranoia_check(info, tty->name, "rs_put_char"))
1159 return 0;
1160
1161 if (!info->xmit_buf)
1162 return 0;
1163
1164 spin_lock_irqsave(&info->lock, flags);
1165 if (info->xmit_cnt < ESP_XMIT_SIZE - 1) {
1166 info->xmit_buf[info->xmit_head++] = ch;
1167 info->xmit_head &= ESP_XMIT_SIZE-1;
1168 info->xmit_cnt++;
1169 ret = 1;
1170 }
1171 spin_unlock_irqrestore(&info->lock, flags);
1172 return ret;
1173}
1174
1175static void rs_flush_chars(struct tty_struct *tty)
1176{
1177 struct esp_struct *info = tty->driver_data;
1178 unsigned long flags;
1179
1180 if (serial_paranoia_check(info, tty->name, "rs_flush_chars"))
1181 return;
1182
1183 spin_lock_irqsave(&info->lock, flags);
1184
1185 if (info->xmit_cnt <= 0 || tty->stopped || !info->xmit_buf)
1186 goto out;
1187
1188 if (!(info->IER & UART_IER_THRI)) {
1189 info->IER |= UART_IER_THRI;
1190 serial_out(info, UART_ESI_CMD1, ESI_SET_SRV_MASK);
1191 serial_out(info, UART_ESI_CMD2, info->IER);
1192 }
1193out:
1194 spin_unlock_irqrestore(&info->lock, flags);
1195}
1196
1197static int rs_write(struct tty_struct *tty,
1198 const unsigned char *buf, int count)
1199{
1200 int c, t, ret = 0;
1201 struct esp_struct *info = tty->driver_data;
1202 unsigned long flags;
1203
1204 if (serial_paranoia_check(info, tty->name, "rs_write"))
1205 return 0;
1206
1207 if (!info->xmit_buf)
1208 return 0;
1209
1210 while (1) {
1211 /* Thanks to R. Wolff for suggesting how to do this with */
1212 /* interrupts enabled */
1213
1214 c = count;
1215 t = ESP_XMIT_SIZE - info->xmit_cnt - 1;
1216
1217 if (t < c)
1218 c = t;
1219
1220 t = ESP_XMIT_SIZE - info->xmit_head;
1221
1222 if (t < c)
1223 c = t;
1224
1225 if (c <= 0)
1226 break;
1227
1228 memcpy(info->xmit_buf + info->xmit_head, buf, c);
1229
1230 info->xmit_head = (info->xmit_head + c) & (ESP_XMIT_SIZE-1);
1231 info->xmit_cnt += c;
1232 buf += c;
1233 count -= c;
1234 ret += c;
1235 }
1236
1237 spin_lock_irqsave(&info->lock, flags);
1238
1239 if (info->xmit_cnt && !tty->stopped && !(info->IER & UART_IER_THRI)) {
1240 info->IER |= UART_IER_THRI;
1241 serial_out(info, UART_ESI_CMD1, ESI_SET_SRV_MASK);
1242 serial_out(info, UART_ESI_CMD2, info->IER);
1243 }
1244
1245 spin_unlock_irqrestore(&info->lock, flags);
1246 return ret;
1247}
1248
1249static int rs_write_room(struct tty_struct *tty)
1250{
1251 struct esp_struct *info = tty->driver_data;
1252 int ret;
1253 unsigned long flags;
1254
1255 if (serial_paranoia_check(info, tty->name, "rs_write_room"))
1256 return 0;
1257
1258 spin_lock_irqsave(&info->lock, flags);
1259
1260 ret = ESP_XMIT_SIZE - info->xmit_cnt - 1;
1261 if (ret < 0)
1262 ret = 0;
1263 spin_unlock_irqrestore(&info->lock, flags);
1264 return ret;
1265}
1266
1267static int rs_chars_in_buffer(struct tty_struct *tty)
1268{
1269 struct esp_struct *info = tty->driver_data;
1270
1271 if (serial_paranoia_check(info, tty->name, "rs_chars_in_buffer"))
1272 return 0;
1273 return info->xmit_cnt;
1274}
1275
1276static void rs_flush_buffer(struct tty_struct *tty)
1277{
1278 struct esp_struct *info = tty->driver_data;
1279 unsigned long flags;
1280
1281 if (serial_paranoia_check(info, tty->name, "rs_flush_buffer"))
1282 return;
1283 spin_lock_irqsave(&info->lock, flags);
1284 info->xmit_cnt = info->xmit_head = info->xmit_tail = 0;
1285 spin_unlock_irqrestore(&info->lock, flags);
1286 tty_wakeup(tty);
1287}
1288
1289/*
1290 * ------------------------------------------------------------
1291 * rs_throttle()
1292 *
1293 * This routine is called by the upper-layer tty layer to signal that
1294 * incoming characters should be throttled.
1295 * ------------------------------------------------------------
1296 */
1297static void rs_throttle(struct tty_struct *tty)
1298{
1299 struct esp_struct *info = tty->driver_data;
1300 unsigned long flags;
1301#ifdef SERIAL_DEBUG_THROTTLE
1302 char buf[64];
1303
1304 printk("throttle %s: %d....\n", tty_name(tty, buf),
1305 tty_chars_in_buffer(tty));
1306#endif
1307
1308 if (serial_paranoia_check(info, tty->name, "rs_throttle"))
1309 return;
1310
1311 spin_lock_irqsave(&info->lock, flags);
1312 info->IER &= ~UART_IER_RDI;
1313 serial_out(info, UART_ESI_CMD1, ESI_SET_SRV_MASK);
1314 serial_out(info, UART_ESI_CMD2, info->IER);
1315 serial_out(info, UART_ESI_CMD1, ESI_SET_RX_TIMEOUT);
1316 serial_out(info, UART_ESI_CMD2, 0x00);
1317 spin_unlock_irqrestore(&info->lock, flags);
1318}
1319
1320static void rs_unthrottle(struct tty_struct *tty)
1321{
1322 struct esp_struct *info = tty->driver_data;
1323 unsigned long flags;
1324#ifdef SERIAL_DEBUG_THROTTLE
1325 char buf[64];
1326
1327 printk(KERN_DEBUG "unthrottle %s: %d....\n", tty_name(tty, buf),
1328 tty_chars_in_buffer(tty));
1329#endif
1330
1331 if (serial_paranoia_check(info, tty->name, "rs_unthrottle"))
1332 return;
1333
1334 spin_lock_irqsave(&info->lock, flags);
1335 info->IER |= UART_IER_RDI;
1336 serial_out(info, UART_ESI_CMD1, ESI_SET_SRV_MASK);
1337 serial_out(info, UART_ESI_CMD2, info->IER);
1338 serial_out(info, UART_ESI_CMD1, ESI_SET_RX_TIMEOUT);
1339 serial_out(info, UART_ESI_CMD2, info->config.rx_timeout);
1340 spin_unlock_irqrestore(&info->lock, flags);
1341}
1342
1343/*
1344 * ------------------------------------------------------------
1345 * rs_ioctl() and friends
1346 * ------------------------------------------------------------
1347 */
1348
1349static int get_serial_info(struct esp_struct *info,
1350 struct serial_struct __user *retinfo)
1351{
1352 struct serial_struct tmp;
1353
1354 lock_kernel();
1355 memset(&tmp, 0, sizeof(tmp));
1356 tmp.type = PORT_16550A;
1357 tmp.line = info->line;
1358 tmp.port = info->io_port;
1359 tmp.irq = info->irq;
1360 tmp.flags = info->port.flags;
1361 tmp.xmit_fifo_size = 1024;
1362 tmp.baud_base = BASE_BAUD;
1363 tmp.close_delay = info->close_delay;
1364 tmp.closing_wait = info->closing_wait;
1365 tmp.custom_divisor = info->custom_divisor;
1366 tmp.hub6 = 0;
1367 unlock_kernel();
1368 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
1369 return -EFAULT;
1370 return 0;
1371}
1372
1373static int get_esp_config(struct esp_struct *info,
1374 struct hayes_esp_config __user *retinfo)
1375{
1376 struct hayes_esp_config tmp;
1377
1378 if (!retinfo)
1379 return -EFAULT;
1380
1381 memset(&tmp, 0, sizeof(tmp));
1382 lock_kernel();
1383 tmp.rx_timeout = info->config.rx_timeout;
1384 tmp.rx_trigger = info->config.rx_trigger;
1385 tmp.tx_trigger = info->config.tx_trigger;
1386 tmp.flow_off = info->config.flow_off;
1387 tmp.flow_on = info->config.flow_on;
1388 tmp.pio_threshold = info->config.pio_threshold;
1389 tmp.dma_channel = (info->stat_flags & ESP_STAT_NEVER_DMA ? 0 : dma);
1390 unlock_kernel();
1391
1392 return copy_to_user(retinfo, &tmp, sizeof(*retinfo)) ? -EFAULT : 0;
1393}
1394
1395static int set_serial_info(struct esp_struct *info,
1396 struct serial_struct __user *new_info)
1397{
1398 struct serial_struct new_serial;
1399 struct esp_struct old_info;
1400 unsigned int change_irq;
1401 int retval = 0;
1402 struct esp_struct *current_async;
1403
1404 if (copy_from_user(&new_serial, new_info, sizeof(new_serial)))
1405 return -EFAULT;
1406 old_info = *info;
1407
1408 if ((new_serial.type != PORT_16550A) ||
1409 (new_serial.hub6) ||
1410 (info->io_port != new_serial.port) ||
1411 (new_serial.baud_base != BASE_BAUD) ||
1412 (new_serial.irq > 15) ||
1413 (new_serial.irq < 2) ||
1414 (new_serial.irq == 6) ||
1415 (new_serial.irq == 8) ||
1416 (new_serial.irq == 13))
1417 return -EINVAL;
1418
1419 change_irq = new_serial.irq != info->irq;
1420
1421 if (change_irq && (info->line % 8))
1422 return -EINVAL;
1423
1424 if (!capable(CAP_SYS_ADMIN)) {
1425 if (change_irq ||
1426 (new_serial.close_delay != info->close_delay) ||
1427 ((new_serial.flags & ~ASYNC_USR_MASK) !=
1428 (info->port.flags & ~ASYNC_USR_MASK)))
1429 return -EPERM;
1430 info->port.flags = ((info->port.flags & ~ASYNC_USR_MASK) |
1431 (new_serial.flags & ASYNC_USR_MASK));
1432 info->custom_divisor = new_serial.custom_divisor;
1433 } else {
1434 if (new_serial.irq == 2)
1435 new_serial.irq = 9;
1436
1437 if (change_irq) {
1438 current_async = ports;
1439
1440 while (current_async) {
1441 if ((current_async->line >= info->line) &&
1442 (current_async->line < (info->line + 8))) {
1443 if (current_async == info) {
1444 if (current_async->port.count > 1)
1445 return -EBUSY;
1446 } else if (current_async->port.count)
1447 return -EBUSY;
1448 }
1449
1450 current_async = current_async->next_port;
1451 }
1452 }
1453
1454 /*
1455 * OK, past this point, all the error checking has been done.
1456 * At this point, we start making changes.....
1457 */
1458
1459 info->port.flags = ((info->port.flags & ~ASYNC_FLAGS) |
1460 (new_serial.flags & ASYNC_FLAGS));
1461 info->custom_divisor = new_serial.custom_divisor;
1462 info->close_delay = new_serial.close_delay * HZ/100;
1463 info->closing_wait = new_serial.closing_wait * HZ/100;
1464
1465 if (change_irq) {
1466 /*
1467 * We need to shutdown the serial port at the old
1468 * port/irq combination.
1469 */
1470 shutdown(info);
1471
1472 current_async = ports;
1473
1474 while (current_async) {
1475 if ((current_async->line >= info->line) &&
1476 (current_async->line < (info->line + 8)))
1477 current_async->irq = new_serial.irq;
1478
1479 current_async = current_async->next_port;
1480 }
1481
1482 serial_out(info, UART_ESI_CMD1, ESI_SET_ENH_IRQ);
1483 if (info->irq == 9)
1484 serial_out(info, UART_ESI_CMD2, 0x02);
1485 else
1486 serial_out(info, UART_ESI_CMD2, info->irq);
1487 }
1488 }
1489
1490 if (info->port.flags & ASYNC_INITIALIZED) {
1491 if (((old_info.port.flags & ASYNC_SPD_MASK) !=
1492 (info->port.flags & ASYNC_SPD_MASK)) ||
1493 (old_info.custom_divisor != info->custom_divisor)) {
1494 if ((info->port.flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
1495 info->port.tty->alt_speed = 57600;
1496 if ((info->port.flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
1497 info->port.tty->alt_speed = 115200;
1498 if ((info->port.flags & ASYNC_SPD_MASK) == ASYNC_SPD_SHI)
1499 info->port.tty->alt_speed = 230400;
1500 if ((info->port.flags & ASYNC_SPD_MASK) == ASYNC_SPD_WARP)
1501 info->port.tty->alt_speed = 460800;
1502 change_speed(info);
1503 }
1504 } else
1505 retval = startup(info);
1506
1507 return retval;
1508}
1509
1510static int set_esp_config(struct esp_struct *info,
1511 struct hayes_esp_config __user *new_info)
1512{
1513 struct hayes_esp_config new_config;
1514 unsigned int change_dma;
1515 int retval = 0;
1516 struct esp_struct *current_async;
1517 unsigned long flags;
1518
1519 /* Perhaps a non-sysadmin user should be able to do some of these */
1520 /* operations. I haven't decided yet. */
1521
1522 if (!capable(CAP_SYS_ADMIN))
1523 return -EPERM;
1524
1525 if (copy_from_user(&new_config, new_info, sizeof(new_config)))
1526 return -EFAULT;
1527
1528 if ((new_config.flow_on >= new_config.flow_off) ||
1529 (new_config.rx_trigger < 1) ||
1530 (new_config.tx_trigger < 1) ||
1531 (new_config.flow_off < 1) ||
1532 (new_config.flow_on < 1) ||
1533 (new_config.rx_trigger > 1023) ||
1534 (new_config.tx_trigger > 1023) ||
1535 (new_config.flow_off > 1023) ||
1536 (new_config.flow_on > 1023) ||
1537 (new_config.pio_threshold < 0) ||
1538 (new_config.pio_threshold > 1024))
1539 return -EINVAL;
1540
1541 if ((new_config.dma_channel != 1) && (new_config.dma_channel != 3))
1542 new_config.dma_channel = 0;
1543
1544 if (info->stat_flags & ESP_STAT_NEVER_DMA)
1545 change_dma = new_config.dma_channel;
1546 else
1547 change_dma = (new_config.dma_channel != dma);
1548
1549 if (change_dma) {
1550 if (new_config.dma_channel) {
1551 /* PIO mode to DMA mode transition OR */
1552 /* change current DMA channel */
1553 current_async = ports;
1554
1555 while (current_async) {
1556 if (current_async == info) {
1557 if (current_async->port.count > 1)
1558 return -EBUSY;
1559 } else if (current_async->port.count)
1560 return -EBUSY;
1561
1562 current_async = current_async->next_port;
1563 }
1564
1565 shutdown(info);
1566 dma = new_config.dma_channel;
1567 info->stat_flags &= ~ESP_STAT_NEVER_DMA;
1568
1569 /* all ports must use the same DMA channel */
1570
1571 spin_lock_irqsave(&info->lock, flags);
1572 current_async = ports;
1573
1574 while (current_async) {
1575 esp_basic_init(current_async);
1576 current_async = current_async->next_port;
1577 }
1578 spin_unlock_irqrestore(&info->lock, flags);
1579 } else {
1580 /* DMA mode to PIO mode only */
1581 if (info->port.count > 1)
1582 return -EBUSY;
1583
1584 shutdown(info);
1585 spin_lock_irqsave(&info->lock, flags);
1586 info->stat_flags |= ESP_STAT_NEVER_DMA;
1587 esp_basic_init(info);
1588 spin_unlock_irqrestore(&info->lock, flags);
1589 }
1590 }
1591
1592 info->config.pio_threshold = new_config.pio_threshold;
1593
1594 if ((new_config.flow_off != info->config.flow_off) ||
1595 (new_config.flow_on != info->config.flow_on)) {
1596 info->config.flow_off = new_config.flow_off;
1597 info->config.flow_on = new_config.flow_on;
1598
1599 spin_lock_irqsave(&info->lock, flags);
1600 serial_out(info, UART_ESI_CMD1, ESI_SET_FLOW_LVL);
1601 serial_out(info, UART_ESI_CMD2, new_config.flow_off >> 8);
1602 serial_out(info, UART_ESI_CMD2, new_config.flow_off);
1603 serial_out(info, UART_ESI_CMD2, new_config.flow_on >> 8);
1604 serial_out(info, UART_ESI_CMD2, new_config.flow_on);
1605 spin_unlock_irqrestore(&info->lock, flags);
1606 }
1607
1608 if ((new_config.rx_trigger != info->config.rx_trigger) ||
1609 (new_config.tx_trigger != info->config.tx_trigger)) {
1610 info->config.rx_trigger = new_config.rx_trigger;
1611 info->config.tx_trigger = new_config.tx_trigger;
1612 spin_lock_irqsave(&info->lock, flags);
1613 serial_out(info, UART_ESI_CMD1, ESI_SET_TRIGGER);
1614 serial_out(info, UART_ESI_CMD2,
1615 new_config.rx_trigger >> 8);
1616 serial_out(info, UART_ESI_CMD2, new_config.rx_trigger);
1617 serial_out(info, UART_ESI_CMD2,
1618 new_config.tx_trigger >> 8);
1619 serial_out(info, UART_ESI_CMD2, new_config.tx_trigger);
1620 spin_unlock_irqrestore(&info->lock, flags);
1621 }
1622
1623 if (new_config.rx_timeout != info->config.rx_timeout) {
1624 info->config.rx_timeout = new_config.rx_timeout;
1625 spin_lock_irqsave(&info->lock, flags);
1626
1627 if (info->IER & UART_IER_RDI) {
1628 serial_out(info, UART_ESI_CMD1,
1629 ESI_SET_RX_TIMEOUT);
1630 serial_out(info, UART_ESI_CMD2,
1631 new_config.rx_timeout);
1632 }
1633
1634 spin_unlock_irqrestore(&info->lock, flags);
1635 }
1636
1637 if (!(info->port.flags & ASYNC_INITIALIZED))
1638 retval = startup(info);
1639
1640 return retval;
1641}
1642
1643/*
1644 * get_lsr_info - get line status register info
1645 *
1646 * Purpose: Let user call ioctl() to get info when the UART physically
1647 * is emptied. On bus types like RS485, the transmitter must
1648 * release the bus after transmitting. This must be done when
1649 * the transmit shift register is empty, not be done when the
1650 * transmit holding register is empty. This functionality
1651 * allows an RS485 driver to be written in user space.
1652 */
1653static int get_lsr_info(struct esp_struct *info, unsigned int __user *value)
1654{
1655 unsigned char status;
1656 unsigned int result;
1657 unsigned long flags;
1658
1659 spin_lock_irqsave(&info->lock, flags);
1660 serial_out(info, UART_ESI_CMD1, ESI_GET_UART_STAT);
1661 status = serial_in(info, UART_ESI_STAT1);
1662 spin_unlock_irqrestore(&info->lock, flags);
1663 result = ((status & UART_LSR_TEMT) ? TIOCSER_TEMT : 0);
1664 return put_user(result, value);
1665}
1666
1667
1668static int esp_tiocmget(struct tty_struct *tty, struct file *file)
1669{
1670 struct esp_struct *info = tty->driver_data;
1671 unsigned char control, status;
1672 unsigned long flags;
1673
1674 if (serial_paranoia_check(info, tty->name, __func__))
1675 return -ENODEV;
1676 if (tty->flags & (1 << TTY_IO_ERROR))
1677 return -EIO;
1678
1679 control = info->MCR;
1680
1681 spin_lock_irqsave(&info->lock, flags);
1682 serial_out(info, UART_ESI_CMD1, ESI_GET_UART_STAT);
1683 status = serial_in(info, UART_ESI_STAT2);
1684 spin_unlock_irqrestore(&info->lock, flags);
1685
1686 return ((control & UART_MCR_RTS) ? TIOCM_RTS : 0)
1687 | ((control & UART_MCR_DTR) ? TIOCM_DTR : 0)
1688 | ((status & UART_MSR_DCD) ? TIOCM_CAR : 0)
1689 | ((status & UART_MSR_RI) ? TIOCM_RNG : 0)
1690 | ((status & UART_MSR_DSR) ? TIOCM_DSR : 0)
1691 | ((status & UART_MSR_CTS) ? TIOCM_CTS : 0);
1692}
1693
1694static int esp_tiocmset(struct tty_struct *tty, struct file *file,
1695 unsigned int set, unsigned int clear)
1696{
1697 struct esp_struct *info = tty->driver_data;
1698 unsigned long flags;
1699
1700 if (serial_paranoia_check(info, tty->name, __func__))
1701 return -ENODEV;
1702 if (tty->flags & (1 << TTY_IO_ERROR))
1703 return -EIO;
1704
1705 spin_lock_irqsave(&info->lock, flags);
1706
1707 if (set & TIOCM_RTS)
1708 info->MCR |= UART_MCR_RTS;
1709 if (set & TIOCM_DTR)
1710 info->MCR |= UART_MCR_DTR;
1711
1712 if (clear & TIOCM_RTS)
1713 info->MCR &= ~UART_MCR_RTS;
1714 if (clear & TIOCM_DTR)
1715 info->MCR &= ~UART_MCR_DTR;
1716
1717 serial_out(info, UART_ESI_CMD1, ESI_WRITE_UART);
1718 serial_out(info, UART_ESI_CMD2, UART_MCR);
1719 serial_out(info, UART_ESI_CMD2, info->MCR);
1720
1721 spin_unlock_irqrestore(&info->lock, flags);
1722 return 0;
1723}
1724
1725/*
1726 * rs_break() --- routine which turns the break handling on or off
1727 */
1728static int esp_break(struct tty_struct *tty, int break_state)
1729{
1730 struct esp_struct *info = tty->driver_data;
1731 unsigned long flags;
1732
1733 if (serial_paranoia_check(info, tty->name, "esp_break"))
1734 return -EINVAL;
1735
1736 if (break_state == -1) {
1737 spin_lock_irqsave(&info->lock, flags);
1738 serial_out(info, UART_ESI_CMD1, ESI_ISSUE_BREAK);
1739 serial_out(info, UART_ESI_CMD2, 0x01);
1740 spin_unlock_irqrestore(&info->lock, flags);
1741
1742 /* FIXME - new style wait needed here */
1743 interruptible_sleep_on(&info->break_wait);
1744 } else {
1745 spin_lock_irqsave(&info->lock, flags);
1746 serial_out(info, UART_ESI_CMD1, ESI_ISSUE_BREAK);
1747 serial_out(info, UART_ESI_CMD2, 0x00);
1748 spin_unlock_irqrestore(&info->lock, flags);
1749 }
1750 return 0;
1751}
1752
1753static int rs_ioctl(struct tty_struct *tty, struct file *file,
1754 unsigned int cmd, unsigned long arg)
1755{
1756 struct esp_struct *info = tty->driver_data;
1757 struct async_icount cprev, cnow; /* kernel counter temps */
1758 struct serial_icounter_struct __user *p_cuser; /* user space */
1759 void __user *argp = (void __user *)arg;
1760 unsigned long flags;
1761 int ret;
1762
1763 if (serial_paranoia_check(info, tty->name, "rs_ioctl"))
1764 return -ENODEV;
1765
1766 if ((cmd != TIOCGSERIAL) && (cmd != TIOCSSERIAL) &&
1767 (cmd != TIOCSERCONFIG) && (cmd != TIOCSERGWILD) &&
1768 (cmd != TIOCSERSWILD) && (cmd != TIOCSERGSTRUCT) &&
1769 (cmd != TIOCMIWAIT) && (cmd != TIOCGICOUNT) &&
1770 (cmd != TIOCGHAYESESP) && (cmd != TIOCSHAYESESP)) {
1771 if (tty->flags & (1 << TTY_IO_ERROR))
1772 return -EIO;
1773 }
1774
1775 switch (cmd) {
1776 case TIOCGSERIAL:
1777 return get_serial_info(info, argp);
1778 case TIOCSSERIAL:
1779 lock_kernel();
1780 ret = set_serial_info(info, argp);
1781 unlock_kernel();
1782 return ret;
1783 case TIOCSERGWILD:
1784 return put_user(0L, (unsigned long __user *)argp);
1785 case TIOCSERGETLSR: /* Get line status register */
1786 return get_lsr_info(info, argp);
1787 case TIOCSERSWILD:
1788 if (!capable(CAP_SYS_ADMIN))
1789 return -EPERM;
1790 return 0;
1791 /*
1792 * Wait for any of the 4 modem inputs (DCD,RI,DSR,CTS) to change
1793 * - mask passed in arg for lines of interest
1794 * (use |'ed TIOCM_RNG/DSR/CD/CTS for masking)
1795 * Caller should use TIOCGICOUNT to see which one it was
1796 */
1797 case TIOCMIWAIT:
1798 spin_lock_irqsave(&info->lock, flags);
1799 cprev = info->icount; /* note the counters on entry */
1800 spin_unlock_irqrestore(&info->lock, flags);
1801 while (1) {
1802 /* FIXME: convert to new style wakeup */
1803 interruptible_sleep_on(&info->port.delta_msr_wait);
1804 /* see if a signal did it */
1805 if (signal_pending(current))
1806 return -ERESTARTSYS;
1807 spin_lock_irqsave(&info->lock, flags);
1808 cnow = info->icount; /* atomic copy */
1809 spin_unlock_irqrestore(&info->lock, flags);
1810 if (cnow.rng == cprev.rng &&
1811 cnow.dsr == cprev.dsr &&
1812 cnow.dcd == cprev.dcd &&
1813 cnow.cts == cprev.cts)
1814 return -EIO; /* no change => error */
1815 if (((arg & TIOCM_RNG) &&
1816 (cnow.rng != cprev.rng)) ||
1817 ((arg & TIOCM_DSR) &&
1818 (cnow.dsr != cprev.dsr)) ||
1819 ((arg & TIOCM_CD) &&
1820 (cnow.dcd != cprev.dcd)) ||
1821 ((arg & TIOCM_CTS) &&
1822 (cnow.cts != cprev.cts))) {
1823 return 0;
1824 }
1825 cprev = cnow;
1826 }
1827 /* NOTREACHED */
1828 /*
1829 * Get counter of input serial line interrupts (DCD,RI,DSR,CTS)
1830 * Return: write counters to the user passed counter struct
1831 * NB: both 1->0 and 0->1 transitions are counted except for
1832 * RI where only 0->1 is counted.
1833 */
1834 case TIOCGICOUNT:
1835 spin_lock_irqsave(&info->lock, flags);
1836 cnow = info->icount;
1837 spin_unlock_irqrestore(&info->lock, flags);
1838 p_cuser = argp;
1839 if (put_user(cnow.cts, &p_cuser->cts) ||
1840 put_user(cnow.dsr, &p_cuser->dsr) ||
1841 put_user(cnow.rng, &p_cuser->rng) ||
1842 put_user(cnow.dcd, &p_cuser->dcd))
1843 return -EFAULT;
1844 return 0;
1845 case TIOCGHAYESESP:
1846 return get_esp_config(info, argp);
1847 case TIOCSHAYESESP:
1848 lock_kernel();
1849 ret = set_esp_config(info, argp);
1850 unlock_kernel();
1851 return ret;
1852 default:
1853 return -ENOIOCTLCMD;
1854 }
1855 return 0;
1856}
1857
1858static void rs_set_termios(struct tty_struct *tty, struct ktermios *old_termios)
1859{
1860 struct esp_struct *info = tty->driver_data;
1861 unsigned long flags;
1862
1863 change_speed(info);
1864
1865 spin_lock_irqsave(&info->lock, flags);
1866
1867 /* Handle transition to B0 status */
1868 if ((old_termios->c_cflag & CBAUD) &&
1869 !(tty->termios->c_cflag & CBAUD)) {
1870 info->MCR &= ~(UART_MCR_DTR|UART_MCR_RTS);
1871 serial_out(info, UART_ESI_CMD1, ESI_WRITE_UART);
1872 serial_out(info, UART_ESI_CMD2, UART_MCR);
1873 serial_out(info, UART_ESI_CMD2, info->MCR);
1874 }
1875
1876 /* Handle transition away from B0 status */
1877 if (!(old_termios->c_cflag & CBAUD) &&
1878 (tty->termios->c_cflag & CBAUD)) {
1879 info->MCR |= (UART_MCR_DTR | UART_MCR_RTS);
1880 serial_out(info, UART_ESI_CMD1, ESI_WRITE_UART);
1881 serial_out(info, UART_ESI_CMD2, UART_MCR);
1882 serial_out(info, UART_ESI_CMD2, info->MCR);
1883 }
1884
1885 spin_unlock_irqrestore(&info->lock, flags);
1886
1887 /* Handle turning of CRTSCTS */
1888 if ((old_termios->c_cflag & CRTSCTS) &&
1889 !(tty->termios->c_cflag & CRTSCTS)) {
1890 rs_start(tty);
1891 }
1892}
1893
1894/*
1895 * ------------------------------------------------------------
1896 * rs_close()
1897 *
1898 * This routine is called when the serial port gets closed. First, we
1899 * wait for the last remaining data to be sent. Then, we unlink its
1900 * async structure from the interrupt chain if necessary, and we free
1901 * that IRQ if nothing is left in the chain.
1902 * ------------------------------------------------------------
1903 */
1904static void rs_close(struct tty_struct *tty, struct file *filp)
1905{
1906 struct esp_struct *info = tty->driver_data;
1907 unsigned long flags;
1908
1909 if (!info || serial_paranoia_check(info, tty->name, "rs_close"))
1910 return;
1911
1912 spin_lock_irqsave(&info->lock, flags);
1913
1914 if (tty_hung_up_p(filp)) {
1915 DBG_CNT("before DEC-hung");
1916 goto out;
1917 }
1918
1919#ifdef SERIAL_DEBUG_OPEN
1920 printk(KERN_DEBUG "rs_close ttys%d, count = %d\n",
1921 info->line, info->port.count);
1922#endif
1923 if (tty->count == 1 && info->port.count != 1) {
1924 /*
1925 * Uh, oh. tty->count is 1, which means that the tty
1926 * structure will be freed. Info->count should always
1927 * be one in these conditions. If it's greater than
1928 * one, we've got real problems, since it means the
1929 * serial port won't be shutdown.
1930 */
1931 printk(KERN_DEBUG "rs_close: bad serial port count; tty->count is 1, info->port.count is %d\n", info->port.count);
1932 info->port.count = 1;
1933 }
1934 if (--info->port.count < 0) {
1935 printk(KERN_ERR "rs_close: bad serial port count for ttys%d: %d\n",
1936 info->line, info->port.count);
1937 info->port.count = 0;
1938 }
1939 if (info->port.count) {
1940 DBG_CNT("before DEC-2");
1941 goto out;
1942 }
1943 info->port.flags |= ASYNC_CLOSING;
1944
1945 spin_unlock_irqrestore(&info->lock, flags);
1946 /*
1947 * Now we wait for the transmit buffer to clear; and we notify
1948 * the line discipline to only process XON/XOFF characters.
1949 */
1950 tty->closing = 1;
1951 if (info->closing_wait != ASYNC_CLOSING_WAIT_NONE)
1952 tty_wait_until_sent(tty, info->closing_wait);
1953 /*
1954 * At this point we stop accepting input. To do this, we
1955 * disable the receive line status interrupts, and tell the
1956 * interrupt driver to stop checking the data ready bit in the
1957 * line status register.
1958 */
1959 /* info->IER &= ~UART_IER_RLSI; */
1960 info->IER &= ~UART_IER_RDI;
1961 info->read_status_mask &= ~UART_LSR_DR;
1962 if (info->port.flags & ASYNC_INITIALIZED) {
1963
1964 spin_lock_irqsave(&info->lock, flags);
1965 serial_out(info, UART_ESI_CMD1, ESI_SET_SRV_MASK);
1966 serial_out(info, UART_ESI_CMD2, info->IER);
1967
1968 /* disable receive timeout */
1969 serial_out(info, UART_ESI_CMD1, ESI_SET_RX_TIMEOUT);
1970 serial_out(info, UART_ESI_CMD2, 0x00);
1971
1972 spin_unlock_irqrestore(&info->lock, flags);
1973
1974 /*
1975 * Before we drop DTR, make sure the UART transmitter
1976 * has completely drained; this is especially
1977 * important if there is a transmit FIFO!
1978 */
1979 rs_wait_until_sent(tty, info->timeout);
1980 }
1981 shutdown(info);
1982 rs_flush_buffer(tty);
1983 tty_ldisc_flush(tty);
1984 tty->closing = 0;
1985 info->port.tty = NULL;
1986
1987 if (info->port.blocked_open) {
1988 if (info->close_delay)
1989 msleep_interruptible(jiffies_to_msecs(info->close_delay));
1990 wake_up_interruptible(&info->port.open_wait);
1991 }
1992 info->port.flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING);
1993 wake_up_interruptible(&info->port.close_wait);
1994 return;
1995
1996out:
1997 spin_unlock_irqrestore(&info->lock, flags);
1998}
1999
2000static void rs_wait_until_sent(struct tty_struct *tty, int timeout)
2001{
2002 struct esp_struct *info = tty->driver_data;
2003 unsigned long orig_jiffies, char_time;
2004 unsigned long flags;
2005
2006 if (serial_paranoia_check(info, tty->name, "rs_wait_until_sent"))
2007 return;
2008
2009 orig_jiffies = jiffies;
2010 char_time = ((info->timeout - HZ / 50) / 1024) / 5;
2011
2012 if (!char_time)
2013 char_time = 1;
2014
2015 spin_lock_irqsave(&info->lock, flags);
2016 serial_out(info, UART_ESI_CMD1, ESI_NO_COMMAND);
2017 serial_out(info, UART_ESI_CMD1, ESI_GET_TX_AVAIL);
2018
2019 while ((serial_in(info, UART_ESI_STAT1) != 0x03) ||
2020 (serial_in(info, UART_ESI_STAT2) != 0xff)) {
2021
2022 spin_unlock_irqrestore(&info->lock, flags);
2023 msleep_interruptible(jiffies_to_msecs(char_time));
2024
2025 if (signal_pending(current))
2026 return;
2027
2028 if (timeout && time_after(jiffies, orig_jiffies + timeout))
2029 return;
2030
2031 spin_lock_irqsave(&info->lock, flags);
2032 serial_out(info, UART_ESI_CMD1, ESI_NO_COMMAND);
2033 serial_out(info, UART_ESI_CMD1, ESI_GET_TX_AVAIL);
2034 }
2035 spin_unlock_irqrestore(&info->lock, flags);
2036 set_current_state(TASK_RUNNING);
2037}
2038
2039/*
2040 * esp_hangup() --- called by tty_hangup() when a hangup is signaled.
2041 */
2042static void esp_hangup(struct tty_struct *tty)
2043{
2044 struct esp_struct *info = tty->driver_data;
2045
2046 if (serial_paranoia_check(info, tty->name, "esp_hangup"))
2047 return;
2048
2049 rs_flush_buffer(tty);
2050 shutdown(info);
2051 info->port.count = 0;
2052 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
2053 info->port.tty = NULL;
2054 wake_up_interruptible(&info->port.open_wait);
2055}
2056
2057static int esp_carrier_raised(struct tty_port *port)
2058{
2059 struct esp_struct *info = container_of(port, struct esp_struct, port);
2060 serial_out(info, UART_ESI_CMD1, ESI_GET_UART_STAT);
2061 if (serial_in(info, UART_ESI_STAT2) & UART_MSR_DCD)
2062 return 1;
2063 return 0;
2064}
2065
2066/*
2067 * ------------------------------------------------------------
2068 * esp_open() and friends
2069 * ------------------------------------------------------------
2070 */
2071static int block_til_ready(struct tty_struct *tty, struct file *filp,
2072 struct esp_struct *info)
2073{
2074 DECLARE_WAITQUEUE(wait, current);
2075 int retval;
2076 int do_clocal = 0;
2077 unsigned long flags;
2078 int cd;
2079 struct tty_port *port = &info->port;
2080
2081 /*
2082 * If the device is in the middle of being closed, then block
2083 * until it's done, and then try again.
2084 */
2085 if (tty_hung_up_p(filp) ||
2086 (port->flags & ASYNC_CLOSING)) {
2087 if (port->flags & ASYNC_CLOSING)
2088 interruptible_sleep_on(&port->close_wait);
2089#ifdef SERIAL_DO_RESTART
2090 if (port->flags & ASYNC_HUP_NOTIFY)
2091 return -EAGAIN;
2092 else
2093 return -ERESTARTSYS;
2094#else
2095 return -EAGAIN;
2096#endif
2097 }
2098
2099 /*
2100 * If non-blocking mode is set, or the port is not enabled,
2101 * then make the check up front and then exit.
2102 */
2103 if ((filp->f_flags & O_NONBLOCK) ||
2104 (tty->flags & (1 << TTY_IO_ERROR))) {
2105 port->flags |= ASYNC_NORMAL_ACTIVE;
2106 return 0;
2107 }
2108
2109 if (tty->termios->c_cflag & CLOCAL)
2110 do_clocal = 1;
2111
2112 /*
2113 * Block waiting for the carrier detect and the line to become
2114 * free (i.e., not in use by the callout). While we are in
2115 * this loop, port->count is dropped by one, so that
2116 * rs_close() knows when to free things. We restore it upon
2117 * exit, either normal or abnormal.
2118 */
2119 retval = 0;
2120 add_wait_queue(&port->open_wait, &wait);
2121#ifdef SERIAL_DEBUG_OPEN
2122 printk(KERN_DEBUG "block_til_ready before block: ttys%d, count = %d\n",
2123 info->line, port->count);
2124#endif
2125 spin_lock_irqsave(&info->lock, flags);
2126 if (!tty_hung_up_p(filp))
2127 port->count--;
2128 port->blocked_open++;
2129 while (1) {
2130 if ((tty->termios->c_cflag & CBAUD)) {
2131 unsigned int scratch;
2132
2133 serial_out(info, UART_ESI_CMD1, ESI_READ_UART);
2134 serial_out(info, UART_ESI_CMD2, UART_MCR);
2135 scratch = serial_in(info, UART_ESI_STAT1);
2136 serial_out(info, UART_ESI_CMD1, ESI_WRITE_UART);
2137 serial_out(info, UART_ESI_CMD2, UART_MCR);
2138 serial_out(info, UART_ESI_CMD2,
2139 scratch | UART_MCR_DTR | UART_MCR_RTS);
2140 }
2141 set_current_state(TASK_INTERRUPTIBLE);
2142 if (tty_hung_up_p(filp) ||
2143 !(port->flags & ASYNC_INITIALIZED)) {
2144#ifdef SERIAL_DO_RESTART
2145 if (port->flags & ASYNC_HUP_NOTIFY)
2146 retval = -EAGAIN;
2147 else
2148 retval = -ERESTARTSYS;
2149#else
2150 retval = -EAGAIN;
2151#endif
2152 break;
2153 }
2154
2155 cd = tty_port_carrier_raised(port);
2156
2157 if (!(port->flags & ASYNC_CLOSING) &&
2158 (do_clocal))
2159 break;
2160 if (signal_pending(current)) {
2161 retval = -ERESTARTSYS;
2162 break;
2163 }
2164#ifdef SERIAL_DEBUG_OPEN
2165 printk(KERN_DEBUG "block_til_ready blocking: ttys%d, count = %d\n",
2166 info->line, port->count);
2167#endif
2168 spin_unlock_irqrestore(&info->lock, flags);
2169 schedule();
2170 spin_lock_irqsave(&info->lock, flags);
2171 }
2172 set_current_state(TASK_RUNNING);
2173 remove_wait_queue(&port->open_wait, &wait);
2174 if (!tty_hung_up_p(filp))
2175 port->count++;
2176 port->blocked_open--;
2177 spin_unlock_irqrestore(&info->lock, flags);
2178#ifdef SERIAL_DEBUG_OPEN
2179 printk(KERN_DEBUG "block_til_ready after blocking: ttys%d, count = %d\n",
2180 info->line, port->count);
2181#endif
2182 if (retval)
2183 return retval;
2184 port->flags |= ASYNC_NORMAL_ACTIVE;
2185 return 0;
2186}
2187
2188/*
2189 * This routine is called whenever a serial port is opened. It
2190 * enables interrupts for a serial port, linking in its async structure into
2191 * the IRQ chain. It also performs the serial-specific
2192 * initialization for the tty structure.
2193 */
2194static int esp_open(struct tty_struct *tty, struct file *filp)
2195{
2196 struct esp_struct *info;
2197 int retval, line;
2198 unsigned long flags;
2199
2200 line = tty->index;
2201 if ((line < 0) || (line >= NR_PORTS))
2202 return -ENODEV;
2203
2204 /* find the port in the chain */
2205
2206 info = ports;
2207
2208 while (info && (info->line != line))
2209 info = info->next_port;
2210
2211 if (!info) {
2212 serial_paranoia_check(info, tty->name, "esp_open");
2213 return -ENODEV;
2214 }
2215
2216#ifdef SERIAL_DEBUG_OPEN
2217 printk(KERN_DEBUG "esp_open %s, count = %d\n", tty->name, info->port.count);
2218#endif
2219 spin_lock_irqsave(&info->lock, flags);
2220 info->port.count++;
2221 tty->driver_data = info;
2222 info->port.tty = tty;
2223
2224 spin_unlock_irqrestore(&info->lock, flags);
2225
2226 /*
2227 * Start up serial port
2228 */
2229 retval = startup(info);
2230 if (retval)
2231 return retval;
2232
2233 retval = block_til_ready(tty, filp, info);
2234 if (retval) {
2235#ifdef SERIAL_DEBUG_OPEN
2236 printk(KERN_DEBUG "esp_open returning after block_til_ready with %d\n",
2237 retval);
2238#endif
2239 return retval;
2240 }
2241#ifdef SERIAL_DEBUG_OPEN
2242 printk(KERN_DEBUG "esp_open %s successful...", tty->name);
2243#endif
2244 return 0;
2245}
2246
2247/*
2248 * ---------------------------------------------------------------------
2249 * espserial_init() and friends
2250 *
2251 * espserial_init() is called at boot-time to initialize the serial driver.
2252 * ---------------------------------------------------------------------
2253 */
2254
2255/*
2256 * This routine prints out the appropriate serial driver version
2257 * number, and identifies which options were configured into this
2258 * driver.
2259 */
2260
2261static void __init show_serial_version(void)
2262{
2263 printk(KERN_INFO "%s version %s (DMA %u)\n",
2264 serial_name, serial_version, dma);
2265}
2266
2267/*
2268 * This routine is called by espserial_init() to initialize a specific serial
2269 * port.
2270 */
2271static int autoconfig(struct esp_struct *info)
2272{
2273 int port_detected = 0;
2274 unsigned long flags;
2275
2276 if (!request_region(info->io_port, REGION_SIZE, "esp serial"))
2277 return -EIO;
2278
2279 spin_lock_irqsave(&info->lock, flags);
2280 /*
2281 * Check for ESP card
2282 */
2283
2284 if (serial_in(info, UART_ESI_BASE) == 0xf3) {
2285 serial_out(info, UART_ESI_CMD1, 0x00);
2286 serial_out(info, UART_ESI_CMD1, 0x01);
2287
2288 if ((serial_in(info, UART_ESI_STAT2) & 0x70) == 0x20) {
2289 port_detected = 1;
2290
2291 if (!(info->irq)) {
2292 serial_out(info, UART_ESI_CMD1, 0x02);
2293
2294 if (serial_in(info, UART_ESI_STAT1) & 0x01)
2295 info->irq = 3;
2296 else
2297 info->irq = 4;
2298 }
2299
2300
2301 /* put card in enhanced mode */
2302 /* this prevents access through */
2303 /* the "old" IO ports */
2304 esp_basic_init(info);
2305
2306 /* clear out MCR */
2307 serial_out(info, UART_ESI_CMD1, ESI_WRITE_UART);
2308 serial_out(info, UART_ESI_CMD2, UART_MCR);
2309 serial_out(info, UART_ESI_CMD2, 0x00);
2310 }
2311 }
2312 if (!port_detected)
2313 release_region(info->io_port, REGION_SIZE);
2314
2315 spin_unlock_irqrestore(&info->lock, flags);
2316 return (port_detected);
2317}
2318
2319static const struct tty_operations esp_ops = {
2320 .open = esp_open,
2321 .close = rs_close,
2322 .write = rs_write,
2323 .put_char = rs_put_char,
2324 .flush_chars = rs_flush_chars,
2325 .write_room = rs_write_room,
2326 .chars_in_buffer = rs_chars_in_buffer,
2327 .flush_buffer = rs_flush_buffer,
2328 .ioctl = rs_ioctl,
2329 .throttle = rs_throttle,
2330 .unthrottle = rs_unthrottle,
2331 .set_termios = rs_set_termios,
2332 .stop = rs_stop,
2333 .start = rs_start,
2334 .hangup = esp_hangup,
2335 .break_ctl = esp_break,
2336 .wait_until_sent = rs_wait_until_sent,
2337 .tiocmget = esp_tiocmget,
2338 .tiocmset = esp_tiocmset,
2339};
2340
2341static const struct tty_port_operations esp_port_ops = {
2342 .esp_carrier_raised,
2343};
2344
2345/*
2346 * The serial driver boot-time initialization code!
2347 */
2348static int __init espserial_init(void)
2349{
2350 int i, offset;
2351 struct esp_struct *info;
2352 struct esp_struct *last_primary = NULL;
2353 int esp[] = { 0x100, 0x140, 0x180, 0x200, 0x240, 0x280, 0x300, 0x380 };
2354
2355 esp_driver = alloc_tty_driver(NR_PORTS);
2356 if (!esp_driver)
2357 return -ENOMEM;
2358
2359 for (i = 0; i < NR_PRIMARY; i++) {
2360 if (irq[i] != 0) {
2361 if ((irq[i] < 2) || (irq[i] > 15) || (irq[i] == 6) ||
2362 (irq[i] == 8) || (irq[i] == 13))
2363 irq[i] = 0;
2364 else if (irq[i] == 2)
2365 irq[i] = 9;
2366 }
2367 }
2368
2369 if ((dma != 1) && (dma != 3))
2370 dma = 0;
2371
2372 if ((rx_trigger < 1) || (rx_trigger > 1023))
2373 rx_trigger = 768;
2374
2375 if ((tx_trigger < 1) || (tx_trigger > 1023))
2376 tx_trigger = 768;
2377
2378 if ((flow_off < 1) || (flow_off > 1023))
2379 flow_off = 1016;
2380
2381 if ((flow_on < 1) || (flow_on > 1023))
2382 flow_on = 944;
2383
2384 if ((rx_timeout < 0) || (rx_timeout > 255))
2385 rx_timeout = 128;
2386
2387 if (flow_on >= flow_off)
2388 flow_on = flow_off - 1;
2389
2390 show_serial_version();
2391
2392 /* Initialize the tty_driver structure */
2393
2394 esp_driver->owner = THIS_MODULE;
2395 esp_driver->name = "ttyP";
2396 esp_driver->major = ESP_IN_MAJOR;
2397 esp_driver->minor_start = 0;
2398 esp_driver->type = TTY_DRIVER_TYPE_SERIAL;
2399 esp_driver->subtype = SERIAL_TYPE_NORMAL;
2400 esp_driver->init_termios = tty_std_termios;
2401 esp_driver->init_termios.c_cflag =
2402 B9600 | CS8 | CREAD | HUPCL | CLOCAL;
2403 esp_driver->init_termios.c_ispeed = 9600;
2404 esp_driver->init_termios.c_ospeed = 9600;
2405 esp_driver->flags = TTY_DRIVER_REAL_RAW;
2406 tty_set_operations(esp_driver, &esp_ops);
2407 if (tty_register_driver(esp_driver)) {
2408 printk(KERN_ERR "Couldn't register esp serial driver");
2409 put_tty_driver(esp_driver);
2410 return 1;
2411 }
2412
2413 info = kzalloc(sizeof(struct esp_struct), GFP_KERNEL);
2414
2415 if (!info) {
2416 printk(KERN_ERR "Couldn't allocate memory for esp serial device information\n");
2417 tty_unregister_driver(esp_driver);
2418 put_tty_driver(esp_driver);
2419 return 1;
2420 }
2421
2422 spin_lock_init(&info->lock);
2423 /* rx_trigger, tx_trigger are needed by autoconfig */
2424 info->config.rx_trigger = rx_trigger;
2425 info->config.tx_trigger = tx_trigger;
2426
2427 i = 0;
2428 offset = 0;
2429
2430 do {
2431 tty_port_init(&info->port);
2432 info->port.ops = &esp_port_ops;
2433 info->io_port = esp[i] + offset;
2434 info->irq = irq[i];
2435 info->line = (i * 8) + (offset / 8);
2436
2437 if (!autoconfig(info)) {
2438 i++;
2439 offset = 0;
2440 continue;
2441 }
2442
2443 info->custom_divisor = (divisor[i] >> (offset / 2)) & 0xf;
2444 info->port.flags = STD_COM_FLAGS;
2445 if (info->custom_divisor)
2446 info->port.flags |= ASYNC_SPD_CUST;
2447 info->magic = ESP_MAGIC;
2448 info->close_delay = 5*HZ/10;
2449 info->closing_wait = 30*HZ;
2450 info->config.rx_timeout = rx_timeout;
2451 info->config.flow_on = flow_on;
2452 info->config.flow_off = flow_off;
2453 info->config.pio_threshold = pio_threshold;
2454 info->next_port = ports;
2455 init_waitqueue_head(&info->break_wait);
2456 ports = info;
2457 printk(KERN_INFO "ttyP%d at 0x%04x (irq = %d) is an ESP ",
2458 info->line, info->io_port, info->irq);
2459
2460 if (info->line % 8) {
2461 printk("secondary port\n");
2462 /* 8 port cards can't do DMA */
2463 info->stat_flags |= ESP_STAT_NEVER_DMA;
2464
2465 if (last_primary)
2466 last_primary->stat_flags |= ESP_STAT_NEVER_DMA;
2467 } else {
2468 printk("primary port\n");
2469 last_primary = info;
2470 irq[i] = info->irq;
2471 }
2472
2473 if (!dma)
2474 info->stat_flags |= ESP_STAT_NEVER_DMA;
2475
2476 info = kzalloc(sizeof(struct esp_struct), GFP_KERNEL);
2477 if (!info) {
2478 printk(KERN_ERR "Couldn't allocate memory for esp serial device information\n");
2479 /* allow use of the already detected ports */
2480 return 0;
2481 }
2482
2483 spin_lock_init(&info->lock);
2484 /* rx_trigger, tx_trigger are needed by autoconfig */
2485 info->config.rx_trigger = rx_trigger;
2486 info->config.tx_trigger = tx_trigger;
2487
2488 if (offset == 56) {
2489 i++;
2490 offset = 0;
2491 } else {
2492 offset += 8;
2493 }
2494 } while (i < NR_PRIMARY);
2495
2496 /* free the last port memory allocation */
2497 kfree(info);
2498
2499 return 0;
2500}
2501
2502static void __exit espserial_exit(void)
2503{
2504 int e1;
2505 struct esp_struct *temp_async;
2506 struct esp_pio_buffer *pio_buf;
2507
2508 e1 = tty_unregister_driver(esp_driver);
2509 if (e1)
2510 printk(KERN_ERR "esp: failed to unregister driver (%d)\n", e1);
2511 put_tty_driver(esp_driver);
2512
2513 while (ports) {
2514 if (ports->io_port)
2515 release_region(ports->io_port, REGION_SIZE);
2516 temp_async = ports->next_port;
2517 kfree(ports);
2518 ports = temp_async;
2519 }
2520
2521 if (dma_buffer)
2522 free_pages((unsigned long)dma_buffer,
2523 get_order(DMA_BUFFER_SZ));
2524
2525 while (free_pio_buf) {
2526 pio_buf = free_pio_buf->next;
2527 kfree(free_pio_buf);
2528 free_pio_buf = pio_buf;
2529 }
2530}
2531
2532module_init(espserial_init);
2533module_exit(espserial_exit);
diff --git a/drivers/char/generic_nvram.c b/drivers/char/generic_nvram.c
index ef31738c2cbe..fda4181b5e67 100644
--- a/drivers/char/generic_nvram.c
+++ b/drivers/char/generic_nvram.c
@@ -19,7 +19,6 @@
19#include <linux/miscdevice.h> 19#include <linux/miscdevice.h>
20#include <linux/fcntl.h> 20#include <linux/fcntl.h>
21#include <linux/init.h> 21#include <linux/init.h>
22#include <linux/smp_lock.h>
23#include <asm/uaccess.h> 22#include <asm/uaccess.h>
24#include <asm/nvram.h> 23#include <asm/nvram.h>
25#ifdef CONFIG_PPC_PMAC 24#ifdef CONFIG_PPC_PMAC
@@ -32,7 +31,6 @@ static ssize_t nvram_len;
32 31
33static loff_t nvram_llseek(struct file *file, loff_t offset, int origin) 32static loff_t nvram_llseek(struct file *file, loff_t offset, int origin)
34{ 33{
35 lock_kernel();
36 switch (origin) { 34 switch (origin) {
37 case 1: 35 case 1:
38 offset += file->f_pos; 36 offset += file->f_pos;
@@ -41,12 +39,11 @@ static loff_t nvram_llseek(struct file *file, loff_t offset, int origin)
41 offset += nvram_len; 39 offset += nvram_len;
42 break; 40 break;
43 } 41 }
44 if (offset < 0) { 42 if (offset < 0)
45 unlock_kernel();
46 return -EINVAL; 43 return -EINVAL;
47 } 44
48 file->f_pos = offset; 45 file->f_pos = offset;
49 unlock_kernel(); 46
50 return file->f_pos; 47 return file->f_pos;
51} 48}
52 49
diff --git a/drivers/char/generic_serial.c b/drivers/char/generic_serial.c
index d400cbd280f2..5954ee1dc953 100644
--- a/drivers/char/generic_serial.c
+++ b/drivers/char/generic_serial.c
@@ -29,6 +29,7 @@
29#include <linux/interrupt.h> 29#include <linux/interrupt.h>
30#include <linux/tty_flip.h> 30#include <linux/tty_flip.h>
31#include <linux/delay.h> 31#include <linux/delay.h>
32#include <linux/gfp.h>
32#include <asm/uaccess.h> 33#include <asm/uaccess.h>
33 34
34#define DEBUG 35#define DEBUG
diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
index 70a770ac0138..9ded667625ac 100644
--- a/drivers/char/hpet.c
+++ b/drivers/char/hpet.c
@@ -31,6 +31,7 @@
31#include <linux/seq_file.h> 31#include <linux/seq_file.h>
32#include <linux/bitops.h> 32#include <linux/bitops.h>
33#include <linux/clocksource.h> 33#include <linux/clocksource.h>
34#include <linux/slab.h>
34 35
35#include <asm/current.h> 36#include <asm/current.h>
36#include <asm/uaccess.h> 37#include <asm/uaccess.h>
@@ -215,9 +216,7 @@ static void hpet_timer_set_irq(struct hpet_dev *devp)
215 else 216 else
216 v &= ~0xffff; 217 v &= ~0xffff;
217 218
218 for (irq = find_first_bit(&v, HPET_MAX_IRQ); irq < HPET_MAX_IRQ; 219 for_each_set_bit(irq, &v, HPET_MAX_IRQ) {
219 irq = find_next_bit(&v, HPET_MAX_IRQ, 1 + irq)) {
220
221 if (irq >= nr_irqs) { 220 if (irq >= nr_irqs) {
222 irq = HPET_MAX_IRQ; 221 irq = HPET_MAX_IRQ;
223 break; 222 break;
@@ -675,36 +674,33 @@ static int hpet_is_known(struct hpet_data *hdp)
675 674
676static ctl_table hpet_table[] = { 675static ctl_table hpet_table[] = {
677 { 676 {
678 .ctl_name = CTL_UNNUMBERED,
679 .procname = "max-user-freq", 677 .procname = "max-user-freq",
680 .data = &hpet_max_freq, 678 .data = &hpet_max_freq,
681 .maxlen = sizeof(int), 679 .maxlen = sizeof(int),
682 .mode = 0644, 680 .mode = 0644,
683 .proc_handler = &proc_dointvec, 681 .proc_handler = proc_dointvec,
684 }, 682 },
685 {.ctl_name = 0} 683 {}
686}; 684};
687 685
688static ctl_table hpet_root[] = { 686static ctl_table hpet_root[] = {
689 { 687 {
690 .ctl_name = CTL_UNNUMBERED,
691 .procname = "hpet", 688 .procname = "hpet",
692 .maxlen = 0, 689 .maxlen = 0,
693 .mode = 0555, 690 .mode = 0555,
694 .child = hpet_table, 691 .child = hpet_table,
695 }, 692 },
696 {.ctl_name = 0} 693 {}
697}; 694};
698 695
699static ctl_table dev_root[] = { 696static ctl_table dev_root[] = {
700 { 697 {
701 .ctl_name = CTL_DEV,
702 .procname = "dev", 698 .procname = "dev",
703 .maxlen = 0, 699 .maxlen = 0,
704 .mode = 0555, 700 .mode = 0555,
705 .child = hpet_root, 701 .child = hpet_root,
706 }, 702 },
707 {.ctl_name = 0} 703 {}
708}; 704};
709 705
710static struct ctl_table_header *sysctl_header; 706static struct ctl_table_header *sysctl_header;
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
87static struct hv_ops hvc_beat_get_put_ops = { 87static 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
100static int __init hvc_beat_console_init(void) 100static 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 a632f25f144a..35cca4c7fb18 100644
--- a/drivers/char/hvc_console.c
+++ b/drivers/char/hvc_console.c
@@ -38,6 +38,7 @@
38#include <linux/spinlock.h> 38#include <linux/spinlock.h>
39#include <linux/delay.h> 39#include <linux/delay.h>
40#include <linux/freezer.h> 40#include <linux/freezer.h>
41#include <linux/slab.h>
41 42
42#include <asm/uaccess.h> 43#include <asm/uaccess.h>
43 44
@@ -125,7 +126,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 126 * 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. 127 * static because kmalloc will not work during early console init.
127 */ 128 */
128static struct hv_ops *cons_ops[MAX_NR_HVC_CONSOLES]; 129static const struct hv_ops *cons_ops[MAX_NR_HVC_CONSOLES];
129static uint32_t vtermnos[MAX_NR_HVC_CONSOLES] = 130static uint32_t vtermnos[MAX_NR_HVC_CONSOLES] =
130 {[0 ... MAX_NR_HVC_CONSOLES - 1] = -1}; 131 {[0 ... MAX_NR_HVC_CONSOLES - 1] = -1};
131 132
@@ -146,7 +147,7 @@ static void hvc_console_print(struct console *co, const char *b,
146 return; 147 return;
147 148
148 /* This console adapter was removed so it is not usable. */ 149 /* This console adapter was removed so it is not usable. */
149 if (vtermnos[index] < 0) 150 if (vtermnos[index] == -1)
150 return; 151 return;
151 152
152 while (count > 0 || i > 0) { 153 while (count > 0 || i > 0) {
@@ -247,7 +248,7 @@ static void destroy_hvc_struct(struct kref *kref)
247 * vty adapters do NOT get an hvc_instantiate() callback since they 248 * vty adapters do NOT get an hvc_instantiate() callback since they
248 * appear after early console init. 249 * appear after early console init.
249 */ 250 */
250int hvc_instantiate(uint32_t vtermno, int index, struct hv_ops *ops) 251int hvc_instantiate(uint32_t vtermno, int index, const struct hv_ops *ops)
251{ 252{
252 struct hvc_struct *hp; 253 struct hvc_struct *hp;
253 254
@@ -312,6 +313,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
312 spin_lock_irqsave(&hp->lock, flags); 313 spin_lock_irqsave(&hp->lock, flags);
313 /* Check and then increment for fast path open. */ 314 /* Check and then increment for fast path open. */
314 if (hp->count++ > 0) { 315 if (hp->count++ > 0) {
316 tty_kref_get(tty);
315 spin_unlock_irqrestore(&hp->lock, flags); 317 spin_unlock_irqrestore(&hp->lock, flags);
316 hvc_kick(); 318 hvc_kick();
317 return 0; 319 return 0;
@@ -319,7 +321,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
319 321
320 tty->driver_data = hp; 322 tty->driver_data = hp;
321 323
322 hp->tty = tty; 324 hp->tty = tty_kref_get(tty);
323 325
324 spin_unlock_irqrestore(&hp->lock, flags); 326 spin_unlock_irqrestore(&hp->lock, flags);
325 327
@@ -336,6 +338,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
336 spin_lock_irqsave(&hp->lock, flags); 338 spin_lock_irqsave(&hp->lock, flags);
337 hp->tty = NULL; 339 hp->tty = NULL;
338 spin_unlock_irqrestore(&hp->lock, flags); 340 spin_unlock_irqrestore(&hp->lock, flags);
341 tty_kref_put(tty);
339 tty->driver_data = NULL; 342 tty->driver_data = NULL;
340 kref_put(&hp->kref, destroy_hvc_struct); 343 kref_put(&hp->kref, destroy_hvc_struct);
341 printk(KERN_ERR "hvc_open: request_irq failed with rc %d.\n", rc); 344 printk(KERN_ERR "hvc_open: request_irq failed with rc %d.\n", rc);
@@ -363,6 +366,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
363 return; 366 return;
364 367
365 hp = tty->driver_data; 368 hp = tty->driver_data;
369
366 spin_lock_irqsave(&hp->lock, flags); 370 spin_lock_irqsave(&hp->lock, flags);
367 371
368 if (--hp->count == 0) { 372 if (--hp->count == 0) {
@@ -389,6 +393,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
389 spin_unlock_irqrestore(&hp->lock, flags); 393 spin_unlock_irqrestore(&hp->lock, flags);
390 } 394 }
391 395
396 tty_kref_put(tty);
392 kref_put(&hp->kref, destroy_hvc_struct); 397 kref_put(&hp->kref, destroy_hvc_struct);
393} 398}
394 399
@@ -424,10 +429,11 @@ static void hvc_hangup(struct tty_struct *tty)
424 spin_unlock_irqrestore(&hp->lock, flags); 429 spin_unlock_irqrestore(&hp->lock, flags);
425 430
426 if (hp->ops->notifier_hangup) 431 if (hp->ops->notifier_hangup)
427 hp->ops->notifier_hangup(hp, hp->data); 432 hp->ops->notifier_hangup(hp, hp->data);
428 433
429 while(temp_open_count) { 434 while(temp_open_count) {
430 --temp_open_count; 435 --temp_open_count;
436 tty_kref_put(tty);
431 kref_put(&hp->kref, destroy_hvc_struct); 437 kref_put(&hp->kref, destroy_hvc_struct);
432 } 438 }
433} 439}
@@ -592,7 +598,7 @@ int hvc_poll(struct hvc_struct *hp)
592 } 598 }
593 599
594 /* No tty attached, just skip */ 600 /* No tty attached, just skip */
595 tty = hp->tty; 601 tty = tty_kref_get(hp->tty);
596 if (tty == NULL) 602 if (tty == NULL)
597 goto bail; 603 goto bail;
598 604
@@ -672,6 +678,8 @@ int hvc_poll(struct hvc_struct *hp)
672 678
673 tty_flip_buffer_push(tty); 679 tty_flip_buffer_push(tty);
674 } 680 }
681 if (tty)
682 tty_kref_put(tty);
675 683
676 return poll_mask; 684 return poll_mask;
677} 685}
@@ -748,8 +756,9 @@ static const struct tty_operations hvc_ops = {
748 .chars_in_buffer = hvc_chars_in_buffer, 756 .chars_in_buffer = hvc_chars_in_buffer,
749}; 757};
750 758
751struct hvc_struct __devinit *hvc_alloc(uint32_t vtermno, int data, 759struct hvc_struct *hvc_alloc(uint32_t vtermno, int data,
752 struct hv_ops *ops, int outbuf_size) 760 const struct hv_ops *ops,
761 int outbuf_size)
753{ 762{
754 struct hvc_struct *hp; 763 struct hvc_struct *hp;
755 int i; 764 int i;
@@ -806,7 +815,7 @@ int hvc_remove(struct hvc_struct *hp)
806 struct tty_struct *tty; 815 struct tty_struct *tty;
807 816
808 spin_lock_irqsave(&hp->lock, flags); 817 spin_lock_irqsave(&hp->lock, flags);
809 tty = hp->tty; 818 tty = tty_kref_get(hp->tty);
810 819
811 if (hp->index < MAX_NR_HVC_CONSOLES) 820 if (hp->index < MAX_NR_HVC_CONSOLES)
812 vtermnos[hp->index] = -1; 821 vtermnos[hp->index] = -1;
@@ -818,20 +827,21 @@ int hvc_remove(struct hvc_struct *hp)
818 /* 827 /*
819 * We 'put' the instance that was grabbed when the kref instance 828 * We 'put' the instance that was grabbed when the kref instance
820 * was initialized using kref_init(). Let the last holder of this 829 * was initialized using kref_init(). Let the last holder of this
821 * kref cause it to be removed, which will probably be the tty_hangup 830 * kref cause it to be removed, which will probably be the tty_vhangup
822 * below. 831 * below.
823 */ 832 */
824 kref_put(&hp->kref, destroy_hvc_struct); 833 kref_put(&hp->kref, destroy_hvc_struct);
825 834
826 /* 835 /*
827 * This function call will auto chain call hvc_hangup. The tty should 836 * This function call will auto chain call hvc_hangup.
828 * always be valid at this time unless a simultaneous tty close already
829 * cleaned up the hvc_struct.
830 */ 837 */
831 if (tty) 838 if (tty) {
832 tty_hangup(tty); 839 tty_vhangup(tty);
840 tty_kref_put(tty);
841 }
833 return 0; 842 return 0;
834} 843}
844EXPORT_SYMBOL_GPL(hvc_remove);
835 845
836/* Driver initialization: called as soon as someone uses hvc_alloc(). */ 846/* Driver initialization: called as soon as someone uses hvc_alloc(). */
837static int hvc_init(void) 847static int hvc_init(void)
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) */
79extern int hvc_instantiate(uint32_t vtermno, int index, struct hv_ops *ops); 79extern 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) */
82extern struct hvc_struct * __devinit hvc_alloc(uint32_t vtermno, int data, 83extern 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) */
85extern int hvc_remove(struct hvc_struct *hp); 86extern 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..21c54955084e 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
200static struct hv_ops hvc_get_put_ops = { 200static 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,
@@ -353,7 +353,7 @@ static void hvc_close_event(struct HvLpEvent *event)
353 353
354 if (!hvlpevent_is_int(event)) { 354 if (!hvlpevent_is_int(event)) {
355 printk(KERN_WARNING 355 printk(KERN_WARNING
356 "hvc: got unexpected close acknowlegement\n"); 356 "hvc: got unexpected close acknowledgement\n");
357 return; 357 return;
358 } 358 }
359 359
diff --git a/drivers/char/hvc_iucv.c b/drivers/char/hvc_iucv.c
index b8a5d654d3d0..5a80ad68ef22 100644
--- a/drivers/char/hvc_iucv.c
+++ b/drivers/char/hvc_iucv.c
@@ -12,6 +12,7 @@
12#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt 12#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
13 13
14#include <linux/types.h> 14#include <linux/types.h>
15#include <linux/slab.h>
15#include <asm/ebcdic.h> 16#include <asm/ebcdic.h>
16#include <linux/ctype.h> 17#include <linux/ctype.h>
17#include <linux/delay.h> 18#include <linux/delay.h>
@@ -139,6 +140,8 @@ struct hvc_iucv_private *hvc_iucv_get_private(uint32_t num)
139 * 140 *
140 * This function allocates a new struct iucv_tty_buffer element and, optionally, 141 * This function allocates a new struct iucv_tty_buffer element and, optionally,
141 * allocates an internal data buffer with the specified size @size. 142 * allocates an internal data buffer with the specified size @size.
143 * The internal data buffer is always allocated with GFP_DMA which is
144 * required for receiving and sending data with IUCV.
142 * Note: The total message size arises from the internal buffer size and the 145 * Note: The total message size arises from the internal buffer size and the
143 * members of the iucv_tty_msg structure. 146 * members of the iucv_tty_msg structure.
144 * The function returns NULL if memory allocation has failed. 147 * The function returns NULL if memory allocation has failed.
@@ -154,7 +157,7 @@ static struct iucv_tty_buffer *alloc_tty_buffer(size_t size, gfp_t flags)
154 157
155 if (size > 0) { 158 if (size > 0) {
156 bufp->msg.length = MSG_SIZE(size); 159 bufp->msg.length = MSG_SIZE(size);
157 bufp->mbuf = kmalloc(bufp->msg.length, flags); 160 bufp->mbuf = kmalloc(bufp->msg.length, flags | GFP_DMA);
158 if (!bufp->mbuf) { 161 if (!bufp->mbuf) {
159 mempool_free(bufp, hvc_iucv_mempool); 162 mempool_free(bufp, hvc_iucv_mempool);
160 return NULL; 163 return NULL;
@@ -237,7 +240,7 @@ static int hvc_iucv_write(struct hvc_iucv_private *priv,
237 if (!rb->mbuf) { /* message not yet received ... */ 240 if (!rb->mbuf) { /* message not yet received ... */
238 /* allocate mem to store msg data; if no memory is available 241 /* allocate mem to store msg data; if no memory is available
239 * then leave the buffer on the list and re-try later */ 242 * then leave the buffer on the list and re-try later */
240 rb->mbuf = kmalloc(rb->msg.length, GFP_ATOMIC); 243 rb->mbuf = kmalloc(rb->msg.length, GFP_ATOMIC | GFP_DMA);
241 if (!rb->mbuf) 244 if (!rb->mbuf)
242 return -ENOMEM; 245 return -ENOMEM;
243 246
@@ -922,7 +925,7 @@ static int hvc_iucv_pm_restore_thaw(struct device *dev)
922 925
923 926
924/* HVC operations */ 927/* HVC operations */
925static struct hv_ops hvc_iucv_ops = { 928static const struct hv_ops hvc_iucv_ops = {
926 .get_chars = hvc_iucv_get_chars, 929 .get_chars = hvc_iucv_get_chars,
927 .put_chars = hvc_iucv_put_chars, 930 .put_chars = hvc_iucv_put_chars,
928 .notifier_add = hvc_iucv_notifier_add, 931 .notifier_add = hvc_iucv_notifier_add,
@@ -931,7 +934,7 @@ static struct hv_ops hvc_iucv_ops = {
931}; 934};
932 935
933/* Suspend / resume device operations */ 936/* Suspend / resume device operations */
934static struct dev_pm_ops hvc_iucv_pm_ops = { 937static const struct dev_pm_ops hvc_iucv_pm_ops = {
935 .freeze = hvc_iucv_pm_freeze, 938 .freeze = hvc_iucv_pm_freeze,
936 .thaw = hvc_iucv_pm_restore_thaw, 939 .thaw = hvc_iucv_pm_restore_thaw,
937 .restore = hvc_iucv_pm_restore_thaw, 940 .restore = hvc_iucv_pm_restore_thaw,
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
74static struct hv_ops hvc_rtas_get_put_ops = { 74static 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
61static struct hv_ops hvc_udbg_ops = { 61static 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
80static struct hv_ops hvc_get_put_ops = { 80static 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 a6ee32b599a8..60446f82a3fc 100644
--- a/drivers/char/hvc_xen.c
+++ b/drivers/char/hvc_xen.c
@@ -25,6 +25,8 @@
25#include <linux/types.h> 25#include <linux/types.h>
26 26
27#include <asm/xen/hypervisor.h> 27#include <asm/xen/hypervisor.h>
28
29#include <xen/xen.h>
28#include <xen/page.h> 30#include <xen/page.h>
29#include <xen/events.h> 31#include <xen/events.h>
30#include <xen/interface/io/console.h> 32#include <xen/interface/io/console.h>
@@ -120,7 +122,7 @@ static int read_console(uint32_t vtermno, char *buf, int len)
120 return recv; 122 return recv;
121} 123}
122 124
123static struct hv_ops hvc_ops = { 125static const struct hv_ops hvc_ops = {
124 .get_chars = read_console, 126 .get_chars = read_console,
125 .put_chars = write_console, 127 .put_chars = write_console,
126 .notifier_add = notifier_add_irq, 128 .notifier_add = notifier_add_irq,
diff --git a/drivers/char/hvcs.c b/drivers/char/hvcs.c
index 266b858b8f85..bedc6c1b6fa5 100644
--- a/drivers/char/hvcs.c
+++ b/drivers/char/hvcs.c
@@ -74,6 +74,7 @@
74#include <linux/module.h> 74#include <linux/module.h>
75#include <linux/moduleparam.h> 75#include <linux/moduleparam.h>
76#include <linux/sched.h> 76#include <linux/sched.h>
77#include <linux/slab.h>
77#include <linux/spinlock.h> 78#include <linux/spinlock.h>
78#include <linux/stat.h> 79#include <linux/stat.h>
79#include <linux/tty.h> 80#include <linux/tty.h>
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
115config HW_RANDOM_OMAP 115config 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
190config 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
18obj-$(CONFIG_HW_RANDOM_TX4939) += tx4939-rng.o 18obj-$(CONFIG_HW_RANDOM_TX4939) += tx4939-rng.o
19obj-$(CONFIG_HW_RANDOM_MXC_RNGA) += mxc-rnga.o 19obj-$(CONFIG_HW_RANDOM_MXC_RNGA) += mxc-rnga.o
20obj-$(CONFIG_HW_RANDOM_OCTEON) += octeon-rng.o 20obj-$(CONFIG_HW_RANDOM_OCTEON) += octeon-rng.o
21obj-$(CONFIG_HW_RANDOM_NOMADIK) += nomadik-rng.o
diff --git a/drivers/char/hw_random/core.c b/drivers/char/hw_random/core.c
index 1573aebd54b5..3d9c61e5acbf 100644
--- a/drivers/char/hw_random/core.c
+++ b/drivers/char/hw_random/core.c
@@ -52,7 +52,9 @@
52static struct hwrng *current_rng; 52static struct hwrng *current_rng;
53static LIST_HEAD(rng_list); 53static LIST_HEAD(rng_list);
54static DEFINE_MUTEX(rng_mutex); 54static DEFINE_MUTEX(rng_mutex);
55 55static int data_avail;
56static u8 rng_buffer[SMP_CACHE_BYTES < 32 ? 32 : SMP_CACHE_BYTES]
57 __cacheline_aligned;
56 58
57static inline int hwrng_init(struct hwrng *rng) 59static inline int hwrng_init(struct hwrng *rng)
58{ 60{
@@ -67,19 +69,6 @@ static inline void hwrng_cleanup(struct hwrng *rng)
67 rng->cleanup(rng); 69 rng->cleanup(rng);
68} 70}
69 71
70static inline int hwrng_data_present(struct hwrng *rng, int wait)
71{
72 if (!rng->data_present)
73 return 1;
74 return rng->data_present(rng, wait);
75}
76
77static inline int hwrng_data_read(struct hwrng *rng, u32 *data)
78{
79 return rng->data_read(rng, data);
80}
81
82
83static int rng_dev_open(struct inode *inode, struct file *filp) 72static int rng_dev_open(struct inode *inode, struct file *filp)
84{ 73{
85 /* enforce read-only access to this chrdev */ 74 /* enforce read-only access to this chrdev */
@@ -87,60 +76,93 @@ static int rng_dev_open(struct inode *inode, struct file *filp)
87 return -EINVAL; 76 return -EINVAL;
88 if (filp->f_mode & FMODE_WRITE) 77 if (filp->f_mode & FMODE_WRITE)
89 return -EINVAL; 78 return -EINVAL;
90 cycle_kernel_lock(); 79 return 0;
80}
81
82static inline int rng_get_data(struct hwrng *rng, u8 *buffer, size_t size,
83 int wait) {
84 int present;
85
86 if (rng->read)
87 return rng->read(rng, (void *)buffer, size, wait);
88
89 if (rng->data_present)
90 present = rng->data_present(rng, wait);
91 else
92 present = 1;
93
94 if (present)
95 return rng->data_read(rng, (u32 *)buffer);
96
91 return 0; 97 return 0;
92} 98}
93 99
94static ssize_t rng_dev_read(struct file *filp, char __user *buf, 100static ssize_t rng_dev_read(struct file *filp, char __user *buf,
95 size_t size, loff_t *offp) 101 size_t size, loff_t *offp)
96{ 102{
97 u32 data;
98 ssize_t ret = 0; 103 ssize_t ret = 0;
99 int err = 0; 104 int err = 0;
100 int bytes_read; 105 int bytes_read, len;
101 106
102 while (size) { 107 while (size) {
103 err = -ERESTARTSYS; 108 if (mutex_lock_interruptible(&rng_mutex)) {
104 if (mutex_lock_interruptible(&rng_mutex)) 109 err = -ERESTARTSYS;
105 goto out; 110 goto out;
111 }
112
106 if (!current_rng) { 113 if (!current_rng) {
107 mutex_unlock(&rng_mutex);
108 err = -ENODEV; 114 err = -ENODEV;
109 goto out; 115 goto out_unlock;
110 } 116 }
111 117
112 bytes_read = 0; 118 if (!data_avail) {
113 if (hwrng_data_present(current_rng, 119 bytes_read = rng_get_data(current_rng, rng_buffer,
114 !(filp->f_flags & O_NONBLOCK))) 120 sizeof(rng_buffer),
115 bytes_read = hwrng_data_read(current_rng, &data); 121 !(filp->f_flags & O_NONBLOCK));
116 mutex_unlock(&rng_mutex); 122 if (bytes_read < 0) {
117 123 err = bytes_read;
118 err = -EAGAIN; 124 goto out_unlock;
119 if (!bytes_read && (filp->f_flags & O_NONBLOCK)) 125 }
120 goto out; 126 data_avail = bytes_read;
121 if (bytes_read < 0) {
122 err = bytes_read;
123 goto out;
124 } 127 }
125 128
126 err = -EFAULT; 129 if (!data_avail) {
127 while (bytes_read && size) { 130 if (filp->f_flags & O_NONBLOCK) {
128 if (put_user((u8)data, buf++)) 131 err = -EAGAIN;
129 goto out; 132 goto out_unlock;
130 size--; 133 }
131 ret++; 134 } else {
132 bytes_read--; 135 len = data_avail;
133 data >>= 8; 136 if (len > size)
137 len = size;
138
139 data_avail -= len;
140
141 if (copy_to_user(buf + ret, rng_buffer + data_avail,
142 len)) {
143 err = -EFAULT;
144 goto out_unlock;
145 }
146
147 size -= len;
148 ret += len;
134 } 149 }
135 150
151 mutex_unlock(&rng_mutex);
152
136 if (need_resched()) 153 if (need_resched())
137 schedule_timeout_interruptible(1); 154 schedule_timeout_interruptible(1);
138 err = -ERESTARTSYS; 155
139 if (signal_pending(current)) 156 if (signal_pending(current)) {
157 err = -ERESTARTSYS;
140 goto out; 158 goto out;
159 }
141 } 160 }
142out: 161out:
143 return ret ? : err; 162 return ret ? : err;
163out_unlock:
164 mutex_unlock(&rng_mutex);
165 goto out;
144} 166}
145 167
146 168
@@ -280,7 +302,7 @@ int hwrng_register(struct hwrng *rng)
280 struct hwrng *old_rng, *tmp; 302 struct hwrng *old_rng, *tmp;
281 303
282 if (rng->name == NULL || 304 if (rng->name == NULL ||
283 rng->data_read == NULL) 305 (rng->data_read == NULL && rng->read == NULL))
284 goto out; 306 goto out;
285 307
286 mutex_lock(&rng_mutex); 308 mutex_lock(&rng_mutex);
diff --git a/drivers/char/hw_random/intel-rng.c b/drivers/char/hw_random/intel-rng.c
index 91b53eb1c053..86fe45c19968 100644
--- a/drivers/char/hw_random/intel-rng.c
+++ b/drivers/char/hw_random/intel-rng.c
@@ -30,6 +30,7 @@
30#include <linux/pci.h> 30#include <linux/pci.h>
31#include <linux/stop_machine.h> 31#include <linux/stop_machine.h>
32#include <linux/delay.h> 32#include <linux/delay.h>
33#include <linux/slab.h>
33#include <asm/io.h> 34#include <asm/io.h>
34 35
35 36
diff --git a/drivers/char/hw_random/n2-drv.c b/drivers/char/hw_random/n2-drv.c
index 9b3e09cd41f9..10f868eefaa6 100644
--- a/drivers/char/hw_random/n2-drv.c
+++ b/drivers/char/hw_random/n2-drv.c
@@ -71,7 +71,7 @@ MODULE_VERSION(DRV_MODULE_VERSION);
71 * x22 + x21 + x17 + x15 + x13 + x12 + x11 + x7 + x5 + x + 1 71 * x22 + x21 + x17 + x15 + x13 + x12 + x11 + x7 + x5 + x + 1
72 * 72 *
73 * The RNG_CTL_VCO value of each noise cell must be programmed 73 * The RNG_CTL_VCO value of each noise cell must be programmed
74 * seperately. This is why 4 control register values must be provided 74 * separately. This is why 4 control register values must be provided
75 * to the hypervisor. During a write, the hypervisor writes them all, 75 * to the hypervisor. During a write, the hypervisor writes them all,
76 * one at a time, to the actual RNG_CTL register. The first three 76 * one at a time, to the actual RNG_CTL register. The first three
77 * values are used to setup the desired RNG_CTL_VCO for each entropy 77 * values are used to setup the desired RNG_CTL_VCO for each entropy
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
19static 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 */
33static struct hwrng nmk_rng = {
34 .name = "nomadik",
35 .read = nmk_rng_read,
36};
37
38static 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
56out_unmap:
57 iounmap(base);
58out_release:
59 amba_release_regions(dev);
60 return ret;
61}
62
63static 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
72static 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
80static 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
90static int __init nmk_rng_init(void)
91{
92 return amba_driver_register(&nmk_rng_driver);
93}
94
95static void __devexit nmk_rng_exit(void)
96{
97 amba_driver_unregister(&nmk_rng_driver);
98}
99
100module_init(nmk_rng_init);
101module_exit(nmk_rng_exit);
102
103MODULE_LICENSE("GPL");
diff --git a/drivers/char/hw_random/octeon-rng.c b/drivers/char/hw_random/octeon-rng.c
index 54b0d9ba65cf..9cd0feca318c 100644
--- a/drivers/char/hw_random/octeon-rng.c
+++ b/drivers/char/hw_random/octeon-rng.c
@@ -15,6 +15,7 @@
15#include <linux/device.h> 15#include <linux/device.h>
16#include <linux/hw_random.h> 16#include <linux/hw_random.h>
17#include <linux/io.h> 17#include <linux/io.h>
18#include <linux/gfp.h>
18 19
19#include <asm/octeon/octeon.h> 20#include <asm/octeon/octeon.h>
20#include <asm/octeon/cvmx-rnm-defs.h> 21#include <asm/octeon/cvmx-rnm-defs.h>
diff --git a/drivers/char/hw_random/tx4939-rng.c b/drivers/char/hw_random/tx4939-rng.c
index 544d9085a8e8..0bc0cb70210b 100644
--- a/drivers/char/hw_random/tx4939-rng.c
+++ b/drivers/char/hw_random/tx4939-rng.c
@@ -14,6 +14,7 @@
14#include <linux/io.h> 14#include <linux/io.h>
15#include <linux/platform_device.h> 15#include <linux/platform_device.h>
16#include <linux/hw_random.h> 16#include <linux/hw_random.h>
17#include <linux/gfp.h>
17 18
18#define TX4939_RNG_RCSR 0x00000000 19#define TX4939_RNG_RCSR 0x00000000
19#define TX4939_RNG_ROR(n) (0x00000018 + (n) * 8) 20#define TX4939_RNG_ROR(n) (0x00000018 + (n) * 8)
diff --git a/drivers/char/hw_random/virtio-rng.c b/drivers/char/hw_random/virtio-rng.c
index 915157fcff98..64fe0a793efd 100644
--- a/drivers/char/hw_random/virtio-rng.c
+++ b/drivers/char/hw_random/virtio-rng.c
@@ -16,6 +16,7 @@
16 * along with this program; if not, write to the Free Software 16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 */ 18 */
19
19#include <linux/err.h> 20#include <linux/err.h>
20#include <linux/hw_random.h> 21#include <linux/hw_random.h>
21#include <linux/scatterlist.h> 22#include <linux/scatterlist.h>
@@ -23,78 +24,64 @@
23#include <linux/virtio.h> 24#include <linux/virtio.h>
24#include <linux/virtio_rng.h> 25#include <linux/virtio_rng.h>
25 26
26/* The host will fill any buffer we give it with sweet, sweet randomness. We
27 * give it 64 bytes at a time, and the hwrng framework takes it 4 bytes at a
28 * time. */
29#define RANDOM_DATA_SIZE 64
30
31static struct virtqueue *vq; 27static struct virtqueue *vq;
32static u32 *random_data; 28static unsigned int data_avail;
33static unsigned int data_left;
34static DECLARE_COMPLETION(have_data); 29static DECLARE_COMPLETION(have_data);
30static bool busy;
35 31
36static void random_recv_done(struct virtqueue *vq) 32static void random_recv_done(struct virtqueue *vq)
37{ 33{
38 unsigned int len;
39
40 /* We can get spurious callbacks, e.g. shared IRQs + virtio_pci. */ 34 /* We can get spurious callbacks, e.g. shared IRQs + virtio_pci. */
41 if (!vq->vq_ops->get_buf(vq, &len)) 35 if (!vq->vq_ops->get_buf(vq, &data_avail))
42 return; 36 return;
43 37
44 data_left += len;
45 complete(&have_data); 38 complete(&have_data);
46} 39}
47 40
48static void register_buffer(void) 41/* The host will fill any buffer we give it with sweet, sweet randomness. */
42static void register_buffer(u8 *buf, size_t size)
49{ 43{
50 struct scatterlist sg; 44 struct scatterlist sg;
51 45
52 sg_init_one(&sg, random_data+data_left, RANDOM_DATA_SIZE-data_left); 46 sg_init_one(&sg, buf, size);
47
53 /* There should always be room for one buffer. */ 48 /* There should always be room for one buffer. */
54 if (vq->vq_ops->add_buf(vq, &sg, 0, 1, random_data) < 0) 49 if (vq->vq_ops->add_buf(vq, &sg, 0, 1, buf) < 0)
55 BUG(); 50 BUG();
51
56 vq->vq_ops->kick(vq); 52 vq->vq_ops->kick(vq);
57} 53}
58 54
59/* At least we don't udelay() in a loop like some other drivers. */ 55static int virtio_read(struct hwrng *rng, void *buf, size_t size, bool wait)
60static int virtio_data_present(struct hwrng *rng, int wait)
61{ 56{
62 if (data_left >= sizeof(u32))
63 return 1;
64 57
65again: 58 if (!busy) {
59 busy = true;
60 init_completion(&have_data);
61 register_buffer(buf, size);
62 }
63
66 if (!wait) 64 if (!wait)
67 return 0; 65 return 0;
68 66
69 wait_for_completion(&have_data); 67 wait_for_completion(&have_data);
70 68
71 /* Not enough? Re-register. */ 69 busy = false;
72 if (unlikely(data_left < sizeof(u32))) {
73 register_buffer();
74 goto again;
75 }
76 70
77 return 1; 71 return data_avail;
78} 72}
79 73
80/* virtio_data_present() must have succeeded before this is called. */ 74static void virtio_cleanup(struct hwrng *rng)
81static int virtio_data_read(struct hwrng *rng, u32 *data)
82{ 75{
83 BUG_ON(data_left < sizeof(u32)); 76 if (busy)
84 data_left -= sizeof(u32); 77 wait_for_completion(&have_data);
85 *data = random_data[data_left / 4];
86
87 if (data_left < sizeof(u32)) {
88 init_completion(&have_data);
89 register_buffer();
90 }
91 return sizeof(*data);
92} 78}
93 79
80
94static struct hwrng virtio_hwrng = { 81static struct hwrng virtio_hwrng = {
95 .name = "virtio", 82 .name = "virtio",
96 .data_present = virtio_data_present, 83 .cleanup = virtio_cleanup,
97 .data_read = virtio_data_read, 84 .read = virtio_read,
98}; 85};
99 86
100static int virtrng_probe(struct virtio_device *vdev) 87static int virtrng_probe(struct virtio_device *vdev)
@@ -112,7 +99,6 @@ static int virtrng_probe(struct virtio_device *vdev)
112 return err; 99 return err;
113 } 100 }
114 101
115 register_buffer();
116 return 0; 102 return 0;
117} 103}
118 104
@@ -128,7 +114,7 @@ static struct virtio_device_id id_table[] = {
128 { 0 }, 114 { 0 },
129}; 115};
130 116
131static struct virtio_driver virtio_rng = { 117static struct virtio_driver virtio_rng_driver = {
132 .driver.name = KBUILD_MODNAME, 118 .driver.name = KBUILD_MODNAME,
133 .driver.owner = THIS_MODULE, 119 .driver.owner = THIS_MODULE,
134 .id_table = id_table, 120 .id_table = id_table,
@@ -138,22 +124,12 @@ static struct virtio_driver virtio_rng = {
138 124
139static int __init init(void) 125static int __init init(void)
140{ 126{
141 int err; 127 return register_virtio_driver(&virtio_rng_driver);
142
143 random_data = kmalloc(RANDOM_DATA_SIZE, GFP_KERNEL);
144 if (!random_data)
145 return -ENOMEM;
146
147 err = register_virtio_driver(&virtio_rng);
148 if (err)
149 kfree(random_data);
150 return err;
151} 128}
152 129
153static void __exit fini(void) 130static void __exit fini(void)
154{ 131{
155 kfree(random_data); 132 unregister_virtio_driver(&virtio_rng_driver);
156 unregister_virtio_driver(&virtio_rng);
157} 133}
158module_init(init); 134module_init(init);
159module_exit(fini); 135module_exit(fini);
diff --git a/drivers/char/ip2/i2hw.h b/drivers/char/ip2/i2hw.h
index 8aa6e7ab8d5b..c0ba6c05f0cd 100644
--- a/drivers/char/ip2/i2hw.h
+++ b/drivers/char/ip2/i2hw.h
@@ -559,7 +559,7 @@ Loadware may be sent to the board in two ways:
559 559
5602) It may be hard-coded into your source by including a .h file (typically 5602) It may be hard-coded into your source by including a .h file (typically
561 supplied by Computone), which declares a data array and initializes every 561 supplied by Computone), which declares a data array and initializes every
562 element. This acheives the same result as if an entire loadware file had 562 element. This achieves the same result as if an entire loadware file had
563 been read into the array. 563 been read into the array.
564 564
565 This requires more data space in your program, but access to the file system 565 This requires more data space in your program, but access to the file system
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
209static void ip2_init_board(int, const struct firmware *); 209static void ip2_init_board(int, const struct firmware *);
210static unsigned short find_eisa_board(int); 210static unsigned short find_eisa_board(int);
211static 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");
285MODULE_DESCRIPTION("Computone IntelliPort Plus Driver"); 286MODULE_DESCRIPTION("Computone IntelliPort Plus Driver");
286MODULE_LICENSE("GPL"); 287MODULE_LICENSE("GPL");
287 288
289#define MAX_CMD_STR 50
290
288static int poll_only; 291static int poll_only;
292static char cmd[MAX_CMD_STR];
289 293
290static int Eisa_irq; 294static int Eisa_irq;
291static int Eisa_slot; 295static int Eisa_slot;
@@ -309,6 +313,8 @@ module_param_array(io, int, NULL, 0);
309MODULE_PARM_DESC(io, "I/O ports for IntelliPort Cards"); 313MODULE_PARM_DESC(io, "I/O ports for IntelliPort Cards");
310module_param(poll_only, bool, 0); 314module_param(poll_only, bool, 0);
311MODULE_PARM_DESC(poll_only, "Do not use card interrupts"); 315MODULE_PARM_DESC(poll_only, "Do not use card interrupts");
316module_param_string(ip2, cmd, MAX_CMD_STR, 0);
317MODULE_PARM_DESC(ip2, "Contains module parameter passed with 'ip2='");
312 318
313/* for sysfs class support */ 319/* for sysfs class support */
314static struct class *ip2_class; 320static 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
536static int __init ip2_loadmain(void) 540static 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;
652out:
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
3199MODULE_DEVICE_TABLE(pci, ip2main_pci_tbl); 3211MODULE_DEVICE_TABLE(pci, ip2main_pci_tbl);
3212
3213MODULE_FIRMWARE("intelliport2.bin");
diff --git a/drivers/char/ipmi/ipmi_kcs_sm.c b/drivers/char/ipmi/ipmi_kcs_sm.c
index 80704875794c..cf82fedae099 100644
--- a/drivers/char/ipmi/ipmi_kcs_sm.c
+++ b/drivers/char/ipmi/ipmi_kcs_sm.c
@@ -370,7 +370,7 @@ static enum si_sm_result kcs_event(struct si_sm_data *kcs, long time)
370 return SI_SM_IDLE; 370 return SI_SM_IDLE;
371 371
372 case KCS_START_OP: 372 case KCS_START_OP:
373 if (state != KCS_IDLE) { 373 if (state != KCS_IDLE_STATE) {
374 start_error_recovery(kcs, 374 start_error_recovery(kcs,
375 "State machine not idle at start"); 375 "State machine not idle at start");
376 break; 376 break;
diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
index ec5e3f8df648..c6ad4234378d 100644
--- a/drivers/char/ipmi/ipmi_msghandler.c
+++ b/drivers/char/ipmi/ipmi_msghandler.c
@@ -2272,42 +2272,52 @@ static int create_files(struct bmc_device *bmc)
2272 bmc->device_id_attr.attr.name = "device_id"; 2272 bmc->device_id_attr.attr.name = "device_id";
2273 bmc->device_id_attr.attr.mode = S_IRUGO; 2273 bmc->device_id_attr.attr.mode = S_IRUGO;
2274 bmc->device_id_attr.show = device_id_show; 2274 bmc->device_id_attr.show = device_id_show;
2275 sysfs_attr_init(&bmc->device_id_attr.attr);
2275 2276
2276 bmc->provides_dev_sdrs_attr.attr.name = "provides_device_sdrs"; 2277 bmc->provides_dev_sdrs_attr.attr.name = "provides_device_sdrs";
2277 bmc->provides_dev_sdrs_attr.attr.mode = S_IRUGO; 2278 bmc->provides_dev_sdrs_attr.attr.mode = S_IRUGO;
2278 bmc->provides_dev_sdrs_attr.show = provides_dev_sdrs_show; 2279 bmc->provides_dev_sdrs_attr.show = provides_dev_sdrs_show;
2280 sysfs_attr_init(&bmc->provides_dev_sdrs_attr.attr);
2279 2281
2280 bmc->revision_attr.attr.name = "revision"; 2282 bmc->revision_attr.attr.name = "revision";
2281 bmc->revision_attr.attr.mode = S_IRUGO; 2283 bmc->revision_attr.attr.mode = S_IRUGO;
2282 bmc->revision_attr.show = revision_show; 2284 bmc->revision_attr.show = revision_show;
2285 sysfs_attr_init(&bmc->revision_attr.attr);
2283 2286
2284 bmc->firmware_rev_attr.attr.name = "firmware_revision"; 2287 bmc->firmware_rev_attr.attr.name = "firmware_revision";
2285 bmc->firmware_rev_attr.attr.mode = S_IRUGO; 2288 bmc->firmware_rev_attr.attr.mode = S_IRUGO;
2286 bmc->firmware_rev_attr.show = firmware_rev_show; 2289 bmc->firmware_rev_attr.show = firmware_rev_show;
2290 sysfs_attr_init(&bmc->firmware_rev_attr.attr);
2287 2291
2288 bmc->version_attr.attr.name = "ipmi_version"; 2292 bmc->version_attr.attr.name = "ipmi_version";
2289 bmc->version_attr.attr.mode = S_IRUGO; 2293 bmc->version_attr.attr.mode = S_IRUGO;
2290 bmc->version_attr.show = ipmi_version_show; 2294 bmc->version_attr.show = ipmi_version_show;
2295 sysfs_attr_init(&bmc->version_attr.attr);
2291 2296
2292 bmc->add_dev_support_attr.attr.name = "additional_device_support"; 2297 bmc->add_dev_support_attr.attr.name = "additional_device_support";
2293 bmc->add_dev_support_attr.attr.mode = S_IRUGO; 2298 bmc->add_dev_support_attr.attr.mode = S_IRUGO;
2294 bmc->add_dev_support_attr.show = add_dev_support_show; 2299 bmc->add_dev_support_attr.show = add_dev_support_show;
2300 sysfs_attr_init(&bmc->add_dev_support_attr.attr);
2295 2301
2296 bmc->manufacturer_id_attr.attr.name = "manufacturer_id"; 2302 bmc->manufacturer_id_attr.attr.name = "manufacturer_id";
2297 bmc->manufacturer_id_attr.attr.mode = S_IRUGO; 2303 bmc->manufacturer_id_attr.attr.mode = S_IRUGO;
2298 bmc->manufacturer_id_attr.show = manufacturer_id_show; 2304 bmc->manufacturer_id_attr.show = manufacturer_id_show;
2305 sysfs_attr_init(&bmc->manufacturer_id_attr.attr);
2299 2306
2300 bmc->product_id_attr.attr.name = "product_id"; 2307 bmc->product_id_attr.attr.name = "product_id";
2301 bmc->product_id_attr.attr.mode = S_IRUGO; 2308 bmc->product_id_attr.attr.mode = S_IRUGO;
2302 bmc->product_id_attr.show = product_id_show; 2309 bmc->product_id_attr.show = product_id_show;
2310 sysfs_attr_init(&bmc->product_id_attr.attr);
2303 2311
2304 bmc->guid_attr.attr.name = "guid"; 2312 bmc->guid_attr.attr.name = "guid";
2305 bmc->guid_attr.attr.mode = S_IRUGO; 2313 bmc->guid_attr.attr.mode = S_IRUGO;
2306 bmc->guid_attr.show = guid_show; 2314 bmc->guid_attr.show = guid_show;
2315 sysfs_attr_init(&bmc->guid_attr.attr);
2307 2316
2308 bmc->aux_firmware_rev_attr.attr.name = "aux_firmware_revision"; 2317 bmc->aux_firmware_rev_attr.attr.name = "aux_firmware_revision";
2309 bmc->aux_firmware_rev_attr.attr.mode = S_IRUGO; 2318 bmc->aux_firmware_rev_attr.attr.mode = S_IRUGO;
2310 bmc->aux_firmware_rev_attr.show = aux_firmware_rev_show; 2319 bmc->aux_firmware_rev_attr.show = aux_firmware_rev_show;
2320 sysfs_attr_init(&bmc->aux_firmware_rev_attr.attr);
2311 2321
2312 err = device_create_file(&bmc->dev->dev, 2322 err = device_create_file(&bmc->dev->dev,
2313 &bmc->device_id_attr); 2323 &bmc->device_id_attr);
diff --git a/drivers/char/ipmi/ipmi_poweroff.c b/drivers/char/ipmi/ipmi_poweroff.c
index 2e66b5f773dd..0dec5da000ef 100644
--- a/drivers/char/ipmi/ipmi_poweroff.c
+++ b/drivers/char/ipmi/ipmi_poweroff.c
@@ -660,26 +660,23 @@ static struct ipmi_smi_watcher smi_watcher = {
660#include <linux/sysctl.h> 660#include <linux/sysctl.h>
661 661
662static ctl_table ipmi_table[] = { 662static ctl_table ipmi_table[] = {
663 { .ctl_name = DEV_IPMI_POWEROFF_POWERCYCLE, 663 { .procname = "poweroff_powercycle",
664 .procname = "poweroff_powercycle",
665 .data = &poweroff_powercycle, 664 .data = &poweroff_powercycle,
666 .maxlen = sizeof(poweroff_powercycle), 665 .maxlen = sizeof(poweroff_powercycle),
667 .mode = 0644, 666 .mode = 0644,
668 .proc_handler = &proc_dointvec }, 667 .proc_handler = proc_dointvec },
669 { } 668 { }
670}; 669};
671 670
672static ctl_table ipmi_dir_table[] = { 671static ctl_table ipmi_dir_table[] = {
673 { .ctl_name = DEV_IPMI, 672 { .procname = "ipmi",
674 .procname = "ipmi",
675 .mode = 0555, 673 .mode = 0555,
676 .child = ipmi_table }, 674 .child = ipmi_table },
677 { } 675 { }
678}; 676};
679 677
680static ctl_table ipmi_root_table[] = { 678static ctl_table ipmi_root_table[] = {
681 { .ctl_name = CTL_DEV, 679 { .procname = "dev",
682 .procname = "dev",
683 .mode = 0555, 680 .mode = 0555,
684 .child = ipmi_dir_table }, 681 .child = ipmi_dir_table },
685 { } 682 { }
diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
index d2e698096ace..4462b113ba3f 100644
--- a/drivers/char/ipmi/ipmi_si_intf.c
+++ b/drivers/char/ipmi/ipmi_si_intf.c
@@ -64,6 +64,7 @@
64#include <linux/dmi.h> 64#include <linux/dmi.h>
65#include <linux/string.h> 65#include <linux/string.h>
66#include <linux/ctype.h> 66#include <linux/ctype.h>
67#include <linux/pnp.h>
67 68
68#ifdef CONFIG_PPC_OF 69#ifdef CONFIG_PPC_OF
69#include <linux/of_device.h> 70#include <linux/of_device.h>
@@ -294,6 +295,9 @@ struct smi_info {
294static int force_kipmid[SI_MAX_PARMS]; 295static int force_kipmid[SI_MAX_PARMS];
295static int num_force_kipmid; 296static int num_force_kipmid;
296 297
298static unsigned int kipmid_max_busy_us[SI_MAX_PARMS];
299static int num_max_busy_us;
300
297static int unload_when_empty = 1; 301static int unload_when_empty = 1;
298 302
299static int try_smi_init(struct smi_info *smi); 303static int try_smi_init(struct smi_info *smi);
@@ -924,23 +928,77 @@ static void set_run_to_completion(void *send_info, int i_run_to_completion)
924 } 928 }
925} 929}
926 930
931/*
932 * Use -1 in the nsec value of the busy waiting timespec to tell that
933 * we are spinning in kipmid looking for something and not delaying
934 * between checks
935 */
936static inline void ipmi_si_set_not_busy(struct timespec *ts)
937{
938 ts->tv_nsec = -1;
939}
940static inline int ipmi_si_is_busy(struct timespec *ts)
941{
942 return ts->tv_nsec != -1;
943}
944
945static int ipmi_thread_busy_wait(enum si_sm_result smi_result,
946 const struct smi_info *smi_info,
947 struct timespec *busy_until)
948{
949 unsigned int max_busy_us = 0;
950
951 if (smi_info->intf_num < num_max_busy_us)
952 max_busy_us = kipmid_max_busy_us[smi_info->intf_num];
953 if (max_busy_us == 0 || smi_result != SI_SM_CALL_WITH_DELAY)
954 ipmi_si_set_not_busy(busy_until);
955 else if (!ipmi_si_is_busy(busy_until)) {
956 getnstimeofday(busy_until);
957 timespec_add_ns(busy_until, max_busy_us*NSEC_PER_USEC);
958 } else {
959 struct timespec now;
960 getnstimeofday(&now);
961 if (unlikely(timespec_compare(&now, busy_until) > 0)) {
962 ipmi_si_set_not_busy(busy_until);
963 return 0;
964 }
965 }
966 return 1;
967}
968
969
970/*
971 * A busy-waiting loop for speeding up IPMI operation.
972 *
973 * Lousy hardware makes this hard. This is only enabled for systems
974 * that are not BT and do not have interrupts. It starts spinning
975 * when an operation is complete or until max_busy tells it to stop
976 * (if that is enabled). See the paragraph on kimid_max_busy_us in
977 * Documentation/IPMI.txt for details.
978 */
927static int ipmi_thread(void *data) 979static int ipmi_thread(void *data)
928{ 980{
929 struct smi_info *smi_info = data; 981 struct smi_info *smi_info = data;
930 unsigned long flags; 982 unsigned long flags;
931 enum si_sm_result smi_result; 983 enum si_sm_result smi_result;
984 struct timespec busy_until;
932 985
986 ipmi_si_set_not_busy(&busy_until);
933 set_user_nice(current, 19); 987 set_user_nice(current, 19);
934 while (!kthread_should_stop()) { 988 while (!kthread_should_stop()) {
989 int busy_wait;
990
935 spin_lock_irqsave(&(smi_info->si_lock), flags); 991 spin_lock_irqsave(&(smi_info->si_lock), flags);
936 smi_result = smi_event_handler(smi_info, 0); 992 smi_result = smi_event_handler(smi_info, 0);
937 spin_unlock_irqrestore(&(smi_info->si_lock), flags); 993 spin_unlock_irqrestore(&(smi_info->si_lock), flags);
994 busy_wait = ipmi_thread_busy_wait(smi_result, smi_info,
995 &busy_until);
938 if (smi_result == SI_SM_CALL_WITHOUT_DELAY) 996 if (smi_result == SI_SM_CALL_WITHOUT_DELAY)
939 ; /* do nothing */ 997 ; /* do nothing */
940 else if (smi_result == SI_SM_CALL_WITH_DELAY) 998 else if (smi_result == SI_SM_CALL_WITH_DELAY && busy_wait)
941 schedule(); 999 schedule();
942 else 1000 else
943 schedule_timeout_interruptible(1); 1001 schedule_timeout_interruptible(0);
944 } 1002 }
945 return 0; 1003 return 0;
946} 1004}
@@ -1143,7 +1201,7 @@ static int regsizes[SI_MAX_PARMS];
1143static unsigned int num_regsizes; 1201static unsigned int num_regsizes;
1144static int regshifts[SI_MAX_PARMS]; 1202static int regshifts[SI_MAX_PARMS];
1145static unsigned int num_regshifts; 1203static unsigned int num_regshifts;
1146static int slave_addrs[SI_MAX_PARMS]; 1204static int slave_addrs[SI_MAX_PARMS]; /* Leaving 0 chooses the default value */
1147static unsigned int num_slave_addrs; 1205static unsigned int num_slave_addrs;
1148 1206
1149#define IPMI_IO_ADDR_SPACE 0 1207#define IPMI_IO_ADDR_SPACE 0
@@ -1211,6 +1269,11 @@ module_param(unload_when_empty, int, 0);
1211MODULE_PARM_DESC(unload_when_empty, "Unload the module if no interfaces are" 1269MODULE_PARM_DESC(unload_when_empty, "Unload the module if no interfaces are"
1212 " specified or found, default is 1. Setting to 0" 1270 " specified or found, default is 1. Setting to 0"
1213 " is useful for hot add of devices using hotmod."); 1271 " is useful for hot add of devices using hotmod.");
1272module_param_array(kipmid_max_busy_us, uint, &num_max_busy_us, 0644);
1273MODULE_PARM_DESC(kipmid_max_busy_us,
1274 "Max time (in microseconds) to busy-wait for IPMI data before"
1275 " sleeping. 0 (default) means to wait forever. Set to 100-500"
1276 " if kipmid is using up a lot of CPU time.");
1214 1277
1215 1278
1216static void std_irq_cleanup(struct smi_info *info) 1279static void std_irq_cleanup(struct smi_info *info)
@@ -1606,7 +1669,7 @@ static int hotmod_handler(const char *val, struct kernel_param *kp)
1606 regsize = 1; 1669 regsize = 1;
1607 regshift = 0; 1670 regshift = 0;
1608 irq = 0; 1671 irq = 0;
1609 ipmb = 0x20; 1672 ipmb = 0; /* Choose the default if not specified */
1610 1673
1611 next = strchr(curr, ':'); 1674 next = strchr(curr, ':');
1612 if (next) { 1675 if (next) {
@@ -1798,6 +1861,7 @@ static __devinit void hardcode_find_bmc(void)
1798 info->irq = irqs[i]; 1861 info->irq = irqs[i];
1799 if (info->irq) 1862 if (info->irq)
1800 info->irq_setup = std_irq_setup; 1863 info->irq_setup = std_irq_setup;
1864 info->slave_addr = slave_addrs[i];
1801 1865
1802 try_smi_init(info); 1866 try_smi_init(info);
1803 } 1867 }
@@ -1919,7 +1983,7 @@ struct SPMITable {
1919 s8 spmi_id[1]; /* A '\0' terminated array starts here. */ 1983 s8 spmi_id[1]; /* A '\0' terminated array starts here. */
1920}; 1984};
1921 1985
1922static __devinit int try_init_acpi(struct SPMITable *spmi) 1986static __devinit int try_init_spmi(struct SPMITable *spmi)
1923{ 1987{
1924 struct smi_info *info; 1988 struct smi_info *info;
1925 u8 addr_space; 1989 u8 addr_space;
@@ -1940,7 +2004,7 @@ static __devinit int try_init_acpi(struct SPMITable *spmi)
1940 return -ENOMEM; 2004 return -ENOMEM;
1941 } 2005 }
1942 2006
1943 info->addr_source = "ACPI"; 2007 info->addr_source = "SPMI";
1944 2008
1945 /* Figure out the interface type. */ 2009 /* Figure out the interface type. */
1946 switch (spmi->InterfaceType) { 2010 switch (spmi->InterfaceType) {
@@ -2002,7 +2066,7 @@ static __devinit int try_init_acpi(struct SPMITable *spmi)
2002 return 0; 2066 return 0;
2003} 2067}
2004 2068
2005static __devinit void acpi_find_bmc(void) 2069static __devinit void spmi_find_bmc(void)
2006{ 2070{
2007 acpi_status status; 2071 acpi_status status;
2008 struct SPMITable *spmi; 2072 struct SPMITable *spmi;
@@ -2020,9 +2084,106 @@ static __devinit void acpi_find_bmc(void)
2020 if (status != AE_OK) 2084 if (status != AE_OK)
2021 return; 2085 return;
2022 2086
2023 try_init_acpi(spmi); 2087 try_init_spmi(spmi);
2024 } 2088 }
2025} 2089}
2090
2091static int __devinit ipmi_pnp_probe(struct pnp_dev *dev,
2092 const struct pnp_device_id *dev_id)
2093{
2094 struct acpi_device *acpi_dev;
2095 struct smi_info *info;
2096 acpi_handle handle;
2097 acpi_status status;
2098 unsigned long long tmp;
2099
2100 acpi_dev = pnp_acpi_device(dev);
2101 if (!acpi_dev)
2102 return -ENODEV;
2103
2104 info = kzalloc(sizeof(*info), GFP_KERNEL);
2105 if (!info)
2106 return -ENOMEM;
2107
2108 info->addr_source = "ACPI";
2109
2110 handle = acpi_dev->handle;
2111
2112 /* _IFT tells us the interface type: KCS, BT, etc */
2113 status = acpi_evaluate_integer(handle, "_IFT", NULL, &tmp);
2114 if (ACPI_FAILURE(status))
2115 goto err_free;
2116
2117 switch (tmp) {
2118 case 1:
2119 info->si_type = SI_KCS;
2120 break;
2121 case 2:
2122 info->si_type = SI_SMIC;
2123 break;
2124 case 3:
2125 info->si_type = SI_BT;
2126 break;
2127 default:
2128 dev_info(&dev->dev, "unknown interface type %lld\n", tmp);
2129 goto err_free;
2130 }
2131
2132 if (pnp_port_valid(dev, 0)) {
2133 info->io_setup = port_setup;
2134 info->io.addr_type = IPMI_IO_ADDR_SPACE;
2135 info->io.addr_data = pnp_port_start(dev, 0);
2136 } else if (pnp_mem_valid(dev, 0)) {
2137 info->io_setup = mem_setup;
2138 info->io.addr_type = IPMI_MEM_ADDR_SPACE;
2139 info->io.addr_data = pnp_mem_start(dev, 0);
2140 } else {
2141 dev_err(&dev->dev, "no I/O or memory address\n");
2142 goto err_free;
2143 }
2144
2145 info->io.regspacing = DEFAULT_REGSPACING;
2146 info->io.regsize = DEFAULT_REGSPACING;
2147 info->io.regshift = 0;
2148
2149 /* If _GPE exists, use it; otherwise use standard interrupts */
2150 status = acpi_evaluate_integer(handle, "_GPE", NULL, &tmp);
2151 if (ACPI_SUCCESS(status)) {
2152 info->irq = tmp;
2153 info->irq_setup = acpi_gpe_irq_setup;
2154 } else if (pnp_irq_valid(dev, 0)) {
2155 info->irq = pnp_irq(dev, 0);
2156 info->irq_setup = std_irq_setup;
2157 }
2158
2159 info->dev = &acpi_dev->dev;
2160 pnp_set_drvdata(dev, info);
2161
2162 return try_smi_init(info);
2163
2164err_free:
2165 kfree(info);
2166 return -EINVAL;
2167}
2168
2169static void __devexit ipmi_pnp_remove(struct pnp_dev *dev)
2170{
2171 struct smi_info *info = pnp_get_drvdata(dev);
2172
2173 cleanup_one_si(info);
2174}
2175
2176static const struct pnp_device_id pnp_dev_table[] = {
2177 {"IPI0001", 0},
2178 {"", 0},
2179};
2180
2181static struct pnp_driver ipmi_pnp_driver = {
2182 .name = DEVICE_NAME,
2183 .probe = ipmi_pnp_probe,
2184 .remove = __devexit_p(ipmi_pnp_remove),
2185 .id_table = pnp_dev_table,
2186};
2026#endif 2187#endif
2027 2188
2028#ifdef CONFIG_DMI 2189#ifdef CONFIG_DMI
@@ -2202,7 +2363,6 @@ static int __devinit ipmi_pci_probe(struct pci_dev *pdev,
2202 int rv; 2363 int rv;
2203 int class_type = pdev->class & PCI_ERMC_CLASSCODE_TYPE_MASK; 2364 int class_type = pdev->class & PCI_ERMC_CLASSCODE_TYPE_MASK;
2204 struct smi_info *info; 2365 struct smi_info *info;
2205 int first_reg_offset = 0;
2206 2366
2207 info = kzalloc(sizeof(*info), GFP_KERNEL); 2367 info = kzalloc(sizeof(*info), GFP_KERNEL);
2208 if (!info) 2368 if (!info)
@@ -2241,9 +2401,6 @@ static int __devinit ipmi_pci_probe(struct pci_dev *pdev,
2241 info->addr_source_cleanup = ipmi_pci_cleanup; 2401 info->addr_source_cleanup = ipmi_pci_cleanup;
2242 info->addr_source_data = pdev; 2402 info->addr_source_data = pdev;
2243 2403
2244 if (pdev->subsystem_vendor == PCI_HP_VENDOR_ID)
2245 first_reg_offset = 1;
2246
2247 if (pci_resource_flags(pdev, 0) & IORESOURCE_IO) { 2404 if (pci_resource_flags(pdev, 0) & IORESOURCE_IO) {
2248 info->io_setup = port_setup; 2405 info->io_setup = port_setup;
2249 info->io.addr_type = IPMI_IO_ADDR_SPACE; 2406 info->io.addr_type = IPMI_IO_ADDR_SPACE;
@@ -3108,7 +3265,10 @@ static __devinit int init_ipmi_si(void)
3108#endif 3265#endif
3109 3266
3110#ifdef CONFIG_ACPI 3267#ifdef CONFIG_ACPI
3111 acpi_find_bmc(); 3268 spmi_find_bmc();
3269#endif
3270#ifdef CONFIG_ACPI
3271 pnp_register_driver(&ipmi_pnp_driver);
3112#endif 3272#endif
3113 3273
3114#ifdef CONFIG_PCI 3274#ifdef CONFIG_PCI
@@ -3233,6 +3393,9 @@ static __exit void cleanup_ipmi_si(void)
3233#ifdef CONFIG_PCI 3393#ifdef CONFIG_PCI
3234 pci_unregister_driver(&ipmi_pci_driver); 3394 pci_unregister_driver(&ipmi_pci_driver);
3235#endif 3395#endif
3396#ifdef CONFIG_ACPI
3397 pnp_unregister_driver(&ipmi_pnp_driver);
3398#endif
3236 3399
3237#ifdef CONFIG_PPC_OF 3400#ifdef CONFIG_PPC_OF
3238 of_unregister_platform_driver(&ipmi_of_platform_driver); 3401 of_unregister_platform_driver(&ipmi_of_platform_driver);
diff --git a/drivers/char/isicom.c b/drivers/char/isicom.c
index 426bfdd7f3e0..c1ab303455cf 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>
@@ -128,6 +130,7 @@
128#include <linux/timer.h> 130#include <linux/timer.h>
129#include <linux/delay.h> 131#include <linux/delay.h>
130#include <linux/ioport.h> 132#include <linux/ioport.h>
133#include <linux/slab.h>
131 134
132#include <linux/uaccess.h> 135#include <linux/uaccess.h>
133#include <linux/io.h> 136#include <linux/io.h>
@@ -140,7 +143,6 @@
140#define InterruptTheCard(base) outw(0, (base) + 0xc) 143#define InterruptTheCard(base) outw(0, (base) + 0xc)
141#define ClearInterrupt(base) inw((base) + 0x0a) 144#define ClearInterrupt(base) inw((base) + 0x0a)
142 145
143#define pr_dbg(str...) pr_debug("ISICOM: " str)
144#ifdef DEBUG 146#ifdef DEBUG
145#define isicom_paranoia_check(a, b, c) __isicom_paranoia_check((a), (b), (c)) 147#define isicom_paranoia_check(a, b, c) __isicom_paranoia_check((a), (b), (c))
146#else 148#else
@@ -249,8 +251,7 @@ static int lock_card(struct isi_board *card)
249 spin_unlock_irqrestore(&card->card_lock, card->flags); 251 spin_unlock_irqrestore(&card->card_lock, card->flags);
250 msleep(10); 252 msleep(10);
251 } 253 }
252 printk(KERN_WARNING "ISICOM: Failed to lock Card (0x%lx)\n", 254 pr_warning("Failed to lock Card (0x%lx)\n", card->base);
253 card->base);
254 255
255 return 0; /* Failed to acquire the card! */ 256 return 0; /* Failed to acquire the card! */
256} 257}
@@ -379,13 +380,13 @@ static inline int __isicom_paranoia_check(struct isi_port const *port,
379 char *name, const char *routine) 380 char *name, const char *routine)
380{ 381{
381 if (!port) { 382 if (!port) {
382 printk(KERN_WARNING "ISICOM: Warning: bad isicom magic for " 383 pr_warning("Warning: bad isicom magic for dev %s in %s.\n",
383 "dev %s in %s.\n", name, routine); 384 name, routine);
384 return 1; 385 return 1;
385 } 386 }
386 if (port->magic != ISICOM_MAGIC) { 387 if (port->magic != ISICOM_MAGIC) {
387 printk(KERN_WARNING "ISICOM: Warning: NULL isicom port for " 388 pr_warning("Warning: NULL isicom port for dev %s in %s.\n",
388 "dev %s in %s.\n", name, routine); 389 name, routine);
389 return 1; 390 return 1;
390 } 391 }
391 392
@@ -450,8 +451,8 @@ static void isicom_tx(unsigned long _data)
450 if (!(inw(base + 0x02) & (1 << port->channel))) 451 if (!(inw(base + 0x02) & (1 << port->channel)))
451 continue; 452 continue;
452 453
453 pr_dbg("txing %d bytes, port%d.\n", txcount, 454 pr_debug("txing %d bytes, port%d.\n",
454 port->channel + 1); 455 txcount, port->channel + 1);
455 outw((port->channel << isi_card[card].shift_count) | txcount, 456 outw((port->channel << isi_card[card].shift_count) | txcount,
456 base); 457 base);
457 residue = NO; 458 residue = NO;
@@ -547,8 +548,8 @@ static irqreturn_t isicom_interrupt(int irq, void *dev_id)
547 byte_count = header & 0xff; 548 byte_count = header & 0xff;
548 549
549 if (channel + 1 > card->port_count) { 550 if (channel + 1 > card->port_count) {
550 printk(KERN_WARNING "ISICOM: isicom_interrupt(0x%lx): " 551 pr_warning("%s(0x%lx): %d(channel) > port_count.\n",
551 "%d(channel) > port_count.\n", base, channel+1); 552 __func__, base, channel+1);
552 outw(0x0000, base+0x04); /* enable interrupts */ 553 outw(0x0000, base+0x04); /* enable interrupts */
553 spin_unlock(&card->card_lock); 554 spin_unlock(&card->card_lock);
554 return IRQ_HANDLED; 555 return IRQ_HANDLED;
@@ -582,14 +583,15 @@ static irqreturn_t isicom_interrupt(int irq, void *dev_id)
582 if (port->status & ISI_DCD) { 583 if (port->status & ISI_DCD) {
583 if (!(header & ISI_DCD)) { 584 if (!(header & ISI_DCD)) {
584 /* Carrier has been lost */ 585 /* Carrier has been lost */
585 pr_dbg("interrupt: DCD->low.\n" 586 pr_debug("%s: DCD->low.\n",
586 ); 587 __func__);
587 port->status &= ~ISI_DCD; 588 port->status &= ~ISI_DCD;
588 tty_hangup(tty); 589 tty_hangup(tty);
589 } 590 }
590 } else if (header & ISI_DCD) { 591 } else if (header & ISI_DCD) {
591 /* Carrier has been detected */ 592 /* Carrier has been detected */
592 pr_dbg("interrupt: DCD->high.\n"); 593 pr_debug("%s: DCD->high.\n",
594 __func__);
593 port->status |= ISI_DCD; 595 port->status |= ISI_DCD;
594 wake_up_interruptible(&port->port.open_wait); 596 wake_up_interruptible(&port->port.open_wait);
595 } 597 }
@@ -641,17 +643,19 @@ static irqreturn_t isicom_interrupt(int irq, void *dev_id)
641 break; 643 break;
642 644
643 case 2: /* Statistics */ 645 case 2: /* Statistics */
644 pr_dbg("isicom_interrupt: stats!!!.\n"); 646 pr_debug("%s: stats!!!\n", __func__);
645 break; 647 break;
646 648
647 default: 649 default:
648 pr_dbg("Intr: Unknown code in status packet.\n"); 650 pr_debug("%s: Unknown code in status packet.\n",
651 __func__);
649 break; 652 break;
650 } 653 }
651 } else { /* Data Packet */ 654 } else { /* Data Packet */
652 655
653 count = tty_prepare_flip_string(tty, &rp, byte_count & ~1); 656 count = tty_prepare_flip_string(tty, &rp, byte_count & ~1);
654 pr_dbg("Intr: Can rx %d of %d bytes.\n", count, byte_count); 657 pr_debug("%s: Can rx %d of %d bytes.\n",
658 __func__, count, byte_count);
655 word_count = count >> 1; 659 word_count = count >> 1;
656 insw(base, rp, word_count); 660 insw(base, rp, word_count);
657 byte_count -= (word_count << 1); 661 byte_count -= (word_count << 1);
@@ -661,8 +665,8 @@ static irqreturn_t isicom_interrupt(int irq, void *dev_id)
661 byte_count -= 2; 665 byte_count -= 2;
662 } 666 }
663 if (byte_count > 0) { 667 if (byte_count > 0) {
664 pr_dbg("Intr(0x%lx:%d): Flip buffer overflow! dropping " 668 pr_debug("%s(0x%lx:%d): Flip buffer overflow! dropping bytes...\n",
665 "bytes...\n", base, channel + 1); 669 __func__, base, channel + 1);
666 /* drain out unread xtra data */ 670 /* drain out unread xtra data */
667 while (byte_count > 0) { 671 while (byte_count > 0) {
668 inw(base); 672 inw(base);
@@ -793,35 +797,30 @@ static inline void isicom_setup_board(struct isi_board *bp)
793{ 797{
794 int channel; 798 int channel;
795 struct isi_port *port; 799 struct isi_port *port;
796 unsigned long flags;
797 800
798 spin_lock_irqsave(&bp->card_lock, flags); 801 bp->count++;
799 if (bp->status & BOARD_ACTIVE) { 802 if (!(bp->status & BOARD_INIT)) {
800 spin_unlock_irqrestore(&bp->card_lock, flags); 803 port = bp->ports;
801 return; 804 for (channel = 0; channel < bp->port_count; channel++, port++)
805 drop_dtr_rts(port);
802 } 806 }
803 port = bp->ports; 807 bp->status |= BOARD_ACTIVE | BOARD_INIT;
804 bp->status |= BOARD_ACTIVE;
805 for (channel = 0; channel < bp->port_count; channel++, port++)
806 drop_dtr_rts(port);
807 spin_unlock_irqrestore(&bp->card_lock, flags);
808} 808}
809 809
810static int isicom_setup_port(struct tty_struct *tty) 810/* Activate and thus setup board are protected from races against shutdown
811 by the tty_port mutex */
812
813static int isicom_activate(struct tty_port *tport, struct tty_struct *tty)
811{ 814{
812 struct isi_port *port = tty->driver_data; 815 struct isi_port *port = container_of(tport, struct isi_port, port);
813 struct isi_board *card = port->card; 816 struct isi_board *card = port->card;
814 unsigned long flags; 817 unsigned long flags;
815 818
816 if (port->port.flags & ASYNC_INITIALIZED) 819 if (tty_port_alloc_xmit_buf(tport) < 0)
817 return 0;
818 if (tty_port_alloc_xmit_buf(&port->port) < 0)
819 return -ENOMEM; 820 return -ENOMEM;
820 821
821 spin_lock_irqsave(&card->card_lock, flags); 822 spin_lock_irqsave(&card->card_lock, flags);
822 clear_bit(TTY_IO_ERROR, &tty->flags); 823 isicom_setup_board(card);
823 if (port->port.count == 1)
824 card->count++;
825 824
826 port->xmit_cnt = port->xmit_head = port->xmit_tail = 0; 825 port->xmit_cnt = port->xmit_head = port->xmit_tail = 0;
827 826
@@ -832,9 +831,7 @@ static int isicom_setup_port(struct tty_struct *tty)
832 outw(((ISICOM_KILLTX | ISICOM_KILLRX) << 8) | 0x06, card->base); 831 outw(((ISICOM_KILLTX | ISICOM_KILLRX) << 8) | 0x06, card->base);
833 InterruptTheCard(card->base); 832 InterruptTheCard(card->base);
834 } 833 }
835
836 isicom_config_port(tty); 834 isicom_config_port(tty);
837 port->port.flags |= ASYNC_INITIALIZED;
838 spin_unlock_irqrestore(&card->card_lock, flags); 835 spin_unlock_irqrestore(&card->card_lock, flags);
839 836
840 return 0; 837 return 0;
@@ -871,85 +868,37 @@ static struct tty_port *isicom_find_port(struct tty_struct *tty)
871 868
872 return &port->port; 869 return &port->port;
873} 870}
874 871
875static int isicom_open(struct tty_struct *tty, struct file *filp) 872static int isicom_open(struct tty_struct *tty, struct file *filp)
876{ 873{
877 struct isi_port *port; 874 struct isi_port *port;
878 struct isi_board *card; 875 struct isi_board *card;
879 struct tty_port *tport; 876 struct tty_port *tport;
880 int error = 0;
881 877
882 tport = isicom_find_port(tty); 878 tport = isicom_find_port(tty);
883 if (tport == NULL) 879 if (tport == NULL)
884 return -ENODEV; 880 return -ENODEV;
885 port = container_of(tport, struct isi_port, port); 881 port = container_of(tport, struct isi_port, port);
886 card = &isi_card[BOARD(tty->index)];
887 isicom_setup_board(card);
888 882
889 /* FIXME: locking on port.count etc */
890 port->port.count++;
891 tty->driver_data = port; 883 tty->driver_data = port;
892 tty_port_tty_set(&port->port, tty); 884 return tty_port_open(tport, tty, filp);
893 /* FIXME: Locking on Initialized flag */
894 if (!test_bit(ASYNCB_INITIALIZED, &tport->flags))
895 error = isicom_setup_port(tty);
896 if (error == 0)
897 error = tty_port_block_til_ready(&port->port, tty, filp);
898 return error;
899} 885}
900 886
901/* close et all */ 887/* close et all */
902 888
903static inline void isicom_shutdown_board(struct isi_board *bp)
904{
905 if (bp->status & BOARD_ACTIVE)
906 bp->status &= ~BOARD_ACTIVE;
907}
908
909/* card->lock HAS to be held */ 889/* card->lock HAS to be held */
910static void isicom_shutdown_port(struct isi_port *port) 890static void isicom_shutdown_port(struct isi_port *port)
911{ 891{
912 struct isi_board *card = port->card; 892 struct isi_board *card = port->card;
913 struct tty_struct *tty;
914
915 tty = tty_port_tty_get(&port->port);
916
917 if (!(port->port.flags & ASYNC_INITIALIZED)) {
918 tty_kref_put(tty);
919 return;
920 }
921
922 tty_port_free_xmit_buf(&port->port);
923 port->port.flags &= ~ASYNC_INITIALIZED;
924 /* 3rd October 2000 : Vinayak P Risbud */
925 tty_port_tty_set(&port->port, NULL);
926
927 /*Fix done by Anil .S on 30-04-2001
928 remote login through isi port has dtr toggle problem
929 due to which the carrier drops before the password prompt
930 appears on the remote end. Now we drop the dtr only if the
931 HUPCL(Hangup on close) flag is set for the tty*/
932
933 if (C_HUPCL(tty))
934 /* drop dtr on this port */
935 drop_dtr(port);
936
937 /* any other port uninits */
938 if (tty)
939 set_bit(TTY_IO_ERROR, &tty->flags);
940 893
941 if (--card->count < 0) { 894 if (--card->count < 0) {
942 pr_dbg("isicom_shutdown_port: bad board(0x%lx) count %d.\n", 895 pr_debug("%s: bad board(0x%lx) count %d.\n",
943 card->base, card->count); 896 __func__, card->base, card->count);
944 card->count = 0; 897 card->count = 0;
945 } 898 }
946 899 /* last port was closed, shutdown that board too */
947 /* last port was closed, shutdown that boad too */ 900 if (!card->count)
948 if (C_HUPCL(tty)) { 901 card->status &= BOARD_ACTIVE;
949 if (!card->count)
950 isicom_shutdown_board(card);
951 }
952 tty_kref_put(tty);
953} 902}
954 903
955static void isicom_flush_buffer(struct tty_struct *tty) 904static void isicom_flush_buffer(struct tty_struct *tty)
@@ -968,7 +917,7 @@ static void isicom_flush_buffer(struct tty_struct *tty)
968 tty_wakeup(tty); 917 tty_wakeup(tty);
969} 918}
970 919
971static void isicom_close_port(struct tty_port *port) 920static void isicom_shutdown(struct tty_port *port)
972{ 921{
973 struct isi_port *ip = container_of(port, struct isi_port, port); 922 struct isi_port *ip = container_of(port, struct isi_port, port);
974 struct isi_board *card = ip->card; 923 struct isi_board *card = ip->card;
@@ -977,26 +926,25 @@ static void isicom_close_port(struct tty_port *port)
977 /* indicate to the card that no more data can be received 926 /* indicate to the card that no more data can be received
978 on this port */ 927 on this port */
979 spin_lock_irqsave(&card->card_lock, flags); 928 spin_lock_irqsave(&card->card_lock, flags);
980 if (port->flags & ASYNC_INITIALIZED) { 929 card->port_status &= ~(1 << ip->channel);
981 card->port_status &= ~(1 << ip->channel); 930 outw(card->port_status, card->base + 0x02);
982 outw(card->port_status, card->base + 0x02);
983 }
984 isicom_shutdown_port(ip); 931 isicom_shutdown_port(ip);
985 spin_unlock_irqrestore(&card->card_lock, flags); 932 spin_unlock_irqrestore(&card->card_lock, flags);
933 tty_port_free_xmit_buf(port);
986} 934}
987 935
988static void isicom_close(struct tty_struct *tty, struct file *filp) 936static void isicom_close(struct tty_struct *tty, struct file *filp)
989{ 937{
990 struct isi_port *ip = tty->driver_data; 938 struct isi_port *ip = tty->driver_data;
991 struct tty_port *port = &ip->port; 939 struct tty_port *port;
992 if (isicom_paranoia_check(ip, tty->name, "isicom_close")) 940
941 if (ip == NULL)
993 return; 942 return;
994 943
995 if (tty_port_close_start(port, tty, filp) == 0) 944 port = &ip->port;
945 if (isicom_paranoia_check(ip, tty->name, "isicom_close"))
996 return; 946 return;
997 isicom_close_port(port); 947 tty_port_close(port, tty, filp);
998 isicom_flush_buffer(tty);
999 tty_port_close_end(port, tty);
1000} 948}
1001 949
1002/* write et all */ 950/* write et all */
@@ -1326,15 +1274,9 @@ static void isicom_start(struct tty_struct *tty)
1326static void isicom_hangup(struct tty_struct *tty) 1274static void isicom_hangup(struct tty_struct *tty)
1327{ 1275{
1328 struct isi_port *port = tty->driver_data; 1276 struct isi_port *port = tty->driver_data;
1329 unsigned long flags;
1330 1277
1331 if (isicom_paranoia_check(port, tty->name, "isicom_hangup")) 1278 if (isicom_paranoia_check(port, tty->name, "isicom_hangup"))
1332 return; 1279 return;
1333
1334 spin_lock_irqsave(&port->card->card_lock, flags);
1335 isicom_shutdown_port(port);
1336 spin_unlock_irqrestore(&port->card->card_lock, flags);
1337
1338 tty_port_hangup(&port->port); 1280 tty_port_hangup(&port->port);
1339} 1281}
1340 1282
@@ -1367,6 +1309,8 @@ static const struct tty_operations isicom_ops = {
1367static const struct tty_port_operations isicom_port_ops = { 1309static const struct tty_port_operations isicom_port_ops = {
1368 .carrier_raised = isicom_carrier_raised, 1310 .carrier_raised = isicom_carrier_raised,
1369 .dtr_rts = isicom_dtr_rts, 1311 .dtr_rts = isicom_dtr_rts,
1312 .activate = isicom_activate,
1313 .shutdown = isicom_shutdown,
1370}; 1314};
1371 1315
1372static int __devinit reset_card(struct pci_dev *pdev, 1316static int __devinit reset_card(struct pci_dev *pdev,
@@ -1746,13 +1690,13 @@ static int __init isicom_init(void)
1746 1690
1747 retval = tty_register_driver(isicom_normal); 1691 retval = tty_register_driver(isicom_normal);
1748 if (retval) { 1692 if (retval) {
1749 pr_dbg("Couldn't register the dialin driver\n"); 1693 pr_debug("Couldn't register the dialin driver\n");
1750 goto err_puttty; 1694 goto err_puttty;
1751 } 1695 }
1752 1696
1753 retval = pci_register_driver(&isicom_driver); 1697 retval = pci_register_driver(&isicom_driver);
1754 if (retval < 0) { 1698 if (retval < 0) {
1755 printk(KERN_ERR "ISICOM: Unable to register pci driver.\n"); 1699 pr_err("Unable to register pci driver.\n");
1756 goto err_unrtty; 1700 goto err_unrtty;
1757 } 1701 }
1758 1702
@@ -1782,3 +1726,8 @@ module_exit(isicom_exit);
1782MODULE_AUTHOR("MultiTech"); 1726MODULE_AUTHOR("MultiTech");
1783MODULE_DESCRIPTION("Driver for the ISI series of cards by MultiTech"); 1727MODULE_DESCRIPTION("Driver for the ISI series of cards by MultiTech");
1784MODULE_LICENSE("GPL"); 1728MODULE_LICENSE("GPL");
1729MODULE_FIRMWARE("isi608.bin");
1730MODULE_FIRMWARE("isi608em.bin");
1731MODULE_FIRMWARE("isi616em.bin");
1732MODULE_FIRMWARE("isi4608.bin");
1733MODULE_FIRMWARE("isi4616.bin");
diff --git a/drivers/char/istallion.c b/drivers/char/istallion.c
index 402838f4083e..4e395c956a09 100644
--- a/drivers/char/istallion.c
+++ b/drivers/char/istallion.c
@@ -213,7 +213,6 @@ static int stli_shared;
213 * with the slave. Most of them need to be updated atomically, so always 213 * with the slave. Most of them need to be updated atomically, so always
214 * use the bit setting operations (unless protected by cli/sti). 214 * use the bit setting operations (unless protected by cli/sti).
215 */ 215 */
216#define ST_INITIALIZING 1
217#define ST_OPENING 2 216#define ST_OPENING 2
218#define ST_CLOSING 3 217#define ST_CLOSING 3
219#define ST_CMDING 4 218#define ST_CMDING 4
@@ -621,7 +620,7 @@ static int stli_brdinit(struct stlibrd *brdp);
621static int stli_startbrd(struct stlibrd *brdp); 620static int stli_startbrd(struct stlibrd *brdp);
622static ssize_t stli_memread(struct file *fp, char __user *buf, size_t count, loff_t *offp); 621static ssize_t stli_memread(struct file *fp, char __user *buf, size_t count, loff_t *offp);
623static ssize_t stli_memwrite(struct file *fp, const char __user *buf, size_t count, loff_t *offp); 622static ssize_t stli_memwrite(struct file *fp, const char __user *buf, size_t count, loff_t *offp);
624static int stli_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, unsigned long arg); 623static long stli_memioctl(struct file *fp, unsigned int cmd, unsigned long arg);
625static void stli_brdpoll(struct stlibrd *brdp, cdkhdr_t __iomem *hdrp); 624static void stli_brdpoll(struct stlibrd *brdp, cdkhdr_t __iomem *hdrp);
626static void stli_poll(unsigned long arg); 625static void stli_poll(unsigned long arg);
627static int stli_hostcmd(struct stlibrd *brdp, struct stliport *portp); 626static int stli_hostcmd(struct stlibrd *brdp, struct stliport *portp);
@@ -704,7 +703,7 @@ static const struct file_operations stli_fsiomem = {
704 .owner = THIS_MODULE, 703 .owner = THIS_MODULE,
705 .read = stli_memread, 704 .read = stli_memread,
706 .write = stli_memwrite, 705 .write = stli_memwrite,
707 .ioctl = stli_memioctl, 706 .unlocked_ioctl = stli_memioctl,
708}; 707};
709 708
710/*****************************************************************************/ 709/*****************************************************************************/
@@ -783,13 +782,32 @@ static int stli_parsebrd(struct stlconf *confp, char **argp)
783 782
784/*****************************************************************************/ 783/*****************************************************************************/
785 784
785/*
786 * On the first open of the device setup the port hardware, and
787 * initialize the per port data structure. Since initializing the port
788 * requires several commands to the board we will need to wait for any
789 * other open that is already initializing the port.
790 *
791 * Locking: protected by the port mutex.
792 */
793
794static int stli_activate(struct tty_port *port, struct tty_struct *tty)
795{
796 struct stliport *portp = container_of(port, struct stliport, port);
797 struct stlibrd *brdp = stli_brds[portp->brdnr];
798 int rc;
799
800 if ((rc = stli_initopen(tty, brdp, portp)) >= 0)
801 clear_bit(TTY_IO_ERROR, &tty->flags);
802 wake_up_interruptible(&portp->raw_wait);
803 return rc;
804}
805
786static int stli_open(struct tty_struct *tty, struct file *filp) 806static int stli_open(struct tty_struct *tty, struct file *filp)
787{ 807{
788 struct stlibrd *brdp; 808 struct stlibrd *brdp;
789 struct stliport *portp; 809 struct stliport *portp;
790 struct tty_port *port;
791 unsigned int minordev, brdnr, portnr; 810 unsigned int minordev, brdnr, portnr;
792 int rc;
793 811
794 minordev = tty->index; 812 minordev = tty->index;
795 brdnr = MINOR2BRD(minordev); 813 brdnr = MINOR2BRD(minordev);
@@ -809,95 +827,58 @@ static int stli_open(struct tty_struct *tty, struct file *filp)
809 return -ENODEV; 827 return -ENODEV;
810 if (portp->devnr < 1) 828 if (portp->devnr < 1)
811 return -ENODEV; 829 return -ENODEV;
812 port = &portp->port;
813 830
814/*
815 * On the first open of the device setup the port hardware, and
816 * initialize the per port data structure. Since initializing the port
817 * requires several commands to the board we will need to wait for any
818 * other open that is already initializing the port.
819 *
820 * Review - locking
821 */
822 tty_port_tty_set(port, tty);
823 tty->driver_data = portp; 831 tty->driver_data = portp;
824 port->count++; 832 return tty_port_open(&portp->port, tty, filp);
825
826 wait_event_interruptible(portp->raw_wait,
827 !test_bit(ST_INITIALIZING, &portp->state));
828 if (signal_pending(current))
829 return -ERESTARTSYS;
830
831 if ((portp->port.flags & ASYNC_INITIALIZED) == 0) {
832 set_bit(ST_INITIALIZING, &portp->state);
833 if ((rc = stli_initopen(tty, brdp, portp)) >= 0) {
834 /* Locking */
835 port->flags |= ASYNC_INITIALIZED;
836 clear_bit(TTY_IO_ERROR, &tty->flags);
837 }
838 clear_bit(ST_INITIALIZING, &portp->state);
839 wake_up_interruptible(&portp->raw_wait);
840 if (rc < 0)
841 return rc;
842 }
843 return tty_port_block_til_ready(&portp->port, tty, filp);
844} 833}
845 834
835
846/*****************************************************************************/ 836/*****************************************************************************/
847 837
848static void stli_close(struct tty_struct *tty, struct file *filp) 838static void stli_shutdown(struct tty_port *port)
849{ 839{
850 struct stlibrd *brdp; 840 struct stlibrd *brdp;
851 struct stliport *portp; 841 unsigned long ftype;
852 struct tty_port *port;
853 unsigned long flags; 842 unsigned long flags;
843 struct stliport *portp = container_of(port, struct stliport, port);
854 844
855 portp = tty->driver_data; 845 if (portp->brdnr >= stli_nrbrds)
856 if (portp == NULL)
857 return; 846 return;
858 port = &portp->port; 847 brdp = stli_brds[portp->brdnr];
859 848 if (brdp == NULL)
860 if (tty_port_close_start(port, tty, filp) == 0)
861 return; 849 return;
862 850
863/* 851 /*
864 * May want to wait for data to drain before closing. The BUSY flag 852 * May want to wait for data to drain before closing. The BUSY
865 * keeps track of whether we are still transmitting or not. It is 853 * flag keeps track of whether we are still transmitting or not.
866 * updated by messages from the slave - indicating when all chars 854 * It is updated by messages from the slave - indicating when all
867 * really have drained. 855 * chars really have drained.
868 */ 856 */
869 spin_lock_irqsave(&stli_lock, flags);
870 if (tty == stli_txcooktty)
871 stli_flushchars(tty);
872 spin_unlock_irqrestore(&stli_lock, flags);
873
874 /* We end up doing this twice for the moment. This needs looking at
875 eventually. Note we still use portp->closing_wait as a result */
876 if (portp->closing_wait != ASYNC_CLOSING_WAIT_NONE)
877 tty_wait_until_sent(tty, portp->closing_wait);
878 857
879 /* FIXME: port locking here needs attending to */ 858 if (!test_bit(ST_CLOSING, &portp->state))
880 port->flags &= ~ASYNC_INITIALIZED; 859 stli_rawclose(brdp, portp, 0, 0);
881 860
882 brdp = stli_brds[portp->brdnr]; 861 spin_lock_irqsave(&stli_lock, flags);
883 stli_rawclose(brdp, portp, 0, 0);
884 if (tty->termios->c_cflag & HUPCL) {
885 stli_mkasysigs(&portp->asig, 0, 0);
886 if (test_bit(ST_CMDING, &portp->state))
887 set_bit(ST_DOSIGS, &portp->state);
888 else
889 stli_sendcmd(brdp, portp, A_SETSIGNALS, &portp->asig,
890 sizeof(asysigs_t), 0);
891 }
892 clear_bit(ST_TXBUSY, &portp->state); 862 clear_bit(ST_TXBUSY, &portp->state);
893 clear_bit(ST_RXSTOP, &portp->state); 863 clear_bit(ST_RXSTOP, &portp->state);
894 set_bit(TTY_IO_ERROR, &tty->flags); 864 spin_unlock_irqrestore(&stli_lock, flags);
895 tty_ldisc_flush(tty);
896 set_bit(ST_DOFLUSHRX, &portp->state);
897 stli_flushbuffer(tty);
898 865
899 tty_port_close_end(port, tty); 866 ftype = FLUSHTX | FLUSHRX;
900 tty_port_tty_set(port, NULL); 867 stli_cmdwait(brdp, portp, A_FLUSH, &ftype, sizeof(u32), 0);
868}
869
870static void stli_close(struct tty_struct *tty, struct file *filp)
871{
872 struct stliport *portp = tty->driver_data;
873 unsigned long flags;
874 if (portp == NULL)
875 return;
876 spin_lock_irqsave(&stli_lock, flags);
877 /* Flush any internal buffering out first */
878 if (tty == stli_txcooktty)
879 stli_flushchars(tty);
880 spin_unlock_irqrestore(&stli_lock, flags);
881 tty_port_close(&portp->port, tty, filp);
901} 882}
902 883
903/*****************************************************************************/ 884/*****************************************************************************/
@@ -1724,6 +1705,7 @@ static void stli_start(struct tty_struct *tty)
1724 1705
1725/*****************************************************************************/ 1706/*****************************************************************************/
1726 1707
1708
1727/* 1709/*
1728 * Hangup this port. This is pretty much like closing the port, only 1710 * Hangup this port. This is pretty much like closing the port, only
1729 * a little more brutal. No waiting for data to drain. Shutdown the 1711 * a little more brutal. No waiting for data to drain. Shutdown the
@@ -1733,47 +1715,8 @@ static void stli_start(struct tty_struct *tty)
1733 1715
1734static void stli_hangup(struct tty_struct *tty) 1716static void stli_hangup(struct tty_struct *tty)
1735{ 1717{
1736 struct stliport *portp; 1718 struct stliport *portp = tty->driver_data;
1737 struct stlibrd *brdp; 1719 tty_port_hangup(&portp->port);
1738 struct tty_port *port;
1739 unsigned long flags;
1740
1741 portp = tty->driver_data;
1742 if (portp == NULL)
1743 return;
1744 if (portp->brdnr >= stli_nrbrds)
1745 return;
1746 brdp = stli_brds[portp->brdnr];
1747 if (brdp == NULL)
1748 return;
1749 port = &portp->port;
1750
1751 spin_lock_irqsave(&port->lock, flags);
1752 port->flags &= ~ASYNC_INITIALIZED;
1753 spin_unlock_irqrestore(&port->lock, flags);
1754
1755 if (!test_bit(ST_CLOSING, &portp->state))
1756 stli_rawclose(brdp, portp, 0, 0);
1757
1758 spin_lock_irqsave(&stli_lock, flags);
1759 if (tty->termios->c_cflag & HUPCL) {
1760 stli_mkasysigs(&portp->asig, 0, 0);
1761 if (test_bit(ST_CMDING, &portp->state)) {
1762 set_bit(ST_DOSIGS, &portp->state);
1763 set_bit(ST_DOFLUSHTX, &portp->state);
1764 set_bit(ST_DOFLUSHRX, &portp->state);
1765 } else {
1766 stli_sendcmd(brdp, portp, A_SETSIGNALSF,
1767 &portp->asig, sizeof(asysigs_t), 0);
1768 }
1769 }
1770
1771 clear_bit(ST_TXBUSY, &portp->state);
1772 clear_bit(ST_RXSTOP, &portp->state);
1773 set_bit(TTY_IO_ERROR, &tty->flags);
1774 spin_unlock_irqrestore(&stli_lock, flags);
1775
1776 tty_port_hangup(port);
1777} 1720}
1778 1721
1779/*****************************************************************************/ 1722/*****************************************************************************/
@@ -4311,7 +4254,7 @@ static int stli_getbrdstruct(struct stlibrd __user *arg)
4311 * reset it, and start/stop it. 4254 * reset it, and start/stop it.
4312 */ 4255 */
4313 4256
4314static int stli_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, unsigned long arg) 4257static long stli_memioctl(struct file *fp, unsigned int cmd, unsigned long arg)
4315{ 4258{
4316 struct stlibrd *brdp; 4259 struct stlibrd *brdp;
4317 int brdnr, rc, done; 4260 int brdnr, rc, done;
@@ -4356,7 +4299,7 @@ static int stli_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, un
4356 * Now handle the board specific ioctls. These all depend on the 4299 * Now handle the board specific ioctls. These all depend on the
4357 * minor number of the device they were called from. 4300 * minor number of the device they were called from.
4358 */ 4301 */
4359 brdnr = iminor(ip); 4302 brdnr = iminor(fp->f_dentry->d_inode);
4360 if (brdnr >= STL_MAXBRDS) 4303 if (brdnr >= STL_MAXBRDS)
4361 return -ENODEV; 4304 return -ENODEV;
4362 brdp = stli_brds[brdnr]; 4305 brdp = stli_brds[brdnr];
@@ -4420,6 +4363,8 @@ static const struct tty_operations stli_ops = {
4420static const struct tty_port_operations stli_port_ops = { 4363static const struct tty_port_operations stli_port_ops = {
4421 .carrier_raised = stli_carrier_raised, 4364 .carrier_raised = stli_carrier_raised,
4422 .dtr_rts = stli_dtr_rts, 4365 .dtr_rts = stli_dtr_rts,
4366 .activate = stli_activate,
4367 .shutdown = stli_shutdown,
4423}; 4368};
4424 4369
4425/*****************************************************************************/ 4370/*****************************************************************************/
diff --git a/drivers/char/keyboard.c b/drivers/char/keyboard.c
index 950837cf9e9c..ada25bb8941e 100644
--- a/drivers/char/keyboard.c
+++ b/drivers/char/keyboard.c
@@ -46,8 +46,6 @@
46 46
47extern void ctrl_alt_del(void); 47extern void ctrl_alt_del(void);
48 48
49#define to_handle_h(n) container_of(n, struct input_handle, h_node)
50
51/* 49/*
52 * Exported functions/variables 50 * Exported functions/variables
53 */ 51 */
@@ -132,6 +130,7 @@ int shift_state = 0;
132 */ 130 */
133 131
134static struct input_handler kbd_handler; 132static struct input_handler kbd_handler;
133static DEFINE_SPINLOCK(kbd_event_lock);
135static unsigned long key_down[BITS_TO_LONGS(KEY_CNT)]; /* keyboard key bitmap */ 134static unsigned long key_down[BITS_TO_LONGS(KEY_CNT)]; /* keyboard key bitmap */
136static unsigned char shift_down[NR_SHIFT]; /* shift state counters.. */ 135static unsigned char shift_down[NR_SHIFT]; /* shift state counters.. */
137static int dead_key_next; 136static int dead_key_next;
@@ -190,78 +189,89 @@ EXPORT_SYMBOL_GPL(unregister_keyboard_notifier);
190 * etc.). So this means that scancodes for the extra function keys won't 189 * etc.). So this means that scancodes for the extra function keys won't
191 * be valid for the first event device, but will be for the second. 190 * be valid for the first event device, but will be for the second.
192 */ 191 */
192
193struct getset_keycode_data {
194 unsigned int scancode;
195 unsigned int keycode;
196 int error;
197};
198
199static int getkeycode_helper(struct input_handle *handle, void *data)
200{
201 struct getset_keycode_data *d = data;
202
203 d->error = input_get_keycode(handle->dev, d->scancode, &d->keycode);
204
205 return d->error == 0; /* stop as soon as we successfully get one */
206}
207
193int getkeycode(unsigned int scancode) 208int getkeycode(unsigned int scancode)
194{ 209{
195 struct input_handle *handle; 210 struct getset_keycode_data d = { scancode, 0, -ENODEV };
196 int keycode;
197 int error = -ENODEV;
198 211
199 list_for_each_entry(handle, &kbd_handler.h_list, h_node) { 212 input_handler_for_each_handle(&kbd_handler, &d, getkeycode_helper);
200 error = input_get_keycode(handle->dev, scancode, &keycode);
201 if (!error)
202 return keycode;
203 }
204 213
205 return error; 214 return d.error ?: d.keycode;
215}
216
217static int setkeycode_helper(struct input_handle *handle, void *data)
218{
219 struct getset_keycode_data *d = data;
220
221 d->error = input_set_keycode(handle->dev, d->scancode, d->keycode);
222
223 return d->error == 0; /* stop as soon as we successfully set one */
206} 224}
207 225
208int setkeycode(unsigned int scancode, unsigned int keycode) 226int setkeycode(unsigned int scancode, unsigned int keycode)
209{ 227{
210 struct input_handle *handle; 228 struct getset_keycode_data d = { scancode, keycode, -ENODEV };
211 int error = -ENODEV;
212 229
213 list_for_each_entry(handle, &kbd_handler.h_list, h_node) { 230 input_handler_for_each_handle(&kbd_handler, &d, setkeycode_helper);
214 error = input_set_keycode(handle->dev, scancode, keycode);
215 if (!error)
216 break;
217 }
218 231
219 return error; 232 return d.error;
220} 233}
221 234
222/* 235/*
223 * Making beeps and bells. 236 * Making beeps and bells. Note that we prefer beeps to bells, but when
237 * shutting the sound off we do both.
224 */ 238 */
225static void kd_nosound(unsigned long ignored) 239
240static int kd_sound_helper(struct input_handle *handle, void *data)
226{ 241{
227 struct input_handle *handle; 242 unsigned int *hz = data;
243 struct input_dev *dev = handle->dev;
228 244
229 list_for_each_entry(handle, &kbd_handler.h_list, h_node) { 245 if (test_bit(EV_SND, dev->evbit)) {
230 if (test_bit(EV_SND, handle->dev->evbit)) { 246 if (test_bit(SND_TONE, dev->sndbit)) {
231 if (test_bit(SND_TONE, handle->dev->sndbit)) 247 input_inject_event(handle, EV_SND, SND_TONE, *hz);
232 input_inject_event(handle, EV_SND, SND_TONE, 0); 248 if (*hz)
233 if (test_bit(SND_BELL, handle->dev->sndbit)) 249 return 0;
234 input_inject_event(handle, EV_SND, SND_BELL, 0);
235 } 250 }
251 if (test_bit(SND_BELL, dev->sndbit))
252 input_inject_event(handle, EV_SND, SND_BELL, *hz ? 1 : 0);
236 } 253 }
254
255 return 0;
256}
257
258static void kd_nosound(unsigned long ignored)
259{
260 static unsigned int zero;
261
262 input_handler_for_each_handle(&kbd_handler, &zero, kd_sound_helper);
237} 263}
238 264
239static DEFINE_TIMER(kd_mksound_timer, kd_nosound, 0, 0); 265static DEFINE_TIMER(kd_mksound_timer, kd_nosound, 0, 0);
240 266
241void kd_mksound(unsigned int hz, unsigned int ticks) 267void kd_mksound(unsigned int hz, unsigned int ticks)
242{ 268{
243 struct list_head *node; 269 del_timer_sync(&kd_mksound_timer);
244 270
245 del_timer(&kd_mksound_timer); 271 input_handler_for_each_handle(&kbd_handler, &hz, kd_sound_helper);
246 272
247 if (hz) { 273 if (hz && ticks)
248 list_for_each_prev(node, &kbd_handler.h_list) { 274 mod_timer(&kd_mksound_timer, jiffies + ticks);
249 struct input_handle *handle = to_handle_h(node);
250 if (test_bit(EV_SND, handle->dev->evbit)) {
251 if (test_bit(SND_TONE, handle->dev->sndbit)) {
252 input_inject_event(handle, EV_SND, SND_TONE, hz);
253 break;
254 }
255 if (test_bit(SND_BELL, handle->dev->sndbit)) {
256 input_inject_event(handle, EV_SND, SND_BELL, 1);
257 break;
258 }
259 }
260 }
261 if (ticks)
262 mod_timer(&kd_mksound_timer, jiffies + ticks);
263 } else
264 kd_nosound(0);
265} 275}
266EXPORT_SYMBOL(kd_mksound); 276EXPORT_SYMBOL(kd_mksound);
267 277
@@ -269,27 +279,34 @@ EXPORT_SYMBOL(kd_mksound);
269 * Setting the keyboard rate. 279 * Setting the keyboard rate.
270 */ 280 */
271 281
272int kbd_rate(struct kbd_repeat *rep) 282static int kbd_rate_helper(struct input_handle *handle, void *data)
273{ 283{
274 struct list_head *node; 284 struct input_dev *dev = handle->dev;
275 unsigned int d = 0; 285 struct kbd_repeat *rep = data;
276 unsigned int p = 0; 286
277 287 if (test_bit(EV_REP, dev->evbit)) {
278 list_for_each(node, &kbd_handler.h_list) { 288
279 struct input_handle *handle = to_handle_h(node); 289 if (rep[0].delay > 0)
280 struct input_dev *dev = handle->dev; 290 input_inject_event(handle,
281 291 EV_REP, REP_DELAY, rep[0].delay);
282 if (test_bit(EV_REP, dev->evbit)) { 292 if (rep[0].period > 0)
283 if (rep->delay > 0) 293 input_inject_event(handle,
284 input_inject_event(handle, EV_REP, REP_DELAY, rep->delay); 294 EV_REP, REP_PERIOD, rep[0].period);
285 if (rep->period > 0) 295
286 input_inject_event(handle, EV_REP, REP_PERIOD, rep->period); 296 rep[1].delay = dev->rep[REP_DELAY];
287 d = dev->rep[REP_DELAY]; 297 rep[1].period = dev->rep[REP_PERIOD];
288 p = dev->rep[REP_PERIOD];
289 }
290 } 298 }
291 rep->delay = d; 299
292 rep->period = p; 300 return 0;
301}
302
303int kbd_rate(struct kbd_repeat *rep)
304{
305 struct kbd_repeat data[2] = { *rep };
306
307 input_handler_for_each_handle(&kbd_handler, data, kbd_rate_helper);
308 *rep = data[1]; /* Copy currently used settings */
309
293 return 0; 310 return 0;
294} 311}
295 312
@@ -997,36 +1014,36 @@ static inline unsigned char getleds(void)
997 return leds; 1014 return leds;
998} 1015}
999 1016
1017static int kbd_update_leds_helper(struct input_handle *handle, void *data)
1018{
1019 unsigned char leds = *(unsigned char *)data;
1020
1021 if (test_bit(EV_LED, handle->dev->evbit)) {
1022 input_inject_event(handle, EV_LED, LED_SCROLLL, !!(leds & 0x01));
1023 input_inject_event(handle, EV_LED, LED_NUML, !!(leds & 0x02));
1024 input_inject_event(handle, EV_LED, LED_CAPSL, !!(leds & 0x04));
1025 input_inject_event(handle, EV_SYN, SYN_REPORT, 0);
1026 }
1027
1028 return 0;
1029}
1030
1000/* 1031/*
1001 * This routine is the bottom half of the keyboard interrupt 1032 * This is the tasklet that updates LED state on all keyboards
1002 * routine, and runs with all interrupts enabled. It does 1033 * attached to the box. The reason we use tasklet is that we
1003 * console changing, led setting and copy_to_cooked, which can 1034 * need to handle the scenario when keyboard handler is not
1004 * take a reasonably long time. 1035 * registered yet but we already getting updates form VT to
1005 * 1036 * update led state.
1006 * Aside from timing (which isn't really that important for
1007 * keyboard interrupts as they happen often), using the software
1008 * interrupt routines for this thing allows us to easily mask
1009 * this when we don't want any of the above to happen.
1010 * This allows for easy and efficient race-condition prevention
1011 * for kbd_start => input_inject_event(dev, EV_LED, ...) => ...
1012 */ 1037 */
1013
1014static void kbd_bh(unsigned long dummy) 1038static void kbd_bh(unsigned long dummy)
1015{ 1039{
1016 struct list_head *node;
1017 unsigned char leds = getleds(); 1040 unsigned char leds = getleds();
1018 1041
1019 if (leds != ledstate) { 1042 if (leds != ledstate) {
1020 list_for_each(node, &kbd_handler.h_list) { 1043 input_handler_for_each_handle(&kbd_handler, &leds,
1021 struct input_handle *handle = to_handle_h(node); 1044 kbd_update_leds_helper);
1022 input_inject_event(handle, EV_LED, LED_SCROLLL, !!(leds & 0x01)); 1045 ledstate = leds;
1023 input_inject_event(handle, EV_LED, LED_NUML, !!(leds & 0x02));
1024 input_inject_event(handle, EV_LED, LED_CAPSL, !!(leds & 0x04));
1025 input_inject_event(handle, EV_SYN, SYN_REPORT, 0);
1026 }
1027 } 1046 }
1028
1029 ledstate = leds;
1030} 1047}
1031 1048
1032DECLARE_TASKLET_DISABLED(keyboard_tasklet, kbd_bh, 0); 1049DECLARE_TASKLET_DISABLED(keyboard_tasklet, kbd_bh, 0);
@@ -1136,7 +1153,7 @@ static int emulate_raw(struct vc_data *vc, unsigned int keycode, unsigned char u
1136static void kbd_rawcode(unsigned char data) 1153static void kbd_rawcode(unsigned char data)
1137{ 1154{
1138 struct vc_data *vc = vc_cons[fg_console].d; 1155 struct vc_data *vc = vc_cons[fg_console].d;
1139 kbd = kbd_table + fg_console; 1156 kbd = kbd_table + vc->vc_num;
1140 if (kbd->kbdmode == VC_RAW) 1157 if (kbd->kbdmode == VC_RAW)
1141 put_queue(vc, data); 1158 put_queue(vc, data);
1142} 1159}
@@ -1157,7 +1174,7 @@ static void kbd_keycode(unsigned int keycode, int down, int hw_raw)
1157 tty->driver_data = vc; 1174 tty->driver_data = vc;
1158 } 1175 }
1159 1176
1160 kbd = kbd_table + fg_console; 1177 kbd = kbd_table + vc->vc_num;
1161 1178
1162 if (keycode == KEY_LEFTALT || keycode == KEY_RIGHTALT) 1179 if (keycode == KEY_LEFTALT || keycode == KEY_RIGHTALT)
1163 sysrq_alt = down ? keycode : 0; 1180 sysrq_alt = down ? keycode : 0;
@@ -1168,11 +1185,6 @@ static void kbd_keycode(unsigned int keycode, int down, int hw_raw)
1168 1185
1169 rep = (down == 2); 1186 rep = (down == 2);
1170 1187
1171#ifdef CONFIG_MAC_EMUMOUSEBTN
1172 if (mac_hid_mouse_emulate_buttons(1, keycode, down))
1173 return;
1174#endif /* CONFIG_MAC_EMUMOUSEBTN */
1175
1176 if ((raw_mode = (kbd->kbdmode == VC_RAW)) && !hw_raw) 1188 if ((raw_mode = (kbd->kbdmode == VC_RAW)) && !hw_raw)
1177 if (emulate_raw(vc, keycode, !down << 7)) 1189 if (emulate_raw(vc, keycode, !down << 7))
1178 if (keycode < BTN_MISC && printk_ratelimit()) 1190 if (keycode < BTN_MISC && printk_ratelimit())
@@ -1296,15 +1308,36 @@ static void kbd_keycode(unsigned int keycode, int down, int hw_raw)
1296static void kbd_event(struct input_handle *handle, unsigned int event_type, 1308static void kbd_event(struct input_handle *handle, unsigned int event_type,
1297 unsigned int event_code, int value) 1309 unsigned int event_code, int value)
1298{ 1310{
1311 /* We are called with interrupts disabled, just take the lock */
1312 spin_lock(&kbd_event_lock);
1313
1299 if (event_type == EV_MSC && event_code == MSC_RAW && HW_RAW(handle->dev)) 1314 if (event_type == EV_MSC && event_code == MSC_RAW && HW_RAW(handle->dev))
1300 kbd_rawcode(value); 1315 kbd_rawcode(value);
1301 if (event_type == EV_KEY) 1316 if (event_type == EV_KEY)
1302 kbd_keycode(event_code, value, HW_RAW(handle->dev)); 1317 kbd_keycode(event_code, value, HW_RAW(handle->dev));
1318
1319 spin_unlock(&kbd_event_lock);
1320
1303 tasklet_schedule(&keyboard_tasklet); 1321 tasklet_schedule(&keyboard_tasklet);
1304 do_poke_blanked_console = 1; 1322 do_poke_blanked_console = 1;
1305 schedule_console_callback(); 1323 schedule_console_callback();
1306} 1324}
1307 1325
1326static 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
1308/* 1341/*
1309 * 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
1310 * 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
@@ -1316,14 +1349,6 @@ static int kbd_connect(struct input_handler *handler, struct input_dev *dev,
1316{ 1349{
1317 struct input_handle *handle; 1350 struct input_handle *handle;
1318 int error; 1351 int error;
1319 int i;
1320
1321 for (i = KEY_RESERVED; i < BTN_MISC; i++)
1322 if (test_bit(i, dev->keybit))
1323 break;
1324
1325 if (i == BTN_MISC && !test_bit(EV_SND, dev->evbit))
1326 return -ENODEV;
1327 1352
1328 handle = kzalloc(sizeof(struct input_handle), GFP_KERNEL); 1353 handle = kzalloc(sizeof(struct input_handle), GFP_KERNEL);
1329 if (!handle) 1354 if (!handle)
@@ -1363,15 +1388,11 @@ static void kbd_disconnect(struct input_handle *handle)
1363 */ 1388 */
1364static void kbd_start(struct input_handle *handle) 1389static void kbd_start(struct input_handle *handle)
1365{ 1390{
1366 unsigned char leds = ledstate;
1367
1368 tasklet_disable(&keyboard_tasklet); 1391 tasklet_disable(&keyboard_tasklet);
1369 if (leds != 0xff) { 1392
1370 input_inject_event(handle, EV_LED, LED_SCROLLL, !!(leds & 0x01)); 1393 if (ledstate != 0xff)
1371 input_inject_event(handle, EV_LED, LED_NUML, !!(leds & 0x02)); 1394 kbd_update_leds_helper(handle, &ledstate);
1372 input_inject_event(handle, EV_LED, LED_CAPSL, !!(leds & 0x04)); 1395
1373 input_inject_event(handle, EV_SYN, SYN_REPORT, 0);
1374 }
1375 tasklet_enable(&keyboard_tasklet); 1396 tasklet_enable(&keyboard_tasklet);
1376} 1397}
1377 1398
@@ -1393,6 +1414,7 @@ MODULE_DEVICE_TABLE(input, kbd_ids);
1393 1414
1394static struct input_handler kbd_handler = { 1415static struct input_handler kbd_handler = {
1395 .event = kbd_event, 1416 .event = kbd_event,
1417 .match = kbd_match,
1396 .connect = kbd_connect, 1418 .connect = kbd_connect,
1397 .disconnect = kbd_disconnect, 1419 .disconnect = kbd_disconnect,
1398 .start = kbd_start, 1420 .start = kbd_start,
diff --git a/drivers/char/lp.c b/drivers/char/lp.c
index e444c2dba160..938a3a273886 100644
--- a/drivers/char/lp.c
+++ b/drivers/char/lp.c
@@ -127,6 +127,7 @@
127#include <linux/wait.h> 127#include <linux/wait.h>
128#include <linux/jiffies.h> 128#include <linux/jiffies.h>
129#include <linux/smp_lock.h> 129#include <linux/smp_lock.h>
130#include <linux/compat.h>
130 131
131#include <linux/parport.h> 132#include <linux/parport.h>
132#undef LP_STATS 133#undef LP_STATS
@@ -571,13 +572,11 @@ static int lp_release(struct inode * inode, struct file * file)
571 return 0; 572 return 0;
572} 573}
573 574
574static int lp_ioctl(struct inode *inode, struct file *file, 575static int lp_do_ioctl(unsigned int minor, unsigned int cmd,
575 unsigned int cmd, unsigned long arg) 576 unsigned long arg, void __user *argp)
576{ 577{
577 unsigned int minor = iminor(inode);
578 int status; 578 int status;
579 int retval = 0; 579 int retval = 0;
580 void __user *argp = (void __user *)arg;
581 580
582#ifdef LP_DEBUG 581#ifdef LP_DEBUG
583 printk(KERN_DEBUG "lp%d ioctl, cmd: 0x%x, arg: 0x%lx\n", minor, cmd, arg); 582 printk(KERN_DEBUG "lp%d ioctl, cmd: 0x%x, arg: 0x%lx\n", minor, cmd, arg);
@@ -587,9 +586,6 @@ static int lp_ioctl(struct inode *inode, struct file *file,
587 if ((LP_F(minor) & LP_EXIST) == 0) 586 if ((LP_F(minor) & LP_EXIST) == 0)
588 return -ENODEV; 587 return -ENODEV;
589 switch ( cmd ) { 588 switch ( cmd ) {
590 struct timeval par_timeout;
591 long to_jiffies;
592
593 case LPTIME: 589 case LPTIME:
594 LP_TIME(minor) = arg * HZ/100; 590 LP_TIME(minor) = arg * HZ/100;
595 break; 591 break;
@@ -652,34 +648,101 @@ static int lp_ioctl(struct inode *inode, struct file *file,
652 return -EFAULT; 648 return -EFAULT;
653 break; 649 break;
654 650
655 case LPSETTIMEOUT:
656 if (copy_from_user (&par_timeout, argp,
657 sizeof (struct timeval))) {
658 return -EFAULT;
659 }
660 /* Convert to jiffies, place in lp_table */
661 if ((par_timeout.tv_sec < 0) ||
662 (par_timeout.tv_usec < 0)) {
663 return -EINVAL;
664 }
665 to_jiffies = DIV_ROUND_UP(par_timeout.tv_usec, 1000000/HZ);
666 to_jiffies += par_timeout.tv_sec * (long) HZ;
667 if (to_jiffies <= 0) {
668 return -EINVAL;
669 }
670 lp_table[minor].timeout = to_jiffies;
671 break;
672
673 default: 651 default:
674 retval = -EINVAL; 652 retval = -EINVAL;
675 } 653 }
676 return retval; 654 return retval;
677} 655}
678 656
657static int lp_set_timeout(unsigned int minor, struct timeval *par_timeout)
658{
659 long to_jiffies;
660
661 /* Convert to jiffies, place in lp_table */
662 if ((par_timeout->tv_sec < 0) ||
663 (par_timeout->tv_usec < 0)) {
664 return -EINVAL;
665 }
666 to_jiffies = DIV_ROUND_UP(par_timeout->tv_usec, 1000000/HZ);
667 to_jiffies += par_timeout->tv_sec * (long) HZ;
668 if (to_jiffies <= 0) {
669 return -EINVAL;
670 }
671 lp_table[minor].timeout = to_jiffies;
672 return 0;
673}
674
675static long lp_ioctl(struct file *file, unsigned int cmd,
676 unsigned long arg)
677{
678 unsigned int minor;
679 struct timeval par_timeout;
680 int ret;
681
682 minor = iminor(file->f_path.dentry->d_inode);
683 lock_kernel();
684 switch (cmd) {
685 case LPSETTIMEOUT:
686 if (copy_from_user(&par_timeout, (void __user *)arg,
687 sizeof (struct timeval))) {
688 ret = -EFAULT;
689 break;
690 }
691 ret = lp_set_timeout(minor, &par_timeout);
692 break;
693 default:
694 ret = lp_do_ioctl(minor, cmd, arg, (void __user *)arg);
695 break;
696 }
697 unlock_kernel();
698
699 return ret;
700}
701
702#ifdef CONFIG_COMPAT
703static long lp_compat_ioctl(struct file *file, unsigned int cmd,
704 unsigned long arg)
705{
706 unsigned int minor;
707 struct timeval par_timeout;
708 struct compat_timeval __user *tc;
709 int ret;
710
711 minor = iminor(file->f_path.dentry->d_inode);
712 lock_kernel();
713 switch (cmd) {
714 case LPSETTIMEOUT:
715 tc = compat_ptr(arg);
716 if (get_user(par_timeout.tv_sec, &tc->tv_sec) ||
717 get_user(par_timeout.tv_usec, &tc->tv_usec)) {
718 ret = -EFAULT;
719 break;
720 }
721 ret = lp_set_timeout(minor, &par_timeout);
722 break;
723#ifdef LP_STATS
724 case LPGETSTATS:
725 /* FIXME: add an implementation if you set LP_STATS */
726 ret = -EINVAL;
727 break;
728#endif
729 default:
730 ret = lp_do_ioctl(minor, cmd, arg, compat_ptr(arg));
731 break;
732 }
733 unlock_kernel();
734
735 return ret;
736}
737#endif
738
679static const struct file_operations lp_fops = { 739static const struct file_operations lp_fops = {
680 .owner = THIS_MODULE, 740 .owner = THIS_MODULE,
681 .write = lp_write, 741 .write = lp_write,
682 .ioctl = lp_ioctl, 742 .unlocked_ioctl = lp_ioctl,
743#ifdef CONFIG_COMPAT
744 .compat_ioctl = lp_compat_ioctl,
745#endif
683 .open = lp_open, 746 .open = lp_open,
684 .release = lp_release, 747 .release = lp_release,
685#ifdef CONFIG_PARPORT_1284 748#ifdef CONFIG_PARPORT_1284
diff --git a/drivers/char/mbcs.c b/drivers/char/mbcs.c
index 87c67b42bc08..83bef4efe376 100644
--- a/drivers/char/mbcs.c
+++ b/drivers/char/mbcs.c
@@ -26,6 +26,7 @@
26#include <linux/uio.h> 26#include <linux/uio.h>
27#include <linux/mutex.h> 27#include <linux/mutex.h>
28#include <linux/smp_lock.h> 28#include <linux/smp_lock.h>
29#include <linux/slab.h>
29#include <asm/io.h> 30#include <asm/io.h>
30#include <asm/uaccess.h> 31#include <asm/uaccess.h>
31#include <asm/system.h> 32#include <asm/system.h>
diff --git a/drivers/char/mem.c b/drivers/char/mem.c
index a074fceb67d3..f54dab8acdcd 100644
--- a/drivers/char/mem.c
+++ b/drivers/char/mem.c
@@ -3,9 +3,9 @@
3 * 3 *
4 * Copyright (C) 1991, 1992 Linus Torvalds 4 * Copyright (C) 1991, 1992 Linus Torvalds
5 * 5 *
6 * Added devfs support. 6 * Added devfs support.
7 * Jan-11-1998, C. Scott Ananian <cananian@alumni.princeton.edu> 7 * Jan-11-1998, C. Scott Ananian <cananian@alumni.princeton.edu>
8 * Shared /dev/zero mmaping support, Feb 2000, Kanoj Sarcar <kanoj@sgi.com> 8 * Shared /dev/zero mmapping support, Feb 2000, Kanoj Sarcar <kanoj@sgi.com>
9 */ 9 */
10 10
11#include <linux/mm.h> 11#include <linux/mm.h>
@@ -26,7 +26,6 @@
26#include <linux/bootmem.h> 26#include <linux/bootmem.h>
27#include <linux/splice.h> 27#include <linux/splice.h>
28#include <linux/pfn.h> 28#include <linux/pfn.h>
29#include <linux/smp_lock.h>
30 29
31#include <asm/uaccess.h> 30#include <asm/uaccess.h>
32#include <asm/io.h> 31#include <asm/io.h>
@@ -35,34 +34,14 @@
35# include <linux/efi.h> 34# include <linux/efi.h>
36#endif 35#endif
37 36
38/* 37static inline unsigned long size_inside_page(unsigned long start,
39 * Architectures vary in how they handle caching for addresses 38 unsigned long size)
40 * outside of main memory.
41 *
42 */
43static inline int uncached_access(struct file *file, unsigned long addr)
44{ 39{
45#if defined(CONFIG_IA64) 40 unsigned long sz;
46 /*
47 * On ia64, we ignore O_SYNC because we cannot tolerate memory attribute aliases.
48 */
49 return !(efi_mem_attributes(addr) & EFI_MEMORY_WB);
50#elif defined(CONFIG_MIPS)
51 {
52 extern int __uncached_access(struct file *file,
53 unsigned long addr);
54 41
55 return __uncached_access(file, addr); 42 sz = PAGE_SIZE - (start & (PAGE_SIZE - 1));
56 } 43
57#else 44 return min(sz, size);
58 /*
59 * Accessing memory above the top the kernel knows about or through a file pointer
60 * that was marked O_SYNC will be done non-cached.
61 */
62 if (file->f_flags & O_SYNC)
63 return 1;
64 return addr >= __pa(high_memory);
65#endif
66} 45}
67 46
68#ifndef ARCH_HAS_VALID_PHYS_ADDR_RANGE 47#ifndef ARCH_HAS_VALID_PHYS_ADDR_RANGE
@@ -106,15 +85,15 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
106} 85}
107#endif 86#endif
108 87
109void __attribute__((weak)) unxlate_dev_mem_ptr(unsigned long phys, void *addr) 88void __weak unxlate_dev_mem_ptr(unsigned long phys, void *addr)
110{ 89{
111} 90}
112 91
113/* 92/*
114 * This funcion reads the *physical* memory. The f_pos points directly to the 93 * This funcion reads the *physical* memory. The f_pos points directly to the
115 * memory location. 94 * memory location.
116 */ 95 */
117static ssize_t read_mem(struct file * file, char __user * buf, 96static ssize_t read_mem(struct file *file, char __user *buf,
118 size_t count, loff_t *ppos) 97 size_t count, loff_t *ppos)
119{ 98{
120 unsigned long p = *ppos; 99 unsigned long p = *ppos;
@@ -127,49 +106,39 @@ static ssize_t read_mem(struct file * file, char __user * buf,
127#ifdef __ARCH_HAS_NO_PAGE_ZERO_MAPPED 106#ifdef __ARCH_HAS_NO_PAGE_ZERO_MAPPED
128 /* we don't have page 0 mapped on sparc and m68k.. */ 107 /* we don't have page 0 mapped on sparc and m68k.. */
129 if (p < PAGE_SIZE) { 108 if (p < PAGE_SIZE) {
130 sz = PAGE_SIZE - p; 109 sz = size_inside_page(p, count);
131 if (sz > count)
132 sz = count;
133 if (sz > 0) { 110 if (sz > 0) {
134 if (clear_user(buf, sz)) 111 if (clear_user(buf, sz))
135 return -EFAULT; 112 return -EFAULT;
136 buf += sz; 113 buf += sz;
137 p += sz; 114 p += sz;
138 count -= sz; 115 count -= sz;
139 read += sz; 116 read += sz;
140 } 117 }
141 } 118 }
142#endif 119#endif
143 120
144 while (count > 0) { 121 while (count > 0) {
145 /* 122 unsigned long remaining;
146 * Handle first page in case it's not aligned
147 */
148 if (-p & (PAGE_SIZE - 1))
149 sz = -p & (PAGE_SIZE - 1);
150 else
151 sz = PAGE_SIZE;
152 123
153 sz = min_t(unsigned long, sz, count); 124 sz = size_inside_page(p, count);
154 125
155 if (!range_is_allowed(p >> PAGE_SHIFT, count)) 126 if (!range_is_allowed(p >> PAGE_SHIFT, count))
156 return -EPERM; 127 return -EPERM;
157 128
158 /* 129 /*
159 * On ia64 if a page has been mapped somewhere as 130 * On ia64 if a page has been mapped somewhere as uncached, then
160 * uncached, then it must also be accessed uncached 131 * it must also be accessed uncached by the kernel or data
161 * by the kernel or data corruption may occur 132 * corruption may occur.
162 */ 133 */
163 ptr = xlate_dev_mem_ptr(p); 134 ptr = xlate_dev_mem_ptr(p);
164 if (!ptr) 135 if (!ptr)
165 return -EFAULT; 136 return -EFAULT;
166 137
167 if (copy_to_user(buf, ptr, sz)) { 138 remaining = copy_to_user(buf, ptr, sz);
168 unxlate_dev_mem_ptr(p, ptr);
169 return -EFAULT;
170 }
171
172 unxlate_dev_mem_ptr(p, ptr); 139 unxlate_dev_mem_ptr(p, ptr);
140 if (remaining)
141 return -EFAULT;
173 142
174 buf += sz; 143 buf += sz;
175 p += sz; 144 p += sz;
@@ -181,7 +150,7 @@ static ssize_t read_mem(struct file * file, char __user * buf,
181 return read; 150 return read;
182} 151}
183 152
184static ssize_t write_mem(struct file * file, const char __user * buf, 153static ssize_t write_mem(struct file *file, const char __user *buf,
185 size_t count, loff_t *ppos) 154 size_t count, loff_t *ppos)
186{ 155{
187 unsigned long p = *ppos; 156 unsigned long p = *ppos;
@@ -197,9 +166,7 @@ static ssize_t write_mem(struct file * file, const char __user * buf,
197#ifdef __ARCH_HAS_NO_PAGE_ZERO_MAPPED 166#ifdef __ARCH_HAS_NO_PAGE_ZERO_MAPPED
198 /* we don't have page 0 mapped on sparc and m68k.. */ 167 /* we don't have page 0 mapped on sparc and m68k.. */
199 if (p < PAGE_SIZE) { 168 if (p < PAGE_SIZE) {
200 unsigned long sz = PAGE_SIZE - p; 169 sz = size_inside_page(p, count);
201 if (sz > count)
202 sz = count;
203 /* Hmm. Do something? */ 170 /* Hmm. Do something? */
204 buf += sz; 171 buf += sz;
205 p += sz; 172 p += sz;
@@ -209,23 +176,15 @@ static ssize_t write_mem(struct file * file, const char __user * buf,
209#endif 176#endif
210 177
211 while (count > 0) { 178 while (count > 0) {
212 /* 179 sz = size_inside_page(p, count);
213 * Handle first page in case it's not aligned
214 */
215 if (-p & (PAGE_SIZE - 1))
216 sz = -p & (PAGE_SIZE - 1);
217 else
218 sz = PAGE_SIZE;
219
220 sz = min_t(unsigned long, sz, count);
221 180
222 if (!range_is_allowed(p >> PAGE_SHIFT, sz)) 181 if (!range_is_allowed(p >> PAGE_SHIFT, sz))
223 return -EPERM; 182 return -EPERM;
224 183
225 /* 184 /*
226 * On ia64 if a page has been mapped somewhere as 185 * On ia64 if a page has been mapped somewhere as uncached, then
227 * uncached, then it must also be accessed uncached 186 * it must also be accessed uncached by the kernel or data
228 * by the kernel or data corruption may occur 187 * corruption may occur.
229 */ 188 */
230 ptr = xlate_dev_mem_ptr(p); 189 ptr = xlate_dev_mem_ptr(p);
231 if (!ptr) { 190 if (!ptr) {
@@ -235,16 +194,14 @@ static ssize_t write_mem(struct file * file, const char __user * buf,
235 } 194 }
236 195
237 copied = copy_from_user(ptr, buf, sz); 196 copied = copy_from_user(ptr, buf, sz);
197 unxlate_dev_mem_ptr(p, ptr);
238 if (copied) { 198 if (copied) {
239 written += sz - copied; 199 written += sz - copied;
240 unxlate_dev_mem_ptr(p, ptr);
241 if (written) 200 if (written)
242 break; 201 break;
243 return -EFAULT; 202 return -EFAULT;
244 } 203 }
245 204
246 unxlate_dev_mem_ptr(p, ptr);
247
248 buf += sz; 205 buf += sz;
249 p += sz; 206 p += sz;
250 count -= sz; 207 count -= sz;
@@ -255,13 +212,48 @@ static ssize_t write_mem(struct file * file, const char __user * buf,
255 return written; 212 return written;
256} 213}
257 214
258int __attribute__((weak)) phys_mem_access_prot_allowed(struct file *file, 215int __weak phys_mem_access_prot_allowed(struct file *file,
259 unsigned long pfn, unsigned long size, pgprot_t *vma_prot) 216 unsigned long pfn, unsigned long size, pgprot_t *vma_prot)
260{ 217{
261 return 1; 218 return 1;
262} 219}
263 220
264#ifndef __HAVE_PHYS_MEM_ACCESS_PROT 221#ifndef __HAVE_PHYS_MEM_ACCESS_PROT
222
223/*
224 * Architectures vary in how they handle caching for addresses
225 * outside of main memory.
226 *
227 */
228#ifdef pgprot_noncached
229static int uncached_access(struct file *file, unsigned long addr)
230{
231#if defined(CONFIG_IA64)
232 /*
233 * On ia64, we ignore O_DSYNC because we cannot tolerate memory
234 * attribute aliases.
235 */
236 return !(efi_mem_attributes(addr) & EFI_MEMORY_WB);
237#elif defined(CONFIG_MIPS)
238 {
239 extern int __uncached_access(struct file *file,
240 unsigned long addr);
241
242 return __uncached_access(file, addr);
243 }
244#else
245 /*
246 * Accessing memory above the top the kernel knows about or through a
247 * file pointer
248 * that was marked O_DSYNC will be done non-cached.
249 */
250 if (file->f_flags & O_DSYNC)
251 return 1;
252 return addr >= __pa(high_memory);
253#endif
254}
255#endif
256
265static pgprot_t phys_mem_access_prot(struct file *file, unsigned long pfn, 257static pgprot_t phys_mem_access_prot(struct file *file, unsigned long pfn,
266 unsigned long size, pgprot_t vma_prot) 258 unsigned long size, pgprot_t vma_prot)
267{ 259{
@@ -307,7 +299,7 @@ static const struct vm_operations_struct mmap_mem_ops = {
307#endif 299#endif
308}; 300};
309 301
310static int mmap_mem(struct file * file, struct vm_area_struct * vma) 302static int mmap_mem(struct file *file, struct vm_area_struct *vma)
311{ 303{
312 size_t size = vma->vm_end - vma->vm_start; 304 size_t size = vma->vm_end - vma->vm_start;
313 305
@@ -342,7 +334,7 @@ static int mmap_mem(struct file * file, struct vm_area_struct * vma)
342} 334}
343 335
344#ifdef CONFIG_DEVKMEM 336#ifdef CONFIG_DEVKMEM
345static int mmap_kmem(struct file * file, struct vm_area_struct * vma) 337static int mmap_kmem(struct file *file, struct vm_area_struct *vma)
346{ 338{
347 unsigned long pfn; 339 unsigned long pfn;
348 340
@@ -350,9 +342,9 @@ static int mmap_kmem(struct file * file, struct vm_area_struct * vma)
350 pfn = __pa((u64)vma->vm_pgoff << PAGE_SHIFT) >> PAGE_SHIFT; 342 pfn = __pa((u64)vma->vm_pgoff << PAGE_SHIFT) >> PAGE_SHIFT;
351 343
352 /* 344 /*
353 * RED-PEN: on some architectures there is more mapped memory 345 * RED-PEN: on some architectures there is more mapped memory than
354 * than available in mem_map which pfn_valid checks 346 * available in mem_map which pfn_valid checks for. Perhaps should add a
355 * for. Perhaps should add a new macro here. 347 * new macro here.
356 * 348 *
357 * RED-PEN: vmalloc is not supported right now. 349 * RED-PEN: vmalloc is not supported right now.
358 */ 350 */
@@ -402,43 +394,35 @@ static ssize_t read_oldmem(struct file *file, char __user *buf,
402/* 394/*
403 * This function reads the *virtual* memory as seen by the kernel. 395 * This function reads the *virtual* memory as seen by the kernel.
404 */ 396 */
405static ssize_t read_kmem(struct file *file, char __user *buf, 397static ssize_t read_kmem(struct file *file, char __user *buf,
406 size_t count, loff_t *ppos) 398 size_t count, loff_t *ppos)
407{ 399{
408 unsigned long p = *ppos; 400 unsigned long p = *ppos;
409 ssize_t low_count, read, sz; 401 ssize_t low_count, read, sz;
410 char * kbuf; /* k-addr because vread() takes vmlist_lock rwlock */ 402 char * kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
403 int err = 0;
411 404
412 read = 0; 405 read = 0;
413 if (p < (unsigned long) high_memory) { 406 if (p < (unsigned long) high_memory) {
414 low_count = count; 407 low_count = count;
415 if (count > (unsigned long) high_memory - p) 408 if (count > (unsigned long)high_memory - p)
416 low_count = (unsigned long) high_memory - p; 409 low_count = (unsigned long)high_memory - p;
417 410
418#ifdef __ARCH_HAS_NO_PAGE_ZERO_MAPPED 411#ifdef __ARCH_HAS_NO_PAGE_ZERO_MAPPED
419 /* we don't have page 0 mapped on sparc and m68k.. */ 412 /* we don't have page 0 mapped on sparc and m68k.. */
420 if (p < PAGE_SIZE && low_count > 0) { 413 if (p < PAGE_SIZE && low_count > 0) {
421 size_t tmp = PAGE_SIZE - p; 414 sz = size_inside_page(p, low_count);
422 if (tmp > low_count) tmp = low_count; 415 if (clear_user(buf, sz))
423 if (clear_user(buf, tmp))
424 return -EFAULT; 416 return -EFAULT;
425 buf += tmp; 417 buf += sz;
426 p += tmp; 418 p += sz;
427 read += tmp; 419 read += sz;
428 low_count -= tmp; 420 low_count -= sz;
429 count -= tmp; 421 count -= sz;
430 } 422 }
431#endif 423#endif
432 while (low_count > 0) { 424 while (low_count > 0) {
433 /* 425 sz = size_inside_page(p, low_count);
434 * Handle first page in case it's not aligned
435 */
436 if (-p & (PAGE_SIZE - 1))
437 sz = -p & (PAGE_SIZE - 1);
438 else
439 sz = PAGE_SIZE;
440
441 sz = min_t(unsigned long, sz, low_count);
442 426
443 /* 427 /*
444 * On ia64 if a page has been mapped somewhere as 428 * On ia64 if a page has been mapped somewhere as
@@ -462,32 +446,32 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
462 if (!kbuf) 446 if (!kbuf)
463 return -ENOMEM; 447 return -ENOMEM;
464 while (count > 0) { 448 while (count > 0) {
465 int len = count; 449 sz = size_inside_page(p, count);
466 450 if (!is_vmalloc_or_module_addr((void *)p)) {
467 if (len > PAGE_SIZE) 451 err = -ENXIO;
468 len = PAGE_SIZE;
469 len = vread(kbuf, (char *)p, len);
470 if (!len)
471 break; 452 break;
472 if (copy_to_user(buf, kbuf, len)) {
473 free_page((unsigned long)kbuf);
474 return -EFAULT;
475 } 453 }
476 count -= len; 454 sz = vread(kbuf, (char *)p, sz);
477 buf += len; 455 if (!sz)
478 read += len; 456 break;
479 p += len; 457 if (copy_to_user(buf, kbuf, sz)) {
458 err = -EFAULT;
459 break;
460 }
461 count -= sz;
462 buf += sz;
463 read += sz;
464 p += sz;
480 } 465 }
481 free_page((unsigned long)kbuf); 466 free_page((unsigned long)kbuf);
482 } 467 }
483 *ppos = p; 468 *ppos = p;
484 return read; 469 return read ? read : err;
485} 470}
486 471
487 472
488static inline ssize_t 473static ssize_t do_write_kmem(unsigned long p, const char __user *buf,
489do_write_kmem(void *p, unsigned long realp, const char __user * buf, 474 size_t count, loff_t *ppos)
490 size_t count, loff_t *ppos)
491{ 475{
492 ssize_t written, sz; 476 ssize_t written, sz;
493 unsigned long copied; 477 unsigned long copied;
@@ -495,14 +479,11 @@ do_write_kmem(void *p, unsigned long realp, const char __user * buf,
495 written = 0; 479 written = 0;
496#ifdef __ARCH_HAS_NO_PAGE_ZERO_MAPPED 480#ifdef __ARCH_HAS_NO_PAGE_ZERO_MAPPED
497 /* we don't have page 0 mapped on sparc and m68k.. */ 481 /* we don't have page 0 mapped on sparc and m68k.. */
498 if (realp < PAGE_SIZE) { 482 if (p < PAGE_SIZE) {
499 unsigned long sz = PAGE_SIZE - realp; 483 sz = size_inside_page(p, count);
500 if (sz > count)
501 sz = count;
502 /* Hmm. Do something? */ 484 /* Hmm. Do something? */
503 buf += sz; 485 buf += sz;
504 p += sz; 486 p += sz;
505 realp += sz;
506 count -= sz; 487 count -= sz;
507 written += sz; 488 written += sz;
508 } 489 }
@@ -510,22 +491,15 @@ do_write_kmem(void *p, unsigned long realp, const char __user * buf,
510 491
511 while (count > 0) { 492 while (count > 0) {
512 char *ptr; 493 char *ptr;
513 /*
514 * Handle first page in case it's not aligned
515 */
516 if (-realp & (PAGE_SIZE - 1))
517 sz = -realp & (PAGE_SIZE - 1);
518 else
519 sz = PAGE_SIZE;
520 494
521 sz = min_t(unsigned long, sz, count); 495 sz = size_inside_page(p, count);
522 496
523 /* 497 /*
524 * On ia64 if a page has been mapped somewhere as 498 * On ia64 if a page has been mapped somewhere as uncached, then
525 * uncached, then it must also be accessed uncached 499 * it must also be accessed uncached by the kernel or data
526 * by the kernel or data corruption may occur 500 * corruption may occur.
527 */ 501 */
528 ptr = xlate_dev_kmem_ptr(p); 502 ptr = xlate_dev_kmem_ptr((char *)p);
529 503
530 copied = copy_from_user(ptr, buf, sz); 504 copied = copy_from_user(ptr, buf, sz);
531 if (copied) { 505 if (copied) {
@@ -536,7 +510,6 @@ do_write_kmem(void *p, unsigned long realp, const char __user * buf,
536 } 510 }
537 buf += sz; 511 buf += sz;
538 p += sz; 512 p += sz;
539 realp += sz;
540 count -= sz; 513 count -= sz;
541 written += sz; 514 written += sz;
542 } 515 }
@@ -545,29 +518,24 @@ do_write_kmem(void *p, unsigned long realp, const char __user * buf,
545 return written; 518 return written;
546} 519}
547 520
548
549/* 521/*
550 * This function writes to the *virtual* memory as seen by the kernel. 522 * This function writes to the *virtual* memory as seen by the kernel.
551 */ 523 */
552static ssize_t write_kmem(struct file * file, const char __user * buf, 524static ssize_t write_kmem(struct file *file, const char __user *buf,
553 size_t count, loff_t *ppos) 525 size_t count, loff_t *ppos)
554{ 526{
555 unsigned long p = *ppos; 527 unsigned long p = *ppos;
556 ssize_t wrote = 0; 528 ssize_t wrote = 0;
557 ssize_t virtr = 0; 529 ssize_t virtr = 0;
558 ssize_t written;
559 char * kbuf; /* k-addr because vwrite() takes vmlist_lock rwlock */ 530 char * kbuf; /* k-addr because vwrite() takes vmlist_lock rwlock */
531 int err = 0;
560 532
561 if (p < (unsigned long) high_memory) { 533 if (p < (unsigned long) high_memory) {
562 534 unsigned long to_write = min_t(unsigned long, count,
563 wrote = count; 535 (unsigned long)high_memory - p);
564 if (count > (unsigned long) high_memory - p) 536 wrote = do_write_kmem(p, buf, to_write, ppos);
565 wrote = (unsigned long) high_memory - p; 537 if (wrote != to_write)
566 538 return wrote;
567 written = do_write_kmem((void*)p, p, buf, wrote, ppos);
568 if (written != wrote)
569 return written;
570 wrote = written;
571 p += wrote; 539 p += wrote;
572 buf += wrote; 540 buf += wrote;
573 count -= wrote; 541 count -= wrote;
@@ -578,45 +546,44 @@ static ssize_t write_kmem(struct file * file, const char __user * buf,
578 if (!kbuf) 546 if (!kbuf)
579 return wrote ? wrote : -ENOMEM; 547 return wrote ? wrote : -ENOMEM;
580 while (count > 0) { 548 while (count > 0) {
581 int len = count; 549 unsigned long sz = size_inside_page(p, count);
582 550 unsigned long n;
583 if (len > PAGE_SIZE) 551
584 len = PAGE_SIZE; 552 if (!is_vmalloc_or_module_addr((void *)p)) {
585 if (len) { 553 err = -ENXIO;
586 written = copy_from_user(kbuf, buf, len); 554 break;
587 if (written) { 555 }
588 if (wrote + virtr) 556 n = copy_from_user(kbuf, buf, sz);
589 break; 557 if (n) {
590 free_page((unsigned long)kbuf); 558 err = -EFAULT;
591 return -EFAULT; 559 break;
592 }
593 } 560 }
594 len = vwrite(kbuf, (char *)p, len); 561 vwrite(kbuf, (char *)p, sz);
595 count -= len; 562 count -= sz;
596 buf += len; 563 buf += sz;
597 virtr += len; 564 virtr += sz;
598 p += len; 565 p += sz;
599 } 566 }
600 free_page((unsigned long)kbuf); 567 free_page((unsigned long)kbuf);
601 } 568 }
602 569
603 *ppos = p; 570 *ppos = p;
604 return virtr + wrote; 571 return virtr + wrote ? : err;
605} 572}
606#endif 573#endif
607 574
608#ifdef CONFIG_DEVPORT 575#ifdef CONFIG_DEVPORT
609static ssize_t read_port(struct file * file, char __user * buf, 576static ssize_t read_port(struct file *file, char __user *buf,
610 size_t count, loff_t *ppos) 577 size_t count, loff_t *ppos)
611{ 578{
612 unsigned long i = *ppos; 579 unsigned long i = *ppos;
613 char __user *tmp = buf; 580 char __user *tmp = buf;
614 581
615 if (!access_ok(VERIFY_WRITE, buf, count)) 582 if (!access_ok(VERIFY_WRITE, buf, count))
616 return -EFAULT; 583 return -EFAULT;
617 while (count-- > 0 && i < 65536) { 584 while (count-- > 0 && i < 65536) {
618 if (__put_user(inb(i),tmp) < 0) 585 if (__put_user(inb(i), tmp) < 0)
619 return -EFAULT; 586 return -EFAULT;
620 i++; 587 i++;
621 tmp++; 588 tmp++;
622 } 589 }
@@ -624,22 +591,22 @@ static ssize_t read_port(struct file * file, char __user * buf,
624 return tmp-buf; 591 return tmp-buf;
625} 592}
626 593
627static ssize_t write_port(struct file * file, const char __user * buf, 594static ssize_t write_port(struct file *file, const char __user *buf,
628 size_t count, loff_t *ppos) 595 size_t count, loff_t *ppos)
629{ 596{
630 unsigned long i = *ppos; 597 unsigned long i = *ppos;
631 const char __user * tmp = buf; 598 const char __user * tmp = buf;
632 599
633 if (!access_ok(VERIFY_READ,buf,count)) 600 if (!access_ok(VERIFY_READ, buf, count))
634 return -EFAULT; 601 return -EFAULT;
635 while (count-- > 0 && i < 65536) { 602 while (count-- > 0 && i < 65536) {
636 char c; 603 char c;
637 if (__get_user(c, tmp)) { 604 if (__get_user(c, tmp)) {
638 if (tmp > buf) 605 if (tmp > buf)
639 break; 606 break;
640 return -EFAULT; 607 return -EFAULT;
641 } 608 }
642 outb(c,i); 609 outb(c, i);
643 i++; 610 i++;
644 tmp++; 611 tmp++;
645 } 612 }
@@ -648,13 +615,13 @@ static ssize_t write_port(struct file * file, const char __user * buf,
648} 615}
649#endif 616#endif
650 617
651static ssize_t read_null(struct file * file, char __user * buf, 618static ssize_t read_null(struct file *file, char __user *buf,
652 size_t count, loff_t *ppos) 619 size_t count, loff_t *ppos)
653{ 620{
654 return 0; 621 return 0;
655} 622}
656 623
657static ssize_t write_null(struct file * file, const char __user * buf, 624static ssize_t write_null(struct file *file, const char __user *buf,
658 size_t count, loff_t *ppos) 625 size_t count, loff_t *ppos)
659{ 626{
660 return count; 627 return count;
@@ -666,13 +633,13 @@ static int pipe_to_null(struct pipe_inode_info *info, struct pipe_buffer *buf,
666 return sd->len; 633 return sd->len;
667} 634}
668 635
669static ssize_t splice_write_null(struct pipe_inode_info *pipe,struct file *out, 636static ssize_t splice_write_null(struct pipe_inode_info *pipe, struct file *out,
670 loff_t *ppos, size_t len, unsigned int flags) 637 loff_t *ppos, size_t len, unsigned int flags)
671{ 638{
672 return splice_from_pipe(pipe, out, ppos, len, flags, pipe_to_null); 639 return splice_from_pipe(pipe, out, ppos, len, flags, pipe_to_null);
673} 640}
674 641
675static ssize_t read_zero(struct file * file, char __user * buf, 642static ssize_t read_zero(struct file *file, char __user *buf,
676 size_t count, loff_t *ppos) 643 size_t count, loff_t *ppos)
677{ 644{
678 size_t written; 645 size_t written;
@@ -703,7 +670,7 @@ static ssize_t read_zero(struct file * file, char __user * buf,
703 return written ? written : -EFAULT; 670 return written ? written : -EFAULT;
704} 671}
705 672
706static int mmap_zero(struct file * file, struct vm_area_struct * vma) 673static int mmap_zero(struct file *file, struct vm_area_struct *vma)
707{ 674{
708#ifndef CONFIG_MMU 675#ifndef CONFIG_MMU
709 return -ENOSYS; 676 return -ENOSYS;
@@ -713,7 +680,7 @@ static int mmap_zero(struct file * file, struct vm_area_struct * vma)
713 return 0; 680 return 0;
714} 681}
715 682
716static ssize_t write_full(struct file * file, const char __user * buf, 683static ssize_t write_full(struct file *file, const char __user *buf,
717 size_t count, loff_t *ppos) 684 size_t count, loff_t *ppos)
718{ 685{
719 return -ENOSPC; 686 return -ENOSPC;
@@ -724,8 +691,7 @@ static ssize_t write_full(struct file * file, const char __user * buf,
724 * can fopen() both devices with "a" now. This was previously impossible. 691 * can fopen() both devices with "a" now. This was previously impossible.
725 * -- SRB. 692 * -- SRB.
726 */ 693 */
727 694static loff_t null_lseek(struct file *file, loff_t offset, int orig)
728static loff_t null_lseek(struct file * file, loff_t offset, int orig)
729{ 695{
730 return file->f_pos = 0; 696 return file->f_pos = 0;
731} 697}
@@ -738,24 +704,26 @@ static loff_t null_lseek(struct file * file, loff_t offset, int orig)
738 * also note that seeking relative to the "end of file" isn't supported: 704 * also note that seeking relative to the "end of file" isn't supported:
739 * it has no meaning, so it returns -EINVAL. 705 * it has no meaning, so it returns -EINVAL.
740 */ 706 */
741static loff_t memory_lseek(struct file * file, loff_t offset, int orig) 707static loff_t memory_lseek(struct file *file, loff_t offset, int orig)
742{ 708{
743 loff_t ret; 709 loff_t ret;
744 710
745 mutex_lock(&file->f_path.dentry->d_inode->i_mutex); 711 mutex_lock(&file->f_path.dentry->d_inode->i_mutex);
746 switch (orig) { 712 switch (orig) {
747 case 0: 713 case SEEK_CUR:
748 file->f_pos = offset; 714 offset += file->f_pos;
749 ret = file->f_pos; 715 case SEEK_SET:
750 force_successful_syscall_return(); 716 /* to avoid userland mistaking f_pos=-9 as -EBADF=-9 */
717 if ((unsigned long long)offset >= ~0xFFFULL) {
718 ret = -EOVERFLOW;
751 break; 719 break;
752 case 1: 720 }
753 file->f_pos += offset; 721 file->f_pos = offset;
754 ret = file->f_pos; 722 ret = file->f_pos;
755 force_successful_syscall_return(); 723 force_successful_syscall_return();
756 break; 724 break;
757 default: 725 default:
758 ret = -EINVAL; 726 ret = -EINVAL;
759 } 727 }
760 mutex_unlock(&file->f_path.dentry->d_inode->i_mutex); 728 mutex_unlock(&file->f_path.dentry->d_inode->i_mutex);
761 return ret; 729 return ret;
@@ -839,7 +807,7 @@ static const struct file_operations oldmem_fops = {
839}; 807};
840#endif 808#endif
841 809
842static ssize_t kmsg_write(struct file * file, const char __user * buf, 810static ssize_t kmsg_write(struct file *file, const char __user *buf,
843 size_t count, loff_t *ppos) 811 size_t count, loff_t *ppos)
844{ 812{
845 char *tmp; 813 char *tmp;
@@ -861,7 +829,7 @@ static ssize_t kmsg_write(struct file * file, const char __user * buf,
861} 829}
862 830
863static const struct file_operations kmsg_fops = { 831static const struct file_operations kmsg_fops = {
864 .write = kmsg_write, 832 .write = kmsg_write,
865}; 833};
866 834
867static const struct memdev { 835static const struct memdev {
@@ -892,33 +860,27 @@ static int memory_open(struct inode *inode, struct file *filp)
892{ 860{
893 int minor; 861 int minor;
894 const struct memdev *dev; 862 const struct memdev *dev;
895 int ret = -ENXIO;
896
897 lock_kernel();
898 863
899 minor = iminor(inode); 864 minor = iminor(inode);
900 if (minor >= ARRAY_SIZE(devlist)) 865 if (minor >= ARRAY_SIZE(devlist))
901 goto out; 866 return -ENXIO;
902 867
903 dev = &devlist[minor]; 868 dev = &devlist[minor];
904 if (!dev->fops) 869 if (!dev->fops)
905 goto out; 870 return -ENXIO;
906 871
907 filp->f_op = dev->fops; 872 filp->f_op = dev->fops;
908 if (dev->dev_info) 873 if (dev->dev_info)
909 filp->f_mapping->backing_dev_info = dev->dev_info; 874 filp->f_mapping->backing_dev_info = dev->dev_info;
910 875
911 if (dev->fops->open) 876 if (dev->fops->open)
912 ret = dev->fops->open(inode, filp); 877 return dev->fops->open(inode, filp);
913 else 878
914 ret = 0; 879 return 0;
915out:
916 unlock_kernel();
917 return ret;
918} 880}
919 881
920static const struct file_operations memory_fops = { 882static const struct file_operations memory_fops = {
921 .open = memory_open, 883 .open = memory_open,
922}; 884};
923 885
924static char *mem_devnode(struct device *dev, mode_t *mode) 886static char *mem_devnode(struct device *dev, mode_t *mode)
@@ -939,10 +901,13 @@ static int __init chr_dev_init(void)
939 if (err) 901 if (err)
940 return err; 902 return err;
941 903
942 if (register_chrdev(MEM_MAJOR,"mem",&memory_fops)) 904 if (register_chrdev(MEM_MAJOR, "mem", &memory_fops))
943 printk("unable to get major %d for memory devs\n", MEM_MAJOR); 905 printk("unable to get major %d for memory devs\n", MEM_MAJOR);
944 906
945 mem_class = class_create(THIS_MODULE, "mem"); 907 mem_class = class_create(THIS_MODULE, "mem");
908 if (IS_ERR(mem_class))
909 return PTR_ERR(mem_class);
910
946 mem_class->devnode = mem_devnode; 911 mem_class->devnode = mem_devnode;
947 for (minor = 1; minor < ARRAY_SIZE(devlist); minor++) { 912 for (minor = 1; minor < ARRAY_SIZE(devlist); minor++) {
948 if (!devlist[minor].name) 913 if (!devlist[minor].name)
diff --git a/drivers/char/misc.c b/drivers/char/misc.c
index 07fa612a58d5..92ab03d28294 100644
--- a/drivers/char/misc.c
+++ b/drivers/char/misc.c
@@ -40,7 +40,6 @@
40#include <linux/miscdevice.h> 40#include <linux/miscdevice.h>
41#include <linux/kernel.h> 41#include <linux/kernel.h>
42#include <linux/major.h> 42#include <linux/major.h>
43#include <linux/slab.h>
44#include <linux/mutex.h> 43#include <linux/mutex.h>
45#include <linux/proc_fs.h> 44#include <linux/proc_fs.h>
46#include <linux/seq_file.h> 45#include <linux/seq_file.h>
@@ -49,7 +48,7 @@
49#include <linux/device.h> 48#include <linux/device.h>
50#include <linux/tty.h> 49#include <linux/tty.h>
51#include <linux/kmod.h> 50#include <linux/kmod.h>
52#include <linux/smp_lock.h> 51#include <linux/gfp.h>
53 52
54/* 53/*
55 * Head entry for the doubly linked miscdevice list 54 * Head entry for the doubly linked miscdevice list
@@ -61,9 +60,7 @@ static DEFINE_MUTEX(misc_mtx);
61 * Assigned numbers, used for dynamic minors 60 * Assigned numbers, used for dynamic minors
62 */ 61 */
63#define DYNAMIC_MINORS 64 /* like dynamic majors */ 62#define DYNAMIC_MINORS 64 /* like dynamic majors */
64static unsigned char misc_minors[DYNAMIC_MINORS / 8]; 63static DECLARE_BITMAP(misc_minors, DYNAMIC_MINORS);
65
66extern int pmu_device_init(void);
67 64
68#ifdef CONFIG_PROC_FS 65#ifdef CONFIG_PROC_FS
69static void *misc_seq_start(struct seq_file *seq, loff_t *pos) 66static void *misc_seq_start(struct seq_file *seq, loff_t *pos)
@@ -118,8 +115,7 @@ static int misc_open(struct inode * inode, struct file * file)
118 struct miscdevice *c; 115 struct miscdevice *c;
119 int err = -ENODEV; 116 int err = -ENODEV;
120 const struct file_operations *old_fops, *new_fops = NULL; 117 const struct file_operations *old_fops, *new_fops = NULL;
121 118
122 lock_kernel();
123 mutex_lock(&misc_mtx); 119 mutex_lock(&misc_mtx);
124 120
125 list_for_each_entry(c, &misc_list, list) { 121 list_for_each_entry(c, &misc_list, list) {
@@ -157,7 +153,6 @@ static int misc_open(struct inode * inode, struct file * file)
157 fops_put(old_fops); 153 fops_put(old_fops);
158fail: 154fail:
159 mutex_unlock(&misc_mtx); 155 mutex_unlock(&misc_mtx);
160 unlock_kernel();
161 return err; 156 return err;
162} 157}
163 158
@@ -201,24 +196,23 @@ int misc_register(struct miscdevice * misc)
201 } 196 }
202 197
203 if (misc->minor == MISC_DYNAMIC_MINOR) { 198 if (misc->minor == MISC_DYNAMIC_MINOR) {
204 int i = DYNAMIC_MINORS; 199 int i = find_first_zero_bit(misc_minors, DYNAMIC_MINORS);
205 while (--i >= 0) 200 if (i >= DYNAMIC_MINORS) {
206 if ( (misc_minors[i>>3] & (1 << (i&7))) == 0)
207 break;
208 if (i<0) {
209 mutex_unlock(&misc_mtx); 201 mutex_unlock(&misc_mtx);
210 return -EBUSY; 202 return -EBUSY;
211 } 203 }
212 misc->minor = i; 204 misc->minor = DYNAMIC_MINORS - i - 1;
205 set_bit(i, misc_minors);
213 } 206 }
214 207
215 if (misc->minor < DYNAMIC_MINORS)
216 misc_minors[misc->minor >> 3] |= 1 << (misc->minor & 7);
217 dev = MKDEV(MISC_MAJOR, misc->minor); 208 dev = MKDEV(MISC_MAJOR, misc->minor);
218 209
219 misc->this_device = device_create(misc_class, misc->parent, dev, 210 misc->this_device = device_create(misc_class, misc->parent, dev,
220 misc, "%s", misc->name); 211 misc, "%s", misc->name);
221 if (IS_ERR(misc->this_device)) { 212 if (IS_ERR(misc->this_device)) {
213 int i = DYNAMIC_MINORS - misc->minor - 1;
214 if (i < DYNAMIC_MINORS && i >= 0)
215 clear_bit(i, misc_minors);
222 err = PTR_ERR(misc->this_device); 216 err = PTR_ERR(misc->this_device);
223 goto out; 217 goto out;
224 } 218 }
@@ -245,7 +239,7 @@ int misc_register(struct miscdevice * misc)
245 239
246int misc_deregister(struct miscdevice *misc) 240int misc_deregister(struct miscdevice *misc)
247{ 241{
248 int i = misc->minor; 242 int i = DYNAMIC_MINORS - misc->minor - 1;
249 243
250 if (list_empty(&misc->list)) 244 if (list_empty(&misc->list))
251 return -EINVAL; 245 return -EINVAL;
@@ -253,9 +247,8 @@ int misc_deregister(struct miscdevice *misc)
253 mutex_lock(&misc_mtx); 247 mutex_lock(&misc_mtx);
254 list_del(&misc->list); 248 list_del(&misc->list);
255 device_destroy(misc_class, MKDEV(MISC_MAJOR, misc->minor)); 249 device_destroy(misc_class, MKDEV(MISC_MAJOR, misc->minor));
256 if (i < DYNAMIC_MINORS && i>0) { 250 if (i < DYNAMIC_MINORS && i >= 0)
257 misc_minors[i>>3] &= ~(1 << (misc->minor & 7)); 251 clear_bit(i, misc_minors);
258 }
259 mutex_unlock(&misc_mtx); 252 mutex_unlock(&misc_mtx);
260 return 0; 253 return 0;
261} 254}
diff --git a/drivers/char/mmtimer.c b/drivers/char/mmtimer.c
index 918711aa56f3..ea7c99fa978f 100644
--- a/drivers/char/mmtimer.c
+++ b/drivers/char/mmtimer.c
@@ -33,6 +33,7 @@
33#include <linux/time.h> 33#include <linux/time.h>
34#include <linux/math64.h> 34#include <linux/math64.h>
35#include <linux/smp_lock.h> 35#include <linux/smp_lock.h>
36#include <linux/slab.h>
36 37
37#include <asm/uaccess.h> 38#include <asm/uaccess.h>
38#include <asm/sn/addrs.h> 39#include <asm/sn/addrs.h>
@@ -546,7 +547,7 @@ static void mmtimer_tasklet(unsigned long data)
546{ 547{
547 int nodeid = data; 548 int nodeid = data;
548 struct mmtimer_node *mn = &timers[nodeid]; 549 struct mmtimer_node *mn = &timers[nodeid];
549 struct mmtimer *x = rb_entry(mn->next, struct mmtimer, list); 550 struct mmtimer *x;
550 struct k_itimer *t; 551 struct k_itimer *t;
551 unsigned long flags; 552 unsigned long flags;
552 553
diff --git a/drivers/char/moxa.c b/drivers/char/moxa.c
index dd0083bbb64a..107b0bd58d19 100644
--- a/drivers/char/moxa.c
+++ b/drivers/char/moxa.c
@@ -34,7 +34,6 @@
34#include <linux/tty.h> 34#include <linux/tty.h>
35#include <linux/tty_flip.h> 35#include <linux/tty_flip.h>
36#include <linux/major.h> 36#include <linux/major.h>
37#include <linux/smp_lock.h>
38#include <linux/string.h> 37#include <linux/string.h>
39#include <linux/fcntl.h> 38#include <linux/fcntl.h>
40#include <linux/ptrace.h> 39#include <linux/ptrace.h>
@@ -44,6 +43,7 @@
44#include <linux/pci.h> 43#include <linux/pci.h>
45#include <linux/init.h> 44#include <linux/init.h>
46#include <linux/bitops.h> 45#include <linux/bitops.h>
46#include <linux/slab.h>
47 47
48#include <asm/system.h> 48#include <asm/system.h>
49#include <asm/io.h> 49#include <asm/io.h>
@@ -139,7 +139,7 @@ struct moxa_port {
139 int cflag; 139 int cflag;
140 unsigned long statusflags; 140 unsigned long statusflags;
141 141
142 u8 DCDState; 142 u8 DCDState; /* Protected by the port lock */
143 u8 lineCtrl; 143 u8 lineCtrl;
144 u8 lowChkFlag; 144 u8 lowChkFlag;
145}; 145};
@@ -151,10 +151,9 @@ struct mon_str {
151}; 151};
152 152
153/* statusflags */ 153/* statusflags */
154#define TXSTOPPED 0x1 154#define TXSTOPPED 1
155#define LOWWAIT 0x2 155#define LOWWAIT 2
156#define EMPTYWAIT 0x4 156#define EMPTYWAIT 3
157#define THROTTLE 0x8
158 157
159#define SERIAL_DO_RESTART 158#define SERIAL_DO_RESTART
160 159
@@ -165,24 +164,26 @@ static struct mon_str moxaLog;
165static unsigned int moxaFuncTout = HZ / 2; 164static unsigned int moxaFuncTout = HZ / 2;
166static unsigned int moxaLowWaterChk; 165static unsigned int moxaLowWaterChk;
167static DEFINE_MUTEX(moxa_openlock); 166static DEFINE_MUTEX(moxa_openlock);
168/* Variables for insmod */ 167static DEFINE_SPINLOCK(moxa_lock);
169#ifdef MODULE 168
170static unsigned long baseaddr[MAX_BOARDS]; 169static unsigned long baseaddr[MAX_BOARDS];
171static unsigned int type[MAX_BOARDS]; 170static unsigned int type[MAX_BOARDS];
172static unsigned int numports[MAX_BOARDS]; 171static unsigned int numports[MAX_BOARDS];
173#endif
174 172
175MODULE_AUTHOR("William Chen"); 173MODULE_AUTHOR("William Chen");
176MODULE_DESCRIPTION("MOXA Intellio Family Multiport Board Device Driver"); 174MODULE_DESCRIPTION("MOXA Intellio Family Multiport Board Device Driver");
177MODULE_LICENSE("GPL"); 175MODULE_LICENSE("GPL");
178#ifdef MODULE 176MODULE_FIRMWARE("c218tunx.cod");
177MODULE_FIRMWARE("cp204unx.cod");
178MODULE_FIRMWARE("c320tunx.cod");
179
179module_param_array(type, uint, NULL, 0); 180module_param_array(type, uint, NULL, 0);
180MODULE_PARM_DESC(type, "card type: C218=2, C320=4"); 181MODULE_PARM_DESC(type, "card type: C218=2, C320=4");
181module_param_array(baseaddr, ulong, NULL, 0); 182module_param_array(baseaddr, ulong, NULL, 0);
182MODULE_PARM_DESC(baseaddr, "base address"); 183MODULE_PARM_DESC(baseaddr, "base address");
183module_param_array(numports, uint, NULL, 0); 184module_param_array(numports, uint, NULL, 0);
184MODULE_PARM_DESC(numports, "numports (ignored for C218)"); 185MODULE_PARM_DESC(numports, "numports (ignored for C218)");
185#endif 186
186module_param(ttymajor, int, 0); 187module_param(ttymajor, int, 0);
187 188
188/* 189/*
@@ -194,8 +195,6 @@ static int moxa_write(struct tty_struct *, const unsigned char *, int);
194static int moxa_write_room(struct tty_struct *); 195static int moxa_write_room(struct tty_struct *);
195static void moxa_flush_buffer(struct tty_struct *); 196static void moxa_flush_buffer(struct tty_struct *);
196static int moxa_chars_in_buffer(struct tty_struct *); 197static int moxa_chars_in_buffer(struct tty_struct *);
197static void moxa_throttle(struct tty_struct *);
198static void moxa_unthrottle(struct tty_struct *);
199static void moxa_set_termios(struct tty_struct *, struct ktermios *); 198static void moxa_set_termios(struct tty_struct *, struct ktermios *);
200static void moxa_stop(struct tty_struct *); 199static void moxa_stop(struct tty_struct *);
201static void moxa_start(struct tty_struct *); 200static void moxa_start(struct tty_struct *);
@@ -205,9 +204,9 @@ static int moxa_tiocmset(struct tty_struct *tty, struct file *file,
205 unsigned int set, unsigned int clear); 204 unsigned int set, unsigned int clear);
206static void moxa_poll(unsigned long); 205static void moxa_poll(unsigned long);
207static void moxa_set_tty_param(struct tty_struct *, struct ktermios *); 206static void moxa_set_tty_param(struct tty_struct *, struct ktermios *);
208static void moxa_setup_empty_event(struct tty_struct *); 207static void moxa_shutdown(struct tty_port *);
209static void moxa_shut_down(struct tty_struct *);
210static int moxa_carrier_raised(struct tty_port *); 208static int moxa_carrier_raised(struct tty_port *);
209static void moxa_dtr_rts(struct tty_port *, int);
211/* 210/*
212 * moxa board interface functions: 211 * moxa board interface functions:
213 */ 212 */
@@ -234,6 +233,8 @@ static void MoxaSetFifo(struct moxa_port *port, int enable);
234 * I/O functions 233 * I/O functions
235 */ 234 */
236 235
236static DEFINE_SPINLOCK(moxafunc_lock);
237
237static void moxa_wait_finish(void __iomem *ofsAddr) 238static void moxa_wait_finish(void __iomem *ofsAddr)
238{ 239{
239 unsigned long end = jiffies + moxaFuncTout; 240 unsigned long end = jiffies + moxaFuncTout;
@@ -247,9 +248,25 @@ static void moxa_wait_finish(void __iomem *ofsAddr)
247 248
248static void moxafunc(void __iomem *ofsAddr, u16 cmd, u16 arg) 249static void moxafunc(void __iomem *ofsAddr, u16 cmd, u16 arg)
249{ 250{
251 unsigned long flags;
252 spin_lock_irqsave(&moxafunc_lock, flags);
250 writew(arg, ofsAddr + FuncArg); 253 writew(arg, ofsAddr + FuncArg);
251 writew(cmd, ofsAddr + FuncCode); 254 writew(cmd, ofsAddr + FuncCode);
252 moxa_wait_finish(ofsAddr); 255 moxa_wait_finish(ofsAddr);
256 spin_unlock_irqrestore(&moxafunc_lock, flags);
257}
258
259static int moxafuncret(void __iomem *ofsAddr, u16 cmd, u16 arg)
260{
261 unsigned long flags;
262 u16 ret;
263 spin_lock_irqsave(&moxafunc_lock, flags);
264 writew(arg, ofsAddr + FuncArg);
265 writew(cmd, ofsAddr + FuncCode);
266 moxa_wait_finish(ofsAddr);
267 ret = readw(ofsAddr + FuncArg);
268 spin_unlock_irqrestore(&moxafunc_lock, flags);
269 return ret;
253} 270}
254 271
255static void moxa_low_water_check(void __iomem *ofsAddr) 272static void moxa_low_water_check(void __iomem *ofsAddr)
@@ -299,22 +316,20 @@ static int moxa_ioctl(struct tty_struct *tty, struct file *file,
299 struct moxa_port *p; 316 struct moxa_port *p;
300 unsigned int i, j; 317 unsigned int i, j;
301 318
302 mutex_lock(&moxa_openlock);
303 for (i = 0; i < MAX_BOARDS; i++) { 319 for (i = 0; i < MAX_BOARDS; i++) {
304 p = moxa_boards[i].ports; 320 p = moxa_boards[i].ports;
305 for (j = 0; j < MAX_PORTS_PER_BOARD; j++, p++, argm++) { 321 for (j = 0; j < MAX_PORTS_PER_BOARD; j++, p++, argm++) {
306 memset(&tmp, 0, sizeof(tmp)); 322 memset(&tmp, 0, sizeof(tmp));
323 spin_lock_bh(&moxa_lock);
307 if (moxa_boards[i].ready) { 324 if (moxa_boards[i].ready) {
308 tmp.inq = MoxaPortRxQueue(p); 325 tmp.inq = MoxaPortRxQueue(p);
309 tmp.outq = MoxaPortTxQueue(p); 326 tmp.outq = MoxaPortTxQueue(p);
310 } 327 }
311 if (copy_to_user(argm, &tmp, sizeof(tmp))) { 328 spin_unlock_bh(&moxa_lock);
312 mutex_unlock(&moxa_openlock); 329 if (copy_to_user(argm, &tmp, sizeof(tmp)))
313 return -EFAULT; 330 return -EFAULT;
314 }
315 } 331 }
316 } 332 }
317 mutex_unlock(&moxa_openlock);
318 break; 333 break;
319 } case MOXA_GET_OQUEUE: 334 } case MOXA_GET_OQUEUE:
320 status = MoxaPortTxQueue(ch); 335 status = MoxaPortTxQueue(ch);
@@ -330,16 +345,20 @@ static int moxa_ioctl(struct tty_struct *tty, struct file *file,
330 struct moxa_port *p; 345 struct moxa_port *p;
331 unsigned int i, j; 346 unsigned int i, j;
332 347
333 mutex_lock(&moxa_openlock);
334 for (i = 0; i < MAX_BOARDS; i++) { 348 for (i = 0; i < MAX_BOARDS; i++) {
335 p = moxa_boards[i].ports; 349 p = moxa_boards[i].ports;
336 for (j = 0; j < MAX_PORTS_PER_BOARD; j++, p++, argm++) { 350 for (j = 0; j < MAX_PORTS_PER_BOARD; j++, p++, argm++) {
337 struct tty_struct *ttyp; 351 struct tty_struct *ttyp;
338 memset(&tmp, 0, sizeof(tmp)); 352 memset(&tmp, 0, sizeof(tmp));
339 if (!moxa_boards[i].ready) 353 spin_lock_bh(&moxa_lock);
354 if (!moxa_boards[i].ready) {
355 spin_unlock_bh(&moxa_lock);
340 goto copy; 356 goto copy;
357 }
341 358
342 status = MoxaPortLineStatus(p); 359 status = MoxaPortLineStatus(p);
360 spin_unlock_bh(&moxa_lock);
361
343 if (status & 1) 362 if (status & 1)
344 tmp.cts = 1; 363 tmp.cts = 1;
345 if (status & 2) 364 if (status & 2)
@@ -354,24 +373,21 @@ static int moxa_ioctl(struct tty_struct *tty, struct file *file,
354 tmp.cflag = ttyp->termios->c_cflag; 373 tmp.cflag = ttyp->termios->c_cflag;
355 tty_kref_put(tty); 374 tty_kref_put(tty);
356copy: 375copy:
357 if (copy_to_user(argm, &tmp, sizeof(tmp))) { 376 if (copy_to_user(argm, &tmp, sizeof(tmp)))
358 mutex_unlock(&moxa_openlock);
359 return -EFAULT; 377 return -EFAULT;
360 }
361 } 378 }
362 } 379 }
363 mutex_unlock(&moxa_openlock);
364 break; 380 break;
365 } 381 }
366 case TIOCGSERIAL: 382 case TIOCGSERIAL:
367 mutex_lock(&moxa_openlock); 383 mutex_lock(&ch->port.mutex);
368 ret = moxa_get_serial_info(ch, argp); 384 ret = moxa_get_serial_info(ch, argp);
369 mutex_unlock(&moxa_openlock); 385 mutex_unlock(&ch->port.mutex);
370 break; 386 break;
371 case TIOCSSERIAL: 387 case TIOCSSERIAL:
372 mutex_lock(&moxa_openlock); 388 mutex_lock(&ch->port.mutex);
373 ret = moxa_set_serial_info(ch, argp); 389 ret = moxa_set_serial_info(ch, argp);
374 mutex_unlock(&moxa_openlock); 390 mutex_unlock(&ch->port.mutex);
375 break; 391 break;
376 default: 392 default:
377 ret = -ENOIOCTLCMD; 393 ret = -ENOIOCTLCMD;
@@ -396,8 +412,6 @@ static const struct tty_operations moxa_ops = {
396 .flush_buffer = moxa_flush_buffer, 412 .flush_buffer = moxa_flush_buffer,
397 .chars_in_buffer = moxa_chars_in_buffer, 413 .chars_in_buffer = moxa_chars_in_buffer,
398 .ioctl = moxa_ioctl, 414 .ioctl = moxa_ioctl,
399 .throttle = moxa_throttle,
400 .unthrottle = moxa_unthrottle,
401 .set_termios = moxa_set_termios, 415 .set_termios = moxa_set_termios,
402 .stop = moxa_stop, 416 .stop = moxa_stop,
403 .start = moxa_start, 417 .start = moxa_start,
@@ -409,11 +423,12 @@ static const struct tty_operations moxa_ops = {
409 423
410static const struct tty_port_operations moxa_port_ops = { 424static const struct tty_port_operations moxa_port_ops = {
411 .carrier_raised = moxa_carrier_raised, 425 .carrier_raised = moxa_carrier_raised,
426 .dtr_rts = moxa_dtr_rts,
427 .shutdown = moxa_shutdown,
412}; 428};
413 429
414static struct tty_driver *moxaDriver; 430static struct tty_driver *moxaDriver;
415static DEFINE_TIMER(moxaTimer, moxa_poll, 0, 0); 431static DEFINE_TIMER(moxaTimer, moxa_poll, 0, 0);
416static DEFINE_SPINLOCK(moxa_lock);
417 432
418/* 433/*
419 * HW init 434 * HW init
@@ -1011,6 +1026,8 @@ static int __init moxa_init(void)
1011{ 1026{
1012 unsigned int isabrds = 0; 1027 unsigned int isabrds = 0;
1013 int retval = 0; 1028 int retval = 0;
1029 struct moxa_board_conf *brd = moxa_boards;
1030 unsigned int i;
1014 1031
1015 printk(KERN_INFO "MOXA Intellio family driver version %s\n", 1032 printk(KERN_INFO "MOXA Intellio family driver version %s\n",
1016 MOXA_VERSION); 1033 MOXA_VERSION);
@@ -1038,10 +1055,7 @@ static int __init moxa_init(void)
1038 } 1055 }
1039 1056
1040 /* Find the boards defined from module args. */ 1057 /* Find the boards defined from module args. */
1041#ifdef MODULE 1058
1042 {
1043 struct moxa_board_conf *brd = moxa_boards;
1044 unsigned int i;
1045 for (i = 0; i < MAX_BOARDS; i++) { 1059 for (i = 0; i < MAX_BOARDS; i++) {
1046 if (!baseaddr[i]) 1060 if (!baseaddr[i])
1047 break; 1061 break;
@@ -1074,8 +1088,6 @@ static int __init moxa_init(void)
1074 isabrds++; 1088 isabrds++;
1075 } 1089 }
1076 } 1090 }
1077 }
1078#endif
1079 1091
1080#ifdef CONFIG_PCI 1092#ifdef CONFIG_PCI
1081 retval = pci_register_driver(&moxa_pci_driver); 1093 retval = pci_register_driver(&moxa_pci_driver);
@@ -1112,14 +1124,12 @@ static void __exit moxa_exit(void)
1112module_init(moxa_init); 1124module_init(moxa_init);
1113module_exit(moxa_exit); 1125module_exit(moxa_exit);
1114 1126
1115static void moxa_close_port(struct tty_struct *tty) 1127static void moxa_shutdown(struct tty_port *port)
1116{ 1128{
1117 struct moxa_port *ch = tty->driver_data; 1129 struct moxa_port *ch = container_of(port, struct moxa_port, port);
1118 moxa_shut_down(tty); 1130 MoxaPortDisable(ch);
1119 MoxaPortFlushData(ch, 2); 1131 MoxaPortFlushData(ch, 2);
1120 ch->port.flags &= ~ASYNC_NORMAL_ACTIVE; 1132 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
1121 tty->driver_data = NULL;
1122 tty_port_tty_set(&ch->port, NULL);
1123} 1133}
1124 1134
1125static int moxa_carrier_raised(struct tty_port *port) 1135static int moxa_carrier_raised(struct tty_port *port)
@@ -1127,45 +1137,19 @@ static int moxa_carrier_raised(struct tty_port *port)
1127 struct moxa_port *ch = container_of(port, struct moxa_port, port); 1137 struct moxa_port *ch = container_of(port, struct moxa_port, port);
1128 int dcd; 1138 int dcd;
1129 1139
1130 spin_lock_bh(&moxa_lock); 1140 spin_lock_irq(&port->lock);
1131 dcd = ch->DCDState; 1141 dcd = ch->DCDState;
1132 spin_unlock_bh(&moxa_lock); 1142 spin_unlock_irq(&port->lock);
1133 return dcd; 1143 return dcd;
1134} 1144}
1135 1145
1136static int moxa_block_till_ready(struct tty_struct *tty, struct file *filp, 1146static void moxa_dtr_rts(struct tty_port *port, int onoff)
1137 struct moxa_port *ch)
1138{ 1147{
1139 struct tty_port *port = &ch->port; 1148 struct moxa_port *ch = container_of(port, struct moxa_port, port);
1140 DEFINE_WAIT(wait); 1149 MoxaPortLineCtrl(ch, onoff, onoff);
1141 int retval = 0;
1142 u8 dcd;
1143
1144 while (1) {
1145 prepare_to_wait(&port->open_wait, &wait, TASK_INTERRUPTIBLE);
1146 if (tty_hung_up_p(filp)) {
1147#ifdef SERIAL_DO_RESTART
1148 retval = -ERESTARTSYS;
1149#else
1150 retval = -EAGAIN;
1151#endif
1152 break;
1153 }
1154 dcd = tty_port_carrier_raised(port);
1155 if (dcd)
1156 break;
1157
1158 if (signal_pending(current)) {
1159 retval = -ERESTARTSYS;
1160 break;
1161 }
1162 schedule();
1163 }
1164 finish_wait(&port->open_wait, &wait);
1165
1166 return retval;
1167} 1150}
1168 1151
1152
1169static int moxa_open(struct tty_struct *tty, struct file *filp) 1153static int moxa_open(struct tty_struct *tty, struct file *filp)
1170{ 1154{
1171 struct moxa_board_conf *brd; 1155 struct moxa_board_conf *brd;
@@ -1194,6 +1178,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
1194 ch->port.count++; 1178 ch->port.count++;
1195 tty->driver_data = ch; 1179 tty->driver_data = ch;
1196 tty_port_tty_set(&ch->port, tty); 1180 tty_port_tty_set(&ch->port, tty);
1181 mutex_lock(&ch->port.mutex);
1197 if (!(ch->port.flags & ASYNC_INITIALIZED)) { 1182 if (!(ch->port.flags & ASYNC_INITIALIZED)) {
1198 ch->statusflags = 0; 1183 ch->statusflags = 0;
1199 moxa_set_tty_param(tty, tty->termios); 1184 moxa_set_tty_param(tty, tty->termios);
@@ -1202,58 +1187,20 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
1202 MoxaSetFifo(ch, ch->type == PORT_16550A); 1187 MoxaSetFifo(ch, ch->type == PORT_16550A);
1203 ch->port.flags |= ASYNC_INITIALIZED; 1188 ch->port.flags |= ASYNC_INITIALIZED;
1204 } 1189 }
1190 mutex_unlock(&ch->port.mutex);
1205 mutex_unlock(&moxa_openlock); 1191 mutex_unlock(&moxa_openlock);
1206 1192
1207 retval = 0; 1193 retval = tty_port_block_til_ready(&ch->port, tty, filp);
1208 if (!(filp->f_flags & O_NONBLOCK) && !C_CLOCAL(tty)) 1194 if (retval == 0)
1209 retval = moxa_block_till_ready(tty, filp, ch); 1195 set_bit(ASYNCB_NORMAL_ACTIVE, &ch->port.flags);
1210 mutex_lock(&moxa_openlock);
1211 if (retval) {
1212 if (ch->port.count) /* 0 means already hung up... */
1213 if (--ch->port.count == 0)
1214 moxa_close_port(tty);
1215 } else
1216 ch->port.flags |= ASYNC_NORMAL_ACTIVE;
1217 mutex_unlock(&moxa_openlock);
1218
1219 return retval; 1196 return retval;
1220} 1197}
1221 1198
1222static void moxa_close(struct tty_struct *tty, struct file *filp) 1199static void moxa_close(struct tty_struct *tty, struct file *filp)
1223{ 1200{
1224 struct moxa_port *ch; 1201 struct moxa_port *ch = tty->driver_data;
1225 int port;
1226
1227 port = tty->index;
1228 if (port == MAX_PORTS || tty_hung_up_p(filp))
1229 return;
1230
1231 mutex_lock(&moxa_openlock);
1232 ch = tty->driver_data;
1233 if (ch == NULL)
1234 goto unlock;
1235 if (tty->count == 1 && ch->port.count != 1) {
1236 printk(KERN_WARNING "moxa_close: bad serial port count; "
1237 "tty->count is 1, ch->port.count is %d\n", ch->port.count);
1238 ch->port.count = 1;
1239 }
1240 if (--ch->port.count < 0) {
1241 printk(KERN_WARNING "moxa_close: bad serial port count, "
1242 "device=%s\n", tty->name);
1243 ch->port.count = 0;
1244 }
1245 if (ch->port.count)
1246 goto unlock;
1247
1248 ch->cflag = tty->termios->c_cflag; 1202 ch->cflag = tty->termios->c_cflag;
1249 if (ch->port.flags & ASYNC_INITIALIZED) { 1203 tty_port_close(&ch->port, tty, filp);
1250 moxa_setup_empty_event(tty);
1251 tty_wait_until_sent(tty, 30 * HZ); /* 30 seconds timeout */
1252 }
1253
1254 moxa_close_port(tty);
1255unlock:
1256 mutex_unlock(&moxa_openlock);
1257} 1204}
1258 1205
1259static int moxa_write(struct tty_struct *tty, 1206static int moxa_write(struct tty_struct *tty,
@@ -1269,7 +1216,7 @@ static int moxa_write(struct tty_struct *tty,
1269 len = MoxaPortWriteData(tty, buf, count); 1216 len = MoxaPortWriteData(tty, buf, count);
1270 spin_unlock_bh(&moxa_lock); 1217 spin_unlock_bh(&moxa_lock);
1271 1218
1272 ch->statusflags |= LOWWAIT; 1219 set_bit(LOWWAIT, &ch->statusflags);
1273 return len; 1220 return len;
1274} 1221}
1275 1222
@@ -1300,40 +1247,21 @@ static int moxa_chars_in_buffer(struct tty_struct *tty)
1300 struct moxa_port *ch = tty->driver_data; 1247 struct moxa_port *ch = tty->driver_data;
1301 int chars; 1248 int chars;
1302 1249
1303 /*
1304 * Sigh...I have to check if driver_data is NULL here, because
1305 * if an open() fails, the TTY subsystem eventually calls
1306 * tty_wait_until_sent(), which calls the driver's chars_in_buffer()
1307 * routine. And since the open() failed, we return 0 here. TDJ
1308 */
1309 if (ch == NULL)
1310 return 0;
1311 lock_kernel();
1312 chars = MoxaPortTxQueue(ch); 1250 chars = MoxaPortTxQueue(ch);
1313 if (chars) { 1251 if (chars)
1314 /* 1252 /*
1315 * Make it possible to wakeup anything waiting for output 1253 * Make it possible to wakeup anything waiting for output
1316 * in tty_ioctl.c, etc. 1254 * in tty_ioctl.c, etc.
1317 */ 1255 */
1318 if (!(ch->statusflags & EMPTYWAIT)) 1256 set_bit(EMPTYWAIT, &ch->statusflags);
1319 moxa_setup_empty_event(tty);
1320 }
1321 unlock_kernel();
1322 return chars; 1257 return chars;
1323} 1258}
1324 1259
1325static int moxa_tiocmget(struct tty_struct *tty, struct file *file) 1260static int moxa_tiocmget(struct tty_struct *tty, struct file *file)
1326{ 1261{
1327 struct moxa_port *ch; 1262 struct moxa_port *ch = tty->driver_data;
1328 int flag = 0, dtr, rts; 1263 int flag = 0, dtr, rts;
1329 1264
1330 mutex_lock(&moxa_openlock);
1331 ch = tty->driver_data;
1332 if (!ch) {
1333 mutex_unlock(&moxa_openlock);
1334 return -EINVAL;
1335 }
1336
1337 MoxaPortGetLineOut(ch, &dtr, &rts); 1265 MoxaPortGetLineOut(ch, &dtr, &rts);
1338 if (dtr) 1266 if (dtr)
1339 flag |= TIOCM_DTR; 1267 flag |= TIOCM_DTR;
@@ -1346,7 +1274,6 @@ static int moxa_tiocmget(struct tty_struct *tty, struct file *file)
1346 flag |= TIOCM_DSR; 1274 flag |= TIOCM_DSR;
1347 if (dtr & 4) 1275 if (dtr & 4)
1348 flag |= TIOCM_CD; 1276 flag |= TIOCM_CD;
1349 mutex_unlock(&moxa_openlock);
1350 return flag; 1277 return flag;
1351} 1278}
1352 1279
@@ -1379,20 +1306,6 @@ static int moxa_tiocmset(struct tty_struct *tty, struct file *file,
1379 return 0; 1306 return 0;
1380} 1307}
1381 1308
1382static void moxa_throttle(struct tty_struct *tty)
1383{
1384 struct moxa_port *ch = tty->driver_data;
1385
1386 ch->statusflags |= THROTTLE;
1387}
1388
1389static void moxa_unthrottle(struct tty_struct *tty)
1390{
1391 struct moxa_port *ch = tty->driver_data;
1392
1393 ch->statusflags &= ~THROTTLE;
1394}
1395
1396static void moxa_set_termios(struct tty_struct *tty, 1309static void moxa_set_termios(struct tty_struct *tty,
1397 struct ktermios *old_termios) 1310 struct ktermios *old_termios)
1398{ 1311{
@@ -1412,7 +1325,7 @@ static void moxa_stop(struct tty_struct *tty)
1412 if (ch == NULL) 1325 if (ch == NULL)
1413 return; 1326 return;
1414 MoxaPortTxDisable(ch); 1327 MoxaPortTxDisable(ch);
1415 ch->statusflags |= TXSTOPPED; 1328 set_bit(TXSTOPPED, &ch->statusflags);
1416} 1329}
1417 1330
1418 1331
@@ -1427,38 +1340,32 @@ static void moxa_start(struct tty_struct *tty)
1427 return; 1340 return;
1428 1341
1429 MoxaPortTxEnable(ch); 1342 MoxaPortTxEnable(ch);
1430 ch->statusflags &= ~TXSTOPPED; 1343 clear_bit(TXSTOPPED, &ch->statusflags);
1431} 1344}
1432 1345
1433static void moxa_hangup(struct tty_struct *tty) 1346static void moxa_hangup(struct tty_struct *tty)
1434{ 1347{
1435 struct moxa_port *ch; 1348 struct moxa_port *ch = tty->driver_data;
1436 1349 tty_port_hangup(&ch->port);
1437 mutex_lock(&moxa_openlock);
1438 ch = tty->driver_data;
1439 if (ch == NULL) {
1440 mutex_unlock(&moxa_openlock);
1441 return;
1442 }
1443 ch->port.count = 0;
1444 moxa_close_port(tty);
1445 mutex_unlock(&moxa_openlock);
1446
1447 wake_up_interruptible(&ch->port.open_wait);
1448} 1350}
1449 1351
1450static void moxa_new_dcdstate(struct moxa_port *p, u8 dcd) 1352static void moxa_new_dcdstate(struct moxa_port *p, u8 dcd)
1451{ 1353{
1452 struct tty_struct *tty; 1354 struct tty_struct *tty;
1355 unsigned long flags;
1453 dcd = !!dcd; 1356 dcd = !!dcd;
1454 1357
1358 spin_lock_irqsave(&p->port.lock, flags);
1455 if (dcd != p->DCDState) { 1359 if (dcd != p->DCDState) {
1360 p->DCDState = dcd;
1361 spin_unlock_irqrestore(&p->port.lock, flags);
1456 tty = tty_port_tty_get(&p->port); 1362 tty = tty_port_tty_get(&p->port);
1457 if (tty && C_CLOCAL(tty) && !dcd) 1363 if (tty && C_CLOCAL(tty) && !dcd)
1458 tty_hangup(tty); 1364 tty_hangup(tty);
1459 tty_kref_put(tty); 1365 tty_kref_put(tty);
1460 } 1366 }
1461 p->DCDState = dcd; 1367 else
1368 spin_unlock_irqrestore(&p->port.lock, flags);
1462} 1369}
1463 1370
1464static int moxa_poll_port(struct moxa_port *p, unsigned int handle, 1371static int moxa_poll_port(struct moxa_port *p, unsigned int handle,
@@ -1470,24 +1377,24 @@ static int moxa_poll_port(struct moxa_port *p, unsigned int handle,
1470 u16 intr; 1377 u16 intr;
1471 1378
1472 if (tty) { 1379 if (tty) {
1473 if ((p->statusflags & EMPTYWAIT) && 1380 if (test_bit(EMPTYWAIT, &p->statusflags) &&
1474 MoxaPortTxQueue(p) == 0) { 1381 MoxaPortTxQueue(p) == 0) {
1475 p->statusflags &= ~EMPTYWAIT; 1382 clear_bit(EMPTYWAIT, &p->statusflags);
1476 tty_wakeup(tty); 1383 tty_wakeup(tty);
1477 } 1384 }
1478 if ((p->statusflags & LOWWAIT) && !tty->stopped && 1385 if (test_bit(LOWWAIT, &p->statusflags) && !tty->stopped &&
1479 MoxaPortTxQueue(p) <= WAKEUP_CHARS) { 1386 MoxaPortTxQueue(p) <= WAKEUP_CHARS) {
1480 p->statusflags &= ~LOWWAIT; 1387 clear_bit(LOWWAIT, &p->statusflags);
1481 tty_wakeup(tty); 1388 tty_wakeup(tty);
1482 } 1389 }
1483 1390
1484 if (inited && !(p->statusflags & THROTTLE) && 1391 if (inited && !test_bit(TTY_THROTTLED, &tty->flags) &&
1485 MoxaPortRxQueue(p) > 0) { /* RX */ 1392 MoxaPortRxQueue(p) > 0) { /* RX */
1486 MoxaPortReadData(p); 1393 MoxaPortReadData(p);
1487 tty_schedule_flip(tty); 1394 tty_schedule_flip(tty);
1488 } 1395 }
1489 } else { 1396 } else {
1490 p->statusflags &= ~EMPTYWAIT; 1397 clear_bit(EMPTYWAIT, &p->statusflags);
1491 MoxaPortFlushData(p, 0); /* flush RX */ 1398 MoxaPortFlushData(p, 0); /* flush RX */
1492 } 1399 }
1493 1400
@@ -1588,35 +1495,6 @@ static void moxa_set_tty_param(struct tty_struct *tty, struct ktermios *old_term
1588 tty_encode_baud_rate(tty, baud, baud); 1495 tty_encode_baud_rate(tty, baud, baud);
1589} 1496}
1590 1497
1591static void moxa_setup_empty_event(struct tty_struct *tty)
1592{
1593 struct moxa_port *ch = tty->driver_data;
1594
1595 spin_lock_bh(&moxa_lock);
1596 ch->statusflags |= EMPTYWAIT;
1597 spin_unlock_bh(&moxa_lock);
1598}
1599
1600static void moxa_shut_down(struct tty_struct *tty)
1601{
1602 struct moxa_port *ch = tty->driver_data;
1603
1604 if (!(ch->port.flags & ASYNC_INITIALIZED))
1605 return;
1606
1607 MoxaPortDisable(ch);
1608
1609 /*
1610 * If we're a modem control device and HUPCL is on, drop RTS & DTR.
1611 */
1612 if (C_HUPCL(tty))
1613 MoxaPortLineCtrl(ch, 0, 0);
1614
1615 spin_lock_bh(&moxa_lock);
1616 ch->port.flags &= ~ASYNC_INITIALIZED;
1617 spin_unlock_bh(&moxa_lock);
1618}
1619
1620/***************************************************************************** 1498/*****************************************************************************
1621 * Driver level functions: * 1499 * Driver level functions: *
1622 *****************************************************************************/ 1500 *****************************************************************************/
@@ -1918,10 +1796,12 @@ static int MoxaPortSetTermio(struct moxa_port *port, struct ktermios *termio,
1918 baud = MoxaPortSetBaud(port, baud); 1796 baud = MoxaPortSetBaud(port, baud);
1919 1797
1920 if (termio->c_iflag & (IXON | IXOFF | IXANY)) { 1798 if (termio->c_iflag & (IXON | IXOFF | IXANY)) {
1799 spin_lock_irq(&moxafunc_lock);
1921 writeb(termio->c_cc[VSTART], ofsAddr + FuncArg); 1800 writeb(termio->c_cc[VSTART], ofsAddr + FuncArg);
1922 writeb(termio->c_cc[VSTOP], ofsAddr + FuncArg1); 1801 writeb(termio->c_cc[VSTOP], ofsAddr + FuncArg1);
1923 writeb(FC_SetXonXoff, ofsAddr + FuncCode); 1802 writeb(FC_SetXonXoff, ofsAddr + FuncCode);
1924 moxa_wait_finish(ofsAddr); 1803 moxa_wait_finish(ofsAddr);
1804 spin_unlock_irq(&moxafunc_lock);
1925 1805
1926 } 1806 }
1927 return baud; 1807 return baud;
@@ -1974,18 +1854,14 @@ static int MoxaPortLineStatus(struct moxa_port *port)
1974 int val; 1854 int val;
1975 1855
1976 ofsAddr = port->tableAddr; 1856 ofsAddr = port->tableAddr;
1977 if (MOXA_IS_320(port->board)) { 1857 if (MOXA_IS_320(port->board))
1978 moxafunc(ofsAddr, FC_LineStatus, 0); 1858 val = moxafuncret(ofsAddr, FC_LineStatus, 0);
1979 val = readw(ofsAddr + FuncArg); 1859 else
1980 } else {
1981 val = readw(ofsAddr + FlagStat) >> 4; 1860 val = readw(ofsAddr + FlagStat) >> 4;
1982 }
1983 val &= 0x0B; 1861 val &= 0x0B;
1984 if (val & 8) 1862 if (val & 8)
1985 val |= 4; 1863 val |= 4;
1986 spin_lock_bh(&moxa_lock);
1987 moxa_new_dcdstate(port, val & 8); 1864 moxa_new_dcdstate(port, val & 8);
1988 spin_unlock_bh(&moxa_lock);
1989 val &= 7; 1865 val &= 7;
1990 return val; 1866 return val;
1991} 1867}
diff --git a/drivers/char/mspec.c b/drivers/char/mspec.c
index 1997270bb6f4..ecb89d798e35 100644
--- a/drivers/char/mspec.c
+++ b/drivers/char/mspec.c
@@ -248,7 +248,7 @@ static const struct vm_operations_struct mspec_vm_ops = {
248/* 248/*
249 * mspec_mmap 249 * mspec_mmap
250 * 250 *
251 * Called when mmaping the device. Initializes the vma with a fault handler 251 * Called when mmapping the device. Initializes the vma with a fault handler
252 * and private data structure necessary to allocate, track, and free the 252 * and private data structure necessary to allocate, track, and free the
253 * underlying pages. 253 * underlying pages.
254 */ 254 */
diff --git a/drivers/char/mxser.c b/drivers/char/mxser.c
index 5e28d39b9e81..d2692d443f7b 100644
--- a/drivers/char/mxser.c
+++ b/drivers/char/mxser.c
@@ -23,7 +23,6 @@
23#include <linux/errno.h> 23#include <linux/errno.h>
24#include <linux/signal.h> 24#include <linux/signal.h>
25#include <linux/sched.h> 25#include <linux/sched.h>
26#include <linux/smp_lock.h>
27#include <linux/timer.h> 26#include <linux/timer.h>
28#include <linux/interrupt.h> 27#include <linux/interrupt.h>
29#include <linux/tty.h> 28#include <linux/tty.h>
@@ -34,12 +33,12 @@
34#include <linux/string.h> 33#include <linux/string.h>
35#include <linux/fcntl.h> 34#include <linux/fcntl.h>
36#include <linux/ptrace.h> 35#include <linux/ptrace.h>
37#include <linux/gfp.h>
38#include <linux/ioport.h> 36#include <linux/ioport.h>
39#include <linux/mm.h> 37#include <linux/mm.h>
40#include <linux/delay.h> 38#include <linux/delay.h>
41#include <linux/pci.h> 39#include <linux/pci.h>
42#include <linux/bitops.h> 40#include <linux/bitops.h>
41#include <linux/slab.h>
43 42
44#include <asm/system.h> 43#include <asm/system.h>
45#include <asm/io.h> 44#include <asm/io.h>
@@ -856,9 +855,9 @@ static void mxser_check_modem_status(struct tty_struct *tty,
856 } 855 }
857} 856}
858 857
859static int mxser_startup(struct tty_struct *tty) 858static int mxser_activate(struct tty_port *port, struct tty_struct *tty)
860{ 859{
861 struct mxser_port *info = tty->driver_data; 860 struct mxser_port *info = container_of(port, struct mxser_port, port);
862 unsigned long page; 861 unsigned long page;
863 unsigned long flags; 862 unsigned long flags;
864 863
@@ -868,22 +867,13 @@ static int mxser_startup(struct tty_struct *tty)
868 867
869 spin_lock_irqsave(&info->slock, flags); 868 spin_lock_irqsave(&info->slock, flags);
870 869
871 if (info->port.flags & ASYNC_INITIALIZED) {
872 free_page(page);
873 spin_unlock_irqrestore(&info->slock, flags);
874 return 0;
875 }
876
877 if (!info->ioaddr || !info->type) { 870 if (!info->ioaddr || !info->type) {
878 set_bit(TTY_IO_ERROR, &tty->flags); 871 set_bit(TTY_IO_ERROR, &tty->flags);
879 free_page(page); 872 free_page(page);
880 spin_unlock_irqrestore(&info->slock, flags); 873 spin_unlock_irqrestore(&info->slock, flags);
881 return 0; 874 return 0;
882 } 875 }
883 if (info->port.xmit_buf) 876 info->port.xmit_buf = (unsigned char *) page;
884 free_page(page);
885 else
886 info->port.xmit_buf = (unsigned char *) page;
887 877
888 /* 878 /*
889 * Clear the FIFO buffers and disable them 879 * Clear the FIFO buffers and disable them
@@ -905,8 +895,7 @@ static int mxser_startup(struct tty_struct *tty)
905 if (inb(info->ioaddr + UART_LSR) == 0xff) { 895 if (inb(info->ioaddr + UART_LSR) == 0xff) {
906 spin_unlock_irqrestore(&info->slock, flags); 896 spin_unlock_irqrestore(&info->slock, flags);
907 if (capable(CAP_SYS_ADMIN)) { 897 if (capable(CAP_SYS_ADMIN)) {
908 if (tty) 898 set_bit(TTY_IO_ERROR, &tty->flags);
909 set_bit(TTY_IO_ERROR, &tty->flags);
910 return 0; 899 return 0;
911 } else 900 } else
912 return -ENODEV; 901 return -ENODEV;
@@ -951,24 +940,19 @@ static int mxser_startup(struct tty_struct *tty)
951 * and set the speed of the serial port 940 * and set the speed of the serial port
952 */ 941 */
953 mxser_change_speed(tty, NULL); 942 mxser_change_speed(tty, NULL);
954 info->port.flags |= ASYNC_INITIALIZED;
955 spin_unlock_irqrestore(&info->slock, flags); 943 spin_unlock_irqrestore(&info->slock, flags);
956 944
957 return 0; 945 return 0;
958} 946}
959 947
960/* 948/*
961 * This routine will shutdown a serial port; interrupts maybe disabled, and 949 * This routine will shutdown a serial port
962 * DTR is dropped if the hangup on close termio flag is on.
963 */ 950 */
964static void mxser_shutdown(struct tty_struct *tty) 951static void mxser_shutdown_port(struct tty_port *port)
965{ 952{
966 struct mxser_port *info = tty->driver_data; 953 struct mxser_port *info = container_of(port, struct mxser_port, port);
967 unsigned long flags; 954 unsigned long flags;
968 955
969 if (!(info->port.flags & ASYNC_INITIALIZED))
970 return;
971
972 spin_lock_irqsave(&info->slock, flags); 956 spin_lock_irqsave(&info->slock, flags);
973 957
974 /* 958 /*
@@ -978,7 +962,7 @@ static void mxser_shutdown(struct tty_struct *tty)
978 wake_up_interruptible(&info->port.delta_msr_wait); 962 wake_up_interruptible(&info->port.delta_msr_wait);
979 963
980 /* 964 /*
981 * Free the IRQ, if necessary 965 * Free the xmit buffer, if necessary
982 */ 966 */
983 if (info->port.xmit_buf) { 967 if (info->port.xmit_buf) {
984 free_page((unsigned long) info->port.xmit_buf); 968 free_page((unsigned long) info->port.xmit_buf);
@@ -988,10 +972,6 @@ static void mxser_shutdown(struct tty_struct *tty)
988 info->IER = 0; 972 info->IER = 0;
989 outb(0x00, info->ioaddr + UART_IER); 973 outb(0x00, info->ioaddr + UART_IER);
990 974
991 if (tty->termios->c_cflag & HUPCL)
992 info->MCR &= ~(UART_MCR_DTR | UART_MCR_RTS);
993 outb(info->MCR, info->ioaddr + UART_MCR);
994
995 /* clear Rx/Tx FIFO's */ 975 /* clear Rx/Tx FIFO's */
996 if (info->board->chip_flag) 976 if (info->board->chip_flag)
997 outb(UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT | 977 outb(UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT |
@@ -1004,9 +984,6 @@ static void mxser_shutdown(struct tty_struct *tty)
1004 /* read data port to reset things */ 984 /* read data port to reset things */
1005 (void) inb(info->ioaddr + UART_RX); 985 (void) inb(info->ioaddr + UART_RX);
1006 986
1007 set_bit(TTY_IO_ERROR, &tty->flags);
1008
1009 info->port.flags &= ~ASYNC_INITIALIZED;
1010 987
1011 if (info->board->chip_flag) 988 if (info->board->chip_flag)
1012 SET_MOXA_MUST_NO_SOFTWARE_FLOW_CONTROL(info->ioaddr); 989 SET_MOXA_MUST_NO_SOFTWARE_FLOW_CONTROL(info->ioaddr);
@@ -1023,8 +1000,7 @@ static void mxser_shutdown(struct tty_struct *tty)
1023static int mxser_open(struct tty_struct *tty, struct file *filp) 1000static int mxser_open(struct tty_struct *tty, struct file *filp)
1024{ 1001{
1025 struct mxser_port *info; 1002 struct mxser_port *info;
1026 unsigned long flags; 1003 int line;
1027 int retval, line;
1028 1004
1029 line = tty->index; 1005 line = tty->index;
1030 if (line == MXSER_PORTS) 1006 if (line == MXSER_PORTS)
@@ -1036,22 +1012,7 @@ static int mxser_open(struct tty_struct *tty, struct file *filp)
1036 return -ENODEV; 1012 return -ENODEV;
1037 1013
1038 tty->driver_data = info; 1014 tty->driver_data = info;
1039 tty_port_tty_set(&info->port, tty); 1015 return tty_port_open(&info->port, tty, filp);
1040 /*
1041 * Start up serial port
1042 */
1043 spin_lock_irqsave(&info->port.lock, flags);
1044 info->port.count++;
1045 spin_unlock_irqrestore(&info->port.lock, flags);
1046 retval = mxser_startup(tty);
1047 if (retval)
1048 return retval;
1049
1050 retval = tty_port_block_til_ready(&info->port, tty, filp);
1051 if (retval)
1052 return retval;
1053
1054 return 0;
1055} 1016}
1056 1017
1057static void mxser_flush_buffer(struct tty_struct *tty) 1018static void mxser_flush_buffer(struct tty_struct *tty)
@@ -1075,19 +1036,11 @@ static void mxser_flush_buffer(struct tty_struct *tty)
1075} 1036}
1076 1037
1077 1038
1078static void mxser_close_port(struct tty_struct *tty, struct tty_port *port) 1039static void mxser_close_port(struct tty_port *port)
1079{ 1040{
1080 struct mxser_port *info = container_of(port, struct mxser_port, port); 1041 struct mxser_port *info = container_of(port, struct mxser_port, port);
1081 unsigned long timeout; 1042 unsigned long timeout;
1082 /* 1043 /*
1083 * Save the termios structure, since this port may have
1084 * separate termios for callout and dialin.
1085 *
1086 * FIXME: Can this go ?
1087 */
1088 if (port->flags & ASYNC_NORMAL_ACTIVE)
1089 info->normal_termios = *tty->termios;
1090 /*
1091 * At this point we stop accepting input. To do this, we 1044 * At this point we stop accepting input. To do this, we
1092 * disable the receive line status interrupts, and tell the 1045 * disable the receive line status interrupts, and tell the
1093 * interrupt driver to stop checking the data ready bit in the 1046 * interrupt driver to stop checking the data ready bit in the
@@ -1097,22 +1050,18 @@ static void mxser_close_port(struct tty_struct *tty, struct tty_port *port)
1097 if (info->board->chip_flag) 1050 if (info->board->chip_flag)
1098 info->IER &= ~MOXA_MUST_RECV_ISR; 1051 info->IER &= ~MOXA_MUST_RECV_ISR;
1099 1052
1100 if (port->flags & ASYNC_INITIALIZED) { 1053 outb(info->IER, info->ioaddr + UART_IER);
1101 outb(info->IER, info->ioaddr + UART_IER); 1054 /*
1102 /* 1055 * Before we drop DTR, make sure the UART transmitter
1103 * Before we drop DTR, make sure the UART transmitter 1056 * has completely drained; this is especially
1104 * has completely drained; this is especially 1057 * important if there is a transmit FIFO!
1105 * important if there is a transmit FIFO! 1058 */
1106 */ 1059 timeout = jiffies + HZ;
1107 timeout = jiffies + HZ; 1060 while (!(inb(info->ioaddr + UART_LSR) & UART_LSR_TEMT)) {
1108 while (!(inb(info->ioaddr + UART_LSR) & UART_LSR_TEMT)) { 1061 schedule_timeout_interruptible(5);
1109 schedule_timeout_interruptible(5); 1062 if (time_after(jiffies, timeout))
1110 if (time_after(jiffies, timeout)) 1063 break;
1111 break;
1112 }
1113 } 1064 }
1114 mxser_shutdown(tty);
1115
1116} 1065}
1117 1066
1118/* 1067/*
@@ -1126,12 +1075,16 @@ static void mxser_close(struct tty_struct *tty, struct file *filp)
1126 struct mxser_port *info = tty->driver_data; 1075 struct mxser_port *info = tty->driver_data;
1127 struct tty_port *port = &info->port; 1076 struct tty_port *port = &info->port;
1128 1077
1129 if (tty->index == MXSER_PORTS) 1078 if (tty->index == MXSER_PORTS || info == NULL)
1130 return; 1079 return;
1131 if (tty_port_close_start(port, tty, filp) == 0) 1080 if (tty_port_close_start(port, tty, filp) == 0)
1132 return; 1081 return;
1133 mxser_close_port(tty, port); 1082 mutex_lock(&port->mutex);
1083 mxser_close_port(port);
1134 mxser_flush_buffer(tty); 1084 mxser_flush_buffer(tty);
1085 mxser_shutdown_port(port);
1086 clear_bit(ASYNCB_INITIALIZED, &port->flags);
1087 mutex_unlock(&port->mutex);
1135 /* Right now the tty_port set is done outside of the close_end helper 1088 /* Right now the tty_port set is done outside of the close_end helper
1136 as we don't yet have everyone using refcounts */ 1089 as we don't yet have everyone using refcounts */
1137 tty_port_close_end(port, tty); 1090 tty_port_close_end(port, tty);
@@ -1275,6 +1228,7 @@ static int mxser_set_serial_info(struct tty_struct *tty,
1275 struct serial_struct __user *new_info) 1228 struct serial_struct __user *new_info)
1276{ 1229{
1277 struct mxser_port *info = tty->driver_data; 1230 struct mxser_port *info = tty->driver_data;
1231 struct tty_port *port = &info->port;
1278 struct serial_struct new_serial; 1232 struct serial_struct new_serial;
1279 speed_t baud; 1233 speed_t baud;
1280 unsigned long sl_flags; 1234 unsigned long sl_flags;
@@ -1290,7 +1244,7 @@ static int mxser_set_serial_info(struct tty_struct *tty,
1290 new_serial.port != info->ioaddr) 1244 new_serial.port != info->ioaddr)
1291 return -EINVAL; 1245 return -EINVAL;
1292 1246
1293 flags = info->port.flags & ASYNC_SPD_MASK; 1247 flags = port->flags & ASYNC_SPD_MASK;
1294 1248
1295 if (!capable(CAP_SYS_ADMIN)) { 1249 if (!capable(CAP_SYS_ADMIN)) {
1296 if ((new_serial.baud_base != info->baud_base) || 1250 if ((new_serial.baud_base != info->baud_base) ||
@@ -1304,16 +1258,17 @@ static int mxser_set_serial_info(struct tty_struct *tty,
1304 * OK, past this point, all the error checking has been done. 1258 * OK, past this point, all the error checking has been done.
1305 * At this point, we start making changes..... 1259 * At this point, we start making changes.....
1306 */ 1260 */
1307 info->port.flags = ((info->port.flags & ~ASYNC_FLAGS) | 1261 port->flags = ((port->flags & ~ASYNC_FLAGS) |
1308 (new_serial.flags & ASYNC_FLAGS)); 1262 (new_serial.flags & ASYNC_FLAGS));
1309 info->port.close_delay = new_serial.close_delay * HZ / 100; 1263 port->close_delay = new_serial.close_delay * HZ / 100;
1310 info->port.closing_wait = new_serial.closing_wait * HZ / 100; 1264 port->closing_wait = new_serial.closing_wait * HZ / 100;
1311 tty->low_latency = (info->port.flags & ASYNC_LOW_LATENCY) 1265 tty->low_latency = (port->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
1312 ? 1 : 0; 1266 if ((port->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST &&
1313 if ((info->port.flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST &&
1314 (new_serial.baud_base != info->baud_base || 1267 (new_serial.baud_base != info->baud_base ||
1315 new_serial.custom_divisor != 1268 new_serial.custom_divisor !=
1316 info->custom_divisor)) { 1269 info->custom_divisor)) {
1270 if (new_serial.custom_divisor == 0)
1271 return -EINVAL;
1317 baud = new_serial.baud_base / new_serial.custom_divisor; 1272 baud = new_serial.baud_base / new_serial.custom_divisor;
1318 tty_encode_baud_rate(tty, baud, baud); 1273 tty_encode_baud_rate(tty, baud, baud);
1319 } 1274 }
@@ -1323,15 +1278,17 @@ static int mxser_set_serial_info(struct tty_struct *tty,
1323 1278
1324 process_txrx_fifo(info); 1279 process_txrx_fifo(info);
1325 1280
1326 if (info->port.flags & ASYNC_INITIALIZED) { 1281 if (test_bit(ASYNCB_INITIALIZED, &port->flags)) {
1327 if (flags != (info->port.flags & ASYNC_SPD_MASK)) { 1282 if (flags != (port->flags & ASYNC_SPD_MASK)) {
1328 spin_lock_irqsave(&info->slock, sl_flags); 1283 spin_lock_irqsave(&info->slock, sl_flags);
1329 mxser_change_speed(tty, NULL); 1284 mxser_change_speed(tty, NULL);
1330 spin_unlock_irqrestore(&info->slock, sl_flags); 1285 spin_unlock_irqrestore(&info->slock, sl_flags);
1331 } 1286 }
1332 } else 1287 } else {
1333 retval = mxser_startup(tty); 1288 retval = mxser_activate(port, tty);
1334 1289 if (retval == 0)
1290 set_bit(ASYNCB_INITIALIZED, &port->flags);
1291 }
1335 return retval; 1292 return retval;
1336} 1293}
1337 1294
@@ -1520,7 +1477,8 @@ static int __init mxser_read_register(int port, unsigned short *regs)
1520 1477
1521static int mxser_ioctl_special(unsigned int cmd, void __user *argp) 1478static int mxser_ioctl_special(unsigned int cmd, void __user *argp)
1522{ 1479{
1523 struct mxser_port *port; 1480 struct mxser_port *ip;
1481 struct tty_port *port;
1524 struct tty_struct *tty; 1482 struct tty_struct *tty;
1525 int result, status; 1483 int result, status;
1526 unsigned int i, j; 1484 unsigned int i, j;
@@ -1536,38 +1494,39 @@ static int mxser_ioctl_special(unsigned int cmd, void __user *argp)
1536 1494
1537 case MOXA_CHKPORTENABLE: 1495 case MOXA_CHKPORTENABLE:
1538 result = 0; 1496 result = 0;
1539 lock_kernel();
1540 for (i = 0; i < MXSER_BOARDS; i++) 1497 for (i = 0; i < MXSER_BOARDS; i++)
1541 for (j = 0; j < MXSER_PORTS_PER_BOARD; j++) 1498 for (j = 0; j < MXSER_PORTS_PER_BOARD; j++)
1542 if (mxser_boards[i].ports[j].ioaddr) 1499 if (mxser_boards[i].ports[j].ioaddr)
1543 result |= (1 << i); 1500 result |= (1 << i);
1544 unlock_kernel();
1545 return put_user(result, (unsigned long __user *)argp); 1501 return put_user(result, (unsigned long __user *)argp);
1546 case MOXA_GETDATACOUNT: 1502 case MOXA_GETDATACOUNT:
1547 lock_kernel(); 1503 /* The receive side is locked by port->slock but it isn't
1504 clear that an exact snapshot is worth copying here */
1548 if (copy_to_user(argp, &mxvar_log, sizeof(mxvar_log))) 1505 if (copy_to_user(argp, &mxvar_log, sizeof(mxvar_log)))
1549 ret = -EFAULT; 1506 ret = -EFAULT;
1550 unlock_kernel();
1551 return ret; 1507 return ret;
1552 case MOXA_GETMSTATUS: { 1508 case MOXA_GETMSTATUS: {
1553 struct mxser_mstatus ms, __user *msu = argp; 1509 struct mxser_mstatus ms, __user *msu = argp;
1554 lock_kernel();
1555 for (i = 0; i < MXSER_BOARDS; i++) 1510 for (i = 0; i < MXSER_BOARDS; i++)
1556 for (j = 0; j < MXSER_PORTS_PER_BOARD; j++) { 1511 for (j = 0; j < MXSER_PORTS_PER_BOARD; j++) {
1557 port = &mxser_boards[i].ports[j]; 1512 ip = &mxser_boards[i].ports[j];
1513 port = &ip->port;
1558 memset(&ms, 0, sizeof(ms)); 1514 memset(&ms, 0, sizeof(ms));
1559 1515
1560 if (!port->ioaddr) 1516 mutex_lock(&port->mutex);
1517 if (!ip->ioaddr)
1561 goto copy; 1518 goto copy;
1562 1519
1563 tty = tty_port_tty_get(&port->port); 1520 tty = tty_port_tty_get(port);
1564 1521
1565 if (!tty || !tty->termios) 1522 if (!tty || !tty->termios)
1566 ms.cflag = port->normal_termios.c_cflag; 1523 ms.cflag = ip->normal_termios.c_cflag;
1567 else 1524 else
1568 ms.cflag = tty->termios->c_cflag; 1525 ms.cflag = tty->termios->c_cflag;
1569 tty_kref_put(tty); 1526 tty_kref_put(tty);
1570 status = inb(port->ioaddr + UART_MSR); 1527 spin_lock_irq(&ip->slock);
1528 status = inb(ip->ioaddr + UART_MSR);
1529 spin_unlock_irq(&ip->slock);
1571 if (status & UART_MSR_DCD) 1530 if (status & UART_MSR_DCD)
1572 ms.dcd = 1; 1531 ms.dcd = 1;
1573 if (status & UART_MSR_DSR) 1532 if (status & UART_MSR_DSR)
@@ -1575,13 +1534,11 @@ static int mxser_ioctl_special(unsigned int cmd, void __user *argp)
1575 if (status & UART_MSR_CTS) 1534 if (status & UART_MSR_CTS)
1576 ms.cts = 1; 1535 ms.cts = 1;
1577 copy: 1536 copy:
1578 if (copy_to_user(msu, &ms, sizeof(ms))) { 1537 mutex_unlock(&port->mutex);
1579 unlock_kernel(); 1538 if (copy_to_user(msu, &ms, sizeof(ms)))
1580 return -EFAULT; 1539 return -EFAULT;
1581 }
1582 msu++; 1540 msu++;
1583 } 1541 }
1584 unlock_kernel();
1585 return 0; 1542 return 0;
1586 } 1543 }
1587 case MOXA_ASPP_MON_EXT: { 1544 case MOXA_ASPP_MON_EXT: {
@@ -1593,41 +1550,48 @@ static int mxser_ioctl_special(unsigned int cmd, void __user *argp)
1593 if (!me) 1550 if (!me)
1594 return -ENOMEM; 1551 return -ENOMEM;
1595 1552
1596 lock_kernel();
1597 for (i = 0, p = 0; i < MXSER_BOARDS; i++) { 1553 for (i = 0, p = 0; i < MXSER_BOARDS; i++) {
1598 for (j = 0; j < MXSER_PORTS_PER_BOARD; j++, p++) { 1554 for (j = 0; j < MXSER_PORTS_PER_BOARD; j++, p++) {
1599 if (p >= ARRAY_SIZE(me->rx_cnt)) { 1555 if (p >= ARRAY_SIZE(me->rx_cnt)) {
1600 i = MXSER_BOARDS; 1556 i = MXSER_BOARDS;
1601 break; 1557 break;
1602 } 1558 }
1603 port = &mxser_boards[i].ports[j]; 1559 ip = &mxser_boards[i].ports[j];
1604 if (!port->ioaddr) 1560 port = &ip->port;
1561
1562 mutex_lock(&port->mutex);
1563 if (!ip->ioaddr) {
1564 mutex_unlock(&port->mutex);
1605 continue; 1565 continue;
1566 }
1606 1567
1607 status = mxser_get_msr(port->ioaddr, 0, p); 1568 spin_lock_irq(&ip->slock);
1569 status = mxser_get_msr(ip->ioaddr, 0, p);
1608 1570
1609 if (status & UART_MSR_TERI) 1571 if (status & UART_MSR_TERI)
1610 port->icount.rng++; 1572 ip->icount.rng++;
1611 if (status & UART_MSR_DDSR) 1573 if (status & UART_MSR_DDSR)
1612 port->icount.dsr++; 1574 ip->icount.dsr++;
1613 if (status & UART_MSR_DDCD) 1575 if (status & UART_MSR_DDCD)
1614 port->icount.dcd++; 1576 ip->icount.dcd++;
1615 if (status & UART_MSR_DCTS) 1577 if (status & UART_MSR_DCTS)
1616 port->icount.cts++; 1578 ip->icount.cts++;
1617 1579
1618 port->mon_data.modem_status = status; 1580 ip->mon_data.modem_status = status;
1619 me->rx_cnt[p] = port->mon_data.rxcnt; 1581 me->rx_cnt[p] = ip->mon_data.rxcnt;
1620 me->tx_cnt[p] = port->mon_data.txcnt; 1582 me->tx_cnt[p] = ip->mon_data.txcnt;
1621 me->up_rxcnt[p] = port->mon_data.up_rxcnt; 1583 me->up_rxcnt[p] = ip->mon_data.up_rxcnt;
1622 me->up_txcnt[p] = port->mon_data.up_txcnt; 1584 me->up_txcnt[p] = ip->mon_data.up_txcnt;
1623 me->modem_status[p] = 1585 me->modem_status[p] =
1624 port->mon_data.modem_status; 1586 ip->mon_data.modem_status;
1625 tty = tty_port_tty_get(&port->port); 1587 spin_unlock_irq(&ip->slock);
1588
1589 tty = tty_port_tty_get(&ip->port);
1626 1590
1627 if (!tty || !tty->termios) { 1591 if (!tty || !tty->termios) {
1628 cflag = port->normal_termios.c_cflag; 1592 cflag = ip->normal_termios.c_cflag;
1629 iflag = port->normal_termios.c_iflag; 1593 iflag = ip->normal_termios.c_iflag;
1630 me->baudrate[p] = tty_termios_baud_rate(&port->normal_termios); 1594 me->baudrate[p] = tty_termios_baud_rate(&ip->normal_termios);
1631 } else { 1595 } else {
1632 cflag = tty->termios->c_cflag; 1596 cflag = tty->termios->c_cflag;
1633 iflag = tty->termios->c_iflag; 1597 iflag = tty->termios->c_iflag;
@@ -1646,16 +1610,15 @@ static int mxser_ioctl_special(unsigned int cmd, void __user *argp)
1646 if (iflag & (IXON | IXOFF)) 1610 if (iflag & (IXON | IXOFF))
1647 me->flowctrl[p] |= 0x0C; 1611 me->flowctrl[p] |= 0x0C;
1648 1612
1649 if (port->type == PORT_16550A) 1613 if (ip->type == PORT_16550A)
1650 me->fifo[p] = 1; 1614 me->fifo[p] = 1;
1651 1615
1652 opmode = inb(port->opmode_ioaddr) >> 1616 opmode = inb(ip->opmode_ioaddr)>>((p % 4) * 2);
1653 ((p % 4) * 2);
1654 opmode &= OP_MODE_MASK; 1617 opmode &= OP_MODE_MASK;
1655 me->iftype[p] = opmode; 1618 me->iftype[p] = opmode;
1619 mutex_unlock(&port->mutex);
1656 } 1620 }
1657 } 1621 }
1658 unlock_kernel();
1659 if (copy_to_user(argp, me, sizeof(*me))) 1622 if (copy_to_user(argp, me, sizeof(*me)))
1660 ret = -EFAULT; 1623 ret = -EFAULT;
1661 kfree(me); 1624 kfree(me);
@@ -1692,6 +1655,7 @@ static int mxser_ioctl(struct tty_struct *tty, struct file *file,
1692 unsigned int cmd, unsigned long arg) 1655 unsigned int cmd, unsigned long arg)
1693{ 1656{
1694 struct mxser_port *info = tty->driver_data; 1657 struct mxser_port *info = tty->driver_data;
1658 struct tty_port *port = &info->port;
1695 struct async_icount cnow; 1659 struct async_icount cnow;
1696 unsigned long flags; 1660 unsigned long flags;
1697 void __user *argp = (void __user *)arg; 1661 void __user *argp = (void __user *)arg;
@@ -1716,20 +1680,20 @@ static int mxser_ioctl(struct tty_struct *tty, struct file *file,
1716 opmode != RS422_MODE && 1680 opmode != RS422_MODE &&
1717 opmode != RS485_4WIRE_MODE) 1681 opmode != RS485_4WIRE_MODE)
1718 return -EFAULT; 1682 return -EFAULT;
1719 lock_kernel();
1720 mask = ModeMask[p]; 1683 mask = ModeMask[p];
1721 shiftbit = p * 2; 1684 shiftbit = p * 2;
1685 spin_lock_irq(&info->slock);
1722 val = inb(info->opmode_ioaddr); 1686 val = inb(info->opmode_ioaddr);
1723 val &= mask; 1687 val &= mask;
1724 val |= (opmode << shiftbit); 1688 val |= (opmode << shiftbit);
1725 outb(val, info->opmode_ioaddr); 1689 outb(val, info->opmode_ioaddr);
1726 unlock_kernel(); 1690 spin_unlock_irq(&info->slock);
1727 } else { 1691 } else {
1728 lock_kernel();
1729 shiftbit = p * 2; 1692 shiftbit = p * 2;
1693 spin_lock_irq(&info->slock);
1730 opmode = inb(info->opmode_ioaddr) >> shiftbit; 1694 opmode = inb(info->opmode_ioaddr) >> shiftbit;
1695 spin_unlock_irq(&info->slock);
1731 opmode &= OP_MODE_MASK; 1696 opmode &= OP_MODE_MASK;
1732 unlock_kernel();
1733 if (put_user(opmode, (int __user *)argp)) 1697 if (put_user(opmode, (int __user *)argp))
1734 return -EFAULT; 1698 return -EFAULT;
1735 } 1699 }
@@ -1742,14 +1706,14 @@ static int mxser_ioctl(struct tty_struct *tty, struct file *file,
1742 1706
1743 switch (cmd) { 1707 switch (cmd) {
1744 case TIOCGSERIAL: 1708 case TIOCGSERIAL:
1745 lock_kernel(); 1709 mutex_lock(&port->mutex);
1746 retval = mxser_get_serial_info(tty, argp); 1710 retval = mxser_get_serial_info(tty, argp);
1747 unlock_kernel(); 1711 mutex_unlock(&port->mutex);
1748 return retval; 1712 return retval;
1749 case TIOCSSERIAL: 1713 case TIOCSSERIAL:
1750 lock_kernel(); 1714 mutex_lock(&port->mutex);
1751 retval = mxser_set_serial_info(tty, argp); 1715 retval = mxser_set_serial_info(tty, argp);
1752 unlock_kernel(); 1716 mutex_unlock(&port->mutex);
1753 return retval; 1717 return retval;
1754 case TIOCSERGETLSR: /* Get line status register */ 1718 case TIOCSERGETLSR: /* Get line status register */
1755 return mxser_get_lsr_info(info, argp); 1719 return mxser_get_lsr_info(info, argp);
@@ -1795,31 +1759,33 @@ static int mxser_ioctl(struct tty_struct *tty, struct file *file,
1795 case MOXA_HighSpeedOn: 1759 case MOXA_HighSpeedOn:
1796 return put_user(info->baud_base != 115200 ? 1 : 0, (int __user *)argp); 1760 return put_user(info->baud_base != 115200 ? 1 : 0, (int __user *)argp);
1797 case MOXA_SDS_RSTICOUNTER: 1761 case MOXA_SDS_RSTICOUNTER:
1798 lock_kernel(); 1762 spin_lock_irq(&info->slock);
1799 info->mon_data.rxcnt = 0; 1763 info->mon_data.rxcnt = 0;
1800 info->mon_data.txcnt = 0; 1764 info->mon_data.txcnt = 0;
1801 unlock_kernel(); 1765 spin_unlock_irq(&info->slock);
1802 return 0; 1766 return 0;
1803 1767
1804 case MOXA_ASPP_OQUEUE:{ 1768 case MOXA_ASPP_OQUEUE:{
1805 int len, lsr; 1769 int len, lsr;
1806 1770
1807 lock_kernel();
1808 len = mxser_chars_in_buffer(tty); 1771 len = mxser_chars_in_buffer(tty);
1772 spin_lock_irq(&info->slock);
1809 lsr = inb(info->ioaddr + UART_LSR) & UART_LSR_THRE; 1773 lsr = inb(info->ioaddr + UART_LSR) & UART_LSR_THRE;
1774 spin_unlock_irq(&info->slock);
1810 len += (lsr ? 0 : 1); 1775 len += (lsr ? 0 : 1);
1811 unlock_kernel();
1812 1776
1813 return put_user(len, (int __user *)argp); 1777 return put_user(len, (int __user *)argp);
1814 } 1778 }
1815 case MOXA_ASPP_MON: { 1779 case MOXA_ASPP_MON: {
1816 int mcr, status; 1780 int mcr, status;
1817 1781
1818 lock_kernel(); 1782 spin_lock_irq(&info->slock);
1819 status = mxser_get_msr(info->ioaddr, 1, tty->index); 1783 status = mxser_get_msr(info->ioaddr, 1, tty->index);
1820 mxser_check_modem_status(tty, info, status); 1784 mxser_check_modem_status(tty, info, status);
1821 1785
1822 mcr = inb(info->ioaddr + UART_MCR); 1786 mcr = inb(info->ioaddr + UART_MCR);
1787 spin_unlock_irq(&info->slock);
1788
1823 if (mcr & MOXA_MUST_MCR_XON_FLAG) 1789 if (mcr & MOXA_MUST_MCR_XON_FLAG)
1824 info->mon_data.hold_reason &= ~NPPI_NOTIFY_XOFFHOLD; 1790 info->mon_data.hold_reason &= ~NPPI_NOTIFY_XOFFHOLD;
1825 else 1791 else
@@ -1834,7 +1800,7 @@ static int mxser_ioctl(struct tty_struct *tty, struct file *file,
1834 info->mon_data.hold_reason |= NPPI_NOTIFY_CTSHOLD; 1800 info->mon_data.hold_reason |= NPPI_NOTIFY_CTSHOLD;
1835 else 1801 else
1836 info->mon_data.hold_reason &= ~NPPI_NOTIFY_CTSHOLD; 1802 info->mon_data.hold_reason &= ~NPPI_NOTIFY_CTSHOLD;
1837 unlock_kernel(); 1803
1838 if (copy_to_user(argp, &info->mon_data, 1804 if (copy_to_user(argp, &info->mon_data,
1839 sizeof(struct mxser_mon))) 1805 sizeof(struct mxser_mon)))
1840 return -EFAULT; 1806 return -EFAULT;
@@ -1993,6 +1959,7 @@ static void mxser_wait_until_sent(struct tty_struct *tty, int timeout)
1993{ 1959{
1994 struct mxser_port *info = tty->driver_data; 1960 struct mxser_port *info = tty->driver_data;
1995 unsigned long orig_jiffies, char_time; 1961 unsigned long orig_jiffies, char_time;
1962 unsigned long flags;
1996 int lsr; 1963 int lsr;
1997 1964
1998 if (info->type == PORT_UNKNOWN) 1965 if (info->type == PORT_UNKNOWN)
@@ -2032,19 +1999,21 @@ static void mxser_wait_until_sent(struct tty_struct *tty, int timeout)
2032 timeout, char_time); 1999 timeout, char_time);
2033 printk("jiff=%lu...", jiffies); 2000 printk("jiff=%lu...", jiffies);
2034#endif 2001#endif
2035 lock_kernel(); 2002 spin_lock_irqsave(&info->slock, flags);
2036 while (!((lsr = inb(info->ioaddr + UART_LSR)) & UART_LSR_TEMT)) { 2003 while (!((lsr = inb(info->ioaddr + UART_LSR)) & UART_LSR_TEMT)) {
2037#ifdef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT 2004#ifdef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT
2038 printk("lsr = %d (jiff=%lu)...", lsr, jiffies); 2005 printk("lsr = %d (jiff=%lu)...", lsr, jiffies);
2039#endif 2006#endif
2007 spin_unlock_irqrestore(&info->slock, flags);
2040 schedule_timeout_interruptible(char_time); 2008 schedule_timeout_interruptible(char_time);
2009 spin_lock_irqsave(&info->slock, flags);
2041 if (signal_pending(current)) 2010 if (signal_pending(current))
2042 break; 2011 break;
2043 if (timeout && time_after(jiffies, orig_jiffies + timeout)) 2012 if (timeout && time_after(jiffies, orig_jiffies + timeout))
2044 break; 2013 break;
2045 } 2014 }
2015 spin_unlock_irqrestore(&info->slock, flags);
2046 set_current_state(TASK_RUNNING); 2016 set_current_state(TASK_RUNNING);
2047 unlock_kernel();
2048 2017
2049#ifdef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT 2018#ifdef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT
2050 printk("lsr = %d (jiff=%lu)...done\n", lsr, jiffies); 2019 printk("lsr = %d (jiff=%lu)...done\n", lsr, jiffies);
@@ -2059,7 +2028,6 @@ static void mxser_hangup(struct tty_struct *tty)
2059 struct mxser_port *info = tty->driver_data; 2028 struct mxser_port *info = tty->driver_data;
2060 2029
2061 mxser_flush_buffer(tty); 2030 mxser_flush_buffer(tty);
2062 mxser_shutdown(tty);
2063 tty_port_hangup(&info->port); 2031 tty_port_hangup(&info->port);
2064} 2032}
2065 2033
@@ -2363,6 +2331,8 @@ static const struct tty_operations mxser_ops = {
2363struct tty_port_operations mxser_port_ops = { 2331struct tty_port_operations mxser_port_ops = {
2364 .carrier_raised = mxser_carrier_raised, 2332 .carrier_raised = mxser_carrier_raised,
2365 .dtr_rts = mxser_dtr_rts, 2333 .dtr_rts = mxser_dtr_rts,
2334 .activate = mxser_activate,
2335 .shutdown = mxser_shutdown_port,
2366}; 2336};
2367 2337
2368/* 2338/*
diff --git a/drivers/char/n_r3964.c b/drivers/char/n_r3964.c
index 6934025a1ac1..c1d8b54c816d 100644
--- a/drivers/char/n_r3964.c
+++ b/drivers/char/n_r3964.c
@@ -602,7 +602,7 @@ static void receive_char(struct r3964_info *pInfo, const unsigned char c)
602 } 602 }
603 break; 603 break;
604 case R3964_WAIT_FOR_RX_REPEAT: 604 case R3964_WAIT_FOR_RX_REPEAT:
605 /* FALLTROUGH */ 605 /* FALLTHROUGH */
606 case R3964_IDLE: 606 case R3964_IDLE:
607 if (c == STX) { 607 if (c == STX) {
608 /* Prevent rx_queue from overflow: */ 608 /* Prevent rx_queue from overflow: */
diff --git a/drivers/char/n_tty.c b/drivers/char/n_tty.c
index 2e50f4dfc79c..bdae8327143c 100644
--- a/drivers/char/n_tty.c
+++ b/drivers/char/n_tty.c
@@ -48,6 +48,7 @@
48#include <linux/audit.h> 48#include <linux/audit.h>
49#include <linux/file.h> 49#include <linux/file.h>
50#include <linux/uaccess.h> 50#include <linux/uaccess.h>
51#include <linux/module.h>
51 52
52#include <asm/system.h> 53#include <asm/system.h>
53 54
@@ -2091,3 +2092,19 @@ struct tty_ldisc_ops tty_ldisc_N_TTY = {
2091 .receive_buf = n_tty_receive_buf, 2092 .receive_buf = n_tty_receive_buf,
2092 .write_wakeup = n_tty_write_wakeup 2093 .write_wakeup = n_tty_write_wakeup
2093}; 2094};
2095
2096/**
2097 * n_tty_inherit_ops - inherit N_TTY methods
2098 * @ops: struct tty_ldisc_ops where to save N_TTY methods
2099 *
2100 * Used by a generic struct tty_ldisc_ops to easily inherit N_TTY
2101 * methods.
2102 */
2103
2104void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
2105{
2106 *ops = tty_ldisc_N_TTY;
2107 ops->owner = NULL;
2108 ops->refcount = ops->flags = 0;
2109}
2110EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
diff --git a/drivers/char/nozomi.c b/drivers/char/nozomi.c
index d3400b20444f..a6638003f530 100644
--- a/drivers/char/nozomi.c
+++ b/drivers/char/nozomi.c
@@ -55,6 +55,7 @@
55#include <linux/init.h> 55#include <linux/init.h>
56#include <linux/kfifo.h> 56#include <linux/kfifo.h>
57#include <linux/uaccess.h> 57#include <linux/uaccess.h>
58#include <linux/slab.h>
58#include <asm/byteorder.h> 59#include <asm/byteorder.h>
59 60
60#include <linux/delay.h> 61#include <linux/delay.h>
@@ -136,10 +137,6 @@ static int debug;
136#define RECEIVE_BUF_MAX 4 137#define RECEIVE_BUF_MAX 4
137 138
138 139
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 */ 140#define R_IIR 0x0000 /* Interrupt Identity Register */
144#define R_FCR 0x0000 /* Flow Control Register */ 141#define R_FCR 0x0000 /* Flow Control Register */
145#define R_IER 0x0004 /* Interrupt Enable Register */ 142#define R_IER 0x0004 /* Interrupt Enable Register */
@@ -358,7 +355,7 @@ struct port {
358 u8 update_flow_control; 355 u8 update_flow_control;
359 struct ctrl_ul ctrl_ul; 356 struct ctrl_ul ctrl_ul;
360 struct ctrl_dl ctrl_dl; 357 struct ctrl_dl ctrl_dl;
361 struct kfifo *fifo_ul; 358 struct kfifo fifo_ul;
362 void __iomem *dl_addr[2]; 359 void __iomem *dl_addr[2];
363 u32 dl_size[2]; 360 u32 dl_size[2];
364 u8 toggle_dl; 361 u8 toggle_dl;
@@ -371,6 +368,8 @@ struct port {
371 struct mutex tty_sem; 368 struct mutex tty_sem;
372 wait_queue_head_t tty_wait; 369 wait_queue_head_t tty_wait;
373 struct async_icount tty_icount; 370 struct async_icount tty_icount;
371
372 struct nozomi *dc;
374}; 373};
375 374
376/* Private data one for each card in the system */ 375/* Private data one for each card in the system */
@@ -405,7 +404,7 @@ struct buffer {
405 404
406/* Global variables */ 405/* Global variables */
407static const struct pci_device_id nozomi_pci_tbl[] __devinitconst = { 406static const struct pci_device_id nozomi_pci_tbl[] __devinitconst = {
408 {PCI_DEVICE(VENDOR1, DEVICE1)}, 407 {PCI_DEVICE(0x1931, 0x000c)}, /* Nozomi HSDPA */
409 {}, 408 {},
410}; 409};
411 410
@@ -414,6 +413,8 @@ MODULE_DEVICE_TABLE(pci, nozomi_pci_tbl);
414static struct nozomi *ndevs[NOZOMI_MAX_CARDS]; 413static struct nozomi *ndevs[NOZOMI_MAX_CARDS];
415static struct tty_driver *ntty_driver; 414static struct tty_driver *ntty_driver;
416 415
416static const struct tty_port_operations noz_tty_port_ops;
417
417/* 418/*
418 * find card by tty_index 419 * find card by tty_index
419 */ 420 */
@@ -685,8 +686,6 @@ static int nozomi_read_config_table(struct nozomi *dc)
685 dump_table(dc); 686 dump_table(dc);
686 687
687 for (i = PORT_MDM; i < MAX_PORT; i++) { 688 for (i = PORT_MDM; i < MAX_PORT; i++) {
688 dc->port[i].fifo_ul =
689 kfifo_alloc(FIFO_BUFFER_SIZE_UL, GFP_ATOMIC, NULL);
690 memset(&dc->port[i].ctrl_dl, 0, sizeof(struct ctrl_dl)); 689 memset(&dc->port[i].ctrl_dl, 0, sizeof(struct ctrl_dl));
691 memset(&dc->port[i].ctrl_ul, 0, sizeof(struct ctrl_ul)); 690 memset(&dc->port[i].ctrl_ul, 0, sizeof(struct ctrl_ul));
692 } 691 }
@@ -798,7 +797,7 @@ static int send_data(enum port_type index, struct nozomi *dc)
798 struct tty_struct *tty = tty_port_tty_get(&port->port); 797 struct tty_struct *tty = tty_port_tty_get(&port->port);
799 798
800 /* Get data from tty and place in buf for now */ 799 /* Get data from tty and place in buf for now */
801 size = __kfifo_get(port->fifo_ul, dc->send_buf, 800 size = kfifo_out(&port->fifo_ul, dc->send_buf,
802 ul_size < SEND_BUF_MAX ? ul_size : SEND_BUF_MAX); 801 ul_size < SEND_BUF_MAX ? ul_size : SEND_BUF_MAX);
803 802
804 if (size == 0) { 803 if (size == 0) {
@@ -855,8 +854,6 @@ static int receive_data(enum port_type index, struct nozomi *dc)
855 goto put; 854 goto put;
856 } 855 }
857 856
858 tty_buffer_request_room(tty, size);
859
860 while (size > 0) { 857 while (size > 0) {
861 read_mem32((u32 *) buf, addr + offset, RECEIVE_BUF_MAX); 858 read_mem32((u32 *) buf, addr + offset, RECEIVE_BUF_MAX);
862 859
@@ -988,11 +985,11 @@ static int receive_flow_control(struct nozomi *dc)
988 985
989 } else if (old_ctrl.CTS == 0 && ctrl_dl.CTS == 1) { 986 } else if (old_ctrl.CTS == 0 && ctrl_dl.CTS == 1) {
990 987
991 if (__kfifo_len(dc->port[port].fifo_ul)) { 988 if (kfifo_len(&dc->port[port].fifo_ul)) {
992 DBG1("Enable interrupt (0x%04X) on port: %d", 989 DBG1("Enable interrupt (0x%04X) on port: %d",
993 enable_ier, port); 990 enable_ier, port);
994 DBG1("Data in buffer [%d], enable transmit! ", 991 DBG1("Data in buffer [%d], enable transmit! ",
995 __kfifo_len(dc->port[port].fifo_ul)); 992 kfifo_len(&dc->port[port].fifo_ul));
996 enable_transmit_ul(port, dc); 993 enable_transmit_ul(port, dc);
997 } else { 994 } else {
998 DBG1("No data in buffer..."); 995 DBG1("No data in buffer...");
@@ -1433,6 +1430,16 @@ static int __devinit nozomi_card_init(struct pci_dev *pdev,
1433 goto err_free_sbuf; 1430 goto err_free_sbuf;
1434 } 1431 }
1435 1432
1433 for (i = PORT_MDM; i < MAX_PORT; i++) {
1434 if (kfifo_alloc(&dc->port[i].fifo_ul,
1435 FIFO_BUFFER_SIZE_UL, GFP_ATOMIC)) {
1436 dev_err(&pdev->dev,
1437 "Could not allocate kfifo buffer\n");
1438 ret = -ENOMEM;
1439 goto err_free_kfifo;
1440 }
1441 }
1442
1436 spin_lock_init(&dc->spin_mutex); 1443 spin_lock_init(&dc->spin_mutex);
1437 1444
1438 nozomi_setup_private_data(dc); 1445 nozomi_setup_private_data(dc);
@@ -1445,7 +1452,7 @@ static int __devinit nozomi_card_init(struct pci_dev *pdev,
1445 NOZOMI_NAME, dc); 1452 NOZOMI_NAME, dc);
1446 if (unlikely(ret)) { 1453 if (unlikely(ret)) {
1447 dev_err(&pdev->dev, "can't request irq %d\n", pdev->irq); 1454 dev_err(&pdev->dev, "can't request irq %d\n", pdev->irq);
1448 goto err_free_sbuf; 1455 goto err_free_kfifo;
1449 } 1456 }
1450 1457
1451 DBG1("base_addr: %p", dc->base_addr); 1458 DBG1("base_addr: %p", dc->base_addr);
@@ -1464,13 +1471,30 @@ static int __devinit nozomi_card_init(struct pci_dev *pdev,
1464 dc->state = NOZOMI_STATE_ENABLED; 1471 dc->state = NOZOMI_STATE_ENABLED;
1465 1472
1466 for (i = 0; i < MAX_PORT; i++) { 1473 for (i = 0; i < MAX_PORT; i++) {
1467 mutex_init(&dc->port[i].tty_sem); 1474 struct device *tty_dev;
1468 tty_port_init(&dc->port[i].port); 1475 struct port *port = &dc->port[i];
1469 tty_register_device(ntty_driver, dc->index_start + i, 1476 port->dc = dc;
1477 mutex_init(&port->tty_sem);
1478 tty_port_init(&port->port);
1479 port->port.ops = &noz_tty_port_ops;
1480 tty_dev = tty_register_device(ntty_driver, dc->index_start + i,
1470 &pdev->dev); 1481 &pdev->dev);
1482
1483 if (IS_ERR(tty_dev)) {
1484 ret = PTR_ERR(tty_dev);
1485 dev_err(&pdev->dev, "Could not allocate tty?\n");
1486 goto err_free_tty;
1487 }
1471 } 1488 }
1489
1472 return 0; 1490 return 0;
1473 1491
1492err_free_tty:
1493 for (i = dc->index_start; i < dc->index_start + MAX_PORT; ++i)
1494 tty_unregister_device(ntty_driver, i);
1495err_free_kfifo:
1496 for (i = 0; i < MAX_PORT; i++)
1497 kfifo_free(&dc->port[i].fifo_ul);
1474err_free_sbuf: 1498err_free_sbuf:
1475 kfree(dc->send_buf); 1499 kfree(dc->send_buf);
1476 iounmap(dc->base_addr); 1500 iounmap(dc->base_addr);
@@ -1536,8 +1560,7 @@ static void __devexit nozomi_card_exit(struct pci_dev *pdev)
1536 free_irq(pdev->irq, dc); 1560 free_irq(pdev->irq, dc);
1537 1561
1538 for (i = 0; i < MAX_PORT; i++) 1562 for (i = 0; i < MAX_PORT; i++)
1539 if (dc->port[i].fifo_ul) 1563 kfifo_free(&dc->port[i].fifo_ul);
1540 kfifo_free(dc->port[i].fifo_ul);
1541 1564
1542 kfree(dc->send_buf); 1565 kfree(dc->send_buf);
1543 1566
@@ -1578,67 +1601,74 @@ static void set_dtr(const struct tty_struct *tty, int dtr)
1578 * ---------------------------------------------------------------------------- 1601 * ----------------------------------------------------------------------------
1579 */ 1602 */
1580 1603
1581/* Called when the userspace process opens the tty, /dev/noz*. */ 1604static int ntty_install(struct tty_driver *driver, struct tty_struct *tty)
1582static int ntty_open(struct tty_struct *tty, struct file *file)
1583{ 1605{
1584 struct port *port = get_port_by_tty(tty); 1606 struct port *port = get_port_by_tty(tty);
1585 struct nozomi *dc = get_dc_by_tty(tty); 1607 struct nozomi *dc = get_dc_by_tty(tty);
1586 unsigned long flags; 1608 int ret;
1587
1588 if (!port || !dc || dc->state != NOZOMI_STATE_READY) 1609 if (!port || !dc || dc->state != NOZOMI_STATE_READY)
1589 return -ENODEV; 1610 return -ENODEV;
1590 1611 ret = tty_init_termios(tty);
1591 if (mutex_lock_interruptible(&port->tty_sem)) 1612 if (ret == 0) {
1592 return -ERESTARTSYS; 1613 tty_driver_kref_get(driver);
1593 1614 driver->ttys[tty->index] = tty;
1594 port->port.count++;
1595 dc->open_ttys++;
1596
1597 /* Enable interrupt downlink for channel */
1598 if (port->port.count == 1) {
1599 tty->driver_data = port;
1600 tty_port_tty_set(&port->port, tty);
1601 DBG1("open: %d", port->token_dl);
1602 spin_lock_irqsave(&dc->spin_mutex, flags);
1603 dc->last_ier = dc->last_ier | port->token_dl;
1604 writew(dc->last_ier, dc->reg_ier);
1605 spin_unlock_irqrestore(&dc->spin_mutex, flags);
1606 } 1615 }
1607 mutex_unlock(&port->tty_sem); 1616 return ret;
1608 return 0;
1609} 1617}
1610 1618
1611/* Called when the userspace process close the tty, /dev/noz*. Also 1619static void ntty_cleanup(struct tty_struct *tty)
1612 called immediately if ntty_open fails in which case tty->driver_data 1620{
1613 will be NULL an we exit by the first return */ 1621 tty->driver_data = NULL;
1622}
1614 1623
1615static void ntty_close(struct tty_struct *tty, struct file *file) 1624static int ntty_activate(struct tty_port *tport, struct tty_struct *tty)
1616{ 1625{
1617 struct nozomi *dc = get_dc_by_tty(tty); 1626 struct port *port = container_of(tport, struct port, port);
1618 struct port *nport = tty->driver_data; 1627 struct nozomi *dc = port->dc;
1619 struct tty_port *port = &nport->port;
1620 unsigned long flags; 1628 unsigned long flags;
1621 1629
1622 if (!dc || !nport) 1630 DBG1("open: %d", port->token_dl);
1623 return; 1631 spin_lock_irqsave(&dc->spin_mutex, flags);
1632 dc->last_ier = dc->last_ier | port->token_dl;
1633 writew(dc->last_ier, dc->reg_ier);
1634 dc->open_ttys++;
1635 spin_unlock_irqrestore(&dc->spin_mutex, flags);
1636 printk("noz: activated %d: %p\n", tty->index, tport);
1637 return 0;
1638}
1624 1639
1625 /* Users cannot interrupt a close */ 1640static int ntty_open(struct tty_struct *tty, struct file *filp)
1626 mutex_lock(&nport->tty_sem); 1641{
1642 struct port *port = get_port_by_tty(tty);
1643 return tty_port_open(&port->port, tty, filp);
1644}
1627 1645
1628 WARN_ON(!port->count); 1646static void ntty_shutdown(struct tty_port *tport)
1647{
1648 struct port *port = container_of(tport, struct port, port);
1649 struct nozomi *dc = port->dc;
1650 unsigned long flags;
1629 1651
1652 DBG1("close: %d", port->token_dl);
1653 spin_lock_irqsave(&dc->spin_mutex, flags);
1654 dc->last_ier &= ~(port->token_dl);
1655 writew(dc->last_ier, dc->reg_ier);
1630 dc->open_ttys--; 1656 dc->open_ttys--;
1631 port->count--; 1657 spin_unlock_irqrestore(&dc->spin_mutex, flags);
1632 tty_port_tty_set(port, NULL); 1658 printk("noz: shutdown %p\n", tport);
1659}
1633 1660
1634 if (port->count == 0) { 1661static void ntty_close(struct tty_struct *tty, struct file *filp)
1635 DBG1("close: %d", nport->token_dl); 1662{
1636 spin_lock_irqsave(&dc->spin_mutex, flags); 1663 struct port *port = tty->driver_data;
1637 dc->last_ier &= ~(nport->token_dl); 1664 if (port)
1638 writew(dc->last_ier, dc->reg_ier); 1665 tty_port_close(&port->port, tty, filp);
1639 spin_unlock_irqrestore(&dc->spin_mutex, flags); 1666}
1640 } 1667
1641 mutex_unlock(&nport->tty_sem); 1668static void ntty_hangup(struct tty_struct *tty)
1669{
1670 struct port *port = tty->driver_data;
1671 tty_port_hangup(&port->port);
1642} 1672}
1643 1673
1644/* 1674/*
@@ -1658,22 +1688,14 @@ static int ntty_write(struct tty_struct *tty, const unsigned char *buffer,
1658 if (!dc || !port) 1688 if (!dc || !port)
1659 return -ENODEV; 1689 return -ENODEV;
1660 1690
1661 if (unlikely(!mutex_trylock(&port->tty_sem))) { 1691 mutex_lock(&port->tty_sem);
1662 /*
1663 * must test lock as tty layer wraps calls
1664 * to this function with BKL
1665 */
1666 dev_err(&dc->pdev->dev, "Would have deadlocked - "
1667 "return EAGAIN\n");
1668 return -EAGAIN;
1669 }
1670 1692
1671 if (unlikely(!port->port.count)) { 1693 if (unlikely(!port->port.count)) {
1672 DBG1(" "); 1694 DBG1(" ");
1673 goto exit; 1695 goto exit;
1674 } 1696 }
1675 1697
1676 rval = __kfifo_put(port->fifo_ul, (unsigned char *)buffer, count); 1698 rval = kfifo_in(&port->fifo_ul, (unsigned char *)buffer, count);
1677 1699
1678 /* notify card */ 1700 /* notify card */
1679 if (unlikely(dc == NULL)) { 1701 if (unlikely(dc == NULL)) {
@@ -1706,25 +1728,23 @@ exit:
1706 * This method is called by the upper tty layer. 1728 * This method is called by the upper tty layer.
1707 * #according to sources N_TTY.c it expects a value >= 0 and 1729 * #according to sources N_TTY.c it expects a value >= 0 and
1708 * does not check for negative values. 1730 * does not check for negative values.
1731 *
1732 * If the port is unplugged report lots of room and let the bits
1733 * dribble away so we don't block anything.
1709 */ 1734 */
1710static int ntty_write_room(struct tty_struct *tty) 1735static int ntty_write_room(struct tty_struct *tty)
1711{ 1736{
1712 struct port *port = tty->driver_data; 1737 struct port *port = tty->driver_data;
1713 int room = 0; 1738 int room = 4096;
1714 const struct nozomi *dc = get_dc_by_tty(tty); 1739 const struct nozomi *dc = get_dc_by_tty(tty);
1715 1740
1716 if (!dc || !port) 1741 if (dc) {
1717 return 0; 1742 mutex_lock(&port->tty_sem);
1718 if (!mutex_trylock(&port->tty_sem)) 1743 if (port->port.count)
1719 return 0; 1744 room = port->fifo_ul.size -
1720 1745 kfifo_len(&port->fifo_ul);
1721 if (!port->port.count) 1746 mutex_unlock(&port->tty_sem);
1722 goto exit; 1747 }
1723
1724 room = port->fifo_ul->size - __kfifo_len(port->fifo_ul);
1725
1726exit:
1727 mutex_unlock(&port->tty_sem);
1728 return room; 1748 return room;
1729} 1749}
1730 1750
@@ -1878,16 +1898,22 @@ static s32 ntty_chars_in_buffer(struct tty_struct *tty)
1878 goto exit_in_buffer; 1898 goto exit_in_buffer;
1879 } 1899 }
1880 1900
1881 rval = __kfifo_len(port->fifo_ul); 1901 rval = kfifo_len(&port->fifo_ul);
1882 1902
1883exit_in_buffer: 1903exit_in_buffer:
1884 return rval; 1904 return rval;
1885} 1905}
1886 1906
1907static const struct tty_port_operations noz_tty_port_ops = {
1908 .activate = ntty_activate,
1909 .shutdown = ntty_shutdown,
1910};
1911
1887static const struct tty_operations tty_ops = { 1912static const struct tty_operations tty_ops = {
1888 .ioctl = ntty_ioctl, 1913 .ioctl = ntty_ioctl,
1889 .open = ntty_open, 1914 .open = ntty_open,
1890 .close = ntty_close, 1915 .close = ntty_close,
1916 .hangup = ntty_hangup,
1891 .write = ntty_write, 1917 .write = ntty_write,
1892 .write_room = ntty_write_room, 1918 .write_room = ntty_write_room,
1893 .unthrottle = ntty_unthrottle, 1919 .unthrottle = ntty_unthrottle,
@@ -1895,6 +1921,8 @@ static const struct tty_operations tty_ops = {
1895 .chars_in_buffer = ntty_chars_in_buffer, 1921 .chars_in_buffer = ntty_chars_in_buffer,
1896 .tiocmget = ntty_tiocmget, 1922 .tiocmget = ntty_tiocmget,
1897 .tiocmset = ntty_tiocmset, 1923 .tiocmset = ntty_tiocmset,
1924 .install = ntty_install,
1925 .cleanup = ntty_cleanup,
1898}; 1926};
1899 1927
1900/* Module initialization */ 1928/* Module initialization */
diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
index 88cee4099be9..47e8f7b0e4c1 100644
--- a/drivers/char/nvram.c
+++ b/drivers/char/nvram.c
@@ -38,7 +38,6 @@
38#define NVRAM_VERSION "1.3" 38#define NVRAM_VERSION "1.3"
39 39
40#include <linux/module.h> 40#include <linux/module.h>
41#include <linux/smp_lock.h>
42#include <linux/nvram.h> 41#include <linux/nvram.h>
43 42
44#define PC 1 43#define PC 1
@@ -101,7 +100,6 @@
101#include <linux/types.h> 100#include <linux/types.h>
102#include <linux/errno.h> 101#include <linux/errno.h>
103#include <linux/miscdevice.h> 102#include <linux/miscdevice.h>
104#include <linux/slab.h>
105#include <linux/ioport.h> 103#include <linux/ioport.h>
106#include <linux/fcntl.h> 104#include <linux/fcntl.h>
107#include <linux/mc146818rtc.h> 105#include <linux/mc146818rtc.h>
@@ -111,6 +109,7 @@
111#include <linux/spinlock.h> 109#include <linux/spinlock.h>
112#include <linux/io.h> 110#include <linux/io.h>
113#include <linux/uaccess.h> 111#include <linux/uaccess.h>
112#include <linux/smp_lock.h>
114 113
115#include <asm/system.h> 114#include <asm/system.h>
116 115
@@ -214,7 +213,6 @@ void nvram_set_checksum(void)
214 213
215static loff_t nvram_llseek(struct file *file, loff_t offset, int origin) 214static loff_t nvram_llseek(struct file *file, loff_t offset, int origin)
216{ 215{
217 lock_kernel();
218 switch (origin) { 216 switch (origin) {
219 case 0: 217 case 0:
220 /* nothing to do */ 218 /* nothing to do */
@@ -226,7 +224,7 @@ static loff_t nvram_llseek(struct file *file, loff_t offset, int origin)
226 offset += NVRAM_BYTES; 224 offset += NVRAM_BYTES;
227 break; 225 break;
228 } 226 }
229 unlock_kernel(); 227
230 return (offset >= 0) ? (file->f_pos = offset) : -EINVAL; 228 return (offset >= 0) ? (file->f_pos = offset) : -EINVAL;
231} 229}
232 230
@@ -265,10 +263,16 @@ static ssize_t nvram_write(struct file *file, const char __user *buf,
265 unsigned char contents[NVRAM_BYTES]; 263 unsigned char contents[NVRAM_BYTES];
266 unsigned i = *ppos; 264 unsigned i = *ppos;
267 unsigned char *tmp; 265 unsigned char *tmp;
268 int len;
269 266
270 len = (NVRAM_BYTES - i) < count ? (NVRAM_BYTES - i) : count; 267 if (i >= NVRAM_BYTES)
271 if (copy_from_user(contents, buf, len)) 268 return 0; /* Past EOF */
269
270 if (count > NVRAM_BYTES - i)
271 count = NVRAM_BYTES - i;
272 if (count > NVRAM_BYTES)
273 return -EFAULT; /* Can't happen, but prove it to gcc */
274
275 if (copy_from_user(contents, buf, count))
272 return -EFAULT; 276 return -EFAULT;
273 277
274 spin_lock_irq(&rtc_lock); 278 spin_lock_irq(&rtc_lock);
@@ -276,7 +280,7 @@ static ssize_t nvram_write(struct file *file, const char __user *buf,
276 if (!__nvram_check_checksum()) 280 if (!__nvram_check_checksum())
277 goto checksum_err; 281 goto checksum_err;
278 282
279 for (tmp = contents; count-- > 0 && i < NVRAM_BYTES; ++i, ++tmp) 283 for (tmp = contents; count--; ++i, ++tmp)
280 __nvram_write_byte(*tmp, i); 284 __nvram_write_byte(*tmp, i);
281 285
282 __nvram_set_checksum(); 286 __nvram_set_checksum();
@@ -331,14 +335,12 @@ static int nvram_ioctl(struct inode *inode, struct file *file,
331 335
332static int nvram_open(struct inode *inode, struct file *file) 336static int nvram_open(struct inode *inode, struct file *file)
333{ 337{
334 lock_kernel();
335 spin_lock(&nvram_state_lock); 338 spin_lock(&nvram_state_lock);
336 339
337 if ((nvram_open_cnt && (file->f_flags & O_EXCL)) || 340 if ((nvram_open_cnt && (file->f_flags & O_EXCL)) ||
338 (nvram_open_mode & NVRAM_EXCL) || 341 (nvram_open_mode & NVRAM_EXCL) ||
339 ((file->f_mode & FMODE_WRITE) && (nvram_open_mode & NVRAM_WRITE))) { 342 ((file->f_mode & FMODE_WRITE) && (nvram_open_mode & NVRAM_WRITE))) {
340 spin_unlock(&nvram_state_lock); 343 spin_unlock(&nvram_state_lock);
341 unlock_kernel();
342 return -EBUSY; 344 return -EBUSY;
343 } 345 }
344 346
@@ -349,7 +351,6 @@ static int nvram_open(struct inode *inode, struct file *file)
349 nvram_open_cnt++; 351 nvram_open_cnt++;
350 352
351 spin_unlock(&nvram_state_lock); 353 spin_unlock(&nvram_state_lock);
352 unlock_kernel();
353 354
354 return 0; 355 return 0;
355} 356}
diff --git a/drivers/char/nwflash.c b/drivers/char/nwflash.c
index 8c7df5ba088f..f80810901db6 100644
--- a/drivers/char/nwflash.c
+++ b/drivers/char/nwflash.c
@@ -27,6 +27,7 @@
27#include <linux/init.h> 27#include <linux/init.h>
28#include <linux/smp_lock.h> 28#include <linux/smp_lock.h>
29#include <linux/mutex.h> 29#include <linux/mutex.h>
30#include <linux/jiffies.h>
30 31
31#include <asm/hardware/dec21285.h> 32#include <asm/hardware/dec21285.h>
32#include <asm/io.h> 33#include <asm/io.h>
diff --git a/drivers/char/pc8736x_gpio.c b/drivers/char/pc8736x_gpio.c
index 3f7da8cf3a80..8ecbcc174c15 100644
--- a/drivers/char/pc8736x_gpio.c
+++ b/drivers/char/pc8736x_gpio.c
@@ -20,7 +20,6 @@
20#include <linux/mutex.h> 20#include <linux/mutex.h>
21#include <linux/nsc_gpio.h> 21#include <linux/nsc_gpio.h>
22#include <linux/platform_device.h> 22#include <linux/platform_device.h>
23#include <linux/smp_lock.h>
24#include <asm/uaccess.h> 23#include <asm/uaccess.h>
25 24
26#define DEVNAME "pc8736x_gpio" 25#define DEVNAME "pc8736x_gpio"
@@ -223,7 +222,6 @@ static int pc8736x_gpio_open(struct inode *inode, struct file *file)
223 unsigned m = iminor(inode); 222 unsigned m = iminor(inode);
224 file->private_data = &pc8736x_gpio_ops; 223 file->private_data = &pc8736x_gpio_ops;
225 224
226 cycle_kernel_lock();
227 dev_dbg(&pdev->dev, "open %d\n", m); 225 dev_dbg(&pdev->dev, "open %d\n", m);
228 226
229 if (m >= PC8736X_GPIO_CT) 227 if (m >= PC8736X_GPIO_CT)
diff --git a/drivers/char/pcmcia/cm4000_cs.c b/drivers/char/pcmcia/cm4000_cs.c
index c250a31efa53..90b199f97bec 100644
--- a/drivers/char/pcmcia/cm4000_cs.c
+++ b/drivers/char/pcmcia/cm4000_cs.c
@@ -23,8 +23,6 @@
23 * All rights reserved. Licensed under dual BSD/GPL license. 23 * All rights reserved. Licensed under dual BSD/GPL license.
24 */ 24 */
25 25
26/* #define PCMCIA_DEBUG 6 */
27
28#include <linux/kernel.h> 26#include <linux/kernel.h>
29#include <linux/module.h> 27#include <linux/module.h>
30#include <linux/slab.h> 28#include <linux/slab.h>
@@ -47,18 +45,17 @@
47 45
48/* #define ATR_CSUM */ 46/* #define ATR_CSUM */
49 47
50#ifdef PCMCIA_DEBUG 48#define reader_to_dev(x) (&x->p_dev->dev)
51#define reader_to_dev(x) (&handle_to_dev(x->p_dev)) 49
52static int pc_debug = PCMCIA_DEBUG; 50/* n (debug level) is ignored */
53module_param(pc_debug, int, 0600); 51/* additional debug output may be enabled by re-compiling with
54#define DEBUGP(n, rdr, x, args...) do { \ 52 * CM4000_DEBUG set */
55 if (pc_debug >= (n)) \ 53/* #define CM4000_DEBUG */
56 dev_printk(KERN_DEBUG, reader_to_dev(rdr), "%s:" x, \ 54#define DEBUGP(n, rdr, x, args...) do { \
57 __func__ , ## args); \ 55 dev_dbg(reader_to_dev(rdr), "%s:" x, \
56 __func__ , ## args); \
58 } while (0) 57 } while (0)
59#else 58
60#define DEBUGP(n, rdr, x, args...)
61#endif
62static char *version = "cm4000_cs.c v2.4.0gm6 - All bugs added by Harald Welte"; 59static char *version = "cm4000_cs.c v2.4.0gm6 - All bugs added by Harald Welte";
63 60
64#define T_1SEC (HZ) 61#define T_1SEC (HZ)
@@ -174,14 +171,13 @@ static unsigned char fi_di_table[10][14] = {
174/* 9 */ {0x09,0x19,0x29,0x39,0x49,0x59,0x69,0x11,0x11,0x99,0xA9,0xB9,0xC9,0xD9} 171/* 9 */ {0x09,0x19,0x29,0x39,0x49,0x59,0x69,0x11,0x11,0x99,0xA9,0xB9,0xC9,0xD9}
175}; 172};
176 173
177#ifndef PCMCIA_DEBUG 174#ifndef CM4000_DEBUG
178#define xoutb outb 175#define xoutb outb
179#define xinb inb 176#define xinb inb
180#else 177#else
181static inline void xoutb(unsigned char val, unsigned short port) 178static inline void xoutb(unsigned char val, unsigned short port)
182{ 179{
183 if (pc_debug >= 7) 180 pr_debug("outb(val=%.2x,port=%.4x)\n", val, port);
184 printk(KERN_DEBUG "outb(val=%.2x,port=%.4x)\n", val, port);
185 outb(val, port); 181 outb(val, port);
186} 182}
187static inline unsigned char xinb(unsigned short port) 183static inline unsigned char xinb(unsigned short port)
@@ -189,8 +185,7 @@ static inline unsigned char xinb(unsigned short port)
189 unsigned char val; 185 unsigned char val;
190 186
191 val = inb(port); 187 val = inb(port);
192 if (pc_debug >= 7) 188 pr_debug("%.2x=inb(%.4x)\n", val, port);
193 printk(KERN_DEBUG "%.2x=inb(%.4x)\n", val, port);
194 189
195 return val; 190 return val;
196} 191}
@@ -514,12 +509,10 @@ static int set_protocol(struct cm4000_dev *dev, struct ptsreq *ptsreq)
514 for (i = 0; i < 4; i++) { 509 for (i = 0; i < 4; i++) {
515 xoutb(i, REG_BUF_ADDR(iobase)); 510 xoutb(i, REG_BUF_ADDR(iobase));
516 xoutb(dev->pts[i], REG_BUF_DATA(iobase)); /* buf data */ 511 xoutb(dev->pts[i], REG_BUF_DATA(iobase)); /* buf data */
517#ifdef PCMCIA_DEBUG 512#ifdef CM4000_DEBUG
518 if (pc_debug >= 5) 513 pr_debug("0x%.2x ", dev->pts[i]);
519 printk("0x%.2x ", dev->pts[i]);
520 } 514 }
521 if (pc_debug >= 5) 515 pr_debug("\n");
522 printk("\n");
523#else 516#else
524 } 517 }
525#endif 518#endif
@@ -579,14 +572,13 @@ static int set_protocol(struct cm4000_dev *dev, struct ptsreq *ptsreq)
579 pts_reply[i] = inb(REG_BUF_DATA(iobase)); 572 pts_reply[i] = inb(REG_BUF_DATA(iobase));
580 } 573 }
581 574
582#ifdef PCMCIA_DEBUG 575#ifdef CM4000_DEBUG
583 DEBUGP(2, dev, "PTSreply: "); 576 DEBUGP(2, dev, "PTSreply: ");
584 for (i = 0; i < num_bytes_read; i++) { 577 for (i = 0; i < num_bytes_read; i++) {
585 if (pc_debug >= 5) 578 pr_debug("0x%.2x ", pts_reply[i]);
586 printk("0x%.2x ", pts_reply[i]);
587 } 579 }
588 printk("\n"); 580 pr_debug("\n");
589#endif /* PCMCIA_DEBUG */ 581#endif /* CM4000_DEBUG */
590 582
591 DEBUGP(5, dev, "Clear Tactive in Flags1\n"); 583 DEBUGP(5, dev, "Clear Tactive in Flags1\n");
592 xoutb(0x20, REG_FLAGS1(iobase)); 584 xoutb(0x20, REG_FLAGS1(iobase));
@@ -655,7 +647,7 @@ static void terminate_monitor(struct cm4000_dev *dev)
655 647
656 DEBUGP(5, dev, "Delete timer\n"); 648 DEBUGP(5, dev, "Delete timer\n");
657 del_timer_sync(&dev->timer); 649 del_timer_sync(&dev->timer);
658#ifdef PCMCIA_DEBUG 650#ifdef CM4000_DEBUG
659 dev->monitor_running = 0; 651 dev->monitor_running = 0;
660#endif 652#endif
661 653
@@ -898,7 +890,7 @@ static void monitor_card(unsigned long p)
898 DEBUGP(4, dev, "ATR checksum (0x%.2x, should " 890 DEBUGP(4, dev, "ATR checksum (0x%.2x, should "
899 "be zero) failed\n", dev->atr_csum); 891 "be zero) failed\n", dev->atr_csum);
900 } 892 }
901#ifdef PCMCIA_DEBUG 893#ifdef CM4000_DEBUG
902 else if (test_bit(IS_BAD_LENGTH, &dev->flags)) { 894 else if (test_bit(IS_BAD_LENGTH, &dev->flags)) {
903 DEBUGP(4, dev, "ATR length error\n"); 895 DEBUGP(4, dev, "ATR length error\n");
904 } else { 896 } else {
@@ -1034,14 +1026,16 @@ static ssize_t cmm_read(struct file *filp, __user char *buf, size_t count,
1034 1026
1035 xoutb(0, REG_FLAGS1(iobase)); /* clear detectCMM */ 1027 xoutb(0, REG_FLAGS1(iobase)); /* clear detectCMM */
1036 /* last check before exit */ 1028 /* last check before exit */
1037 if (!io_detect_cm4000(iobase, dev)) 1029 if (!io_detect_cm4000(iobase, dev)) {
1038 count = -ENODEV; 1030 rc = -ENODEV;
1031 goto release_io;
1032 }
1039 1033
1040 if (test_bit(IS_INVREV, &dev->flags) && count > 0) 1034 if (test_bit(IS_INVREV, &dev->flags) && count > 0)
1041 str_invert_revert(dev->rbuf, count); 1035 str_invert_revert(dev->rbuf, count);
1042 1036
1043 if (copy_to_user(buf, dev->rbuf, count)) 1037 if (copy_to_user(buf, dev->rbuf, count))
1044 return -EFAULT; 1038 rc = -EFAULT;
1045 1039
1046release_io: 1040release_io:
1047 clear_bit(LOCK_IO, &dev->flags); 1041 clear_bit(LOCK_IO, &dev->flags);
@@ -1055,7 +1049,7 @@ release_io:
1055static ssize_t cmm_write(struct file *filp, const char __user *buf, 1049static ssize_t cmm_write(struct file *filp, const char __user *buf,
1056 size_t count, loff_t *ppos) 1050 size_t count, loff_t *ppos)
1057{ 1051{
1058 struct cm4000_dev *dev = (struct cm4000_dev *) filp->private_data; 1052 struct cm4000_dev *dev = filp->private_data;
1059 unsigned int iobase = dev->p_dev->io.BasePort1; 1053 unsigned int iobase = dev->p_dev->io.BasePort1;
1060 unsigned short s; 1054 unsigned short s;
1061 unsigned char tmp; 1055 unsigned char tmp;
@@ -1415,7 +1409,7 @@ static long cmm_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
1415 int size; 1409 int size;
1416 int rc; 1410 int rc;
1417 void __user *argp = (void __user *)arg; 1411 void __user *argp = (void __user *)arg;
1418#ifdef PCMCIA_DEBUG 1412#ifdef CM4000_DEBUG
1419 char *ioctl_names[CM_IOC_MAXNR + 1] = { 1413 char *ioctl_names[CM_IOC_MAXNR + 1] = {
1420 [_IOC_NR(CM_IOCGSTATUS)] "CM_IOCGSTATUS", 1414 [_IOC_NR(CM_IOCGSTATUS)] "CM_IOCGSTATUS",
1421 [_IOC_NR(CM_IOCGATR)] "CM_IOCGATR", 1415 [_IOC_NR(CM_IOCGATR)] "CM_IOCGATR",
@@ -1423,9 +1417,9 @@ static long cmm_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
1423 [_IOC_NR(CM_IOCSPTS)] "CM_IOCSPTS", 1417 [_IOC_NR(CM_IOCSPTS)] "CM_IOCSPTS",
1424 [_IOC_NR(CM_IOSDBGLVL)] "CM4000_DBGLVL", 1418 [_IOC_NR(CM_IOSDBGLVL)] "CM4000_DBGLVL",
1425 }; 1419 };
1426#endif
1427 DEBUGP(3, dev, "cmm_ioctl(device=%d.%d) %s\n", imajor(inode), 1420 DEBUGP(3, dev, "cmm_ioctl(device=%d.%d) %s\n", imajor(inode),
1428 iminor(inode), ioctl_names[_IOC_NR(cmd)]); 1421 iminor(inode), ioctl_names[_IOC_NR(cmd)]);
1422#endif
1429 1423
1430 lock_kernel(); 1424 lock_kernel();
1431 rc = -ENODEV; 1425 rc = -ENODEV;
@@ -1523,7 +1517,7 @@ static long cmm_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
1523 } 1517 }
1524 case CM_IOCARDOFF: 1518 case CM_IOCARDOFF:
1525 1519
1526#ifdef PCMCIA_DEBUG 1520#ifdef CM4000_DEBUG
1527 DEBUGP(4, dev, "... in CM_IOCARDOFF\n"); 1521 DEBUGP(4, dev, "... in CM_IOCARDOFF\n");
1528 if (dev->flags0 & 0x01) { 1522 if (dev->flags0 & 0x01) {
1529 DEBUGP(4, dev, " Card inserted\n"); 1523 DEBUGP(4, dev, " Card inserted\n");
@@ -1625,18 +1619,9 @@ static long cmm_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
1625 1619
1626 } 1620 }
1627 break; 1621 break;
1628#ifdef PCMCIA_DEBUG 1622#ifdef CM4000_DEBUG
1629 case CM_IOSDBGLVL: /* set debug log level */ 1623 case CM_IOSDBGLVL:
1630 { 1624 rc = -ENOTTY;
1631 int old_pc_debug = 0;
1632
1633 old_pc_debug = pc_debug;
1634 if (copy_from_user(&pc_debug, argp, sizeof(int)))
1635 rc = -EFAULT;
1636 else if (old_pc_debug != pc_debug)
1637 DEBUGP(0, dev, "Changed debug log level "
1638 "to %i\n", pc_debug);
1639 }
1640 break; 1625 break;
1641#endif 1626#endif
1642 default: 1627 default:
diff --git a/drivers/char/pcmcia/cm4040_cs.c b/drivers/char/pcmcia/cm4040_cs.c
index 4f0723b07974..a6a70e476bea 100644
--- a/drivers/char/pcmcia/cm4040_cs.c
+++ b/drivers/char/pcmcia/cm4040_cs.c
@@ -17,8 +17,6 @@
17 * All rights reserved, Dual BSD/GPL Licensed. 17 * All rights reserved, Dual BSD/GPL Licensed.
18 */ 18 */
19 19
20/* #define PCMCIA_DEBUG 6 */
21
22#include <linux/kernel.h> 20#include <linux/kernel.h>
23#include <linux/module.h> 21#include <linux/module.h>
24#include <linux/slab.h> 22#include <linux/slab.h>
@@ -41,18 +39,16 @@
41#include "cm4040_cs.h" 39#include "cm4040_cs.h"
42 40
43 41
44#ifdef PCMCIA_DEBUG 42#define reader_to_dev(x) (&x->p_dev->dev)
45#define reader_to_dev(x) (&handle_to_dev(x->p_dev)) 43
46static int pc_debug = PCMCIA_DEBUG; 44/* n (debug level) is ignored */
47module_param(pc_debug, int, 0600); 45/* additional debug output may be enabled by re-compiling with
48#define DEBUGP(n, rdr, x, args...) do { \ 46 * CM4040_DEBUG set */
49 if (pc_debug >= (n)) \ 47/* #define CM4040_DEBUG */
50 dev_printk(KERN_DEBUG, reader_to_dev(rdr), "%s:" x, \ 48#define DEBUGP(n, rdr, x, args...) do { \
51 __func__ , ##args); \ 49 dev_dbg(reader_to_dev(rdr), "%s:" x, \
50 __func__ , ## args); \
52 } while (0) 51 } while (0)
53#else
54#define DEBUGP(n, rdr, x, args...)
55#endif
56 52
57static char *version = 53static char *version =
58"OMNIKEY CardMan 4040 v1.1.0gm5 - All bugs added by Harald Welte"; 54"OMNIKEY CardMan 4040 v1.1.0gm5 - All bugs added by Harald Welte";
@@ -90,14 +86,13 @@ struct reader_dev {
90 86
91static struct pcmcia_device *dev_table[CM_MAX_DEV]; 87static struct pcmcia_device *dev_table[CM_MAX_DEV];
92 88
93#ifndef PCMCIA_DEBUG 89#ifndef CM4040_DEBUG
94#define xoutb outb 90#define xoutb outb
95#define xinb inb 91#define xinb inb
96#else 92#else
97static inline void xoutb(unsigned char val, unsigned short port) 93static inline void xoutb(unsigned char val, unsigned short port)
98{ 94{
99 if (pc_debug >= 7) 95 pr_debug("outb(val=%.2x,port=%.4x)\n", val, port);
100 printk(KERN_DEBUG "outb(val=%.2x,port=%.4x)\n", val, port);
101 outb(val, port); 96 outb(val, port);
102} 97}
103 98
@@ -106,8 +101,7 @@ static inline unsigned char xinb(unsigned short port)
106 unsigned char val; 101 unsigned char val;
107 102
108 val = inb(port); 103 val = inb(port);
109 if (pc_debug >= 7) 104 pr_debug("%.2x=inb(%.4x)\n", val, port);
110 printk(KERN_DEBUG "%.2x=inb(%.4x)\n", val, port);
111 return val; 105 return val;
112} 106}
113#endif 107#endif
@@ -260,23 +254,22 @@ static ssize_t cm4040_read(struct file *filp, char __user *buf,
260 return -EIO; 254 return -EIO;
261 } 255 }
262 dev->r_buf[i] = xinb(iobase + REG_OFFSET_BULK_IN); 256 dev->r_buf[i] = xinb(iobase + REG_OFFSET_BULK_IN);
263#ifdef PCMCIA_DEBUG 257#ifdef CM4040_DEBUG
264 if (pc_debug >= 6) 258 pr_debug("%lu:%2x ", i, dev->r_buf[i]);
265 printk(KERN_DEBUG "%lu:%2x ", i, dev->r_buf[i]);
266 } 259 }
267 printk("\n"); 260 pr_debug("\n");
268#else 261#else
269 } 262 }
270#endif 263#endif
271 264
272 bytes_to_read = 5 + le32_to_cpu(*(__le32 *)&dev->r_buf[1]); 265 bytes_to_read = 5 + le32_to_cpu(*(__le32 *)&dev->r_buf[1]);
273 266
274 DEBUGP(6, dev, "BytesToRead=%lu\n", bytes_to_read); 267 DEBUGP(6, dev, "BytesToRead=%zu\n", bytes_to_read);
275 268
276 min_bytes_to_read = min(count, bytes_to_read + 5); 269 min_bytes_to_read = min(count, bytes_to_read + 5);
277 min_bytes_to_read = min_t(size_t, min_bytes_to_read, READ_WRITE_BUFFER_SIZE); 270 min_bytes_to_read = min_t(size_t, min_bytes_to_read, READ_WRITE_BUFFER_SIZE);
278 271
279 DEBUGP(6, dev, "Min=%lu\n", min_bytes_to_read); 272 DEBUGP(6, dev, "Min=%zu\n", min_bytes_to_read);
280 273
281 for (i = 0; i < (min_bytes_to_read-5); i++) { 274 for (i = 0; i < (min_bytes_to_read-5); i++) {
282 rc = wait_for_bulk_in_ready(dev); 275 rc = wait_for_bulk_in_ready(dev);
@@ -288,11 +281,10 @@ static ssize_t cm4040_read(struct file *filp, char __user *buf,
288 return -EIO; 281 return -EIO;
289 } 282 }
290 dev->r_buf[i+5] = xinb(iobase + REG_OFFSET_BULK_IN); 283 dev->r_buf[i+5] = xinb(iobase + REG_OFFSET_BULK_IN);
291#ifdef PCMCIA_DEBUG 284#ifdef CM4040_DEBUG
292 if (pc_debug >= 6) 285 pr_debug("%lu:%2x ", i, dev->r_buf[i]);
293 printk(KERN_DEBUG "%lu:%2x ", i, dev->r_buf[i]);
294 } 286 }
295 printk("\n"); 287 pr_debug("\n");
296#else 288#else
297 } 289 }
298#endif 290#endif
@@ -547,7 +539,7 @@ static int cm4040_config_check(struct pcmcia_device *p_dev,
547 p_dev->io.IOAddrLines = cfg->io.flags & CISTPL_IO_LINES_MASK; 539 p_dev->io.IOAddrLines = cfg->io.flags & CISTPL_IO_LINES_MASK;
548 540
549 rc = pcmcia_request_io(p_dev, &p_dev->io); 541 rc = pcmcia_request_io(p_dev, &p_dev->io);
550 dev_printk(KERN_INFO, &handle_to_dev(p_dev), 542 dev_printk(KERN_INFO, &p_dev->dev,
551 "pcmcia_request_io returned 0x%x\n", rc); 543 "pcmcia_request_io returned 0x%x\n", rc);
552 return rc; 544 return rc;
553} 545}
@@ -569,7 +561,7 @@ static int reader_config(struct pcmcia_device *link, int devno)
569 561
570 fail_rc = pcmcia_request_configuration(link, &link->conf); 562 fail_rc = pcmcia_request_configuration(link, &link->conf);
571 if (fail_rc != 0) { 563 if (fail_rc != 0) {
572 dev_printk(KERN_INFO, &handle_to_dev(link), 564 dev_printk(KERN_INFO, &link->dev,
573 "pcmcia_request_configuration failed 0x%x\n", 565 "pcmcia_request_configuration failed 0x%x\n",
574 fail_rc); 566 fail_rc);
575 goto cs_release; 567 goto cs_release;
diff --git a/drivers/char/pcmcia/ipwireless/hardware.c b/drivers/char/pcmcia/ipwireless/hardware.c
index 4c1820cad712..99cffdab1056 100644
--- a/drivers/char/pcmcia/ipwireless/hardware.c
+++ b/drivers/char/pcmcia/ipwireless/hardware.c
@@ -1213,12 +1213,12 @@ static irqreturn_t ipwireless_handle_v2_v3_interrupt(int irq,
1213 1213
1214irqreturn_t ipwireless_interrupt(int irq, void *dev_id) 1214irqreturn_t ipwireless_interrupt(int irq, void *dev_id)
1215{ 1215{
1216 struct ipw_hardware *hw = dev_id; 1216 struct ipw_dev *ipw = dev_id;
1217 1217
1218 if (hw->hw_version == HW_VERSION_1) 1218 if (ipw->hardware->hw_version == HW_VERSION_1)
1219 return ipwireless_handle_v1_interrupt(irq, hw); 1219 return ipwireless_handle_v1_interrupt(irq, ipw->hardware);
1220 else 1220 else
1221 return ipwireless_handle_v2_v3_interrupt(irq, hw); 1221 return ipwireless_handle_v2_v3_interrupt(irq, ipw->hardware);
1222} 1222}
1223 1223
1224static void flush_packets_to_hw(struct ipw_hardware *hw) 1224static void flush_packets_to_hw(struct ipw_hardware *hw)
diff --git a/drivers/char/pcmcia/ipwireless/main.c b/drivers/char/pcmcia/ipwireless/main.c
index 5216fce0c62d..dff24dae1485 100644
--- a/drivers/char/pcmcia/ipwireless/main.c
+++ b/drivers/char/pcmcia/ipwireless/main.c
@@ -65,10 +65,7 @@ static void signalled_reboot_work(struct work_struct *work_reboot)
65 struct ipw_dev *ipw = container_of(work_reboot, struct ipw_dev, 65 struct ipw_dev *ipw = container_of(work_reboot, struct ipw_dev,
66 work_reboot); 66 work_reboot);
67 struct pcmcia_device *link = ipw->link; 67 struct pcmcia_device *link = ipw->link;
68 int ret = pcmcia_reset_card(link->socket); 68 pcmcia_reset_card(link->socket);
69
70 if (ret != 0)
71 cs_error(link, ResetCard, ret);
72} 69}
73 70
74static void signalled_reboot_callback(void *callback_data) 71static void signalled_reboot_callback(void *callback_data)
@@ -79,208 +76,127 @@ static void signalled_reboot_callback(void *callback_data)
79 schedule_work(&ipw->work_reboot); 76 schedule_work(&ipw->work_reboot);
80} 77}
81 78
82static int config_ipwireless(struct ipw_dev *ipw) 79static int ipwireless_probe(struct pcmcia_device *p_dev,
80 cistpl_cftable_entry_t *cfg,
81 cistpl_cftable_entry_t *dflt,
82 unsigned int vcc,
83 void *priv_data)
83{ 84{
84 struct pcmcia_device *link = ipw->link; 85 struct ipw_dev *ipw = priv_data;
85 int ret; 86 struct resource *io_resource;
86 tuple_t tuple;
87 unsigned short buf[64];
88 cisparse_t parse;
89 unsigned short cor_value;
90 memreq_t memreq_attr_memory; 87 memreq_t memreq_attr_memory;
91 memreq_t memreq_common_memory; 88 memreq_t memreq_common_memory;
89 int ret;
92 90
93 ipw->is_v2_card = 0; 91 p_dev->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO;
94 92 p_dev->io.BasePort1 = cfg->io.win[0].base;
95 tuple.Attributes = 0; 93 p_dev->io.NumPorts1 = cfg->io.win[0].len;
96 tuple.TupleData = (cisdata_t *) buf; 94 p_dev->io.IOAddrLines = 16;
97 tuple.TupleDataMax = sizeof(buf);
98 tuple.TupleOffset = 0;
99
100 tuple.DesiredTuple = RETURN_FIRST_TUPLE;
101
102 ret = pcmcia_get_first_tuple(link, &tuple);
103
104 while (ret == 0) {
105 ret = pcmcia_get_tuple_data(link, &tuple);
106
107 if (ret != 0) {
108 cs_error(link, GetTupleData, ret);
109 goto exit0;
110 }
111 ret = pcmcia_get_next_tuple(link, &tuple);
112 }
113
114 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
115
116 ret = pcmcia_get_first_tuple(link, &tuple);
117
118 if (ret != 0) {
119 cs_error(link, GetFirstTuple, ret);
120 goto exit0;
121 }
122
123 ret = pcmcia_get_tuple_data(link, &tuple);
124
125 if (ret != 0) {
126 cs_error(link, GetTupleData, ret);
127 goto exit0;
128 }
129
130 ret = pcmcia_parse_tuple(&tuple, &parse);
131
132 if (ret != 0) {
133 cs_error(link, ParseTuple, ret);
134 goto exit0;
135 }
136
137 link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO;
138 link->io.BasePort1 = parse.cftable_entry.io.win[0].base;
139 link->io.NumPorts1 = parse.cftable_entry.io.win[0].len;
140 link->io.IOAddrLines = 16;
141
142 link->irq.IRQInfo1 = parse.cftable_entry.irq.IRQInfo1;
143 95
144 /* 0x40 causes it to generate level mode interrupts. */ 96 /* 0x40 causes it to generate level mode interrupts. */
145 /* 0x04 enables IREQ pin. */ 97 /* 0x04 enables IREQ pin. */
146 cor_value = parse.cftable_entry.index | 0x44; 98 p_dev->conf.ConfigIndex = cfg->index | 0x44;
147 link->conf.ConfigIndex = cor_value; 99 ret = pcmcia_request_io(p_dev, &p_dev->io);
100 if (ret)
101 return ret;
148 102
149 /* IRQ and I/O settings */ 103 io_resource = request_region(p_dev->io.BasePort1, p_dev->io.NumPorts1,
150 tuple.DesiredTuple = CISTPL_CONFIG; 104 IPWIRELESS_PCCARD_NAME);
151 105
152 ret = pcmcia_get_first_tuple(link, &tuple); 106 if (cfg->mem.nwin == 0)
107 return 0;
153 108
154 if (ret != 0) { 109 ipw->request_common_memory.Attributes =
155 cs_error(link, GetFirstTuple, ret); 110 WIN_DATA_WIDTH_16 | WIN_MEMORY_TYPE_CM | WIN_ENABLE;
156 goto exit0; 111 ipw->request_common_memory.Base = cfg->mem.win[0].host_addr;
157 } 112 ipw->request_common_memory.Size = cfg->mem.win[0].len;
113 if (ipw->request_common_memory.Size < 0x1000)
114 ipw->request_common_memory.Size = 0x1000;
115 ipw->request_common_memory.AccessSpeed = 0;
158 116
159 ret = pcmcia_get_tuple_data(link, &tuple); 117 ret = pcmcia_request_window(p_dev, &ipw->request_common_memory,
160 118 &ipw->handle_common_memory);
161 if (ret != 0) {
162 cs_error(link, GetTupleData, ret);
163 goto exit0;
164 }
165 119
166 ret = pcmcia_parse_tuple(&tuple, &parse); 120 if (ret != 0)
121 goto exit1;
167 122
168 if (ret != 0) { 123 memreq_common_memory.CardOffset = cfg->mem.win[0].card_addr;
169 cs_error(link, GetTupleData, ret); 124 memreq_common_memory.Page = 0;
170 goto exit0;
171 }
172 link->conf.Attributes = CONF_ENABLE_IRQ;
173 link->conf.ConfigBase = parse.config.base;
174 link->conf.Present = parse.config.rmask[0];
175 link->conf.IntType = INT_MEMORY_AND_IO;
176 125
177 link->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING | IRQ_HANDLE_PRESENT; 126 ret = pcmcia_map_mem_page(p_dev, ipw->handle_common_memory,
178 link->irq.Handler = ipwireless_interrupt; 127 &memreq_common_memory);
179 link->irq.Instance = ipw->hardware;
180 128
181 ret = pcmcia_request_io(link, &link->io); 129 if (ret != 0)
130 goto exit2;
182 131
183 if (ret != 0) { 132 ipw->is_v2_card = cfg->mem.win[0].len == 0x100;
184 cs_error(link, RequestIO, ret);
185 goto exit0;
186 }
187 133
188 request_region(link->io.BasePort1, link->io.NumPorts1, 134 ipw->common_memory = ioremap(ipw->request_common_memory.Base,
135 ipw->request_common_memory.Size);
136 request_mem_region(ipw->request_common_memory.Base,
137 ipw->request_common_memory.Size,
189 IPWIRELESS_PCCARD_NAME); 138 IPWIRELESS_PCCARD_NAME);
190 139
191 /* memory settings */ 140 ipw->request_attr_memory.Attributes =
192 141 WIN_DATA_WIDTH_16 | WIN_MEMORY_TYPE_AM | WIN_ENABLE;
193 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY; 142 ipw->request_attr_memory.Base = 0;
194 143 ipw->request_attr_memory.Size = 0; /* this used to be 0x1000 */
195 ret = pcmcia_get_first_tuple(link, &tuple); 144 ipw->request_attr_memory.AccessSpeed = 0;
196
197 if (ret != 0) {
198 cs_error(link, GetFirstTuple, ret);
199 goto exit1;
200 }
201
202 ret = pcmcia_get_tuple_data(link, &tuple);
203 145
204 if (ret != 0) { 146 ret = pcmcia_request_window(p_dev, &ipw->request_attr_memory,
205 cs_error(link, GetTupleData, ret); 147 &ipw->handle_attr_memory);
206 goto exit1;
207 }
208
209 ret = pcmcia_parse_tuple(&tuple, &parse);
210
211 if (ret != 0) {
212 cs_error(link, ParseTuple, ret);
213 goto exit1;
214 }
215 148
216 if (parse.cftable_entry.mem.nwin > 0) { 149 if (ret != 0)
217 ipw->request_common_memory.Attributes = 150 goto exit2;
218 WIN_DATA_WIDTH_16 | WIN_MEMORY_TYPE_CM | WIN_ENABLE;
219 ipw->request_common_memory.Base =
220 parse.cftable_entry.mem.win[0].host_addr;
221 ipw->request_common_memory.Size = parse.cftable_entry.mem.win[0].len;
222 if (ipw->request_common_memory.Size < 0x1000)
223 ipw->request_common_memory.Size = 0x1000;
224 ipw->request_common_memory.AccessSpeed = 0;
225
226 ret = pcmcia_request_window(&link, &ipw->request_common_memory,
227 &ipw->handle_common_memory);
228 151
229 if (ret != 0) { 152 memreq_attr_memory.CardOffset = 0;
230 cs_error(link, RequestWindow, ret); 153 memreq_attr_memory.Page = 0;
231 goto exit1;
232 }
233 154
234 memreq_common_memory.CardOffset = 155 ret = pcmcia_map_mem_page(p_dev, ipw->handle_attr_memory,
235 parse.cftable_entry.mem.win[0].card_addr; 156 &memreq_attr_memory);
236 memreq_common_memory.Page = 0;
237 157
238 ret = pcmcia_map_mem_page(ipw->handle_common_memory, 158 if (ret != 0)
239 &memreq_common_memory); 159 goto exit3;
240 160
241 if (ret != 0) { 161 ipw->attr_memory = ioremap(ipw->request_attr_memory.Base,
242 cs_error(link, MapMemPage, ret); 162 ipw->request_attr_memory.Size);
243 goto exit1; 163 request_mem_region(ipw->request_attr_memory.Base,
244 } 164 ipw->request_attr_memory.Size, IPWIRELESS_PCCARD_NAME);
245 165
246 ipw->is_v2_card = 166 return 0;
247 parse.cftable_entry.mem.win[0].len == 0x100;
248 167
249 ipw->common_memory = ioremap(ipw->request_common_memory.Base, 168exit3:
169 pcmcia_release_window(p_dev, ipw->handle_attr_memory);
170exit2:
171 if (ipw->common_memory) {
172 release_mem_region(ipw->request_common_memory.Base,
250 ipw->request_common_memory.Size); 173 ipw->request_common_memory.Size);
251 request_mem_region(ipw->request_common_memory.Base, 174 iounmap(ipw->common_memory);
252 ipw->request_common_memory.Size, IPWIRELESS_PCCARD_NAME); 175 pcmcia_release_window(p_dev, ipw->handle_common_memory);
253 176 } else
254 ipw->request_attr_memory.Attributes = 177 pcmcia_release_window(p_dev, ipw->handle_common_memory);
255 WIN_DATA_WIDTH_16 | WIN_MEMORY_TYPE_AM | WIN_ENABLE; 178exit1:
256 ipw->request_attr_memory.Base = 0; 179 release_resource(io_resource);
257 ipw->request_attr_memory.Size = 0; /* this used to be 0x1000 */ 180 pcmcia_disable_device(p_dev);
258 ipw->request_attr_memory.AccessSpeed = 0; 181 return -1;
259 182}
260 ret = pcmcia_request_window(&link, &ipw->request_attr_memory,
261 &ipw->handle_attr_memory);
262 183
263 if (ret != 0) { 184static int config_ipwireless(struct ipw_dev *ipw)
264 cs_error(link, RequestWindow, ret); 185{
265 goto exit2; 186 struct pcmcia_device *link = ipw->link;
266 } 187 int ret = 0;
267 188
268 memreq_attr_memory.CardOffset = 0; 189 ipw->is_v2_card = 0;
269 memreq_attr_memory.Page = 0;
270 190
271 ret = pcmcia_map_mem_page(ipw->handle_attr_memory, 191 ret = pcmcia_loop_config(link, ipwireless_probe, ipw);
272 &memreq_attr_memory); 192 if (ret != 0)
193 return ret;
273 194
274 if (ret != 0) { 195 link->conf.Attributes = CONF_ENABLE_IRQ;
275 cs_error(link, MapMemPage, ret); 196 link->conf.IntType = INT_MEMORY_AND_IO;
276 goto exit2;
277 }
278 197
279 ipw->attr_memory = ioremap(ipw->request_attr_memory.Base, 198 link->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING;
280 ipw->request_attr_memory.Size); 199 link->irq.Handler = ipwireless_interrupt;
281 request_mem_region(ipw->request_attr_memory.Base, ipw->request_attr_memory.Size,
282 IPWIRELESS_PCCARD_NAME);
283 }
284 200
285 INIT_WORK(&ipw->work_reboot, signalled_reboot_work); 201 INIT_WORK(&ipw->work_reboot, signalled_reboot_work);
286 202
@@ -291,10 +207,8 @@ static int config_ipwireless(struct ipw_dev *ipw)
291 207
292 ret = pcmcia_request_irq(link, &link->irq); 208 ret = pcmcia_request_irq(link, &link->irq);
293 209
294 if (ret != 0) { 210 if (ret != 0)
295 cs_error(link, RequestIRQ, ret); 211 goto exit;
296 goto exit3;
297 }
298 212
299 printk(KERN_INFO IPWIRELESS_PCCARD_NAME ": Card type %s\n", 213 printk(KERN_INFO IPWIRELESS_PCCARD_NAME ": Card type %s\n",
300 ipw->is_v2_card ? "V2/V3" : "V1"); 214 ipw->is_v2_card ? "V2/V3" : "V1");
@@ -316,12 +230,12 @@ static int config_ipwireless(struct ipw_dev *ipw)
316 230
317 ipw->network = ipwireless_network_create(ipw->hardware); 231 ipw->network = ipwireless_network_create(ipw->hardware);
318 if (!ipw->network) 232 if (!ipw->network)
319 goto exit3; 233 goto exit;
320 234
321 ipw->tty = ipwireless_tty_create(ipw->hardware, ipw->network, 235 ipw->tty = ipwireless_tty_create(ipw->hardware, ipw->network,
322 ipw->nodes); 236 ipw->nodes);
323 if (!ipw->tty) 237 if (!ipw->tty)
324 goto exit3; 238 goto exit;
325 239
326 ipwireless_init_hardware_v2_v3(ipw->hardware); 240 ipwireless_init_hardware_v2_v3(ipw->hardware);
327 241
@@ -331,35 +245,27 @@ static int config_ipwireless(struct ipw_dev *ipw)
331 */ 245 */
332 ret = pcmcia_request_configuration(link, &link->conf); 246 ret = pcmcia_request_configuration(link, &link->conf);
333 247
334 if (ret != 0) { 248 if (ret != 0)
335 cs_error(link, RequestConfiguration, ret); 249 goto exit;
336 goto exit4;
337 }
338 250
339 link->dev_node = &ipw->nodes[0]; 251 link->dev_node = &ipw->nodes[0];
340 252
341 return 0; 253 return 0;
342 254
343exit4: 255exit:
344 pcmcia_disable_device(link);
345exit3:
346 if (ipw->attr_memory) { 256 if (ipw->attr_memory) {
347 release_mem_region(ipw->request_attr_memory.Base, 257 release_mem_region(ipw->request_attr_memory.Base,
348 ipw->request_attr_memory.Size); 258 ipw->request_attr_memory.Size);
349 iounmap(ipw->attr_memory); 259 iounmap(ipw->attr_memory);
350 pcmcia_release_window(ipw->handle_attr_memory); 260 pcmcia_release_window(link, ipw->handle_attr_memory);
351 pcmcia_disable_device(link);
352 } 261 }
353exit2:
354 if (ipw->common_memory) { 262 if (ipw->common_memory) {
355 release_mem_region(ipw->request_common_memory.Base, 263 release_mem_region(ipw->request_common_memory.Base,
356 ipw->request_common_memory.Size); 264 ipw->request_common_memory.Size);
357 iounmap(ipw->common_memory); 265 iounmap(ipw->common_memory);
358 pcmcia_release_window(ipw->handle_common_memory); 266 pcmcia_release_window(link, ipw->handle_common_memory);
359 } 267 }
360exit1:
361 pcmcia_disable_device(link); 268 pcmcia_disable_device(link);
362exit0:
363 return -1; 269 return -1;
364} 270}
365 271
@@ -378,9 +284,9 @@ static void release_ipwireless(struct ipw_dev *ipw)
378 iounmap(ipw->attr_memory); 284 iounmap(ipw->attr_memory);
379 } 285 }
380 if (ipw->common_memory) 286 if (ipw->common_memory)
381 pcmcia_release_window(ipw->handle_common_memory); 287 pcmcia_release_window(ipw->link, ipw->handle_common_memory);
382 if (ipw->attr_memory) 288 if (ipw->attr_memory)
383 pcmcia_release_window(ipw->handle_attr_memory); 289 pcmcia_release_window(ipw->link, ipw->handle_attr_memory);
384 290
385 /* Break the link with Card Services */ 291 /* Break the link with Card Services */
386 pcmcia_disable_device(ipw->link); 292 pcmcia_disable_device(ipw->link);
@@ -406,7 +312,6 @@ static int ipwireless_attach(struct pcmcia_device *link)
406 312
407 ipw->link = link; 313 ipw->link = link;
408 link->priv = ipw; 314 link->priv = ipw;
409 link->irq.Instance = ipw;
410 315
411 /* Link this device into our device list. */ 316 /* Link this device into our device list. */
412 link->dev_node = &ipw->nodes[0]; 317 link->dev_node = &ipw->nodes[0];
@@ -421,7 +326,6 @@ static int ipwireless_attach(struct pcmcia_device *link)
421 ret = config_ipwireless(ipw); 326 ret = config_ipwireless(ipw);
422 327
423 if (ret != 0) { 328 if (ret != 0) {
424 cs_error(link, RegisterClient, ret);
425 ipwireless_detach(link); 329 ipwireless_detach(link);
426 return ret; 330 return ret;
427 } 331 }
diff --git a/drivers/char/pcmcia/ipwireless/network.c b/drivers/char/pcmcia/ipwireless/network.c
index 590762a7f217..65920163f53d 100644
--- a/drivers/char/pcmcia/ipwireless/network.c
+++ b/drivers/char/pcmcia/ipwireless/network.c
@@ -21,6 +21,7 @@
21#include <linux/netdevice.h> 21#include <linux/netdevice.h>
22#include <linux/ppp_channel.h> 22#include <linux/ppp_channel.h>
23#include <linux/ppp_defs.h> 23#include <linux/ppp_defs.h>
24#include <linux/slab.h>
24#include <linux/if_ppp.h> 25#include <linux/if_ppp.h>
25#include <linux/skbuff.h> 26#include <linux/skbuff.h>
26 27
diff --git a/drivers/char/pcmcia/ipwireless/tty.c b/drivers/char/pcmcia/ipwireless/tty.c
index 674b3ab3587d..2bb7874a6899 100644
--- a/drivers/char/pcmcia/ipwireless/tty.c
+++ b/drivers/char/pcmcia/ipwireless/tty.c
@@ -603,7 +603,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
603 } 603 }
604} 604}
605 605
606static struct tty_operations tty_ops = { 606static const struct tty_operations tty_ops = {
607 .open = ipw_open, 607 .open = ipw_open,
608 .close = ipw_close, 608 .close = ipw_close,
609 .hangup = ipw_hangup, 609 .hangup = ipw_hangup,
diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
index caf6e4d19469..c31a0d913d37 100644
--- a/drivers/char/pcmcia/synclink_cs.c
+++ b/drivers/char/pcmcia/synclink_cs.c
@@ -554,7 +554,6 @@ static int mgslpc_probe(struct pcmcia_device *link)
554 554
555 /* Interrupt setup */ 555 /* Interrupt setup */
556 link->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING; 556 link->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING;
557 link->irq.IRQInfo1 = IRQ_LEVEL_ID;
558 link->irq.Handler = NULL; 557 link->irq.Handler = NULL;
559 558
560 link->conf.Attributes = 0; 559 link->conf.Attributes = 0;
@@ -572,69 +571,51 @@ static int mgslpc_probe(struct pcmcia_device *link)
572/* Card has been inserted. 571/* Card has been inserted.
573 */ 572 */
574 573
575#define CS_CHECK(fn, ret) \ 574static int mgslpc_ioprobe(struct pcmcia_device *p_dev,
576do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0) 575 cistpl_cftable_entry_t *cfg,
576 cistpl_cftable_entry_t *dflt,
577 unsigned int vcc,
578 void *priv_data)
579{
580 if (cfg->io.nwin > 0) {
581 p_dev->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO;
582 if (!(cfg->io.flags & CISTPL_IO_8BIT))
583 p_dev->io.Attributes1 = IO_DATA_PATH_WIDTH_16;
584 if (!(cfg->io.flags & CISTPL_IO_16BIT))
585 p_dev->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
586 p_dev->io.IOAddrLines = cfg->io.flags & CISTPL_IO_LINES_MASK;
587 p_dev->io.BasePort1 = cfg->io.win[0].base;
588 p_dev->io.NumPorts1 = cfg->io.win[0].len;
589 return pcmcia_request_io(p_dev, &p_dev->io);
590 }
591 return -ENODEV;
592}
577 593
578static int mgslpc_config(struct pcmcia_device *link) 594static int mgslpc_config(struct pcmcia_device *link)
579{ 595{
580 MGSLPC_INFO *info = link->priv; 596 MGSLPC_INFO *info = link->priv;
581 tuple_t tuple; 597 int ret;
582 cisparse_t parse;
583 int last_fn, last_ret;
584 u_char buf[64];
585 cistpl_cftable_entry_t dflt = { 0 };
586 cistpl_cftable_entry_t *cfg;
587 598
588 if (debug_level >= DEBUG_LEVEL_INFO) 599 if (debug_level >= DEBUG_LEVEL_INFO)
589 printk("mgslpc_config(0x%p)\n", link); 600 printk("mgslpc_config(0x%p)\n", link);
590 601
591 tuple.Attributes = 0; 602 ret = pcmcia_loop_config(link, mgslpc_ioprobe, NULL);
592 tuple.TupleData = buf; 603 if (ret != 0)
593 tuple.TupleDataMax = sizeof(buf); 604 goto failed;
594 tuple.TupleOffset = 0;
595
596 /* get CIS configuration entry */
597
598 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
599 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
600
601 cfg = &(parse.cftable_entry);
602 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(link, &tuple));
603 CS_CHECK(ParseTuple, pcmcia_parse_tuple(&tuple, &parse));
604
605 if (cfg->flags & CISTPL_CFTABLE_DEFAULT) dflt = *cfg;
606 if (cfg->index == 0)
607 goto cs_failed;
608
609 link->conf.ConfigIndex = cfg->index;
610 link->conf.Attributes |= CONF_ENABLE_IRQ;
611
612 /* IO window settings */
613 link->io.NumPorts1 = 0;
614 if ((cfg->io.nwin > 0) || (dflt.io.nwin > 0)) {
615 cistpl_io_t *io = (cfg->io.nwin) ? &cfg->io : &dflt.io;
616 link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO;
617 if (!(io->flags & CISTPL_IO_8BIT))
618 link->io.Attributes1 = IO_DATA_PATH_WIDTH_16;
619 if (!(io->flags & CISTPL_IO_16BIT))
620 link->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
621 link->io.IOAddrLines = io->flags & CISTPL_IO_LINES_MASK;
622 link->io.BasePort1 = io->win[0].base;
623 link->io.NumPorts1 = io->win[0].len;
624 CS_CHECK(RequestIO, pcmcia_request_io(link, &link->io));
625 }
626 605
627 link->conf.Attributes = CONF_ENABLE_IRQ; 606 link->conf.Attributes = CONF_ENABLE_IRQ;
628 link->conf.IntType = INT_MEMORY_AND_IO; 607 link->conf.IntType = INT_MEMORY_AND_IO;
629 link->conf.ConfigIndex = 8; 608 link->conf.ConfigIndex = 8;
630 link->conf.Present = PRESENT_OPTION; 609 link->conf.Present = PRESENT_OPTION;
631 610
632 link->irq.Attributes |= IRQ_HANDLE_PRESENT;
633 link->irq.Handler = mgslpc_isr; 611 link->irq.Handler = mgslpc_isr;
634 link->irq.Instance = info;
635 CS_CHECK(RequestIRQ, pcmcia_request_irq(link, &link->irq));
636 612
637 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link, &link->conf)); 613 ret = pcmcia_request_irq(link, &link->irq);
614 if (ret)
615 goto failed;
616 ret = pcmcia_request_configuration(link, &link->conf);
617 if (ret)
618 goto failed;
638 619
639 info->io_base = link->io.BasePort1; 620 info->io_base = link->io.BasePort1;
640 info->irq_level = link->irq.AssignedIRQ; 621 info->irq_level = link->irq.AssignedIRQ;
@@ -654,8 +635,7 @@ static int mgslpc_config(struct pcmcia_device *link)
654 printk("\n"); 635 printk("\n");
655 return 0; 636 return 0;
656 637
657cs_failed: 638failed:
658 cs_error(link, last_fn, last_ret);
659 mgslpc_release((u_long)link); 639 mgslpc_release((u_long)link);
660 return -ENODEV; 640 return -ENODEV;
661} 641}
diff --git a/drivers/char/ppdev.c b/drivers/char/ppdev.c
index 432655bcb04c..fdd37543aa79 100644
--- a/drivers/char/ppdev.c
+++ b/drivers/char/ppdev.c
@@ -64,6 +64,7 @@
64#include <linux/parport.h> 64#include <linux/parport.h>
65#include <linux/ctype.h> 65#include <linux/ctype.h>
66#include <linux/poll.h> 66#include <linux/poll.h>
67#include <linux/slab.h>
67#include <linux/major.h> 68#include <linux/major.h>
68#include <linux/ppdev.h> 69#include <linux/ppdev.h>
69#include <linux/smp_lock.h> 70#include <linux/smp_lock.h>
diff --git a/drivers/char/ps3flash.c b/drivers/char/ps3flash.c
index f424d394a286..606048b72bcf 100644
--- a/drivers/char/ps3flash.c
+++ b/drivers/char/ps3flash.c
@@ -20,6 +20,7 @@
20 20
21#include <linux/fs.h> 21#include <linux/fs.h>
22#include <linux/miscdevice.h> 22#include <linux/miscdevice.h>
23#include <linux/slab.h>
23#include <linux/uaccess.h> 24#include <linux/uaccess.h>
24 25
25#include <asm/lv1call.h> 26#include <asm/lv1call.h>
diff --git a/drivers/char/pty.c b/drivers/char/pty.c
index 62f282e67638..d83a43130df4 100644
--- a/drivers/char/pty.c
+++ b/drivers/char/pty.c
@@ -29,6 +29,7 @@
29#include <linux/uaccess.h> 29#include <linux/uaccess.h>
30#include <linux/bitops.h> 30#include <linux/bitops.h>
31#include <linux/devpts_fs.h> 31#include <linux/devpts_fs.h>
32#include <linux/slab.h>
32 33
33#include <asm/system.h> 34#include <asm/system.h>
34 35
@@ -220,7 +221,7 @@ static void pty_set_termios(struct tty_struct *tty,
220 * @tty: tty being resized 221 * @tty: tty being resized
221 * @ws: window size being set. 222 * @ws: window size being set.
222 * 223 *
223 * Update the termios variables and send the neccessary signals to 224 * Update the termios variables and send the necessary signals to
224 * peform a terminal resize correctly 225 * peform a terminal resize correctly
225 */ 226 */
226 227
@@ -431,30 +432,25 @@ static struct cdev ptmx_cdev;
431 432
432static struct ctl_table pty_table[] = { 433static struct ctl_table pty_table[] = {
433 { 434 {
434 .ctl_name = PTY_MAX,
435 .procname = "max", 435 .procname = "max",
436 .maxlen = sizeof(int), 436 .maxlen = sizeof(int),
437 .mode = 0644, 437 .mode = 0644,
438 .data = &pty_limit, 438 .data = &pty_limit,
439 .proc_handler = &proc_dointvec_minmax, 439 .proc_handler = proc_dointvec_minmax,
440 .strategy = &sysctl_intvec,
441 .extra1 = &pty_limit_min, 440 .extra1 = &pty_limit_min,
442 .extra2 = &pty_limit_max, 441 .extra2 = &pty_limit_max,
443 }, { 442 }, {
444 .ctl_name = PTY_NR,
445 .procname = "nr", 443 .procname = "nr",
446 .maxlen = sizeof(int), 444 .maxlen = sizeof(int),
447 .mode = 0444, 445 .mode = 0444,
448 .data = &pty_count, 446 .data = &pty_count,
449 .proc_handler = &proc_dointvec, 447 .proc_handler = proc_dointvec,
450 }, { 448 },
451 .ctl_name = 0 449 {}
452 }
453}; 450};
454 451
455static struct ctl_table pty_kern_table[] = { 452static struct ctl_table pty_kern_table[] = {
456 { 453 {
457 .ctl_name = KERN_PTY,
458 .procname = "pty", 454 .procname = "pty",
459 .mode = 0555, 455 .mode = 0555,
460 .child = pty_table, 456 .child = pty_table,
@@ -464,7 +460,6 @@ static struct ctl_table pty_kern_table[] = {
464 460
465static struct ctl_table pty_root_table[] = { 461static struct ctl_table pty_root_table[] = {
466 { 462 {
467 .ctl_name = CTL_KERN,
468 .procname = "kernel", 463 .procname = "kernel",
469 .mode = 0555, 464 .mode = 0555,
470 .child = pty_kern_table, 465 .child = pty_kern_table,
@@ -665,7 +660,7 @@ static int __ptmx_open(struct inode *inode, struct file *filp)
665 if (!retval) 660 if (!retval)
666 return 0; 661 return 0;
667out1: 662out1:
668 tty_release_dev(filp); 663 tty_release(inode, filp);
669 return retval; 664 return retval;
670out: 665out:
671 devpts_kill_index(inode, index); 666 devpts_kill_index(inode, index);
diff --git a/drivers/char/random.c b/drivers/char/random.c
index 04b505e5a5e2..2fd3d39995d5 100644
--- a/drivers/char/random.c
+++ b/drivers/char/random.c
@@ -1051,12 +1051,6 @@ random_read(struct file *file, char __user *buf, size_t nbytes, loff_t *ppos)
1051 /* like a named pipe */ 1051 /* like a named pipe */
1052 } 1052 }
1053 1053
1054 /*
1055 * If we gave the user some bytes, update the access time.
1056 */
1057 if (count)
1058 file_accessed(file);
1059
1060 return (count ? count : retval); 1054 return (count ? count : retval);
1061} 1055}
1062 1056
@@ -1107,7 +1101,6 @@ static ssize_t random_write(struct file *file, const char __user *buffer,
1107 size_t count, loff_t *ppos) 1101 size_t count, loff_t *ppos)
1108{ 1102{
1109 size_t ret; 1103 size_t ret;
1110 struct inode *inode = file->f_path.dentry->d_inode;
1111 1104
1112 ret = write_pool(&blocking_pool, buffer, count); 1105 ret = write_pool(&blocking_pool, buffer, count);
1113 if (ret) 1106 if (ret)
@@ -1116,8 +1109,6 @@ static ssize_t random_write(struct file *file, const char __user *buffer,
1116 if (ret) 1109 if (ret)
1117 return ret; 1110 return ret;
1118 1111
1119 inode->i_mtime = current_fs_time(inode->i_sb);
1120 mark_inode_dirty(inode);
1121 return (ssize_t)count; 1112 return (ssize_t)count;
1122} 1113}
1123 1114
@@ -1200,7 +1191,7 @@ const struct file_operations urandom_fops = {
1200void generate_random_uuid(unsigned char uuid_out[16]) 1191void generate_random_uuid(unsigned char uuid_out[16])
1201{ 1192{
1202 get_random_bytes(uuid_out, 16); 1193 get_random_bytes(uuid_out, 16);
1203 /* Set UUID version to 4 --- truely random generation */ 1194 /* Set UUID version to 4 --- truly random generation */
1204 uuid_out[6] = (uuid_out[6] & 0x0F) | 0x40; 1195 uuid_out[6] = (uuid_out[6] & 0x0F) | 0x40;
1205 /* Set the UUID variant to DCE */ 1196 /* Set the UUID variant to DCE */
1206 uuid_out[8] = (uuid_out[8] & 0x3F) | 0x80; 1197 uuid_out[8] = (uuid_out[8] & 0x3F) | 0x80;
@@ -1245,112 +1236,68 @@ static int proc_do_uuid(ctl_table *table, int write,
1245 if (uuid[8] == 0) 1236 if (uuid[8] == 0)
1246 generate_random_uuid(uuid); 1237 generate_random_uuid(uuid);
1247 1238
1248 sprintf(buf, "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-" 1239 sprintf(buf, "%pU", uuid);
1249 "%02x%02x%02x%02x%02x%02x", 1240
1250 uuid[0], uuid[1], uuid[2], uuid[3],
1251 uuid[4], uuid[5], uuid[6], uuid[7],
1252 uuid[8], uuid[9], uuid[10], uuid[11],
1253 uuid[12], uuid[13], uuid[14], uuid[15]);
1254 fake_table.data = buf; 1241 fake_table.data = buf;
1255 fake_table.maxlen = sizeof(buf); 1242 fake_table.maxlen = sizeof(buf);
1256 1243
1257 return proc_dostring(&fake_table, write, buffer, lenp, ppos); 1244 return proc_dostring(&fake_table, write, buffer, lenp, ppos);
1258} 1245}
1259 1246
1260static int uuid_strategy(ctl_table *table,
1261 void __user *oldval, size_t __user *oldlenp,
1262 void __user *newval, size_t newlen)
1263{
1264 unsigned char tmp_uuid[16], *uuid;
1265 unsigned int len;
1266
1267 if (!oldval || !oldlenp)
1268 return 1;
1269
1270 uuid = table->data;
1271 if (!uuid) {
1272 uuid = tmp_uuid;
1273 uuid[8] = 0;
1274 }
1275 if (uuid[8] == 0)
1276 generate_random_uuid(uuid);
1277
1278 if (get_user(len, oldlenp))
1279 return -EFAULT;
1280 if (len) {
1281 if (len > 16)
1282 len = 16;
1283 if (copy_to_user(oldval, uuid, len) ||
1284 put_user(len, oldlenp))
1285 return -EFAULT;
1286 }
1287 return 1;
1288}
1289
1290static int sysctl_poolsize = INPUT_POOL_WORDS * 32; 1247static int sysctl_poolsize = INPUT_POOL_WORDS * 32;
1291ctl_table random_table[] = { 1248ctl_table random_table[] = {
1292 { 1249 {
1293 .ctl_name = RANDOM_POOLSIZE,
1294 .procname = "poolsize", 1250 .procname = "poolsize",
1295 .data = &sysctl_poolsize, 1251 .data = &sysctl_poolsize,
1296 .maxlen = sizeof(int), 1252 .maxlen = sizeof(int),
1297 .mode = 0444, 1253 .mode = 0444,
1298 .proc_handler = &proc_dointvec, 1254 .proc_handler = proc_dointvec,
1299 }, 1255 },
1300 { 1256 {
1301 .ctl_name = RANDOM_ENTROPY_COUNT,
1302 .procname = "entropy_avail", 1257 .procname = "entropy_avail",
1303 .maxlen = sizeof(int), 1258 .maxlen = sizeof(int),
1304 .mode = 0444, 1259 .mode = 0444,
1305 .proc_handler = &proc_dointvec, 1260 .proc_handler = proc_dointvec,
1306 .data = &input_pool.entropy_count, 1261 .data = &input_pool.entropy_count,
1307 }, 1262 },
1308 { 1263 {
1309 .ctl_name = RANDOM_READ_THRESH,
1310 .procname = "read_wakeup_threshold", 1264 .procname = "read_wakeup_threshold",
1311 .data = &random_read_wakeup_thresh, 1265 .data = &random_read_wakeup_thresh,
1312 .maxlen = sizeof(int), 1266 .maxlen = sizeof(int),
1313 .mode = 0644, 1267 .mode = 0644,
1314 .proc_handler = &proc_dointvec_minmax, 1268 .proc_handler = proc_dointvec_minmax,
1315 .strategy = &sysctl_intvec,
1316 .extra1 = &min_read_thresh, 1269 .extra1 = &min_read_thresh,
1317 .extra2 = &max_read_thresh, 1270 .extra2 = &max_read_thresh,
1318 }, 1271 },
1319 { 1272 {
1320 .ctl_name = RANDOM_WRITE_THRESH,
1321 .procname = "write_wakeup_threshold", 1273 .procname = "write_wakeup_threshold",
1322 .data = &random_write_wakeup_thresh, 1274 .data = &random_write_wakeup_thresh,
1323 .maxlen = sizeof(int), 1275 .maxlen = sizeof(int),
1324 .mode = 0644, 1276 .mode = 0644,
1325 .proc_handler = &proc_dointvec_minmax, 1277 .proc_handler = proc_dointvec_minmax,
1326 .strategy = &sysctl_intvec,
1327 .extra1 = &min_write_thresh, 1278 .extra1 = &min_write_thresh,
1328 .extra2 = &max_write_thresh, 1279 .extra2 = &max_write_thresh,
1329 }, 1280 },
1330 { 1281 {
1331 .ctl_name = RANDOM_BOOT_ID,
1332 .procname = "boot_id", 1282 .procname = "boot_id",
1333 .data = &sysctl_bootid, 1283 .data = &sysctl_bootid,
1334 .maxlen = 16, 1284 .maxlen = 16,
1335 .mode = 0444, 1285 .mode = 0444,
1336 .proc_handler = &proc_do_uuid, 1286 .proc_handler = proc_do_uuid,
1337 .strategy = &uuid_strategy,
1338 }, 1287 },
1339 { 1288 {
1340 .ctl_name = RANDOM_UUID,
1341 .procname = "uuid", 1289 .procname = "uuid",
1342 .maxlen = 16, 1290 .maxlen = 16,
1343 .mode = 0444, 1291 .mode = 0444,
1344 .proc_handler = &proc_do_uuid, 1292 .proc_handler = proc_do_uuid,
1345 .strategy = &uuid_strategy,
1346 }, 1293 },
1347 { .ctl_name = 0 } 1294 { }
1348}; 1295};
1349#endif /* CONFIG_SYSCTL */ 1296#endif /* CONFIG_SYSCTL */
1350 1297
1351/******************************************************************** 1298/********************************************************************
1352 * 1299 *
1353 * Random funtions for networking 1300 * Random functions for networking
1354 * 1301 *
1355 ********************************************************************/ 1302 ********************************************************************/
1356 1303
diff --git a/drivers/char/raw.c b/drivers/char/raw.c
index 64acd05f71c8..8756ab0daa8b 100644
--- a/drivers/char/raw.c
+++ b/drivers/char/raw.c
@@ -20,6 +20,7 @@
20#include <linux/device.h> 20#include <linux/device.h>
21#include <linux/mutex.h> 21#include <linux/mutex.h>
22#include <linux/smp_lock.h> 22#include <linux/smp_lock.h>
23#include <linux/gfp.h>
23 24
24#include <asm/uaccess.h> 25#include <asm/uaccess.h>
25 26
@@ -247,6 +248,7 @@ static const struct file_operations raw_fops = {
247 .aio_read = generic_file_aio_read, 248 .aio_read = generic_file_aio_read,
248 .write = do_sync_write, 249 .write = do_sync_write,
249 .aio_write = blkdev_aio_write, 250 .aio_write = blkdev_aio_write,
251 .fsync = blkdev_fsync,
250 .open = raw_open, 252 .open = raw_open,
251 .release= raw_release, 253 .release= raw_release,
252 .ioctl = raw_ioctl, 254 .ioctl = raw_ioctl,
diff --git a/drivers/char/rio/rioinit.c b/drivers/char/rio/rioinit.c
index be0ba401966e..24a282bb89d4 100644
--- a/drivers/char/rio/rioinit.c
+++ b/drivers/char/rio/rioinit.c
@@ -31,7 +31,6 @@
31*/ 31*/
32 32
33#include <linux/module.h> 33#include <linux/module.h>
34#include <linux/slab.h>
35#include <linux/errno.h> 34#include <linux/errno.h>
36#include <linux/delay.h> 35#include <linux/delay.h>
37#include <asm/io.h> 36#include <asm/io.h>
diff --git a/drivers/char/rio/riointr.c b/drivers/char/rio/riointr.c
index 71f87600907c..2e71aecae206 100644
--- a/drivers/char/rio/riointr.c
+++ b/drivers/char/rio/riointr.c
@@ -31,7 +31,6 @@
31*/ 31*/
32 32
33#include <linux/module.h> 33#include <linux/module.h>
34#include <linux/slab.h>
35#include <linux/errno.h> 34#include <linux/errno.h>
36#include <linux/tty.h> 35#include <linux/tty.h>
37#include <linux/tty_flip.h> 36#include <linux/tty_flip.h>
diff --git a/drivers/char/rio/rioparam.c b/drivers/char/rio/rioparam.c
index d687c17be152..6415f3f32a72 100644
--- a/drivers/char/rio/rioparam.c
+++ b/drivers/char/rio/rioparam.c
@@ -31,7 +31,6 @@
31*/ 31*/
32 32
33#include <linux/module.h> 33#include <linux/module.h>
34#include <linux/slab.h>
35#include <linux/errno.h> 34#include <linux/errno.h>
36#include <linux/tty.h> 35#include <linux/tty.h>
37#include <asm/io.h> 36#include <asm/io.h>
diff --git a/drivers/char/rio/rioroute.c b/drivers/char/rio/rioroute.c
index 706c2a25f7aa..f9b936ac3394 100644
--- a/drivers/char/rio/rioroute.c
+++ b/drivers/char/rio/rioroute.c
@@ -31,7 +31,6 @@
31*/ 31*/
32 32
33#include <linux/module.h> 33#include <linux/module.h>
34#include <linux/slab.h>
35#include <linux/errno.h> 34#include <linux/errno.h>
36#include <asm/io.h> 35#include <asm/io.h>
37#include <asm/system.h> 36#include <asm/system.h>
diff --git a/drivers/char/rio/riotty.c b/drivers/char/rio/riotty.c
index 47fab7c33073..8a90393faf3c 100644
--- a/drivers/char/rio/riotty.c
+++ b/drivers/char/rio/riotty.c
@@ -34,7 +34,6 @@
34 34
35#include <linux/module.h> 35#include <linux/module.h>
36#include <linux/sched.h> 36#include <linux/sched.h>
37#include <linux/slab.h>
38#include <linux/errno.h> 37#include <linux/errno.h>
39#include <linux/tty.h> 38#include <linux/tty.h>
40#include <linux/string.h> 39#include <linux/string.h>
diff --git a/drivers/char/rio/route.h b/drivers/char/rio/route.h
index 20ed73f3fd7b..46e963771c30 100644
--- a/drivers/char/rio/route.h
+++ b/drivers/char/rio/route.h
@@ -67,7 +67,7 @@
67typedef struct COST_ROUTE COST_ROUTE; 67typedef struct COST_ROUTE COST_ROUTE;
68struct COST_ROUTE { 68struct COST_ROUTE {
69 unsigned char cost; /* Cost down this link */ 69 unsigned char cost; /* Cost down this link */
70 unsigned char route[NODE_BYTES]; /* Nodes thorough this route */ 70 unsigned char route[NODE_BYTES]; /* Nodes through this route */
71}; 71};
72 72
73typedef struct ROUTE_STR ROUTE_STR; 73typedef struct ROUTE_STR ROUTE_STR;
diff --git a/drivers/char/riscom8.c b/drivers/char/riscom8.c
index 3cfa22d469e0..b02332a5412f 100644
--- a/drivers/char/riscom8.c
+++ b/drivers/char/riscom8.c
@@ -793,26 +793,21 @@ static void rc_change_speed(struct tty_struct *tty, struct riscom_board *bp,
793} 793}
794 794
795/* Must be called with interrupts enabled */ 795/* Must be called with interrupts enabled */
796static int rc_setup_port(struct tty_struct *tty, struct riscom_board *bp, 796static int rc_activate_port(struct tty_port *port, struct tty_struct *tty)
797 struct riscom_port *port)
798{ 797{
798 struct riscom_port *rp = container_of(port, struct riscom_port, port);
799 struct riscom_board *bp = port_Board(rp);
799 unsigned long flags; 800 unsigned long flags;
800 801
801 if (port->port.flags & ASYNC_INITIALIZED) 802 if (tty_port_alloc_xmit_buf(port) < 0)
802 return 0;
803
804 if (tty_port_alloc_xmit_buf(&port->port) < 0)
805 return -ENOMEM; 803 return -ENOMEM;
806 804
807 spin_lock_irqsave(&riscom_lock, flags); 805 spin_lock_irqsave(&riscom_lock, flags);
808 806
809 clear_bit(TTY_IO_ERROR, &tty->flags); 807 clear_bit(TTY_IO_ERROR, &tty->flags);
810 if (port->port.count == 1) 808 bp->count++;
811 bp->count++; 809 rp->xmit_cnt = rp->xmit_head = rp->xmit_tail = 0;
812 port->xmit_cnt = port->xmit_head = port->xmit_tail = 0; 810 rc_change_speed(tty, bp, rp);
813 rc_change_speed(tty, bp, port);
814 port->port.flags |= ASYNC_INITIALIZED;
815
816 spin_unlock_irqrestore(&riscom_lock, flags); 811 spin_unlock_irqrestore(&riscom_lock, flags);
817 return 0; 812 return 0;
818} 813}
@@ -821,9 +816,6 @@ static int rc_setup_port(struct tty_struct *tty, struct riscom_board *bp,
821static void rc_shutdown_port(struct tty_struct *tty, 816static void rc_shutdown_port(struct tty_struct *tty,
822 struct riscom_board *bp, struct riscom_port *port) 817 struct riscom_board *bp, struct riscom_port *port)
823{ 818{
824 if (!(port->port.flags & ASYNC_INITIALIZED))
825 return;
826
827#ifdef RC_REPORT_OVERRUN 819#ifdef RC_REPORT_OVERRUN
828 printk(KERN_INFO "rc%d: port %d: Total %ld overruns were detected.\n", 820 printk(KERN_INFO "rc%d: port %d: Total %ld overruns were detected.\n",
829 board_No(bp), port_No(port), port->overrun); 821 board_No(bp), port_No(port), port->overrun);
@@ -840,11 +832,6 @@ static void rc_shutdown_port(struct tty_struct *tty,
840 } 832 }
841#endif 833#endif
842 tty_port_free_xmit_buf(&port->port); 834 tty_port_free_xmit_buf(&port->port);
843 if (C_HUPCL(tty)) {
844 /* Drop DTR */
845 bp->DTR |= (1u << port_No(port));
846 rc_out(bp, RC_DTR, bp->DTR);
847 }
848 835
849 /* Select port */ 836 /* Select port */
850 rc_out(bp, CD180_CAR, port_No(port)); 837 rc_out(bp, CD180_CAR, port_No(port));
@@ -856,7 +843,6 @@ static void rc_shutdown_port(struct tty_struct *tty,
856 rc_out(bp, CD180_IER, port->IER); 843 rc_out(bp, CD180_IER, port->IER);
857 844
858 set_bit(TTY_IO_ERROR, &tty->flags); 845 set_bit(TTY_IO_ERROR, &tty->flags);
859 port->port.flags &= ~ASYNC_INITIALIZED;
860 846
861 if (--bp->count < 0) { 847 if (--bp->count < 0) {
862 printk(KERN_INFO "rc%d: rc_shutdown_port: " 848 printk(KERN_INFO "rc%d: rc_shutdown_port: "
@@ -889,6 +875,20 @@ static int carrier_raised(struct tty_port *port)
889 return CD; 875 return CD;
890} 876}
891 877
878static void dtr_rts(struct tty_port *port, int onoff)
879{
880 struct riscom_port *p = container_of(port, struct riscom_port, port);
881 struct riscom_board *bp = port_Board(p);
882 unsigned long flags;
883
884 spin_lock_irqsave(&riscom_lock, flags);
885 bp->DTR &= ~(1u << port_No(p));
886 if (onoff == 0)
887 bp->DTR |= (1u << port_No(p));
888 rc_out(bp, RC_DTR, bp->DTR);
889 spin_unlock_irqrestore(&riscom_lock, flags);
890}
891
892static int rc_open(struct tty_struct *tty, struct file *filp) 892static int rc_open(struct tty_struct *tty, struct file *filp)
893{ 893{
894 int board; 894 int board;
@@ -909,14 +909,8 @@ static int rc_open(struct tty_struct *tty, struct file *filp)
909 if (error) 909 if (error)
910 return error; 910 return error;
911 911
912 port->port.count++;
913 tty->driver_data = port; 912 tty->driver_data = port;
914 tty_port_tty_set(&port->port, tty); 913 return tty_port_open(&port->port, tty, filp);
915
916 error = rc_setup_port(tty, bp, port);
917 if (error == 0)
918 error = tty_port_block_til_ready(&port->port, tty, filp);
919 return error;
920} 914}
921 915
922static void rc_flush_buffer(struct tty_struct *tty) 916static void rc_flush_buffer(struct tty_struct *tty)
@@ -950,24 +944,23 @@ static void rc_close_port(struct tty_port *port)
950 944
951 spin_lock_irqsave(&riscom_lock, flags); 945 spin_lock_irqsave(&riscom_lock, flags);
952 rp->IER &= ~IER_RXD; 946 rp->IER &= ~IER_RXD;
953 if (port->flags & ASYNC_INITIALIZED) { 947
954 rp->IER &= ~IER_TXRDY; 948 rp->IER &= ~IER_TXRDY;
955 rp->IER |= IER_TXEMPTY; 949 rp->IER |= IER_TXEMPTY;
956 rc_out(bp, CD180_CAR, port_No(rp)); 950 rc_out(bp, CD180_CAR, port_No(rp));
957 rc_out(bp, CD180_IER, rp->IER); 951 rc_out(bp, CD180_IER, rp->IER);
958 /* 952 /*
959 * Before we drop DTR, make sure the UART transmitter 953 * Before we drop DTR, make sure the UART transmitter
960 * has completely drained; this is especially 954 * has completely drained; this is especially
961 * important if there is a transmit FIFO! 955 * important if there is a transmit FIFO!
962 */ 956 */
963 timeout = jiffies + HZ; 957 timeout = jiffies + HZ;
964 while (rp->IER & IER_TXEMPTY) { 958 while (rp->IER & IER_TXEMPTY) {
965 spin_unlock_irqrestore(&riscom_lock, flags); 959 spin_unlock_irqrestore(&riscom_lock, flags);
966 msleep_interruptible(jiffies_to_msecs(rp->timeout)); 960 msleep_interruptible(jiffies_to_msecs(rp->timeout));
967 spin_lock_irqsave(&riscom_lock, flags); 961 spin_lock_irqsave(&riscom_lock, flags);
968 if (time_after(jiffies, timeout)) 962 if (time_after(jiffies, timeout))
969 break; 963 break;
970 }
971 } 964 }
972 rc_shutdown_port(port->tty, bp, rp); 965 rc_shutdown_port(port->tty, bp, rp);
973 spin_unlock_irqrestore(&riscom_lock, flags); 966 spin_unlock_irqrestore(&riscom_lock, flags);
@@ -1354,7 +1347,6 @@ static void rc_hangup(struct tty_struct *tty)
1354 if (rc_paranoia_check(port, tty->name, "rc_hangup")) 1347 if (rc_paranoia_check(port, tty->name, "rc_hangup"))
1355 return; 1348 return;
1356 1349
1357 rc_shutdown_port(tty, port_Board(port), port);
1358 tty_port_hangup(&port->port); 1350 tty_port_hangup(&port->port);
1359} 1351}
1360 1352
@@ -1401,7 +1393,9 @@ static const struct tty_operations riscom_ops = {
1401 1393
1402static const struct tty_port_operations riscom_port_ops = { 1394static const struct tty_port_operations riscom_port_ops = {
1403 .carrier_raised = carrier_raised, 1395 .carrier_raised = carrier_raised,
1396 .dtr_rts = dtr_rts,
1404 .shutdown = rc_close_port, 1397 .shutdown = rc_close_port,
1398 .activate = rc_activate_port,
1405}; 1399};
1406 1400
1407 1401
diff --git a/drivers/char/rtc.c b/drivers/char/rtc.c
index bc4ab3e54550..95acb8c880f4 100644
--- a/drivers/char/rtc.c
+++ b/drivers/char/rtc.c
@@ -282,34 +282,31 @@ static irqreturn_t rtc_interrupt(int irq, void *dev_id)
282 */ 282 */
283static ctl_table rtc_table[] = { 283static ctl_table rtc_table[] = {
284 { 284 {
285 .ctl_name = CTL_UNNUMBERED,
286 .procname = "max-user-freq", 285 .procname = "max-user-freq",
287 .data = &rtc_max_user_freq, 286 .data = &rtc_max_user_freq,
288 .maxlen = sizeof(int), 287 .maxlen = sizeof(int),
289 .mode = 0644, 288 .mode = 0644,
290 .proc_handler = &proc_dointvec, 289 .proc_handler = proc_dointvec,
291 }, 290 },
292 { .ctl_name = 0 } 291 { }
293}; 292};
294 293
295static ctl_table rtc_root[] = { 294static ctl_table rtc_root[] = {
296 { 295 {
297 .ctl_name = CTL_UNNUMBERED,
298 .procname = "rtc", 296 .procname = "rtc",
299 .mode = 0555, 297 .mode = 0555,
300 .child = rtc_table, 298 .child = rtc_table,
301 }, 299 },
302 { .ctl_name = 0 } 300 { }
303}; 301};
304 302
305static ctl_table dev_root[] = { 303static ctl_table dev_root[] = {
306 { 304 {
307 .ctl_name = CTL_DEV,
308 .procname = "dev", 305 .procname = "dev",
309 .mode = 0555, 306 .mode = 0555,
310 .child = rtc_root, 307 .child = rtc_root,
311 }, 308 },
312 { .ctl_name = 0 } 309 { }
313}; 310};
314 311
315static struct ctl_table_header *sysctl_header; 312static struct ctl_table_header *sysctl_header;
diff --git a/drivers/char/scx200_gpio.c b/drivers/char/scx200_gpio.c
index 1d9100561c8a..99e5272e3c53 100644
--- a/drivers/char/scx200_gpio.c
+++ b/drivers/char/scx200_gpio.c
@@ -12,7 +12,6 @@
12#include <linux/kernel.h> 12#include <linux/kernel.h>
13#include <linux/init.h> 13#include <linux/init.h>
14#include <linux/platform_device.h> 14#include <linux/platform_device.h>
15#include <linux/smp_lock.h>
16#include <asm/uaccess.h> 15#include <asm/uaccess.h>
17#include <asm/io.h> 16#include <asm/io.h>
18 17
@@ -52,7 +51,6 @@ static int scx200_gpio_open(struct inode *inode, struct file *file)
52 unsigned m = iminor(inode); 51 unsigned m = iminor(inode);
53 file->private_data = &scx200_gpio_ops; 52 file->private_data = &scx200_gpio_ops;
54 53
55 cycle_kernel_lock();
56 if (m >= MAX_PINS) 54 if (m >= MAX_PINS)
57 return -EINVAL; 55 return -EINVAL;
58 return nonseekable_open(inode, file); 56 return nonseekable_open(inode, file);
diff --git a/drivers/char/serial167.c b/drivers/char/serial167.c
index 452370af95de..8dfd24721a82 100644
--- a/drivers/char/serial167.c
+++ b/drivers/char/serial167.c
@@ -64,6 +64,7 @@
64#include <linux/module.h> 64#include <linux/module.h>
65#include <linux/bitops.h> 65#include <linux/bitops.h>
66#include <linux/tty_flip.h> 66#include <linux/tty_flip.h>
67#include <linux/gfp.h>
67 68
68#include <asm/system.h> 69#include <asm/system.h>
69#include <asm/io.h> 70#include <asm/io.h>
@@ -658,8 +659,7 @@ static irqreturn_t cd2401_rx_interrupt(int irq, void *dev_id)
658 info->mon.char_max = char_count; 659 info->mon.char_max = char_count;
659 info->mon.char_last = char_count; 660 info->mon.char_last = char_count;
660#endif 661#endif
661 len = tty_buffer_request_room(tty, char_count); 662 while (char_count--) {
662 while (len--) {
663 data = base_addr[CyRDR]; 663 data = base_addr[CyRDR];
664 tty_insert_flip_char(tty, data, TTY_NORMAL); 664 tty_insert_flip_char(tty, data, TTY_NORMAL);
665#ifdef CYCLOM_16Y_HACK 665#ifdef CYCLOM_16Y_HACK
@@ -1990,7 +1990,7 @@ void mvme167_serial_console_setup(int cflag)
1990 /* 1990 /*
1991 * Attempt to set up all channels to something reasonable, and 1991 * Attempt to set up all channels to something reasonable, and
1992 * bang out a INIT_CHAN command. We should then be able to limit 1992 * bang out a INIT_CHAN command. We should then be able to limit
1993 * the ammount of fiddling we have to do in normal running. 1993 * the amount of fiddling we have to do in normal running.
1994 */ 1994 */
1995 1995
1996 for (ch = 3; ch >= 0; ch--) { 1996 for (ch = 3; ch >= 0; ch--) {
diff --git a/drivers/char/snsc_event.c b/drivers/char/snsc_event.c
index 55a95892ccf9..ee156948b9f8 100644
--- a/drivers/char/snsc_event.c
+++ b/drivers/char/snsc_event.c
@@ -17,6 +17,7 @@
17 17
18#include <linux/interrupt.h> 18#include <linux/interrupt.h>
19#include <linux/sched.h> 19#include <linux/sched.h>
20#include <linux/slab.h>
20#include <asm/byteorder.h> 21#include <asm/byteorder.h>
21#include <asm/sn/sn_sal.h> 22#include <asm/sn/sn_sal.h>
22#include <asm/unaligned.h> 23#include <asm/unaligned.h>
diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
index 8c262aaf7c26..73f66d03624d 100644
--- a/drivers/char/sonypi.c
+++ b/drivers/char/sonypi.c
@@ -50,7 +50,7 @@
50#include <linux/err.h> 50#include <linux/err.h>
51#include <linux/kfifo.h> 51#include <linux/kfifo.h>
52#include <linux/platform_device.h> 52#include <linux/platform_device.h>
53#include <linux/smp_lock.h> 53#include <linux/gfp.h>
54 54
55#include <asm/uaccess.h> 55#include <asm/uaccess.h>
56#include <asm/io.h> 56#include <asm/io.h>
@@ -487,7 +487,7 @@ static struct sonypi_device {
487 int camera_power; 487 int camera_power;
488 int bluetooth_power; 488 int bluetooth_power;
489 struct mutex lock; 489 struct mutex lock;
490 struct kfifo *fifo; 490 struct kfifo fifo;
491 spinlock_t fifo_lock; 491 spinlock_t fifo_lock;
492 wait_queue_head_t fifo_proc_list; 492 wait_queue_head_t fifo_proc_list;
493 struct fasync_struct *fifo_async; 493 struct fasync_struct *fifo_async;
@@ -496,7 +496,7 @@ static struct sonypi_device {
496 struct input_dev *input_jog_dev; 496 struct input_dev *input_jog_dev;
497 struct input_dev *input_key_dev; 497 struct input_dev *input_key_dev;
498 struct work_struct input_work; 498 struct work_struct input_work;
499 struct kfifo *input_fifo; 499 struct kfifo input_fifo;
500 spinlock_t input_fifo_lock; 500 spinlock_t input_fifo_lock;
501} sonypi_device; 501} sonypi_device;
502 502
@@ -777,8 +777,9 @@ static void input_keyrelease(struct work_struct *work)
777{ 777{
778 struct sonypi_keypress kp; 778 struct sonypi_keypress kp;
779 779
780 while (kfifo_get(sonypi_device.input_fifo, (unsigned char *)&kp, 780 while (kfifo_out_locked(&sonypi_device.input_fifo, (unsigned char *)&kp,
781 sizeof(kp)) == sizeof(kp)) { 781 sizeof(kp), &sonypi_device.input_fifo_lock)
782 == sizeof(kp)) {
782 msleep(10); 783 msleep(10);
783 input_report_key(kp.dev, kp.key, 0); 784 input_report_key(kp.dev, kp.key, 0);
784 input_sync(kp.dev); 785 input_sync(kp.dev);
@@ -827,8 +828,9 @@ static void sonypi_report_input_event(u8 event)
827 if (kp.dev) { 828 if (kp.dev) {
828 input_report_key(kp.dev, kp.key, 1); 829 input_report_key(kp.dev, kp.key, 1);
829 input_sync(kp.dev); 830 input_sync(kp.dev);
830 kfifo_put(sonypi_device.input_fifo, 831 kfifo_in_locked(&sonypi_device.input_fifo,
831 (unsigned char *)&kp, sizeof(kp)); 832 (unsigned char *)&kp, sizeof(kp),
833 &sonypi_device.input_fifo_lock);
832 schedule_work(&sonypi_device.input_work); 834 schedule_work(&sonypi_device.input_work);
833 } 835 }
834} 836}
@@ -880,7 +882,8 @@ found:
880 acpi_bus_generate_proc_event(sonypi_acpi_device, 1, event); 882 acpi_bus_generate_proc_event(sonypi_acpi_device, 1, event);
881#endif 883#endif
882 884
883 kfifo_put(sonypi_device.fifo, (unsigned char *)&event, sizeof(event)); 885 kfifo_in_locked(&sonypi_device.fifo, (unsigned char *)&event,
886 sizeof(event), &sonypi_device.fifo_lock);
884 kill_fasync(&sonypi_device.fifo_async, SIGIO, POLL_IN); 887 kill_fasync(&sonypi_device.fifo_async, SIGIO, POLL_IN);
885 wake_up_interruptible(&sonypi_device.fifo_proc_list); 888 wake_up_interruptible(&sonypi_device.fifo_proc_list);
886 889
@@ -902,14 +905,13 @@ static int sonypi_misc_release(struct inode *inode, struct file *file)
902 905
903static int sonypi_misc_open(struct inode *inode, struct file *file) 906static int sonypi_misc_open(struct inode *inode, struct file *file)
904{ 907{
905 lock_kernel();
906 mutex_lock(&sonypi_device.lock); 908 mutex_lock(&sonypi_device.lock);
907 /* Flush input queue on first open */ 909 /* Flush input queue on first open */
908 if (!sonypi_device.open_count) 910 if (!sonypi_device.open_count)
909 kfifo_reset(sonypi_device.fifo); 911 kfifo_reset(&sonypi_device.fifo);
910 sonypi_device.open_count++; 912 sonypi_device.open_count++;
911 mutex_unlock(&sonypi_device.lock); 913 mutex_unlock(&sonypi_device.lock);
912 unlock_kernel(); 914
913 return 0; 915 return 0;
914} 916}
915 917
@@ -919,17 +921,18 @@ static ssize_t sonypi_misc_read(struct file *file, char __user *buf,
919 ssize_t ret; 921 ssize_t ret;
920 unsigned char c; 922 unsigned char c;
921 923
922 if ((kfifo_len(sonypi_device.fifo) == 0) && 924 if ((kfifo_len(&sonypi_device.fifo) == 0) &&
923 (file->f_flags & O_NONBLOCK)) 925 (file->f_flags & O_NONBLOCK))
924 return -EAGAIN; 926 return -EAGAIN;
925 927
926 ret = wait_event_interruptible(sonypi_device.fifo_proc_list, 928 ret = wait_event_interruptible(sonypi_device.fifo_proc_list,
927 kfifo_len(sonypi_device.fifo) != 0); 929 kfifo_len(&sonypi_device.fifo) != 0);
928 if (ret) 930 if (ret)
929 return ret; 931 return ret;
930 932
931 while (ret < count && 933 while (ret < count &&
932 (kfifo_get(sonypi_device.fifo, &c, sizeof(c)) == sizeof(c))) { 934 (kfifo_out_locked(&sonypi_device.fifo, &c, sizeof(c),
935 &sonypi_device.fifo_lock) == sizeof(c))) {
933 if (put_user(c, buf++)) 936 if (put_user(c, buf++))
934 return -EFAULT; 937 return -EFAULT;
935 ret++; 938 ret++;
@@ -946,15 +949,15 @@ static ssize_t sonypi_misc_read(struct file *file, char __user *buf,
946static unsigned int sonypi_misc_poll(struct file *file, poll_table *wait) 949static unsigned int sonypi_misc_poll(struct file *file, poll_table *wait)
947{ 950{
948 poll_wait(file, &sonypi_device.fifo_proc_list, wait); 951 poll_wait(file, &sonypi_device.fifo_proc_list, wait);
949 if (kfifo_len(sonypi_device.fifo)) 952 if (kfifo_len(&sonypi_device.fifo))
950 return POLLIN | POLLRDNORM; 953 return POLLIN | POLLRDNORM;
951 return 0; 954 return 0;
952} 955}
953 956
954static int sonypi_misc_ioctl(struct inode *ip, struct file *fp, 957static long sonypi_misc_ioctl(struct file *fp,
955 unsigned int cmd, unsigned long arg) 958 unsigned int cmd, unsigned long arg)
956{ 959{
957 int ret = 0; 960 long ret = 0;
958 void __user *argp = (void __user *)arg; 961 void __user *argp = (void __user *)arg;
959 u8 val8; 962 u8 val8;
960 u16 val16; 963 u16 val16;
@@ -1070,7 +1073,8 @@ static const struct file_operations sonypi_misc_fops = {
1070 .open = sonypi_misc_open, 1073 .open = sonypi_misc_open,
1071 .release = sonypi_misc_release, 1074 .release = sonypi_misc_release,
1072 .fasync = sonypi_misc_fasync, 1075 .fasync = sonypi_misc_fasync,
1073 .ioctl = sonypi_misc_ioctl, 1076 .unlocked_ioctl = sonypi_misc_ioctl,
1077 .llseek = no_llseek,
1074}; 1078};
1075 1079
1076static struct miscdevice sonypi_misc_device = { 1080static struct miscdevice sonypi_misc_device = {
@@ -1313,11 +1317,10 @@ static int __devinit sonypi_probe(struct platform_device *dev)
1313 "http://www.linux.it/~malattia/wiki/index.php/Sony_drivers\n"); 1317 "http://www.linux.it/~malattia/wiki/index.php/Sony_drivers\n");
1314 1318
1315 spin_lock_init(&sonypi_device.fifo_lock); 1319 spin_lock_init(&sonypi_device.fifo_lock);
1316 sonypi_device.fifo = kfifo_alloc(SONYPI_BUF_SIZE, GFP_KERNEL, 1320 error = kfifo_alloc(&sonypi_device.fifo, SONYPI_BUF_SIZE, GFP_KERNEL);
1317 &sonypi_device.fifo_lock); 1321 if (error) {
1318 if (IS_ERR(sonypi_device.fifo)) {
1319 printk(KERN_ERR "sonypi: kfifo_alloc failed\n"); 1322 printk(KERN_ERR "sonypi: kfifo_alloc failed\n");
1320 return PTR_ERR(sonypi_device.fifo); 1323 return error;
1321 } 1324 }
1322 1325
1323 init_waitqueue_head(&sonypi_device.fifo_proc_list); 1326 init_waitqueue_head(&sonypi_device.fifo_proc_list);
@@ -1393,12 +1396,10 @@ static int __devinit sonypi_probe(struct platform_device *dev)
1393 } 1396 }
1394 1397
1395 spin_lock_init(&sonypi_device.input_fifo_lock); 1398 spin_lock_init(&sonypi_device.input_fifo_lock);
1396 sonypi_device.input_fifo = 1399 error = kfifo_alloc(&sonypi_device.input_fifo, SONYPI_BUF_SIZE,
1397 kfifo_alloc(SONYPI_BUF_SIZE, GFP_KERNEL, 1400 GFP_KERNEL);
1398 &sonypi_device.input_fifo_lock); 1401 if (error) {
1399 if (IS_ERR(sonypi_device.input_fifo)) {
1400 printk(KERN_ERR "sonypi: kfifo_alloc failed\n"); 1402 printk(KERN_ERR "sonypi: kfifo_alloc failed\n");
1401 error = PTR_ERR(sonypi_device.input_fifo);
1402 goto err_inpdev_unregister; 1403 goto err_inpdev_unregister;
1403 } 1404 }
1404 1405
@@ -1423,7 +1424,7 @@ static int __devinit sonypi_probe(struct platform_device *dev)
1423 pci_disable_device(pcidev); 1424 pci_disable_device(pcidev);
1424 err_put_pcidev: 1425 err_put_pcidev:
1425 pci_dev_put(pcidev); 1426 pci_dev_put(pcidev);
1426 kfifo_free(sonypi_device.fifo); 1427 kfifo_free(&sonypi_device.fifo);
1427 1428
1428 return error; 1429 return error;
1429} 1430}
@@ -1438,7 +1439,7 @@ static int __devexit sonypi_remove(struct platform_device *dev)
1438 if (useinput) { 1439 if (useinput) {
1439 input_unregister_device(sonypi_device.input_key_dev); 1440 input_unregister_device(sonypi_device.input_key_dev);
1440 input_unregister_device(sonypi_device.input_jog_dev); 1441 input_unregister_device(sonypi_device.input_jog_dev);
1441 kfifo_free(sonypi_device.input_fifo); 1442 kfifo_free(&sonypi_device.input_fifo);
1442 } 1443 }
1443 1444
1444 misc_deregister(&sonypi_misc_device); 1445 misc_deregister(&sonypi_misc_device);
@@ -1451,7 +1452,7 @@ static int __devexit sonypi_remove(struct platform_device *dev)
1451 pci_dev_put(sonypi_device.dev); 1452 pci_dev_put(sonypi_device.dev);
1452 } 1453 }
1453 1454
1454 kfifo_free(sonypi_device.fifo); 1455 kfifo_free(&sonypi_device.fifo);
1455 1456
1456 return 0; 1457 return 0;
1457} 1458}
diff --git a/drivers/char/specialix.c b/drivers/char/specialix.c
index 268e17f9ec3f..2c24fcdc722a 100644
--- a/drivers/char/specialix.c
+++ b/drivers/char/specialix.c
@@ -94,6 +94,7 @@
94#include <linux/pci.h> 94#include <linux/pci.h>
95#include <linux/init.h> 95#include <linux/init.h>
96#include <linux/uaccess.h> 96#include <linux/uaccess.h>
97#include <linux/gfp.h>
97 98
98#include "specialix_io8.h" 99#include "specialix_io8.h"
99#include "cd1865.h" 100#include "cd1865.h"
@@ -646,8 +647,6 @@ static void sx_receive(struct specialix_board *bp)
646 dprintk(SX_DEBUG_RX, "port: %p: count: %d\n", port, count); 647 dprintk(SX_DEBUG_RX, "port: %p: count: %d\n", port, count);
647 port->hits[count > 8 ? 9 : count]++; 648 port->hits[count > 8 ? 9 : count]++;
648 649
649 tty_buffer_request_room(tty, count);
650
651 while (count--) 650 while (count--)
652 tty_insert_flip_char(tty, sx_in(bp, CD186x_RDR), TTY_NORMAL); 651 tty_insert_flip_char(tty, sx_in(bp, CD186x_RDR), TTY_NORMAL);
653 tty_flip_buffer_push(tty); 652 tty_flip_buffer_push(tty);
diff --git a/drivers/char/stallion.c b/drivers/char/stallion.c
index db6dcfa35ba0..6049fd731924 100644
--- a/drivers/char/stallion.c
+++ b/drivers/char/stallion.c
@@ -407,7 +407,7 @@ static unsigned int stl_baudrates[] = {
407 * Declare all those functions in this driver! 407 * Declare all those functions in this driver!
408 */ 408 */
409 409
410static int stl_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, unsigned long arg); 410static long stl_memioctl(struct file *fp, unsigned int cmd, unsigned long arg);
411static int stl_brdinit(struct stlbrd *brdp); 411static int stl_brdinit(struct stlbrd *brdp);
412static int stl_getportstats(struct tty_struct *tty, struct stlport *portp, comstats_t __user *cp); 412static int stl_getportstats(struct tty_struct *tty, struct stlport *portp, comstats_t __user *cp);
413static int stl_clrportstats(struct stlport *portp, comstats_t __user *cp); 413static int stl_clrportstats(struct stlport *portp, comstats_t __user *cp);
@@ -607,7 +607,7 @@ static unsigned int sc26198_baudtable[] = {
607 */ 607 */
608static const struct file_operations stl_fsiomem = { 608static const struct file_operations stl_fsiomem = {
609 .owner = THIS_MODULE, 609 .owner = THIS_MODULE,
610 .ioctl = stl_memioctl, 610 .unlocked_ioctl = stl_memioctl,
611}; 611};
612 612
613static struct class *stallion_class; 613static struct class *stallion_class;
@@ -702,11 +702,28 @@ static struct stlbrd *stl_allocbrd(void)
702 702
703/*****************************************************************************/ 703/*****************************************************************************/
704 704
705static int stl_activate(struct tty_port *port, struct tty_struct *tty)
706{
707 struct stlport *portp = container_of(port, struct stlport, port);
708 if (!portp->tx.buf) {
709 portp->tx.buf = kmalloc(STL_TXBUFSIZE, GFP_KERNEL);
710 if (!portp->tx.buf)
711 return -ENOMEM;
712 portp->tx.head = portp->tx.buf;
713 portp->tx.tail = portp->tx.buf;
714 }
715 stl_setport(portp, tty->termios);
716 portp->sigs = stl_getsignals(portp);
717 stl_setsignals(portp, 1, 1);
718 stl_enablerxtx(portp, 1, 1);
719 stl_startrxtx(portp, 1, 0);
720 return 0;
721}
722
705static int stl_open(struct tty_struct *tty, struct file *filp) 723static int stl_open(struct tty_struct *tty, struct file *filp)
706{ 724{
707 struct stlport *portp; 725 struct stlport *portp;
708 struct stlbrd *brdp; 726 struct stlbrd *brdp;
709 struct tty_port *port;
710 unsigned int minordev, brdnr, panelnr; 727 unsigned int minordev, brdnr, panelnr;
711 int portnr; 728 int portnr;
712 729
@@ -736,33 +753,10 @@ static int stl_open(struct tty_struct *tty, struct file *filp)
736 portp = brdp->panels[panelnr]->ports[portnr]; 753 portp = brdp->panels[panelnr]->ports[portnr];
737 if (portp == NULL) 754 if (portp == NULL)
738 return -ENODEV; 755 return -ENODEV;
739 port = &portp->port;
740 756
741/*
742 * On the first open of the device setup the port hardware, and
743 * initialize the per port data structure.
744 */
745 tty_port_tty_set(port, tty);
746 tty->driver_data = portp; 757 tty->driver_data = portp;
747 port->count++; 758 return tty_port_open(&portp->port, tty, filp);
748 759
749 if ((port->flags & ASYNC_INITIALIZED) == 0) {
750 if (!portp->tx.buf) {
751 portp->tx.buf = kmalloc(STL_TXBUFSIZE, GFP_KERNEL);
752 if (!portp->tx.buf)
753 return -ENOMEM;
754 portp->tx.head = portp->tx.buf;
755 portp->tx.tail = portp->tx.buf;
756 }
757 stl_setport(portp, tty->termios);
758 portp->sigs = stl_getsignals(portp);
759 stl_setsignals(portp, 1, 1);
760 stl_enablerxtx(portp, 1, 1);
761 stl_startrxtx(portp, 1, 0);
762 clear_bit(TTY_IO_ERROR, &tty->flags);
763 port->flags |= ASYNC_INITIALIZED;
764 }
765 return tty_port_block_til_ready(port, tty, filp);
766} 760}
767 761
768/*****************************************************************************/ 762/*****************************************************************************/
@@ -826,38 +820,12 @@ static void stl_waituntilsent(struct tty_struct *tty, int timeout)
826 820
827/*****************************************************************************/ 821/*****************************************************************************/
828 822
829static void stl_close(struct tty_struct *tty, struct file *filp) 823static void stl_shutdown(struct tty_port *port)
830{ 824{
831 struct stlport *portp; 825 struct stlport *portp = container_of(port, struct stlport, port);
832 struct tty_port *port;
833 unsigned long flags;
834
835 pr_debug("stl_close(tty=%p,filp=%p)\n", tty, filp);
836
837 portp = tty->driver_data;
838 BUG_ON(portp == NULL);
839
840 port = &portp->port;
841
842 if (tty_port_close_start(port, tty, filp) == 0)
843 return;
844/*
845 * May want to wait for any data to drain before closing. The BUSY
846 * flag keeps track of whether we are still sending or not - it is
847 * very accurate for the cd1400, not quite so for the sc26198.
848 * (The sc26198 has no "end-of-data" interrupt only empty FIFO)
849 */
850 stl_waituntilsent(tty, (HZ / 2));
851
852 spin_lock_irqsave(&port->lock, flags);
853 portp->port.flags &= ~ASYNC_INITIALIZED;
854 spin_unlock_irqrestore(&port->lock, flags);
855
856 stl_disableintrs(portp); 826 stl_disableintrs(portp);
857 if (tty->termios->c_cflag & HUPCL)
858 stl_setsignals(portp, 0, 0);
859 stl_enablerxtx(portp, 0, 0); 827 stl_enablerxtx(portp, 0, 0);
860 stl_flushbuffer(tty); 828 stl_flush(portp);
861 portp->istate = 0; 829 portp->istate = 0;
862 if (portp->tx.buf != NULL) { 830 if (portp->tx.buf != NULL) {
863 kfree(portp->tx.buf); 831 kfree(portp->tx.buf);
@@ -865,9 +833,17 @@ static void stl_close(struct tty_struct *tty, struct file *filp)
865 portp->tx.head = NULL; 833 portp->tx.head = NULL;
866 portp->tx.tail = NULL; 834 portp->tx.tail = NULL;
867 } 835 }
836}
837
838static void stl_close(struct tty_struct *tty, struct file *filp)
839{
840 struct stlport*portp;
841 pr_debug("stl_close(tty=%p,filp=%p)\n", tty, filp);
868 842
869 tty_port_close_end(port, tty); 843 portp = tty->driver_data;
870 tty_port_tty_set(port, NULL); 844 if(portp == NULL)
845 return;
846 tty_port_close(&portp->port, tty, filp);
871} 847}
872 848
873/*****************************************************************************/ 849/*****************************************************************************/
@@ -1314,35 +1290,12 @@ static void stl_stop(struct tty_struct *tty)
1314 1290
1315static void stl_hangup(struct tty_struct *tty) 1291static void stl_hangup(struct tty_struct *tty)
1316{ 1292{
1317 struct stlport *portp; 1293 struct stlport *portp = tty->driver_data;
1318 struct tty_port *port;
1319 unsigned long flags;
1320
1321 pr_debug("stl_hangup(tty=%p)\n", tty); 1294 pr_debug("stl_hangup(tty=%p)\n", tty);
1322 1295
1323 portp = tty->driver_data;
1324 if (portp == NULL) 1296 if (portp == NULL)
1325 return; 1297 return;
1326 port = &portp->port; 1298 tty_port_hangup(&portp->port);
1327
1328 spin_lock_irqsave(&port->lock, flags);
1329 port->flags &= ~ASYNC_INITIALIZED;
1330 spin_unlock_irqrestore(&port->lock, flags);
1331
1332 stl_disableintrs(portp);
1333 if (tty->termios->c_cflag & HUPCL)
1334 stl_setsignals(portp, 0, 0);
1335 stl_enablerxtx(portp, 0, 0);
1336 stl_flushbuffer(tty);
1337 portp->istate = 0;
1338 set_bit(TTY_IO_ERROR, &tty->flags);
1339 if (portp->tx.buf != NULL) {
1340 kfree(portp->tx.buf);
1341 portp->tx.buf = NULL;
1342 portp->tx.head = NULL;
1343 portp->tx.tail = NULL;
1344 }
1345 tty_port_hangup(port);
1346} 1299}
1347 1300
1348/*****************************************************************************/ 1301/*****************************************************************************/
@@ -2486,18 +2439,19 @@ static int stl_getbrdstruct(struct stlbrd __user *arg)
2486 * collection. 2439 * collection.
2487 */ 2440 */
2488 2441
2489static int stl_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, unsigned long arg) 2442static long stl_memioctl(struct file *fp, unsigned int cmd, unsigned long arg)
2490{ 2443{
2491 int brdnr, rc; 2444 int brdnr, rc;
2492 void __user *argp = (void __user *)arg; 2445 void __user *argp = (void __user *)arg;
2493 2446
2494 pr_debug("stl_memioctl(ip=%p,fp=%p,cmd=%x,arg=%lx)\n", ip, fp, cmd,arg); 2447 pr_debug("stl_memioctl(fp=%p,cmd=%x,arg=%lx)\n", fp, cmd,arg);
2495 2448
2496 brdnr = iminor(ip); 2449 brdnr = iminor(fp->f_dentry->d_inode);
2497 if (brdnr >= STL_MAXBRDS) 2450 if (brdnr >= STL_MAXBRDS)
2498 return -ENODEV; 2451 return -ENODEV;
2499 rc = 0; 2452 rc = 0;
2500 2453
2454 lock_kernel();
2501 switch (cmd) { 2455 switch (cmd) {
2502 case COM_GETPORTSTATS: 2456 case COM_GETPORTSTATS:
2503 rc = stl_getportstats(NULL, NULL, argp); 2457 rc = stl_getportstats(NULL, NULL, argp);
@@ -2518,7 +2472,7 @@ static int stl_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, uns
2518 rc = -ENOIOCTLCMD; 2472 rc = -ENOIOCTLCMD;
2519 break; 2473 break;
2520 } 2474 }
2521 2475 unlock_kernel();
2522 return rc; 2476 return rc;
2523} 2477}
2524 2478
@@ -2549,6 +2503,8 @@ static const struct tty_operations stl_ops = {
2549static const struct tty_port_operations stl_port_ops = { 2503static const struct tty_port_operations stl_port_ops = {
2550 .carrier_raised = stl_carrier_raised, 2504 .carrier_raised = stl_carrier_raised,
2551 .dtr_rts = stl_dtr_rts, 2505 .dtr_rts = stl_dtr_rts,
2506 .activate = stl_activate,
2507 .shutdown = stl_shutdown,
2552}; 2508};
2553 2509
2554/*****************************************************************************/ 2510/*****************************************************************************/
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);
468static unsigned int tbuf_bytes(struct slgt_info *info); 468static unsigned int tbuf_bytes(struct slgt_info *info);
469static void reset_tbufs(struct slgt_info *info); 469static void reset_tbufs(struct slgt_info *info);
470static void tdma_reset(struct slgt_info *info); 470static void tdma_reset(struct slgt_info *info);
471static void tx_load(struct slgt_info *info, const char *buf, unsigned int count); 471static bool tx_load(struct slgt_info *info, const char *buf, unsigned int count);
472 472
473static void get_signals(struct slgt_info *info); 473static void get_signals(struct slgt_info *info);
474static void set_signals(struct slgt_info *info); 474static 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
848start:
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
868cleanup: 840cleanup:
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 */
2251static 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
2279static void isr_txeom(struct slgt_info *info, unsigned short status) 2275static 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 */
4777static void tx_load(struct slgt_info *info, const char *buf, unsigned int size) 4777static 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
4818static int register_test(struct slgt_info *info) 4844static 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/sysrq.c b/drivers/char/sysrq.c
index 44203ff599da..59de2525d303 100644
--- a/drivers/char/sysrq.c
+++ b/drivers/char/sysrq.c
@@ -38,6 +38,7 @@
38#include <linux/workqueue.h> 38#include <linux/workqueue.h>
39#include <linux/hrtimer.h> 39#include <linux/hrtimer.h>
40#include <linux/oom.h> 40#include <linux/oom.h>
41#include <linux/slab.h>
41 42
42#include <asm/ptrace.h> 43#include <asm/ptrace.h>
43#include <asm/irq_regs.h> 44#include <asm/irq_regs.h>
@@ -339,7 +340,7 @@ static struct sysrq_key_op sysrq_term_op = {
339 340
340static void moom_callback(struct work_struct *ignored) 341static void moom_callback(struct work_struct *ignored)
341{ 342{
342 out_of_memory(node_zonelist(0, GFP_KERNEL), GFP_KERNEL, 0); 343 out_of_memory(node_zonelist(0, GFP_KERNEL), GFP_KERNEL, 0, NULL);
343} 344}
344 345
345static DECLARE_WORK(moom_work, moom_callback); 346static DECLARE_WORK(moom_work, moom_callback);
diff --git a/drivers/char/tb0219.c b/drivers/char/tb0219.c
index b3ec9b10e292..cad4eb65f13d 100644
--- a/drivers/char/tb0219.c
+++ b/drivers/char/tb0219.c
@@ -21,7 +21,6 @@
21#include <linux/fs.h> 21#include <linux/fs.h>
22#include <linux/init.h> 22#include <linux/init.h>
23#include <linux/module.h> 23#include <linux/module.h>
24#include <linux/smp_lock.h>
25 24
26#include <asm/io.h> 25#include <asm/io.h>
27#include <asm/reboot.h> 26#include <asm/reboot.h>
@@ -38,7 +37,7 @@ MODULE_PARM_DESC(major, "Major device number");
38 37
39static void (*old_machine_restart)(char *command); 38static void (*old_machine_restart)(char *command);
40static void __iomem *tb0219_base; 39static void __iomem *tb0219_base;
41static spinlock_t tb0219_lock; 40static DEFINE_SPINLOCK(tb0219_lock);
42 41
43#define tb0219_read(offset) readw(tb0219_base + (offset)) 42#define tb0219_read(offset) readw(tb0219_base + (offset))
44#define tb0219_write(offset, value) writew((value), tb0219_base + (offset)) 43#define tb0219_write(offset, value) writew((value), tb0219_base + (offset))
@@ -237,7 +236,6 @@ static int tanbac_tb0219_open(struct inode *inode, struct file *file)
237{ 236{
238 unsigned int minor; 237 unsigned int minor;
239 238
240 cycle_kernel_lock();
241 minor = iminor(inode); 239 minor = iminor(inode);
242 switch (minor) { 240 switch (minor) {
243 case 0: 241 case 0:
@@ -306,8 +304,6 @@ static int __devinit tb0219_probe(struct platform_device *dev)
306 return retval; 304 return retval;
307 } 305 }
308 306
309 spin_lock_init(&tb0219_lock);
310
311 old_machine_restart = _machine_restart; 307 old_machine_restart = _machine_restart;
312 _machine_restart = tb0219_restart; 308 _machine_restart = tb0219_restart;
313 309
diff --git a/drivers/char/toshiba.c b/drivers/char/toshiba.c
index 663cd15d7c78..f8bc79f6de34 100644
--- a/drivers/char/toshiba.c
+++ b/drivers/char/toshiba.c
@@ -68,7 +68,7 @@
68#include <linux/stat.h> 68#include <linux/stat.h>
69#include <linux/proc_fs.h> 69#include <linux/proc_fs.h>
70#include <linux/seq_file.h> 70#include <linux/seq_file.h>
71 71#include <linux/smp_lock.h>
72#include <linux/toshiba.h> 72#include <linux/toshiba.h>
73 73
74#define TOSH_MINOR_DEV 181 74#define TOSH_MINOR_DEV 181
@@ -88,13 +88,13 @@ static int tosh_date;
88static int tosh_sci; 88static int tosh_sci;
89static int tosh_fan; 89static int tosh_fan;
90 90
91static int tosh_ioctl(struct inode *, struct file *, unsigned int, 91static long tosh_ioctl(struct file *, unsigned int,
92 unsigned long); 92 unsigned long);
93 93
94 94
95static const struct file_operations tosh_fops = { 95static const struct file_operations tosh_fops = {
96 .owner = THIS_MODULE, 96 .owner = THIS_MODULE,
97 .ioctl = tosh_ioctl, 97 .unlocked_ioctl = tosh_ioctl,
98}; 98};
99 99
100static struct miscdevice tosh_device = { 100static struct miscdevice tosh_device = {
@@ -252,8 +252,7 @@ int tosh_smm(SMMRegisters *regs)
252EXPORT_SYMBOL(tosh_smm); 252EXPORT_SYMBOL(tosh_smm);
253 253
254 254
255static int tosh_ioctl(struct inode *ip, struct file *fp, unsigned int cmd, 255static long tosh_ioctl(struct file *fp, unsigned int cmd, unsigned long arg)
256 unsigned long arg)
257{ 256{
258 SMMRegisters regs; 257 SMMRegisters regs;
259 SMMRegisters __user *argp = (SMMRegisters __user *)arg; 258 SMMRegisters __user *argp = (SMMRegisters __user *)arg;
@@ -275,13 +274,16 @@ static int tosh_ioctl(struct inode *ip, struct file *fp, unsigned int cmd,
275 return -EINVAL; 274 return -EINVAL;
276 275
277 /* do we need to emulate the fan ? */ 276 /* do we need to emulate the fan ? */
277 lock_kernel();
278 if (tosh_fan==1) { 278 if (tosh_fan==1) {
279 if (((ax==0xf300) || (ax==0xf400)) && (bx==0x0004)) { 279 if (((ax==0xf300) || (ax==0xf400)) && (bx==0x0004)) {
280 err = tosh_emulate_fan(&regs); 280 err = tosh_emulate_fan(&regs);
281 unlock_kernel();
281 break; 282 break;
282 } 283 }
283 } 284 }
284 err = tosh_smm(&regs); 285 err = tosh_smm(&regs);
286 unlock_kernel();
285 break; 287 break;
286 default: 288 default:
287 return -EINVAL; 289 return -EINVAL;
diff --git a/drivers/char/tpm/tpm.c b/drivers/char/tpm/tpm.c
index 47c2d2763456..068c816e6942 100644
--- a/drivers/char/tpm/tpm.c
+++ b/drivers/char/tpm/tpm.c
@@ -24,6 +24,7 @@
24 */ 24 */
25 25
26#include <linux/poll.h> 26#include <linux/poll.h>
27#include <linux/slab.h>
27#include <linux/mutex.h> 28#include <linux/mutex.h>
28#include <linux/spinlock.h> 29#include <linux/spinlock.h>
29 30
@@ -31,7 +32,7 @@
31 32
32enum tpm_const { 33enum tpm_const {
33 TPM_MINOR = 224, /* officially assigned */ 34 TPM_MINOR = 224, /* officially assigned */
34 TPM_BUFSIZE = 2048, 35 TPM_BUFSIZE = 4096,
35 TPM_NUM_DEVICES = 256, 36 TPM_NUM_DEVICES = 256,
36}; 37};
37 38
diff --git a/drivers/char/tpm/tpm_bios.c b/drivers/char/tpm/tpm_bios.c
index bf2170fb1cdd..0636520fa9bf 100644
--- a/drivers/char/tpm/tpm_bios.c
+++ b/drivers/char/tpm/tpm_bios.c
@@ -22,6 +22,7 @@
22#include <linux/fs.h> 22#include <linux/fs.h>
23#include <linux/security.h> 23#include <linux/security.h>
24#include <linux/module.h> 24#include <linux/module.h>
25#include <linux/slab.h>
25#include <acpi/acpi.h> 26#include <acpi/acpi.h>
26#include "tpm.h" 27#include "tpm.h"
27 28
diff --git a/drivers/char/tpm/tpm_infineon.c b/drivers/char/tpm/tpm_infineon.c
index ecba4942fc8e..f58440791e65 100644
--- a/drivers/char/tpm/tpm_infineon.c
+++ b/drivers/char/tpm/tpm_infineon.c
@@ -39,12 +39,12 @@
39struct tpm_inf_dev { 39struct tpm_inf_dev {
40 int iotype; 40 int iotype;
41 41
42 void __iomem *mem_base; /* MMIO ioremap'd addr */ 42 void __iomem *mem_base; /* MMIO ioremap'd addr */
43 unsigned long map_base; /* phys MMIO base */ 43 unsigned long map_base; /* phys MMIO base */
44 unsigned long map_size; /* MMIO region size */ 44 unsigned long map_size; /* MMIO region size */
45 unsigned int index_off; /* index register offset */ 45 unsigned int index_off; /* index register offset */
46 46
47 unsigned int data_regs; /* Data registers */ 47 unsigned int data_regs; /* Data registers */
48 unsigned int data_size; 48 unsigned int data_size;
49 49
50 unsigned int config_port; /* IO Port config index reg */ 50 unsigned int config_port; /* IO Port config index reg */
@@ -406,14 +406,14 @@ static const struct tpm_vendor_specific tpm_inf = {
406 .miscdev = {.fops = &inf_ops,}, 406 .miscdev = {.fops = &inf_ops,},
407}; 407};
408 408
409static const struct pnp_device_id tpm_pnp_tbl[] = { 409static const struct pnp_device_id tpm_inf_pnp_tbl[] = {
410 /* Infineon TPMs */ 410 /* Infineon TPMs */
411 {"IFX0101", 0}, 411 {"IFX0101", 0},
412 {"IFX0102", 0}, 412 {"IFX0102", 0},
413 {"", 0} 413 {"", 0}
414}; 414};
415 415
416MODULE_DEVICE_TABLE(pnp, tpm_pnp_tbl); 416MODULE_DEVICE_TABLE(pnp, tpm_inf_pnp_tbl);
417 417
418static int __devinit tpm_inf_pnp_probe(struct pnp_dev *dev, 418static int __devinit tpm_inf_pnp_probe(struct pnp_dev *dev,
419 const struct pnp_device_id *dev_id) 419 const struct pnp_device_id *dev_id)
@@ -430,7 +430,7 @@ static int __devinit tpm_inf_pnp_probe(struct pnp_dev *dev,
430 if (pnp_port_valid(dev, 0) && pnp_port_valid(dev, 1) && 430 if (pnp_port_valid(dev, 0) && pnp_port_valid(dev, 1) &&
431 !(pnp_port_flags(dev, 0) & IORESOURCE_DISABLED)) { 431 !(pnp_port_flags(dev, 0) & IORESOURCE_DISABLED)) {
432 432
433 tpm_dev.iotype = TPM_INF_IO_PORT; 433 tpm_dev.iotype = TPM_INF_IO_PORT;
434 434
435 tpm_dev.config_port = pnp_port_start(dev, 0); 435 tpm_dev.config_port = pnp_port_start(dev, 0);
436 tpm_dev.config_size = pnp_port_len(dev, 0); 436 tpm_dev.config_size = pnp_port_len(dev, 0);
@@ -459,9 +459,9 @@ static int __devinit tpm_inf_pnp_probe(struct pnp_dev *dev,
459 goto err_last; 459 goto err_last;
460 } 460 }
461 } else if (pnp_mem_valid(dev, 0) && 461 } else if (pnp_mem_valid(dev, 0) &&
462 !(pnp_mem_flags(dev, 0) & IORESOURCE_DISABLED)) { 462 !(pnp_mem_flags(dev, 0) & IORESOURCE_DISABLED)) {
463 463
464 tpm_dev.iotype = TPM_INF_IO_MEM; 464 tpm_dev.iotype = TPM_INF_IO_MEM;
465 465
466 tpm_dev.map_base = pnp_mem_start(dev, 0); 466 tpm_dev.map_base = pnp_mem_start(dev, 0);
467 tpm_dev.map_size = pnp_mem_len(dev, 0); 467 tpm_dev.map_size = pnp_mem_len(dev, 0);
@@ -563,11 +563,11 @@ static int __devinit tpm_inf_pnp_probe(struct pnp_dev *dev,
563 "product id 0x%02x%02x" 563 "product id 0x%02x%02x"
564 "%s\n", 564 "%s\n",
565 tpm_dev.iotype == TPM_INF_IO_PORT ? 565 tpm_dev.iotype == TPM_INF_IO_PORT ?
566 tpm_dev.config_port : 566 tpm_dev.config_port :
567 tpm_dev.map_base + tpm_dev.index_off, 567 tpm_dev.map_base + tpm_dev.index_off,
568 tpm_dev.iotype == TPM_INF_IO_PORT ? 568 tpm_dev.iotype == TPM_INF_IO_PORT ?
569 tpm_dev.data_regs : 569 tpm_dev.data_regs :
570 tpm_dev.map_base + tpm_dev.data_regs, 570 tpm_dev.map_base + tpm_dev.data_regs,
571 version[0], version[1], 571 version[0], version[1],
572 vendorid[0], vendorid[1], 572 vendorid[0], vendorid[1],
573 productid[0], productid[1], chipname); 573 productid[0], productid[1], chipname);
@@ -607,20 +607,55 @@ static __devexit void tpm_inf_pnp_remove(struct pnp_dev *dev)
607 iounmap(tpm_dev.mem_base); 607 iounmap(tpm_dev.mem_base);
608 release_mem_region(tpm_dev.map_base, tpm_dev.map_size); 608 release_mem_region(tpm_dev.map_base, tpm_dev.map_size);
609 } 609 }
610 tpm_dev_vendor_release(chip);
610 tpm_remove_hardware(chip->dev); 611 tpm_remove_hardware(chip->dev);
611 } 612 }
612} 613}
613 614
615static int tpm_inf_pnp_suspend(struct pnp_dev *dev, pm_message_t pm_state)
616{
617 struct tpm_chip *chip = pnp_get_drvdata(dev);
618 int rc;
619 if (chip) {
620 u8 savestate[] = {
621 0, 193, /* TPM_TAG_RQU_COMMAND */
622 0, 0, 0, 10, /* blob length (in bytes) */
623 0, 0, 0, 152 /* TPM_ORD_SaveState */
624 };
625 dev_info(&dev->dev, "saving TPM state\n");
626 rc = tpm_inf_send(chip, savestate, sizeof(savestate));
627 if (rc < 0) {
628 dev_err(&dev->dev, "error while saving TPM state\n");
629 return rc;
630 }
631 }
632 return 0;
633}
634
635static int tpm_inf_pnp_resume(struct pnp_dev *dev)
636{
637 /* Re-configure TPM after suspending */
638 tpm_config_out(ENABLE_REGISTER_PAIR, TPM_INF_ADDR);
639 tpm_config_out(IOLIMH, TPM_INF_ADDR);
640 tpm_config_out((tpm_dev.data_regs >> 8) & 0xff, TPM_INF_DATA);
641 tpm_config_out(IOLIML, TPM_INF_ADDR);
642 tpm_config_out((tpm_dev.data_regs & 0xff), TPM_INF_DATA);
643 /* activate register */
644 tpm_config_out(TPM_DAR, TPM_INF_ADDR);
645 tpm_config_out(0x01, TPM_INF_DATA);
646 tpm_config_out(DISABLE_REGISTER_PAIR, TPM_INF_ADDR);
647 /* disable RESET, LP and IRQC */
648 tpm_data_out(RESET_LP_IRQC_DISABLE, CMD);
649 return tpm_pm_resume(&dev->dev);
650}
651
614static struct pnp_driver tpm_inf_pnp_driver = { 652static struct pnp_driver tpm_inf_pnp_driver = {
615 .name = "tpm_inf_pnp", 653 .name = "tpm_inf_pnp",
616 .driver = { 654 .id_table = tpm_inf_pnp_tbl,
617 .owner = THIS_MODULE,
618 .suspend = tpm_pm_suspend,
619 .resume = tpm_pm_resume,
620 },
621 .id_table = tpm_pnp_tbl,
622 .probe = tpm_inf_pnp_probe, 655 .probe = tpm_inf_pnp_probe,
623 .remove = __devexit_p(tpm_inf_pnp_remove), 656 .suspend = tpm_inf_pnp_suspend,
657 .resume = tpm_inf_pnp_resume,
658 .remove = __devexit_p(tpm_inf_pnp_remove)
624}; 659};
625 660
626static int __init init_inf(void) 661static int __init init_inf(void)
@@ -638,5 +673,5 @@ module_exit(cleanup_inf);
638 673
639MODULE_AUTHOR("Marcel Selhorst <m.selhorst@sirrix.com>"); 674MODULE_AUTHOR("Marcel Selhorst <m.selhorst@sirrix.com>");
640MODULE_DESCRIPTION("Driver for Infineon TPM SLD 9630 TT 1.1 / SLB 9635 TT 1.2"); 675MODULE_DESCRIPTION("Driver for Infineon TPM SLD 9630 TT 1.1 / SLB 9635 TT 1.2");
641MODULE_VERSION("1.9"); 676MODULE_VERSION("1.9.2");
642MODULE_LICENSE("GPL"); 677MODULE_LICENSE("GPL");
diff --git a/drivers/char/tpm/tpm_nsc.c b/drivers/char/tpm/tpm_nsc.c
index 70efba2ee053..a605cb7dd898 100644
--- a/drivers/char/tpm/tpm_nsc.c
+++ b/drivers/char/tpm/tpm_nsc.c
@@ -20,6 +20,7 @@
20 */ 20 */
21 21
22#include <linux/platform_device.h> 22#include <linux/platform_device.h>
23#include <linux/slab.h>
23#include "tpm.h" 24#include "tpm.h"
24 25
25/* National definitions */ 26/* National definitions */
diff --git a/drivers/char/tpm/tpm_tis.c b/drivers/char/tpm/tpm_tis.c
index 0b73e4ec1add..94345994f8a6 100644
--- a/drivers/char/tpm/tpm_tis.c
+++ b/drivers/char/tpm/tpm_tis.c
@@ -22,6 +22,7 @@
22#include <linux/module.h> 22#include <linux/module.h>
23#include <linux/moduleparam.h> 23#include <linux/moduleparam.h>
24#include <linux/pnp.h> 24#include <linux/pnp.h>
25#include <linux/slab.h>
25#include <linux/interrupt.h> 26#include <linux/interrupt.h>
26#include <linux/wait.h> 27#include <linux/wait.h>
27#include "tpm.h" 28#include "tpm.h"
@@ -257,6 +258,10 @@ out:
257 return size; 258 return size;
258} 259}
259 260
261static int itpm;
262module_param(itpm, bool, 0444);
263MODULE_PARM_DESC(itpm, "Force iTPM workarounds (found on some Lenovo laptops)");
264
260/* 265/*
261 * If interrupts are used (signaled by an irq set in the vendor structure) 266 * If interrupts are used (signaled by an irq set in the vendor structure)
262 * tpm.c can skip polling for the data to be available as the interrupt is 267 * tpm.c can skip polling for the data to be available as the interrupt is
@@ -293,7 +298,7 @@ static int tpm_tis_send(struct tpm_chip *chip, u8 *buf, size_t len)
293 wait_for_stat(chip, TPM_STS_VALID, chip->vendor.timeout_c, 298 wait_for_stat(chip, TPM_STS_VALID, chip->vendor.timeout_c,
294 &chip->vendor.int_queue); 299 &chip->vendor.int_queue);
295 status = tpm_tis_status(chip); 300 status = tpm_tis_status(chip);
296 if ((status & TPM_STS_DATA_EXPECT) == 0) { 301 if (!itpm && (status & TPM_STS_DATA_EXPECT) == 0) {
297 rc = -EIO; 302 rc = -EIO;
298 goto out_err; 303 goto out_err;
299 } 304 }
@@ -467,6 +472,10 @@ static int tpm_tis_init(struct device *dev, resource_size_t start,
467 "1.2 TPM (device-id 0x%X, rev-id %d)\n", 472 "1.2 TPM (device-id 0x%X, rev-id %d)\n",
468 vendor >> 16, ioread8(chip->vendor.iobase + TPM_RID(0))); 473 vendor >> 16, ioread8(chip->vendor.iobase + TPM_RID(0)));
469 474
475 if (itpm)
476 dev_info(dev, "Intel iTPM workaround enabled\n");
477
478
470 /* Figure out the capabilities */ 479 /* Figure out the capabilities */
471 intfcaps = 480 intfcaps =
472 ioread32(chip->vendor.iobase + 481 ioread32(chip->vendor.iobase +
@@ -629,6 +638,7 @@ static struct pnp_device_id tpm_pnp_tbl[] __devinitdata = {
629 {"", 0}, /* User Specified */ 638 {"", 0}, /* User Specified */
630 {"", 0} /* Terminator */ 639 {"", 0} /* Terminator */
631}; 640};
641MODULE_DEVICE_TABLE(pnp, tpm_pnp_tbl);
632 642
633static __devexit void tpm_tis_pnp_remove(struct pnp_dev *dev) 643static __devexit void tpm_tis_pnp_remove(struct pnp_dev *dev)
634{ 644{
diff --git a/drivers/char/tty_audit.c b/drivers/char/tty_audit.c
index ac16fbec72d0..1b8ee590b4ca 100644
--- a/drivers/char/tty_audit.c
+++ b/drivers/char/tty_audit.c
@@ -10,6 +10,7 @@
10 */ 10 */
11 11
12#include <linux/audit.h> 12#include <linux/audit.h>
13#include <linux/slab.h>
13#include <linux/tty.h> 14#include <linux/tty.h>
14 15
15struct tty_audit_buf { 16struct tty_audit_buf {
@@ -148,7 +149,6 @@ void tty_audit_fork(struct signal_struct *sig)
148 spin_lock_irq(&current->sighand->siglock); 149 spin_lock_irq(&current->sighand->siglock);
149 sig->audit_tty = current->signal->audit_tty; 150 sig->audit_tty = current->signal->audit_tty;
150 spin_unlock_irq(&current->sighand->siglock); 151 spin_unlock_irq(&current->sighand->siglock);
151 sig->tty_audit_buf = NULL;
152} 152}
153 153
154/** 154/**
diff --git a/drivers/char/tty_buffer.c b/drivers/char/tty_buffer.c
index 66fa4e10d76b..7ee52164d474 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)
231EXPORT_SYMBOL_GPL(tty_buffer_request_room); 231EXPORT_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
245int tty_insert_flip_string(struct tty_struct *tty, const unsigned char *chars, 246int 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_t(size_t, 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}
265EXPORT_SYMBOL(tty_insert_flip_string); 267EXPORT_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_t(size_t, 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_io.c b/drivers/char/tty_io.c
index 59499ee0fe6a..d71f0fc34b46 100644
--- a/drivers/char/tty_io.c
+++ b/drivers/char/tty_io.c
@@ -142,7 +142,6 @@ ssize_t redirected_tty_write(struct file *, const char __user *,
142 size_t, loff_t *); 142 size_t, loff_t *);
143static unsigned int tty_poll(struct file *, poll_table *); 143static unsigned int tty_poll(struct file *, poll_table *);
144static int tty_open(struct inode *, struct file *); 144static int tty_open(struct inode *, struct file *);
145static int tty_release(struct inode *, struct file *);
146long tty_ioctl(struct file *file, unsigned int cmd, unsigned long arg); 145long tty_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
147#ifdef CONFIG_COMPAT 146#ifdef CONFIG_COMPAT
148static long tty_compat_ioctl(struct file *file, unsigned int cmd, 147static long tty_compat_ioctl(struct file *file, unsigned int cmd,
@@ -506,8 +505,6 @@ static void do_tty_hangup(struct work_struct *work)
506 if (!tty) 505 if (!tty)
507 return; 506 return;
508 507
509 /* inuse_filps is protected by the single kernel lock */
510 lock_kernel();
511 508
512 spin_lock(&redirect_lock); 509 spin_lock(&redirect_lock);
513 if (redirect && redirect->private_data == tty) { 510 if (redirect && redirect->private_data == tty) {
@@ -516,7 +513,10 @@ static void do_tty_hangup(struct work_struct *work)
516 } 513 }
517 spin_unlock(&redirect_lock); 514 spin_unlock(&redirect_lock);
518 515
516 /* inuse_filps is protected by the single kernel lock */
517 lock_kernel();
519 check_tty_count(tty, "do_tty_hangup"); 518 check_tty_count(tty, "do_tty_hangup");
519
520 file_list_lock(); 520 file_list_lock();
521 /* This breaks for file handles being sent over AF_UNIX sockets ? */ 521 /* This breaks for file handles being sent over AF_UNIX sockets ? */
522 list_for_each_entry(filp, &tty->tty_files, f_u.fu_list) { 522 list_for_each_entry(filp, &tty->tty_files, f_u.fu_list) {
@@ -708,6 +708,8 @@ void disassociate_ctty(int on_exit)
708 struct tty_struct *tty; 708 struct tty_struct *tty;
709 struct pid *tty_pgrp = NULL; 709 struct pid *tty_pgrp = NULL;
710 710
711 if (!current->signal->leader)
712 return;
711 713
712 tty = get_current_tty(); 714 tty = get_current_tty();
713 if (tty) { 715 if (tty) {
@@ -773,8 +775,7 @@ void no_tty(void)
773{ 775{
774 struct task_struct *tsk = current; 776 struct task_struct *tsk = current;
775 lock_kernel(); 777 lock_kernel();
776 if (tsk->signal->leader) 778 disassociate_ctty(0);
777 disassociate_ctty(0);
778 unlock_kernel(); 779 unlock_kernel();
779 proc_clear_tty(tsk); 780 proc_clear_tty(tsk);
780} 781}
@@ -1017,14 +1018,16 @@ out:
1017 1018
1018void tty_write_message(struct tty_struct *tty, char *msg) 1019void tty_write_message(struct tty_struct *tty, char *msg)
1019{ 1020{
1020 lock_kernel();
1021 if (tty) { 1021 if (tty) {
1022 mutex_lock(&tty->atomic_write_lock); 1022 mutex_lock(&tty->atomic_write_lock);
1023 if (tty->ops->write && !test_bit(TTY_CLOSING, &tty->flags)) 1023 lock_kernel();
1024 if (tty->ops->write && !test_bit(TTY_CLOSING, &tty->flags)) {
1025 unlock_kernel();
1024 tty->ops->write(tty, msg, strlen(msg)); 1026 tty->ops->write(tty, msg, strlen(msg));
1027 } else
1028 unlock_kernel();
1025 tty_write_unlock(tty); 1029 tty_write_unlock(tty);
1026 } 1030 }
1027 unlock_kernel();
1028 return; 1031 return;
1029} 1032}
1030 1033
@@ -1202,14 +1205,21 @@ static int tty_driver_install_tty(struct tty_driver *driver,
1202 struct tty_struct *tty) 1205 struct tty_struct *tty)
1203{ 1206{
1204 int idx = tty->index; 1207 int idx = tty->index;
1208 int ret;
1205 1209
1206 if (driver->ops->install) 1210 if (driver->ops->install) {
1207 return driver->ops->install(driver, tty); 1211 lock_kernel();
1212 ret = driver->ops->install(driver, tty);
1213 unlock_kernel();
1214 return ret;
1215 }
1208 1216
1209 if (tty_init_termios(tty) == 0) { 1217 if (tty_init_termios(tty) == 0) {
1218 lock_kernel();
1210 tty_driver_kref_get(driver); 1219 tty_driver_kref_get(driver);
1211 tty->count++; 1220 tty->count++;
1212 driver->ttys[idx] = tty; 1221 driver->ttys[idx] = tty;
1222 unlock_kernel();
1213 return 0; 1223 return 0;
1214 } 1224 }
1215 return -ENOMEM; 1225 return -ENOMEM;
@@ -1302,10 +1312,14 @@ struct tty_struct *tty_init_dev(struct tty_driver *driver, int idx,
1302 struct tty_struct *tty; 1312 struct tty_struct *tty;
1303 int retval; 1313 int retval;
1304 1314
1315 lock_kernel();
1305 /* Check if pty master is being opened multiple times */ 1316 /* Check if pty master is being opened multiple times */
1306 if (driver->subtype == PTY_TYPE_MASTER && 1317 if (driver->subtype == PTY_TYPE_MASTER &&
1307 (driver->flags & TTY_DRIVER_DEVPTS_MEM) && !first_ok) 1318 (driver->flags & TTY_DRIVER_DEVPTS_MEM) && !first_ok) {
1319 unlock_kernel();
1308 return ERR_PTR(-EIO); 1320 return ERR_PTR(-EIO);
1321 }
1322 unlock_kernel();
1309 1323
1310 /* 1324 /*
1311 * First time open is complex, especially for PTY devices. 1325 * First time open is complex, especially for PTY devices.
@@ -1335,7 +1349,6 @@ struct tty_struct *tty_init_dev(struct tty_driver *driver, int idx,
1335 * If we fail here just call release_tty to clean up. No need 1349 * If we fail here just call release_tty to clean up. No need
1336 * to decrement the use counts, as release_tty doesn't care. 1350 * to decrement the use counts, as release_tty doesn't care.
1337 */ 1351 */
1338
1339 retval = tty_ldisc_setup(tty, tty->link); 1352 retval = tty_ldisc_setup(tty, tty->link);
1340 if (retval) 1353 if (retval)
1341 goto release_mem_out; 1354 goto release_mem_out;
@@ -1350,7 +1363,9 @@ release_mem_out:
1350 if (printk_ratelimit()) 1363 if (printk_ratelimit())
1351 printk(KERN_INFO "tty_init_dev: ldisc open failed, " 1364 printk(KERN_INFO "tty_init_dev: ldisc open failed, "
1352 "clearing slot %d\n", idx); 1365 "clearing slot %d\n", idx);
1366 lock_kernel();
1353 release_tty(tty, idx); 1367 release_tty(tty, idx);
1368 unlock_kernel();
1354 return ERR_PTR(retval); 1369 return ERR_PTR(retval);
1355} 1370}
1356 1371
@@ -1408,6 +1423,8 @@ static void release_one_tty(struct work_struct *work)
1408 list_del_init(&tty->tty_files); 1423 list_del_init(&tty->tty_files);
1409 file_list_unlock(); 1424 file_list_unlock();
1410 1425
1426 put_pid(tty->pgrp);
1427 put_pid(tty->session);
1411 free_tty_struct(tty); 1428 free_tty_struct(tty);
1412} 1429}
1413 1430
@@ -1464,7 +1481,17 @@ static void release_tty(struct tty_struct *tty, int idx)
1464 tty_kref_put(tty); 1481 tty_kref_put(tty);
1465} 1482}
1466 1483
1467/* 1484/**
1485 * tty_release - vfs callback for close
1486 * @inode: inode of tty
1487 * @filp: file pointer for handle to tty
1488 *
1489 * Called the last time each file handle is closed that references
1490 * this tty. There may however be several such references.
1491 *
1492 * Locking:
1493 * Takes bkl. See tty_release_dev
1494 *
1468 * Even releasing the tty structures is a tricky business.. We have 1495 * Even releasing the tty structures is a tricky business.. We have
1469 * to be very careful that the structures are all released at the 1496 * to be very careful that the structures are all released at the
1470 * same time, as interrupts might otherwise get the wrong pointers. 1497 * same time, as interrupts might otherwise get the wrong pointers.
@@ -1472,20 +1499,20 @@ static void release_tty(struct tty_struct *tty, int idx)
1472 * WSH 09/09/97: rewritten to avoid some nasty race conditions that could 1499 * WSH 09/09/97: rewritten to avoid some nasty race conditions that could
1473 * lead to double frees or releasing memory still in use. 1500 * lead to double frees or releasing memory still in use.
1474 */ 1501 */
1475void tty_release_dev(struct file *filp) 1502
1503int tty_release(struct inode *inode, struct file *filp)
1476{ 1504{
1477 struct tty_struct *tty, *o_tty; 1505 struct tty_struct *tty, *o_tty;
1478 int pty_master, tty_closing, o_tty_closing, do_sleep; 1506 int pty_master, tty_closing, o_tty_closing, do_sleep;
1479 int devpts; 1507 int devpts;
1480 int idx; 1508 int idx;
1481 char buf[64]; 1509 char buf[64];
1482 struct inode *inode;
1483 1510
1484 inode = filp->f_path.dentry->d_inode;
1485 tty = (struct tty_struct *)filp->private_data; 1511 tty = (struct tty_struct *)filp->private_data;
1486 if (tty_paranoia_check(tty, inode, "tty_release_dev")) 1512 if (tty_paranoia_check(tty, inode, "tty_release_dev"))
1487 return; 1513 return 0;
1488 1514
1515 lock_kernel();
1489 check_tty_count(tty, "tty_release_dev"); 1516 check_tty_count(tty, "tty_release_dev");
1490 1517
1491 tty_fasync(-1, filp, 0); 1518 tty_fasync(-1, filp, 0);
@@ -1500,19 +1527,22 @@ void tty_release_dev(struct file *filp)
1500 if (idx < 0 || idx >= tty->driver->num) { 1527 if (idx < 0 || idx >= tty->driver->num) {
1501 printk(KERN_DEBUG "tty_release_dev: bad idx when trying to " 1528 printk(KERN_DEBUG "tty_release_dev: bad idx when trying to "
1502 "free (%s)\n", tty->name); 1529 "free (%s)\n", tty->name);
1503 return; 1530 unlock_kernel();
1531 return 0;
1504 } 1532 }
1505 if (!devpts) { 1533 if (!devpts) {
1506 if (tty != tty->driver->ttys[idx]) { 1534 if (tty != tty->driver->ttys[idx]) {
1535 unlock_kernel();
1507 printk(KERN_DEBUG "tty_release_dev: driver.table[%d] not tty " 1536 printk(KERN_DEBUG "tty_release_dev: driver.table[%d] not tty "
1508 "for (%s)\n", idx, tty->name); 1537 "for (%s)\n", idx, tty->name);
1509 return; 1538 return 0;
1510 } 1539 }
1511 if (tty->termios != tty->driver->termios[idx]) { 1540 if (tty->termios != tty->driver->termios[idx]) {
1541 unlock_kernel();
1512 printk(KERN_DEBUG "tty_release_dev: driver.termios[%d] not termios " 1542 printk(KERN_DEBUG "tty_release_dev: driver.termios[%d] not termios "
1513 "for (%s)\n", 1543 "for (%s)\n",
1514 idx, tty->name); 1544 idx, tty->name);
1515 return; 1545 return 0;
1516 } 1546 }
1517 } 1547 }
1518#endif 1548#endif
@@ -1526,26 +1556,30 @@ void tty_release_dev(struct file *filp)
1526 if (tty->driver->other && 1556 if (tty->driver->other &&
1527 !(tty->driver->flags & TTY_DRIVER_DEVPTS_MEM)) { 1557 !(tty->driver->flags & TTY_DRIVER_DEVPTS_MEM)) {
1528 if (o_tty != tty->driver->other->ttys[idx]) { 1558 if (o_tty != tty->driver->other->ttys[idx]) {
1559 unlock_kernel();
1529 printk(KERN_DEBUG "tty_release_dev: other->table[%d] " 1560 printk(KERN_DEBUG "tty_release_dev: other->table[%d] "
1530 "not o_tty for (%s)\n", 1561 "not o_tty for (%s)\n",
1531 idx, tty->name); 1562 idx, tty->name);
1532 return; 1563 return 0 ;
1533 } 1564 }
1534 if (o_tty->termios != tty->driver->other->termios[idx]) { 1565 if (o_tty->termios != tty->driver->other->termios[idx]) {
1566 unlock_kernel();
1535 printk(KERN_DEBUG "tty_release_dev: other->termios[%d] " 1567 printk(KERN_DEBUG "tty_release_dev: other->termios[%d] "
1536 "not o_termios for (%s)\n", 1568 "not o_termios for (%s)\n",
1537 idx, tty->name); 1569 idx, tty->name);
1538 return; 1570 return 0;
1539 } 1571 }
1540 if (o_tty->link != tty) { 1572 if (o_tty->link != tty) {
1573 unlock_kernel();
1541 printk(KERN_DEBUG "tty_release_dev: bad pty pointers\n"); 1574 printk(KERN_DEBUG "tty_release_dev: bad pty pointers\n");
1542 return; 1575 return 0;
1543 } 1576 }
1544 } 1577 }
1545#endif 1578#endif
1546 if (tty->ops->close) 1579 if (tty->ops->close)
1547 tty->ops->close(tty, filp); 1580 tty->ops->close(tty, filp);
1548 1581
1582 unlock_kernel();
1549 /* 1583 /*
1550 * Sanity check: if tty->count is going to zero, there shouldn't be 1584 * Sanity check: if tty->count is going to zero, there shouldn't be
1551 * any waiters on tty->read_wait or tty->write_wait. We test the 1585 * any waiters on tty->read_wait or tty->write_wait. We test the
@@ -1568,6 +1602,7 @@ void tty_release_dev(struct file *filp)
1568 opens on /dev/tty */ 1602 opens on /dev/tty */
1569 1603
1570 mutex_lock(&tty_mutex); 1604 mutex_lock(&tty_mutex);
1605 lock_kernel();
1571 tty_closing = tty->count <= 1; 1606 tty_closing = tty->count <= 1;
1572 o_tty_closing = o_tty && 1607 o_tty_closing = o_tty &&
1573 (o_tty->count <= (pty_master ? 1 : 0)); 1608 (o_tty->count <= (pty_master ? 1 : 0));
@@ -1598,6 +1633,7 @@ void tty_release_dev(struct file *filp)
1598 1633
1599 printk(KERN_WARNING "tty_release_dev: %s: read/write wait queue " 1634 printk(KERN_WARNING "tty_release_dev: %s: read/write wait queue "
1600 "active!\n", tty_name(tty, buf)); 1635 "active!\n", tty_name(tty, buf));
1636 unlock_kernel();
1601 mutex_unlock(&tty_mutex); 1637 mutex_unlock(&tty_mutex);
1602 schedule(); 1638 schedule();
1603 } 1639 }
@@ -1661,8 +1697,10 @@ void tty_release_dev(struct file *filp)
1661 mutex_unlock(&tty_mutex); 1697 mutex_unlock(&tty_mutex);
1662 1698
1663 /* check whether both sides are closing ... */ 1699 /* check whether both sides are closing ... */
1664 if (!tty_closing || (o_tty && !o_tty_closing)) 1700 if (!tty_closing || (o_tty && !o_tty_closing)) {
1665 return; 1701 unlock_kernel();
1702 return 0;
1703 }
1666 1704
1667#ifdef TTY_DEBUG_HANGUP 1705#ifdef TTY_DEBUG_HANGUP
1668 printk(KERN_DEBUG "freeing tty structure..."); 1706 printk(KERN_DEBUG "freeing tty structure...");
@@ -1680,10 +1718,12 @@ void tty_release_dev(struct file *filp)
1680 /* Make this pty number available for reallocation */ 1718 /* Make this pty number available for reallocation */
1681 if (devpts) 1719 if (devpts)
1682 devpts_kill_index(inode, idx); 1720 devpts_kill_index(inode, idx);
1721 unlock_kernel();
1722 return 0;
1683} 1723}
1684 1724
1685/** 1725/**
1686 * __tty_open - open a tty device 1726 * tty_open - open a tty device
1687 * @inode: inode of device file 1727 * @inode: inode of device file
1688 * @filp: file pointer to tty 1728 * @filp: file pointer to tty
1689 * 1729 *
@@ -1703,7 +1743,7 @@ void tty_release_dev(struct file *filp)
1703 * ->siglock protects ->signal/->sighand 1743 * ->siglock protects ->signal/->sighand
1704 */ 1744 */
1705 1745
1706static int __tty_open(struct inode *inode, struct file *filp) 1746static int tty_open(struct inode *inode, struct file *filp)
1707{ 1747{
1708 struct tty_struct *tty = NULL; 1748 struct tty_struct *tty = NULL;
1709 int noctty, retval; 1749 int noctty, retval;
@@ -1720,10 +1760,12 @@ retry_open:
1720 retval = 0; 1760 retval = 0;
1721 1761
1722 mutex_lock(&tty_mutex); 1762 mutex_lock(&tty_mutex);
1763 lock_kernel();
1723 1764
1724 if (device == MKDEV(TTYAUX_MAJOR, 0)) { 1765 if (device == MKDEV(TTYAUX_MAJOR, 0)) {
1725 tty = get_current_tty(); 1766 tty = get_current_tty();
1726 if (!tty) { 1767 if (!tty) {
1768 unlock_kernel();
1727 mutex_unlock(&tty_mutex); 1769 mutex_unlock(&tty_mutex);
1728 return -ENXIO; 1770 return -ENXIO;
1729 } 1771 }
@@ -1755,12 +1797,14 @@ retry_open:
1755 goto got_driver; 1797 goto got_driver;
1756 } 1798 }
1757 } 1799 }
1800 unlock_kernel();
1758 mutex_unlock(&tty_mutex); 1801 mutex_unlock(&tty_mutex);
1759 return -ENODEV; 1802 return -ENODEV;
1760 } 1803 }
1761 1804
1762 driver = get_tty_driver(device, &index); 1805 driver = get_tty_driver(device, &index);
1763 if (!driver) { 1806 if (!driver) {
1807 unlock_kernel();
1764 mutex_unlock(&tty_mutex); 1808 mutex_unlock(&tty_mutex);
1765 return -ENODEV; 1809 return -ENODEV;
1766 } 1810 }
@@ -1770,6 +1814,7 @@ got_driver:
1770 tty = tty_driver_lookup_tty(driver, inode, index); 1814 tty = tty_driver_lookup_tty(driver, inode, index);
1771 1815
1772 if (IS_ERR(tty)) { 1816 if (IS_ERR(tty)) {
1817 unlock_kernel();
1773 mutex_unlock(&tty_mutex); 1818 mutex_unlock(&tty_mutex);
1774 return PTR_ERR(tty); 1819 return PTR_ERR(tty);
1775 } 1820 }
@@ -1784,8 +1829,10 @@ got_driver:
1784 1829
1785 mutex_unlock(&tty_mutex); 1830 mutex_unlock(&tty_mutex);
1786 tty_driver_kref_put(driver); 1831 tty_driver_kref_put(driver);
1787 if (IS_ERR(tty)) 1832 if (IS_ERR(tty)) {
1833 unlock_kernel();
1788 return PTR_ERR(tty); 1834 return PTR_ERR(tty);
1835 }
1789 1836
1790 filp->private_data = tty; 1837 filp->private_data = tty;
1791 file_move(filp, &tty->tty_files); 1838 file_move(filp, &tty->tty_files);
@@ -1813,21 +1860,29 @@ got_driver:
1813 printk(KERN_DEBUG "error %d in opening %s...", retval, 1860 printk(KERN_DEBUG "error %d in opening %s...", retval,
1814 tty->name); 1861 tty->name);
1815#endif 1862#endif
1816 tty_release_dev(filp); 1863 tty_release(inode, filp);
1817 if (retval != -ERESTARTSYS) 1864 if (retval != -ERESTARTSYS) {
1865 unlock_kernel();
1818 return retval; 1866 return retval;
1819 if (signal_pending(current)) 1867 }
1868 if (signal_pending(current)) {
1869 unlock_kernel();
1820 return retval; 1870 return retval;
1871 }
1821 schedule(); 1872 schedule();
1822 /* 1873 /*
1823 * Need to reset f_op in case a hangup happened. 1874 * Need to reset f_op in case a hangup happened.
1824 */ 1875 */
1825 if (filp->f_op == &hung_up_tty_fops) 1876 if (filp->f_op == &hung_up_tty_fops)
1826 filp->f_op = &tty_fops; 1877 filp->f_op = &tty_fops;
1878 unlock_kernel();
1827 goto retry_open; 1879 goto retry_open;
1828 } 1880 }
1881 unlock_kernel();
1882
1829 1883
1830 mutex_lock(&tty_mutex); 1884 mutex_lock(&tty_mutex);
1885 lock_kernel();
1831 spin_lock_irq(&current->sighand->siglock); 1886 spin_lock_irq(&current->sighand->siglock);
1832 if (!noctty && 1887 if (!noctty &&
1833 current->signal->leader && 1888 current->signal->leader &&
@@ -1835,43 +1890,12 @@ got_driver:
1835 tty->session == NULL) 1890 tty->session == NULL)
1836 __proc_set_tty(current, tty); 1891 __proc_set_tty(current, tty);
1837 spin_unlock_irq(&current->sighand->siglock); 1892 spin_unlock_irq(&current->sighand->siglock);
1893 unlock_kernel();
1838 mutex_unlock(&tty_mutex); 1894 mutex_unlock(&tty_mutex);
1839 return 0; 1895 return 0;
1840} 1896}
1841 1897
1842/* BKL pushdown: scary code avoidance wrapper */
1843static int tty_open(struct inode *inode, struct file *filp)
1844{
1845 int ret;
1846
1847 lock_kernel();
1848 ret = __tty_open(inode, filp);
1849 unlock_kernel();
1850 return ret;
1851}
1852
1853
1854
1855
1856/**
1857 * tty_release - vfs callback for close
1858 * @inode: inode of tty
1859 * @filp: file pointer for handle to tty
1860 *
1861 * Called the last time each file handle is closed that references
1862 * this tty. There may however be several such references.
1863 *
1864 * Locking:
1865 * Takes bkl. See tty_release_dev
1866 */
1867 1898
1868static int tty_release(struct inode *inode, struct file *filp)
1869{
1870 lock_kernel();
1871 tty_release_dev(filp);
1872 unlock_kernel();
1873 return 0;
1874}
1875 1899
1876/** 1900/**
1877 * tty_poll - check tty status 1901 * tty_poll - check tty status
@@ -1930,8 +1954,10 @@ static int tty_fasync(int fd, struct file *filp, int on)
1930 pid = task_pid(current); 1954 pid = task_pid(current);
1931 type = PIDTYPE_PID; 1955 type = PIDTYPE_PID;
1932 } 1956 }
1957 get_pid(pid);
1933 spin_unlock_irqrestore(&tty->ctrl_lock, flags); 1958 spin_unlock_irqrestore(&tty->ctrl_lock, flags);
1934 retval = __f_setown(filp, pid, type, 0); 1959 retval = __f_setown(filp, pid, type, 0);
1960 put_pid(pid);
1935 if (retval) 1961 if (retval)
1936 goto out; 1962 goto out;
1937 } else { 1963 } else {
@@ -2005,7 +2031,7 @@ static int tiocgwinsz(struct tty_struct *tty, struct winsize __user *arg)
2005 * @rows: rows (character) 2031 * @rows: rows (character)
2006 * @cols: cols (character) 2032 * @cols: cols (character)
2007 * 2033 *
2008 * Update the termios variables and send the neccessary signals to 2034 * Update the termios variables and send the necessary signals to
2009 * peform a terminal resize correctly 2035 * peform a terminal resize correctly
2010 */ 2036 */
2011 2037
@@ -2317,9 +2343,7 @@ static int tiocsetd(struct tty_struct *tty, int __user *p)
2317 if (get_user(ldisc, p)) 2343 if (get_user(ldisc, p))
2318 return -EFAULT; 2344 return -EFAULT;
2319 2345
2320 lock_kernel();
2321 ret = tty_set_ldisc(tty, ldisc); 2346 ret = tty_set_ldisc(tty, ldisc);
2322 unlock_kernel();
2323 2347
2324 return ret; 2348 return ret;
2325} 2349}
diff --git a/drivers/char/tty_ioctl.c b/drivers/char/tty_ioctl.c
index 8e67d5c642a4..6bd5f8866c74 100644
--- a/drivers/char/tty_ioctl.c
+++ b/drivers/char/tty_ioctl.c
@@ -315,7 +315,7 @@ EXPORT_SYMBOL(tty_termios_input_baud_rate);
315 * For maximal back compatibility with legacy SYS5/POSIX *nix behaviour 315 * For maximal back compatibility with legacy SYS5/POSIX *nix behaviour
316 * we need to carefully set the bits when the user does not get the 316 * we need to carefully set the bits when the user does not get the
317 * desired speed. We allow small margins and preserve as much of possible 317 * desired speed. We allow small margins and preserve as much of possible
318 * of the input intent to keep compatiblity. 318 * of the input intent to keep compatibility.
319 * 319 *
320 * Locking: Caller should hold termios lock. This is already held 320 * Locking: Caller should hold termios lock. This is already held
321 * when calling this function from the driver termios handler. 321 * when calling this function from the driver termios handler.
diff --git a/drivers/char/tty_ldisc.c b/drivers/char/tty_ldisc.c
index feb55075819b..500e740ec5e4 100644
--- a/drivers/char/tty_ldisc.c
+++ b/drivers/char/tty_ldisc.c
@@ -34,6 +34,8 @@
34#include <linux/vt_kern.h> 34#include <linux/vt_kern.h>
35#include <linux/selection.h> 35#include <linux/selection.h>
36 36
37#include <linux/smp_lock.h> /* For the moment */
38
37#include <linux/kmod.h> 39#include <linux/kmod.h>
38#include <linux/nsproxy.h> 40#include <linux/nsproxy.h>
39 41
@@ -443,8 +445,14 @@ static void tty_set_termios_ldisc(struct tty_struct *tty, int num)
443static int tty_ldisc_open(struct tty_struct *tty, struct tty_ldisc *ld) 445static int tty_ldisc_open(struct tty_struct *tty, struct tty_ldisc *ld)
444{ 446{
445 WARN_ON(test_and_set_bit(TTY_LDISC_OPEN, &tty->flags)); 447 WARN_ON(test_and_set_bit(TTY_LDISC_OPEN, &tty->flags));
446 if (ld->ops->open) 448 if (ld->ops->open) {
447 return ld->ops->open(tty); 449 int ret;
450 /* BKL here locks verus a hangup event */
451 lock_kernel();
452 ret = ld->ops->open(tty);
453 unlock_kernel();
454 return ret;
455 }
448 return 0; 456 return 0;
449} 457}
450 458
@@ -545,6 +553,7 @@ int tty_set_ldisc(struct tty_struct *tty, int ldisc)
545 if (IS_ERR(new_ldisc)) 553 if (IS_ERR(new_ldisc))
546 return PTR_ERR(new_ldisc); 554 return PTR_ERR(new_ldisc);
547 555
556 lock_kernel();
548 /* 557 /*
549 * We need to look at the tty locking here for pty/tty pairs 558 * We need to look at the tty locking here for pty/tty pairs
550 * when both sides try to change in parallel. 559 * when both sides try to change in parallel.
@@ -558,10 +567,12 @@ int tty_set_ldisc(struct tty_struct *tty, int ldisc)
558 */ 567 */
559 568
560 if (tty->ldisc->ops->num == ldisc) { 569 if (tty->ldisc->ops->num == ldisc) {
570 unlock_kernel();
561 tty_ldisc_put(new_ldisc); 571 tty_ldisc_put(new_ldisc);
562 return 0; 572 return 0;
563 } 573 }
564 574
575 unlock_kernel();
565 /* 576 /*
566 * Problem: What do we do if this blocks ? 577 * Problem: What do we do if this blocks ?
567 * We could deadlock here 578 * We could deadlock here
@@ -582,6 +593,9 @@ int tty_set_ldisc(struct tty_struct *tty, int ldisc)
582 test_bit(TTY_LDISC_CHANGING, &tty->flags) == 0); 593 test_bit(TTY_LDISC_CHANGING, &tty->flags) == 0);
583 mutex_lock(&tty->ldisc_mutex); 594 mutex_lock(&tty->ldisc_mutex);
584 } 595 }
596
597 lock_kernel();
598
585 set_bit(TTY_LDISC_CHANGING, &tty->flags); 599 set_bit(TTY_LDISC_CHANGING, &tty->flags);
586 600
587 /* 601 /*
@@ -592,6 +606,8 @@ int tty_set_ldisc(struct tty_struct *tty, int ldisc)
592 tty->receive_room = 0; 606 tty->receive_room = 0;
593 607
594 o_ldisc = tty->ldisc; 608 o_ldisc = tty->ldisc;
609
610 unlock_kernel();
595 /* 611 /*
596 * Make sure we don't change while someone holds a 612 * Make sure we don't change while someone holds a
597 * reference to the line discipline. The TTY_LDISC bit 613 * reference to the line discipline. The TTY_LDISC bit
@@ -617,12 +633,14 @@ int tty_set_ldisc(struct tty_struct *tty, int ldisc)
617 flush_scheduled_work(); 633 flush_scheduled_work();
618 634
619 mutex_lock(&tty->ldisc_mutex); 635 mutex_lock(&tty->ldisc_mutex);
636 lock_kernel();
620 if (test_bit(TTY_HUPPED, &tty->flags)) { 637 if (test_bit(TTY_HUPPED, &tty->flags)) {
621 /* We were raced by the hangup method. It will have stomped 638 /* We were raced by the hangup method. It will have stomped
622 the ldisc data and closed the ldisc down */ 639 the ldisc data and closed the ldisc down */
623 clear_bit(TTY_LDISC_CHANGING, &tty->flags); 640 clear_bit(TTY_LDISC_CHANGING, &tty->flags);
624 mutex_unlock(&tty->ldisc_mutex); 641 mutex_unlock(&tty->ldisc_mutex);
625 tty_ldisc_put(new_ldisc); 642 tty_ldisc_put(new_ldisc);
643 unlock_kernel();
626 return -EIO; 644 return -EIO;
627 } 645 }
628 646
@@ -664,6 +682,7 @@ int tty_set_ldisc(struct tty_struct *tty, int ldisc)
664 if (o_work) 682 if (o_work)
665 schedule_delayed_work(&o_tty->buf.work, 1); 683 schedule_delayed_work(&o_tty->buf.work, 1);
666 mutex_unlock(&tty->ldisc_mutex); 684 mutex_unlock(&tty->ldisc_mutex);
685 unlock_kernel();
667 return retval; 686 return retval;
668} 687}
669 688
@@ -687,12 +706,13 @@ static void tty_reset_termios(struct tty_struct *tty)
687/** 706/**
688 * tty_ldisc_reinit - reinitialise the tty ldisc 707 * tty_ldisc_reinit - reinitialise the tty ldisc
689 * @tty: tty to reinit 708 * @tty: tty to reinit
709 * @ldisc: line discipline to reinitialize
690 * 710 *
691 * Switch the tty back to N_TTY line discipline and leave the 711 * Switch the tty to a line discipline and leave the ldisc
692 * ldisc state closed 712 * state closed
693 */ 713 */
694 714
695static void tty_ldisc_reinit(struct tty_struct *tty) 715static void tty_ldisc_reinit(struct tty_struct *tty, int ldisc)
696{ 716{
697 struct tty_ldisc *ld; 717 struct tty_ldisc *ld;
698 718
@@ -702,10 +722,10 @@ static void tty_ldisc_reinit(struct tty_struct *tty)
702 /* 722 /*
703 * Switch the line discipline back 723 * Switch the line discipline back
704 */ 724 */
705 ld = tty_ldisc_get(N_TTY); 725 ld = tty_ldisc_get(ldisc);
706 BUG_ON(IS_ERR(ld)); 726 BUG_ON(IS_ERR(ld));
707 tty_ldisc_assign(tty, ld); 727 tty_ldisc_assign(tty, ld);
708 tty_set_termios_ldisc(tty, N_TTY); 728 tty_set_termios_ldisc(tty, ldisc);
709} 729}
710 730
711/** 731/**
@@ -726,6 +746,8 @@ static void tty_ldisc_reinit(struct tty_struct *tty)
726void tty_ldisc_hangup(struct tty_struct *tty) 746void tty_ldisc_hangup(struct tty_struct *tty)
727{ 747{
728 struct tty_ldisc *ld; 748 struct tty_ldisc *ld;
749 int reset = tty->driver->flags & TTY_DRIVER_RESET_TERMIOS;
750 int err = 0;
729 751
730 /* 752 /*
731 * FIXME! What are the locking issues here? This may me overdoing 753 * FIXME! What are the locking issues here? This may me overdoing
@@ -753,25 +775,32 @@ void tty_ldisc_hangup(struct tty_struct *tty)
753 wake_up_interruptible_poll(&tty->read_wait, POLLIN); 775 wake_up_interruptible_poll(&tty->read_wait, POLLIN);
754 /* 776 /*
755 * Shutdown the current line discipline, and reset it to 777 * Shutdown the current line discipline, and reset it to
756 * N_TTY. 778 * N_TTY if need be.
779 *
780 * Avoid racing set_ldisc or tty_ldisc_release
757 */ 781 */
758 if (tty->driver->flags & TTY_DRIVER_RESET_TERMIOS) { 782 mutex_lock(&tty->ldisc_mutex);
759 /* Avoid racing set_ldisc or tty_ldisc_release */ 783 tty_ldisc_halt(tty);
760 mutex_lock(&tty->ldisc_mutex); 784 /* At this point we have a closed ldisc and we want to
761 tty_ldisc_halt(tty); 785 reopen it. We could defer this to the next open but
762 if (tty->ldisc) { /* Not yet closed */ 786 it means auditing a lot of other paths so this is
763 /* Switch back to N_TTY */ 787 a FIXME */
764 tty_ldisc_reinit(tty); 788 if (tty->ldisc) { /* Not yet closed */
765 /* At this point we have a closed ldisc and we want to 789 if (reset == 0) {
766 reopen it. We could defer this to the next open but 790 tty_ldisc_reinit(tty, tty->termios->c_line);
767 it means auditing a lot of other paths so this is 791 err = tty_ldisc_open(tty, tty->ldisc);
768 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);
769 WARN_ON(tty_ldisc_open(tty, tty->ldisc)); 797 WARN_ON(tty_ldisc_open(tty, tty->ldisc));
770 tty_ldisc_enable(tty);
771 } 798 }
772 mutex_unlock(&tty->ldisc_mutex); 799 tty_ldisc_enable(tty);
773 tty_reset_termios(tty);
774 } 800 }
801 mutex_unlock(&tty->ldisc_mutex);
802 if (reset)
803 tty_reset_termios(tty);
775} 804}
776 805
777/** 806/**
diff --git a/drivers/char/tty_port.c b/drivers/char/tty_port.c
index c63f3d33914a..a3bd1d0b66cf 100644
--- a/drivers/char/tty_port.c
+++ b/drivers/char/tty_port.c
@@ -25,19 +25,21 @@ void tty_port_init(struct tty_port *port)
25 init_waitqueue_head(&port->close_wait); 25 init_waitqueue_head(&port->close_wait);
26 init_waitqueue_head(&port->delta_msr_wait); 26 init_waitqueue_head(&port->delta_msr_wait);
27 mutex_init(&port->mutex); 27 mutex_init(&port->mutex);
28 mutex_init(&port->buf_mutex);
28 spin_lock_init(&port->lock); 29 spin_lock_init(&port->lock);
29 port->close_delay = (50 * HZ) / 100; 30 port->close_delay = (50 * HZ) / 100;
30 port->closing_wait = (3000 * HZ) / 100; 31 port->closing_wait = (3000 * HZ) / 100;
32 kref_init(&port->kref);
31} 33}
32EXPORT_SYMBOL(tty_port_init); 34EXPORT_SYMBOL(tty_port_init);
33 35
34int tty_port_alloc_xmit_buf(struct tty_port *port) 36int tty_port_alloc_xmit_buf(struct tty_port *port)
35{ 37{
36 /* We may sleep in get_zeroed_page() */ 38 /* We may sleep in get_zeroed_page() */
37 mutex_lock(&port->mutex); 39 mutex_lock(&port->buf_mutex);
38 if (port->xmit_buf == NULL) 40 if (port->xmit_buf == NULL)
39 port->xmit_buf = (unsigned char *)get_zeroed_page(GFP_KERNEL); 41 port->xmit_buf = (unsigned char *)get_zeroed_page(GFP_KERNEL);
40 mutex_unlock(&port->mutex); 42 mutex_unlock(&port->buf_mutex);
41 if (port->xmit_buf == NULL) 43 if (port->xmit_buf == NULL)
42 return -ENOMEM; 44 return -ENOMEM;
43 return 0; 45 return 0;
@@ -46,15 +48,32 @@ EXPORT_SYMBOL(tty_port_alloc_xmit_buf);
46 48
47void tty_port_free_xmit_buf(struct tty_port *port) 49void tty_port_free_xmit_buf(struct tty_port *port)
48{ 50{
49 mutex_lock(&port->mutex); 51 mutex_lock(&port->buf_mutex);
50 if (port->xmit_buf != NULL) { 52 if (port->xmit_buf != NULL) {
51 free_page((unsigned long)port->xmit_buf); 53 free_page((unsigned long)port->xmit_buf);
52 port->xmit_buf = NULL; 54 port->xmit_buf = NULL;
53 } 55 }
54 mutex_unlock(&port->mutex); 56 mutex_unlock(&port->buf_mutex);
55} 57}
56EXPORT_SYMBOL(tty_port_free_xmit_buf); 58EXPORT_SYMBOL(tty_port_free_xmit_buf);
57 59
60static void tty_port_destructor(struct kref *kref)
61{
62 struct tty_port *port = container_of(kref, struct tty_port, kref);
63 if (port->xmit_buf)
64 free_page((unsigned long)port->xmit_buf);
65 if (port->ops->destruct)
66 port->ops->destruct(port);
67 else
68 kfree(port);
69}
70
71void tty_port_put(struct tty_port *port)
72{
73 if (port)
74 kref_put(&port->kref, tty_port_destructor);
75}
76EXPORT_SYMBOL(tty_port_put);
58 77
59/** 78/**
60 * tty_port_tty_get - get a tty reference 79 * tty_port_tty_get - get a tty reference
@@ -99,10 +118,11 @@ EXPORT_SYMBOL(tty_port_tty_set);
99 118
100static void tty_port_shutdown(struct tty_port *port) 119static void tty_port_shutdown(struct tty_port *port)
101{ 120{
102 if (port->ops->shutdown && 121 mutex_lock(&port->mutex);
122 if (port->ops->shutdown && !port->console &&
103 test_and_clear_bit(ASYNCB_INITIALIZED, &port->flags)) 123 test_and_clear_bit(ASYNCB_INITIALIZED, &port->flags))
104 port->ops->shutdown(port); 124 port->ops->shutdown(port);
105 125 mutex_unlock(&port->mutex);
106} 126}
107 127
108/** 128/**
@@ -120,8 +140,10 @@ void tty_port_hangup(struct tty_port *port)
120 spin_lock_irqsave(&port->lock, flags); 140 spin_lock_irqsave(&port->lock, flags);
121 port->count = 0; 141 port->count = 0;
122 port->flags &= ~ASYNC_NORMAL_ACTIVE; 142 port->flags &= ~ASYNC_NORMAL_ACTIVE;
123 if (port->tty) 143 if (port->tty) {
144 set_bit(TTY_IO_ERROR, &port->tty->flags);
124 tty_kref_put(port->tty); 145 tty_kref_put(port->tty);
146 }
125 port->tty = NULL; 147 port->tty = NULL;
126 spin_unlock_irqrestore(&port->lock, flags); 148 spin_unlock_irqrestore(&port->lock, flags);
127 wake_up_interruptible(&port->open_wait); 149 wake_up_interruptible(&port->open_wait);
@@ -198,7 +220,7 @@ EXPORT_SYMBOL(tty_port_lower_dtr_rts);
198 * management of these lines. Note that the dtr/rts raise is done each 220 * management of these lines. Note that the dtr/rts raise is done each
199 * iteration as a hangup may have previously dropped them while we wait. 221 * iteration as a hangup may have previously dropped them while we wait.
200 */ 222 */
201 223
202int tty_port_block_til_ready(struct tty_port *port, 224int tty_port_block_til_ready(struct tty_port *port,
203 struct tty_struct *tty, struct file *filp) 225 struct tty_struct *tty, struct file *filp)
204{ 226{
@@ -253,7 +275,8 @@ int tty_port_block_til_ready(struct tty_port *port,
253 tty_port_raise_dtr_rts(port); 275 tty_port_raise_dtr_rts(port);
254 276
255 prepare_to_wait(&port->open_wait, &wait, TASK_INTERRUPTIBLE); 277 prepare_to_wait(&port->open_wait, &wait, TASK_INTERRUPTIBLE);
256 /* Check for a hangup or uninitialised port. Return accordingly */ 278 /* Check for a hangup or uninitialised port.
279 Return accordingly */
257 if (tty_hung_up_p(filp) || !(port->flags & ASYNC_INITIALIZED)) { 280 if (tty_hung_up_p(filp) || !(port->flags & ASYNC_INITIALIZED)) {
258 if (port->flags & ASYNC_HUP_NOTIFY) 281 if (port->flags & ASYNC_HUP_NOTIFY)
259 retval = -EAGAIN; 282 retval = -EAGAIN;
@@ -285,11 +308,11 @@ int tty_port_block_til_ready(struct tty_port *port,
285 port->flags |= ASYNC_NORMAL_ACTIVE; 308 port->flags |= ASYNC_NORMAL_ACTIVE;
286 spin_unlock_irqrestore(&port->lock, flags); 309 spin_unlock_irqrestore(&port->lock, flags);
287 return retval; 310 return retval;
288
289} 311}
290EXPORT_SYMBOL(tty_port_block_til_ready); 312EXPORT_SYMBOL(tty_port_block_til_ready);
291 313
292int tty_port_close_start(struct tty_port *port, struct tty_struct *tty, struct file *filp) 314int tty_port_close_start(struct tty_port *port,
315 struct tty_struct *tty, struct file *filp)
293{ 316{
294 unsigned long flags; 317 unsigned long flags;
295 318
@@ -299,7 +322,7 @@ int tty_port_close_start(struct tty_port *port, struct tty_struct *tty, struct f
299 return 0; 322 return 0;
300 } 323 }
301 324
302 if( tty->count == 1 && port->count != 1) { 325 if (tty->count == 1 && port->count != 1) {
303 printk(KERN_WARNING 326 printk(KERN_WARNING
304 "tty_port_close_start: tty->count = 1 port count = %d.\n", 327 "tty_port_close_start: tty->count = 1 port count = %d.\n",
305 port->count); 328 port->count);
@@ -331,12 +354,20 @@ int tty_port_close_start(struct tty_port *port, struct tty_struct *tty, struct f
331 long timeout; 354 long timeout;
332 355
333 if (bps > 1200) 356 if (bps > 1200)
334 timeout = max_t(long, (HZ * 10 * port->drain_delay) / bps, 357 timeout = max_t(long,
335 HZ / 10); 358 (HZ * 10 * port->drain_delay) / bps, HZ / 10);
336 else 359 else
337 timeout = 2 * HZ; 360 timeout = 2 * HZ;
338 schedule_timeout_interruptible(timeout); 361 schedule_timeout_interruptible(timeout);
339 } 362 }
363 /* Flush the ldisc buffering */
364 tty_ldisc_flush(tty);
365
366 /* Drop DTR/RTS if HUPCL is set. This causes any attached modem to
367 hang up the line */
368 if (tty->termios->c_cflag & HUPCL)
369 tty_port_lower_dtr_rts(port);
370
340 /* Don't call port->drop for the last reference. Callers will want 371 /* Don't call port->drop for the last reference. Callers will want
341 to drop the last active reference in ->shutdown() or the tty 372 to drop the last active reference in ->shutdown() or the tty
342 shutdown path */ 373 shutdown path */
@@ -348,11 +379,6 @@ void tty_port_close_end(struct tty_port *port, struct tty_struct *tty)
348{ 379{
349 unsigned long flags; 380 unsigned long flags;
350 381
351 tty_ldisc_flush(tty);
352
353 if (tty->termios->c_cflag & HUPCL)
354 tty_port_lower_dtr_rts(port);
355
356 spin_lock_irqsave(&port->lock, flags); 382 spin_lock_irqsave(&port->lock, flags);
357 tty->closing = 0; 383 tty->closing = 0;
358 384
@@ -377,7 +403,42 @@ void tty_port_close(struct tty_port *port, struct tty_struct *tty,
377 if (tty_port_close_start(port, tty, filp) == 0) 403 if (tty_port_close_start(port, tty, filp) == 0)
378 return; 404 return;
379 tty_port_shutdown(port); 405 tty_port_shutdown(port);
406 set_bit(TTY_IO_ERROR, &tty->flags);
380 tty_port_close_end(port, tty); 407 tty_port_close_end(port, tty);
381 tty_port_tty_set(port, NULL); 408 tty_port_tty_set(port, NULL);
382} 409}
383EXPORT_SYMBOL(tty_port_close); 410EXPORT_SYMBOL(tty_port_close);
411
412int tty_port_open(struct tty_port *port, struct tty_struct *tty,
413 struct file *filp)
414{
415 spin_lock_irq(&port->lock);
416 if (!tty_hung_up_p(filp))
417 ++port->count;
418 spin_unlock_irq(&port->lock);
419 tty_port_tty_set(port, tty);
420
421 /*
422 * Do the device-specific open only if the hardware isn't
423 * already initialized. Serialize open and shutdown using the
424 * port mutex.
425 */
426
427 mutex_lock(&port->mutex);
428
429 if (!test_bit(ASYNCB_INITIALIZED, &port->flags)) {
430 clear_bit(TTY_IO_ERROR, &tty->flags);
431 if (port->ops->activate) {
432 int retval = port->ops->activate(port, tty);
433 if (retval) {
434 mutex_unlock(&port->mutex);
435 return retval;
436 }
437 }
438 set_bit(ASYNCB_INITIALIZED, &port->flags);
439 }
440 mutex_unlock(&port->mutex);
441 return tty_port_block_til_ready(port, tty, filp);
442}
443
444EXPORT_SYMBOL(tty_port_open);
diff --git a/drivers/char/uv_mmtimer.c b/drivers/char/uv_mmtimer.c
index 867b67be9f0a..c7072ba14f48 100644
--- a/drivers/char/uv_mmtimer.c
+++ b/drivers/char/uv_mmtimer.c
@@ -89,13 +89,17 @@ static long uv_mmtimer_ioctl(struct file *file, unsigned int cmd,
89 switch (cmd) { 89 switch (cmd) {
90 case MMTIMER_GETOFFSET: /* offset of the counter */ 90 case MMTIMER_GETOFFSET: /* offset of the counter */
91 /* 91 /*
92 * UV RTC register is on its own page 92 * Starting with HUB rev 2.0, the UV RTC register is
93 * replicated across all cachelines of it's own page.
94 * This allows faster simultaneous reads from a given socket.
95 *
96 * The offset returned is in 64 bit units.
93 */ 97 */
94 if (PAGE_SIZE <= (1 << 16)) 98 if (uv_get_min_hub_revision_id() == 1)
95 ret = ((UV_LOCAL_MMR_BASE | UVH_RTC) & (PAGE_SIZE-1)) 99 ret = 0;
96 / 8;
97 else 100 else
98 ret = -ENOSYS; 101 ret = ((uv_blade_processor_id() * L1_CACHE_BYTES) %
102 PAGE_SIZE) / 8;
99 break; 103 break;
100 104
101 case MMTIMER_GETRES: /* resolution of the clock in 10^-15 s */ 105 case MMTIMER_GETRES: /* resolution of the clock in 10^-15 s */
@@ -115,8 +119,8 @@ static long uv_mmtimer_ioctl(struct file *file, unsigned int cmd,
115 ret = hweight64(UVH_RTC_REAL_TIME_CLOCK_MASK); 119 ret = hweight64(UVH_RTC_REAL_TIME_CLOCK_MASK);
116 break; 120 break;
117 121
118 case MMTIMER_MMAPAVAIL: /* can we mmap the clock into userspace? */ 122 case MMTIMER_MMAPAVAIL:
119 ret = (PAGE_SIZE <= (1 << 16)) ? 1 : 0; 123 ret = 1;
120 break; 124 break;
121 125
122 case MMTIMER_GETCOUNTER: 126 case MMTIMER_GETCOUNTER:
diff --git a/drivers/char/viotape.c b/drivers/char/viotape.c
index 042c8149a6d1..1144a04cda6e 100644
--- a/drivers/char/viotape.c
+++ b/drivers/char/viotape.c
@@ -47,6 +47,7 @@
47#include <linux/proc_fs.h> 47#include <linux/proc_fs.h>
48#include <linux/seq_file.h> 48#include <linux/seq_file.h>
49#include <linux/smp_lock.h> 49#include <linux/smp_lock.h>
50#include <linux/slab.h>
50 51
51#include <asm/uaccess.h> 52#include <asm/uaccess.h>
52#include <asm/ioctls.h> 53#include <asm/ioctls.h>
diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
index a035ae39a359..196428c2287a 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,724 @@
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/slab.h>
29#include <linux/spinlock.h>
33#include <linux/virtio.h> 30#include <linux/virtio.h>
34#include <linux/virtio_console.h> 31#include <linux/virtio_console.h>
32#include <linux/wait.h>
33#include <linux/workqueue.h>
35#include "hvc_console.h" 34#include "hvc_console.h"
36 35
37/*D:340 These represent our input and output console queues, and the virtio 36/* Moved here from .h file in order to disable MULTIPORT. */
38 * operations for them. */ 37#define VIRTIO_CONSOLE_F_MULTIPORT 1 /* Does host provide multiple ports? */
39static struct virtqueue *in_vq, *out_vq;
40static struct virtio_device *vdev;
41 38
42/* This is our input buffer, and how much data is left in it. */ 39struct virtio_console_multiport_conf {
43static unsigned int in_len; 40 struct virtio_console_config config;
44static char *in, *inbuf; 41 /* max. number of ports this device can hold */
42 __u32 max_nr_ports;
43 /* number of ports added so far */
44 __u32 nr_ports;
45} __attribute__((packed));
45 46
46/* The operations for our console. */ 47/*
47static struct hv_ops virtio_cons; 48 * A message that's passed between the Host and the Guest for a
49 * particular port.
50 */
51struct virtio_console_control {
52 __u32 id; /* Port number */
53 __u16 event; /* The kind of control event (see below) */
54 __u16 value; /* Extra information for the key */
55};
48 56
49/* The hvc device */ 57/* Some events for control messages */
50static struct hvc_struct *hvc; 58#define VIRTIO_CONSOLE_PORT_READY 0
59#define VIRTIO_CONSOLE_CONSOLE_PORT 1
60#define VIRTIO_CONSOLE_RESIZE 2
61#define VIRTIO_CONSOLE_PORT_OPEN 3
62#define VIRTIO_CONSOLE_PORT_NAME 4
63#define VIRTIO_CONSOLE_PORT_REMOVE 5
51 64
52/*D:310 The put_chars() callback is pretty straightforward. 65/*
66 * This is a global struct for storing common data for all the devices
67 * this driver handles.
53 * 68 *
54 * We turn the characters into a scatter-gather list, add it to the output 69 * Mainly, it has a linked list for all the consoles in one place so
55 * queue and then kick the Host. Then we sit here waiting for it to finish: 70 * that callbacks from hvc for get_chars(), put_chars() work properly
56 * inefficient in theory, but in practice implementations will do it 71 * across multiple devices and multiple ports per device.
57 * immediately (lguest's Launcher does). */ 72 */
58static int put_chars(u32 vtermno, const char *buf, int count) 73struct ports_driver_data {
74 /* Used for registering chardevs */
75 struct class *class;
76
77 /* Used for exporting per-port information to debugfs */
78 struct dentry *debugfs_dir;
79
80 /* Number of devices this driver is handling */
81 unsigned int index;
82
83 /*
84 * This is used to keep track of the number of hvc consoles
85 * spawned by this driver. This number is given as the first
86 * argument to hvc_alloc(). To correctly map an initial
87 * console spawned via hvc_instantiate to the console being
88 * hooked up via hvc_alloc, we need to pass the same vtermno.
89 *
90 * We also just assume the first console being initialised was
91 * the first one that got used as the initial console.
92 */
93 unsigned int next_vtermno;
94
95 /* All the console devices handled by this driver */
96 struct list_head consoles;
97};
98static struct ports_driver_data pdrvdata;
99
100DEFINE_SPINLOCK(pdrvdata_lock);
101
102/* This struct holds information that's relevant only for console ports */
103struct console {
104 /* We'll place all consoles in a list in the pdrvdata struct */
105 struct list_head list;
106
107 /* The hvc device associated with this console port */
108 struct hvc_struct *hvc;
109
110 /*
111 * This number identifies the number that we used to register
112 * with hvc in hvc_instantiate() and hvc_alloc(); this is the
113 * number passed on by the hvc callbacks to us to
114 * differentiate between the other console ports handled by
115 * this driver
116 */
117 u32 vtermno;
118};
119
120struct port_buffer {
121 char *buf;
122
123 /* size of the buffer in *buf above */
124 size_t size;
125
126 /* used length of the buffer */
127 size_t len;
128 /* offset in the buf from which to consume data */
129 size_t offset;
130};
131
132/*
133 * This is a per-device struct that stores data common to all the
134 * ports for that device (vdev->priv).
135 */
136struct ports_device {
137 /*
138 * Workqueue handlers where we process deferred work after
139 * notification
140 */
141 struct work_struct control_work;
142 struct work_struct config_work;
143
144 struct list_head ports;
145
146 /* To protect the list of ports */
147 spinlock_t ports_lock;
148
149 /* To protect the vq operations for the control channel */
150 spinlock_t cvq_lock;
151
152 /* The current config space is stored here */
153 struct virtio_console_multiport_conf config;
154
155 /* The virtio device we're associated with */
156 struct virtio_device *vdev;
157
158 /*
159 * A couple of virtqueues for the control channel: one for
160 * guest->host transfers, one for host->guest transfers
161 */
162 struct virtqueue *c_ivq, *c_ovq;
163
164 /* Array of per-port IO virtqueues */
165 struct virtqueue **in_vqs, **out_vqs;
166
167 /* Used for numbering devices for sysfs and debugfs */
168 unsigned int drv_index;
169
170 /* Major number for this device. Ports will be created as minors. */
171 int chr_major;
172};
173
174/* This struct holds the per-port data */
175struct port {
176 /* Next port in the list, head is in the ports_device */
177 struct list_head list;
178
179 /* Pointer to the parent virtio_console device */
180 struct ports_device *portdev;
181
182 /* The current buffer from which data has to be fed to readers */
183 struct port_buffer *inbuf;
184
185 /*
186 * To protect the operations on the in_vq associated with this
187 * port. Has to be a spinlock because it can be called from
188 * interrupt context (get_char()).
189 */
190 spinlock_t inbuf_lock;
191
192 /* The IO vqs for this port */
193 struct virtqueue *in_vq, *out_vq;
194
195 /* File in the debugfs directory that exposes this port's information */
196 struct dentry *debugfs_file;
197
198 /*
199 * The entries in this struct will be valid if this port is
200 * hooked up to an hvc console
201 */
202 struct console cons;
203
204 /* Each port associates with a separate char device */
205 struct cdev cdev;
206 struct device *dev;
207
208 /* A waitqueue for poll() or blocking read operations */
209 wait_queue_head_t waitqueue;
210
211 /* The 'name' of the port that we expose via sysfs properties */
212 char *name;
213
214 /* The 'id' to identify the port with the Host */
215 u32 id;
216
217 /* Is the host device open */
218 bool host_connected;
219
220 /* We should allow only one process to open a port */
221 bool guest_connected;
222};
223
224/* This is the very early arch-specified put chars function. */
225static int (*early_put_chars)(u32, const char *, int);
226
227static struct port *find_port_by_vtermno(u32 vtermno)
228{
229 struct port *port;
230 struct console *cons;
231 unsigned long flags;
232
233 spin_lock_irqsave(&pdrvdata_lock, flags);
234 list_for_each_entry(cons, &pdrvdata.consoles, list) {
235 if (cons->vtermno == vtermno) {
236 port = container_of(cons, struct port, cons);
237 goto out;
238 }
239 }
240 port = NULL;
241out:
242 spin_unlock_irqrestore(&pdrvdata_lock, flags);
243 return port;
244}
245
246static struct port *find_port_by_id(struct ports_device *portdev, u32 id)
247{
248 struct port *port;
249 unsigned long flags;
250
251 spin_lock_irqsave(&portdev->ports_lock, flags);
252 list_for_each_entry(port, &portdev->ports, list)
253 if (port->id == id)
254 goto out;
255 port = NULL;
256out:
257 spin_unlock_irqrestore(&portdev->ports_lock, flags);
258
259 return port;
260}
261
262static struct port *find_port_by_vq(struct ports_device *portdev,
263 struct virtqueue *vq)
264{
265 struct port *port;
266 unsigned long flags;
267
268 spin_lock_irqsave(&portdev->ports_lock, flags);
269 list_for_each_entry(port, &portdev->ports, list)
270 if (port->in_vq == vq || port->out_vq == vq)
271 goto out;
272 port = NULL;
273out:
274 spin_unlock_irqrestore(&portdev->ports_lock, flags);
275 return port;
276}
277
278static bool is_console_port(struct port *port)
279{
280 if (port->cons.hvc)
281 return true;
282 return false;
283}
284
285static inline bool use_multiport(struct ports_device *portdev)
286{
287 /*
288 * This condition can be true when put_chars is called from
289 * early_init
290 */
291 if (!portdev->vdev)
292 return 0;
293 return portdev->vdev->features[0] & (1 << VIRTIO_CONSOLE_F_MULTIPORT);
294}
295
296static void free_buf(struct port_buffer *buf)
297{
298 kfree(buf->buf);
299 kfree(buf);
300}
301
302static struct port_buffer *alloc_buf(size_t buf_size)
303{
304 struct port_buffer *buf;
305
306 buf = kmalloc(sizeof(*buf), GFP_KERNEL);
307 if (!buf)
308 goto fail;
309 buf->buf = kzalloc(buf_size, GFP_KERNEL);
310 if (!buf->buf)
311 goto free_buf;
312 buf->len = 0;
313 buf->offset = 0;
314 buf->size = buf_size;
315 return buf;
316
317free_buf:
318 kfree(buf);
319fail:
320 return NULL;
321}
322
323/* Callers should take appropriate locks */
324static void *get_inbuf(struct port *port)
325{
326 struct port_buffer *buf;
327 struct virtqueue *vq;
328 unsigned int len;
329
330 vq = port->in_vq;
331 buf = vq->vq_ops->get_buf(vq, &len);
332 if (buf) {
333 buf->len = len;
334 buf->offset = 0;
335 }
336 return buf;
337}
338
339/*
340 * Create a scatter-gather list representing our input buffer and put
341 * it in the queue.
342 *
343 * Callers should take appropriate locks.
344 */
345static int add_inbuf(struct virtqueue *vq, struct port_buffer *buf)
59{ 346{
60 struct scatterlist sg[1]; 347 struct scatterlist sg[1];
348 int ret;
349
350 sg_init_one(sg, buf->buf, buf->size);
351
352 ret = vq->vq_ops->add_buf(vq, sg, 0, 1, buf);
353 vq->vq_ops->kick(vq);
354 return ret;
355}
356
357/* Discard any unread data this port has. Callers lockers. */
358static void discard_port_data(struct port *port)
359{
360 struct port_buffer *buf;
361 struct virtqueue *vq;
61 unsigned int len; 362 unsigned int len;
363 int ret;
62 364
63 /* This is a convenient routine to initialize a single-elem sg list */ 365 vq = port->in_vq;
64 sg_init_one(sg, buf, count); 366 if (port->inbuf)
367 buf = port->inbuf;
368 else
369 buf = vq->vq_ops->get_buf(vq, &len);
65 370
66 /* add_buf wants a token to identify this buffer: we hand it any 371 ret = 0;
67 * non-NULL pointer, since there's only ever one buffer. */ 372 while (buf) {
68 if (out_vq->vq_ops->add_buf(out_vq, sg, 1, 0, (void *)1) >= 0) { 373 if (add_inbuf(vq, buf) < 0) {
69 /* Tell Host to go! */ 374 ret++;
70 out_vq->vq_ops->kick(out_vq); 375 free_buf(buf);
71 /* Chill out until it's done with the buffer. */ 376 }
72 while (!out_vq->vq_ops->get_buf(out_vq, &len)) 377 buf = vq->vq_ops->get_buf(vq, &len);
73 cpu_relax();
74 } 378 }
379 port->inbuf = NULL;
380 if (ret)
381 dev_warn(port->dev, "Errors adding %d buffers back to vq\n",
382 ret);
383}
384
385static bool port_has_data(struct port *port)
386{
387 unsigned long flags;
388 bool ret;
389
390 spin_lock_irqsave(&port->inbuf_lock, flags);
391 if (port->inbuf) {
392 ret = true;
393 goto out;
394 }
395 port->inbuf = get_inbuf(port);
396 if (port->inbuf) {
397 ret = true;
398 goto out;
399 }
400 ret = false;
401out:
402 spin_unlock_irqrestore(&port->inbuf_lock, flags);
403 return ret;
404}
405
406static ssize_t send_control_msg(struct port *port, unsigned int event,
407 unsigned int value)
408{
409 struct scatterlist sg[1];
410 struct virtio_console_control cpkt;
411 struct virtqueue *vq;
412 unsigned int len;
413
414 if (!use_multiport(port->portdev))
415 return 0;
416
417 cpkt.id = port->id;
418 cpkt.event = event;
419 cpkt.value = value;
75 420
76 /* We're expected to return the amount of data we wrote: all of it. */ 421 vq = port->portdev->c_ovq;
77 return count; 422
423 sg_init_one(sg, &cpkt, sizeof(cpkt));
424 if (vq->vq_ops->add_buf(vq, sg, 1, 0, &cpkt) >= 0) {
425 vq->vq_ops->kick(vq);
426 while (!vq->vq_ops->get_buf(vq, &len))
427 cpu_relax();
428 }
429 return 0;
78} 430}
79 431
80/* Create a scatter-gather list representing our input buffer and put it in the 432static ssize_t send_buf(struct port *port, void *in_buf, size_t in_count)
81 * queue. */
82static void add_inbuf(void)
83{ 433{
84 struct scatterlist sg[1]; 434 struct scatterlist sg[1];
85 sg_init_one(sg, inbuf, PAGE_SIZE); 435 struct virtqueue *out_vq;
436 ssize_t ret;
437 unsigned int len;
438
439 out_vq = port->out_vq;
440
441 sg_init_one(sg, in_buf, in_count);
442 ret = out_vq->vq_ops->add_buf(out_vq, sg, 1, 0, in_buf);
86 443
87 /* We should always be able to add one buffer to an empty queue. */ 444 /* Tell Host to go! */
88 if (in_vq->vq_ops->add_buf(in_vq, sg, 0, 1, inbuf) < 0) 445 out_vq->vq_ops->kick(out_vq);
89 BUG(); 446
90 in_vq->vq_ops->kick(in_vq); 447 if (ret < 0) {
448 in_count = 0;
449 goto fail;
450 }
451
452 /* Wait till the host acknowledges it pushed out the data we sent. */
453 while (!out_vq->vq_ops->get_buf(out_vq, &len))
454 cpu_relax();
455fail:
456 /* We're expected to return the amount of data we wrote */
457 return in_count;
91} 458}
92 459
93/*D:350 get_chars() is the callback from the hvc_console infrastructure when 460/*
94 * an interrupt is received. 461 * Give out the data that's requested from the buffer that we have
95 * 462 * queued up.
96 * Most of the code deals with the fact that the hvc_console() infrastructure 463 */
97 * only asks us for 16 bytes at a time. We keep in_offset and in_used fields 464static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
98 * for partially-filled buffers. */ 465 bool to_user)
99static int get_chars(u32 vtermno, char *buf, int count)
100{ 466{
101 /* If we don't have an input queue yet, we can't get input. */ 467 struct port_buffer *buf;
102 BUG_ON(!in_vq); 468 unsigned long flags;
469
470 if (!out_count || !port_has_data(port))
471 return 0;
472
473 buf = port->inbuf;
474 out_count = min(out_count, buf->len - buf->offset);
475
476 if (to_user) {
477 ssize_t ret;
478
479 ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
480 if (ret)
481 return -EFAULT;
482 } else {
483 memcpy(out_buf, buf->buf + buf->offset, out_count);
484 }
485
486 buf->offset += out_count;
103 487
104 /* No buffer? Try to get one. */ 488 if (buf->offset == buf->len) {
105 if (!in_len) { 489 /*
106 in = in_vq->vq_ops->get_buf(in_vq, &in_len); 490 * We're done using all the data in this buffer.
107 if (!in) 491 * Re-queue so that the Host can send us more data.
492 */
493 spin_lock_irqsave(&port->inbuf_lock, flags);
494 port->inbuf = NULL;
495
496 if (add_inbuf(port->in_vq, buf) < 0)
497 dev_warn(port->dev, "failed add_buf\n");
498
499 spin_unlock_irqrestore(&port->inbuf_lock, flags);
500 }
501 /* Return the number of bytes actually copied */
502 return out_count;
503}
504
505/* The condition that must be true for polling to end */
506static bool wait_is_over(struct port *port)
507{
508 return port_has_data(port) || !port->host_connected;
509}
510
511static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
512 size_t count, loff_t *offp)
513{
514 struct port *port;
515 ssize_t ret;
516
517 port = filp->private_data;
518
519 if (!port_has_data(port)) {
520 /*
521 * If nothing's connected on the host just return 0 in
522 * case of list_empty; this tells the userspace app
523 * that there's no connection
524 */
525 if (!port->host_connected)
108 return 0; 526 return 0;
527 if (filp->f_flags & O_NONBLOCK)
528 return -EAGAIN;
529
530 ret = wait_event_interruptible(port->waitqueue,
531 wait_is_over(port));
532 if (ret < 0)
533 return ret;
534 }
535 /*
536 * We could've received a disconnection message while we were
537 * waiting for more data.
538 *
539 * This check is not clubbed in the if() statement above as we
540 * might receive some data as well as the host could get
541 * disconnected after we got woken up from our wait. So we
542 * really want to give off whatever data we have and only then
543 * check for host_connected.
544 */
545 if (!port_has_data(port) && !port->host_connected)
546 return 0;
547
548 return fill_readbuf(port, ubuf, count, true);
549}
550
551static ssize_t port_fops_write(struct file *filp, const char __user *ubuf,
552 size_t count, loff_t *offp)
553{
554 struct port *port;
555 char *buf;
556 ssize_t ret;
557
558 port = filp->private_data;
559
560 count = min((size_t)(32 * 1024), count);
561
562 buf = kmalloc(count, GFP_KERNEL);
563 if (!buf)
564 return -ENOMEM;
565
566 ret = copy_from_user(buf, ubuf, count);
567 if (ret) {
568 ret = -EFAULT;
569 goto free_buf;
109 } 570 }
110 571
111 /* You want more than we have to give? Well, try wanting less! */ 572 ret = send_buf(port, buf, count);
112 if (in_len < count) 573free_buf:
113 count = in_len; 574 kfree(buf);
575 return ret;
576}
577
578static unsigned int port_fops_poll(struct file *filp, poll_table *wait)
579{
580 struct port *port;
581 unsigned int ret;
582
583 port = filp->private_data;
584 poll_wait(filp, &port->waitqueue, wait);
114 585
115 /* Copy across to their buffer and increment offset. */ 586 ret = 0;
116 memcpy(buf, in, count); 587 if (port->inbuf)
117 in += count; 588 ret |= POLLIN | POLLRDNORM;
118 in_len -= count; 589 if (port->host_connected)
590 ret |= POLLOUT;
591 if (!port->host_connected)
592 ret |= POLLHUP;
119 593
120 /* Finished? Re-register buffer so Host will use it again. */ 594 return ret;
121 if (in_len == 0) 595}
122 add_inbuf(); 596
597static int port_fops_release(struct inode *inode, struct file *filp)
598{
599 struct port *port;
600
601 port = filp->private_data;
602
603 /* Notify host of port being closed */
604 send_control_msg(port, VIRTIO_CONSOLE_PORT_OPEN, 0);
605
606 spin_lock_irq(&port->inbuf_lock);
607 port->guest_connected = false;
608
609 discard_port_data(port);
123 610
124 return count; 611 spin_unlock_irq(&port->inbuf_lock);
612
613 return 0;
125} 614}
126/*:*/
127 615
128/*D:320 Console drivers are initialized very early so boot messages can go out, 616static int port_fops_open(struct inode *inode, struct file *filp)
129 * so we do things slightly differently from the generic virtio initialization 617{
130 * of the net and block drivers. 618 struct cdev *cdev = inode->i_cdev;
619 struct port *port;
620
621 port = container_of(cdev, struct port, cdev);
622 filp->private_data = port;
623
624 /*
625 * Don't allow opening of console port devices -- that's done
626 * via /dev/hvc
627 */
628 if (is_console_port(port))
629 return -ENXIO;
630
631 /* Allow only one process to open a particular port at a time */
632 spin_lock_irq(&port->inbuf_lock);
633 if (port->guest_connected) {
634 spin_unlock_irq(&port->inbuf_lock);
635 return -EMFILE;
636 }
637
638 port->guest_connected = true;
639 spin_unlock_irq(&port->inbuf_lock);
640
641 /* Notify host of port being opened */
642 send_control_msg(filp->private_data, VIRTIO_CONSOLE_PORT_OPEN, 1);
643
644 return 0;
645}
646
647/*
648 * The file operations that we support: programs in the guest can open
649 * a console device, read from it, write to it, poll for data and
650 * close it. The devices are at
651 * /dev/vport<device number>p<port number>
652 */
653static const struct file_operations port_fops = {
654 .owner = THIS_MODULE,
655 .open = port_fops_open,
656 .read = port_fops_read,
657 .write = port_fops_write,
658 .poll = port_fops_poll,
659 .release = port_fops_release,
660};
661
662/*
663 * The put_chars() callback is pretty straightforward.
131 * 664 *
132 * At this stage, the console is output-only. It's too early to set up a 665 * 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. */ 666 * output queue and then kick the Host. Then we sit here waiting for
134int __init virtio_cons_early_init(int (*put_chars)(u32, const char *, int)) 667 * it to finish: inefficient in theory, but in practice
668 * implementations will do it immediately (lguest's Launcher does).
669 */
670static int put_chars(u32 vtermno, const char *buf, int count)
135{ 671{
136 virtio_cons.put_chars = put_chars; 672 struct port *port;
137 return hvc_instantiate(0, 0, &virtio_cons); 673
674 if (unlikely(early_put_chars))
675 return early_put_chars(vtermno, buf, count);
676
677 port = find_port_by_vtermno(vtermno);
678 if (!port)
679 return 0;
680
681 return send_buf(port, (void *)buf, count);
138} 682}
139 683
140/* 684/*
141 * virtio console configuration. This supports: 685 * get_chars() is the callback from the hvc_console infrastructure
142 * - console resize 686 * when an interrupt is received.
687 *
688 * We call out to fill_readbuf that gets us the required data from the
689 * buffers that are queued up.
143 */ 690 */
144static void virtcons_apply_config(struct virtio_device *dev) 691static int get_chars(u32 vtermno, char *buf, int count)
692{
693 struct port *port;
694
695 port = find_port_by_vtermno(vtermno);
696 if (!port)
697 return 0;
698
699 /* If we don't have an input queue yet, we can't get input. */
700 BUG_ON(!port->in_vq);
701
702 return fill_readbuf(port, buf, count, false);
703}
704
705static void resize_console(struct port *port)
145{ 706{
707 struct virtio_device *vdev;
146 struct winsize ws; 708 struct winsize ws;
147 709
148 if (virtio_has_feature(dev, VIRTIO_CONSOLE_F_SIZE)) { 710 /* The port could have been hot-unplugged */
149 dev->config->get(dev, 711 if (!port)
150 offsetof(struct virtio_console_config, cols), 712 return;
151 &ws.ws_col, sizeof(u16)); 713
152 dev->config->get(dev, 714 vdev = port->portdev->vdev;
153 offsetof(struct virtio_console_config, rows), 715 if (virtio_has_feature(vdev, VIRTIO_CONSOLE_F_SIZE)) {
154 &ws.ws_row, sizeof(u16)); 716 vdev->config->get(vdev,
155 hvc_resize(hvc, ws); 717 offsetof(struct virtio_console_config, cols),
718 &ws.ws_col, sizeof(u16));
719 vdev->config->get(vdev,
720 offsetof(struct virtio_console_config, rows),
721 &ws.ws_row, sizeof(u16));
722 hvc_resize(port->cons.hvc, ws);
156 } 723 }
157} 724}
158 725
159/* 726/* 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 */
163static int notifier_add_vio(struct hvc_struct *hp, int data) 727static int notifier_add_vio(struct hvc_struct *hp, int data)
164{ 728{
729 struct port *port;
730
731 port = find_port_by_vtermno(hp->vtermno);
732 if (!port)
733 return -EINVAL;
734
165 hp->irq_requested = 1; 735 hp->irq_requested = 1;
166 virtcons_apply_config(vdev); 736 resize_console(port);
167 737
168 return 0; 738 return 0;
169} 739}
@@ -173,79 +743,812 @@ static void notifier_del_vio(struct hvc_struct *hp, int data)
173 hp->irq_requested = 0; 743 hp->irq_requested = 0;
174} 744}
175 745
176static void hvc_handle_input(struct virtqueue *vq) 746/* The operations for console ports. */
747static const struct hv_ops hv_ops = {
748 .get_chars = get_chars,
749 .put_chars = put_chars,
750 .notifier_add = notifier_add_vio,
751 .notifier_del = notifier_del_vio,
752 .notifier_hangup = notifier_del_vio,
753};
754
755/*
756 * Console drivers are initialized very early so boot messages can go
757 * out, so we do things slightly differently from the generic virtio
758 * initialization of the net and block drivers.
759 *
760 * At this stage, the console is output-only. It's too early to set
761 * up a virtqueue, so we let the drivers do some boutique early-output
762 * thing.
763 */
764int __init virtio_cons_early_init(int (*put_chars)(u32, const char *, int))
177{ 765{
178 if (hvc_poll(hvc)) 766 early_put_chars = put_chars;
767 return hvc_instantiate(0, 0, &hv_ops);
768}
769
770int init_port_console(struct port *port)
771{
772 int ret;
773
774 /*
775 * The Host's telling us this port is a console port. Hook it
776 * up with an hvc console.
777 *
778 * To set up and manage our virtual console, we call
779 * hvc_alloc().
780 *
781 * The first argument of hvc_alloc() is the virtual console
782 * number. The second argument is the parameter for the
783 * notification mechanism (like irq number). We currently
784 * leave this as zero, virtqueues have implicit notifications.
785 *
786 * The third argument is a "struct hv_ops" containing the
787 * put_chars() get_chars(), notifier_add() and notifier_del()
788 * pointers. The final argument is the output buffer size: we
789 * can do any size, so we put PAGE_SIZE here.
790 */
791 port->cons.vtermno = pdrvdata.next_vtermno;
792
793 port->cons.hvc = hvc_alloc(port->cons.vtermno, 0, &hv_ops, PAGE_SIZE);
794 if (IS_ERR(port->cons.hvc)) {
795 ret = PTR_ERR(port->cons.hvc);
796 dev_err(port->dev,
797 "error %d allocating hvc for port\n", ret);
798 port->cons.hvc = NULL;
799 return ret;
800 }
801 spin_lock_irq(&pdrvdata_lock);
802 pdrvdata.next_vtermno++;
803 list_add_tail(&port->cons.list, &pdrvdata.consoles);
804 spin_unlock_irq(&pdrvdata_lock);
805 port->guest_connected = true;
806
807 /* Notify host of port being opened */
808 send_control_msg(port, VIRTIO_CONSOLE_PORT_OPEN, 1);
809
810 return 0;
811}
812
813static ssize_t show_port_name(struct device *dev,
814 struct device_attribute *attr, char *buffer)
815{
816 struct port *port;
817
818 port = dev_get_drvdata(dev);
819
820 return sprintf(buffer, "%s\n", port->name);
821}
822
823static DEVICE_ATTR(name, S_IRUGO, show_port_name, NULL);
824
825static struct attribute *port_sysfs_entries[] = {
826 &dev_attr_name.attr,
827 NULL
828};
829
830static struct attribute_group port_attribute_group = {
831 .name = NULL, /* put in device directory */
832 .attrs = port_sysfs_entries,
833};
834
835static int debugfs_open(struct inode *inode, struct file *filp)
836{
837 filp->private_data = inode->i_private;
838 return 0;
839}
840
841static ssize_t debugfs_read(struct file *filp, char __user *ubuf,
842 size_t count, loff_t *offp)
843{
844 struct port *port;
845 char *buf;
846 ssize_t ret, out_offset, out_count;
847
848 out_count = 1024;
849 buf = kmalloc(out_count, GFP_KERNEL);
850 if (!buf)
851 return -ENOMEM;
852
853 port = filp->private_data;
854 out_offset = 0;
855 out_offset += snprintf(buf + out_offset, out_count,
856 "name: %s\n", port->name ? port->name : "");
857 out_offset += snprintf(buf + out_offset, out_count - out_offset,
858 "guest_connected: %d\n", port->guest_connected);
859 out_offset += snprintf(buf + out_offset, out_count - out_offset,
860 "host_connected: %d\n", port->host_connected);
861 out_offset += snprintf(buf + out_offset, out_count - out_offset,
862 "is_console: %s\n",
863 is_console_port(port) ? "yes" : "no");
864 out_offset += snprintf(buf + out_offset, out_count - out_offset,
865 "console_vtermno: %u\n", port->cons.vtermno);
866
867 ret = simple_read_from_buffer(ubuf, count, offp, buf, out_offset);
868 kfree(buf);
869 return ret;
870}
871
872static const struct file_operations port_debugfs_ops = {
873 .owner = THIS_MODULE,
874 .open = debugfs_open,
875 .read = debugfs_read,
876};
877
878/* Remove all port-specific data. */
879static int remove_port(struct port *port)
880{
881 struct port_buffer *buf;
882
883 spin_lock_irq(&port->portdev->ports_lock);
884 list_del(&port->list);
885 spin_unlock_irq(&port->portdev->ports_lock);
886
887 if (is_console_port(port)) {
888 spin_lock_irq(&pdrvdata_lock);
889 list_del(&port->cons.list);
890 spin_unlock_irq(&pdrvdata_lock);
891 hvc_remove(port->cons.hvc);
892 }
893 if (port->guest_connected)
894 send_control_msg(port, VIRTIO_CONSOLE_PORT_OPEN, 0);
895
896 sysfs_remove_group(&port->dev->kobj, &port_attribute_group);
897 device_destroy(pdrvdata.class, port->dev->devt);
898 cdev_del(&port->cdev);
899
900 /* Remove unused data this port might have received. */
901 discard_port_data(port);
902
903 /* Remove buffers we queued up for the Host to send us data in. */
904 while ((buf = port->in_vq->vq_ops->detach_unused_buf(port->in_vq)))
905 free_buf(buf);
906
907 kfree(port->name);
908
909 debugfs_remove(port->debugfs_file);
910
911 kfree(port);
912 return 0;
913}
914
915/* Any private messages that the Host and Guest want to share */
916static void handle_control_message(struct ports_device *portdev,
917 struct port_buffer *buf)
918{
919 struct virtio_console_control *cpkt;
920 struct port *port;
921 size_t name_size;
922 int err;
923
924 cpkt = (struct virtio_console_control *)(buf->buf + buf->offset);
925
926 port = find_port_by_id(portdev, cpkt->id);
927 if (!port) {
928 /* No valid header at start of buffer. Drop it. */
929 dev_dbg(&portdev->vdev->dev,
930 "Invalid index %u in control packet\n", cpkt->id);
931 return;
932 }
933
934 switch (cpkt->event) {
935 case VIRTIO_CONSOLE_CONSOLE_PORT:
936 if (!cpkt->value)
937 break;
938 if (is_console_port(port))
939 break;
940
941 init_port_console(port);
942 /*
943 * Could remove the port here in case init fails - but
944 * have to notify the host first.
945 */
946 break;
947 case VIRTIO_CONSOLE_RESIZE:
948 if (!is_console_port(port))
949 break;
950 port->cons.hvc->irq_requested = 1;
951 resize_console(port);
952 break;
953 case VIRTIO_CONSOLE_PORT_OPEN:
954 port->host_connected = cpkt->value;
955 wake_up_interruptible(&port->waitqueue);
956 break;
957 case VIRTIO_CONSOLE_PORT_NAME:
958 /*
959 * Skip the size of the header and the cpkt to get the size
960 * of the name that was sent
961 */
962 name_size = buf->len - buf->offset - sizeof(*cpkt) + 1;
963
964 port->name = kmalloc(name_size, GFP_KERNEL);
965 if (!port->name) {
966 dev_err(port->dev,
967 "Not enough space to store port name\n");
968 break;
969 }
970 strncpy(port->name, buf->buf + buf->offset + sizeof(*cpkt),
971 name_size - 1);
972 port->name[name_size - 1] = 0;
973
974 /*
975 * Since we only have one sysfs attribute, 'name',
976 * create it only if we have a name for the port.
977 */
978 err = sysfs_create_group(&port->dev->kobj,
979 &port_attribute_group);
980 if (err) {
981 dev_err(port->dev,
982 "Error %d creating sysfs device attributes\n",
983 err);
984 } else {
985 /*
986 * Generate a udev event so that appropriate
987 * symlinks can be created based on udev
988 * rules.
989 */
990 kobject_uevent(&port->dev->kobj, KOBJ_CHANGE);
991 }
992 break;
993 case VIRTIO_CONSOLE_PORT_REMOVE:
994 /*
995 * Hot unplug the port. We don't decrement nr_ports
996 * since we don't want to deal with extra complexities
997 * of using the lowest-available port id: We can just
998 * pick up the nr_ports number as the id and not have
999 * userspace send it to us. This helps us in two
1000 * ways:
1001 *
1002 * - We don't need to have a 'port_id' field in the
1003 * config space when a port is hot-added. This is a
1004 * good thing as we might queue up multiple hotplug
1005 * requests issued in our workqueue.
1006 *
1007 * - Another way to deal with this would have been to
1008 * use a bitmap of the active ports and select the
1009 * lowest non-active port from that map. That
1010 * bloats the already tight config space and we
1011 * would end up artificially limiting the
1012 * max. number of ports to sizeof(bitmap). Right
1013 * now we can support 2^32 ports (as the port id is
1014 * stored in a u32 type).
1015 *
1016 */
1017 remove_port(port);
1018 break;
1019 }
1020}
1021
1022static void control_work_handler(struct work_struct *work)
1023{
1024 struct ports_device *portdev;
1025 struct virtqueue *vq;
1026 struct port_buffer *buf;
1027 unsigned int len;
1028
1029 portdev = container_of(work, struct ports_device, control_work);
1030 vq = portdev->c_ivq;
1031
1032 spin_lock(&portdev->cvq_lock);
1033 while ((buf = vq->vq_ops->get_buf(vq, &len))) {
1034 spin_unlock(&portdev->cvq_lock);
1035
1036 buf->len = len;
1037 buf->offset = 0;
1038
1039 handle_control_message(portdev, buf);
1040
1041 spin_lock(&portdev->cvq_lock);
1042 if (add_inbuf(portdev->c_ivq, buf) < 0) {
1043 dev_warn(&portdev->vdev->dev,
1044 "Error adding buffer to queue\n");
1045 free_buf(buf);
1046 }
1047 }
1048 spin_unlock(&portdev->cvq_lock);
1049}
1050
1051static void in_intr(struct virtqueue *vq)
1052{
1053 struct port *port;
1054 unsigned long flags;
1055
1056 port = find_port_by_vq(vq->vdev->priv, vq);
1057 if (!port)
1058 return;
1059
1060 spin_lock_irqsave(&port->inbuf_lock, flags);
1061 if (!port->inbuf)
1062 port->inbuf = get_inbuf(port);
1063
1064 /*
1065 * Don't queue up data when port is closed. This condition
1066 * can be reached when a console port is not yet connected (no
1067 * tty is spawned) and the host sends out data to console
1068 * ports. For generic serial ports, the host won't
1069 * (shouldn't) send data till the guest is connected.
1070 */
1071 if (!port->guest_connected)
1072 discard_port_data(port);
1073
1074 spin_unlock_irqrestore(&port->inbuf_lock, flags);
1075
1076 wake_up_interruptible(&port->waitqueue);
1077
1078 if (is_console_port(port) && hvc_poll(port->cons.hvc))
179 hvc_kick(); 1079 hvc_kick();
180} 1080}
181 1081
182/*D:370 Once we're further in boot, we get probed like any other virtio device. 1082static void control_intr(struct virtqueue *vq)
183 * At this stage we set up the output virtqueue. 1083{
184 * 1084 struct ports_device *portdev;
185 * To set up and manage our virtual console, we call hvc_alloc(). Since we 1085
186 * never remove the console device we never need this pointer again. 1086 portdev = vq->vdev->priv;
1087 schedule_work(&portdev->control_work);
1088}
1089
1090static void config_intr(struct virtio_device *vdev)
1091{
1092 struct ports_device *portdev;
1093
1094 portdev = vdev->priv;
1095 if (use_multiport(portdev)) {
1096 /* Handle port hot-add */
1097 schedule_work(&portdev->config_work);
1098 }
1099 /*
1100 * We'll use this way of resizing only for legacy support.
1101 * For newer userspace (VIRTIO_CONSOLE_F_MULTPORT+), use
1102 * control messages to indicate console size changes so that
1103 * it can be done per-port
1104 */
1105 resize_console(find_port_by_id(portdev, 0));
1106}
1107
1108static unsigned int fill_queue(struct virtqueue *vq, spinlock_t *lock)
1109{
1110 struct port_buffer *buf;
1111 unsigned int nr_added_bufs;
1112 int ret;
1113
1114 nr_added_bufs = 0;
1115 do {
1116 buf = alloc_buf(PAGE_SIZE);
1117 if (!buf)
1118 break;
1119
1120 spin_lock_irq(lock);
1121 ret = add_inbuf(vq, buf);
1122 if (ret < 0) {
1123 spin_unlock_irq(lock);
1124 free_buf(buf);
1125 break;
1126 }
1127 nr_added_bufs++;
1128 spin_unlock_irq(lock);
1129 } while (ret > 0);
1130
1131 return nr_added_bufs;
1132}
1133
1134static int add_port(struct ports_device *portdev, u32 id)
1135{
1136 char debugfs_name[16];
1137 struct port *port;
1138 struct port_buffer *buf;
1139 dev_t devt;
1140 unsigned int nr_added_bufs;
1141 int err;
1142
1143 port = kmalloc(sizeof(*port), GFP_KERNEL);
1144 if (!port) {
1145 err = -ENOMEM;
1146 goto fail;
1147 }
1148
1149 port->portdev = portdev;
1150 port->id = id;
1151
1152 port->name = NULL;
1153 port->inbuf = NULL;
1154 port->cons.hvc = NULL;
1155
1156 port->host_connected = port->guest_connected = false;
1157
1158 port->in_vq = portdev->in_vqs[port->id];
1159 port->out_vq = portdev->out_vqs[port->id];
1160
1161 cdev_init(&port->cdev, &port_fops);
1162
1163 devt = MKDEV(portdev->chr_major, id);
1164 err = cdev_add(&port->cdev, devt, 1);
1165 if (err < 0) {
1166 dev_err(&port->portdev->vdev->dev,
1167 "Error %d adding cdev for port %u\n", err, id);
1168 goto free_port;
1169 }
1170 port->dev = device_create(pdrvdata.class, &port->portdev->vdev->dev,
1171 devt, port, "vport%up%u",
1172 port->portdev->drv_index, id);
1173 if (IS_ERR(port->dev)) {
1174 err = PTR_ERR(port->dev);
1175 dev_err(&port->portdev->vdev->dev,
1176 "Error %d creating device for port %u\n",
1177 err, id);
1178 goto free_cdev;
1179 }
1180
1181 spin_lock_init(&port->inbuf_lock);
1182 init_waitqueue_head(&port->waitqueue);
1183
1184 /* Fill the in_vq with buffers so the host can send us data. */
1185 nr_added_bufs = fill_queue(port->in_vq, &port->inbuf_lock);
1186 if (!nr_added_bufs) {
1187 dev_err(port->dev, "Error allocating inbufs\n");
1188 err = -ENOMEM;
1189 goto free_device;
1190 }
1191
1192 /*
1193 * If we're not using multiport support, this has to be a console port
1194 */
1195 if (!use_multiport(port->portdev)) {
1196 err = init_port_console(port);
1197 if (err)
1198 goto free_inbufs;
1199 }
1200
1201 spin_lock_irq(&portdev->ports_lock);
1202 list_add_tail(&port->list, &port->portdev->ports);
1203 spin_unlock_irq(&portdev->ports_lock);
1204
1205 /*
1206 * Tell the Host we're set so that it can send us various
1207 * configuration parameters for this port (eg, port name,
1208 * caching, whether this is a console port, etc.)
1209 */
1210 send_control_msg(port, VIRTIO_CONSOLE_PORT_READY, 1);
1211
1212 if (pdrvdata.debugfs_dir) {
1213 /*
1214 * Finally, create the debugfs file that we can use to
1215 * inspect a port's state at any time
1216 */
1217 sprintf(debugfs_name, "vport%up%u",
1218 port->portdev->drv_index, id);
1219 port->debugfs_file = debugfs_create_file(debugfs_name, 0444,
1220 pdrvdata.debugfs_dir,
1221 port,
1222 &port_debugfs_ops);
1223 }
1224 return 0;
1225
1226free_inbufs:
1227 while ((buf = port->in_vq->vq_ops->detach_unused_buf(port->in_vq)))
1228 free_buf(buf);
1229free_device:
1230 device_destroy(pdrvdata.class, port->dev->devt);
1231free_cdev:
1232 cdev_del(&port->cdev);
1233free_port:
1234 kfree(port);
1235fail:
1236 return err;
1237}
1238
1239/*
1240 * The workhandler for config-space updates.
187 * 1241 *
188 * Finally we put our input buffer in the input queue, ready to receive. */ 1242 * This is called when ports are hot-added.
189static int __devinit virtcons_probe(struct virtio_device *dev) 1243 */
1244static void config_work_handler(struct work_struct *work)
190{ 1245{
191 vq_callback_t *callbacks[] = { hvc_handle_input, NULL}; 1246 struct virtio_console_multiport_conf virtconconf;
192 const char *names[] = { "input", "output" }; 1247 struct ports_device *portdev;
193 struct virtqueue *vqs[2]; 1248 struct virtio_device *vdev;
194 int err; 1249 int err;
195 1250
196 vdev = dev; 1251 portdev = container_of(work, struct ports_device, config_work);
197 1252
198 /* This is the scratch page we use to receive console input */ 1253 vdev = portdev->vdev;
199 inbuf = kmalloc(PAGE_SIZE, GFP_KERNEL); 1254 vdev->config->get(vdev,
200 if (!inbuf) { 1255 offsetof(struct virtio_console_multiport_conf,
1256 nr_ports),
1257 &virtconconf.nr_ports,
1258 sizeof(virtconconf.nr_ports));
1259
1260 if (portdev->config.nr_ports == virtconconf.nr_ports) {
1261 /*
1262 * Port 0 got hot-added. Since we already did all the
1263 * other initialisation for it, just tell the Host
1264 * that the port is ready if we find the port. In
1265 * case the port was hot-removed earlier, we call
1266 * add_port to add the port.
1267 */
1268 struct port *port;
1269
1270 port = find_port_by_id(portdev, 0);
1271 if (!port)
1272 add_port(portdev, 0);
1273 else
1274 send_control_msg(port, VIRTIO_CONSOLE_PORT_READY, 1);
1275 return;
1276 }
1277 if (virtconconf.nr_ports > portdev->config.max_nr_ports) {
1278 dev_warn(&vdev->dev,
1279 "More ports specified (%u) than allowed (%u)",
1280 portdev->config.nr_ports + 1,
1281 portdev->config.max_nr_ports);
1282 return;
1283 }
1284 if (virtconconf.nr_ports < portdev->config.nr_ports)
1285 return;
1286
1287 /* Hot-add ports */
1288 while (virtconconf.nr_ports - portdev->config.nr_ports) {
1289 err = add_port(portdev, portdev->config.nr_ports);
1290 if (err)
1291 break;
1292 portdev->config.nr_ports++;
1293 }
1294}
1295
1296static int init_vqs(struct ports_device *portdev)
1297{
1298 vq_callback_t **io_callbacks;
1299 char **io_names;
1300 struct virtqueue **vqs;
1301 u32 i, j, nr_ports, nr_queues;
1302 int err;
1303
1304 nr_ports = portdev->config.max_nr_ports;
1305 nr_queues = use_multiport(portdev) ? (nr_ports + 1) * 2 : 2;
1306
1307 vqs = kmalloc(nr_queues * sizeof(struct virtqueue *), GFP_KERNEL);
1308 if (!vqs) {
201 err = -ENOMEM; 1309 err = -ENOMEM;
202 goto fail; 1310 goto fail;
203 } 1311 }
1312 io_callbacks = kmalloc(nr_queues * sizeof(vq_callback_t *), GFP_KERNEL);
1313 if (!io_callbacks) {
1314 err = -ENOMEM;
1315 goto free_vqs;
1316 }
1317 io_names = kmalloc(nr_queues * sizeof(char *), GFP_KERNEL);
1318 if (!io_names) {
1319 err = -ENOMEM;
1320 goto free_callbacks;
1321 }
1322 portdev->in_vqs = kmalloc(nr_ports * sizeof(struct virtqueue *),
1323 GFP_KERNEL);
1324 if (!portdev->in_vqs) {
1325 err = -ENOMEM;
1326 goto free_names;
1327 }
1328 portdev->out_vqs = kmalloc(nr_ports * sizeof(struct virtqueue *),
1329 GFP_KERNEL);
1330 if (!portdev->out_vqs) {
1331 err = -ENOMEM;
1332 goto free_invqs;
1333 }
1334
1335 /*
1336 * For backward compat (newer host but older guest), the host
1337 * spawns a console port first and also inits the vqs for port
1338 * 0 before others.
1339 */
1340 j = 0;
1341 io_callbacks[j] = in_intr;
1342 io_callbacks[j + 1] = NULL;
1343 io_names[j] = "input";
1344 io_names[j + 1] = "output";
1345 j += 2;
204 1346
1347 if (use_multiport(portdev)) {
1348 io_callbacks[j] = control_intr;
1349 io_callbacks[j + 1] = NULL;
1350 io_names[j] = "control-i";
1351 io_names[j + 1] = "control-o";
1352
1353 for (i = 1; i < nr_ports; i++) {
1354 j += 2;
1355 io_callbacks[j] = in_intr;
1356 io_callbacks[j + 1] = NULL;
1357 io_names[j] = "input";
1358 io_names[j + 1] = "output";
1359 }
1360 }
205 /* Find the queues. */ 1361 /* Find the queues. */
206 /* FIXME: This is why we want to wean off hvc: we do nothing 1362 err = portdev->vdev->config->find_vqs(portdev->vdev, nr_queues, vqs,
207 * when input comes in. */ 1363 io_callbacks,
208 err = vdev->config->find_vqs(vdev, 2, vqs, callbacks, names); 1364 (const char **)io_names);
209 if (err) 1365 if (err)
1366 goto free_outvqs;
1367
1368 j = 0;
1369 portdev->in_vqs[0] = vqs[0];
1370 portdev->out_vqs[0] = vqs[1];
1371 j += 2;
1372 if (use_multiport(portdev)) {
1373 portdev->c_ivq = vqs[j];
1374 portdev->c_ovq = vqs[j + 1];
1375
1376 for (i = 1; i < nr_ports; i++) {
1377 j += 2;
1378 portdev->in_vqs[i] = vqs[j];
1379 portdev->out_vqs[i] = vqs[j + 1];
1380 }
1381 }
1382 kfree(io_callbacks);
1383 kfree(io_names);
1384 kfree(vqs);
1385
1386 return 0;
1387
1388free_names:
1389 kfree(io_names);
1390free_callbacks:
1391 kfree(io_callbacks);
1392free_outvqs:
1393 kfree(portdev->out_vqs);
1394free_invqs:
1395 kfree(portdev->in_vqs);
1396free_vqs:
1397 kfree(vqs);
1398fail:
1399 return err;
1400}
1401
1402static const struct file_operations portdev_fops = {
1403 .owner = THIS_MODULE,
1404};
1405
1406/*
1407 * Once we're further in boot, we get probed like any other virtio
1408 * device.
1409 *
1410 * If the host also supports multiple console ports, we check the
1411 * config space to see how many ports the host has spawned. We
1412 * initialize each port found.
1413 */
1414static int __devinit virtcons_probe(struct virtio_device *vdev)
1415{
1416 struct ports_device *portdev;
1417 u32 i;
1418 int err;
1419 bool multiport;
1420
1421 portdev = kmalloc(sizeof(*portdev), GFP_KERNEL);
1422 if (!portdev) {
1423 err = -ENOMEM;
1424 goto fail;
1425 }
1426
1427 /* Attach this portdev to this virtio_device, and vice-versa. */
1428 portdev->vdev = vdev;
1429 vdev->priv = portdev;
1430
1431 spin_lock_irq(&pdrvdata_lock);
1432 portdev->drv_index = pdrvdata.index++;
1433 spin_unlock_irq(&pdrvdata_lock);
1434
1435 portdev->chr_major = register_chrdev(0, "virtio-portsdev",
1436 &portdev_fops);
1437 if (portdev->chr_major < 0) {
1438 dev_err(&vdev->dev,
1439 "Error %d registering chrdev for device %u\n",
1440 portdev->chr_major, portdev->drv_index);
1441 err = portdev->chr_major;
210 goto free; 1442 goto free;
1443 }
211 1444
212 in_vq = vqs[0]; 1445 multiport = false;
213 out_vq = vqs[1]; 1446 portdev->config.nr_ports = 1;
1447 portdev->config.max_nr_ports = 1;
1448#if 0 /* Multiport is not quite ready yet --RR */
1449 if (virtio_has_feature(vdev, VIRTIO_CONSOLE_F_MULTIPORT)) {
1450 multiport = true;
1451 vdev->features[0] |= 1 << VIRTIO_CONSOLE_F_MULTIPORT;
214 1452
215 /* Start using the new console output. */ 1453 vdev->config->get(vdev,
216 virtio_cons.get_chars = get_chars; 1454 offsetof(struct virtio_console_multiport_conf,
217 virtio_cons.put_chars = put_chars; 1455 nr_ports),
218 virtio_cons.notifier_add = notifier_add_vio; 1456 &portdev->config.nr_ports,
219 virtio_cons.notifier_del = notifier_del_vio; 1457 sizeof(portdev->config.nr_ports));
220 virtio_cons.notifier_hangup = notifier_del_vio; 1458 vdev->config->get(vdev,
221 1459 offsetof(struct virtio_console_multiport_conf,
222 /* The first argument of hvc_alloc() is the virtual console number, so 1460 max_nr_ports),
223 * we use zero. The second argument is the parameter for the 1461 &portdev->config.max_nr_ports,
224 * notification mechanism (like irq number). We currently leave this 1462 sizeof(portdev->config.max_nr_ports));
225 * as zero, virtqueues have implicit notifications. 1463 if (portdev->config.nr_ports > portdev->config.max_nr_ports) {
226 * 1464 dev_warn(&vdev->dev,
227 * The third argument is a "struct hv_ops" containing the put_chars() 1465 "More ports (%u) specified than allowed (%u). Will init %u ports.",
228 * get_chars(), notifier_add() and notifier_del() pointers. 1466 portdev->config.nr_ports,
229 * The final argument is the output buffer size: we can do any size, 1467 portdev->config.max_nr_ports,
230 * so we put PAGE_SIZE here. */ 1468 portdev->config.max_nr_ports);
231 hvc = hvc_alloc(0, 0, &virtio_cons, PAGE_SIZE); 1469
232 if (IS_ERR(hvc)) { 1470 portdev->config.nr_ports = portdev->config.max_nr_ports;
233 err = PTR_ERR(hvc); 1471 }
234 goto free_vqs; 1472 }
1473
1474 /* Let the Host know we support multiple ports.*/
1475 vdev->config->finalize_features(vdev);
1476#endif
1477
1478 err = init_vqs(portdev);
1479 if (err < 0) {
1480 dev_err(&vdev->dev, "Error %d initializing vqs\n", err);
1481 goto free_chrdev;
1482 }
1483
1484 spin_lock_init(&portdev->ports_lock);
1485 INIT_LIST_HEAD(&portdev->ports);
1486
1487 if (multiport) {
1488 unsigned int nr_added_bufs;
1489
1490 spin_lock_init(&portdev->cvq_lock);
1491 INIT_WORK(&portdev->control_work, &control_work_handler);
1492 INIT_WORK(&portdev->config_work, &config_work_handler);
1493
1494 nr_added_bufs = fill_queue(portdev->c_ivq, &portdev->cvq_lock);
1495 if (!nr_added_bufs) {
1496 dev_err(&vdev->dev,
1497 "Error allocating buffers for control queue\n");
1498 err = -ENOMEM;
1499 goto free_vqs;
1500 }
235 } 1501 }
236 1502
237 /* Register the input buffer the first time. */ 1503 for (i = 0; i < portdev->config.nr_ports; i++)
238 add_inbuf(); 1504 add_port(portdev, i);
1505
1506 /* Start using the new console output. */
1507 early_put_chars = NULL;
239 return 0; 1508 return 0;
240 1509
241free_vqs: 1510free_vqs:
242 vdev->config->del_vqs(vdev); 1511 vdev->config->del_vqs(vdev);
1512 kfree(portdev->in_vqs);
1513 kfree(portdev->out_vqs);
1514free_chrdev:
1515 unregister_chrdev(portdev->chr_major, "virtio-portsdev");
243free: 1516free:
244 kfree(inbuf); 1517 kfree(portdev);
245fail: 1518fail:
246 return err; 1519 return err;
247} 1520}
248 1521
1522static void virtcons_remove(struct virtio_device *vdev)
1523{
1524 struct ports_device *portdev;
1525 struct port *port, *port2;
1526 struct port_buffer *buf;
1527 unsigned int len;
1528
1529 portdev = vdev->priv;
1530
1531 cancel_work_sync(&portdev->control_work);
1532 cancel_work_sync(&portdev->config_work);
1533
1534 list_for_each_entry_safe(port, port2, &portdev->ports, list)
1535 remove_port(port);
1536
1537 unregister_chrdev(portdev->chr_major, "virtio-portsdev");
1538
1539 while ((buf = portdev->c_ivq->vq_ops->get_buf(portdev->c_ivq, &len)))
1540 free_buf(buf);
1541
1542 while ((buf = portdev->c_ivq->vq_ops->detach_unused_buf(portdev->c_ivq)))
1543 free_buf(buf);
1544
1545 vdev->config->del_vqs(vdev);
1546 kfree(portdev->in_vqs);
1547 kfree(portdev->out_vqs);
1548
1549 kfree(portdev);
1550}
1551
249static struct virtio_device_id id_table[] = { 1552static struct virtio_device_id id_table[] = {
250 { VIRTIO_ID_CONSOLE, VIRTIO_DEV_ANY_ID }, 1553 { VIRTIO_ID_CONSOLE, VIRTIO_DEV_ANY_ID },
251 { 0 }, 1554 { 0 },
@@ -262,14 +1565,41 @@ static struct virtio_driver virtio_console = {
262 .driver.owner = THIS_MODULE, 1565 .driver.owner = THIS_MODULE,
263 .id_table = id_table, 1566 .id_table = id_table,
264 .probe = virtcons_probe, 1567 .probe = virtcons_probe,
265 .config_changed = virtcons_apply_config, 1568 .remove = virtcons_remove,
1569 .config_changed = config_intr,
266}; 1570};
267 1571
268static int __init init(void) 1572static int __init init(void)
269{ 1573{
1574 int err;
1575
1576 pdrvdata.class = class_create(THIS_MODULE, "virtio-ports");
1577 if (IS_ERR(pdrvdata.class)) {
1578 err = PTR_ERR(pdrvdata.class);
1579 pr_err("Error %d creating virtio-ports class\n", err);
1580 return err;
1581 }
1582
1583 pdrvdata.debugfs_dir = debugfs_create_dir("virtio-ports", NULL);
1584 if (!pdrvdata.debugfs_dir) {
1585 pr_warning("Error %ld creating debugfs dir for virtio-ports\n",
1586 PTR_ERR(pdrvdata.debugfs_dir));
1587 }
1588 INIT_LIST_HEAD(&pdrvdata.consoles);
1589
270 return register_virtio_driver(&virtio_console); 1590 return register_virtio_driver(&virtio_console);
271} 1591}
1592
1593static void __exit fini(void)
1594{
1595 unregister_virtio_driver(&virtio_console);
1596
1597 class_destroy(pdrvdata.class);
1598 if (pdrvdata.debugfs_dir)
1599 debugfs_remove_recursive(pdrvdata.debugfs_dir);
1600}
272module_init(init); 1601module_init(init);
1602module_exit(fini);
273 1603
274MODULE_DEVICE_TABLE(virtio, id_table); 1604MODULE_DEVICE_TABLE(virtio, id_table);
275MODULE_DESCRIPTION("Virtio console driver"); 1605MODULE_DESCRIPTION("Virtio console driver");
diff --git a/drivers/char/vme_scc.c b/drivers/char/vme_scc.c
index 994e1a58b987..12de1202d22c 100644
--- a/drivers/char/vme_scc.c
+++ b/drivers/char/vme_scc.c
@@ -27,7 +27,6 @@
27#include <linux/fcntl.h> 27#include <linux/fcntl.h>
28#include <linux/major.h> 28#include <linux/major.h>
29#include <linux/delay.h> 29#include <linux/delay.h>
30#include <linux/slab.h>
31#include <linux/miscdevice.h> 30#include <linux/miscdevice.h>
32#include <linux/console.h> 31#include <linux/console.h>
33#include <linux/init.h> 32#include <linux/init.h>
@@ -136,7 +135,7 @@ static const struct tty_port_operations scc_port_ops = {
136 * vme_scc_init() and support functions 135 * vme_scc_init() and support functions
137 *---------------------------------------------------------------------------*/ 136 *---------------------------------------------------------------------------*/
138 137
139static int scc_init_drivers(void) 138static int __init scc_init_drivers(void)
140{ 139{
141 int error; 140 int error;
142 141
@@ -172,7 +171,7 @@ static int scc_init_drivers(void)
172/* ports[] array is indexed by line no (i.e. [0] for ttyS0, [1] for ttyS1). 171/* ports[] array is indexed by line no (i.e. [0] for ttyS0, [1] for ttyS1).
173 */ 172 */
174 173
175static void scc_init_portstructs(void) 174static void __init scc_init_portstructs(void)
176{ 175{
177 struct scc_port *port; 176 struct scc_port *port;
178 int i; 177 int i;
@@ -195,7 +194,7 @@ static void scc_init_portstructs(void)
195 194
196 195
197#ifdef CONFIG_MVME147_SCC 196#ifdef CONFIG_MVME147_SCC
198static int mvme147_scc_init(void) 197static int __init mvme147_scc_init(void)
199{ 198{
200 struct scc_port *port; 199 struct scc_port *port;
201 int error; 200 int error;
@@ -298,7 +297,7 @@ fail:
298 297
299 298
300#ifdef CONFIG_MVME162_SCC 299#ifdef CONFIG_MVME162_SCC
301static int mvme162_scc_init(void) 300static int __init mvme162_scc_init(void)
302{ 301{
303 struct scc_port *port; 302 struct scc_port *port;
304 int error; 303 int error;
@@ -404,7 +403,7 @@ fail:
404 403
405 404
406#ifdef CONFIG_BVME6000_SCC 405#ifdef CONFIG_BVME6000_SCC
407static int bvme6000_scc_init(void) 406static int __init bvme6000_scc_init(void)
408{ 407{
409 struct scc_port *port; 408 struct scc_port *port;
410 int error; 409 int error;
@@ -503,7 +502,7 @@ fail_free_b_rx:
503#endif 502#endif
504 503
505 504
506static int vme_scc_init(void) 505static int __init vme_scc_init(void)
507{ 506{
508 int res = -ENODEV; 507 int res = -ENODEV;
509 508
diff --git a/drivers/char/vt.c b/drivers/char/vt.c
index 0c80c68cd047..bd1d1164fec5 100644
--- a/drivers/char/vt.c
+++ b/drivers/char/vt.c
@@ -161,6 +161,11 @@ static void set_palette(struct vc_data *vc);
161static int printable; /* Is console ready for printing? */ 161static int printable; /* Is console ready for printing? */
162int default_utf8 = true; 162int default_utf8 = true;
163module_param(default_utf8, int, S_IRUGO | S_IWUSR); 163module_param(default_utf8, int, S_IRUGO | S_IWUSR);
164int global_cursor_default = -1;
165module_param(global_cursor_default, int, S_IRUGO | S_IWUSR);
166
167static int cur_default = CUR_DEFAULT;
168module_param(cur_default, int, S_IRUGO | S_IWUSR);
164 169
165/* 170/*
166 * ignore_poke: don't unblank the screen when things are typed. This is 171 * ignore_poke: don't unblank the screen when things are typed. This is
@@ -182,12 +187,10 @@ static DECLARE_WORK(console_work, console_callback);
182 * fg_console is the current virtual console, 187 * fg_console is the current virtual console,
183 * last_console is the last used one, 188 * last_console is the last used one,
184 * want_console is the console we want to switch to, 189 * want_console is the console we want to switch to,
185 * kmsg_redirect is the console for kernel messages,
186 */ 190 */
187int fg_console; 191int fg_console;
188int last_console; 192int last_console;
189int want_console = -1; 193int want_console = -1;
190int kmsg_redirect;
191 194
192/* 195/*
193 * For each existing display, we have a pointer to console currently visible 196 * For each existing display, we have a pointer to console currently visible
@@ -775,6 +778,12 @@ int vc_allocate(unsigned int currcons) /* return 0 on success */
775 vc_cons[currcons].d = NULL; 778 vc_cons[currcons].d = NULL;
776 return -ENOMEM; 779 return -ENOMEM;
777 } 780 }
781
782 /* If no drivers have overridden us and the user didn't pass a
783 boot option, default to displaying the cursor */
784 if (global_cursor_default == -1)
785 global_cursor_default = 1;
786
778 vc_init(vc, vc->vc_rows, vc->vc_cols, 1); 787 vc_init(vc, vc->vc_rows, vc->vc_cols, 1);
779 vcs_make_sysfs(currcons); 788 vcs_make_sysfs(currcons);
780 atomic_notifier_call_chain(&vt_notifier_list, VT_ALLOCATE, &param); 789 atomic_notifier_call_chain(&vt_notifier_list, VT_ALLOCATE, &param);
@@ -812,7 +821,7 @@ static inline int resize_screen(struct vc_data *vc, int width, int height,
812 * 821 *
813 * Resize a virtual console, clipping according to the actual constraints. 822 * Resize a virtual console, clipping according to the actual constraints.
814 * If the caller passes a tty structure then update the termios winsize 823 * If the caller passes a tty structure then update the termios winsize
815 * information and perform any neccessary signal handling. 824 * information and perform any necessary signal handling.
816 * 825 *
817 * Caller must hold the console semaphore. Takes the termios mutex and 826 * Caller must hold the console semaphore. Takes the termios mutex and
818 * ctrl_lock of the tty IFF a tty is passed. 827 * ctrl_lock of the tty IFF a tty is passed.
@@ -1616,7 +1625,7 @@ static void reset_terminal(struct vc_data *vc, int do_clear)
1616 vc->vc_decscnm = 0; 1625 vc->vc_decscnm = 0;
1617 vc->vc_decom = 0; 1626 vc->vc_decom = 0;
1618 vc->vc_decawm = 1; 1627 vc->vc_decawm = 1;
1619 vc->vc_deccm = 1; 1628 vc->vc_deccm = global_cursor_default;
1620 vc->vc_decim = 0; 1629 vc->vc_decim = 0;
1621 1630
1622 set_kbd(vc, decarm); 1631 set_kbd(vc, decarm);
@@ -1630,7 +1639,7 @@ static void reset_terminal(struct vc_data *vc, int do_clear)
1630 /* do not do set_leds here because this causes an endless tasklet loop 1639 /* do not do set_leds here because this causes an endless tasklet loop
1631 when the keyboard hasn't been initialized yet */ 1640 when the keyboard hasn't been initialized yet */
1632 1641
1633 vc->vc_cursor_type = CUR_DEFAULT; 1642 vc->vc_cursor_type = cur_default;
1634 vc->vc_complement_mask = vc->vc_s_complement_mask; 1643 vc->vc_complement_mask = vc->vc_s_complement_mask;
1635 1644
1636 default_attr(vc); 1645 default_attr(vc);
@@ -1832,7 +1841,7 @@ static void do_con_trol(struct tty_struct *tty, struct vc_data *vc, int c)
1832 if (vc->vc_par[0]) 1841 if (vc->vc_par[0])
1833 vc->vc_cursor_type = vc->vc_par[0] | (vc->vc_par[1] << 8) | (vc->vc_par[2] << 16); 1842 vc->vc_cursor_type = vc->vc_par[0] | (vc->vc_par[1] << 8) | (vc->vc_par[2] << 16);
1834 else 1843 else
1835 vc->vc_cursor_type = CUR_DEFAULT; 1844 vc->vc_cursor_type = cur_default;
1836 return; 1845 return;
1837 } 1846 }
1838 break; 1847 break;
@@ -2110,8 +2119,6 @@ static int do_con_write(struct tty_struct *tty, const unsigned char *buf, int co
2110 uint8_t inverse; 2119 uint8_t inverse;
2111 uint8_t width; 2120 uint8_t width;
2112 u16 himask, charmask; 2121 u16 himask, charmask;
2113 const unsigned char *orig_buf = NULL;
2114 int orig_count;
2115 2122
2116 if (in_interrupt()) 2123 if (in_interrupt())
2117 return count; 2124 return count;
@@ -2133,8 +2140,6 @@ static int do_con_write(struct tty_struct *tty, const unsigned char *buf, int co
2133 release_console_sem(); 2140 release_console_sem();
2134 return 0; 2141 return 0;
2135 } 2142 }
2136 orig_buf = buf;
2137 orig_count = count;
2138 2143
2139 himask = vc->vc_hi_font_mask; 2144 himask = vc->vc_hi_font_mask;
2140 charmask = himask ? 0x1ff : 0xff; 2145 charmask = himask ? 0x1ff : 0xff;
@@ -2426,6 +2431,37 @@ struct tty_driver *console_driver;
2426 2431
2427#ifdef CONFIG_VT_CONSOLE 2432#ifdef CONFIG_VT_CONSOLE
2428 2433
2434/**
2435 * vt_kmsg_redirect() - Sets/gets the kernel message console
2436 * @new: The new virtual terminal number or -1 if the console should stay
2437 * unchanged
2438 *
2439 * By default, the kernel messages are always printed on the current virtual
2440 * console. However, the user may modify that default with the
2441 * TIOCL_SETKMSGREDIRECT ioctl call.
2442 *
2443 * This function sets the kernel message console to be @new. It returns the old
2444 * virtual console number. The virtual terminal number 0 (both as parameter and
2445 * return value) means no redirection (i.e. always printed on the currently
2446 * active console).
2447 *
2448 * The parameter -1 means that only the current console is returned, but the
2449 * value is not modified. You may use the macro vt_get_kmsg_redirect() in that
2450 * case to make the code more understandable.
2451 *
2452 * When the kernel is compiled without CONFIG_VT_CONSOLE, this function ignores
2453 * the parameter and always returns 0.
2454 */
2455int vt_kmsg_redirect(int new)
2456{
2457 static int kmsg_con;
2458
2459 if (new != -1)
2460 return xchg(&kmsg_con, new);
2461 else
2462 return kmsg_con;
2463}
2464
2429/* 2465/*
2430 * Console on virtual terminal 2466 * Console on virtual terminal
2431 * 2467 *
@@ -2440,6 +2476,7 @@ static void vt_console_print(struct console *co, const char *b, unsigned count)
2440 const ushort *start; 2476 const ushort *start;
2441 ushort cnt = 0; 2477 ushort cnt = 0;
2442 ushort myx; 2478 ushort myx;
2479 int kmsg_console;
2443 2480
2444 /* console busy or not yet initialized */ 2481 /* console busy or not yet initialized */
2445 if (!printable) 2482 if (!printable)
@@ -2447,8 +2484,9 @@ static void vt_console_print(struct console *co, const char *b, unsigned count)
2447 if (!spin_trylock(&printing_lock)) 2484 if (!spin_trylock(&printing_lock))
2448 return; 2485 return;
2449 2486
2450 if (kmsg_redirect && vc_cons_allocated(kmsg_redirect - 1)) 2487 kmsg_console = vt_get_kmsg_redirect();
2451 vc = vc_cons[kmsg_redirect - 1].d; 2488 if (kmsg_console && vc_cons_allocated(kmsg_console - 1))
2489 vc = vc_cons[kmsg_console - 1].d;
2452 2490
2453 /* read `x' only after setting currcons properly (otherwise 2491 /* read `x' only after setting currcons properly (otherwise
2454 the `x' macro will read the x of the foreground console). */ 2492 the `x' macro will read the x of the foreground console). */
@@ -2605,7 +2643,7 @@ int tioclinux(struct tty_struct *tty, unsigned long arg)
2605 ret = set_vesa_blanking(p); 2643 ret = set_vesa_blanking(p);
2606 break; 2644 break;
2607 case TIOCL_GETKMSGREDIRECT: 2645 case TIOCL_GETKMSGREDIRECT:
2608 data = kmsg_redirect; 2646 data = vt_get_kmsg_redirect();
2609 ret = __put_user(data, p); 2647 ret = __put_user(data, p);
2610 break; 2648 break;
2611 case TIOCL_SETKMSGREDIRECT: 2649 case TIOCL_SETKMSGREDIRECT:
@@ -2615,7 +2653,7 @@ int tioclinux(struct tty_struct *tty, unsigned long arg)
2615 if (get_user(data, p+1)) 2653 if (get_user(data, p+1))
2616 ret = -EFAULT; 2654 ret = -EFAULT;
2617 else 2655 else
2618 kmsg_redirect = data; 2656 vt_kmsg_redirect(data);
2619 } 2657 }
2620 break; 2658 break;
2621 case TIOCL_GETFGCONSOLE: 2659 case TIOCL_GETFGCONSOLE:
@@ -4078,6 +4116,7 @@ EXPORT_SYMBOL(fg_console);
4078EXPORT_SYMBOL(console_blank_hook); 4116EXPORT_SYMBOL(console_blank_hook);
4079EXPORT_SYMBOL(console_blanked); 4117EXPORT_SYMBOL(console_blanked);
4080EXPORT_SYMBOL(vc_cons); 4118EXPORT_SYMBOL(vc_cons);
4119EXPORT_SYMBOL(global_cursor_default);
4081#ifndef VT_SINGLE_DRIVER 4120#ifndef VT_SINGLE_DRIVER
4082EXPORT_SYMBOL(take_over_console); 4121EXPORT_SYMBOL(take_over_console);
4083EXPORT_SYMBOL(give_up_console); 4122EXPORT_SYMBOL(give_up_console);
diff --git a/drivers/char/xilinx_hwicap/xilinx_hwicap.c b/drivers/char/xilinx_hwicap/xilinx_hwicap.c
index 4846d50199f3..7261b8d9087c 100644
--- a/drivers/char/xilinx_hwicap/xilinx_hwicap.c
+++ b/drivers/char/xilinx_hwicap/xilinx_hwicap.c
@@ -86,6 +86,7 @@
86#include <linux/fs.h> 86#include <linux/fs.h>
87#include <linux/cdev.h> 87#include <linux/cdev.h>
88#include <linux/platform_device.h> 88#include <linux/platform_device.h>
89#include <linux/slab.h>
89 90
90#include <asm/io.h> 91#include <asm/io.h>
91#include <asm/uaccess.h> 92#include <asm/uaccess.h>