Skip to content

Commit bda0f5b

Browse files
tile: various console improvements
This change improves and cleans up the tile console. - We enable HVC_IRQ support on tilegx, with the addition of a new Tilera hypervisor API for tilegx to allow a console IPI. If IPI support is not available we fall back to the previous polling mode. - We simplify the earlyprintk code to use CON_BOOT and eliminate some of the other supporting earlyprintk code. - A new tile_console_write() primitive is used to send output to the console and is factored out of the hvc_tile driver. This lets us support a "sim_console" boot argument to allow using simulator hooks to send output to the "console" as a slightly faster alternative to emulating the hardware more directly. Signed-off-by: Chris Metcalf <cmetcalf@tilera.com> Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 7c29b78 commit bda0f5b

7 files changed

Lines changed: 186 additions & 48 deletions

File tree

‎arch/tile/Kconfig‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ config SMP
112112
config HVC_TILE
113113
depends on TTY
114114
select HVC_DRIVER
115+
select HVC_IRQ if TILEGX
115116
def_bool y
116117

117118
config TILEGX

‎arch/tile/include/asm/setup.h‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,8 @@
2424
*/
2525
#define MAXMEM_PFN PFN_DOWN(MAXMEM)
2626

27+
int tile_console_write(const char *buf, int count);
2728
void early_panic(const char *fmt, ...);
28-
void warn_early_printk(void);
29-
void __init disable_early_printk(void);
3029

3130
/* Init-time routine to do tile-specific per-cpu setup. */
3231
void setup_cpu(int boot);

‎arch/tile/include/hv/hypervisor.h‎

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,8 +318,11 @@
318318
/** hv_set_pte_super_shift */
319319
#define HV_DISPATCH_SET_PTE_SUPER_SHIFT 57
320320

321+
/** hv_console_set_ipi */
322+
#define HV_DISPATCH_CONSOLE_SET_IPI 63
323+
321324
/** One more than the largest dispatch value */
322-
#define _HV_DISPATCH_END 58
325+
#define _HV_DISPATCH_END 64
323326

324327

325328
#ifndef __ASSEMBLER__
@@ -585,6 +588,30 @@ typedef struct
585588
*/
586589
int hv_get_ipi_pte(HV_Coord tile, int pl, HV_PTE* pte);
587590

591+
/** Configure the console interrupt.
592+
*
593+
* When the console client interrupt is enabled, the hypervisor will
594+
* deliver the specified IPI to the client in the following situations:
595+
*
596+
* - The console has at least one character available for input.
597+
*
598+
* - The console can accept new characters for output, and the last call
599+
* to hv_console_write() did not write all of the characters requested
600+
* by the client.
601+
*
602+
* Note that in some system configurations, console interrupt will not
603+
* be available; clients should be prepared for this routine to fail and
604+
* to fall back to periodic console polling in that case.
605+
*
606+
* @param ipi Index of the IPI register which will receive the interrupt.
607+
* @param event IPI event number for console interrupt. If less than 0,
608+
* disable the console IPI interrupt.
609+
* @param coord Tile to be targeted for console interrupt.
610+
* @return 0 on success, otherwise, HV_EINVAL if illegal parameter,
611+
* HV_ENOTSUP if console interrupt are not available.
612+
*/
613+
int hv_console_set_ipi(int ipi, int event, HV_Coord coord);
614+
588615
#else /* !CHIP_HAS_IPI() */
589616

590617
/** A set of interrupts. */

‎arch/tile/kernel/early_printk.c‎

Lines changed: 11 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -23,71 +23,46 @@
2323

2424
static void early_hv_write(struct console *con, const char *s, unsigned n)
2525
{
26-
hv_console_write((HV_VirtAddr) s, n);
26+
tile_console_write(s, n);
27+
28+
/*
29+
* Convert NL to NLCR (close enough to CRNL) during early boot.
30+
* We assume newlines are at the ends of strings, which turns out
31+
* to be good enough for early boot console output.
32+
*/
33+
if (n && s[n-1] == '\n')
34+
tile_console_write("\r", 1);
2735
}
2836

2937
static struct console early_hv_console = {
3038
.name = "earlyhv",
3139
.write = early_hv_write,
32-
.flags = CON_PRINTBUFFER,
40+
.flags = CON_PRINTBUFFER | CON_BOOT,
3341
.index = -1,
3442
};
3543

36-
/* Direct interface for emergencies */
37-
static int early_console_complete;
38-
3944
void early_panic(const char *fmt, ...)
4045
{
4146
va_list ap;
4247
arch_local_irq_disable_all();
4348
va_start(ap, fmt);
4449
early_printk("Kernel panic - not syncing: ");
4550
early_vprintk(fmt, ap);
46-
early_console->write(early_console, "\n", 1);
51+
early_printk("\n");
4752
va_end(ap);
4853
dump_stack();
4954
hv_halt();
5055
}
5156

52-
static int __initdata keep_early;
53-
5457
static int __init setup_early_printk(char *str)
5558
{
5659
if (early_console)
5760
return 1;
5861

59-
if (str != NULL && strncmp(str, "keep", 4) == 0)
60-
keep_early = 1;
61-
6262
early_console = &early_hv_console;
6363
register_console(early_console);
6464

6565
return 0;
6666
}
6767

68-
void __init disable_early_printk(void)
69-
{
70-
early_console_complete = 1;
71-
if (!early_console)
72-
return;
73-
if (!keep_early) {
74-
early_printk("disabling early console\n");
75-
unregister_console(early_console);
76-
early_console = NULL;
77-
} else {
78-
early_printk("keeping early console\n");
79-
}
80-
}
81-
82-
void warn_early_printk(void)
83-
{
84-
if (early_console_complete || early_console)
85-
return;
86-
early_printk("\
87-
Machine shutting down before console output is fully initialized.\n\
88-
You may wish to reboot and add the option 'earlyprintk' to your\n\
89-
boot command line to see any diagnostic early console output.\n\
90-
");
91-
}
92-
9368
early_param("earlyprintk", setup_early_printk);

‎arch/tile/kernel/hvglue.lds‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,5 @@ hv_inquire_realpa = TEXT_OFFSET + 0x106c0;
5656
hv_flush_all = TEXT_OFFSET + 0x106e0;
5757
hv_get_ipi_pte = TEXT_OFFSET + 0x10700;
5858
hv_set_pte_super_shift = TEXT_OFFSET + 0x10720;
59-
hv_glue_internals = TEXT_OFFSET + 0x10740;
59+
hv_console_set_ipi = TEXT_OFFSET + 0x107e0;
60+
hv_glue_internals = TEXT_OFFSET + 0x10800;

‎arch/tile/kernel/reboot.c‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,13 @@
2727

2828
void machine_halt(void)
2929
{
30-
warn_early_printk();
3130
arch_local_irq_disable_all();
3231
smp_send_stop();
3332
hv_halt();
3433
}
3534

3635
void machine_power_off(void)
3736
{
38-
warn_early_printk();
3937
arch_local_irq_disable_all();
4038
smp_send_stop();
4139
hv_power_off();

‎drivers/tty/hvc/hvc_tile.c‎

Lines changed: 143 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,46 @@
1818
#include <linux/delay.h>
1919
#include <linux/err.h>
2020
#include <linux/init.h>
21+
#include <linux/interrupt.h>
22+
#include <linux/irq.h>
2123
#include <linux/moduleparam.h>
24+
#include <linux/platform_device.h>
2225
#include <linux/types.h>
2326

27+
#include <asm/setup.h>
28+
#include <arch/sim_def.h>
29+
2430
#include <hv/hypervisor.h>
2531

2632
#include "hvc_console.h"
2733

34+
static int use_sim_console;
35+
static int __init sim_console(char *str)
36+
{
37+
use_sim_console = 1;
38+
return 0;
39+
}
40+
early_param("sim_console", sim_console);
41+
42+
int tile_console_write(const char *buf, int count)
43+
{
44+
if (unlikely(use_sim_console)) {
45+
int i;
46+
for (i = 0; i < count; ++i)
47+
__insn_mtspr(SPR_SIM_CONTROL, SIM_CONTROL_PUTC |
48+
(buf[i] << _SIM_CONTROL_OPERATOR_BITS));
49+
__insn_mtspr(SPR_SIM_CONTROL, SIM_CONTROL_PUTC |
50+
(SIM_PUTC_FLUSH_BINARY <<
51+
_SIM_CONTROL_OPERATOR_BITS));
52+
return 0;
53+
} else {
54+
return hv_console_write((HV_VirtAddr)buf, count);
55+
}
56+
}
57+
2858
static int hvc_tile_put_chars(uint32_t vt, const char *buf, int count)
2959
{
30-
return hv_console_write((HV_VirtAddr)buf, count);
60+
return tile_console_write(buf, count);
3161
}
3262

3363
static int hvc_tile_get_chars(uint32_t vt, char *buf, int count)
@@ -44,25 +74,132 @@ static int hvc_tile_get_chars(uint32_t vt, char *buf, int count)
4474
return i;
4575
}
4676

77+
#ifdef __tilegx__
78+
/*
79+
* IRQ based callbacks.
80+
*/
81+
static int hvc_tile_notifier_add_irq(struct hvc_struct *hp, int irq)
82+
{
83+
int rc;
84+
int cpu = raw_smp_processor_id(); /* Choose an arbitrary cpu */
85+
HV_Coord coord = { .x = cpu_x(cpu), .y = cpu_y(cpu) };
86+
87+
rc = notifier_add_irq(hp, irq);
88+
if (rc)
89+
return rc;
90+
91+
/*
92+
* Request that the hypervisor start sending us interrupts.
93+
* If the hypervisor returns an error, we still return 0, so that
94+
* we can fall back to polling.
95+
*/
96+
if (hv_console_set_ipi(KERNEL_PL, irq, coord) < 0)
97+
notifier_del_irq(hp, irq);
98+
99+
return 0;
100+
}
101+
102+
static void hvc_tile_notifier_del_irq(struct hvc_struct *hp, int irq)
103+
{
104+
HV_Coord coord = { 0, 0 };
105+
106+
/* Tell the hypervisor to stop sending us interrupts. */
107+
hv_console_set_ipi(KERNEL_PL, -1, coord);
108+
109+
notifier_del_irq(hp, irq);
110+
}
111+
112+
static void hvc_tile_notifier_hangup_irq(struct hvc_struct *hp, int irq)
113+
{
114+
hvc_tile_notifier_del_irq(hp, irq);
115+
}
116+
#endif
117+
47118
static const struct hv_ops hvc_tile_get_put_ops = {
48119
.get_chars = hvc_tile_get_chars,
49120
.put_chars = hvc_tile_put_chars,
121+
#ifdef __tilegx__
122+
.notifier_add = hvc_tile_notifier_add_irq,
123+
.notifier_del = hvc_tile_notifier_del_irq,
124+
.notifier_hangup = hvc_tile_notifier_hangup_irq,
125+
#endif
126+
};
127+
128+
129+
#ifdef __tilegx__
130+
static int hvc_tile_probe(struct platform_device *pdev)
131+
{
132+
struct hvc_struct *hp;
133+
int tile_hvc_irq;
134+
135+
/* Create our IRQ and register it. */
136+
tile_hvc_irq = create_irq();
137+
if (tile_hvc_irq < 0)
138+
return -ENXIO;
139+
140+
tile_irq_activate(tile_hvc_irq, TILE_IRQ_PERCPU);
141+
hp = hvc_alloc(0, tile_hvc_irq, &hvc_tile_get_put_ops, 128);
142+
if (IS_ERR(hp)) {
143+
destroy_irq(tile_hvc_irq);
144+
return PTR_ERR(hp);
145+
}
146+
dev_set_drvdata(&pdev->dev, hp);
147+
148+
return 0;
149+
}
150+
151+
static int hvc_tile_remove(struct platform_device *pdev)
152+
{
153+
int rc;
154+
struct hvc_struct *hp = dev_get_drvdata(&pdev->dev);
155+
156+
rc = hvc_remove(hp);
157+
if (rc == 0)
158+
destroy_irq(hp->data);
159+
160+
return rc;
161+
}
162+
163+
static void hvc_tile_shutdown(struct platform_device *pdev)
164+
{
165+
struct hvc_struct *hp = dev_get_drvdata(&pdev->dev);
166+
167+
hvc_tile_notifier_del_irq(hp, hp->data);
168+
}
169+
170+
static struct platform_device hvc_tile_pdev = {
171+
.name = "hvc-tile",
172+
.id = 0,
173+
};
174+
175+
static struct platform_driver hvc_tile_driver = {
176+
.probe = hvc_tile_probe,
177+
.remove = hvc_tile_remove,
178+
.shutdown = hvc_tile_shutdown,
179+
.driver = {
180+
.name = "hvc-tile",
181+
.owner = THIS_MODULE,
182+
}
50183
};
184+
#endif
51185

52186
static int __init hvc_tile_console_init(void)
53187
{
54-
extern void disable_early_printk(void);
55188
hvc_instantiate(0, 0, &hvc_tile_get_put_ops);
56189
add_preferred_console("hvc", 0, NULL);
57-
disable_early_printk();
58190
return 0;
59191
}
60192
console_initcall(hvc_tile_console_init);
61193

62194
static int __init hvc_tile_init(void)
63195
{
64-
struct hvc_struct *s;
65-
s = hvc_alloc(0, 0, &hvc_tile_get_put_ops, 128);
66-
return IS_ERR(s) ? PTR_ERR(s) : 0;
196+
#ifndef __tilegx__
197+
struct hvc_struct *hp;
198+
hp = hvc_alloc(0, 0, &hvc_tile_get_put_ops, 128);
199+
return IS_ERR(hp) ? PTR_ERR(hp) : 0;
200+
#else
201+
platform_device_register(&hvc_tile_pdev);
202+
return platform_driver_register(&hvc_tile_driver);
203+
#endif
67204
}
68205
device_initcall(hvc_tile_init);

0 commit comments

Comments
 (0)