All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alexandre Courbot <acourbot-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
To: Ben Skeggs <bskeggs-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
Cc: nouveau-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org
Subject: [PATCH v2 13/14] secboot: remove ls_ucode_mgr
Date: Thu, 27 Oct 2016 13:37:07 +0900	[thread overview]
Message-ID: <20161027043708.22538-14-acourbot@nvidia.com> (raw)
In-Reply-To: <20161027043708.22538-1-acourbot-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>

This was used only locally to one function and can be replaced by ad-hoc
variables.

Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
---
 drm/nouveau/nvkm/subdev/secboot/acr_r352.c | 90 +++++++++++-------------------
 1 file changed, 33 insertions(+), 57 deletions(-)

diff --git a/drm/nouveau/nvkm/subdev/secboot/acr_r352.c b/drm/nouveau/nvkm/subdev/secboot/acr_r352.c
index 15e1d829f265..72985aa1e553 100644
--- a/drm/nouveau/nvkm/subdev/secboot/acr_r352.c
+++ b/drm/nouveau/nvkm/subdev/secboot/acr_r352.c
@@ -276,75 +276,44 @@ ls_ucode_img_fill_headers(struct nvkm_acr_r352 *acr, struct ls_ucode_img *img,
 }
 
 /**
- * struct ls_ucode_mgr - manager for all LS falcon firmwares
- * @count:	number of managed LS falcons
- * @wpr_size:	size of the required WPR region in bytes
- * @img_list:	linked list of lsf_ucode_img
+ * acr_r352_ls_fill_headers - fill WPR and LSB headers of all managed images
  */
-struct ls_ucode_mgr {
-	u16 count;
-	u32 wpr_size;
-	struct list_head img_list;
-};
-
-static void
-ls_ucode_mgr_init(struct ls_ucode_mgr *mgr)
-{
-	memset(mgr, 0, sizeof(*mgr));
-	INIT_LIST_HEAD(&mgr->img_list);
-}
-
-static void
-ls_ucode_mgr_cleanup(struct ls_ucode_mgr *mgr)
-{
-	struct ls_ucode_img *img, *t;
-
-	list_for_each_entry_safe(img, t, &mgr->img_list, node) {
-		kfree(img->ucode_data);
-		kfree(img);
-	}
-}
-
-static void
-ls_ucode_mgr_add_img(struct ls_ucode_mgr *mgr, struct ls_ucode_img *img)
-{
-	mgr->count++;
-	list_add_tail(&img->node, &mgr->img_list);
-}
-
-/**
- * ls_ucode_mgr_fill_headers - fill WPR and LSB headers of all managed images
- */
-static void
-ls_ucode_mgr_fill_headers(struct nvkm_acr_r352 *acr, struct ls_ucode_mgr *mgr)
+static int
+acr_r352_ls_fill_headers(struct nvkm_acr_r352 *acr, struct list_head *imgs)
 {
 	struct ls_ucode_img *img;
+	struct list_head *l;
+	u32 count = 0;
 	u32 offset;
 
+	/* Count the number of images to manage */
+	list_for_each(l, imgs)
+		count++;
+
 	/*
 	 * Start with an array of WPR headers at the base of the WPR.
 	 * The expectation here is that the secure falcon will do a single DMA
 	 * read of this array and cache it internally so it's ok to pack these.
 	 * Also, we add 1 to the falcon count to indicate the end of the array.
 	 */
-	offset = sizeof(struct lsf_wpr_header) * (mgr->count + 1);
+	offset = sizeof(struct lsf_wpr_header) * (count + 1);
 
 	/*
 	 * Walk the managed falcons, accounting for the LSB structs
 	 * as well as the ucode images.
 	 */
-	list_for_each_entry(img, &mgr->img_list, node) {
+	list_for_each_entry(img, imgs, node) {
 		offset = ls_ucode_img_fill_headers(acr, img, offset);
 	}
 
-	mgr->wpr_size = offset;
+	return offset;
 }
 
 /**
  * ls_ucode_mgr_write_wpr - write the WPR blob contents
  */
 static int
-ls_ucode_mgr_write_wpr(struct nvkm_acr_r352 *acr, struct ls_ucode_mgr *mgr,
+ls_ucode_mgr_write_wpr(struct nvkm_acr_r352 *acr, struct list_head *imgs,
 		       struct nvkm_gpuobj *wpr_blob, u32 wpr_addr)
 {
 	struct ls_ucode_img *img;
@@ -352,7 +321,7 @@ ls_ucode_mgr_write_wpr(struct nvkm_acr_r352 *acr, struct ls_ucode_mgr *mgr,
 
 	nvkm_kmap(wpr_blob);
 
-	list_for_each_entry(img, &mgr->img_list, node) {
+	list_for_each_entry(img, imgs, node) {
 		const struct nvkm_acr_r352_ls_func *ls_func =
 					     acr->func->ls_func[img->falcon_id];
 		u8 gdesc[ls_func->bl_desc_size];
@@ -398,11 +367,14 @@ acr_r352_prepare_ls_blob(struct nvkm_acr_r352 *acr, u64 wpr_addr, u32 wpr_size,
 			 unsigned long managed_falcons)
 {
 	const struct nvkm_subdev *subdev = acr->base.subdev;
-	struct ls_ucode_mgr mgr;
+	struct list_head imgs;
+	struct ls_ucode_img *img, *t;
+	int managed_count = 0;
+	u32 image_wpr_size;
 	int falcon_id;
 	int ret;
 
-	ls_ucode_mgr_init(&mgr);
+	INIT_LIST_HEAD(&imgs);
 
 	/* Load all LS blobs */
 	for_each_set_bit(falcon_id, &managed_falcons, NVKM_FALCON_END) {
@@ -415,48 +387,52 @@ acr_r352_prepare_ls_blob(struct nvkm_acr_r352 *acr, u64 wpr_addr, u32 wpr_size,
 			ret = PTR_ERR(img);
 			goto cleanup;
 		}
-		ls_ucode_mgr_add_img(&mgr, img);
+		list_add_tail(&img->node, &imgs);
+		managed_count++;
 	}
 
 	/*
 	 * Fill the WPR and LSF headers with the right offsets and compute
 	 * required WPR size
 	 */
-	ls_ucode_mgr_fill_headers(acr, &mgr);
-	mgr.wpr_size = ALIGN(mgr.wpr_size, WPR_ALIGNMENT);
+	image_wpr_size = acr_r352_ls_fill_headers(acr, &imgs);
+	image_wpr_size = ALIGN(image_wpr_size, WPR_ALIGNMENT);
 
 	/* Allocate GPU object that will contain the WPR region */
-	ret = nvkm_gpuobj_new(subdev->device, mgr.wpr_size, WPR_ALIGNMENT,
+	ret = nvkm_gpuobj_new(subdev->device, image_wpr_size, WPR_ALIGNMENT,
 			      false, NULL, &acr->ls_blob);
 	if (ret)
 		goto cleanup;
 
 	nvkm_debug(subdev, "%d managed LS falcons, WPR size is %d bytes\n",
-		    mgr.count, mgr.wpr_size);
+		    managed_count, image_wpr_size);
 
 	/* If WPR address and size are not fixed, set them to fit the LS blob */
 	if (wpr_size == 0) {
 		wpr_addr = acr->ls_blob->addr;
-		wpr_size = mgr.wpr_size;
+		wpr_size = image_wpr_size;
 	/*
 	 * But if the WPR region is set by the bootloader, it is illegal for
 	 * the HS blob to be larger than this region.
 	 */
-	} else if (mgr.wpr_size > wpr_size) {
+	} else if (image_wpr_size > wpr_size) {
 		nvkm_error(subdev, "WPR region too small for FW blob!\n");
-		nvkm_error(subdev, "required: %dB\n", mgr.wpr_size);
+		nvkm_error(subdev, "required: %dB\n", image_wpr_size);
 		nvkm_error(subdev, "available: %dB\n", wpr_size);
 		ret = -ENOSPC;
 		goto cleanup;
 	}
 
 	/* Write LS blob */
-	ret = ls_ucode_mgr_write_wpr(acr, &mgr, acr->ls_blob, wpr_addr);
+	ret = ls_ucode_mgr_write_wpr(acr, &imgs, acr->ls_blob, wpr_addr);
 	if (ret)
 		nvkm_gpuobj_del(&acr->ls_blob);
 
 cleanup:
-	ls_ucode_mgr_cleanup(&mgr);
+	list_for_each_entry_safe(img, t, &imgs, node) {
+		kfree(img->ucode_data);
+		kfree(img);
+	}
 
 	return ret;
 }
-- 
2.10.0

_______________________________________________
Nouveau mailing list
Nouveau@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/nouveau

  parent reply	other threads:[~2016-10-27  4:37 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-27  4:36 [PATCH v2 00/14] Secure Boot refactoring Alexandre Courbot
     [not found] ` <20161027043708.22538-1-acourbot-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2016-10-27  4:36   ` [PATCH v2 01/14] core: constify nv*_printk macros Alexandre Courbot
2016-10-27  4:36   ` [PATCH v2 02/14] core: add falcon library Alexandre Courbot
2016-10-27  4:36   ` [PATCH v2 03/14] secboot: use falcon library's IMEM/DMEM loading functions Alexandre Courbot
2016-10-27  4:36   ` [PATCH v2 04/14] secboot: rename init() hook to oneinit() Alexandre Courbot
2016-10-27  4:36   ` [PATCH v2 05/14] secboot: remove fixup_hs_desc hook Alexandre Courbot
2016-10-27  4:37   ` [PATCH v2 06/14] secboot: add low-secure firmware hooks Alexandre Courbot
2016-10-27  4:37   ` [PATCH v2 07/14] secboot: generate HS BL descriptor in hook Alexandre Courbot
2016-10-27  4:37   ` [PATCH v2 08/14] secboot: reorganize into more files Alexandre Courbot
2016-10-27  4:37   ` [PATCH v2 09/14] secboot: add LS flags to LS func structure Alexandre Courbot
2016-10-27  4:37   ` [PATCH v2 10/14] secboot: split reset function Alexandre Courbot
2016-10-27  4:37   ` [PATCH v2 11/14] secboot: disable falcon interrupts before running Alexandre Courbot
2016-10-27  4:37   ` [PATCH v2 12/14] secboot: remove unneeded ls_ucode_img member Alexandre Courbot
2016-10-27  4:37   ` Alexandre Courbot [this message]
2016-10-27  4:37   ` [PATCH v2 14/14] secboot: abstract LS firmware loading functions Alexandre Courbot
2016-10-27  8:27   ` [PATCH v2 00/14] Secure Boot refactoring Alexandre Courbot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20161027043708.22538-14-acourbot@nvidia.com \
    --to=acourbot-ddmlm1+adcrqt0dzr+alfa@public.gmane.org \
    --cc=bskeggs-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org \
    --cc=nouveau-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.