firmware.c 45.5 KB
Newer Older
L
Linus Torvalds 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13
/*
 * arch/parisc/kernel/firmware.c  - safe PDC access routines
 *
 *	PDC == Processor Dependent Code
 *
 * See http://www.parisc-linux.org/documentation/index.html
 * for documentation describing the entry points and calling
 * conventions defined below.
 *
 * Copyright 1999 SuSE GmbH Nuernberg (Philipp Rumpf, prumpf@tux.org)
 * Copyright 1999 The Puffin Group, (Alex deVries, David Kennedy)
 * Copyright 2003 Grant Grundler <grundler parisc-linux org>
 * Copyright 2003,2004 Ryan Bradetich <rbrad@parisc-linux.org>
14
 * Copyright 2004,2006 Thibaut VARENE <varenet@parisc-linux.org>
L
Linus Torvalds 已提交
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 41 42 43 44 45 46 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
 *
 *    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; either version 2 of the License, or
 *    (at your option) any later version.
 *
 */

/*	I think it would be in everyone's best interest to follow this
 *	guidelines when writing PDC wrappers:
 *
 *	 - the name of the pdc wrapper should match one of the macros
 *	   used for the first two arguments
 *	 - don't use caps for random parts of the name
 *	 - use the static PDC result buffers and "copyout" to structs
 *	   supplied by the caller to encapsulate alignment restrictions
 *	 - hold pdc_lock while in PDC or using static result buffers
 *	 - use __pa() to convert virtual (kernel) pointers to physical
 *	   ones.
 *	 - the name of the struct used for pdc return values should equal
 *	   one of the macros used for the first two arguments to the
 *	   corresponding PDC call
 *	 - keep the order of arguments
 *	 - don't be smart (setting trailing NUL bytes for strings, return
 *	   something useful even if the call failed) unless you are sure
 *	   it's not going to affect functionality or performance
 *
 *	Example:
 *	int pdc_cache_info(struct pdc_cache_info *cache_info )
 *	{
 *		int retval;
 *
 *		spin_lock_irq(&pdc_lock);
 *		retval = mem_pdc_call(PDC_CACHE,PDC_CACHE_INFO,__pa(cache_info),0);
 *		convert_to_wide(pdc_result);
 *		memcpy(cache_info, pdc_result, sizeof(*cache_info));
 *		spin_unlock_irq(&pdc_lock);
 *
 *		return retval;
 *	}
 *					prumpf	991016	
 */

#include <stdarg.h>

#include <linux/delay.h>
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/string.h>
#include <linux/spinlock.h>

#include <asm/page.h>
#include <asm/pdc.h>
#include <asm/pdcpat.h>
#include <asm/processor.h>	/* for boot_cpu_data */

static DEFINE_SPINLOCK(pdc_lock);
K
Kyle McMartin 已提交
73 74
extern unsigned long pdc_result[NUM_PDC_RESULT];
extern unsigned long pdc_result2[NUM_PDC_RESULT];
L
Linus Torvalds 已提交
75

76
#ifdef CONFIG_64BIT
L
Linus Torvalds 已提交
77 78 79 80 81
#define WIDE_FIRMWARE 0x1
#define NARROW_FIRMWARE 0x2

/* Firmware needs to be initially set to narrow to determine the 
 * actual firmware width. */
82
int parisc_narrow_firmware __read_mostly = 1;
L
Linus Torvalds 已提交
83 84
#endif

85 86 87
/* On most currently-supported platforms, IODC I/O calls are 32-bit calls
 * and MEM_PDC calls are always the same width as the OS.
 * Some PAT boxes may have 64-bit IODC I/O.
L
Linus Torvalds 已提交
88
 *
89 90 91 92 93
 * Ryan Bradetich added the now obsolete CONFIG_PDC_NARROW to allow
 * 64-bit kernels to run on systems with 32-bit MEM_PDC calls.
 * This allowed wide kernels to run on Cxxx boxes.
 * We now detect 32-bit-only PDC and dynamically switch to 32-bit mode
 * when running a 64-bit kernel on such boxes (e.g. C200 or C360).
L
Linus Torvalds 已提交
94 95
 */

96
#ifdef CONFIG_64BIT
L
Linus Torvalds 已提交
97 98 99 100
long real64_call(unsigned long function, ...);
#endif
long real32_call(unsigned long function, ...);

101
#ifdef CONFIG_64BIT
L
Linus Torvalds 已提交
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
#   define MEM_PDC (unsigned long)(PAGE0->mem_pdc_hi) << 32 | PAGE0->mem_pdc
#   define mem_pdc_call(args...) unlikely(parisc_narrow_firmware) ? real32_call(MEM_PDC, args) : real64_call(MEM_PDC, args)
#else
#   define MEM_PDC (unsigned long)PAGE0->mem_pdc
#   define mem_pdc_call(args...) real32_call(MEM_PDC, args)
#endif


/**
 * f_extend - Convert PDC addresses to kernel addresses.
 * @address: Address returned from PDC.
 *
 * This function is used to convert PDC addresses into kernel addresses
 * when the PDC address size and kernel address size are different.
 */
static unsigned long f_extend(unsigned long address)
{
119
#ifdef CONFIG_64BIT
L
Linus Torvalds 已提交
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
	if(unlikely(parisc_narrow_firmware)) {
		if((address & 0xff000000) == 0xf0000000)
			return 0xf0f0f0f000000000UL | (u32)address;

		if((address & 0xf0000000) == 0xf0000000)
			return 0xffffffff00000000UL | (u32)address;
	}
#endif
	return address;
}

/**
 * convert_to_wide - Convert the return buffer addresses into kernel addresses.
 * @address: The return buffer from PDC.
 *
 * This function is used to convert the return buffer addresses retrieved from PDC
 * into kernel addresses when the PDC address size and kernel address size are
 * different.
 */
static void convert_to_wide(unsigned long *addr)
{
141
#ifdef CONFIG_64BIT
L
Linus Torvalds 已提交
142 143 144 145 146 147 148 149 150 151
	int i;
	unsigned int *p = (unsigned int *)addr;

	if(unlikely(parisc_narrow_firmware)) {
		for(i = 31; i >= 0; --i)
			addr[i] = p[i];
	}
#endif
}

152
#ifdef CONFIG_64BIT
153
void set_firmware_width_unlocked(void)
154 155 156 157 158 159 160 161 162 163
{
	int ret;

	ret = mem_pdc_call(PDC_MODEL, PDC_MODEL_CAPABILITIES,
		__pa(pdc_result), 0);
	convert_to_wide(pdc_result);
	if (pdc_result[0] != NARROW_FIRMWARE)
		parisc_narrow_firmware = 0;
}
	
L
Linus Torvalds 已提交
164 165 166
/**
 * set_firmware_width - Determine if the firmware is wide or narrow.
 * 
167 168
 * This function must be called before any pdc_* function that uses the
 * convert_to_wide function.
L
Linus Torvalds 已提交
169
 */
170
void set_firmware_width(void)
L
Linus Torvalds 已提交
171
{
172
	unsigned long flags;
173 174 175 176 177
	spin_lock_irqsave(&pdc_lock, flags);
	set_firmware_width_unlocked();
	spin_unlock_irqrestore(&pdc_lock, flags);
}
#else
178 179
void set_firmware_width_unlocked(void)
{
180 181
	return;
}
L
Linus Torvalds 已提交
182

183 184
void set_firmware_width(void)
{
185
	return;
L
Linus Torvalds 已提交
186
}
187
#endif /*CONFIG_64BIT*/
L
Linus Torvalds 已提交
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214

/**
 * pdc_emergency_unlock - Unlock the linux pdc lock
 *
 * This call unlocks the linux pdc lock in case we need some PDC functions
 * (like pdc_add_valid) during kernel stack dump.
 */
void pdc_emergency_unlock(void)
{
 	/* Spinlock DEBUG code freaks out if we unconditionally unlock */
        if (spin_is_locked(&pdc_lock))
		spin_unlock(&pdc_lock);
}


/**
 * pdc_add_valid - Verify address can be accessed without causing a HPMC.
 * @address: Address to be verified.
 *
 * This PDC call attempts to read from the specified address and verifies
 * if the address is valid.
 * 
 * The return value is PDC_OK (0) in case accessing this address is valid.
 */
int pdc_add_valid(unsigned long address)
{
        int retval;
215
	unsigned long flags;
L
Linus Torvalds 已提交
216

217
        spin_lock_irqsave(&pdc_lock, flags);
L
Linus Torvalds 已提交
218
        retval = mem_pdc_call(PDC_ADD_VALID, PDC_ADD_VALID_VERIFY, address);
219
        spin_unlock_irqrestore(&pdc_lock, flags);
L
Linus Torvalds 已提交
220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235

        return retval;
}
EXPORT_SYMBOL(pdc_add_valid);

/**
 * pdc_chassis_info - Return chassis information.
 * @result: The return buffer.
 * @chassis_info: The memory buffer address.
 * @len: The size of the memory buffer address.
 *
 * An HVERSION dependent call for returning the chassis information.
 */
int __init pdc_chassis_info(struct pdc_chassis_info *chassis_info, void *led_info, unsigned long len)
{
        int retval;
236
	unsigned long flags;
L
Linus Torvalds 已提交
237

238
        spin_lock_irqsave(&pdc_lock, flags);
L
Linus Torvalds 已提交
239 240 241 242 243 244
        memcpy(&pdc_result, chassis_info, sizeof(*chassis_info));
        memcpy(&pdc_result2, led_info, len);
        retval = mem_pdc_call(PDC_CHASSIS, PDC_RETURN_CHASSIS_INFO,
                              __pa(pdc_result), __pa(pdc_result2), len);
        memcpy(chassis_info, pdc_result, sizeof(*chassis_info));
        memcpy(led_info, pdc_result2, len);
245
        spin_unlock_irqrestore(&pdc_lock, flags);
L
Linus Torvalds 已提交
246 247 248 249 250 251 252 253 254 255

        return retval;
}

/**
 * pdc_pat_chassis_send_log - Sends a PDC PAT CHASSIS log message.
 * @retval: -1 on error, 0 on success. Other value are PDC errors
 * 
 * Must be correctly formatted or expect system crash
 */
256
#ifdef CONFIG_64BIT
L
Linus Torvalds 已提交
257 258 259
int pdc_pat_chassis_send_log(unsigned long state, unsigned long data)
{
	int retval = 0;
260
	unsigned long flags;
L
Linus Torvalds 已提交
261 262 263 264
        
	if (!is_pdc_pat())
		return -1;

265
	spin_lock_irqsave(&pdc_lock, flags);
L
Linus Torvalds 已提交
266
	retval = mem_pdc_call(PDC_PAT_CHASSIS_LOG, PDC_PAT_CHASSIS_WRITE_LOG, __pa(&state), __pa(&data));
267
	spin_unlock_irqrestore(&pdc_lock, flags);
L
Linus Torvalds 已提交
268 269 270 271 272 273

	return retval;
}
#endif

/**
274
 * pdc_chassis_disp - Updates chassis code
L
Linus Torvalds 已提交
275 276 277 278 279
 * @retval: -1 on error, 0 on success
 */
int pdc_chassis_disp(unsigned long disp)
{
	int retval = 0;
280
	unsigned long flags;
L
Linus Torvalds 已提交
281

282
	spin_lock_irqsave(&pdc_lock, flags);
L
Linus Torvalds 已提交
283
	retval = mem_pdc_call(PDC_CHASSIS, PDC_CHASSIS_DISP, disp);
284
	spin_unlock_irqrestore(&pdc_lock, flags);
L
Linus Torvalds 已提交
285 286 287 288

	return retval;
}

289 290 291 292 293 294 295
/**
 * pdc_chassis_warn - Fetches chassis warnings
 * @retval: -1 on error, 0 on success
 */
int pdc_chassis_warn(unsigned long *warn)
{
	int retval = 0;
296
	unsigned long flags;
297

298
	spin_lock_irqsave(&pdc_lock, flags);
299 300
	retval = mem_pdc_call(PDC_CHASSIS, PDC_CHASSIS_WARN, __pa(pdc_result));
	*warn = pdc_result[0];
301
	spin_unlock_irqrestore(&pdc_lock, flags);
302 303 304 305

	return retval;
}

306
int pdc_coproc_cfg_unlocked(struct pdc_coproc_cfg *pdc_coproc_info)
307 308 309 310 311 312 313 314 315 316 317 318 319
{
	int ret;

	ret = mem_pdc_call(PDC_COPROC, PDC_COPROC_CFG, __pa(pdc_result));
	convert_to_wide(pdc_result);
	pdc_coproc_info->ccr_functional = pdc_result[0];
	pdc_coproc_info->ccr_present = pdc_result[1];
	pdc_coproc_info->revision = pdc_result[17];
	pdc_coproc_info->model = pdc_result[18];

	return ret;
}

L
Linus Torvalds 已提交
320 321 322 323 324 325 326
/**
 * pdc_coproc_cfg - To identify coprocessors attached to the processor.
 * @pdc_coproc_info: Return buffer address.
 *
 * This PDC call returns the presence and status of all the coprocessors
 * attached to the processor.
 */
327
int pdc_coproc_cfg(struct pdc_coproc_cfg *pdc_coproc_info)
L
Linus Torvalds 已提交
328
{
329
	int ret;
330
	unsigned long flags;
L
Linus Torvalds 已提交
331

332 333 334
	spin_lock_irqsave(&pdc_lock, flags);
	ret = pdc_coproc_cfg_unlocked(pdc_coproc_info);
	spin_unlock_irqrestore(&pdc_lock, flags);
L
Linus Torvalds 已提交
335

336
	return ret;
L
Linus Torvalds 已提交
337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353
}

/**
 * pdc_iodc_read - Read data from the modules IODC.
 * @actcnt: The actual number of bytes.
 * @hpa: The HPA of the module for the iodc read.
 * @index: The iodc entry point.
 * @iodc_data: A buffer memory for the iodc options.
 * @iodc_data_size: Size of the memory buffer.
 *
 * This PDC call reads from the IODC of the module specified by the hpa
 * argument.
 */
int pdc_iodc_read(unsigned long *actcnt, unsigned long hpa, unsigned int index,
		  void *iodc_data, unsigned int iodc_data_size)
{
	int retval;
354
	unsigned long flags;
L
Linus Torvalds 已提交
355

356
	spin_lock_irqsave(&pdc_lock, flags);
L
Linus Torvalds 已提交
357 358 359 360 361
	retval = mem_pdc_call(PDC_IODC, PDC_IODC_READ, __pa(pdc_result), hpa, 
			      index, __pa(pdc_result2), iodc_data_size);
	convert_to_wide(pdc_result);
	*actcnt = pdc_result[0];
	memcpy(iodc_data, pdc_result2, iodc_data_size);
362
	spin_unlock_irqrestore(&pdc_lock, flags);
L
Linus Torvalds 已提交
363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380

	return retval;
}
EXPORT_SYMBOL(pdc_iodc_read);

/**
 * pdc_system_map_find_mods - Locate unarchitected modules.
 * @pdc_mod_info: Return buffer address.
 * @mod_path: pointer to dev path structure.
 * @mod_index: fixed address module index.
 *
 * To locate and identify modules which reside at fixed I/O addresses, which
 * do not self-identify via architected bus walks.
 */
int pdc_system_map_find_mods(struct pdc_system_map_mod_info *pdc_mod_info,
			     struct pdc_module_path *mod_path, long mod_index)
{
	int retval;
381
	unsigned long flags;
L
Linus Torvalds 已提交
382

383
	spin_lock_irqsave(&pdc_lock, flags);
L
Linus Torvalds 已提交
384 385 386 387 388
	retval = mem_pdc_call(PDC_SYSTEM_MAP, PDC_FIND_MODULE, __pa(pdc_result), 
			      __pa(pdc_result2), mod_index);
	convert_to_wide(pdc_result);
	memcpy(pdc_mod_info, pdc_result, sizeof(*pdc_mod_info));
	memcpy(mod_path, pdc_result2, sizeof(*mod_path));
389
	spin_unlock_irqrestore(&pdc_lock, flags);
L
Linus Torvalds 已提交
390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407

	pdc_mod_info->mod_addr = f_extend(pdc_mod_info->mod_addr);
	return retval;
}

/**
 * pdc_system_map_find_addrs - Retrieve additional address ranges.
 * @pdc_addr_info: Return buffer address.
 * @mod_index: Fixed address module index.
 * @addr_index: Address range index.
 * 
 * Retrieve additional information about subsequent address ranges for modules
 * with multiple address ranges.  
 */
int pdc_system_map_find_addrs(struct pdc_system_map_addr_info *pdc_addr_info, 
			      long mod_index, long addr_index)
{
	int retval;
408
	unsigned long flags;
L
Linus Torvalds 已提交
409

410
	spin_lock_irqsave(&pdc_lock, flags);
L
Linus Torvalds 已提交
411 412 413 414
	retval = mem_pdc_call(PDC_SYSTEM_MAP, PDC_FIND_ADDRESS, __pa(pdc_result),
			      mod_index, addr_index);
	convert_to_wide(pdc_result);
	memcpy(pdc_addr_info, pdc_result, sizeof(*pdc_addr_info));
415
	spin_unlock_irqrestore(&pdc_lock, flags);
L
Linus Torvalds 已提交
416 417 418 419 420 421 422 423 424 425 426 427 428 429

	pdc_addr_info->mod_addr = f_extend(pdc_addr_info->mod_addr);
	return retval;
}

/**
 * pdc_model_info - Return model information about the processor.
 * @model: The return buffer.
 *
 * Returns the version numbers, identifiers, and capabilities from the processor module.
 */
int pdc_model_info(struct pdc_model *model) 
{
	int retval;
430
	unsigned long flags;
L
Linus Torvalds 已提交
431

432
	spin_lock_irqsave(&pdc_lock, flags);
L
Linus Torvalds 已提交
433 434 435
	retval = mem_pdc_call(PDC_MODEL, PDC_MODEL_INFO, __pa(pdc_result), 0);
	convert_to_wide(pdc_result);
	memcpy(model, pdc_result, sizeof(*model));
436
	spin_unlock_irqrestore(&pdc_lock, flags);
L
Linus Torvalds 已提交
437 438 439 440 441 442 443 444

	return retval;
}

/**
 * pdc_model_sysmodel - Get the system model name.
 * @name: A char array of at least 81 characters.
 *
K
Kyle McMartin 已提交
445 446 447
 * Get system model name from PDC ROM (e.g. 9000/715 or 9000/778/B160L).
 * Using OS_ID_HPUX will return the equivalent of the 'modelname' command
 * on HP/UX.
L
Linus Torvalds 已提交
448 449 450 451
 */
int pdc_model_sysmodel(char *name)
{
        int retval;
452
	unsigned long flags;
L
Linus Torvalds 已提交
453

454
        spin_lock_irqsave(&pdc_lock, flags);
L
Linus Torvalds 已提交
455 456 457 458 459 460 461 462 463
        retval = mem_pdc_call(PDC_MODEL, PDC_MODEL_SYSMODEL, __pa(pdc_result),
                              OS_ID_HPUX, __pa(name));
        convert_to_wide(pdc_result);

        if (retval == PDC_OK) {
                name[pdc_result[0]] = '\0'; /* add trailing '\0' */
        } else {
                name[0] = 0;
        }
464
        spin_unlock_irqrestore(&pdc_lock, flags);
L
Linus Torvalds 已提交
465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481

        return retval;
}

/**
 * pdc_model_versions - Identify the version number of each processor.
 * @cpu_id: The return buffer.
 * @id: The id of the processor to check.
 *
 * Returns the version number for each processor component.
 *
 * This comment was here before, but I do not know what it means :( -RB
 * id: 0 = cpu revision, 1 = boot-rom-version
 */
int pdc_model_versions(unsigned long *versions, int id)
{
        int retval;
482
	unsigned long flags;
L
Linus Torvalds 已提交
483

484
        spin_lock_irqsave(&pdc_lock, flags);
L
Linus Torvalds 已提交
485 486 487
        retval = mem_pdc_call(PDC_MODEL, PDC_MODEL_VERSIONS, __pa(pdc_result), id);
        convert_to_wide(pdc_result);
        *versions = pdc_result[0];
488
        spin_unlock_irqrestore(&pdc_lock, flags);
L
Linus Torvalds 已提交
489 490 491 492 493 494 495 496 497 498 499 500 501 502

        return retval;
}

/**
 * pdc_model_cpuid - Returns the CPU_ID.
 * @cpu_id: The return buffer.
 *
 * Returns the CPU_ID value which uniquely identifies the cpu portion of
 * the processor module.
 */
int pdc_model_cpuid(unsigned long *cpu_id)
{
        int retval;
503
	unsigned long flags;
L
Linus Torvalds 已提交
504

505
        spin_lock_irqsave(&pdc_lock, flags);
L
Linus Torvalds 已提交
506 507 508 509
        pdc_result[0] = 0; /* preset zero (call may not be implemented!) */
        retval = mem_pdc_call(PDC_MODEL, PDC_MODEL_CPU_ID, __pa(pdc_result), 0);
        convert_to_wide(pdc_result);
        *cpu_id = pdc_result[0];
510
        spin_unlock_irqrestore(&pdc_lock, flags);
L
Linus Torvalds 已提交
511 512 513 514 515 516 517 518 519 520 521 522 523 524

        return retval;
}

/**
 * pdc_model_capabilities - Returns the platform capabilities.
 * @capabilities: The return buffer.
 *
 * Returns information about platform support for 32- and/or 64-bit
 * OSes, IO-PDIR coherency, and virtual aliasing.
 */
int pdc_model_capabilities(unsigned long *capabilities)
{
        int retval;
525
	unsigned long flags;
L
Linus Torvalds 已提交
526

527
        spin_lock_irqsave(&pdc_lock, flags);
L
Linus Torvalds 已提交
528 529 530
        pdc_result[0] = 0; /* preset zero (call may not be implemented!) */
        retval = mem_pdc_call(PDC_MODEL, PDC_MODEL_CAPABILITIES, __pa(pdc_result), 0);
        convert_to_wide(pdc_result);
531 532 533 534 535
        if (retval == PDC_OK) {
                *capabilities = pdc_result[0];
        } else {
                *capabilities = PDC_MODEL_OS32;
        }
536
        spin_unlock_irqrestore(&pdc_lock, flags);
L
Linus Torvalds 已提交
537 538 539 540 541 542 543 544 545 546 547 548 549

        return retval;
}

/**
 * pdc_cache_info - Return cache and TLB information.
 * @cache_info: The return buffer.
 *
 * Returns information about the processor's cache and TLB.
 */
int pdc_cache_info(struct pdc_cache_info *cache_info)
{
        int retval;
550
	unsigned long flags;
L
Linus Torvalds 已提交
551

552
        spin_lock_irqsave(&pdc_lock, flags);
L
Linus Torvalds 已提交
553 554 555
        retval = mem_pdc_call(PDC_CACHE, PDC_CACHE_INFO, __pa(pdc_result), 0);
        convert_to_wide(pdc_result);
        memcpy(cache_info, pdc_result, sizeof(*cache_info));
556
        spin_unlock_irqrestore(&pdc_lock, flags);
L
Linus Torvalds 已提交
557 558 559 560

        return retval;
}

561 562 563 564 565 566 567 568 569
/**
 * pdc_spaceid_bits - Return whether Space ID hashing is turned on.
 * @space_bits: Should be 0, if not, bad mojo!
 *
 * Returns information about Space ID hashing.
 */
int pdc_spaceid_bits(unsigned long *space_bits)
{
	int retval;
570
	unsigned long flags;
571

572
	spin_lock_irqsave(&pdc_lock, flags);
573 574 575 576
	pdc_result[0] = 0;
	retval = mem_pdc_call(PDC_CACHE, PDC_CACHE_RET_SPID, __pa(pdc_result), 0);
	convert_to_wide(pdc_result);
	*space_bits = pdc_result[0];
577
	spin_unlock_irqrestore(&pdc_lock, flags);
578 579 580 581

	return retval;
}

L
Linus Torvalds 已提交
582 583 584 585 586 587 588 589 590 591
#ifndef CONFIG_PA20
/**
 * pdc_btlb_info - Return block TLB information.
 * @btlb: The return buffer.
 *
 * Returns information about the hardware Block TLB.
 */
int pdc_btlb_info(struct pdc_btlb_info *btlb) 
{
        int retval;
592
	unsigned long flags;
L
Linus Torvalds 已提交
593

594
        spin_lock_irqsave(&pdc_lock, flags);
L
Linus Torvalds 已提交
595 596
        retval = mem_pdc_call(PDC_BLOCK_TLB, PDC_BTLB_INFO, __pa(pdc_result), 0);
        memcpy(btlb, pdc_result, sizeof(*btlb));
597
        spin_unlock_irqrestore(&pdc_lock, flags);
L
Linus Torvalds 已提交
598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620

        if(retval < 0) {
                btlb->max_size = 0;
        }
        return retval;
}

/**
 * pdc_mem_map_hpa - Find fixed module information.  
 * @address: The return buffer
 * @mod_path: pointer to dev path structure.
 *
 * This call was developed for S700 workstations to allow the kernel to find
 * the I/O devices (Core I/O). In the future (Kittyhawk and beyond) this
 * call will be replaced (on workstations) by the architected PDC_SYSTEM_MAP
 * call.
 *
 * This call is supported by all existing S700 workstations (up to  Gecko).
 */
int pdc_mem_map_hpa(struct pdc_memory_map *address,
		struct pdc_module_path *mod_path)
{
        int retval;
621
	unsigned long flags;
L
Linus Torvalds 已提交
622

623
        spin_lock_irqsave(&pdc_lock, flags);
L
Linus Torvalds 已提交
624 625 626 627
        memcpy(pdc_result2, mod_path, sizeof(*mod_path));
        retval = mem_pdc_call(PDC_MEM_MAP, PDC_MEM_MAP_HPA, __pa(pdc_result),
				__pa(pdc_result2));
        memcpy(address, pdc_result, sizeof(*address));
628
        spin_unlock_irqrestore(&pdc_lock, flags);
L
Linus Torvalds 已提交
629 630 631 632 633 634 635 636 637 638 639 640 641 642 643

        return retval;
}
#endif	/* !CONFIG_PA20 */

/**
 * pdc_lan_station_id - Get the LAN address.
 * @lan_addr: The return buffer.
 * @hpa: The network device HPA.
 *
 * Get the LAN station address when it is not directly available from the LAN hardware.
 */
int pdc_lan_station_id(char *lan_addr, unsigned long hpa)
{
	int retval;
644
	unsigned long flags;
L
Linus Torvalds 已提交
645

646
	spin_lock_irqsave(&pdc_lock, flags);
L
Linus Torvalds 已提交
647 648 649 650 651 652 653 654
	retval = mem_pdc_call(PDC_LAN_STATION_ID, PDC_LAN_STATION_ID_READ,
			__pa(pdc_result), hpa);
	if (retval < 0) {
		/* FIXME: else read MAC from NVRAM */
		memset(lan_addr, 0, PDC_LAN_STATION_ID_SIZE);
	} else {
		memcpy(lan_addr, pdc_result, PDC_LAN_STATION_ID_SIZE);
	}
655
	spin_unlock_irqrestore(&pdc_lock, flags);
L
Linus Torvalds 已提交
656 657 658 659 660 661 662 663 664

	return retval;
}
EXPORT_SYMBOL(pdc_lan_station_id);

/**
 * pdc_stable_read - Read data from Stable Storage.
 * @staddr: Stable Storage address to access.
 * @memaddr: The memory address where Stable Storage data shall be copied.
665
 * @count: number of bytes to transfer. count is multiple of 4.
L
Linus Torvalds 已提交
666 667 668 669 670 671 672 673
 *
 * This PDC call reads from the Stable Storage address supplied in staddr
 * and copies count bytes to the memory address memaddr.
 * The call will fail if staddr+count > PDC_STABLE size.
 */
int pdc_stable_read(unsigned long staddr, void *memaddr, unsigned long count)
{
       int retval;
674
	unsigned long flags;
L
Linus Torvalds 已提交
675

676
       spin_lock_irqsave(&pdc_lock, flags);
L
Linus Torvalds 已提交
677 678 679 680
       retval = mem_pdc_call(PDC_STABLE, PDC_STABLE_READ, staddr,
               __pa(pdc_result), count);
       convert_to_wide(pdc_result);
       memcpy(memaddr, pdc_result, count);
681
       spin_unlock_irqrestore(&pdc_lock, flags);
L
Linus Torvalds 已提交
682 683 684 685 686 687 688 689 690

       return retval;
}
EXPORT_SYMBOL(pdc_stable_read);

/**
 * pdc_stable_write - Write data to Stable Storage.
 * @staddr: Stable Storage address to access.
 * @memaddr: The memory address where Stable Storage data shall be read from.
691
 * @count: number of bytes to transfer. count is multiple of 4.
L
Linus Torvalds 已提交
692 693 694 695 696 697 698 699
 *
 * This PDC call reads count bytes from the supplied memaddr address,
 * and copies count bytes to the Stable Storage address staddr.
 * The call will fail if staddr+count > PDC_STABLE size.
 */
int pdc_stable_write(unsigned long staddr, void *memaddr, unsigned long count)
{
       int retval;
700
	unsigned long flags;
L
Linus Torvalds 已提交
701

702
       spin_lock_irqsave(&pdc_lock, flags);
L
Linus Torvalds 已提交
703 704 705 706
       memcpy(pdc_result, memaddr, count);
       convert_to_wide(pdc_result);
       retval = mem_pdc_call(PDC_STABLE, PDC_STABLE_WRITE, staddr,
               __pa(pdc_result), count);
707
       spin_unlock_irqrestore(&pdc_lock, flags);
L
Linus Torvalds 已提交
708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724

       return retval;
}
EXPORT_SYMBOL(pdc_stable_write);

/**
 * pdc_stable_get_size - Get Stable Storage size in bytes.
 * @size: pointer where the size will be stored.
 *
 * This PDC call returns the number of bytes in the processor's Stable
 * Storage, which is the number of contiguous bytes implemented in Stable
 * Storage starting from staddr=0. size in an unsigned 64-bit integer
 * which is a multiple of four.
 */
int pdc_stable_get_size(unsigned long *size)
{
       int retval;
725
	unsigned long flags;
L
Linus Torvalds 已提交
726

727
       spin_lock_irqsave(&pdc_lock, flags);
L
Linus Torvalds 已提交
728 729
       retval = mem_pdc_call(PDC_STABLE, PDC_STABLE_RETURN_SIZE, __pa(pdc_result));
       *size = pdc_result[0];
730
       spin_unlock_irqrestore(&pdc_lock, flags);
L
Linus Torvalds 已提交
731 732 733 734 735 736 737 738 739 740 741 742 743 744

       return retval;
}
EXPORT_SYMBOL(pdc_stable_get_size);

/**
 * pdc_stable_verify_contents - Checks that Stable Storage contents are valid.
 *
 * This PDC call is meant to be used to check the integrity of the current
 * contents of Stable Storage.
 */
int pdc_stable_verify_contents(void)
{
       int retval;
745
	unsigned long flags;
L
Linus Torvalds 已提交
746

747
       spin_lock_irqsave(&pdc_lock, flags);
L
Linus Torvalds 已提交
748
       retval = mem_pdc_call(PDC_STABLE, PDC_STABLE_VERIFY_CONTENTS);
749
       spin_unlock_irqrestore(&pdc_lock, flags);
L
Linus Torvalds 已提交
750 751 752 753 754 755 756 757 758 759 760 761 762 763

       return retval;
}
EXPORT_SYMBOL(pdc_stable_verify_contents);

/**
 * pdc_stable_initialize - Sets Stable Storage contents to zero and initialize
 * the validity indicator.
 *
 * This PDC call will erase all contents of Stable Storage. Use with care!
 */
int pdc_stable_initialize(void)
{
       int retval;
764
	unsigned long flags;
L
Linus Torvalds 已提交
765

766
       spin_lock_irqsave(&pdc_lock, flags);
L
Linus Torvalds 已提交
767
       retval = mem_pdc_call(PDC_STABLE, PDC_STABLE_INITIALIZE);
768
       spin_unlock_irqrestore(&pdc_lock, flags);
L
Linus Torvalds 已提交
769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790

       return retval;
}
EXPORT_SYMBOL(pdc_stable_initialize);

/**
 * pdc_get_initiator - Get the SCSI Interface Card params (SCSI ID, SDTR, SE or LVD)
 * @hwpath: fully bc.mod style path to the device.
 * @initiator: the array to return the result into
 *
 * Get the SCSI operational parameters from PDC.
 * Needed since HPUX never used BIOS or symbios card NVRAM.
 * Most ncr/sym cards won't have an entry and just use whatever
 * capabilities of the card are (eg Ultra, LVD). But there are
 * several cases where it's useful:
 *    o set SCSI id for Multi-initiator clusters,
 *    o cable too long (ie SE scsi 10Mhz won't support 6m length),
 *    o bus width exported is less than what the interface chip supports.
 */
int pdc_get_initiator(struct hardware_path *hwpath, struct pdc_initiator *initiator)
{
	int retval;
791
	unsigned long flags;
L
Linus Torvalds 已提交
792

793
	spin_lock_irqsave(&pdc_lock, flags);
L
Linus Torvalds 已提交
794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832

/* BCJ-XXXX series boxes. E.G. "9000/785/C3000" */
#define IS_SPROCKETS() (strlen(boot_cpu_data.pdc.sys_model_name) == 14 && \
	strncmp(boot_cpu_data.pdc.sys_model_name, "9000/785", 8) == 0)

	retval = mem_pdc_call(PDC_INITIATOR, PDC_GET_INITIATOR, 
			      __pa(pdc_result), __pa(hwpath));
	if (retval < PDC_OK)
		goto out;

	if (pdc_result[0] < 16) {
		initiator->host_id = pdc_result[0];
	} else {
		initiator->host_id = -1;
	}

	/*
	 * Sprockets and Piranha return 20 or 40 (MT/s).  Prelude returns
	 * 1, 2, 5 or 10 for 5, 10, 20 or 40 MT/s, respectively
	 */
	switch (pdc_result[1]) {
		case  1: initiator->factor = 50; break;
		case  2: initiator->factor = 25; break;
		case  5: initiator->factor = 12; break;
		case 25: initiator->factor = 10; break;
		case 20: initiator->factor = 12; break;
		case 40: initiator->factor = 10; break;
		default: initiator->factor = -1; break;
	}

	if (IS_SPROCKETS()) {
		initiator->width = pdc_result[4];
		initiator->mode = pdc_result[5];
	} else {
		initiator->width = -1;
		initiator->mode = -1;
	}

 out:
833 834
	spin_unlock_irqrestore(&pdc_lock, flags);

L
Linus Torvalds 已提交
835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851
	return (retval >= PDC_OK);
}
EXPORT_SYMBOL(pdc_get_initiator);


/**
 * pdc_pci_irt_size - Get the number of entries in the interrupt routing table.
 * @num_entries: The return value.
 * @hpa: The HPA for the device.
 *
 * This PDC function returns the number of entries in the specified cell's
 * interrupt table.
 * Similar to PDC_PAT stuff - but added for Forte/Allegro boxes
 */ 
int pdc_pci_irt_size(unsigned long *num_entries, unsigned long hpa)
{
	int retval;
852
	unsigned long flags;
L
Linus Torvalds 已提交
853

854
	spin_lock_irqsave(&pdc_lock, flags);
L
Linus Torvalds 已提交
855 856 857 858
	retval = mem_pdc_call(PDC_PCI_INDEX, PDC_PCI_GET_INT_TBL_SIZE, 
			      __pa(pdc_result), hpa);
	convert_to_wide(pdc_result);
	*num_entries = pdc_result[0];
859
	spin_unlock_irqrestore(&pdc_lock, flags);
L
Linus Torvalds 已提交
860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875

	return retval;
}

/** 
 * pdc_pci_irt - Get the PCI interrupt routing table.
 * @num_entries: The number of entries in the table.
 * @hpa: The Hard Physical Address of the device.
 * @tbl: 
 *
 * Get the PCI interrupt routing table for the device at the given HPA.
 * Similar to PDC_PAT stuff - but added for Forte/Allegro boxes
 */
int pdc_pci_irt(unsigned long num_entries, unsigned long hpa, void *tbl)
{
	int retval;
876
	unsigned long flags;
L
Linus Torvalds 已提交
877 878 879

	BUG_ON((unsigned long)tbl & 0x7);

880
	spin_lock_irqsave(&pdc_lock, flags);
L
Linus Torvalds 已提交
881 882 883
	pdc_result[0] = num_entries;
	retval = mem_pdc_call(PDC_PCI_INDEX, PDC_PCI_GET_INT_TBL, 
			      __pa(pdc_result), hpa, __pa(tbl));
884
	spin_unlock_irqrestore(&pdc_lock, flags);
L
Linus Torvalds 已提交
885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901

	return retval;
}


#if 0	/* UNTEST CODE - left here in case someone needs it */

/** 
 * pdc_pci_config_read - read PCI config space.
 * @hpa		token from PDC to indicate which PCI device
 * @pci_addr	configuration space address to read from
 *
 * Read PCI Configuration space *before* linux PCI subsystem is running.
 */
unsigned int pdc_pci_config_read(void *hpa, unsigned long cfg_addr)
{
	int retval;
902 903 904
	unsigned long flags;

	spin_lock_irqsave(&pdc_lock, flags);
L
Linus Torvalds 已提交
905 906 907 908
	pdc_result[0] = 0;
	pdc_result[1] = 0;
	retval = mem_pdc_call(PDC_PCI_INDEX, PDC_PCI_READ_CONFIG, 
			      __pa(pdc_result), hpa, cfg_addr&~3UL, 4UL);
909 910
	spin_unlock_irqrestore(&pdc_lock, flags);

L
Linus Torvalds 已提交
911 912 913 914 915 916 917 918 919 920 921 922 923 924 925
	return retval ? ~0 : (unsigned int) pdc_result[0];
}


/** 
 * pdc_pci_config_write - read PCI config space.
 * @hpa		token from PDC to indicate which PCI device
 * @pci_addr	configuration space address to write
 * @val		value we want in the 32-bit register
 *
 * Write PCI Configuration space *before* linux PCI subsystem is running.
 */
void pdc_pci_config_write(void *hpa, unsigned long cfg_addr, unsigned int val)
{
	int retval;
926 927 928
	unsigned long flags;

	spin_lock_irqsave(&pdc_lock, flags);
L
Linus Torvalds 已提交
929 930 931 932
	pdc_result[0] = 0;
	retval = mem_pdc_call(PDC_PCI_INDEX, PDC_PCI_WRITE_CONFIG, 
			      __pa(pdc_result), hpa,
			      cfg_addr&~3UL, 4UL, (unsigned long) val);
933 934
	spin_unlock_irqrestore(&pdc_lock, flags);

L
Linus Torvalds 已提交
935 936 937 938 939 940 941 942 943 944 945 946 947
	return retval;
}
#endif /* UNTESTED CODE */

/**
 * pdc_tod_read - Read the Time-Of-Day clock.
 * @tod: The return buffer:
 *
 * Read the Time-Of-Day clock
 */
int pdc_tod_read(struct pdc_tod *tod)
{
        int retval;
948
	unsigned long flags;
L
Linus Torvalds 已提交
949

950
        spin_lock_irqsave(&pdc_lock, flags);
L
Linus Torvalds 已提交
951 952 953
        retval = mem_pdc_call(PDC_TOD, PDC_TOD_READ, __pa(pdc_result), 0);
        convert_to_wide(pdc_result);
        memcpy(tod, pdc_result, sizeof(*tod));
954
        spin_unlock_irqrestore(&pdc_lock, flags);
L
Linus Torvalds 已提交
955 956 957 958 959

        return retval;
}
EXPORT_SYMBOL(pdc_tod_read);

960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994
int pdc_mem_pdt_info(struct pdc_mem_retinfo *rinfo)
{
	int retval;
	unsigned long flags;

	spin_lock_irqsave(&pdc_lock, flags);
	retval = mem_pdc_call(PDC_MEM, PDC_MEM_MEMINFO, __pa(pdc_result), 0);
	convert_to_wide(pdc_result);
	memcpy(rinfo, pdc_result, sizeof(*rinfo));
	spin_unlock_irqrestore(&pdc_lock, flags);

	return retval;
}

int pdc_mem_pdt_read_entries(struct pdc_mem_read_pdt *pret,
		unsigned long *pdt_entries_ptr)
{
	int retval;
	unsigned long flags;

	spin_lock_irqsave(&pdc_lock, flags);
	retval = mem_pdc_call(PDC_MEM, PDC_MEM_READ_PDT, __pa(pdc_result),
			__pa(pdc_result2));
	if (retval == PDC_OK) {
		convert_to_wide(pdc_result);
		memcpy(pret, pdc_result, sizeof(*pret));
		convert_to_wide(pdc_result2);
		memcpy(pdt_entries_ptr, pdc_result2,
			pret->pdt_entries * sizeof(*pdt_entries_ptr));
	}
	spin_unlock_irqrestore(&pdc_lock, flags);

	return retval;
}

L
Linus Torvalds 已提交
995 996 997 998 999 1000 1001 1002 1003 1004
/**
 * pdc_tod_set - Set the Time-Of-Day clock.
 * @sec: The number of seconds since epoch.
 * @usec: The number of micro seconds.
 *
 * Set the Time-Of-Day clock.
 */ 
int pdc_tod_set(unsigned long sec, unsigned long usec)
{
        int retval;
1005
	unsigned long flags;
L
Linus Torvalds 已提交
1006

1007
        spin_lock_irqsave(&pdc_lock, flags);
L
Linus Torvalds 已提交
1008
        retval = mem_pdc_call(PDC_TOD, PDC_TOD_WRITE, sec, usec);
1009
        spin_unlock_irqrestore(&pdc_lock, flags);
L
Linus Torvalds 已提交
1010 1011 1012 1013 1014

        return retval;
}
EXPORT_SYMBOL(pdc_tod_set);

1015
#ifdef CONFIG_64BIT
L
Linus Torvalds 已提交
1016 1017 1018 1019
int pdc_mem_mem_table(struct pdc_memory_table_raddr *r_addr,
		struct pdc_memory_table *tbl, unsigned long entries)
{
	int retval;
1020
	unsigned long flags;
L
Linus Torvalds 已提交
1021

1022
	spin_lock_irqsave(&pdc_lock, flags);
L
Linus Torvalds 已提交
1023 1024 1025 1026
	retval = mem_pdc_call(PDC_MEM, PDC_MEM_TABLE, __pa(pdc_result), __pa(pdc_result2), entries);
	convert_to_wide(pdc_result);
	memcpy(r_addr, pdc_result, sizeof(*r_addr));
	memcpy(tbl, pdc_result2, entries * sizeof(*tbl));
1027
	spin_unlock_irqrestore(&pdc_lock, flags);
L
Linus Torvalds 已提交
1028 1029 1030

	return retval;
}
1031
#endif /* CONFIG_64BIT */
L
Linus Torvalds 已提交
1032 1033 1034 1035 1036 1037 1038 1039

/* FIXME: Is this pdc used?  I could not find type reference to ftc_bitmap
 * so I guessed at unsigned long.  Someone who knows what this does, can fix
 * it later. :)
 */
int pdc_do_firm_test_reset(unsigned long ftc_bitmap)
{
        int retval;
1040
	unsigned long flags;
L
Linus Torvalds 已提交
1041

1042
        spin_lock_irqsave(&pdc_lock, flags);
L
Linus Torvalds 已提交
1043 1044
        retval = mem_pdc_call(PDC_BROADCAST_RESET, PDC_DO_FIRM_TEST_RESET,
                              PDC_FIRM_TEST_MAGIC, ftc_bitmap);
1045
        spin_unlock_irqrestore(&pdc_lock, flags);
L
Linus Torvalds 已提交
1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057

        return retval;
}

/*
 * pdc_do_reset - Reset the system.
 *
 * Reset the system.
 */
int pdc_do_reset(void)
{
        int retval;
1058
	unsigned long flags;
L
Linus Torvalds 已提交
1059

1060
        spin_lock_irqsave(&pdc_lock, flags);
L
Linus Torvalds 已提交
1061
        retval = mem_pdc_call(PDC_BROADCAST_RESET, PDC_DO_RESET);
1062
        spin_unlock_irqrestore(&pdc_lock, flags);
L
Linus Torvalds 已提交
1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075

        return retval;
}

/*
 * pdc_soft_power_info - Enable soft power switch.
 * @power_reg: address of soft power register
 *
 * Return the absolute address of the soft power switch register
 */
int __init pdc_soft_power_info(unsigned long *power_reg)
{
	int retval;
1076
	unsigned long flags;
L
Linus Torvalds 已提交
1077 1078 1079

	*power_reg = (unsigned long) (-1);
	
1080
	spin_lock_irqsave(&pdc_lock, flags);
L
Linus Torvalds 已提交
1081 1082 1083 1084 1085
	retval = mem_pdc_call(PDC_SOFT_POWER, PDC_SOFT_POWER_INFO, __pa(pdc_result), 0);
	if (retval == PDC_OK) {
                convert_to_wide(pdc_result);
                *power_reg = f_extend(pdc_result[0]);
	}
1086
	spin_unlock_irqrestore(&pdc_lock, flags);
L
Linus Torvalds 已提交
1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104

	return retval;
}

/*
 * pdc_soft_power_button - Control the soft power button behaviour
 * @sw_control: 0 for hardware control, 1 for software control 
 *
 *
 * This PDC function places the soft power button under software or
 * hardware control.
 * Under software control the OS may control to when to allow to shut 
 * down the system. Under hardware control pressing the power button 
 * powers off the system immediately.
 */
int pdc_soft_power_button(int sw_control)
{
	int retval;
1105 1106 1107
	unsigned long flags;

	spin_lock_irqsave(&pdc_lock, flags);
L
Linus Torvalds 已提交
1108
	retval = mem_pdc_call(PDC_SOFT_POWER, PDC_SOFT_POWER_ENABLE, __pa(pdc_result), sw_control);
1109 1110
	spin_unlock_irqrestore(&pdc_lock, flags);

L
Linus Torvalds 已提交
1111 1112 1113 1114 1115 1116 1117 1118 1119 1120
	return retval;
}

/*
 * pdc_io_reset - Hack to avoid overlapping range registers of Bridges devices.
 * Primarily a problem on T600 (which parisc-linux doesn't support) but
 * who knows what other platform firmware might do with this OS "hook".
 */
void pdc_io_reset(void)
{
1121 1122 1123
	unsigned long flags;

	spin_lock_irqsave(&pdc_lock, flags);
L
Linus Torvalds 已提交
1124
	mem_pdc_call(PDC_IO, PDC_IO_RESET, 0);
1125
	spin_unlock_irqrestore(&pdc_lock, flags);
L
Linus Torvalds 已提交
1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138
}

/*
 * pdc_io_reset_devices - Hack to Stop USB controller
 *
 * If PDC used the usb controller, the usb controller
 * is still running and will crash the machines during iommu 
 * setup, because of still running DMA. This PDC call
 * stops the USB controller.
 * Normally called after calling pdc_io_reset().
 */
void pdc_io_reset_devices(void)
{
1139 1140 1141
	unsigned long flags;

	spin_lock_irqsave(&pdc_lock, flags);
L
Linus Torvalds 已提交
1142
	mem_pdc_call(PDC_IO, PDC_IO_RESET_DEVICES, 0);
1143
	spin_unlock_irqrestore(&pdc_lock, flags);
L
Linus Torvalds 已提交
1144 1145
}

1146 1147 1148
/* locked by pdc_console_lock */
static int __attribute__((aligned(8)))   iodc_retbuf[32];
static char __attribute__((aligned(64))) iodc_dbuf[4096];
L
Linus Torvalds 已提交
1149 1150

/**
1151 1152 1153
 * pdc_iodc_print - Console print using IODC.
 * @str: the string to output.
 * @count: length of str
L
Linus Torvalds 已提交
1154 1155 1156 1157 1158 1159
 *
 * Note that only these special chars are architected for console IODC io:
 * BEL, BS, CR, and LF. Others are passed through.
 * Since the HP console requires CR+LF to perform a 'newline', we translate
 * "\n" to "\r\n".
 */
1160
int pdc_iodc_print(const unsigned char *str, unsigned count)
L
Linus Torvalds 已提交
1161
{
1162
	unsigned int i;
1163
	unsigned long flags;
L
Linus Torvalds 已提交
1164

1165
	for (i = 0; i < count;) {
1166 1167 1168 1169 1170
		switch(str[i]) {
		case '\n':
			iodc_dbuf[i+0] = '\r';
			iodc_dbuf[i+1] = '\n';
			i += 2;
1171
			goto print;
1172 1173
		default:
			iodc_dbuf[i] = str[i];
1174
			i++;
1175 1176 1177
			break;
		}
	}
L
Linus Torvalds 已提交
1178

1179
print:
L
Linus Torvalds 已提交
1180 1181 1182 1183
        spin_lock_irqsave(&pdc_lock, flags);
        real32_call(PAGE0->mem_cons.iodc_io,
                    (unsigned long)PAGE0->mem_cons.hpa, ENTRY_IO_COUT,
                    PAGE0->mem_cons.spa, __pa(PAGE0->mem_cons.dp.layers),
1184
                    __pa(iodc_retbuf), 0, __pa(iodc_dbuf), i, 0);
L
Linus Torvalds 已提交
1185 1186
        spin_unlock_irqrestore(&pdc_lock, flags);

1187
	return i;
L
Linus Torvalds 已提交
1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199
}

/**
 * pdc_iodc_getc - Read a character (non-blocking) from the PDC console.
 *
 * Read a character (non-blocking) from the PDC console, returns -1 if
 * key is not present.
 */
int pdc_iodc_getc(void)
{
	int ch;
	int status;
1200
	unsigned long flags;
L
Linus Torvalds 已提交
1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227

	/* Bail if no console input device. */
	if (!PAGE0->mem_kbd.iodc_io)
		return 0;
	
	/* wait for a keyboard (rs232)-input */
	spin_lock_irqsave(&pdc_lock, flags);
	real32_call(PAGE0->mem_kbd.iodc_io,
		    (unsigned long)PAGE0->mem_kbd.hpa, ENTRY_IO_CIN,
		    PAGE0->mem_kbd.spa, __pa(PAGE0->mem_kbd.dp.layers), 
		    __pa(iodc_retbuf), 0, __pa(iodc_dbuf), 1, 0);

	ch = *iodc_dbuf;
	status = *iodc_retbuf;
	spin_unlock_irqrestore(&pdc_lock, flags);

	if (status == 0)
	    return -1;
	
	return ch;
}

int pdc_sti_call(unsigned long func, unsigned long flags,
                 unsigned long inptr, unsigned long outputr,
                 unsigned long glob_cfg)
{
        int retval;
1228
	unsigned long irqflags;
L
Linus Torvalds 已提交
1229

1230
        spin_lock_irqsave(&pdc_lock, irqflags);  
L
Linus Torvalds 已提交
1231
        retval = real32_call(func, flags, inptr, outputr, glob_cfg);
1232
        spin_unlock_irqrestore(&pdc_lock, irqflags);
L
Linus Torvalds 已提交
1233 1234 1235 1236 1237

        return retval;
}
EXPORT_SYMBOL(pdc_sti_call);

1238
#ifdef CONFIG_64BIT
L
Linus Torvalds 已提交
1239 1240 1241 1242 1243 1244 1245 1246 1247 1248
/**
 * pdc_pat_cell_get_number - Returns the cell number.
 * @cell_info: The return buffer.
 *
 * This PDC call returns the cell number of the cell from which the call
 * is made.
 */
int pdc_pat_cell_get_number(struct pdc_pat_cell_num *cell_info)
{
	int retval;
1249
	unsigned long flags;
L
Linus Torvalds 已提交
1250

1251
	spin_lock_irqsave(&pdc_lock, flags);
L
Linus Torvalds 已提交
1252 1253
	retval = mem_pdc_call(PDC_PAT_CELL, PDC_PAT_CELL_GET_NUMBER, __pa(pdc_result));
	memcpy(cell_info, pdc_result, sizeof(*cell_info));
1254
	spin_unlock_irqrestore(&pdc_lock, flags);
L
Linus Torvalds 已提交
1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273

	return retval;
}

/**
 * pdc_pat_cell_module - Retrieve the cell's module information.
 * @actcnt: The number of bytes written to mem_addr.
 * @ploc: The physical location.
 * @mod: The module index.
 * @view_type: The view of the address type.
 * @mem_addr: The return buffer.
 *
 * This PDC call returns information about each module attached to the cell
 * at the specified location.
 */
int pdc_pat_cell_module(unsigned long *actcnt, unsigned long ploc, unsigned long mod,
			unsigned long view_type, void *mem_addr)
{
	int retval;
1274
	unsigned long flags;
L
Linus Torvalds 已提交
1275 1276
	static struct pdc_pat_cell_mod_maddr_block result __attribute__ ((aligned (8)));

1277
	spin_lock_irqsave(&pdc_lock, flags);
L
Linus Torvalds 已提交
1278 1279 1280 1281 1282 1283
	retval = mem_pdc_call(PDC_PAT_CELL, PDC_PAT_CELL_MODULE, __pa(pdc_result), 
			      ploc, mod, view_type, __pa(&result));
	if(!retval) {
		*actcnt = pdc_result[0];
		memcpy(mem_addr, &result, *actcnt);
	}
1284
	spin_unlock_irqrestore(&pdc_lock, flags);
L
Linus Torvalds 已提交
1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295

	return retval;
}

/**
 * pdc_pat_cpu_get_number - Retrieve the cpu number.
 * @cpu_info: The return buffer.
 * @hpa: The Hard Physical Address of the CPU.
 *
 * Retrieve the cpu number for the cpu at the specified HPA.
 */
1296
int pdc_pat_cpu_get_number(struct pdc_pat_cpu_num *cpu_info, unsigned long hpa)
L
Linus Torvalds 已提交
1297 1298
{
	int retval;
1299
	unsigned long flags;
L
Linus Torvalds 已提交
1300

1301
	spin_lock_irqsave(&pdc_lock, flags);
L
Linus Torvalds 已提交
1302 1303 1304
	retval = mem_pdc_call(PDC_PAT_CPU, PDC_PAT_CPU_GET_NUMBER,
			      __pa(&pdc_result), hpa);
	memcpy(cpu_info, pdc_result, sizeof(*cpu_info));
1305
	spin_unlock_irqrestore(&pdc_lock, flags);
L
Linus Torvalds 已提交
1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320

	return retval;
}

/**
 * pdc_pat_get_irt_size - Retrieve the number of entries in the cell's interrupt table.
 * @num_entries: The return value.
 * @cell_num: The target cell.
 *
 * This PDC function returns the number of entries in the specified cell's
 * interrupt table.
 */
int pdc_pat_get_irt_size(unsigned long *num_entries, unsigned long cell_num)
{
	int retval;
1321
	unsigned long flags;
L
Linus Torvalds 已提交
1322

1323
	spin_lock_irqsave(&pdc_lock, flags);
L
Linus Torvalds 已提交
1324 1325 1326
	retval = mem_pdc_call(PDC_PAT_IO, PDC_PAT_IO_GET_PCI_ROUTING_TABLE_SIZE,
			      __pa(pdc_result), cell_num);
	*num_entries = pdc_result[0];
1327
	spin_unlock_irqrestore(&pdc_lock, flags);
L
Linus Torvalds 已提交
1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341

	return retval;
}

/**
 * pdc_pat_get_irt - Retrieve the cell's interrupt table.
 * @r_addr: The return buffer.
 * @cell_num: The target cell.
 *
 * This PDC function returns the actual interrupt table for the specified cell.
 */
int pdc_pat_get_irt(void *r_addr, unsigned long cell_num)
{
	int retval;
1342
	unsigned long flags;
L
Linus Torvalds 已提交
1343

1344
	spin_lock_irqsave(&pdc_lock, flags);
L
Linus Torvalds 已提交
1345 1346
	retval = mem_pdc_call(PDC_PAT_IO, PDC_PAT_IO_GET_PCI_ROUTING_TABLE,
			      __pa(r_addr), cell_num);
1347
	spin_unlock_irqrestore(&pdc_lock, flags);
L
Linus Torvalds 已提交
1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363

	return retval;
}

/**
 * pdc_pat_pd_get_addr_map - Retrieve information about memory address ranges.
 * @actlen: The return buffer.
 * @mem_addr: Pointer to the memory buffer.
 * @count: The number of bytes to read from the buffer.
 * @offset: The offset with respect to the beginning of the buffer.
 *
 */
int pdc_pat_pd_get_addr_map(unsigned long *actual_len, void *mem_addr, 
			    unsigned long count, unsigned long offset)
{
	int retval;
1364
	unsigned long flags;
L
Linus Torvalds 已提交
1365

1366
	spin_lock_irqsave(&pdc_lock, flags);
L
Linus Torvalds 已提交
1367 1368 1369 1370
	retval = mem_pdc_call(PDC_PAT_PD, PDC_PAT_PD_GET_ADDR_MAP, __pa(pdc_result), 
			      __pa(pdc_result2), count, offset);
	*actual_len = pdc_result[0];
	memcpy(mem_addr, pdc_result2, *actual_len);
1371
	spin_unlock_irqrestore(&pdc_lock, flags);
L
Linus Torvalds 已提交
1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385

	return retval;
}

/**
 * pdc_pat_io_pci_cfg_read - Read PCI configuration space.
 * @pci_addr: PCI configuration space address for which the read request is being made.
 * @pci_size: Size of read in bytes. Valid values are 1, 2, and 4. 
 * @mem_addr: Pointer to return memory buffer.
 *
 */
int pdc_pat_io_pci_cfg_read(unsigned long pci_addr, int pci_size, u32 *mem_addr)
{
	int retval;
1386 1387 1388
	unsigned long flags;

	spin_lock_irqsave(&pdc_lock, flags);
L
Linus Torvalds 已提交
1389 1390 1391
	retval = mem_pdc_call(PDC_PAT_IO, PDC_PAT_IO_PCI_CONFIG_READ,
					__pa(pdc_result), pci_addr, pci_size);
	switch(pci_size) {
1392 1393 1394
		case 1: *(u8 *) mem_addr =  (u8)  pdc_result[0]; break;
		case 2: *(u16 *)mem_addr =  (u16) pdc_result[0]; break;
		case 4: *(u32 *)mem_addr =  (u32) pdc_result[0]; break;
L
Linus Torvalds 已提交
1395
	}
1396
	spin_unlock_irqrestore(&pdc_lock, flags);
L
Linus Torvalds 已提交
1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411

	return retval;
}

/**
 * pdc_pat_io_pci_cfg_write - Retrieve information about memory address ranges.
 * @pci_addr: PCI configuration space address for which the write  request is being made.
 * @pci_size: Size of write in bytes. Valid values are 1, 2, and 4. 
 * @value: Pointer to 1, 2, or 4 byte value in low order end of argument to be 
 *         written to PCI Config space.
 *
 */
int pdc_pat_io_pci_cfg_write(unsigned long pci_addr, int pci_size, u32 val)
{
	int retval;
1412
	unsigned long flags;
L
Linus Torvalds 已提交
1413

1414
	spin_lock_irqsave(&pdc_lock, flags);
L
Linus Torvalds 已提交
1415 1416
	retval = mem_pdc_call(PDC_PAT_IO, PDC_PAT_IO_PCI_CONFIG_WRITE,
				pci_addr, pci_size, val);
1417
	spin_unlock_irqrestore(&pdc_lock, flags);
L
Linus Torvalds 已提交
1418 1419 1420

	return retval;
}
1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483

/**
 * pdc_pat_mem_pdc_info - Retrieve information about page deallocation table
 * @rinfo: memory pdt information
 *
 */
int pdc_pat_mem_pdt_info(struct pdc_pat_mem_retinfo *rinfo)
{
	int retval;
	unsigned long flags;

	spin_lock_irqsave(&pdc_lock, flags);
	retval = mem_pdc_call(PDC_PAT_MEM, PDC_PAT_MEM_PD_INFO,
			__pa(&pdc_result));
	if (retval == PDC_OK)
		memcpy(rinfo, &pdc_result, sizeof(*rinfo));
	spin_unlock_irqrestore(&pdc_lock, flags);

	return retval;
}

/**
 * pdc_pat_mem_read_cell_pdt - Read PDT entries from (old) PAT firmware
 * @pret: array of PDT entries
 * @pdt_entries_ptr: ptr to hold number of PDT entries
 * @max_entries: maximum number of entries to be read
 *
 */
int pdc_pat_mem_read_cell_pdt(struct pdc_pat_mem_read_pd_retinfo *pret,
		unsigned long *pdt_entries_ptr, unsigned long max_entries)
{
	int retval;
	unsigned long flags, entries;

	spin_lock_irqsave(&pdc_lock, flags);
	/* PDC_PAT_MEM_CELL_READ is available on early PAT machines only */
	retval = mem_pdc_call(PDC_PAT_MEM, PDC_PAT_MEM_CELL_READ,
			__pa(&pdc_result), parisc_cell_num, __pa(&pdc_result2));

	if (retval == PDC_OK) {
		/* build up return value as for PDC_PAT_MEM_PD_READ */
		entries = min(pdc_result[0], max_entries);
		pret->pdt_entries = entries;
		pret->actual_count_bytes = entries * sizeof(unsigned long);
		memcpy(pdt_entries_ptr, &pdc_result2, pret->actual_count_bytes);
	}

	spin_unlock_irqrestore(&pdc_lock, flags);
	WARN_ON(retval == PDC_OK && pdc_result[0] > max_entries);

	return retval;
}
/**
 * pdc_pat_mem_read_pd_pdt - Read PDT entries from (newer) PAT firmware
 * @pret: array of PDT entries
 * @pdt_entries_ptr: ptr to hold number of PDT entries
 *
 */
int pdc_pat_mem_read_pd_pdt(struct pdc_pat_mem_read_pd_retinfo *pret,
		unsigned long *pdt_entries_ptr, unsigned long count,
		unsigned long offset)
{
	int retval;
1484
	unsigned long flags, entries;
1485 1486 1487

	spin_lock_irqsave(&pdc_lock, flags);
	retval = mem_pdc_call(PDC_PAT_MEM, PDC_PAT_MEM_PD_READ,
1488
		__pa(&pdc_result), __pa(pdt_entries_ptr),
1489
		count, offset);
1490 1491 1492 1493 1494 1495 1496

	if (retval == PDC_OK) {
		entries = min(pdc_result[0], count);
		pret->actual_count_bytes = entries;
		pret->pdt_entries = entries / sizeof(unsigned long);
	}

1497 1498 1499 1500
	spin_unlock_irqrestore(&pdc_lock, flags);

	return retval;
}
1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525

/**
 * pdc_pat_mem_get_dimm_phys_location - Get physical DIMM slot via PAT firmware
 * @pret: ptr to hold returned information
 * @phys_addr: physical address to examine
 *
 */
int pdc_pat_mem_get_dimm_phys_location(
		struct pdc_pat_mem_phys_mem_location *pret,
		unsigned long phys_addr)
{
	int retval;
	unsigned long flags;

	spin_lock_irqsave(&pdc_lock, flags);
	retval = mem_pdc_call(PDC_PAT_MEM, PDC_PAT_MEM_ADDRESS,
		__pa(&pdc_result), phys_addr);

	if (retval == PDC_OK)
		memcpy(pret, &pdc_result, sizeof(*pret));

	spin_unlock_irqrestore(&pdc_lock, flags);

	return retval;
}
1526
#endif /* CONFIG_64BIT */
L
Linus Torvalds 已提交
1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583


/***************** 32-bit real-mode calls ***********/
/* The struct below is used
 * to overlay real_stack (real2.S), preparing a 32-bit call frame.
 * real32_call_asm() then uses this stack in narrow real mode
 */

struct narrow_stack {
	/* use int, not long which is 64 bits */
	unsigned int arg13;
	unsigned int arg12;
	unsigned int arg11;
	unsigned int arg10;
	unsigned int arg9;
	unsigned int arg8;
	unsigned int arg7;
	unsigned int arg6;
	unsigned int arg5;
	unsigned int arg4;
	unsigned int arg3;
	unsigned int arg2;
	unsigned int arg1;
	unsigned int arg0;
	unsigned int frame_marker[8];
	unsigned int sp;
	/* in reality, there's nearly 8k of stack after this */
};

long real32_call(unsigned long fn, ...)
{
	va_list args;
	extern struct narrow_stack real_stack;
	extern unsigned long real32_call_asm(unsigned int *,
					     unsigned int *, 
					     unsigned int);
	
	va_start(args, fn);
	real_stack.arg0 = va_arg(args, unsigned int);
	real_stack.arg1 = va_arg(args, unsigned int);
	real_stack.arg2 = va_arg(args, unsigned int);
	real_stack.arg3 = va_arg(args, unsigned int);
	real_stack.arg4 = va_arg(args, unsigned int);
	real_stack.arg5 = va_arg(args, unsigned int);
	real_stack.arg6 = va_arg(args, unsigned int);
	real_stack.arg7 = va_arg(args, unsigned int);
	real_stack.arg8 = va_arg(args, unsigned int);
	real_stack.arg9 = va_arg(args, unsigned int);
	real_stack.arg10 = va_arg(args, unsigned int);
	real_stack.arg11 = va_arg(args, unsigned int);
	real_stack.arg12 = va_arg(args, unsigned int);
	real_stack.arg13 = va_arg(args, unsigned int);
	va_end(args);
	
	return real32_call_asm(&real_stack.sp, &real_stack.arg0, fn);
}

1584
#ifdef CONFIG_64BIT
L
Linus Torvalds 已提交
1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634
/***************** 64-bit real-mode calls ***********/

struct wide_stack {
	unsigned long arg0;
	unsigned long arg1;
	unsigned long arg2;
	unsigned long arg3;
	unsigned long arg4;
	unsigned long arg5;
	unsigned long arg6;
	unsigned long arg7;
	unsigned long arg8;
	unsigned long arg9;
	unsigned long arg10;
	unsigned long arg11;
	unsigned long arg12;
	unsigned long arg13;
	unsigned long frame_marker[2];	/* rp, previous sp */
	unsigned long sp;
	/* in reality, there's nearly 8k of stack after this */
};

long real64_call(unsigned long fn, ...)
{
	va_list args;
	extern struct wide_stack real64_stack;
	extern unsigned long real64_call_asm(unsigned long *,
					     unsigned long *, 
					     unsigned long);
    
	va_start(args, fn);
	real64_stack.arg0 = va_arg(args, unsigned long);
	real64_stack.arg1 = va_arg(args, unsigned long);
	real64_stack.arg2 = va_arg(args, unsigned long);
	real64_stack.arg3 = va_arg(args, unsigned long);
	real64_stack.arg4 = va_arg(args, unsigned long);
	real64_stack.arg5 = va_arg(args, unsigned long);
	real64_stack.arg6 = va_arg(args, unsigned long);
	real64_stack.arg7 = va_arg(args, unsigned long);
	real64_stack.arg8 = va_arg(args, unsigned long);
	real64_stack.arg9 = va_arg(args, unsigned long);
	real64_stack.arg10 = va_arg(args, unsigned long);
	real64_stack.arg11 = va_arg(args, unsigned long);
	real64_stack.arg12 = va_arg(args, unsigned long);
	real64_stack.arg13 = va_arg(args, unsigned long);
	va_end(args);
	
	return real64_call_asm(&real64_stack.sp, &real64_stack.arg0, fn);
}

1635
#endif /* CONFIG_64BIT */
L
Linus Torvalds 已提交
1636