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
3 changes: 2 additions & 1 deletion Documentation/devicetree/bindings/power/apple,pmc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ patternProperties:
A rail floor, provided as a power domain. While the domain is powered,
the AP's voter agent holds the rail at least at the given performance
state. Floors on the same rail combine to the highest powered one. The
AP agent must be a static voter, and the DCS rail cannot have a floor.
AP agent must be a static voter. A floor on the DCS rail shares the AP
agent's DCS vote with the DCS limit, which caps it.
additionalProperties: false

properties:
Expand Down
18 changes: 16 additions & 2 deletions arch/arm64/boot/dts/apple/t8140.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -587,14 +587,17 @@
/*
* ProRes is soc-device record 14, DVFS ordinal 7. Its VMAX
* request votes the SOC rail through the PMP's static agent,
* like AVD; it has no cluster-agent bit.
* like AVD; it has no cluster-agent bit. The PMP votes no DCS
* state for it, and with the CPUs idle the CLPC drops DCS to
* state 0 during an encode: the DCS floor holds DRAM up while
* frames are in the engine.
*/
pmp_report_prores: report@e {
compatible = "apple,t8140-pmp-v2-report-entry";
reg = <0xe>;
label = "pmp-prores";
#power-domain-cells = <0>;
power-domains = <&ps_prores>;
power-domains = <&ps_prores>, <&pmc_dcs_max>;
apple,dvfs = <0x197 2>;
};

Expand Down Expand Up @@ -1367,6 +1370,17 @@
apple,static-voters = <0 1 3>;
status = "disabled";

/*
* DCS (DRAM) at its highest state, through the AP's agent.
* The DCS limit still caps it.
*/
pmc_dcs_max: floor-dcs-max {
label = "dcs-max";
#power-domain-cells = <0>;
apple,rail = <0>;
apple,level = <4>;
};

/* VENC-CLSTR-V: the video encoder cluster, bit 3. */
pmc_venc_cluster: cluster-venc {
label = "venc-cluster";
Expand Down
32 changes: 32 additions & 0 deletions drivers/pmdomain/apple/pmc-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,39 @@ static void apple_pmc_test_floor_pending_timeout(struct kunit *test)
KUNIT_EXPECT_FALSE(test, dom->on);
}

/*
* A DCS floor raises the AP's DCS vote above its inherited vote while held,
* yields to the DCS limit, and gives the inherited vote back when released.
*/
static void apple_pmc_test_dcs_floor(struct kunit *test)
{
struct apple_pmc *pmc = apple_pmc_test_alloc(test);
const struct apple_pmc_hw *hw = pmc->hw;
struct apple_pmc_domain *dom;

INIT_LIST_HEAD(&pmc->domains);
apple_pmc_test_set_dcs_vote(pmc, hw->ap_agent, 1);
pmc->ap_dcs_vote = apple_pmc_ap_dcs_read(pmc);
pmc->enable[hw->dcs_rail] = BIT(1) | BIT(hw->ap_agent);
dom = apple_pmc_test_floor(test, pmc, hw->dcs_rail, hw->dcs_max);

KUNIT_ASSERT_EQ(test, apple_pmc_floor_set(dom, true), 0);
KUNIT_EXPECT_EQ(test, apple_pmc_ap_dcs_read(pmc), hw->dcs_max);
/* The limit caps the floor; the other agents ask for nothing. */
pmc->dcs_state = 3;
apple_pmc_dcs_vote(pmc);
KUNIT_EXPECT_EQ(test, apple_pmc_ap_dcs_read(pmc), hw->dcs_max - 3);
pmc->dcs_state = 0;
apple_pmc_dcs_vote(pmc);
KUNIT_EXPECT_EQ(test, apple_pmc_ap_dcs_read(pmc), hw->dcs_max);
KUNIT_ASSERT_EQ(test, apple_pmc_floor_set(dom, false), 0);
KUNIT_EXPECT_EQ(test, apple_pmc_ap_dcs_read(pmc), 1);
/* Other rails of the AP's floor word are untouched. */
KUNIT_EXPECT_EQ(test, apple_pmc_test_ap_floor(pmc) & ~APPLE_PMC_RAIL_MASK(hw->dcs_rail), 0U);
}

static struct kunit_case apple_pmc_test_cases[] = {
KUNIT_CASE(apple_pmc_test_dcs_floor),
KUNIT_CASE(apple_pmc_test_partial_enable),
KUNIT_CASE(apple_pmc_test_release_restores_ap_vote),
KUNIT_CASE(apple_pmc_test_pending_floor),
Expand Down
25 changes: 18 additions & 7 deletions drivers/pmdomain/apple/pmc.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ struct apple_pmc {
unsigned long dcs_state;
/* DCS state the AP's agent voted for before probe, kept without a limit. */
unsigned int ap_dcs_vote;
/* Highest DCS floor held by a floor domain; protected by @lock. */
unsigned int dcs_floor;
/* Power cost of each DCS state in mW, if a model is described. */
u32 dcs_power[APPLE_PMC_MAX_STATES];
struct delayed_work dcs_work;
Expand Down Expand Up @@ -386,19 +388,20 @@ static unsigned int apple_pmc_ap_dcs_read(struct apple_pmc *pmc)

/*
* Caller holds pmc->lock. Vote through the AP's agent for what the other
* agents ask for, capped by the limit; without a limit, put back the vote
* the AP's agent had before probe.
* agents ask for and the DCS floors held, capped by the limit; without a
* limit, the vote the AP's agent had before probe or the floors, if higher.
*/
static void apple_pmc_dcs_vote(struct apple_pmc *pmc)
{
const struct apple_pmc_hw *hw = pmc->hw;
void __iomem *reg = pmc->voters + hw->ap_agent * hw->agent_stride;
u32 mask = APPLE_PMC_RAIL_MASK(hw->dcs_rail);
unsigned int state = pmc->ap_dcs_vote;
unsigned int state = max(pmc->ap_dcs_vote, pmc->dcs_floor);
u32 old, val;

if (pmc->dcs_state)
state = min_t(unsigned int, apple_pmc_dcs_demand(pmc),
state = min_t(unsigned int,
max(apple_pmc_dcs_demand(pmc), pmc->dcs_floor),
hw->dcs_max - pmc->dcs_state);

old = readl(reg);
Expand Down Expand Up @@ -618,6 +621,13 @@ static int apple_pmc_floor_apply(struct apple_pmc *pmc, unsigned int rail)
if (dom->floor && dom->rail == rail && dom->on)
level = max(level, dom->level);

/* The AP's DCS vote also carries the DCS limit; it combines both. */
if (rail == pmc->hw->dcs_rail) {
pmc->dcs_floor = level;
apple_pmc_dcs_vote(pmc);
return 0;
}

return __apple_pmc_floor_update(pmc, pmc->hw->ap_agent,
APPLE_PMC_RAIL_MASK(rail),
level << APPLE_PMC_RAIL_SHIFT(rail));
Expand Down Expand Up @@ -860,11 +870,12 @@ static int apple_pmc_floor_add(struct apple_pmc *pmc, struct device_node *np)
if (of_property_read_u32(np, "apple,rail", &rail) ||
of_property_read_u32(np, "apple,level", &level))
return dev_err_probe(dev, -EINVAL, "%pOF: missing rail or level\n", np);
/* The DCS rail's AP vote belongs to the DCS limit. */
if (rail >= hw->rails || rail == hw->dcs_rail ||
/* A DCS floor shares the AP's DCS vote with the DCS limit, which caps it. */
if (rail >= hw->rails ||
(hw->agent_rails && !(hw->agent_rails & BIT(rail))))
return dev_err_probe(dev, -EINVAL, "%pOF: invalid rail %u\n", np, rail);
if (!level || level >= APPLE_PMC_MAX_STATES)
if (!level || level >= APPLE_PMC_MAX_STATES ||
(rail == hw->dcs_rail && level > hw->dcs_max))
return dev_err_probe(dev, -EINVAL, "%pOF: invalid level %u\n", np, level);
if (!(pmc->static_agents & BIT(hw->ap_agent)))
return dev_err_probe(dev, -EINVAL,
Expand Down