aboutsummaryrefslogtreecommitdiffstats
path: root/recipes/linux/linux-2.6.24/hipox/ox810-pci-abort-handler.patch
blob: 321dfa9ca8e3d37e735caabf8edc27c68d478a64 (plain)
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
diff -Nurd linux-2.6.24.orig//arch/arm/mach-hipox/pci.c linux-2.6.24/arch/arm/mach-hipox/pci.c
--- linux-2.6.24.orig//arch/arm/mach-hipox/pci.c	2011-06-15 08:54:13.869073667 +0200
+++ linux-2.6.24/arch/arm/mach-hipox/pci.c	2011-06-15 08:56:11.275235253 +0200
@@ -667,6 +667,44 @@
 	.postinit		= hipox_pci_postinit,
 };
 
+static int abort_handler(unsigned long addr, unsigned int fsr, struct pt_regs *regs) 
+{
+    unsigned long pc = instruction_pointer(regs);
+    unsigned long instr = *(unsigned long *)pc;
+
+    static unsigned int mod = 1;
+
+    CheckAndClearBusError();
+
+    if ( 0 == (++mod % 100000) )
+        printk(KERN_ERR "PCI: Bus error happened %u times; last is at address 0x%lX.\n", mod,  addr);
+
+    /* set return value to -1 if this was a read */
+	if ((instr & 0x0c100000) == 0x04100000) {
+		int reg = (instr >> 12) & 15;
+		unsigned long val;
+
+		if (instr & 0x00400000)
+			val = 255; /* byte read */
+		else
+			val = -1;
+
+		regs->uregs[reg] = val;
+		regs->ARM_pc += 4;
+		return 0;
+	}
+
+	if ((instr & 0x0e100090) == 0x00100090) {
+		int reg = (instr >> 12) & 15;
+
+		regs->uregs[reg] = -1;
+		regs->ARM_pc += 4;
+		return 0;
+	}
+
+    return 0;
+}
+
 static int __init hipox_pci_init(void)
 {
 #ifdef CONFIG_HIPOX_PCI_RESET
@@ -679,6 +717,7 @@
 	printk(KERN_DEBUG "PCI: hipox_pci_init now it's %lu, will wait till %lu to become ready for config\n", pci_trhfa_startwait, pci_trhfa_timeout);
 #endif // CONFIG_HIPOX_PCI_RESET
 
+    hook_fault_code(8, abort_handler, SIGBUS, "PCI external abort on non-linefetch");
     pci_common_init(&hipox_pci);
 	return 0;
 }
diff -Nurd linux-2.6.24.orig//arch/arm/mach-hipox/smc.c linux-2.6.24/arch/arm/mach-hipox/smc.c
--- linux-2.6.24.orig//arch/arm/mach-hipox/smc.c	2011-06-15 08:54:13.869073667 +0200
+++ linux-2.6.24/arch/arm/mach-hipox/smc.c	2011-06-15 08:58:49.038353811 +0200
@@ -20,6 +20,7 @@
 
 #include <asm/io.h>
 #include <asm/hardware.h>
+#include <asm/semaphore.h>
 #include <asm/arch/smc.h>
 #include <linux/delay.h>
 #include <linux/jiffies.h>
@@ -30,7 +31,7 @@
 /*
  * Request PCI_ARB to grant access to the STATIC core.
  */
-void hipox_smc_request_pci_ad_31_0(void)
+static int _hipox_smc_request_pci_ad_31_0(void)
 {
 	unsigned maxtries = 10; /* wait for maxtries jiffies at maximum */
 
@@ -51,12 +52,14 @@
 		printk(KERN_WARNING "%s: timeout requesting access to PCI bus for static memory interface\n",  __func__);
 
 	request_pci_timestamp = ktime_get();
+
+    return ( 0 != ( readl(SYS_CTRL_PCI_STAT) & (1UL << SYSCTL_PCI_STAT_SYSPCI_STATIC_GNT) ) ? 0 : 1 );
 }
 
 /*
  * Release access to PCI bus.
  */
-void hipox_smc_release_pci_ad_31_0(void)
+static void _hipox_smc_release_pci_ad_31_0(void)
 {
 	const s64 timeout = 400; /* us */  
 	s64 delta = ktime_us_delta(ktime_get(), request_pci_timestamp);
@@ -70,5 +73,163 @@
 	}
 }
 
-EXPORT_SYMBOL(hipox_smc_request_pci_ad_31_0);
-EXPORT_SYMBOL(hipox_smc_release_pci_ad_31_0);
+/*
+ *  PCI / PNX / Flash interlock handling
+ *
+ */
+
+enum pci_semaphore_id {
+    no_one      = 0,
+    ox810_pci   = 1,
+    ox810_flash = 2,
+    remote_pci  = 3
+};
+
+DECLARE_MUTEX(_pci_bus_linux_semaphore); // don't be fooled; this actually declares a _semaphore_ (see asm-arm/semaphore.h)
+struct pci_semaphore {
+    struct semaphore      *linux_sem;   /**< lock the bus for flash or pci accesses */
+    enum pci_semaphore_id current_owner;
+    uint32_t              current_count;
+};
+
+static struct pci_semaphore _pnx_pci_semaphore = {
+    &_pci_bus_linux_semaphore,
+    no_one,
+    0
+};
+/* ---- */
+
+static int default_sem_acquire( void *ignored, uint32_t ignored2)
+{
+    return 0;
+}
+/* ---- */
+
+static int default_sem_release ( void *ignored )
+{
+    return 0;
+}
+/* ---- */
+
+static int (*pci_sem_acquire)( void * ctx, uint32_t value ) = default_sem_acquire;
+static int (*pci_sem_release)( void * ctx ) = default_sem_release;
+static void * pci_sem_context = NULL;
+
+void ox810_pci_register_semaphore_callbacks( int (*acquire)(void*, uint32_t), int (*release)(void*), void * ctx )
+{
+    pci_sem_acquire = acquire;
+    pci_sem_release = release;
+    pci_sem_context = ctx;
+}
+/* ---- */
+
+void ox810_pci_reset_semaphore_callbacks( void )
+{
+    pci_sem_acquire = default_sem_acquire;
+    pci_sem_release = default_sem_release;
+}
+/* ---- */
+
+static int sem_acquire( enum pci_semaphore_id caller_id )
+{
+    if ( 0 != down_trylock( _pnx_pci_semaphore.linux_sem ) ) {
+        if ( _pnx_pci_semaphore.current_owner == caller_id ) {
+            _pnx_pci_semaphore.current_count++;
+            return 0;
+        }
+
+        down( _pnx_pci_semaphore.linux_sem );
+    }
+
+    if ( 0 ==  pci_sem_acquire( pci_sem_context, caller_id) ) {
+
+        if (    ( caller_id == ox810_flash )
+             && ( 0 != _hipox_smc_request_pci_ad_31_0() ) ) {
+            up( _pnx_pci_semaphore.linux_sem );
+            return 1;
+        }
+
+        _pnx_pci_semaphore.current_owner = caller_id;
+        _pnx_pci_semaphore.current_count = 1;
+
+        return 0;
+    }
+
+    up( _pnx_pci_semaphore.linux_sem );
+
+    return 1;
+}
+/* ---- */
+
+static int sem_release( enum pci_semaphore_id caller_id )
+{
+    if ( _pnx_pci_semaphore.current_owner != caller_id )
+        return 1;
+
+    _pnx_pci_semaphore.current_count--;
+    if ( 0 != _pnx_pci_semaphore.current_count )
+        return 0;
+
+    if ( caller_id == ox810_flash )
+        _hipox_smc_release_pci_ad_31_0();
+
+    if ( 0 != pci_sem_release( pci_sem_context ))
+        return 1;
+
+    _pnx_pci_semaphore.current_owner = no_one;
+    up( _pnx_pci_semaphore.linux_sem );
+
+    return 0;
+}
+/* ---- */
+
+int ox810_pci_acquire_bus( void )
+{
+    return sem_acquire ( ox810_pci );
+}
+/* ---- */
+
+int ox810_pci_release_bus( void )
+{
+    return sem_release ( ox810_pci );
+}
+/* ---- */
+
+int ox810_flash_acquire_bus( void ) 
+{
+    return sem_acquire( ox810_flash );
+}
+/* ---- */
+
+int ox810_flash_release_bus( void ) 
+{
+    return sem_release( ox810_flash );
+}
+/* ---- */
+
+void hipox_smc_request_pci_ad_31_0( void )
+{
+    static uint32_t warned = 0;
+    if ( 0 == (warned++ % 10000) )
+        printk( KERN_ERR "ERROR in arch/arm/mach-hipox/smc.c: deprecated hipox_smc_request_pci_ad_31_0() called instead of ox810_flash_acquire_bus(). This interface will die soon. PLEASE UPDATE YOUR DRIVER.\n");
+    ox810_flash_acquire_bus();
+}
+void hipox_smc_release_pci_ad_31_0( void )
+{
+    static uint32_t warned = 0;
+    if ( 0 == (warned++ % 10000) )
+        printk( KERN_ERR "ERROR in arch/arm/mach-hipox/smc.c: deprecated hipox_smc_release_pci_ad_31_0() called instead of ox810_flash_release_bus(). This interface will die soon. PLEASE UPDATE YOUR DRIVER.\n");
+    ox810_flash_release_bus();
+}
+/* ---- */
+
+EXPORT_SYMBOL( hipox_smc_request_pci_ad_31_0 );
+EXPORT_SYMBOL( hipox_smc_release_pci_ad_31_0 );
+
+EXPORT_SYMBOL(ox810_pci_acquire_bus);
+EXPORT_SYMBOL(ox810_pci_release_bus);
+EXPORT_SYMBOL(ox810_flash_acquire_bus);
+EXPORT_SYMBOL(ox810_flash_release_bus);
+
+EXPORT_SYMBOL(ox810_pci_register_semaphore_callbacks);
+EXPORT_SYMBOL(ox810_pci_reset_semaphore_callbacks);
diff -Nurd linux-2.6.24.orig//drivers/mtd/maps/physmap.c linux-2.6.24/drivers/mtd/maps/physmap.c
--- linux-2.6.24.orig//drivers/mtd/maps/physmap.c	2011-06-15 08:54:14.204048457 +0200
+++ linux-2.6.24/drivers/mtd/maps/physmap.c	2011-06-15 09:12:40.775896237 +0200
@@ -22,6 +22,7 @@
 #include <linux/mtd/partitions.h>
 #include <linux/mtd/physmap.h>
 #include <asm/io.h>
+#include <asm/bug.h>
 
 #if defined (CONFIG_ARCH_HIPOX)
 #include <asm/arch/smc.h>
@@ -87,11 +88,12 @@
 
 	// printk("%s:%d would wait for hipox_flash_mutex\n", __func__, __LINE__);
 	mutex_lock(&hipox_flash_mutex);
-	hipox_smc_request_pci_ad_31_0();
+	if ( 0 != ox810_flash_acquire_bus() )
+		BUG();
 
 	ret = inline_map_read(map, ofs);
 
-	hipox_smc_release_pci_ad_31_0();
+	ox810_flash_release_bus();
 	mutex_unlock(&hipox_flash_mutex);
 	// printk("%s:%d hipox_flash_mutex unlocked\n", __func__, __LINE__);
 
@@ -102,11 +104,12 @@
 {
 	// printk("%s:%d would wait for hipox_flash_mutex\n", __func__, __LINE__);
 	mutex_lock(&hipox_flash_mutex);
-	hipox_smc_request_pci_ad_31_0();
+	if ( 0 != ox810_flash_acquire_bus() )
+		BUG();
 
 	inline_map_write(map, datum, ofs);
 
-	hipox_smc_release_pci_ad_31_0();
+	ox810_flash_release_bus();
 	mutex_unlock(&hipox_flash_mutex);
 	// printk("%s:%d hipox_flash_mutex unlocked\n", __func__, __LINE__);
 }
@@ -115,11 +118,12 @@
 {
 	// printk("%s:%d would wait for hipox_flash_mutex\n", __func__, __LINE__);
 	mutex_lock(&hipox_flash_mutex);
-	hipox_smc_request_pci_ad_31_0();
+	if ( 0 != ox810_flash_acquire_bus() )
+		BUG();
 
 	inline_map_copy_from(map, to, from, len);
 
-	hipox_smc_release_pci_ad_31_0();
+	ox810_flash_release_bus();
 	mutex_unlock(&hipox_flash_mutex);
 	// printk("%s:%d hipox_flash_mutex unlocked\n", __func__, __LINE__);
 }
@@ -128,11 +132,12 @@
 {
 	// printk("%s:%d would wait for hipox_flash_mutex\n", __func__, __LINE__);
 	mutex_lock(&hipox_flash_mutex);
-	hipox_smc_request_pci_ad_31_0();
+	if ( 0 != ox810_flash_acquire_bus() )
+		BUG();
 
 	inline_map_copy_to(map, to, from, len);
 
-	hipox_smc_release_pci_ad_31_0();
+	ox810_flash_release_bus();
 	mutex_unlock(&hipox_flash_mutex);
 	// printk("%s:%d hipox_flash_mutex unlocked\n", __func__, __LINE__);
 }
diff -Nurd linux-2.6.24.orig//drivers/mtd/nand/hipox_nand.c linux-2.6.24/drivers/mtd/nand/hipox_nand.c
--- linux-2.6.24.orig//drivers/mtd/nand/hipox_nand.c	2011-06-15 08:54:14.197048982 +0200
+++ linux-2.6.24/drivers/mtd/nand/hipox_nand.c	2011-06-15 09:07:11.675625433 +0200
@@ -23,6 +23,7 @@
 #include <linux/delay.h>
 #include <linux/mutex.h>
 #include <asm/io.h>
+#include <asm/bug.h>
 #include <asm/arch/hardware.h>
 #include <asm/arch/smc.h>
 #include <asm/sizes.h>
@@ -104,9 +105,10 @@
 
 	if (cmd != NAND_CMD_NONE)
 	{
-		hipox_smc_request_pci_ad_31_0();
+		if ( ox810_flash_acquire_bus() )
+			BUG();
 		writeb(cmd, this->IO_ADDR_W);
-		hipox_smc_release_pci_ad_31_0();
+		ox810_flash_release_bus();
 	}
 }
 
@@ -120,9 +122,13 @@
 {
 	struct nand_chip *chip = mtd->priv;
 	uint8_t res;
-	hipox_smc_request_pci_ad_31_0();
+
+	if ( ox810_flash_acquire_bus() )
+		BUG();
+
 	res = readb(chip->IO_ADDR_R);
-	hipox_smc_release_pci_ad_31_0();
+
+	ox810_flash_release_bus();
 	return res;
 }
 
@@ -137,9 +143,13 @@
 {
 	struct nand_chip *chip = mtd->priv;
 	u16 res;
-	hipox_smc_request_pci_ad_31_0();
+
+	if ( ox810_flash_acquire_bus() )
+		BUG();
+
 	res = readw(chip->IO_ADDR_R);
-	hipox_smc_release_pci_ad_31_0();
+
+	ox810_flash_release_bus();
 	return res;
 }
 
@@ -156,10 +166,13 @@
 	int i;
 	struct nand_chip *chip = mtd->priv;
 
-	hipox_smc_request_pci_ad_31_0();
+	if ( ox810_flash_acquire_bus() )
+		BUG();
+
 	for (i = 0; i < len; i++)
 		buf[i] = readb(chip->IO_ADDR_R);
-	hipox_smc_release_pci_ad_31_0();
+
+	ox810_flash_release_bus();
 }
 
 /**
@@ -175,10 +188,13 @@
 	int i;
 	struct nand_chip *chip = mtd->priv;
 
-	hipox_smc_request_pci_ad_31_0();
+	if ( ox810_flash_acquire_bus() )
+		BUG();
+
 	for (i = 0; i < len; i++)
 		writeb(buf[i], chip->IO_ADDR_W);
-	hipox_smc_release_pci_ad_31_0();
+
+	ox810_flash_release_bus();
 }
 
 /**
@@ -195,7 +211,9 @@
 	int ret = 0;
 	struct nand_chip *chip = mtd->priv;
 
-	hipox_smc_request_pci_ad_31_0();
+	if ( ox810_flash_acquire_bus() )
+		BUG();
+
 	for (i = 0; i < len; i++)
 	{
 		if (buf[i] != readb(chip->IO_ADDR_R))
@@ -204,7 +222,8 @@
 			break;
 		}
 	}
-	hipox_smc_release_pci_ad_31_0();
+
+	ox810_flash_release_bus();
 
 	return ret;
 }
diff -Nurd linux-2.6.24.orig//include/asm-arm/arch-hipox/smc.h linux-2.6.24/include/asm-arm/arch-hipox/smc.h
--- linux-2.6.24.orig//include/asm-arm/arch-hipox/smc.h	2011-06-15 08:54:17.548796712 +0200
+++ linux-2.6.24/include/asm-arm/arch-hipox/smc.h	2011-06-15 09:01:21.333880081 +0200
@@ -15,14 +15,43 @@
  */
 extern struct mutex hipox_flash_mutex;
 
+
+/* Low level PCI BUS semaphore acquisition
+ *
+ * This handler will claim the linux semaphore and the PCI bus semaphore
+ * for the caller's ID.
+ *
+ * Returns 0 if the claim was successful and both semaphores are held; !=0 otherwise.
+ * */
+int ox810_pci_acquire_bus( void );
+int ox810_flash_acquire_bus( void );
+
+/* Low level PCI BUS semaphore release
+ *
+ * Returns 0 if release was successful, !=0 otherwise.
+ */
+int ox810_pci_release_bus( void );
+int ox810_flash_release_bus( void ); 
+
 /*
- * Request PCI_ARB to grant access to the STATIC core.
+ * PCI Driver bus semaphore registration / deregistration.
+ * This is used by the PCI driver which implements the low level bus semaphore logic:
+ * - int acquire (void * context, uint32_t owner): 
+ *      acquire the semaphore for an owner ID. Returns 0 if successful, 
+ *      !=0 otherwise.
+ * - int release (void * context): 
+ *      release the bus semaphore. There will be no owner check of the 
+ *      semaphore. Returns 0 if successful, !=0 otherwise.
+ *
+ * Deregistration must be done by the PCI driver upon unloading.
  */
-void hipox_smc_request_pci_ad_31_0(void);
+void ox810_pci_register_semaphore_callbacks( int (*acquire)(void*, uint32_t), int (*release)(void*), void * ctx );
+void ox810_pci_reset_semaphore_callbacks( void );
 
 /*
- * Release access to PCI bus.
+ * LEGACY interface. Will print ugly error messages if used. Do not use. Use ox810_flash_[release|request]_bus() instead.
  */
-void hipox_smc_release_pci_ad_31_0(void);
+void hipox_smc_release_pci_ad_31_0( void );
+void hipox_smc_request_pci_ad_31_0( void );
 
 #endif // __ASM_ARCH_SMC_H