2002-02-07 03:09:34

by Anton Altaparmakov

[permalink] [raw]
Subject: [PATCH] Fix floppy io ports reservation

Hi,

Below is a patch that fixes the io ports reservation of the floppy driver
as the one in the driver is actually incorrect and this clashes with the
(correct) reservation by the PNPBIOS driver.

I asked a friend to check and on his Windows 2000 system the port
reservation was 0x3f2-0x3f5 + 0x3f7, i.e. it just excludes ports
0x3f0-0x3f1, which are NOT used anywhere in the driver anyway.

This patch works for me on ia32 (Pentium 4), however I am not 100% sure it
will work on all architectures. From a quick look I would say it will work
but I may have missed something...

Before I get flamed for this patch being a hack, yes it is a bit of a
hack, but the full solution involving changing of the actual base
address and all the offsets to the base is a huge patch and involves
changing quite a bit of architecture specific code in non-obvious ways.
(Most non-obvious are the changes to Sparc, Sparc64, mips, mips64 and
m68k, the rest of the arch are a piece of cake.)

I would suggest that people give this patch a go, especially on non-ia32
arch and let us all know if it doesn't work. Perhaps best would be to
include it in the next -pre kernels and see if anyone screams. (-:

Almost forgot, patch is against 2.4.18-pre7-ac2 but I would think it will
apply to any 2.4 and probably 2.5 kernel.

Best regards,

Anton
--
Anton Altaparmakov <aia21 at cam.ac.uk> (replace at with @)
Linux NTFS maintainer / WWW: http://linux-ntfs.sf.net/
ICQ: 8561279 / WWW: http://www-stu.christs.cam.ac.uk/~aia21/

---floppy.diff---
--- l/drivers/block/floppy.c Thu Jan 31 18:16:20 2002
+++ linux-2.4.18-pre7-ac2-vanilla/drivers/block/floppy.c Thu Feb 7 02:35:07 2002
@@ -129,6 +129,12 @@
* floppy controller (lingering task on list after module is gone... boom.)
*/

+/*
+ * 2002/02/07 -- Anton Altaparmakov - Fix io ports reservation to correct range
+ * (0x3f2-0x3f5, 0x3f7). This fix is a bit of a hack but the proper fix
+ * requires many non-obvious changes in arch dependent code.
+ */
+
#define FLOPPY_SANITY_CHECK
#undef FLOPPY_SILENT_DCL_CLEAR

@@ -4229,7 +4235,7 @@
FDCS->rawcmd = 2;
if (user_reset_fdc(-1,FD_RESET_ALWAYS,0)){
/* free ioports reserved by floppy_grab_irq_and_dma() */
- release_region(FDCS->address, 6);
+ release_region(FDCS->address+2, 4);
release_region(FDCS->address+7, 1);
FDCS->address = -1;
FDCS->version = FDC_NONE;
@@ -4239,7 +4245,7 @@
FDCS->version = get_fdc_version();
if (FDCS->version == FDC_NONE){
/* free ioports reserved by floppy_grab_irq_and_dma() */
- release_region(FDCS->address, 6);
+ release_region(FDCS->address+2, 4);
release_region(FDCS->address+7, 1);
FDCS->address = -1;
continue;
@@ -4318,11 +4324,11 @@

for (fdc=0; fdc< N_FDC; fdc++){
if (FDCS->address != -1){
- if (!request_region(FDCS->address, 6, "floppy")) {
- DPRINT("Floppy io-port 0x%04lx in use\n", FDCS->address);
+ if (!request_region(FDCS->address+2, 4, "floppy")) {
+ DPRINT("Floppy io-port 0x%04lx in use\n", FDCS->address + 2);
goto cleanup1;
}
- if (!request_region(FDCS->address + 7, 1, "floppy DIR")) {
+ if (!request_region(FDCS->address+7, 1, "floppy DIR")) {
DPRINT("Floppy io-port 0x%04lx in use\n", FDCS->address + 7);
goto cleanup2;
}
@@ -4350,12 +4356,12 @@
irqdma_allocated = 1;
return 0;
cleanup2:
- release_region(FDCS->address, 6);
+ release_region(FDCS->address + 2, 4);
cleanup1:
fd_free_irq();
fd_free_dma();
while(--fdc >= 0) {
- release_region(FDCS->address, 6);
+ release_region(FDCS->address + 2, 4);
release_region(FDCS->address + 7, 1);
}
MOD_DEC_USE_COUNT;
@@ -4422,7 +4428,7 @@
old_fdc = fdc;
for (fdc = 0; fdc < N_FDC; fdc++)
if (FDCS->address != -1) {
- release_region(FDCS->address, 6);
+ release_region(FDCS->address+2, 4);
release_region(FDCS->address+7, 1);
}
fdc = old_fdc;


2002-02-07 20:25:14

by Guest section DW

[permalink] [raw]
Subject: Re: [PATCH] Fix floppy io ports reservation

On Thu, Feb 07, 2002 at 03:09:08AM +0000, Anton Altaparmakov wrote:

> Below is a patch that fixes the io ports reservation of the floppy driver
> as the one in the driver is actually incorrect and this clashes with the
> (correct) reservation by the PNPBIOS driver.
>
> I asked a friend to check and on his Windows 2000 system the port
> reservation was 0x3f2-0x3f5 + 0x3f7, i.e. it just excludes ports
> 0x3f0-0x3f1, which are NOT used anywhere in the driver anyway.

ports 0x3f0 and 0x3f1 are used on certain PS/2 systems
and on some very old AT clones

2002-02-07 21:58:57

by Alan

[permalink] [raw]
Subject: Re: [PATCH] Fix floppy io ports reservation

> > I asked a friend to check and on his Windows 2000 system the port
> > reservation was 0x3f2-0x3f5 + 0x3f7, i.e. it just excludes ports
> > 0x3f0-0x3f1, which are NOT used anywhere in the driver anyway.
>
> ports 0x3f0 and 0x3f1 are used on certain PS/2 systems
> and on some very old AT clones

The driver must only reserve those ports on machines which needed them and
when it needs them (which it never actually does). The ports are used for
other superio related things on newer machines

2002-02-08 00:05:07

by Anton Altaparmakov

[permalink] [raw]
Subject: Re: [PATCH] Fix floppy io ports reservation

At 20:24 07/02/02, Guest section DW wrote:
>On Thu, Feb 07, 2002 at 03:09:08AM +0000, Anton Altaparmakov wrote:
> > Below is a patch that fixes the io ports reservation of the floppy driver
> > as the one in the driver is actually incorrect and this clashes with the
> > (correct) reservation by the PNPBIOS driver.
> >
> > I asked a friend to check and on his Windows 2000 system the port
> > reservation was 0x3f2-0x3f5 + 0x3f7, i.e. it just excludes ports
> > 0x3f0-0x3f1, which are NOT used anywhere in the driver anyway.
>
>ports 0x3f0 and 0x3f1 are used on certain PS/2 systems

Can you point me to the code for the PS/2 systems in question? I fail to
see instances where anything less than 0x3f2 is used. Assuming such code is
present and I have just missed it, perhaps we can find a way to detect such
cases and only then register the ports.

>and on some very old AT clones

And we care because? AT = 80286 CPU in the definition I am aware of, which
Linux doesn't support and catering for unsupported hardware seems silly.
(-; But perhaps you meant something else by "AT clones"?

btw. Today I got a chance to check Windows XP Pro and that like Win2k only
uses ports 0x3f2-0x3f5 and 0x3f7. As I have never heard of anyone
complaining their floppy doesn't work with Windows (except for that Tyan
BIOS bug a few years ago that is...), it would appear it is quite safe to
do the same in the linux floppy driver...

FYI: Just skimmed through the WinXP floppy source (what a windows driver is
not closed source? YES, it is in the DDK, they obviously don't think it
worth hiding...(-:). Anyway, they never use 0x3f0-0x3f1 either AFAICS and
in fact there is an interesting comment in the source:

---quote from pdc.c---
The PC97(98) hardware specification defines only 3f2, 3f4, and 3f5 as
io port resources for standard floppy controllers (based on IBM PC floppy
controller configurations). In addition to these resources, fdc.sys
requires 3f7 for disk change detection and data rate programming and
optionally 3f3 for floppy tape support. In addition, some bioses define
aliased resources (e.g. 3f2 & 7f2, etc.)
---end of quote---

Best regards,

Anton


--
"I've not lost my mind. It's backed up on tape somewhere." - Unknown
--
Anton Altaparmakov <aia21 at cam.ac.uk> (replace at with @)
Linux NTFS Maintainer / WWW: http://linux-ntfs.sf.net/
ICQ: 8561279 / WWW: http://www-stu.christs.cam.ac.uk/~aia21/

2002-02-08 00:16:57

by Anton Altaparmakov

[permalink] [raw]
Subject: Re: [PATCH] Fix floppy io ports reservation

At 21:54 07/02/02, Alan Cox wrote:
> > > I asked a friend to check and on his Windows 2000 system the port
> > > reservation was 0x3f2-0x3f5 + 0x3f7, i.e. it just excludes ports
> > > 0x3f0-0x3f1, which are NOT used anywhere in the driver anyway.
> >
> > ports 0x3f0 and 0x3f1 are used on certain PS/2 systems
> > and on some very old AT clones
>
>The driver must only reserve those ports on machines which needed them and
>when it needs them (which it never actually does). The ports are used for
>other superio related things on newer machines

Indeed, I couldn't find any code making use of the 0x3f0 and 0x3f1 ports,
hence why I put forward my patch... If someone would like to prove me wrong
here, please do so. (-:

Best regards,

Anton


--
"I've not lost my mind. It's backed up on tape somewhere." - Unknown
--
Anton Altaparmakov <aia21 at cam.ac.uk> (replace at with @)
Linux NTFS Maintainer / WWW: http://linux-ntfs.sf.net/
ICQ: 8561279 / WWW: http://www-stu.christs.cam.ac.uk/~aia21/

2002-02-08 00:25:39

by Thomas Hood

[permalink] [raw]
Subject: Re: [PATCH] Fix floppy io ports reservation

Alan Cox wrote:
>ports 0x3f0 and 0x3f1 are used on certain PS/2 systems

Anton Altaparmakov wrote:
> Can you point me to the code for the PS/2 systems in
> question? I fail to see instances where anything less
> than 0x3f2 is used.

ports 0x3f0 and 0x3f1 were floppy-related on PS/2 systems,
but the current Linux floppy driver makes no use of
these ports under any circumstances.




2002-02-08 15:24:13

by Guest section DW

[permalink] [raw]
Subject: Re: [PATCH] Fix floppy io ports reservation

>> ports 0x3f0 and 0x3f1 are used on certain PS/2 systems
>> and on some very old AT clones
>
> [PS/2] Can you point me to the code for the PS/2 systems in question?
> [AT] And we care because?

You need not worry - these systems have been dead for over fifteen years.

2002-02-08 21:42:46

by Ian Molton

[permalink] [raw]
Subject: Re: [PATCH] Fix floppy io ports reservation

On a sunny Fri, 8 Feb 2002 16:23:48 +0100 Guest section DW gathered a sheaf
of electrons and etched in their motions the following immortal words:

> >> ports 0x3f0 and 0x3f1 are used on certain PS/2 systems
> >> and on some very old AT clones
> >
> > [PS/2] Can you point me to the code for the PS/2 systems in question?
> > [AT] And we care because?
>
> You need not worry - these systems have been dead for over fifteen years.

I dont like that attitude. I have a system that has been 'dead' for a while
(its now 15 years old), and I'm 're'-porting linux to it (Acorn A400).

Linux is meant to be fun, not just 'latest X86 crap'.

Not to say that we should restrict anything for old hardware, but it doesnt
hurt to spare a thought for it. Doing so may even encourage people to write
better code.