11da177e4SLinus Torvalds /* 21da177e4SLinus Torvalds * IBM Hot Plug Controller Driver 31da177e4SLinus Torvalds * 41da177e4SLinus Torvalds * Written By: Tong Yu, IBM Corporation 51da177e4SLinus Torvalds * 61da177e4SLinus Torvalds * Copyright (C) 2001,2003 Greg Kroah-Hartman (greg@kroah.com) 71da177e4SLinus Torvalds * Copyright (C) 2001-2003 IBM Corp. 81da177e4SLinus Torvalds * 91da177e4SLinus Torvalds * All rights reserved. 101da177e4SLinus Torvalds * 111da177e4SLinus Torvalds * This program is free software; you can redistribute it and/or modify 121da177e4SLinus Torvalds * it under the terms of the GNU General Public License as published by 131da177e4SLinus Torvalds * the Free Software Foundation; either version 2 of the License, or (at 141da177e4SLinus Torvalds * your option) any later version. 151da177e4SLinus Torvalds * 161da177e4SLinus Torvalds * This program is distributed in the hope that it will be useful, but 171da177e4SLinus Torvalds * WITHOUT ANY WARRANTY; without even the implied warranty of 181da177e4SLinus Torvalds * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or 191da177e4SLinus Torvalds * NON INFRINGEMENT. See the GNU General Public License for more 201da177e4SLinus Torvalds * details. 211da177e4SLinus Torvalds * 221da177e4SLinus Torvalds * You should have received a copy of the GNU General Public License 231da177e4SLinus Torvalds * along with this program; if not, write to the Free Software 241da177e4SLinus Torvalds * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 251da177e4SLinus Torvalds * 261da177e4SLinus Torvalds * Send feedback to <gregkh@us.ibm.com> 271da177e4SLinus Torvalds * 281da177e4SLinus Torvalds */ 291da177e4SLinus Torvalds 301da177e4SLinus Torvalds #include <linux/module.h> 311da177e4SLinus Torvalds #include <linux/errno.h> 321da177e4SLinus Torvalds #include <linux/mm.h> 331da177e4SLinus Torvalds #include <linux/slab.h> 341da177e4SLinus Torvalds #include <linux/pci.h> 351da177e4SLinus Torvalds #include <linux/list.h> 361da177e4SLinus Torvalds #include <linux/init.h> 371da177e4SLinus Torvalds #include "ibmphp.h" 381da177e4SLinus Torvalds 391da177e4SLinus Torvalds /* 401da177e4SLinus Torvalds * POST builds data blocks(in this data block definition, a char-1 411da177e4SLinus Torvalds * byte, short(or word)-2 byte, long(dword)-4 byte) in the Extended 421da177e4SLinus Torvalds * BIOS Data Area which describe the configuration of the hot-plug 431da177e4SLinus Torvalds * controllers and resources used by the PCI Hot-Plug devices. 441da177e4SLinus Torvalds * 451da177e4SLinus Torvalds * This file walks EBDA, maps data block from physical addr, 461da177e4SLinus Torvalds * reconstruct linked lists about all system resource(MEM, PFM, IO) 471da177e4SLinus Torvalds * already assigned by POST, as well as linked lists about hot plug 481da177e4SLinus Torvalds * controllers (ctlr#, slot#, bus&slot features...) 491da177e4SLinus Torvalds */ 501da177e4SLinus Torvalds 511da177e4SLinus Torvalds /* Global lists */ 521da177e4SLinus Torvalds LIST_HEAD(ibmphp_ebda_pci_rsrc_head); 531da177e4SLinus Torvalds LIST_HEAD(ibmphp_slot_head); 541da177e4SLinus Torvalds 551da177e4SLinus Torvalds /* Local variables */ 561da177e4SLinus Torvalds static struct ebda_hpc_list *hpc_list_ptr; 571da177e4SLinus Torvalds static struct ebda_rsrc_list *rsrc_list_ptr; 581da177e4SLinus Torvalds static struct rio_table_hdr *rio_table_ptr = NULL; 591da177e4SLinus Torvalds static LIST_HEAD(ebda_hpc_head); 601da177e4SLinus Torvalds static LIST_HEAD(bus_info_head); 611da177e4SLinus Torvalds static LIST_HEAD(rio_vg_head); 621da177e4SLinus Torvalds static LIST_HEAD(rio_lo_head); 631da177e4SLinus Torvalds static LIST_HEAD(opt_vg_head); 641da177e4SLinus Torvalds static LIST_HEAD(opt_lo_head); 651da177e4SLinus Torvalds static void __iomem *io_mem; 661da177e4SLinus Torvalds 671da177e4SLinus Torvalds /* Local functions */ 681da177e4SLinus Torvalds static int ebda_rsrc_controller(void); 691da177e4SLinus Torvalds static int ebda_rsrc_rsrc(void); 701da177e4SLinus Torvalds static int ebda_rio_table(void); 711da177e4SLinus Torvalds 721da177e4SLinus Torvalds static struct ebda_hpc_list * __init alloc_ebda_hpc_list(void) 731da177e4SLinus Torvalds { 74f5afe806SEric Sesterhenn return kzalloc(sizeof(struct ebda_hpc_list), GFP_KERNEL); 751da177e4SLinus Torvalds } 761da177e4SLinus Torvalds 771da177e4SLinus Torvalds static struct controller *alloc_ebda_hpc(u32 slot_count, u32 bus_count) 781da177e4SLinus Torvalds { 791da177e4SLinus Torvalds struct controller *controller; 801da177e4SLinus Torvalds struct ebda_hpc_slot *slots; 811da177e4SLinus Torvalds struct ebda_hpc_bus *buses; 821da177e4SLinus Torvalds 83f5afe806SEric Sesterhenn controller = kzalloc(sizeof(struct controller), GFP_KERNEL); 841da177e4SLinus Torvalds if (!controller) 851da177e4SLinus Torvalds goto error; 861da177e4SLinus Torvalds 87f5afe806SEric Sesterhenn slots = kcalloc(slot_count, sizeof(struct ebda_hpc_slot), GFP_KERNEL); 881da177e4SLinus Torvalds if (!slots) 891da177e4SLinus Torvalds goto error_contr; 901da177e4SLinus Torvalds controller->slots = slots; 911da177e4SLinus Torvalds 92f5afe806SEric Sesterhenn buses = kcalloc(bus_count, sizeof(struct ebda_hpc_bus), GFP_KERNEL); 931da177e4SLinus Torvalds if (!buses) 941da177e4SLinus Torvalds goto error_slots; 951da177e4SLinus Torvalds controller->buses = buses; 961da177e4SLinus Torvalds 971da177e4SLinus Torvalds return controller; 981da177e4SLinus Torvalds error_slots: 991da177e4SLinus Torvalds kfree(controller->slots); 1001da177e4SLinus Torvalds error_contr: 1011da177e4SLinus Torvalds kfree(controller); 1021da177e4SLinus Torvalds error: 1031da177e4SLinus Torvalds return NULL; 1041da177e4SLinus Torvalds } 1051da177e4SLinus Torvalds 1061da177e4SLinus Torvalds static void free_ebda_hpc(struct controller *controller) 1071da177e4SLinus Torvalds { 1081da177e4SLinus Torvalds kfree(controller->slots); 1091da177e4SLinus Torvalds kfree(controller->buses); 1101da177e4SLinus Torvalds kfree(controller); 1111da177e4SLinus Torvalds } 1121da177e4SLinus Torvalds 1131da177e4SLinus Torvalds static struct ebda_rsrc_list * __init alloc_ebda_rsrc_list(void) 1141da177e4SLinus Torvalds { 115f5afe806SEric Sesterhenn return kzalloc(sizeof(struct ebda_rsrc_list), GFP_KERNEL); 1161da177e4SLinus Torvalds } 1171da177e4SLinus Torvalds 1181da177e4SLinus Torvalds static struct ebda_pci_rsrc *alloc_ebda_pci_rsrc(void) 1191da177e4SLinus Torvalds { 120f5afe806SEric Sesterhenn return kzalloc(sizeof(struct ebda_pci_rsrc), GFP_KERNEL); 1211da177e4SLinus Torvalds } 1221da177e4SLinus Torvalds 1231da177e4SLinus Torvalds static void __init print_bus_info(void) 1241da177e4SLinus Torvalds { 1251da177e4SLinus Torvalds struct bus_info *ptr; 1261da177e4SLinus Torvalds 127a8d2dbd3Sakpm@linux-foundation.org list_for_each_entry(ptr, &bus_info_head, bus_info_list) { 12866bef8c0SHarvey Harrison debug("%s - slot_min = %x\n", __func__, ptr->slot_min); 12966bef8c0SHarvey Harrison debug("%s - slot_max = %x\n", __func__, ptr->slot_max); 13066bef8c0SHarvey Harrison debug("%s - slot_count = %x\n", __func__, ptr->slot_count); 13166bef8c0SHarvey Harrison debug("%s - bus# = %x\n", __func__, ptr->busno); 13266bef8c0SHarvey Harrison debug("%s - current_speed = %x\n", __func__, ptr->current_speed); 13366bef8c0SHarvey Harrison debug("%s - controller_id = %x\n", __func__, ptr->controller_id); 1341da177e4SLinus Torvalds 13566bef8c0SHarvey Harrison debug("%s - slots_at_33_conv = %x\n", __func__, ptr->slots_at_33_conv); 13666bef8c0SHarvey Harrison debug("%s - slots_at_66_conv = %x\n", __func__, ptr->slots_at_66_conv); 13766bef8c0SHarvey Harrison debug("%s - slots_at_66_pcix = %x\n", __func__, ptr->slots_at_66_pcix); 13866bef8c0SHarvey Harrison debug("%s - slots_at_100_pcix = %x\n", __func__, ptr->slots_at_100_pcix); 13966bef8c0SHarvey Harrison debug("%s - slots_at_133_pcix = %x\n", __func__, ptr->slots_at_133_pcix); 1401da177e4SLinus Torvalds 1411da177e4SLinus Torvalds } 1421da177e4SLinus Torvalds } 1431da177e4SLinus Torvalds 1441da177e4SLinus Torvalds static void print_lo_info(void) 1451da177e4SLinus Torvalds { 1461da177e4SLinus Torvalds struct rio_detail *ptr; 1471da177e4SLinus Torvalds debug("print_lo_info ----\n"); 148a8d2dbd3Sakpm@linux-foundation.org list_for_each_entry(ptr, &rio_lo_head, rio_detail_list) { 14966bef8c0SHarvey Harrison debug("%s - rio_node_id = %x\n", __func__, ptr->rio_node_id); 15066bef8c0SHarvey Harrison debug("%s - rio_type = %x\n", __func__, ptr->rio_type); 15166bef8c0SHarvey Harrison debug("%s - owner_id = %x\n", __func__, ptr->owner_id); 15266bef8c0SHarvey Harrison debug("%s - first_slot_num = %x\n", __func__, ptr->first_slot_num); 15366bef8c0SHarvey Harrison debug("%s - wpindex = %x\n", __func__, ptr->wpindex); 15466bef8c0SHarvey Harrison debug("%s - chassis_num = %x\n", __func__, ptr->chassis_num); 1551da177e4SLinus Torvalds 1561da177e4SLinus Torvalds } 1571da177e4SLinus Torvalds } 1581da177e4SLinus Torvalds 1591da177e4SLinus Torvalds static void print_vg_info(void) 1601da177e4SLinus Torvalds { 1611da177e4SLinus Torvalds struct rio_detail *ptr; 16266bef8c0SHarvey Harrison debug("%s ---\n", __func__); 163a8d2dbd3Sakpm@linux-foundation.org list_for_each_entry(ptr, &rio_vg_head, rio_detail_list) { 16466bef8c0SHarvey Harrison debug("%s - rio_node_id = %x\n", __func__, ptr->rio_node_id); 16566bef8c0SHarvey Harrison debug("%s - rio_type = %x\n", __func__, ptr->rio_type); 16666bef8c0SHarvey Harrison debug("%s - owner_id = %x\n", __func__, ptr->owner_id); 16766bef8c0SHarvey Harrison debug("%s - first_slot_num = %x\n", __func__, ptr->first_slot_num); 16866bef8c0SHarvey Harrison debug("%s - wpindex = %x\n", __func__, ptr->wpindex); 16966bef8c0SHarvey Harrison debug("%s - chassis_num = %x\n", __func__, ptr->chassis_num); 1701da177e4SLinus Torvalds 1711da177e4SLinus Torvalds } 1721da177e4SLinus Torvalds } 1731da177e4SLinus Torvalds 1741da177e4SLinus Torvalds static void __init print_ebda_pci_rsrc(void) 1751da177e4SLinus Torvalds { 1761da177e4SLinus Torvalds struct ebda_pci_rsrc *ptr; 1771da177e4SLinus Torvalds 178a8d2dbd3Sakpm@linux-foundation.org list_for_each_entry(ptr, &ibmphp_ebda_pci_rsrc_head, ebda_pci_rsrc_list) { 1791da177e4SLinus Torvalds debug("%s - rsrc type: %x bus#: %x dev_func: %x start addr: %x end addr: %x\n", 18066bef8c0SHarvey Harrison __func__, ptr->rsrc_type, ptr->bus_num, ptr->dev_fun, ptr->start_addr, ptr->end_addr); 1811da177e4SLinus Torvalds } 1821da177e4SLinus Torvalds } 1831da177e4SLinus Torvalds 1841da177e4SLinus Torvalds static void __init print_ibm_slot(void) 1851da177e4SLinus Torvalds { 1861da177e4SLinus Torvalds struct slot *ptr; 1871da177e4SLinus Torvalds 188a8d2dbd3Sakpm@linux-foundation.org list_for_each_entry(ptr, &ibmphp_slot_head, ibm_slot_list) { 18966bef8c0SHarvey Harrison debug("%s - slot_number: %x\n", __func__, ptr->number); 1901da177e4SLinus Torvalds } 1911da177e4SLinus Torvalds } 1921da177e4SLinus Torvalds 1931da177e4SLinus Torvalds static void __init print_opt_vg(void) 1941da177e4SLinus Torvalds { 1951da177e4SLinus Torvalds struct opt_rio *ptr; 19666bef8c0SHarvey Harrison debug("%s ---\n", __func__); 197a8d2dbd3Sakpm@linux-foundation.org list_for_each_entry(ptr, &opt_vg_head, opt_rio_list) { 19866bef8c0SHarvey Harrison debug("%s - rio_type %x\n", __func__, ptr->rio_type); 19966bef8c0SHarvey Harrison debug("%s - chassis_num: %x\n", __func__, ptr->chassis_num); 20066bef8c0SHarvey Harrison debug("%s - first_slot_num: %x\n", __func__, ptr->first_slot_num); 20166bef8c0SHarvey Harrison debug("%s - middle_num: %x\n", __func__, ptr->middle_num); 2021da177e4SLinus Torvalds } 2031da177e4SLinus Torvalds } 2041da177e4SLinus Torvalds 2051da177e4SLinus Torvalds static void __init print_ebda_hpc(void) 2061da177e4SLinus Torvalds { 2071da177e4SLinus Torvalds struct controller *hpc_ptr; 2081da177e4SLinus Torvalds u16 index; 2091da177e4SLinus Torvalds 210a8d2dbd3Sakpm@linux-foundation.org list_for_each_entry(hpc_ptr, &ebda_hpc_head, ebda_hpc_list) { 2111da177e4SLinus Torvalds for (index = 0; index < hpc_ptr->slot_count; index++) { 21266bef8c0SHarvey Harrison debug("%s - physical slot#: %x\n", __func__, hpc_ptr->slots[index].slot_num); 21366bef8c0SHarvey Harrison debug("%s - pci bus# of the slot: %x\n", __func__, hpc_ptr->slots[index].slot_bus_num); 21466bef8c0SHarvey Harrison debug("%s - index into ctlr addr: %x\n", __func__, hpc_ptr->slots[index].ctl_index); 21566bef8c0SHarvey Harrison debug("%s - cap of the slot: %x\n", __func__, hpc_ptr->slots[index].slot_cap); 2161da177e4SLinus Torvalds } 2171da177e4SLinus Torvalds 218656f978fSQuentin Lambert for (index = 0; index < hpc_ptr->bus_count; index++) 21966bef8c0SHarvey Harrison debug("%s - bus# of each bus controlled by this ctlr: %x\n", __func__, hpc_ptr->buses[index].bus_num); 2201da177e4SLinus Torvalds 22166bef8c0SHarvey Harrison debug("%s - type of hpc: %x\n", __func__, hpc_ptr->ctlr_type); 2221da177e4SLinus Torvalds switch (hpc_ptr->ctlr_type) { 2231da177e4SLinus Torvalds case 1: 22466bef8c0SHarvey Harrison debug("%s - bus: %x\n", __func__, hpc_ptr->u.pci_ctlr.bus); 22566bef8c0SHarvey Harrison debug("%s - dev_fun: %x\n", __func__, hpc_ptr->u.pci_ctlr.dev_fun); 22666bef8c0SHarvey Harrison debug("%s - irq: %x\n", __func__, hpc_ptr->irq); 2271da177e4SLinus Torvalds break; 2281da177e4SLinus Torvalds 2291da177e4SLinus Torvalds case 0: 23066bef8c0SHarvey Harrison debug("%s - io_start: %x\n", __func__, hpc_ptr->u.isa_ctlr.io_start); 23166bef8c0SHarvey Harrison debug("%s - io_end: %x\n", __func__, hpc_ptr->u.isa_ctlr.io_end); 23266bef8c0SHarvey Harrison debug("%s - irq: %x\n", __func__, hpc_ptr->irq); 2331da177e4SLinus Torvalds break; 2341da177e4SLinus Torvalds 2351da177e4SLinus Torvalds case 2: 2361da177e4SLinus Torvalds case 4: 23766bef8c0SHarvey Harrison debug("%s - wpegbbar: %lx\n", __func__, hpc_ptr->u.wpeg_ctlr.wpegbbar); 23866bef8c0SHarvey Harrison debug("%s - i2c_addr: %x\n", __func__, hpc_ptr->u.wpeg_ctlr.i2c_addr); 23966bef8c0SHarvey Harrison debug("%s - irq: %x\n", __func__, hpc_ptr->irq); 2401da177e4SLinus Torvalds break; 2411da177e4SLinus Torvalds } 2421da177e4SLinus Torvalds } 2431da177e4SLinus Torvalds } 2441da177e4SLinus Torvalds 2451da177e4SLinus Torvalds int __init ibmphp_access_ebda(void) 2461da177e4SLinus Torvalds { 247b0fc889cSChandru u8 format, num_ctlrs, rio_complete, hs_complete, ebda_sz; 2481da177e4SLinus Torvalds u16 ebda_seg, num_entries, next_offset, offset, blk_id, sub_addr, re, rc_id, re_id, base; 2491da177e4SLinus Torvalds int rc = 0; 2501da177e4SLinus Torvalds 2511da177e4SLinus Torvalds 2521da177e4SLinus Torvalds rio_complete = 0; 2531da177e4SLinus Torvalds hs_complete = 0; 2541da177e4SLinus Torvalds 2551da177e4SLinus Torvalds io_mem = ioremap((0x40 << 4) + 0x0e, 2); 2561da177e4SLinus Torvalds if (!io_mem) 2571da177e4SLinus Torvalds return -ENOMEM; 2581da177e4SLinus Torvalds ebda_seg = readw(io_mem); 2591da177e4SLinus Torvalds iounmap(io_mem); 2601da177e4SLinus Torvalds debug("returned ebda segment: %x\n", ebda_seg); 2611da177e4SLinus Torvalds 262b0fc889cSChandru io_mem = ioremap(ebda_seg<<4, 1); 263ba02b242SAndrew Morton if (!io_mem) 264ba02b242SAndrew Morton return -ENOMEM; 265b0fc889cSChandru ebda_sz = readb(io_mem); 266b0fc889cSChandru iounmap(io_mem); 267b0fc889cSChandru debug("ebda size: %d(KiB)\n", ebda_sz); 268b0fc889cSChandru if (ebda_sz == 0) 269b0fc889cSChandru return -ENOMEM; 270b0fc889cSChandru 271b0fc889cSChandru io_mem = ioremap(ebda_seg<<4, (ebda_sz * 1024)); 2721da177e4SLinus Torvalds if (!io_mem) 2731da177e4SLinus Torvalds return -ENOMEM; 2741da177e4SLinus Torvalds next_offset = 0x180; 2751da177e4SLinus Torvalds 2761da177e4SLinus Torvalds for (;;) { 2771da177e4SLinus Torvalds offset = next_offset; 278ac3abf2cSSteven Rostedt 279ac3abf2cSSteven Rostedt /* Make sure what we read is still in the mapped section */ 280ac3abf2cSSteven Rostedt if (WARN(offset > (ebda_sz * 1024 - 4), 281ac3abf2cSSteven Rostedt "ibmphp_ebda: next read is beyond ebda_sz\n")) 282ac3abf2cSSteven Rostedt break; 283ac3abf2cSSteven Rostedt 2841da177e4SLinus Torvalds next_offset = readw(io_mem + offset); /* offset of next blk */ 2851da177e4SLinus Torvalds 2861da177e4SLinus Torvalds offset += 2; 2871da177e4SLinus Torvalds if (next_offset == 0) /* 0 indicate it's last blk */ 2881da177e4SLinus Torvalds break; 2891da177e4SLinus Torvalds blk_id = readw(io_mem + offset); /* this blk id */ 2901da177e4SLinus Torvalds 2911da177e4SLinus Torvalds offset += 2; 2921da177e4SLinus Torvalds /* check if it is hot swap block or rio block */ 2931da177e4SLinus Torvalds if (blk_id != 0x4853 && blk_id != 0x4752) 2941da177e4SLinus Torvalds continue; 2951da177e4SLinus Torvalds /* found hs table */ 2961da177e4SLinus Torvalds if (blk_id == 0x4853) { 2971da177e4SLinus Torvalds debug("now enter hot swap block---\n"); 2981da177e4SLinus Torvalds debug("hot blk id: %x\n", blk_id); 2991da177e4SLinus Torvalds format = readb(io_mem + offset); 3001da177e4SLinus Torvalds 3011da177e4SLinus Torvalds offset += 1; 3021da177e4SLinus Torvalds if (format != 4) 3031da177e4SLinus Torvalds goto error_nodev; 3041da177e4SLinus Torvalds debug("hot blk format: %x\n", format); 3051da177e4SLinus Torvalds /* hot swap sub blk */ 3061da177e4SLinus Torvalds base = offset; 3071da177e4SLinus Torvalds 3081da177e4SLinus Torvalds sub_addr = base; 3091da177e4SLinus Torvalds re = readw(io_mem + sub_addr); /* next sub blk */ 3101da177e4SLinus Torvalds 3111da177e4SLinus Torvalds sub_addr += 2; 3121da177e4SLinus Torvalds rc_id = readw(io_mem + sub_addr); /* sub blk id */ 3131da177e4SLinus Torvalds 3141da177e4SLinus Torvalds sub_addr += 2; 3151da177e4SLinus Torvalds if (rc_id != 0x5243) 3161da177e4SLinus Torvalds goto error_nodev; 3171da177e4SLinus Torvalds /* rc sub blk signature */ 3181da177e4SLinus Torvalds num_ctlrs = readb(io_mem + sub_addr); 3191da177e4SLinus Torvalds 3201da177e4SLinus Torvalds sub_addr += 1; 3211da177e4SLinus Torvalds hpc_list_ptr = alloc_ebda_hpc_list(); 3221da177e4SLinus Torvalds if (!hpc_list_ptr) { 3231da177e4SLinus Torvalds rc = -ENOMEM; 3241da177e4SLinus Torvalds goto out; 3251da177e4SLinus Torvalds } 3261da177e4SLinus Torvalds hpc_list_ptr->format = format; 3271da177e4SLinus Torvalds hpc_list_ptr->num_ctlrs = num_ctlrs; 3281da177e4SLinus Torvalds hpc_list_ptr->phys_addr = sub_addr; /* offset of RSRC_CONTROLLER blk */ 3291da177e4SLinus Torvalds debug("info about hpc descriptor---\n"); 3301da177e4SLinus Torvalds debug("hot blk format: %x\n", format); 3311da177e4SLinus Torvalds debug("num of controller: %x\n", num_ctlrs); 332f7625980SBjorn Helgaas debug("offset of hpc data structure entries: %x\n ", sub_addr); 3331da177e4SLinus Torvalds 3341da177e4SLinus Torvalds sub_addr = base + re; /* re sub blk */ 3351da177e4SLinus Torvalds /* FIXME: rc is never used/checked */ 3361da177e4SLinus Torvalds rc = readw(io_mem + sub_addr); /* next sub blk */ 3371da177e4SLinus Torvalds 3381da177e4SLinus Torvalds sub_addr += 2; 3391da177e4SLinus Torvalds re_id = readw(io_mem + sub_addr); /* sub blk id */ 3401da177e4SLinus Torvalds 3411da177e4SLinus Torvalds sub_addr += 2; 3421da177e4SLinus Torvalds if (re_id != 0x5245) 3431da177e4SLinus Torvalds goto error_nodev; 3441da177e4SLinus Torvalds 3451da177e4SLinus Torvalds /* signature of re */ 3461da177e4SLinus Torvalds num_entries = readw(io_mem + sub_addr); 3471da177e4SLinus Torvalds 3481da177e4SLinus Torvalds sub_addr += 2; /* offset of RSRC_ENTRIES blk */ 3491da177e4SLinus Torvalds rsrc_list_ptr = alloc_ebda_rsrc_list(); 3501da177e4SLinus Torvalds if (!rsrc_list_ptr) { 3511da177e4SLinus Torvalds rc = -ENOMEM; 3521da177e4SLinus Torvalds goto out; 3531da177e4SLinus Torvalds } 3541da177e4SLinus Torvalds rsrc_list_ptr->format = format; 3551da177e4SLinus Torvalds rsrc_list_ptr->num_entries = num_entries; 3561da177e4SLinus Torvalds rsrc_list_ptr->phys_addr = sub_addr; 3571da177e4SLinus Torvalds 3581da177e4SLinus Torvalds debug("info about rsrc descriptor---\n"); 3591da177e4SLinus Torvalds debug("format: %x\n", format); 3601da177e4SLinus Torvalds debug("num of rsrc: %x\n", num_entries); 361f7625980SBjorn Helgaas debug("offset of rsrc data structure entries: %x\n ", sub_addr); 3621da177e4SLinus Torvalds 3631da177e4SLinus Torvalds hs_complete = 1; 3641da177e4SLinus Torvalds } else { 3651da177e4SLinus Torvalds /* found rio table, blk_id == 0x4752 */ 3661da177e4SLinus Torvalds debug("now enter io table ---\n"); 3671da177e4SLinus Torvalds debug("rio blk id: %x\n", blk_id); 3681da177e4SLinus Torvalds 369f5afe806SEric Sesterhenn rio_table_ptr = kzalloc(sizeof(struct rio_table_hdr), GFP_KERNEL); 3708f0cdddcSJulia Lawall if (!rio_table_ptr) { 3718f0cdddcSJulia Lawall rc = -ENOMEM; 3728f0cdddcSJulia Lawall goto out; 3738f0cdddcSJulia Lawall } 3741da177e4SLinus Torvalds rio_table_ptr->ver_num = readb(io_mem + offset); 3751da177e4SLinus Torvalds rio_table_ptr->scal_count = readb(io_mem + offset + 1); 3761da177e4SLinus Torvalds rio_table_ptr->riodev_count = readb(io_mem + offset + 2); 3771da177e4SLinus Torvalds rio_table_ptr->offset = offset + 3 ; 3781da177e4SLinus Torvalds 3791da177e4SLinus Torvalds debug("info about rio table hdr ---\n"); 3801da177e4SLinus Torvalds debug("ver_num: %x\nscal_count: %x\nriodev_count: %x\noffset of rio table: %x\n ", 3811da177e4SLinus Torvalds rio_table_ptr->ver_num, rio_table_ptr->scal_count, 3821da177e4SLinus Torvalds rio_table_ptr->riodev_count, rio_table_ptr->offset); 3831da177e4SLinus Torvalds 3841da177e4SLinus Torvalds rio_complete = 1; 3851da177e4SLinus Torvalds } 3861da177e4SLinus Torvalds } 3871da177e4SLinus Torvalds 3881da177e4SLinus Torvalds if (!hs_complete && !rio_complete) 3891da177e4SLinus Torvalds goto error_nodev; 3901da177e4SLinus Torvalds 3911da177e4SLinus Torvalds if (rio_table_ptr) { 3921da177e4SLinus Torvalds if (rio_complete && rio_table_ptr->ver_num == 3) { 3931da177e4SLinus Torvalds rc = ebda_rio_table(); 3941da177e4SLinus Torvalds if (rc) 3951da177e4SLinus Torvalds goto out; 3961da177e4SLinus Torvalds } 3971da177e4SLinus Torvalds } 3981da177e4SLinus Torvalds rc = ebda_rsrc_controller(); 3991da177e4SLinus Torvalds if (rc) 4001da177e4SLinus Torvalds goto out; 4011da177e4SLinus Torvalds 4021da177e4SLinus Torvalds rc = ebda_rsrc_rsrc(); 4031da177e4SLinus Torvalds goto out; 4041da177e4SLinus Torvalds error_nodev: 4051da177e4SLinus Torvalds rc = -ENODEV; 4061da177e4SLinus Torvalds out: 4071da177e4SLinus Torvalds iounmap(io_mem); 4081da177e4SLinus Torvalds return rc; 4091da177e4SLinus Torvalds } 4101da177e4SLinus Torvalds 4111da177e4SLinus Torvalds /* 4121da177e4SLinus Torvalds * map info of scalability details and rio details from physical address 4131da177e4SLinus Torvalds */ 4141da177e4SLinus Torvalds static int __init ebda_rio_table(void) 4151da177e4SLinus Torvalds { 4161da177e4SLinus Torvalds u16 offset; 4171da177e4SLinus Torvalds u8 i; 4181da177e4SLinus Torvalds struct rio_detail *rio_detail_ptr; 4191da177e4SLinus Torvalds 4201da177e4SLinus Torvalds offset = rio_table_ptr->offset; 4211da177e4SLinus Torvalds offset += 12 * rio_table_ptr->scal_count; 4221da177e4SLinus Torvalds 4231da177e4SLinus Torvalds // we do concern about rio details 4241da177e4SLinus Torvalds for (i = 0; i < rio_table_ptr->riodev_count; i++) { 425f5afe806SEric Sesterhenn rio_detail_ptr = kzalloc(sizeof(struct rio_detail), GFP_KERNEL); 4261da177e4SLinus Torvalds if (!rio_detail_ptr) 4271da177e4SLinus Torvalds return -ENOMEM; 4281da177e4SLinus Torvalds rio_detail_ptr->rio_node_id = readb(io_mem + offset); 4291da177e4SLinus Torvalds rio_detail_ptr->bbar = readl(io_mem + offset + 1); 4301da177e4SLinus Torvalds rio_detail_ptr->rio_type = readb(io_mem + offset + 5); 4311da177e4SLinus Torvalds rio_detail_ptr->owner_id = readb(io_mem + offset + 6); 4321da177e4SLinus Torvalds rio_detail_ptr->port0_node_connect = readb(io_mem + offset + 7); 4331da177e4SLinus Torvalds rio_detail_ptr->port0_port_connect = readb(io_mem + offset + 8); 4341da177e4SLinus Torvalds rio_detail_ptr->port1_node_connect = readb(io_mem + offset + 9); 4351da177e4SLinus Torvalds rio_detail_ptr->port1_port_connect = readb(io_mem + offset + 10); 4361da177e4SLinus Torvalds rio_detail_ptr->first_slot_num = readb(io_mem + offset + 11); 4371da177e4SLinus Torvalds rio_detail_ptr->status = readb(io_mem + offset + 12); 4381da177e4SLinus Torvalds rio_detail_ptr->wpindex = readb(io_mem + offset + 13); 4391da177e4SLinus Torvalds rio_detail_ptr->chassis_num = readb(io_mem + offset + 14); 4401da177e4SLinus Torvalds // debug("rio_node_id: %x\nbbar: %x\nrio_type: %x\nowner_id: %x\nport0_node: %x\nport0_port: %x\nport1_node: %x\nport1_port: %x\nfirst_slot_num: %x\nstatus: %x\n", rio_detail_ptr->rio_node_id, rio_detail_ptr->bbar, rio_detail_ptr->rio_type, rio_detail_ptr->owner_id, rio_detail_ptr->port0_node_connect, rio_detail_ptr->port0_port_connect, rio_detail_ptr->port1_node_connect, rio_detail_ptr->port1_port_connect, rio_detail_ptr->first_slot_num, rio_detail_ptr->status); 4411da177e4SLinus Torvalds //create linked list of chassis 4421da177e4SLinus Torvalds if (rio_detail_ptr->rio_type == 4 || rio_detail_ptr->rio_type == 5) 4431da177e4SLinus Torvalds list_add(&rio_detail_ptr->rio_detail_list, &rio_vg_head); 4441da177e4SLinus Torvalds //create linked list of expansion box 4451da177e4SLinus Torvalds else if (rio_detail_ptr->rio_type == 6 || rio_detail_ptr->rio_type == 7) 4461da177e4SLinus Torvalds list_add(&rio_detail_ptr->rio_detail_list, &rio_lo_head); 4471da177e4SLinus Torvalds else 4481da177e4SLinus Torvalds // not in my concern 4491da177e4SLinus Torvalds kfree(rio_detail_ptr); 4501da177e4SLinus Torvalds offset += 15; 4511da177e4SLinus Torvalds } 4521da177e4SLinus Torvalds print_lo_info(); 4531da177e4SLinus Torvalds print_vg_info(); 4541da177e4SLinus Torvalds return 0; 4551da177e4SLinus Torvalds } 4561da177e4SLinus Torvalds 4571da177e4SLinus Torvalds /* 4581da177e4SLinus Torvalds * reorganizing linked list of chassis 4591da177e4SLinus Torvalds */ 4601da177e4SLinus Torvalds static struct opt_rio *search_opt_vg(u8 chassis_num) 4611da177e4SLinus Torvalds { 4621da177e4SLinus Torvalds struct opt_rio *ptr; 463a8d2dbd3Sakpm@linux-foundation.org list_for_each_entry(ptr, &opt_vg_head, opt_rio_list) { 4641da177e4SLinus Torvalds if (ptr->chassis_num == chassis_num) 4651da177e4SLinus Torvalds return ptr; 4661da177e4SLinus Torvalds } 4671da177e4SLinus Torvalds return NULL; 4681da177e4SLinus Torvalds } 4691da177e4SLinus Torvalds 4701da177e4SLinus Torvalds static int __init combine_wpg_for_chassis(void) 4711da177e4SLinus Torvalds { 4721da177e4SLinus Torvalds struct opt_rio *opt_rio_ptr = NULL; 4731da177e4SLinus Torvalds struct rio_detail *rio_detail_ptr = NULL; 4741da177e4SLinus Torvalds 475a8d2dbd3Sakpm@linux-foundation.org list_for_each_entry(rio_detail_ptr, &rio_vg_head, rio_detail_list) { 4761da177e4SLinus Torvalds opt_rio_ptr = search_opt_vg(rio_detail_ptr->chassis_num); 4771da177e4SLinus Torvalds if (!opt_rio_ptr) { 478f5afe806SEric Sesterhenn opt_rio_ptr = kzalloc(sizeof(struct opt_rio), GFP_KERNEL); 4791da177e4SLinus Torvalds if (!opt_rio_ptr) 4801da177e4SLinus Torvalds return -ENOMEM; 4811da177e4SLinus Torvalds opt_rio_ptr->rio_type = rio_detail_ptr->rio_type; 4821da177e4SLinus Torvalds opt_rio_ptr->chassis_num = rio_detail_ptr->chassis_num; 4831da177e4SLinus Torvalds opt_rio_ptr->first_slot_num = rio_detail_ptr->first_slot_num; 4841da177e4SLinus Torvalds opt_rio_ptr->middle_num = rio_detail_ptr->first_slot_num; 4851da177e4SLinus Torvalds list_add(&opt_rio_ptr->opt_rio_list, &opt_vg_head); 4861da177e4SLinus Torvalds } else { 4871da177e4SLinus Torvalds opt_rio_ptr->first_slot_num = min(opt_rio_ptr->first_slot_num, rio_detail_ptr->first_slot_num); 4881da177e4SLinus Torvalds opt_rio_ptr->middle_num = max(opt_rio_ptr->middle_num, rio_detail_ptr->first_slot_num); 4891da177e4SLinus Torvalds } 4901da177e4SLinus Torvalds } 4911da177e4SLinus Torvalds print_opt_vg(); 4921da177e4SLinus Torvalds return 0; 4931da177e4SLinus Torvalds } 4941da177e4SLinus Torvalds 4951da177e4SLinus Torvalds /* 496a8d2dbd3Sakpm@linux-foundation.org * reorganizing linked list of expansion box 4971da177e4SLinus Torvalds */ 4981da177e4SLinus Torvalds static struct opt_rio_lo *search_opt_lo(u8 chassis_num) 4991da177e4SLinus Torvalds { 5001da177e4SLinus Torvalds struct opt_rio_lo *ptr; 501a8d2dbd3Sakpm@linux-foundation.org list_for_each_entry(ptr, &opt_lo_head, opt_rio_lo_list) { 5021da177e4SLinus Torvalds if (ptr->chassis_num == chassis_num) 5031da177e4SLinus Torvalds return ptr; 5041da177e4SLinus Torvalds } 5051da177e4SLinus Torvalds return NULL; 5061da177e4SLinus Torvalds } 5071da177e4SLinus Torvalds 5081da177e4SLinus Torvalds static int combine_wpg_for_expansion(void) 5091da177e4SLinus Torvalds { 5101da177e4SLinus Torvalds struct opt_rio_lo *opt_rio_lo_ptr = NULL; 5111da177e4SLinus Torvalds struct rio_detail *rio_detail_ptr = NULL; 5121da177e4SLinus Torvalds 513a8d2dbd3Sakpm@linux-foundation.org list_for_each_entry(rio_detail_ptr, &rio_lo_head, rio_detail_list) { 5141da177e4SLinus Torvalds opt_rio_lo_ptr = search_opt_lo(rio_detail_ptr->chassis_num); 5151da177e4SLinus Torvalds if (!opt_rio_lo_ptr) { 516f5afe806SEric Sesterhenn opt_rio_lo_ptr = kzalloc(sizeof(struct opt_rio_lo), GFP_KERNEL); 5171da177e4SLinus Torvalds if (!opt_rio_lo_ptr) 5181da177e4SLinus Torvalds return -ENOMEM; 5191da177e4SLinus Torvalds opt_rio_lo_ptr->rio_type = rio_detail_ptr->rio_type; 5201da177e4SLinus Torvalds opt_rio_lo_ptr->chassis_num = rio_detail_ptr->chassis_num; 5211da177e4SLinus Torvalds opt_rio_lo_ptr->first_slot_num = rio_detail_ptr->first_slot_num; 5221da177e4SLinus Torvalds opt_rio_lo_ptr->middle_num = rio_detail_ptr->first_slot_num; 5231da177e4SLinus Torvalds opt_rio_lo_ptr->pack_count = 1; 5241da177e4SLinus Torvalds 5251da177e4SLinus Torvalds list_add(&opt_rio_lo_ptr->opt_rio_lo_list, &opt_lo_head); 5261da177e4SLinus Torvalds } else { 5271da177e4SLinus Torvalds opt_rio_lo_ptr->first_slot_num = min(opt_rio_lo_ptr->first_slot_num, rio_detail_ptr->first_slot_num); 5281da177e4SLinus Torvalds opt_rio_lo_ptr->middle_num = max(opt_rio_lo_ptr->middle_num, rio_detail_ptr->first_slot_num); 5291da177e4SLinus Torvalds opt_rio_lo_ptr->pack_count = 2; 5301da177e4SLinus Torvalds } 5311da177e4SLinus Torvalds } 5321da177e4SLinus Torvalds return 0; 5331da177e4SLinus Torvalds } 5341da177e4SLinus Torvalds 5351da177e4SLinus Torvalds 5361da177e4SLinus Torvalds /* Since we don't know the max slot number per each chassis, hence go 5371da177e4SLinus Torvalds * through the list of all chassis to find out the range 5381da177e4SLinus Torvalds * Arguments: slot_num, 1st slot number of the chassis we think we are on, 5391da177e4SLinus Torvalds * var (0 = chassis, 1 = expansion box) 5401da177e4SLinus Torvalds */ 5411da177e4SLinus Torvalds static int first_slot_num(u8 slot_num, u8 first_slot, u8 var) 5421da177e4SLinus Torvalds { 5431da177e4SLinus Torvalds struct opt_rio *opt_vg_ptr = NULL; 5441da177e4SLinus Torvalds struct opt_rio_lo *opt_lo_ptr = NULL; 5451da177e4SLinus Torvalds int rc = 0; 5461da177e4SLinus Torvalds 5471da177e4SLinus Torvalds if (!var) { 548a8d2dbd3Sakpm@linux-foundation.org list_for_each_entry(opt_vg_ptr, &opt_vg_head, opt_rio_list) { 5491da177e4SLinus Torvalds if ((first_slot < opt_vg_ptr->first_slot_num) && (slot_num >= opt_vg_ptr->first_slot_num)) { 5501da177e4SLinus Torvalds rc = -ENODEV; 5511da177e4SLinus Torvalds break; 5521da177e4SLinus Torvalds } 5531da177e4SLinus Torvalds } 5541da177e4SLinus Torvalds } else { 555a8d2dbd3Sakpm@linux-foundation.org list_for_each_entry(opt_lo_ptr, &opt_lo_head, opt_rio_lo_list) { 5561da177e4SLinus Torvalds if ((first_slot < opt_lo_ptr->first_slot_num) && (slot_num >= opt_lo_ptr->first_slot_num)) { 5571da177e4SLinus Torvalds rc = -ENODEV; 5581da177e4SLinus Torvalds break; 5591da177e4SLinus Torvalds } 5601da177e4SLinus Torvalds } 5611da177e4SLinus Torvalds } 5621da177e4SLinus Torvalds return rc; 5631da177e4SLinus Torvalds } 5641da177e4SLinus Torvalds 5651da177e4SLinus Torvalds static struct opt_rio_lo *find_rxe_num(u8 slot_num) 5661da177e4SLinus Torvalds { 5671da177e4SLinus Torvalds struct opt_rio_lo *opt_lo_ptr; 5681da177e4SLinus Torvalds 569a8d2dbd3Sakpm@linux-foundation.org list_for_each_entry(opt_lo_ptr, &opt_lo_head, opt_rio_lo_list) { 5701da177e4SLinus Torvalds //check to see if this slot_num belongs to expansion box 5711da177e4SLinus Torvalds if ((slot_num >= opt_lo_ptr->first_slot_num) && (!first_slot_num(slot_num, opt_lo_ptr->first_slot_num, 1))) 5721da177e4SLinus Torvalds return opt_lo_ptr; 5731da177e4SLinus Torvalds } 5741da177e4SLinus Torvalds return NULL; 5751da177e4SLinus Torvalds } 5761da177e4SLinus Torvalds 5771da177e4SLinus Torvalds static struct opt_rio *find_chassis_num(u8 slot_num) 5781da177e4SLinus Torvalds { 5791da177e4SLinus Torvalds struct opt_rio *opt_vg_ptr; 5801da177e4SLinus Torvalds 581a8d2dbd3Sakpm@linux-foundation.org list_for_each_entry(opt_vg_ptr, &opt_vg_head, opt_rio_list) { 5821da177e4SLinus Torvalds //check to see if this slot_num belongs to chassis 5831da177e4SLinus Torvalds if ((slot_num >= opt_vg_ptr->first_slot_num) && (!first_slot_num(slot_num, opt_vg_ptr->first_slot_num, 0))) 5841da177e4SLinus Torvalds return opt_vg_ptr; 5851da177e4SLinus Torvalds } 5861da177e4SLinus Torvalds return NULL; 5871da177e4SLinus Torvalds } 5881da177e4SLinus Torvalds 5891da177e4SLinus Torvalds /* This routine will find out how many slots are in the chassis, so that 5901da177e4SLinus Torvalds * the slot numbers for rxe100 would start from 1, and not from 7, or 6 etc 5911da177e4SLinus Torvalds */ 5921da177e4SLinus Torvalds static u8 calculate_first_slot(u8 slot_num) 5931da177e4SLinus Torvalds { 5941da177e4SLinus Torvalds u8 first_slot = 1; 5951da177e4SLinus Torvalds struct slot *slot_cur; 5961da177e4SLinus Torvalds 597a8d2dbd3Sakpm@linux-foundation.org list_for_each_entry(slot_cur, &ibmphp_slot_head, ibm_slot_list) { 5981da177e4SLinus Torvalds if (slot_cur->ctrl) { 5991da177e4SLinus Torvalds if ((slot_cur->ctrl->ctlr_type != 4) && (slot_cur->ctrl->ending_slot_num > first_slot) && (slot_num > slot_cur->ctrl->ending_slot_num)) 6001da177e4SLinus Torvalds first_slot = slot_cur->ctrl->ending_slot_num; 6011da177e4SLinus Torvalds } 6021da177e4SLinus Torvalds } 6031da177e4SLinus Torvalds return first_slot + 1; 6041da177e4SLinus Torvalds 6051da177e4SLinus Torvalds } 606a32615a1SAlex Chiang 607a32615a1SAlex Chiang #define SLOT_NAME_SIZE 30 608a32615a1SAlex Chiang 6091da177e4SLinus Torvalds static char *create_file_name(struct slot *slot_cur) 6101da177e4SLinus Torvalds { 6111da177e4SLinus Torvalds struct opt_rio *opt_vg_ptr = NULL; 6121da177e4SLinus Torvalds struct opt_rio_lo *opt_lo_ptr = NULL; 613a32615a1SAlex Chiang static char str[SLOT_NAME_SIZE]; 6141da177e4SLinus Torvalds int which = 0; /* rxe = 1, chassis = 0 */ 6151da177e4SLinus Torvalds u8 number = 1; /* either chassis or rxe # */ 6161da177e4SLinus Torvalds u8 first_slot = 1; 6171da177e4SLinus Torvalds u8 slot_num; 6181da177e4SLinus Torvalds u8 flag = 0; 6191da177e4SLinus Torvalds 6201da177e4SLinus Torvalds if (!slot_cur) { 6211da177e4SLinus Torvalds err("Structure passed is empty\n"); 6221da177e4SLinus Torvalds return NULL; 6231da177e4SLinus Torvalds } 6241da177e4SLinus Torvalds 6251da177e4SLinus Torvalds slot_num = slot_cur->number; 6261da177e4SLinus Torvalds 6271da177e4SLinus Torvalds memset(str, 0, sizeof(str)); 6281da177e4SLinus Torvalds 6291da177e4SLinus Torvalds if (rio_table_ptr) { 6301da177e4SLinus Torvalds if (rio_table_ptr->ver_num == 3) { 6311da177e4SLinus Torvalds opt_vg_ptr = find_chassis_num(slot_num); 6321da177e4SLinus Torvalds opt_lo_ptr = find_rxe_num(slot_num); 6331da177e4SLinus Torvalds } 6341da177e4SLinus Torvalds } 6351da177e4SLinus Torvalds if (opt_vg_ptr) { 6361da177e4SLinus Torvalds if (opt_lo_ptr) { 6371da177e4SLinus Torvalds if ((slot_num - opt_vg_ptr->first_slot_num) > (slot_num - opt_lo_ptr->first_slot_num)) { 6381da177e4SLinus Torvalds number = opt_lo_ptr->chassis_num; 6391da177e4SLinus Torvalds first_slot = opt_lo_ptr->first_slot_num; 6401da177e4SLinus Torvalds which = 1; /* it is RXE */ 6411da177e4SLinus Torvalds } else { 6421da177e4SLinus Torvalds first_slot = opt_vg_ptr->first_slot_num; 6431da177e4SLinus Torvalds number = opt_vg_ptr->chassis_num; 6441da177e4SLinus Torvalds which = 0; 6451da177e4SLinus Torvalds } 6461da177e4SLinus Torvalds } else { 6471da177e4SLinus Torvalds first_slot = opt_vg_ptr->first_slot_num; 6481da177e4SLinus Torvalds number = opt_vg_ptr->chassis_num; 6491da177e4SLinus Torvalds which = 0; 6501da177e4SLinus Torvalds } 6511da177e4SLinus Torvalds ++flag; 6521da177e4SLinus Torvalds } else if (opt_lo_ptr) { 6531da177e4SLinus Torvalds number = opt_lo_ptr->chassis_num; 6541da177e4SLinus Torvalds first_slot = opt_lo_ptr->first_slot_num; 6551da177e4SLinus Torvalds which = 1; 6561da177e4SLinus Torvalds ++flag; 6571da177e4SLinus Torvalds } else if (rio_table_ptr) { 6581da177e4SLinus Torvalds if (rio_table_ptr->ver_num == 3) { 6591da177e4SLinus Torvalds /* if both NULL and we DO have correct RIO table in BIOS */ 6601da177e4SLinus Torvalds return NULL; 6611da177e4SLinus Torvalds } 6621da177e4SLinus Torvalds } 6631da177e4SLinus Torvalds if (!flag) { 6641da177e4SLinus Torvalds if (slot_cur->ctrl->ctlr_type == 4) { 6651da177e4SLinus Torvalds first_slot = calculate_first_slot(slot_num); 6661da177e4SLinus Torvalds which = 1; 6671da177e4SLinus Torvalds } else { 6681da177e4SLinus Torvalds which = 0; 6691da177e4SLinus Torvalds } 6701da177e4SLinus Torvalds } 6711da177e4SLinus Torvalds 6721da177e4SLinus Torvalds sprintf(str, "%s%dslot%d", 6731da177e4SLinus Torvalds which == 0 ? "chassis" : "rxe", 6741da177e4SLinus Torvalds number, slot_num - first_slot + 1); 6751da177e4SLinus Torvalds return str; 6761da177e4SLinus Torvalds } 6771da177e4SLinus Torvalds 6781da177e4SLinus Torvalds static int fillslotinfo(struct hotplug_slot *hotplug_slot) 6791da177e4SLinus Torvalds { 6801da177e4SLinus Torvalds struct slot *slot; 6811da177e4SLinus Torvalds int rc = 0; 6821da177e4SLinus Torvalds 6831da177e4SLinus Torvalds if (!hotplug_slot || !hotplug_slot->private) 6841da177e4SLinus Torvalds return -EINVAL; 6851da177e4SLinus Torvalds 6861da177e4SLinus Torvalds slot = hotplug_slot->private; 6871da177e4SLinus Torvalds rc = ibmphp_hpc_readslot(slot, READ_ALLSTAT, NULL); 6881da177e4SLinus Torvalds if (rc) 6891da177e4SLinus Torvalds return rc; 6901da177e4SLinus Torvalds 6911da177e4SLinus Torvalds // power - enabled:1 not:0 6921da177e4SLinus Torvalds hotplug_slot->info->power_status = SLOT_POWER(slot->status); 6931da177e4SLinus Torvalds 6941da177e4SLinus Torvalds // attention - off:0, on:1, blinking:2 6951da177e4SLinus Torvalds hotplug_slot->info->attention_status = SLOT_ATTN(slot->status, slot->ext_status); 6961da177e4SLinus Torvalds 6971da177e4SLinus Torvalds // latch - open:1 closed:0 6981da177e4SLinus Torvalds hotplug_slot->info->latch_status = SLOT_LATCH(slot->status); 6991da177e4SLinus Torvalds 7001da177e4SLinus Torvalds // pci board - present:1 not:0 7011da177e4SLinus Torvalds if (SLOT_PRESENT(slot->status)) 7021da177e4SLinus Torvalds hotplug_slot->info->adapter_status = 1; 7031da177e4SLinus Torvalds else 7041da177e4SLinus Torvalds hotplug_slot->info->adapter_status = 0; 7051da177e4SLinus Torvalds /* 7061da177e4SLinus Torvalds if (slot->bus_on->supported_bus_mode 7071da177e4SLinus Torvalds && (slot->bus_on->supported_speed == BUS_SPEED_66)) 7081da177e4SLinus Torvalds hotplug_slot->info->max_bus_speed_status = BUS_SPEED_66PCIX; 7091da177e4SLinus Torvalds else 7101da177e4SLinus Torvalds hotplug_slot->info->max_bus_speed_status = slot->bus_on->supported_speed; 7111da177e4SLinus Torvalds */ 7121da177e4SLinus Torvalds 7131da177e4SLinus Torvalds return rc; 7141da177e4SLinus Torvalds } 7151da177e4SLinus Torvalds 7161da177e4SLinus Torvalds static void release_slot(struct hotplug_slot *hotplug_slot) 7171da177e4SLinus Torvalds { 7181da177e4SLinus Torvalds struct slot *slot; 7191da177e4SLinus Torvalds 7201da177e4SLinus Torvalds if (!hotplug_slot || !hotplug_slot->private) 7211da177e4SLinus Torvalds return; 7221da177e4SLinus Torvalds 7231da177e4SLinus Torvalds slot = hotplug_slot->private; 7241da177e4SLinus Torvalds kfree(slot->hotplug_slot->info); 7251da177e4SLinus Torvalds kfree(slot->hotplug_slot); 7261da177e4SLinus Torvalds slot->ctrl = NULL; 7271da177e4SLinus Torvalds slot->bus_on = NULL; 7281da177e4SLinus Torvalds 7291da177e4SLinus Torvalds /* we don't want to actually remove the resources, since free_resources will do just that */ 7301da177e4SLinus Torvalds ibmphp_unconfigure_card(&slot, -1); 7311da177e4SLinus Torvalds 7321da177e4SLinus Torvalds kfree(slot); 7331da177e4SLinus Torvalds } 7341da177e4SLinus Torvalds 7351da177e4SLinus Torvalds static struct pci_driver ibmphp_driver; 7361da177e4SLinus Torvalds 7371da177e4SLinus Torvalds /* 7381da177e4SLinus Torvalds * map info (ctlr-id, slot count, slot#.. bus count, bus#, ctlr type...) of 7391da177e4SLinus Torvalds * each hpc from physical address to a list of hot plug controllers based on 7401da177e4SLinus Torvalds * hpc descriptors. 7411da177e4SLinus Torvalds */ 7421da177e4SLinus Torvalds static int __init ebda_rsrc_controller(void) 7431da177e4SLinus Torvalds { 7441da177e4SLinus Torvalds u16 addr, addr_slot, addr_bus; 7451da177e4SLinus Torvalds u8 ctlr_id, temp, bus_index; 7461da177e4SLinus Torvalds u16 ctlr, slot, bus; 7471da177e4SLinus Torvalds u16 slot_num, bus_num, index; 7481da177e4SLinus Torvalds struct hotplug_slot *hp_slot_ptr; 7491da177e4SLinus Torvalds struct controller *hpc_ptr; 7501da177e4SLinus Torvalds struct ebda_hpc_bus *bus_ptr; 7511da177e4SLinus Torvalds struct ebda_hpc_slot *slot_ptr; 7521da177e4SLinus Torvalds struct bus_info *bus_info_ptr1, *bus_info_ptr2; 7531da177e4SLinus Torvalds int rc; 7541da177e4SLinus Torvalds struct slot *tmp_slot; 755a32615a1SAlex Chiang char name[SLOT_NAME_SIZE]; 7561da177e4SLinus Torvalds 7571da177e4SLinus Torvalds addr = hpc_list_ptr->phys_addr; 7581da177e4SLinus Torvalds for (ctlr = 0; ctlr < hpc_list_ptr->num_ctlrs; ctlr++) { 7591da177e4SLinus Torvalds bus_index = 1; 7601da177e4SLinus Torvalds ctlr_id = readb(io_mem + addr); 7611da177e4SLinus Torvalds addr += 1; 7621da177e4SLinus Torvalds slot_num = readb(io_mem + addr); 7631da177e4SLinus Torvalds 7641da177e4SLinus Torvalds addr += 1; 7651da177e4SLinus Torvalds addr_slot = addr; /* offset of slot structure */ 7661da177e4SLinus Torvalds addr += (slot_num * 4); 7671da177e4SLinus Torvalds 7681da177e4SLinus Torvalds bus_num = readb(io_mem + addr); 7691da177e4SLinus Torvalds 7701da177e4SLinus Torvalds addr += 1; 7711da177e4SLinus Torvalds addr_bus = addr; /* offset of bus */ 7721da177e4SLinus Torvalds addr += (bus_num * 9); /* offset of ctlr_type */ 7731da177e4SLinus Torvalds temp = readb(io_mem + addr); 7741da177e4SLinus Torvalds 7751da177e4SLinus Torvalds addr += 1; 7761da177e4SLinus Torvalds /* init hpc structure */ 7771da177e4SLinus Torvalds hpc_ptr = alloc_ebda_hpc(slot_num, bus_num); 7781da177e4SLinus Torvalds if (!hpc_ptr) { 7791da177e4SLinus Torvalds rc = -ENOMEM; 7801da177e4SLinus Torvalds goto error_no_hpc; 7811da177e4SLinus Torvalds } 7821da177e4SLinus Torvalds hpc_ptr->ctlr_id = ctlr_id; 7831da177e4SLinus Torvalds hpc_ptr->ctlr_relative_id = ctlr; 7841da177e4SLinus Torvalds hpc_ptr->slot_count = slot_num; 7851da177e4SLinus Torvalds hpc_ptr->bus_count = bus_num; 786367fa982SMasanari Iida debug("now enter ctlr data structure ---\n"); 7871da177e4SLinus Torvalds debug("ctlr id: %x\n", ctlr_id); 7881da177e4SLinus Torvalds debug("ctlr_relative_id: %x\n", hpc_ptr->ctlr_relative_id); 7891da177e4SLinus Torvalds debug("count of slots controlled by this ctlr: %x\n", slot_num); 7901da177e4SLinus Torvalds debug("count of buses controlled by this ctlr: %x\n", bus_num); 7911da177e4SLinus Torvalds 7921da177e4SLinus Torvalds /* init slot structure, fetch slot, bus, cap... */ 7931da177e4SLinus Torvalds slot_ptr = hpc_ptr->slots; 7941da177e4SLinus Torvalds for (slot = 0; slot < slot_num; slot++) { 7951da177e4SLinus Torvalds slot_ptr->slot_num = readb(io_mem + addr_slot); 7961da177e4SLinus Torvalds slot_ptr->slot_bus_num = readb(io_mem + addr_slot + slot_num); 7971da177e4SLinus Torvalds slot_ptr->ctl_index = readb(io_mem + addr_slot + 2*slot_num); 7981da177e4SLinus Torvalds slot_ptr->slot_cap = readb(io_mem + addr_slot + 3*slot_num); 7991da177e4SLinus Torvalds 8001da177e4SLinus Torvalds // create bus_info lined list --- if only one slot per bus: slot_min = slot_max 8011da177e4SLinus Torvalds 8021da177e4SLinus Torvalds bus_info_ptr2 = ibmphp_find_same_bus_num(slot_ptr->slot_bus_num); 8031da177e4SLinus Torvalds if (!bus_info_ptr2) { 804f5afe806SEric Sesterhenn bus_info_ptr1 = kzalloc(sizeof(struct bus_info), GFP_KERNEL); 8051da177e4SLinus Torvalds if (!bus_info_ptr1) { 8061da177e4SLinus Torvalds rc = -ENOMEM; 8071da177e4SLinus Torvalds goto error_no_hp_slot; 8081da177e4SLinus Torvalds } 8091da177e4SLinus Torvalds bus_info_ptr1->slot_min = slot_ptr->slot_num; 8101da177e4SLinus Torvalds bus_info_ptr1->slot_max = slot_ptr->slot_num; 8111da177e4SLinus Torvalds bus_info_ptr1->slot_count += 1; 8121da177e4SLinus Torvalds bus_info_ptr1->busno = slot_ptr->slot_bus_num; 8131da177e4SLinus Torvalds bus_info_ptr1->index = bus_index++; 8141da177e4SLinus Torvalds bus_info_ptr1->current_speed = 0xff; 8151da177e4SLinus Torvalds bus_info_ptr1->current_bus_mode = 0xff; 8161da177e4SLinus Torvalds 8171da177e4SLinus Torvalds bus_info_ptr1->controller_id = hpc_ptr->ctlr_id; 8181da177e4SLinus Torvalds 8191da177e4SLinus Torvalds list_add_tail(&bus_info_ptr1->bus_info_list, &bus_info_head); 8201da177e4SLinus Torvalds 8211da177e4SLinus Torvalds } else { 8221da177e4SLinus Torvalds bus_info_ptr2->slot_min = min(bus_info_ptr2->slot_min, slot_ptr->slot_num); 8231da177e4SLinus Torvalds bus_info_ptr2->slot_max = max(bus_info_ptr2->slot_max, slot_ptr->slot_num); 8241da177e4SLinus Torvalds bus_info_ptr2->slot_count += 1; 8251da177e4SLinus Torvalds 8261da177e4SLinus Torvalds } 8271da177e4SLinus Torvalds 8281da177e4SLinus Torvalds // end of creating the bus_info linked list 8291da177e4SLinus Torvalds 8301da177e4SLinus Torvalds slot_ptr++; 8311da177e4SLinus Torvalds addr_slot += 1; 8321da177e4SLinus Torvalds } 8331da177e4SLinus Torvalds 8341da177e4SLinus Torvalds /* init bus structure */ 8351da177e4SLinus Torvalds bus_ptr = hpc_ptr->buses; 8361da177e4SLinus Torvalds for (bus = 0; bus < bus_num; bus++) { 8371da177e4SLinus Torvalds bus_ptr->bus_num = readb(io_mem + addr_bus + bus); 8381da177e4SLinus Torvalds bus_ptr->slots_at_33_conv = readb(io_mem + addr_bus + bus_num + 8 * bus); 8391da177e4SLinus Torvalds bus_ptr->slots_at_66_conv = readb(io_mem + addr_bus + bus_num + 8 * bus + 1); 8401da177e4SLinus Torvalds 8411da177e4SLinus Torvalds bus_ptr->slots_at_66_pcix = readb(io_mem + addr_bus + bus_num + 8 * bus + 2); 8421da177e4SLinus Torvalds 8431da177e4SLinus Torvalds bus_ptr->slots_at_100_pcix = readb(io_mem + addr_bus + bus_num + 8 * bus + 3); 8441da177e4SLinus Torvalds 8451da177e4SLinus Torvalds bus_ptr->slots_at_133_pcix = readb(io_mem + addr_bus + bus_num + 8 * bus + 4); 8461da177e4SLinus Torvalds 8471da177e4SLinus Torvalds bus_info_ptr2 = ibmphp_find_same_bus_num(bus_ptr->bus_num); 8481da177e4SLinus Torvalds if (bus_info_ptr2) { 8491da177e4SLinus Torvalds bus_info_ptr2->slots_at_33_conv = bus_ptr->slots_at_33_conv; 8501da177e4SLinus Torvalds bus_info_ptr2->slots_at_66_conv = bus_ptr->slots_at_66_conv; 8511da177e4SLinus Torvalds bus_info_ptr2->slots_at_66_pcix = bus_ptr->slots_at_66_pcix; 8521da177e4SLinus Torvalds bus_info_ptr2->slots_at_100_pcix = bus_ptr->slots_at_100_pcix; 8531da177e4SLinus Torvalds bus_info_ptr2->slots_at_133_pcix = bus_ptr->slots_at_133_pcix; 8541da177e4SLinus Torvalds } 8551da177e4SLinus Torvalds bus_ptr++; 8561da177e4SLinus Torvalds } 8571da177e4SLinus Torvalds 8581da177e4SLinus Torvalds hpc_ptr->ctlr_type = temp; 8591da177e4SLinus Torvalds 8601da177e4SLinus Torvalds switch (hpc_ptr->ctlr_type) { 8611da177e4SLinus Torvalds case 1: 8621da177e4SLinus Torvalds hpc_ptr->u.pci_ctlr.bus = readb(io_mem + addr); 8631da177e4SLinus Torvalds hpc_ptr->u.pci_ctlr.dev_fun = readb(io_mem + addr + 1); 8641da177e4SLinus Torvalds hpc_ptr->irq = readb(io_mem + addr + 2); 8651da177e4SLinus Torvalds addr += 3; 8661da177e4SLinus Torvalds debug("ctrl bus = %x, ctlr devfun = %x, irq = %x\n", 8671da177e4SLinus Torvalds hpc_ptr->u.pci_ctlr.bus, 8681da177e4SLinus Torvalds hpc_ptr->u.pci_ctlr.dev_fun, hpc_ptr->irq); 8691da177e4SLinus Torvalds break; 8701da177e4SLinus Torvalds 8711da177e4SLinus Torvalds case 0: 8721da177e4SLinus Torvalds hpc_ptr->u.isa_ctlr.io_start = readw(io_mem + addr); 8731da177e4SLinus Torvalds hpc_ptr->u.isa_ctlr.io_end = readw(io_mem + addr + 2); 8741da177e4SLinus Torvalds if (!request_region(hpc_ptr->u.isa_ctlr.io_start, 8751da177e4SLinus Torvalds (hpc_ptr->u.isa_ctlr.io_end - hpc_ptr->u.isa_ctlr.io_start + 1), 8761da177e4SLinus Torvalds "ibmphp")) { 8771da177e4SLinus Torvalds rc = -ENODEV; 8781da177e4SLinus Torvalds goto error_no_hp_slot; 8791da177e4SLinus Torvalds } 8801da177e4SLinus Torvalds hpc_ptr->irq = readb(io_mem + addr + 4); 8811da177e4SLinus Torvalds addr += 5; 8821da177e4SLinus Torvalds break; 8831da177e4SLinus Torvalds 8841da177e4SLinus Torvalds case 2: 8851da177e4SLinus Torvalds case 4: 8861da177e4SLinus Torvalds hpc_ptr->u.wpeg_ctlr.wpegbbar = readl(io_mem + addr); 8871da177e4SLinus Torvalds hpc_ptr->u.wpeg_ctlr.i2c_addr = readb(io_mem + addr + 4); 8881da177e4SLinus Torvalds hpc_ptr->irq = readb(io_mem + addr + 5); 8891da177e4SLinus Torvalds addr += 6; 8901da177e4SLinus Torvalds break; 8911da177e4SLinus Torvalds default: 8921da177e4SLinus Torvalds rc = -ENODEV; 8931da177e4SLinus Torvalds goto error_no_hp_slot; 8941da177e4SLinus Torvalds } 8951da177e4SLinus Torvalds 8961da177e4SLinus Torvalds //reorganize chassis' linked list 8971da177e4SLinus Torvalds combine_wpg_for_chassis(); 8981da177e4SLinus Torvalds combine_wpg_for_expansion(); 8991da177e4SLinus Torvalds hpc_ptr->revision = 0xff; 9001da177e4SLinus Torvalds hpc_ptr->options = 0xff; 9011da177e4SLinus Torvalds hpc_ptr->starting_slot_num = hpc_ptr->slots[0].slot_num; 9021da177e4SLinus Torvalds hpc_ptr->ending_slot_num = hpc_ptr->slots[slot_num-1].slot_num; 9031da177e4SLinus Torvalds 9041da177e4SLinus Torvalds // register slots with hpc core as well as create linked list of ibm slot 9051da177e4SLinus Torvalds for (index = 0; index < hpc_ptr->slot_count; index++) { 9061da177e4SLinus Torvalds 907f5afe806SEric Sesterhenn hp_slot_ptr = kzalloc(sizeof(*hp_slot_ptr), GFP_KERNEL); 9081da177e4SLinus Torvalds if (!hp_slot_ptr) { 9091da177e4SLinus Torvalds rc = -ENOMEM; 9101da177e4SLinus Torvalds goto error_no_hp_slot; 9111da177e4SLinus Torvalds } 9121da177e4SLinus Torvalds 913f5afe806SEric Sesterhenn hp_slot_ptr->info = kzalloc(sizeof(struct hotplug_slot_info), GFP_KERNEL); 9141da177e4SLinus Torvalds if (!hp_slot_ptr->info) { 9151da177e4SLinus Torvalds rc = -ENOMEM; 9161da177e4SLinus Torvalds goto error_no_hp_info; 9171da177e4SLinus Torvalds } 9181da177e4SLinus Torvalds 919f5afe806SEric Sesterhenn tmp_slot = kzalloc(sizeof(*tmp_slot), GFP_KERNEL); 9201da177e4SLinus Torvalds if (!tmp_slot) { 9211da177e4SLinus Torvalds rc = -ENOMEM; 9221da177e4SLinus Torvalds goto error_no_slot; 9231da177e4SLinus Torvalds } 9241da177e4SLinus Torvalds 925dc6712d1SKristen Accardi tmp_slot->flag = 1; 9261da177e4SLinus Torvalds 9271da177e4SLinus Torvalds tmp_slot->capabilities = hpc_ptr->slots[index].slot_cap; 9281da177e4SLinus Torvalds if ((hpc_ptr->slots[index].slot_cap & EBDA_SLOT_133_MAX) == EBDA_SLOT_133_MAX) 9291da177e4SLinus Torvalds tmp_slot->supported_speed = 3; 9301da177e4SLinus Torvalds else if ((hpc_ptr->slots[index].slot_cap & EBDA_SLOT_100_MAX) == EBDA_SLOT_100_MAX) 9311da177e4SLinus Torvalds tmp_slot->supported_speed = 2; 9321da177e4SLinus Torvalds else if ((hpc_ptr->slots[index].slot_cap & EBDA_SLOT_66_MAX) == EBDA_SLOT_66_MAX) 9331da177e4SLinus Torvalds tmp_slot->supported_speed = 1; 9341da177e4SLinus Torvalds 9351da177e4SLinus Torvalds if ((hpc_ptr->slots[index].slot_cap & EBDA_SLOT_PCIX_CAP) == EBDA_SLOT_PCIX_CAP) 9361da177e4SLinus Torvalds tmp_slot->supported_bus_mode = 1; 9371da177e4SLinus Torvalds else 9381da177e4SLinus Torvalds tmp_slot->supported_bus_mode = 0; 9391da177e4SLinus Torvalds 9401da177e4SLinus Torvalds 9411da177e4SLinus Torvalds tmp_slot->bus = hpc_ptr->slots[index].slot_bus_num; 9421da177e4SLinus Torvalds 9431da177e4SLinus Torvalds bus_info_ptr1 = ibmphp_find_same_bus_num(hpc_ptr->slots[index].slot_bus_num); 9441da177e4SLinus Torvalds if (!bus_info_ptr1) { 945b91aac29SJesper Juhl kfree(tmp_slot); 9461da177e4SLinus Torvalds rc = -ENODEV; 9471da177e4SLinus Torvalds goto error; 9481da177e4SLinus Torvalds } 9491da177e4SLinus Torvalds tmp_slot->bus_on = bus_info_ptr1; 9501da177e4SLinus Torvalds bus_info_ptr1 = NULL; 9511da177e4SLinus Torvalds tmp_slot->ctrl = hpc_ptr; 9521da177e4SLinus Torvalds 9531da177e4SLinus Torvalds tmp_slot->ctlr_index = hpc_ptr->slots[index].ctl_index; 9541da177e4SLinus Torvalds tmp_slot->number = hpc_ptr->slots[index].slot_num; 9551da177e4SLinus Torvalds tmp_slot->hotplug_slot = hp_slot_ptr; 9561da177e4SLinus Torvalds 9571da177e4SLinus Torvalds hp_slot_ptr->private = tmp_slot; 9581da177e4SLinus Torvalds hp_slot_ptr->release = release_slot; 9591da177e4SLinus Torvalds 9601da177e4SLinus Torvalds rc = fillslotinfo(hp_slot_ptr); 9611da177e4SLinus Torvalds if (rc) 9621da177e4SLinus Torvalds goto error; 9631da177e4SLinus Torvalds 9641da177e4SLinus Torvalds rc = ibmphp_init_devno((struct slot **) &hp_slot_ptr->private); 9651da177e4SLinus Torvalds if (rc) 9661da177e4SLinus Torvalds goto error; 9671da177e4SLinus Torvalds hp_slot_ptr->ops = &ibmphp_hotplug_slot_ops; 9681da177e4SLinus Torvalds 9691da177e4SLinus Torvalds // end of registering ibm slot with hotplug core 9701da177e4SLinus Torvalds 9711da177e4SLinus Torvalds list_add(&((struct slot *)(hp_slot_ptr->private))->ibm_slot_list, &ibmphp_slot_head); 9721da177e4SLinus Torvalds } 9731da177e4SLinus Torvalds 9741da177e4SLinus Torvalds print_bus_info(); 9751da177e4SLinus Torvalds list_add(&hpc_ptr->ebda_hpc_list, &ebda_hpc_head); 9761da177e4SLinus Torvalds 9771da177e4SLinus Torvalds } /* each hpc */ 9781da177e4SLinus Torvalds 979a8d2dbd3Sakpm@linux-foundation.org list_for_each_entry(tmp_slot, &ibmphp_slot_head, ibm_slot_list) { 980a32615a1SAlex Chiang snprintf(name, SLOT_NAME_SIZE, "%s", create_file_name(tmp_slot)); 981f46753c5SAlex Chiang pci_hp_register(tmp_slot->hotplug_slot, 982a32615a1SAlex Chiang pci_find_bus(0, tmp_slot->bus), tmp_slot->device, name); 9831da177e4SLinus Torvalds } 9841da177e4SLinus Torvalds 9851da177e4SLinus Torvalds print_ebda_hpc(); 9861da177e4SLinus Torvalds print_ibm_slot(); 9871da177e4SLinus Torvalds return 0; 9881da177e4SLinus Torvalds 9891da177e4SLinus Torvalds error: 9901da177e4SLinus Torvalds kfree(hp_slot_ptr->private); 9911da177e4SLinus Torvalds error_no_slot: 9921da177e4SLinus Torvalds kfree(hp_slot_ptr->info); 9931da177e4SLinus Torvalds error_no_hp_info: 9941da177e4SLinus Torvalds kfree(hp_slot_ptr); 9951da177e4SLinus Torvalds error_no_hp_slot: 9961da177e4SLinus Torvalds free_ebda_hpc(hpc_ptr); 9971da177e4SLinus Torvalds error_no_hpc: 9981da177e4SLinus Torvalds iounmap(io_mem); 9991da177e4SLinus Torvalds return rc; 10001da177e4SLinus Torvalds } 10011da177e4SLinus Torvalds 10021da177e4SLinus Torvalds /* 10031da177e4SLinus Torvalds * map info (bus, devfun, start addr, end addr..) of i/o, memory, 10041da177e4SLinus Torvalds * pfm from the physical addr to a list of resource. 10051da177e4SLinus Torvalds */ 10061da177e4SLinus Torvalds static int __init ebda_rsrc_rsrc(void) 10071da177e4SLinus Torvalds { 10081da177e4SLinus Torvalds u16 addr; 10091da177e4SLinus Torvalds short rsrc; 10101da177e4SLinus Torvalds u8 type, rsrc_type; 10111da177e4SLinus Torvalds struct ebda_pci_rsrc *rsrc_ptr; 10121da177e4SLinus Torvalds 10131da177e4SLinus Torvalds addr = rsrc_list_ptr->phys_addr; 10141da177e4SLinus Torvalds debug("now entering rsrc land\n"); 10151da177e4SLinus Torvalds debug("offset of rsrc: %x\n", rsrc_list_ptr->phys_addr); 10161da177e4SLinus Torvalds 10171da177e4SLinus Torvalds for (rsrc = 0; rsrc < rsrc_list_ptr->num_entries; rsrc++) { 10181da177e4SLinus Torvalds type = readb(io_mem + addr); 10191da177e4SLinus Torvalds 10201da177e4SLinus Torvalds addr += 1; 10211da177e4SLinus Torvalds rsrc_type = type & EBDA_RSRC_TYPE_MASK; 10221da177e4SLinus Torvalds 10231da177e4SLinus Torvalds if (rsrc_type == EBDA_IO_RSRC_TYPE) { 10241da177e4SLinus Torvalds rsrc_ptr = alloc_ebda_pci_rsrc(); 10251da177e4SLinus Torvalds if (!rsrc_ptr) { 10261da177e4SLinus Torvalds iounmap(io_mem); 10271da177e4SLinus Torvalds return -ENOMEM; 10281da177e4SLinus Torvalds } 10291da177e4SLinus Torvalds rsrc_ptr->rsrc_type = type; 10301da177e4SLinus Torvalds 10311da177e4SLinus Torvalds rsrc_ptr->bus_num = readb(io_mem + addr); 10321da177e4SLinus Torvalds rsrc_ptr->dev_fun = readb(io_mem + addr + 1); 10331da177e4SLinus Torvalds rsrc_ptr->start_addr = readw(io_mem + addr + 2); 10341da177e4SLinus Torvalds rsrc_ptr->end_addr = readw(io_mem + addr + 4); 10351da177e4SLinus Torvalds addr += 6; 10361da177e4SLinus Torvalds 10371da177e4SLinus Torvalds debug("rsrc from io type ----\n"); 10381da177e4SLinus Torvalds debug("rsrc type: %x bus#: %x dev_func: %x start addr: %x end addr: %x\n", 10391da177e4SLinus Torvalds rsrc_ptr->rsrc_type, rsrc_ptr->bus_num, rsrc_ptr->dev_fun, rsrc_ptr->start_addr, rsrc_ptr->end_addr); 10401da177e4SLinus Torvalds 10411da177e4SLinus Torvalds list_add(&rsrc_ptr->ebda_pci_rsrc_list, &ibmphp_ebda_pci_rsrc_head); 10421da177e4SLinus Torvalds } 10431da177e4SLinus Torvalds 10441da177e4SLinus Torvalds if (rsrc_type == EBDA_MEM_RSRC_TYPE || rsrc_type == EBDA_PFM_RSRC_TYPE) { 10451da177e4SLinus Torvalds rsrc_ptr = alloc_ebda_pci_rsrc(); 10461da177e4SLinus Torvalds if (!rsrc_ptr) { 10471da177e4SLinus Torvalds iounmap(io_mem); 10481da177e4SLinus Torvalds return -ENOMEM; 10491da177e4SLinus Torvalds } 10501da177e4SLinus Torvalds rsrc_ptr->rsrc_type = type; 10511da177e4SLinus Torvalds 10521da177e4SLinus Torvalds rsrc_ptr->bus_num = readb(io_mem + addr); 10531da177e4SLinus Torvalds rsrc_ptr->dev_fun = readb(io_mem + addr + 1); 10541da177e4SLinus Torvalds rsrc_ptr->start_addr = readl(io_mem + addr + 2); 10551da177e4SLinus Torvalds rsrc_ptr->end_addr = readl(io_mem + addr + 6); 10561da177e4SLinus Torvalds addr += 10; 10571da177e4SLinus Torvalds 10581da177e4SLinus Torvalds debug("rsrc from mem or pfm ---\n"); 10591da177e4SLinus Torvalds debug("rsrc type: %x bus#: %x dev_func: %x start addr: %x end addr: %x\n", 10601da177e4SLinus Torvalds rsrc_ptr->rsrc_type, rsrc_ptr->bus_num, rsrc_ptr->dev_fun, rsrc_ptr->start_addr, rsrc_ptr->end_addr); 10611da177e4SLinus Torvalds 10621da177e4SLinus Torvalds list_add(&rsrc_ptr->ebda_pci_rsrc_list, &ibmphp_ebda_pci_rsrc_head); 10631da177e4SLinus Torvalds } 10641da177e4SLinus Torvalds } 10651da177e4SLinus Torvalds kfree(rsrc_list_ptr); 10661da177e4SLinus Torvalds rsrc_list_ptr = NULL; 10671da177e4SLinus Torvalds print_ebda_pci_rsrc(); 10681da177e4SLinus Torvalds return 0; 10691da177e4SLinus Torvalds } 10701da177e4SLinus Torvalds 10711da177e4SLinus Torvalds u16 ibmphp_get_total_controllers(void) 10721da177e4SLinus Torvalds { 10731da177e4SLinus Torvalds return hpc_list_ptr->num_ctlrs; 10741da177e4SLinus Torvalds } 10751da177e4SLinus Torvalds 10761da177e4SLinus Torvalds struct slot *ibmphp_get_slot_from_physical_num(u8 physical_num) 10771da177e4SLinus Torvalds { 10781da177e4SLinus Torvalds struct slot *slot; 10791da177e4SLinus Torvalds 1080a8d2dbd3Sakpm@linux-foundation.org list_for_each_entry(slot, &ibmphp_slot_head, ibm_slot_list) { 10811da177e4SLinus Torvalds if (slot->number == physical_num) 10821da177e4SLinus Torvalds return slot; 10831da177e4SLinus Torvalds } 10841da177e4SLinus Torvalds return NULL; 10851da177e4SLinus Torvalds } 10861da177e4SLinus Torvalds 10871da177e4SLinus Torvalds /* To find: 10881da177e4SLinus Torvalds * - the smallest slot number 10891da177e4SLinus Torvalds * - the largest slot number 10901da177e4SLinus Torvalds * - the total number of the slots based on each bus 10911da177e4SLinus Torvalds * (if only one slot per bus slot_min = slot_max ) 10921da177e4SLinus Torvalds */ 10931da177e4SLinus Torvalds struct bus_info *ibmphp_find_same_bus_num(u32 num) 10941da177e4SLinus Torvalds { 10951da177e4SLinus Torvalds struct bus_info *ptr; 10961da177e4SLinus Torvalds 1097a8d2dbd3Sakpm@linux-foundation.org list_for_each_entry(ptr, &bus_info_head, bus_info_list) { 10981da177e4SLinus Torvalds if (ptr->busno == num) 10991da177e4SLinus Torvalds return ptr; 11001da177e4SLinus Torvalds } 11011da177e4SLinus Torvalds return NULL; 11021da177e4SLinus Torvalds } 11031da177e4SLinus Torvalds 11041da177e4SLinus Torvalds /* Finding relative bus number, in order to map corresponding 11051da177e4SLinus Torvalds * bus register 11061da177e4SLinus Torvalds */ 11071da177e4SLinus Torvalds int ibmphp_get_bus_index(u8 num) 11081da177e4SLinus Torvalds { 11091da177e4SLinus Torvalds struct bus_info *ptr; 11101da177e4SLinus Torvalds 1111a8d2dbd3Sakpm@linux-foundation.org list_for_each_entry(ptr, &bus_info_head, bus_info_list) { 11121da177e4SLinus Torvalds if (ptr->busno == num) 11131da177e4SLinus Torvalds return ptr->index; 11141da177e4SLinus Torvalds } 11151da177e4SLinus Torvalds return -ENODEV; 11161da177e4SLinus Torvalds } 11171da177e4SLinus Torvalds 11181da177e4SLinus Torvalds void ibmphp_free_bus_info_queue(void) 11191da177e4SLinus Torvalds { 11202ac83cccSGeliang Tang struct bus_info *bus_info, *next; 11211da177e4SLinus Torvalds 11222ac83cccSGeliang Tang list_for_each_entry_safe(bus_info, next, &bus_info_head, 11232ac83cccSGeliang Tang bus_info_list) { 11241da177e4SLinus Torvalds kfree (bus_info); 11251da177e4SLinus Torvalds } 11261da177e4SLinus Torvalds } 11271da177e4SLinus Torvalds 11281da177e4SLinus Torvalds void ibmphp_free_ebda_hpc_queue(void) 11291da177e4SLinus Torvalds { 11302ac83cccSGeliang Tang struct controller *controller = NULL, *next; 11311da177e4SLinus Torvalds int pci_flag = 0; 11321da177e4SLinus Torvalds 11332ac83cccSGeliang Tang list_for_each_entry_safe(controller, next, &ebda_hpc_head, 11342ac83cccSGeliang Tang ebda_hpc_list) { 11351da177e4SLinus Torvalds if (controller->ctlr_type == 0) 11361da177e4SLinus Torvalds release_region(controller->u.isa_ctlr.io_start, (controller->u.isa_ctlr.io_end - controller->u.isa_ctlr.io_start + 1)); 11371da177e4SLinus Torvalds else if ((controller->ctlr_type == 1) && (!pci_flag)) { 11381da177e4SLinus Torvalds ++pci_flag; 11391da177e4SLinus Torvalds pci_unregister_driver(&ibmphp_driver); 11401da177e4SLinus Torvalds } 11411da177e4SLinus Torvalds free_ebda_hpc(controller); 11421da177e4SLinus Torvalds } 11431da177e4SLinus Torvalds } 11441da177e4SLinus Torvalds 11451da177e4SLinus Torvalds void ibmphp_free_ebda_pci_rsrc_queue(void) 11461da177e4SLinus Torvalds { 11472ac83cccSGeliang Tang struct ebda_pci_rsrc *resource, *next; 11481da177e4SLinus Torvalds 11492ac83cccSGeliang Tang list_for_each_entry_safe(resource, next, &ibmphp_ebda_pci_rsrc_head, 11502ac83cccSGeliang Tang ebda_pci_rsrc_list) { 11511da177e4SLinus Torvalds kfree (resource); 11521da177e4SLinus Torvalds resource = NULL; 11531da177e4SLinus Torvalds } 11541da177e4SLinus Torvalds } 11551da177e4SLinus Torvalds 11568394264dSArvind Yadav static const struct pci_device_id id_table[] = { 11571da177e4SLinus Torvalds { 11581da177e4SLinus Torvalds .vendor = PCI_VENDOR_ID_IBM, 11591da177e4SLinus Torvalds .device = HPC_DEVICE_ID, 11601da177e4SLinus Torvalds .subvendor = PCI_VENDOR_ID_IBM, 11611da177e4SLinus Torvalds .subdevice = HPC_SUBSYSTEM_ID, 11621da177e4SLinus Torvalds .class = ((PCI_CLASS_SYSTEM_PCI_HOTPLUG << 8) | 0x00), 11631da177e4SLinus Torvalds }, {} 11641da177e4SLinus Torvalds }; 11651da177e4SLinus Torvalds 11661da177e4SLinus Torvalds MODULE_DEVICE_TABLE(pci, id_table); 11671da177e4SLinus Torvalds 11681da177e4SLinus Torvalds static int ibmphp_probe(struct pci_dev *, const struct pci_device_id *); 11691da177e4SLinus Torvalds static struct pci_driver ibmphp_driver = { 11701da177e4SLinus Torvalds .name = "ibmphp", 11711da177e4SLinus Torvalds .id_table = id_table, 11721da177e4SLinus Torvalds .probe = ibmphp_probe, 11731da177e4SLinus Torvalds }; 11741da177e4SLinus Torvalds 11751da177e4SLinus Torvalds int ibmphp_register_pci(void) 11761da177e4SLinus Torvalds { 11771da177e4SLinus Torvalds struct controller *ctrl; 11781da177e4SLinus Torvalds int rc = 0; 11791da177e4SLinus Torvalds 1180a8d2dbd3Sakpm@linux-foundation.org list_for_each_entry(ctrl, &ebda_hpc_head, ebda_hpc_list) { 11811da177e4SLinus Torvalds if (ctrl->ctlr_type == 1) { 11821da177e4SLinus Torvalds rc = pci_register_driver(&ibmphp_driver); 11831da177e4SLinus Torvalds break; 11841da177e4SLinus Torvalds } 11851da177e4SLinus Torvalds } 11861da177e4SLinus Torvalds return rc; 11871da177e4SLinus Torvalds } 11881da177e4SLinus Torvalds static int ibmphp_probe(struct pci_dev *dev, const struct pci_device_id *ids) 11891da177e4SLinus Torvalds { 11901da177e4SLinus Torvalds struct controller *ctrl; 11911da177e4SLinus Torvalds 11921da177e4SLinus Torvalds debug("inside ibmphp_probe\n"); 11931da177e4SLinus Torvalds 1194a8d2dbd3Sakpm@linux-foundation.org list_for_each_entry(ctrl, &ebda_hpc_head, ebda_hpc_list) { 11951da177e4SLinus Torvalds if (ctrl->ctlr_type == 1) { 11961da177e4SLinus Torvalds if ((dev->devfn == ctrl->u.pci_ctlr.dev_fun) && (dev->bus->number == ctrl->u.pci_ctlr.bus)) { 11971da177e4SLinus Torvalds ctrl->ctrl_dev = dev; 11981da177e4SLinus Torvalds debug("found device!!!\n"); 11991da177e4SLinus Torvalds debug("dev->device = %x, dev->subsystem_device = %x\n", dev->device, dev->subsystem_device); 12001da177e4SLinus Torvalds return 0; 12011da177e4SLinus Torvalds } 12021da177e4SLinus Torvalds } 12031da177e4SLinus Torvalds } 12041da177e4SLinus Torvalds return -ENODEV; 12051da177e4SLinus Torvalds } 1206