Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * IBM Hot Plug Controller Driver |
| 3 | * |
| 4 | * Written By: Tong Yu, IBM Corporation |
| 5 | * |
| 6 | * Copyright (C) 2001,2003 Greg Kroah-Hartman (greg@kroah.com) |
| 7 | * Copyright (C) 2001-2003 IBM Corp. |
| 8 | * |
| 9 | * All rights reserved. |
| 10 | * |
| 11 | * This program is free software; you can redistribute it and/or modify |
| 12 | * it under the terms of the GNU General Public License as published by |
| 13 | * the Free Software Foundation; either version 2 of the License, or (at |
| 14 | * your option) any later version. |
| 15 | * |
| 16 | * This program is distributed in the hope that it will be useful, but |
| 17 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or |
| 19 | * NON INFRINGEMENT. See the GNU General Public License for more |
| 20 | * details. |
| 21 | * |
| 22 | * You should have received a copy of the GNU General Public License |
| 23 | * along with this program; if not, write to the Free Software |
| 24 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 25 | * |
| 26 | * Send feedback to <gregkh@us.ibm.com> |
| 27 | * |
| 28 | */ |
| 29 | |
| 30 | #include <linux/module.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | #include <linux/errno.h> |
| 32 | #include <linux/mm.h> |
| 33 | #include <linux/slab.h> |
| 34 | #include <linux/pci.h> |
| 35 | #include <linux/list.h> |
| 36 | #include <linux/init.h> |
| 37 | #include "ibmphp.h" |
| 38 | |
| 39 | /* |
| 40 | * POST builds data blocks(in this data block definition, a char-1 |
| 41 | * byte, short(or word)-2 byte, long(dword)-4 byte) in the Extended |
| 42 | * BIOS Data Area which describe the configuration of the hot-plug |
| 43 | * controllers and resources used by the PCI Hot-Plug devices. |
| 44 | * |
| 45 | * This file walks EBDA, maps data block from physical addr, |
| 46 | * reconstruct linked lists about all system resource(MEM, PFM, IO) |
| 47 | * already assigned by POST, as well as linked lists about hot plug |
| 48 | * controllers (ctlr#, slot#, bus&slot features...) |
| 49 | */ |
| 50 | |
| 51 | /* Global lists */ |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 52 | LIST_HEAD(ibmphp_ebda_pci_rsrc_head); |
| 53 | LIST_HEAD(ibmphp_slot_head); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | |
| 55 | /* Local variables */ |
| 56 | static struct ebda_hpc_list *hpc_list_ptr; |
| 57 | static struct ebda_rsrc_list *rsrc_list_ptr; |
| 58 | static struct rio_table_hdr *rio_table_ptr = NULL; |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 59 | static LIST_HEAD(ebda_hpc_head); |
| 60 | static LIST_HEAD(bus_info_head); |
| 61 | static LIST_HEAD(rio_vg_head); |
| 62 | static LIST_HEAD(rio_lo_head); |
| 63 | static LIST_HEAD(opt_vg_head); |
| 64 | static LIST_HEAD(opt_lo_head); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | static void __iomem *io_mem; |
| 66 | |
| 67 | /* Local functions */ |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 68 | static int ebda_rsrc_controller(void); |
| 69 | static int ebda_rsrc_rsrc(void); |
| 70 | static int ebda_rio_table(void); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 72 | static struct ebda_hpc_list * __init alloc_ebda_hpc_list(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | { |
Eric Sesterhenn | f5afe80 | 2006-02-28 15:34:49 +0100 | [diff] [blame] | 74 | return kzalloc(sizeof(struct ebda_hpc_list), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | } |
| 76 | |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 77 | static struct controller *alloc_ebda_hpc(u32 slot_count, u32 bus_count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | { |
| 79 | struct controller *controller; |
| 80 | struct ebda_hpc_slot *slots; |
| 81 | struct ebda_hpc_bus *buses; |
| 82 | |
Eric Sesterhenn | f5afe80 | 2006-02-28 15:34:49 +0100 | [diff] [blame] | 83 | controller = kzalloc(sizeof(struct controller), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | if (!controller) |
| 85 | goto error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | |
Eric Sesterhenn | f5afe80 | 2006-02-28 15:34:49 +0100 | [diff] [blame] | 87 | slots = kcalloc(slot_count, sizeof(struct ebda_hpc_slot), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | if (!slots) |
| 89 | goto error_contr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | controller->slots = slots; |
| 91 | |
Eric Sesterhenn | f5afe80 | 2006-02-28 15:34:49 +0100 | [diff] [blame] | 92 | buses = kcalloc(bus_count, sizeof(struct ebda_hpc_bus), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | if (!buses) |
| 94 | goto error_slots; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | controller->buses = buses; |
| 96 | |
| 97 | return controller; |
| 98 | error_slots: |
| 99 | kfree(controller->slots); |
| 100 | error_contr: |
| 101 | kfree(controller); |
| 102 | error: |
| 103 | return NULL; |
| 104 | } |
| 105 | |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 106 | static void free_ebda_hpc(struct controller *controller) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | { |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 108 | kfree(controller->slots); |
| 109 | kfree(controller->buses); |
| 110 | kfree(controller); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | } |
| 112 | |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 113 | static struct ebda_rsrc_list * __init alloc_ebda_rsrc_list(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | { |
Eric Sesterhenn | f5afe80 | 2006-02-28 15:34:49 +0100 | [diff] [blame] | 115 | return kzalloc(sizeof(struct ebda_rsrc_list), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | } |
| 117 | |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 118 | static struct ebda_pci_rsrc *alloc_ebda_pci_rsrc(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | { |
Eric Sesterhenn | f5afe80 | 2006-02-28 15:34:49 +0100 | [diff] [blame] | 120 | return kzalloc(sizeof(struct ebda_pci_rsrc), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | } |
| 122 | |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 123 | static void __init print_bus_info(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | { |
| 125 | struct bus_info *ptr; |
Bjorn Helgaas | f762598 | 2013-11-14 11:28:18 -0700 | [diff] [blame] | 126 | |
akpm@linux-foundation.org | 2fd39aa | 2008-08-22 13:30:14 -0700 | [diff] [blame] | 127 | list_for_each_entry(ptr, &bus_info_head, bus_info_list) { |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 128 | debug("%s - slot_min = %x\n", __func__, ptr->slot_min); |
| 129 | debug("%s - slot_max = %x\n", __func__, ptr->slot_max); |
| 130 | debug("%s - slot_count = %x\n", __func__, ptr->slot_count); |
| 131 | debug("%s - bus# = %x\n", __func__, ptr->busno); |
| 132 | debug("%s - current_speed = %x\n", __func__, ptr->current_speed); |
| 133 | debug("%s - controller_id = %x\n", __func__, ptr->controller_id); |
Bjorn Helgaas | f762598 | 2013-11-14 11:28:18 -0700 | [diff] [blame] | 134 | |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 135 | debug("%s - slots_at_33_conv = %x\n", __func__, ptr->slots_at_33_conv); |
| 136 | debug("%s - slots_at_66_conv = %x\n", __func__, ptr->slots_at_66_conv); |
| 137 | debug("%s - slots_at_66_pcix = %x\n", __func__, ptr->slots_at_66_pcix); |
| 138 | debug("%s - slots_at_100_pcix = %x\n", __func__, ptr->slots_at_100_pcix); |
| 139 | debug("%s - slots_at_133_pcix = %x\n", __func__, ptr->slots_at_133_pcix); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | |
| 141 | } |
| 142 | } |
| 143 | |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 144 | static void print_lo_info(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | { |
| 146 | struct rio_detail *ptr; |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 147 | debug("print_lo_info ----\n"); |
akpm@linux-foundation.org | 2fd39aa | 2008-08-22 13:30:14 -0700 | [diff] [blame] | 148 | list_for_each_entry(ptr, &rio_lo_head, rio_detail_list) { |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 149 | debug("%s - rio_node_id = %x\n", __func__, ptr->rio_node_id); |
| 150 | debug("%s - rio_type = %x\n", __func__, ptr->rio_type); |
| 151 | debug("%s - owner_id = %x\n", __func__, ptr->owner_id); |
| 152 | debug("%s - first_slot_num = %x\n", __func__, ptr->first_slot_num); |
| 153 | debug("%s - wpindex = %x\n", __func__, ptr->wpindex); |
| 154 | debug("%s - chassis_num = %x\n", __func__, ptr->chassis_num); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | |
| 156 | } |
| 157 | } |
| 158 | |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 159 | static void print_vg_info(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | { |
| 161 | struct rio_detail *ptr; |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 162 | debug("%s ---\n", __func__); |
akpm@linux-foundation.org | 2fd39aa | 2008-08-22 13:30:14 -0700 | [diff] [blame] | 163 | list_for_each_entry(ptr, &rio_vg_head, rio_detail_list) { |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 164 | debug("%s - rio_node_id = %x\n", __func__, ptr->rio_node_id); |
| 165 | debug("%s - rio_type = %x\n", __func__, ptr->rio_type); |
| 166 | debug("%s - owner_id = %x\n", __func__, ptr->owner_id); |
| 167 | debug("%s - first_slot_num = %x\n", __func__, ptr->first_slot_num); |
| 168 | debug("%s - wpindex = %x\n", __func__, ptr->wpindex); |
| 169 | debug("%s - chassis_num = %x\n", __func__, ptr->chassis_num); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | |
| 171 | } |
| 172 | } |
| 173 | |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 174 | static void __init print_ebda_pci_rsrc(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | { |
| 176 | struct ebda_pci_rsrc *ptr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | |
akpm@linux-foundation.org | 2fd39aa | 2008-08-22 13:30:14 -0700 | [diff] [blame] | 178 | list_for_each_entry(ptr, &ibmphp_ebda_pci_rsrc_head, ebda_pci_rsrc_list) { |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 179 | debug("%s - rsrc type: %x bus#: %x dev_func: %x start addr: %x end addr: %x\n", |
| 180 | __func__, ptr->rsrc_type, ptr->bus_num, ptr->dev_fun, ptr->start_addr, ptr->end_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | } |
| 182 | } |
| 183 | |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 184 | static void __init print_ibm_slot(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | { |
| 186 | struct slot *ptr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | |
akpm@linux-foundation.org | 2fd39aa | 2008-08-22 13:30:14 -0700 | [diff] [blame] | 188 | list_for_each_entry(ptr, &ibmphp_slot_head, ibm_slot_list) { |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 189 | debug("%s - slot_number: %x\n", __func__, ptr->number); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | } |
| 191 | } |
| 192 | |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 193 | static void __init print_opt_vg(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | { |
| 195 | struct opt_rio *ptr; |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 196 | debug("%s ---\n", __func__); |
akpm@linux-foundation.org | 2fd39aa | 2008-08-22 13:30:14 -0700 | [diff] [blame] | 197 | list_for_each_entry(ptr, &opt_vg_head, opt_rio_list) { |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 198 | debug("%s - rio_type %x\n", __func__, ptr->rio_type); |
| 199 | debug("%s - chassis_num: %x\n", __func__, ptr->chassis_num); |
| 200 | debug("%s - first_slot_num: %x\n", __func__, ptr->first_slot_num); |
| 201 | debug("%s - middle_num: %x\n", __func__, ptr->middle_num); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | } |
| 203 | } |
| 204 | |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 205 | static void __init print_ebda_hpc(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 | { |
| 207 | struct controller *hpc_ptr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | u16 index; |
| 209 | |
akpm@linux-foundation.org | 2fd39aa | 2008-08-22 13:30:14 -0700 | [diff] [blame] | 210 | list_for_each_entry(hpc_ptr, &ebda_hpc_head, ebda_hpc_list) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | for (index = 0; index < hpc_ptr->slot_count; index++) { |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 212 | debug("%s - physical slot#: %x\n", __func__, hpc_ptr->slots[index].slot_num); |
| 213 | debug("%s - pci bus# of the slot: %x\n", __func__, hpc_ptr->slots[index].slot_bus_num); |
| 214 | debug("%s - index into ctlr addr: %x\n", __func__, hpc_ptr->slots[index].ctl_index); |
| 215 | debug("%s - cap of the slot: %x\n", __func__, hpc_ptr->slots[index].slot_cap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | } |
| 217 | |
Quentin Lambert | 656f978 | 2014-09-07 20:02:47 +0200 | [diff] [blame] | 218 | for (index = 0; index < hpc_ptr->bus_count; index++) |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 219 | debug("%s - bus# of each bus controlled by this ctlr: %x\n", __func__, hpc_ptr->buses[index].bus_num); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 221 | debug("%s - type of hpc: %x\n", __func__, hpc_ptr->ctlr_type); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | switch (hpc_ptr->ctlr_type) { |
| 223 | case 1: |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 224 | debug("%s - bus: %x\n", __func__, hpc_ptr->u.pci_ctlr.bus); |
| 225 | debug("%s - dev_fun: %x\n", __func__, hpc_ptr->u.pci_ctlr.dev_fun); |
| 226 | debug("%s - irq: %x\n", __func__, hpc_ptr->irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | break; |
| 228 | |
| 229 | case 0: |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 230 | debug("%s - io_start: %x\n", __func__, hpc_ptr->u.isa_ctlr.io_start); |
| 231 | debug("%s - io_end: %x\n", __func__, hpc_ptr->u.isa_ctlr.io_end); |
| 232 | debug("%s - irq: %x\n", __func__, hpc_ptr->irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | break; |
| 234 | |
| 235 | case 2: |
| 236 | case 4: |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 237 | debug("%s - wpegbbar: %lx\n", __func__, hpc_ptr->u.wpeg_ctlr.wpegbbar); |
| 238 | debug("%s - i2c_addr: %x\n", __func__, hpc_ptr->u.wpeg_ctlr.i2c_addr); |
| 239 | debug("%s - irq: %x\n", __func__, hpc_ptr->irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 | break; |
| 241 | } |
| 242 | } |
| 243 | } |
| 244 | |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 245 | int __init ibmphp_access_ebda(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 | { |
Chandru | b0fc889 | 2010-01-11 11:49:21 +0530 | [diff] [blame] | 247 | u8 format, num_ctlrs, rio_complete, hs_complete, ebda_sz; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | u16 ebda_seg, num_entries, next_offset, offset, blk_id, sub_addr, re, rc_id, re_id, base; |
| 249 | int rc = 0; |
| 250 | |
| 251 | |
| 252 | rio_complete = 0; |
| 253 | hs_complete = 0; |
| 254 | |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 255 | io_mem = ioremap((0x40 << 4) + 0x0e, 2); |
| 256 | if (!io_mem) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 | return -ENOMEM; |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 258 | ebda_seg = readw(io_mem); |
| 259 | iounmap(io_mem); |
| 260 | debug("returned ebda segment: %x\n", ebda_seg); |
Bjorn Helgaas | f762598 | 2013-11-14 11:28:18 -0700 | [diff] [blame] | 261 | |
Chandru | b0fc889 | 2010-01-11 11:49:21 +0530 | [diff] [blame] | 262 | io_mem = ioremap(ebda_seg<<4, 1); |
Andrew Morton | ba02b24 | 2010-02-02 14:45:54 -0800 | [diff] [blame] | 263 | if (!io_mem) |
| 264 | return -ENOMEM; |
Chandru | b0fc889 | 2010-01-11 11:49:21 +0530 | [diff] [blame] | 265 | ebda_sz = readb(io_mem); |
| 266 | iounmap(io_mem); |
| 267 | debug("ebda size: %d(KiB)\n", ebda_sz); |
| 268 | if (ebda_sz == 0) |
| 269 | return -ENOMEM; |
| 270 | |
| 271 | io_mem = ioremap(ebda_seg<<4, (ebda_sz * 1024)); |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 272 | if (!io_mem) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 273 | return -ENOMEM; |
| 274 | next_offset = 0x180; |
| 275 | |
| 276 | for (;;) { |
| 277 | offset = next_offset; |
Steven Rostedt | ac3abf2 | 2010-11-08 23:20:27 -0500 | [diff] [blame] | 278 | |
| 279 | /* Make sure what we read is still in the mapped section */ |
| 280 | if (WARN(offset > (ebda_sz * 1024 - 4), |
| 281 | "ibmphp_ebda: next read is beyond ebda_sz\n")) |
| 282 | break; |
| 283 | |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 284 | next_offset = readw(io_mem + offset); /* offset of next blk */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | |
| 286 | offset += 2; |
| 287 | if (next_offset == 0) /* 0 indicate it's last blk */ |
| 288 | break; |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 289 | blk_id = readw(io_mem + offset); /* this blk id */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | |
| 291 | offset += 2; |
| 292 | /* check if it is hot swap block or rio block */ |
| 293 | if (blk_id != 0x4853 && blk_id != 0x4752) |
| 294 | continue; |
| 295 | /* found hs table */ |
| 296 | if (blk_id == 0x4853) { |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 297 | debug("now enter hot swap block---\n"); |
| 298 | debug("hot blk id: %x\n", blk_id); |
| 299 | format = readb(io_mem + offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 300 | |
| 301 | offset += 1; |
| 302 | if (format != 4) |
| 303 | goto error_nodev; |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 304 | debug("hot blk format: %x\n", format); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 305 | /* hot swap sub blk */ |
| 306 | base = offset; |
| 307 | |
| 308 | sub_addr = base; |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 309 | re = readw(io_mem + sub_addr); /* next sub blk */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 310 | |
| 311 | sub_addr += 2; |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 312 | rc_id = readw(io_mem + sub_addr); /* sub blk id */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 313 | |
| 314 | sub_addr += 2; |
| 315 | if (rc_id != 0x5243) |
| 316 | goto error_nodev; |
| 317 | /* rc sub blk signature */ |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 318 | num_ctlrs = readb(io_mem + sub_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 | |
| 320 | sub_addr += 1; |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 321 | hpc_list_ptr = alloc_ebda_hpc_list(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 322 | if (!hpc_list_ptr) { |
| 323 | rc = -ENOMEM; |
| 324 | goto out; |
| 325 | } |
| 326 | hpc_list_ptr->format = format; |
| 327 | hpc_list_ptr->num_ctlrs = num_ctlrs; |
| 328 | hpc_list_ptr->phys_addr = sub_addr; /* offset of RSRC_CONTROLLER blk */ |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 329 | debug("info about hpc descriptor---\n"); |
| 330 | debug("hot blk format: %x\n", format); |
| 331 | debug("num of controller: %x\n", num_ctlrs); |
| 332 | debug("offset of hpc data structure entries: %x\n ", sub_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 333 | |
| 334 | sub_addr = base + re; /* re sub blk */ |
| 335 | /* FIXME: rc is never used/checked */ |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 336 | rc = readw(io_mem + sub_addr); /* next sub blk */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 337 | |
| 338 | sub_addr += 2; |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 339 | re_id = readw(io_mem + sub_addr); /* sub blk id */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | |
| 341 | sub_addr += 2; |
| 342 | if (re_id != 0x5245) |
| 343 | goto error_nodev; |
| 344 | |
| 345 | /* signature of re */ |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 346 | num_entries = readw(io_mem + sub_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 347 | |
| 348 | sub_addr += 2; /* offset of RSRC_ENTRIES blk */ |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 349 | rsrc_list_ptr = alloc_ebda_rsrc_list(); |
| 350 | if (!rsrc_list_ptr) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 351 | rc = -ENOMEM; |
| 352 | goto out; |
| 353 | } |
| 354 | rsrc_list_ptr->format = format; |
| 355 | rsrc_list_ptr->num_entries = num_entries; |
| 356 | rsrc_list_ptr->phys_addr = sub_addr; |
| 357 | |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 358 | debug("info about rsrc descriptor---\n"); |
| 359 | debug("format: %x\n", format); |
| 360 | debug("num of rsrc: %x\n", num_entries); |
| 361 | debug("offset of rsrc data structure entries: %x\n ", sub_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 362 | |
| 363 | hs_complete = 1; |
| 364 | } else { |
| 365 | /* found rio table, blk_id == 0x4752 */ |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 366 | debug("now enter io table ---\n"); |
| 367 | debug("rio blk id: %x\n", blk_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 | |
Eric Sesterhenn | f5afe80 | 2006-02-28 15:34:49 +0100 | [diff] [blame] | 369 | rio_table_ptr = kzalloc(sizeof(struct rio_table_hdr), GFP_KERNEL); |
Julia Lawall | 8f0cddd | 2012-01-12 10:55:16 +0100 | [diff] [blame] | 370 | if (!rio_table_ptr) { |
| 371 | rc = -ENOMEM; |
| 372 | goto out; |
| 373 | } |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 374 | rio_table_ptr->ver_num = readb(io_mem + offset); |
| 375 | rio_table_ptr->scal_count = readb(io_mem + offset + 1); |
| 376 | rio_table_ptr->riodev_count = readb(io_mem + offset + 2); |
| 377 | rio_table_ptr->offset = offset + 3 ; |
Bjorn Helgaas | f762598 | 2013-11-14 11:28:18 -0700 | [diff] [blame] | 378 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 379 | debug("info about rio table hdr ---\n"); |
| 380 | debug("ver_num: %x\nscal_count: %x\nriodev_count: %x\noffset of rio table: %x\n ", |
| 381 | rio_table_ptr->ver_num, rio_table_ptr->scal_count, |
| 382 | rio_table_ptr->riodev_count, rio_table_ptr->offset); |
| 383 | |
| 384 | rio_complete = 1; |
| 385 | } |
| 386 | } |
| 387 | |
| 388 | if (!hs_complete && !rio_complete) |
| 389 | goto error_nodev; |
| 390 | |
| 391 | if (rio_table_ptr) { |
| 392 | if (rio_complete && rio_table_ptr->ver_num == 3) { |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 393 | rc = ebda_rio_table(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 394 | if (rc) |
| 395 | goto out; |
| 396 | } |
| 397 | } |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 398 | rc = ebda_rsrc_controller(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 399 | if (rc) |
| 400 | goto out; |
| 401 | |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 402 | rc = ebda_rsrc_rsrc(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 403 | goto out; |
| 404 | error_nodev: |
| 405 | rc = -ENODEV; |
| 406 | out: |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 407 | iounmap(io_mem); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 408 | return rc; |
| 409 | } |
| 410 | |
| 411 | /* |
| 412 | * map info of scalability details and rio details from physical address |
| 413 | */ |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 414 | static int __init ebda_rio_table(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 415 | { |
| 416 | u16 offset; |
| 417 | u8 i; |
| 418 | struct rio_detail *rio_detail_ptr; |
| 419 | |
| 420 | offset = rio_table_ptr->offset; |
| 421 | offset += 12 * rio_table_ptr->scal_count; |
| 422 | |
| 423 | // we do concern about rio details |
| 424 | for (i = 0; i < rio_table_ptr->riodev_count; i++) { |
Eric Sesterhenn | f5afe80 | 2006-02-28 15:34:49 +0100 | [diff] [blame] | 425 | rio_detail_ptr = kzalloc(sizeof(struct rio_detail), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 426 | if (!rio_detail_ptr) |
| 427 | return -ENOMEM; |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 428 | rio_detail_ptr->rio_node_id = readb(io_mem + offset); |
| 429 | rio_detail_ptr->bbar = readl(io_mem + offset + 1); |
| 430 | rio_detail_ptr->rio_type = readb(io_mem + offset + 5); |
| 431 | rio_detail_ptr->owner_id = readb(io_mem + offset + 6); |
| 432 | rio_detail_ptr->port0_node_connect = readb(io_mem + offset + 7); |
| 433 | rio_detail_ptr->port0_port_connect = readb(io_mem + offset + 8); |
| 434 | rio_detail_ptr->port1_node_connect = readb(io_mem + offset + 9); |
| 435 | rio_detail_ptr->port1_port_connect = readb(io_mem + offset + 10); |
| 436 | rio_detail_ptr->first_slot_num = readb(io_mem + offset + 11); |
| 437 | rio_detail_ptr->status = readb(io_mem + offset + 12); |
| 438 | rio_detail_ptr->wpindex = readb(io_mem + offset + 13); |
| 439 | rio_detail_ptr->chassis_num = readb(io_mem + offset + 14); |
| 440 | // 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); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 441 | //create linked list of chassis |
Bjorn Helgaas | f762598 | 2013-11-14 11:28:18 -0700 | [diff] [blame] | 442 | if (rio_detail_ptr->rio_type == 4 || rio_detail_ptr->rio_type == 5) |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 443 | list_add(&rio_detail_ptr->rio_detail_list, &rio_vg_head); |
Bjorn Helgaas | f762598 | 2013-11-14 11:28:18 -0700 | [diff] [blame] | 444 | //create linked list of expansion box |
| 445 | else if (rio_detail_ptr->rio_type == 6 || rio_detail_ptr->rio_type == 7) |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 446 | list_add(&rio_detail_ptr->rio_detail_list, &rio_lo_head); |
Bjorn Helgaas | f762598 | 2013-11-14 11:28:18 -0700 | [diff] [blame] | 447 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 448 | // not in my concern |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 449 | kfree(rio_detail_ptr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 450 | offset += 15; |
| 451 | } |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 452 | print_lo_info(); |
| 453 | print_vg_info(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 454 | return 0; |
| 455 | } |
| 456 | |
| 457 | /* |
Bjorn Helgaas | f762598 | 2013-11-14 11:28:18 -0700 | [diff] [blame] | 458 | * reorganizing linked list of chassis |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 459 | */ |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 460 | static struct opt_rio *search_opt_vg(u8 chassis_num) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 461 | { |
| 462 | struct opt_rio *ptr; |
akpm@linux-foundation.org | 2fd39aa | 2008-08-22 13:30:14 -0700 | [diff] [blame] | 463 | list_for_each_entry(ptr, &opt_vg_head, opt_rio_list) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 464 | if (ptr->chassis_num == chassis_num) |
| 465 | return ptr; |
Bjorn Helgaas | f762598 | 2013-11-14 11:28:18 -0700 | [diff] [blame] | 466 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 467 | return NULL; |
| 468 | } |
| 469 | |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 470 | static int __init combine_wpg_for_chassis(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 471 | { |
| 472 | struct opt_rio *opt_rio_ptr = NULL; |
| 473 | struct rio_detail *rio_detail_ptr = NULL; |
Bjorn Helgaas | f762598 | 2013-11-14 11:28:18 -0700 | [diff] [blame] | 474 | |
akpm@linux-foundation.org | 2fd39aa | 2008-08-22 13:30:14 -0700 | [diff] [blame] | 475 | list_for_each_entry(rio_detail_ptr, &rio_vg_head, rio_detail_list) { |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 476 | opt_rio_ptr = search_opt_vg(rio_detail_ptr->chassis_num); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 477 | if (!opt_rio_ptr) { |
Eric Sesterhenn | f5afe80 | 2006-02-28 15:34:49 +0100 | [diff] [blame] | 478 | opt_rio_ptr = kzalloc(sizeof(struct opt_rio), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 479 | if (!opt_rio_ptr) |
| 480 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 481 | opt_rio_ptr->rio_type = rio_detail_ptr->rio_type; |
| 482 | opt_rio_ptr->chassis_num = rio_detail_ptr->chassis_num; |
| 483 | opt_rio_ptr->first_slot_num = rio_detail_ptr->first_slot_num; |
| 484 | opt_rio_ptr->middle_num = rio_detail_ptr->first_slot_num; |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 485 | list_add(&opt_rio_ptr->opt_rio_list, &opt_vg_head); |
Bjorn Helgaas | f762598 | 2013-11-14 11:28:18 -0700 | [diff] [blame] | 486 | } else { |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 487 | opt_rio_ptr->first_slot_num = min(opt_rio_ptr->first_slot_num, rio_detail_ptr->first_slot_num); |
| 488 | opt_rio_ptr->middle_num = max(opt_rio_ptr->middle_num, rio_detail_ptr->first_slot_num); |
Bjorn Helgaas | f762598 | 2013-11-14 11:28:18 -0700 | [diff] [blame] | 489 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 490 | } |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 491 | print_opt_vg(); |
Bjorn Helgaas | f762598 | 2013-11-14 11:28:18 -0700 | [diff] [blame] | 492 | return 0; |
| 493 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 494 | |
| 495 | /* |
akpm@linux-foundation.org | a8d2dbd | 2008-08-22 13:28:17 -0700 | [diff] [blame] | 496 | * reorganizing linked list of expansion box |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 497 | */ |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 498 | static struct opt_rio_lo *search_opt_lo(u8 chassis_num) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 499 | { |
| 500 | struct opt_rio_lo *ptr; |
akpm@linux-foundation.org | 2fd39aa | 2008-08-22 13:30:14 -0700 | [diff] [blame] | 501 | list_for_each_entry(ptr, &opt_lo_head, opt_rio_lo_list) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 502 | if (ptr->chassis_num == chassis_num) |
| 503 | return ptr; |
Bjorn Helgaas | f762598 | 2013-11-14 11:28:18 -0700 | [diff] [blame] | 504 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 505 | return NULL; |
| 506 | } |
| 507 | |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 508 | static int combine_wpg_for_expansion(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 509 | { |
| 510 | struct opt_rio_lo *opt_rio_lo_ptr = NULL; |
| 511 | struct rio_detail *rio_detail_ptr = NULL; |
Bjorn Helgaas | f762598 | 2013-11-14 11:28:18 -0700 | [diff] [blame] | 512 | |
akpm@linux-foundation.org | 2fd39aa | 2008-08-22 13:30:14 -0700 | [diff] [blame] | 513 | list_for_each_entry(rio_detail_ptr, &rio_lo_head, rio_detail_list) { |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 514 | opt_rio_lo_ptr = search_opt_lo(rio_detail_ptr->chassis_num); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 515 | if (!opt_rio_lo_ptr) { |
Eric Sesterhenn | f5afe80 | 2006-02-28 15:34:49 +0100 | [diff] [blame] | 516 | opt_rio_lo_ptr = kzalloc(sizeof(struct opt_rio_lo), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 517 | if (!opt_rio_lo_ptr) |
| 518 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 519 | opt_rio_lo_ptr->rio_type = rio_detail_ptr->rio_type; |
| 520 | opt_rio_lo_ptr->chassis_num = rio_detail_ptr->chassis_num; |
| 521 | opt_rio_lo_ptr->first_slot_num = rio_detail_ptr->first_slot_num; |
| 522 | opt_rio_lo_ptr->middle_num = rio_detail_ptr->first_slot_num; |
| 523 | opt_rio_lo_ptr->pack_count = 1; |
Bjorn Helgaas | f762598 | 2013-11-14 11:28:18 -0700 | [diff] [blame] | 524 | |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 525 | list_add(&opt_rio_lo_ptr->opt_rio_lo_list, &opt_lo_head); |
Bjorn Helgaas | f762598 | 2013-11-14 11:28:18 -0700 | [diff] [blame] | 526 | } else { |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 527 | opt_rio_lo_ptr->first_slot_num = min(opt_rio_lo_ptr->first_slot_num, rio_detail_ptr->first_slot_num); |
| 528 | opt_rio_lo_ptr->middle_num = max(opt_rio_lo_ptr->middle_num, rio_detail_ptr->first_slot_num); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 529 | opt_rio_lo_ptr->pack_count = 2; |
Bjorn Helgaas | f762598 | 2013-11-14 11:28:18 -0700 | [diff] [blame] | 530 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 531 | } |
Bjorn Helgaas | f762598 | 2013-11-14 11:28:18 -0700 | [diff] [blame] | 532 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 533 | } |
Bjorn Helgaas | f762598 | 2013-11-14 11:28:18 -0700 | [diff] [blame] | 534 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 535 | |
| 536 | /* Since we don't know the max slot number per each chassis, hence go |
| 537 | * through the list of all chassis to find out the range |
Bjorn Helgaas | f762598 | 2013-11-14 11:28:18 -0700 | [diff] [blame] | 538 | * Arguments: slot_num, 1st slot number of the chassis we think we are on, |
| 539 | * var (0 = chassis, 1 = expansion box) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 540 | */ |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 541 | static int first_slot_num(u8 slot_num, u8 first_slot, u8 var) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 542 | { |
| 543 | struct opt_rio *opt_vg_ptr = NULL; |
| 544 | struct opt_rio_lo *opt_lo_ptr = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 545 | int rc = 0; |
| 546 | |
| 547 | if (!var) { |
akpm@linux-foundation.org | 2fd39aa | 2008-08-22 13:30:14 -0700 | [diff] [blame] | 548 | list_for_each_entry(opt_vg_ptr, &opt_vg_head, opt_rio_list) { |
Bjorn Helgaas | f762598 | 2013-11-14 11:28:18 -0700 | [diff] [blame] | 549 | if ((first_slot < opt_vg_ptr->first_slot_num) && (slot_num >= opt_vg_ptr->first_slot_num)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 550 | rc = -ENODEV; |
| 551 | break; |
| 552 | } |
| 553 | } |
| 554 | } else { |
akpm@linux-foundation.org | 2fd39aa | 2008-08-22 13:30:14 -0700 | [diff] [blame] | 555 | list_for_each_entry(opt_lo_ptr, &opt_lo_head, opt_rio_lo_list) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 556 | if ((first_slot < opt_lo_ptr->first_slot_num) && (slot_num >= opt_lo_ptr->first_slot_num)) { |
| 557 | rc = -ENODEV; |
| 558 | break; |
| 559 | } |
| 560 | } |
| 561 | } |
| 562 | return rc; |
| 563 | } |
| 564 | |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 565 | static struct opt_rio_lo *find_rxe_num(u8 slot_num) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 566 | { |
| 567 | struct opt_rio_lo *opt_lo_ptr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 568 | |
akpm@linux-foundation.org | 2fd39aa | 2008-08-22 13:30:14 -0700 | [diff] [blame] | 569 | list_for_each_entry(opt_lo_ptr, &opt_lo_head, opt_rio_lo_list) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 570 | //check to see if this slot_num belongs to expansion box |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 571 | if ((slot_num >= opt_lo_ptr->first_slot_num) && (!first_slot_num(slot_num, opt_lo_ptr->first_slot_num, 1))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 572 | return opt_lo_ptr; |
| 573 | } |
| 574 | return NULL; |
| 575 | } |
| 576 | |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 577 | static struct opt_rio *find_chassis_num(u8 slot_num) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 578 | { |
| 579 | struct opt_rio *opt_vg_ptr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 580 | |
akpm@linux-foundation.org | 2fd39aa | 2008-08-22 13:30:14 -0700 | [diff] [blame] | 581 | list_for_each_entry(opt_vg_ptr, &opt_vg_head, opt_rio_list) { |
Bjorn Helgaas | f762598 | 2013-11-14 11:28:18 -0700 | [diff] [blame] | 582 | //check to see if this slot_num belongs to chassis |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 583 | if ((slot_num >= opt_vg_ptr->first_slot_num) && (!first_slot_num(slot_num, opt_vg_ptr->first_slot_num, 0))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 584 | return opt_vg_ptr; |
| 585 | } |
| 586 | return NULL; |
| 587 | } |
| 588 | |
| 589 | /* This routine will find out how many slots are in the chassis, so that |
| 590 | * the slot numbers for rxe100 would start from 1, and not from 7, or 6 etc |
| 591 | */ |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 592 | static u8 calculate_first_slot(u8 slot_num) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 593 | { |
| 594 | u8 first_slot = 1; |
Ryan Desfosses | 3c78bc6 | 2014-04-18 20:13:49 -0400 | [diff] [blame] | 595 | struct slot *slot_cur; |
Bjorn Helgaas | f762598 | 2013-11-14 11:28:18 -0700 | [diff] [blame] | 596 | |
akpm@linux-foundation.org | 2fd39aa | 2008-08-22 13:30:14 -0700 | [diff] [blame] | 597 | list_for_each_entry(slot_cur, &ibmphp_slot_head, ibm_slot_list) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 598 | if (slot_cur->ctrl) { |
Bjorn Helgaas | f762598 | 2013-11-14 11:28:18 -0700 | [diff] [blame] | 599 | if ((slot_cur->ctrl->ctlr_type != 4) && (slot_cur->ctrl->ending_slot_num > first_slot) && (slot_num > slot_cur->ctrl->ending_slot_num)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 600 | first_slot = slot_cur->ctrl->ending_slot_num; |
| 601 | } |
Bjorn Helgaas | f762598 | 2013-11-14 11:28:18 -0700 | [diff] [blame] | 602 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 603 | return first_slot + 1; |
| 604 | |
| 605 | } |
Alex Chiang | a32615a | 2008-10-20 17:41:33 -0600 | [diff] [blame] | 606 | |
| 607 | #define SLOT_NAME_SIZE 30 |
| 608 | |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 609 | static char *create_file_name(struct slot *slot_cur) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 610 | { |
| 611 | struct opt_rio *opt_vg_ptr = NULL; |
| 612 | struct opt_rio_lo *opt_lo_ptr = NULL; |
Alex Chiang | a32615a | 2008-10-20 17:41:33 -0600 | [diff] [blame] | 613 | static char str[SLOT_NAME_SIZE]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 614 | int which = 0; /* rxe = 1, chassis = 0 */ |
| 615 | u8 number = 1; /* either chassis or rxe # */ |
| 616 | u8 first_slot = 1; |
| 617 | u8 slot_num; |
| 618 | u8 flag = 0; |
| 619 | |
| 620 | if (!slot_cur) { |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 621 | err("Structure passed is empty\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 622 | return NULL; |
| 623 | } |
Bjorn Helgaas | f762598 | 2013-11-14 11:28:18 -0700 | [diff] [blame] | 624 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 625 | slot_num = slot_cur->number; |
| 626 | |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 627 | memset(str, 0, sizeof(str)); |
Bjorn Helgaas | f762598 | 2013-11-14 11:28:18 -0700 | [diff] [blame] | 628 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 629 | if (rio_table_ptr) { |
| 630 | if (rio_table_ptr->ver_num == 3) { |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 631 | opt_vg_ptr = find_chassis_num(slot_num); |
| 632 | opt_lo_ptr = find_rxe_num(slot_num); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 633 | } |
| 634 | } |
| 635 | if (opt_vg_ptr) { |
| 636 | if (opt_lo_ptr) { |
| 637 | if ((slot_num - opt_vg_ptr->first_slot_num) > (slot_num - opt_lo_ptr->first_slot_num)) { |
| 638 | number = opt_lo_ptr->chassis_num; |
| 639 | first_slot = opt_lo_ptr->first_slot_num; |
| 640 | which = 1; /* it is RXE */ |
| 641 | } else { |
| 642 | first_slot = opt_vg_ptr->first_slot_num; |
| 643 | number = opt_vg_ptr->chassis_num; |
| 644 | which = 0; |
| 645 | } |
| 646 | } else { |
| 647 | first_slot = opt_vg_ptr->first_slot_num; |
| 648 | number = opt_vg_ptr->chassis_num; |
| 649 | which = 0; |
| 650 | } |
| 651 | ++flag; |
| 652 | } else if (opt_lo_ptr) { |
| 653 | number = opt_lo_ptr->chassis_num; |
| 654 | first_slot = opt_lo_ptr->first_slot_num; |
| 655 | which = 1; |
| 656 | ++flag; |
| 657 | } else if (rio_table_ptr) { |
| 658 | if (rio_table_ptr->ver_num == 3) { |
| 659 | /* if both NULL and we DO have correct RIO table in BIOS */ |
| 660 | return NULL; |
| 661 | } |
Bjorn Helgaas | f762598 | 2013-11-14 11:28:18 -0700 | [diff] [blame] | 662 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 663 | if (!flag) { |
| 664 | if (slot_cur->ctrl->ctlr_type == 4) { |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 665 | first_slot = calculate_first_slot(slot_num); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 666 | which = 1; |
| 667 | } else { |
| 668 | which = 0; |
| 669 | } |
| 670 | } |
| 671 | |
| 672 | sprintf(str, "%s%dslot%d", |
| 673 | which == 0 ? "chassis" : "rxe", |
| 674 | number, slot_num - first_slot + 1); |
| 675 | return str; |
| 676 | } |
| 677 | |
| 678 | static int fillslotinfo(struct hotplug_slot *hotplug_slot) |
| 679 | { |
| 680 | struct slot *slot; |
| 681 | int rc = 0; |
| 682 | |
| 683 | if (!hotplug_slot || !hotplug_slot->private) |
| 684 | return -EINVAL; |
| 685 | |
| 686 | slot = hotplug_slot->private; |
| 687 | rc = ibmphp_hpc_readslot(slot, READ_ALLSTAT, NULL); |
| 688 | if (rc) |
| 689 | return rc; |
| 690 | |
| 691 | // power - enabled:1 not:0 |
| 692 | hotplug_slot->info->power_status = SLOT_POWER(slot->status); |
| 693 | |
| 694 | // attention - off:0, on:1, blinking:2 |
| 695 | hotplug_slot->info->attention_status = SLOT_ATTN(slot->status, slot->ext_status); |
| 696 | |
| 697 | // latch - open:1 closed:0 |
| 698 | hotplug_slot->info->latch_status = SLOT_LATCH(slot->status); |
| 699 | |
| 700 | // pci board - present:1 not:0 |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 701 | if (SLOT_PRESENT(slot->status)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 702 | hotplug_slot->info->adapter_status = 1; |
| 703 | else |
| 704 | hotplug_slot->info->adapter_status = 0; |
| 705 | /* |
| 706 | if (slot->bus_on->supported_bus_mode |
| 707 | && (slot->bus_on->supported_speed == BUS_SPEED_66)) |
| 708 | hotplug_slot->info->max_bus_speed_status = BUS_SPEED_66PCIX; |
| 709 | else |
| 710 | hotplug_slot->info->max_bus_speed_status = slot->bus_on->supported_speed; |
| 711 | */ |
| 712 | |
| 713 | return rc; |
| 714 | } |
| 715 | |
| 716 | static void release_slot(struct hotplug_slot *hotplug_slot) |
| 717 | { |
| 718 | struct slot *slot; |
| 719 | |
| 720 | if (!hotplug_slot || !hotplug_slot->private) |
| 721 | return; |
| 722 | |
| 723 | slot = hotplug_slot->private; |
| 724 | kfree(slot->hotplug_slot->info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 725 | kfree(slot->hotplug_slot); |
| 726 | slot->ctrl = NULL; |
| 727 | slot->bus_on = NULL; |
| 728 | |
| 729 | /* we don't want to actually remove the resources, since free_resources will do just that */ |
| 730 | ibmphp_unconfigure_card(&slot, -1); |
| 731 | |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 732 | kfree(slot); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 733 | } |
| 734 | |
| 735 | static struct pci_driver ibmphp_driver; |
| 736 | |
| 737 | /* |
| 738 | * map info (ctlr-id, slot count, slot#.. bus count, bus#, ctlr type...) of |
| 739 | * each hpc from physical address to a list of hot plug controllers based on |
| 740 | * hpc descriptors. |
| 741 | */ |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 742 | static int __init ebda_rsrc_controller(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 743 | { |
| 744 | u16 addr, addr_slot, addr_bus; |
| 745 | u8 ctlr_id, temp, bus_index; |
| 746 | u16 ctlr, slot, bus; |
| 747 | u16 slot_num, bus_num, index; |
| 748 | struct hotplug_slot *hp_slot_ptr; |
| 749 | struct controller *hpc_ptr; |
| 750 | struct ebda_hpc_bus *bus_ptr; |
| 751 | struct ebda_hpc_slot *slot_ptr; |
| 752 | struct bus_info *bus_info_ptr1, *bus_info_ptr2; |
| 753 | int rc; |
| 754 | struct slot *tmp_slot; |
Alex Chiang | a32615a | 2008-10-20 17:41:33 -0600 | [diff] [blame] | 755 | char name[SLOT_NAME_SIZE]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 756 | |
| 757 | addr = hpc_list_ptr->phys_addr; |
| 758 | for (ctlr = 0; ctlr < hpc_list_ptr->num_ctlrs; ctlr++) { |
| 759 | bus_index = 1; |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 760 | ctlr_id = readb(io_mem + addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 761 | addr += 1; |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 762 | slot_num = readb(io_mem + addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 763 | |
| 764 | addr += 1; |
| 765 | addr_slot = addr; /* offset of slot structure */ |
| 766 | addr += (slot_num * 4); |
| 767 | |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 768 | bus_num = readb(io_mem + addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 769 | |
| 770 | addr += 1; |
| 771 | addr_bus = addr; /* offset of bus */ |
| 772 | addr += (bus_num * 9); /* offset of ctlr_type */ |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 773 | temp = readb(io_mem + addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 774 | |
| 775 | addr += 1; |
| 776 | /* init hpc structure */ |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 777 | hpc_ptr = alloc_ebda_hpc(slot_num, bus_num); |
| 778 | if (!hpc_ptr) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 779 | rc = -ENOMEM; |
| 780 | goto error_no_hpc; |
| 781 | } |
| 782 | hpc_ptr->ctlr_id = ctlr_id; |
| 783 | hpc_ptr->ctlr_relative_id = ctlr; |
| 784 | hpc_ptr->slot_count = slot_num; |
| 785 | hpc_ptr->bus_count = bus_num; |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 786 | debug("now enter ctlr data structure ---\n"); |
| 787 | debug("ctlr id: %x\n", ctlr_id); |
| 788 | debug("ctlr_relative_id: %x\n", hpc_ptr->ctlr_relative_id); |
| 789 | debug("count of slots controlled by this ctlr: %x\n", slot_num); |
| 790 | debug("count of buses controlled by this ctlr: %x\n", bus_num); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 791 | |
| 792 | /* init slot structure, fetch slot, bus, cap... */ |
| 793 | slot_ptr = hpc_ptr->slots; |
| 794 | for (slot = 0; slot < slot_num; slot++) { |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 795 | slot_ptr->slot_num = readb(io_mem + addr_slot); |
| 796 | slot_ptr->slot_bus_num = readb(io_mem + addr_slot + slot_num); |
| 797 | slot_ptr->ctl_index = readb(io_mem + addr_slot + 2*slot_num); |
| 798 | slot_ptr->slot_cap = readb(io_mem + addr_slot + 3*slot_num); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 799 | |
Bjorn Helgaas | f762598 | 2013-11-14 11:28:18 -0700 | [diff] [blame] | 800 | // create bus_info lined list --- if only one slot per bus: slot_min = slot_max |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 801 | |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 802 | bus_info_ptr2 = ibmphp_find_same_bus_num(slot_ptr->slot_bus_num); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 803 | if (!bus_info_ptr2) { |
Eric Sesterhenn | f5afe80 | 2006-02-28 15:34:49 +0100 | [diff] [blame] | 804 | bus_info_ptr1 = kzalloc(sizeof(struct bus_info), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 805 | if (!bus_info_ptr1) { |
| 806 | rc = -ENOMEM; |
| 807 | goto error_no_hp_slot; |
| 808 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 809 | bus_info_ptr1->slot_min = slot_ptr->slot_num; |
| 810 | bus_info_ptr1->slot_max = slot_ptr->slot_num; |
| 811 | bus_info_ptr1->slot_count += 1; |
| 812 | bus_info_ptr1->busno = slot_ptr->slot_bus_num; |
| 813 | bus_info_ptr1->index = bus_index++; |
| 814 | bus_info_ptr1->current_speed = 0xff; |
| 815 | bus_info_ptr1->current_bus_mode = 0xff; |
Bjorn Helgaas | f762598 | 2013-11-14 11:28:18 -0700 | [diff] [blame] | 816 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 817 | bus_info_ptr1->controller_id = hpc_ptr->ctlr_id; |
Bjorn Helgaas | f762598 | 2013-11-14 11:28:18 -0700 | [diff] [blame] | 818 | |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 819 | list_add_tail(&bus_info_ptr1->bus_info_list, &bus_info_head); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 820 | |
| 821 | } else { |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 822 | bus_info_ptr2->slot_min = min(bus_info_ptr2->slot_min, slot_ptr->slot_num); |
| 823 | bus_info_ptr2->slot_max = max(bus_info_ptr2->slot_max, slot_ptr->slot_num); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 824 | bus_info_ptr2->slot_count += 1; |
| 825 | |
| 826 | } |
| 827 | |
| 828 | // end of creating the bus_info linked list |
| 829 | |
| 830 | slot_ptr++; |
| 831 | addr_slot += 1; |
| 832 | } |
| 833 | |
| 834 | /* init bus structure */ |
| 835 | bus_ptr = hpc_ptr->buses; |
| 836 | for (bus = 0; bus < bus_num; bus++) { |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 837 | bus_ptr->bus_num = readb(io_mem + addr_bus + bus); |
| 838 | bus_ptr->slots_at_33_conv = readb(io_mem + addr_bus + bus_num + 8 * bus); |
| 839 | bus_ptr->slots_at_66_conv = readb(io_mem + addr_bus + bus_num + 8 * bus + 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 840 | |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 841 | bus_ptr->slots_at_66_pcix = readb(io_mem + addr_bus + bus_num + 8 * bus + 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 842 | |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 843 | bus_ptr->slots_at_100_pcix = readb(io_mem + addr_bus + bus_num + 8 * bus + 3); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 844 | |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 845 | bus_ptr->slots_at_133_pcix = readb(io_mem + addr_bus + bus_num + 8 * bus + 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 846 | |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 847 | bus_info_ptr2 = ibmphp_find_same_bus_num(bus_ptr->bus_num); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 848 | if (bus_info_ptr2) { |
| 849 | bus_info_ptr2->slots_at_33_conv = bus_ptr->slots_at_33_conv; |
| 850 | bus_info_ptr2->slots_at_66_conv = bus_ptr->slots_at_66_conv; |
| 851 | bus_info_ptr2->slots_at_66_pcix = bus_ptr->slots_at_66_pcix; |
| 852 | bus_info_ptr2->slots_at_100_pcix = bus_ptr->slots_at_100_pcix; |
Bjorn Helgaas | f762598 | 2013-11-14 11:28:18 -0700 | [diff] [blame] | 853 | bus_info_ptr2->slots_at_133_pcix = bus_ptr->slots_at_133_pcix; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 854 | } |
| 855 | bus_ptr++; |
| 856 | } |
| 857 | |
| 858 | hpc_ptr->ctlr_type = temp; |
| 859 | |
| 860 | switch (hpc_ptr->ctlr_type) { |
| 861 | case 1: |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 862 | hpc_ptr->u.pci_ctlr.bus = readb(io_mem + addr); |
| 863 | hpc_ptr->u.pci_ctlr.dev_fun = readb(io_mem + addr + 1); |
| 864 | hpc_ptr->irq = readb(io_mem + addr + 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 865 | addr += 3; |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 866 | debug("ctrl bus = %x, ctlr devfun = %x, irq = %x\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 867 | hpc_ptr->u.pci_ctlr.bus, |
| 868 | hpc_ptr->u.pci_ctlr.dev_fun, hpc_ptr->irq); |
| 869 | break; |
| 870 | |
| 871 | case 0: |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 872 | hpc_ptr->u.isa_ctlr.io_start = readw(io_mem + addr); |
| 873 | hpc_ptr->u.isa_ctlr.io_end = readw(io_mem + addr + 2); |
| 874 | if (!request_region(hpc_ptr->u.isa_ctlr.io_start, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 875 | (hpc_ptr->u.isa_ctlr.io_end - hpc_ptr->u.isa_ctlr.io_start + 1), |
| 876 | "ibmphp")) { |
| 877 | rc = -ENODEV; |
| 878 | goto error_no_hp_slot; |
| 879 | } |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 880 | hpc_ptr->irq = readb(io_mem + addr + 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 881 | addr += 5; |
| 882 | break; |
| 883 | |
| 884 | case 2: |
| 885 | case 4: |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 886 | hpc_ptr->u.wpeg_ctlr.wpegbbar = readl(io_mem + addr); |
| 887 | hpc_ptr->u.wpeg_ctlr.i2c_addr = readb(io_mem + addr + 4); |
| 888 | hpc_ptr->irq = readb(io_mem + addr + 5); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 889 | addr += 6; |
| 890 | break; |
| 891 | default: |
| 892 | rc = -ENODEV; |
| 893 | goto error_no_hp_slot; |
| 894 | } |
| 895 | |
| 896 | //reorganize chassis' linked list |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 897 | combine_wpg_for_chassis(); |
| 898 | combine_wpg_for_expansion(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 899 | hpc_ptr->revision = 0xff; |
| 900 | hpc_ptr->options = 0xff; |
| 901 | hpc_ptr->starting_slot_num = hpc_ptr->slots[0].slot_num; |
| 902 | hpc_ptr->ending_slot_num = hpc_ptr->slots[slot_num-1].slot_num; |
| 903 | |
| 904 | // register slots with hpc core as well as create linked list of ibm slot |
| 905 | for (index = 0; index < hpc_ptr->slot_count; index++) { |
| 906 | |
Eric Sesterhenn | f5afe80 | 2006-02-28 15:34:49 +0100 | [diff] [blame] | 907 | hp_slot_ptr = kzalloc(sizeof(*hp_slot_ptr), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 908 | if (!hp_slot_ptr) { |
| 909 | rc = -ENOMEM; |
| 910 | goto error_no_hp_slot; |
| 911 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 912 | |
Eric Sesterhenn | f5afe80 | 2006-02-28 15:34:49 +0100 | [diff] [blame] | 913 | hp_slot_ptr->info = kzalloc(sizeof(struct hotplug_slot_info), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 914 | if (!hp_slot_ptr->info) { |
| 915 | rc = -ENOMEM; |
| 916 | goto error_no_hp_info; |
| 917 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 918 | |
Eric Sesterhenn | f5afe80 | 2006-02-28 15:34:49 +0100 | [diff] [blame] | 919 | tmp_slot = kzalloc(sizeof(*tmp_slot), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 920 | if (!tmp_slot) { |
| 921 | rc = -ENOMEM; |
| 922 | goto error_no_slot; |
| 923 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 924 | |
Kristen Accardi | dc6712d | 2006-03-14 16:24:47 -0800 | [diff] [blame] | 925 | tmp_slot->flag = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 926 | |
| 927 | tmp_slot->capabilities = hpc_ptr->slots[index].slot_cap; |
| 928 | if ((hpc_ptr->slots[index].slot_cap & EBDA_SLOT_133_MAX) == EBDA_SLOT_133_MAX) |
| 929 | tmp_slot->supported_speed = 3; |
| 930 | else if ((hpc_ptr->slots[index].slot_cap & EBDA_SLOT_100_MAX) == EBDA_SLOT_100_MAX) |
| 931 | tmp_slot->supported_speed = 2; |
| 932 | else if ((hpc_ptr->slots[index].slot_cap & EBDA_SLOT_66_MAX) == EBDA_SLOT_66_MAX) |
| 933 | tmp_slot->supported_speed = 1; |
Bjorn Helgaas | f762598 | 2013-11-14 11:28:18 -0700 | [diff] [blame] | 934 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 935 | if ((hpc_ptr->slots[index].slot_cap & EBDA_SLOT_PCIX_CAP) == EBDA_SLOT_PCIX_CAP) |
| 936 | tmp_slot->supported_bus_mode = 1; |
| 937 | else |
| 938 | tmp_slot->supported_bus_mode = 0; |
| 939 | |
| 940 | |
| 941 | tmp_slot->bus = hpc_ptr->slots[index].slot_bus_num; |
| 942 | |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 943 | bus_info_ptr1 = ibmphp_find_same_bus_num(hpc_ptr->slots[index].slot_bus_num); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 944 | if (!bus_info_ptr1) { |
Jesper Juhl | b91aac2 | 2008-03-08 02:16:07 +0100 | [diff] [blame] | 945 | kfree(tmp_slot); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 946 | rc = -ENODEV; |
| 947 | goto error; |
| 948 | } |
| 949 | tmp_slot->bus_on = bus_info_ptr1; |
| 950 | bus_info_ptr1 = NULL; |
| 951 | tmp_slot->ctrl = hpc_ptr; |
| 952 | |
| 953 | tmp_slot->ctlr_index = hpc_ptr->slots[index].ctl_index; |
| 954 | tmp_slot->number = hpc_ptr->slots[index].slot_num; |
| 955 | tmp_slot->hotplug_slot = hp_slot_ptr; |
| 956 | |
| 957 | hp_slot_ptr->private = tmp_slot; |
| 958 | hp_slot_ptr->release = release_slot; |
| 959 | |
| 960 | rc = fillslotinfo(hp_slot_ptr); |
| 961 | if (rc) |
| 962 | goto error; |
| 963 | |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 964 | rc = ibmphp_init_devno((struct slot **) &hp_slot_ptr->private); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 965 | if (rc) |
| 966 | goto error; |
| 967 | hp_slot_ptr->ops = &ibmphp_hotplug_slot_ops; |
| 968 | |
| 969 | // end of registering ibm slot with hotplug core |
| 970 | |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 971 | list_add(&((struct slot *)(hp_slot_ptr->private))->ibm_slot_list, &ibmphp_slot_head); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 972 | } |
| 973 | |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 974 | print_bus_info(); |
| 975 | list_add(&hpc_ptr->ebda_hpc_list, &ebda_hpc_head); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 976 | |
| 977 | } /* each hpc */ |
| 978 | |
akpm@linux-foundation.org | 2fd39aa | 2008-08-22 13:30:14 -0700 | [diff] [blame] | 979 | list_for_each_entry(tmp_slot, &ibmphp_slot_head, ibm_slot_list) { |
Alex Chiang | a32615a | 2008-10-20 17:41:33 -0600 | [diff] [blame] | 980 | snprintf(name, SLOT_NAME_SIZE, "%s", create_file_name(tmp_slot)); |
Alex Chiang | f46753c | 2008-06-10 15:28:50 -0600 | [diff] [blame] | 981 | pci_hp_register(tmp_slot->hotplug_slot, |
Alex Chiang | a32615a | 2008-10-20 17:41:33 -0600 | [diff] [blame] | 982 | pci_find_bus(0, tmp_slot->bus), tmp_slot->device, name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 983 | } |
| 984 | |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 985 | print_ebda_hpc(); |
| 986 | print_ibm_slot(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 987 | return 0; |
| 988 | |
| 989 | error: |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 990 | kfree(hp_slot_ptr->private); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 991 | error_no_slot: |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 992 | kfree(hp_slot_ptr->info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 993 | error_no_hp_info: |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 994 | kfree(hp_slot_ptr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 995 | error_no_hp_slot: |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 996 | free_ebda_hpc(hpc_ptr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 997 | error_no_hpc: |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 998 | iounmap(io_mem); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 999 | return rc; |
| 1000 | } |
| 1001 | |
Bjorn Helgaas | f762598 | 2013-11-14 11:28:18 -0700 | [diff] [blame] | 1002 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1003 | * map info (bus, devfun, start addr, end addr..) of i/o, memory, |
| 1004 | * pfm from the physical addr to a list of resource. |
| 1005 | */ |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 1006 | static int __init ebda_rsrc_rsrc(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1007 | { |
| 1008 | u16 addr; |
| 1009 | short rsrc; |
| 1010 | u8 type, rsrc_type; |
| 1011 | struct ebda_pci_rsrc *rsrc_ptr; |
| 1012 | |
| 1013 | addr = rsrc_list_ptr->phys_addr; |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 1014 | debug("now entering rsrc land\n"); |
| 1015 | debug("offset of rsrc: %x\n", rsrc_list_ptr->phys_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1016 | |
| 1017 | for (rsrc = 0; rsrc < rsrc_list_ptr->num_entries; rsrc++) { |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 1018 | type = readb(io_mem + addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1019 | |
| 1020 | addr += 1; |
| 1021 | rsrc_type = type & EBDA_RSRC_TYPE_MASK; |
| 1022 | |
| 1023 | if (rsrc_type == EBDA_IO_RSRC_TYPE) { |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 1024 | rsrc_ptr = alloc_ebda_pci_rsrc(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1025 | if (!rsrc_ptr) { |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 1026 | iounmap(io_mem); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1027 | return -ENOMEM; |
| 1028 | } |
| 1029 | rsrc_ptr->rsrc_type = type; |
| 1030 | |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 1031 | rsrc_ptr->bus_num = readb(io_mem + addr); |
| 1032 | rsrc_ptr->dev_fun = readb(io_mem + addr + 1); |
| 1033 | rsrc_ptr->start_addr = readw(io_mem + addr + 2); |
| 1034 | rsrc_ptr->end_addr = readw(io_mem + addr + 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1035 | addr += 6; |
| 1036 | |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 1037 | debug("rsrc from io type ----\n"); |
| 1038 | debug("rsrc type: %x bus#: %x dev_func: %x start addr: %x end addr: %x\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1039 | rsrc_ptr->rsrc_type, rsrc_ptr->bus_num, rsrc_ptr->dev_fun, rsrc_ptr->start_addr, rsrc_ptr->end_addr); |
| 1040 | |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 1041 | list_add(&rsrc_ptr->ebda_pci_rsrc_list, &ibmphp_ebda_pci_rsrc_head); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1042 | } |
| 1043 | |
| 1044 | if (rsrc_type == EBDA_MEM_RSRC_TYPE || rsrc_type == EBDA_PFM_RSRC_TYPE) { |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 1045 | rsrc_ptr = alloc_ebda_pci_rsrc(); |
| 1046 | if (!rsrc_ptr) { |
| 1047 | iounmap(io_mem); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1048 | return -ENOMEM; |
| 1049 | } |
| 1050 | rsrc_ptr->rsrc_type = type; |
| 1051 | |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 1052 | rsrc_ptr->bus_num = readb(io_mem + addr); |
| 1053 | rsrc_ptr->dev_fun = readb(io_mem + addr + 1); |
| 1054 | rsrc_ptr->start_addr = readl(io_mem + addr + 2); |
| 1055 | rsrc_ptr->end_addr = readl(io_mem + addr + 6); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1056 | addr += 10; |
| 1057 | |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 1058 | debug("rsrc from mem or pfm ---\n"); |
| 1059 | debug("rsrc type: %x bus#: %x dev_func: %x start addr: %x end addr: %x\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1060 | rsrc_ptr->rsrc_type, rsrc_ptr->bus_num, rsrc_ptr->dev_fun, rsrc_ptr->start_addr, rsrc_ptr->end_addr); |
| 1061 | |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 1062 | list_add(&rsrc_ptr->ebda_pci_rsrc_list, &ibmphp_ebda_pci_rsrc_head); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1063 | } |
| 1064 | } |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 1065 | kfree(rsrc_list_ptr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1066 | rsrc_list_ptr = NULL; |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 1067 | print_ebda_pci_rsrc(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1068 | return 0; |
| 1069 | } |
| 1070 | |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 1071 | u16 ibmphp_get_total_controllers(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1072 | { |
| 1073 | return hpc_list_ptr->num_ctlrs; |
| 1074 | } |
| 1075 | |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 1076 | struct slot *ibmphp_get_slot_from_physical_num(u8 physical_num) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1077 | { |
| 1078 | struct slot *slot; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1079 | |
akpm@linux-foundation.org | 2fd39aa | 2008-08-22 13:30:14 -0700 | [diff] [blame] | 1080 | list_for_each_entry(slot, &ibmphp_slot_head, ibm_slot_list) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1081 | if (slot->number == physical_num) |
| 1082 | return slot; |
| 1083 | } |
| 1084 | return NULL; |
| 1085 | } |
| 1086 | |
| 1087 | /* To find: |
| 1088 | * - the smallest slot number |
| 1089 | * - the largest slot number |
| 1090 | * - the total number of the slots based on each bus |
| 1091 | * (if only one slot per bus slot_min = slot_max ) |
| 1092 | */ |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 1093 | struct bus_info *ibmphp_find_same_bus_num(u32 num) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1094 | { |
| 1095 | struct bus_info *ptr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1096 | |
akpm@linux-foundation.org | 2fd39aa | 2008-08-22 13:30:14 -0700 | [diff] [blame] | 1097 | list_for_each_entry(ptr, &bus_info_head, bus_info_list) { |
Bjorn Helgaas | f762598 | 2013-11-14 11:28:18 -0700 | [diff] [blame] | 1098 | if (ptr->busno == num) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1099 | return ptr; |
| 1100 | } |
| 1101 | return NULL; |
| 1102 | } |
| 1103 | |
| 1104 | /* Finding relative bus number, in order to map corresponding |
| 1105 | * bus register |
| 1106 | */ |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 1107 | int ibmphp_get_bus_index(u8 num) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1108 | { |
| 1109 | struct bus_info *ptr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1110 | |
akpm@linux-foundation.org | 2fd39aa | 2008-08-22 13:30:14 -0700 | [diff] [blame] | 1111 | list_for_each_entry(ptr, &bus_info_head, bus_info_list) { |
Bjorn Helgaas | f762598 | 2013-11-14 11:28:18 -0700 | [diff] [blame] | 1112 | if (ptr->busno == num) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1113 | return ptr->index; |
| 1114 | } |
| 1115 | return -ENODEV; |
| 1116 | } |
| 1117 | |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 1118 | void ibmphp_free_bus_info_queue(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1119 | { |
Geliang Tang | 2ac83cc | 2015-12-12 21:36:57 +0800 | [diff] [blame] | 1120 | struct bus_info *bus_info, *next; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1121 | |
Geliang Tang | 2ac83cc | 2015-12-12 21:36:57 +0800 | [diff] [blame] | 1122 | list_for_each_entry_safe(bus_info, next, &bus_info_head, |
| 1123 | bus_info_list) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1124 | kfree (bus_info); |
| 1125 | } |
| 1126 | } |
| 1127 | |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 1128 | void ibmphp_free_ebda_hpc_queue(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1129 | { |
Geliang Tang | 2ac83cc | 2015-12-12 21:36:57 +0800 | [diff] [blame] | 1130 | struct controller *controller = NULL, *next; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1131 | int pci_flag = 0; |
| 1132 | |
Geliang Tang | 2ac83cc | 2015-12-12 21:36:57 +0800 | [diff] [blame] | 1133 | list_for_each_entry_safe(controller, next, &ebda_hpc_head, |
| 1134 | ebda_hpc_list) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1135 | if (controller->ctlr_type == 0) |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 1136 | release_region(controller->u.isa_ctlr.io_start, (controller->u.isa_ctlr.io_end - controller->u.isa_ctlr.io_start + 1)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1137 | else if ((controller->ctlr_type == 1) && (!pci_flag)) { |
| 1138 | ++pci_flag; |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 1139 | pci_unregister_driver(&ibmphp_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1140 | } |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 1141 | free_ebda_hpc(controller); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1142 | } |
| 1143 | } |
| 1144 | |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 1145 | void ibmphp_free_ebda_pci_rsrc_queue(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1146 | { |
Geliang Tang | 2ac83cc | 2015-12-12 21:36:57 +0800 | [diff] [blame] | 1147 | struct ebda_pci_rsrc *resource, *next; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1148 | |
Geliang Tang | 2ac83cc | 2015-12-12 21:36:57 +0800 | [diff] [blame] | 1149 | list_for_each_entry_safe(resource, next, &ibmphp_ebda_pci_rsrc_head, |
| 1150 | ebda_pci_rsrc_list) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1151 | kfree (resource); |
| 1152 | resource = NULL; |
| 1153 | } |
| 1154 | } |
| 1155 | |
Arvind Yadav | 8394264 | 2017-08-03 18:20:17 -0500 | [diff] [blame] | 1156 | static const struct pci_device_id id_table[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1157 | { |
| 1158 | .vendor = PCI_VENDOR_ID_IBM, |
| 1159 | .device = HPC_DEVICE_ID, |
| 1160 | .subvendor = PCI_VENDOR_ID_IBM, |
| 1161 | .subdevice = HPC_SUBSYSTEM_ID, |
| 1162 | .class = ((PCI_CLASS_SYSTEM_PCI_HOTPLUG << 8) | 0x00), |
| 1163 | }, {} |
Bjorn Helgaas | f762598 | 2013-11-14 11:28:18 -0700 | [diff] [blame] | 1164 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1165 | |
| 1166 | MODULE_DEVICE_TABLE(pci, id_table); |
| 1167 | |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 1168 | static int ibmphp_probe(struct pci_dev *, const struct pci_device_id *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1169 | static struct pci_driver ibmphp_driver = { |
| 1170 | .name = "ibmphp", |
| 1171 | .id_table = id_table, |
| 1172 | .probe = ibmphp_probe, |
| 1173 | }; |
| 1174 | |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 1175 | int ibmphp_register_pci(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1176 | { |
| 1177 | struct controller *ctrl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1178 | int rc = 0; |
| 1179 | |
akpm@linux-foundation.org | 2fd39aa | 2008-08-22 13:30:14 -0700 | [diff] [blame] | 1180 | list_for_each_entry(ctrl, &ebda_hpc_head, ebda_hpc_list) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1181 | if (ctrl->ctlr_type == 1) { |
| 1182 | rc = pci_register_driver(&ibmphp_driver); |
| 1183 | break; |
| 1184 | } |
| 1185 | } |
| 1186 | return rc; |
| 1187 | } |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 1188 | static int ibmphp_probe(struct pci_dev *dev, const struct pci_device_id *ids) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1189 | { |
| 1190 | struct controller *ctrl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1191 | |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 1192 | debug("inside ibmphp_probe\n"); |
Bjorn Helgaas | f762598 | 2013-11-14 11:28:18 -0700 | [diff] [blame] | 1193 | |
akpm@linux-foundation.org | 2fd39aa | 2008-08-22 13:30:14 -0700 | [diff] [blame] | 1194 | list_for_each_entry(ctrl, &ebda_hpc_head, ebda_hpc_list) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1195 | if (ctrl->ctlr_type == 1) { |
| 1196 | if ((dev->devfn == ctrl->u.pci_ctlr.dev_fun) && (dev->bus->number == ctrl->u.pci_ctlr.bus)) { |
| 1197 | ctrl->ctrl_dev = dev; |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 1198 | debug("found device!!!\n"); |
| 1199 | debug("dev->device = %x, dev->subsystem_device = %x\n", dev->device, dev->subsystem_device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1200 | return 0; |
| 1201 | } |
| 1202 | } |
| 1203 | } |
| 1204 | return -ENODEV; |
| 1205 | } |