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
13 changes: 13 additions & 0 deletions Documentation/devicetree/bindings/power/apple,pmc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,15 @@ properties:
$ref: /schemas/types.yaml#/definitions/phandle
description: PMP firmware owner that initializes the voter interface.

apple,pmp-voter:
$ref: /schemas/types.yaml#/definitions/uint32
maximum: 31
description:
Voter agent of the PMP named by apple,pmp, for a PMP whose board values
(apple,board-id and apple,dram-vendor-id) the boot loader fills in.
When it has not filled them in, the PMP never starts, so the PMC does
not wait for it and leaves this agent out of apple,static-voters.

apple,static-voters:
$ref: /schemas/types.yaml#/definitions/uint32-array
description: Voter agents to enable on every rail.
Expand Down Expand Up @@ -344,6 +353,10 @@ patternProperties:
- compatible
- reg

dependentRequired:
apple,pmp-voter:
- apple,pmp

required:
- compatible
- reg
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,9 @@ properties:
$ref: /schemas/types.yaml#/definitions/phandle
description:
The PMP that publishes this report, on SoCs where the host starts the
PMP after a display handoff.
PMP after a display handoff, or where the boot loader fills in the
PMP's board values (apple,board-id and apple,dram-vendor-id). The
report does not wait for an enabled PMP without those values.

apple,pmp-tables:
$ref: /schemas/types.yaml#/definitions/phandle
Expand Down
23 changes: 23 additions & 0 deletions drivers/pmdomain/apple/pmc.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@
#include <linux/thermal.h>
#include <linux/workqueue.h>

#include "pmp-handoff.h"

#if IS_ENABLED(CONFIG_APPLE_PMC_KUNIT_TEST)
#include <kunit/static_stub.h>
#endif
Expand Down Expand Up @@ -1330,8 +1332,23 @@ static int apple_pmc_probe(struct platform_device *pdev)
struct device_node *pmp_node;
struct platform_device *pmp;
struct device_link *link;
bool pmp_voter_off = false;
u32 pmp_voter;

pmp_node = of_parse_phandle(np, "apple,pmp", 0);
if (pmp_node && !of_property_read_u32(np, "apple,pmp-voter", &pmp_voter) &&
!(of_device_is_available(pmp_node) && apple_pmp_has_board_values(pmp_node))) {
/*
* The boot loader did not hand this PMP over, so it never
* starts. Run without its votes rather than wait for it, so
* that the CLPC below still comes up.
*/
dev_info(dev, "%pOF was not handed over; running without its votes\n",
pmp_node);
of_node_put(pmp_node);
pmp_node = NULL;
pmp_voter_off = true;
}
if (pmp_node) {
pmp = of_find_device_by_node(pmp_node);
of_node_put(pmp_node);
Expand Down Expand Up @@ -1402,6 +1419,12 @@ static int apple_pmc_probe(struct platform_device *pdev)
pmc->static_agents |= BIT(agents[i]);
}
}
if (pmp_voter_off) {
if (pmp_voter >= pmc->hw->agents)
return dev_err_probe(dev, -EINVAL, "invalid PMP voter %u\n",
pmp_voter);
pmc->static_agents &= ~BIT(pmp_voter);
}

platform_set_drvdata(pdev, pmc);
ret = devm_add_action_or_reset(dev, apple_pmc_release, pmc);
Expand Down
22 changes: 22 additions & 0 deletions drivers/pmdomain/apple/pmp-handoff.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/* SPDX-License-Identifier: GPL-2.0-only */
#ifndef _APPLE_PMP_HANDOFF_H
#define _APPLE_PMP_HANDOFF_H

#include <linux/of.h>
#include <linux/types.h>

/*
* Whether @pmp has the running machine's apple,board-id and
* apple,dram-vendor-id. The PMP driver refuses to start the PMP without
* them, and a DT that leaves them to the boot loader only has them when the
* loader filled them in.
*/
static inline bool apple_pmp_has_board_values(const struct device_node *pmp)
{
u32 val;

return !of_property_read_u32(pmp, "apple,board-id", &val) &&
!of_property_read_u32(pmp, "apple,dram-vendor-id", &val);
}

#endif /* _APPLE_PMP_HANDOFF_H */
20 changes: 19 additions & 1 deletion drivers/pmdomain/apple/pmp-report.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
#include "pmp-dram.h"
#include "pmp-ane.h"
#include "pmp-floor-gov.h"
#include "pmp-handoff.h"

#define PMP_REPORT_READY 0x1

Expand Down Expand Up @@ -2474,6 +2475,23 @@ static int apple_pmp_report_resume(struct device *dev)
static DEFINE_SIMPLE_DEV_PM_OPS(apple_pmp_report_pm_ops, apple_pmp_report_suspend,
apple_pmp_report_resume);

/*
* Whether to wait for the PMP to run. A report that names an enabled PMP in
* apple,pmp whose board values the boot loader did not fill in keeps its
* requests to itself: that PMP never starts. Any other report waits for it.
*/
static bool apple_pmp_report_pmp_handed_over(struct apple_pmp_report *rep)
{
struct device_node *pmp = of_parse_phandle(rep->dev->of_node, "apple,pmp", 0);
bool wait = !pmp || !of_device_is_available(pmp) ||
apple_pmp_has_board_values(pmp);

if (!wait)
dev_info(rep->dev, "%pOF was not handed over; not waiting for it\n", pmp);
of_node_put(pmp);
return wait;
}

static int apple_pmp_report_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
Expand Down Expand Up @@ -2565,7 +2583,7 @@ static int apple_pmp_report_probe(struct platform_device *pdev)
if (ret)
return dev_err_probe(dev, ret, "failed to create child devices\n");

if (rep->defer)
if (rep->defer && apple_pmp_report_pmp_handed_over(rep))
queue_delayed_work(system_freezable_power_efficient_wq,
&rep->ready_work, 0);

Expand Down
36 changes: 36 additions & 0 deletions tools/asahi/t6030-pmp-graph-tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ static void host_log(const char *format, ...)
struct device_node {
const char *name, *compatible;
bool available, always_on, no_ack, deferred, irq_safe, uuid, soc_record, release_sleep;
bool has_board_id, has_dram_vendor_id;
u32 reg;
int refs;
struct device_node *parent, *child, *sibling, *pmp;
Expand Down Expand Up @@ -501,6 +502,14 @@ static bool of_property_present(const struct device_node *n, const char *p)
static int of_property_read_u32(const struct device_node *n, const char *p,
u32 *v)
{
if (!strcmp(p, "apple,board-id") || !strcmp(p, "apple,dram-vendor-id")) {
bool present = !strcmp(p, "apple,board-id") ? n->has_board_id : n->has_dram_vendor_id;

if (!present)
return -EINVAL;
*v = 0;
return 0;
}
assert(!strcmp(p, "reg"));
*v = n->reg;
return 0;
Expand Down Expand Up @@ -911,8 +920,35 @@ static int g15_vote(void)
commands++;
return ret;
}
#if HOST_HAS_PMP_HANDOFF
static void test_pmp_handoff(void)
{
struct device_node pmp = {};
struct device_node report = {};
struct device dev = { .of_node = &report };
struct apple_pmp_report rep = { .dev = &dev };

assert(apple_pmp_report_pmp_handed_over(&rep));
report.pmp = &pmp;
assert(apple_pmp_report_pmp_handed_over(&rep));
pmp.available = true;
assert(!apple_pmp_report_pmp_handed_over(&rep));
pmp.has_board_id = true;
assert(!apple_pmp_report_pmp_handed_over(&rep));
pmp.has_board_id = false;
pmp.has_dram_vendor_id = true;
assert(!apple_pmp_report_pmp_handed_over(&rep));
pmp.has_board_id = true;
assert(apple_pmp_report_pmp_handed_over(&rep));
assert(pmp.refs == 0);
}
#endif

int main(void)
{
#if HOST_HAS_PMP_HANDOFF
test_pmp_handoff();
#endif
unsigned int cases = 0;
(void)apple_pmp_start_init;
(void)apple_pmp_report_wait_t6030_14;
Expand Down
16 changes: 14 additions & 2 deletions tools/asahi/t6030-pmp-graph-tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@ def main():
p.add_argument('--mutations', action='store_true')
p.add_argument('--output', required=True, type=Path)
args = p.parse_args(); args.output.mkdir(parents=True, exist_ok=False)
source = subprocess.check_output(['git', '-C', str(ROOT), 'show', args.ref + ':' + extract.REPORT], text=True) if args.ref else (ROOT / extract.REPORT).read_text()
def read_source(path):
if args.ref:
return subprocess.check_output(['git', '-C', str(ROOT), 'show', args.ref + ':' + path], text=True)
return (ROOT / path).read_text()

source = read_source(extract.REPORT)
overlay = (ROOT / 'drivers/soc/apple/t6030-pmp.dtso').read_text()
entries = []
for node in re.findall(r'report@[0-9a-f]+\s*\{(.*?)\n\s*\};', overlay, re.S):
Expand Down Expand Up @@ -59,7 +64,14 @@ def main():
'static int apple_pmp_report_entry_suspend_noirq(',
'static int apple_pmp_report_entry_resume_noirq(']
offsets = re.search(r'static const struct apple_pmp_report_offsets apple_pmp_offsets_t6030 = \{.*?\n\};', source, re.S)[0]
functions = '\n'.join(extract.function(source, n) for n in names)
handoff = ''
handoff_fn = 'static bool apple_pmp_report_pmp_handed_over('
if handoff_fn in source:
names.insert(names.index('static int apple_pmp_report_probe('), handoff_fn)
header = read_source('drivers/pmdomain/apple/pmp-handoff.h')
handoff = ('#define HOST_HAS_PMP_HANDOFF 1\n' +
extract.function(header, 'static inline bool apple_pmp_has_board_values('))
functions = handoff + '\n'.join(extract.function(source, n) for n in names)
# The T8122 14.x wait (CONFIG_APPLE_T8122_GPU_PMP_LINK=0 here) precedes the dispatch; it is
# added after the mutations are placed, so they target the T6030 path only.
t8122 = extract.function(source, 'static int apple_pmp_report_wait_t8122_14(') + '\n'
Expand Down
Loading