--- /dev/null +++ b/include/linux/crashlog.h @@ -0,0 +1,17 @@ +#ifndef __CRASHLOG_H +#define __CRASHLOG_H + +#ifdef CONFIG_CRASHLOG +void crashlog_init_bootmem(struct bootmem_data *bdata); +void crashlog_init_memblock(phys_addr_t addr, phys_addr_t size); +#else +static inline void crashlog_init_bootmem(struct bootmem_data *bdata) +{ +} + +static inline void crashlog_init_memblock(phys_addr_t addr, phys_addr_t size) +{ +} +#endif + +#endif --- a/init/Kconfig +++ b/init/Kconfig @@ -1186,6 +1186,10 @@ config RELAY If unsure, say N. +config CRASHLOG + bool "Crash logging" + depends on (!NO_BOOTMEM || HAVE_MEMBLOCK) && !(ARM || SPARC || PPC) + config BLK_DEV_INITRD bool "Initial RAM filesystem and RAM disk (initramfs/initrd) support" depends on BROKEN || !FRV --- a/kernel/Makefile +++ b/kernel/Makefile @@ -110,6 +110,7 @@ obj-$(CONFIG_PADATA) += padata.o obj-$(CONFIG_CRASH_DUMP) += crash_dump.o obj-$(CONFIG_JUMP_LABEL) += jump_label.o obj-$(CONFIG_CONTEXT_TRACKING) += context_tracking.o +obj-$(CONFIG_CRASHLOG) += crashlog.o $(obj)/configs.o: $(obj)/config_data.h --- /dev/null +++ b/kernel/crashlog.c @@ -0,0 +1,181 @@ +/* + * Crash information logger + * Copyright (C) 2010 Felix Fietkau + * + * Based on ramoops.c + * Copyright (C) 2010 Marco Stornelli + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * version 2 as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define CRASHLOG_PAGES 4 +#define CRASHLOG_SIZE (CRASHLOG_PAGES * PAGE_SIZE) +#define CRASHLOG_MAGIC 0xa1eedead + +/* + * Start the log at 1M before the end of RAM, as some boot loaders like + * to use the end of the RAM for stack usage and other things + * If this fails, fall back to using the last part. + */ +#define CRASHLOG_OFFSET (1024 * 1024) + +struct crashlog_data { + u32 magic; + u32 len; + u8 data[]; +}; + +static struct debugfs_blob_wrapper crashlog_blob; +static unsigned long crashlog_addr = 0; +static struct crashlog_data *crashlog_buf; +static struct kmsg_dumper dump; +static bool first = true; + +extern struct list_head *crashlog_modules; + +#ifndef CONFIG_NO_BOOTMEM +void __init crashlog_init_bootmem(bootmem_data_t *bdata) +{ + unsigned long addr; + + if (crashlog_addr) + return; + + addr = PFN_PHYS(bdata->node_low_pfn) - CRASHLOG_OFFSET; + if (reserve_bootmem(addr, CRASHLOG_SIZE, BOOTMEM_EXCLUSIVE) < 0) { + printk("Crashlog failed to allocate RAM at address 0x%lx\n", addr); + bdata->node_low_pfn -= CRASHLOG_PAGES; + addr = PFN_PHYS(bdata->node_low_pfn); + } + crashlog_addr = addr; +} +#endif + +#ifdef CONFIG_HAVE_MEMBLOCK +void __meminit crashlog_init_memblock(phys_addr_t addr, phys_addr_t size) +{ + if (crashlog_addr) + return; + + addr += size - CRASHLOG_OFFSET; + if (memblock_reserve(addr, CRASHLOG_SIZE)) { + printk("Crashlog failed to allocate RAM at address 0x%lx\n", (unsigned long) addr); + return; + } + + crashlog_addr = addr; +} +#endif + +static void __init crashlog_copy(void) +{ + if (crashlog_buf->magic != CRASHLOG_MAGIC) + return; + + if (!crashlog_buf->len || crashlog_buf->len > + CRASHLOG_SIZE - sizeof(*crashlog_buf)) + return; + + crashlog_blob.size = crashlog_buf->len; + crashlog_blob.data = kmemdup(crashlog_buf->data, + crashlog_buf->len, GFP_KERNEL); + + debugfs_create_blob("crashlog", 0700, NULL, &crashlog_blob); +} + +static int get_maxlen(void) +{ + return CRASHLOG_SIZE - sizeof(*crashlog_buf) - crashlog_buf->len; +} + +static void crashlog_printf(const char *fmt, ...) +{ + va_list args; + int len = get_maxlen(); + + if (!len) + return; + + va_start(args, fmt); + crashlog_buf->len += vscnprintf( + &crashlog_buf->data[crashlog_buf->len], + len, fmt, args); + va_end(args); +} + +static void crashlog_do_dump(struct kmsg_dumper *dumper, + enum kmsg_dump_reason reason) +{ + struct timeval tv; + struct module *m; + char *buf; + size_t len; + + if (!first) + crashlog_printf("\n===================================\n"); + + do_gettimeofday(&tv); + crashlog_printf("Time: %lu.%lu\n", + (long)tv.tv_sec, (long)tv.tv_usec); + + if (first) { + crashlog_printf("Modules:"); + list_for_each_entry(m, crashlog_modules, list) { + crashlog_printf("\t%s@%p+%x", m->name, + m->module_core, m->core_size, + m->module_init, m->init_size); + } + crashlog_printf("\n"); + first = false; + } + + buf = (char *)&crashlog_buf->data[crashlog_buf->len]; + + kmsg_dump_get_buffer(dumper, true, buf, get_maxlen(), &len); + + crashlog_buf->len += len; +} + + +int __init crashlog_init_fs(void) +{ + if (!crashlog_addr) + return -ENOMEM; + + crashlog_buf = ioremap(crashlog_addr, CRASHLOG_SIZE); + + crashlog_copy(); + + crashlog_buf->magic = CRASHLOG_MAGIC; + crashlog_buf->len = 0; + + dump.max_reason = KMSG_DUMP_OOPS; + dump.dump = crashlog_do_dump; + kmsg_dump_register(&dump); + + return 0; +} +module_init(crashlog_init_fs); --- a/mm/bootmem.c +++ b/mm/bootmem.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include @@ -177,6 +178,7 @@ static unsigned long __init free_all_boo if (!bdata->node_bootmem_map) return 0; + crashlog_init_bootmem(bdata); start = bdata->node_min_pfn; end = bdata->node_low_pfn; --- a/kernel/module.c +++ b/kernel/module.c @@ -106,6 +106,9 @@ static LIST_HEAD(modules); #ifdef CONFIG_KGDB_KDB struct list_head *kdb_modules = &modules; /* kdb needs the list of modules */ #endif /* CONFIG_KGDB_KDB */ +#ifdef CONFIG_CRASHLOG +struct list_head *crashlog_modules = &modules; +#endif #ifdef CONFIG_MODULE_SIG #ifdef CONFIG_MODULE_SIG_FORCE --- a/mm/memblock.c +++ b/mm/memblock.c @@ -19,6 +19,7 @@ #include #include #include +#include static struct memblock_region memblock_memory_init_regions[INIT_MEMBLOCK_REGIONS] __initdata_memblock; static struct memblock_region memblock_reserved_init_regions[INIT_MEMBLOCK_REGIONS] __initdata_memblock; @@ -344,6 +345,8 @@ static void __init_memblock memblock_ins memblock_set_region_node(rgn, nid); type->cnt++; type->total_size += size; + if (type == &memblock.memory && idx == 0) + crashlog_init_memblock(base, size); } /** >82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160
From patchwork Fri Dec  8 09:42:28 2017
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Subject: [v4,10/12] clk: qcom: Add safe switch hook for krait mux clocks
From: Sricharan R <sricharan@codeaurora.org>
X-Patchwork-Id: 10102057
Message-Id: <1512726150-7204-11-git-send-email-sricharan@codeaurora.org>
To: mturquette@baylibre.com, sboyd@codeaurora.org,
 devicetree@vger.kernel.org, linux-pm@vger.kernel.org,
 linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org,
 viresh.kumar@linaro.org, linux-arm-kernel@lists.infradead.org
Cc: sricharan@codeaurora.org
Date: Fri,  8 Dec 2017 15:12:28 +0530

When the Hfplls are reprogrammed during the rate change,
the primary muxes which are sourced from the same hfpll
for higher frequencies, needs to be switched to the 'safe
secondary mux' as the parent for that small window. This
is done by registering a clk notifier for the muxes and
switching to the safe parent in the PRE_RATE_CHANGE notifier
and back to the original parent in the POST_RATE_CHANGE notifier.

Signed-off-by: Sricharan R <sricharan@codeaurora.org>
---
 drivers/clk/qcom/clk-krait.c |  2 ++
 drivers/clk/qcom/clk-krait.h |  3 +++
 drivers/clk/qcom/krait-cc.c  | 56 ++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 61 insertions(+)

--- a/drivers/clk/qcom/clk-krait.c
+++ b/drivers/clk/qcom/clk-krait.c
@@ -60,6 +60,8 @@ static int krait_mux_set_parent(struct c
 	if (__clk_is_enabled(hw->clk))
 		__krait_mux_set_sel(mux, sel);
 
+	mux->reparent = true;
+
 	return 0;
 }
 
--- a/drivers/clk/qcom/clk-krait.h
+++ b/drivers/clk/qcom/clk-krait.h
@@ -23,6 +23,9 @@ struct krait_mux_clk {
 	u32		shift;
 	u32		en_mask;
 	bool		lpl;
+	u8		safe_sel;
+	u8		old_index;
+	bool		reparent;
 
 	struct clk_hw	hw;
 	struct notifier_block   clk_nb;
--- a/drivers/clk/qcom/krait-cc.c
+++ b/drivers/clk/qcom/krait-cc.c
@@ -35,6 +35,49 @@ static unsigned int pri_mux_map[] = {
 	0,
 };
 
+/*
+ * Notifier function for switching the muxes to safe parent
+ * while the hfpll is getting reprogrammed.
+ */
+static int krait_notifier_cb(struct notifier_block *nb,
+			     unsigned long event,
+			     void *data)
+{
+	int ret = 0;
+	struct krait_mux_clk *mux = container_of(nb, struct krait_mux_clk,
+						 clk_nb);
+	/* Switch to safe parent */
+	if (event == PRE_RATE_CHANGE) {
+		mux->old_index = krait_mux_clk_ops.get_parent(&mux->hw);
+		ret = krait_mux_clk_ops.set_parent(&mux->hw, mux->safe_sel);
+		mux->reparent = false;
+	/*
+	 * By the time POST_RATE_CHANGE notifier is called,
+	 * clk framework itself would have changed the parent for the new rate.
+	 * Only otherwise, put back to the old parent.
+	 */
+	} else if (event == POST_RATE_CHANGE) {
+		if (!mux->reparent)
+			ret = krait_mux_clk_ops.set_parent(&mux->hw,
+							   mux->old_index);
+	}
+
+	return notifier_from_errno(ret);
+}
+
+static int krait_notifier_register(struct device *dev, struct clk *clk,
+				   struct krait_mux_clk *mux)
+{
+	int ret = 0;
+
+	mux->clk_nb.notifier_call = krait_notifier_cb;
+	ret = clk_notifier_register(clk, &mux->clk_nb);
+	if (ret)
+		dev_err(dev, "failed to register clock notifier: %d\n", ret);
+
+	return ret;
+}
+
 static int
 krait_add_div(struct device *dev, int id, const char *s, unsigned int offset)
 {
@@ -79,6 +122,7 @@ static int
 krait_add_sec_mux(struct device *dev, int id, const char *s,
 		  unsigned int offset, bool unique_aux)
 {
+	int ret;
 	struct krait_mux_clk *mux;
 	static const char *sec_mux_list[] = {
 		"acpu_aux",
@@ -102,6 +146,7 @@ krait_add_sec_mux(struct device *dev, in
 	mux->shift = 2;
 	mux->parent_map = sec_mux_map;
 	mux->hw.init = &init;
+	mux->safe_sel = 0;
 
 	init.name = kasprintf(GFP_KERNEL, "krait%s_sec_mux", s);
 	if (!init.name)
@@ -117,6 +162,11 @@ krait_add_sec_mux(struct device *dev, in
 
 	clk = devm_clk_register(dev, &mux->hw);
 
+	ret = krait_notifier_register(dev, clk, mux);
+	if (ret)
+		goto unique_aux;
+
+unique_aux:
 	if (unique_aux)
 		kfree(sec_mux_list[0]);
 err_aux:
@@ -128,6 +178,7 @@ static struct clk *
 krait_add_pri_mux(struct device *dev, int id, const char *s,
 		  unsigned int offset)
 {
+	int ret;
 	struct krait_mux_clk *mux;
 	const char *p_names[3];
 	struct clk_init_data init = {
@@ -148,6 +199,7 @@ krait_add_pri_mux(struct device *dev, in
 	mux->lpl = id >= 0;
 	mux->parent_map = pri_mux_map;
 	mux->hw.init = &init;
+	mux->safe_sel = 2;
 
 	init.name = kasprintf(GFP_KERNEL, "krait%s_pri_mux", s);
 	if (!init.name)
@@ -173,6 +225,10 @@ krait_add_pri_mux(struct device *dev, in
 
 	clk = devm_clk_register(dev, &mux->hw);
 
+	ret = krait_notifier_register(dev, clk, mux);
+	if (ret)
+		goto err_p3;
+err_p3:
 	kfree(p_names[2]);
 err_p2:
 	kfree(p_names[1]);