2005-11-19 17:17:32 +08:00
|
|
|
#ifndef _ASM_POWERPC_PCI_BRIDGE_H
|
|
|
|
#define _ASM_POWERPC_PCI_BRIDGE_H
|
2005-12-17 05:43:46 +08:00
|
|
|
#ifdef __KERNEL__
|
2007-12-06 15:02:28 +08:00
|
|
|
/*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version
|
|
|
|
* 2 of the License, or (at your option) any later version.
|
|
|
|
*/
|
2007-06-27 13:16:25 +08:00
|
|
|
#include <linux/pci.h>
|
2007-06-28 02:09:43 +08:00
|
|
|
#include <linux/list.h>
|
|
|
|
#include <linux/ioport.h>
|
|
|
|
|
2007-12-10 11:33:21 +08:00
|
|
|
struct device_node;
|
|
|
|
|
2015-03-31 13:00:42 +08:00
|
|
|
/*
|
|
|
|
* PCI controller operations
|
|
|
|
*/
|
|
|
|
struct pci_controller_ops {
|
2016-05-03 13:41:20 +08:00
|
|
|
void (*dma_dev_setup)(struct pci_dev *pdev);
|
2015-03-31 13:00:43 +08:00
|
|
|
void (*dma_bus_setup)(struct pci_bus *bus);
|
2015-03-31 13:00:44 +08:00
|
|
|
|
2016-05-03 13:41:20 +08:00
|
|
|
int (*probe_mode)(struct pci_bus *bus);
|
2015-03-31 13:00:45 +08:00
|
|
|
|
|
|
|
/* Called when pci_enable_device() is called. Returns true to
|
|
|
|
* allow assignment/enabling of the device. */
|
2016-05-03 13:41:20 +08:00
|
|
|
bool (*enable_device_hook)(struct pci_dev *pdev);
|
2015-03-31 13:00:46 +08:00
|
|
|
|
2016-05-03 13:41:20 +08:00
|
|
|
void (*disable_device)(struct pci_dev *pdev);
|
2015-05-27 14:07:00 +08:00
|
|
|
|
2016-05-03 13:41:20 +08:00
|
|
|
void (*release_device)(struct pci_dev *pdev);
|
2015-05-27 14:06:57 +08:00
|
|
|
|
2015-03-31 13:00:46 +08:00
|
|
|
/* Called during PCI resource reassignment */
|
2016-05-03 13:41:20 +08:00
|
|
|
resource_size_t (*window_alignment)(struct pci_bus *bus,
|
|
|
|
unsigned long type);
|
2016-05-20 14:41:26 +08:00
|
|
|
void (*setup_bridge)(struct pci_bus *bus,
|
|
|
|
unsigned long type);
|
2016-05-03 13:41:20 +08:00
|
|
|
void (*reset_secondary_bus)(struct pci_dev *pdev);
|
2015-04-14 12:27:54 +08:00
|
|
|
|
|
|
|
#ifdef CONFIG_PCI_MSI
|
2016-05-03 13:41:20 +08:00
|
|
|
int (*setup_msi_irqs)(struct pci_dev *pdev,
|
2015-04-14 12:27:54 +08:00
|
|
|
int nvec, int type);
|
2016-05-03 13:41:20 +08:00
|
|
|
void (*teardown_msi_irqs)(struct pci_dev *pdev);
|
2015-04-14 12:27:54 +08:00
|
|
|
#endif
|
2015-04-28 13:12:06 +08:00
|
|
|
|
2016-05-03 13:41:20 +08:00
|
|
|
int (*dma_set_mask)(struct pci_dev *pdev, u64 dma_mask);
|
|
|
|
u64 (*dma_get_required_mask)(struct pci_dev *pdev);
|
2015-05-27 14:06:59 +08:00
|
|
|
|
2016-05-03 13:41:20 +08:00
|
|
|
void (*shutdown)(struct pci_controller *hose);
|
2015-03-31 13:00:42 +08:00
|
|
|
};
|
|
|
|
|
2007-06-27 13:16:25 +08:00
|
|
|
/*
|
|
|
|
* Structure of a PCI controller (host bridge)
|
|
|
|
*/
|
|
|
|
struct pci_controller {
|
|
|
|
struct pci_bus *bus;
|
2007-06-28 02:09:43 +08:00
|
|
|
char is_dynamic;
|
2007-12-11 08:00:13 +08:00
|
|
|
#ifdef CONFIG_PPC64
|
|
|
|
int node;
|
|
|
|
#endif
|
2007-12-10 11:33:21 +08:00
|
|
|
struct device_node *dn;
|
2007-06-28 02:09:43 +08:00
|
|
|
struct list_head list_node;
|
2007-06-27 13:16:25 +08:00
|
|
|
struct device *parent;
|
|
|
|
|
|
|
|
int first_busno;
|
|
|
|
int last_busno;
|
|
|
|
int self_busno;
|
2012-05-18 09:51:12 +08:00
|
|
|
struct resource busn;
|
2007-06-27 13:16:25 +08:00
|
|
|
|
|
|
|
void __iomem *io_base_virt;
|
2007-12-11 08:00:13 +08:00
|
|
|
#ifdef CONFIG_PPC64
|
|
|
|
void *io_base_alloc;
|
|
|
|
#endif
|
2007-06-27 13:16:25 +08:00
|
|
|
resource_size_t io_base_phys;
|
2007-12-11 11:48:18 +08:00
|
|
|
resource_size_t pci_io_size;
|
2007-06-27 13:16:25 +08:00
|
|
|
|
2008-10-14 08:55:31 +08:00
|
|
|
/* Some machines have a special region to forward the ISA
|
|
|
|
* "memory" cycles such as VGA memory regions. Left to 0
|
|
|
|
* if unsupported
|
|
|
|
*/
|
|
|
|
resource_size_t isa_mem_phys;
|
|
|
|
resource_size_t isa_mem_size;
|
|
|
|
|
2015-03-31 13:00:42 +08:00
|
|
|
struct pci_controller_ops controller_ops;
|
2007-06-27 13:16:25 +08:00
|
|
|
struct pci_ops *ops;
|
2007-12-21 12:23:48 +08:00
|
|
|
unsigned int __iomem *cfg_addr;
|
|
|
|
void __iomem *cfg_data;
|
2007-06-27 13:16:25 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Used for variants of PCI indirect handling and possible quirks:
|
|
|
|
* SET_CFG_TYPE - used on 4xx or any PHB that does explicit type0/1
|
|
|
|
* EXT_REG - provides access to PCI-e extended registers
|
2011-03-31 09:57:33 +08:00
|
|
|
* SURPRESS_PRIMARY_BUS - we suppress the setting of PCI_PRIMARY_BUS
|
2007-06-27 13:16:25 +08:00
|
|
|
* on Freescale PCI-e controllers since they used the PCI_PRIMARY_BUS
|
|
|
|
* to determine which bus number to match on when generating type0
|
|
|
|
* config cycles
|
2007-07-12 02:22:41 +08:00
|
|
|
* NO_PCIE_LINK - the Freescale PCI-e controllers have issues with
|
|
|
|
* hanging if we don't have link and try to do config cycles to
|
|
|
|
* anything but the PHB. Only allow talking to the PHB if this is
|
|
|
|
* set.
|
2007-07-20 05:07:35 +08:00
|
|
|
* BIG_ENDIAN - cfg_addr is a big endian register
|
2008-06-18 07:01:38 +08:00
|
|
|
* BROKEN_MRM - the 440EPx/GRx chips have an errata that causes hangs on
|
|
|
|
* the PLB4. Effectively disable MRM commands by setting this.
|
2013-03-14 03:07:15 +08:00
|
|
|
* FSL_CFG_REG_LINK - Freescale controller version in which the PCIe
|
|
|
|
* link status is in a RC PCIe cfg register (vs being a SoC register)
|
2007-06-27 13:16:25 +08:00
|
|
|
*/
|
2007-12-06 15:02:28 +08:00
|
|
|
#define PPC_INDIRECT_TYPE_SET_CFG_TYPE 0x00000001
|
|
|
|
#define PPC_INDIRECT_TYPE_EXT_REG 0x00000002
|
|
|
|
#define PPC_INDIRECT_TYPE_SURPRESS_PRIMARY_BUS 0x00000004
|
|
|
|
#define PPC_INDIRECT_TYPE_NO_PCIE_LINK 0x00000008
|
|
|
|
#define PPC_INDIRECT_TYPE_BIG_ENDIAN 0x00000010
|
2008-06-18 07:01:38 +08:00
|
|
|
#define PPC_INDIRECT_TYPE_BROKEN_MRM 0x00000020
|
2013-03-14 03:07:15 +08:00
|
|
|
#define PPC_INDIRECT_TYPE_FSL_CFG_REG_LINK 0x00000040
|
2007-06-27 13:16:25 +08:00
|
|
|
u32 indirect_type;
|
|
|
|
/* Currently, we limit ourselves to 1 IO range and 3 mem
|
|
|
|
* ranges since the common pci_bus structure can't handle more
|
|
|
|
*/
|
|
|
|
struct resource io_resource;
|
|
|
|
struct resource mem_resources[3];
|
2013-05-06 11:40:40 +08:00
|
|
|
resource_size_t mem_offset[3];
|
2007-06-27 14:17:57 +08:00
|
|
|
int global_number; /* PCI domain number */
|
2009-04-21 00:26:48 +08:00
|
|
|
|
|
|
|
resource_size_t dma_window_base_cur;
|
|
|
|
resource_size_t dma_window_size;
|
|
|
|
|
2007-12-11 08:00:13 +08:00
|
|
|
#ifdef CONFIG_PPC64
|
|
|
|
unsigned long buid;
|
2015-03-17 13:15:02 +08:00
|
|
|
struct pci_dn *pci_data;
|
2013-03-14 03:07:15 +08:00
|
|
|
#endif /* CONFIG_PPC64 */
|
2007-12-11 08:00:13 +08:00
|
|
|
|
|
|
|
void *private_data;
|
2007-06-27 13:16:25 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/* These are used for config access before all the PCI probing
|
|
|
|
has been done. */
|
2007-12-06 15:02:28 +08:00
|
|
|
extern int early_read_config_byte(struct pci_controller *hose, int bus,
|
|
|
|
int dev_fn, int where, u8 *val);
|
|
|
|
extern int early_read_config_word(struct pci_controller *hose, int bus,
|
|
|
|
int dev_fn, int where, u16 *val);
|
|
|
|
extern int early_read_config_dword(struct pci_controller *hose, int bus,
|
|
|
|
int dev_fn, int where, u32 *val);
|
|
|
|
extern int early_write_config_byte(struct pci_controller *hose, int bus,
|
|
|
|
int dev_fn, int where, u8 val);
|
|
|
|
extern int early_write_config_word(struct pci_controller *hose, int bus,
|
|
|
|
int dev_fn, int where, u16 val);
|
|
|
|
extern int early_write_config_dword(struct pci_controller *hose, int bus,
|
|
|
|
int dev_fn, int where, u32 val);
|
2007-06-27 13:16:25 +08:00
|
|
|
|
2007-07-11 12:37:45 +08:00
|
|
|
extern int early_find_capability(struct pci_controller *hose, int bus,
|
|
|
|
int dev_fn, int cap);
|
|
|
|
|
2007-06-27 13:16:25 +08:00
|
|
|
extern void setup_indirect_pci(struct pci_controller* hose,
|
2007-10-08 20:51:24 +08:00
|
|
|
resource_size_t cfg_addr,
|
|
|
|
resource_size_t cfg_data, u32 flags);
|
2009-08-26 00:20:45 +08:00
|
|
|
|
2013-04-08 16:15:28 +08:00
|
|
|
extern int indirect_read_config(struct pci_bus *bus, unsigned int devfn,
|
|
|
|
int offset, int len, u32 *val);
|
|
|
|
|
2015-01-23 09:05:06 +08:00
|
|
|
extern int __indirect_read_config(struct pci_controller *hose,
|
|
|
|
unsigned char bus_number, unsigned int devfn,
|
|
|
|
int offset, int len, u32 *val);
|
|
|
|
|
2013-04-08 16:15:28 +08:00
|
|
|
extern int indirect_write_config(struct pci_bus *bus, unsigned int devfn,
|
|
|
|
int offset, int len, u32 val);
|
|
|
|
|
2009-08-26 00:20:45 +08:00
|
|
|
static inline struct pci_controller *pci_bus_to_host(const struct pci_bus *bus)
|
|
|
|
{
|
|
|
|
return bus->sysdata;
|
|
|
|
}
|
|
|
|
|
2011-04-11 09:37:07 +08:00
|
|
|
#ifndef CONFIG_PPC64
|
|
|
|
|
|
|
|
extern int pci_device_from_OF_node(struct device_node *node,
|
|
|
|
u8 *bus, u8 *devfn);
|
|
|
|
extern void pci_create_OF_bus_map(void);
|
|
|
|
|
2009-08-26 00:20:45 +08:00
|
|
|
static inline int isa_vaddr_is_ioport(void __iomem *address)
|
|
|
|
{
|
|
|
|
/* No specific ISA handling on ppc32 at this stage, it
|
|
|
|
* all goes through PCI
|
|
|
|
*/
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-12-06 15:02:28 +08:00
|
|
|
#else /* CONFIG_PPC64 */
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-09-06 11:17:54 +08:00
|
|
|
/*
|
|
|
|
* PCI stuff, for nodes representing PCI devices, pointed to
|
|
|
|
* by device_node->data.
|
|
|
|
*/
|
|
|
|
struct iommu_table;
|
|
|
|
|
|
|
|
struct pci_dn {
|
2015-03-17 13:15:02 +08:00
|
|
|
int flags;
|
2015-03-25 16:23:52 +08:00
|
|
|
#define PCI_DN_FLAG_IOV_VF 0x01
|
2015-03-17 13:15:02 +08:00
|
|
|
|
2005-11-04 08:55:19 +08:00
|
|
|
int busno; /* pci bus number */
|
|
|
|
int devfn; /* pci device and function number */
|
2015-03-17 13:15:04 +08:00
|
|
|
int vendor_id; /* Vendor ID */
|
|
|
|
int device_id; /* Device ID */
|
|
|
|
int class_code; /* Device class code */
|
2005-11-15 13:05:33 +08:00
|
|
|
|
2015-03-17 13:15:02 +08:00
|
|
|
struct pci_dn *parent;
|
2007-05-23 02:18:04 +08:00
|
|
|
struct pci_controller *phb; /* for pci devices */
|
2015-06-05 14:35:08 +08:00
|
|
|
struct iommu_table_group *table_group; /* for phb's or bridges */
|
2007-05-23 02:18:04 +08:00
|
|
|
struct device_node *node; /* back-pointer to the device_node */
|
|
|
|
|
|
|
|
int pci_ext_config_space; /* for pci devices */
|
|
|
|
|
2015-12-17 10:43:11 +08:00
|
|
|
struct pci_dev *pcidev; /* back-pointer to the pci device */
|
2011-11-16 01:29:08 +08:00
|
|
|
#ifdef CONFIG_EEH
|
2012-03-21 05:30:27 +08:00
|
|
|
struct eeh_dev *edev; /* eeh device */
|
2007-05-23 02:18:04 +08:00
|
|
|
#endif
|
2016-05-03 13:41:25 +08:00
|
|
|
#define IODA_INVALID_PE 0xFFFFFFFF
|
2011-11-16 01:29:08 +08:00
|
|
|
#ifdef CONFIG_PPC_POWERNV
|
2016-05-03 13:41:25 +08:00
|
|
|
unsigned int pe_number;
|
2016-03-04 07:53:11 +08:00
|
|
|
int vf_index; /* VF index in the PF */
|
2015-03-25 16:23:55 +08:00
|
|
|
#ifdef CONFIG_PCI_IOV
|
|
|
|
u16 vfs_expanded; /* number of VFs IOV BAR expanded */
|
2015-03-25 16:23:57 +08:00
|
|
|
u16 num_vfs; /* number of VFs enabled*/
|
2016-05-03 13:41:25 +08:00
|
|
|
unsigned int *pe_num_map; /* PE# for the first VF PE or array */
|
2015-10-22 09:22:16 +08:00
|
|
|
bool m64_single_mode; /* Use M64 BAR in Single Mode */
|
2015-03-25 16:23:57 +08:00
|
|
|
#define IODA_INVALID_M64 (-1)
|
2015-10-22 09:22:16 +08:00
|
|
|
int (*m64_map)[PCI_SRIOV_NUM_BARS];
|
2015-03-25 16:23:55 +08:00
|
|
|
#endif /* CONFIG_PCI_IOV */
|
powerpc/powernv: Support PCI config restore for VFs
After PE reset, OPAL API opal_pci_reinit() is called on all devices
contained in the PE to reinitialize them. While skiboot is not aware of
VFs, we have to implement the function in kernel to reinitialize VFs after
reset on PE for VFs.
In this patch, two functions pnv_pci_fixup_vf_mps() and
pnv_eeh_restore_vf_config() both manipulate the MPS of the VF, since for a
VF it has three cases.
1. Normal creation for a VF
In this case, pnv_pci_fixup_vf_mps() is called to make the MPS a proper
value compared with its parent.
2. EEH recovery without VF removed
In this case, MPS is stored in pci_dn and pnv_eeh_restore_vf_config() is
called to restore it and reinitialize other part.
3. EEH recovery with VF removed
In this case, VF will be removed then re-created. Both functions are
called. First pnv_pci_fixup_vf_mps() is called to store the proper MPS
to pci_dn and then pnv_eeh_restore_vf_config() is called to do proper
thing.
This introduces two functions: pnv_pci_fixup_vf_mps() to fixup the VF's
MPS to make sure it is equal to parent's and store this value in pci_dn
for future use. pnv_eeh_restore_vf_config() to re-initialize on VF by
restoring MPS, disabling completion timeout, enabling SERR, etc.
Signed-off-by: Wei Yang <weiyang@linux.vnet.ibm.com>
Acked-by: Gavin Shan <gwshan@linux.vnet.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2016-03-04 07:53:10 +08:00
|
|
|
int mps; /* Maximum Payload Size */
|
2011-11-16 01:29:08 +08:00
|
|
|
#endif
|
2015-03-17 13:15:02 +08:00
|
|
|
struct list_head child_list;
|
|
|
|
struct list_head list;
|
2005-09-06 11:17:54 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Get the pointer to a device_node's pci_dn */
|
|
|
|
#define PCI_DN(dn) ((struct pci_dn *) (dn)->data)
|
|
|
|
|
2015-03-17 13:15:02 +08:00
|
|
|
extern struct pci_dn *pci_get_pdn_by_devfn(struct pci_bus *bus,
|
|
|
|
int devfn);
|
2013-05-22 06:58:21 +08:00
|
|
|
extern struct pci_dn *pci_get_pdn(struct pci_dev *pdev);
|
2015-03-25 16:23:52 +08:00
|
|
|
extern struct pci_dn *add_dev_pci_data(struct pci_dev *pdev);
|
|
|
|
extern void remove_dev_pci_data(struct pci_dev *pdev);
|
2016-05-03 13:41:40 +08:00
|
|
|
extern struct pci_dn *pci_add_device_node_info(struct pci_controller *hose,
|
|
|
|
struct device_node *dn);
|
2016-05-03 13:41:41 +08:00
|
|
|
extern void pci_remove_device_node_info(struct device_node *dn);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-10-10 20:50:37 +08:00
|
|
|
static inline int pci_device_from_OF_node(struct device_node *np,
|
|
|
|
u8 *bus, u8 *devfn)
|
|
|
|
{
|
|
|
|
if (!PCI_DN(np))
|
|
|
|
return -ENODEV;
|
|
|
|
*bus = PCI_DN(np)->busno;
|
|
|
|
*devfn = PCI_DN(np)->devfn;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-03-21 05:30:27 +08:00
|
|
|
#if defined(CONFIG_EEH)
|
2015-03-17 13:15:05 +08:00
|
|
|
static inline struct eeh_dev *pdn_to_eeh_dev(struct pci_dn *pdn)
|
|
|
|
{
|
|
|
|
return pdn ? pdn->edev : NULL;
|
|
|
|
}
|
2012-09-08 06:44:22 +08:00
|
|
|
#else
|
2015-03-17 13:15:05 +08:00
|
|
|
#define pdn_to_eeh_dev(x) (NULL)
|
2012-03-21 05:30:27 +08:00
|
|
|
#endif
|
|
|
|
|
2005-11-04 08:52:16 +08:00
|
|
|
/** Find the bus corresponding to the indicated device node */
|
2016-05-03 13:41:38 +08:00
|
|
|
extern struct pci_bus *pci_find_bus_by_node(struct device_node *dn);
|
2005-11-04 08:52:16 +08:00
|
|
|
|
|
|
|
/** Remove all of the PCI devices under this bus */
|
2016-05-03 13:41:37 +08:00
|
|
|
extern void pci_hp_remove_devices(struct pci_bus *bus);
|
2005-11-04 08:52:16 +08:00
|
|
|
|
|
|
|
/** Discover new pci devices under this bus, and add them */
|
2016-05-03 13:41:37 +08:00
|
|
|
extern void pci_hp_add_devices(struct pci_bus *bus);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-11-15 13:05:33 +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
|
|
|
extern void isa_bridge_find_early(struct pci_controller *hose);
|
|
|
|
|
2007-07-26 12:07:13 +08:00
|
|
|
static inline int isa_vaddr_is_ioport(void __iomem *address)
|
|
|
|
{
|
|
|
|
/* Check if address hits the reserved legacy IO range */
|
|
|
|
unsigned long ea = (unsigned long)address;
|
|
|
|
return ea >= ISA_IO_BASE && ea < ISA_IO_END;
|
|
|
|
}
|
|
|
|
|
[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
|
|
|
extern int pcibios_unmap_io_space(struct pci_bus *bus);
|
|
|
|
extern int pcibios_map_io_space(struct pci_bus *bus);
|
|
|
|
|
2006-06-10 18:53:06 +08:00
|
|
|
#ifdef CONFIG_NUMA
|
|
|
|
#define PHB_SET_NODE(PHB, NODE) ((PHB)->node = (NODE))
|
|
|
|
#else
|
|
|
|
#define PHB_SET_NODE(PHB, NODE) ((PHB)->node = -1)
|
|
|
|
#endif
|
|
|
|
|
2007-12-06 15:02:28 +08:00
|
|
|
#endif /* CONFIG_PPC64 */
|
2007-06-27 13:16:25 +08:00
|
|
|
|
|
|
|
/* Get the PCI host controller for an OF device */
|
2007-12-06 15:02:28 +08:00
|
|
|
extern struct pci_controller *pci_find_hose_for_OF_device(
|
|
|
|
struct device_node* node);
|
2007-06-27 13:16:25 +08:00
|
|
|
|
|
|
|
/* Fill up host controller resources from the OF node */
|
2007-12-06 15:02:28 +08:00
|
|
|
extern void pci_process_bridge_OF_ranges(struct pci_controller *hose,
|
|
|
|
struct device_node *dev, int primary);
|
2007-06-27 13:16:25 +08:00
|
|
|
|
2007-11-16 15:42:18 +08:00
|
|
|
/* Allocate & free a PCI host bridge structure */
|
2007-12-06 15:02:28 +08:00
|
|
|
extern struct pci_controller *pcibios_alloc_controller(struct device_node *dev);
|
2007-11-16 15:42:18 +08:00
|
|
|
extern void pcibios_free_controller(struct pci_controller *phb);
|
powerpc/pseries: use pci_host_bridge.release_fn() to kfree(phb)
This patch leverages 'struct pci_host_bridge' from the PCI subsystem
in order to free the pci_controller only after the last reference to
its devices is dropped (avoiding an oops in pcibios_release_device()
if the last reference is dropped after pcibios_free_controller()).
The patch relies on pci_host_bridge.release_fn() (and .release_data),
which is called automatically by the PCI subsystem when the root bus
is released (i.e., the last reference is dropped). Those fields are
set via pci_set_host_bridge_release() (e.g. in the platform-specific
implementation of pcibios_root_bridge_prepare()).
It introduces the 'pcibios_free_controller_deferred()' .release_fn()
and it expects .release_data to hold a pointer to the pci_controller.
The function implictly calls 'pcibios_free_controller()', so an user
must *NOT* explicitly call it if using the new _deferred() callback.
The functionality is enabled for pseries (although it isn't platform
specific, and may be used by cxl).
Details on not-so-elegant design choices:
- Use 'pci_host_bridge.release_data' field as pointer to associated
'struct pci_controller' so *not* to 'pci_bus_to_host(bridge->bus)'
in pcibios_free_controller_deferred().
That's because pci_remove_root_bus() sets 'host_bridge->bus = NULL'
(so, if the last reference is released after pci_remove_root_bus()
runs, which eventually reaches pcibios_free_controller_deferred(),
that would hit a null pointer dereference).
The cxl/vphb.c code calls pci_remove_root_bus(), and the cxl folks
are interested in this fix.
Test-case #1 (hold references)
# ls -ld /sys/block/sd* | grep -m1 0021:01:00.0
<...> /sys/block/sdaa -> ../devices/pci0021:01/0021:01:00.0/<...>
# ls -ld /sys/block/sd* | grep -m1 0021:01:00.1
<...> /sys/block/sdab -> ../devices/pci0021:01/0021:01:00.1/<...>
# cat >/dev/sdaa & pid1=$!
# cat >/dev/sdab & pid2=$!
# drmgr -w 5 -d 1 -c phb -s 'PHB 33' -r
Validating PHB DLPAR capability...yes.
[ 594.306719] pci_hp_remove_devices: PCI: Removing devices on bus 0021:01
[ 594.306738] pci_hp_remove_devices: Removing 0021:01:00.0...
...
[ 598.236381] pci_hp_remove_devices: Removing 0021:01:00.1...
...
[ 611.972077] pci_bus 0021:01: busn_res: [bus 01-ff] is released
[ 611.972140] rpadlpar_io: slot PHB 33 removed
# kill -9 $pid1
# kill -9 $pid2
[ 632.918088] pcibios_free_controller_deferred: domain 33, dynamic 1
Test-case #2 (don't hold references)
# drmgr -w 5 -d 1 -c phb -s 'PHB 33' -r
Validating PHB DLPAR capability...yes.
[ 916.357363] pci_hp_remove_devices: PCI: Removing devices on bus 0021:01
[ 916.357386] pci_hp_remove_devices: Removing 0021:01:00.0...
...
[ 920.566527] pci_hp_remove_devices: Removing 0021:01:00.1...
...
[ 933.955873] pci_bus 0021:01: busn_res: [bus 01-ff] is released
[ 933.955977] pcibios_free_controller_deferred: domain 33, dynamic 1
[ 933.955999] rpadlpar_io: slot PHB 33 removed
Suggested-By: Gavin Shan <gwshan@linux.vnet.ibm.com>
Signed-off-by: Mauricio Faria de Oliveira <mauricfo@linux.vnet.ibm.com>
Reviewed-by: Gavin Shan <gwshan@linux.vnet.ibm.com>
Reviewed-by: Andrew Donnellan <andrew.donnellan@au1.ibm.com>
Tested-by: Andrew Donnellan <andrew.donnellan@au1.ibm.com> # cxl
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
2016-08-12 04:25:40 +08:00
|
|
|
extern void pcibios_free_controller_deferred(struct pci_host_bridge *bridge);
|
2007-11-16 15:42:18 +08:00
|
|
|
|
2007-06-27 13:16:25 +08:00
|
|
|
#ifdef CONFIG_PCI
|
2007-07-26 12:07:13 +08:00
|
|
|
extern int pcibios_vaddr_is_ioport(void __iomem *address);
|
2007-06-27 13:16:25 +08:00
|
|
|
#else
|
2007-07-26 12:07:13 +08:00
|
|
|
static inline int pcibios_vaddr_is_ioport(void __iomem *address)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
2007-12-06 15:02:28 +08:00
|
|
|
#endif /* CONFIG_PCI */
|
2007-06-27 13:16:25 +08:00
|
|
|
|
2007-12-06 15:02:28 +08:00
|
|
|
#endif /* __KERNEL__ */
|
|
|
|
#endif /* _ASM_POWERPC_PCI_BRIDGE_H */
|