2001-11-09 12:05:29

by Bakonyi Ferenc

[permalink] [raw]
Subject: [PATCH] hgafb oopses


Hi!

Somebody submitted a patch against 2.4.13 which broke hgafb. That patch
called isa_memset() and isa_writeb() with an _already_ mapped address.
So that address was mapped twice -> oops.

The patch below is against 2.4.15-pre1. It resolves the ISA address
confusion, replaces scr_{read|write} functions with isa_{read|write},
and elimiates a cosmetic compiler warning about suggested parens.

Best regards:
Ferenc Bakonyi



--- linux-2.4.15-pre1/drivers/video/hgafb.c Fri Nov 9 12:22:42 2001
+++ linux/drivers/video/hgafb.c Fri Nov 9 12:26:33 2001
@@ -312,10 +312,10 @@
static int __init hga_card_detect(void)
{
int count=0;
- u16 *p, p_save;
- u16 *q, q_save;
+ unsigned char p, p_save;
+ unsigned char q, q_save;

- hga_vram_base = VGA_MAP_MEM(0xb0000);
+ hga_vram_base = 0xb0000;
hga_vram_len = 0x08000;

if (request_region(0x3b0, 12, "hgafb"))
@@ -325,14 +325,14 @@

/* do a memory check */

- p = (u16 *) hga_vram_base;
- q = (u16 *) (hga_vram_base + 0x01000);
+ p = hga_vram_base;
+ q = hga_vram_base + 0x01000;

- p_save = scr_readw(p); q_save = scr_readw(q);
+ p_save = isa_readw(p); q_save = isa_readw(q);

- scr_writew(0xaa55, p); if (scr_readw(p) == 0xaa55) count++;
- scr_writew(0x55aa, p); if (scr_readw(p) == 0x55aa) count++;
- scr_writew(p_save, p);
+ isa_writew(0xaa55, p); if (isa_readw(p) == 0xaa55) count++;
+ isa_writew(0x55aa, p); if (isa_readw(p) == 0x55aa) count++;
+ isa_writew(p_save, p);

if (count != 2) {
return 0;
@@ -717,7 +717,7 @@
if (!nologo) hga_show_logo();
#endif /* MODULE */

- hga_fix.smem_start = hga_vram_base;
+ hga_fix.smem_start = VGA_MAP_MEM(hga_vram_base);
hga_fix.smem_len = hga_vram_len;

disp.var = hga_default_var;
@@ -795,7 +795,7 @@
if (!options || !*options)
return 0;

- while (this_opt = strsep(&options, ",")) {
+ while ((this_opt = strsep(&options, ","))) {
if (!strncmp(this_opt, "font:", 5))
strcpy(fb_info.fontname, this_opt+5);
}


2001-11-12 07:28:52

by Geert Uytterhoeven

[permalink] [raw]
Subject: Re: [PATCH] hgafb oopses

On Fri, 9 Nov 2001, Bakonyi Ferenc wrote:
> Somebody submitted a patch against 2.4.13 which broke hgafb. That patch
> called isa_memset() and isa_writeb() with an _already_ mapped address.
> So that address was mapped twice -> oops.

Sorry... Anyway, the old code was broken too, since it wasn't portable.

(Why did no one told me? I did receive an additional patch to make hgafb work
again after I posted the first version to linux-kernel, which I did
incorporate in the final version).

> The patch below is against 2.4.15-pre1. It resolves the ISA address
> confusion, replaces scr_{read|write} functions with isa_{read|write},
> and elimiates a cosmetic compiler warning about suggested parens.

But it does some other Bad Things(TM): putting ISA memory _adresses_ and
_16_bit_ values in _unsigned_chars_ is not good for your health...

> --- linux-2.4.15-pre1/drivers/video/hgafb.c Fri Nov 9 12:22:42 2001
> +++ linux/drivers/video/hgafb.c Fri Nov 9 12:26:33 2001
> @@ -312,10 +312,10 @@
> static int __init hga_card_detect(void)
> {
> int count=0;
> - u16 *p, p_save;
> - u16 *q, q_save;
> + unsigned char p, p_save;
> + unsigned char q, q_save;
^^^^^^^^^^^^^
>
> - hga_vram_base = VGA_MAP_MEM(0xb0000);
> + hga_vram_base = 0xb0000;
> hga_vram_len = 0x08000;
>
> if (request_region(0x3b0, 12, "hgafb"))
> @@ -325,14 +325,14 @@
>
> /* do a memory check */
>
> - p = (u16 *) hga_vram_base;
> - q = (u16 *) (hga_vram_base + 0x01000);
> + p = hga_vram_base;
> + q = hga_vram_base + 0x01000;
>
> - p_save = scr_readw(p); q_save = scr_readw(q);
> + p_save = isa_readw(p); q_save = isa_readw(q);
>
> - scr_writew(0xaa55, p); if (scr_readw(p) == 0xaa55) count++;
> - scr_writew(0x55aa, p); if (scr_readw(p) == 0x55aa) count++;
> - scr_writew(p_save, p);
> + isa_writew(0xaa55, p); if (isa_readw(p) == 0xaa55) count++;
> + isa_writew(0x55aa, p); if (isa_readw(p) == 0x55aa) count++;
> + isa_writew(p_save, p);

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

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

2001-11-12 12:29:36

by Bakonyi Ferenc

[permalink] [raw]
Subject: Re: [PATCH] hgafb oopses


Hi!

On Mon, 12 Nov 2001, Geert Uytterhoeven wrote:
>
> Sorry... Anyway, the old code was broken too, since it wasn't portable.
>

Is it portable now? Can you test it on non-i386?

> > The patch below is against 2.4.15-pre1. It resolves the ISA address
> > confusion, replaces scr_{read|write} functions with isa_{read|write},
> > and elimiates a cosmetic compiler warning about suggested parens.

> But it does some other Bad Things(TM): putting ISA memory _adresses_ and
> _16_bit_ values in _unsigned_chars_ is not good for your health...

There is no mercy for my brain-damage, patch follows.

Regards:
Ferenc Bakonyi


--- linux-2.4.15-pre3/drivers/video/hgafb.c Mon Nov 12 13:16:32 2001
+++ linux/drivers/video/hgafb.c Mon Nov 12 13:15:56 2001
@@ -312,8 +312,8 @@
static int __init hga_card_detect(void)
{
int count=0;
- unsigned char p, p_save;
- unsigned char q, q_save;
+ unsigned long p, q;
+ unsigned short p_save, q_save;

hga_vram_base = 0xb0000;
hga_vram_len = 0x08000;

2001-11-12 12:34:36

by Geert Uytterhoeven

[permalink] [raw]
Subject: Re: [PATCH] hgafb oopses

On Mon, 12 Nov 2001, Bakonyi Ferenc wrote:
> On Mon, 12 Nov 2001, Geert Uytterhoeven wrote:
> > Sorry... Anyway, the old code was broken too, since it wasn't portable.
>
> Is it portable now? Can you test it on non-i386?

Unfortunately not. I don't have HGA hardware.

All I can do is read the code and comment :-)

> > > The patch below is against 2.4.15-pre1. It resolves the ISA address
> > > confusion, replaces scr_{read|write} functions with isa_{read|write},
> > > and elimiates a cosmetic compiler warning about suggested parens.
>
> > But it does some other Bad Things(TM): putting ISA memory _adresses_ and
> > _16_bit_ values in _unsigned_chars_ is not good for your health...
>
> There is no mercy for my brain-damage, patch follows.
>
> --- linux-2.4.15-pre3/drivers/video/hgafb.c Mon Nov 12 13:16:32 2001
> +++ linux/drivers/video/hgafb.c Mon Nov 12 13:15:56 2001
> @@ -312,8 +312,8 @@
> static int __init hga_card_detect(void)
> {
> int count=0;
> - unsigned char p, p_save;
> - unsigned char q, q_save;
> + unsigned long p, q;
> + unsigned short p_save, q_save;
>
> hga_vram_base = 0xb0000;
> hga_vram_len = 0x08000;

Thanks, that looks better!

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

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