|
|
|
|
@@ -40,6 +40,7 @@
|
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
|
#include <linux/pci.h>
|
|
|
|
|
#include <linux/pci-ecam.h>
|
|
|
|
|
#include <linux/delay.h>
|
|
|
|
|
#include <linux/semaphore.h>
|
|
|
|
|
#include <linux/irqdomain.h>
|
|
|
|
|
@@ -473,7 +474,13 @@ enum hv_pcibus_state {
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct hv_pcibus_device {
|
|
|
|
|
#ifdef CONFIG_X86
|
|
|
|
|
struct pci_sysdata sysdata;
|
|
|
|
|
#elif defined(CONFIG_ARM64)
|
|
|
|
|
struct pci_config_window sysdata;
|
|
|
|
|
#endif
|
|
|
|
|
struct pci_host_bridge *bridge;
|
|
|
|
|
struct fwnode_handle *fwnode;
|
|
|
|
|
/* Protocol version negotiated with the host */
|
|
|
|
|
enum pci_protocol_version_t protocol_version;
|
|
|
|
|
enum hv_pcibus_state state;
|
|
|
|
|
@@ -489,8 +496,6 @@ struct hv_pcibus_device {
|
|
|
|
|
spinlock_t device_list_lock; /* Protect lists below */
|
|
|
|
|
void __iomem *cfg_addr;
|
|
|
|
|
|
|
|
|
|
struct list_head resources_for_children;
|
|
|
|
|
|
|
|
|
|
struct list_head children;
|
|
|
|
|
struct list_head dr_list;
|
|
|
|
|
|
|
|
|
|
@@ -1623,7 +1628,7 @@ static int hv_pcie_init_irq_domain(struct hv_pcibus_device *hbus)
|
|
|
|
|
hbus->msi_info.handler = handle_edge_irq;
|
|
|
|
|
hbus->msi_info.handler_name = "edge";
|
|
|
|
|
hbus->msi_info.data = hbus;
|
|
|
|
|
hbus->irq_domain = pci_msi_create_irq_domain(hbus->sysdata.fwnode,
|
|
|
|
|
hbus->irq_domain = pci_msi_create_irq_domain(hbus->fwnode,
|
|
|
|
|
&hbus->msi_info,
|
|
|
|
|
x86_vector_domain);
|
|
|
|
|
if (!hbus->irq_domain) {
|
|
|
|
|
@@ -1632,6 +1637,8 @@ static int hv_pcie_init_irq_domain(struct hv_pcibus_device *hbus)
|
|
|
|
|
return -ENODEV;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dev_set_msi_domain(&hbus->bridge->dev, hbus->irq_domain);
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -1854,7 +1861,7 @@ static void hv_pci_assign_slots(struct hv_pcibus_device *hbus)
|
|
|
|
|
|
|
|
|
|
slot_nr = PCI_SLOT(wslot_to_devfn(hpdev->desc.win_slot.slot));
|
|
|
|
|
snprintf(name, SLOT_NAME_SIZE, "%u", hpdev->desc.ser);
|
|
|
|
|
hpdev->pci_slot = pci_create_slot(hbus->pci_bus, slot_nr,
|
|
|
|
|
hpdev->pci_slot = pci_create_slot(hbus->bridge->bus, slot_nr,
|
|
|
|
|
name, NULL);
|
|
|
|
|
if (IS_ERR(hpdev->pci_slot)) {
|
|
|
|
|
pr_warn("pci_create slot %s failed\n", name);
|
|
|
|
|
@@ -1884,7 +1891,7 @@ static void hv_pci_remove_slots(struct hv_pcibus_device *hbus)
|
|
|
|
|
static void hv_pci_assign_numa_node(struct hv_pcibus_device *hbus)
|
|
|
|
|
{
|
|
|
|
|
struct pci_dev *dev;
|
|
|
|
|
struct pci_bus *bus = hbus->pci_bus;
|
|
|
|
|
struct pci_bus *bus = hbus->bridge->bus;
|
|
|
|
|
struct hv_pci_dev *hv_dev;
|
|
|
|
|
|
|
|
|
|
list_for_each_entry(dev, &bus->devices, bus_list) {
|
|
|
|
|
@@ -1907,21 +1914,22 @@ static void hv_pci_assign_numa_node(struct hv_pcibus_device *hbus)
|
|
|
|
|
*/
|
|
|
|
|
static int create_root_hv_pci_bus(struct hv_pcibus_device *hbus)
|
|
|
|
|
{
|
|
|
|
|
/* Register the device */
|
|
|
|
|
hbus->pci_bus = pci_create_root_bus(&hbus->hdev->device,
|
|
|
|
|
0, /* bus number is always zero */
|
|
|
|
|
&hv_pcifront_ops,
|
|
|
|
|
&hbus->sysdata,
|
|
|
|
|
&hbus->resources_for_children);
|
|
|
|
|
if (!hbus->pci_bus)
|
|
|
|
|
return -ENODEV;
|
|
|
|
|
int error;
|
|
|
|
|
struct pci_host_bridge *bridge = hbus->bridge;
|
|
|
|
|
|
|
|
|
|
bridge->dev.parent = &hbus->hdev->device;
|
|
|
|
|
bridge->sysdata = &hbus->sysdata;
|
|
|
|
|
bridge->ops = &hv_pcifront_ops;
|
|
|
|
|
|
|
|
|
|
error = pci_scan_root_bus_bridge(bridge);
|
|
|
|
|
if (error)
|
|
|
|
|
return error;
|
|
|
|
|
|
|
|
|
|
pci_lock_rescan_remove();
|
|
|
|
|
pci_scan_child_bus(hbus->pci_bus);
|
|
|
|
|
hv_pci_assign_numa_node(hbus);
|
|
|
|
|
pci_bus_assign_resources(hbus->pci_bus);
|
|
|
|
|
pci_bus_assign_resources(bridge->bus);
|
|
|
|
|
hv_pci_assign_slots(hbus);
|
|
|
|
|
pci_bus_add_devices(hbus->pci_bus);
|
|
|
|
|
pci_bus_add_devices(bridge->bus);
|
|
|
|
|
pci_unlock_rescan_remove();
|
|
|
|
|
hbus->state = hv_pcibus_installed;
|
|
|
|
|
return 0;
|
|
|
|
|
@@ -2184,7 +2192,7 @@ static void pci_devices_present_work(struct work_struct *work)
|
|
|
|
|
* because there may have been changes.
|
|
|
|
|
*/
|
|
|
|
|
pci_lock_rescan_remove();
|
|
|
|
|
pci_scan_child_bus(hbus->pci_bus);
|
|
|
|
|
pci_scan_child_bus(hbus->bridge->bus);
|
|
|
|
|
hv_pci_assign_numa_node(hbus);
|
|
|
|
|
hv_pci_assign_slots(hbus);
|
|
|
|
|
pci_unlock_rescan_remove();
|
|
|
|
|
@@ -2352,11 +2360,11 @@ static void hv_eject_device_work(struct work_struct *work)
|
|
|
|
|
/*
|
|
|
|
|
* Ejection can come before or after the PCI bus has been set up, so
|
|
|
|
|
* attempt to find it and tear down the bus state, if it exists. This
|
|
|
|
|
* must be done without constructs like pci_domain_nr(hbus->pci_bus)
|
|
|
|
|
* because hbus->pci_bus may not exist yet.
|
|
|
|
|
* must be done without constructs like pci_domain_nr(hbus->bridge->bus)
|
|
|
|
|
* because hbus->bridge->bus may not exist yet.
|
|
|
|
|
*/
|
|
|
|
|
wslot = wslot_to_devfn(hpdev->desc.win_slot.slot);
|
|
|
|
|
pdev = pci_get_domain_bus_and_slot(hbus->sysdata.domain, 0, wslot);
|
|
|
|
|
pdev = pci_get_domain_bus_and_slot(hbus->bridge->domain_nr, 0, wslot);
|
|
|
|
|
if (pdev) {
|
|
|
|
|
pci_lock_rescan_remove();
|
|
|
|
|
pci_stop_and_remove_bus_device(pdev);
|
|
|
|
|
@@ -2719,8 +2727,7 @@ static int hv_pci_allocate_bridge_windows(struct hv_pcibus_device *hbus)
|
|
|
|
|
/* Modify this resource to become a bridge window. */
|
|
|
|
|
hbus->low_mmio_res->flags |= IORESOURCE_WINDOW;
|
|
|
|
|
hbus->low_mmio_res->flags &= ~IORESOURCE_BUSY;
|
|
|
|
|
pci_add_resource(&hbus->resources_for_children,
|
|
|
|
|
hbus->low_mmio_res);
|
|
|
|
|
pci_add_resource(&hbus->bridge->windows, hbus->low_mmio_res);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (hbus->high_mmio_space) {
|
|
|
|
|
@@ -2739,8 +2746,7 @@ static int hv_pci_allocate_bridge_windows(struct hv_pcibus_device *hbus)
|
|
|
|
|
/* Modify this resource to become a bridge window. */
|
|
|
|
|
hbus->high_mmio_res->flags |= IORESOURCE_WINDOW;
|
|
|
|
|
hbus->high_mmio_res->flags &= ~IORESOURCE_BUSY;
|
|
|
|
|
pci_add_resource(&hbus->resources_for_children,
|
|
|
|
|
hbus->high_mmio_res);
|
|
|
|
|
pci_add_resource(&hbus->bridge->windows, hbus->high_mmio_res);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
@@ -3059,6 +3065,7 @@ static void hv_put_dom_num(u16 dom)
|
|
|
|
|
static int hv_pci_probe(struct hv_device *hdev,
|
|
|
|
|
const struct hv_vmbus_device_id *dev_id)
|
|
|
|
|
{
|
|
|
|
|
struct pci_host_bridge *bridge;
|
|
|
|
|
struct hv_pcibus_device *hbus;
|
|
|
|
|
u16 dom_req, dom;
|
|
|
|
|
char *name;
|
|
|
|
|
@@ -3071,6 +3078,10 @@ static int hv_pci_probe(struct hv_device *hdev,
|
|
|
|
|
*/
|
|
|
|
|
BUILD_BUG_ON(sizeof(*hbus) > HV_HYP_PAGE_SIZE);
|
|
|
|
|
|
|
|
|
|
bridge = devm_pci_alloc_host_bridge(&hdev->device, 0);
|
|
|
|
|
if (!bridge)
|
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* With the recent 59bb47985c1d ("mm, sl[aou]b: guarantee natural
|
|
|
|
|
* alignment for kmalloc(power-of-two)"), kzalloc() is able to allocate
|
|
|
|
|
@@ -3092,6 +3103,8 @@ static int hv_pci_probe(struct hv_device *hdev,
|
|
|
|
|
hbus = kzalloc(HV_HYP_PAGE_SIZE, GFP_KERNEL);
|
|
|
|
|
if (!hbus)
|
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
|
|
hbus->bridge = bridge;
|
|
|
|
|
hbus->state = hv_pcibus_init;
|
|
|
|
|
hbus->wslot_res_allocated = -1;
|
|
|
|
|
|
|
|
|
|
@@ -3123,17 +3136,19 @@ static int hv_pci_probe(struct hv_device *hdev,
|
|
|
|
|
"PCI dom# 0x%hx has collision, using 0x%hx",
|
|
|
|
|
dom_req, dom);
|
|
|
|
|
|
|
|
|
|
hbus->bridge->domain_nr = dom;
|
|
|
|
|
#ifdef CONFIG_X86
|
|
|
|
|
hbus->sysdata.domain = dom;
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
hbus->hdev = hdev;
|
|
|
|
|
INIT_LIST_HEAD(&hbus->children);
|
|
|
|
|
INIT_LIST_HEAD(&hbus->dr_list);
|
|
|
|
|
INIT_LIST_HEAD(&hbus->resources_for_children);
|
|
|
|
|
spin_lock_init(&hbus->config_lock);
|
|
|
|
|
spin_lock_init(&hbus->device_list_lock);
|
|
|
|
|
spin_lock_init(&hbus->retarget_msi_interrupt_lock);
|
|
|
|
|
hbus->wq = alloc_ordered_workqueue("hv_pci_%x", 0,
|
|
|
|
|
hbus->sysdata.domain);
|
|
|
|
|
hbus->bridge->domain_nr);
|
|
|
|
|
if (!hbus->wq) {
|
|
|
|
|
ret = -ENOMEM;
|
|
|
|
|
goto free_dom;
|
|
|
|
|
@@ -3170,9 +3185,9 @@ static int hv_pci_probe(struct hv_device *hdev,
|
|
|
|
|
goto unmap;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hbus->sysdata.fwnode = irq_domain_alloc_named_fwnode(name);
|
|
|
|
|
hbus->fwnode = irq_domain_alloc_named_fwnode(name);
|
|
|
|
|
kfree(name);
|
|
|
|
|
if (!hbus->sysdata.fwnode) {
|
|
|
|
|
if (!hbus->fwnode) {
|
|
|
|
|
ret = -ENOMEM;
|
|
|
|
|
goto unmap;
|
|
|
|
|
}
|
|
|
|
|
@@ -3250,7 +3265,7 @@ exit_d0:
|
|
|
|
|
free_irq_domain:
|
|
|
|
|
irq_domain_remove(hbus->irq_domain);
|
|
|
|
|
free_fwnode:
|
|
|
|
|
irq_domain_free_fwnode(hbus->sysdata.fwnode);
|
|
|
|
|
irq_domain_free_fwnode(hbus->fwnode);
|
|
|
|
|
unmap:
|
|
|
|
|
iounmap(hbus->cfg_addr);
|
|
|
|
|
free_config:
|
|
|
|
|
@@ -3260,7 +3275,7 @@ close:
|
|
|
|
|
destroy_wq:
|
|
|
|
|
destroy_workqueue(hbus->wq);
|
|
|
|
|
free_dom:
|
|
|
|
|
hv_put_dom_num(hbus->sysdata.domain);
|
|
|
|
|
hv_put_dom_num(hbus->bridge->domain_nr);
|
|
|
|
|
free_bus:
|
|
|
|
|
kfree(hbus);
|
|
|
|
|
return ret;
|
|
|
|
|
@@ -3352,9 +3367,9 @@ static int hv_pci_remove(struct hv_device *hdev)
|
|
|
|
|
|
|
|
|
|
/* Remove the bus from PCI's point of view. */
|
|
|
|
|
pci_lock_rescan_remove();
|
|
|
|
|
pci_stop_root_bus(hbus->pci_bus);
|
|
|
|
|
pci_stop_root_bus(hbus->bridge->bus);
|
|
|
|
|
hv_pci_remove_slots(hbus);
|
|
|
|
|
pci_remove_root_bus(hbus->pci_bus);
|
|
|
|
|
pci_remove_root_bus(hbus->bridge->bus);
|
|
|
|
|
pci_unlock_rescan_remove();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -3364,12 +3379,11 @@ static int hv_pci_remove(struct hv_device *hdev)
|
|
|
|
|
|
|
|
|
|
iounmap(hbus->cfg_addr);
|
|
|
|
|
hv_free_config_window(hbus);
|
|
|
|
|
pci_free_resource_list(&hbus->resources_for_children);
|
|
|
|
|
hv_pci_free_bridge_windows(hbus);
|
|
|
|
|
irq_domain_remove(hbus->irq_domain);
|
|
|
|
|
irq_domain_free_fwnode(hbus->sysdata.fwnode);
|
|
|
|
|
irq_domain_free_fwnode(hbus->fwnode);
|
|
|
|
|
|
|
|
|
|
hv_put_dom_num(hbus->sysdata.domain);
|
|
|
|
|
hv_put_dom_num(hbus->bridge->domain_nr);
|
|
|
|
|
|
|
|
|
|
kfree(hbus);
|
|
|
|
|
return ret;
|
|
|
|
|
@@ -3447,7 +3461,7 @@ static int hv_pci_restore_msi_msg(struct pci_dev *pdev, void *arg)
|
|
|
|
|
*/
|
|
|
|
|
static void hv_pci_restore_msi_state(struct hv_pcibus_device *hbus)
|
|
|
|
|
{
|
|
|
|
|
pci_walk_bus(hbus->pci_bus, hv_pci_restore_msi_msg, NULL);
|
|
|
|
|
pci_walk_bus(hbus->bridge->bus, hv_pci_restore_msi_msg, NULL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int hv_pci_resume(struct hv_device *hdev)
|
|
|
|
|
|