2018-01-27 04:22:04 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* Interface for Dynamic Logical Partitioning of I/O Slots on
|
|
|
|
* RPA-compliant PPC64 platform.
|
|
|
|
*
|
|
|
|
* John Rose <johnrose@austin.ibm.com>
|
|
|
|
* Linda Xie <lxie@us.ibm.com>
|
|
|
|
*
|
|
|
|
* October 2003
|
|
|
|
*
|
|
|
|
* Copyright (C) 2003 IBM.
|
|
|
|
*/
|
2008-10-28 03:48:52 +08:00
|
|
|
|
|
|
|
#undef DEBUG
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <linux/init.h>
|
2011-05-27 21:42:30 +08:00
|
|
|
#include <linux/module.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <linux/pci.h>
|
2005-10-31 07:03:48 +08:00
|
|
|
#include <linux/string.h>
|
2010-04-06 23:03:40 +08:00
|
|
|
#include <linux/vmalloc.h>
|
2005-10-31 07:03:48 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <asm/pci-bridge.h>
|
2006-03-26 17:37:14 +08:00
|
|
|
#include <linux/mutex.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <asm/rtas.h>
|
2005-07-25 23:16:42 +08:00
|
|
|
#include <asm/vio.h>
|
hotplug/drc-info: Add code to search ibm,drc-info property
rpadlpar_core.c: Provide parallel routines to search the older device-
tree properties ("ibm,drc-indexes", "ibm,drc-names", "ibm,drc-types"
and "ibm,drc-power-domains"), or the new property "ibm,drc-info".
The interface to examine the DRC information is changed from a "get"
function that returns values for local verification elsewhere, to a
"check" function that validates the 'name' and/or 'type' of a device
node. This update hides the format of the underlying device-tree
properties, and concentrates the value checks into a single function
without requiring the user to verify whether a search was successful.
Signed-off-by: Michael Bringmann <mwb@linux.vnet.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2017-12-02 07:19:48 +08:00
|
|
|
#include <linux/firmware.h>
|
2005-10-31 07:03:48 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
#include "../pci.h"
|
|
|
|
#include "rpaphp.h"
|
|
|
|
#include "rpadlpar.h"
|
|
|
|
|
2006-03-26 17:37:14 +08:00
|
|
|
static DEFINE_MUTEX(rpadlpar_mutex);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-07-25 23:17:03 +08:00
|
|
|
#define DLPAR_MODULE_NAME "rpadlpar_io"
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
#define NODE_TYPE_VIO 1
|
|
|
|
#define NODE_TYPE_SLOT 2
|
|
|
|
#define NODE_TYPE_PHB 3
|
|
|
|
|
2005-07-25 23:16:42 +08:00
|
|
|
static struct device_node *find_vio_slot_node(char *drc_name)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct device_node *parent = of_find_node_by_name(NULL, "vdevice");
|
2005-07-25 23:16:42 +08:00
|
|
|
struct device_node *dn = NULL;
|
|
|
|
int rc;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (!parent)
|
|
|
|
return NULL;
|
|
|
|
|
2005-07-25 23:16:42 +08:00
|
|
|
while ((dn = of_get_next_child(parent, dn))) {
|
hotplug/drc-info: Add code to search ibm,drc-info property
rpadlpar_core.c: Provide parallel routines to search the older device-
tree properties ("ibm,drc-indexes", "ibm,drc-names", "ibm,drc-types"
and "ibm,drc-power-domains"), or the new property "ibm,drc-info".
The interface to examine the DRC information is changed from a "get"
function that returns values for local verification elsewhere, to a
"check" function that validates the 'name' and/or 'type' of a device
node. This update hides the format of the underlying device-tree
properties, and concentrates the value checks into a single function
without requiring the user to verify whether a search was successful.
Signed-off-by: Michael Bringmann <mwb@linux.vnet.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2017-12-02 07:19:48 +08:00
|
|
|
rc = rpaphp_check_drc_props(dn, drc_name, NULL);
|
|
|
|
if (rc == 0)
|
2005-07-25 23:16:42 +08:00
|
|
|
break;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2019-03-23 02:27:21 +08:00
|
|
|
of_node_put(parent);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-07-25 23:16:42 +08:00
|
|
|
return dn;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Find dlpar-capable pci node that contains the specified name and type */
|
|
|
|
static struct device_node *find_php_slot_pci_node(char *drc_name,
|
|
|
|
char *drc_type)
|
|
|
|
{
|
|
|
|
struct device_node *np = NULL;
|
|
|
|
int rc;
|
|
|
|
|
2006-11-14 07:12:52 +08:00
|
|
|
while ((np = of_find_node_by_name(np, "pci"))) {
|
hotplug/drc-info: Add code to search ibm,drc-info property
rpadlpar_core.c: Provide parallel routines to search the older device-
tree properties ("ibm,drc-indexes", "ibm,drc-names", "ibm,drc-types"
and "ibm,drc-power-domains"), or the new property "ibm,drc-info".
The interface to examine the DRC information is changed from a "get"
function that returns values for local verification elsewhere, to a
"check" function that validates the 'name' and/or 'type' of a device
node. This update hides the format of the underlying device-tree
properties, and concentrates the value checks into a single function
without requiring the user to verify whether a search was successful.
Signed-off-by: Michael Bringmann <mwb@linux.vnet.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2017-12-02 07:19:48 +08:00
|
|
|
rc = rpaphp_check_drc_props(np, drc_name, drc_type);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (rc == 0)
|
hotplug/drc-info: Add code to search ibm,drc-info property
rpadlpar_core.c: Provide parallel routines to search the older device-
tree properties ("ibm,drc-indexes", "ibm,drc-names", "ibm,drc-types"
and "ibm,drc-power-domains"), or the new property "ibm,drc-info".
The interface to examine the DRC information is changed from a "get"
function that returns values for local verification elsewhere, to a
"check" function that validates the 'name' and/or 'type' of a device
node. This update hides the format of the underlying device-tree
properties, and concentrates the value checks into a single function
without requiring the user to verify whether a search was successful.
Signed-off-by: Michael Bringmann <mwb@linux.vnet.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2017-12-02 07:19:48 +08:00
|
|
|
break;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return np;
|
|
|
|
}
|
|
|
|
|
2019-03-23 02:27:21 +08:00
|
|
|
/* Returns a device_node with its reference count incremented */
|
2005-07-25 23:16:42 +08:00
|
|
|
static struct device_node *find_dlpar_node(char *drc_name, int *node_type)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct device_node *dn;
|
|
|
|
|
|
|
|
dn = find_php_slot_pci_node(drc_name, "SLOT");
|
|
|
|
if (dn) {
|
|
|
|
*node_type = NODE_TYPE_SLOT;
|
|
|
|
return dn;
|
|
|
|
}
|
|
|
|
|
|
|
|
dn = find_php_slot_pci_node(drc_name, "PHB");
|
|
|
|
if (dn) {
|
|
|
|
*node_type = NODE_TYPE_PHB;
|
|
|
|
return dn;
|
|
|
|
}
|
|
|
|
|
2005-07-25 23:16:42 +08:00
|
|
|
dn = find_vio_slot_node(drc_name);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (dn) {
|
|
|
|
*node_type = NODE_TYPE_VIO;
|
|
|
|
return dn;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2007-04-14 06:34:21 +08:00
|
|
|
/**
|
|
|
|
* find_php_slot - return hotplug slot structure for device node
|
2007-11-29 01:04:30 +08:00
|
|
|
* @dn: target &device_node
|
2007-04-14 06:34:21 +08:00
|
|
|
*
|
|
|
|
* This routine will return the hotplug slot structure
|
|
|
|
* for a given device node. Note that built-in PCI slots
|
|
|
|
* may be dlpar-able, but not hot-pluggable, so this routine
|
|
|
|
* will return NULL for built-in PCI slots.
|
|
|
|
*/
|
|
|
|
static struct slot *find_php_slot(struct device_node *dn)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2015-12-12 21:36:57 +08:00
|
|
|
struct slot *slot, *next;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2015-12-12 21:36:57 +08:00
|
|
|
list_for_each_entry_safe(slot, next, &rpaphp_slot_head,
|
|
|
|
rpaphp_slot_list) {
|
2006-01-13 08:35:23 +08:00
|
|
|
if (slot->dn == dn)
|
|
|
|
return slot;
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-01-13 08:35:23 +08:00
|
|
|
return NULL;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2005-07-25 23:16:53 +08:00
|
|
|
static struct pci_dev *dlpar_find_new_dev(struct pci_bus *parent,
|
|
|
|
struct device_node *dev_dn)
|
|
|
|
{
|
|
|
|
struct pci_dev *tmp = NULL;
|
|
|
|
struct device_node *child_dn;
|
|
|
|
|
|
|
|
list_for_each_entry(tmp, &parent->devices, bus_list) {
|
|
|
|
child_dn = pci_device_to_OF_node(tmp);
|
|
|
|
if (child_dn == dev_dn)
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2006-01-13 08:35:23 +08:00
|
|
|
static void dlpar_pci_add_bus(struct device_node *dn)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2006-01-13 08:35:23 +08:00
|
|
|
struct pci_dn *pdn = PCI_DN(dn);
|
2005-11-05 05:38:50 +08:00
|
|
|
struct pci_controller *phb = pdn->phb;
|
2005-04-17 06:20:36 +08:00
|
|
|
struct pci_dev *dev = NULL;
|
|
|
|
|
2015-03-17 13:15:06 +08:00
|
|
|
eeh_add_device_tree_early(pdn);
|
2005-12-02 08:56:14 +08:00
|
|
|
|
2005-11-05 05:38:50 +08:00
|
|
|
/* Add EADS device to PHB bus, adding new entry to bus->devices */
|
|
|
|
dev = of_create_pci_dev(dn, phb->bus, pdn->devfn);
|
|
|
|
if (!dev) {
|
2017-07-19 05:43:21 +08:00
|
|
|
printk(KERN_ERR "%s: failed to create pci dev for %pOF\n",
|
|
|
|
__func__, dn);
|
2006-01-13 08:35:23 +08:00
|
|
|
return;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2008-10-28 03:48:52 +08:00
|
|
|
/* Scan below the new bridge */
|
2014-05-04 12:23:43 +08:00
|
|
|
if (pci_is_bridge(dev))
|
2011-04-11 09:37:07 +08:00
|
|
|
of_scan_pci_bridge(dev);
|
2005-11-05 05:38:50 +08:00
|
|
|
|
[POWERPC] Rewrite IO allocation & mapping on powerpc64
This rewrites pretty much from scratch the handling of MMIO and PIO
space allocations on powerpc64. The main goals are:
- Get rid of imalloc and use more common code where possible
- Simplify the current mess so that PIO space is allocated and
mapped in a single place for PCI bridges
- Handle allocation constraints of PIO for all bridges including
hot plugged ones within the 2GB space reserved for IO ports,
so that devices on hotplugged busses will now work with drivers
that assume IO ports fit in an int.
- Cleanup and separate tracking of the ISA space in the reserved
low 64K of IO space. No ISA -> Nothing mapped there.
I booted a cell blade with IDE on PIO and MMIO and a dual G5 so
far, that's it :-)
With this patch, all allocations are done using the code in
mm/vmalloc.c, though we use the low level __get_vm_area with
explicit start/stop constraints in order to manage separate
areas for vmalloc/vmap, ioremap, and PCI IOs.
This greatly simplifies a lot of things, as you can see in the
diffstat of that patch :-)
A new pair of functions pcibios_map/unmap_io_space() now replace
all of the previous code that used to manipulate PCI IOs space.
The allocation is done at mapping time, which is now called from
scan_phb's, just before the devices are probed (instead of after,
which is by itself a bug fix). The only other caller is the PCI
hotplug code for hot adding PCI-PCI bridges (slots).
imalloc is gone, as is the "sub-allocation" thing, but I do beleive
that hotplug should still work in the sense that the space allocation
is always done by the PHB, but if you unmap a child bus of this PHB
(which seems to be possible), then the code should properly tear
down all the HPTE mappings for that area of the PHB allocated IO space.
I now always reserve the first 64K of IO space for the bridge with
the ISA bus on it. I have moved the code for tracking ISA in a separate
file which should also make it smarter if we ever are capable of
hot unplugging or re-plugging an ISA bridge.
This should have a side effect on platforms like powermac where VGA IOs
will no longer work. This is done on purpose though as they would have
worked semi-randomly before. The idea at this point is to isolate drivers
that might need to access those and fix them by providing a proper
function to obtain an offset to the legacy IOs of a given bus.
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Signed-off-by: Paul Mackerras <paulus@samba.org>
2007-06-04 13:15:36 +08:00
|
|
|
/* Map IO space for child bus, which may or may not succeed */
|
|
|
|
pcibios_map_io_space(dev->subordinate);
|
2005-11-05 05:38:50 +08:00
|
|
|
|
2008-10-28 03:48:52 +08:00
|
|
|
/* Finish adding it : resource allocation, adding devices, etc...
|
|
|
|
* Note that we need to perform the finish pass on the -parent-
|
|
|
|
* bus of the EADS bridge so the bridge device itself gets
|
|
|
|
* properly added
|
|
|
|
*/
|
|
|
|
pcibios_finish_adding_to_bus(phb->bus);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2005-07-25 23:16:58 +08:00
|
|
|
static int dlpar_add_pci_slot(char *drc_name, struct device_node *dn)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct pci_dev *dev;
|
2006-01-13 08:35:23 +08:00
|
|
|
struct pci_controller *phb;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2016-05-03 13:41:38 +08:00
|
|
|
if (pci_find_bus_by_node(dn))
|
2005-07-25 23:17:03 +08:00
|
|
|
return -EINVAL;
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* Add pci bus */
|
2006-01-13 08:35:23 +08:00
|
|
|
dlpar_pci_add_bus(dn);
|
|
|
|
|
|
|
|
/* Confirm new bridge dev was created */
|
|
|
|
phb = PCI_DN(dn)->phb;
|
|
|
|
dev = dlpar_find_new_dev(phb->bus, dn);
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
if (!dev) {
|
2008-03-04 11:09:46 +08:00
|
|
|
printk(KERN_ERR "%s: unable to add bus %s\n", __func__,
|
2005-04-17 06:20:36 +08:00
|
|
|
drc_name);
|
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
|
2006-01-13 08:35:23 +08:00
|
|
|
if (dev->hdr_type != PCI_HEADER_TYPE_BRIDGE) {
|
|
|
|
printk(KERN_ERR "%s: unexpected header type %d, unable to add bus %s\n",
|
2008-03-04 11:09:46 +08:00
|
|
|
__func__, dev->hdr_type, drc_name);
|
2006-01-13 08:35:23 +08:00
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
|
2005-07-25 23:16:42 +08:00
|
|
|
/* Add hotplug slot */
|
|
|
|
if (rpaphp_add_slot(dn)) {
|
|
|
|
printk(KERN_ERR "%s: unable to add hotplug slot %s\n",
|
2008-03-04 11:09:46 +08:00
|
|
|
__func__, drc_name);
|
2005-07-25 23:16:42 +08:00
|
|
|
return -EIO;
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-07-25 23:17:03 +08:00
|
|
|
static int dlpar_remove_phb(char *drc_name, struct device_node *dn)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2005-07-25 23:17:03 +08:00
|
|
|
struct slot *slot;
|
2005-09-06 11:17:54 +08:00
|
|
|
struct pci_dn *pdn;
|
2005-04-17 06:20:36 +08:00
|
|
|
int rc = 0;
|
|
|
|
|
2016-05-03 13:41:38 +08:00
|
|
|
if (!pci_find_bus_by_node(dn))
|
2005-07-25 23:17:03 +08:00
|
|
|
return -EINVAL;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2013-11-15 02:28:18 +08:00
|
|
|
/* If pci slot is hotpluggable, use hotplug to remove it */
|
2007-04-14 06:34:21 +08:00
|
|
|
slot = find_php_slot(dn);
|
2008-10-28 03:48:52 +08:00
|
|
|
if (slot && rpaphp_deregister_slot(slot)) {
|
|
|
|
printk(KERN_ERR "%s: unable to remove hotplug slot %s\n",
|
|
|
|
__func__, drc_name);
|
|
|
|
return -EIO;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2005-09-06 11:17:54 +08:00
|
|
|
pdn = dn->data;
|
|
|
|
BUG_ON(!pdn || !pdn->phb);
|
2008-10-28 03:48:52 +08:00
|
|
|
rc = remove_phb_dynamic(pdn->phb);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (rc < 0)
|
|
|
|
return rc;
|
|
|
|
|
2005-09-06 11:17:54 +08:00
|
|
|
pdn->phb = NULL;
|
2005-07-25 23:17:03 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-07-25 23:16:42 +08:00
|
|
|
static int dlpar_add_phb(char *drc_name, struct device_node *dn)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct pci_controller *phb;
|
|
|
|
|
2005-11-04 08:51:17 +08:00
|
|
|
if (PCI_DN(dn) && PCI_DN(dn)->phb) {
|
2005-07-25 23:17:03 +08:00
|
|
|
/* PHB already exists */
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
phb = init_phb_dynamic(dn);
|
|
|
|
if (!phb)
|
2005-07-25 23:17:03 +08:00
|
|
|
return -EIO;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-07-25 23:16:42 +08:00
|
|
|
if (rpaphp_add_slot(dn)) {
|
|
|
|
printk(KERN_ERR "%s: unable to add hotplug slot %s\n",
|
2008-03-04 11:09:46 +08:00
|
|
|
__func__, drc_name);
|
2005-07-25 23:16:42 +08:00
|
|
|
return -EIO;
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-07-25 23:17:03 +08:00
|
|
|
static int dlpar_add_vio_slot(char *drc_name, struct device_node *dn)
|
|
|
|
{
|
2016-11-01 23:26:03 +08:00
|
|
|
struct vio_dev *vio_dev;
|
|
|
|
|
|
|
|
vio_dev = vio_find_node(dn);
|
|
|
|
if (vio_dev) {
|
|
|
|
put_device(&vio_dev->dev);
|
2005-07-25 23:17:03 +08:00
|
|
|
return -EINVAL;
|
2016-11-01 23:26:03 +08:00
|
|
|
}
|
2005-07-25 23:17:03 +08:00
|
|
|
|
|
|
|
if (!vio_register_device_node(dn)) {
|
|
|
|
printk(KERN_ERR
|
|
|
|
"%s: failed to register vio node %s\n",
|
2008-03-04 11:09:46 +08:00
|
|
|
__func__, drc_name);
|
2005-07-25 23:17:03 +08:00
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/**
|
|
|
|
* dlpar_add_slot - DLPAR add an I/O Slot
|
|
|
|
* @drc_name: drc-name of newly added slot
|
|
|
|
*
|
2007-11-29 01:04:30 +08:00
|
|
|
* Make the hotplug module and the kernel aware of a newly added I/O Slot.
|
|
|
|
* Return Codes:
|
2005-04-17 06:20:36 +08:00
|
|
|
* 0 Success
|
|
|
|
* -ENODEV Not a valid drc_name
|
|
|
|
* -EINVAL Slot already added
|
|
|
|
* -ERESTARTSYS Signalled before obtaining lock
|
|
|
|
* -EIO Internal PCI Error
|
|
|
|
*/
|
|
|
|
int dlpar_add_slot(char *drc_name)
|
|
|
|
{
|
|
|
|
struct device_node *dn = NULL;
|
|
|
|
int node_type;
|
2005-07-25 23:17:03 +08:00
|
|
|
int rc = -EIO;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-03-26 17:37:14 +08:00
|
|
|
if (mutex_lock_interruptible(&rpadlpar_mutex))
|
2005-04-17 06:20:36 +08:00
|
|
|
return -ERESTARTSYS;
|
|
|
|
|
2005-07-25 23:16:42 +08:00
|
|
|
/* Find newly added node */
|
|
|
|
dn = find_dlpar_node(drc_name, &node_type);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (!dn) {
|
|
|
|
rc = -ENODEV;
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (node_type) {
|
|
|
|
case NODE_TYPE_VIO:
|
2005-07-25 23:17:03 +08:00
|
|
|
rc = dlpar_add_vio_slot(drc_name, dn);
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
|
|
|
case NODE_TYPE_SLOT:
|
|
|
|
rc = dlpar_add_pci_slot(drc_name, dn);
|
|
|
|
break;
|
|
|
|
case NODE_TYPE_PHB:
|
2005-07-25 23:16:42 +08:00
|
|
|
rc = dlpar_add_phb(drc_name, dn);
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
|
|
|
}
|
2019-03-23 02:27:21 +08:00
|
|
|
of_node_put(dn);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-07-25 23:17:03 +08:00
|
|
|
printk(KERN_INFO "%s: slot %s added\n", DLPAR_MODULE_NAME, drc_name);
|
2005-04-17 06:20:36 +08:00
|
|
|
exit:
|
2006-03-26 17:37:14 +08:00
|
|
|
mutex_unlock(&rpadlpar_mutex);
|
2005-04-17 06:20:36 +08:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* dlpar_remove_vio_slot - DLPAR remove a virtual I/O Slot
|
|
|
|
* @drc_name: drc-name of newly added slot
|
2007-11-29 01:04:30 +08:00
|
|
|
* @dn: &device_node
|
2005-04-17 06:20:36 +08:00
|
|
|
*
|
2007-11-29 01:04:30 +08:00
|
|
|
* Remove the kernel and hotplug representations of an I/O Slot.
|
2005-04-17 06:20:36 +08:00
|
|
|
* Return Codes:
|
|
|
|
* 0 Success
|
2005-07-25 23:17:03 +08:00
|
|
|
* -EINVAL Vio dev doesn't exist
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
2005-07-25 23:17:03 +08:00
|
|
|
static int dlpar_remove_vio_slot(char *drc_name, struct device_node *dn)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2005-07-25 23:16:42 +08:00
|
|
|
struct vio_dev *vio_dev;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-07-25 23:16:42 +08:00
|
|
|
vio_dev = vio_find_node(dn);
|
2005-07-25 23:17:03 +08:00
|
|
|
if (!vio_dev)
|
|
|
|
return -EINVAL;
|
2005-07-25 23:16:42 +08:00
|
|
|
|
|
|
|
vio_unregister_device(vio_dev);
|
2016-11-01 23:26:03 +08:00
|
|
|
|
|
|
|
put_device(&vio_dev->dev);
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2007-11-29 01:04:30 +08:00
|
|
|
* dlpar_remove_pci_slot - DLPAR remove a PCI I/O Slot
|
2005-04-17 06:20:36 +08:00
|
|
|
* @drc_name: drc-name of newly added slot
|
2007-11-29 01:04:30 +08:00
|
|
|
* @dn: &device_node
|
2005-04-17 06:20:36 +08:00
|
|
|
*
|
2007-11-29 01:04:30 +08:00
|
|
|
* Remove the kernel and hotplug representations of a PCI I/O Slot.
|
2005-04-17 06:20:36 +08:00
|
|
|
* Return Codes:
|
|
|
|
* 0 Success
|
|
|
|
* -ENODEV Not a valid drc_name
|
|
|
|
* -EIO Internal PCI Error
|
|
|
|
*/
|
2005-07-25 23:17:03 +08:00
|
|
|
int dlpar_remove_pci_slot(char *drc_name, struct device_node *dn)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2005-07-25 23:17:03 +08:00
|
|
|
struct pci_bus *bus;
|
|
|
|
struct slot *slot;
|
2014-01-15 03:03:14 +08:00
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
pci_lock_rescan_remove();
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2016-05-03 13:41:38 +08:00
|
|
|
bus = pci_find_bus_by_node(dn);
|
2014-01-15 03:03:14 +08:00
|
|
|
if (!bus) {
|
|
|
|
ret = -EINVAL;
|
|
|
|
goto out;
|
|
|
|
}
|
2005-07-25 23:17:03 +08:00
|
|
|
|
2008-10-28 03:48:52 +08:00
|
|
|
pr_debug("PCI: Removing PCI slot below EADS bridge %s\n",
|
|
|
|
bus->self ? pci_name(bus->self) : "<!PHB!>");
|
|
|
|
|
2007-04-14 06:34:21 +08:00
|
|
|
slot = find_php_slot(dn);
|
2005-07-25 23:17:03 +08:00
|
|
|
if (slot) {
|
2008-10-28 03:48:52 +08:00
|
|
|
pr_debug("PCI: Removing hotplug slot for %04x:%02x...\n",
|
|
|
|
pci_domain_nr(bus), bus->number);
|
|
|
|
|
2006-01-13 08:31:01 +08:00
|
|
|
if (rpaphp_deregister_slot(slot)) {
|
2005-07-25 23:17:03 +08:00
|
|
|
printk(KERN_ERR
|
|
|
|
"%s: unable to remove hotplug slot %s\n",
|
2008-03-04 11:09:46 +08:00
|
|
|
__func__, drc_name);
|
2014-01-15 03:03:14 +08:00
|
|
|
ret = -EIO;
|
|
|
|
goto out;
|
2005-07-25 23:17:03 +08:00
|
|
|
}
|
2008-10-28 03:48:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Remove all devices below slot */
|
2016-05-03 13:41:37 +08:00
|
|
|
pci_hp_remove_devices(bus);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-10-28 03:48:52 +08:00
|
|
|
/* Unmap PCI IO space */
|
[POWERPC] Rewrite IO allocation & mapping on powerpc64
This rewrites pretty much from scratch the handling of MMIO and PIO
space allocations on powerpc64. The main goals are:
- Get rid of imalloc and use more common code where possible
- Simplify the current mess so that PIO space is allocated and
mapped in a single place for PCI bridges
- Handle allocation constraints of PIO for all bridges including
hot plugged ones within the 2GB space reserved for IO ports,
so that devices on hotplugged busses will now work with drivers
that assume IO ports fit in an int.
- Cleanup and separate tracking of the ISA space in the reserved
low 64K of IO space. No ISA -> Nothing mapped there.
I booted a cell blade with IDE on PIO and MMIO and a dual G5 so
far, that's it :-)
With this patch, all allocations are done using the code in
mm/vmalloc.c, though we use the low level __get_vm_area with
explicit start/stop constraints in order to manage separate
areas for vmalloc/vmap, ioremap, and PCI IOs.
This greatly simplifies a lot of things, as you can see in the
diffstat of that patch :-)
A new pair of functions pcibios_map/unmap_io_space() now replace
all of the previous code that used to manipulate PCI IOs space.
The allocation is done at mapping time, which is now called from
scan_phb's, just before the devices are probed (instead of after,
which is by itself a bug fix). The only other caller is the PCI
hotplug code for hot adding PCI-PCI bridges (slots).
imalloc is gone, as is the "sub-allocation" thing, but I do beleive
that hotplug should still work in the sense that the space allocation
is always done by the PHB, but if you unmap a child bus of this PHB
(which seems to be possible), then the code should properly tear
down all the HPTE mappings for that area of the PHB allocated IO space.
I now always reserve the first 64K of IO space for the bridge with
the ISA bus on it. I have moved the code for tracking ISA in a separate
file which should also make it smarter if we ever are capable of
hot unplugging or re-plugging an ISA bridge.
This should have a side effect on platforms like powermac where VGA IOs
will no longer work. This is done on purpose though as they would have
worked semi-randomly before. The idea at this point is to isolate drivers
that might need to access those and fix them by providing a proper
function to obtain an offset to the legacy IOs of a given bus.
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Signed-off-by: Paul Mackerras <paulus@samba.org>
2007-06-04 13:15:36 +08:00
|
|
|
if (pcibios_unmap_io_space(bus)) {
|
2005-07-26 00:13:38 +08:00
|
|
|
printk(KERN_ERR "%s: failed to unmap bus range\n",
|
2008-03-04 11:09:46 +08:00
|
|
|
__func__);
|
2014-01-15 03:03:14 +08:00
|
|
|
ret = -ERANGE;
|
|
|
|
goto out;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2005-07-26 00:13:38 +08:00
|
|
|
|
2008-10-28 03:48:52 +08:00
|
|
|
/* Remove the EADS bridge device itself */
|
2005-07-26 00:13:38 +08:00
|
|
|
BUG_ON(!bus->self);
|
2008-10-28 03:48:52 +08:00
|
|
|
pr_debug("PCI: Now removing bridge device %s\n", pci_name(bus->self));
|
2012-02-26 05:54:20 +08:00
|
|
|
pci_stop_and_remove_bus_device(bus->self);
|
2008-10-28 03:48:52 +08:00
|
|
|
|
2014-01-15 03:03:14 +08:00
|
|
|
out:
|
|
|
|
pci_unlock_rescan_remove();
|
|
|
|
return ret;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* dlpar_remove_slot - DLPAR remove an I/O Slot
|
|
|
|
* @drc_name: drc-name of newly added slot
|
|
|
|
*
|
2007-11-29 01:04:30 +08:00
|
|
|
* Remove the kernel and hotplug representations of an I/O Slot.
|
2005-04-17 06:20:36 +08:00
|
|
|
* Return Codes:
|
|
|
|
* 0 Success
|
|
|
|
* -ENODEV Not a valid drc_name
|
|
|
|
* -EINVAL Slot already removed
|
|
|
|
* -ERESTARTSYS Signalled before obtaining lock
|
|
|
|
* -EIO Internal Error
|
|
|
|
*/
|
|
|
|
int dlpar_remove_slot(char *drc_name)
|
|
|
|
{
|
2005-07-25 23:16:42 +08:00
|
|
|
struct device_node *dn;
|
|
|
|
int node_type;
|
2005-04-17 06:20:36 +08:00
|
|
|
int rc = 0;
|
|
|
|
|
2006-03-26 17:37:14 +08:00
|
|
|
if (mutex_lock_interruptible(&rpadlpar_mutex))
|
2005-04-17 06:20:36 +08:00
|
|
|
return -ERESTARTSYS;
|
|
|
|
|
2005-07-25 23:16:42 +08:00
|
|
|
dn = find_dlpar_node(drc_name, &node_type);
|
|
|
|
if (!dn) {
|
2005-04-17 06:20:36 +08:00
|
|
|
rc = -ENODEV;
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
|
2005-07-25 23:17:03 +08:00
|
|
|
switch (node_type) {
|
|
|
|
case NODE_TYPE_VIO:
|
|
|
|
rc = dlpar_remove_vio_slot(drc_name, dn);
|
|
|
|
break;
|
|
|
|
case NODE_TYPE_PHB:
|
|
|
|
rc = dlpar_remove_phb(drc_name, dn);
|
|
|
|
break;
|
|
|
|
case NODE_TYPE_SLOT:
|
|
|
|
rc = dlpar_remove_pci_slot(drc_name, dn);
|
|
|
|
break;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2019-03-23 02:27:21 +08:00
|
|
|
of_node_put(dn);
|
2010-04-06 23:03:40 +08:00
|
|
|
vm_unmap_aliases();
|
|
|
|
|
2005-07-25 23:17:03 +08:00
|
|
|
printk(KERN_INFO "%s: slot %s removed\n", DLPAR_MODULE_NAME, drc_name);
|
2005-04-17 06:20:36 +08:00
|
|
|
exit:
|
2006-03-26 17:37:14 +08:00
|
|
|
mutex_unlock(&rpadlpar_mutex);
|
2005-04-17 06:20:36 +08:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int is_dlpar_capable(void)
|
|
|
|
{
|
|
|
|
int rc = rtas_token("ibm,configure-connector");
|
|
|
|
|
|
|
|
return (int) (rc != RTAS_UNKNOWN_SERVICE);
|
|
|
|
}
|
|
|
|
|
|
|
|
int __init rpadlpar_io_init(void)
|
|
|
|
{
|
|
|
|
|
|
|
|
if (!is_dlpar_capable()) {
|
|
|
|
printk(KERN_WARNING "%s: partition not DLPAR capable\n",
|
2008-03-04 11:09:46 +08:00
|
|
|
__func__);
|
2005-04-17 06:20:36 +08:00
|
|
|
return -EPERM;
|
|
|
|
}
|
|
|
|
|
2016-12-24 17:38:00 +08:00
|
|
|
return dlpar_sysfs_init();
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void rpadlpar_io_exit(void)
|
|
|
|
{
|
|
|
|
dlpar_sysfs_exit();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
module_init(rpadlpar_io_init);
|
|
|
|
module_exit(rpadlpar_io_exit);
|
|
|
|
MODULE_LICENSE("GPL");
|