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

📄 klconflib.c

📁 Linux内核源代码 为压缩文件 是<<Linux内核>>一书中的源代码
💻 C
📖 第 1 页 / 共 3 页
字号:
/* $Id$ * * This file is subject to the terms and conditions of the GNU General Public * License.  See the file "COPYING" in the main directory of this archive * for more details. * * Copyright (C) 1992 - 1997, 2000 Silicon Graphics, Inc. * Copyright (C) 2000 by Colin Ngam */#include <linux/types.h>#include <linux/config.h>#include <linux/ctype.h>#include <asm/sn/sgi.h>#include <asm/sn/iograph.h>#include <asm/sn/invent.h>#include <asm/sn/hcl.h>#include <asm/sn/labelcl.h>#include <asm/sn/agent.h>#include <asm/sn/klconfig.h>#include <asm/sn/nodepda.h>#include <asm/sn/module.h>#include <asm/sn/router.h>#include <asm/sn/xtalk/xbow.h>#define printf printkint hasmetarouter;#define LDEBUG 0#define NIC_UNKNOWN ((nic_t) -1)#undef DEBUG_KLGRAPH#ifdef DEBUG_KLGRAPH#define DBG(x...) printk(x)#else#define DBG(x...)#endif /* DEBUG_KLGRAPH */static void sort_nic_names(lboard_t *) ;lboard_t *find_lboard(lboard_t *start, unsigned char brd_type){	/* Search all boards stored on this node. */	while (start) {		if (start->brd_type == brd_type)			return start;		start = KLCF_NEXT(start);	}	/* Didn't find it. */	return (lboard_t *)NULL;}lboard_t *find_lboard_class(lboard_t *start, unsigned char brd_type){	/* Search all boards stored on this node. */	while (start) {		if (KLCLASS(start->brd_type) == KLCLASS(brd_type))			return start;		start = KLCF_NEXT(start);	}	/* Didn't find it. */	return (lboard_t *)NULL;}klinfo_t *find_component(lboard_t *brd, klinfo_t *kli, unsigned char struct_type){	int index, j;	if (kli == (klinfo_t *)NULL) {		index = 0;	} else {		for (j = 0; j < KLCF_NUM_COMPS(brd); j++) {			if (kli == KLCF_COMP(brd, j))				break;		}		index = j;		if (index == KLCF_NUM_COMPS(brd)) {			printf("find_component: Bad pointer: 0x%p\n", kli);			return (klinfo_t *)NULL;		}		index++;	/* next component */	}		for (; index < KLCF_NUM_COMPS(brd); index++) {				kli = KLCF_COMP(brd, index);		DBG("find_component: brd %p kli %p  request type = 0x%x kli type 0x%x\n", brd, kli, kli->struct_type, KLCF_COMP_TYPE(kli));		if (KLCF_COMP_TYPE(kli) == struct_type)			return kli;	}	/* Didn't find it. */	return (klinfo_t *)NULL;}klinfo_t *find_first_component(lboard_t *brd, unsigned char struct_type){	return find_component(brd, (klinfo_t *)NULL, struct_type);}lboard_t *find_lboard_modslot(lboard_t *start, moduleid_t mod, slotid_t slot){	/* Search all boards stored on this node. */	while (start) {		if (MODULE_MATCH(start->brd_module, mod) &&		    (start->brd_slot == slot))			return start;		start = KLCF_NEXT(start);	}	/* Didn't find it. */	return (lboard_t *)NULL;}lboard_t *find_lboard_module(lboard_t *start, moduleid_t mod){        /* Search all boards stored on this node. */        while (start) {                if (MODULE_MATCH(start->brd_module, mod))                        return start;                start = KLCF_NEXT(start);        }        /* Didn't find it. */        return (lboard_t *)NULL;}lboard_t *find_lboard_module_class(lboard_t *start, moduleid_t mod,                                                unsigned char brd_type){	while (start) {		DBG("find_lboard_module_class: lboard 0x%p, start->brd_module 0x%x, mod 0x%x, start->brd_type 0x%x, brd_type 0x%x\n", start, start->brd_module, mod, start->brd_type, brd_type);		if (MODULE_MATCH(start->brd_module, mod) &&			(KLCLASS(start->brd_type) == KLCLASS(brd_type)))			return start;		start = KLCF_NEXT(start);	}	/* Didn't find it. */	return (lboard_t *)NULL;}#ifndef CONFIG_IA64_SGI_IO#define tolower(c)	(isupper(c) ? (c) - 'A' + 'a' : (c))#define toupper(c)	(islower(c) ? (c) - 'a' + 'A' : (c))#endif/* * Convert a NIC name to a name for use in the hardware graph. */voidnic_name_convert(char *old_name, char *new_name){        int i;        char c;        char *compare_ptr;	if ((old_name[0] == '\0') || (old_name[1] == '\0')) {                strcpy(new_name, EDGE_LBL_XWIDGET);        } else {                for (i = 0; i < strlen(old_name); i++) {                        c = old_name[i];                        if (isalpha(c))                                new_name[i] = tolower(c);                        else if (isdigit(c))                                new_name[i] = c;                        else                                new_name[i] = '_';                }                new_name[i] = '\0';        }        /* XXX -         * Since a bunch of boards made it out with weird names like         * IO6-fibbbed and IO6P2, we need to look for IO6 in a name and         * replace it with "baseio" to avoid confusion in the field.	 * We also have to make sure we don't report media_io instead of	 * baseio.         */        /* Skip underscores at the beginning of the name */        for (compare_ptr = new_name; (*compare_ptr) == '_'; compare_ptr++)                ;	/*	 * Check for some names we need to replace.  Early boards	 * had junk following the name so check only the first	 * characters.	 */        if (!strncmp(new_name, "io6", 3) ||             !strncmp(new_name, "mio", 3) || 	    !strncmp(new_name, "media_io", 8))		strcpy(new_name, "baseio");#if !defined(CONFIG_SGI_IP35) && !defined(CONFIG_IA64_SGI_SN1) && !defined(CONFIG_IA64_GENERIC)	else if (!strncmp(new_name, "ip29", 4))		strcpy(new_name,SN00_MOTHERBOARD);#endif	else if (!strncmp(new_name, "divo", 4))		strcpy(new_name, "divo") ;}/* Check if the given board corresponds to the global  * master io6 */intis_master_baseio(nasid_t nasid,moduleid_t module,slotid_t slot){	lboard_t	*board;#if CONFIG_SGI_IP35 || CONFIG_IA64_SGI_SN1 || CONFIG_IA64_GENERIC/* BRINGUP: If this works then look for callers of is_master_baseio() * (e.g. iograph.c) and let them pass in a slot if they want */	board = find_lboard_module((lboard_t *)KL_CONFIG_INFO(nasid), module);#else	board = find_lboard_modslot((lboard_t *)KL_CONFIG_INFO(nasid),				    module, slot);#endif#ifndef _STANDALONE	{		cnodeid_t cnode = NASID_TO_COMPACT_NODEID(nasid);		if (!board && (NODEPDA(cnode)->xbow_peer != INVALID_NASID))#if CONFIG_SGI_IP35 || CONFIG_IA64_SGI_SN1 || CONFIG_IA64_GENERIC			board = find_lboard_module((lboard_t *)				    KL_CONFIG_INFO(NODEPDA(cnode)->xbow_peer),				    module);#else			board = find_lboard_modslot((lboard_t *)				    KL_CONFIG_INFO(NODEPDA(cnode)->xbow_peer),				    module, slot);#endif	}#endif	if (!board)		return(0);	return(board->brd_flags & GLOBAL_MASTER_IO6);}/* * Find the lboard structure and get the board name. * If we can't find the structure or it's too low a revision, * use default name. */lboard_t *get_board_name(nasid_t nasid, moduleid_t mod, slotid_t slot, char *name){	lboard_t *brd;	brd = find_lboard_modslot((lboard_t *)KL_CONFIG_INFO(nasid),				  mod, slot);#ifndef _STANDALONE	{		cnodeid_t cnode = NASID_TO_COMPACT_NODEID(nasid);		if (!brd && (NODEPDA(cnode)->xbow_peer != INVALID_NASID))			brd = find_lboard_modslot((lboard_t *)				KL_CONFIG_INFO(NODEPDA(cnode)->xbow_peer),				mod, slot);	}#endif	if (!brd || (brd->brd_sversion < 2)) {		strcpy(name, EDGE_LBL_XWIDGET);	} else {		nic_name_convert(brd->brd_name, name);	}	/* 	 * PV # 540860	 * If the name is not 'baseio' or SN00 MOTHERBOARD	 * get the lowest of all the names in the nic string.	 * This is needed for boards like divo, which can have	 * a bunch of daughter cards, but would like to be called	 * divo. We could do this for baseio and SN00 MOTHERBOARD 	 * but it has some special case names that we would not 	 * like to disturb at this point.	 */	/* gfx boards don't need any of this name scrambling */	if (brd && (KLCLASS(brd->brd_type) == KLCLASS_GFX)) {		return(brd);	}	if (!(!strcmp(name, "baseio") )) {		if (brd) {			sort_nic_names(brd) ;			/* Convert to small case, '-' to '_' etc */			nic_name_convert(brd->brd_name, name) ;		}	}	return(brd);}intget_cpu_slice(cpuid_t cpu){	klcpu_t *acpu;	if ((acpu = get_cpuinfo(cpu)) == NULL)	    return -1;	return acpu->cpu_info.physid;}/* * get_actual_nasid * *	Completely disabled brds have their klconfig on  *	some other nasid as they have no memory. But their *	actual nasid is hidden in the klconfig. Use this *	routine to get it. Works for normal boards too. */nasid_tget_actual_nasid(lboard_t *brd){	klhub_t	*hub ;	if (!brd)		return INVALID_NASID ;	/* find out if we are a completely disabled brd. */        hub  = (klhub_t *)find_first_component(brd, KLSTRUCT_HUB);	if (!hub)                return INVALID_NASID ;	if (!(hub->hub_info.flags & KLINFO_ENABLE))	/* disabled node brd */		return hub->hub_info.physid ;	else		return brd->brd_nasid ;}intxbow_port_io_enabled(nasid_t nasid, int link){	lboard_t *brd;	klxbow_t *xbow_p;	/*	 * look for boards that might contain an xbow or xbridge	 */#if SN0	brd = find_lboard((lboard_t *)KL_CONFIG_INFO(nasid), KLTYPE_MIDPLANE8);#else	brd = find_lboard((lboard_t *)KL_CONFIG_INFO(nasid), KLTYPE_PBRICK_XBOW);#endif	if (brd == NULL) return 0;			if ((xbow_p = (klxbow_t *)find_component(brd, NULL, KLSTRUCT_XBOW))	    == NULL)	    return 0;	if (!XBOW_PORT_TYPE_IO(xbow_p, link) || !XBOW_PORT_IS_ENABLED(xbow_p, link))	    return 0;	printf("xbow_port_io_enabled:  brd 0x%p xbow_p 0x%p \n", brd, xbow_p);	return 1;}voidboard_to_path(lboard_t *brd, char *path){	moduleid_t modnum;	char *board_name;#if !defined(CONFIG_SGI_IP35) && !defined(CONFIG_IA64_SGI_SN1) && !defined(CONFIG_IA64_GENERIC)	slotid_t slot;	char slot_name[SLOTNUM_MAXLENGTH];#endif	ASSERT(brd);	switch (KLCLASS(brd->brd_type)) {		case KLCLASS_NODE:			board_name = EDGE_LBL_NODE;			break;		case KLCLASS_ROUTER:			if (brd->brd_type == KLTYPE_META_ROUTER) {				board_name = EDGE_LBL_META_ROUTER;				hasmetarouter++;			} else				board_name = EDGE_LBL_ROUTER;			break;		case KLCLASS_MIDPLANE:			board_name = EDGE_LBL_MIDPLANE;			break;		case KLCLASS_IO:			board_name = EDGE_LBL_IO;			break;		case KLCLASS_IOBRICK:			if (brd->brd_type == KLTYPE_PBRICK)				board_name = EDGE_LBL_PBRICK;			else if (brd->brd_type == KLTYPE_IBRICK)				board_name = EDGE_LBL_IBRICK;			else if (brd->brd_type == KLTYPE_XBRICK)				board_name = EDGE_LBL_XBRICK;			else				board_name = EDGE_LBL_IOBRICK;			break;		default:			board_name = EDGE_LBL_UNKNOWN;	}				modnum = brd->brd_module;#if defined(SN0)	slot = brd->brd_slot;	get_slotname(slot, slot_name);	ASSERT(modnum >= 0);	sprintf(path, "%H/" EDGE_LBL_SLOT "/%s/%s", 		modnum, slot_name, board_name);#else	ASSERT(modnum != MODULE_UNKNOWN && modnum != INVALID_MODULE);#ifdef BRINGUP /* fix IP35 hwgraph */	sprintf(path, EDGE_LBL_MODULE "/%x/%s", modnum, board_name);#else	sprintf(path, "%H/%s", modnum, board_name);#endif#endif}/* * Get the module number for a NASID. */moduleid_tget_module_id(nasid_t nasid)

⌨️ 快捷键说明

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