All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] m68k/atari - stram: alloc ST-RAM pool even if kernel not in ST-RAM
@ 2014-03-19  7:23 Michael Schmitz
  2014-03-19  7:23 ` [PATCH 2/2] m68k/atari - atafb: convert allocation of fb ram to new interface Michael Schmitz
                   ` (6 more replies)
  0 siblings, 7 replies; 18+ messages in thread
From: Michael Schmitz @ 2014-03-19  7:23 UTC (permalink / raw)
  To: linux-m68k; +Cc: geert, debian-68k, Michael Schmitz

With the kernel loaded to FastRAM (TT-RAM), none of the ST-RAM
address range is mapped by init_mem, and ST-RAM is not accessible
through the normal allocation pathways as a result.

Implement ST-RAM pool allocation to be based on physical addresses
always (it already was when the kernel was loaded in ST-RAM).
Return kernel virtual addresses as per normal.

The current test for the kernel residing in ST-RAM always returns
true. Use the bootinfo memory chunk order instead - with the kernel
in FastRAM, ST-RAM (phys. 0x0) is not the first chunk.

Instead of mucking around with ioremap (which appears to
rely on the physical area being mappped by mem_init), use
the initial mapping of the first 16 MB of address space
to 0xFF000000, done in head.S.

Provide helper functions for those users of ST-RAM that need
to be aware of the backing physical addresses.

Kudos to Geert for his hints on getting this started.

Signed-off-by: Michael Schmitz <schmitz@debian.org>
---
 arch/m68k/atari/stram.c             |   66 ++++++++++++++++++++++++++---------
 arch/m68k/include/asm/atari_stram.h |    2 +
 2 files changed, 51 insertions(+), 17 deletions(-)

diff --git a/arch/m68k/atari/stram.c b/arch/m68k/atari/stram.c
index 0810c8d..91fbb11 100644
--- a/arch/m68k/atari/stram.c
+++ b/arch/m68k/atari/stram.c
@@ -47,6 +47,7 @@ static struct resource stram_pool = {
 
 static unsigned long pool_size = 1024*1024;
 
+static unsigned long stram_virt_offset = 0;
 
 static int __init atari_stram_setup(char *arg)
 {
@@ -67,14 +68,12 @@ early_param("stram_pool", atari_stram_setup);
 void __init atari_stram_init(void)
 {
 	int i;
-	void *stram_start;
 
 	/*
 	 * determine whether kernel code resides in ST-RAM
 	 * (then ST-RAM is the first memory block at virtual 0x0)
 	 */
-	stram_start = phys_to_virt(0);
-	kernel_in_stram = (stram_start == 0);
+	kernel_in_stram = (m68k_memory[0].addr == 0);
 
 	for (i = 0; i < m68k_num_memory; ++i) {
 		if (m68k_memory[i].addr == 0) {
@@ -93,21 +92,54 @@ void __init atari_stram_init(void)
  */
 void __init atari_stram_reserve_pages(void *start_mem)
 {
-	/*
-	 * always reserve first page of ST-RAM, the first 2 KiB are
-	 * supervisor-only!
-	 */
-	if (!kernel_in_stram)
-		reserve_bootmem(0, PAGE_SIZE, BOOTMEM_DEFAULT);
-
-	stram_pool.start = (resource_size_t)alloc_bootmem_low_pages(pool_size);
-	stram_pool.end = stram_pool.start + pool_size - 1;
-	request_resource(&iomem_resource, &stram_pool);
+	if (kernel_in_stram) {
+
+		stram_pool.start = (resource_size_t)alloc_bootmem_low_pages(pool_size);
+		stram_pool.end = stram_pool.start + pool_size - 1;
+		request_resource(&iomem_resource, &stram_pool);
+
+		printk("atari_stram pool: kernel in ST-RAM, using alloc_bootmem!\n");
+
+		printk("atari_stram pool: size = %lu bytes, resource = %pR\n",
+			 pool_size, &stram_pool);
+		printk("atari_stram pool: start = %p, end = %p\n",
+                         (void *) stram_pool.start, (void *) stram_pool.end);		
+		printk("atari_stram pool: stram_virt_offset = %p\n",
+                         (void *) stram_virt_offset);		
+	} else {
+		/*
+		 * Skip page 0, as the fhe first 2 KiB are supervisor-only!
+		 */
+
+		printk("atari_stram pool: kernel not in ST-RAM, using ioremap!\n");
+
+		stram_pool.start = PAGE_SIZE;
+		stram_pool.end = stram_pool.start + pool_size - 1;
+
+		request_resource(&iomem_resource, &stram_pool);
+
+		printk("atari_stram pool: size = %lu bytes, resource = %pR\n",
+			 pool_size, &stram_pool);		
+		printk("atari_stram pool: start = %p, end = %p\n",
+                         (void *) stram_pool.start, (void *) stram_pool.end);		
+
+		/* stram_virt_offset = ioremap(stram_pool.start, pool_size); */
+		stram_virt_offset = (unsigned long) 0xFF000000;
+  
+		printk("atari_stram pool: stram_virt_offset = %p\n",
+                         (void *) stram_virt_offset);		
+	}
+}
 
-	pr_debug("atari_stram pool: size = %lu bytes, resource = %pR\n",
-		 pool_size, &stram_pool);
+void *atari_stram_to_virt(unsigned long phys)
+{
+	return (void *)(phys + stram_virt_offset);
 }
 
+void *atari_stram_to_phys(unsigned long virt)
+{
+	return (void *)(virt - stram_virt_offset);
+}
 
 void *atari_stram_alloc(unsigned long size, const char *owner)
 {
@@ -134,14 +166,14 @@ void *atari_stram_alloc(unsigned long size, const char *owner)
 	}
 
 	pr_debug("atari_stram_alloc: returning %pR\n", res);
-	return (void *)res->start;
+	return atari_stram_to_virt(res->start);
 }
 EXPORT_SYMBOL(atari_stram_alloc);
 
 
 void atari_stram_free(void *addr)
 {
-	unsigned long start = (unsigned long)addr;
+	unsigned long start = (unsigned long) atari_stram_to_phys((unsigned long) addr);
 	struct resource *res;
 	unsigned long size;
 
diff --git a/arch/m68k/include/asm/atari_stram.h b/arch/m68k/include/asm/atari_stram.h
index 62e2759..03ba5b0 100644
--- a/arch/m68k/include/asm/atari_stram.h
+++ b/arch/m68k/include/asm/atari_stram.h
@@ -8,6 +8,8 @@
 /* public interface */
 void *atari_stram_alloc(unsigned long size, const char *owner);
 void atari_stram_free(void *);
+void *atari_stram_to_virt(unsigned long phys);
+void *atari_stram_to_phys(unsigned long virt);
 
 /* functions called internally by other parts of the kernel */
 void atari_stram_init(void);
-- 
1.7.0.4

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH 2/2] m68k/atari - atafb: convert allocation of fb ram to new interface
  2014-03-19  7:23 [PATCH 1/2] m68k/atari - stram: alloc ST-RAM pool even if kernel not in ST-RAM Michael Schmitz
@ 2014-03-19  7:23 ` Michael Schmitz
  2014-03-19  8:01   ` Geert Uytterhoeven
  2014-03-19  7:51 ` [PATCH 1/2] m68k/atari - stram: alloc ST-RAM pool even if kernel not in ST-RAM Geert Uytterhoeven
                   ` (5 subsequent siblings)
  6 siblings, 1 reply; 18+ messages in thread
From: Michael Schmitz @ 2014-03-19  7:23 UTC (permalink / raw)
  To: linux-m68k; +Cc: geert, debian-68k, Michael Schmitz

The new atari_stram_alloc interface returns kernel virtual addresses
even if the kernel runs in FastRAM. These addresses are not
guaranteed to be identical with the physical addresses. Since ST-RAM
mappings have not been set up by mem_init, virt_to_phys() and its
cousin do not work and the atari_stram_to_phys() etc. helpers must
be used to determine physical addresses.
fb.fix->smem_start needs physical addresses, fb.par->screen_base
needs virtual addresses. Take care of the virt-to-phys conversion
both on fb init and par changes.

FIXME - currently double faukts at fb init.

Signed-off-by: Michael Schmitz <schmitz@debian.org>
---
 drivers/video/atafb.c |   12 ++++++------
 1 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/video/atafb.c b/drivers/video/atafb.c
index e21d1f5..40d105e 100644
--- a/drivers/video/atafb.c
+++ b/drivers/video/atafb.c
@@ -790,7 +790,7 @@ static void tt_get_par(struct atafb_par *par)
 	addr = ((shifter.bas_hi & 0xff) << 16) |
 	       ((shifter.bas_md & 0xff) << 8)  |
 	       ((shifter.bas_lo & 0xff));
-	par->screen_base = phys_to_virt(addr);
+	par->screen_base = atari_stram_to_virt(addr);
 }
 
 static void tt_set_par(struct atafb_par *par)
@@ -1584,7 +1584,7 @@ static void falcon_get_par(struct atafb_par *par)
 	addr = (shifter.bas_hi & 0xff) << 16 |
 	       (shifter.bas_md & 0xff) << 8  |
 	       (shifter.bas_lo & 0xff);
-	par->screen_base = phys_to_virt(addr);
+	par->screen_base = atari_stram_to_virt(addr);
 
 	/* derived parameters */
 	hw->ste_mode = (hw->f_shift & 0x510) == 0 && hw->st_shift == 0x100;
@@ -1980,7 +1980,7 @@ static void stste_get_par(struct atafb_par *par)
 	       ((shifter.bas_md & 0xff) << 8);
 	if (ATARIHW_PRESENT(EXTD_SHIFTER))
 		addr |= (shifter.bas_lo & 0xff);
-	par->screen_base = phys_to_virt(addr);
+	par->screen_base = atari_stram_to_virt(addr);
 }
 
 static void stste_set_par(struct atafb_par *par)
@@ -2039,7 +2039,7 @@ static int stste_detect(void)
 static void stste_set_screen_base(void *s_base)
 {
 	unsigned long addr;
-	addr = virt_to_phys(s_base);
+	addr = (unsigned long) atari_stram_to_phys((unsigned long) s_base);
 	/* Setup Screen Memory */
 	shifter.bas_hi = (unsigned char)((addr & 0xff0000) >> 16);
 	shifter.bas_md = (unsigned char)((addr & 0x00ff00) >> 8);
@@ -2286,7 +2286,7 @@ static void set_screen_base(void *s_base)
 {
 	unsigned long addr;
 
-	addr = virt_to_phys(s_base);
+	addr = (unsigned long) atari_stram_to_phys((unsigned long) s_base);
 	/* Setup Screen Memory */
 	shifter.bas_hi = (unsigned char)((addr & 0xff0000) >> 16);
 	shifter.bas_md = (unsigned char)((addr & 0x00ff00) >> 8);
@@ -3166,7 +3166,7 @@ int __init atafb_init(void)
 		memset(screen_base, 0, mem_req);
 		pad = -(unsigned long)screen_base & (PAGE_SIZE - 1);
 		screen_base += pad;
-		real_screen_base = screen_base + ovsc_offset;
+		real_screen_base = atari_stram_to_phys((unsigned long) (screen_base + ovsc_offset));
 		screen_len = (mem_req - pad - ovsc_offset) & PAGE_MASK;
 		st_ovsc_switch();
 		if (CPU_IS_040_OR_060) {
-- 
1.7.0.4

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* Re: [PATCH 1/2] m68k/atari - stram: alloc ST-RAM pool even if kernel not in ST-RAM
  2014-03-19  7:23 [PATCH 1/2] m68k/atari - stram: alloc ST-RAM pool even if kernel not in ST-RAM Michael Schmitz
  2014-03-19  7:23 ` [PATCH 2/2] m68k/atari - atafb: convert allocation of fb ram to new interface Michael Schmitz
@ 2014-03-19  7:51 ` Geert Uytterhoeven
  2014-03-20  8:23   ` schmitz
  2014-03-19  8:18 ` Andreas Schwab
                   ` (4 subsequent siblings)
  6 siblings, 1 reply; 18+ messages in thread
From: Geert Uytterhoeven @ 2014-03-19  7:51 UTC (permalink / raw)
  To: Michael Schmitz; +Cc: Linux/m68k, Debian m68k, Michael Schmitz

Hi Michael,

On Wed, Mar 19, 2014 at 8:23 AM, Michael Schmitz <schmitzmic@gmail.com> wrote:
> Instead of mucking around with ioremap (which appears to
> rely on the physical area being mappped by mem_init), use

That's not true. E.g. I/O memory is never mapped by mem_init().

> @@ -93,21 +92,54 @@ void __init atari_stram_init(void)
>   */
>  void __init atari_stram_reserve_pages(void *start_mem)
>  {
> -       /*
> -        * always reserve first page of ST-RAM, the first 2 KiB are
> -        * supervisor-only!
> -        */
> -       if (!kernel_in_stram)
> -               reserve_bootmem(0, PAGE_SIZE, BOOTMEM_DEFAULT);
> -
> -       stram_pool.start = (resource_size_t)alloc_bootmem_low_pages(pool_size);
> -       stram_pool.end = stram_pool.start + pool_size - 1;
> -       request_resource(&iomem_resource, &stram_pool);
> +       if (kernel_in_stram) {
> +
> +               stram_pool.start = (resource_size_t)alloc_bootmem_low_pages(pool_size);
> +               stram_pool.end = stram_pool.start + pool_size - 1;
> +               request_resource(&iomem_resource, &stram_pool);
> +
> +               printk("atari_stram pool: kernel in ST-RAM, using alloc_bootmem!\n");
> +
> +               printk("atari_stram pool: size = %lu bytes, resource = %pR\n",
> +                        pool_size, &stram_pool);
> +               printk("atari_stram pool: start = %p, end = %p\n",
> +                         (void *) stram_pool.start, (void *) stram_pool.end);
> +               printk("atari_stram pool: stram_virt_offset = %p\n",
> +                         (void *) stram_virt_offset);
> +       } else {
> +               /*
> +                * Skip page 0, as the fhe first 2 KiB are supervisor-only!
> +                */
> +
> +               printk("atari_stram pool: kernel not in ST-RAM, using ioremap!\n");
> +
> +               stram_pool.start = PAGE_SIZE;
> +               stram_pool.end = stram_pool.start + pool_size - 1;
> +
> +               request_resource(&iomem_resource, &stram_pool);
> +
> +               printk("atari_stram pool: size = %lu bytes, resource = %pR\n",
> +                        pool_size, &stram_pool);
> +               printk("atari_stram pool: start = %p, end = %p\n",
> +                         (void *) stram_pool.start, (void *) stram_pool.end);
> +
> +               /* stram_virt_offset = ioremap(stram_pool.start, pool_size); */
> +               stram_virt_offset = (unsigned long) 0xFF000000;
> +
> +               printk("atari_stram pool: stram_virt_offset = %p\n",
> +                         (void *) stram_virt_offset);
> +       }

If you reorder some lines, you can share more code between the "if" and
"else" cases.

> +void *atari_stram_to_virt(unsigned long phys)
> +{
> +       return (void *)(phys + stram_virt_offset);
>  }
>
> +void *atari_stram_to_phys(unsigned long virt)

This should be "unsigned long atari_stram_to_phys(void *)",
allowing to remove a few casts in the callers...

> +{
> +       return (void *)(virt - stram_virt_offset);
> +}

>  void atari_stram_free(void *addr)
>  {
> -       unsigned long start = (unsigned long)addr;
> +       unsigned long start = (unsigned long) atari_stram_to_phys((unsigned long) addr);

... like here.

Gr{oetje,eeting}s,

                        Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH 2/2] m68k/atari - atafb: convert allocation of fb ram to new interface
  2014-03-19  7:23 ` [PATCH 2/2] m68k/atari - atafb: convert allocation of fb ram to new interface Michael Schmitz
@ 2014-03-19  8:01   ` Geert Uytterhoeven
  2014-03-20  8:17     ` schmitz
  0 siblings, 1 reply; 18+ messages in thread
From: Geert Uytterhoeven @ 2014-03-19  8:01 UTC (permalink / raw)
  To: Michael Schmitz; +Cc: Linux/m68k, Debian m68k, Michael Schmitz

On Wed, Mar 19, 2014 at 8:23 AM, Michael Schmitz <schmitzmic@gmail.com> wrote:
> @@ -3166,7 +3166,7 @@ int __init atafb_init(void)
>                 memset(screen_base, 0, mem_req);
>                 pad = -(unsigned long)screen_base & (PAGE_SIZE - 1);
>                 screen_base += pad;
> -               real_screen_base = screen_base + ovsc_offset;
> +               real_screen_base = atari_stram_to_phys((unsigned long) (screen_base + ovsc_offset));

This triggered my eye, but it's actually correct, as it's stored in
fix->smem_start,
which should be the physical address.

But the external_addr case is wrong ;-)

>                 screen_len = (mem_req - pad - ovsc_offset) & PAGE_MASK;
>                 st_ovsc_switch();
>                 if (CPU_IS_040_OR_060) {

Starting here, you have:

        cache_push(virt_to_phys(screen_base), screen_len);

atari_stram_to_phys()

        kernel_set_cachemode(screen_base, screen_len,
                                                     IOMAP_WRITETHROUGH);

woops, that won't work with the virt_to_phys() above, nor with transparent
translation. I guess it writes to a non-existent pointer table,
causing the crash?

Gr{oetje,eeting}s,

                        Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH 1/2] m68k/atari - stram: alloc ST-RAM pool even if kernel not in ST-RAM
  2014-03-19  7:23 [PATCH 1/2] m68k/atari - stram: alloc ST-RAM pool even if kernel not in ST-RAM Michael Schmitz
  2014-03-19  7:23 ` [PATCH 2/2] m68k/atari - atafb: convert allocation of fb ram to new interface Michael Schmitz
  2014-03-19  7:51 ` [PATCH 1/2] m68k/atari - stram: alloc ST-RAM pool even if kernel not in ST-RAM Geert Uytterhoeven
@ 2014-03-19  8:18 ` Andreas Schwab
  2014-03-20  6:35 ` Patrice Mandin
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 18+ messages in thread
From: Andreas Schwab @ 2014-03-19  8:18 UTC (permalink / raw)
  To: Michael Schmitz; +Cc: linux-m68k, geert, debian-68k, Michael Schmitz

Michael Schmitz <schmitzmic@gmail.com> writes:

> +		 * Skip page 0, as the fhe first 2 KiB are supervisor-only!

s/fhe//

Andreas.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH 1/2] m68k/atari - stram: alloc ST-RAM pool even if kernel not in ST-RAM
  2014-03-19  7:23 [PATCH 1/2] m68k/atari - stram: alloc ST-RAM pool even if kernel not in ST-RAM Michael Schmitz
                   ` (2 preceding siblings ...)
  2014-03-19  8:18 ` Andreas Schwab
@ 2014-03-20  6:35 ` Patrice Mandin
  2014-03-22  8:47 ` [PATCH 0/2] m68k/atari - make atafb work with kernel loaded to FastRAM Michael Schmitz
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 18+ messages in thread
From: Patrice Mandin @ 2014-03-20  6:35 UTC (permalink / raw)
  To: linux-m68k; +Cc: debian-68k

Hello,

I confirm there is a problem with stram/fastram usage. On my Falcon
+CT60, whenever I tried to run kernel from FastRam, nothing was
displayed on screen. The system was running because I could use it
through serial console, and see that everything was OK.

Of course, running the kernel from FastRam is much faster than running
it from STRam (something like 4x faster), so fixing this issue would be
very useful.

-- 
Patrice Mandin
WWW: http://pmandin.atari.org/

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH 2/2] m68k/atari - atafb: convert allocation of fb ram to new interface
  2014-03-19  8:01   ` Geert Uytterhoeven
@ 2014-03-20  8:17     ` schmitz
  2014-03-20  8:33       ` Geert Uytterhoeven
  0 siblings, 1 reply; 18+ messages in thread
From: schmitz @ 2014-03-20  8:17 UTC (permalink / raw)
  To: Geert Uytterhoeven
  Cc: Michael Schmitz, Linux/m68k, Debian m68k, Michael Schmitz

Geert Uytterhoeven wrote:
> On Wed, Mar 19, 2014 at 8:23 AM, Michael Schmitz <schmitzmic@gmail.com> wrote:
>   
>> @@ -3166,7 +3166,7 @@ int __init atafb_init(void)
>>                 memset(screen_base, 0, mem_req);
>>                 pad = -(unsigned long)screen_base & (PAGE_SIZE - 1);
>>                 screen_base += pad;
>> -               real_screen_base = screen_base + ovsc_offset;
>> +               real_screen_base = atari_stram_to_phys((unsigned long) (screen_base + ovsc_offset));
>>     
>
> This triggered my eye, but it's actually correct, as it's stored in
> fix->smem_start,
> which should be the physical address.
>
> But the external_addr case is wrong ;-)
>
>   

Haven't touched that at all yet.

>>                 screen_len = (mem_req - pad - ovsc_offset) & PAGE_MASK;
>>                 st_ovsc_switch();
>>                 if (CPU_IS_040_OR_060) {
>>     
>
> Starting here, you have:
>
>         cache_push(virt_to_phys(screen_base), screen_len);
>
> atari_stram_to_phys()
>   

Well spotted - I'm sure I searched for to_phys, must have missed that 
somehow

>         kernel_set_cachemode(screen_base, screen_len,
>                                                      IOMAP_WRITETHROUGH);
>
> woops, that won't work with the virt_to_phys() above, nor with transparent
> translation. I guess it writes to a non-existent pointer table,
> causing the crash?
>
>   
You mean kernel_set_cachemode wants a physical address?

Not sure the mapping in head.S is actually per transparent translation 
for 040 or 060. But I'll try with that chunk of code disabled (the early 
mapping is done as NOCACHE_SER so we don't really need all of that if 
the kernel is not in ST-RAM).

The last log line I get is:

atafb_init: start
atafb_init: initializing Falcon hw
atafb: screen_base ff001000 real_screen_base 00001000 screen_len 69632
Determined 640x400, depth 1
   virtual 640x870

which is a bit further down.

I guess it dies in register_framebuffer() - the next log entry is missing:

        fb_info(&fb_info, "frame buffer device, using %dK of video 
memory\n",
                screen_len >> 10);

Cheers,

    Michael

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH 1/2] m68k/atari - stram: alloc ST-RAM pool even if kernel not in ST-RAM
  2014-03-19  7:51 ` [PATCH 1/2] m68k/atari - stram: alloc ST-RAM pool even if kernel not in ST-RAM Geert Uytterhoeven
@ 2014-03-20  8:23   ` schmitz
  2014-03-20  8:35     ` Geert Uytterhoeven
  0 siblings, 1 reply; 18+ messages in thread
From: schmitz @ 2014-03-20  8:23 UTC (permalink / raw)
  To: Geert Uytterhoeven
  Cc: Michael Schmitz, Linux/m68k, Debian m68k, Michael Schmitz

Geert,
>> Instead of mucking around with ioremap (which appears to
>> rely on the physical area being mappped by mem_init), use
>>     
>
> That's not true. E.g. I/O memory is never mapped by mem_init().
>   

Why, then, does the ioremap() of ST-RAM fail? Because the physical 
address is lower than the lowest currently mapped physical address?

>   
>> @@ -93,21 +92,54 @@ void __init atari_stram_init(void)
>>   */
>>  void __init atari_stram_reserve_pages(void *start_mem)
>>  {
>> -       /*
>> -        * always reserve first page of ST-RAM, the first 2 KiB are
>> -        * supervisor-only!
>> -        */
>> -       if (!kernel_in_stram)
>> -               reserve_bootmem(0, PAGE_SIZE, BOOTMEM_DEFAULT);
>> -
>> -       stram_pool.start = (resource_size_t)alloc_bootmem_low_pages(pool_size);
>> -       stram_pool.end = stram_pool.start + pool_size - 1;
>> -       request_resource(&iomem_resource, &stram_pool);
>> +       if (kernel_in_stram) {
>> +
>> +               stram_pool.start = (resource_size_t)alloc_bootmem_low_pages(pool_size);
>> +               stram_pool.end = stram_pool.start + pool_size - 1;
>> +               request_resource(&iomem_resource, &stram_pool);
>> +
>> +               printk("atari_stram pool: kernel in ST-RAM, using alloc_bootmem!\n");
>> +
>> +               printk("atari_stram pool: size = %lu bytes, resource = %pR\n",
>> +                        pool_size, &stram_pool);
>> +               printk("atari_stram pool: start = %p, end = %p\n",
>> +                         (void *) stram_pool.start, (void *) stram_pool.end);
>> +               printk("atari_stram pool: stram_virt_offset = %p\n",
>> +                         (void *) stram_virt_offset);
>> +       } else {
>> +               /*
>> +                * Skip page 0, as the fhe first 2 KiB are supervisor-only!
>> +                */
>> +
>> +               printk("atari_stram pool: kernel not in ST-RAM, using ioremap!\n");
>> +
>> +               stram_pool.start = PAGE_SIZE;
>> +               stram_pool.end = stram_pool.start + pool_size - 1;
>> +
>> +               request_resource(&iomem_resource, &stram_pool);
>> +
>> +               printk("atari_stram pool: size = %lu bytes, resource = %pR\n",
>> +                        pool_size, &stram_pool);
>> +               printk("atari_stram pool: start = %p, end = %p\n",
>> +                         (void *) stram_pool.start, (void *) stram_pool.end);
>> +
>> +               /* stram_virt_offset = ioremap(stram_pool.start, pool_size); */
>> +               stram_virt_offset = (unsigned long) 0xFF000000;
>> +
>> +               printk("atari_stram pool: stram_virt_offset = %p\n",
>> +                         (void *) stram_virt_offset);
>> +       }
>>     
>
> If you reorder some lines, you can share more code between the "if" and
> "else" cases.
>
>   
>> +void *atari_stram_to_virt(unsigned long phys)
>> +{
>> +       return (void *)(phys + stram_virt_offset);
>>  }
>>
>> +void *atari_stram_to_phys(unsigned long virt)
>>     
>
> This should be "unsigned long atari_stram_to_phys(void *)",
> allowing to remove a few casts in the callers...
>   

Yep, that was a bit awkward to cast. This clearly needs a few more 
iterations.

Thanks for your feedback!

Cheers,

    Michael

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH 2/2] m68k/atari - atafb: convert allocation of fb ram to new interface
  2014-03-20  8:17     ` schmitz
@ 2014-03-20  8:33       ` Geert Uytterhoeven
  2014-03-22  1:28         ` schmitz
  0 siblings, 1 reply; 18+ messages in thread
From: Geert Uytterhoeven @ 2014-03-20  8:33 UTC (permalink / raw)
  To: schmitz; +Cc: Michael Schmitz, Linux/m68k, Debian m68k, Michael Schmitz

Hi Michael,

On Thu, Mar 20, 2014 at 9:17 AM, schmitz
<schmitz@biophys.uni-duesseldorf.de> wrote:
>>         kernel_set_cachemode(screen_base, screen_len,
>>                                                      IOMAP_WRITETHROUGH);
>>
>> woops, that won't work with the virt_to_phys() above, nor with transparent
>> translation. I guess it writes to a non-existent pointer table,
>> causing the crash?
>
> You mean kernel_set_cachemode wants a physical address?

No, it wants memory mapped using the page tables. Probably it will
work only for System RAM, not for MMIO mapped in head.S.

> Not sure the mapping in head.S is actually per transparent translation for
> 040 or 060. But I'll try with that chunk of code disabled (the early mapping
> is done as NOCACHE_SER so we don't really need all of that if the kernel is
> not in ST-RAM).

it's using mmu_map, not mmu_map_tt, so no transparent translation.

> The last log line I get is:
>
> atafb_init: start
> atafb_init: initializing Falcon hw
> atafb: screen_base ff001000 real_screen_base 00001000 screen_len 69632
> Determined 640x400, depth 1
>   virtual 640x870
>
> which is a bit further down.
>
> I guess it dies in register_framebuffer() - the next log entry is missing:
>
>        fb_info(&fb_info, "frame buffer device, using %dK of video memory\n",
>                screen_len >> 10);

And register_framebuffer() will write to the frame buffer, I think.
So info->screen_base may be incorrect.

Yep:

static void atafb_set_disp(struct fb_info *info)
{
        atafb_get_var(&info->var, info);
        atafb_get_fix(&info->fix, info);

        info->screen_base = (void *)info->fix.smem_start;
}

Missing atari_stram_to_virt().

Any other casts that indicate bugs? ;-)

Gr{oetje,eeting}s,

                        Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH 1/2] m68k/atari - stram: alloc ST-RAM pool even if kernel not in ST-RAM
  2014-03-20  8:23   ` schmitz
@ 2014-03-20  8:35     ` Geert Uytterhoeven
  2014-03-22  1:32       ` schmitz
  0 siblings, 1 reply; 18+ messages in thread
From: Geert Uytterhoeven @ 2014-03-20  8:35 UTC (permalink / raw)
  To: schmitz; +Cc: Michael Schmitz, Linux/m68k, Debian m68k, Michael Schmitz

On Thu, Mar 20, 2014 at 9:23 AM, schmitz
<schmitz@biophys.uni-duesseldorf.de> wrote:
>>> Instead of mucking around with ioremap (which appears to
>>> rely on the physical area being mappped by mem_init), use
>>>
>>
>>
>> That's not true. E.g. I/O memory is never mapped by mem_init().
>
> Why, then, does the ioremap() of ST-RAM fail? Because the physical address
> is lower than the lowest currently mapped physical address?

I don't know. How does it fail?

Gr{oetje,eeting}s,

                        Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH 2/2] m68k/atari - atafb: convert allocation of fb ram to new interface
  2014-03-20  8:33       ` Geert Uytterhoeven
@ 2014-03-22  1:28         ` schmitz
  2014-03-22  7:36           ` schmitz
  0 siblings, 1 reply; 18+ messages in thread
From: schmitz @ 2014-03-22  1:28 UTC (permalink / raw)
  To: Geert Uytterhoeven
  Cc: Michael Schmitz, Linux/m68k, Debian m68k, Michael Schmitz

Hi Geert,
>>>         kernel_set_cachemode(screen_base, screen_len,
>>>                                                      IOMAP_WRITETHROUGH);
>>>
>>> woops, that won't work with the virt_to_phys() above, nor with transparent
>>> translation. I guess it writes to a non-existent pointer table,
>>> causing the crash?
>>>       
>> You mean kernel_set_cachemode wants a physical address?
>>     
>
> No, it wants memory mapped using the page tables. Probably it will
> work only for System RAM, not for MMIO mapped in head.S.
>   

I've disabled both to check, no change. ST-RAM (4 MB of it) is mapped 
per page tables in head.S so we should be fine.

>   
>> The last log line I get is:
>>
>> atafb_init: start
>> atafb_init: initializing Falcon hw
>> atafb: screen_base ff001000 real_screen_base 00001000 screen_len 69632
>> Determined 640x400, depth 1
>>   virtual 640x870
>>
>> which is a bit further down.
>>
>> I guess it dies in register_framebuffer() - the next log entry is missing:
>>
>>        fb_info(&fb_info, "frame buffer device, using %dK of video memory\n",
>>                screen_len >> 10);
>>     
>
> And register_framebuffer() will write to the frame buffer, I think.
> So info->screen_base may be incorrect.
>
> Yep:
>
> static void atafb_set_disp(struct fb_info *info)
> {
>         atafb_get_var(&info->var, info);
>         atafb_get_fix(&info->fix, info);
>
>         info->screen_base = (void *)info->fix.smem_start;
> }
>
> Missing atari_stram_to_virt().
>   

Should have had phys_to_virt() before I guess. Thanks.

> Any other casts that indicate bugs? ;-)
>   

Probably - I'll go over the source again. My port of atafb a few years 
back was none too subtle.

Cheers,

    Michael

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH 1/2] m68k/atari - stram: alloc ST-RAM pool even if kernel not in ST-RAM
  2014-03-20  8:35     ` Geert Uytterhoeven
@ 2014-03-22  1:32       ` schmitz
  2014-03-23 20:02         ` Geert Uytterhoeven
  0 siblings, 1 reply; 18+ messages in thread
From: schmitz @ 2014-03-22  1:32 UTC (permalink / raw)
  To: Geert Uytterhoeven
  Cc: Michael Schmitz, Linux/m68k, Debian m68k, Michael Schmitz

Hi Geert
>
>>> That's not true. E.g. I/O memory is never mapped by mem_init().
>>>       
>> Why, then, does the ioremap() of ST-RAM fail? Because the physical address
>> is lower than the lowest currently mapped physical address?
>>     
>
> I don't know. How does it fail?
>   
Example:

Unable to handle kernel access at virtual address 5f435059
Oops: 00000000
Modules linked in:
PC: [<00089552>] kmem_cache_alloc+0x12/0x9a
SR: 2700  SP: 0029dec0  a2: 002a42d8
d0: 000080d0    d1: 00000013    d2: 000080d0    d3: 0007fe3c
d4: 00000001    d5: 000000d0    a0: 5f435055    a1: 002a75ee
Process swapper (pid: 0, task=002a42d8)
Frame format=4 fault addr=5f435059 fslw=01051000
Stack from 0029defc:
        000ff000 00080000 00216f06 00216f06 0007fe3c 00000000 000080d0 
000ff000
        00000000 00000001 00001000 00216f06 00080a6a 000ff000 00000001 
00000001
        00800000 d0000000 000000d0 00006bb4 00006bb4 000ff000 00000001 
04300601
        00000008 00216f06 002b9030 000b3ef4 00216f06 00216f06 002d55e0 
0029dfc8
        002d61cc 00001000 000ff000 00000001 000070dc 002d5bfc 00267189 
04300601
        002ec0ac 0012b010 002d4776 002eb0ae 00000000 00000000 00000000 
003bee10
Call Trace: [<000ff000>] keyctl_instantiate_key_iov+0x24/0xcc
 [<00080000>] vm_unmap_aliases+0x14/0x11a
 [<00216f06>] printk+0x0/0x24
 [<00216f06>] printk+0x0/0x24
 [<0007fe3c>] __get_vm_area_node.isra.33+0x5c/0x114
 [<000080d0>] atari_tt_hwclk+0x288/0x384
 [<000ff000>] keyctl_instantiate_key_iov+0x24/0xcc
 [<00001000>] kernel_pg_dir+0x0/0x1000
 [<00216f06>] printk+0x0/0x24
 [<00080a6a>] get_vm_area+0x30/0x38
 [<000ff000>] keyctl_instantiate_key_iov+0x24/0xcc
 [<00006bb4>] __ioremap+0x42/0x16a
 [<00006bb4>] __ioremap+0x42/0x16a
 [<000ff000>] keyctl_instantiate_key_iov+0x24/0xcc
 [<00216f06>] printk+0x0/0x24
 [<000b3ef4>] __block_write_begin+0x26c/0x41e
 [<00216f06>] printk+0x0/0x24
 [<00216f06>] printk+0x0/0x24
 [<002d55e0>] atari_parse_bootinfo+0x0/0x30
 [<002d61cc>] atari_stram_init+0xbc/0xfe
 [<00001000>] kernel_pg_dir+0x0/0x1000
 [<000ff000>] keyctl_instantiate_key_iov+0x24/0xcc
 [<000070dc>] hwreg_present+0x0/0x28
 [<002d5bfc>] config_atari+0x5ec/0x628
 [<0012b010>] strlcpy+0x0/0x64
 [<002d4776>] setup_arch+0x1ca/0x29c
 [<00216f06>] printk+0x0/0x24
 [<002d2da2>] start_kernel+0x6c/0x3ac
 [<000d3880>] devinfo_show+0x50/0x88
 [<002d2360>] _sinittext+0x360/0x9fa

Code: 3018 286f 0014 242f 0018 262f 0010 2054 <2228> 0004 2650 4a8b 6764 
202c 0014 2273 0800 40c0 007c 0700 2054 b7d0 6716 4281

I'll have to try that again with a fresh version that I can still 
correlate to a symbol map and object...

Cheers,

    Michael

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH 2/2] m68k/atari - atafb: convert allocation of fb ram to new interface
  2014-03-22  1:28         ` schmitz
@ 2014-03-22  7:36           ` schmitz
  0 siblings, 0 replies; 18+ messages in thread
From: schmitz @ 2014-03-22  7:36 UTC (permalink / raw)
  To: Geert Uytterhoeven
  Cc: Michael Schmitz, Linux/m68k, Debian m68k, Michael Schmitz

Hi Geert,
>>> I guess it dies in register_framebuffer() - the next log entry is 
>>> missing:
>>>
>>>        fb_info(&fb_info, "frame buffer device, using %dK of video 
>>> memory\n",
>>>                screen_len >> 10);
>>>     
>>
>> And register_framebuffer() will write to the frame buffer, I think.
>> So info->screen_base may be incorrect.
>>
>> Yep:
>>
>> static void atafb_set_disp(struct fb_info *info)
>> {
>>         atafb_get_var(&info->var, info);
>>         atafb_get_fix(&info->fix, info);
>>
>>         info->screen_base = (void *)info->fix.smem_start;
>> }
>>
>> Missing atari_stram_to_virt().
>>   
>
> Should have had phys_to_virt() before I guess. Thanks.

Bingo!

>
>> Any other casts that indicate bugs? ;-)
>>   
>
> Probably - I'll go over the source again. My port of atafb a few years 
> back was none too subtle.
>

Only a few more - in the external VGA adapter code, in the ioctl code 
(copy tp/from user) and one in the atafb_imageblit() that I'm fairly 
sure is dead code.

ARAnyM is happy - I'll have yet to see how this works on real hardware. 
We might yet need a writethrough mapping for performance.

In the interest of minimizing casts, I'll rewrite the virt/phys 
translation helpers and clean up the rest of the code a bit more. Saves 
a bit of headache when I need to revisit this code in another decade or 
so :-)

Thanks again for your help in tracking this down.

Cheers,

    Michael

^ permalink raw reply	[flat|nested] 18+ messages in thread

* [PATCH 0/2] m68k/atari - make atafb work with kernel loaded to FastRAM
  2014-03-19  7:23 [PATCH 1/2] m68k/atari - stram: alloc ST-RAM pool even if kernel not in ST-RAM Michael Schmitz
                   ` (3 preceding siblings ...)
  2014-03-20  6:35 ` Patrice Mandin
@ 2014-03-22  8:47 ` Michael Schmitz
  2014-03-23  0:28   ` schmitz
  2014-03-22  8:47 ` [PATCH 1/2] m68k/atari - stram: alloc ST-RAM pool even if kernel not in ST-RAM Michael Schmitz
  2014-03-22  8:47 ` [PATCH 2/2] m68k/atari - atafb: convert allocation of fb ram to new interface Michael Schmitz
  6 siblings, 1 reply; 18+ messages in thread
From: Michael Schmitz @ 2014-03-22  8:47 UTC (permalink / raw)
  To: linux-m68k; +Cc: geert, debian-68k

Geert,

cleaned up version of my earlier patches to make allocation of ST-RAM work
even when the kernel resides in FastRAM, and ST-RAM is not normally usable
by Linux because it violates the memory chunk order required for the 
discontig memory model.

The code relies on a mapping that has been set up for the first 16 MB of
address space in head.S - this may  not be ideal, because the mapping is
set up as non-cacheable and serialized (for reasons of hardware registers
mapped in the upper end of that segment). 

I've taken care not to disturb the cache mode for the framebuffer if the
framebuffer resides in the first 4 MB of ST-RAM, for now. This is easily
disabled by reverting the relevant piece of code back to its old state
(preserving the changes to the virt/phys translation).

So far, I've only tested this on a patched version of ARAnyM, using Andreas'
SkipSTRAM or LoadToFastRAM options. 

Code path for external framebuffer has not been changed - this code relies on
the user passing the address of an external VGA framebuffer to the kernel, 
and should continue to work as normal. 

The use of special ST-RAM virt/phys translation helpers somewhat complicates
the addition of code to deal with Videl-compatible hardware that uses a
dedicated video RAM chunk distinct from ST-RAM. Not sure how to work around
that. 

Cheers,

	Michael
 

^ permalink raw reply	[flat|nested] 18+ messages in thread

* [PATCH 1/2] m68k/atari - stram: alloc ST-RAM pool even if kernel not in ST-RAM
  2014-03-19  7:23 [PATCH 1/2] m68k/atari - stram: alloc ST-RAM pool even if kernel not in ST-RAM Michael Schmitz
                   ` (4 preceding siblings ...)
  2014-03-22  8:47 ` [PATCH 0/2] m68k/atari - make atafb work with kernel loaded to FastRAM Michael Schmitz
@ 2014-03-22  8:47 ` Michael Schmitz
  2014-03-22  8:47 ` [PATCH 2/2] m68k/atari - atafb: convert allocation of fb ram to new interface Michael Schmitz
  6 siblings, 0 replies; 18+ messages in thread
From: Michael Schmitz @ 2014-03-22  8:47 UTC (permalink / raw)
  To: linux-m68k; +Cc: geert, debian-68k, Michael Schmitz

With the kernel loaded to FastRAM (TT-RAM), none of the ST-RAM
address range is mapped by init_mem, and ST-RAM is not accessible
through the normal allocation pathways as a result.

Implement ST-RAM pool allocation to be based on physical addresses
always (it already was when the kernel was loaded in ST-RAM).
Return kernel virtual addresses as per normal.

The current test for the kernel residing in ST-RAM always returns
true. Use the bootinfo memory chunk order instead - with the kernel
in FastRAM, ST-RAM (phys. 0x0) is not the first chunk.

Instead of mucking around with ioremap (which appears to
rely on the physical area being mappped by mem_init), use
the initial mapping of the first 16 MB of address space
to 0xFF000000, done in head.S.

Provide helper functions for those users of ST-RAM that need
to be aware of the backing physical addresses.

Kudos to Geert for his hints on getting this started.

Signed-off-by: Michael Schmitz <schmitz@debian.org>
---
 arch/m68k/atari/stram.c             |   50 ++++++++++++++++++++++++----------
 arch/m68k/include/asm/atari_stram.h |    2 +
 2 files changed, 37 insertions(+), 15 deletions(-)

diff --git a/arch/m68k/atari/stram.c b/arch/m68k/atari/stram.c
index 0810c8d..441330e 100644
--- a/arch/m68k/atari/stram.c
+++ b/arch/m68k/atari/stram.c
@@ -47,6 +47,7 @@ static struct resource stram_pool = {
 
 static unsigned long pool_size = 1024*1024;
 
+static unsigned long stram_virt_offset = 0;
 
 static int __init atari_stram_setup(char *arg)
 {
@@ -67,14 +68,12 @@ early_param("stram_pool", atari_stram_setup);
 void __init atari_stram_init(void)
 {
 	int i;
-	void *stram_start;
 
 	/*
 	 * determine whether kernel code resides in ST-RAM
 	 * (then ST-RAM is the first memory block at virtual 0x0)
 	 */
-	stram_start = phys_to_virt(0);
-	kernel_in_stram = (stram_start == 0);
+	kernel_in_stram = (m68k_memory[0].addr == 0);
 
 	for (i = 0; i < m68k_num_memory; ++i) {
 		if (m68k_memory[i].addr == 0) {
@@ -93,21 +92,42 @@ void __init atari_stram_init(void)
  */
 void __init atari_stram_reserve_pages(void *start_mem)
 {
-	/*
-	 * always reserve first page of ST-RAM, the first 2 KiB are
-	 * supervisor-only!
-	 */
-	if (!kernel_in_stram)
-		reserve_bootmem(0, PAGE_SIZE, BOOTMEM_DEFAULT);
-
-	stram_pool.start = (resource_size_t)alloc_bootmem_low_pages(pool_size);
+	if (kernel_in_stram) {
+		printk("atari_stram pool: kernel in ST-RAM, using alloc_bootmem!\n");
+		stram_pool.start = (resource_size_t)alloc_bootmem_low_pages(pool_size);
+
+	} else {
+		printk("atari_stram pool: kernel not in ST-RAM, using ioremap!\n");
+		/*
+		 * Skip page 0, as the fhe first 2 KiB are supervisor-only!
+		 */
+		stram_pool.start = PAGE_SIZE;
+		/*
+		 * Use the virtual address we mapped the first 16 MB of address
+		 * space at in head.S
+		 * Caution: this is mapped nocache/serialized!
+		 */
+		stram_virt_offset = (unsigned long) 0xFF000000;
+  	}
 	stram_pool.end = stram_pool.start + pool_size - 1;
 	request_resource(&iomem_resource, &stram_pool);
+	printk("atari_stram pool: size = %lu bytes, resource = %pR\n",
+		pool_size, &stram_pool);
+	printk("atari_stram pool: start = %p, end = %p\n",
+		(void *) stram_pool.start, (void *) stram_pool.end);		
+	printk("atari_stram pool: stram_virt_offset = %p\n",
+		(void *) stram_virt_offset);		
+}
 
-	pr_debug("atari_stram pool: size = %lu bytes, resource = %pR\n",
-		 pool_size, &stram_pool);
+void *atari_stram_to_virt(unsigned long phys)
+{
+	return (void *)(phys + stram_virt_offset);
 }
 
+unsigned long atari_stram_to_phys(void *virt)
+{
+	return (unsigned long)(virt - stram_virt_offset);
+}
 
 void *atari_stram_alloc(unsigned long size, const char *owner)
 {
@@ -134,14 +154,14 @@ void *atari_stram_alloc(unsigned long size, const char *owner)
 	}
 
 	pr_debug("atari_stram_alloc: returning %pR\n", res);
-	return (void *)res->start;
+	return atari_stram_to_virt(res->start);
 }
 EXPORT_SYMBOL(atari_stram_alloc);
 
 
 void atari_stram_free(void *addr)
 {
-	unsigned long start = (unsigned long)addr;
+	unsigned long start = atari_stram_to_phys(addr);
 	struct resource *res;
 	unsigned long size;
 
diff --git a/arch/m68k/include/asm/atari_stram.h b/arch/m68k/include/asm/atari_stram.h
index 62e2759..4e771c2 100644
--- a/arch/m68k/include/asm/atari_stram.h
+++ b/arch/m68k/include/asm/atari_stram.h
@@ -8,6 +8,8 @@
 /* public interface */
 void *atari_stram_alloc(unsigned long size, const char *owner);
 void atari_stram_free(void *);
+void *atari_stram_to_virt(unsigned long phys);
+unsigned long atari_stram_to_phys(void *);
 
 /* functions called internally by other parts of the kernel */
 void atari_stram_init(void);
-- 
1.7.0.4

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH 2/2] m68k/atari - atafb: convert allocation of fb ram to new interface
  2014-03-19  7:23 [PATCH 1/2] m68k/atari - stram: alloc ST-RAM pool even if kernel not in ST-RAM Michael Schmitz
                   ` (5 preceding siblings ...)
  2014-03-22  8:47 ` [PATCH 1/2] m68k/atari - stram: alloc ST-RAM pool even if kernel not in ST-RAM Michael Schmitz
@ 2014-03-22  8:47 ` Michael Schmitz
  6 siblings, 0 replies; 18+ messages in thread
From: Michael Schmitz @ 2014-03-22  8:47 UTC (permalink / raw)
  To: linux-m68k; +Cc: geert, debian-68k, Michael Schmitz

The new atari_stram_alloc interface returns kernel virtual addresses
even if the kernel runs in FastRAM. These addresses are not
guaranteed to be identical with the physical addresses. Since ST-RAM
mappings have not been set up by mem_init, virt_to_phys() and its
cousin do not work and the atari_stram_to_phys() etc. helpers must
be used to determine physical addresses.
fb.fix->smem_start needs physical addresses, fb.par->screen_base
needs virtual addresses. Take care of the virt-to-phys conversion
both on fb init and par changes.

Signed-off-by: Michael Schmitz <schmitz@debian.org>
---
 drivers/video/atafb.c |   27 +++++++++++++++++----------
 1 files changed, 17 insertions(+), 10 deletions(-)

diff --git a/drivers/video/atafb.c b/drivers/video/atafb.c
index e21d1f5..b0d3e42 100644
--- a/drivers/video/atafb.c
+++ b/drivers/video/atafb.c
@@ -790,7 +790,7 @@ static void tt_get_par(struct atafb_par *par)
 	addr = ((shifter.bas_hi & 0xff) << 16) |
 	       ((shifter.bas_md & 0xff) << 8)  |
 	       ((shifter.bas_lo & 0xff));
-	par->screen_base = phys_to_virt(addr);
+	par->screen_base = atari_stram_to_virt(addr);
 }
 
 static void tt_set_par(struct atafb_par *par)
@@ -1584,7 +1584,7 @@ static void falcon_get_par(struct atafb_par *par)
 	addr = (shifter.bas_hi & 0xff) << 16 |
 	       (shifter.bas_md & 0xff) << 8  |
 	       (shifter.bas_lo & 0xff);
-	par->screen_base = phys_to_virt(addr);
+	par->screen_base = atari_stram_to_virt(addr);
 
 	/* derived parameters */
 	hw->ste_mode = (hw->f_shift & 0x510) == 0 && hw->st_shift == 0x100;
@@ -1980,7 +1980,7 @@ static void stste_get_par(struct atafb_par *par)
 	       ((shifter.bas_md & 0xff) << 8);
 	if (ATARIHW_PRESENT(EXTD_SHIFTER))
 		addr |= (shifter.bas_lo & 0xff);
-	par->screen_base = phys_to_virt(addr);
+	par->screen_base = atari_stram_to_virt(addr);
 }
 
 static void stste_set_par(struct atafb_par *par)
@@ -2039,7 +2039,7 @@ static int stste_detect(void)
 static void stste_set_screen_base(void *s_base)
 {
 	unsigned long addr;
-	addr = virt_to_phys(s_base);
+	addr = atari_stram_to_phys(s_base);
 	/* Setup Screen Memory */
 	shifter.bas_hi = (unsigned char)((addr & 0xff0000) >> 16);
 	shifter.bas_md = (unsigned char)((addr & 0x00ff00) >> 8);
@@ -2286,7 +2286,7 @@ static void set_screen_base(void *s_base)
 {
 	unsigned long addr;
 
-	addr = virt_to_phys(s_base);
+	addr = atari_stram_to_phys(s_base);
 	/* Setup Screen Memory */
 	shifter.bas_hi = (unsigned char)((addr & 0xff0000) >> 16);
 	shifter.bas_md = (unsigned char)((addr & 0x00ff00) >> 8);
@@ -2433,7 +2433,8 @@ static void atafb_set_disp(struct fb_info *info)
 	atafb_get_var(&info->var, info);
 	atafb_get_fix(&info->fix, info);
 
-	info->screen_base = (void *)info->fix.smem_start;
+	/* Note: smem_start derives from real_screen_base, not screen_base! */
+	info->screen_base = atari_stram_to_virt(info->fix.smem_start);
 }
 
 static int atafb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
@@ -3166,15 +3167,21 @@ int __init atafb_init(void)
 		memset(screen_base, 0, mem_req);
 		pad = -(unsigned long)screen_base & (PAGE_SIZE - 1);
 		screen_base += pad;
-		real_screen_base = screen_base + ovsc_offset;
+		real_screen_base = (void *) atari_stram_to_phys(screen_base + ovsc_offset);
 		screen_len = (mem_req - pad - ovsc_offset) & PAGE_MASK;
 		st_ovsc_switch();
 		if (CPU_IS_040_OR_060) {
 			/* On a '040+, the cache mode of video RAM must be set to
 			 * write-through also for internal video hardware! */
-			cache_push(virt_to_phys(screen_base), screen_len);
-			kernel_set_cachemode(screen_base, screen_len,
-					     IOMAP_WRITETHROUGH);
+			if ((unsigned long) screen_base & 0xFF000000) {
+				/* If the kernel is not residing in ST-RAM, we use 
+				 * the mapping set up in head.S for the low 4MB of
+				 * ST-RAM. This mapping is nocache/serialized so 
+				 * no tweaking of cache mode is needed here */
+				cache_push(atari_stram_to_phys(screen_base), screen_len);
+				kernel_set_cachemode(screen_base, screen_len,
+						     IOMAP_WRITETHROUGH);
+			}        
 		}
 		printk("atafb: screen_base %p real_screen_base %p screen_len %d\n",
 			screen_base, real_screen_base, screen_len);
-- 
1.7.0.4

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* Re: [PATCH 0/2] m68k/atari - make atafb work with kernel loaded to FastRAM
  2014-03-22  8:47 ` [PATCH 0/2] m68k/atari - make atafb work with kernel loaded to FastRAM Michael Schmitz
@ 2014-03-23  0:28   ` schmitz
  0 siblings, 0 replies; 18+ messages in thread
From: schmitz @ 2014-03-23  0:28 UTC (permalink / raw)
  To: linux-m68k; +Cc: geert, debian-68k

Michael Schmitz wrote:
> So far, I've only tested this on a patched version of ARAnyM, using Andreas'
> SkipSTRAM or LoadToFastRAM options. 
>   
Works just fine on my Falcon with CT60. Would be nice to have this 
tested on a stock Falcon, or TT.

Cheers,

    Michael

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH 1/2] m68k/atari - stram: alloc ST-RAM pool even if kernel not in ST-RAM
  2014-03-22  1:32       ` schmitz
@ 2014-03-23 20:02         ` Geert Uytterhoeven
  0 siblings, 0 replies; 18+ messages in thread
From: Geert Uytterhoeven @ 2014-03-23 20:02 UTC (permalink / raw)
  To: schmitz; +Cc: Michael Schmitz, Linux/m68k, Debian m68k, Michael Schmitz

Hi Michael,

On Sat, Mar 22, 2014 at 2:32 AM, schmitz
<schmitz@biophys.uni-duesseldorf.de> wrote:
>>>> That's not true. E.g. I/O memory is never mapped by mem_init().
>>>>
>>>
>>> Why, then, does the ioremap() of ST-RAM fail? Because the physical
>>> address
>>> is lower than the lowest currently mapped physical address?
>>
>> I don't know. How does it fail?
>
> Example:
>
> Unable to handle kernel access at virtual address 5f435059
> Oops: 00000000
> Modules linked in:
> PC: [<00089552>] kmem_cache_alloc+0x12/0x9a
> SR: 2700  SP: 0029dec0  a2: 002a42d8
> d0: 000080d0    d1: 00000013    d2: 000080d0    d3: 0007fe3c
> d4: 00000001    d5: 000000d0    a0: 5f435055    a1: 002a75ee

This may be too early in the boot process to call ioremap().

Gr{oetje,eeting}s,

                        Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

^ permalink raw reply	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2014-03-23 20:02 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-03-19  7:23 [PATCH 1/2] m68k/atari - stram: alloc ST-RAM pool even if kernel not in ST-RAM Michael Schmitz
2014-03-19  7:23 ` [PATCH 2/2] m68k/atari - atafb: convert allocation of fb ram to new interface Michael Schmitz
2014-03-19  8:01   ` Geert Uytterhoeven
2014-03-20  8:17     ` schmitz
2014-03-20  8:33       ` Geert Uytterhoeven
2014-03-22  1:28         ` schmitz
2014-03-22  7:36           ` schmitz
2014-03-19  7:51 ` [PATCH 1/2] m68k/atari - stram: alloc ST-RAM pool even if kernel not in ST-RAM Geert Uytterhoeven
2014-03-20  8:23   ` schmitz
2014-03-20  8:35     ` Geert Uytterhoeven
2014-03-22  1:32       ` schmitz
2014-03-23 20:02         ` Geert Uytterhoeven
2014-03-19  8:18 ` Andreas Schwab
2014-03-20  6:35 ` Patrice Mandin
2014-03-22  8:47 ` [PATCH 0/2] m68k/atari - make atafb work with kernel loaded to FastRAM Michael Schmitz
2014-03-23  0:28   ` schmitz
2014-03-22  8:47 ` [PATCH 1/2] m68k/atari - stram: alloc ST-RAM pool even if kernel not in ST-RAM Michael Schmitz
2014-03-22  8:47 ` [PATCH 2/2] m68k/atari - atafb: convert allocation of fb ram to new interface Michael Schmitz

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.