setup.c 6.4 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
/*
 *  PS3 platform setup routines.
 *
 *  Copyright (C) 2006 Sony Computer Entertainment Inc.
 *  Copyright 2006 Sony Corp.
 *
 *  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 of the License.
 *
 *  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.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

#include <linux/kernel.h>
#include <linux/delay.h>
#include <linux/fs.h>
#include <linux/root_dev.h>
#include <linux/console.h>
26
#include <linux/export.h>
27
#include <linux/bootmem.h>
28 29 30 31 32 33 34 35

#include <asm/machdep.h>
#include <asm/firmware.h>
#include <asm/time.h>
#include <asm/iommu.h>
#include <asm/udbg.h>
#include <asm/prom.h>
#include <asm/lv1call.h>
36
#include <asm/ps3gpu.h>
37 38 39 40

#include "platform.h"

#if defined(DEBUG)
41
#define DBG udbg_printf
42
#else
43
#define DBG pr_debug
44 45
#endif

46 47 48 49
/* mutex synchronizing GPU accesses and video mode changes */
DEFINE_MUTEX(ps3_gpu_mutex);
EXPORT_SYMBOL_GPL(ps3_gpu_mutex);

50 51 52
static union ps3_firmware_version ps3_firmware_version;

void ps3_get_firmware_version(union ps3_firmware_version *v)
53
{
54 55 56
	*v = ps3_firmware_version;
}
EXPORT_SYMBOL_GPL(ps3_get_firmware_version);
57

58 59 60 61 62 63 64 65
int ps3_compare_firmware_version(u16 major, u16 minor, u16 rev)
{
	union ps3_firmware_version x;

	x.pad = 0;
	x.major = major;
	x.minor = minor;
	x.rev = rev;
66

67 68
	return (ps3_firmware_version.raw > x.raw) -
	       (ps3_firmware_version.raw < x.raw);
69
}
70
EXPORT_SYMBOL_GPL(ps3_compare_firmware_version);
71

72 73 74 75 76 77 78 79 80 81 82
static void ps3_power_save(void)
{
	/*
	 * lv1_pause() puts the PPE thread into inactive state until an
	 * irq on an unmasked plug exists. MSR[EE] has no effect.
	 * flags: 0 = wake on DEC interrupt, 1 = ignore DEC interrupt.
	 */

	lv1_pause(0);
}

83
static void __noreturn ps3_restart(char *cmd)
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
{
	DBG("%s:%d cmd '%s'\n", __func__, __LINE__, cmd);

	smp_send_stop();
	ps3_sys_manager_restart(); /* never returns */
}

static void ps3_power_off(void)
{
	DBG("%s:%d\n", __func__, __LINE__);

	smp_send_stop();
	ps3_sys_manager_power_off(); /* never returns */
}

99
static void __noreturn ps3_halt(void)
100 101 102 103 104 105 106
{
	DBG("%s:%d\n", __func__, __LINE__);

	smp_send_stop();
	ps3_sys_manager_halt(); /* never returns */
}

107 108 109 110 111 112 113 114 115 116 117 118 119 120
static void ps3_panic(char *str)
{
	DBG("%s:%d %s\n", __func__, __LINE__, str);

	smp_send_stop();
	printk("\n");
	printk("   System does not reboot automatically.\n");
	printk("   Please press POWER button.\n");
	printk("\n");

	while(1)
		lv1_pause(1);
}

121 122
#if defined(CONFIG_FB_PS3) || defined(CONFIG_FB_PS3_MODULE) || \
    defined(CONFIG_PS3_FLASH) || defined(CONFIG_PS3_FLASH_MODULE)
123
static void __init prealloc(struct ps3_prealloc *p)
124 125 126 127
{
	if (!p->size)
		return;

128
	p->address = memblock_virt_alloc(p->size, p->align);
129 130 131 132

	printk(KERN_INFO "%s: %lu bytes at %p\n", p->name, p->size,
	       p->address);
}
133
#endif
134

135
#if defined(CONFIG_FB_PS3) || defined(CONFIG_FB_PS3_MODULE)
136
struct ps3_prealloc ps3fb_videomemory = {
137 138 139
	.name = "ps3fb videomemory",
	.size = CONFIG_FB_PS3_DEFAULT_SIZE_M*1024*1024,
	.align = 1024*1024		/* the GPU requires 1 MiB alignment */
140
};
141
EXPORT_SYMBOL_GPL(ps3fb_videomemory);
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157
#define prealloc_ps3fb_videomemory()	prealloc(&ps3fb_videomemory)

static int __init early_parse_ps3fb(char *p)
{
	if (!p)
		return 1;

	ps3fb_videomemory.size = _ALIGN_UP(memparse(p, &p),
					   ps3fb_videomemory.align);
	return 0;
}
early_param("ps3fb", early_parse_ps3fb);
#else
#define prealloc_ps3fb_videomemory()	do { } while (0)
#endif

158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181
#if defined(CONFIG_PS3_FLASH) || defined(CONFIG_PS3_FLASH_MODULE)
struct ps3_prealloc ps3flash_bounce_buffer = {
	.name = "ps3flash bounce buffer",
	.size = 256*1024,
	.align = 256*1024
};
EXPORT_SYMBOL_GPL(ps3flash_bounce_buffer);
#define prealloc_ps3flash_bounce_buffer()	prealloc(&ps3flash_bounce_buffer)

static int __init early_parse_ps3flash(char *p)
{
	if (!p)
		return 1;

	if (!strcmp(p, "off"))
		ps3flash_bounce_buffer.size = 0;

	return 0;
}
early_param("ps3flash", early_parse_ps3flash);
#else
#define prealloc_ps3flash_bounce_buffer()	do { } while (0)
#endif

182
static int ps3_set_dabr(unsigned long dabr, unsigned long dabrx)
G
Geoff Levand 已提交
183
{
184 185 186 187 188
	/* Have to set at least one bit in the DABRX */
	if (dabrx == 0 && dabr == 0)
		dabrx = DABRX_USER;
	/* hypervisor only allows us to set BTI, Kernel and user */
	dabrx &= DABRX_BTI | DABRX_KERNEL | DABRX_USER;
G
Geoff Levand 已提交
189

190
	return lv1_set_dabr(dabr, dabrx) ? -1 : 0;
G
Geoff Levand 已提交
191
}
192

193 194
static void __init ps3_setup_arch(void)
{
195
	u64 tmp;
196

197 198
	DBG(" -> %s:%d\n", __func__, __LINE__);

199 200
	lv1_get_version_info(&ps3_firmware_version.raw, &tmp);

201 202 203
	printk(KERN_INFO "PS3 firmware version %u.%u.%u\n",
	       ps3_firmware_version.major, ps3_firmware_version.minor,
	       ps3_firmware_version.rev);
204

205 206 207 208 209 210 211 212 213 214
	ps3_spu_set_platform();

#ifdef CONFIG_SMP
	smp_init_ps3();
#endif

#ifdef CONFIG_DUMMY_CONSOLE
	conswitchp = &dummy_con;
#endif

215
	prealloc_ps3fb_videomemory();
216 217
	prealloc_ps3flash_bounce_buffer();

218
	ppc_md.power_save = ps3_power_save;
219
	ps3_os_area_init();
220 221 222 223 224 225 226 227 228

	DBG(" <- %s:%d\n", __func__, __LINE__);
}

static void __init ps3_progress(char *s, unsigned short hex)
{
	printk("*** %04x : %s\n", hex, s ? s : "");
}

229
void __init ps3_early_mm_init(void)
230 231
{
	unsigned long htab_size;
232 233 234 235 236 237 238 239

	ps3_mm_init();
	ps3_mm_vas_create(&htab_size);
	ps3_hpte_init(htab_size);
}

static int __init ps3_probe(void)
{
240 241
	DBG(" -> %s:%d\n", __func__, __LINE__);

242
	if (!of_machine_is_compatible("sony,ps3"))
243 244
		return 0;

245
	ps3_os_area_save_params();
246

247
	pm_power_off = ps3_power_off;
248 249 250 251 252

	DBG(" <- %s:%d\n", __func__, __LINE__);
	return 1;
}

253
#if defined(CONFIG_KEXEC_CORE)
254 255
static void ps3_kexec_cpu_down(int crash_shutdown, int secondary)
{
G
Geoff Levand 已提交
256
	int cpu = smp_processor_id();
257

G
Geoff Levand 已提交
258
	DBG(" -> %s:%d: (%d)\n", __func__, __LINE__, cpu);
259

G
Geoff Levand 已提交
260 261
	ps3_smp_cleanup_cpu(cpu);
	ps3_shutdown_IRQ(cpu);
262 263 264 265 266 267 268 269 270 271

	DBG(" <- %s:%d\n", __func__, __LINE__);
}
#endif

define_machine(ps3) {
	.name				= "PS3",
	.probe				= ps3_probe,
	.setup_arch			= ps3_setup_arch,
	.init_IRQ			= ps3_init_IRQ,
272
	.panic				= ps3_panic,
273
	.get_boot_time			= ps3_get_boot_time,
G
Geoff Levand 已提交
274
	.set_dabr			= ps3_set_dabr,
275 276
	.calibrate_decr			= ps3_calibrate_decr,
	.progress			= ps3_progress,
277
	.restart			= ps3_restart,
278
	.halt				= ps3_halt,
279
#if defined(CONFIG_KEXEC_CORE)
280 281 282
	.kexec_cpu_down			= ps3_kexec_cpu_down,
#endif
};