// SPDX-License-Identifier: GPL-2.0+
/*
* IBM Hot Plug Controller Driver
*
* Written By: Tong Yu, IBM Corporation
*
* Copyright (C) 2001,2003 Greg Kroah-Hartman (greg@kroah.com)
* Copyright (C) 2001-2003 IBM Corp.
*
* All rights reserved.
*
* Send feedback to <gregkh@us.ibm.com>
*
*/
#include <linux/module.h>
#include <linux/errno.h>
#include <linux/mm.h>
#include <linux/slab.h>
#include <linux/pci.h>
#include <linux/list.h>
#include <linux/init.h>
#include "ibmphp.h"
/*
* POST builds data blocks(in this data block definition, a char-1
* byte, short(or word)-2 byte, long(dword)-4 byte) in the Extended
* BIOS Data Area which describe the configuration of the hot-plug
* controllers and resources used by the PCI Hot-Plug devices.
*
* This file walks EBDA, maps data block from physical addr,
* reconstruct linked lists about all system resource(MEM, PFM, IO)
* already assigned by POST, as well as linked lists about hot plug
* controllers (ctlr#, slot#, bus&slot features...)
*/
/* Global lists */
LIST_HEAD(ibmphp_ebda_pci_rsrc_head);
LIST_HEAD(ibmphp_slot_head);
/* Local variables */
static struct ebda_hpc_list *hpc_list_ptr;
static struct ebda_rsrc_list *rsrc_list_ptr;
static struct rio_table_hdr *rio_table_ptr = NULL;
static LIST_HEAD(ebda_hpc_head);
static LIST_HEAD(bus_info_head);
static LIST_HEAD(rio_vg_head);
static LIST_HEAD(rio_lo_head);
static LIST_HEAD(opt_vg_head);
static LIST_HEAD(opt_lo_head);
static void __iomem *io_mem;
/* Local functions */
static int ebda_rsrc_controller(void);
static int ebda_rsrc_rsrc(void);
static int ebda_rio_table(void);
static struct ebda_hpc_list * __init alloc_ebda_hpc_list(void)
{
return kzalloc(sizeof(struct ebda_hpc_list), GFP_KERNEL);
}
static struct controller *alloc_ebda_hpc(u32 slot_count, u32 bus_count)
{
struct controller *controller;
struct ebda_hpc_slot *slots;
struct ebda_hpc_bus *buses;
controller = kzalloc(sizeof(struct controller), GFP_KERNEL);
if (!controller)
goto error;
slots = kcalloc(slot_count, sizeof(struct ebda_hpc_slot), GFP_KERNEL);
if (!slots)
goto error_contr;
controller->slots = slots;
buses = kcalloc(bus_count, sizeof(struct ebda_hpc_bus), GFP_KERNEL);
if (!buses)
goto error_slots;
controller->buses = buses;
return controller;
error_slots:
kfree(controller->slots);
error_contr:
kfree(controller);
error:
return NULL;
}
static void free_ebda_hpc(struct controller *controller)
{
kfree(controller->slots);
kfree(controller->buses);
kfree(controller);
}
static struct ebda_rsrc_list * __init alloc_ebda_rsrc_list(void)
{
return kzalloc(sizeof(struct ebda_rsrc_list), GFP_KERNEL);
}
static struct ebda_pci_rsrc *alloc_ebda_pci_rsrc(void)
{
return kzalloc(sizeof(struct ebda_pci_rsrc), GFP_KERNEL);
}
static void __init print_bus_info(void)
{
struct bus_info *ptr;
list_for_each_entry(ptr, &bus_info_head, bus_info_list) {
debug("%s - slot_min = %x\n", __func__, ptr->slot_min);
debug("%s - slot_max = %x\n", __func__, ptr->slot_max);
debug("%s - slot_count = %x\n", __func__, ptr->slot_count);
debug("%s - bus# = %x\n", __func__, ptr->busno);
debug("%s - current_speed = %x\n", __func__, ptr->current_speed);
debug("%s - controller_id = %x\n", __func__, ptr->controller_id);
debug("%s - slots_at_33_conv = %x\n", __func__, ptr->slots_at_33_conv);
debug("%s - slots_at_66_conv = %x\n", __func__, ptr->slots_at_66_conv);
debug("%s - slots_at_66_pcix = %x\n", __func__, ptr->slots_at_66_pcix);
debug("%s - slots_at_100_pcix = %x