Commit 56a47da1b940b6d3812de67fd94af9bfda6ee93a

Authored by Maciej W. Rozycki
Committed by Ralf Baechle
1 parent b454cc6636

[TC] MIPS: TURBOchannel resources off-by-one fix

Fix resource reservation of TURBOchannel areas, where the end is one byte
too far.

Signed-off-by: Maciej W. Rozycki <macro@linux-mips.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Ralf Baechle <ralf@linux-mips.org>

Showing 1 changed file with 2 additions and 2 deletions Inline Diff

1 /* 1 /*
2 * TURBOchannel bus services. 2 * TURBOchannel bus services.
3 * 3 *
4 * Copyright (c) Harald Koerfgen, 1998 4 * Copyright (c) Harald Koerfgen, 1998
5 * Copyright (c) 2001, 2003, 2005, 2006 Maciej W. Rozycki 5 * Copyright (c) 2001, 2003, 2005, 2006 Maciej W. Rozycki
6 * Copyright (c) 2005 James Simmons 6 * Copyright (c) 2005 James Simmons
7 * 7 *
8 * This file is subject to the terms and conditions of the GNU 8 * This file is subject to the terms and conditions of the GNU
9 * General Public License. See the file "COPYING" in the main 9 * General Public License. See the file "COPYING" in the main
10 * directory of this archive for more details. 10 * directory of this archive for more details.
11 */ 11 */
12 #include <linux/compiler.h> 12 #include <linux/compiler.h>
13 #include <linux/errno.h> 13 #include <linux/errno.h>
14 #include <linux/init.h> 14 #include <linux/init.h>
15 #include <linux/ioport.h> 15 #include <linux/ioport.h>
16 #include <linux/kernel.h> 16 #include <linux/kernel.h>
17 #include <linux/list.h> 17 #include <linux/list.h>
18 #include <linux/module.h> 18 #include <linux/module.h>
19 #include <linux/string.h> 19 #include <linux/string.h>
20 #include <linux/tc.h> 20 #include <linux/tc.h>
21 #include <linux/types.h> 21 #include <linux/types.h>
22 22
23 #include <asm/io.h> 23 #include <asm/io.h>
24 24
25 static struct tc_bus tc_bus = { 25 static struct tc_bus tc_bus = {
26 .name = "TURBOchannel", 26 .name = "TURBOchannel",
27 }; 27 };
28 28
29 /* 29 /*
30 * Probing for TURBOchannel modules. 30 * Probing for TURBOchannel modules.
31 */ 31 */
32 static void __init tc_bus_add_devices(struct tc_bus *tbus) 32 static void __init tc_bus_add_devices(struct tc_bus *tbus)
33 { 33 {
34 resource_size_t slotsize = tbus->info.slot_size << 20; 34 resource_size_t slotsize = tbus->info.slot_size << 20;
35 resource_size_t extslotsize = tbus->ext_slot_size; 35 resource_size_t extslotsize = tbus->ext_slot_size;
36 resource_size_t slotaddr; 36 resource_size_t slotaddr;
37 resource_size_t extslotaddr; 37 resource_size_t extslotaddr;
38 resource_size_t devsize; 38 resource_size_t devsize;
39 void __iomem *module; 39 void __iomem *module;
40 struct tc_dev *tdev; 40 struct tc_dev *tdev;
41 int i, slot, err; 41 int i, slot, err;
42 u8 pattern[4]; 42 u8 pattern[4];
43 long offset; 43 long offset;
44 44
45 for (slot = 0; slot < tbus->num_tcslots; slot++) { 45 for (slot = 0; slot < tbus->num_tcslots; slot++) {
46 slotaddr = tbus->slot_base + slot * slotsize; 46 slotaddr = tbus->slot_base + slot * slotsize;
47 extslotaddr = tbus->ext_slot_base + slot * extslotsize; 47 extslotaddr = tbus->ext_slot_base + slot * extslotsize;
48 module = ioremap_nocache(slotaddr, slotsize); 48 module = ioremap_nocache(slotaddr, slotsize);
49 BUG_ON(!module); 49 BUG_ON(!module);
50 50
51 offset = TC_OLDCARD; 51 offset = TC_OLDCARD;
52 52
53 err = 0; 53 err = 0;
54 err |= tc_preadb(pattern + 0, module + offset + TC_PATTERN0); 54 err |= tc_preadb(pattern + 0, module + offset + TC_PATTERN0);
55 err |= tc_preadb(pattern + 1, module + offset + TC_PATTERN1); 55 err |= tc_preadb(pattern + 1, module + offset + TC_PATTERN1);
56 err |= tc_preadb(pattern + 2, module + offset + TC_PATTERN2); 56 err |= tc_preadb(pattern + 2, module + offset + TC_PATTERN2);
57 err |= tc_preadb(pattern + 3, module + offset + TC_PATTERN3); 57 err |= tc_preadb(pattern + 3, module + offset + TC_PATTERN3);
58 if (err) 58 if (err)
59 goto out_err; 59 goto out_err;
60 60
61 if (pattern[0] != 0x55 || pattern[1] != 0x00 || 61 if (pattern[0] != 0x55 || pattern[1] != 0x00 ||
62 pattern[2] != 0xaa || pattern[3] != 0xff) { 62 pattern[2] != 0xaa || pattern[3] != 0xff) {
63 offset = TC_NEWCARD; 63 offset = TC_NEWCARD;
64 64
65 err = 0; 65 err = 0;
66 err |= tc_preadb(pattern + 0, 66 err |= tc_preadb(pattern + 0,
67 module + offset + TC_PATTERN0); 67 module + offset + TC_PATTERN0);
68 err |= tc_preadb(pattern + 1, 68 err |= tc_preadb(pattern + 1,
69 module + offset + TC_PATTERN1); 69 module + offset + TC_PATTERN1);
70 err |= tc_preadb(pattern + 2, 70 err |= tc_preadb(pattern + 2,
71 module + offset + TC_PATTERN2); 71 module + offset + TC_PATTERN2);
72 err |= tc_preadb(pattern + 3, 72 err |= tc_preadb(pattern + 3,
73 module + offset + TC_PATTERN3); 73 module + offset + TC_PATTERN3);
74 if (err) 74 if (err)
75 goto out_err; 75 goto out_err;
76 } 76 }
77 77
78 if (pattern[0] != 0x55 || pattern[1] != 0x00 || 78 if (pattern[0] != 0x55 || pattern[1] != 0x00 ||
79 pattern[2] != 0xaa || pattern[3] != 0xff) 79 pattern[2] != 0xaa || pattern[3] != 0xff)
80 goto out_err; 80 goto out_err;
81 81
82 /* Found a board, allocate it an entry in the list */ 82 /* Found a board, allocate it an entry in the list */
83 tdev = kzalloc(sizeof(*tdev), GFP_KERNEL); 83 tdev = kzalloc(sizeof(*tdev), GFP_KERNEL);
84 if (!tdev) { 84 if (!tdev) {
85 printk(KERN_ERR "tc%x: unable to allocate tc_dev\n", 85 printk(KERN_ERR "tc%x: unable to allocate tc_dev\n",
86 slot); 86 slot);
87 goto out_err; 87 goto out_err;
88 } 88 }
89 sprintf(tdev->dev.bus_id, "tc%x", slot); 89 sprintf(tdev->dev.bus_id, "tc%x", slot);
90 tdev->bus = tbus; 90 tdev->bus = tbus;
91 tdev->dev.parent = &tbus->dev; 91 tdev->dev.parent = &tbus->dev;
92 tdev->dev.bus = &tc_bus_type; 92 tdev->dev.bus = &tc_bus_type;
93 tdev->slot = slot; 93 tdev->slot = slot;
94 94
95 for (i = 0; i < 8; i++) { 95 for (i = 0; i < 8; i++) {
96 tdev->firmware[i] = 96 tdev->firmware[i] =
97 readb(module + offset + TC_FIRM_VER + 4 * i); 97 readb(module + offset + TC_FIRM_VER + 4 * i);
98 tdev->vendor[i] = 98 tdev->vendor[i] =
99 readb(module + offset + TC_VENDOR + 4 * i); 99 readb(module + offset + TC_VENDOR + 4 * i);
100 tdev->name[i] = 100 tdev->name[i] =
101 readb(module + offset + TC_MODULE + 4 * i); 101 readb(module + offset + TC_MODULE + 4 * i);
102 } 102 }
103 tdev->firmware[8] = 0; 103 tdev->firmware[8] = 0;
104 tdev->vendor[8] = 0; 104 tdev->vendor[8] = 0;
105 tdev->name[8] = 0; 105 tdev->name[8] = 0;
106 106
107 pr_info("%s: %s %s %s\n", tdev->dev.bus_id, tdev->vendor, 107 pr_info("%s: %s %s %s\n", tdev->dev.bus_id, tdev->vendor,
108 tdev->name, tdev->firmware); 108 tdev->name, tdev->firmware);
109 109
110 devsize = readb(module + offset + TC_SLOT_SIZE); 110 devsize = readb(module + offset + TC_SLOT_SIZE);
111 devsize <<= 22; 111 devsize <<= 22;
112 if (devsize <= slotsize) { 112 if (devsize <= slotsize) {
113 tdev->resource.start = slotaddr; 113 tdev->resource.start = slotaddr;
114 tdev->resource.end = slotaddr + devsize - 1; 114 tdev->resource.end = slotaddr + devsize - 1;
115 } else if (devsize <= extslotsize) { 115 } else if (devsize <= extslotsize) {
116 tdev->resource.start = extslotaddr; 116 tdev->resource.start = extslotaddr;
117 tdev->resource.end = extslotaddr + devsize - 1; 117 tdev->resource.end = extslotaddr + devsize - 1;
118 } else { 118 } else {
119 printk(KERN_ERR "%s: Cannot provide slot space " 119 printk(KERN_ERR "%s: Cannot provide slot space "
120 "(%dMiB required, up to %dMiB supported)\n", 120 "(%dMiB required, up to %dMiB supported)\n",
121 tdev->dev.bus_id, devsize >> 20, 121 tdev->dev.bus_id, devsize >> 20,
122 max(slotsize, extslotsize) >> 20); 122 max(slotsize, extslotsize) >> 20);
123 kfree(tdev); 123 kfree(tdev);
124 goto out_err; 124 goto out_err;
125 } 125 }
126 tdev->resource.name = tdev->name; 126 tdev->resource.name = tdev->name;
127 tdev->resource.flags = IORESOURCE_MEM; 127 tdev->resource.flags = IORESOURCE_MEM;
128 128
129 tc_device_get_irq(tdev); 129 tc_device_get_irq(tdev);
130 130
131 device_register(&tdev->dev); 131 device_register(&tdev->dev);
132 list_add_tail(&tdev->node, &tbus->devices); 132 list_add_tail(&tdev->node, &tbus->devices);
133 133
134 out_err: 134 out_err:
135 iounmap(module); 135 iounmap(module);
136 } 136 }
137 } 137 }
138 138
139 /* 139 /*
140 * The main entry. 140 * The main entry.
141 */ 141 */
142 static int __init tc_init(void) 142 static int __init tc_init(void)
143 { 143 {
144 /* Initialize the TURBOchannel bus */ 144 /* Initialize the TURBOchannel bus */
145 if (tc_bus_get_info(&tc_bus)) 145 if (tc_bus_get_info(&tc_bus))
146 return 0; 146 return 0;
147 147
148 INIT_LIST_HEAD(&tc_bus.devices); 148 INIT_LIST_HEAD(&tc_bus.devices);
149 strcpy(tc_bus.dev.bus_id, "tc"); 149 strcpy(tc_bus.dev.bus_id, "tc");
150 device_register(&tc_bus.dev); 150 device_register(&tc_bus.dev);
151 151
152 if (tc_bus.info.slot_size) { 152 if (tc_bus.info.slot_size) {
153 unsigned int tc_clock = tc_get_speed(&tc_bus) / 100000; 153 unsigned int tc_clock = tc_get_speed(&tc_bus) / 100000;
154 154
155 pr_info("tc: TURBOchannel rev. %d at %d.%d MHz " 155 pr_info("tc: TURBOchannel rev. %d at %d.%d MHz "
156 "(with%s parity)\n", tc_bus.info.revision, 156 "(with%s parity)\n", tc_bus.info.revision,
157 tc_clock / 10, tc_clock % 10, 157 tc_clock / 10, tc_clock % 10,
158 tc_bus.info.parity ? "" : "out"); 158 tc_bus.info.parity ? "" : "out");
159 159
160 tc_bus.resource[0].start = tc_bus.slot_base; 160 tc_bus.resource[0].start = tc_bus.slot_base;
161 tc_bus.resource[0].end = tc_bus.slot_base + 161 tc_bus.resource[0].end = tc_bus.slot_base +
162 (tc_bus.info.slot_size << 20) * 162 (tc_bus.info.slot_size << 20) *
163 tc_bus.num_tcslots; 163 tc_bus.num_tcslots - 1;
164 tc_bus.resource[0].name = tc_bus.name; 164 tc_bus.resource[0].name = tc_bus.name;
165 tc_bus.resource[0].flags = IORESOURCE_MEM; 165 tc_bus.resource[0].flags = IORESOURCE_MEM;
166 if (request_resource(&iomem_resource, 166 if (request_resource(&iomem_resource,
167 &tc_bus.resource[0]) < 0) { 167 &tc_bus.resource[0]) < 0) {
168 printk(KERN_ERR "tc: Cannot reserve resource\n"); 168 printk(KERN_ERR "tc: Cannot reserve resource\n");
169 return 0; 169 return 0;
170 } 170 }
171 if (tc_bus.ext_slot_size) { 171 if (tc_bus.ext_slot_size) {
172 tc_bus.resource[1].start = tc_bus.ext_slot_base; 172 tc_bus.resource[1].start = tc_bus.ext_slot_base;
173 tc_bus.resource[1].end = tc_bus.ext_slot_base + 173 tc_bus.resource[1].end = tc_bus.ext_slot_base +
174 tc_bus.ext_slot_size * 174 tc_bus.ext_slot_size *
175 tc_bus.num_tcslots; 175 tc_bus.num_tcslots - 1;
176 tc_bus.resource[1].name = tc_bus.name; 176 tc_bus.resource[1].name = tc_bus.name;
177 tc_bus.resource[1].flags = IORESOURCE_MEM; 177 tc_bus.resource[1].flags = IORESOURCE_MEM;
178 if (request_resource(&iomem_resource, 178 if (request_resource(&iomem_resource,
179 &tc_bus.resource[1]) < 0) { 179 &tc_bus.resource[1]) < 0) {
180 printk(KERN_ERR 180 printk(KERN_ERR
181 "tc: Cannot reserve resource\n"); 181 "tc: Cannot reserve resource\n");
182 release_resource(&tc_bus.resource[0]); 182 release_resource(&tc_bus.resource[0]);
183 return 0; 183 return 0;
184 } 184 }
185 } 185 }
186 186
187 tc_bus_add_devices(&tc_bus); 187 tc_bus_add_devices(&tc_bus);
188 } 188 }
189 189
190 return 0; 190 return 0;
191 } 191 }
192 192
193 subsys_initcall(tc_init); 193 subsys_initcall(tc_init);
194 194