2023-06-09 02:26:32

by Max Filippov

[permalink] [raw]
Subject: [PATCH 0/5] xtensa: clean up platform interface

Hello,

this series drops platform_* interfaces that lost their meaning or got a
different standard implementation and cleans up existing users and
default definitions.

Max Filippov (5):
xtensa: xt2000: drop empty platform_init
xtensa: drop platform_heartbeat
xtensa: drop platform_restart
xtensa: drop platform_halt and platform_power_off
xtensa: clean up default platform functions

arch/xtensa/include/asm/platform.h | 20 ------------
arch/xtensa/kernel/platform.c | 29 +++++++++--------
arch/xtensa/kernel/setup.c | 22 ++++++++++---
arch/xtensa/kernel/time.c | 4 ---
arch/xtensa/platforms/iss/setup.c | 24 ++++++++------
arch/xtensa/platforms/xt2000/setup.c | 48 ++++++++++++++--------------
arch/xtensa/platforms/xtfpga/setup.c | 34 +++++++++++++-------
7 files changed, 94 insertions(+), 87 deletions(-)

--
2.30.2



2023-06-09 02:30:23

by Max Filippov

[permalink] [raw]
Subject: [PATCH 5/5] xtensa: clean up default platform functions

Drop _F macro used to define default platform functions and rewrite
definitions as normal functions. Don't define separate __platform_*
function and platform_* weak alias, just define a weak function.

Signed-off-by: Max Filippov <[email protected]>
---
arch/xtensa/kernel/platform.c | 25 +++++++++++++++----------
1 file changed, 15 insertions(+), 10 deletions(-)

diff --git a/arch/xtensa/kernel/platform.c b/arch/xtensa/kernel/platform.c
index 29fa5d659274..926b8bf0f14c 100644
--- a/arch/xtensa/kernel/platform.c
+++ b/arch/xtensa/kernel/platform.c
@@ -17,23 +17,28 @@
#include <asm/platform.h>
#include <asm/timex.h>

-#define _F(r,f,a,b) \
- r __platform_##f a b; \
- r platform_##f a __attribute__((weak, alias("__platform_"#f)))
-
/*
* Default functions that are used if no platform specific function is defined.
- * (Please, refer to include/asm-xtensa/platform.h for more information)
+ * (Please, refer to arch/xtensa/include/asm/platform.h for more information)
*/

-_F(void, init, (bp_tag_t *first), { });
-_F(void, setup, (char** cmd), { });
-_F(void, idle, (void), { __asm__ __volatile__ ("waiti 0" ::: "memory"); });
+void __weak __init platform_init(bp_tag_t *first)
+{
+}
+
+void __weak __init platform_setup(char **cmd)
+{
+}
+
+void __weak platform_idle(void)
+{
+ __asm__ __volatile__ ("waiti 0" ::: "memory");
+}

#ifdef CONFIG_XTENSA_CALIBRATE_CCOUNT
-_F(void, calibrate_ccount, (void),
+void __weak platform_calibrate_ccount(void)
{
pr_err("ERROR: Cannot calibrate cpu frequency! Assuming 10MHz.\n");
ccount_freq = 10 * 1000000UL;
-});
+}
#endif
--
2.30.2


2023-06-09 02:32:32

by Max Filippov

[permalink] [raw]
Subject: [PATCH 4/5] xtensa: drop platform_halt and platform_power_off

Instead of using xtensa-specific platform_halt and platform_power_off
callbacks use do_kernel_power_off in the machine_halt and
machine_power_off and reimplement existing platform_halt and
platform_power_off users with register_sys_off_handler.

Drop platform_halt and platform_power_off declarations and default
implementations.

Signed-off-by: Max Filippov <[email protected]>
---
arch/xtensa/include/asm/platform.h | 10 ----------
arch/xtensa/kernel/platform.c | 2 --
arch/xtensa/kernel/setup.c | 14 ++++++++++----
arch/xtensa/platforms/iss/setup.c | 12 +++++-------
arch/xtensa/platforms/xt2000/setup.c | 13 +++++--------
arch/xtensa/platforms/xtfpga/setup.c | 14 +++++---------
6 files changed, 25 insertions(+), 40 deletions(-)

diff --git a/arch/xtensa/include/asm/platform.h b/arch/xtensa/include/asm/platform.h
index 5b3c1f96f7b5..94f13fabf7cd 100644
--- a/arch/xtensa/include/asm/platform.h
+++ b/arch/xtensa/include/asm/platform.h
@@ -27,16 +27,6 @@ extern void platform_init(bp_tag_t*);
*/
extern void platform_setup (char **);

-/*
- * platform_halt is called to stop the system and halt.
- */
-extern void platform_halt (void);
-
-/*
- * platform_power_off is called to stop the system and power it off.
- */
-extern void platform_power_off (void);
-
/*
* platform_idle is called from the idle function.
*/
diff --git a/arch/xtensa/kernel/platform.c b/arch/xtensa/kernel/platform.c
index 526ab744271f..29fa5d659274 100644
--- a/arch/xtensa/kernel/platform.c
+++ b/arch/xtensa/kernel/platform.c
@@ -28,8 +28,6 @@

_F(void, init, (bp_tag_t *first), { });
_F(void, setup, (char** cmd), { });
-_F(void, halt, (void), { while(1); });
-_F(void, power_off, (void), { while(1); });
_F(void, idle, (void), { __asm__ __volatile__ ("waiti 0" ::: "memory"); });

#ifdef CONFIG_XTENSA_CALIBRATE_CCOUNT
diff --git a/arch/xtensa/kernel/setup.c b/arch/xtensa/kernel/setup.c
index 8f72039335c2..5680391d7e35 100644
--- a/arch/xtensa/kernel/setup.c
+++ b/arch/xtensa/kernel/setup.c
@@ -533,14 +533,20 @@ void machine_restart(char * cmd)

void machine_halt(void)
{
- platform_halt();
- while (1);
+ local_irq_disable();
+ smp_send_stop();
+ do_kernel_power_off();
+ while (1)
+ cpu_relax();
}

void machine_power_off(void)
{
- platform_power_off();
- while (1);
+ local_irq_disable();
+ smp_send_stop();
+ do_kernel_power_off();
+ while (1)
+ cpu_relax();
}
#ifdef CONFIG_PROC_FS

diff --git a/arch/xtensa/platforms/iss/setup.c b/arch/xtensa/platforms/iss/setup.c
index a7009f223ef2..0f1fe132691e 100644
--- a/arch/xtensa/platforms/iss/setup.c
+++ b/arch/xtensa/platforms/iss/setup.c
@@ -25,16 +25,11 @@
#include <platform/simcall.h>


-void platform_halt(void)
-{
- pr_info(" ** Called platform_halt() **\n");
- simc_exit(0);
-}
-
-void platform_power_off(void)
+static int iss_power_off(struct sys_off_data *unused)
{
pr_info(" ** Called platform_power_off() **\n");
simc_exit(0);
+ return NOTIFY_DONE;
}

static int iss_restart(struct notifier_block *this,
@@ -90,4 +85,7 @@ void __init platform_setup(char **p_cmdline)

atomic_notifier_chain_register(&panic_notifier_list, &iss_panic_block);
register_restart_handler(&iss_restart_block);
+ register_sys_off_handler(SYS_OFF_MODE_POWER_OFF,
+ SYS_OFF_PRIO_PLATFORM,
+ iss_power_off, NULL);
}
diff --git a/arch/xtensa/platforms/xt2000/setup.c b/arch/xtensa/platforms/xt2000/setup.c
index 71b57ab50599..258e01a51fd8 100644
--- a/arch/xtensa/platforms/xt2000/setup.c
+++ b/arch/xtensa/platforms/xt2000/setup.c
@@ -42,18 +42,12 @@ static void led_print (int f, char *s)
break;
}

-void platform_halt(void)
-{
- led_print (0, " HALT ");
- local_irq_disable();
- while (1);
-}
-
-void platform_power_off(void)
+static int xt2000_power_off(struct sys_off_data *unused)
{
led_print (0, "POWEROFF");
local_irq_disable();
while (1);
+ return NOTIFY_DONE;
}

static int xt2000_restart(struct notifier_block *this,
@@ -147,6 +141,9 @@ static int __init xt2000_setup_devinit(void)
platform_device_register(&xt2000_sonic_device);
mod_timer(&heartbeat_timer, jiffies + HZ / 2);
register_restart_handler(&xt2000_restart_block);
+ register_sys_off_handler(SYS_OFF_MODE_POWER_OFF,
+ SYS_OFF_PRIO_DEFAULT,
+ xt2000_power_off, NULL);
return 0;
}

diff --git a/arch/xtensa/platforms/xtfpga/setup.c b/arch/xtensa/platforms/xtfpga/setup.c
index 1690232c003e..a2432f081710 100644
--- a/arch/xtensa/platforms/xtfpga/setup.c
+++ b/arch/xtensa/platforms/xtfpga/setup.c
@@ -33,20 +33,13 @@
#include <platform/lcd.h>
#include <platform/hardware.h>

-void platform_halt(void)
-{
- lcd_disp_at_pos(" HALT ", 0);
- local_irq_disable();
- while (1)
- cpu_relax();
-}
-
-void platform_power_off(void)
+static int xtfpga_power_off(struct sys_off_data *unused)
{
lcd_disp_at_pos("POWEROFF", 0);
local_irq_disable();
while (1)
cpu_relax();
+ return NOTIFY_DONE;
}

static int xtfpga_restart(struct notifier_block *this,
@@ -79,6 +72,9 @@ void __init platform_calibrate_ccount(void)
static void __init xtfpga_register_handlers(void)
{
register_restart_handler(&xtfpga_restart_block);
+ register_sys_off_handler(SYS_OFF_MODE_POWER_OFF,
+ SYS_OFF_PRIO_DEFAULT,
+ xtfpga_power_off, NULL);
}

#ifdef CONFIG_USE_OF
--
2.30.2


2023-06-09 02:33:30

by Max Filippov

[permalink] [raw]
Subject: [PATCH 3/5] xtensa: drop platform_restart

Instead of using xtensa-specific platform_restart callback use
do_kernel_restart in the machine_restart implementation and reimplement
existing platform_restart users with register_restart_handler.
Drop platform_restart declaration and default implementation.

Signed-off-by: Max Filippov <[email protected]>
---
arch/xtensa/include/asm/platform.h | 5 -----
arch/xtensa/kernel/platform.c | 1 -
arch/xtensa/kernel/setup.c | 8 +++++++-
arch/xtensa/platforms/iss/setup.c | 12 ++++++++++--
arch/xtensa/platforms/xt2000/setup.c | 11 +++++++++--
arch/xtensa/platforms/xtfpga/setup.c | 20 ++++++++++++++++++--
6 files changed, 44 insertions(+), 13 deletions(-)

diff --git a/arch/xtensa/include/asm/platform.h b/arch/xtensa/include/asm/platform.h
index 3be6b4bf9763..5b3c1f96f7b5 100644
--- a/arch/xtensa/include/asm/platform.h
+++ b/arch/xtensa/include/asm/platform.h
@@ -27,11 +27,6 @@ extern void platform_init(bp_tag_t*);
*/
extern void platform_setup (char **);

-/*
- * platform_restart is called to restart the system.
- */
-extern void platform_restart (void);
-
/*
* platform_halt is called to stop the system and halt.
*/
diff --git a/arch/xtensa/kernel/platform.c b/arch/xtensa/kernel/platform.c
index bb4d426ebb44..526ab744271f 100644
--- a/arch/xtensa/kernel/platform.c
+++ b/arch/xtensa/kernel/platform.c
@@ -28,7 +28,6 @@

_F(void, init, (bp_tag_t *first), { });
_F(void, setup, (char** cmd), { });
-_F(void, restart, (void), { while(1); });
_F(void, halt, (void), { while(1); });
_F(void, power_off, (void), { while(1); });
_F(void, idle, (void), { __asm__ __volatile__ ("waiti 0" ::: "memory"); });
diff --git a/arch/xtensa/kernel/setup.c b/arch/xtensa/kernel/setup.c
index 9191738f9941..8f72039335c2 100644
--- a/arch/xtensa/kernel/setup.c
+++ b/arch/xtensa/kernel/setup.c
@@ -22,6 +22,7 @@
#include <linux/screen_info.h>
#include <linux/kernel.h>
#include <linux/percpu.h>
+#include <linux/reboot.h>
#include <linux/cpu.h>
#include <linux/of.h>
#include <linux/of_fdt.h>
@@ -522,7 +523,12 @@ void cpu_reset(void)

void machine_restart(char * cmd)
{
- platform_restart();
+ local_irq_disable();
+ smp_send_stop();
+ do_kernel_restart(cmd);
+ pr_err("Reboot failed -- System halted\n");
+ while (1)
+ cpu_relax();
}

void machine_halt(void)
diff --git a/arch/xtensa/platforms/iss/setup.c b/arch/xtensa/platforms/iss/setup.c
index d3433e1bb94e..a7009f223ef2 100644
--- a/arch/xtensa/platforms/iss/setup.c
+++ b/arch/xtensa/platforms/iss/setup.c
@@ -16,6 +16,7 @@
#include <linux/notifier.h>
#include <linux/panic_notifier.h>
#include <linux/printk.h>
+#include <linux/reboot.h>
#include <linux/string.h>

#include <asm/platform.h>
@@ -36,14 +37,20 @@ void platform_power_off(void)
simc_exit(0);
}

-void platform_restart(void)
+static int iss_restart(struct notifier_block *this,
+ unsigned long event, void *ptr)
{
/* Flush and reset the mmu, simulate a processor reset, and
* jump to the reset vector. */
cpu_reset();
- /* control never gets here */
+
+ return NOTIFY_DONE;
}

+static struct notifier_block iss_restart_block = {
+ .notifier_call = iss_restart,
+};
+
static int
iss_panic_event(struct notifier_block *this, unsigned long event, void *ptr)
{
@@ -82,4 +89,5 @@ void __init platform_setup(char **p_cmdline)
}

atomic_notifier_chain_register(&panic_notifier_list, &iss_panic_block);
+ register_restart_handler(&iss_restart_block);
}
diff --git a/arch/xtensa/platforms/xt2000/setup.c b/arch/xtensa/platforms/xt2000/setup.c
index dc187684203b..71b57ab50599 100644
--- a/arch/xtensa/platforms/xt2000/setup.c
+++ b/arch/xtensa/platforms/xt2000/setup.c
@@ -56,14 +56,20 @@ void platform_power_off(void)
while (1);
}

-void platform_restart(void)
+static int xt2000_restart(struct notifier_block *this,
+ unsigned long event, void *ptr)
{
/* Flush and reset the mmu, simulate a processor reset, and
* jump to the reset vector. */
cpu_reset();
- /* control never gets here */
+
+ return NOTIFY_DONE;
}

+static struct notifier_block xt2000_restart_block = {
+ .notifier_call = xt2000_restart,
+};
+
void __init platform_setup(char** cmdline)
{
led_print (0, "LINUX ");
@@ -140,6 +146,7 @@ static int __init xt2000_setup_devinit(void)
platform_device_register(&xt2000_serial8250_device);
platform_device_register(&xt2000_sonic_device);
mod_timer(&heartbeat_timer, jiffies + HZ / 2);
+ register_restart_handler(&xt2000_restart_block);
return 0;
}

diff --git a/arch/xtensa/platforms/xtfpga/setup.c b/arch/xtensa/platforms/xtfpga/setup.c
index c79c1d09ea86..1690232c003e 100644
--- a/arch/xtensa/platforms/xtfpga/setup.c
+++ b/arch/xtensa/platforms/xtfpga/setup.c
@@ -49,7 +49,8 @@ void platform_power_off(void)
cpu_relax();
}

-void platform_restart(void)
+static int xtfpga_restart(struct notifier_block *this,
+ unsigned long event, void *ptr)
{
/* Try software reset first. */
WRITE_ONCE(*(u32 *)XTFPGA_SWRST_VADDR, 0xdead);
@@ -58,9 +59,14 @@ void platform_restart(void)
* simulate a processor reset, and jump to the reset vector.
*/
cpu_reset();
- /* control never gets here */
+
+ return NOTIFY_DONE;
}

+static struct notifier_block xtfpga_restart_block = {
+ .notifier_call = xtfpga_restart,
+};
+
#ifdef CONFIG_XTENSA_CALIBRATE_CCOUNT

void __init platform_calibrate_ccount(void)
@@ -70,6 +76,11 @@ void __init platform_calibrate_ccount(void)

#endif

+static void __init xtfpga_register_handlers(void)
+{
+ register_restart_handler(&xtfpga_restart_block);
+}
+
#ifdef CONFIG_USE_OF

static void __init xtfpga_clk_setup(struct device_node *np)
@@ -134,6 +145,9 @@ static int __init machine_setup(void)
if ((eth = of_find_compatible_node(eth, NULL, "opencores,ethoc")))
update_local_mac(eth);
of_node_put(eth);
+
+ xtfpga_register_handlers();
+
return 0;
}
arch_initcall(machine_setup);
@@ -281,6 +295,8 @@ static int __init xtavnet_init(void)
pr_info("XTFPGA: Ethernet MAC %pM\n", ethoc_pdata.hwaddr);
ethoc_pdata.eth_clkfreq = *(long *)XTFPGA_CLKFRQ_VADDR;

+ xtfpga_register_handlers();
+
return 0;
}

--
2.30.2


2023-06-09 02:35:11

by Max Filippov

[permalink] [raw]
Subject: [PATCH 1/5] xtensa: xt2000: drop empty platform_init

platform_init doesn't do anything for xt2000, drop it.

Signed-off-by: Max Filippov <[email protected]>
---
arch/xtensa/platforms/xt2000/setup.c | 6 ------
1 file changed, 6 deletions(-)

diff --git a/arch/xtensa/platforms/xt2000/setup.c b/arch/xtensa/platforms/xt2000/setup.c
index 0dc22c371614..08bc9b0ede3e 100644
--- a/arch/xtensa/platforms/xt2000/setup.c
+++ b/arch/xtensa/platforms/xt2000/setup.c
@@ -68,12 +68,6 @@ void __init platform_setup(char** cmdline)
led_print (0, "LINUX ");
}

-/* early initialization */
-
-void __init platform_init(bp_tag_t *first)
-{
-}
-
/* Heartbeat. Let the LED blink. */

void platform_heartbeat(void)
--
2.30.2


2023-06-09 02:55:24

by Max Filippov

[permalink] [raw]
Subject: [PATCH 2/5] xtensa: drop platform_heartbeat

platform_heartbeat is called from the timer interrupt handler, but
there may be no periodic timer interrupts on xtensa, so the frequency of
platform_heartbeat calls may be unrelated to HZ. Drop the callback and
reimplement its only user with a timer.

Signed-off-by: Max Filippov <[email protected]>
---
arch/xtensa/include/asm/platform.h | 5 -----
arch/xtensa/kernel/platform.c | 1 -
arch/xtensa/kernel/time.c | 4 ----
arch/xtensa/platforms/xt2000/setup.c | 20 +++++++++++---------
4 files changed, 11 insertions(+), 19 deletions(-)

diff --git a/arch/xtensa/include/asm/platform.h b/arch/xtensa/include/asm/platform.h
index 354ca942de40..3be6b4bf9763 100644
--- a/arch/xtensa/include/asm/platform.h
+++ b/arch/xtensa/include/asm/platform.h
@@ -47,11 +47,6 @@ extern void platform_power_off (void);
*/
extern void platform_idle (void);

-/*
- * platform_heartbeat is called every HZ
- */
-extern void platform_heartbeat (void);
-
/*
* platform_calibrate_ccount calibrates cpu clock freq (CONFIG_XTENSA_CALIBRATE)
*/
diff --git a/arch/xtensa/kernel/platform.c b/arch/xtensa/kernel/platform.c
index ac1e0e566995..bb4d426ebb44 100644
--- a/arch/xtensa/kernel/platform.c
+++ b/arch/xtensa/kernel/platform.c
@@ -32,7 +32,6 @@ _F(void, restart, (void), { while(1); });
_F(void, halt, (void), { while(1); });
_F(void, power_off, (void), { while(1); });
_F(void, idle, (void), { __asm__ __volatile__ ("waiti 0" ::: "memory"); });
-_F(void, heartbeat, (void), { });

#ifdef CONFIG_XTENSA_CALIBRATE_CCOUNT
_F(void, calibrate_ccount, (void),
diff --git a/arch/xtensa/kernel/time.c b/arch/xtensa/kernel/time.c
index 16b8a6273772..1c3dfea843ec 100644
--- a/arch/xtensa/kernel/time.c
+++ b/arch/xtensa/kernel/time.c
@@ -121,10 +121,6 @@ static irqreturn_t timer_interrupt(int irq, void *dev_id)

set_linux_timer(get_linux_timer());
evt->event_handler(evt);
-
- /* Allow platform to do something useful (Wdog). */
- platform_heartbeat();
-
return IRQ_HANDLED;
}

diff --git a/arch/xtensa/platforms/xt2000/setup.c b/arch/xtensa/platforms/xt2000/setup.c
index 08bc9b0ede3e..dc187684203b 100644
--- a/arch/xtensa/platforms/xt2000/setup.c
+++ b/arch/xtensa/platforms/xt2000/setup.c
@@ -23,6 +23,7 @@
#include <linux/platform_device.h>
#include <linux/serial.h>
#include <linux/serial_8250.h>
+#include <linux/timer.h>

#include <asm/processor.h>
#include <asm/platform.h>
@@ -70,16 +71,17 @@ void __init platform_setup(char** cmdline)

/* Heartbeat. Let the LED blink. */

-void platform_heartbeat(void)
+static void xt2000_heartbeat(struct timer_list *unused);
+
+static DEFINE_TIMER(heartbeat_timer, xt2000_heartbeat);
+
+static void xt2000_heartbeat(struct timer_list *unused)
{
- static int i, t;
+ static int i;

- if (--t < 0)
- {
- t = 59;
- led_print(7, i ? ".": " ");
- i ^= 1;
- }
+ led_print(7, i ? "." : " ");
+ i ^= 1;
+ mod_timer(&heartbeat_timer, jiffies + HZ / 2);
}

//#define RS_TABLE_SIZE 2
@@ -137,7 +139,7 @@ static int __init xt2000_setup_devinit(void)
{
platform_device_register(&xt2000_serial8250_device);
platform_device_register(&xt2000_sonic_device);
-
+ mod_timer(&heartbeat_timer, jiffies + HZ / 2);
return 0;
}

--
2.30.2