浏览代码

Extracted from 3c509.c

tags/v0.9.3
Michael Brown 19 年前
父节点
当前提交
1aee4e8001
共有 2 个文件被更改,包括 189 次插入0 次删除
  1. 114
    0
      src/drivers/bus/mca.c
  2. 75
    0
      src/include/mca.h

+ 114
- 0
src/drivers/bus/mca.c 查看文件

@@ -0,0 +1,114 @@
1
+/*
2
+ * MCA bus driver code
3
+ *
4
+ * Abstracted from 3c509.c.
5
+ *
6
+ */
7
+
8
+#include "etherboot.h"
9
+#include "dev.h"
10
+#include "io.h"
11
+#include "mca.h"
12
+
13
+#define DEBUG_MCA
14
+
15
+#undef DBG
16
+#ifdef DEBUG_MCA
17
+#define DBG(...) printf ( __VA_ARGS__ )
18
+#else
19
+#define DBG(...)
20
+#endif
21
+
22
+/*
23
+ * Fill in parameters for an MCA device based on slot number
24
+ *
25
+ */
26
+static int fill_mca_device ( struct mca_device *mca ) {
27
+	unsigned int i;
28
+
29
+	/* Make sure motherboard setup is off */
30
+	outb_p ( 0xff, MCA_MOTHERBOARD_SETUP_REG );
31
+
32
+	/* Select the slot */
33
+	outb_p ( 0x8 | ( mca->slot & 0xf ), MCA_ADAPTER_SETUP_REG );
34
+
35
+	/* Read the POS registers */
36
+	for ( i = 0 ; i < ( sizeof ( mca->pos ) / sizeof ( mca->pos[0] ) ) ;
37
+	      i++ ) {
38
+		mca->pos[i] = inb_p ( MCA_POS_REG ( i ) );
39
+	}
40
+
41
+	/* Kill all setup modes */
42
+	outb_p ( 0, MCA_ADAPTER_SETUP_REG );
43
+
44
+	DBG ( "MCA slot %d id %hx (%hhx:%hhx:%hhx:%hhx:%hhx:%hhx:%hhx:%hhx)\n",
45
+	      mca->slot, MCA_ID ( mca ),
46
+	      mca->pos[0], mca->pos[1], mca->pos[2], mca->pos[3],
47
+	      mca->pos[4], mca->pos[5], mca->pos[6], mca->pos[7] );
48
+
49
+	return 1;
50
+}
51
+
52
+/*
53
+ * Obtain a struct mca * from a struct dev *
54
+ *
55
+ * If dev has not previously been used for an MCA device scan, blank
56
+ * out dev.mca
57
+ */
58
+struct mca_device * mca_device ( struct dev *dev ) {
59
+	struct mca_device *mca = &dev->mca;
60
+
61
+	if ( dev->devid.bus_type != MCA_BUS_TYPE ) {
62
+		memset ( mca, 0, sizeof ( *mca ) );
63
+		dev->devid.bus_type = MCA_BUS_TYPE;
64
+	}
65
+	mca->dev = dev;
66
+	return mca;
67
+}
68
+
69
+/*
70
+ * Find an MCA device matching the specified driver
71
+ *
72
+ */
73
+int find_mca_device ( struct mca_device *mca, struct mca_driver *driver ) {
74
+	unsigned int i;
75
+
76
+	/* Iterate through all possible MCA slots, starting where we
77
+	 * left off/
78
+	 */
79
+	for ( ; mca->slot < MCA_MAX_SLOT_NR ; mca->slot++ ) {
80
+		/* If we've already used this device, skip it */
81
+		if ( mca->already_tried ) {
82
+			mca->already_tried = 0;
83
+			continue;
84
+		}
85
+
86
+		/* Fill in device parameters */
87
+		if ( ! fill_mca_device ( mca ) ) {
88
+			continue;
89
+		}
90
+
91
+		/* Compare against driver's ID list */
92
+		for ( i = 0 ; i < driver->id_count ; i++ ) {
93
+			struct mca_id *id = &driver->ids[i];
94
+
95
+			if ( MCA_ID ( mca ) == id->id ) {
96
+				DBG ( "Device %s (driver %s) matches ID %hx\n",
97
+				      id->name, driver->name, id->id );
98
+				if ( mca->dev ) {
99
+					mca->dev->name = driver->name;
100
+					mca->dev->devid.vendor_id =
101
+						htons ( GENERIC_MCA_VENDOR );
102
+					mca->dev->devid.device_id =
103
+						htons ( id->id );
104
+				}
105
+				mca->already_tried = 1;
106
+				return 1;
107
+			}
108
+		}
109
+	}
110
+
111
+	/* No device found */
112
+	mca->slot = 0;
113
+	return 0;
114
+}

+ 75
- 0
src/include/mca.h 查看文件

@@ -0,0 +1,75 @@
1
+/*
2
+ * MCA bus driver code
3
+ *
4
+ * Abstracted from 3c509.c.
5
+ *
6
+ */
7
+
8
+#ifndef MCA_H
9
+#define MCA_H
10
+
11
+/*
12
+ * MCA constants
13
+ *
14
+ */
15
+
16
+#define MCA_MOTHERBOARD_SETUP_REG	0x94
17
+#define MCA_ADAPTER_SETUP_REG		0x96
18
+#define MCA_MAX_SLOT_NR			8
19
+#define MCA_POS_REG(n)			(0x100+(n))
20
+
21
+/* Is there a standard that would define this? */
22
+#include "isa.h"
23
+#define GENERIC_MCA_VENDOR ISAPNP_VENDOR ( 'M', 'C', 'A' )
24
+
25
+/*
26
+ * A physical MCA device
27
+ *
28
+ */
29
+struct dev;
30
+struct mca_device {
31
+	struct dev *dev;
32
+	unsigned int slot;
33
+	unsigned char pos[8];
34
+	int already_tried;
35
+};
36
+#define MCA_ID(mca) ( ( (mca)->pos[1] << 8 ) + (mca)->pos[0] )
37
+
38
+/*
39
+ * An individual MCA device identified by ID
40
+ *
41
+ */
42
+struct mca_id {
43
+        const char *name;
44
+        int id;
45
+};
46
+
47
+/*
48
+ * An MCA driver, with a device ID (struct mca_id) table.
49
+ *
50
+ */
51
+struct mca_driver {
52
+	const char *name;
53
+	struct mca_id *ids;
54
+	unsigned int id_count;
55
+};
56
+
57
+/*
58
+ * Define an MCA driver
59
+ *
60
+ */
61
+#define MCA_DRIVER( driver_name, mca_ids ) {			\
62
+	.name = driver_name,					\
63
+	.ids = mca_ids,						\
64
+	.id_count = sizeof ( mca_ids ) / sizeof ( mca_ids[0] ),	\
65
+}
66
+
67
+/*
68
+ * Functions in mca.c
69
+ *
70
+ */
71
+extern struct mca_device * mca_device ( struct dev *dev );
72
+extern int find_mca_device ( struct mca_device *mca,
73
+			     struct mca_driver *driver );
74
+
75
+#endif

正在加载...
取消
保存