Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -189,32 +189,66 @@ allOf:
properties:
reg:
minItems: 21
maxItems: 22
maxItems: 25
reg-names:
minItems: 21
items:
- const: ps
- const: pwrgate
- const: cpu-start
- const: cllt
- const: cluster
- const: commit
- const: wdt
- const: spmi
- const: spmi-hpm
- const: wake
- const: ps-aon
- const: mcc-a
- const: mcc-b
- const: mcc-c
- const: mcc-d
- const: apcie-axi
- const: apcie-rc
- const: apcie-clkgen
- const: apcie-phy
- const: apcie-phy-ip
- const: apcie-port0
- const: clk-mux
oneOf:
- description: USB-C port controllers on SPMI
minItems: 21
items:
- const: ps
- const: pwrgate
- const: cpu-start
- const: cllt
- const: cluster
- const: commit
- const: wdt
- const: spmi
- const: spmi-hpm
- const: wake
- const: ps-aon
- const: mcc-a
- const: mcc-b
- const: mcc-c
- const: mcc-d
- const: apcie-axi
- const: apcie-rc
- const: apcie-clkgen
- const: apcie-phy
- const: apcie-phy-ip
- const: apcie-port0
- const: clk-mux
- description:
USB-C port controllers on I2C, which leave out their SPMI bus.
apcie-portN and apcie-phyN are those of a PCIe port past port
0, its registers and its PHY lane's. Deep sleep is refused on
a board that enables such a port without them.
minItems: 21
items:
- const: ps
- const: pwrgate
- const: cpu-start
- const: cllt
- const: cluster
- const: commit
- const: wdt
- const: spmi
- const: wake
- const: ps-aon
- const: mcc-a
- const: mcc-b
- const: mcc-c
- const: mcc-d
- const: apcie-axi
- const: apcie-rc
- const: apcie-clkgen
- const: apcie-phy
- const: apcie-phy-ip
- const: apcie-port0
- const: clk-mux
- const: apcie-port1
- const: apcie-phy1
- const: apcie-port2
- const: apcie-phy2
- if:
properties:
compatible:
Expand Down
12 changes: 12 additions & 0 deletions drivers/iommu/apple-dart.c
Original file line number Diff line number Diff line change
Expand Up @@ -7285,6 +7285,18 @@ int apple_dart_quiesce_commands(struct device *dev)
}
EXPORT_SYMBOL_GPL(apple_dart_quiesce_commands);

void apple_dart_host_wake_failed(struct device *dev)
{
struct apple_dart *dart = dev_get_drvdata(dev);

if (WARN_ON_ONCE(!dart))
return;
guard(spinlock_irqsave)(&dart->lock);
dart->host_resumes = true;
WRITE_ONCE(dart->commands_gated, true);
}
EXPORT_SYMBOL_GPL(apple_dart_host_wake_failed);

int apple_dart_resume_commands(struct device *dev)
{
struct apple_dart *dart = dev_get_drvdata(dev);
Expand Down
66 changes: 64 additions & 2 deletions drivers/pci/controller/pcie-apple.c
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,7 @@ struct apple_radio_sleep;
struct apple_pcie {
struct mutex lock;
struct device *dev;
bool t8122_native;
void __iomem *base;
void __iomem *fabric_base;
void __iomem *debug_base;
Expand Down Expand Up @@ -741,6 +742,7 @@ struct apple_pcie_port {
bool started;
bool needs_stop;
bool link_failed;
bool sleep_clock_failed;
bool irq_disabled;
void __iomem *intr2axi; /* adopt_link: this port's */
u8 adopted_bus; /* adopt_link: the secondary bus */
Expand Down Expand Up @@ -1345,7 +1347,7 @@ static void apple_pcie_port_enable_irq(struct apple_pcie_port *port)
{
unsigned long flags;

if (!port->irq_disabled)
if (!port->irq_disabled || port->sleep_clock_failed)
return;

raw_spin_lock_irqsave(&port->irq_lock, flags);
Expand Down Expand Up @@ -4034,6 +4036,8 @@ static int apple_pcie_enable_device(struct pci_host_bridge *bridge, struct pci_d
port = apple_pcie_get_port(pdev);
if (!port)
return 0;
if (port->sleep_clock_failed)
return -ENODEV;

dev_dbg(&pdev->dev, "added to bus %s, index %d\n",
pci_name(pdev->bus->self), port->idx);
Expand Down Expand Up @@ -4123,7 +4127,7 @@ static void apple_pcie_disable_device(struct pci_host_bridge *bridge, struct pci
int idx;

port = apple_pcie_get_port(pdev);
if (!port || port->pcie->hw->adopt_link)
if (!port || port->pcie->hw->adopt_link || port->sleep_clock_failed)
return;

mutex_lock(&port->pcie->lock);
Expand Down Expand Up @@ -4161,6 +4165,7 @@ static int apple_pcie_init(struct pci_config_window *cfg)
if (WARN_ON(!pcie))
return -ENOENT;
pcie->cfg = cfg;
pcie->t8122_native = of_device_is_compatible(dev->of_node, "apple,t8122-pcie");

for_each_available_child_of_node_scoped(dev->of_node, of_port) {
ret = apple_pcie_setup_port(pcie, of_port);
Expand All @@ -4180,6 +4185,23 @@ static int apple_pcie_init(struct pci_config_window *cfg)
return 0;
}

static bool apple_pcie_t8122_config_blocked(struct apple_pcie *pcie, struct pci_bus *bus,
unsigned int devfn)
{
unsigned long failed;

if (!pcie->t8122_native)
return false;
failed = apple_sleep_t8122_failed_ports();
if (!failed)
return false;
while (bus->parent) {
devfn = bus->self->devfn;
bus = bus->parent;
}
return failed & BIT(PCI_SLOT(devfn));
}

/*
* The T8140 host starts with all downstream accesses blocked.
* Only a successful owned bootstrap and typed ECAM checks open functions0/1.
Expand All @@ -4194,6 +4216,8 @@ static void __iomem *apple_pcie_map_bus(struct pci_bus *bus,

if (READ_ONCE(pcie->cio_changed))
return NULL;
if (apple_pcie_t8122_config_blocked(pcie, bus, devfn))
return NULL;
if (!apple_radio_config_allowed(pcie))
return NULL;
if (pcie->hw->adopt_link) {
Expand Down Expand Up @@ -7857,6 +7881,38 @@ static int apple_pcie_resume_early(struct device *dev)
return 0;
}

static void apple_pcie_disconnect_failed_t8122_ports(struct apple_pcie *pcie)
{
struct pci_host_bridge *bridge = pci_host_bridge_from_priv(pcie);
struct apple_pcie_port *port;
unsigned long failed;

if (!pcie->t8122_native)
return;
failed = apple_sleep_t8122_failed_ports();
if (!failed)
return;
list_for_each_entry(port, &pcie->ports, entry) {
struct pci_dev *root;

if (!(failed & BIT(port->idx)))
continue;
port->sleep_clock_failed = true;
port->hib_link_up = false;
port->hib_cold = false;
apple_pcie_port_disable_irq(port);
if (!bridge->bus)
continue;
root = pci_get_slot(bridge->bus, PCI_DEVFN(port->idx, 0));
if (!root)
continue;
pci_dev_set_disconnected(root, NULL);
if (root->subordinate)
pci_walk_bus(root->subordinate, pci_dev_set_disconnected, NULL);
pci_dev_put(root);
}
}

static int apple_pcie_resume_noirq(struct device *dev)
{
struct apple_pcie *pcie = apple_pcie_lookup(dev);
Expand All @@ -7865,6 +7921,7 @@ static int apple_pcie_resume_noirq(struct device *dev)

/* The domain's hold for the sleep ends first, whatever follows. */
apple_pcie_release_domains(pcie);
apple_pcie_disconnect_failed_t8122_ports(pcie);
if (pcie->cio_prepared) {
ret = apple_pcie_cio_resume(pcie);
if (!ret)
Expand Down Expand Up @@ -9608,6 +9665,8 @@ static int apple_pcie_resume(struct device *dev)
return 0;
}
list_for_each_entry(port, &pcie->ports, entry) {
if (port->sleep_clock_failed)
continue;
if (!port->hib_link_up) {
apple_pcie_port_writel(port, ~0, PORT_INTMSK);
apple_pcie_port_writel(port, ~0, PORT_INTSTAT);
Expand Down Expand Up @@ -9661,6 +9720,9 @@ static int apple_pcie_prepare(struct device *dev)
struct apple_pcie *pcie = apple_pcie_lookup(dev);
int ret;

if (pcie && pcie->t8122_native && apple_sleep_t8122_failed_ports())
return -EIO;

/*
* A host-owned PCIe-C DART sleeps only inside the NHI's deep-sleep
* transaction, prepared before this, or with a kept s2idle link.
Expand Down
Loading
Loading