Blame view

drivers/tty/hvc/hvc_tile.c 4.68 KB
867e359b9   Chris Metcalf   arch/tile: core s...
1
  /*
ef06f55a5   Chris Metcalf   arch/tile: catch ...
2
   * Copyright 2010 Tilera Corporation. All Rights Reserved.
867e359b9   Chris Metcalf   arch/tile: core s...
3
   *
ef06f55a5   Chris Metcalf   arch/tile: catch ...
4
5
6
   *   This program is free software; you can redistribute it and/or
   *   modify it under the terms of the GNU General Public License
   *   as published by the Free Software Foundation, version 2.
867e359b9   Chris Metcalf   arch/tile: core s...
7
   *
ef06f55a5   Chris Metcalf   arch/tile: catch ...
8
9
10
11
12
   *   This program is distributed in the hope that it will be useful, but
   *   WITHOUT ANY WARRANTY; without even the implied warranty of
   *   MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
   *   NON INFRINGEMENT.  See the GNU General Public License for
   *   more details.
867e359b9   Chris Metcalf   arch/tile: core s...
13
14
15
16
17
18
19
20
   *
   * Tilera TILE Processor hypervisor console
   */
  
  #include <linux/console.h>
  #include <linux/delay.h>
  #include <linux/err.h>
  #include <linux/init.h>
bda0f5bad   Chris Metcalf   tile: various con...
21
22
  #include <linux/interrupt.h>
  #include <linux/irq.h>
867e359b9   Chris Metcalf   arch/tile: core s...
23
  #include <linux/moduleparam.h>
bda0f5bad   Chris Metcalf   tile: various con...
24
  #include <linux/platform_device.h>
867e359b9   Chris Metcalf   arch/tile: core s...
25
  #include <linux/types.h>
bda0f5bad   Chris Metcalf   tile: various con...
26
27
  #include <asm/setup.h>
  #include <arch/sim_def.h>
867e359b9   Chris Metcalf   arch/tile: core s...
28
29
30
  #include <hv/hypervisor.h>
  
  #include "hvc_console.h"
bda0f5bad   Chris Metcalf   tile: various con...
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
  static int use_sim_console;
  static int __init sim_console(char *str)
  {
  	use_sim_console = 1;
  	return 0;
  }
  early_param("sim_console", sim_console);
  
  int tile_console_write(const char *buf, int count)
  {
  	if (unlikely(use_sim_console)) {
  		int i;
  		for (i = 0; i < count; ++i)
  			__insn_mtspr(SPR_SIM_CONTROL, SIM_CONTROL_PUTC |
  				     (buf[i] << _SIM_CONTROL_OPERATOR_BITS));
  		__insn_mtspr(SPR_SIM_CONTROL, SIM_CONTROL_PUTC |
  			     (SIM_PUTC_FLUSH_BINARY <<
  			      _SIM_CONTROL_OPERATOR_BITS));
  		return 0;
  	} else {
b4287df82   Chris Metcalf   drivers/tty/hvc/h...
51
52
  		/* Translate 0 bytes written to EAGAIN for hvc_console_print. */
  		return hv_console_write((HV_VirtAddr)buf, count) ?: -EAGAIN;
bda0f5bad   Chris Metcalf   tile: various con...
53
54
  	}
  }
867e359b9   Chris Metcalf   arch/tile: core s...
55
56
  static int hvc_tile_put_chars(uint32_t vt, const char *buf, int count)
  {
bda0f5bad   Chris Metcalf   tile: various con...
57
  	return tile_console_write(buf, count);
867e359b9   Chris Metcalf   arch/tile: core s...
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
  }
  
  static int hvc_tile_get_chars(uint32_t vt, char *buf, int count)
  {
  	int i, c;
  
  	for (i = 0; i < count; ++i) {
  		c = hv_console_read_if_ready();
  		if (c < 0)
  			break;
  		buf[i] = c;
  	}
  
  	return i;
  }
bda0f5bad   Chris Metcalf   tile: various con...
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
  #ifdef __tilegx__
  /*
   * IRQ based callbacks.
   */
  static int hvc_tile_notifier_add_irq(struct hvc_struct *hp, int irq)
  {
  	int rc;
  	int cpu = raw_smp_processor_id();  /* Choose an arbitrary cpu */
  	HV_Coord coord = { .x = cpu_x(cpu), .y = cpu_y(cpu) };
  
  	rc = notifier_add_irq(hp, irq);
  	if (rc)
  		return rc;
  
  	/*
  	 * Request that the hypervisor start sending us interrupts.
  	 * If the hypervisor returns an error, we still return 0, so that
  	 * we can fall back to polling.
  	 */
  	if (hv_console_set_ipi(KERNEL_PL, irq, coord) < 0)
  		notifier_del_irq(hp, irq);
  
  	return 0;
  }
  
  static void hvc_tile_notifier_del_irq(struct hvc_struct *hp, int irq)
  {
  	HV_Coord coord = { 0, 0 };
  
  	/* Tell the hypervisor to stop sending us interrupts. */
  	hv_console_set_ipi(KERNEL_PL, -1, coord);
  
  	notifier_del_irq(hp, irq);
  }
  
  static void hvc_tile_notifier_hangup_irq(struct hvc_struct *hp, int irq)
  {
  	hvc_tile_notifier_del_irq(hp, irq);
  }
  #endif
867e359b9   Chris Metcalf   arch/tile: core s...
113
114
115
  static const struct hv_ops hvc_tile_get_put_ops = {
  	.get_chars = hvc_tile_get_chars,
  	.put_chars = hvc_tile_put_chars,
bda0f5bad   Chris Metcalf   tile: various con...
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
  #ifdef __tilegx__
  	.notifier_add = hvc_tile_notifier_add_irq,
  	.notifier_del = hvc_tile_notifier_del_irq,
  	.notifier_hangup = hvc_tile_notifier_hangup_irq,
  #endif
  };
  
  
  #ifdef __tilegx__
  static int hvc_tile_probe(struct platform_device *pdev)
  {
  	struct hvc_struct *hp;
  	int tile_hvc_irq;
  
  	/* Create our IRQ and register it. */
3dfd442e5   Thomas Gleixner   tile: hvc: Use ir...
131
132
  	tile_hvc_irq = irq_alloc_hwirq(-1);
  	if (!tile_hvc_irq)
bda0f5bad   Chris Metcalf   tile: various con...
133
134
135
136
137
  		return -ENXIO;
  
  	tile_irq_activate(tile_hvc_irq, TILE_IRQ_PERCPU);
  	hp = hvc_alloc(0, tile_hvc_irq, &hvc_tile_get_put_ops, 128);
  	if (IS_ERR(hp)) {
3dfd442e5   Thomas Gleixner   tile: hvc: Use ir...
138
  		irq_free_hwirq(tile_hvc_irq);
bda0f5bad   Chris Metcalf   tile: various con...
139
140
141
142
143
144
145
146
147
148
149
150
151
152
  		return PTR_ERR(hp);
  	}
  	dev_set_drvdata(&pdev->dev, hp);
  
  	return 0;
  }
  
  static int hvc_tile_remove(struct platform_device *pdev)
  {
  	int rc;
  	struct hvc_struct *hp = dev_get_drvdata(&pdev->dev);
  
  	rc = hvc_remove(hp);
  	if (rc == 0)
3dfd442e5   Thomas Gleixner   tile: hvc: Use ir...
153
  		irq_free_hwirq(hp->data);
bda0f5bad   Chris Metcalf   tile: various con...
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
  
  	return rc;
  }
  
  static void hvc_tile_shutdown(struct platform_device *pdev)
  {
  	struct hvc_struct *hp = dev_get_drvdata(&pdev->dev);
  
  	hvc_tile_notifier_del_irq(hp, hp->data);
  }
  
  static struct platform_device hvc_tile_pdev = {
  	.name           = "hvc-tile",
  	.id             = 0,
  };
  
  static struct platform_driver hvc_tile_driver = {
  	.probe          = hvc_tile_probe,
  	.remove         = hvc_tile_remove,
  	.shutdown	= hvc_tile_shutdown,
  	.driver         = {
  		.name   = "hvc-tile",
bda0f5bad   Chris Metcalf   tile: various con...
176
  	}
867e359b9   Chris Metcalf   arch/tile: core s...
177
  };
bda0f5bad   Chris Metcalf   tile: various con...
178
  #endif
867e359b9   Chris Metcalf   arch/tile: core s...
179
180
181
  
  static int __init hvc_tile_console_init(void)
  {
867e359b9   Chris Metcalf   arch/tile: core s...
182
183
  	hvc_instantiate(0, 0, &hvc_tile_get_put_ops);
  	add_preferred_console("hvc", 0, NULL);
867e359b9   Chris Metcalf   arch/tile: core s...
184
185
186
187
188
189
  	return 0;
  }
  console_initcall(hvc_tile_console_init);
  
  static int __init hvc_tile_init(void)
  {
bda0f5bad   Chris Metcalf   tile: various con...
190
191
192
  #ifndef __tilegx__
  	struct hvc_struct *hp;
  	hp = hvc_alloc(0, 0, &hvc_tile_get_put_ops, 128);
60f917b8d   Fabian Frederick   drivers/tty/hvc/h...
193
  	return PTR_ERR_OR_ZERO(hp);
bda0f5bad   Chris Metcalf   tile: various con...
194
195
196
197
  #else
  	platform_device_register(&hvc_tile_pdev);
  	return platform_driver_register(&hvc_tile_driver);
  #endif
867e359b9   Chris Metcalf   arch/tile: core s...
198
199
  }
  device_initcall(hvc_tile_init);