^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) * ACPI PCI HotPlug glue functions to ACPI CA subsystem
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (C) 2002,2003 Takayoshi Kochi (t-kochi@bq.jp.nec.com)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Copyright (C) 2002 Hiroshi Aono (h-aono@ap.jp.nec.com)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Copyright (C) 2002,2003 NEC Corporation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * Copyright (C) 2003-2005 Matthew Wilcox (willy@infradead.org)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * Copyright (C) 2003-2005 Hewlett Packard
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * Copyright (C) 2005 Rajesh Shah (rajesh.shah@intel.com)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * Copyright (C) 2005 Intel Corporation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) * All rights reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) * Send feedback to <kristen.c.accardi@intel.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) * Lifetime rules for pci_dev:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) * - The one in acpiphp_bridge has its refcount elevated by pci_get_slot()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) * when the bridge is scanned and it loses a refcount when the bridge
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) * is removed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) * - When a P2P bridge is present, we elevate the refcount on the subordinate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) * bus. It loses the refcount when the the driver unloads.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #define pr_fmt(fmt) "acpiphp_glue: " fmt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #include <linux/pci.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) #include <linux/pci_hotplug.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) #include <linux/pci-acpi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) #include <linux/pm_runtime.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) #include <linux/mutex.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) #include <linux/acpi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) #include "../pci.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) #include "acpiphp.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) static LIST_HEAD(bridge_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) static DEFINE_MUTEX(bridge_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) static int acpiphp_hotplug_notify(struct acpi_device *adev, u32 type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) static void acpiphp_post_dock_fixup(struct acpi_device *adev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) static void acpiphp_sanitize_bus(struct pci_bus *bus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) static void hotplug_event(u32 type, struct acpiphp_context *context);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) static void free_bridge(struct kref *kref);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) * acpiphp_init_context - Create hotplug context and grab a reference to it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) * @adev: ACPI device object to create the context for.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) * Call under acpi_hp_context_lock.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) static struct acpiphp_context *acpiphp_init_context(struct acpi_device *adev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) struct acpiphp_context *context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) context = kzalloc(sizeof(*context), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) if (!context)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) context->refcount = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) context->hp.notify = acpiphp_hotplug_notify;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) context->hp.fixup = acpiphp_post_dock_fixup;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) acpi_set_hp_context(adev, &context->hp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) return context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) * acpiphp_get_context - Get hotplug context and grab a reference to it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) * @adev: ACPI device object to get the context for.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) * Call under acpi_hp_context_lock.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) static struct acpiphp_context *acpiphp_get_context(struct acpi_device *adev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) struct acpiphp_context *context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) if (!adev->hp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) context = to_acpiphp_context(adev->hp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) context->refcount++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) return context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) }
^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) * acpiphp_put_context - Drop a reference to ACPI hotplug context.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) * @context: ACPI hotplug context to drop a reference to.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) * The context object is removed if there are no more references to it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) * Call under acpi_hp_context_lock.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) static void acpiphp_put_context(struct acpiphp_context *context)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) if (--context->refcount)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) WARN_ON(context->bridge);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) context->hp.self->hp = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) kfree(context);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) static inline void get_bridge(struct acpiphp_bridge *bridge)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) kref_get(&bridge->ref);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) static inline void put_bridge(struct acpiphp_bridge *bridge)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) kref_put(&bridge->ref, free_bridge);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) static struct acpiphp_context *acpiphp_grab_context(struct acpi_device *adev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) struct acpiphp_context *context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) acpi_lock_hp_context();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) context = acpiphp_get_context(adev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) if (!context)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) goto unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) if (context->func.parent->is_going_away) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) acpiphp_put_context(context);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) context = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) goto unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) get_bridge(context->func.parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) acpiphp_put_context(context);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) unlock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) acpi_unlock_hp_context();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) return context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) static void acpiphp_let_context_go(struct acpiphp_context *context)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) put_bridge(context->func.parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) static void free_bridge(struct kref *kref)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) struct acpiphp_context *context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) struct acpiphp_bridge *bridge;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) struct acpiphp_slot *slot, *next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) struct acpiphp_func *func, *tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) acpi_lock_hp_context();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) bridge = container_of(kref, struct acpiphp_bridge, ref);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) list_for_each_entry_safe(slot, next, &bridge->slots, node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) list_for_each_entry_safe(func, tmp, &slot->funcs, sibling)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) acpiphp_put_context(func_to_context(func));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) kfree(slot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) context = bridge->context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) /* Root bridges will not have hotplug context. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) if (context) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) /* Release the reference taken by acpiphp_enumerate_slots(). */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) put_bridge(context->func.parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) context->bridge = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) acpiphp_put_context(context);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) put_device(&bridge->pci_bus->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) pci_dev_put(bridge->pci_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) kfree(bridge);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) acpi_unlock_hp_context();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) * acpiphp_post_dock_fixup - Post-dock fixups for PCI devices.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) * @adev: ACPI device object corresponding to a PCI device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) * TBD - figure out a way to only call fixups for systems that require them.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) static void acpiphp_post_dock_fixup(struct acpi_device *adev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) struct acpiphp_context *context = acpiphp_grab_context(adev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) struct pci_bus *bus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) u32 buses;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) if (!context)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) bus = context->func.slot->bus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) if (!bus->self)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) /* fixup bad _DCK function that rewrites
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) * secondary bridge on slot
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) pci_read_config_dword(bus->self, PCI_PRIMARY_BUS, &buses);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) if (((buses >> 8) & 0xff) != bus->busn_res.start) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) buses = (buses & 0xff000000)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) | ((unsigned int)(bus->primary) << 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) | ((unsigned int)(bus->busn_res.start) << 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) | ((unsigned int)(bus->busn_res.end) << 16);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) pci_write_config_dword(bus->self, PCI_PRIMARY_BUS, buses);
^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) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) acpiphp_let_context_go(context);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) }
^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) * acpiphp_add_context - Add ACPIPHP context to an ACPI device object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) * @handle: ACPI handle of the object to add a context to.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) * @lvl: Not used.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) * @data: The object's parent ACPIPHP bridge.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) * @rv: Not used.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) static acpi_status acpiphp_add_context(acpi_handle handle, u32 lvl, void *data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) void **rv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) struct acpiphp_bridge *bridge = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) struct acpiphp_context *context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) struct acpi_device *adev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) struct acpiphp_slot *slot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) struct acpiphp_func *newfunc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) acpi_status status = AE_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) unsigned long long adr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) int device, function;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) struct pci_bus *pbus = bridge->pci_bus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) struct pci_dev *pdev = bridge->pci_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) u32 val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) status = acpi_evaluate_integer(handle, "_ADR", NULL, &adr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) if (ACPI_FAILURE(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) if (status != AE_NOT_FOUND)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) acpi_handle_warn(handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) "can't evaluate _ADR (%#x)\n", status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) return AE_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) if (acpi_bus_get_device(handle, &adev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) return AE_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) device = (adr >> 16) & 0xffff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) function = adr & 0xffff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) acpi_lock_hp_context();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) context = acpiphp_init_context(adev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) if (!context) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) acpi_unlock_hp_context();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) acpi_handle_err(handle, "No hotplug context\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) return AE_NOT_EXIST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) newfunc = &context->func;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) newfunc->function = function;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) newfunc->parent = bridge;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) acpi_unlock_hp_context();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) * If this is a dock device, its _EJ0 should be executed by the dock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) * notify handler after calling _DCK.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) if (!is_dock_device(adev) && acpi_has_method(handle, "_EJ0"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) newfunc->flags = FUNC_HAS_EJ0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) if (acpi_has_method(handle, "_STA"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) newfunc->flags |= FUNC_HAS_STA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) /* search for objects that share the same slot */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) list_for_each_entry(slot, &bridge->slots, node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) if (slot->device == device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) goto slot_found;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) slot = kzalloc(sizeof(struct acpiphp_slot), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) if (!slot) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) acpi_lock_hp_context();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) acpiphp_put_context(context);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) acpi_unlock_hp_context();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) return AE_NO_MEMORY;
^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) slot->bus = bridge->pci_bus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) slot->device = device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) INIT_LIST_HEAD(&slot->funcs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) list_add_tail(&slot->node, &bridge->slots);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) * Expose slots to user space for functions that have _EJ0 or _RMV or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) * are located in dock stations. Do not expose them for devices handled
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) * by the native PCIe hotplug (PCIeHP) or standard PCI hotplug
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) * (SHPCHP), because that code is supposed to expose slots to user
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) * space in those cases.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) if ((acpi_pci_check_ejectable(pbus, handle) || is_dock_device(adev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) && !(pdev && hotplug_is_native(pdev))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) unsigned long long sun;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) int retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) bridge->nr_slots++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) status = acpi_evaluate_integer(handle, "_SUN", NULL, &sun);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) if (ACPI_FAILURE(status))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) sun = bridge->nr_slots;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) pr_debug("found ACPI PCI Hotplug slot %llu at PCI %04x:%02x:%02x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) sun, pci_domain_nr(pbus), pbus->number, device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) retval = acpiphp_register_hotplug_slot(slot, sun);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) if (retval) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) slot->slot = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) bridge->nr_slots--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) if (retval == -EBUSY)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) pr_warn("Slot %llu already registered by another hotplug driver\n", sun);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) pr_warn("acpiphp_register_hotplug_slot failed (err code = 0x%x)\n", retval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) /* Even if the slot registration fails, we can still use it. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) slot_found:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) newfunc->slot = slot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) list_add_tail(&newfunc->sibling, &slot->funcs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) if (pci_bus_read_dev_vendor_id(pbus, PCI_DEVFN(device, function),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) &val, 60*1000))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) slot->flags |= SLOT_ENABLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) return AE_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) static void cleanup_bridge(struct acpiphp_bridge *bridge)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) struct acpiphp_slot *slot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) struct acpiphp_func *func;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) list_for_each_entry(slot, &bridge->slots, node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) list_for_each_entry(func, &slot->funcs, sibling) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) struct acpi_device *adev = func_to_acpi_device(func);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) acpi_lock_hp_context();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) adev->hp->notify = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) adev->hp->fixup = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) acpi_unlock_hp_context();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) slot->flags |= SLOT_IS_GOING_AWAY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) if (slot->slot)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) acpiphp_unregister_hotplug_slot(slot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) mutex_lock(&bridge_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) list_del(&bridge->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) mutex_unlock(&bridge_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) acpi_lock_hp_context();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) bridge->is_going_away = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) acpi_unlock_hp_context();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) * acpiphp_max_busnr - return the highest reserved bus number under the given bus.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) * @bus: bus to start search with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) static unsigned char acpiphp_max_busnr(struct pci_bus *bus)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) struct pci_bus *tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) unsigned char max, n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) * pci_bus_max_busnr will return the highest
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) * reserved busnr for all these children.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) * that is equivalent to the bus->subordinate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) * value. We don't want to use the parent's
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) * bus->subordinate value because it could have
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) * padding in it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) max = bus->busn_res.start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) list_for_each_entry(tmp, &bus->children, node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) n = pci_bus_max_busnr(tmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) if (n > max)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) max = n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) return max;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) static void acpiphp_set_acpi_region(struct acpiphp_slot *slot)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) struct acpiphp_func *func;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) list_for_each_entry(func, &slot->funcs, sibling) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) /* _REG is optional, we don't care about if there is failure */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) acpi_evaluate_reg(func_to_handle(func),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) ACPI_ADR_SPACE_PCI_CONFIG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) ACPI_REG_CONNECT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) static void check_hotplug_bridge(struct acpiphp_slot *slot, struct pci_dev *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) struct acpiphp_func *func;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) /* quirk, or pcie could set it already */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) if (dev->is_hotplug_bridge)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) list_for_each_entry(func, &slot->funcs, sibling) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) if (PCI_FUNC(dev->devfn) == func->function) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) dev->is_hotplug_bridge = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) }
^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) static int acpiphp_rescan_slot(struct acpiphp_slot *slot)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) struct acpiphp_func *func;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) list_for_each_entry(func, &slot->funcs, sibling) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) struct acpi_device *adev = func_to_acpi_device(func);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) acpi_bus_scan(adev->handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) if (acpi_device_enumerated(adev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) acpi_device_set_power(adev, ACPI_STATE_D0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) return pci_scan_slot(slot->bus, PCI_DEVFN(slot->device, 0));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) static void acpiphp_native_scan_bridge(struct pci_dev *bridge)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) struct pci_bus *bus = bridge->subordinate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) struct pci_dev *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) int max;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) if (!bus)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) max = bus->busn_res.start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) /* Scan already configured non-hotplug bridges */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) for_each_pci_bridge(dev, bus) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) if (!hotplug_is_native(dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) max = pci_scan_bridge(bus, dev, max, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) /* Scan non-hotplug bridges that need to be reconfigured */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) for_each_pci_bridge(dev, bus) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) if (hotplug_is_native(dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) max = pci_scan_bridge(bus, dev, max, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) if (dev->subordinate) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) pcibios_resource_survey_bus(dev->subordinate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) pci_bus_size_bridges(dev->subordinate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) pci_bus_assign_resources(dev->subordinate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) * enable_slot - enable, configure a slot
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) * @slot: slot to be enabled
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) * @bridge: true if enable is for the whole bridge (not a single slot)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) * This function should be called per *physical slot*,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) * not per each slot object in ACPI namespace.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) static void enable_slot(struct acpiphp_slot *slot, bool bridge)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) struct pci_dev *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) struct pci_bus *bus = slot->bus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) struct acpiphp_func *func;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) if (bridge && bus->self && hotplug_is_native(bus->self)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) * If native hotplug is used, it will take care of hotplug
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) * slot management and resource allocation for hotplug
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) * bridges. However, ACPI hotplug may still be used for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) * non-hotplug bridges to bring in additional devices such
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) * as a Thunderbolt host controller.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) for_each_pci_bridge(dev, bus) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) if (PCI_SLOT(dev->devfn) == slot->device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) acpiphp_native_scan_bridge(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) LIST_HEAD(add_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) int max, pass;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) acpiphp_rescan_slot(slot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) max = acpiphp_max_busnr(bus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) for (pass = 0; pass < 2; pass++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) for_each_pci_bridge(dev, bus) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) if (PCI_SLOT(dev->devfn) != slot->device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) max = pci_scan_bridge(bus, dev, max, pass);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) if (pass && dev->subordinate) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) check_hotplug_bridge(slot, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) pcibios_resource_survey_bus(dev->subordinate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) __pci_bus_size_bridges(dev->subordinate,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) &add_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) __pci_bus_assign_resources(bus, &add_list, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) acpiphp_sanitize_bus(bus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) pcie_bus_configure_settings(bus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) acpiphp_set_acpi_region(slot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) list_for_each_entry(dev, &bus->devices, bus_list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) /* Assume that newly added devices are powered on already. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) if (!pci_dev_is_added(dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) dev->current_state = PCI_D0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) pci_bus_add_devices(bus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) slot->flags |= SLOT_ENABLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) list_for_each_entry(func, &slot->funcs, sibling) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) dev = pci_get_slot(bus, PCI_DEVFN(slot->device,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) func->function));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) if (!dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) /* Do not set SLOT_ENABLED flag if some funcs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) are not added. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) slot->flags &= ~SLOT_ENABLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) pci_dev_put(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) * disable_slot - disable a slot
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) * @slot: ACPI PHP slot
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) static void disable_slot(struct acpiphp_slot *slot)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) struct pci_bus *bus = slot->bus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) struct pci_dev *dev, *prev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) struct acpiphp_func *func;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) * enable_slot() enumerates all functions in this device via
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) * pci_scan_slot(), whether they have associated ACPI hotplug
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) * methods (_EJ0, etc.) or not. Therefore, we remove all functions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) * here.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) list_for_each_entry_safe_reverse(dev, prev, &bus->devices, bus_list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) if (PCI_SLOT(dev->devfn) == slot->device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) pci_stop_and_remove_bus_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) list_for_each_entry(func, &slot->funcs, sibling)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) acpi_bus_trim(func_to_acpi_device(func));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) slot->flags &= ~SLOT_ENABLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) static bool slot_no_hotplug(struct acpiphp_slot *slot)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) struct pci_bus *bus = slot->bus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) struct pci_dev *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) list_for_each_entry(dev, &bus->devices, bus_list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) if (PCI_SLOT(dev->devfn) == slot->device && dev->ignore_hotplug)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) * get_slot_status - get ACPI slot status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) * @slot: ACPI PHP slot
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) * If a slot has _STA for each function and if any one of them
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) * returned non-zero status, return it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) * If a slot doesn't have _STA and if any one of its functions'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) * configuration space is configured, return 0x0f as a _STA.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) * Otherwise return 0.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) static unsigned int get_slot_status(struct acpiphp_slot *slot)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) unsigned long long sta = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) struct acpiphp_func *func;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) u32 dvid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) list_for_each_entry(func, &slot->funcs, sibling) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) if (func->flags & FUNC_HAS_STA) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) acpi_status status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) status = acpi_evaluate_integer(func_to_handle(func),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) "_STA", NULL, &sta);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) if (ACPI_SUCCESS(status) && sta)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) if (pci_bus_read_dev_vendor_id(slot->bus,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) PCI_DEVFN(slot->device, func->function),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) &dvid, 0)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) sta = ACPI_STA_ALL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) }
^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) if (!sta) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) * Check for the slot itself since it may be that the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) * ACPI slot is a device below PCIe upstream port so in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) * that case it may not even be reachable yet.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) if (pci_bus_read_dev_vendor_id(slot->bus,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) PCI_DEVFN(slot->device, 0), &dvid, 0)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) sta = ACPI_STA_ALL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) return (unsigned int)sta;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) static inline bool device_status_valid(unsigned int sta)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) * ACPI spec says that _STA may return bit 0 clear with bit 3 set
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) * if the device is valid but does not require a device driver to be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) * loaded (Section 6.3.7 of ACPI 5.0A).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) unsigned int mask = ACPI_STA_DEVICE_ENABLED | ACPI_STA_DEVICE_FUNCTIONING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) return (sta & mask) == mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) * trim_stale_devices - remove PCI devices that are not responding.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) * @dev: PCI device to start walking the hierarchy from.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) static void trim_stale_devices(struct pci_dev *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) struct acpi_device *adev = ACPI_COMPANION(&dev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) struct pci_bus *bus = dev->subordinate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) bool alive = dev->ignore_hotplug;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) if (adev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) acpi_status status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) unsigned long long sta;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) status = acpi_evaluate_integer(adev->handle, "_STA", NULL, &sta);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) alive = alive || (ACPI_SUCCESS(status) && device_status_valid(sta));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) if (!alive)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) alive = pci_device_is_present(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) if (!alive) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) pci_dev_set_disconnected(dev, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) if (pci_has_subordinate(dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) pci_walk_bus(dev->subordinate, pci_dev_set_disconnected,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) pci_stop_and_remove_bus_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) if (adev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) acpi_bus_trim(adev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) } else if (bus) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) struct pci_dev *child, *tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) /* The device is a bridge. so check the bus below it. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) pm_runtime_get_sync(&dev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) list_for_each_entry_safe_reverse(child, tmp, &bus->devices, bus_list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) trim_stale_devices(child);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) pm_runtime_put(&dev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) * acpiphp_check_bridge - re-enumerate devices
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) * @bridge: where to begin re-enumeration
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) * Iterate over all slots under this bridge and make sure that if a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) * card is present they are enabled, and if not they are disabled.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) static void acpiphp_check_bridge(struct acpiphp_bridge *bridge)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) struct acpiphp_slot *slot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) /* Bail out if the bridge is going away. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) if (bridge->is_going_away)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) if (bridge->pci_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) pm_runtime_get_sync(&bridge->pci_dev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) list_for_each_entry(slot, &bridge->slots, node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) struct pci_bus *bus = slot->bus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) struct pci_dev *dev, *tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) if (slot_no_hotplug(slot)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) ; /* do nothing */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) } else if (device_status_valid(get_slot_status(slot))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) /* remove stale devices if any */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) list_for_each_entry_safe_reverse(dev, tmp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) &bus->devices, bus_list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) if (PCI_SLOT(dev->devfn) == slot->device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) trim_stale_devices(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) /* configure all functions */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) enable_slot(slot, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) disable_slot(slot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) if (bridge->pci_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) pm_runtime_put(&bridge->pci_dev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) * Remove devices for which we could not assign resources, call
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) * arch specific code to fix-up the bus
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) static void acpiphp_sanitize_bus(struct pci_bus *bus)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) struct pci_dev *dev, *tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) unsigned long type_mask = IORESOURCE_IO | IORESOURCE_MEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) list_for_each_entry_safe_reverse(dev, tmp, &bus->devices, bus_list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) for (i = 0; i < PCI_BRIDGE_RESOURCES; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) struct resource *res = &dev->resource[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) if ((res->flags & type_mask) && !res->start &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) res->end) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) /* Could not assign a required resources
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) * for this device, remove it */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) pci_stop_and_remove_bus_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) * ACPI event handlers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) void acpiphp_check_host_bridge(struct acpi_device *adev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) struct acpiphp_bridge *bridge = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) acpi_lock_hp_context();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) if (adev->hp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) bridge = to_acpiphp_root_context(adev->hp)->root_bridge;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) if (bridge)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) get_bridge(bridge);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) acpi_unlock_hp_context();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) if (bridge) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) pci_lock_rescan_remove();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) acpiphp_check_bridge(bridge);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) pci_unlock_rescan_remove();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) put_bridge(bridge);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) static int acpiphp_disable_and_eject_slot(struct acpiphp_slot *slot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) static void hotplug_event(u32 type, struct acpiphp_context *context)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) acpi_handle handle = context->hp.self->handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) struct acpiphp_func *func = &context->func;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) struct acpiphp_slot *slot = func->slot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) struct acpiphp_bridge *bridge;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) acpi_lock_hp_context();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) bridge = context->bridge;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) if (bridge)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) get_bridge(bridge);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) acpi_unlock_hp_context();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) pci_lock_rescan_remove();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) switch (type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) case ACPI_NOTIFY_BUS_CHECK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) /* bus re-enumerate */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) acpi_handle_debug(handle, "Bus check in %s()\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) if (bridge)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) acpiphp_check_bridge(bridge);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) else if (!(slot->flags & SLOT_IS_GOING_AWAY))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) enable_slot(slot, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) case ACPI_NOTIFY_DEVICE_CHECK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) /* device check */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) acpi_handle_debug(handle, "Device check in %s()\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) if (bridge) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) acpiphp_check_bridge(bridge);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) } else if (!(slot->flags & SLOT_IS_GOING_AWAY)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) * Check if anything has changed in the slot and rescan
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) * from the parent if that's the case.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) if (acpiphp_rescan_slot(slot))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) acpiphp_check_bridge(func->parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) case ACPI_NOTIFY_EJECT_REQUEST:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) /* request device eject */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) acpi_handle_debug(handle, "Eject request in %s()\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) acpiphp_disable_and_eject_slot(slot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) pci_unlock_rescan_remove();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) if (bridge)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) put_bridge(bridge);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) static int acpiphp_hotplug_notify(struct acpi_device *adev, u32 type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) struct acpiphp_context *context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) context = acpiphp_grab_context(adev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) if (!context)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834) return -ENODATA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836) hotplug_event(type, context);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837) acpiphp_let_context_go(context);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) * acpiphp_enumerate_slots - Enumerate PCI slots for a given bus.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843) * @bus: PCI bus to enumerate the slots for.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845) * A "slot" is an object associated with a PCI device number. All functions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846) * (PCI devices) with the same bus and device number belong to the same slot.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848) void acpiphp_enumerate_slots(struct pci_bus *bus)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) struct acpiphp_bridge *bridge;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851) struct acpi_device *adev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852) acpi_handle handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853) acpi_status status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) if (acpiphp_disabled)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858) adev = ACPI_COMPANION(bus->bridge);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859) if (!adev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862) handle = adev->handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863) bridge = kzalloc(sizeof(struct acpiphp_bridge), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864) if (!bridge)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867) INIT_LIST_HEAD(&bridge->slots);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868) kref_init(&bridge->ref);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869) bridge->pci_dev = pci_dev_get(bus->self);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870) bridge->pci_bus = bus;
^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) * Grab a ref to the subordinate PCI bus in case the bus is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874) * removed via PCI core logical hotplug. The ref pins the bus
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875) * (which we access during module unload).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877) get_device(&bus->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879) acpi_lock_hp_context();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880) if (pci_is_root_bus(bridge->pci_bus)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881) struct acpiphp_root_context *root_context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883) root_context = kzalloc(sizeof(*root_context), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884) if (!root_context)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887) root_context->root_bridge = bridge;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888) acpi_set_hp_context(adev, &root_context->hp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890) struct acpiphp_context *context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893) * This bridge should have been registered as a hotplug function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894) * under its parent, so the context should be there, unless the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 895) * parent is going to be handled by pciehp, in which case this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896) * bridge is not interesting to us either.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 897) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 898) context = acpiphp_get_context(adev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 899) if (!context)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 900) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 901)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 902) bridge->context = context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 903) context->bridge = bridge;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 904) /* Get a reference to the parent bridge. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 905) get_bridge(context->func.parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 906) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 907) acpi_unlock_hp_context();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 908)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 909) /* Must be added to the list prior to calling acpiphp_add_context(). */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 910) mutex_lock(&bridge_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 911) list_add(&bridge->list, &bridge_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 912) mutex_unlock(&bridge_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 913)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 914) /* register all slot objects under this bridge */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 915) status = acpi_walk_namespace(ACPI_TYPE_DEVICE, handle, 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 916) acpiphp_add_context, NULL, bridge, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 917) if (ACPI_FAILURE(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 918) acpi_handle_err(handle, "failed to register slots\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 919) cleanup_bridge(bridge);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 920) put_bridge(bridge);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 921) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 922) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 923)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 924) err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 925) acpi_unlock_hp_context();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 926) put_device(&bus->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 927) pci_dev_put(bridge->pci_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 928) kfree(bridge);
^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) static void acpiphp_drop_bridge(struct acpiphp_bridge *bridge)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 932) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 933) if (pci_is_root_bus(bridge->pci_bus)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 934) struct acpiphp_root_context *root_context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 935) struct acpi_device *adev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 936)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 937) acpi_lock_hp_context();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 938) adev = ACPI_COMPANION(bridge->pci_bus->bridge);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 939) root_context = to_acpiphp_root_context(adev->hp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 940) adev->hp = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 941) acpi_unlock_hp_context();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 942) kfree(root_context);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 943) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 944) cleanup_bridge(bridge);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 945) put_bridge(bridge);
^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) * acpiphp_remove_slots - Remove slot objects associated with a given bus.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 950) * @bus: PCI bus to remove the slot objects for.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 951) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 952) void acpiphp_remove_slots(struct pci_bus *bus)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 953) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 954) struct acpiphp_bridge *bridge;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 955)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 956) if (acpiphp_disabled)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 957) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 958)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 959) mutex_lock(&bridge_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 960) list_for_each_entry(bridge, &bridge_list, list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 961) if (bridge->pci_bus == bus) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 962) mutex_unlock(&bridge_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 963) acpiphp_drop_bridge(bridge);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 964) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 965) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 966)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 967) mutex_unlock(&bridge_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 968) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 969)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 970) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 971) * acpiphp_enable_slot - power on slot
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 972) * @slot: ACPI PHP slot
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 973) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 974) int acpiphp_enable_slot(struct acpiphp_slot *slot)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 975) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 976) pci_lock_rescan_remove();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 977)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 978) if (slot->flags & SLOT_IS_GOING_AWAY) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 979) pci_unlock_rescan_remove();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 980) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 981) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 982)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 983) /* configure all functions */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 984) if (!(slot->flags & SLOT_ENABLED))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 985) enable_slot(slot, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 986)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 987) pci_unlock_rescan_remove();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 988) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 989) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 990)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 991) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 992) * acpiphp_disable_and_eject_slot - power off and eject slot
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 993) * @slot: ACPI PHP slot
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 994) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 995) static int acpiphp_disable_and_eject_slot(struct acpiphp_slot *slot)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 996) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 997) struct acpiphp_func *func;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 998)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 999) if (slot->flags & SLOT_IS_GOING_AWAY)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) /* unconfigure all functions */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) disable_slot(slot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) list_for_each_entry(func, &slot->funcs, sibling)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) if (func->flags & FUNC_HAS_EJ0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) acpi_handle handle = func_to_handle(func);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) if (ACPI_FAILURE(acpi_evaluate_ej0(handle)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) acpi_handle_err(handle, "_EJ0 failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) break;
^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) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) int acpiphp_disable_slot(struct acpiphp_slot *slot)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) * Acquire acpi_scan_lock to ensure that the execution of _EJ0 in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) * acpiphp_disable_and_eject_slot() will be synchronized properly.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) acpi_scan_lock_acquire();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) pci_lock_rescan_remove();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) ret = acpiphp_disable_and_eject_slot(slot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) pci_unlock_rescan_remove();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) acpi_scan_lock_release();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) * slot enabled: 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) * slot disabled: 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) u8 acpiphp_get_power_status(struct acpiphp_slot *slot)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) return (slot->flags & SLOT_ENABLED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) * latch open: 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) * latch closed: 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) u8 acpiphp_get_latch_status(struct acpiphp_slot *slot)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) return !(get_slot_status(slot) & ACPI_STA_DEVICE_UI);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) * adapter presence : 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) * absence : 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) u8 acpiphp_get_adapter_status(struct acpiphp_slot *slot)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) return !!get_slot_status(slot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) }