es7000_32.c 8.0 KB
Newer Older
L
Linus Torvalds 已提交
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 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
/*
 * Written by: Garry Forsgren, Unisys Corporation
 *             Natalie Protasevich, Unisys Corporation
 * This file contains the code to configure and interface
 * with Unisys ES7000 series hardware system manager.
 *
 * Copyright (c) 2003 Unisys Corporation.  All Rights Reserved.
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of version 2 of the GNU General Public License as
 * published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it would be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write the Free Software Foundation, Inc., 59
 * Temple Place - Suite 330, Boston MA 02111-1307, USA.
 *
 * Contact information: Unisys Corporation, Township Line & Union Meeting
 * Roads-A, Unisys Way, Blue Bell, Pennsylvania, 19424, or:
 *
 * http://www.unisys.com
 */

#include <linux/module.h>
#include <linux/types.h>
#include <linux/kernel.h>
#include <linux/smp.h>
#include <linux/string.h>
#include <linux/spinlock.h>
#include <linux/errno.h>
#include <linux/notifier.h>
#include <linux/reboot.h>
#include <linux/init.h>
#include <linux/acpi.h>
#include <asm/io.h>
#include <asm/nmi.h>
#include <asm/smp.h>
41
#include <asm/atomic.h>
L
Linus Torvalds 已提交
42
#include <asm/apicdef.h>
V
Vivek Goyal 已提交
43
#include <mach_mpparse.h>
44
#include <asm/genapic.h>
45
#include <asm/setup.h>
L
Linus Torvalds 已提交
46

Y
Yinghai Lu 已提交
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 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 113 114
/*
 * ES7000 chipsets
 */

#define NON_UNISYS		0
#define ES7000_CLASSIC		1
#define ES7000_ZORRO		2


#define	MIP_REG			1
#define	MIP_PSAI_REG		4

#define	MIP_BUSY		1
#define	MIP_SPIN		0xf0000
#define	MIP_VALID		0x0100000000000000ULL
#define	MIP_PORT(VALUE)	((VALUE >> 32) & 0xffff)

#define	MIP_RD_LO(VALUE)	(VALUE & 0xffffffff)

struct mip_reg_info {
	unsigned long long mip_info;
	unsigned long long delivery_info;
	unsigned long long host_reg;
	unsigned long long mip_reg;
};

struct part_info {
	unsigned char type;
	unsigned char length;
	unsigned char part_id;
	unsigned char apic_mode;
	unsigned long snum;
	char ptype[16];
	char sname[64];
	char pname[64];
};

struct psai {
	unsigned long long entry_type;
	unsigned long long addr;
	unsigned long long bep_addr;
};

struct es7000_mem_info {
	unsigned char type;
	unsigned char length;
	unsigned char resv[6];
	unsigned long long  start;
	unsigned long long  size;
};

struct es7000_oem_table {
	unsigned long long hdr;
	struct mip_reg_info mip;
	struct part_info pif;
	struct es7000_mem_info shm;
	struct psai psai;
};

#ifdef CONFIG_ACPI

struct oem_table {
	struct acpi_table_header Header;
	u32 OEMTableAddr;
	u32 OEMTableSize;
};

extern int find_unisys_acpi_oem_table(unsigned long *oem_addr);
115
extern void unmap_unisys_acpi_oem_table(unsigned long oem_addr);
Y
Yinghai Lu 已提交
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
#endif

struct mip_reg {
	unsigned long long off_0;
	unsigned long long off_8;
	unsigned long long off_10;
	unsigned long long off_18;
	unsigned long long off_20;
	unsigned long long off_28;
	unsigned long long off_30;
	unsigned long long off_38;
};

#define	MIP_SW_APIC		0x1020b
#define	MIP_FUNC(VALUE)		(VALUE & 0xff)

L
Linus Torvalds 已提交
132 133 134 135
/*
 * ES7000 Globals
 */

A
Adrian Bunk 已提交
136 137 138 139 140
static volatile unsigned long	*psai = NULL;
static struct mip_reg		*mip_reg;
static struct mip_reg		*host_reg;
static int 			mip_port;
static unsigned long		mip_addr, host_addr;
L
Linus Torvalds 已提交
141

142 143
int es7000_plat;

L
Linus Torvalds 已提交
144 145 146 147 148 149 150 151 152
/*
 * GSI override for ES7000 platforms.
 */

static unsigned int base;

static int
es7000_rename_gsi(int ioapic, int gsi)
{
153 154 155
	if (es7000_plat == ES7000_ZORRO)
		return gsi;

L
Linus Torvalds 已提交
156 157 158 159 160 161
	if (!base) {
		int i;
		for (i = 0; i < nr_ioapics; i++)
			base += nr_ioapic_registers[i];
	}

Y
Yinghai Lu 已提交
162
	if (!ioapic && (gsi < 16))
L
Linus Torvalds 已提交
163 164 165 166
		gsi += base;
	return gsi;
}

167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183
static int wakeup_secondary_cpu_via_mip(int cpu, unsigned long eip)
{
	unsigned long vect = 0, psaival = 0;

	if (psai == NULL)
		return -1;

	vect = ((unsigned long)__pa(eip)/0x1000) << 16;
	psaival = (0x1000000 | vect | cpu);

	while (*psai & 0x1000000)
		;

	*psai = psaival;

	return 0;
}
184

185 186 187 188
static void noop_wait_for_deassert(atomic_t *deassert_not_used)
{
}

189 190
static int __init es7000_update_genapic(void)
{
I
Ingo Molnar 已提交
191
	apic->wakeup_cpu = wakeup_secondary_cpu_via_mip;
192

193 194 195 196
	/* MPENTIUMIII */
	if (boot_cpu_data.x86 == 6 &&
	    (boot_cpu_data.x86_model >= 7 || boot_cpu_data.x86_model <= 11)) {
		es7000_update_genapic_to_cluster();
I
Ingo Molnar 已提交
197 198
		apic->wait_for_init_deassert = noop_wait_for_deassert;
		apic->wakeup_cpu = wakeup_secondary_cpu_via_mip;
199 200
	}

201 202
	return 0;
}
203

204
void __init
205
setup_unisys(void)
206 207 208 209 210 211 212 213 214
{
	/*
	 * Determine the generation of the ES7000 currently running.
	 *
	 * es7000_plat = 1 if the machine is a 5xx ES7000 box
	 * es7000_plat = 2 if the machine is a x86_64 ES7000 box
	 *
	 */
	if (!(boot_cpu_data.x86 <= 15 && boot_cpu_data.x86_model <= 2))
215
		es7000_plat = ES7000_ZORRO;
216
	else
217
		es7000_plat = ES7000_CLASSIC;
218
	ioapic_renumber_irq = es7000_rename_gsi;
219 220

	x86_quirks->update_genapic = es7000_update_genapic;
221 222
}

L
Linus Torvalds 已提交
223 224 225 226 227
/*
 * Parse the OEM Table
 */

int __init
228
parse_unisys_oem (char *oemptr)
L
Linus Torvalds 已提交
229 230 231 232 233 234 235 236 237 238 239 240 241 242
{
	int                     i;
	int 			success = 0;
	unsigned char           type, size;
	unsigned long           val;
	char                    *tp = NULL;
	struct psai             *psaip = NULL;
	struct mip_reg_info 	*mi;
	struct mip_reg		*host, *mip;

	tp = oemptr;

	tp += 8;

243
	for (i=0; i <= 6; i++) {
L
Linus Torvalds 已提交
244 245 246 247 248 249 250 251 252 253 254 255 256 257 258
		type = *tp++;
		size = *tp++;
		tp -= 2;
		switch (type) {
		case MIP_REG:
			mi = (struct mip_reg_info *)tp;
			val = MIP_RD_LO(mi->host_reg);
			host_addr = val;
			host = (struct mip_reg *)val;
			host_reg = __va(host);
			val = MIP_RD_LO(mi->mip_reg);
			mip_port = MIP_PORT(mi->mip_info);
			mip_addr = val;
			mip = (struct mip_reg *)val;
			mip_reg = __va(mip);
259 260 261 262
			pr_debug("es7000_mipcfg: host_reg = 0x%lx \n",
				 (unsigned long)host_reg);
			pr_debug("es7000_mipcfg: mip_reg = 0x%lx \n",
				 (unsigned long)mip_reg);
L
Linus Torvalds 已提交
263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281
			success++;
			break;
		case MIP_PSAI_REG:
			psaip = (struct psai *)tp;
			if (tp != NULL) {
				if (psaip->addr)
					psai = __va(psaip->addr);
				else
					psai = NULL;
				success++;
			}
			break;
		default:
			break;
		}
		tp += size;
	}

	if (success < 2) {
282
		es7000_plat = NON_UNISYS;
283 284
	} else
		setup_unisys();
L
Linus Torvalds 已提交
285 286 287
	return es7000_plat;
}

288
#ifdef CONFIG_ACPI
289 290 291
static unsigned long oem_addrX;
static unsigned long oem_size;
int __init find_unisys_acpi_oem_table(unsigned long *oem_addr)
L
Linus Torvalds 已提交
292
{
293 294
	struct acpi_table_header *header = NULL;
	int i = 0;
295

Y
Yinghai Lu 已提交
296
	while (ACPI_SUCCESS(acpi_get_table("OEM1", i++, &header))) {
297 298
		if (!memcmp((char *) &header->oem_id, "UNISYS", 6)) {
			struct oem_table *t = (struct oem_table *)header;
299 300 301 302 303 304

			oem_addrX = t->OEMTableAddr;
			oem_size = t->OEMTableSize;

			*oem_addr = (unsigned long)__acpi_map_table(oem_addrX,
								    oem_size);
305
			return 0;
L
Linus Torvalds 已提交
306 307 308 309
		}
	}
	return -1;
}
310 311 312 313

void __init unmap_unisys_acpi_oem_table(unsigned long oem_addr)
{
}
314
#endif
L
Linus Torvalds 已提交
315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361

static void
es7000_spin(int n)
{
	int i = 0;

	while (i++ < n)
		rep_nop();
}

static int __init
es7000_mip_write(struct mip_reg *mip_reg)
{
	int			status = 0;
	int			spin;

	spin = MIP_SPIN;
	while (((unsigned long long)host_reg->off_38 &
		(unsigned long long)MIP_VALID) != 0) {
			if (--spin <= 0) {
				printk("es7000_mip_write: Timeout waiting for Host Valid Flag");
				return -1;
			}
		es7000_spin(MIP_SPIN);
	}

	memcpy(host_reg, mip_reg, sizeof(struct mip_reg));
	outb(1, mip_port);

	spin = MIP_SPIN;

	while (((unsigned long long)mip_reg->off_38 &
		(unsigned long long)MIP_VALID) == 0) {
		if (--spin <= 0) {
			printk("es7000_mip_write: Timeout waiting for MIP Valid Flag");
			return -1;
		}
		es7000_spin(MIP_SPIN);
	}

	status = ((unsigned long long)mip_reg->off_0 &
		(unsigned long long)0xffff0000000000ULL) >> 48;
	mip_reg->off_38 = ((unsigned long long)mip_reg->off_38 &
		(unsigned long long)~MIP_VALID);
	return status;
}

362
void __init es7000_enable_apic_mode(void)
L
Linus Torvalds 已提交
363
{
364 365 366 367
	struct mip_reg es7000_mip_reg;
	int mip_status;

	if (!es7000_plat)
L
Linus Torvalds 已提交
368
		return;
369 370 371 372 373 374 375 376 377

	printk("ES7000: Enabling APIC mode.\n");
       	memset(&es7000_mip_reg, 0, sizeof(struct mip_reg));
       	es7000_mip_reg.off_0 = MIP_SW_APIC;
       	es7000_mip_reg.off_38 = MIP_VALID;

       	while ((mip_status = es7000_mip_write(&es7000_mip_reg)) != 0) {
		printk("es7000_enable_apic_mode: command failed, status = %x\n",
			mip_status);
L
Linus Torvalds 已提交
378 379
	}
}