summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAurora zuma automerger <aurora-zuma-automerger@google.com>2022-10-24 22:19:37 -0700
committerCopybara-Service <copybara-worker@google.com>2022-11-09 23:30:47 -0800
commit5ffa0dbbb9b69681ad069d3e875a2a2273ac25b3 (patch)
tree460ac5b7b6b3fa8fce1c73237af60a79efac25f4
parent205a8ff3884b375d5a25c2655eed06ba3d104cc9 (diff)
downloadzuma-5ffa0dbbb9b69681ad069d3e875a2a2273ac25b3.tar.gz
gxp: [Copybara Auto Merge] Merge branch 'zuma' into 'android13-gs-pixel-5.15'
gxp: add support for firmware header gen 2 gxp: Fix reader/writer lock for vd allocation Bug: 257049139 gxp: remove obsolete compatible string gxp: Add a static debug pointer to driver state Bug: 255451381 gxp: fixup headers in platform.c gxp: Add namespace import for DMA_BUF for 5.16 Bug: 232003048 gcip: add common authenticated image format header GCIP_HEADERS_REV_ID: aa321de4afdfdcea612cba24a2dc40cdab089c43 GitOrigin-RevId: 6cf43b28f0789fc8eedcb9730d6344fb56f28d0b Change-Id: I7cc3d7edf6729a9d332035338a409867bc4c6f9d
-rw-r--r--callisto-platform.c1
-rw-r--r--gcip-kernel-driver/include/gcip/gcip-common-image-header.h65
-rw-r--r--gxp-client.c2
-rw-r--r--gxp-common-platform.c13
-rw-r--r--gxp-dmabuf.c5
-rw-r--r--gxp-mcu-firmware.c29
-rw-r--r--gxp-mcu-firmware.h5
7 files changed, 97 insertions, 23 deletions
diff --git a/callisto-platform.c b/callisto-platform.c
index 5221f62..6143ad7 100644
--- a/callisto-platform.c
+++ b/callisto-platform.c
@@ -512,7 +512,6 @@ static int gxp_platform_remove(struct platform_device *pdev)
static const struct of_device_id gxp_of_match[] = {
{ .compatible = "google,gxp", },
- { .compatible = "google,gxp-gs301", },
{ .compatible = "google,gxp-zuma", },
{ /* end of list */ },
};
diff --git a/gcip-kernel-driver/include/gcip/gcip-common-image-header.h b/gcip-kernel-driver/include/gcip/gcip-common-image-header.h
new file mode 100644
index 0000000..d376be1
--- /dev/null
+++ b/gcip-kernel-driver/include/gcip/gcip-common-image-header.h
@@ -0,0 +1,65 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Common authenticated image format for Google SoCs
+ *
+ * Copyright (C) 2022 Google LLC
+ */
+
+#ifndef __GCIP_COMMON_IMAGE_HEADER_H__
+#define __GCIP_COMMON_IMAGE_HEADER_H__
+
+#include "gcip-image-config.h"
+
+#define GCIP_FW_HEADER_SIZE (0x1000)
+
+struct gcip_common_image_sub_header_common {
+ int magic;
+ int generation;
+ int rollback_info;
+ int length;
+ char flags[16];
+};
+
+struct gcip_common_image_sub_header_gen1 {
+ char body_hash[32];
+ char chip_id[32];
+ char auth_config[256];
+ struct gcip_image_config image_config;
+};
+
+struct gcip_common_image_sub_header_gen2 {
+ char body_hash[64];
+ char chip_id[32];
+ char auth_config[256];
+ struct gcip_image_config image_config;
+};
+
+struct gcip_common_image_header {
+ char sig[512];
+ char pub[512];
+ struct {
+ struct gcip_common_image_sub_header_common common;
+ union {
+ struct gcip_common_image_sub_header_gen1 gen1;
+ struct gcip_common_image_sub_header_gen2 gen2;
+ };
+ };
+};
+
+/*
+ * Returns the image config field from a common image header
+ * or NULL if the header has an invalid generation identifier
+ */
+static inline struct gcip_image_config *
+get_image_config_from_hdr(struct gcip_common_image_header *hdr)
+{
+ switch (hdr->common.generation) {
+ case 1:
+ return &hdr->gen1.image_config;
+ case 2:
+ return &hdr->gen2.image_config;
+ }
+ return NULL;
+}
+
+#endif /* __GCIP_COMMON_IMAGE_HEADER_H__ */
diff --git a/gxp-client.c b/gxp-client.c
index 431e3ea..dfcaed5 100644
--- a/gxp-client.c
+++ b/gxp-client.c
@@ -100,7 +100,6 @@ int gxp_client_allocate_virtual_device(struct gxp_client *client,
ret);
goto error;
}
- up_write(&gxp->vd_semaphore);
if (client->has_block_wakelock) {
ret = gxp_vd_block_ready(vd);
@@ -109,6 +108,7 @@ int gxp_client_allocate_virtual_device(struct gxp_client *client,
goto error;
}
}
+ up_write(&gxp->vd_semaphore);
client->vd = vd;
return 0;
diff --git a/gxp-common-platform.c b/gxp-common-platform.c
index 42c4195..615da3d 100644
--- a/gxp-common-platform.c
+++ b/gxp-common-platform.c
@@ -9,21 +9,16 @@
#include <linux/platform_data/sscoredump.h>
#endif
-#include <linux/acpi.h>
-#include <linux/cred.h>
#include <linux/device.h>
#include <linux/dma-mapping.h>
#include <linux/file.h>
#include <linux/fs.h>
-#include <linux/genalloc.h>
-#include <linux/kthread.h>
-#include <linux/log2.h>
#include <linux/miscdevice.h>
#include <linux/module.h>
#include <linux/of_device.h>
#include <linux/platform_device.h>
-#include <linux/pm_runtime.h>
#include <linux/sched.h>
+#include <linux/slab.h>
#include <linux/uaccess.h>
#include <linux/uidgid.h>
#if (IS_ENABLED(CONFIG_GXP_TEST) || IS_ENABLED(CONFIG_ANDROID)) && !IS_ENABLED(CONFIG_GXP_GEM5)
@@ -57,6 +52,8 @@
#include "gxp-dci.h"
#endif
+static struct gxp_dev *gxp_debug_pointer;
+
/* Caller needs to hold client->semaphore */
static bool check_client_has_available_vd(struct gxp_client *client,
char *ioctl_name)
@@ -1856,6 +1853,8 @@ static int gxp_common_platform_probe(struct platform_device *pdev, struct gxp_de
goto err_before_remove;
}
+ gxp_debug_pointer = gxp;
+
dev_info(dev, "Probe finished");
return 0;
@@ -1903,6 +1902,8 @@ static int gxp_common_platform_remove(struct platform_device *pdev)
put_device(gxp->tpu_dev.dev);
gxp_pm_destroy(gxp);
+ gxp_debug_pointer = NULL;
+
return 0;
}
diff --git a/gxp-dmabuf.c b/gxp-dmabuf.c
index db20c07..85fd832 100644
--- a/gxp-dmabuf.c
+++ b/gxp-dmabuf.c
@@ -8,6 +8,7 @@
#include <linux/dma-buf.h>
#include <linux/scatterlist.h>
#include <linux/slab.h>
+#include <linux/version.h>
#include "gxp-dma.h"
#include "gxp-dmabuf.h"
@@ -114,3 +115,7 @@ err_attach:
dma_buf_put(dmabuf);
return ERR_PTR(ret);
}
+
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 16, 0)
+MODULE_IMPORT_NS(DMA_BUF);
+#endif
diff --git a/gxp-mcu-firmware.c b/gxp-mcu-firmware.c
index 7126077..f4c5f5e 100644
--- a/gxp-mcu-firmware.c
+++ b/gxp-mcu-firmware.c
@@ -13,6 +13,7 @@
#include <linux/resource.h>
#include <linux/string.h>
+#include <gcip/gcip-common-image-header.h>
#include <gcip/gcip-image-config.h>
#include "gxp-bpm.h"
@@ -26,7 +27,8 @@
#include "gxp-pm.h"
#include "gxp-wakelock.h"
-static const char signature_magic_string[] = "DSPF";
+/* Value of Magic field in the common header "DSPF' as a 32-bit LE int */
+#define GXP_FW_MAGIC 0x46505344
/*
* Programs instruction remap CSRs.
@@ -46,13 +48,13 @@ static void program_iremap_csr(struct gxp_dev *gxp,
/*
* Check whether the firmware file is signed or not.
*/
-static bool is_signed_firmware(const struct firmware *fw)
+static bool is_signed_firmware(const struct firmware *fw,
+ const struct gcip_common_image_header *hdr)
{
- if (fw->size < MCU_SIGNATURE_SIZE)
+ if (fw->size < GCIP_FW_HEADER_SIZE)
return false;
- if (strncmp(fw->data + MCU_SIGNATURE_HEADER_OFFSET,
- signature_magic_string, strlen(signature_magic_string)))
+ if (hdr->common.magic != GXP_FW_MAGIC)
return false;
return true;
@@ -69,6 +71,7 @@ static int gxp_mcu_firmware_load_locked(struct gxp_mcu_firmware *mcu_fw,
struct device *dev = gxp->dev;
struct gcip_image_config *imgcfg;
const struct firmware *fw;
+ struct gcip_common_image_header *hdr;
size_t offset, size;
lockdep_assert_held(&mcu_fw->lock);
@@ -78,11 +81,13 @@ static int gxp_mcu_firmware_load_locked(struct gxp_mcu_firmware *mcu_fw,
return ret;
}
- mcu_fw->is_signed = is_signed_firmware(fw);
+ hdr = (struct gcip_common_image_header *)fw->data;
+
+ mcu_fw->is_signed = is_signed_firmware(fw, hdr);
if (mcu_fw->is_signed) {
- offset = MCU_SIGNATURE_SIZE;
- size = fw->size - MCU_SIGNATURE_SIZE;
+ offset = GCIP_FW_HEADER_SIZE;
+ size = fw->size - GCIP_FW_HEADER_SIZE;
} else {
offset = 0;
size = fw->size;
@@ -96,8 +101,12 @@ static int gxp_mcu_firmware_load_locked(struct gxp_mcu_firmware *mcu_fw,
}
if (mcu_fw->is_signed) {
- imgcfg = (struct gcip_image_config *)(fw->data +
- MCU_IMAGE_CONFIG_OFFSET);
+ imgcfg = get_image_config_from_hdr(hdr);
+ if (!imgcfg) {
+ dev_err(dev, "Unsupported image header generation");
+ ret = -EINVAL;
+ goto out_release_firmware;
+ }
ret = gcip_image_config_parse(&mcu_fw->cfg_parser, imgcfg);
if (ret)
dev_err(dev, "image config parsing failed: %d", ret);
diff --git a/gxp-mcu-firmware.h b/gxp-mcu-firmware.h
index 5affc48..6218d5e 100644
--- a/gxp-mcu-firmware.h
+++ b/gxp-mcu-firmware.h
@@ -15,11 +15,6 @@
#include "gxp-internal.h"
-#define MCU_SIGNATURE_SIZE 0x1000
-#define MCU_SIGNATURE_HEADER_OFFSET 0x400
-/* The offset from top of the signed MCU firmware to the image config data. */
-#define MCU_IMAGE_CONFIG_OFFSET 0x560
-
struct gxp_mcu_firmware {
struct gxp_dev *gxp;
/* resource for MCU firmware image */