From patchwork Sat May 29 00:25:05 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Baryshkov X-Patchwork-Id: 450062 Delivered-To: patch@linaro.org Received: by 2002:a02:7a1b:0:0:0:0:0 with SMTP id a27csp811584jac; Fri, 28 May 2021 17:25:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx/mviu4nl//H71VRvTK9MOFG9WGzsUsoFdlCOy5XqGX/BRjxCiAjoUwjfRLgNdzf7orvgA X-Received: by 2002:a05:6402:8d0:: with SMTP id d16mr12596398edz.36.1622247923723; Fri, 28 May 2021 17:25:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622247923; cv=none; d=google.com; s=arc-20160816; b=DdpoZtb7gX9964f2HlSR9sWJoR2UERWFhCWJ84s76ZThYK6ds7ppU6WeVYEEZMXFvl f1jxAxpAuysgTHZmgGlr1QHWdIcUX0fsewq24jxG1vkh4S5m57YNUkzQvpNmw0wGBdXq 0N2AtQISvukRpKlvNEruw0VkkuNpAqAq45QB6CUEE3B6Dh4r/ry9YrIaQUuEV13dPejv nVN5NBu6Wk61Zxw99NuRQw6n/K91lsgCs2C3oE1I7dYUb3SmyB2d8L4/ZtEOELN/xQN/ Sp4zgUKnoX2pOCn7fZQcZkVIybmlfrk8+AF3CAtzCy/V0OKxwM8qhQyqJ8DgwYRA51Ai Cdng== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=khM8ENZRiO9GfrYZWjrb0BjgVR9cdtd9zq05AkI4UO4=; b=WAMKMSbvWzlWXiqgnhGtzewcdibDsDlYMxY/CdzHXRcIKBjJPuxXu0R0P1yzzs7fay yt0wycElTPHqN0e/jCOjApcjhIQhWM9vdtclrwt3HWxMIwgio7lYKDcn+KOcxl7NAmKj 8lAq8GzDZbUe6TNUTQx+x+Nekb2vecAQA7zDGEFh+Rm9IwoJI34P/Hv+NCjpKLLvsgai ucxTfqXvjp/RDdgx3nNn8TMw4nYm8/ngxi/azmDQpjf55GrvnH0aDQgA2STgPN9QsO1H e7pSXuq/NT1+BrfCHCpY/QAuKz/jb4y+yjz0EZZGPD0GOm+UwUi3Y+ELTRWTBBqGopSf E1ZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ZDBw+iBt; spf=pass (google.com: domain of linux-arm-msm-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-arm-msm-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id nc14si5580362ejc.387.2021.05.28.17.25.23; Fri, 28 May 2021 17:25:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-arm-msm-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ZDBw+iBt; spf=pass (google.com: domain of linux-arm-msm-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-arm-msm-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229666AbhE2A06 (ORCPT + 17 others); Fri, 28 May 2021 20:26:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52200 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229563AbhE2A05 (ORCPT ); Fri, 28 May 2021 20:26:57 -0400 Received: from mail-lf1-x12e.google.com (mail-lf1-x12e.google.com [IPv6:2a00:1450:4864:20::12e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5E443C061574 for ; Fri, 28 May 2021 17:25:21 -0700 (PDT) Received: by mail-lf1-x12e.google.com with SMTP id b18so3640462lfv.11 for ; Fri, 28 May 2021 17:25:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=khM8ENZRiO9GfrYZWjrb0BjgVR9cdtd9zq05AkI4UO4=; b=ZDBw+iBt/3RegQRJ6kZ2Bow9ygm56XgFbr1rxodRCeVpxPKIAB0TSIm8WMFbKfyokj f82cHgyaBSkgSjIoPcRfIOAFYNBhWbD3E96iZiYJmoaB025ZgomsZb/BK/4baPp2stMM H8rwtBAnqcAV8GhfWRTEpHmrUTg3Ifk5AMMtD266gbePuxZqdzBnZrguCTndviz5/qKH 0z85ln7LihtyR8t5dHNL9BrgyHnD4Z0JlX9wtnn5q9PaDofoLSlwxhweOK5z8d1ODRnS X0ehSo+O+AUrk0zDfigbjDWmp7Zjf+F8H03afbv5LXktBguoCedNLwD8pPthHodRIxcC Ij8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=khM8ENZRiO9GfrYZWjrb0BjgVR9cdtd9zq05AkI4UO4=; b=IGnK3zbj4+u0ku5uKvHOorl4kfVeTourkiQvpNYVWBWO8S+6+PXlPOExGaiOqN9GE3 pKod8py6W0pemS6Ct1hTQ3aIBbvGWBPrly9VQn7y6/Awk1KjO6bEJVil3Dxw3NWZnDIh oKwjSiBg0cjEN6ZnIAw4lBqTmsFzbx/x5HqJrYcilPrHOkPwl3kuBoEz4OBnHjWUi9EB KO0FILXvRs/4tB+y3Ys7Crc5B5sHfS0B/wyR7G/qAPSpI/SU1EsJr3KasCw5h+xEObKv bO9N2N5kOxIq0dh66B8SzGb7ZvPw7UjHEdC8mymZpMwrYg1iuHs8HBj2wkDjex2XVZ5i 3zmA== X-Gm-Message-State: AOAM532aHb/8DX6TZULbZkVg3nu/9Qko53MfcyOiav6IbwUlDx9bTCH2 EUGMutOFrk2U6GN7N40YZidY+Q== X-Received: by 2002:ac2:5fae:: with SMTP id s14mr8040712lfe.588.1622247919684; Fri, 28 May 2021 17:25:19 -0700 (PDT) Received: from eriador.lan ([37.153.55.125]) by smtp.gmail.com with ESMTPSA id c8sm701078ljd.82.2021.05.28.17.25.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 28 May 2021 17:25:19 -0700 (PDT) From: Dmitry Baryshkov To: Rob Clark , Sean Paul , Abhinav Kumar , Michael Turquette Cc: Jonathan Marek , Stephen Boyd , David Airlie , Daniel Vetter , linux-arm-msm@vger.kernel.org, dri-devel@lists.freedesktop.org, freedreno@lists.freedesktop.org Subject: [RFC 5/8] lib: add small API for handling register snapshots Date: Sat, 29 May 2021 03:25:05 +0300 Message-Id: <20210529002508.3839467-6-dmitry.baryshkov@linaro.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210529002508.3839467-1-dmitry.baryshkov@linaro.org> References: <20210529002508.3839467-1-dmitry.baryshkov@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org Add small API covering lists of register dumps. Currently this is a part of MSM DRM driver, but is extracted as it might be usefull to other drivers too. Signed-off-by: Dmitry Baryshkov --- include/linux/dump_state.h | 78 ++++++++++++++++++++++++++++++++++++++ lib/Kconfig | 3 ++ lib/Makefile | 1 + lib/dump_state.c | 51 +++++++++++++++++++++++++ 4 files changed, 133 insertions(+) create mode 100644 include/linux/dump_state.h create mode 100644 lib/dump_state.c -- 2.30.2 diff --git a/include/linux/dump_state.h b/include/linux/dump_state.h new file mode 100644 index 000000000000..9cf2cd2e99a6 --- /dev/null +++ b/include/linux/dump_state.h @@ -0,0 +1,78 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Copyright (c) 2020-2021, The Linux Foundation. All rights reserved. + * Copyright (c) 2021, Linaro Ltd + */ + +#ifndef LINUX_DUMP_STATE_H +#define LINUX_DUMP_STATE_H + +#include +#include + +/** + * struct dump_state_block - structure to store each hardware block state + * @name: name of the block + * @drm_dev: handle to the linked list head + * @size: size of the register space of this hardware block + * @state: array holding the register dump of this hardware block + * @base_addr: starting address of this hardware block's register space + */ +struct dump_state_block { + char name[SZ_128]; + struct list_head node; + void __iomem *base_addr; + size_t size; + u8 state[0] __aligned(8); +}; + +/** + * struct dump_state - structure to store reg dump state + * @blocks: hardware blocks info related to this dump state + */ +struct dump_state { + struct list_head blocks; +}; + +static inline void dump_state_init(struct dump_state *state) +{ + INIT_LIST_HEAD(&state->blocks); +} + +#define dump_state_for_each_block(state, block) \ + list_for_each_entry(block, &(state)->blocks, node) + +/** + * dump_state_free_blocks - free allocated blocks + * @state: handle to struct dump_state + */ +void dump_state_free_blocks(struct dump_state *state); + +/** + * dump_state_allocate_block - allocate data block for register dumps + * @len: size of the register space of the hardware block + * @base_addr: starting address of the register space of the hardware block + * @gfp: type of memory allocation + * @fmt: format in which the block names need to be printed + * + * Returns: new block + */ +extern __printf(4, 5) +struct dump_state_block *dump_state_allocate_block(void __iomem *base_addr, size_t len, gfp_t gfp, const char *fmt, ...); + +/** + * dump_state_allocate_block_va - allocate data block for register dumps + * @len: size of the register space of the hardware block + * @base_addr: starting address of the register space of the hardware block + * @gfp: type of memory allocation + * @fmt: format in which the block names need to be printed + * + * Returns: new block + */ +extern __printf(4, 0) +struct dump_state_block *dump_state_allocate_block_va(void __iomem *base_addr, size_t len, gfp_t gfp, const char *fmt, va_list args); + +#define dump_state_add_block(state, block) \ + list_add_tail(&(state)->blocks, &(block)->node) + +#endif diff --git a/lib/Kconfig b/lib/Kconfig index ac3b30697b2b..ab654232ecb6 100644 --- a/lib/Kconfig +++ b/lib/Kconfig @@ -704,3 +704,6 @@ config PLDMFW config ASN1_ENCODER tristate + +config DUMP_STATE + tristate diff --git a/lib/Makefile b/lib/Makefile index 2cc359ec1fdd..4836a0e3aef2 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -356,3 +356,4 @@ obj-$(CONFIG_BITS_TEST) += test_bits.o obj-$(CONFIG_CMDLINE_KUNIT_TEST) += cmdline_kunit.o obj-$(CONFIG_GENERIC_LIB_DEVMEM_IS_ALLOWED) += devmem_is_allowed.o +obj-$(CONFIG_DUMP_STATE) += dump_state.o diff --git a/lib/dump_state.c b/lib/dump_state.c new file mode 100644 index 000000000000..58d88be65c0a --- /dev/null +++ b/lib/dump_state.c @@ -0,0 +1,51 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Copyright (c) 2020-2021, The Linux Foundation. All rights reserved. + * Copyright (c) 2021, Linaro Ltd + */ + +#include +#include + +void dump_state_free_blocks(struct dump_state *state) +{ + struct dump_state_block *block, *tmp; + + list_for_each_entry_safe(block, tmp, &state->blocks, node) { + list_del(&block->node); + kfree(block); + } +} +EXPORT_SYMBOL(dump_state_free_blocks); + +struct dump_state_block *dump_state_allocate_block_va(void __iomem *base_addr, size_t len, gfp_t gfp, const char *fmt, va_list args) +{ + struct dump_state_block *block = kzalloc(sizeof(*block) + len, gfp); + + if (!block) + return ERR_PTR(-ENOMEM); + + vsnprintf(block->name, sizeof(block->name), fmt, args); + + INIT_LIST_HEAD(&block->node); + block->size = len; + block->base_addr = base_addr; + + return block; +} +EXPORT_SYMBOL(dump_state_allocate_block); + +struct dump_state_block *dump_state_allocate_block(void __iomem *base_addr, size_t len, gfp_t gfp, const char *fmt, ...) +{ + struct dump_state_block *block; + va_list va; + + va_start(va, fmt); + + block = dump_state_allocate_block_va(base_addr, len, gfp, fmt, va); + + va_end(va); + + return block; +} +EXPORT_SYMBOL(dump_state_allocate_block_va);