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
8 changes: 8 additions & 0 deletions Documentation/devicetree/bindings/gpu/apple,t8020-agx.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ properties:
The firmware's segments as Apple's device tree lists them (32 bytes
each: physical address, address in the firmware's space, size).

apple,firmware-build:
description:
The GPU firmware build the board's boot loader is given, for when the
driver cannot recognise the loaded firmware itself.
enum:
- 20g81
- 21b91

apple,g11-core-perf-states:
$ref: /schemas/types.yaml#/definitions/uint32-array
description: The GPU's performance states, frequency and voltage pairs.
Expand Down
9 changes: 9 additions & 0 deletions arch/arm64/boot/dts/apple/t8020-ipad8.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -263,3 +263,12 @@
dmas = <&sio 0x2c>;
dma-names = "tx1a";
};

/*
* The GPU firmware the iPad 8 is given is 17.1.1's (21B91), the build
* dr1408's backend fits; the driver recognises it from the firmware, and
* falls back to this.
*/
&gfx_asc {
apple,firmware-build = "21b91";
};
1 change: 1 addition & 0 deletions drivers/gpu/drm/agx/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ config DRM_AGX
depends on DRM && ARCH_APPLE && APPLE_RTKIT
select DRM_GEM_SHMEM_HELPER
select DRM_SCHED
select CRYPTO_LIB_SHA256
help
Compute-only DRM driver for the GPU in the Apple A12 (T8020). It
boots the GPU firmware and runs compute jobs through the Asahi uAPI.
8 changes: 5 additions & 3 deletions drivers/gpu/drm/agx/agx.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,10 @@ struct agx_device {
struct { u32 cmd, evc, useq, scratch; } slot[4];
/* Render: one job's commands and the buffer manager, see agx_fw_render(). */
struct {
u32 bmd, bms, init, ta, frag, scratch, tilemap, tpc, heapmeta, pre;
bool frag_pending;
u32 bmd, bms, init, barrier, ta, frag, scratch, tilemap, tpc, heapmeta,
pre;
/* last stamp values, see agx_fw_render() */
u32 ta_stamp, frag_stamp;
} rn;
bool wedged;

Expand All @@ -80,7 +82,7 @@ struct agx_device {
spinlock_t fence_lock;
u64 fence_ctx, fence_seqno;
struct dma_fence *active;
u32 active_stamp;
u32 active_stamp, active_value;

struct mutex ctx_lock;
unsigned long ctx_used[BITS_TO_LONGS(AGX_NR_CTX)];
Expand Down
93 changes: 83 additions & 10 deletions drivers/gpu/drm/agx/agx_drv.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@
#include <drm/drm_gem_shmem_helper.h>
#include <drm/drm_ioctl.h>
#include <drm/drm_syncobj.h>
#include <crypto/sha2.h>
#include <drm/gpu_scheduler.h>
#include <linux/dma-fence-chain.h>
#include <linux/dma-mapping.h>
#include <linux/dmapool.h>
#include <linux/io.h>
#include <linux/module.h>
#include <linux/of.h>
#include <linux/platform_device.h>
Expand Down Expand Up @@ -759,29 +761,100 @@ struct agx_device *agx21_asahi_register(struct platform_device *pdev,
return agx;
}

static char *agx_firmware = "21b91";
static char *agx_firmware = "";
module_param_named(firmware, agx_firmware, charp, 0400);
MODULE_PARM_DESC(firmware, "GPU firmware build iBoot loads: 21b91 (17.1.1) or 20g81 (16.6.1)");
MODULE_PARM_DESC(firmware, "GPU firmware build iBoot loaded: 20g81 (16.6.1) or 21b91 (17.1.1); default: recognised from the firmware");

/*
* The GPU firmware builds this driver speaks, by the SHA-256 of their
* __TEXT segment (0x44000 bytes) as iBoot loads it: armfw_g11p's Mach-O,
* after its rkosftab header. Each is the same file on every A12 board that
* has the build (20G81: the iPhone XS, XS Max and XR; 21B91: the XR and
* iPad 8).
*/
#define AGX_FW_TEXT_SIZE 0x44000
static const struct {
const char *build;
u8 text[SHA256_DIGEST_SIZE];
} agx_known_firmware[] = {
{ "20g81", { 0x80, 0x47, 0x72, 0x3b, 0xc6, 0xdb, 0x37, 0x48,
0x9d, 0xc7, 0xf7, 0x50, 0xc5, 0xdc, 0x44, 0xf3,
0xf5, 0xef, 0xa8, 0x26, 0xb3, 0xbb, 0xd7, 0xe9,
0x38, 0x1b, 0x77, 0x35, 0x96, 0xaa, 0x83, 0xa0 } },
{ "21b91", { 0xc6, 0x3d, 0x55, 0xb5, 0xa3, 0x11, 0x33, 0xfd,
0x9f, 0x18, 0x19, 0x47, 0x1d, 0x97, 0x50, 0x41,
0x9c, 0x68, 0x4c, 0x57, 0x6c, 0x9b, 0xb0, 0x93,
0xa9, 0x1f, 0x7f, 0xa3, 0x72, 0xbe, 0xd9, 0x3d } },
};

/* One entry of apple,segment-ranges: {phys, iova, remap, size, flags}. */
struct agx_segment_range {
__le64 phys;
__le64 iova;
__le64 remap;
__le32 size;
__le32 flags;
} __packed;

/*
* The build of the firmware iBoot loaded: from the module parameter, else
* recognised by its __TEXT segment, else the board's apple,firmware-build,
* else 20g81, the build badapple runs on the XS Max.
*/
static const char *agx_firmware_build(struct device *dev)
{
const struct agx_segment_range *seg;
const char *build;
u8 digest[SHA256_DIGEST_SIZE];
int len, i, j;

if (agx_firmware[0])
return agx_firmware;
seg = of_get_property(dev->of_node, "apple,segment-ranges", &len);
for (i = 0; seg && i < len / (int)sizeof(*seg); i++) {
void *text;

if (le32_to_cpu(seg[i].size) != AGX_FW_TEXT_SIZE ||
le64_to_cpu(seg[i].iova))
continue;
/* iBoot loaded it and m1n1 reserved it; nothing runs it yet */
text = memremap(le64_to_cpu(seg[i].phys), AGX_FW_TEXT_SIZE, MEMREMAP_WB);
if (!text)
continue;
sha256(text, AGX_FW_TEXT_SIZE, digest);
memunmap(text);
for (j = 0; j < ARRAY_SIZE(agx_known_firmware); j++) {
if (!memcmp(digest, agx_known_firmware[j].text, sizeof(digest))) {
dev_info(dev, "GPU firmware %s\n", agx_known_firmware[j].build);
return agx_known_firmware[j].build;
}
}
dev_warn(dev, "GPU firmware not one this driver knows (__TEXT %*phN)\n",
8, digest);
}
if (!of_property_read_string(dev->of_node, "apple,firmware-build", &build))
return build;
return "20g81";
}

static int agx_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
struct agx_device *agx;
struct resource *res;
void __iomem *asc;
const char *build;
int len, ret;

build = agx_firmware_build(dev);
/*
* Which firmware build iBoot was given decides the ABI. Orchard hands
* every A12 board the 17.1.1 (21B91) GPU firmware, the build the 21B91
* backend fits; the XS Max's 16.6.1 (20G81) layout below is kept for
* that firmware and taken with agx.firmware=20g81.
* The firmware build iBoot loaded decides the ABI: badapple's 16.6.1
* (20G81) layout below, or dr1408's 17.1.1 (21B91) backend.
*/
if (!strcmp(agx_firmware, "21b91"))
if (!strcmp(build, "21b91"))
return agx21_transport_probe(pdev);
if (strcmp(agx_firmware, "20g81"))
return dev_err_probe(dev, -EINVAL, "unknown firmware build %s\n",
agx_firmware);
if (strcmp(build, "20g81"))
return dev_err_probe(dev, -EINVAL, "unknown firmware build %s\n", build);

agx = devm_drm_dev_alloc(dev, &agx_drm_driver, struct agx_device, drm);
if (IS_ERR(agx))
Expand Down
Loading
Loading