aboutsummaryrefslogtreecommitdiff
path: root/sys/i386/isa/aic7770.c
blob: 4848e9941cb853a173724c2cdef72f4f67668e1a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/*
 * Product specific probe and attach routines for:
 * 	27/284X and aic7770 motherboard SCSI controllers
 *
 * Copyright (c) 1995 Justin T. Gibbs
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice immediately at the beginning of the file, without modification,
 *    this list of conditions, and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. Absolutely no warranty of function or purpose is made by the author
 *    Justin T. Gibbs.
 * 4. Modifications may be freely made to this file if the above conditions
 *    are met.
 *
 *	aic7770.c,v 1.14 1995/05/30 08:01:15 rgrimes Exp
 */

#include <sys/param.h>
#include <sys/systm.h>
#include <i386/isa/isa.h>
#include <i386/isa/isa_device.h>
#include <scsi/scsi_all.h>
#include <scsi/scsiconf.h>
#include <sys/devconf.h>
#include <machine/cpufunc.h>
#include <i386/scsi/aic7xxx.h>

int	aic7770probe __P((struct isa_device *dev));
int	aic7770_attach __P((struct isa_device *dev));

/*
 * Standard EISA Host ID regs  (Offset from slot base)
 */

#define HID0		0xC80	/* 0,1: msb of ID2, 2-7: ID1      */
#define HID1		0xC81	/* 0-4: ID3, 5-7: LSB ID2         */
#define HID2		0xC82	/* product                        */
#define HID3		0xC83	/* firmware revision              */

#define CHAR1(B1,B2) (((B1>>2) & 0x1F) | '@')
#define CHAR2(B1,B2) (((B1<<3) & 0x18) | ((B2>>5) & 0x7)|'@')
#define CHAR3(B1,B2) ((B2 & 0x1F) | '@')

#define	EISA_MAX_SLOTS	16	/* XXX should be defined in a common header */
static	ahc_slot = 0;		/* slot last board was found in */

struct isa_driver ahcdriver = {aic7770probe, aic7770_attach, "ahc"};

typedef struct
{
  ahc_type type;
  unsigned char id; /* The Last EISA Host ID reg */
} aic7770_sig;

static struct kern_devconf kdc_aic7770[NAHC] = { {
	0, 0, 0,                /* filled in by dev_attach */
	"ahc", 0, { MDDT_ISA, 0, "bio" },
	isa_generic_externalize, 0, 0, ISA_EXTERNALLEN,
	&kdc_isa0,		/* parent */
	0,			/* parentdata */
	DC_UNCONFIGURED,	/* always start out here */
	"Adaptec aic7770 based SCSI host adapter",
	DC_CLS_MISC		/* host adapters aren't special */
} };

static inline void
aic7770_registerdev(struct isa_device *id)
{
	if(id->id_unit)
		kdc_aic7770[id->id_unit] = kdc_aic7770[0];
	kdc_aic7770[id->id_unit].kdc_unit = id->id_unit;
	kdc_aic7770[id->id_unit].kdc_parentdata = id;
	dev_attach(&kdc_aic7770[id->id_unit]);
}

int
aic7770probe(struct isa_device *dev)
{
        u_long  port;
	int	i;
        u_char  sig_id[4];

	aic7770_sig valid_ids[] = {
	/* Entries of other tested adaptors should be added here */
		{ AHC_274, 0x71 }, /*274x*/
		{ AHC_274, 0x70 }, /*aic7770 on Motherboard*/
		{ AHC_284, 0x56 }, /*284x, BIOS enabled*/
		{ AHC_284, 0x57 }  /*284x, BIOS disabled*/
	};


        ahc_slot++;
        while (ahc_slot < EISA_MAX_SLOTS) {
                port = 0x1000 * ahc_slot;
		for( i = 0; i < sizeof(sig_id); i++ )
		{
		       /*
			* An outb is required to prime these registers on
			* VL cards
			*/
		        outb( port + HID0, HID0 + i );
                        sig_id[i] = inb(port + HID0 + i);
		}
                if (sig_id[0] == 0xff) {
                        ahc_slot++;
                        continue;
                }
		/* Check manufacturer's ID. */
		if ((CHAR1(sig_id[0], sig_id[1]) == 'A')
		    && (CHAR2(sig_id[0], sig_id[1]) == 'D')
		    && (CHAR3(sig_id[0], sig_id[1]) == 'P')
		    && (sig_id[2] == 0x77)) {
			for(i=0; i < sizeof(valid_ids)/sizeof(aic7770_sig);i++)
                        	if ( sig_id[3] == valid_ids[i].id ) {
					int unit = dev->id_unit;
		                        dev->id_iobase = port;
#ifndef DEV_LKM
					aic7770_registerdev(dev);
#endif /* DEV_LKM */
               			        if(ahcprobe(unit, port,
						  valid_ids[i].type)){
					        /*
					         * If it's there, put in it's
						 * interrupt vectors
					         */
					        dev->id_irq = (1 <<
							ahcdata[unit]->vect);
					        dev->id_drq = -1; /* EISA dma */
				        	ahc_unit++;
					        return IO_EISASIZE;
	                   		}
				}
		}
                ahc_slot++;
        }
        return 0;
}

int
aic7770_attach(dev)
        struct isa_device *dev;
{
        int     unit = dev->id_unit;
	kdc_aic7770[unit].kdc_state = DC_BUSY; /* host adapters always busy */
	return ahc_attach(unit);
}