Skip to contentSkip to conversation

nios2: convert nios2 cpu to driver model

PATCH Superseded Thomas Chou 4 participants 13 messages Sep 28, 2015 – Oct 4, 2015 NIOS2 architecture

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 nios2: convert nios2 cpu to driver model

Convert nios2 cpu to driver model. The cpu parameters are extracted from device tree and saved to global data structure. We will use them to replace the custom_fpga.h .

---
 arch/Kconfig                         |  3 ++
 arch/nios2/cpu/cpu.c                 | 80 ++++++++++++++++++++++++++++++++++--
 arch/nios2/dts/3c120_devboard.dts    |  1 +
 arch/nios2/include/asm/global_data.h |  8 ++++
 configs/nios2-generic_defconfig      |  2 -
 5 files changed, 89 insertions(+), 5 deletions(-)
arch/Kconfig +3 -0
index 207c778..9be1538 100644
@@ -64,6 +64,9 @@ config NIOS2
 	select HAVE_GENERIC_BOARD
 	select SYS_GENERIC_BOARD
 	select SUPPORT_OF_CONTROL
+	select OF_CONTROL
+	select DM
+	select CPU
 
 config OPENRISC
 	bool "OpenRISC architecture"
arch/nios2/cpu/cpu.c +77 -3

94 lines not on this page · raw message

arch/nios2/dts/3c120_devboard.dts +1 -0
index 781a652..2e2956f 100644
@@ -41,6 +41,7 @@
 			altr,exception-addr = <0xd0000020>;
 			altr,has-initda = <1>;
 			altr,has-mmu = <1>;
+			u-boot,dm-pre-reloc;
 		};
 	};
 
arch/nios2/include/asm/global_data.h +8 -0
index 580b019..ee5180b 100644
@@ -9,6 +9,14 @@
 
 /* Architecture-specific global data */
 struct arch_global_data {
+	u32 dcache_line_size;
+	u32 icache_line_size;
+	u32 dcache_size;
+	u32 icache_size;
+	u32 reset_addr;
+	u32 exception_addr;
+	int has_mmu;
+	u32 io_region_base;
 };
 
 #include <asm-generic/global_data.h>
configs/nios2-generic_defconfig +0 -2
index ad72272..63d99d8 100644
@@ -13,9 +13,7 @@ CONFIG_HUSH_PARSER=y
 CONFIG_CMD_DHCP=y
 # CONFIG_CMD_NFS is not set
 CONFIG_CMD_PING=y
-CONFIG_OF_CONTROL=y
 CONFIG_NET_RANDOM_ETHADDR=y
-CONFIG_DM=y
 CONFIG_ALTERA_PIO=y
 CONFIG_ALTERA_JTAG_UART=y
 CONFIG_ALTERA_JTAG_UART_BYPASS=y
Signature · 1 line
2.1.4
#1 lore raw

PATCH v2 1/1 nios2: convert nios2 cpu to driver model

Convert nios2 cpu to driver model. The cpu parameters are extracted from device tree and saved to global data structure. We will use them to replace the custom_fpga.h .

---
v2
move cpu param setup to arch_cpu_init_dm, remove probe.

 arch/Kconfig                         |  3 ++
 arch/nios2/cpu/cpu.c                 | 76 ++++++++++++++++++++++++++++++++++--
 arch/nios2/dts/3c120_devboard.dts    |  1 +
 arch/nios2/include/asm/global_data.h |  8 ++++
 configs/nios2-generic_defconfig      |  2 -
 5 files changed, 85 insertions(+), 5 deletions(-)
arch/Kconfig +3 -0
index 207c778..9be1538 100644
@@ -64,6 +64,9 @@ config NIOS2
 	select HAVE_GENERIC_BOARD
 	select SYS_GENERIC_BOARD
 	select SUPPORT_OF_CONTROL
+	select OF_CONTROL
+	select DM
+	select CPU
 
 config OPENRISC
 	bool "OpenRISC architecture"
arch/nios2/cpu/cpu.c +73 -3

90 lines not on this page · raw message

arch/nios2/dts/3c120_devboard.dts +1 -0
index 781a652..2e2956f 100644
@@ -41,6 +41,7 @@
 			altr,exception-addr = <0xd0000020>;
 			altr,has-initda = <1>;
 			altr,has-mmu = <1>;
+			u-boot,dm-pre-reloc;
 		};
 	};
 
arch/nios2/include/asm/global_data.h +8 -0
index 580b019..ee5180b 100644
@@ -9,6 +9,14 @@
 
 /* Architecture-specific global data */
 struct arch_global_data {
+	u32 dcache_line_size;
+	u32 icache_line_size;
+	u32 dcache_size;
+	u32 icache_size;
+	u32 reset_addr;
+	u32 exception_addr;
+	int has_mmu;
+	u32 io_region_base;
 };
 
 #include <asm-generic/global_data.h>
configs/nios2-generic_defconfig +0 -2
index ad72272..63d99d8 100644
@@ -13,9 +13,7 @@ CONFIG_HUSH_PARSER=y
 CONFIG_CMD_DHCP=y
 # CONFIG_CMD_NFS is not set
 CONFIG_CMD_PING=y
-CONFIG_OF_CONTROL=y
 CONFIG_NET_RANDOM_ETHADDR=y
-CONFIG_DM=y
 CONFIG_ALTERA_PIO=y
 CONFIG_ALTERA_JTAG_UART=y
 CONFIG_ALTERA_JTAG_UART_BYPASS=y
Signature · 1 line
2.1.4
#2 lore raw

PATCH v2 1/1 nios2: convert nios2 cpu to driver model

Quoted 5 lines · Thomas Chou

Convert nios2 cpu to driver model. The cpu parameters are extracted from device tree and saved to global data structure. We will use them to replace the custom_fpga.h .

Hi!

Minor nitpicks below.

Quoted 17 lines

---
v2
move cpu param setup to arch_cpu_init_dm, remove probe.

 arch/Kconfig                         |  3 ++
 arch/nios2/cpu/cpu.c                 | 76
++++++++++++++++++++++++++++++++++-- arch/nios2/dts/3c120_devboard.dts   
|  1 +
 arch/nios2/include/asm/global_data.h |  8 ++++
 configs/nios2-generic_defconfig      |  2 -
 5 files changed, 85 insertions(+), 5 deletions(-)
arch/Kconfig +0 -0
index 207c778..9be1538 100644

arch/Kconfig config NIOS2 · line 69

Quoted 6 lines
arch/Kconfig +3 -0
@@ -64,6 +64,9 @@ config NIOS2
 	select HAVE_GENERIC_BOARD
 	select SYS_GENERIC_BOARD
 	select SUPPORT_OF_CONTROL
+	select OF_CONTROL
+	select DM
+	select CPU

What's this CONFIG_CPU for please ?

Quoted 37 lines
arch/Kconfig +0 -0
 config OPENRISC
 	bool "OpenRISC architecture"
arch/nios2/cpu/cpu.c +16 -3
index 39ae972..88984e2 100644
@@ -6,7 +6,9 @@
  */
 
 #include <common.h>
-#include <asm/nios2.h>
+#include <cpu.h>
+#include <dm.h>
+#include <errno.h>
 #include <asm/cache.h>
 
 DECLARE_GLOBAL_DATA_PTR;
@@ -51,10 +53,78 @@ void dcache_disable(void)
 	flush_dcache(CONFIG_SYS_DCACHE_SIZE, CONFIG_SYS_DCACHELINE_SIZE);
 }
 
-int arch_cpu_init(void)
+int arch_cpu_init_dm(void)
 {
-	gd->cpu_clk = CONFIG_SYS_CLK_FREQ;
+	struct udevice *dev;
+
+	uclass_first_device(UCLASS_CPU, &dev);
+	if (!dev)
+		return -ENODEV;
+
+	gd->cpu_clk = fdtdec_get_int(gd->fdt_blob, dev->of_offset,
+		"clock-frequency", 0);
+	gd->arch.dcache_line_size = fdtdec_get_int(gd->fdt_blob, dev->of_offset,
+		"dcache-line-size", 0);
+	gd->arch.icache_line_size = fdtdec_get_int(gd->fdt_blob, dev->of_offset,
+		"icache-line-size", 0);

arch/nios2/cpu/cpu.c void dcache_disable(void) · line 79

Quoted 10 lines
arch/nios2/cpu/cpu.c +10 -0
+	gd->arch.dcache_size = fdtdec_get_int(gd->fdt_blob, dev->of_offset,
+		"dcache-size", 0);
+	gd->arch.icache_size = fdtdec_get_int(gd->fdt_blob, dev->of_offset,
+		"icache-size", 0);
+	gd->arch.reset_addr = fdtdec_get_int(gd->fdt_blob, dev->of_offset,
+		"altr,reset-addr", 0);
+	gd->arch.exception_addr = fdtdec_get_int(gd->fdt_blob, dev->of_offset,
+		"altr,exception-addr", 0);
+	gd->arch.has_mmu = fdtdec_get_int(gd->fdt_blob, dev->of_offset,
+		"altr,has-mmu", 0);

Shouldn't there be some sort of return value checking here ?

Quoted 19 lines
arch/nios2/cpu/cpu.c +14 -0
+	gd->arch.io_region_base = gd->arch.has_mmu ? 0xe0000000 : 0x8000000;
 	gd->ram_size = CONFIG_SYS_SDRAM_SIZE;
 
 	return 0;
 }
+
+static int altera_nios2_get_desc(struct udevice *dev, char *buf, int size)
+{
+	const char *cpu_name = "Nios-II";
+
+	if (size < strlen(cpu_name))
+		return -ENOSPC;
+	strcpy(buf, cpu_name);
+
+	return 0;
+}
+
+static int altera_nios2_get_info(struct udevice *dev, struct cpu_info

*info) +{

arch/nios2/cpu/cpu.c void dcache_disable(void) · line 102

Quoted 4 lines
arch/nios2/cpu/cpu.c +4 -0
+
+	info->cpu_freq = gd->cpu_clk;
+	info->features = 1 << CPU_FEAT_L1_CACHE
+		| (gd->arch.has_mmu ? 1 << CPU_FEAT_MMU : 0);

I'd add parenthesis around the bitshifts, for the sake of clarity. Also, please put the ORR operator@the end of the line.

arch/nios2/cpu/cpu.c

Quoted 2 lines
arch/nios2/cpu/cpu.c +2 -0
+	return 0;
+}

Thanks a lot :)

#3 lore raw

PATCH v2 1/1 nios2: convert nios2 cpu to driver model

Hi Marek,

Quoted 11 lines · Marek Vasut

arch/Kconfig config NIOS2 · line 69

Quoted 9 lines
arch/Kconfig +3 -0
@@ -64,6 +64,9 @@ config NIOS2
  	select HAVE_GENERIC_BOARD
  	select SYS_GENERIC_BOARD
  	select SUPPORT_OF_CONTROL
+	select OF_CONTROL
+	select DM
+	select CPU

What's this CONFIG_CPU for please ?

drivers/cpu/Kconfig

It is "Enable CPU drivers using Driver Model". I think it should have been named as CONFIG_DM_CPU to avoid confusion.

Quoted 20 lines
Quoted 20 lines
arch/Kconfig +17 -2
-int arch_cpu_init(void)
+int arch_cpu_init_dm(void)
  {
-	gd->cpu_clk = CONFIG_SYS_CLK_FREQ;
+	struct udevice *dev;
+
+	uclass_first_device(UCLASS_CPU, &dev);
+	if (!dev)
+		return -ENODEV;
+
+	gd->cpu_clk = fdtdec_get_int(gd->fdt_blob, dev->of_offset,
+		"clock-frequency", 0);
+	gd->arch.dcache_line_size = fdtdec_get_int(gd->fdt_blob, dev->of_offset,
+		"dcache-line-size", 0);
+	gd->arch.icache_line_size = fdtdec_get_int(gd->fdt_blob, dev->of_offset,
+		"icache-line-size", 0);
+	gd->arch.dcache_size = fdtdec_get_int(gd->fdt_blob, dev->of_offset,
+		"dcache-size", 0);
+	gd->arch.icache_size = fdtdec_get_int(gd->fdt_blob, dev->of_offset,
+		"icache-size", 0);
Quoted 8 lines

arch/Kconfig

Quoted 6 lines
arch/Kconfig +6 -0
+	gd->arch.reset_addr = fdtdec_get_int(gd->fdt_blob, dev->of_offset,
+		"altr,reset-addr", 0);
+	gd->arch.exception_addr = fdtdec_get_int(gd->fdt_blob, dev->of_offset,
+		"altr,exception-addr", 0);
+	gd->arch.has_mmu = fdtdec_get_int(gd->fdt_blob, dev->of_offset,
+		"altr,has-mmu", 0);

Shouldn't there be some sort of return value checking here ?

There might be some. Though I would like to depend upon the sopc2dts which generates the dts. I don't think these values should be tweaked by a human. :)

Quoted 6 lines

arch/Kconfig

Quoted 3 lines
arch/Kconfig +2 -0
+	info->features = 1 << CPU_FEAT_L1_CACHE
+		| (gd->arch.has_mmu ? 1 << CPU_FEAT_MMU : 0);

I'd add parenthesis around the bitshifts, for the sake of clarity. Also, please put the ORR operator at the end of the line.

Will do as suggested.

Thanks a lot for your review.

Best regards,
Thomas Chou

#4 lore raw

PATCH v2 1/1 nios2: convert nios2 cpu to driver model

+Simon

Quoted 18 lines · Thomas Chou

Hi Marek,

Quoted 13 lines · Marek Vasut

arch/Kconfig config NIOS2 · line 69

Quoted 10 lines
arch/Kconfig +3 -0
@@ -64,6 +64,9 @@ config NIOS2
        select HAVE_GENERIC_BOARD
        select SYS_GENERIC_BOARD
        select SUPPORT_OF_CONTROL
+       select OF_CONTROL
+       select DM
+       select CPU

What's this CONFIG_CPU for please ?

Quoted 4 lines

drivers/cpu/Kconfig

It is "Enable CPU drivers using Driver Model". I think it should have been named as CONFIG_DM_CPU to avoid confusion.

I remember Simon intended to name it as CONFIG_DM_CPU as I raised similar comments before.

[snip]

Regards,
Bin

#5 lore raw

PATCH v2 1/1 nios2: convert nios2 cpu to driver model

Quoted 21 lines · Bin Meng

+Simon

Quoted 18 lines · Thomas Chou

Hi Marek,

Quoted 13 lines · Marek Vasut

arch/Kconfig config NIOS2 · line 69

Quoted 10 lines
arch/Kconfig +3 -0
@@ -64,6 +64,9 @@ config NIOS2
        select HAVE_GENERIC_BOARD
        select SYS_GENERIC_BOARD
        select SUPPORT_OF_CONTROL
+       select OF_CONTROL
+       select DM
+       select CPU

What's this CONFIG_CPU for please ?

Quoted 7 lines
Quoted 4 lines

drivers/cpu/Kconfig

It is "Enable CPU drivers using Driver Model". I think it should have been named as CONFIG_DM_CPU to avoid confusion.

I remember Simon intended to name it as CONFIG_DM_CPU as I raised similar comments before.

Oops, I must be drunk! I mean CONFIG_CPU ...

Quoted 5 lines

[snip]

Regards,
Bin

#6 lore raw

PATCH v2 1/1 nios2: convert nios2 cpu to driver model

Hi,

Quoted 24 lines · Bin Meng
Quoted 23 lines · Bin Meng

+Simon

Quoted 20 lines · Thomas Chou

Hi Marek,

Quoted 13 lines · Marek Vasut

arch/Kconfig config NIOS2 · line 69

Quoted 10 lines
arch/Kconfig +3 -0
@@ -64,6 +64,9 @@ config NIOS2
        select HAVE_GENERIC_BOARD
        select SYS_GENERIC_BOARD
        select SUPPORT_OF_CONTROL
+       select OF_CONTROL
+       select DM
+       select CPU

What's this CONFIG_CPU for please ?

drivers/cpu/Kconfig

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

It is "Enable CPU drivers using Driver Model". I think it should have been named as CONFIG_DM_CPU to avoid confusion.

I remember Simon intended to name it as CONFIG_DM_CPU as I raised similar comments before.

Oops, I must be drunk! I mean CONFIG_CPU ...

Yes. The CONFIG_DM_xxx options will go away as each subsystem is converted to driver model.

Regards,
Simon

#7 lore raw

PATCH v3 1/1 nios2: convert nios2 cpu to driver model

In reply to Thomas Chou

Convert nios2 cpu to driver model. The cpu parameters are extracted from device tree and saved to global data structure. We will use them to replace the custom_fpga.h .

---
v2
move cpu param setup to arch_cpu_init_dm, remove probe.
v3
fix coding style as Marek suggested.
select CMD_CPU.

 arch/Kconfig                         |  3 ++
 arch/nios2/cpu/cpu.c                 | 75 ++++++++++++++++++++++++++++++++++--
 arch/nios2/dts/3c120_devboard.dts    |  1 +
 arch/nios2/include/asm/global_data.h |  8 ++++
 configs/nios2-generic_defconfig      |  3 +-
 5 files changed, 85 insertions(+), 5 deletions(-)
arch/Kconfig +3 -0
index 207c778..9be1538 100644
@@ -64,6 +64,9 @@ config NIOS2
 	select HAVE_GENERIC_BOARD
 	select SYS_GENERIC_BOARD
 	select SUPPORT_OF_CONTROL
+	select OF_CONTROL
+	select DM
+	select CPU
 
 config OPENRISC
 	bool "OpenRISC architecture"
arch/nios2/cpu/cpu.c +72 -3

89 lines not on this page · raw message

arch/nios2/dts/3c120_devboard.dts +1 -0
index 781a652..2e2956f 100644
@@ -41,6 +41,7 @@
 			altr,exception-addr = <0xd0000020>;
 			altr,has-initda = <1>;
 			altr,has-mmu = <1>;
+			u-boot,dm-pre-reloc;
 		};
 	};
 
arch/nios2/include/asm/global_data.h +8 -0
index 580b019..ee5180b 100644
@@ -9,6 +9,14 @@
 
 /* Architecture-specific global data */
 struct arch_global_data {
+	u32 dcache_line_size;
+	u32 icache_line_size;
+	u32 dcache_size;
+	u32 icache_size;
+	u32 reset_addr;
+	u32 exception_addr;
+	int has_mmu;
+	u32 io_region_base;
 };
 
 #include <asm-generic/global_data.h>
configs/nios2-generic_defconfig +1 -2
index ad72272..707ee33 100644
@@ -4,6 +4,7 @@ CONFIG_DM_GPIO=y
 CONFIG_TARGET_NIOS2_GENERIC=y
 CONFIG_DEFAULT_DEVICE_TREE="3c120_devboard"
 CONFIG_HUSH_PARSER=y
+CONFIG_CMD_CPU=y
 # CONFIG_CMD_BOOTD is not set
 # CONFIG_CMD_IMLS is not set
 # CONFIG_CMD_XIMG is not set
@@ -13,9 +14,7 @@ CONFIG_HUSH_PARSER=y
 CONFIG_CMD_DHCP=y
 # CONFIG_CMD_NFS is not set
 CONFIG_CMD_PING=y
-CONFIG_OF_CONTROL=y
 CONFIG_NET_RANDOM_ETHADDR=y
-CONFIG_DM=y
 CONFIG_ALTERA_PIO=y
 CONFIG_ALTERA_JTAG_UART=y
 CONFIG_ALTERA_JTAG_UART_BYPASS=y
Signature · 1 line
2.1.4
#8 lore raw

PATCH v3 1/1 nios2: convert nios2 cpu to driver model

Hi Thomas,

Quoted 12 lines · Thomas Chou

Convert nios2 cpu to driver model. The cpu parameters are extracted from device tree and saved to global data structure. We will use them to replace the custom_fpga.h .

---
v2
move cpu param setup to arch_cpu_init_dm, remove probe.
v3
fix coding style as Marek suggested.
select CMD_CPU.

Quoted 6 lines
 arch/Kconfig                         |  3 ++
 arch/nios2/cpu/cpu.c                 | 75 ++++++++++++++++++++++++++++++++++--
 arch/nios2/dts/3c120_devboard.dts    |  1 +
 arch/nios2/include/asm/global_data.h |  8 ++++
 configs/nios2-generic_defconfig      |  3 +-
 5 files changed, 85 insertions(+), 5 deletions(-)

Looks good, a few minor comments below.

Quoted 31 lines
arch/Kconfig +3 -0
index 207c778..9be1538 100644
@@ -64,6 +64,9 @@ config NIOS2
        select HAVE_GENERIC_BOARD
        select SYS_GENERIC_BOARD
        select SUPPORT_OF_CONTROL
+       select OF_CONTROL
+       select DM
+       select CPU
 
 config OPENRISC
        bool "OpenRISC architecture"
arch/nios2/cpu/cpu.c +3 -1
index 39ae972..9e98742 100644
@@ -6,7 +6,9 @@
  */
 
 #include <common.h>
-#include <asm/nios2.h>
+#include <cpu.h>
+#include <dm.h>
+#include <errno.h>
 #include <asm/cache.h>
 
 DECLARE_GLOBAL_DATA_PTR;

arch/nios2/cpu/cpu.c void dcache_disable(void) · line 60

Quoted 10 lines
arch/nios2/cpu/cpu.c +4 -2
@@ -51,10 +53,77 @@ void dcache_disable(void)
        flush_dcache(CONFIG_SYS_DCACHE_SIZE, CONFIG_SYS_DCACHELINE_SIZE);
 }
 
-int arch_cpu_init(void)
+int arch_cpu_init_dm(void)
 {
-       gd->cpu_clk = CONFIG_SYS_CLK_FREQ;
+       struct udevice *dev;
+
+       uclass_first_device(UCLASS_CPU, &dev);

Should check the error return too.

ret = uclass_first_device(...)
if (ret)
return ret;

arch/nios2/cpu/cpu.c void dcache_disable(void) · line 64

Quoted 4 lines
arch/nios2/cpu/cpu.c +4 -0
+       if (!dev)
+               return -ENODEV;
+
+       gd->cpu_clk = fdtdec_get_int(gd->fdt_blob, dev->of_offset,

This code should go in a probe() method in this driver. Then when the device is probed (by your arch_cpu_init_dm() function this code will be executed. The problem here is that you are looking at dev->of_offset, which is the drivers's responsibility. I know this code is in the same file, but this is not a driver method function.

You could make this briefer by declaring a few locals:

const void *blob = gd->fdt_blob;
int node = dev->of_offset;

Quoted 5 lines
arch/nios2/cpu/cpu.c +5 -0
+               "clock-frequency", 0);
+       gd->arch.dcache_line_size = fdtdec_get_int(gd->fdt_blob, dev->of_offset,
+               "dcache-line-size", 0);
+       gd->arch.icache_line_size = fdtdec_get_int(gd->fdt_blob, dev->of_offset,
+               "icache-line-size", 0);

arch/nios2/cpu/cpu.c void dcache_disable(void) · line 79

Quoted 10 lines
arch/nios2/cpu/cpu.c +10 -0
+       gd->arch.dcache_size = fdtdec_get_int(gd->fdt_blob, dev->of_offset,
+               "dcache-size", 0);
+       gd->arch.icache_size = fdtdec_get_int(gd->fdt_blob, dev->of_offset,
+               "icache-size", 0);
+       gd->arch.reset_addr = fdtdec_get_int(gd->fdt_blob, dev->of_offset,
+               "altr,reset-addr", 0);
+       gd->arch.exception_addr = fdtdec_get_int(gd->fdt_blob, dev->of_offset,
+               "altr,exception-addr", 0);
+       gd->arch.has_mmu = fdtdec_get_int(gd->fdt_blob, dev->of_offset,
+               "altr,has-mmu", 0);

Should that be fdtdec_get_bool()? Also is there a device tree binding file for these settings?

Quoted 104 lines
arch/nios2/cpu/cpu.c +46 -0
+       gd->arch.io_region_base = gd->arch.has_mmu ? 0xe0000000 : 0x8000000;
        gd->ram_size = CONFIG_SYS_SDRAM_SIZE;
 
        return 0;
 }
+
+static int altera_nios2_get_desc(struct udevice *dev, char *buf, int size)
+{
+       const char *cpu_name = "Nios-II";
+
+       if (size < strlen(cpu_name))
+               return -ENOSPC;
+       strcpy(buf, cpu_name);
+
+       return 0;
+}
+
+static int altera_nios2_get_info(struct udevice *dev, struct cpu_info *info)
+{
+       info->cpu_freq = gd->cpu_clk;
+       info->features = (1 << CPU_FEAT_L1_CACHE) |
+               (gd->arch.has_mmu ? (1 << CPU_FEAT_MMU) : 0);
+
+       return 0;
+}
+
+static int altera_nios2_get_count(struct udevice *dev)
+{
+       return 1;
+}
+
+static const struct cpu_ops altera_nios2_ops = {
+       .get_desc       = altera_nios2_get_desc,
+       .get_info       = altera_nios2_get_info,
+       .get_count      = altera_nios2_get_count,
+};
+
+static const struct udevice_id altera_nios2_ids[] = {
+       { .compatible = "altr,nios2-1.0" },
+       { .compatible = "altr,nios2-1.1" },
+       { }
+};
+
+U_BOOT_DRIVER(altera_nios2) = {
+       .name           = "altera_nios2",
+       .id             = UCLASS_CPU,
+       .of_match       = altera_nios2_ids,
+       .ops            = &altera_nios2_ops,
+       .flags          = DM_FLAG_PRE_RELOC,
+};
arch/nios2/dts/3c120_devboard.dts +1 -0
index 781a652..2e2956f 100644
@@ -41,6 +41,7 @@
                        altr,exception-addr = <0xd0000020>;
                        altr,has-initda = <1>;
                        altr,has-mmu = <1>;
+                       u-boot,dm-pre-reloc;
                };
        };
 
arch/nios2/include/asm/global_data.h +8 -0
index 580b019..ee5180b 100644
@@ -9,6 +9,14 @@
 
 /* Architecture-specific global data */
 struct arch_global_data {
+       u32 dcache_line_size;
+       u32 icache_line_size;
+       u32 dcache_size;
+       u32 icache_size;
+       u32 reset_addr;
+       u32 exception_addr;
+       int has_mmu;
+       u32 io_region_base;
 };
 
 #include <asm-generic/global_data.h>
configs/nios2-generic_defconfig +1 -3
index ad72272..707ee33 100644
@@ -4,6 +4,7 @@ CONFIG_DM_GPIO=y
 CONFIG_TARGET_NIOS2_GENERIC=y
 CONFIG_DEFAULT_DEVICE_TREE="3c120_devboard"
 CONFIG_HUSH_PARSER=y
+CONFIG_CMD_CPU=y
 # CONFIG_CMD_BOOTD is not set
 # CONFIG_CMD_IMLS is not set
 # CONFIG_CMD_XIMG is not set
@@ -13,9 +14,7 @@ CONFIG_HUSH_PARSER=y
 CONFIG_CMD_DHCP=y
 # CONFIG_CMD_NFS is not set
 CONFIG_CMD_PING=y
-CONFIG_OF_CONTROL=y
 CONFIG_NET_RANDOM_ETHADDR=y
-CONFIG_DM=y
 CONFIG_ALTERA_PIO=y
 CONFIG_ALTERA_JTAG_UART=y
 CONFIG_ALTERA_JTAG_UART_BYPASS=y
--
Quoted 2 lines

2.1.4

Regards,
Simon

#9 lore raw

PATCH v3 1/1 nios2: convert nios2 cpu to driver model

Hi Simon,

Quoted 5 lines · Simon Glass

arch/nios2/cpu/cpu.c void dcache_disable(void) · line 79

Quoted 2 lines
arch/nios2/cpu/cpu.c +2 -0
+       gd->arch.has_mmu = fdtdec_get_int(gd->fdt_blob, dev->of_offset,
+               "altr,has-mmu", 0);

Should that be fdtdec_get_bool()? Also is there a device tree binding file for these settings?

With fdtdec_get_bool(), a boolean properly is true if present in the device tree and false if not present, regardless of its value.

It will be wrong if there is "altr,has-mmu = <0>;" .

A dts binding file will be added.

Thanks for your review.

Best regards,
Thomas

#10 lore raw

PATCH 1/1 nios2: convert nios2 cpu to driver model

In reply to Thomas Chou

Convert nios2 cpu to driver model. The cpu parameters are extracted from device tree and saved to global data structure. We will use them to replace the custom_fpga.h .

---
v2
move cpu param setup to arch_cpu_init_dm, remove probe.
v3
fix coding style as Marek suggested.
select CMD_CPU.
v4
revert to v1 probe method.
doc dts binding.
check uclass_first_device() return.
clean up as Simon suggested.

 arch/Kconfig                           |  3 ++
 arch/nios2/cpu/cpu.c                   | 88 ++++++++++++++++++++++++++++++++--
 arch/nios2/dts/3c120_devboard.dts      |  1 +
 arch/nios2/include/asm/global_data.h   |  8 ++++
 configs/nios2-generic_defconfig        |  3 +-
 doc/device-tree-bindings/cpu/nios2.txt | 54 +++++++++++++++++++++
 6 files changed, 152 insertions(+), 5 deletions(-)
 create mode 100644 doc/device-tree-bindings/cpu/nios2.txt
arch/Kconfig +3 -0
index 207c778..9be1538 100644
@@ -64,6 +64,9 @@ config NIOS2
 	select HAVE_GENERIC_BOARD
 	select SYS_GENERIC_BOARD
 	select SUPPORT_OF_CONTROL
+	select OF_CONTROL
+	select DM
+	select CPU
 
 config OPENRISC
 	bool "OpenRISC architecture"
arch/nios2/cpu/cpu.c +85 -3

102 lines not on this page · raw message

arch/nios2/dts/3c120_devboard.dts +1 -0
index 781a652..2e2956f 100644
@@ -41,6 +41,7 @@
 			altr,exception-addr = <0xd0000020>;
 			altr,has-initda = <1>;
 			altr,has-mmu = <1>;
+			u-boot,dm-pre-reloc;
 		};
 	};
 
arch/nios2/include/asm/global_data.h +8 -0
index 580b019..ee5180b 100644
@@ -9,6 +9,14 @@
 
 /* Architecture-specific global data */
 struct arch_global_data {
+	u32 dcache_line_size;
+	u32 icache_line_size;
+	u32 dcache_size;
+	u32 icache_size;
+	u32 reset_addr;
+	u32 exception_addr;
+	int has_mmu;
+	u32 io_region_base;
 };
 
 #include <asm-generic/global_data.h>
configs/nios2-generic_defconfig +1 -2
index ad72272..707ee33 100644
@@ -4,6 +4,7 @@ CONFIG_DM_GPIO=y
 CONFIG_TARGET_NIOS2_GENERIC=y
 CONFIG_DEFAULT_DEVICE_TREE="3c120_devboard"
 CONFIG_HUSH_PARSER=y
+CONFIG_CMD_CPU=y
 # CONFIG_CMD_BOOTD is not set
 # CONFIG_CMD_IMLS is not set
 # CONFIG_CMD_XIMG is not set
@@ -13,9 +14,7 @@ CONFIG_HUSH_PARSER=y
 CONFIG_CMD_DHCP=y
 # CONFIG_CMD_NFS is not set
 CONFIG_CMD_PING=y
-CONFIG_OF_CONTROL=y
 CONFIG_NET_RANDOM_ETHADDR=y
-CONFIG_DM=y
 CONFIG_ALTERA_PIO=y
 CONFIG_ALTERA_JTAG_UART=y
 CONFIG_ALTERA_JTAG_UART_BYPASS=y
doc/device-tree-bindings/cpu/nios2.txt new file +54 -0

54 lines not on this page · raw message

Signature · 1 line
2.1.4
#11 lore raw

PATCH 1/1 nios2: convert nios2 cpu to driver model

Quoted 18 lines · Thomas Chou

Convert nios2 cpu to driver model. The cpu parameters are extracted from device tree and saved to global data structure. We will use them to replace the custom_fpga.h .

---
v2
move cpu param setup to arch_cpu_init_dm, remove probe.
v3
fix coding style as Marek suggested.
select CMD_CPU.
v4
revert to v1 probe method.
doc dts binding.
check uclass_first_device() return.
clean up as Simon suggested.

Quoted 8 lines
 arch/Kconfig                           |  3 ++
 arch/nios2/cpu/cpu.c                   | 88 ++++++++++++++++++++++++++++++++--
 arch/nios2/dts/3c120_devboard.dts      |  1 +
 arch/nios2/include/asm/global_data.h   |  8 ++++
 configs/nios2-generic_defconfig        |  3 +-
 doc/device-tree-bindings/cpu/nios2.txt | 54 +++++++++++++++++++++
 6 files changed, 152 insertions(+), 5 deletions(-)
 create mode 100644 doc/device-tree-bindings/cpu/nios2.txt
Quoted 2 lines
#12 lore raw

PATCH 1/1 nios2: convert nios2 cpu to driver model

In reply to Thomas Chou
Quoted 17 lines · Thomas Chou

Convert nios2 cpu to driver model. The cpu parameters are extracted from device tree and saved to global data structure. We will use them to replace the custom_fpga.h .

---
v2
move cpu param setup to arch_cpu_init_dm, remove probe.
v3
fix coding style as Marek suggested.
select CMD_CPU.
v4
revert to v1 probe method.
doc dts binding.
check uclass_first_device() return.
clean up as Simon suggested.

Quoted 8 lines
  arch/Kconfig                           |  3 ++
  arch/nios2/cpu/cpu.c                   | 88 ++++++++++++++++++++++++++++++++--
  arch/nios2/dts/3c120_devboard.dts      |  1 +
  arch/nios2/include/asm/global_data.h   |  8 ++++
  configs/nios2-generic_defconfig        |  3 +-
  doc/device-tree-bindings/cpu/nios2.txt | 54 +++++++++++++++++++++
  6 files changed, 152 insertions(+), 5 deletions(-)

create mode 100644 doc/device-tree-bindings/cpu/nios2.txt

Applied to u-boot-nios.