diff options
Diffstat (limited to 'include/linux/un.h')
0 files changed, 0 insertions, 0 deletions
![]() |
index : litmus-rt.git | |
The LITMUS^RT kernel. | Bjoern Brandenburg |
aboutsummaryrefslogtreecommitdiffstats |
/* ps2esdi driver based on assembler code by Arindam Banerji,
written by Peter De Schrijver */
/* Reassuring note to IBM : This driver was NOT developed by vice-versa
engineering the PS/2's BIOS */
/* Dedicated to Wannes, Tofke, Ykke, Godot, Killroy and all those
other lovely fish out there... */
/* This code was written during the long and boring WINA
elections 1994 */
/* Thanks to Arindam Banerij for giving me the source of his driver */
/* This code may be freely distributed and modified in any way,
as long as these notes remain intact */
/* Revised: 05/07/94 by Arindam Banerji (axb@cse.nd.edu) */
/* Revised: 09/08/94 by Peter De Schrijver (stud11@cc4.kuleuven.ac.be)
Thanks to Arindam Banerij for sending me the docs of the adapter */
/* BA Modified for ThinkPad 720 by Boris Ashkinazi */
/* (bash@vnet.ibm.com) 08/08/95 */
/* Modified further for ThinkPad-720C by Uri Blumenthal */
/* (uri@watson.ibm.com) Sep 11, 1995 */
/* TODO :
+ Timeouts
+ Get disk parameters
+ DMA above 16MB
+ reset after read/write error
*/
#define DEVICE_NAME "PS/2 ESDI"
#include <linux/major.h>
#include <linux/errno.h>
#include <linux/wait.h>
#include <linux/interrupt.h>
#include <linux/fs.h>
#include <linux/kernel.h>
#include <linux/genhd.h>
#include <linux/ps2esdi.h>
#include <linux/blkdev.h>
#include <linux/mca-legacy.h>
#include <linux/init.h>
#include <linux/ioport.h>
#include <linux/module.h>
#include <linux/hdreg.h>
#include <asm/system.h>
#include <asm/io.h>
#include <asm/dma.h>
#include <asm/mca_dma.h>
#include <asm/uaccess.h>
#define PS2ESDI_IRQ 14
#define MAX_HD 2
#define MAX_RETRIES 5
#define MAX_16BIT 65536
#define ESDI_TIMEOUT 0xf000
#define ESDI_STAT_TIMEOUT 4
#define TYPE_0_CMD_BLK_LENGTH 2
#define TYPE_1_CMD_BLK_LENGTH 4
static void reset_ctrl(void);
static int ps2esdi_geninit(void);
static void do_ps2esdi_request(request_queue_t * q);
static void ps2esdi_readwrite(int cmd, struct request *req);
static void ps2esdi_fill_cmd_block(u_short * cmd_blk, u_short cmd,
u_short cyl, u_short head, u_short sector, u_short length, u_char drive);
static int ps2esdi_out_cmd_blk(u_short * cmd_blk);
static void ps2esdi_prep_dma(char *buffer, u_short length, u_char dma_xmode);
static irqreturn_t ps2esdi_interrupt_handler(int irq, void *dev_id);
static void (*current_int_handler) (u_int) = NULL;
static void ps2esdi_normal_interrupt_handler(u_int);
static void ps2esdi_initial_reset_int_handler(u_int);
static void ps2esdi_geometry_int_handler(u_int);
static int ps2esdi_getgeo(struct block_device *bdev, struct hd_geometry *geo);
static int ps2esdi_read_status_words(int num_words, int max_words, u_short * buffer);
static void dump_cmd_complete_status(u_int int_ret_code);
static void ps2esdi_get_device_cfg(void);
static void ps2esdi_reset_timer(unsigned long unused);
static u_int dma_arb_level; /* DMA arbitration level */
static DECLARE_WAIT_QUEUE_HEAD(ps2esdi_int);
static int no_int_yet;
static int ps2esdi_drives;
static u_short io_base;
static DEFINE_TIMER(esdi_timer, ps2esdi_reset_timer, 0, 0);
static int reset_status;
static int ps2esdi_slot = -1;
static int tp720esdi = 0; /* Is it Integrated ESDI of ThinkPad-720? */
static int intg_esdi = 0; /* If integrated adapter */
struct ps2esdi_i_struct {
unsigned int head, sect, cyl, wpcom, lzone, ctl;
};
static DEFINE_SPINLOCK(ps2esdi_lock);
static struct request_queue *ps2esdi_queue;
static struct request *current_req;
#if 0
#if 0 /* try both - I don't know which one is better... UB */
static struct ps2esdi_i_struct ps2esdi_info[MAX_HD] =
{
{4, 48, 1553, 0, 0, 0},
{0, 0, 0, 0, 0, 0}};
#else
static struct ps2esdi_i_struct ps2esdi_info[MAX_HD] =
{
{64, 32, 161, 0, 0, 0},
{0, 0, 0, 0, 0, 0}};
#endif
#endif
static struct ps2esdi_i_struct ps2esdi_info[MAX_HD] =
{
{0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0}};
static struct block_device_operations ps2esdi_fops =
{
.owner = THIS_MODULE,
.getgeo = ps2esdi_getgeo,
};
static struct gendisk *ps2esdi_gendisk[2];
/* initialization routine called by ll_rw_blk.c */
static int __init ps2esdi_init(void)
{
int error = 0;
/* register the device - pass the name and major number */
if (register_blkdev(PS2ESDI_MAJOR, "ed"))
return -EBUSY;
/* set up some global information - indicating device specific info */
ps2esdi_queue = blk_init_queue(do_ps2esdi_request, &ps2esdi_lock);
if (!ps2esdi_queue) {
unregister_blkdev(PS2ESDI_MAJOR, "ed");
return -ENOMEM;
}
/* some minor housekeeping - setup the global gendisk structure */
error = ps2esdi_geninit();
if (error) {
printk(KERN_WARNING "PS2ESDI: error initialising"
" device, releasing resources\n");
unregister_blkdev(PS2ESDI_MAJOR, "ed");
blk_cleanup_queue(ps2esdi_queue);
return error;
}
return 0;
} /* ps2esdi_init */
#ifndef MODULE
module_init(ps2esdi_init);
#else
static int cyl[MAX_HD] = {-1,-1};
static int head[MAX_HD] = {-1, -1};
static int sect[MAX_HD] = {-1, -1};
module_param(tp720esdi, bool, 0);
module_param_array(cyl, int, NULL, 0);
module_param_array(head, int, NULL, 0);
module_param_array(sect, int, NULL, 0);
MODULE_LICENSE("GPL");
int init_module(void) {
int drive;
for(drive = 0; drive < MAX_HD; drive++) {
struct ps2esdi_i_struct *info = &ps2esdi_info[drive];
if (cyl[drive] != -1) {
info->cyl = info->lzone = cyl[drive];
info->wpcom = 0;
}
if (head[drive] != -1) {
info->head = head[drive];
info->ctl = (head[drive] > 8 ? 8 : 0);
}
if (sect[drive] != -1) info->sect = sect[drive];
}
return ps2esdi_init();
}
void
cleanup_module(void) {
int i;
if(ps2esdi_slot) {
mca_mark_as_unused(ps2esdi_slot);
mca_set_adapter_procfn(ps2esdi_slot, NULL, NULL);
}
release_region(io_base, 4);
free_dma(dma_arb_level);
free_irq(PS2ESDI_IRQ, &ps2esdi_gendisk);
unregister_blkdev(PS2ESDI_MAJOR, "ed");
blk_cleanup_queue(ps2esdi_queue);
for (i = 0; i < ps2esdi_drives; i++) {
del_gendisk(ps2esdi_gendisk[i]);
put_disk(ps2esdi_gendisk[i]);
}
}
#endif /* MODULE */
/* handles boot time command line parameters */
void __init tp720_setup(char *str, int *ints)
{
/* no params, just sets the tp720esdi flag if it exists */
printk("%s: TP 720 ESDI flag set\n", DEVICE_NAME);
tp720esdi = 1;
}
void __init ed_setup(char *str, int *ints)
{
int hdind = 0;
/* handles 3 parameters only - corresponding to
1. Number of cylinders
2. Number of heads
3. Sectors/track
*/
if (ints[0] != 3)
return;
/* print out the information - seen at boot time */
printk("%s: ints[0]=%d ints[1]=%d ints[2]=%d ints[3]=%d\n",
DEVICE_NAME, ints[0], ints[1], ints[2], ints[3]);
/* set the index into device specific information table */
if (ps2esdi_info[0].head != 0)
hdind = 1;
/* set up all the device information */
ps2esdi_info[hdind].head = ints[2];
ps2esdi_info[hdind].sect = ints[3];
ps2esdi_info[hdind].cyl = ints[1];
ps2esdi_info[hdind].wpcom = 0;
ps2esdi_info[hdind].lzone = ints[1];
ps2esdi_info[hdind].ctl = (ints[2] > 8 ? 8 : 0);
#if 0 /* this may be needed for PS2/Mod.80, but it hurts ThinkPad! */
ps2esdi_drives = hdind + 1; /* increment index for the next time */
#endif
} /* ed_setup */
static int ps2esdi_getinfo(char *buf, int slot, void *d)
{
int len = 0;
len += sprintf(buf + len, "DMA Arbitration Level: %d\n",
dma_arb_level);
len += sprintf(buf + len, "IO Port: %x\n", io_base);
len += sprintf(buf + len, "IRQ: 14\n");
len += sprintf(buf + len, "Drives: %d\n", ps2esdi_drives);
return len;
}
/* ps2 esdi specific initialization - called thru the gendisk chain */
static int __init ps2esdi_geninit(void)
{
/*
The first part contains the initialization code
for the ESDI disk subsystem. All we really do
is search for the POS registers of the controller
to do some simple setup operations. First, we
must ensure that the controller is installed,
enabled, and configured as PRIMARY. Then we must
determine the DMA arbitration level being used by
the controller so we can handle data transfer
operations properly. If all of this works, then
we will set the INIT_FLAG to a non-zero value.
*/
int slot = 0, i, reset_start, reset_end;
u_char status;
unsigned short adapterID;
int error = 0;
if ((slot = mca_find_adapter(INTG_ESDI_ID, 0)) != MCA_NOTFOUND) {
adapterID = INTG_ESDI_ID;
printk("%s: integrated ESDI adapter found in slot %d\n",
DEVICE_NAME, slot+1);
#ifndef MODULE
mca_set_adapter_name(slot, "PS/2 Integrated ESDI");
#endif
} else if ((slot = mca_find_adapter(NRML_ESDI_ID, 0)) != -1) {
adapterID = NRML_ESDI_ID;
printk("%s: normal ESDI adapter found in slot %d\n",
DEVICE_NAME, slot+1);
mca_set_adapter_name(slot, "PS/2 ESDI");
} else {
return -ENODEV;
}
ps2esdi_slot = slot;
mca_mark_as_used(slot);
mca_set_adapter_procfn(slot, (MCA_ProcFn) ps2esdi_getinfo, NULL);
/* Found the slot - read the POS register 2 to get the necessary
configuration and status information. POS register 2 has the
following information :
Bit Function
7 reserved = 0
6 arbitration method
0 - fairness enabled
1 - fairness disabled, linear priority assignment
5-2 arbitration level
1 alternate address
1 alternate address
0 - use addresses 0x3510 - 0x3517
0 adapter enable
*/
status = mca_read_stored_pos(slot, 2);
/* is it enabled ? */
if (!(status & STATUS_ENABLED)) {
printk("%s: ESDI adapter disabled\n", DEVICE_NAME);
error = -ENODEV;
goto err_out1;
}
/* try to grab IRQ, and try to grab a slow IRQ if it fails, so we can
share with the SCSI driver */
if (request_irq(PS2ESDI_IRQ, ps2esdi_interrupt_handler,
IRQF_DISABLED | IRQF_SHARED, "PS/2 ESDI", &ps2esdi_gendisk)
&& request_irq(PS2ESDI_IRQ, ps2esdi_interrupt_handler,
IRQF_SHARED, "PS/2 ESDI", &ps2esdi_gendisk)
) {
printk("%s: Unable to get IRQ %d\n", DEVICE_NAME, PS2ESDI_IRQ);
error = -EBUSY;
goto err_out1;
}
if (status & STATUS_ALTERNATE)
io_base = ALT_IO_BASE;
else
io_base = PRIMARY_IO_BASE;
if (!request_region(io_base, 4, "ed")) {
printk(KERN_WARNING"Unable to request region 0x%x\n", io_base);
error = -EBUSY;
goto err_out2;
}
/* get the dma arbitration level */
dma_arb_level = (status >> 2) & 0xf;
/* BA */
printk("%s: DMA arbitration level : %d\n",
DEVICE_NAME, dma_arb_level);
LITE_ON;
current_int_handler = ps2esdi_initial_reset_int_handler;
reset_ctrl();
reset_status = 0;
reset_start = jiffies;
while (!reset_status) {
init_timer(&esdi_timer);
esdi_timer.expires = jiffies + HZ;
esdi_timer.data = 0;
add_timer(&esdi_timer);
sleep_on(&ps2esdi_int);
}
reset_end = jiffies;
LITE_OFF;
printk("%s: reset interrupt after %d jiffies, %u.%02u secs\n",
DEVICE_NAME, reset_end - reset_start, (reset_end - reset_start) / HZ,
(reset_end - reset_start) % HZ);
/* Integrated ESDI Disk and Controller has only one drive! */
if (adapterID == INTG_ESDI_ID) {/* if not "normal" PS2 ESDI adapter */
ps2esdi_drives = 1; /* then we have only one physical disk! */ intg_esdi = 1;
}
/* finally this part sets up some global data structures etc. */
ps2esdi_get_device_cfg();
/* some annoyance in the above routine returns TWO drives?
Is something else happining in the background?
Regaurdless we fix the # of drives again. AJK */
/* Integrated ESDI Disk and Controller has only one drive! */
if (adapterID == INTG_ESDI_ID) /* if not "normal" PS2 ESDI adapter */
ps2esdi_drives = 1; /* Not three or two, ONE DAMNIT! */
current_int_handler = ps2esdi_normal_interrupt_handler;
if (request_dma(dma_arb_level, "ed") !=0) {
printk(KERN_WARNING "PS2ESDI: Can't request dma-channel %d\n"
,(int) dma_arb_level);
error = -EBUSY;
goto err_out3;
}
blk_queue_max_sectors(ps2esdi_queue, 128);
error = -ENOMEM;
for (i = 0; i < ps2esdi_drives; i++) {
struct gendisk *disk = alloc_disk(64);
if (!disk)
goto err_out4;
disk->major = PS2ESDI_MAJOR;
disk->first_minor = i<<6;
sprintf(disk->disk_name, "ed%c", 'a'+i);
disk->fops = &ps2esdi_fops;
ps2esdi_gendisk[i] = disk;
}
for (i = 0; i < ps2esdi_drives; i++) {
struct gendisk *disk = ps2esdi_gendisk[i];
set_capacity(disk, ps2esdi_info[i].head * ps2esdi_info[i].sect *
ps2esdi_info[i].cyl);
disk->queue = ps2esdi_queue;
disk->private_data = &ps2esdi_info[i];
add_disk(disk);
}
return 0;
err_out4:
while (i--)
put_disk(ps2esdi_gendisk[i]);
err_out3:
release_region(io_base, 4);
err_out2:
free_irq(PS2ESDI_IRQ, &ps2esdi_gendisk);
err_out1:
if(ps2esdi_slot) {
mca_mark_as_unused(ps2esdi_slot);
mca_set_adapter_procfn(ps2esdi_slot, NULL, NULL);
}
return error;
}
static void __init ps2esdi_get_device_cfg(void)
{
u_short cmd_blk[TYPE_0_CMD_BLK_LENGTH];
/*BA */ printk("%s: Drive 0\n", DEVICE_NAME);