^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0+
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Compaq Hot Plug Controller Driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (C) 1995,2001 Compaq Computer Corporation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Copyright (C) 2001 Greg Kroah-Hartman (greg@kroah.com)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Copyright (C) 2001 IBM Corp.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * All rights reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * Send feedback to <greg@kroah.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/workqueue.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <linux/wait.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <linux/pci.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <linux/pci_hotplug.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include <linux/kthread.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include "cpqphp.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) static u32 configure_new_device(struct controller *ctrl, struct pci_func *func,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) u8 behind_bridge, struct resource_lists *resources);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) static int configure_new_function(struct controller *ctrl, struct pci_func *func,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) u8 behind_bridge, struct resource_lists *resources);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) static void interrupt_event_handler(struct controller *ctrl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) static struct task_struct *cpqhp_event_thread;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) static struct timer_list *pushbutton_pending; /* = NULL */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) /* delay is in jiffies to wait for */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) static void long_delay(int delay)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) * XXX(hch): if someone is bored please convert all callers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) * to call msleep_interruptible directly. They really want
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) * to specify timeouts in natural units and spend a lot of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) * effort converting them to jiffies..
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) msleep_interruptible(jiffies_to_msecs(delay));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) /* FIXME: The following line needs to be somewhere else... */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) #define WRONG_BUS_FREQUENCY 0x07
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) static u8 handle_switch_change(u8 change, struct controller *ctrl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) int hp_slot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) u8 rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) u16 temp_word;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) struct pci_func *func;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) struct event_info *taskInfo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) if (!change)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) /* Switch Change */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) dbg("cpqsbd: Switch interrupt received.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) for (hp_slot = 0; hp_slot < 6; hp_slot++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) if (change & (0x1L << hp_slot)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) * this one changed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) func = cpqhp_slot_find(ctrl->bus,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) (hp_slot + ctrl->slot_device_offset), 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) /* this is the structure that tells the worker thread
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) * what to do
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) taskInfo = &(ctrl->event_queue[ctrl->next_event]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) ctrl->next_event = (ctrl->next_event + 1) % 10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) taskInfo->hp_slot = hp_slot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) rc++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) temp_word = ctrl->ctrl_int_comp >> 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) func->presence_save = (temp_word >> hp_slot) & 0x01;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) func->presence_save |= (temp_word >> (hp_slot + 7)) & 0x02;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) if (ctrl->ctrl_int_comp & (0x1L << hp_slot)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) * Switch opened
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) func->switch_save = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) taskInfo->event_type = INT_SWITCH_OPEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) * Switch closed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) func->switch_save = 0x10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) taskInfo->event_type = INT_SWITCH_CLOSE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) * cpqhp_find_slot - find the struct slot of given device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) * @ctrl: scan lots of this controller
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) * @device: the device id to find
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) static struct slot *cpqhp_find_slot(struct controller *ctrl, u8 device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) struct slot *slot = ctrl->slot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) while (slot && (slot->device != device))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) slot = slot->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) return slot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) static u8 handle_presence_change(u16 change, struct controller *ctrl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) int hp_slot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) u8 rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) u8 temp_byte;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) u16 temp_word;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) struct pci_func *func;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) struct event_info *taskInfo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) struct slot *p_slot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) if (!change)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) * Presence Change
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) dbg("cpqsbd: Presence/Notify input change.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) dbg(" Changed bits are 0x%4.4x\n", change);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) for (hp_slot = 0; hp_slot < 6; hp_slot++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) if (change & (0x0101 << hp_slot)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) * this one changed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) func = cpqhp_slot_find(ctrl->bus,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) (hp_slot + ctrl->slot_device_offset), 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) taskInfo = &(ctrl->event_queue[ctrl->next_event]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) ctrl->next_event = (ctrl->next_event + 1) % 10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) taskInfo->hp_slot = hp_slot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) rc++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) p_slot = cpqhp_find_slot(ctrl, hp_slot + (readb(ctrl->hpc_reg + SLOT_MASK) >> 4));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) if (!p_slot)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) /* If the switch closed, must be a button
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) * If not in button mode, nevermind
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) if (func->switch_save && (ctrl->push_button == 1)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) temp_word = ctrl->ctrl_int_comp >> 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) temp_byte = (temp_word >> hp_slot) & 0x01;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) temp_byte |= (temp_word >> (hp_slot + 7)) & 0x02;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) if (temp_byte != func->presence_save) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) * button Pressed (doesn't do anything)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) dbg("hp_slot %d button pressed\n", hp_slot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) taskInfo->event_type = INT_BUTTON_PRESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) * button Released - TAKE ACTION!!!!
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) dbg("hp_slot %d button released\n", hp_slot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) taskInfo->event_type = INT_BUTTON_RELEASE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) /* Cancel if we are still blinking */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) if ((p_slot->state == BLINKINGON_STATE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) || (p_slot->state == BLINKINGOFF_STATE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) taskInfo->event_type = INT_BUTTON_CANCEL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) dbg("hp_slot %d button cancel\n", hp_slot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) } else if ((p_slot->state == POWERON_STATE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) || (p_slot->state == POWEROFF_STATE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) /* info(msg_button_ignore, p_slot->number); */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) taskInfo->event_type = INT_BUTTON_IGNORE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) dbg("hp_slot %d button ignore\n", hp_slot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) /* Switch is open, assume a presence change
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) * Save the presence state
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) temp_word = ctrl->ctrl_int_comp >> 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) func->presence_save = (temp_word >> hp_slot) & 0x01;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) func->presence_save |= (temp_word >> (hp_slot + 7)) & 0x02;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) if ((!(ctrl->ctrl_int_comp & (0x010000 << hp_slot))) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) (!(ctrl->ctrl_int_comp & (0x01000000 << hp_slot)))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) /* Present */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) taskInfo->event_type = INT_PRESENCE_ON;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) /* Not Present */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) taskInfo->event_type = INT_PRESENCE_OFF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) static u8 handle_power_fault(u8 change, struct controller *ctrl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) int hp_slot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) u8 rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) struct pci_func *func;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) struct event_info *taskInfo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) if (!change)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) * power fault
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) info("power fault interrupt\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) for (hp_slot = 0; hp_slot < 6; hp_slot++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) if (change & (0x01 << hp_slot)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) * this one changed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) func = cpqhp_slot_find(ctrl->bus,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) (hp_slot + ctrl->slot_device_offset), 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) taskInfo = &(ctrl->event_queue[ctrl->next_event]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) ctrl->next_event = (ctrl->next_event + 1) % 10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) taskInfo->hp_slot = hp_slot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) rc++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) if (ctrl->ctrl_int_comp & (0x00000100 << hp_slot)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) * power fault Cleared
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) func->status = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) taskInfo->event_type = INT_POWER_FAULT_CLEAR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) * power fault
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) taskInfo->event_type = INT_POWER_FAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) if (ctrl->rev < 4) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) amber_LED_on(ctrl, hp_slot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) green_LED_off(ctrl, hp_slot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) set_SOGO(ctrl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) /* this is a fatal condition, we want
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) * to crash the machine to protect from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) * data corruption. simulated_NMI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) * shouldn't ever return */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) /* FIXME
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) simulated_NMI(hp_slot, ctrl); */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) /* The following code causes a software
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) * crash just in case simulated_NMI did
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) * return */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) /*FIXME
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) panic(msg_power_fault); */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) /* set power fault status for this board */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) func->status = 0xFF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) info("power fault bit %x set\n", hp_slot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) * sort_by_size - sort nodes on the list by their length, smallest first.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) * @head: list to sort
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) static int sort_by_size(struct pci_resource **head)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) struct pci_resource *current_res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) struct pci_resource *next_res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) int out_of_order = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) if (!(*head))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) if (!((*head)->next))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) while (out_of_order) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) out_of_order = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) /* Special case for swapping list head */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) if (((*head)->next) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) ((*head)->length > (*head)->next->length)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) out_of_order++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) current_res = *head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) *head = (*head)->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) current_res->next = (*head)->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) (*head)->next = current_res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) current_res = *head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) while (current_res->next && current_res->next->next) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) if (current_res->next->length > current_res->next->next->length) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) out_of_order++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) next_res = current_res->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) current_res->next = current_res->next->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) current_res = current_res->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) next_res->next = current_res->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) current_res->next = next_res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) current_res = current_res->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) } /* End of out_of_order loop */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) * sort_by_max_size - sort nodes on the list by their length, largest first.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) * @head: list to sort
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) static int sort_by_max_size(struct pci_resource **head)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) struct pci_resource *current_res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) struct pci_resource *next_res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) int out_of_order = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) if (!(*head))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) if (!((*head)->next))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) while (out_of_order) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) out_of_order = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) /* Special case for swapping list head */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) if (((*head)->next) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) ((*head)->length < (*head)->next->length)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) out_of_order++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) current_res = *head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) *head = (*head)->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) current_res->next = (*head)->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) (*head)->next = current_res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) current_res = *head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) while (current_res->next && current_res->next->next) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) if (current_res->next->length < current_res->next->next->length) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) out_of_order++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) next_res = current_res->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) current_res->next = current_res->next->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) current_res = current_res->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) next_res->next = current_res->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) current_res->next = next_res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) current_res = current_res->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) } /* End of out_of_order loop */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) * do_pre_bridge_resource_split - find node of resources that are unused
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) * @head: new list head
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) * @orig_head: original list head
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) * @alignment: max node size (?)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) static struct pci_resource *do_pre_bridge_resource_split(struct pci_resource **head,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) struct pci_resource **orig_head, u32 alignment)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) struct pci_resource *prevnode = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) struct pci_resource *node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) struct pci_resource *split_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) u32 rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) u32 temp_dword;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) dbg("do_pre_bridge_resource_split\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) if (!(*head) || !(*orig_head))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) rc = cpqhp_resource_sort_and_combine(head);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) if ((*head)->base != (*orig_head)->base)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) if ((*head)->length == (*orig_head)->length)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) /* If we got here, there the bridge requires some of the resource, but
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) * we may be able to split some off of the front
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) node = *head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) if (node->length & (alignment - 1)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) /* this one isn't an aligned length, so we'll make a new entry
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) * and split it up.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) split_node = kmalloc(sizeof(*split_node), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) if (!split_node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) temp_dword = (node->length | (alignment-1)) + 1 - alignment;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) split_node->base = node->base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) split_node->length = temp_dword;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) node->length -= temp_dword;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) node->base += split_node->length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) /* Put it in the list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) *head = split_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) split_node->next = node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) if (node->length < alignment)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) /* Now unlink it */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) if (*head == node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) *head = node->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) prevnode = *head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) while (prevnode->next != node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) prevnode = prevnode->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) prevnode->next = node->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) node->next = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) return node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) * do_bridge_resource_split - find one node of resources that aren't in use
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) * @head: list head
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) * @alignment: max node size (?)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) static struct pci_resource *do_bridge_resource_split(struct pci_resource **head, u32 alignment)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) struct pci_resource *prevnode = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) struct pci_resource *node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) u32 rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) u32 temp_dword;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) rc = cpqhp_resource_sort_and_combine(head);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) node = *head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) while (node->next) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) prevnode = node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) node = node->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) kfree(prevnode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) if (node->length < alignment)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) if (node->base & (alignment - 1)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) /* Short circuit if adjusted size is too small */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) temp_dword = (node->base | (alignment-1)) + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) if ((node->length - (temp_dword - node->base)) < alignment)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) node->length -= (temp_dword - node->base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) node->base = temp_dword;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) if (node->length & (alignment - 1))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) /* There's stuff in use after this node */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) return node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) kfree(node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) * get_io_resource - find first node of given size not in ISA aliasing window.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) * @head: list to search
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) * @size: size of node to find, must be a power of two.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) * Description: This function sorts the resource list by size and then returns
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) * returns the first node of "size" length that is not in the ISA aliasing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) * window. If it finds a node larger than "size" it will split it up.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) static struct pci_resource *get_io_resource(struct pci_resource **head, u32 size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) struct pci_resource *prevnode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) struct pci_resource *node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) struct pci_resource *split_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) u32 temp_dword;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) if (!(*head))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) if (cpqhp_resource_sort_and_combine(head))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) if (sort_by_size(head))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) for (node = *head; node; node = node->next) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) if (node->length < size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) if (node->base & (size - 1)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) /* this one isn't base aligned properly
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) * so we'll make a new entry and split it up
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) temp_dword = (node->base | (size-1)) + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) /* Short circuit if adjusted size is too small */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) if ((node->length - (temp_dword - node->base)) < size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) split_node = kmalloc(sizeof(*split_node), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) if (!split_node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) split_node->base = node->base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) split_node->length = temp_dword - node->base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) node->base = temp_dword;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) node->length -= split_node->length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) /* Put it in the list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) split_node->next = node->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) node->next = split_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) } /* End of non-aligned base */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) /* Don't need to check if too small since we already did */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) if (node->length > size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) /* this one is longer than we need
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) * so we'll make a new entry and split it up
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) split_node = kmalloc(sizeof(*split_node), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) if (!split_node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) split_node->base = node->base + size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) split_node->length = node->length - size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) node->length = size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) /* Put it in the list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) split_node->next = node->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) node->next = split_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) } /* End of too big on top end */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) /* For IO make sure it's not in the ISA aliasing space */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) if (node->base & 0x300L)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) /* If we got here, then it is the right size
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) * Now take it out of the list and break
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) if (*head == node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) *head = node->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) prevnode = *head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) while (prevnode->next != node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) prevnode = prevnode->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) prevnode->next = node->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) node->next = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) return node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) * get_max_resource - get largest node which has at least the given size.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) * @head: the list to search the node in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) * @size: the minimum size of the node to find
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) * Description: Gets the largest node that is at least "size" big from the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) * list pointed to by head. It aligns the node on top and bottom
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) * to "size" alignment before returning it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) static struct pci_resource *get_max_resource(struct pci_resource **head, u32 size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) struct pci_resource *max;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) struct pci_resource *temp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) struct pci_resource *split_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) u32 temp_dword;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) if (cpqhp_resource_sort_and_combine(head))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) if (sort_by_max_size(head))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) for (max = *head; max; max = max->next) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) /* If not big enough we could probably just bail,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) * instead we'll continue to the next.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) if (max->length < size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) if (max->base & (size - 1)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) /* this one isn't base aligned properly
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) * so we'll make a new entry and split it up
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) temp_dword = (max->base | (size-1)) + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) /* Short circuit if adjusted size is too small */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) if ((max->length - (temp_dword - max->base)) < size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) split_node = kmalloc(sizeof(*split_node), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) if (!split_node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) split_node->base = max->base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) split_node->length = temp_dword - max->base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) max->base = temp_dword;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) max->length -= split_node->length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) split_node->next = max->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) max->next = split_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) if ((max->base + max->length) & (size - 1)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) /* this one isn't end aligned properly at the top
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) * so we'll make a new entry and split it up
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) split_node = kmalloc(sizeof(*split_node), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) if (!split_node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) temp_dword = ((max->base + max->length) & ~(size - 1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) split_node->base = temp_dword;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) split_node->length = max->length + max->base
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) - split_node->base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) max->length -= split_node->length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) split_node->next = max->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) max->next = split_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) /* Make sure it didn't shrink too much when we aligned it */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) if (max->length < size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) /* Now take it out of the list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) temp = *head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) if (temp == max) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) *head = max->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) while (temp && temp->next != max)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) temp = temp->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) if (temp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) temp->next = max->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) max->next = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) return max;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) * get_resource - find resource of given size and split up larger ones.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) * @head: the list to search for resources
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) * @size: the size limit to use
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) * Description: This function sorts the resource list by size and then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) * returns the first node of "size" length. If it finds a node
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) * larger than "size" it will split it up.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) * size must be a power of two.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) static struct pci_resource *get_resource(struct pci_resource **head, u32 size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) struct pci_resource *prevnode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) struct pci_resource *node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) struct pci_resource *split_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) u32 temp_dword;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) if (cpqhp_resource_sort_and_combine(head))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) if (sort_by_size(head))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) for (node = *head; node; node = node->next) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) dbg("%s: req_size =%x node=%p, base=%x, length=%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) __func__, size, node, node->base, node->length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) if (node->length < size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) if (node->base & (size - 1)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) dbg("%s: not aligned\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) /* this one isn't base aligned properly
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) * so we'll make a new entry and split it up
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) temp_dword = (node->base | (size-1)) + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) /* Short circuit if adjusted size is too small */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) if ((node->length - (temp_dword - node->base)) < size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) split_node = kmalloc(sizeof(*split_node), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) if (!split_node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) split_node->base = node->base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) split_node->length = temp_dword - node->base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) node->base = temp_dword;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) node->length -= split_node->length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) split_node->next = node->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) node->next = split_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) } /* End of non-aligned base */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) /* Don't need to check if too small since we already did */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) if (node->length > size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) dbg("%s: too big\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) /* this one is longer than we need
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) * so we'll make a new entry and split it up
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) split_node = kmalloc(sizeof(*split_node), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) if (!split_node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) split_node->base = node->base + size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) split_node->length = node->length - size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) node->length = size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) /* Put it in the list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) split_node->next = node->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) node->next = split_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) } /* End of too big on top end */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) dbg("%s: got one!!!\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) /* If we got here, then it is the right size
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) * Now take it out of the list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) if (*head == node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) *head = node->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) prevnode = *head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) while (prevnode->next != node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) prevnode = prevnode->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) prevnode->next = node->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) node->next = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) return node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) * cpqhp_resource_sort_and_combine - sort nodes by base addresses and clean up
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) * @head: the list to sort and clean up
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) * Description: Sorts all of the nodes in the list in ascending order by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) * their base addresses. Also does garbage collection by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) * combining adjacent nodes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) * Returns %0 if success.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) int cpqhp_resource_sort_and_combine(struct pci_resource **head)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) struct pci_resource *node1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) struct pci_resource *node2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) int out_of_order = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) dbg("%s: head = %p, *head = %p\n", __func__, head, *head);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) if (!(*head))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) dbg("*head->next = %p\n", (*head)->next);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826) if (!(*head)->next)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) return 0; /* only one item on the list, already sorted! */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) dbg("*head->base = 0x%x\n", (*head)->base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) dbg("*head->next->base = 0x%x\n", (*head)->next->base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) while (out_of_order) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) out_of_order = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834) /* Special case for swapping list head */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835) if (((*head)->next) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836) ((*head)->base > (*head)->next->base)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837) node1 = *head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) (*head) = (*head)->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839) node1->next = (*head)->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840) (*head)->next = node1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) out_of_order++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) node1 = (*head);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846) while (node1->next && node1->next->next) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) if (node1->next->base > node1->next->next->base) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848) out_of_order++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849) node2 = node1->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) node1->next = node1->next->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851) node1 = node1->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852) node2->next = node1->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853) node1->next = node2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) node1 = node1->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857) } /* End of out_of_order loop */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859) node1 = *head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861) while (node1 && node1->next) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862) if ((node1->base + node1->length) == node1->next->base) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863) /* Combine */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864) dbg("8..\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865) node1->length += node1->next->length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866) node2 = node1->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867) node1->next = node1->next->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868) kfree(node2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870) node1 = node1->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877) irqreturn_t cpqhp_ctrl_intr(int IRQ, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879) struct controller *ctrl = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880) u8 schedule_flag = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881) u8 reset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882) u16 misc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883) u32 Diff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884) u32 temp_dword;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887) misc = readw(ctrl->hpc_reg + MISC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889) * Check to see if it was our interrupt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891) if (!(misc & 0x000C))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892) return IRQ_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894) if (misc & 0x0004) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 895) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896) * Serial Output interrupt Pending
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 897) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 898)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 899) /* Clear the interrupt */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 900) misc |= 0x0004;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 901) writew(misc, ctrl->hpc_reg + MISC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 902)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 903) /* Read to clear posted writes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 904) misc = readw(ctrl->hpc_reg + MISC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 905)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 906) dbg("%s - waking up\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 907) wake_up_interruptible(&ctrl->queue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 908) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 909)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 910) if (misc & 0x0008) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 911) /* General-interrupt-input interrupt Pending */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 912) Diff = readl(ctrl->hpc_reg + INT_INPUT_CLEAR) ^ ctrl->ctrl_int_comp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 913)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 914) ctrl->ctrl_int_comp = readl(ctrl->hpc_reg + INT_INPUT_CLEAR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 915)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 916) /* Clear the interrupt */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 917) writel(Diff, ctrl->hpc_reg + INT_INPUT_CLEAR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 918)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 919) /* Read it back to clear any posted writes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 920) temp_dword = readl(ctrl->hpc_reg + INT_INPUT_CLEAR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 921)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 922) if (!Diff)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 923) /* Clear all interrupts */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 924) writel(0xFFFFFFFF, ctrl->hpc_reg + INT_INPUT_CLEAR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 925)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 926) schedule_flag += handle_switch_change((u8)(Diff & 0xFFL), ctrl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 927) schedule_flag += handle_presence_change((u16)((Diff & 0xFFFF0000L) >> 16), ctrl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 928) schedule_flag += handle_power_fault((u8)((Diff & 0xFF00L) >> 8), ctrl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 929) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 930)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 931) reset = readb(ctrl->hpc_reg + RESET_FREQ_MODE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 932) if (reset & 0x40) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 933) /* Bus reset has completed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 934) reset &= 0xCF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 935) writeb(reset, ctrl->hpc_reg + RESET_FREQ_MODE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 936) reset = readb(ctrl->hpc_reg + RESET_FREQ_MODE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 937) wake_up_interruptible(&ctrl->queue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 938) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 939)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 940) if (schedule_flag) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 941) wake_up_process(cpqhp_event_thread);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 942) dbg("Waking even thread");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 943) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 944) return IRQ_HANDLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 945) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 946)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 947)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 948) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 949) * cpqhp_slot_create - Creates a node and adds it to the proper bus.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 950) * @busnumber: bus where new node is to be located
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 951) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 952) * Returns pointer to the new node or %NULL if unsuccessful.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 953) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 954) struct pci_func *cpqhp_slot_create(u8 busnumber)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 955) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 956) struct pci_func *new_slot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 957) struct pci_func *next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 958)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 959) new_slot = kzalloc(sizeof(*new_slot), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 960) if (new_slot == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 961) return new_slot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 962)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 963) new_slot->next = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 964) new_slot->configured = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 965)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 966) if (cpqhp_slot_list[busnumber] == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 967) cpqhp_slot_list[busnumber] = new_slot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 968) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 969) next = cpqhp_slot_list[busnumber];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 970) while (next->next != NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 971) next = next->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 972) next->next = new_slot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 973) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 974) return new_slot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 975) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 976)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 977)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 978) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 979) * slot_remove - Removes a node from the linked list of slots.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 980) * @old_slot: slot to remove
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 981) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 982) * Returns %0 if successful, !0 otherwise.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 983) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 984) static int slot_remove(struct pci_func *old_slot)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 985) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 986) struct pci_func *next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 987)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 988) if (old_slot == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 989) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 990)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 991) next = cpqhp_slot_list[old_slot->bus];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 992) if (next == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 993) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 994)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 995) if (next == old_slot) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 996) cpqhp_slot_list[old_slot->bus] = old_slot->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 997) cpqhp_destroy_board_resources(old_slot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 998) kfree(old_slot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 999) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) while ((next->next != old_slot) && (next->next != NULL))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) next = next->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) if (next->next == old_slot) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) next->next = old_slot->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) cpqhp_destroy_board_resources(old_slot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) kfree(old_slot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) return 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) * bridge_slot_remove - Removes a node from the linked list of slots.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) * @bridge: bridge to remove
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) * Returns %0 if successful, !0 otherwise.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) static int bridge_slot_remove(struct pci_func *bridge)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) u8 subordinateBus, secondaryBus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) u8 tempBus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) struct pci_func *next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) secondaryBus = (bridge->config_space[0x06] >> 8) & 0xFF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) subordinateBus = (bridge->config_space[0x06] >> 16) & 0xFF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) for (tempBus = secondaryBus; tempBus <= subordinateBus; tempBus++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) next = cpqhp_slot_list[tempBus];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) while (!slot_remove(next))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) next = cpqhp_slot_list[tempBus];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) next = cpqhp_slot_list[bridge->bus];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) if (next == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) if (next == bridge) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) cpqhp_slot_list[bridge->bus] = bridge->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) while ((next->next != bridge) && (next->next != NULL))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) next = next->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) if (next->next != bridge)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) return 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) next->next = bridge->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) kfree(bridge);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) * cpqhp_slot_find - Looks for a node by bus, and device, multiple functions accessed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) * @bus: bus to find
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) * @device: device to find
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) * @index: is %0 for first function found, %1 for the second...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) * Returns pointer to the node if successful, %NULL otherwise.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) struct pci_func *cpqhp_slot_find(u8 bus, u8 device, u8 index)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) int found = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) struct pci_func *func;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) func = cpqhp_slot_list[bus];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) if ((func == NULL) || ((func->device == device) && (index == 0)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) return func;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) if (func->device == device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) found++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) while (func->next != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) func = func->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) if (func->device == device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) found++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) if (found == index)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) return func;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) /* DJZ: I don't think is_bridge will work as is.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) * FIXME */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) static int is_bridge(struct pci_func *func)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) /* Check the header type */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) if (((func->config_space[0x03] >> 16) & 0xFF) == 0x01)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) * set_controller_speed - set the frequency and/or mode of a specific controller segment.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) * @ctrl: controller to change frequency/mode for.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) * @adapter_speed: the speed of the adapter we want to match.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) * @hp_slot: the slot number where the adapter is installed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) * Returns %0 if we successfully change frequency and/or mode to match the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) * adapter speed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) static u8 set_controller_speed(struct controller *ctrl, u8 adapter_speed, u8 hp_slot)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) struct slot *slot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) struct pci_bus *bus = ctrl->pci_bus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) u8 reg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) u8 slot_power = readb(ctrl->hpc_reg + SLOT_POWER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) u16 reg16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) u32 leds = readl(ctrl->hpc_reg + LED_CONTROL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) if (bus->cur_bus_speed == adapter_speed)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) /* We don't allow freq/mode changes if we find another adapter running
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) * in another slot on this controller
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) for (slot = ctrl->slot; slot; slot = slot->next) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) if (slot->device == (hp_slot + ctrl->slot_device_offset))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) if (get_presence_status(ctrl, slot) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) /* If another adapter is running on the same segment but at a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) * lower speed/mode, we allow the new adapter to function at
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) * this rate if supported
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) if (bus->cur_bus_speed < adapter_speed)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) /* If the controller doesn't support freq/mode changes and the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) * controller is running at a higher mode, we bail
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) if ((bus->cur_bus_speed > adapter_speed) && (!ctrl->pcix_speed_capability))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151) /* But we allow the adapter to run at a lower rate if possible */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152) if ((bus->cur_bus_speed < adapter_speed) && (!ctrl->pcix_speed_capability))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155) /* We try to set the max speed supported by both the adapter and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) * controller
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) if (bus->max_bus_speed < adapter_speed) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159) if (bus->cur_bus_speed == bus->max_bus_speed)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) adapter_speed = bus->max_bus_speed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164) writel(0x0L, ctrl->hpc_reg + LED_CONTROL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165) writeb(0x00, ctrl->hpc_reg + SLOT_ENABLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) set_SOGO(ctrl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168) wait_for_ctrl_irq(ctrl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170) if (adapter_speed != PCI_SPEED_133MHz_PCIX)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171) reg = 0xF5;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173) reg = 0xF4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174) pci_write_config_byte(ctrl->pci_dev, 0x41, reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176) reg16 = readw(ctrl->hpc_reg + NEXT_CURR_FREQ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177) reg16 &= ~0x000F;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178) switch (adapter_speed) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179) case(PCI_SPEED_133MHz_PCIX):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180) reg = 0x75;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181) reg16 |= 0xB;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183) case(PCI_SPEED_100MHz_PCIX):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184) reg = 0x74;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185) reg16 |= 0xA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187) case(PCI_SPEED_66MHz_PCIX):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188) reg = 0x73;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189) reg16 |= 0x9;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191) case(PCI_SPEED_66MHz):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192) reg = 0x73;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193) reg16 |= 0x1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195) default: /* 33MHz PCI 2.2 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196) reg = 0x71;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200) reg16 |= 0xB << 12;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201) writew(reg16, ctrl->hpc_reg + NEXT_CURR_FREQ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203) mdelay(5);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205) /* Reenable interrupts */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206) writel(0, ctrl->hpc_reg + INT_MASK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208) pci_write_config_byte(ctrl->pci_dev, 0x41, reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210) /* Restart state machine */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211) reg = ~0xF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212) pci_read_config_byte(ctrl->pci_dev, 0x43, ®);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213) pci_write_config_byte(ctrl->pci_dev, 0x43, reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215) /* Only if mode change...*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216) if (((bus->cur_bus_speed == PCI_SPEED_66MHz) && (adapter_speed == PCI_SPEED_66MHz_PCIX)) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217) ((bus->cur_bus_speed == PCI_SPEED_66MHz_PCIX) && (adapter_speed == PCI_SPEED_66MHz)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218) set_SOGO(ctrl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220) wait_for_ctrl_irq(ctrl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221) mdelay(1100);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223) /* Restore LED/Slot state */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224) writel(leds, ctrl->hpc_reg + LED_CONTROL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225) writeb(slot_power, ctrl->hpc_reg + SLOT_ENABLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227) set_SOGO(ctrl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228) wait_for_ctrl_irq(ctrl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1230) bus->cur_bus_speed = adapter_speed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1231) slot = cpqhp_find_slot(ctrl, hp_slot + ctrl->slot_device_offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1232)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1233) info("Successfully changed frequency/mode for adapter in slot %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1234) slot->number);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1235) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1236) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1237)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1238) /* the following routines constitute the bulk of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1239) * hotplug controller logic
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1240) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1241)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1242)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1243) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1244) * board_replaced - Called after a board has been replaced in the system.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1245) * @func: PCI device/function information
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1246) * @ctrl: hotplug controller
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1247) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1248) * This is only used if we don't have resources for hot add.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1249) * Turns power on for the board.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1250) * Checks to see if board is the same.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1251) * If board is same, reconfigures it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1252) * If board isn't same, turns it back off.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1253) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1254) static u32 board_replaced(struct pci_func *func, struct controller *ctrl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1255) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1256) struct pci_bus *bus = ctrl->pci_bus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1257) u8 hp_slot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1258) u8 temp_byte;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1259) u8 adapter_speed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1260) u32 rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1261)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1262) hp_slot = func->device - ctrl->slot_device_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1263)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1264) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1265) * The switch is open.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1266) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1267) if (readl(ctrl->hpc_reg + INT_INPUT_CLEAR) & (0x01L << hp_slot))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1268) rc = INTERLOCK_OPEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1269) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1270) * The board is already on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1271) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1272) else if (is_slot_enabled(ctrl, hp_slot))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1273) rc = CARD_FUNCTIONING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1274) else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1275) mutex_lock(&ctrl->crit_sect);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1276)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1277) /* turn on board without attaching to the bus */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1278) enable_slot_power(ctrl, hp_slot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1279)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1280) set_SOGO(ctrl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1281)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1282) /* Wait for SOBS to be unset */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1283) wait_for_ctrl_irq(ctrl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1284)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1285) /* Change bits in slot power register to force another shift out
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1286) * NOTE: this is to work around the timer bug */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1287) temp_byte = readb(ctrl->hpc_reg + SLOT_POWER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1288) writeb(0x00, ctrl->hpc_reg + SLOT_POWER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1289) writeb(temp_byte, ctrl->hpc_reg + SLOT_POWER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1290)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1291) set_SOGO(ctrl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1292)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1293) /* Wait for SOBS to be unset */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1294) wait_for_ctrl_irq(ctrl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1295)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1296) adapter_speed = get_adapter_speed(ctrl, hp_slot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1297) if (bus->cur_bus_speed != adapter_speed)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1298) if (set_controller_speed(ctrl, adapter_speed, hp_slot))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1299) rc = WRONG_BUS_FREQUENCY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1300)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1301) /* turn off board without attaching to the bus */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1302) disable_slot_power(ctrl, hp_slot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1303)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1304) set_SOGO(ctrl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1305)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1306) /* Wait for SOBS to be unset */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1307) wait_for_ctrl_irq(ctrl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1308)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1309) mutex_unlock(&ctrl->crit_sect);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1310)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1311) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1312) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1313)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1314) mutex_lock(&ctrl->crit_sect);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1315)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1316) slot_enable(ctrl, hp_slot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1317) green_LED_blink(ctrl, hp_slot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1318)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1319) amber_LED_off(ctrl, hp_slot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1320)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1321) set_SOGO(ctrl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1322)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1323) /* Wait for SOBS to be unset */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1324) wait_for_ctrl_irq(ctrl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1325)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1326) mutex_unlock(&ctrl->crit_sect);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1327)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1328) /* Wait for ~1 second because of hot plug spec */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1329) long_delay(1*HZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1330)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1331) /* Check for a power fault */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1332) if (func->status == 0xFF) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1333) /* power fault occurred, but it was benign */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1334) rc = POWER_FAILURE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1335) func->status = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1336) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1337) rc = cpqhp_valid_replace(ctrl, func);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1338)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1339) if (!rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1340) /* It must be the same board */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1341)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1342) rc = cpqhp_configure_board(ctrl, func);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1343)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1344) /* If configuration fails, turn it off
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1345) * Get slot won't work for devices behind
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1346) * bridges, but in this case it will always be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1347) * called for the "base" bus/dev/func of an
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1348) * adapter.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1349) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1350)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1351) mutex_lock(&ctrl->crit_sect);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1352)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1353) amber_LED_on(ctrl, hp_slot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1354) green_LED_off(ctrl, hp_slot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1355) slot_disable(ctrl, hp_slot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1356)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1357) set_SOGO(ctrl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1358)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1359) /* Wait for SOBS to be unset */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1360) wait_for_ctrl_irq(ctrl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1361)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1362) mutex_unlock(&ctrl->crit_sect);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1363)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1364) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1365) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1366) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1367) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1368)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1369) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1370) /* Something is wrong
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1371)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1372) * Get slot won't work for devices behind bridges, but
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1373) * in this case it will always be called for the "base"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1374) * bus/dev/func of an adapter.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1375) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1376)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1377) mutex_lock(&ctrl->crit_sect);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1378)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1379) amber_LED_on(ctrl, hp_slot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1380) green_LED_off(ctrl, hp_slot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1381) slot_disable(ctrl, hp_slot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1382)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1383) set_SOGO(ctrl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1384)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1385) /* Wait for SOBS to be unset */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1386) wait_for_ctrl_irq(ctrl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1387)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1388) mutex_unlock(&ctrl->crit_sect);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1389) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1390)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1391) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1392) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1393)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1394) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1395)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1396)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1397) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1398) * board_added - Called after a board has been added to the system.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1399) * @func: PCI device/function info
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1400) * @ctrl: hotplug controller
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1401) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1402) * Turns power on for the board.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1403) * Configures board.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1404) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1405) static u32 board_added(struct pci_func *func, struct controller *ctrl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1406) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1407) u8 hp_slot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1408) u8 temp_byte;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1409) u8 adapter_speed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1410) int index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1411) u32 temp_register = 0xFFFFFFFF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1412) u32 rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1413) struct pci_func *new_slot = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1414) struct pci_bus *bus = ctrl->pci_bus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1415) struct slot *p_slot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1416) struct resource_lists res_lists;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1417)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1418) hp_slot = func->device - ctrl->slot_device_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1419) dbg("%s: func->device, slot_offset, hp_slot = %d, %d ,%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1420) __func__, func->device, ctrl->slot_device_offset, hp_slot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1421)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1422) mutex_lock(&ctrl->crit_sect);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1423)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1424) /* turn on board without attaching to the bus */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1425) enable_slot_power(ctrl, hp_slot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1426)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1427) set_SOGO(ctrl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1428)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1429) /* Wait for SOBS to be unset */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1430) wait_for_ctrl_irq(ctrl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1431)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1432) /* Change bits in slot power register to force another shift out
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1433) * NOTE: this is to work around the timer bug
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1434) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1435) temp_byte = readb(ctrl->hpc_reg + SLOT_POWER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1436) writeb(0x00, ctrl->hpc_reg + SLOT_POWER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1437) writeb(temp_byte, ctrl->hpc_reg + SLOT_POWER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1438)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1439) set_SOGO(ctrl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1440)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1441) /* Wait for SOBS to be unset */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1442) wait_for_ctrl_irq(ctrl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1443)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1444) adapter_speed = get_adapter_speed(ctrl, hp_slot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1445) if (bus->cur_bus_speed != adapter_speed)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1446) if (set_controller_speed(ctrl, adapter_speed, hp_slot))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1447) rc = WRONG_BUS_FREQUENCY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1448)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1449) /* turn off board without attaching to the bus */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1450) disable_slot_power(ctrl, hp_slot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1451)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1452) set_SOGO(ctrl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1453)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1454) /* Wait for SOBS to be unset */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1455) wait_for_ctrl_irq(ctrl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1456)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1457) mutex_unlock(&ctrl->crit_sect);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1458)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1459) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1460) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1461)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1462) p_slot = cpqhp_find_slot(ctrl, hp_slot + ctrl->slot_device_offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1463)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1464) /* turn on board and blink green LED */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1465)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1466) dbg("%s: before down\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1467) mutex_lock(&ctrl->crit_sect);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1468) dbg("%s: after down\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1469)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1470) dbg("%s: before slot_enable\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1471) slot_enable(ctrl, hp_slot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1472)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1473) dbg("%s: before green_LED_blink\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1474) green_LED_blink(ctrl, hp_slot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1475)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1476) dbg("%s: before amber_LED_blink\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1477) amber_LED_off(ctrl, hp_slot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1478)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1479) dbg("%s: before set_SOGO\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1480) set_SOGO(ctrl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1481)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1482) /* Wait for SOBS to be unset */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1483) dbg("%s: before wait_for_ctrl_irq\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1484) wait_for_ctrl_irq(ctrl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1485) dbg("%s: after wait_for_ctrl_irq\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1486)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1487) dbg("%s: before up\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1488) mutex_unlock(&ctrl->crit_sect);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1489) dbg("%s: after up\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1490)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1491) /* Wait for ~1 second because of hot plug spec */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1492) dbg("%s: before long_delay\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1493) long_delay(1*HZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1494) dbg("%s: after long_delay\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1495)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1496) dbg("%s: func status = %x\n", __func__, func->status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1497) /* Check for a power fault */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1498) if (func->status == 0xFF) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1499) /* power fault occurred, but it was benign */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1500) temp_register = 0xFFFFFFFF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1501) dbg("%s: temp register set to %x by power fault\n", __func__, temp_register);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1502) rc = POWER_FAILURE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1503) func->status = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1504) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1505) /* Get vendor/device ID u32 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1506) ctrl->pci_bus->number = func->bus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1507) rc = pci_bus_read_config_dword(ctrl->pci_bus, PCI_DEVFN(func->device, func->function), PCI_VENDOR_ID, &temp_register);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1508) dbg("%s: pci_read_config_dword returns %d\n", __func__, rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1509) dbg("%s: temp_register is %x\n", __func__, temp_register);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1510)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1511) if (rc != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1512) /* Something's wrong here */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1513) temp_register = 0xFFFFFFFF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1514) dbg("%s: temp register set to %x by error\n", __func__, temp_register);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1515) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1516) /* Preset return code. It will be changed later if things go okay. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1517) rc = NO_ADAPTER_PRESENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1518) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1519)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1520) /* All F's is an empty slot or an invalid board */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1521) if (temp_register != 0xFFFFFFFF) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1522) res_lists.io_head = ctrl->io_head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1523) res_lists.mem_head = ctrl->mem_head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1524) res_lists.p_mem_head = ctrl->p_mem_head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1525) res_lists.bus_head = ctrl->bus_head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1526) res_lists.irqs = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1527)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1528) rc = configure_new_device(ctrl, func, 0, &res_lists);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1529)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1530) dbg("%s: back from configure_new_device\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1531) ctrl->io_head = res_lists.io_head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1532) ctrl->mem_head = res_lists.mem_head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1533) ctrl->p_mem_head = res_lists.p_mem_head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1534) ctrl->bus_head = res_lists.bus_head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1535)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1536) cpqhp_resource_sort_and_combine(&(ctrl->mem_head));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1537) cpqhp_resource_sort_and_combine(&(ctrl->p_mem_head));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1538) cpqhp_resource_sort_and_combine(&(ctrl->io_head));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1539) cpqhp_resource_sort_and_combine(&(ctrl->bus_head));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1540)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1541) if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1542) mutex_lock(&ctrl->crit_sect);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1543)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1544) amber_LED_on(ctrl, hp_slot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1545) green_LED_off(ctrl, hp_slot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1546) slot_disable(ctrl, hp_slot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1547)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1548) set_SOGO(ctrl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1549)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1550) /* Wait for SOBS to be unset */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1551) wait_for_ctrl_irq(ctrl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1552)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1553) mutex_unlock(&ctrl->crit_sect);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1554) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1555) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1556) cpqhp_save_slot_config(ctrl, func);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1557) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1558)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1559)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1560) func->status = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1561) func->switch_save = 0x10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1562) func->is_a_board = 0x01;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1563)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1564) /* next, we will instantiate the linux pci_dev structures (with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1565) * appropriate driver notification, if already present) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1566) dbg("%s: configure linux pci_dev structure\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1567) index = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1568) do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1569) new_slot = cpqhp_slot_find(ctrl->bus, func->device, index++);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1570) if (new_slot && !new_slot->pci_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1571) cpqhp_configure_device(ctrl, new_slot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1572) } while (new_slot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1573)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1574) mutex_lock(&ctrl->crit_sect);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1575)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1576) green_LED_on(ctrl, hp_slot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1577)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1578) set_SOGO(ctrl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1579)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1580) /* Wait for SOBS to be unset */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1581) wait_for_ctrl_irq(ctrl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1582)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1583) mutex_unlock(&ctrl->crit_sect);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1584) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1585) mutex_lock(&ctrl->crit_sect);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1586)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1587) amber_LED_on(ctrl, hp_slot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1588) green_LED_off(ctrl, hp_slot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1589) slot_disable(ctrl, hp_slot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1590)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1591) set_SOGO(ctrl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1592)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1593) /* Wait for SOBS to be unset */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1594) wait_for_ctrl_irq(ctrl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1595)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1596) mutex_unlock(&ctrl->crit_sect);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1597)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1598) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1599) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1600) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1601) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1602)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1603)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1604) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1605) * remove_board - Turns off slot and LEDs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1606) * @func: PCI device/function info
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1607) * @replace_flag: whether replacing or adding a new device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1608) * @ctrl: target controller
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1609) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1610) static u32 remove_board(struct pci_func *func, u32 replace_flag, struct controller *ctrl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1611) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1612) int index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1613) u8 skip = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1614) u8 device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1615) u8 hp_slot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1616) u8 temp_byte;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1617) u32 rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1618) struct resource_lists res_lists;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1619) struct pci_func *temp_func;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1620)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1621) if (cpqhp_unconfigure_device(func))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1622) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1623)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1624) device = func->device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1625)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1626) hp_slot = func->device - ctrl->slot_device_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1627) dbg("In %s, hp_slot = %d\n", __func__, hp_slot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1628)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1629) /* When we get here, it is safe to change base address registers.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1630) * We will attempt to save the base address register lengths */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1631) if (replace_flag || !ctrl->add_support)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1632) rc = cpqhp_save_base_addr_length(ctrl, func);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1633) else if (!func->bus_head && !func->mem_head &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1634) !func->p_mem_head && !func->io_head) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1635) /* Here we check to see if we've saved any of the board's
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1636) * resources already. If so, we'll skip the attempt to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1637) * determine what's being used. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1638) index = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1639) temp_func = cpqhp_slot_find(func->bus, func->device, index++);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1640) while (temp_func) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1641) if (temp_func->bus_head || temp_func->mem_head
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1642) || temp_func->p_mem_head || temp_func->io_head) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1643) skip = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1644) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1645) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1646) temp_func = cpqhp_slot_find(temp_func->bus, temp_func->device, index++);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1647) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1648)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1649) if (!skip)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1650) rc = cpqhp_save_used_resources(ctrl, func);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1651) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1652) /* Change status to shutdown */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1653) if (func->is_a_board)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1654) func->status = 0x01;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1655) func->configured = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1656)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1657) mutex_lock(&ctrl->crit_sect);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1658)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1659) green_LED_off(ctrl, hp_slot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1660) slot_disable(ctrl, hp_slot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1661)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1662) set_SOGO(ctrl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1663)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1664) /* turn off SERR for slot */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1665) temp_byte = readb(ctrl->hpc_reg + SLOT_SERR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1666) temp_byte &= ~(0x01 << hp_slot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1667) writeb(temp_byte, ctrl->hpc_reg + SLOT_SERR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1668)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1669) /* Wait for SOBS to be unset */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1670) wait_for_ctrl_irq(ctrl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1671)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1672) mutex_unlock(&ctrl->crit_sect);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1673)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1674) if (!replace_flag && ctrl->add_support) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1675) while (func) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1676) res_lists.io_head = ctrl->io_head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1677) res_lists.mem_head = ctrl->mem_head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1678) res_lists.p_mem_head = ctrl->p_mem_head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1679) res_lists.bus_head = ctrl->bus_head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1680)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1681) cpqhp_return_board_resources(func, &res_lists);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1682)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1683) ctrl->io_head = res_lists.io_head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1684) ctrl->mem_head = res_lists.mem_head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1685) ctrl->p_mem_head = res_lists.p_mem_head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1686) ctrl->bus_head = res_lists.bus_head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1687)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1688) cpqhp_resource_sort_and_combine(&(ctrl->mem_head));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1689) cpqhp_resource_sort_and_combine(&(ctrl->p_mem_head));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1690) cpqhp_resource_sort_and_combine(&(ctrl->io_head));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1691) cpqhp_resource_sort_and_combine(&(ctrl->bus_head));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1692)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1693) if (is_bridge(func)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1694) bridge_slot_remove(func);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1695) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1696) slot_remove(func);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1697)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1698) func = cpqhp_slot_find(ctrl->bus, device, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1699) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1700)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1701) /* Setup slot structure with entry for empty slot */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1702) func = cpqhp_slot_create(ctrl->bus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1703)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1704) if (func == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1705) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1706)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1707) func->bus = ctrl->bus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1708) func->device = device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1709) func->function = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1710) func->configured = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1711) func->switch_save = 0x10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1712) func->is_a_board = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1713) func->p_task_event = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1714) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1715)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1716) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1717) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1718)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1719) static void pushbutton_helper_thread(struct timer_list *t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1720) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1721) pushbutton_pending = t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1722)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1723) wake_up_process(cpqhp_event_thread);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1724) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1725)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1726)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1727) /* this is the main worker thread */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1728) static int event_thread(void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1729) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1730) struct controller *ctrl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1731)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1732) while (1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1733) dbg("!!!!event_thread sleeping\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1734) set_current_state(TASK_INTERRUPTIBLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1735) schedule();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1736)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1737) if (kthread_should_stop())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1738) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1739) /* Do stuff here */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1740) if (pushbutton_pending)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1741) cpqhp_pushbutton_thread(pushbutton_pending);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1742) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1743) for (ctrl = cpqhp_ctrl_list; ctrl; ctrl = ctrl->next)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1744) interrupt_event_handler(ctrl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1745) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1746) dbg("event_thread signals exit\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1747) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1748) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1749)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1750) int cpqhp_event_start_thread(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1751) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1752) cpqhp_event_thread = kthread_run(event_thread, NULL, "phpd_event");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1753) if (IS_ERR(cpqhp_event_thread)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1754) err("Can't start up our event thread\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1755) return PTR_ERR(cpqhp_event_thread);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1756) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1757)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1758) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1759) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1760)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1761)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1762) void cpqhp_event_stop_thread(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1763) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1764) kthread_stop(cpqhp_event_thread);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1765) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1766)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1767)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1768) static void interrupt_event_handler(struct controller *ctrl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1769) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1770) int loop = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1771) int change = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1772) struct pci_func *func;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1773) u8 hp_slot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1774) struct slot *p_slot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1775)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1776) while (change) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1777) change = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1778)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1779) for (loop = 0; loop < 10; loop++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1780) /* dbg("loop %d\n", loop); */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1781) if (ctrl->event_queue[loop].event_type != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1782) hp_slot = ctrl->event_queue[loop].hp_slot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1783)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1784) func = cpqhp_slot_find(ctrl->bus, (hp_slot + ctrl->slot_device_offset), 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1785) if (!func)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1786) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1787)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1788) p_slot = cpqhp_find_slot(ctrl, hp_slot + ctrl->slot_device_offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1789) if (!p_slot)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1790) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1791)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1792) dbg("hp_slot %d, func %p, p_slot %p\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1793) hp_slot, func, p_slot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1794)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1795) if (ctrl->event_queue[loop].event_type == INT_BUTTON_PRESS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1796) dbg("button pressed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1797) } else if (ctrl->event_queue[loop].event_type ==
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1798) INT_BUTTON_CANCEL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1799) dbg("button cancel\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1800) del_timer(&p_slot->task_event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1801)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1802) mutex_lock(&ctrl->crit_sect);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1803)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1804) if (p_slot->state == BLINKINGOFF_STATE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1805) /* slot is on */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1806) dbg("turn on green LED\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1807) green_LED_on(ctrl, hp_slot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1808) } else if (p_slot->state == BLINKINGON_STATE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1809) /* slot is off */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1810) dbg("turn off green LED\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1811) green_LED_off(ctrl, hp_slot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1812) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1813)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1814) info(msg_button_cancel, p_slot->number);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1815)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1816) p_slot->state = STATIC_STATE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1817)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1818) amber_LED_off(ctrl, hp_slot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1819)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1820) set_SOGO(ctrl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1821)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1822) /* Wait for SOBS to be unset */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1823) wait_for_ctrl_irq(ctrl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1824)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1825) mutex_unlock(&ctrl->crit_sect);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1826) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1827) /*** button Released (No action on press...) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1828) else if (ctrl->event_queue[loop].event_type == INT_BUTTON_RELEASE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1829) dbg("button release\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1830)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1831) if (is_slot_enabled(ctrl, hp_slot)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1832) dbg("slot is on\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1833) p_slot->state = BLINKINGOFF_STATE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1834) info(msg_button_off, p_slot->number);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1835) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1836) dbg("slot is off\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1837) p_slot->state = BLINKINGON_STATE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1838) info(msg_button_on, p_slot->number);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1839) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1840) mutex_lock(&ctrl->crit_sect);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1841)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1842) dbg("blink green LED and turn off amber\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1843)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1844) amber_LED_off(ctrl, hp_slot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1845) green_LED_blink(ctrl, hp_slot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1846)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1847) set_SOGO(ctrl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1848)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1849) /* Wait for SOBS to be unset */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1850) wait_for_ctrl_irq(ctrl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1851)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1852) mutex_unlock(&ctrl->crit_sect);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1853) timer_setup(&p_slot->task_event,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1854) pushbutton_helper_thread,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1855) 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1856) p_slot->hp_slot = hp_slot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1857) p_slot->ctrl = ctrl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1858) /* p_slot->physical_slot = physical_slot; */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1859) p_slot->task_event.expires = jiffies + 5 * HZ; /* 5 second delay */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1860)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1861) dbg("add_timer p_slot = %p\n", p_slot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1862) add_timer(&p_slot->task_event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1863) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1864) /***********POWER FAULT */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1865) else if (ctrl->event_queue[loop].event_type == INT_POWER_FAULT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1866) dbg("power fault\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1867) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1868)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1869) ctrl->event_queue[loop].event_type = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1870)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1871) change = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1872) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1873) } /* End of FOR loop */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1874) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1875) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1876)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1877)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1878) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1879) * cpqhp_pushbutton_thread - handle pushbutton events
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1880) * @slot: target slot (struct)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1881) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1882) * Scheduled procedure to handle blocking stuff for the pushbuttons.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1883) * Handles all pending events and exits.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1884) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1885) void cpqhp_pushbutton_thread(struct timer_list *t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1886) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1887) u8 hp_slot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1888) u8 device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1889) struct pci_func *func;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1890) struct slot *p_slot = from_timer(p_slot, t, task_event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1891) struct controller *ctrl = (struct controller *) p_slot->ctrl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1892)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1893) pushbutton_pending = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1894) hp_slot = p_slot->hp_slot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1895)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1896) device = p_slot->device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1897)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1898) if (is_slot_enabled(ctrl, hp_slot)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1899) p_slot->state = POWEROFF_STATE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1900) /* power Down board */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1901) func = cpqhp_slot_find(p_slot->bus, p_slot->device, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1902) dbg("In power_down_board, func = %p, ctrl = %p\n", func, ctrl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1903) if (!func) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1904) dbg("Error! func NULL in %s\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1905) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1906) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1907)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1908) if (cpqhp_process_SS(ctrl, func) != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1909) amber_LED_on(ctrl, hp_slot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1910) green_LED_on(ctrl, hp_slot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1911)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1912) set_SOGO(ctrl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1913)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1914) /* Wait for SOBS to be unset */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1915) wait_for_ctrl_irq(ctrl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1916) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1917)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1918) p_slot->state = STATIC_STATE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1919) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1920) p_slot->state = POWERON_STATE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1921) /* slot is off */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1922)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1923) func = cpqhp_slot_find(p_slot->bus, p_slot->device, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1924) dbg("In add_board, func = %p, ctrl = %p\n", func, ctrl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1925) if (!func) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1926) dbg("Error! func NULL in %s\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1927) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1928) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1929)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1930) if (ctrl != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1931) if (cpqhp_process_SI(ctrl, func) != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1932) amber_LED_on(ctrl, hp_slot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1933) green_LED_off(ctrl, hp_slot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1934)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1935) set_SOGO(ctrl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1936)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1937) /* Wait for SOBS to be unset */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1938) wait_for_ctrl_irq(ctrl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1939) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1940) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1941)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1942) p_slot->state = STATIC_STATE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1943) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1944) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1945)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1946)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1947) int cpqhp_process_SI(struct controller *ctrl, struct pci_func *func)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1948) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1949) u8 device, hp_slot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1950) u16 temp_word;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1951) u32 tempdword;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1952) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1953) struct slot *p_slot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1954) int physical_slot = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1955)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1956) tempdword = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1957)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1958) device = func->device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1959) hp_slot = device - ctrl->slot_device_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1960) p_slot = cpqhp_find_slot(ctrl, device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1961) if (p_slot)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1962) physical_slot = p_slot->number;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1963)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1964) /* Check to see if the interlock is closed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1965) tempdword = readl(ctrl->hpc_reg + INT_INPUT_CLEAR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1966)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1967) if (tempdword & (0x01 << hp_slot))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1968) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1969)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1970) if (func->is_a_board) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1971) rc = board_replaced(func, ctrl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1972) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1973) /* add board */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1974) slot_remove(func);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1975)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1976) func = cpqhp_slot_create(ctrl->bus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1977) if (func == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1978) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1979)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1980) func->bus = ctrl->bus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1981) func->device = device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1982) func->function = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1983) func->configured = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1984) func->is_a_board = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1985)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1986) /* We have to save the presence info for these slots */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1987) temp_word = ctrl->ctrl_int_comp >> 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1988) func->presence_save = (temp_word >> hp_slot) & 0x01;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1989) func->presence_save |= (temp_word >> (hp_slot + 7)) & 0x02;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1990)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1991) if (ctrl->ctrl_int_comp & (0x1L << hp_slot)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1992) func->switch_save = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1993) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1994) func->switch_save = 0x10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1995) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1996)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1997) rc = board_added(func, ctrl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1998) if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1999) if (is_bridge(func)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2000) bridge_slot_remove(func);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2001) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2002) slot_remove(func);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2003)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2004) /* Setup slot structure with entry for empty slot */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2005) func = cpqhp_slot_create(ctrl->bus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2006)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2007) if (func == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2008) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2009)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2010) func->bus = ctrl->bus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2011) func->device = device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2012) func->function = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2013) func->configured = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2014) func->is_a_board = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2015)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2016) /* We have to save the presence info for these slots */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2017) temp_word = ctrl->ctrl_int_comp >> 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2018) func->presence_save = (temp_word >> hp_slot) & 0x01;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2019) func->presence_save |=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2020) (temp_word >> (hp_slot + 7)) & 0x02;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2021)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2022) if (ctrl->ctrl_int_comp & (0x1L << hp_slot)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2023) func->switch_save = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2024) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2025) func->switch_save = 0x10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2026) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2027) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2028) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2029)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2030) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2031) dbg("%s: rc = %d\n", __func__, rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2032)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2033) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2034) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2035)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2036)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2037) int cpqhp_process_SS(struct controller *ctrl, struct pci_func *func)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2038) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2039) u8 device, class_code, header_type, BCR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2040) u8 index = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2041) u8 replace_flag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2042) u32 rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2043) unsigned int devfn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2044) struct slot *p_slot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2045) struct pci_bus *pci_bus = ctrl->pci_bus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2046) int physical_slot = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2047)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2048) device = func->device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2049) func = cpqhp_slot_find(ctrl->bus, device, index++);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2050) p_slot = cpqhp_find_slot(ctrl, device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2051) if (p_slot)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2052) physical_slot = p_slot->number;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2053)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2054) /* Make sure there are no video controllers here */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2055) while (func && !rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2056) pci_bus->number = func->bus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2057) devfn = PCI_DEVFN(func->device, func->function);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2058)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2059) /* Check the Class Code */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2060) rc = pci_bus_read_config_byte(pci_bus, devfn, 0x0B, &class_code);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2061) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2062) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2063)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2064) if (class_code == PCI_BASE_CLASS_DISPLAY) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2065) /* Display/Video adapter (not supported) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2066) rc = REMOVE_NOT_SUPPORTED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2067) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2068) /* See if it's a bridge */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2069) rc = pci_bus_read_config_byte(pci_bus, devfn, PCI_HEADER_TYPE, &header_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2070) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2071) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2072)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2073) /* If it's a bridge, check the VGA Enable bit */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2074) if ((header_type & 0x7F) == PCI_HEADER_TYPE_BRIDGE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2075) rc = pci_bus_read_config_byte(pci_bus, devfn, PCI_BRIDGE_CONTROL, &BCR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2076) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2077) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2078)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2079) /* If the VGA Enable bit is set, remove isn't
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2080) * supported */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2081) if (BCR & PCI_BRIDGE_CTL_VGA)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2082) rc = REMOVE_NOT_SUPPORTED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2083) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2084) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2085)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2086) func = cpqhp_slot_find(ctrl->bus, device, index++);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2087) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2088)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2089) func = cpqhp_slot_find(ctrl->bus, device, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2090) if ((func != NULL) && !rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2091) /* FIXME: Replace flag should be passed into process_SS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2092) replace_flag = !(ctrl->add_support);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2093) rc = remove_board(func, replace_flag, ctrl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2094) } else if (!rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2095) rc = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2096) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2097)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2098) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2099) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2101) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2102) * switch_leds - switch the leds, go from one site to the other.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2103) * @ctrl: controller to use
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2104) * @num_of_slots: number of slots to use
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2105) * @work_LED: LED control value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2106) * @direction: 1 to start from the left side, 0 to start right.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2107) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2108) static void switch_leds(struct controller *ctrl, const int num_of_slots,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2109) u32 *work_LED, const int direction)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2110) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2111) int loop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2112)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2113) for (loop = 0; loop < num_of_slots; loop++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2114) if (direction)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2115) *work_LED = *work_LED >> 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2116) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2117) *work_LED = *work_LED << 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2118) writel(*work_LED, ctrl->hpc_reg + LED_CONTROL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2119)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2120) set_SOGO(ctrl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2121)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2122) /* Wait for SOGO interrupt */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2123) wait_for_ctrl_irq(ctrl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2124)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2125) /* Get ready for next iteration */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2126) long_delay((2*HZ)/10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2127) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2128) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2129)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2130) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2131) * cpqhp_hardware_test - runs hardware tests
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2132) * @ctrl: target controller
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2133) * @test_num: the number written to the "test" file in sysfs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2134) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2135) * For hot plug ctrl folks to play with.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2136) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2137) int cpqhp_hardware_test(struct controller *ctrl, int test_num)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2138) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2139) u32 save_LED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2140) u32 work_LED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2141) int loop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2142) int num_of_slots;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2143)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2144) num_of_slots = readb(ctrl->hpc_reg + SLOT_MASK) & 0x0f;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2145)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2146) switch (test_num) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2147) case 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2148) /* Do stuff here! */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2149)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2150) /* Do that funky LED thing */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2151) /* so we can restore them later */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2152) save_LED = readl(ctrl->hpc_reg + LED_CONTROL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2153) work_LED = 0x01010101;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2154) switch_leds(ctrl, num_of_slots, &work_LED, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2155) switch_leds(ctrl, num_of_slots, &work_LED, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2156) switch_leds(ctrl, num_of_slots, &work_LED, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2157) switch_leds(ctrl, num_of_slots, &work_LED, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2158)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2159) work_LED = 0x01010000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2160) writel(work_LED, ctrl->hpc_reg + LED_CONTROL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2161) switch_leds(ctrl, num_of_slots, &work_LED, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2162) switch_leds(ctrl, num_of_slots, &work_LED, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2163) work_LED = 0x00000101;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2164) writel(work_LED, ctrl->hpc_reg + LED_CONTROL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2165) switch_leds(ctrl, num_of_slots, &work_LED, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2166) switch_leds(ctrl, num_of_slots, &work_LED, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2167)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2168) work_LED = 0x01010000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2169) writel(work_LED, ctrl->hpc_reg + LED_CONTROL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2170) for (loop = 0; loop < num_of_slots; loop++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2171) set_SOGO(ctrl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2172)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2173) /* Wait for SOGO interrupt */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2174) wait_for_ctrl_irq(ctrl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2175)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2176) /* Get ready for next iteration */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2177) long_delay((3*HZ)/10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2178) work_LED = work_LED >> 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2179) writel(work_LED, ctrl->hpc_reg + LED_CONTROL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2180)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2181) set_SOGO(ctrl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2182)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2183) /* Wait for SOGO interrupt */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2184) wait_for_ctrl_irq(ctrl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2185)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2186) /* Get ready for next iteration */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2187) long_delay((3*HZ)/10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2188) work_LED = work_LED << 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2189) writel(work_LED, ctrl->hpc_reg + LED_CONTROL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2190) work_LED = work_LED << 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2191) writel(work_LED, ctrl->hpc_reg + LED_CONTROL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2192) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2193)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2194) /* put it back the way it was */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2195) writel(save_LED, ctrl->hpc_reg + LED_CONTROL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2196)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2197) set_SOGO(ctrl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2198)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2199) /* Wait for SOBS to be unset */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2200) wait_for_ctrl_irq(ctrl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2201) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2202) case 2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2203) /* Do other stuff here! */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2204) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2205) case 3:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2206) /* and more... */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2207) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2208) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2209) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2210) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2211)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2212)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2213) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2214) * configure_new_device - Configures the PCI header information of one board.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2215) * @ctrl: pointer to controller structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2216) * @func: pointer to function structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2217) * @behind_bridge: 1 if this is a recursive call, 0 if not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2218) * @resources: pointer to set of resource lists
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2219) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2220) * Returns 0 if success.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2221) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2222) static u32 configure_new_device(struct controller *ctrl, struct pci_func *func,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2223) u8 behind_bridge, struct resource_lists *resources)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2224) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2225) u8 temp_byte, function, max_functions, stop_it;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2226) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2227) u32 ID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2228) struct pci_func *new_slot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2229) int index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2230)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2231) new_slot = func;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2232)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2233) dbg("%s\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2234) /* Check for Multi-function device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2235) ctrl->pci_bus->number = func->bus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2236) rc = pci_bus_read_config_byte(ctrl->pci_bus, PCI_DEVFN(func->device, func->function), 0x0E, &temp_byte);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2237) if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2238) dbg("%s: rc = %d\n", __func__, rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2239) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2240) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2241)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2242) if (temp_byte & 0x80) /* Multi-function device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2243) max_functions = 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2244) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2245) max_functions = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2246)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2247) function = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2248)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2249) do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2250) rc = configure_new_function(ctrl, new_slot, behind_bridge, resources);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2251)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2252) if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2253) dbg("configure_new_function failed %d\n", rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2254) index = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2255)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2256) while (new_slot) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2257) new_slot = cpqhp_slot_find(new_slot->bus, new_slot->device, index++);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2258)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2259) if (new_slot)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2260) cpqhp_return_board_resources(new_slot, resources);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2261) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2262)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2263) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2264) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2265)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2266) function++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2267)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2268) stop_it = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2269)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2270) /* The following loop skips to the next present function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2271) * and creates a board structure */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2272)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2273) while ((function < max_functions) && (!stop_it)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2274) pci_bus_read_config_dword(ctrl->pci_bus, PCI_DEVFN(func->device, function), 0x00, &ID);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2275)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2276) if (ID == 0xFFFFFFFF) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2277) function++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2278) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2279) /* Setup slot structure. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2280) new_slot = cpqhp_slot_create(func->bus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2281)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2282) if (new_slot == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2283) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2284)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2285) new_slot->bus = func->bus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2286) new_slot->device = func->device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2287) new_slot->function = function;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2288) new_slot->is_a_board = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2289) new_slot->status = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2290)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2291) stop_it++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2292) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2293) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2294)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2295) } while (function < max_functions);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2296) dbg("returning from configure_new_device\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2297)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2298) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2299) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2300)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2301)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2302) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2303) * Configuration logic that involves the hotplug data structures and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2304) * their bookkeeping
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2305) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2306)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2307)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2308) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2309) * configure_new_function - Configures the PCI header information of one device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2310) * @ctrl: pointer to controller structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2311) * @func: pointer to function structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2312) * @behind_bridge: 1 if this is a recursive call, 0 if not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2313) * @resources: pointer to set of resource lists
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2314) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2315) * Calls itself recursively for bridged devices.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2316) * Returns 0 if success.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2317) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2318) static int configure_new_function(struct controller *ctrl, struct pci_func *func,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2319) u8 behind_bridge,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2320) struct resource_lists *resources)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2321) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2322) int cloop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2323) u8 IRQ = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2324) u8 temp_byte;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2325) u8 device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2326) u8 class_code;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2327) u16 command;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2328) u16 temp_word;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2329) u32 temp_dword;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2330) u32 rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2331) u32 temp_register;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2332) u32 base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2333) u32 ID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2334) unsigned int devfn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2335) struct pci_resource *mem_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2336) struct pci_resource *p_mem_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2337) struct pci_resource *io_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2338) struct pci_resource *bus_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2339) struct pci_resource *hold_mem_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2340) struct pci_resource *hold_p_mem_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2341) struct pci_resource *hold_IO_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2342) struct pci_resource *hold_bus_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2343) struct irq_mapping irqs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2344) struct pci_func *new_slot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2345) struct pci_bus *pci_bus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2346) struct resource_lists temp_resources;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2347)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2348) pci_bus = ctrl->pci_bus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2349) pci_bus->number = func->bus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2350) devfn = PCI_DEVFN(func->device, func->function);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2351)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2352) /* Check for Bridge */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2353) rc = pci_bus_read_config_byte(pci_bus, devfn, PCI_HEADER_TYPE, &temp_byte);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2354) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2355) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2356)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2357) if ((temp_byte & 0x7F) == PCI_HEADER_TYPE_BRIDGE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2358) /* set Primary bus */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2359) dbg("set Primary bus = %d\n", func->bus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2360) rc = pci_bus_write_config_byte(pci_bus, devfn, PCI_PRIMARY_BUS, func->bus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2361) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2362) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2363)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2364) /* find range of buses to use */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2365) dbg("find ranges of buses to use\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2366) bus_node = get_max_resource(&(resources->bus_head), 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2367)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2368) /* If we don't have any buses to allocate, we can't continue */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2369) if (!bus_node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2370) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2371)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2372) /* set Secondary bus */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2373) temp_byte = bus_node->base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2374) dbg("set Secondary bus = %d\n", bus_node->base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2375) rc = pci_bus_write_config_byte(pci_bus, devfn, PCI_SECONDARY_BUS, temp_byte);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2376) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2377) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2378)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2379) /* set subordinate bus */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2380) temp_byte = bus_node->base + bus_node->length - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2381) dbg("set subordinate bus = %d\n", bus_node->base + bus_node->length - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2382) rc = pci_bus_write_config_byte(pci_bus, devfn, PCI_SUBORDINATE_BUS, temp_byte);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2383) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2384) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2385)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2386) /* set subordinate Latency Timer and base Latency Timer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2387) temp_byte = 0x40;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2388) rc = pci_bus_write_config_byte(pci_bus, devfn, PCI_SEC_LATENCY_TIMER, temp_byte);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2389) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2390) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2391) rc = pci_bus_write_config_byte(pci_bus, devfn, PCI_LATENCY_TIMER, temp_byte);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2392) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2393) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2394)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2395) /* set Cache Line size */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2396) temp_byte = 0x08;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2397) rc = pci_bus_write_config_byte(pci_bus, devfn, PCI_CACHE_LINE_SIZE, temp_byte);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2398) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2399) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2400)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2401) /* Setup the IO, memory, and prefetchable windows */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2402) io_node = get_max_resource(&(resources->io_head), 0x1000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2403) if (!io_node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2404) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2405) mem_node = get_max_resource(&(resources->mem_head), 0x100000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2406) if (!mem_node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2407) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2408) p_mem_node = get_max_resource(&(resources->p_mem_head), 0x100000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2409) if (!p_mem_node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2410) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2411) dbg("Setup the IO, memory, and prefetchable windows\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2412) dbg("io_node\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2413) dbg("(base, len, next) (%x, %x, %p)\n", io_node->base,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2414) io_node->length, io_node->next);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2415) dbg("mem_node\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2416) dbg("(base, len, next) (%x, %x, %p)\n", mem_node->base,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2417) mem_node->length, mem_node->next);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2418) dbg("p_mem_node\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2419) dbg("(base, len, next) (%x, %x, %p)\n", p_mem_node->base,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2420) p_mem_node->length, p_mem_node->next);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2421)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2422) /* set up the IRQ info */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2423) if (!resources->irqs) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2424) irqs.barber_pole = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2425) irqs.interrupt[0] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2426) irqs.interrupt[1] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2427) irqs.interrupt[2] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2428) irqs.interrupt[3] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2429) irqs.valid_INT = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2430) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2431) irqs.barber_pole = resources->irqs->barber_pole;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2432) irqs.interrupt[0] = resources->irqs->interrupt[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2433) irqs.interrupt[1] = resources->irqs->interrupt[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2434) irqs.interrupt[2] = resources->irqs->interrupt[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2435) irqs.interrupt[3] = resources->irqs->interrupt[3];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2436) irqs.valid_INT = resources->irqs->valid_INT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2437) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2438)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2439) /* set up resource lists that are now aligned on top and bottom
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2440) * for anything behind the bridge. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2441) temp_resources.bus_head = bus_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2442) temp_resources.io_head = io_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2443) temp_resources.mem_head = mem_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2444) temp_resources.p_mem_head = p_mem_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2445) temp_resources.irqs = &irqs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2446)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2447) /* Make copies of the nodes we are going to pass down so that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2448) * if there is a problem,we can just use these to free resources
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2449) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2450) hold_bus_node = kmalloc(sizeof(*hold_bus_node), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2451) hold_IO_node = kmalloc(sizeof(*hold_IO_node), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2452) hold_mem_node = kmalloc(sizeof(*hold_mem_node), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2453) hold_p_mem_node = kmalloc(sizeof(*hold_p_mem_node), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2454)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2455) if (!hold_bus_node || !hold_IO_node || !hold_mem_node || !hold_p_mem_node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2456) kfree(hold_bus_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2457) kfree(hold_IO_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2458) kfree(hold_mem_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2459) kfree(hold_p_mem_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2460)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2461) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2462) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2463)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2464) memcpy(hold_bus_node, bus_node, sizeof(struct pci_resource));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2465)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2466) bus_node->base += 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2467) bus_node->length -= 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2468) bus_node->next = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2469)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2470) /* If we have IO resources copy them and fill in the bridge's
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2471) * IO range registers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2472) memcpy(hold_IO_node, io_node, sizeof(struct pci_resource));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2473) io_node->next = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2474)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2475) /* set IO base and Limit registers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2476) temp_byte = io_node->base >> 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2477) rc = pci_bus_write_config_byte(pci_bus, devfn, PCI_IO_BASE, temp_byte);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2478)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2479) temp_byte = (io_node->base + io_node->length - 1) >> 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2480) rc = pci_bus_write_config_byte(pci_bus, devfn, PCI_IO_LIMIT, temp_byte);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2481)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2482) /* Copy the memory resources and fill in the bridge's memory
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2483) * range registers.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2484) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2485) memcpy(hold_mem_node, mem_node, sizeof(struct pci_resource));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2486) mem_node->next = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2487)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2488) /* set Mem base and Limit registers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2489) temp_word = mem_node->base >> 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2490) rc = pci_bus_write_config_word(pci_bus, devfn, PCI_MEMORY_BASE, temp_word);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2491)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2492) temp_word = (mem_node->base + mem_node->length - 1) >> 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2493) rc = pci_bus_write_config_word(pci_bus, devfn, PCI_MEMORY_LIMIT, temp_word);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2494)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2495) memcpy(hold_p_mem_node, p_mem_node, sizeof(struct pci_resource));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2496) p_mem_node->next = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2497)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2498) /* set Pre Mem base and Limit registers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2499) temp_word = p_mem_node->base >> 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2500) rc = pci_bus_write_config_word(pci_bus, devfn, PCI_PREF_MEMORY_BASE, temp_word);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2501)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2502) temp_word = (p_mem_node->base + p_mem_node->length - 1) >> 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2503) rc = pci_bus_write_config_word(pci_bus, devfn, PCI_PREF_MEMORY_LIMIT, temp_word);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2504)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2505) /* Adjust this to compensate for extra adjustment in first loop
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2506) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2507) irqs.barber_pole--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2508)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2509) rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2510)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2511) /* Here we actually find the devices and configure them */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2512) for (device = 0; (device <= 0x1F) && !rc; device++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2513) irqs.barber_pole = (irqs.barber_pole + 1) & 0x03;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2514)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2515) ID = 0xFFFFFFFF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2516) pci_bus->number = hold_bus_node->base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2517) pci_bus_read_config_dword(pci_bus, PCI_DEVFN(device, 0), 0x00, &ID);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2518) pci_bus->number = func->bus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2519)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2520) if (ID != 0xFFFFFFFF) { /* device present */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2521) /* Setup slot structure. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2522) new_slot = cpqhp_slot_create(hold_bus_node->base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2523)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2524) if (new_slot == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2525) rc = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2526) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2527) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2528)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2529) new_slot->bus = hold_bus_node->base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2530) new_slot->device = device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2531) new_slot->function = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2532) new_slot->is_a_board = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2533) new_slot->status = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2534)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2535) rc = configure_new_device(ctrl, new_slot, 1, &temp_resources);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2536) dbg("configure_new_device rc=0x%x\n", rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2537) } /* End of IF (device in slot?) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2538) } /* End of FOR loop */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2539)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2540) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2541) goto free_and_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2542) /* save the interrupt routing information */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2543) if (resources->irqs) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2544) resources->irqs->interrupt[0] = irqs.interrupt[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2545) resources->irqs->interrupt[1] = irqs.interrupt[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2546) resources->irqs->interrupt[2] = irqs.interrupt[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2547) resources->irqs->interrupt[3] = irqs.interrupt[3];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2548) resources->irqs->valid_INT = irqs.valid_INT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2549) } else if (!behind_bridge) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2550) /* We need to hook up the interrupts here */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2551) for (cloop = 0; cloop < 4; cloop++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2552) if (irqs.valid_INT & (0x01 << cloop)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2553) rc = cpqhp_set_irq(func->bus, func->device,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2554) cloop + 1, irqs.interrupt[cloop]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2555) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2556) goto free_and_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2557) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2558) } /* end of for loop */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2559) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2560) /* Return unused bus resources
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2561) * First use the temporary node to store information for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2562) * the board */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2563) if (bus_node && temp_resources.bus_head) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2564) hold_bus_node->length = bus_node->base - hold_bus_node->base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2565)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2566) hold_bus_node->next = func->bus_head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2567) func->bus_head = hold_bus_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2568)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2569) temp_byte = temp_resources.bus_head->base - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2570)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2571) /* set subordinate bus */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2572) rc = pci_bus_write_config_byte(pci_bus, devfn, PCI_SUBORDINATE_BUS, temp_byte);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2573)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2574) if (temp_resources.bus_head->length == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2575) kfree(temp_resources.bus_head);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2576) temp_resources.bus_head = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2577) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2578) return_resource(&(resources->bus_head), temp_resources.bus_head);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2579) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2580) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2581)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2582) /* If we have IO space available and there is some left,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2583) * return the unused portion */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2584) if (hold_IO_node && temp_resources.io_head) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2585) io_node = do_pre_bridge_resource_split(&(temp_resources.io_head),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2586) &hold_IO_node, 0x1000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2587)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2588) /* Check if we were able to split something off */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2589) if (io_node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2590) hold_IO_node->base = io_node->base + io_node->length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2591)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2592) temp_byte = (hold_IO_node->base) >> 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2593) rc = pci_bus_write_config_word(pci_bus, devfn, PCI_IO_BASE, temp_byte);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2594)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2595) return_resource(&(resources->io_head), io_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2596) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2597)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2598) io_node = do_bridge_resource_split(&(temp_resources.io_head), 0x1000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2599)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2600) /* Check if we were able to split something off */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2601) if (io_node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2602) /* First use the temporary node to store
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2603) * information for the board */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2604) hold_IO_node->length = io_node->base - hold_IO_node->base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2605)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2606) /* If we used any, add it to the board's list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2607) if (hold_IO_node->length) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2608) hold_IO_node->next = func->io_head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2609) func->io_head = hold_IO_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2610)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2611) temp_byte = (io_node->base - 1) >> 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2612) rc = pci_bus_write_config_byte(pci_bus, devfn, PCI_IO_LIMIT, temp_byte);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2613)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2614) return_resource(&(resources->io_head), io_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2615) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2616) /* it doesn't need any IO */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2617) temp_word = 0x0000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2618) rc = pci_bus_write_config_word(pci_bus, devfn, PCI_IO_LIMIT, temp_word);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2619)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2620) return_resource(&(resources->io_head), io_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2621) kfree(hold_IO_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2622) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2623) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2624) /* it used most of the range */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2625) hold_IO_node->next = func->io_head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2626) func->io_head = hold_IO_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2627) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2628) } else if (hold_IO_node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2629) /* it used the whole range */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2630) hold_IO_node->next = func->io_head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2631) func->io_head = hold_IO_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2632) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2633) /* If we have memory space available and there is some left,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2634) * return the unused portion */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2635) if (hold_mem_node && temp_resources.mem_head) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2636) mem_node = do_pre_bridge_resource_split(&(temp_resources. mem_head),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2637) &hold_mem_node, 0x100000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2638)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2639) /* Check if we were able to split something off */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2640) if (mem_node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2641) hold_mem_node->base = mem_node->base + mem_node->length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2642)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2643) temp_word = (hold_mem_node->base) >> 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2644) rc = pci_bus_write_config_word(pci_bus, devfn, PCI_MEMORY_BASE, temp_word);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2645)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2646) return_resource(&(resources->mem_head), mem_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2647) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2648)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2649) mem_node = do_bridge_resource_split(&(temp_resources.mem_head), 0x100000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2650)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2651) /* Check if we were able to split something off */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2652) if (mem_node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2653) /* First use the temporary node to store
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2654) * information for the board */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2655) hold_mem_node->length = mem_node->base - hold_mem_node->base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2656)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2657) if (hold_mem_node->length) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2658) hold_mem_node->next = func->mem_head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2659) func->mem_head = hold_mem_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2660)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2661) /* configure end address */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2662) temp_word = (mem_node->base - 1) >> 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2663) rc = pci_bus_write_config_word(pci_bus, devfn, PCI_MEMORY_LIMIT, temp_word);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2664)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2665) /* Return unused resources to the pool */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2666) return_resource(&(resources->mem_head), mem_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2667) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2668) /* it doesn't need any Mem */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2669) temp_word = 0x0000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2670) rc = pci_bus_write_config_word(pci_bus, devfn, PCI_MEMORY_LIMIT, temp_word);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2671)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2672) return_resource(&(resources->mem_head), mem_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2673) kfree(hold_mem_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2674) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2675) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2676) /* it used most of the range */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2677) hold_mem_node->next = func->mem_head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2678) func->mem_head = hold_mem_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2679) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2680) } else if (hold_mem_node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2681) /* it used the whole range */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2682) hold_mem_node->next = func->mem_head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2683) func->mem_head = hold_mem_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2684) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2685) /* If we have prefetchable memory space available and there
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2686) * is some left at the end, return the unused portion */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2687) if (temp_resources.p_mem_head) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2688) p_mem_node = do_pre_bridge_resource_split(&(temp_resources.p_mem_head),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2689) &hold_p_mem_node, 0x100000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2690)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2691) /* Check if we were able to split something off */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2692) if (p_mem_node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2693) hold_p_mem_node->base = p_mem_node->base + p_mem_node->length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2694)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2695) temp_word = (hold_p_mem_node->base) >> 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2696) rc = pci_bus_write_config_word(pci_bus, devfn, PCI_PREF_MEMORY_BASE, temp_word);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2697)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2698) return_resource(&(resources->p_mem_head), p_mem_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2699) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2700)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2701) p_mem_node = do_bridge_resource_split(&(temp_resources.p_mem_head), 0x100000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2702)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2703) /* Check if we were able to split something off */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2704) if (p_mem_node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2705) /* First use the temporary node to store
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2706) * information for the board */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2707) hold_p_mem_node->length = p_mem_node->base - hold_p_mem_node->base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2708)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2709) /* If we used any, add it to the board's list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2710) if (hold_p_mem_node->length) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2711) hold_p_mem_node->next = func->p_mem_head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2712) func->p_mem_head = hold_p_mem_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2713)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2714) temp_word = (p_mem_node->base - 1) >> 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2715) rc = pci_bus_write_config_word(pci_bus, devfn, PCI_PREF_MEMORY_LIMIT, temp_word);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2716)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2717) return_resource(&(resources->p_mem_head), p_mem_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2718) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2719) /* it doesn't need any PMem */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2720) temp_word = 0x0000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2721) rc = pci_bus_write_config_word(pci_bus, devfn, PCI_PREF_MEMORY_LIMIT, temp_word);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2722)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2723) return_resource(&(resources->p_mem_head), p_mem_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2724) kfree(hold_p_mem_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2725) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2726) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2727) /* it used the most of the range */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2728) hold_p_mem_node->next = func->p_mem_head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2729) func->p_mem_head = hold_p_mem_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2730) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2731) } else if (hold_p_mem_node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2732) /* it used the whole range */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2733) hold_p_mem_node->next = func->p_mem_head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2734) func->p_mem_head = hold_p_mem_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2735) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2736) /* We should be configuring an IRQ and the bridge's base address
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2737) * registers if it needs them. Although we have never seen such
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2738) * a device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2739)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2740) /* enable card */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2741) command = 0x0157; /* = PCI_COMMAND_IO |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2742) * PCI_COMMAND_MEMORY |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2743) * PCI_COMMAND_MASTER |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2744) * PCI_COMMAND_INVALIDATE |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2745) * PCI_COMMAND_PARITY |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2746) * PCI_COMMAND_SERR */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2747) rc = pci_bus_write_config_word(pci_bus, devfn, PCI_COMMAND, command);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2748)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2749) /* set Bridge Control Register */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2750) command = 0x07; /* = PCI_BRIDGE_CTL_PARITY |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2751) * PCI_BRIDGE_CTL_SERR |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2752) * PCI_BRIDGE_CTL_NO_ISA */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2753) rc = pci_bus_write_config_word(pci_bus, devfn, PCI_BRIDGE_CONTROL, command);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2754) } else if ((temp_byte & 0x7F) == PCI_HEADER_TYPE_NORMAL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2755) /* Standard device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2756) rc = pci_bus_read_config_byte(pci_bus, devfn, 0x0B, &class_code);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2757)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2758) if (class_code == PCI_BASE_CLASS_DISPLAY) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2759) /* Display (video) adapter (not supported) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2760) return DEVICE_TYPE_NOT_SUPPORTED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2761) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2762) /* Figure out IO and memory needs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2763) for (cloop = 0x10; cloop <= 0x24; cloop += 4) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2764) temp_register = 0xFFFFFFFF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2765)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2766) dbg("CND: bus=%d, devfn=%d, offset=%d\n", pci_bus->number, devfn, cloop);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2767) rc = pci_bus_write_config_dword(pci_bus, devfn, cloop, temp_register);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2768)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2769) rc = pci_bus_read_config_dword(pci_bus, devfn, cloop, &temp_register);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2770) dbg("CND: base = 0x%x\n", temp_register);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2771)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2772) if (temp_register) { /* If this register is implemented */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2773) if ((temp_register & 0x03L) == 0x01) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2774) /* Map IO */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2775)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2776) /* set base = amount of IO space */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2777) base = temp_register & 0xFFFFFFFC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2778) base = ~base + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2779)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2780) dbg("CND: length = 0x%x\n", base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2781) io_node = get_io_resource(&(resources->io_head), base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2782) if (!io_node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2783) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2784) dbg("Got io_node start = %8.8x, length = %8.8x next (%p)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2785) io_node->base, io_node->length, io_node->next);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2786) dbg("func (%p) io_head (%p)\n", func, func->io_head);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2787)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2788) /* allocate the resource to the board */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2789) base = io_node->base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2790) io_node->next = func->io_head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2791) func->io_head = io_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2792) } else if ((temp_register & 0x0BL) == 0x08) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2793) /* Map prefetchable memory */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2794) base = temp_register & 0xFFFFFFF0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2795) base = ~base + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2796)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2797) dbg("CND: length = 0x%x\n", base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2798) p_mem_node = get_resource(&(resources->p_mem_head), base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2799)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2800) /* allocate the resource to the board */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2801) if (p_mem_node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2802) base = p_mem_node->base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2803)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2804) p_mem_node->next = func->p_mem_head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2805) func->p_mem_head = p_mem_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2806) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2807) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2808) } else if ((temp_register & 0x0BL) == 0x00) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2809) /* Map memory */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2810) base = temp_register & 0xFFFFFFF0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2811) base = ~base + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2812)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2813) dbg("CND: length = 0x%x\n", base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2814) mem_node = get_resource(&(resources->mem_head), base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2815)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2816) /* allocate the resource to the board */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2817) if (mem_node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2818) base = mem_node->base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2819)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2820) mem_node->next = func->mem_head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2821) func->mem_head = mem_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2822) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2823) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2824) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2825) /* Reserved bits or requesting space below 1M */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2826) return NOT_ENOUGH_RESOURCES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2827) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2828)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2829) rc = pci_bus_write_config_dword(pci_bus, devfn, cloop, base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2830)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2831) /* Check for 64-bit base */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2832) if ((temp_register & 0x07L) == 0x04) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2833) cloop += 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2834)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2835) /* Upper 32 bits of address always zero
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2836) * on today's systems */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2837) /* FIXME this is probably not true on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2838) * Alpha and ia64??? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2839) base = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2840) rc = pci_bus_write_config_dword(pci_bus, devfn, cloop, base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2841) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2842) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2843) } /* End of base register loop */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2844) if (cpqhp_legacy_mode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2845) /* Figure out which interrupt pin this function uses */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2846) rc = pci_bus_read_config_byte(pci_bus, devfn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2847) PCI_INTERRUPT_PIN, &temp_byte);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2848)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2849) /* If this function needs an interrupt and we are behind
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2850) * a bridge and the pin is tied to something that's
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2851) * already mapped, set this one the same */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2852) if (temp_byte && resources->irqs &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2853) (resources->irqs->valid_INT &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2854) (0x01 << ((temp_byte + resources->irqs->barber_pole - 1) & 0x03)))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2855) /* We have to share with something already set up */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2856) IRQ = resources->irqs->interrupt[(temp_byte +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2857) resources->irqs->barber_pole - 1) & 0x03];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2858) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2859) /* Program IRQ based on card type */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2860) rc = pci_bus_read_config_byte(pci_bus, devfn, 0x0B, &class_code);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2861)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2862) if (class_code == PCI_BASE_CLASS_STORAGE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2863) IRQ = cpqhp_disk_irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2864) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2865) IRQ = cpqhp_nic_irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2866) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2867)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2868) /* IRQ Line */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2869) rc = pci_bus_write_config_byte(pci_bus, devfn, PCI_INTERRUPT_LINE, IRQ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2870) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2871)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2872) if (!behind_bridge) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2873) rc = cpqhp_set_irq(func->bus, func->device, temp_byte, IRQ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2874) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2875) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2876) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2877) /* TBD - this code may also belong in the other clause
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2878) * of this If statement */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2879) resources->irqs->interrupt[(temp_byte + resources->irqs->barber_pole - 1) & 0x03] = IRQ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2880) resources->irqs->valid_INT |= 0x01 << (temp_byte + resources->irqs->barber_pole - 1) & 0x03;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2881) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2882)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2883) /* Latency Timer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2884) temp_byte = 0x40;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2885) rc = pci_bus_write_config_byte(pci_bus, devfn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2886) PCI_LATENCY_TIMER, temp_byte);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2887)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2888) /* Cache Line size */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2889) temp_byte = 0x08;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2890) rc = pci_bus_write_config_byte(pci_bus, devfn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2891) PCI_CACHE_LINE_SIZE, temp_byte);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2892)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2893) /* disable ROM base Address */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2894) temp_dword = 0x00L;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2895) rc = pci_bus_write_config_word(pci_bus, devfn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2896) PCI_ROM_ADDRESS, temp_dword);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2897)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2898) /* enable card */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2899) temp_word = 0x0157; /* = PCI_COMMAND_IO |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2900) * PCI_COMMAND_MEMORY |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2901) * PCI_COMMAND_MASTER |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2902) * PCI_COMMAND_INVALIDATE |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2903) * PCI_COMMAND_PARITY |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2904) * PCI_COMMAND_SERR */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2905) rc = pci_bus_write_config_word(pci_bus, devfn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2906) PCI_COMMAND, temp_word);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2907) } else { /* End of Not-A-Bridge else */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2908) /* It's some strange type of PCI adapter (Cardbus?) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2909) return DEVICE_TYPE_NOT_SUPPORTED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2910) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2911)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2912) func->configured = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2913)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2914) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2915) free_and_out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2916) cpqhp_destroy_resource_list(&temp_resources);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2917)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2918) return_resource(&(resources->bus_head), hold_bus_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2919) return_resource(&(resources->io_head), hold_IO_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2920) return_resource(&(resources->mem_head), hold_mem_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2921) return_resource(&(resources->p_mem_head), hold_p_mem_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2922) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2923) }