qic02 modularization

Tekno Soft Snc (MC3641@mclink.it)
Mon, 20 May 96 19:05:00 CEST


This patch modularize the QIC02 driver

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

--- drivers/char/tpqic02.c.old Mon May 20 15:59:09 1996
+++ drivers/char/tpqic02.c Mon May 20 18:09:29 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 (TeknoSOFT
s.n.c.)
+ *
* 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>
@@ -333,8 +338,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 +2259,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 +2446,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;
@@ -2913,12 +2925,26 @@

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");
+ 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) {
@@ -2933,6 +2959,9 @@
#ifndef CONFIG_QIC02_DYNCONF
free_irq(QIC02_TAPE_IRQ, NULL);
free_dma(QIC02_TAPE_DMA);
+#ifdef MODULE
+ kfree((void *)qic02_tape_buf);
+#endif
#endif
return -ENODEV;
}
@@ -2949,6 +2978,9 @@
status_dead = YES;
free_irq(QIC02_TAPE_IRQ, NULL);
free_dma(QIC02_TAPE_DMA);
+#ifdef MODULE
+ kfree((void *)qic02_tape_buf);
+#endif
unregister_chrdev(QIC02_TAPE_MAJOR, TPQIC02_NAME);
return -ENODEV;
} else {
@@ -2972,3 +3004,17 @@
return 0;
} /* qic02_tape_init */

+#ifdef MODULE
+int init_module(void)
+{
+ return qic02_tape_init();
+}
+
+void cleanup_module(void)
+{
+ free_irq(QIC02_TAPE_IRQ, NULL);
+ free_dma(QIC02_TAPE_DMA);
+ kfree((void *)qic02_tape_buf);
+ unregister_chrdev(QIC02_TAPE_MAJOR, TPQIC02_NAME);
+}
+#endif /* MODULE */
--- drivers/char/Config.in.old Mon May 20 16:41:35 1996
+++ drivers/char/Config.in Mon May 20 16:41:35 1996
@@ -23,8 +23,8 @@
tristate 'ATIXL busmouse support' CONFIG_ATIXL_BUSMOUSE
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!'
--- drivers/char/Makefile.old Mon May 20 16:46:52 1996
+++ drivers/char/Makefile Mon May 20 16:46:52 1996
@@ -156,8 +156,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)
--- include/linux/tpqic02.h.old Mon May 20 17:11:43 1996
+++ include/linux/tpqic02.h Mon May 20 18:36:27 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 ----

--
Roberto Fichera - email MC3641@mclink.it
TeknoSOFT s.n.c. - ITALY