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

📄 ibmphp_ebda.c

📁 优龙2410linux2.6.8内核源代码
💻 C
📖 第 1 页 / 共 3 页
字号:
/* * IBM Hot Plug Controller Driver * * Written By: Tong Yu, IBM Corporation * * Copyright (C) 2001,2003 Greg Kroah-Hartman (greg@kroah.com) * Copyright (C) 2001-2003 IBM Corp. * * All rights reserved. * * 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. * * 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, GOOD TITLE or * NON INFRINGEMENT.  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., 675 Mass Ave, Cambridge, MA 02139, USA. * * Send feedback to <gregkh@us.ibm.com> * */#include <linux/module.h>#include <linux/sched.h>#include <linux/errno.h>#include <linux/mm.h>#include <linux/slab.h>#include <linux/pci.h>#include <linux/list.h>#include <linux/init.h>#include "ibmphp.h"/* * POST builds data blocks(in this data block definition, a char-1 * byte, short(or word)-2 byte, long(dword)-4 byte) in the Extended * BIOS Data Area which describe the configuration of the hot-plug * controllers and resources used by the PCI Hot-Plug devices. * * This file walks EBDA, maps data block from physical addr, * reconstruct linked lists about all system resource(MEM, PFM, IO) * already assigned by POST, as well as linked lists about hot plug * controllers (ctlr#, slot#, bus&slot features...) *//* Global lists */LIST_HEAD (ibmphp_ebda_pci_rsrc_head);LIST_HEAD (ibmphp_slot_head);/* Local variables */static struct ebda_hpc_list *hpc_list_ptr;static struct ebda_rsrc_list *rsrc_list_ptr;static struct rio_table_hdr *rio_table_ptr = NULL;static LIST_HEAD (ebda_hpc_head);static LIST_HEAD (bus_info_head);static LIST_HEAD (rio_vg_head);static LIST_HEAD (rio_lo_head);static LIST_HEAD (opt_vg_head);static LIST_HEAD (opt_lo_head);static void *io_mem;/* Local functions */static int ebda_rsrc_controller (void);static int ebda_rsrc_rsrc (void);static int ebda_rio_table (void);static struct ebda_hpc_list * __init alloc_ebda_hpc_list (void){	struct ebda_hpc_list *list;	list = kmalloc (sizeof (struct ebda_hpc_list), GFP_KERNEL);	if (!list)		return NULL;	memset (list, 0, sizeof (*list));	return list;}static struct controller *alloc_ebda_hpc (u32 slot_count, u32 bus_count){	struct controller *controller;	struct ebda_hpc_slot *slots;	struct ebda_hpc_bus *buses;	controller = kmalloc (sizeof (struct controller), GFP_KERNEL);	if (!controller)		goto error;	memset (controller, 0, sizeof (*controller));	slots = kmalloc (sizeof (struct ebda_hpc_slot) * slot_count, GFP_KERNEL);	if (!slots)		goto error_contr;	memset (slots, 0, sizeof (*slots) * slot_count);	controller->slots = slots;	buses = kmalloc (sizeof (struct ebda_hpc_bus) * bus_count, GFP_KERNEL);	if (!buses)		goto error_slots;	memset (buses, 0, sizeof (*buses) * bus_count);	controller->buses = buses;	return controller;error_slots:	kfree(controller->slots);error_contr:	kfree(controller);error:	return NULL;}static void free_ebda_hpc (struct controller *controller){	kfree (controller->slots);	kfree (controller->buses);	kfree (controller);}static struct ebda_rsrc_list * __init alloc_ebda_rsrc_list (void){	struct ebda_rsrc_list *list;	list = kmalloc (sizeof (struct ebda_rsrc_list), GFP_KERNEL);	if (!list)		return NULL;	memset (list, 0, sizeof (*list));	return list;}static struct ebda_pci_rsrc *alloc_ebda_pci_rsrc (void){	struct ebda_pci_rsrc *resource;	resource = kmalloc (sizeof (struct ebda_pci_rsrc), GFP_KERNEL);	if (!resource)		return NULL;	memset (resource, 0, sizeof (*resource));	return resource;}static void __init print_bus_info (void){	struct bus_info *ptr;	struct list_head *ptr1;		list_for_each (ptr1, &bus_info_head) {		ptr = list_entry (ptr1, struct bus_info, bus_info_list);		debug ("%s - slot_min = %x\n", __FUNCTION__, ptr->slot_min);		debug ("%s - slot_max = %x\n", __FUNCTION__, ptr->slot_max);		debug ("%s - slot_count = %x\n", __FUNCTION__, ptr->slot_count);		debug ("%s - bus# = %x\n", __FUNCTION__, ptr->busno);		debug ("%s - current_speed = %x\n", __FUNCTION__, ptr->current_speed);		debug ("%s - controller_id = %x\n", __FUNCTION__, ptr->controller_id);				debug ("%s - slots_at_33_conv = %x\n", __FUNCTION__, ptr->slots_at_33_conv);		debug ("%s - slots_at_66_conv = %x\n", __FUNCTION__, ptr->slots_at_66_conv);		debug ("%s - slots_at_66_pcix = %x\n", __FUNCTION__, ptr->slots_at_66_pcix);		debug ("%s - slots_at_100_pcix = %x\n", __FUNCTION__, ptr->slots_at_100_pcix);		debug ("%s - slots_at_133_pcix = %x\n", __FUNCTION__, ptr->slots_at_133_pcix);	}}static void print_lo_info (void){	struct rio_detail *ptr;	struct list_head *ptr1;	debug ("print_lo_info ----\n");		list_for_each (ptr1, &rio_lo_head) {		ptr = list_entry (ptr1, struct rio_detail, rio_detail_list);		debug ("%s - rio_node_id = %x\n", __FUNCTION__, ptr->rio_node_id);		debug ("%s - rio_type = %x\n", __FUNCTION__, ptr->rio_type);		debug ("%s - owner_id = %x\n", __FUNCTION__, ptr->owner_id);		debug ("%s - first_slot_num = %x\n", __FUNCTION__, ptr->first_slot_num);		debug ("%s - wpindex = %x\n", __FUNCTION__, ptr->wpindex);		debug ("%s - chassis_num = %x\n", __FUNCTION__, ptr->chassis_num);	}}static void print_vg_info (void){	struct rio_detail *ptr;	struct list_head *ptr1;	debug ("%s ---\n", __FUNCTION__);	list_for_each (ptr1, &rio_vg_head) {		ptr = list_entry (ptr1, struct rio_detail, rio_detail_list);		debug ("%s - rio_node_id = %x\n", __FUNCTION__, ptr->rio_node_id);		debug ("%s - rio_type = %x\n", __FUNCTION__, ptr->rio_type);		debug ("%s - owner_id = %x\n", __FUNCTION__, ptr->owner_id);		debug ("%s - first_slot_num = %x\n", __FUNCTION__, ptr->first_slot_num);		debug ("%s - wpindex = %x\n", __FUNCTION__, ptr->wpindex);		debug ("%s - chassis_num = %x\n", __FUNCTION__, ptr->chassis_num);	}}static void __init print_ebda_pci_rsrc (void){	struct ebda_pci_rsrc *ptr;	struct list_head *ptr1;	list_for_each (ptr1, &ibmphp_ebda_pci_rsrc_head) {		ptr = list_entry (ptr1, struct ebda_pci_rsrc, ebda_pci_rsrc_list);		debug ("%s - rsrc type: %x bus#: %x dev_func: %x start addr: %x end addr: %x\n", 			__FUNCTION__, ptr->rsrc_type ,ptr->bus_num, ptr->dev_fun,ptr->start_addr, ptr->end_addr);	}}static void __init print_ibm_slot (void){	struct slot *ptr;	struct list_head *ptr1;	list_for_each (ptr1, &ibmphp_slot_head) {		ptr = list_entry (ptr1, struct slot, ibm_slot_list);		debug ("%s - slot_number: %x\n", __FUNCTION__, ptr->number); 	}}static void __init print_opt_vg (void){	struct opt_rio *ptr;	struct list_head *ptr1;	debug ("%s ---\n", __FUNCTION__);	list_for_each (ptr1, &opt_vg_head) {		ptr = list_entry (ptr1, struct opt_rio, opt_rio_list);		debug ("%s - rio_type %x\n", __FUNCTION__, ptr->rio_type); 		debug ("%s - chassis_num: %x\n", __FUNCTION__, ptr->chassis_num); 		debug ("%s - first_slot_num: %x\n", __FUNCTION__, ptr->first_slot_num); 		debug ("%s - middle_num: %x\n", __FUNCTION__, ptr->middle_num); 	}}static void __init print_ebda_hpc (void){	struct controller *hpc_ptr;	struct list_head *ptr1;	u16 index;	list_for_each (ptr1, &ebda_hpc_head) {		hpc_ptr = list_entry (ptr1, struct controller, ebda_hpc_list); 		for (index = 0; index < hpc_ptr->slot_count; index++) {			debug ("%s - physical slot#: %x\n", __FUNCTION__, hpc_ptr->slots[index].slot_num);			debug ("%s - pci bus# of the slot: %x\n", __FUNCTION__, hpc_ptr->slots[index].slot_bus_num);			debug ("%s - index into ctlr addr: %x\n", __FUNCTION__, hpc_ptr->slots[index].ctl_index);			debug ("%s - cap of the slot: %x\n", __FUNCTION__, hpc_ptr->slots[index].slot_cap);		}		for (index = 0; index < hpc_ptr->bus_count; index++) {			debug ("%s - bus# of each bus controlled by this ctlr: %x\n", __FUNCTION__, hpc_ptr->buses[index].bus_num);		}		debug ("%s - type of hpc: %x\n", __FUNCTION__, hpc_ptr->ctlr_type);		switch (hpc_ptr->ctlr_type) {		case 1:			debug ("%s - bus: %x\n", __FUNCTION__, hpc_ptr->u.pci_ctlr.bus);			debug ("%s - dev_fun: %x\n", __FUNCTION__, hpc_ptr->u.pci_ctlr.dev_fun);			debug ("%s - irq: %x\n", __FUNCTION__, hpc_ptr->irq);			break;		case 0:			debug ("%s - io_start: %x\n", __FUNCTION__, hpc_ptr->u.isa_ctlr.io_start);			debug ("%s - io_end: %x\n", __FUNCTION__, hpc_ptr->u.isa_ctlr.io_end);			debug ("%s - irq: %x\n", __FUNCTION__, hpc_ptr->irq);			break;		case 2:		case 4:			debug ("%s - wpegbbar: %lx\n", __FUNCTION__, hpc_ptr->u.wpeg_ctlr.wpegbbar);			debug ("%s - i2c_addr: %x\n", __FUNCTION__, hpc_ptr->u.wpeg_ctlr.i2c_addr);			debug ("%s - irq: %x\n", __FUNCTION__, hpc_ptr->irq);			break;		}	}}int __init ibmphp_access_ebda (void){	u8 format, num_ctlrs, rio_complete, hs_complete;	u16 ebda_seg, num_entries, next_offset, offset, blk_id, sub_addr, re, rc_id, re_id, base;	int rc = 0;	rio_complete = 0;	hs_complete = 0;	io_mem = ioremap ((0x40 << 4) + 0x0e, 2);	if (!io_mem )		return -ENOMEM;	ebda_seg = readw (io_mem);	iounmap (io_mem);	debug ("returned ebda segment: %x\n", ebda_seg);		io_mem = ioremap (ebda_seg<<4, 65000);	if (!io_mem )		return -ENOMEM;	next_offset = 0x180;	for (;;) {		offset = next_offset;		next_offset = readw (io_mem + offset);	/* offset of next blk */		offset += 2;		if (next_offset == 0)	/* 0 indicate it's last blk */			break;		blk_id = readw (io_mem + offset);	/* this blk id */		offset += 2;		/* check if it is hot swap block or rio block */		if (blk_id != 0x4853 && blk_id != 0x4752)			continue;		/* found hs table */		if (blk_id == 0x4853) {			debug ("now enter hot swap block---\n");			debug ("hot blk id: %x\n", blk_id);			format = readb (io_mem + offset);			offset += 1;			if (format != 4)				goto error_nodev;			debug ("hot blk format: %x\n", format);			/* hot swap sub blk */			base = offset;			sub_addr = base;			re = readw (io_mem + sub_addr);	/* next sub blk */			sub_addr += 2;			rc_id = readw (io_mem + sub_addr); 	/* sub blk id */			sub_addr += 2;			if (rc_id != 0x5243)				goto error_nodev;			/* rc sub blk signature  */			num_ctlrs = readb (io_mem + sub_addr);			sub_addr += 1;			hpc_list_ptr = alloc_ebda_hpc_list ();			if (!hpc_list_ptr) {				rc = -ENOMEM;				goto out;			}			hpc_list_ptr->format = format;			hpc_list_ptr->num_ctlrs = num_ctlrs;			hpc_list_ptr->phys_addr = sub_addr;	/*  offset of RSRC_CONTROLLER blk */			debug ("info about hpc descriptor---\n");			debug ("hot blk format: %x\n", format);			debug ("num of controller: %x\n", num_ctlrs);			debug ("offset of hpc data structure enteries: %x\n ", sub_addr);			sub_addr = base + re;	/* re sub blk */			/* FIXME: rc is never used/checked */			rc = readw (io_mem + sub_addr);	/* next sub blk */			sub_addr += 2;			re_id = readw (io_mem + sub_addr);	/* sub blk id */			sub_addr += 2;			if (re_id != 0x5245)				goto error_nodev;			/* signature of re */			num_entries = readw (io_mem + sub_addr);			sub_addr += 2;	/* offset of RSRC_ENTRIES blk */			rsrc_list_ptr = alloc_ebda_rsrc_list ();			if (!rsrc_list_ptr ) {				rc = -ENOMEM;				goto out;			}			rsrc_list_ptr->format = format;			rsrc_list_ptr->num_entries = num_entries;			rsrc_list_ptr->phys_addr = sub_addr;			debug ("info about rsrc descriptor---\n");			debug ("format: %x\n", format);			debug ("num of rsrc: %x\n", num_entries);			debug ("offset of rsrc data structure enteries: %x\n ", sub_addr);			hs_complete = 1;		} else {		/* found rio table, blk_id == 0x4752 */			debug ("now enter io table ---\n");			debug ("rio blk id: %x\n", blk_id);			rio_table_ptr = kmalloc (sizeof (struct rio_table_hdr), GFP_KERNEL);			if (!rio_table_ptr)				return -ENOMEM; 			memset (rio_table_ptr, 0, sizeof (struct rio_table_hdr) );			rio_table_ptr->ver_num = readb (io_mem + offset);			rio_table_ptr->scal_count = readb (io_mem + offset + 1);			rio_table_ptr->riodev_count = readb (io_mem + offset + 2);			rio_table_ptr->offset = offset +3 ;						debug("info about rio table hdr ---\n");			debug("ver_num: %x\nscal_count: %x\nriodev_count: %x\noffset of rio table: %x\n ",				rio_table_ptr->ver_num, rio_table_ptr->scal_count,				rio_table_ptr->riodev_count, rio_table_ptr->offset);			rio_complete = 1;		}	}	if (!hs_complete && !rio_complete)		goto error_nodev;	if (rio_table_ptr) {		if (rio_complete && rio_table_ptr->ver_num == 3) {			rc = ebda_rio_table ();			if (rc)				goto out;		}	}	rc = ebda_rsrc_controller ();	if (rc)		goto out;	rc = ebda_rsrc_rsrc ();	goto out;

⌨️ 快捷键说明

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