modular qic02 patch for 2.0.1

Tekno Soft Snc (MC3641@mclink.it)
Mon, 5 Aug 96 19:03:55 CEST


Hi All,

This is the patch for modularized QIC-02 tape driver, aligned
to 2.0.11.

--- cut here --- cut here --- cut here --- cut here --- cut here --- cut
here
diff -u --recursive --new-file -x=.* linux-2.0.11/drivers/char/Config.in
linux-2.0.11/drivers/char/Config.in
--- linux-2.0.11/drivers/char/Config.in Mon Aug 5 15:35:24 1996
+++ linux-2.0.11/drivers/char/Config.in Mon Aug 5 15:42:06 1996
@@ -29,8 +29,8 @@

bool 'Support for user misc device modules' CONFIG_UMISC

-bool 'QIC-02 tape support' CONFIG_QIC02_TAPE
-if [ "$CONFIG_QIC02_TAPE" = "y" ]; then
+tristate 'QIC-02 tape support' CONFIG_QIC02_TAPE
+if [ "$CONFIG_QIC02_TAPE" != "n" ]; then
bool 'Do you want runtime configuration for QIC-02'
CONFIG_QIC02_DYNCONF
if [ "$CONFIG_QIC02_DYNCONF" != "y" ]; then
comment 'Edit configuration parameters in ./include/linux/tpqic02.h!'
diff -u --recursive --new-file -x=.* linux-2.0.11/drivers/char/Makefile
linux-2.0.11/drivers/char/Makefile
--- linux-2.0.11/drivers/char/Makefile Mon Aug 5 15:35:24 1996
+++ linux-2.0.11/drivers/char/Makefile Mon Aug 5 15:42:06 1996
@@ -160,8 +160,12 @@
L_OBJS += rtc.o
endif

-ifdef CONFIG_QIC02_TAPE
-L_OBJS += tpqic02.o
+ifeq ($(CONFIG_QIC02_TAPE),y)
+ L_OBJS += tpqic02.o
+else
+ ifeq ($(CONFIG_QIC02_TAPE),m)
+ M_OBJS += tpqic02.o
+ endif
endif

ifeq ($(CONFIG_FTAPE),y)
diff -u --recursive --new-file -x=.* linux-2.0.11/drivers/char/tpqic02.c
linux-2.0.11/drivers/char/tpqic02.c
--- linux-2.0.11/drivers/char/tpqic02.c Fri Mar 1 04:50:41 1996
+++ linux-2.0.11/drivers/char/tpqic02.c Mon Aug 5 15:42:06 1996
@@ -34,6 +34,9 @@
* You are not allowed to change this line nor the text above.
*
* $Log: tpqic02.c,v $
+ * Revision 0.4.1.6 1996/05/20 16:00:00
+ * Modularized. Roberto Fichera - mc3641@mclink.it
+ *
* Revision 0.4.1.5 1994/10/29 02:46:13 root
* Minor cleanups.
*
@@ -200,6 +203,8 @@

#define REALLY_SLOW_IO /* it sure is ... */

+#include <linux/module.h>
+#include <linux/malloc.h>
#include <linux/sched.h>
#include <linux/timer.h>
#include <linux/fs.h>
@@ -212,6 +217,7 @@
#include <linux/tpqic02.h>
#include <linux/config.h>
#include <linux/mm.h>
+#include <linux/ioport.h>

#include <asm/dma.h>
#include <asm/system.h>
@@ -333,8 +339,12 @@
* at 512 bytes, to prevent problems with 64k boundaries.
*/

+#ifndef MODULE
static volatile char qic02_tape_buf[TPQBUF_SIZE+TAPE_BLKSIZE];
/* A really good compiler would be able to align this at 512 bytes... :-(
*/
+#else
+static volatile char *qic02_tape_buf=(char *)NULL;
+#endif

static unsigned long buffaddr; /* aligned physical address of buffer */

@@ -2250,6 +2260,7 @@
unsigned short dens = 0;
int s;

+ MOD_INC_USE_COUNT;

if (TP_DIAGS(dev)) {
printk("qic02_tape_open: dev=%s, flags=%x ",
@@ -2436,6 +2447,8 @@
if (TP_DIAGS(dev))
printk("qic02_tape_release: dev=%s\n",
kdevname(dev));
+
+ MOD_DEC_USE_COUNT;

if (status_zombie==YES) /* don't rewind in zombie mode */
return;
@@ -2814,6 +2827,7 @@
{
free_irq(QIC02_TAPE_IRQ, NULL);
free_dma(QIC02_TAPE_DMA);
+ release_region(QIC02_TAPE_PORT, 4);
status_zombie = YES;
} /* qic02_release_resources */

@@ -2851,6 +2865,19 @@
return -1;
}

+ /* Check the request IO region */
+ if (check_region(QIC02_TAPE_PORT, 4) < 0) {
+ printk(TPQIC02_NAME ": can't allocate I/O region
0x%04x-0x%04x for QIC-02 tape",
+ QIC02_TAPE_PORT, QIC02_TAPE_PORT+4);
+ free_irq(QIC02_TAPE_IRQ, NULL);
+ free_dma(QIC02_TAPE_DMA);
+ status_zombie = YES;
+ return -1;
+ }
+
+ /* Now we can allocate the requested IO region */
+ request_region(QIC02_TAPE_PORT, 4, "QIC-02");
+
printk(TPQIC02_NAME ": Settings: IRQ %d, DMA %d, IO 0x%x, IFC
%s\n",
QIC02_TAPE_IRQ, QIC02_TAPE_DMA,
((QIC02_TAPE_IFC==ARCHIVE) || (QIC02_TAPE_IFC==MOUNTAIN))?
@@ -2913,16 +2940,39 @@

printk(TPQIC02_NAME ": DMA buffers: %u blocks", NR_BLK_BUF);

+#ifdef MODULE
+ /* On a module we must allocate the buffer in low memory */
+ qic02_tape_buf = (char
*)kmalloc((size_t)(TPQBUF_SIZE+TAPE_BLKSIZE), GFP_DMA);
+ if (qic02_tape_buf == (char *)NULL) {
+ printk (TPQIC02_NAME ": kmalloc() failed to allocate
low-memory\n");
+ free_irq(QIC02_TAPE_IRQ, NULL);
+ free_dma(QIC02_TAPE_DMA);
+ release_region(QIC02_TAPE_PORT, 4);
+ return -ENODEV;
+ }
+#endif
+
/* Setup the page-address for the dma transfer.
* This assumes a one-to-one identity mapping between
* kernel addresses and physical memory.
*/
+#ifndef MODULE
buffaddr = align_buffer((unsigned long) &qic02_tape_buf,
TAPE_BLKSIZE);
printk(", at address 0x%lx (0x%lx)\n", buffaddr, (unsigned long)
&qic02_tape_buf);
+#else
+ buffaddr = align_buffer((unsigned long) qic02_tape_buf,
TAPE_BLKSIZE);
+ printk(", at address 0x%lx (0x%lx)\n", buffaddr, (unsigned long)
&qic02_tape_buf);
+#endif

#ifndef CONFIG_MAX_16M
if (buffaddr+TPQBUF_SIZE>=0x1000000) {
printk(TPQIC02_NAME ": DMA buffer *must* be in lower
16MB\n");
+ free_irq(QIC02_TAPE_IRQ, NULL);
+ free_dma(QIC02_TAPE_DMA);
+ release_region(QIC02_TAPE_PORT, 4);
+#ifdef MODULE
+ kfree((void *)qic02_tape_buf);
+#endif
return -ENODEV;
}
#endif
@@ -2933,6 +2983,10 @@
#ifndef CONFIG_QIC02_DYNCONF
free_irq(QIC02_TAPE_IRQ, NULL);
free_dma(QIC02_TAPE_DMA);
+ release_region(QIC02_TAPE_PORT, 4);
+#ifdef MODULE
+ kfree((void *)qic02_tape_buf);
+#endif
#endif
return -ENODEV;
}
@@ -2949,6 +3003,10 @@
status_dead = YES;
free_irq(QIC02_TAPE_IRQ, NULL);
free_dma(QIC02_TAPE_DMA);
+ release_region(QIC02_TAPE_PORT, 4);
+#ifdef MODULE
+ kfree((void *)qic02_tape_buf);
+#endif
unregister_chrdev(QIC02_TAPE_MAJOR, TPQIC02_NAME);
return -ENODEV;
} else {
@@ -2972,3 +3030,20 @@
return 0;
} /* qic02_tape_init */

+#ifdef MODULE
+int init_module(void)
+{
+ printk("tpqic02.c:v0.2 21/05/96 modularized version
MC3641@mclink.it\n");
+
+ return qic02_tape_init();
+}
+
+void cleanup_module(void)
+{
+ free_irq(QIC02_TAPE_IRQ, NULL);
+ free_dma(QIC02_TAPE_DMA);
+ release_region(QIC02_TAPE_PORT, 4);
+ kfree((void *)qic02_tape_buf);
+ unregister_chrdev(QIC02_TAPE_MAJOR, TPQIC02_NAME);
+}
+#endif /* MODULE */
diff -u --recursive --new-file -x=.* linux-2.0.11/include/linux/tpqic02.h
linux-2.0.11/include/linux/tpqic02.h
--- linux-2.0.11/include/linux/tpqic02.h Wed Apr 3 10:09:00 1996
+++ linux-2.0.11/include/linux/tpqic02.h Mon Aug 5 15:42:07 1996
@@ -12,7 +12,8 @@

#include <linux/config.h>

-#if CONFIG_QIC02_TAPE
+#if CONFIG_QIC02_TAPE || \
+ CONFIG_QIC02_TAPE_MODULE

/* need to have QIC02_TAPE_DRIVE and QIC02_TAPE_IFC expand to something
*/
#include <linux/mtio.h>

--- cut here --- cut here --- cut here --- cut here --- cut here --- cut
here

--
Roberto Fichera - email MC3641@mclink.it