[PATCH 12/14] hvc_console: Register ops when setting up hvc_console

Anton Blanchard anton at samba.org
Thu Jul 7 02:02:09 EST 2005


From: Milton Miller <miltonm at bga.com>

When registering the hvc console port, register a list of ops (read and
write) to go with it, instead of calling fixed function names.

This allows different ports to encode the data differently.

Signed-off-by: Milton Miller <miltonm at bga.com>
Signed-off-by: Anton Blanchard <anton at samba.org>

diff -puN drivers/char/hvc_console.c~hvc-console-hooked drivers/char/hvc_console.c
--- gr_work_small/drivers/char/hvc_console.c~hvc-console-hooked	2005-05-31 21:59:59.410444389 -0500
+++ gr_work_small-miltonm/drivers/char/hvc_console.c	2005-05-31 21:59:59.432440906 -0500
@@ -85,6 +85,7 @@ struct hvc_struct {
 	char outbuf[N_OUTBUF] __ALIGNED__;
 	int n_outbuf;
 	uint32_t vtermno;
+	struct hv_ops *ops;
 	int irq_requested;
 	int irq;
 	struct list_head next;
@@ -142,6 +143,7 @@ struct hvc_struct *hvc_get_by_index(int 
  * console interfaces but can still be used as a tty device.  This has to be
  * static because kmalloc will not work during early console init.
  */
+static struct hv_ops *cons_ops[MAX_NR_HVC_CONSOLES];
 static uint32_t vtermnos[MAX_NR_HVC_CONSOLES] =
 	{[0 ... MAX_NR_HVC_CONSOLES - 1] = -1};
 
@@ -154,14 +156,14 @@ void hvc_console_print(struct console *c
 {
 	char c[16] __ALIGNED__;
 	unsigned i = 0, n = 0;
-	int r, donecr = 0;
+	int r, donecr = 0, index = co->index;
 
 	/* Console access attempt outside of acceptable console range. */
-	if (co->index >= MAX_NR_HVC_CONSOLES)
+	if (index >= MAX_NR_HVC_CONSOLES)
 		return;
 
 	/* This console adapter was removed so it is not useable. */
-	if (vtermnos[co->index] < 0)
+	if (vtermnos[index] < 0)
 		return;
 
 	while (count > 0 || i > 0) {
@@ -175,7 +177,7 @@ void hvc_console_print(struct console *c
 				--count;
 			}
 		} else {
-			r = hvc_put_chars(vtermnos[co->index], c, i);
+			r = cons_ops[index]->put_chars(vtermnos[index], c, i);
 			if (r < 0) {
 				/* throw away chars on error */
 				i = 0;
@@ -245,7 +247,7 @@ console_initcall(hvc_console_init);
  * vty adapters do NOT get an hvc_instantiate() callback since they
  * appear after early console init.
  */
-int hvc_instantiate(uint32_t vtermno, int index)
+int hvc_instantiate(uint32_t vtermno, int index, struct hv_ops *ops)
 {
 	struct hvc_struct *hp;
 
@@ -263,6 +265,7 @@ int hvc_instantiate(uint32_t vtermno, in
 	}
 
 	vtermnos[index] = vtermno;
+	cons_ops[index] = ops;
 
 	/* reserve all indices upto and including this index */
 	if (last_hvc < index)
@@ -466,7 +469,7 @@ static void hvc_push(struct hvc_struct *
 {
 	int n;
 
-	n = hvc_put_chars(hp->vtermno, hp->outbuf, hp->n_outbuf);
+	n = hp->ops->put_chars(hp->vtermno, hp->outbuf, hp->n_outbuf);
 	if (n <= 0) {
 		if (n == 0)
 			return;
@@ -604,7 +607,7 @@ static int hvc_poll(struct hvc_struct *h
 			break;
 		}
 
-		n = hvc_get_chars(hp->vtermno, buf, count);
+		n = hp->ops->get_chars(hp->vtermno, buf, count);
 		if (n <= 0) {
 			/* Hangup the tty when disconnected from host */
 			if (n == -EPIPE) {
@@ -737,7 +740,8 @@ static struct kobj_type hvc_kobj_type = 
 	.release = destroy_hvc_struct,
 };
 
-struct hvc_struct __devinit *hvc_alloc(uint32_t vtermno, int irq)
+struct hvc_struct __devinit *hvc_alloc(uint32_t vtermno, int irq,
+					struct hv_ops *ops)
 {
 	struct hvc_struct *hp;
 	int i;
@@ -750,6 +754,7 @@ struct hvc_struct __devinit *hvc_alloc(u
 
 	hp->vtermno = vtermno;
 	hp->irq = irq;
+	hp->ops = ops;
 
 	kobject_init(&hp->kobj);
 	hp->kobj.ktype = &hvc_kobj_type;
diff -puN drivers/char/hvc_vio.c~hvc-console-hooked drivers/char/hvc_vio.c
--- gr_work_small/drivers/char/hvc_vio.c~hvc-console-hooked	2005-05-31 21:59:59.414443756 -0500
+++ gr_work_small-miltonm/drivers/char/hvc_vio.c	2005-05-31 22:01:10.628964170 -0500
@@ -43,6 +43,11 @@ static struct vio_device_id hvc_driver_t
 };
 MODULE_DEVICE_TABLE(vio, hvc_driver_table);
 
+static struct hv_ops hvc_get_put_ops = {
+	.get_chars = hvc_get_chars,
+	.put_chars = hvc_put_chars,
+};
+
 static int __devinit hvc_vio_probe(struct vio_dev *vdev,
 				const struct vio_device_id *id)
 {
@@ -52,7 +57,7 @@ static int __devinit hvc_vio_probe(struc
 	if (!vdev || !id)
 		return -EPERM;
 
-	hp = hvc_alloc(vdev->unit_address, vdev->irq);
+	hp = hvc_alloc(vdev->unit_address, vdev->irq, &hvc_get_put_ops);
 	if (IS_ERR(hp))
 		return PTR_ERR(hp);
 	dev_set_drvdata(&vdev->dev, hp);
@@ -115,7 +120,7 @@ static int hvc_find_vtys(void)
 			continue;
 
 		if (device_is_compatible(vty, "hvterm1")) {
-			hvc_instantiate(*vtermno, num_found);
+			hvc_instantiate(*vtermno, num_found, &hvc_get_put_ops);
 			++num_found;
 		}
 	}
diff -puN include/asm-ppc64/hvconsole.h~hvc-console-hooked include/asm-ppc64/hvconsole.h
--- gr_work_small/include/asm-ppc64/hvconsole.h~hvc-console-hooked	2005-05-31 21:59:59.419442964 -0500
+++ gr_work_small-miltonm/include/asm-ppc64/hvconsole.h	2005-05-31 21:59:59.433440748 -0500
@@ -30,15 +30,20 @@
 #define MAX_NR_HVC_CONSOLES	16
 
 /* implemented by a low level driver */
+struct hv_ops {
+	int (*get_chars)(uint32_t vtermno, char *buf, int count);
+	int (*put_chars)(uint32_t vtermno, const char *buf, int count);
+};
 extern int hvc_get_chars(uint32_t vtermno, char *buf, int count);
 extern int hvc_put_chars(uint32_t vtermno, const char *buf, int count);
 
 struct hvc_struct;
 
 /* Register a vterm and a slot index for use as a console (console_init) */
-extern int hvc_instantiate(uint32_t vtermno, int index);
+extern int hvc_instantiate(uint32_t vtermno, int index, struct hv_ops *ops);
 /* register a vterm for hvc tty operation (module_init or hotplug add) */
-extern struct hvc_struct * __devinit hvc_alloc(uint32_t vtermno, int irq);
+extern struct hvc_struct * __devinit hvc_alloc(uint32_t vtermno, int irq,
+						 struct hv_ops *ops);
 /* remove a vterm from hvc tty operation (modele_exit or hotplug remove) */
 extern int __devexit hvc_remove(struct hvc_struct *hp);
 #endif /* _PPC64_HVCONSOLE_H */
_



More information about the Linuxppc64-dev mailing list