Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[PATCH] powerpc: hvc_console updates

These are some updates from both Ryan and Arnd for the hvc_console
driver:

The main point is to enable the inclusion of a console driver
for rtas, which is currrently needed for the cell platform.

Also shuffle around some data-type declarations and moves some
functions out of include/asm-ppc64/hvconsole.h and into a new
drivers/char/hvc_console.h file.

Signed-off-by: "Ryan S. Arnold" <rsa@us.ibm.com>
Signed-off-by: Arnd Bergmann <abergman@de.ibm.com>
Signed-off-by: Paul Mackerras <paulus@samba.org>

authored by

Ryan S. Arnold and committed by
Paul Mackerras
45d607ed 11089f08

+128 -59
+5
arch/powerpc/platforms/pseries/hvconsole.c
··· 62 62 unsigned long *lbuf = (unsigned long *) buf; 63 63 long ret; 64 64 65 + 66 + /* hcall will ret H_PARAMETER if 'count' exceeds firmware max.*/ 67 + if (count > MAX_VIO_PUT_CHARS) 68 + count = MAX_VIO_PUT_CHARS; 69 + 65 70 ret = plpar_hcall_norets(H_PUT_TERM_CHAR, vtermno, count, lbuf[0], 66 71 lbuf[1]); 67 72 if (ret == H_Success)
+10
drivers/char/Kconfig
··· 561 561 562 562 If unsure, say N. 563 563 564 + config HVC_DRIVER 565 + bool 566 + help 567 + Users of pSeries machines that want to utilize the hvc console front-end 568 + module for their backend console driver should select this option. 569 + It will automatically be selected if one of the back-end console drivers 570 + is selected. 571 + 572 + 564 573 config HVC_CONSOLE 565 574 bool "pSeries Hypervisor Virtual Console support" 566 575 depends on PPC_PSERIES 576 + select HVC_DRIVER 567 577 help 568 578 pSeries machines when partitioned support a hypervisor virtual 569 579 console. This driver allows each pSeries partition to have a console
+2 -1
drivers/char/Makefile
··· 41 41 obj-$(CONFIG_AMIGA_BUILTIN_SERIAL) += amiserial.o 42 42 obj-$(CONFIG_SX) += sx.o generic_serial.o 43 43 obj-$(CONFIG_RIO) += rio/ generic_serial.o 44 - obj-$(CONFIG_HVC_CONSOLE) += hvc_console.o hvc_vio.o hvsi.o 44 + obj-$(CONFIG_HVC_DRIVER) += hvc_console.o 45 + obj-$(CONFIG_HVC_CONSOLE) += hvc_vio.o hvsi.o 45 46 obj-$(CONFIG_RAW_DRIVER) += raw.o 46 47 obj-$(CONFIG_SGI_SNSC) += snsc.o snsc_event.o 47 48 obj-$(CONFIG_MMTIMER) += mmtimer.o
+29 -40
drivers/char/hvc_console.c
··· 39 39 #include <linux/sched.h> 40 40 #include <linux/spinlock.h> 41 41 #include <linux/delay.h> 42 + 42 43 #include <asm/uaccess.h> 43 - #include <asm/hvconsole.h> 44 + 45 + #include "hvc_console.h" 44 46 45 47 #define HVC_MAJOR 229 46 48 #define HVC_MINOR 0 ··· 56 54 #define HVC_CLOSE_WAIT (HZ/100) /* 1/10 of a second */ 57 55 58 56 /* 59 - * The Linux TTY code does not support dynamic addition of tty derived devices 60 - * so we need to know how many tty devices we might need when space is allocated 61 - * for the tty device. Since this driver supports hotplug of vty adapters we 62 - * need to make sure we have enough allocated. 57 + * These sizes are most efficient for vio, because they are the 58 + * native transfer size. We could make them selectable in the 59 + * future to better deal with backends that want other buffer sizes. 63 60 */ 64 - #define HVC_ALLOC_TTY_ADAPTERS 8 65 - 66 61 #define N_OUTBUF 16 67 62 #define N_INBUF 16 68 63 69 - #define __ALIGNED__ __attribute__((__aligned__(8))) 64 + #define __ALIGNED__ __attribute__((__aligned__(sizeof(long)))) 70 65 71 66 static struct tty_driver *hvc_driver; 72 67 static struct task_struct *hvc_task; ··· 153 154 154 155 void hvc_console_print(struct console *co, const char *b, unsigned count) 155 156 { 156 - char c[16] __ALIGNED__; 157 + char c[N_OUTBUF] __ALIGNED__; 157 158 unsigned i = 0, n = 0; 158 159 int r, donecr = 0, index = co->index; 159 160 ··· 472 473 473 474 n = hp->ops->put_chars(hp->vtermno, hp->outbuf, hp->n_outbuf); 474 475 if (n <= 0) { 475 - if (n == 0) 476 + if (n == 0) { 477 + hp->do_wakeup = 1; 476 478 return; 479 + } 477 480 /* throw away output on error; this happens when 478 481 there is no session connected to the vterm. */ 479 482 hp->n_outbuf = 0; ··· 487 486 hp->do_wakeup = 1; 488 487 } 489 488 490 - static inline int __hvc_write_kernel(struct hvc_struct *hp, 491 - const unsigned char *buf, int count) 489 + static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count) 492 490 { 491 + struct hvc_struct *hp = tty->driver_data; 493 492 unsigned long flags; 494 493 int rsize, written = 0; 494 + 495 + /* This write was probably executed during a tty close. */ 496 + if (!hp) 497 + return -EPIPE; 498 + 499 + if (hp->count <= 0) 500 + return -EIO; 495 501 496 502 spin_lock_irqsave(&hp->lock, flags); 497 503 ··· 518 510 } 519 511 spin_unlock_irqrestore(&hp->lock, flags); 520 512 521 - return written; 522 - } 523 - static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count) 524 - { 525 - struct hvc_struct *hp = tty->driver_data; 526 - int written; 527 - 528 - /* This write was probably executed during a tty close. */ 529 - if (!hp) 530 - return -EPIPE; 531 - 532 - if (hp->count <= 0) 533 - return -EIO; 534 - 535 - written = __hvc_write_kernel(hp, buf, count); 536 - 537 513 /* 538 514 * Racy, but harmless, kick thread if there is still pending data. 539 - * There really is nothing wrong with kicking the thread, even if there 540 - * is no buffered data. 541 515 */ 542 516 if (hp->n_outbuf) 543 517 hvc_kick(); ··· 604 614 spin_unlock_irqrestore(&hp->lock, flags); 605 615 tty_hangup(tty); 606 616 spin_lock_irqsave(&hp->lock, flags); 617 + } else if ( n == -EAGAIN ) { 618 + /* 619 + * Some back-ends can only ensure a certain min 620 + * num of bytes read, which may be > 'count'. 621 + * Let the tty clear the flip buff to make room. 622 + */ 623 + poll_mask |= HVC_POLL_READ; 607 624 } 608 625 break; 609 626 } ··· 632 635 tty_insert_flip_char(tty, buf[i], 0); 633 636 } 634 637 635 - /* 636 - * Account for the total amount read in one loop, and if above 637 - * 64 bytes, we do a quick schedule loop to let the tty grok 638 - * the data and eventually throttle us. 639 - */ 640 638 read_total += n; 641 - if (read_total >= 64) { 642 - poll_mask |= HVC_POLL_QUICK; 643 - break; 644 - } 645 639 } 646 640 throttled: 647 641 /* Wakeup write queue if necessary */ ··· 755 767 * see if this vterm id matches one registered for console. 756 768 */ 757 769 for (i=0; i < MAX_NR_HVC_CONSOLES; i++) 758 - if (vtermnos[i] == hp->vtermno) 770 + if (vtermnos[i] == hp->vtermno && 771 + cons_ops[i] == hp->ops) 759 772 break; 760 773 761 774 /* no matching slot, just use a counter */
+63
drivers/char/hvc_console.h
··· 1 + /* 2 + * hvc_console.h 3 + * Copyright (C) 2005 IBM Corporation 4 + * 5 + * Author(s): 6 + * Ryan S. Arnold <rsa@us.ibm.com> 7 + * 8 + * hvc_console header information: 9 + * moved here from include/asm-powerpc/hvconsole.h 10 + * and drivers/char/hvc_console.c 11 + * 12 + * This program is free software; you can redistribute it and/or modify 13 + * it under the terms of the GNU General Public License as published by 14 + * the Free Software Foundation; either version 2 of the License, or 15 + * (at your option) any later version. 16 + * 17 + * This program is distributed in the hope that it will be useful, 18 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 19 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 + * GNU General Public License for more details. 21 + * 22 + * You should have received a copy of the GNU General Public License 23 + * along with this program; if not, write to the Free Software 24 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 25 + */ 26 + 27 + #ifndef HVC_CONSOLE_H 28 + #define HVC_CONSOLE_H 29 + 30 + /* 31 + * This is the max number of console adapters that can/will be found as 32 + * console devices on first stage console init. Any number beyond this range 33 + * can't be used as a console device but is still a valid tty device. 34 + */ 35 + #define MAX_NR_HVC_CONSOLES 16 36 + 37 + /* 38 + * The Linux TTY code does not support dynamic addition of tty derived devices 39 + * so we need to know how many tty devices we might need when space is allocated 40 + * for the tty device. Since this driver supports hotplug of vty adapters we 41 + * need to make sure we have enough allocated. 42 + */ 43 + #define HVC_ALLOC_TTY_ADAPTERS 8 44 + 45 + 46 + /* implemented by a low level driver */ 47 + struct hv_ops { 48 + int (*get_chars)(uint32_t vtermno, char *buf, int count); 49 + int (*put_chars)(uint32_t vtermno, const char *buf, int count); 50 + }; 51 + 52 + struct hvc_struct; 53 + 54 + /* Register a vterm and a slot index for use as a console (console_init) */ 55 + extern int hvc_instantiate(uint32_t vtermno, int index, struct hv_ops *ops); 56 + 57 + /* register a vterm for hvc tty operation (module_init or hotplug add) */ 58 + extern struct hvc_struct * __devinit hvc_alloc(uint32_t vtermno, int irq, 59 + struct hv_ops *ops); 60 + /* remove a vterm from hvc tty operation (modele_exit or hotplug remove) */ 61 + extern int __devexit hvc_remove(struct hvc_struct *hp); 62 + 63 + #endif // HVC_CONSOLE_H
+11
drivers/char/hvc_vio.c
··· 31 31 32 32 #include <linux/types.h> 33 33 #include <linux/init.h> 34 + 34 35 #include <asm/hvconsole.h> 35 36 #include <asm/vio.h> 36 37 #include <asm/prom.h> 38 + 39 + #include "hvc_console.h" 37 40 38 41 char hvc_driver_name[] = "hvc_console"; 39 42 ··· 50 47 { 51 48 unsigned long got; 52 49 int i; 50 + 51 + /* 52 + * Vio firmware will read up to SIZE_VIO_GET_CHARS at its own discretion 53 + * so we play safe and avoid the situation where got > count which could 54 + * overload the flip buffer. 55 + */ 56 + if (count < SIZE_VIO_GET_CHARS) 57 + return -EAGAIN; 53 58 54 59 got = hvc_get_chars(vtermno, buf, count); 55 60
+8 -18
include/asm-powerpc/hvconsole.h
··· 24 24 #ifdef __KERNEL__ 25 25 26 26 /* 27 - * This is the max number of console adapters that can/will be found as 28 - * console devices on first stage console init. Any number beyond this range 29 - * can't be used as a console device but is still a valid tty device. 27 + * PSeries firmware will only send/recv up to 16 bytes of character data per 28 + * hcall. 30 29 */ 31 - #define MAX_NR_HVC_CONSOLES 16 30 + #define MAX_VIO_PUT_CHARS 16 31 + #define SIZE_VIO_GET_CHARS 16 32 32 33 - /* implemented by a low level driver */ 34 - struct hv_ops { 35 - int (*get_chars)(uint32_t vtermno, char *buf, int count); 36 - int (*put_chars)(uint32_t vtermno, const char *buf, int count); 37 - }; 33 + /* 34 + * Vio firmware always attempts to fetch MAX_VIO_GET_CHARS chars. The 'count' 35 + * parm is included to conform to put_chars() function pointer template 36 + */ 38 37 extern int hvc_get_chars(uint32_t vtermno, char *buf, int count); 39 38 extern int hvc_put_chars(uint32_t vtermno, const char *buf, int count); 40 39 41 - struct hvc_struct; 42 - 43 - /* Register a vterm and a slot index for use as a console (console_init) */ 44 - extern int hvc_instantiate(uint32_t vtermno, int index, struct hv_ops *ops); 45 - /* register a vterm for hvc tty operation (module_init or hotplug add) */ 46 - extern struct hvc_struct * __devinit hvc_alloc(uint32_t vtermno, int irq, 47 - struct hv_ops *ops); 48 - /* remove a vterm from hvc tty operation (modele_exit or hotplug remove) */ 49 - extern int __devexit hvc_remove(struct hvc_struct *hp); 50 40 #endif /* __KERNEL__ */ 51 41 #endif /* _PPC64_HVCONSOLE_H */