⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 firmware.c

📁 优龙2410linux2.6.8内核源代码
💻 C
📖 第 1 页 / 共 3 页
字号:
/* * 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> * *    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/system.h>#include <asm/processor.h>	/* for boot_cpu_data */static spinlock_t pdc_lock = SPIN_LOCK_UNLOCKED;static unsigned long pdc_result[32] __attribute__ ((aligned (8)));static unsigned long pdc_result2[32] __attribute__ ((aligned (8)));#ifdef __LP64__#define WIDE_FIRMWARE 0x1#define NARROW_FIRMWARE 0x2/* Firmware needs to be initially set to narrow to determine the  * actual firmware width. */int parisc_narrow_firmware = 1;#endif/* on all currently-supported platforms, IODC I/O calls are always * 32-bit calls, and MEM_PDC calls are always the same width as the OS. * This means Cxxx boxes can't run wide kernels right now. -PB * * CONFIG_PDC_NARROW has been added to allow 64-bit kernels to run on * systems with 32-bit MEM_PDC calls. This will allow wide kernels to * run on Cxxx boxes now. -RB * * Note that some PAT boxes may have 64-bit IODC I/O... */#ifdef __LP64__long real64_call(unsigned long function, ...);#endiflong real32_call(unsigned long function, ...);#ifdef __LP64__#   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){#ifdef __LP64__	if(unlikely(parisc_narrow_firmware)) {		if((address & 0xff000000) == 0xf0000000)			return 0xf0f0f0f000000000 | (u32)address;		if((address & 0xf0000000) == 0xf0000000)			return 0xffffffff00000000 | (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){#ifdef __LP64__	int i;	unsigned int *p = (unsigned int *)addr;	if(unlikely(parisc_narrow_firmware)) {		for(i = 31; i >= 0; --i)			addr[i] = p[i];	}#endif}/** * set_firmware_width - Determine if the firmware is wide or narrow. *  * This function must be called before any pdc_* function that uses the convert_to_wide * function. */void __init set_firmware_width(void){#ifdef __LP64__	int retval;        spin_lock_irq(&pdc_lock);	retval = 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;        spin_unlock_irq(&pdc_lock);#endif}/** * 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;        spin_lock_irq(&pdc_lock);        retval = mem_pdc_call(PDC_ADD_VALID, PDC_ADD_VALID_VERIFY, address);        spin_unlock_irq(&pdc_lock);        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;        spin_lock_irq(&pdc_lock);        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);        spin_unlock_irq(&pdc_lock);        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 */#ifdef __LP64__int pdc_pat_chassis_send_log(unsigned long state, unsigned long data){	int retval = 0;        	if (!is_pdc_pat())		return -1;	spin_lock_irq(&pdc_lock);	retval = mem_pdc_call(PDC_PAT_CHASSIS_LOG, PDC_PAT_CHASSIS_WRITE_LOG, __pa(&state), __pa(&data));	spin_unlock_irq(&pdc_lock);	return retval;}#endif/** * pdc_chassis_disp - Updates display * @retval: -1 on error, 0 on success * * Works on old PDC only (E class, others?) */int pdc_chassis_disp(unsigned long disp){	int retval = 0;	spin_lock_irq(&pdc_lock);	retval = mem_pdc_call(PDC_CHASSIS, PDC_CHASSIS_DISP, disp);	spin_unlock_irq(&pdc_lock);	return retval;}/** * 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. */int __init pdc_coproc_cfg(struct pdc_coproc_cfg *pdc_coproc_info){        int retval;        spin_lock_irq(&pdc_lock);        retval = 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];        spin_unlock_irq(&pdc_lock);        return retval;}/** * 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;	spin_lock_irq(&pdc_lock);	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);	spin_unlock_irq(&pdc_lock);	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;	spin_lock_irq(&pdc_lock);	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));	spin_unlock_irq(&pdc_lock);	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;	spin_lock_irq(&pdc_lock);	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));	spin_unlock_irq(&pdc_lock);	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;	spin_lock_irq(&pdc_lock);	retval = mem_pdc_call(PDC_MODEL, PDC_MODEL_INFO, __pa(pdc_result), 0);	convert_to_wide(pdc_result);	memcpy(model, pdc_result, sizeof(*model));	spin_unlock_irq(&pdc_lock);	return retval;}/** * pdc_model_sysmodel - Get the system model name. * @name: A char array of at least 81 characters. * * Get system model name from PDC ROM (e.g. 9000/715 or 9000/778/B160L) */int pdc_model_sysmodel(char *name){        int retval;        spin_lock_irq(&pdc_lock);        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;        }        spin_unlock_irq(&pdc_lock);        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;        spin_lock_irq(&pdc_lock);        retval = mem_pdc_call(PDC_MODEL, PDC_MODEL_VERSIONS, __pa(pdc_result), id);        convert_to_wide(pdc_result);        *versions = pdc_result[0];        spin_unlock_irq(&pdc_lock);        return retval;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -