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
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5365
5366
5367
5368
5369
5370
5371
5372
5373
5374
5375
5376
5377
5378
5379
5380
5381
5382
5383
5384
5385
5386
5387
5388
5389
5390
5391
5392
5393
5394
5395
5396
5397
5398
5399
5400
5401
5402
5403
5404
5405
5406
5407
5408
5409
5410
5411
5412
5413
5414
5415
5416
5417
5418
5419
5420
5421
5422
5423
5424
5425
5426
5427
5428
5429
5430
5431
5432
5433
5434
5435
5436
5437
5438
5439
5440
5441
5442
5443
5444
5445
5446
5447
5448
5449
5450
5451
5452
5453
5454
5455
5456
5457
5458
5459
5460
5461
5462
5463
5464
5465
5466
5467
5468
5469
5470
5471
5472
5473
5474
5475
5476
5477
5478
5479
5480
5481
5482
5483
5484
5485
5486
5487
5488
5489
5490
5491
5492
5493
5494
5495
5496
5497
5498
5499
5500
5501
5502
5503
5504
5505
5506
5507
5508
5509
5510
5511
5512
5513
5514
5515
5516
5517
5518
5519
5520
5521
5522
5523
5524
5525
5526
5527
5528
5529
5530
5531
5532
5533
5534
5535
5536
5537
5538
5539
5540
5541
5542
5543
5544
5545
5546
5547
5548
5549
5550
5551
5552
5553
5554
5555
5556
5557
5558
5559
5560
5561
5562
5563
5564
5565
5566
5567
5568
5569
5570
5571
5572
5573
5574
5575
5576
5577
5578
5579
5580
5581
5582
5583
5584
5585
5586
5587
5588
5589
5590
5591
5592
5593
5594
5595
5596
5597
5598
5599
5600
5601
5602
5603
5604
5605
5606
5607
5608
5609
5610
5611
5612
5613
5614
5615
5616
5617
5618
5619
5620
5621
5622
5623
5624
5625
5626
5627
5628
5629
5630
5631
5632
5633
5634
5635
5636
5637
5638
5639
5640
5641
5642
5643
5644
5645
5646
5647
5648
5649
5650
5651
5652
5653
5654
5655
5656
5657
5658
5659
5660
5661
5662
5663
5664
5665
5666
5667
5668
5669
5670
5671
5672
5673
5674
5675
5676
5677
5678
5679
5680
5681
5682
5683
5684
5685
5686
5687
5688
5689
5690
5691
5692
5693
5694
5695
5696
5697
5698
5699
5700
5701
5702
5703
5704
5705
5706
5707
5708
5709
5710
5711
5712
5713
5714
5715
5716
5717
5718
5719
5720
5721
5722
5723
5724
5725
5726
5727
5728
5729
5730
5731
5732
5733
5734
5735
5736
5737
5738
5739
5740
5741
5742
5743
5744
5745
5746
5747
5748
5749
5750
5751
5752
5753
5754
5755
5756
5757
5758
5759
5760
5761
5762
5763
5764
5765
5766
5767
5768
5769
5770
5771
5772
5773
5774
5775
5776
5777
5778
5779
5780
5781
5782
5783
5784
5785
5786
5787
5788
5789
5790
5791
5792
5793
5794
5795
5796
5797
5798
5799
5800
5801
5802
5803
5804
5805
5806
5807
5808
5809
5810
5811
5812
5813
5814
5815
5816
5817
5818
5819
5820
5821
5822
5823
5824
5825
5826
5827
5828
5829
5830
5831
5832
5833
5834
5835
5836
5837
5838
5839
5840
5841
5842
5843
5844
5845
5846
5847
5848
5849
5850
5851
5852
5853
5854
5855
5856
5857
5858
5859
5860
5861
5862
5863
5864
5865
5866
5867
5868
5869
5870
5871
5872
5873
5874
5875
5876
5877
5878
5879
5880
5881
5882
5883
5884
5885
5886
5887
5888
5889
5890
5891
5892
5893
5894
5895
5896
5897
5898
5899
5900
5901
5902
5903
5904
5905
5906
5907
5908
5909
5910
5911
5912
5913
5914
5915
5916
5917
5918
5919
5920
5921
5922
5923
5924
5925
5926
5927
5928
5929
5930
5931
5932
5933
5934
5935
5936
5937
5938
5939
5940
5941
5942
5943
5944
5945
5946
5947
5948
5949
5950
5951
5952
5953
5954
5955
5956
5957
5958
5959
5960
5961
5962
5963
5964
5965
5966
5967
5968
5969
5970
5971
5972
5973
5974
5975
5976
5977
5978
5979
5980
5981
5982
5983
5984
5985
5986
5987
5988
5989
5990
5991
5992
5993
5994
5995
5996
5997
5998
5999
6000
6001
6002
6003
6004
6005
6006
6007
6008
6009
6010
6011
6012
6013
6014
6015
6016
6017
6018
6019
6020
6021
6022
6023
6024
6025
6026
6027
6028
6029
6030
6031
6032
6033
6034
6035
6036
6037
6038
6039
6040
6041
6042
6043
6044
6045
6046
6047
6048
6049
6050
6051
6052
6053
6054
6055
6056
6057
6058
6059
6060
6061
6062
6063
6064
6065
6066
6067
6068
6069
6070
6071
6072
6073
6074
6075
6076
6077
6078
6079
6080
6081
6082
6083
6084
6085
6086
6087
6088
6089
6090
6091
6092
6093
6094
6095
6096
6097
6098
6099
6100
6101
6102
6103
6104
6105
6106
6107
6108
6109
6110
6111
6112
6113
6114
6115
6116
6117
6118
6119
6120
6121
6122
6123
6124
6125
6126
6127
6128
6129
6130
6131
6132
6133
6134
6135
6136
6137
6138
6139
6140
6141
6142
6143
6144
6145
6146
6147
6148
6149
6150
6151
6152
6153
6154
6155
6156
6157
6158
6159
6160
6161
6162
6163
6164
6165
6166
6167
6168
6169
6170
6171
6172
6173
6174
6175
6176
6177
6178
6179
6180
6181
6182
6183
6184
6185
6186
6187
6188
6189
6190
6191
6192
6193
6194
6195
6196
6197
6198
6199
6200
6201
6202
6203
6204
6205
6206
6207
6208
6209
6210
6211
6212
6213
6214
6215
6216
6217
6218
6219
6220
6221
6222
6223
6224
6225
6226
6227
6228
6229
6230
6231
6232
6233
6234
6235
6236
6237
6238
6239
6240
6241
6242
6243
6244
6245
6246
6247
6248
6249
6250
6251
6252
6253
6254
6255
6256
6257
6258
6259
6260
6261
6262
6263
6264
6265
6266
6267
6268
6269
6270
6271
6272
6273
6274
6275
6276
6277
6278
6279
6280
6281
6282
6283
6284
6285
6286
6287
6288
6289
6290
6291
6292
6293
6294
6295
6296
6297
6298
6299
6300
6301
6302
6303
6304
6305
6306
6307
6308
6309
6310
6311
6312
6313
6314
6315
6316
6317
6318
6319
6320
6321
6322
6323
6324
6325
6326
6327
6328
6329
6330
6331
6332
6333
6334
6335
6336
6337
6338
6339
6340
6341
6342
6343
6344
6345
6346
6347
6348
6349
6350
6351
6352
6353
6354
6355
6356
6357
6358
6359
6360
6361
6362
6363
6364
6365
6366
6367
6368
6369
6370
6371
6372
6373
6374
6375
6376
6377
6378
6379
6380
6381
6382
6383
6384
6385
6386
6387
6388
6389
6390
6391
6392
6393
6394
6395
6396
6397
6398
6399
6400
6401
6402
6403
6404
6405
6406
6407
6408
6409
6410
6411
6412
6413
6414
6415
6416
6417
6418
6419
6420
6421
6422
6423
6424
6425
6426
6427
6428
6429
6430
6431
6432
6433
6434
6435
6436
6437
6438
6439
6440
6441
6442
6443
6444
6445
6446
6447
6448
6449
6450
6451
6452
6453
6454
6455
6456
6457
6458
6459
6460
6461
6462
6463
6464
6465
6466
6467
6468
6469
6470
6471
6472
6473
6474
6475
6476
6477
6478
6479
6480
6481
6482
6483
6484
6485
6486
6487
6488
6489
6490
6491
6492
6493
6494
6495
6496
6497
6498
6499
6500
6501
6502
6503
6504
6505
6506
6507
6508
6509
6510
6511
6512
6513
6514
6515
6516
6517
6518
6519
6520
6521
6522
6523
6524
6525
6526
6527
6528
6529
6530
6531
6532
6533
6534
6535
6536
6537
6538
6539
6540
6541
6542
6543
6544
6545
6546
6547
6548
6549
6550
6551
6552
6553
6554
6555
6556
6557
6558
6559
6560
6561
6562
6563
6564
6565
6566
6567
6568
6569
6570
6571
6572
6573
6574
6575
6576
6577
6578
6579
6580
6581
6582
6583
6584
6585
6586
6587
6588
6589
6590
6591
6592
6593
6594
6595
6596
6597
6598
6599
6600
6601
6602
6603
6604
6605
6606
6607
6608
6609
6610
6611
6612
6613
6614
6615
6616
6617
6618
6619
6620
6621
6622
6623
6624
6625
6626
6627
6628
6629
6630
6631
6632
6633
6634
6635
6636
6637
6638
6639
6640
6641
6642
6643
6644
6645
6646
6647
6648
6649
6650
6651
6652
6653
6654
6655
6656
6657
6658
6659
6660
6661
6662
6663
6664
6665
6666
6667
6668
6669
6670
6671
6672
6673
6674
6675
6676
6677
6678
6679
6680
6681
6682
6683
6684
6685
6686
6687
6688
6689
6690
6691
6692
6693
6694
6695
6696
6697
6698
6699
6700
6701
6702
6703
6704
6705
6706
6707
6708
6709
6710
6711
6712
6713
6714
6715
6716
6717
6718
6719
6720
6721
6722
6723
6724
6725
6726
6727
6728
6729
6730
6731
6732
6733
6734
6735
6736
6737
6738
6739
6740
6741
6742
6743
6744
6745
6746
6747
6748
6749
6750
6751
6752
6753
6754
6755
6756
6757
6758
6759
6760
6761
6762
6763
6764
6765
6766
6767
6768
6769
6770
6771
6772
6773
6774
6775
6776
6777
6778
6779
6780
6781
6782
6783
6784
6785
6786
6787
6788
6789
6790
6791
6792
6793
6794
6795
6796
6797
6798
6799
6800
6801
6802
6803
6804
6805
6806
6807
6808
6809
6810
6811
6812
6813
6814
6815
6816
6817
6818
6819
6820
6821
6822
6823
6824
6825
6826
6827
6828
6829
6830
6831
6832
6833
6834
6835
6836
6837
6838
6839
6840
6841
6842
6843
6844
6845
6846
6847
6848
6849
6850
6851
6852
6853
6854
6855
6856
6857
6858
6859
6860
6861
6862
6863
6864
6865
6866
6867
6868
6869
6870
6871
6872
6873
6874
6875
6876
6877
6878
6879
6880
6881
6882
6883
6884
6885
6886
6887
6888
6889
6890
6891
6892
6893
6894
6895
6896
6897
6898
6899
6900
6901
6902
6903
6904
6905
6906
6907
6908
6909
6910
6911
6912
6913
6914
6915
6916
6917
6918
6919
6920
6921
6922
6923
6924
6925
6926
6927
6928
6929
6930
6931
6932
6933
6934
6935
6936
6937
6938
6939
6940
6941
6942
6943
6944
6945
6946
6947
6948
6949
6950
6951
6952
6953
6954
6955
6956
6957
6958
6959
6960
6961
6962
6963
6964
6965
6966
6967
6968
6969
6970
6971
6972
6973
6974
6975
6976
6977
6978
6979
6980
6981
6982
6983
6984
6985
6986
6987
6988
6989
6990
6991
6992
6993
6994
6995
6996
6997
6998
6999
7000
7001
7002
7003
7004
7005
7006
7007
7008
7009
7010
7011
7012
7013
7014
7015
7016
7017
7018
7019
7020
7021
7022
7023
7024
7025
7026
7027
7028
7029
7030
7031
7032
7033
7034
7035
7036
7037
7038
7039
7040
7041
7042
7043
7044
7045
7046
7047
7048
7049
7050
7051
7052
7053
7054
7055
7056
7057
7058
7059
7060
7061
7062
7063
7064
7065
7066
7067
7068
7069
7070
7071
7072
7073
7074
7075
7076
7077
7078
7079
7080
7081
7082
7083
7084
7085
7086
7087
7088
7089
7090
7091
7092
7093
7094
7095
7096
7097
7098
7099
7100
7101
7102
7103
7104
7105
7106
7107
7108
7109
7110
7111
7112
7113
7114
7115
7116
7117
7118
7119
7120
7121
7122
7123
7124
7125
7126
7127
7128
7129
7130
7131
7132
7133
7134
7135
7136
7137
7138
7139
7140
7141
7142
7143
7144
7145
7146
7147
7148
7149
7150
7151
7152
7153
7154
7155
7156
7157
7158
7159
7160
7161
7162
7163
7164
7165
7166
7167
7168
7169
7170
7171
7172
7173
7174
7175
7176
7177
7178
7179
7180
7181
7182
7183
7184
7185
7186
7187
7188
7189
7190
7191
7192
7193
7194
7195
7196
7197
7198
7199
7200
7201
7202
7203
7204
7205
7206
7207
7208
7209
7210
7211
7212
7213
7214
7215
7216
7217
7218
7219
7220
7221
7222
7223
7224
7225
7226
7227
7228
7229
7230
7231
7232
7233
7234
7235
7236
7237
7238
7239
7240
7241
7242
7243
7244
7245
7246
7247
7248
7249
7250
7251
7252
7253
7254
7255
7256
7257
7258
7259
7260
7261
7262
7263
7264
7265
7266
7267
7268
7269
7270
7271
7272
7273
7274
7275
7276
7277
7278
7279
7280
7281
7282
7283
7284
7285
7286
7287
7288
7289
7290
7291
7292
7293
7294
7295
7296
7297
7298
7299
7300
7301
7302
7303
7304
7305
7306
7307
7308
7309
7310
7311
7312
7313
7314
7315
7316
7317
7318
7319
7320
7321
7322
7323
7324
7325
7326
7327
7328
7329
7330
7331
7332
7333
7334
7335
7336
7337
7338
7339
7340
7341
7342
7343
7344
7345
7346
7347
7348
7349
7350
7351
7352
7353
7354
7355
7356
7357
7358
7359
7360
7361
7362
7363
7364
7365
7366
7367
7368
7369
7370
7371
7372
7373
7374
7375
7376
7377
7378
7379
7380
7381
7382
7383
7384
7385
7386
7387
7388
7389
7390
7391
7392
7393
7394
7395
7396
7397
7398
7399
7400
7401
7402
7403
7404
7405
7406
7407
7408
7409
7410
7411
7412
7413
7414
7415
7416
7417
7418
7419
7420
7421
7422
7423
7424
7425
7426
7427
7428
7429
7430
7431
7432
7433
7434
7435
7436
7437
7438
7439
7440
7441
7442
7443
7444
7445
7446
7447
7448
7449
7450
7451
7452
7453
7454
7455
7456
7457
7458
7459
7460
7461
7462
7463
7464
7465
7466
7467
7468
7469
7470
7471
7472
7473
7474
7475
7476
7477
7478
7479
7480
7481
7482
7483
7484
7485
7486
7487
7488
7489
7490
7491
7492
7493
7494
7495
7496
7497
7498
7499
7500
7501
7502
7503
7504
7505
7506
7507
7508
7509
7510
7511
7512
7513
7514
7515
7516
7517
7518
7519
7520
7521
7522
7523
7524
7525
7526
7527
7528
7529
7530
7531
7532
7533
7534
7535
7536
7537
7538
7539
7540
7541
7542
7543
7544
7545
7546
7547
7548
7549
7550
7551
7552
7553
7554
7555
7556
7557
7558
7559
7560
7561
7562
7563
7564
7565
7566
7567
7568
7569
7570
7571
7572
7573
7574
7575
7576
7577
7578
7579
7580
7581
7582
7583
7584
7585
7586
7587
7588
7589
7590
7591
7592
7593
7594
7595
7596
7597
7598
7599
7600
7601
7602
7603
7604
7605
7606
7607
7608
7609
7610
7611
7612
7613
7614
7615
7616
7617
7618
7619
7620
7621
7622
7623
7624
7625
7626
7627
7628
7629
7630
7631
7632
7633
7634
7635
7636
7637
7638
7639
7640
7641
7642
7643
7644
7645
7646
7647
7648
7649
7650
7651
7652
7653
7654
7655
7656
7657
7658
7659
7660
7661
7662
7663
7664
7665
7666
7667
7668
7669
7670
7671
7672
7673
7674
7675
7676
7677
7678
7679
7680
7681
7682
7683
7684
7685
7686
7687
7688
7689
7690
7691
7692
7693
7694
7695
7696
7697
7698
7699
7700
7701
7702
7703
7704
7705
7706
7707
7708
7709
7710
7711
7712
7713
7714
7715
7716
7717
7718
7719
7720
7721
7722
7723
7724
7725
7726
7727
7728
7729
7730
7731
7732
7733
7734
7735
7736
7737
7738
7739
7740
7741
7742
7743
7744
7745
7746
7747
7748
7749
7750
7751
7752
7753
7754
7755
7756
7757
7758
7759
7760
7761
7762
7763
7764
7765
7766
7767
7768
7769
7770
7771
7772
7773
7774
7775
7776
7777
7778
7779
7780
7781
7782
7783
7784
7785
7786
7787
7788
7789
7790
7791
7792
7793
7794
7795
7796
7797
7798
7799
7800
7801
7802
7803
7804
7805
7806
7807
7808
7809
7810
7811
7812
7813
7814
7815
7816
7817
7818
7819
7820
7821
7822
7823
7824
7825
7826
7827
7828
7829
7830
7831
7832
7833
7834
7835
7836
7837
7838
7839
7840
7841
7842
7843
7844
7845
7846
7847
7848
7849
7850
7851
7852
7853
7854
7855
7856
7857
7858
7859
7860
7861
7862
7863
7864
7865
7866
7867
7868
7869
7870
7871
7872
7873
7874
7875
7876
7877
7878
7879
7880
7881
7882
7883
7884
7885
7886
7887
7888
7889
7890
7891
7892
7893
7894
7895
7896
7897
7898
7899
7900
7901
7902
7903
7904
7905
7906
7907
7908
7909
7910
7911
7912
7913
7914
7915
7916
7917
7918
7919
7920
7921
7922
7923
7924
7925
7926
7927
7928
7929
7930
7931
7932
7933
7934
7935
7936
7937
7938
7939
7940
7941
7942
7943
7944
7945
7946
7947
7948
7949
7950
7951
7952
7953
7954
7955
7956
7957
7958
7959
7960
7961
7962
7963
7964
7965
7966
7967
7968
7969
7970
7971
7972
7973
7974
7975
7976
7977
7978
7979
7980
7981
7982
7983
7984
7985
7986
7987
7988
7989
7990
7991
7992
7993
7994
7995
7996
7997
7998
7999
8000
8001
8002
8003
8004
8005
8006
8007
8008
8009
8010
8011
8012
8013
8014
8015
8016
8017
8018
8019
8020
8021
8022
8023
8024
8025
8026
8027
8028
8029
8030
8031
8032
8033
8034
8035
8036
8037
8038
8039
8040
8041
8042
8043
8044
8045
8046
8047
8048
8049
8050
8051
8052
8053
8054
8055
8056
8057
8058
8059
8060
8061
8062
8063
8064
8065
8066
8067
8068
8069
8070
8071
8072
8073
8074
8075
8076
8077
8078
8079
8080
8081
8082
8083
8084
8085
8086
8087
8088
8089
8090
8091
8092
8093
8094
8095
8096
8097
8098
8099
8100
8101
8102
8103
8104
8105
8106
8107
8108
8109
8110
8111
8112
8113
8114
8115
8116
8117
8118
8119
8120
8121
8122
8123
8124
8125
8126
8127
8128
8129
8130
8131
8132
8133
8134
8135
8136
8137
8138
8139
8140
8141
8142
8143
8144
8145
8146
8147
8148
8149
8150
8151
8152
8153
8154
8155
8156
8157
8158
8159
8160
8161
8162
8163
8164
8165
8166
8167
8168
8169
8170
8171
8172
8173
8174
8175
8176
8177
8178
8179
8180
8181
8182
8183
8184
8185
8186
8187
8188
8189
8190
8191
8192
8193
8194
8195
8196
8197
8198
8199
8200
8201
8202
8203
8204
8205
8206
8207
8208
8209
8210
8211
8212
8213
8214
8215
8216
8217
8218
8219
8220
8221
8222
8223
8224
8225
8226
8227
8228
8229
8230
8231
8232
8233
8234
8235
8236
8237
8238
8239
8240
8241
8242
8243
8244
8245
8246
8247
8248
8249
8250
8251
8252
8253
8254
8255
8256
8257
8258
8259
8260
8261
8262
8263
8264
8265
8266
8267
8268
8269
8270
8271
8272
8273
8274
8275
8276
8277
8278
8279
8280
8281
8282
8283
8284
8285
8286
8287
8288
8289
8290
8291
8292
8293
8294
8295
8296
8297
8298
8299
8300
8301
8302
8303
8304
8305
8306
8307
8308
8309
8310
8311
8312
8313
8314
8315
8316
8317
8318
8319
8320
8321
8322
8323
8324
8325
8326
8327
8328
8329
8330
8331
8332
8333
8334
8335
8336
8337
8338
8339
8340
8341
8342
8343
8344
8345
8346
8347
8348
8349
8350
8351
8352
8353
8354
8355
8356
8357
8358
8359
8360
8361
8362
8363
8364
8365
8366
8367
8368
8369
8370
8371
8372
8373
8374
8375
8376
8377
8378
8379
8380
8381
8382
8383
8384
8385
8386
8387
8388
8389
8390
8391
8392
8393
8394
8395
8396
8397
8398
8399
8400
8401
8402
8403
8404
8405
8406
8407
8408
8409
8410
8411
8412
8413
8414
8415
8416
8417
8418
8419
8420
8421
8422
8423
8424
8425
8426
8427
8428
8429
8430
8431
8432
8433
8434
8435
8436
8437
8438
8439
8440
8441
8442
8443
8444
8445
8446
8447
8448
8449
8450
8451
8452
8453
8454
8455
8456
8457
8458
8459
8460
8461
8462
8463
8464
8465
8466
8467
8468
8469
8470
8471
8472
8473
8474
8475
8476
8477
8478
8479
8480
8481
8482
8483
8484
8485
8486
8487
8488
8489
8490
8491
8492
8493
8494
8495
8496
8497
8498
8499
8500
8501
8502
8503
8504
8505
8506
8507
8508
8509
8510
8511
8512
8513
8514
8515
8516
8517
8518
8519
8520
8521
8522
8523
8524
8525
8526
8527
8528
8529
8530
8531
8532
8533
8534
8535
8536
8537
8538
8539
8540
8541
8542
8543
8544
8545
8546
8547
8548
8549
8550
8551
8552
8553
8554
8555
8556
8557
8558
8559
8560
8561
8562
8563
8564
8565
8566
8567
8568
8569
8570
8571
8572
8573
8574
8575
8576
8577
8578
8579
8580
8581
8582
8583
8584
8585
8586
8587
8588
8589
8590
8591
8592
8593
8594
8595
8596
8597
8598
8599
8600
8601
8602
8603
8604
8605
8606
8607
8608
8609
8610
8611
8612
8613
8614
8615
8616
8617
8618
8619
8620
8621
8622
8623
8624
8625
8626
8627
8628
8629
8630
8631
8632
8633
8634
8635
8636
8637
8638
8639
8640
8641
8642
8643
8644
8645
8646
8647
8648
8649
8650
8651
8652
8653
8654
8655
8656
8657
8658
8659
8660
8661
8662
8663
8664
8665
8666
8667
8668
8669
8670
8671
8672
8673
8674
8675
8676
8677
8678
8679
8680
8681
8682
8683
8684
8685
8686
8687
8688
8689
8690
8691
8692
8693
8694
8695
8696
8697
8698
8699
8700
8701
8702
8703
8704
8705
8706
8707
8708
8709
8710
8711
8712
8713
8714
8715
8716
8717
8718
8719
8720
8721
8722
8723
8724
8725
8726
8727
8728
8729
8730
8731
8732
8733
8734
8735
8736
8737
8738
8739
8740
8741
8742
8743
8744
8745
8746
8747
8748
8749
8750
8751
8752
8753
8754
8755
8756
8757
8758
8759
8760
8761
8762
8763
8764
8765
8766
8767
8768
8769
8770
8771
8772
8773
8774
8775
8776
8777
8778
8779
8780
8781
8782
8783
8784
8785
8786
8787
8788
8789
8790
8791
8792
8793
8794
8795
8796
8797
8798
8799
8800
8801
8802
8803
8804
8805
8806
8807
8808
8809
8810
8811
8812
8813
8814
8815
8816
8817
8818
8819
8820
8821
8822
8823
8824
8825
8826
8827
8828
8829
8830
8831
8832
8833
8834
8835
8836
8837
8838
8839
8840
8841
8842
8843
8844
8845
8846
8847
8848
8849
8850
8851
8852
8853
8854
8855
8856
8857
8858
8859
8860
8861
8862
8863
8864
8865
8866
8867
8868
8869
8870
8871
8872
8873
8874
8875
8876
8877
8878
8879
8880
8881
8882
8883
8884
8885
8886
8887
8888
8889
8890
8891
8892
8893
8894
8895
8896
8897
8898
8899
8900
8901
8902
8903
8904
8905
8906
8907
8908
8909
8910
8911
8912
8913
8914
8915
8916
8917
8918
8919
8920
8921
8922
8923
8924
8925
8926
8927
8928
8929
8930
8931
8932
8933
8934
8935
8936
8937
8938
8939
8940
8941
8942
8943
8944
8945
8946
8947
8948
8949
8950
8951
8952
8953
8954
8955
8956
8957
8958
8959
8960
8961
8962
8963
8964
8965
8966
8967
8968
8969
8970
8971
8972
8973
8974
8975
8976
8977
8978
8979
8980
8981
8982
8983
8984
8985
8986
8987
8988
8989
8990
8991
8992
8993
8994
8995
8996
8997
8998
8999
9000
9001
9002
9003
9004
9005
9006
9007
9008
9009
9010
9011
9012
9013
9014
9015
9016
9017
9018
9019
9020
9021
9022
9023
9024
9025
9026
9027
9028
9029
9030
9031
9032
9033
9034
9035
9036
9037
9038
9039
9040
9041
9042
9043
9044
9045
9046
9047
9048
9049
9050
9051
9052
9053
9054
9055
9056
9057
9058
9059
9060
9061
9062
9063
9064
9065
9066
9067
9068
9069
9070
9071
9072
9073
9074
9075
9076
9077
9078
9079
9080
9081
9082
9083
9084
9085
9086
9087
9088
9089
9090
9091
9092
9093
9094
9095
9096
9097
9098
9099
9100
9101
9102
9103
9104
9105
9106
9107
9108
9109
9110
9111
9112
9113
9114
9115
9116
9117
9118
9119
9120
9121
9122
9123
9124
9125
9126
9127
9128
9129
9130
9131
9132
9133
9134
9135
9136
9137
9138
9139
9140
9141
9142
9143
9144
9145
9146
9147
9148
9149
9150
9151
9152
9153
9154
9155
9156
9157
9158
9159
9160
9161
9162
9163
9164
9165
9166
9167
9168
9169
9170
9171
9172
9173
9174
9175
9176
9177
9178
9179
9180
9181
9182
9183
9184
9185
9186
9187
9188
9189
9190
9191
9192
9193
9194
9195
9196
9197
9198
9199
9200
9201
9202
9203
9204
9205
9206
9207
9208
9209
9210
9211
9212
9213
9214
9215
9216
9217
9218
9219
9220
9221
9222
9223
9224
9225
9226
9227
9228
9229
9230
9231
9232
9233
9234
9235
9236
9237
9238
9239
9240
9241
9242
9243
9244
9245
9246
9247
9248
9249
9250
9251
9252
9253
9254
9255
9256
9257
9258
9259
9260
9261
9262
9263
9264
9265
9266
9267
9268
9269
9270
9271
9272
9273
9274
9275
9276
9277
9278
9279
9280
9281
9282
9283
9284
9285
9286
9287
9288
9289
9290
9291
9292
9293
9294
9295
9296
9297
9298
9299
9300
9301
9302
9303
9304
9305
9306
9307
9308
9309
9310
9311
9312
9313
9314
9315
9316
9317
9318
9319
9320
9321
9322
9323
9324
9325
9326
9327
9328
9329
9330
9331
9332
9333
9334
9335
9336
9337
9338
9339
9340
9341
9342
9343
9344
9345
9346
9347
9348
9349
9350
9351
9352
9353
9354
9355
9356
9357
9358
9359
9360
9361
9362
9363
9364
9365
9366
9367
9368
9369
9370
9371
9372
9373
9374
9375
9376
9377
9378
9379
9380
9381
9382
9383
9384
9385
9386
9387
9388
9389
9390
9391
9392
9393
9394
9395
9396
9397
9398
9399
9400
9401
9402
9403
9404
9405
9406
9407
9408
9409
9410
9411
9412
9413
9414
9415
9416
9417
9418
9419
9420
9421
9422
9423
9424
9425
9426
9427
9428
9429
9430
9431
9432
9433
9434
9435
9436
9437
9438
9439
9440
9441
9442
9443
9444
9445
9446
9447
9448
9449
9450
9451
9452
9453
9454
9455
9456
9457
9458
9459
9460
9461
9462
9463
9464
9465
9466
9467
9468
9469
9470
9471
9472
9473
9474
9475
9476
9477
9478
9479
9480
9481
9482
9483
9484
9485
9486
9487
9488
9489
9490
9491
9492
9493
9494
9495
9496
9497
9498
9499
9500
9501
9502
9503
9504
9505
9506
9507
9508
9509
9510
9511
9512
9513
9514
9515
9516
9517
9518
9519
9520
9521
9522
9523
9524
9525
9526
9527
9528
9529
9530
9531
9532
9533
9534
9535
9536
9537
9538
9539
9540
9541
9542
9543
9544
9545
9546
9547
9548
9549
9550
9551
9552
9553
9554
9555
9556
9557
9558
9559
9560
9561
9562
9563
9564
9565
9566
9567
9568
9569
9570
9571
9572
9573
9574
9575
9576
9577
9578
9579
9580
9581
9582
9583
9584
9585
9586
9587
9588
9589
9590
9591
9592
9593
9594
9595
9596
9597
9598
9599
9600
9601
9602
9603
9604
9605
9606
9607
9608
9609
9610
9611
9612
9613
9614
9615
9616
9617
9618
9619
9620
9621
9622
9623
9624
9625
9626
9627
9628
9629
9630
9631
9632
9633
9634
9635
9636
9637
9638
9639
9640
9641
9642
9643
9644
9645
9646
9647
9648
9649
9650
9651
9652
9653
9654
9655
9656
9657
9658
9659
9660
9661
9662
9663
9664
9665
9666
9667
9668
9669
9670
9671
9672
9673
9674
9675
9676
9677
9678
9679
9680
9681
9682
9683
9684
9685
9686
9687
9688
9689
9690
9691
9692
9693
9694
9695
9696
9697
9698
9699
9700
9701
9702
9703
9704
9705
9706
9707
9708
9709
9710
9711
9712
9713
9714
9715
9716
9717
9718
9719
9720
9721
9722
9723
9724
9725
9726
9727
9728
9729
9730
9731
9732
9733
9734
9735
9736
9737
9738
9739
9740
9741
9742
9743
9744
9745
9746
9747
9748
9749
9750
9751
9752
9753
9754
9755
9756
9757
9758
9759
9760
9761
9762
9763
9764
9765
9766
9767
9768
9769
9770
9771
9772
9773
9774
9775
9776
9777
9778
9779
9780
9781
9782
9783
9784
9785
9786
9787
9788
9789
9790
9791
9792
9793
9794
9795
9796
9797
9798
9799
9800
9801
9802
9803
9804
9805
9806
9807
9808
9809
9810
9811
9812
9813
9814
9815
9816
9817
9818
9819
9820
9821
9822
9823
9824
9825
9826
9827
9828
9829
9830
9831
9832
9833
9834
9835
9836
9837
9838
9839
9840
9841
9842
9843
9844
9845
9846
9847
9848
9849
9850
9851
9852
9853
9854
9855
9856
9857
9858
9859
9860
9861
9862
9863
9864
9865
9866
9867
9868
9869
9870
9871
9872
9873
9874
9875
9876
9877
9878
9879
9880
9881
9882
9883
9884
9885
9886
9887
9888
9889
9890
9891
9892
9893
9894
9895
9896
9897
9898
9899
9900
9901
9902
9903
9904
9905
9906
9907
9908
9909
9910
9911
9912
9913
9914
9915
9916
9917
9918
9919
9920
9921
9922
9923
9924
9925
9926
9927
9928
9929
9930
9931
9932
9933
9934
9935
9936
9937
9938
9939
9940
9941
9942
9943
9944
9945
9946
9947
9948
9949
9950
9951
9952
9953
9954
9955
9956
9957
9958
9959
9960
9961
9962
9963
9964
9965
9966
9967
9968
9969
9970
9971
9972
9973
9974
9975
9976
9977
9978
9979
9980
9981
9982
9983
9984
9985
9986
9987
9988
9989
9990
9991
9992
9993
9994
9995
9996
9997
9998
9999
10000
10001
10002
10003
10004
10005
10006
10007
10008
10009
10010
10011
10012
10013
10014
10015
10016
10017
10018
10019
10020
10021
10022
10023
10024
10025
10026
10027
10028
10029
10030
10031
10032
10033
10034
10035
10036
10037
10038
10039
10040
10041
10042
10043
10044
10045
10046
10047
10048
10049
10050
10051
10052
10053
10054
10055
10056
10057
10058
10059
10060
10061
10062
10063
10064
10065
10066
10067
10068
10069
10070
10071
10072
10073
10074
10075
10076
10077
10078
10079
10080
10081
10082
10083
10084
10085
10086
10087
10088
10089
10090
10091
10092
10093
10094
10095
10096
10097
10098
10099
10100
10101
10102
10103
10104
10105
10106
10107
10108
10109
10110
10111
10112
10113
10114
10115
10116
10117
10118
10119
10120
10121
10122
10123
10124
10125
10126
10127
10128
10129
10130
10131
10132
10133
10134
10135
10136
10137
10138
10139
10140
10141
10142
10143
10144
10145
10146
10147
10148
10149
10150
10151
10152
10153
10154
10155
10156
10157
10158
10159
10160
10161
10162
10163
10164
10165
10166
10167
10168
10169
10170
10171
10172
10173
10174
10175
10176
10177
10178
10179
10180
10181
10182
10183
10184
10185
10186
10187
10188
10189
10190
10191
10192
10193
10194
10195
10196
10197
10198
10199
10200
10201
10202
10203
10204
10205
10206
10207
10208
10209
10210
10211
10212
10213
10214
10215
10216
10217
10218
10219
10220
10221
10222
10223
10224
10225
10226
10227
10228
10229
10230
10231
10232
10233
10234
10235
10236
10237
10238
10239
10240
10241
10242
10243
10244
10245
10246
10247
10248
10249
10250
10251
10252
10253
10254
10255
10256
10257
10258
10259
10260
10261
10262
10263
10264
10265
10266
10267
10268
10269
10270
10271
10272
10273
10274
10275
10276
10277
10278
10279
10280
10281
10282
10283
10284
10285
10286
10287
10288
10289
10290
10291
10292
10293
10294
10295
10296
10297
10298
10299
10300
10301
10302
10303
10304
10305
10306
10307
10308
10309
10310
10311
10312
10313
10314
10315
10316
10317
10318
10319
10320
10321
10322
10323
10324
10325
10326
10327
10328
10329
10330
10331
10332
10333
10334
10335
10336
10337
10338
10339
10340
10341
10342
10343
10344
10345
10346
10347
10348
10349
10350
10351
10352
10353
10354
10355
10356
10357
10358
10359
10360
10361
10362
10363
10364
10365
10366
10367
10368
10369
10370
10371
10372
10373
10374
10375
10376
10377
10378
10379
10380
10381
10382
10383
10384
10385
10386
10387
10388
10389
10390
10391
10392
10393
10394
10395
10396
10397
10398
10399
10400
10401
10402
10403
10404
10405
10406
10407
10408
10409
10410
10411
10412
10413
10414
10415
10416
10417
10418
10419
10420
10421
10422
10423
10424
10425
10426
10427
10428
10429
10430
10431
10432
10433
10434
10435
10436
10437
10438
10439
10440
10441
10442
10443
10444
10445
10446
10447
10448
10449
10450
10451
10452
10453
10454
10455
10456
10457
10458
10459
10460
10461
10462
10463
10464
10465
10466
10467
10468
10469
10470
10471
10472
10473
10474
10475
10476
10477
10478
10479
10480
10481
10482
10483
10484
10485
10486
10487
10488
10489
10490
10491
10492
10493
10494
10495
10496
10497
10498
10499
10500
10501
10502
10503
10504
10505
10506
10507
10508
10509
10510
10511
10512
10513
10514
10515
10516
10517
10518
10519
10520
10521
10522
10523
10524
10525
10526
10527
10528
10529
10530
10531
10532
10533
10534
10535
10536
10537
10538
10539
10540
10541
10542
10543
10544
10545
10546
10547
10548
10549
10550
10551
10552
10553
10554
10555
10556
10557
10558
10559
10560
10561
10562
10563
10564
10565
10566
10567
10568
10569
10570
10571
10572
10573
10574
10575
10576
10577
10578
10579
10580
10581
10582
10583
10584
10585
10586
10587
10588
10589
10590
10591
10592
10593
10594
10595
10596
10597
10598
10599
10600
10601
10602
10603
10604
10605
10606
10607
10608
10609
10610
10611
10612
10613
10614
10615
10616
10617
10618
10619
10620
10621
10622
10623
10624
10625
10626
10627
10628
10629
10630
10631
10632
10633
10634
10635
10636
10637
10638
10639
10640
10641
10642
10643
10644
10645
10646
10647
10648
10649
10650
10651
10652
10653
10654
10655
10656
10657
10658
10659
10660
10661
10662
10663
10664
10665
10666
10667
10668
10669
10670
10671
10672
10673
10674
10675
10676
10677
10678
10679
10680
10681
10682
10683
10684
10685
10686
10687
10688
10689
10690
10691
10692
10693
10694
10695
10696
10697
10698
10699
10700
10701
10702
10703
10704
10705
10706
10707
10708
10709
10710
10711
10712
10713
10714
10715
10716
10717
10718
10719
10720
10721
10722
10723
10724
10725
10726
10727
10728
10729
10730
10731
10732
10733
10734
10735
10736
10737
10738
10739
10740
10741
10742
10743
10744
10745
10746
10747
10748
10749
10750
10751
10752
10753
10754
10755
10756
10757
10758
10759
10760
10761
10762
10763
10764
10765
10766
10767
10768
10769
10770
10771
10772
10773
10774
10775
10776
10777
10778
10779
10780
10781
10782
10783
10784
10785
10786
10787
10788
10789
10790
10791
10792
10793
10794
10795
10796
10797
10798
10799
10800
10801
10802
10803
10804
10805
10806
10807
10808
10809
10810
10811
10812
10813
10814
10815
10816
10817
10818
10819
10820
10821
10822
10823
10824
10825
10826
10827
10828
10829
10830
10831
10832
10833
10834
10835
10836
10837
10838
10839
10840
10841
10842
10843
10844
10845
10846
10847
10848
10849
10850
10851
10852
10853
10854
10855
10856
10857
10858
10859
10860
10861
10862
10863
10864
10865
10866
10867
10868
10869
10870
10871
10872
10873
10874
10875
10876
10877
10878
10879
10880
10881
10882
10883
10884
10885
10886
10887
10888
10889
10890
10891
10892
10893
10894
10895
10896
10897
10898
10899
10900
10901
10902
10903
10904
10905
10906
10907
10908
10909
10910
10911
10912
10913
10914
10915
10916
10917
10918
10919
10920
10921
10922
10923
10924
10925
10926
10927
10928
10929
10930
10931
10932
10933
10934
10935
10936
10937
10938
10939
10940
10941
10942
10943
10944
10945
10946
10947
10948
10949
10950
10951
10952
10953
10954
10955
10956
10957
10958
10959
10960
10961
10962
10963
10964
10965
10966
10967
10968
10969
10970
10971
10972
10973
10974
10975
10976
10977
10978
10979
10980
10981
10982
10983
10984
10985
10986
10987
10988
10989
10990
10991
10992
10993
10994
10995
10996
10997
10998
10999
11000
11001
11002
11003
11004
11005
11006
11007
11008
11009
11010
11011
11012
11013
11014
11015
11016
11017
11018
11019
11020
11021
11022
11023
11024
11025
11026
11027
11028
11029
11030
11031
11032
11033
11034
11035
11036
11037
11038
11039
11040
11041
11042
11043
11044
11045
11046
11047
11048
11049
11050
11051
11052
11053
11054
11055
11056
11057
11058
11059
11060
11061
11062
11063
11064
11065
11066
11067
11068
11069
11070
11071
11072
11073
11074
11075
11076
11077
11078
11079
11080
11081
11082
11083
11084
11085
11086
11087
11088
11089
11090
11091
11092
11093
11094
11095
11096
11097
11098
11099
11100
11101
11102
11103
11104
11105
11106
11107
11108
11109
11110
11111
11112
11113
11114
11115
11116
11117
11118
11119
11120
11121
11122
11123
11124
11125
11126
11127
11128
11129
11130
11131
11132
11133
11134
11135
11136
11137
11138
11139
11140
11141
11142
11143
11144
11145
11146
11147
11148
11149
11150
11151
11152
11153
11154
11155
11156
11157
11158
11159
11160
11161
11162
11163
11164
11165
11166
11167
11168
11169
11170
11171
11172
11173
11174
11175
11176
11177
11178
11179
11180
11181
11182
11183
11184
11185
11186
11187
11188
11189
11190
11191
11192
11193
11194
11195
11196
11197
11198
11199
11200
11201
11202
11203
11204
11205
11206
11207
11208
11209
11210
11211
11212
11213
11214
11215
11216
11217
11218
11219
11220
11221
11222
11223
11224
11225
11226
11227
11228
11229
11230
11231
11232
11233
11234
11235
11236
11237
11238
11239
11240
11241
11242
11243
11244
11245
11246
11247
11248
11249
11250
11251
11252
11253
11254
11255
11256
11257
11258
11259
11260
11261
11262
11263
11264
11265
11266
11267
11268
11269
11270
11271
11272
11273
11274
11275
11276
11277
11278
11279
11280
11281
11282
11283
11284
11285
11286
11287
11288
11289
11290
11291
11292
11293
11294
11295
11296
11297
11298
11299
11300
11301
11302
11303
11304
11305
11306
11307
11308
11309
11310
11311
11312
11313
11314
11315
11316
11317
11318
11319
11320
11321
11322
11323
11324
11325
11326
11327
11328
11329
11330
11331
11332
11333
11334
11335
11336
11337
11338
11339
11340
11341
11342
11343
11344
11345
11346
11347
11348
11349
11350
11351
11352
11353
11354
11355
11356
11357
11358
11359
11360
11361
11362
11363
11364
11365
11366
11367
11368
11369
11370
11371
11372
11373
11374
11375
11376
11377
11378
11379
11380
11381
11382
11383
11384
11385
11386
11387
11388
11389
11390
11391
11392
11393
11394
11395
11396
11397
11398
11399
11400
11401
11402
11403
11404
11405
11406
11407
11408
11409
11410
11411
11412
11413
11414
11415
11416
11417
11418
11419
11420
11421
11422
11423
11424
11425
11426
11427
11428
11429
11430
11431
11432
11433
11434
11435
11436
11437
11438
11439
11440
11441
11442
11443
11444
11445
11446
11447
11448
11449
11450
11451
11452
11453
11454
11455
11456
11457
11458
11459
11460
11461
11462
11463
11464
11465
11466
11467
11468
11469
11470
11471
11472
11473
11474
11475
11476
11477
11478
11479
11480
11481
11482
11483
11484
11485
11486
11487
11488
11489
11490
11491
11492
11493
11494
11495
11496
11497
11498
11499
11500
11501
11502
11503
11504
11505
11506
11507
11508
11509
11510
11511
11512
11513
11514
11515
11516
11517
11518
11519
11520
11521
11522
11523
11524
11525
11526
11527
11528
11529
11530
11531
11532
11533
11534
11535
11536
11537
11538
11539
11540
11541
11542
11543
11544
11545
11546
11547
11548
11549
11550
11551
11552
11553
11554
11555
11556
11557
11558
11559
11560
11561
11562
11563
11564
11565
11566
11567
11568
11569
11570
11571
11572
11573
11574
11575
11576
11577
11578
11579
11580
11581
11582
11583
11584
11585
11586
11587
11588
11589
11590
11591
11592
11593
11594
11595
11596
11597
11598
11599
11600
11601
11602
11603
11604
11605
11606
11607
11608
11609
11610
11611
11612
11613
11614
11615
11616
11617
11618
11619
11620
11621
11622
11623
11624
11625
11626
11627
11628
11629
11630
11631
11632
11633
11634
11635
11636
11637
11638
11639
11640
11641
11642
11643
11644
11645
11646
11647
11648
11649
11650
11651
11652
11653
11654
11655
11656
11657
11658
11659
11660
11661
11662
11663
11664
11665
11666
11667
11668
11669
11670
11671
11672
11673
11674
11675
11676
11677
11678
11679
11680
11681
11682
11683
11684
11685
11686
11687
11688
11689
11690
11691
11692
11693
11694
11695
11696
11697
11698
11699
11700
11701
11702
11703
11704
11705
11706
11707
11708
11709
11710
11711
11712
11713
11714
11715
11716
11717
11718
11719
11720
11721
11722
11723
11724
11725
11726
11727
11728
11729
11730
11731
11732
11733
11734
11735
11736
11737
11738
11739
11740
11741
11742
11743
11744
11745
11746
11747
11748
11749
11750
11751
11752
11753
11754
11755
11756
11757
11758
11759
11760
11761
11762
11763
11764
11765
11766
11767
11768
11769
11770
11771
11772
11773
11774
11775
11776
11777
11778
11779
11780
11781
11782
11783
11784
11785
11786
11787
11788
11789
11790
11791
11792
11793
11794
11795
11796
11797
11798
11799
11800
11801
11802
11803
11804
11805
11806
11807
11808
11809
11810
11811
11812
11813
11814
11815
11816
11817
11818
11819
11820
11821
11822
11823
11824
11825
11826
11827
11828
11829
11830
11831
11832
11833
11834
11835
11836
11837
11838
11839
11840
11841
11842
11843
11844
11845
11846
11847
11848
11849
11850
11851
11852
11853
11854
11855
11856
11857
11858
11859
11860
11861
11862
11863
11864
11865
11866
11867
11868
11869
11870
11871
11872
11873
11874
11875
11876
11877
11878
11879
11880
11881
11882
11883
11884
11885
11886
11887
11888
11889
11890
11891
11892
11893
11894
11895
11896
11897
11898
11899
11900
11901
11902
11903
11904
11905
11906
11907
11908
11909
11910
11911
11912
11913
11914
11915
11916
11917
11918
11919
11920
11921
11922
11923
11924
11925
11926
11927
11928
11929
11930
11931
11932
11933
11934
11935
11936
11937
11938
11939
11940
11941
11942
11943
11944
11945
11946
11947
11948
11949
11950
11951
11952
11953
11954
11955
11956
11957
11958
11959
11960
11961
11962
11963
11964
11965
11966
11967
11968
11969
11970
11971
11972
11973
11974
11975
11976
11977
11978
11979
11980
11981
11982
11983
11984
11985
11986
11987
11988
11989
11990
11991
11992
11993
11994
11995
11996
11997
11998
11999
12000
12001
12002
12003
12004
12005
12006
12007
12008
12009
12010
12011
12012
12013
12014
12015
12016
12017
12018
12019
12020
12021
12022
12023
12024
12025
12026
12027
12028
12029
12030
12031
12032
12033
12034
12035
12036
12037
12038
12039
12040
12041
12042
12043
12044
12045
12046
12047
12048
12049
12050
12051
12052
12053
12054
12055
12056
12057
12058
12059
12060
12061
12062
12063
12064
12065
12066
12067
12068
12069
12070
12071
12072
12073
12074
12075
12076
12077
12078
12079
12080
12081
12082
12083
12084
12085
12086
12087
12088
12089
12090
12091
12092
12093
12094
12095
12096
12097
12098
12099
12100
12101
12102
12103
12104
12105
12106
12107
12108
12109
12110
12111
12112
12113
12114
12115
12116
12117
12118
12119
12120
12121
12122
12123
12124
12125
12126
12127
12128
12129
12130
12131
12132
12133
12134
12135
12136
12137
12138
12139
12140
12141
12142
12143
12144
12145
12146
12147
12148
12149
12150
12151
12152
12153
12154
12155
12156
12157
12158
12159
12160
12161
12162
12163
12164
12165
12166
12167
12168
12169
12170
12171
12172
12173
12174
12175
12176
12177
12178
12179
12180
12181
12182
12183
12184
12185
12186
12187
12188
12189
12190
12191
12192
12193
12194
12195
12196
12197
12198
12199
12200
12201
12202
12203
12204
12205
12206
12207
12208
12209
12210
12211
12212
12213
12214
12215
12216
12217
12218
12219
12220
12221
12222
12223
12224
12225
12226
12227
12228
12229
12230
12231
12232
12233
12234
12235
12236
12237
12238
12239
12240
12241
12242
12243
12244
12245
12246
12247
12248
12249
12250
12251
12252
12253
12254
12255
12256
12257
12258
12259
12260
12261
12262
12263
12264
12265
12266
12267
12268
12269
12270
12271
12272
12273
12274
12275
12276
12277
12278
12279
12280
12281
12282
12283
12284
12285
12286
12287
12288
12289
12290
12291
12292
12293
12294
12295
12296
12297
12298
12299
12300
12301
12302
12303
12304
12305
12306
12307
12308
12309
12310
12311
12312
12313
12314
12315
12316
12317
12318
12319
12320
12321
12322
12323
12324
12325
12326
12327
12328
12329
12330
12331
12332
12333
12334
12335
12336
12337
12338
12339
12340
12341
12342
12343
12344
12345
12346
12347
12348
12349
12350
12351
12352
12353
12354
12355
12356
12357
12358
12359
12360
12361
12362
12363
12364
12365
12366
12367
12368
12369
12370
12371
12372
12373
12374
12375
12376
12377
12378
12379
12380
12381
12382
12383
12384
12385
12386
12387
12388
12389
12390
12391
12392
12393
12394
12395
12396
12397
12398
12399
12400
12401
12402
12403
12404
12405
12406
12407
12408
12409
12410
12411
12412
12413
12414
12415
12416
12417
12418
12419
12420
12421
12422
12423
12424
12425
12426
12427
12428
12429
12430
12431
12432
12433
12434
12435
12436
12437
12438
12439
12440
12441
12442
12443
12444
12445
12446
12447
12448
12449
12450
12451
12452
12453
12454
12455
12456
12457
12458
12459
12460
12461
12462
12463
12464
12465
12466
12467
12468
12469
12470
12471
12472
12473
12474
12475
12476
12477
12478
12479
12480
12481
12482
12483
12484
12485
12486
12487
12488
12489
12490
12491
12492
12493
12494
12495
12496
12497
12498
12499
12500
12501
12502
12503
12504
12505
12506
12507
12508
12509
12510
12511
12512
12513
12514
12515
12516
12517
12518
12519
12520
12521
12522
12523
12524
12525
12526
12527
12528
12529
12530
12531
12532
12533
12534
12535
12536
12537
12538
12539
12540
12541
12542
12543
12544
12545
12546
12547
12548
12549
12550
12551
12552
12553
12554
12555
12556
12557
12558
12559
12560
12561
12562
12563
12564
12565
12566
12567
12568
12569
12570
12571
12572
12573
12574
12575
12576
12577
12578
12579
12580
12581
12582
12583
12584
12585
12586
12587
12588
12589
12590
12591
12592
12593
12594
12595
12596
12597
12598
12599
12600
12601
12602
12603
12604
12605
12606
12607
12608
12609
12610
12611
12612
12613
12614
12615
12616
12617
12618
12619
12620
12621
12622
12623
12624
12625
12626
12627
12628
12629
12630
12631
12632
12633
12634
12635
12636
12637
12638
12639
12640
12641
12642
12643
12644
12645
12646
12647
12648
12649
12650
12651
12652
12653
12654
12655
12656
12657
12658
12659
12660
12661
12662
12663
12664
12665
12666
12667
12668
12669
12670
12671
12672
12673
12674
12675
12676
12677
12678
12679
12680
12681
12682
12683
12684
12685
12686
12687
12688
12689
12690
12691
12692
12693
12694
12695
12696
12697
12698
12699
12700
12701
12702
12703
12704
12705
12706
12707
12708
12709
12710
12711
12712
12713
12714
12715
12716
12717
12718
12719
12720
12721
12722
12723
12724
12725
12726
12727
12728
12729
12730
12731
12732
12733
12734
12735
12736
12737
12738
12739
12740
12741
12742
12743
12744
12745
12746
12747
12748
12749
12750
12751
12752
12753
12754
12755
12756
12757
12758
12759
12760
12761
12762
12763
12764
12765
12766
12767
12768
12769
12770
12771
12772
12773
12774
12775
12776
12777
12778
12779
12780
12781
12782
12783
12784
12785
12786
12787
12788
12789
12790
12791
12792
12793
12794
12795
12796
12797
12798
12799
12800
12801
12802
12803
12804
12805
12806
12807
12808
12809
12810
12811
12812
12813
12814
12815
12816
12817
12818
12819
12820
12821
12822
12823
12824
12825
12826
12827
12828
12829
12830
12831
12832
12833
12834
12835
12836
12837
12838
12839
12840
12841
12842
12843
12844
12845
12846
12847
12848
12849
12850
12851
12852
12853
12854
12855
12856
12857
12858
12859
12860
12861
12862
12863
12864
12865
12866
12867
12868
12869
12870
12871
12872
12873
12874
12875
12876
12877
12878
12879
12880
12881
12882
12883
12884
12885
12886
12887
12888
12889
12890
12891
12892
12893
12894
12895
12896
12897
12898
12899
12900
12901
12902
12903
12904
12905
12906
12907
12908
12909
12910
12911
12912
12913
12914
12915
12916
12917
12918
12919
12920
12921
12922
12923
12924
12925
12926
12927
12928
12929
12930
12931
12932
12933
12934
12935
12936
12937
12938
12939
12940
12941
12942
12943
12944
12945
12946
12947
12948
12949
12950
12951
12952
12953
12954
12955
12956
12957
12958
12959
12960
12961
12962
12963
12964
12965
12966
12967
12968
12969
12970
12971
12972
12973
12974
12975
12976
12977
12978
12979
12980
12981
12982
12983
12984
12985
12986
12987
12988
12989
12990
12991
12992
12993
12994
12995
12996
12997
12998
12999
13000
13001
13002
13003
13004
13005
13006
13007
13008
13009
13010
13011
13012
13013
13014
13015
13016
13017
13018
13019
13020
13021
13022
13023
13024
13025
13026
13027
13028
13029
13030
13031
13032
13033
13034
13035
13036
13037
13038
13039
13040
13041
13042
13043
13044
13045
13046
13047
13048
13049
13050
13051
13052
13053
13054
13055
13056
13057
13058
13059
13060
13061
13062
13063
13064
13065
13066
13067
13068
13069
13070
13071
13072
13073
13074
13075
13076
13077
13078
13079
13080
13081
13082
13083
13084
13085
13086
13087
13088
13089
13090
13091
13092
13093
13094
13095
13096
13097
13098
13099
13100
13101
13102
13103
13104
13105
13106
13107
13108
13109
13110
13111
13112
13113
13114
13115
13116
13117
13118
13119
13120
13121
13122
13123
13124
13125
13126
13127
13128
13129
13130
13131
13132
13133
13134
13135
13136
13137
13138
13139
13140
13141
13142
13143
13144
13145
13146
13147
13148
13149
13150
13151
13152
13153
13154
13155
13156
13157
13158
13159
13160
13161
13162
13163
13164
13165
13166
13167
13168
13169
13170
13171
13172
13173
13174
13175
13176
13177
13178
13179
13180
13181
13182
13183
13184
13185
13186
13187
13188
13189
13190
13191
13192
13193
13194
13195
13196
13197
13198
13199
13200
13201
13202
13203
13204
13205
13206
13207
13208
13209
13210
13211
13212
13213
13214
13215
13216
13217
13218
13219
13220
13221
13222
13223
13224
13225
13226
13227
13228
13229
13230
13231
13232
13233
13234
13235
13236
13237
13238
13239
13240
13241
13242
13243
13244
13245
13246
13247
13248
13249
13250
13251
13252
13253
13254
13255
13256
13257
13258
13259
13260
13261
13262
13263
13264
13265
13266
13267
13268
13269
13270
13271
13272
13273
13274
13275
13276
13277
13278
13279
13280
13281
13282
13283
13284
13285
13286
13287
13288
13289
13290
13291
13292
13293
13294
13295
13296
13297
13298
13299
13300
13301
13302
13303
13304
13305
13306
13307
13308
13309
13310
13311
13312
13313
13314
13315
13316
13317
13318
13319
13320
13321
13322
13323
13324
13325
13326
13327
13328
13329
13330
13331
13332
13333
13334
13335
13336
13337
13338
13339
13340
13341
13342
13343
13344
13345
13346
13347
13348
13349
13350
13351
13352
13353
13354
13355
13356
13357
13358
13359
13360
13361
13362
13363
13364
13365
13366
13367
13368
13369
13370
13371
13372
13373
13374
13375
13376
13377
13378
13379
13380
13381
13382
13383
13384
13385
13386
13387
13388
13389
13390
13391
13392
13393
13394
13395
13396
13397
13398
13399
13400
13401
13402
13403
13404
13405
13406
13407
13408
13409
13410
13411
13412
13413
13414
13415
13416
13417
13418
13419
13420
13421
13422
13423
13424
13425
13426
13427
13428
13429
13430
13431
13432
13433
13434
13435
13436
13437
13438
13439
13440
13441
13442
13443
13444
13445
13446
13447
13448
13449
13450
13451
13452
13453
13454
13455
13456
13457
13458
13459
13460
13461
13462
13463
13464
13465
13466
13467
13468
13469
13470
13471
13472
13473
13474
13475
13476
13477
13478
13479
13480
13481
13482
13483
13484
13485
13486
13487
13488
13489
13490
13491
13492
13493
13494
13495
13496
13497
13498
13499
13500
13501
13502
13503
13504
13505
13506
13507
13508
13509
13510
13511
13512
13513
13514
13515
13516
13517
13518
13519
13520
13521
13522
13523
13524
13525
13526
13527
13528
13529
13530
13531
13532
13533
13534
13535
13536
13537
13538
13539
13540
13541
13542
13543
13544
13545
13546
13547
13548
13549
13550
13551
13552
13553
13554
13555
13556
13557
13558
13559
13560
13561
13562
13563
13564
13565
13566
13567
13568
13569
13570
13571
13572
13573
13574
13575
13576
13577
13578
13579
13580
13581
13582
13583
13584
13585
13586
13587
13588
13589
13590
13591
13592
13593
13594
13595
13596
13597
13598
13599
13600
13601
13602
13603
13604
13605
13606
13607
13608
13609
13610
13611
13612
13613
13614
13615
13616
13617
13618
13619
13620
13621
13622
13623
13624
13625
13626
13627
13628
13629
13630
13631
13632
13633
13634
13635
13636
13637
13638
13639
13640
13641
13642
13643
13644
13645
13646
13647
13648
13649
13650
13651
13652
13653
13654
13655
13656
13657
13658
13659
13660
13661
13662
13663
13664
13665
13666
13667
13668
13669
13670
13671
13672
13673
13674
13675
13676
13677
13678
13679
13680
13681
13682
13683
13684
13685
13686
13687
13688
13689
13690
13691
13692
13693
13694
13695
13696
13697
13698
13699
13700
13701
13702
13703
13704
13705
13706
13707
13708
13709
13710
13711
13712
13713
13714
13715
13716
13717
13718
13719
13720
13721
13722
13723
13724
13725
13726
13727
13728
13729
13730
13731
13732
13733
13734
13735
13736
13737
13738
13739
13740
13741
13742
13743
13744
13745
13746
13747
13748
13749
13750
13751
13752
13753
13754
13755
13756
13757
13758
13759
13760
13761
13762
13763
13764
13765
13766
13767
13768
13769
13770
13771
13772
13773
13774
13775
13776
13777
13778
13779
13780
13781
13782
13783
13784
13785
13786
13787
13788
13789
13790
13791
13792
13793
13794
13795
13796
13797
13798
13799
13800
13801
13802
13803
13804
13805
13806
13807
13808
13809
13810
13811
13812
13813
13814
13815
13816
13817
13818
13819
13820
13821
13822
13823
13824
13825
13826
13827
13828
13829
13830
13831
13832
13833
13834
13835
13836
13837
13838
13839
13840
13841
13842
13843
13844
13845
13846
13847
13848
13849
13850
13851
13852
13853
13854
13855
13856
13857
13858
13859
13860
13861
13862
13863
13864
13865
13866
13867
13868
13869
13870
13871
13872
13873
13874
13875
13876
13877
13878
13879
13880
13881
13882
13883
13884
13885
13886
13887
13888
13889
13890
13891
13892
13893
13894
13895
13896
13897
13898
13899
13900
13901
13902
13903
13904
13905
13906
13907
13908
13909
13910
13911
13912
13913
13914
13915
13916
13917
13918
13919
13920
13921
13922
13923
13924
13925
13926
13927
13928
13929
13930
13931
13932
13933
13934
13935
13936
13937
13938
13939
13940
13941
13942
13943
13944
13945
13946
13947
13948
13949
13950
13951
13952
13953
13954
13955
13956
13957
13958
13959
13960
13961
13962
13963
13964
13965
13966
13967
13968
13969
13970
13971
13972
13973
13974
13975
13976
13977
13978
13979
13980
13981
13982
13983
13984
13985
13986
13987
13988
13989
13990
13991
13992
13993
13994
13995
13996
13997
13998
13999
14000
14001
14002
14003
14004
14005
14006
14007
14008
14009
14010
14011
14012
14013
14014
14015
14016
14017
14018
14019
14020
14021
14022
14023
14024
14025
14026
14027
14028
14029
14030
14031
14032
14033
14034
14035
14036
14037
14038
14039
14040
14041
14042
14043
14044
14045
14046
14047
14048
14049
14050
14051
14052
14053
14054
14055
14056
14057
14058
14059
14060
14061
14062
14063
14064
14065
14066
14067
14068
14069
14070
14071
14072
14073
14074
14075
14076
14077
14078
14079
14080
14081
14082
14083
14084
14085
14086
14087
14088
14089
14090
14091
14092
14093
14094
14095
14096
14097
14098
14099
14100
14101
14102
14103
14104
14105
14106
14107
14108
14109
14110
14111
14112
14113
14114
14115
14116
14117
14118
14119
14120
14121
14122
14123
14124
14125
14126
14127
14128
14129
14130
14131
14132
14133
14134
14135
14136
14137
14138
14139
14140
14141
14142
14143
14144
14145
14146
14147
14148
14149
14150
14151
14152
14153
14154
14155
14156
14157
14158
14159
14160
14161
14162
14163
14164
14165
14166
14167
14168
14169
14170
14171
14172
14173
14174
14175
14176
14177
14178
14179
14180
14181
14182
14183
14184
14185
14186
14187
14188
14189
14190
14191
14192
14193
14194
14195
14196
14197
14198
14199
14200
14201
14202
14203
14204
14205
14206
14207
14208
14209
14210
14211
14212
14213
14214
14215
14216
14217
14218
14219
14220
14221
14222
14223
14224
14225
14226
14227
14228
14229
14230
14231
14232
14233
14234
14235
14236
14237
14238
14239
14240
14241
14242
14243
14244
14245
14246
14247
14248
14249
14250
14251
14252
14253
14254
14255
14256
14257
14258
14259
14260
14261
14262
14263
14264
14265
14266
14267
14268
14269
14270
14271
14272
14273
14274
14275
14276
14277
14278
14279
14280
14281
14282
14283
14284
14285
14286
14287
14288
14289
14290
14291
14292
14293
14294
14295
14296
14297
14298
14299
14300
14301
14302
14303
14304
14305
14306
14307
14308
14309
14310
14311
14312
14313
14314
14315
14316
14317
14318
14319
14320
14321
14322
14323
14324
14325
14326
14327
14328
14329
14330
14331
14332
14333
14334
14335
14336
14337
14338
14339
14340
14341
14342
14343
14344
14345
14346
14347
14348
14349
14350
14351
14352
14353
14354
14355
14356
14357
14358
14359
14360
14361
14362
14363
14364
14365
14366
14367
14368
14369
14370
14371
14372
14373
14374
14375
14376
14377
14378
14379
14380
14381
14382
14383
14384
14385
14386
14387
14388
14389
14390
14391
14392
14393
14394
14395
14396
14397
14398
14399
14400
14401
14402
14403
14404
14405
14406
14407
14408
14409
14410
14411
14412
14413
14414
14415
14416
14417
14418
14419
14420
14421
14422
14423
14424
14425
14426
14427
14428
14429
14430
14431
14432
14433
14434
14435
14436
14437
14438
14439
14440
14441
14442
14443
14444
14445
14446
14447
14448
14449
14450
14451
14452
14453
14454
14455
14456
14457
14458
14459
14460
14461
14462
14463
14464
14465
14466
14467
14468
14469
14470
14471
14472
14473
14474
14475
14476
14477
14478
14479
14480
14481
14482
14483
14484
14485
14486
14487
14488
14489
14490
14491
14492
14493
14494
14495
14496
14497
14498
14499
14500
14501
14502
14503
14504
14505
14506
14507
14508
14509
14510
14511
14512
14513
14514
14515
14516
14517
14518
14519
14520
14521
14522
14523
14524
14525
14526
14527
14528
14529
14530
14531
14532
14533
14534
14535
14536
14537
14538
14539
14540
14541
14542
14543
14544
14545
14546
14547
14548
14549
14550
14551
14552
14553
14554
14555
14556
14557
14558
14559
14560
14561
14562
14563
14564
14565
14566
14567
14568
14569
14570
14571
14572
14573
14574
14575
14576
14577
14578
14579
14580
14581
14582
14583
14584
14585
14586
14587
14588
14589
14590
14591
14592
14593
14594
14595
14596
14597
14598
14599
14600
14601
14602
14603
14604
14605
14606
14607
14608
14609
14610
14611
14612
14613
14614
14615
14616
14617
14618
14619
14620
14621
14622
14623
14624
14625
14626
14627
14628
14629
14630
14631
14632
14633
14634
14635
14636
14637
14638
14639
14640
14641
14642
14643
14644
14645
14646
14647
14648
14649
14650
14651
14652
14653
14654
14655
14656
14657
14658
14659
14660
14661
14662
14663
14664
14665
14666
14667
14668
14669
14670
14671
14672
14673
14674
14675
14676
14677
14678
14679
14680
14681
14682
14683
14684
14685
14686
14687
14688
14689
14690
14691
14692
14693
14694
14695
14696
14697
14698
14699
14700
14701
14702
14703
14704
14705
14706
14707
14708
14709
14710
14711
14712
14713
14714
14715
14716
14717
14718
14719
14720
14721
14722
14723
14724
14725
14726
14727
14728
14729
14730
14731
14732
14733
14734
14735
14736
14737
14738
14739
14740
14741
14742
14743
14744
14745
14746
14747
14748
14749
14750
14751
14752
14753
14754
14755
14756
14757
14758
14759
14760
14761
14762
14763
14764
14765
14766
14767
14768
14769
14770
14771
14772
14773
14774
14775
14776
14777
14778
14779
14780
14781
14782
14783
14784
14785
14786
14787
14788
14789
14790
14791
14792
14793
14794
14795
14796
14797
14798
14799
14800
14801
14802
14803
14804
14805
14806
14807
14808
14809
14810
14811
14812
14813
14814
14815
14816
14817
14818
14819
14820
14821
14822
14823
14824
14825
14826
14827
14828
14829
14830
14831
14832
14833
14834
14835
14836
14837
14838
14839
14840
14841
14842
14843
14844
14845
14846
14847
14848
14849
14850
14851
14852
14853
14854
14855
14856
14857
14858
14859
14860
14861
14862
14863
14864
14865
14866
14867
14868
14869
14870
14871
14872
14873
14874
14875
14876
14877
14878
14879
14880
14881
14882
14883
14884
14885
14886
14887
14888
14889
14890
14891
14892
14893
14894
14895
14896
14897
14898
14899
14900
14901
14902
14903
14904
14905
14906
14907
14908
14909
14910
14911
14912
14913
14914
14915
14916
14917
14918
14919
14920
14921
14922
14923
14924
14925
14926
14927
14928
14929
14930
14931
14932
14933
14934
14935
14936
14937
14938
14939
14940
14941
14942
14943
14944
14945
14946
14947
14948
14949
14950
14951
14952
14953
14954
14955
14956
14957
14958
14959
14960
14961
14962
14963
14964
14965
14966
14967
14968
14969
14970
14971
14972
14973
14974
14975
14976
14977
14978
14979
14980
14981
14982
14983
14984
14985
14986
14987
14988
14989
14990
14991
14992
14993
14994
14995
14996
14997
14998
14999
15000
15001
15002
15003
15004
15005
15006
15007
15008
15009
15010
15011
15012
15013
15014
15015
15016
15017
15018
15019
15020
15021
15022
15023
15024
15025
15026
15027
15028
15029
15030
15031
15032
15033
15034
15035
15036
15037
15038
15039
15040
15041
15042
15043
15044
15045
15046
15047
15048
15049
15050
15051
15052
15053
15054
15055
15056
15057
15058
15059
15060
15061
15062
15063
15064
15065
15066
15067
15068
15069
15070
15071
15072
15073
15074
15075
15076
15077
15078
15079
15080
15081
15082
15083
15084
15085
15086
15087
15088
15089
15090
15091
15092
15093
15094
15095
15096
15097
15098
15099
15100
15101
15102
15103
15104
15105
15106
15107
15108
15109
15110
15111
15112
15113
15114
15115
15116
15117
15118
15119
15120
15121
15122
15123
15124
15125
15126
15127
15128
15129
15130
15131
15132
15133
15134
15135
15136
15137
15138
15139
15140
15141
15142
15143
15144
15145
15146
15147
15148
15149
15150
15151
15152
15153
15154
15155
15156
15157
15158
15159
15160
15161
15162
15163
15164
15165
15166
15167
15168
15169
15170
15171
15172
15173
15174
15175
15176
15177
15178
15179
15180
15181
15182
15183
15184
15185
15186
15187
15188
15189
15190
15191
15192
15193
15194
15195
15196
15197
15198
15199
15200
15201
15202
15203
15204
15205
15206
15207
15208
15209
15210
15211
15212
15213
15214
15215
15216
15217
15218
15219
15220
15221
15222
15223
15224
15225
15226
15227
15228
15229
15230
15231
15232
15233
15234
15235
15236
15237
15238
15239
15240
15241
15242
15243
15244
15245
15246
15247
15248
15249
15250
15251
15252
15253
15254
15255
15256
15257
15258
15259
15260
15261
15262
15263
15264
15265
15266
15267
15268
15269
15270
15271
15272
15273
15274
15275
15276
15277
15278
15279
15280
15281
15282
15283
15284
15285
15286
15287
15288
15289
15290
15291
15292
15293
15294
15295
15296
15297
15298
15299
15300
15301
15302
15303
15304
15305
15306
15307
15308
15309
15310
15311
15312
15313
15314
15315
15316
15317
15318
15319
15320
15321
15322
15323
15324
15325
15326
15327
15328
15329
15330
15331
15332
15333
15334
15335
15336
15337
15338
15339
15340
15341
15342
15343
15344
15345
15346
15347
15348
15349
15350
15351
15352
15353
15354
15355
15356
15357
15358
15359
15360
15361
15362
15363
15364
15365
15366
15367
15368
15369
15370
15371
15372
15373
15374
15375
15376
15377
15378
15379
15380
15381
15382
15383
15384
15385
15386
15387
15388
15389
15390
15391
15392
15393
15394
15395
15396
15397
15398
15399
15400
15401
15402
15403
15404
15405
15406
15407
15408
15409
15410
15411
15412
15413
15414
15415
15416
15417
15418
15419
15420
15421
15422
15423
15424
15425
15426
15427
15428
15429
15430
15431
15432
15433
15434
15435
15436
15437
15438
15439
15440
15441
15442
15443
15444
15445
15446
15447
15448
15449
15450
15451
15452
15453
15454
15455
15456
15457
15458
15459
15460
15461
15462
15463
15464
15465
15466
15467
15468
15469
15470
15471
15472
15473
15474
15475
15476
15477
15478
15479
15480
15481
15482
15483
15484
15485
15486
15487
15488
15489
15490
15491
15492
15493
15494
15495
15496
15497
15498
15499
15500
15501
15502
15503
15504
15505
15506
15507
15508
15509
15510
15511
15512
15513
15514
15515
15516
15517
15518
15519
15520
15521
15522
15523
15524
15525
15526
15527
15528
15529
15530
15531
15532
15533
15534
15535
15536
15537
15538
15539
15540
15541
15542
15543
15544
15545
15546
15547
15548
15549
15550
15551
15552
15553
15554
15555
15556
15557
15558
15559
15560
15561
15562
15563
15564
15565
15566
15567
15568
15569
15570
15571
15572
15573
15574
15575
15576
15577
15578
15579
15580
15581
15582
15583
15584
15585
15586
15587
15588
15589
15590
15591
15592
15593
15594
15595
15596
15597
15598
15599
15600
15601
15602
15603
15604
15605
15606
15607
15608
15609
15610
15611
15612
15613
15614
15615
15616
15617
15618
15619
15620
15621
15622
15623
15624
15625
15626
15627
15628
15629
15630
15631
15632
15633
15634
15635
15636
15637
15638
15639
15640
15641
15642
15643
15644
15645
15646
15647
15648
15649
15650
15651
15652
15653
15654
15655
15656
15657
15658
15659
15660
15661
15662
15663
15664
15665
15666
15667
15668
15669
15670
15671
15672
15673
15674
15675
15676
15677
15678
15679
15680
15681
15682
15683
15684
15685
15686
15687
15688
15689
15690
15691
15692
15693
15694
15695
15696
15697
15698
15699
15700
15701
15702
15703
15704
15705
15706
15707
15708
15709
15710
15711
15712
15713
15714
15715
15716
15717
15718
15719
15720
15721
15722
15723
15724
15725
15726
15727
15728
15729
15730
15731
15732
15733
15734
15735
15736
15737
15738
15739
15740
15741
15742
15743
15744
15745
15746
15747
15748
15749
15750
15751
15752
15753
15754
15755
15756
15757
15758
15759
15760
15761
15762
15763
15764
15765
15766
15767
15768
15769
15770
15771
15772
15773
15774
15775
15776
15777
15778
15779
15780
15781
15782
15783
15784
15785
15786
15787
15788
15789
15790
15791
15792
15793
15794
15795
15796
15797
15798
15799
15800
15801
15802
15803
15804
15805
15806
15807
15808
15809
15810
15811
15812
15813
15814
15815
15816
15817
15818
15819
15820
15821
15822
15823
15824
15825
15826
15827
15828
15829
15830
15831
15832
15833
15834
15835
15836
15837
15838
15839
15840
15841
15842
15843
15844
15845
15846
15847
15848
15849
15850
15851
15852
15853
15854
15855
15856
15857
15858
15859
15860
15861
15862
15863
15864
15865
15866
15867
15868
15869
15870
15871
15872
15873
15874
15875
15876
15877
15878
15879
15880
15881
15882
15883
15884
15885
15886
15887
15888
15889
15890
15891
15892
15893
15894
15895
15896
15897
15898
15899
15900
15901
15902
15903
15904
15905
15906
15907
15908
15909
15910
15911
15912
15913
15914
15915
15916
15917
15918
15919
15920
15921
15922
15923
15924
15925
15926
15927
15928
15929
15930
15931
15932
15933
15934
15935
15936
15937
15938
15939
15940
15941
15942
15943
15944
15945
15946
15947
15948
15949
15950
15951
15952
15953
15954
15955
15956
15957
15958
15959
15960
15961
15962
15963
15964
15965
15966
15967
15968
15969
15970
15971
15972
15973
15974
15975
15976
15977
15978
15979
15980
15981
15982
15983
15984
15985
15986
15987
15988
15989
15990
15991
15992
15993
15994
15995
15996
15997
15998
15999
16000
16001
16002
16003
16004
16005
16006
16007
16008
16009
16010
16011
16012
16013
16014
16015
16016
16017
16018
16019
16020
16021
16022
16023
16024
16025
16026
16027
16028
16029
16030
16031
16032
16033
16034
16035
16036
16037
16038
16039
16040
16041
16042
16043
16044
16045
16046
16047
16048
16049
16050
16051
16052
16053
16054
16055
16056
16057
16058
16059
16060
16061
16062
16063
16064
16065
16066
16067
16068
16069
16070
16071
16072
16073
16074
16075
16076
16077
16078
16079
16080
16081
16082
16083
16084
16085
16086
16087
16088
16089
16090
16091
16092
16093
16094
16095
16096
16097
16098
16099
16100
16101
16102
16103
16104
16105
16106
16107
16108
16109
16110
16111
16112
16113
16114
16115
16116
16117
16118
16119
16120
16121
16122
16123
16124
16125
16126
16127
16128
16129
16130
16131
16132
16133
16134
16135
16136
16137
16138
16139
16140
16141
16142
16143
16144
16145
16146
16147
16148
16149
16150
16151
16152
16153
16154
16155
16156
16157
16158
16159
16160
16161
16162
16163
16164
16165
16166
16167
16168
16169
16170
16171
16172
16173
16174
16175
16176
16177
16178
16179
16180
16181
16182
16183
16184
16185
16186
16187
16188
16189
16190
16191
16192
16193
16194
16195
16196
16197
16198
16199
16200
16201
16202
16203
16204
16205
16206
16207
16208
16209
16210
16211
16212
16213
16214
16215
16216
16217
16218
16219
16220
16221
16222
16223
16224
16225
16226
16227
16228
16229
16230
16231
16232
16233
16234
16235
16236
16237
16238
16239
16240
16241
16242
16243
16244
16245
16246
16247
16248
16249
16250
16251
16252
16253
16254
16255
16256
16257
16258
16259
16260
16261
16262
16263
16264
16265
16266
16267
16268
16269
16270
16271
16272
16273
16274
16275
16276
16277
16278
16279
16280
16281
16282
16283
16284
16285
16286
16287
16288
16289
16290
16291
16292
16293
16294
16295
16296
16297
16298
16299
16300
16301
16302
16303
16304
16305
16306
16307
16308
16309
16310
16311
16312
16313
16314
16315
16316
16317
16318
16319
16320
16321
16322
16323
16324
16325
16326
16327
16328
16329
16330
16331
16332
16333
16334
16335
16336
16337
16338
16339
16340
16341
16342
16343
16344
16345
16346
16347
16348
16349
16350
16351
16352
16353
16354
16355
16356
16357
16358
16359
16360
16361
16362
16363
16364
16365
16366
16367
16368
16369
16370
16371
16372
16373
16374
16375
16376
16377
16378
16379
16380
16381
16382
16383
16384
16385
16386
16387
16388
16389
16390
16391
16392
16393
16394
16395
16396
16397
16398
16399
16400
16401
16402
16403
16404
16405
16406
16407
16408
16409
16410
16411
16412
16413
16414
16415
16416
16417
16418
16419
16420
16421
16422
16423
16424
16425
16426
16427
16428
16429
16430
16431
16432
16433
16434
16435
16436
16437
16438
16439
16440
16441
16442
16443
16444
16445
16446
16447
16448
16449
16450
16451
16452
16453
16454
16455
16456
16457
16458
16459
16460
16461
16462
16463
16464
16465
16466
16467
16468
16469
16470
16471
16472
16473
16474
16475
16476
16477
16478
16479
16480
16481
16482
16483
16484
16485
16486
16487
16488
16489
16490
16491
16492
16493
16494
16495
16496
16497
16498
16499
16500
16501
16502
16503
16504
16505
16506
16507
16508
16509
16510
16511
16512
16513
16514
16515
16516
16517
16518
16519
16520
16521
16522
16523
16524
16525
16526
16527
16528
16529
16530
16531
16532
16533
16534
16535
16536
16537
16538
16539
16540
16541
16542
16543
16544
16545
16546
16547
16548
16549
16550
16551
16552
16553
16554
16555
16556
16557
16558
16559
16560
16561
16562
16563
16564
16565
16566
16567
16568
16569
16570
16571
16572
16573
16574
16575
16576
16577
16578
16579
16580
16581
16582
16583
16584
16585
16586
16587
16588
16589
16590
16591
16592
16593
16594
16595
16596
16597
16598
16599
16600
16601
16602
16603
16604
16605
16606
16607
16608
16609
16610
16611
16612
16613
16614
16615
16616
16617
16618
16619
16620
16621
16622
16623
16624
16625
16626
16627
16628
16629
16630
16631
16632
16633
16634
16635
16636
16637
16638
16639
16640
16641
16642
16643
16644
16645
16646
16647
16648
16649
16650
16651
16652
16653
16654
16655
16656
16657
16658
16659
16660
16661
16662
16663
16664
16665
16666
16667
16668
16669
16670
16671
16672
16673
16674
16675
16676
16677
16678
16679
16680
16681
16682
16683
16684
16685
16686
16687
16688
16689
16690
16691
16692
16693
16694
16695
16696
16697
16698
16699
16700
16701
16702
16703
16704
16705
16706
16707
16708
16709
16710
16711
16712
16713
16714
16715
16716
16717
16718
16719
16720
16721
16722
16723
16724
16725
16726
16727
16728
16729
16730
16731
16732
16733
16734
16735
16736
16737
16738
16739
16740
16741
16742
16743
16744
16745
16746
16747
16748
16749
16750
16751
16752
16753
16754
16755
16756
16757
16758
16759
16760
16761
16762
16763
16764
16765
16766
16767
16768
16769
16770
16771
16772
16773
16774
16775
16776
16777
16778
16779
16780
16781
16782
16783
16784
16785
16786
16787
16788
16789
16790
16791
16792
16793
16794
16795
16796
16797
16798
16799
16800
16801
16802
16803
16804
16805
16806
16807
16808
16809
16810
16811
16812
16813
16814
16815
16816
16817
16818
16819
16820
16821
16822
16823
16824
16825
16826
16827
16828
16829
16830
16831
16832
16833
16834
16835
16836
16837
16838
16839
16840
16841
16842
16843
16844
16845
16846
16847
16848
16849
16850
16851
16852
16853
16854
16855
16856
16857
16858
16859
16860
16861
16862
16863
16864
16865
16866
16867
16868
16869
16870
16871
16872
16873
16874
16875
16876
16877
16878
16879
16880
16881
16882
16883
16884
16885
16886
16887
16888
16889
16890
16891
16892
16893
16894
16895
16896
16897
16898
16899
16900
16901
16902
16903
16904
16905
16906
16907
16908
16909
16910
16911
16912
16913
16914
16915
16916
16917
16918
16919
16920
16921
16922
16923
16924
16925
16926
16927
16928
16929
16930
16931
16932
16933
16934
16935
16936
16937
16938
16939
16940
16941
16942
16943
16944
16945
16946
16947
16948
16949
16950
16951
16952
16953
16954
16955
16956
16957
16958
16959
16960
16961
16962
16963
16964
16965
16966
16967
16968
16969
16970
16971
16972
16973
16974
16975
16976
16977
16978
16979
16980
16981
16982
16983
16984
16985
16986
16987
16988
16989
16990
16991
16992
16993
16994
16995
16996
16997
16998
16999
17000
17001
17002
17003
17004
17005
17006
17007
17008
17009
17010
17011
17012
17013
17014
17015
17016
17017
17018
17019
17020
17021
17022
17023
17024
17025
17026
17027
17028
17029
17030
17031
17032
17033
17034
17035
17036
17037
17038
17039
17040
17041
17042
17043
17044
17045
17046
17047
17048
17049
17050
17051
17052
17053
17054
17055
17056
17057
17058
17059
17060
17061
17062
17063
17064
17065
17066
17067
17068
17069
17070
17071
17072
17073
17074
17075
17076
17077
17078
17079
17080
17081
17082
17083
17084
17085
17086
17087
17088
17089
17090
17091
17092
17093
17094
17095
17096
17097
17098
17099
17100
17101
17102
17103
17104
17105
17106
17107
17108
17109
17110
17111
17112
17113
17114
17115
17116
17117
17118
17119
17120
17121
17122
17123
17124
17125
17126
17127
17128
17129
17130
17131
17132
17133
17134
17135
17136
17137
17138
17139
17140
17141
17142
17143
17144
17145
17146
17147
17148
17149
17150
17151
17152
17153
17154
17155
17156
17157
17158
17159
17160
17161
17162
17163
17164
17165
17166
17167
17168
17169
17170
17171
17172
17173
17174
17175
17176
17177
17178
17179
17180
17181
17182
17183
17184
17185
17186
17187
17188
17189
17190
17191
17192
17193
17194
17195
17196
17197
17198
17199
17200
17201
17202
17203
17204
17205
17206
17207
17208
17209
17210
17211
17212
17213
17214
17215
17216
17217
17218
17219
17220
17221
17222
17223
17224
17225
17226
17227
17228
17229
17230
17231
17232
17233
17234
17235
17236
17237
17238
17239
17240
17241
17242
17243
17244
17245
17246
17247
17248
17249
17250
17251
17252
17253
17254
17255
17256
17257
17258
17259
17260
17261
17262
17263
17264
17265
17266
17267
17268
17269
17270
17271
17272
17273
17274
17275
17276
17277
17278
17279
17280
17281
17282
17283
17284
17285
17286
17287
17288
17289
17290
17291
17292
17293
17294
17295
17296
17297
17298
17299
17300
17301
17302
17303
17304
17305
17306
17307
17308
17309
17310
17311
17312
17313
17314
17315
17316
17317
17318
17319
17320
17321
17322
17323
17324
17325
17326
17327
17328
17329
17330
17331
17332
17333
17334
17335
17336
17337
17338
17339
17340
17341
17342
17343
17344
17345
17346
17347
17348
17349
17350
17351
17352
17353
17354
17355
17356
17357
17358
17359
17360
17361
17362
17363
17364
17365
17366
17367
17368
17369
17370
17371
17372
17373
17374
17375
17376
17377
17378
17379
17380
17381
17382
17383
17384
17385
17386
17387
17388
17389
17390
17391
17392
17393
17394
17395
17396
17397
17398
17399
17400
17401
17402
17403
17404
17405
17406
17407
17408
17409
17410
17411
17412
17413
17414
17415
17416
17417
17418
17419
17420
17421
17422
17423
17424
17425
17426
17427
17428
17429
17430
17431
17432
17433
17434
17435
17436
17437
17438
17439
17440
17441
17442
17443
17444
17445
17446
17447
17448
17449
17450
17451
17452
17453
17454
17455
17456
17457
17458
17459
17460
17461
17462
17463
17464
17465
17466
17467
17468
17469
17470
17471
17472
17473
17474
17475
17476
17477
17478
17479
17480
17481
17482
17483
17484
17485
17486
17487
17488
17489
17490
17491
17492
17493
17494
17495
17496
17497
17498
17499
17500
17501
17502
17503
17504
17505
17506
17507
17508
17509
17510
17511
17512
17513
17514
17515
17516
17517
17518
17519
17520
17521
17522
17523
17524
17525
17526
17527
17528
17529
17530
17531
17532
17533
17534
17535
17536
17537
17538
17539
17540
17541
17542
17543
17544
17545
17546
17547
17548
17549
17550
17551
17552
17553
17554
17555
17556
17557
17558
17559
17560
17561
17562
17563
17564
17565
17566
17567
17568
17569
17570
17571
17572
17573
17574
17575
17576
17577
17578
17579
17580
17581
17582
17583
17584
17585
17586
17587
17588
17589
17590
17591
17592
17593
17594
17595
17596
17597
17598
17599
17600
17601
17602
17603
17604
17605
17606
17607
17608
17609
17610
17611
17612
17613
17614
17615
17616
17617
17618
17619
17620
17621
17622
17623
17624
17625
17626
17627
17628
17629
17630
17631
17632
17633
17634
17635
17636
17637
17638
17639
17640
17641
17642
17643
17644
17645
17646
17647
17648
17649
17650
17651
17652
17653
17654
17655
17656
17657
17658
17659
17660
17661
17662
17663
17664
17665
17666
17667
17668
17669
17670
17671
17672
17673
17674
17675
17676
17677
17678
17679
17680
17681
17682
17683
17684
17685
17686
17687
17688
17689
17690
17691
17692
17693
17694
17695
17696
17697
17698
17699
17700
17701
17702
17703
17704
17705
17706
17707
17708
17709
17710
17711
17712
17713
17714
17715
17716
17717
17718
17719
17720
17721
17722
17723
17724
17725
17726
17727
17728
17729
17730
17731
17732
17733
17734
17735
17736
17737
17738
17739
17740
17741
17742
17743
17744
17745
17746
17747
17748
17749
17750
17751
17752
17753
17754
17755
17756
17757
17758
17759
17760
17761
17762
17763
17764
17765
17766
17767
17768
17769
17770
17771
17772
17773
17774
17775
17776
17777
17778
17779
17780
17781
17782
17783
17784
17785
17786
17787
17788
17789
17790
17791
17792
17793
17794
17795
17796
17797
17798
17799
17800
17801
17802
17803
17804
17805
17806
17807
17808
17809
17810
17811
17812
17813
17814
17815
17816
17817
17818
17819
17820
17821
17822
17823
17824
17825
17826
17827
17828
17829
17830
17831
17832
17833
17834
17835
17836
17837
17838
17839
17840
17841
17842
17843
17844
17845
17846
17847
17848
17849
17850
17851
17852
17853
17854
17855
17856
17857
17858
17859
17860
17861
17862
17863
17864
17865
17866
17867
17868
17869
17870
17871
17872
17873
17874
17875
17876
17877
17878
17879
17880
17881
17882
17883
17884
17885
17886
17887
17888
17889
17890
17891
17892
17893
17894
17895
17896
17897
17898
17899
17900
17901
17902
17903
17904
17905
17906
17907
17908
17909
17910
17911
17912
17913
17914
17915
17916
17917
17918
17919
17920
17921
17922
17923
17924
17925
17926
17927
17928
17929
17930
17931
17932
17933
17934
17935
17936
17937
17938
17939
17940
17941
17942
17943
17944
17945
17946
17947
17948
17949
17950
17951
17952
17953
17954
17955
17956
17957
17958
17959
17960
17961
17962
17963
17964
17965
17966
17967
17968
17969
17970
17971
17972
17973
17974
17975
17976
17977
17978
17979
17980
17981
17982
17983
17984
17985
17986
17987
17988
17989
17990
17991
17992
17993
17994
17995
17996
17997
17998
17999
18000
18001
18002
18003
18004
18005
18006
18007
18008
18009
18010
18011
18012
18013
18014
18015
18016
18017
18018
18019
18020
18021
18022
18023
18024
18025
18026
18027
18028
18029
18030
18031
18032
18033
18034
18035
18036
18037
18038
18039
18040
18041
18042
18043
18044
18045
18046
18047
18048
18049
18050
18051
18052
18053
18054
18055
18056
18057
18058
18059
18060
18061
18062
18063
18064
18065
18066
18067
18068
18069
18070
18071
18072
18073
18074
18075
18076
18077
18078
18079
18080
18081
18082
18083
18084
18085
18086
18087
18088
18089
18090
18091
18092
18093
18094
18095
18096
18097
18098
18099
18100
18101
18102
18103
18104
18105
18106
18107
18108
18109
18110
18111
18112
18113
18114
18115
18116
18117
18118
18119
18120
18121
18122
18123
18124
18125
18126
18127
18128
18129
18130
18131
18132
18133
18134
18135
18136
18137
18138
18139
18140
18141
18142
18143
18144
18145
18146
18147
18148
18149
18150
18151
18152
18153
18154
18155
18156
18157
18158
18159
18160
18161
18162
18163
18164
18165
18166
18167
18168
18169
18170
18171
18172
18173
18174
18175
18176
18177
18178
18179
18180
18181
18182
18183
18184
18185
18186
18187
18188
18189
18190
18191
18192
18193
18194
18195
18196
18197
18198
18199
18200
18201
18202
18203
18204
18205
18206
18207
18208
18209
18210
18211
18212
18213
18214
18215
18216
18217
18218
18219
18220
18221
18222
18223
18224
18225
18226
18227
18228
18229
18230
18231
18232
18233
18234
18235
18236
18237
18238
18239
18240
18241
18242
18243
18244
18245
18246
18247
18248
18249
18250
18251
18252
18253
18254
18255
18256
18257
18258
18259
18260
18261
18262
18263
18264
18265
18266
18267
18268
18269
18270
18271
18272
18273
18274
18275
18276
18277
18278
18279
18280
18281
18282
18283
18284
18285
18286
18287
18288
18289
18290
18291
18292
18293
18294
18295
18296
18297
18298
18299
18300
18301
18302
18303
18304
18305
18306
18307
18308
18309
18310
18311
18312
18313
18314
18315
18316
18317
18318
18319
18320
18321
18322
18323
18324
18325
18326
18327
18328
18329
18330
18331
18332
18333
18334
18335
18336
18337
18338
18339
18340
18341
18342
18343
18344
18345
18346
18347
18348
18349
18350
18351
18352
18353
18354
18355
18356
18357
18358
18359
18360
18361
18362
18363
18364
18365
18366
18367
18368
18369
18370
18371
18372
18373
18374
18375
18376
18377
18378
18379
18380
18381
18382
18383
18384
18385
18386
18387
18388
18389
18390
18391
18392
18393
18394
18395
18396
18397
18398
18399
18400
18401
18402
18403
18404
18405
18406
18407
18408
18409
18410
18411
18412
18413
18414
18415
18416
18417
18418
18419
18420
18421
18422
18423
18424
18425
18426
18427
18428
18429
18430
18431
18432
18433
18434
18435
18436
18437
18438
18439
18440
18441
18442
18443
18444
18445
18446
18447
18448
18449
18450
18451
18452
18453
18454
18455
18456
18457
18458
18459
18460
18461
18462
18463
18464
18465
18466
18467
18468
18469
18470
18471
18472
18473
18474
18475
18476
18477
18478
18479
18480
18481
18482
18483
18484
18485
18486
18487
18488
18489
18490
18491
18492
18493
18494
18495
18496
18497
18498
18499
18500
18501
18502
18503
18504
18505
18506
18507
18508
18509
18510
18511
18512
18513
18514
18515
18516
18517
18518
18519
18520
18521
18522
18523
18524
18525
18526
18527
18528
18529
18530
18531
18532
18533
18534
18535
18536
18537
18538
18539
18540
18541
18542
18543
18544
18545
18546
18547
18548
18549
18550
18551
18552
18553
18554
18555
18556
18557
18558
18559
18560
18561
18562
18563
18564
18565
18566
18567
18568
18569
18570
18571
18572
18573
18574
18575
18576
18577
18578
18579
18580
18581
18582
18583
18584
18585
18586
18587
18588
18589
18590
18591
18592
18593
18594
18595
18596
18597
18598
18599
18600
18601
18602
18603
18604
18605
18606
18607
18608
18609
18610
18611
18612
18613
18614
18615
18616
18617
18618
18619
18620
18621
18622
18623
18624
18625
18626
18627
18628
18629
18630
18631
18632
18633
18634
18635
18636
18637
18638
18639
18640
18641
18642
18643
18644
18645
18646
18647
18648
18649
18650
18651
18652
18653
18654
18655
18656
18657
18658
18659
18660
18661
18662
18663
18664
18665
18666
18667
18668
18669
18670
18671
18672
18673
18674
18675
18676
18677
18678
18679
18680
18681
18682
18683
18684
18685
18686
18687
18688
18689
18690
18691
18692
18693
18694
18695
18696
18697
18698
18699
18700
18701
18702
18703
18704
18705
18706
18707
18708
18709
18710
18711
18712
18713
18714
18715
18716
18717
18718
18719
18720
18721
18722
18723
18724
18725
18726
18727
18728
18729
18730
18731
18732
18733
18734
18735
18736
18737
18738
18739
18740
18741
18742
18743
18744
18745
18746
18747
18748
18749
18750
18751
18752
18753
18754
18755
18756
18757
18758
18759
18760
18761
18762
18763
18764
18765
18766
18767
18768
18769
18770
18771
18772
18773
18774
18775
18776
18777
18778
18779
18780
18781
18782
18783
18784
18785
18786
18787
18788
18789
18790
18791
18792
18793
18794
18795
18796
18797
18798
18799
18800
18801
18802
18803
18804
18805
18806
18807
18808
18809
18810
18811
18812
18813
18814
18815
18816
18817
18818
18819
18820
18821
18822
18823
18824
18825
18826
18827
18828
18829
18830
18831
18832
18833
18834
18835
18836
18837
18838
18839
18840
18841
18842
18843
18844
18845
18846
18847
18848
18849
18850
18851
18852
18853
18854
18855
18856
18857
18858
18859
18860
18861
18862
18863
18864
18865
18866
18867
18868
18869
18870
18871
18872
18873
18874
18875
18876
18877
18878
18879
18880
18881
18882
18883
18884
18885
18886
18887
18888
18889
18890
18891
18892
18893
18894
18895
18896
18897
18898
18899
18900
18901
18902
18903
18904
18905
18906
18907
18908
18909
18910
18911
18912
18913
18914
18915
18916
18917
18918
18919
18920
18921
18922
18923
18924
18925
18926
18927
18928
18929
18930
18931
18932
18933
18934
18935
18936
18937
18938
18939
18940
18941
18942
18943
18944
18945
18946
18947
18948
18949
18950
18951
18952
18953
18954
18955
18956
18957
18958
18959
18960
18961
18962
18963
18964
18965
18966
18967
18968
18969
18970
18971
18972
18973
18974
18975
18976
18977
18978
18979
18980
18981
18982
18983
18984
18985
18986
18987
18988
18989
18990
18991
18992
18993
18994
18995
18996
18997
18998
18999
19000
19001
19002
19003
19004
19005
19006
19007
19008
19009
19010
19011
19012
19013
19014
19015
19016
19017
19018
19019
19020
19021
19022
19023
19024
19025
19026
19027
19028
19029
19030
19031
19032
19033
19034
19035
19036
19037
19038
19039
19040
19041
19042
19043
19044
19045
19046
19047
19048
19049
19050
19051
19052
19053
19054
19055
19056
19057
19058
19059
19060
19061
19062
19063
19064
19065
19066
19067
19068
19069
19070
19071
19072
19073
19074
19075
19076
19077
19078
19079
19080
19081
19082
19083
19084
19085
19086
19087
19088
19089
19090
19091
19092
19093
19094
19095
19096
19097
19098
19099
19100
19101
19102
19103
19104
19105
19106
19107
19108
19109
19110
19111
19112
19113
19114
19115
19116
19117
19118
19119
19120
19121
19122
19123
19124
19125
19126
19127
19128
19129
19130
19131
19132
19133
19134
19135
19136
19137
19138
19139
19140
19141
19142
19143
19144
19145
19146
19147
19148
19149
19150
19151
19152
19153
19154
19155
19156
19157
19158
19159
19160
19161
19162
19163
19164
19165
19166
19167
19168
19169
19170
19171
19172
19173
19174
19175
19176
19177
19178
19179
19180
19181
19182
19183
19184
19185
19186
19187
19188
19189
19190
19191
19192
19193
19194
19195
19196
19197
19198
19199
19200
19201
19202
19203
19204
19205
19206
19207
19208
19209
19210
19211
19212
19213
19214
19215
19216
19217
19218
19219
19220
19221
19222
19223
19224
19225
19226
19227
19228
19229
19230
19231
19232
19233
19234
19235
19236
19237
19238
19239
19240
19241
19242
19243
19244
19245
19246
19247
19248
19249
19250
19251
19252
19253
19254
19255
19256
19257
19258
19259
19260
19261
19262
19263
19264
19265
19266
19267
19268
19269
19270
19271
19272
19273
19274
19275
19276
19277
19278
19279
19280
19281
19282
19283
19284
19285
19286
19287
19288
19289
19290
19291
19292
19293
19294
19295
19296
19297
19298
19299
19300
19301
19302
19303
19304
19305
19306
19307
19308
19309
19310
19311
19312
19313
19314
19315
19316
19317
19318
19319
19320
19321
19322
19323
19324
19325
19326
19327
19328
19329
19330
19331
19332
19333
19334
19335
19336
19337
19338
19339
19340
19341
19342
19343
19344
19345
19346
19347
19348
19349
19350
19351
19352
19353
19354
19355
19356
19357
19358
19359
19360
19361
19362
19363
19364
19365
19366
19367
19368
19369
19370
19371
19372
19373
19374
19375
19376
19377
19378
19379
19380
19381
19382
19383
19384
19385
19386
19387
19388
19389
19390
19391
19392
19393
19394
19395
19396
19397
19398
19399
19400
19401
19402
19403
19404
19405
19406
19407
19408
19409
19410
19411
19412
19413
19414
19415
19416
19417
19418
19419
19420
19421
19422
19423
19424
19425
19426
19427
19428
19429
19430
19431
19432
19433
19434
19435
19436
19437
19438
19439
19440
19441
19442
19443
19444
19445
19446
19447
19448
19449
19450
19451
19452
19453
19454
19455
19456
19457
19458
19459
19460
19461
19462
19463
19464
19465
19466
19467
19468
19469
19470
19471
19472
19473
19474
19475
19476
19477
19478
19479
19480
19481
19482
19483
19484
19485
19486
19487
19488
19489
19490
19491
19492
19493
19494
19495
19496
19497
19498
19499
19500
19501
19502
19503
19504
19505
19506
19507
19508
19509
19510
19511
19512
19513
19514
19515
19516
19517
19518
19519
19520
19521
19522
19523
19524
19525
19526
19527
19528
19529
19530
19531
19532
19533
19534
19535
19536
19537
19538
19539
19540
19541
19542
19543
19544
19545
19546
19547
19548
19549
19550
19551
19552
19553
19554
19555
19556
19557
19558
19559
19560
19561
19562
19563
19564
19565
19566
19567
19568
19569
19570
19571
19572
19573
19574
19575
19576
19577
19578
19579
19580
19581
19582
19583
19584
19585
19586
19587
19588
19589
19590
19591
19592
19593
19594
19595
19596
19597
19598
19599
19600
19601
19602
19603
19604
19605
19606
19607
19608
19609
19610
19611
19612
19613
19614
19615
19616
19617
19618
19619
19620
19621
19622
19623
19624
19625
19626
19627
19628
19629
19630
19631
19632
19633
19634
19635
19636
19637
19638
19639
19640
19641
19642
19643
19644
19645
19646
19647
19648
19649
19650
19651
19652
19653
19654
19655
19656
19657
19658
19659
19660
19661
19662
19663
19664
19665
19666
19667
19668
19669
19670
19671
19672
19673
19674
19675
19676
19677
19678
19679
19680
19681
19682
19683
19684
19685
19686
19687
19688
19689
19690
19691
19692
19693
19694
19695
19696
19697
19698
19699
19700
19701
19702
19703
19704
19705
19706
19707
19708
19709
19710
19711
19712
19713
19714
19715
19716
19717
19718
19719
19720
19721
19722
19723
19724
19725
19726
19727
19728
19729
19730
19731
19732
19733
19734
19735
19736
19737
19738
19739
19740
19741
19742
19743
19744
19745
19746
19747
19748
19749
19750
19751
19752
19753
19754
19755
19756
19757
19758
19759
19760
19761
19762
19763
19764
19765
19766
19767
19768
19769
19770
19771
19772
19773
19774
19775
19776
19777
19778
19779
19780
19781
19782
19783
19784
19785
19786
19787
19788
19789
19790
19791
19792
19793
19794
19795
19796
19797
19798
19799
19800
19801
19802
19803
19804
19805
19806
19807
19808
19809
19810
19811
19812
19813
19814
19815
19816
19817
19818
19819
19820
19821
19822
19823
19824
19825
19826
19827
19828
19829
19830
19831
19832
19833
19834
19835
19836
19837
19838
19839
19840
19841
19842
19843
19844
19845
19846
19847
19848
19849
19850
19851
19852
19853
19854
19855
19856
19857
19858
19859
19860
19861
19862
19863
19864
19865
19866
19867
19868
19869
19870
19871
19872
19873
19874
19875
19876
19877
19878
19879
19880
19881
19882
19883
19884
19885
19886
19887
19888
19889
19890
19891
19892
19893
19894
19895
19896
19897
19898
19899
19900
19901
19902
19903
19904
19905
19906
19907
19908
19909
19910
19911
19912
19913
19914
19915
19916
19917
19918
19919
19920
19921
19922
19923
19924
19925
19926
19927
19928
19929
19930
19931
19932
19933
19934
19935
19936
19937
19938
19939
19940
19941
19942
19943
19944
19945
19946
19947
19948
19949
19950
19951
19952
19953
19954
19955
19956
19957
19958
19959
19960
19961
19962
19963
19964
19965
19966
19967
19968
19969
19970
19971
19972
19973
19974
19975
19976
19977
19978
19979
19980
19981
19982
19983
19984
19985
19986
19987
19988
19989
19990
19991
19992
19993
19994
19995
19996
19997
19998
19999
20000
20001
20002
20003
20004
20005
20006
20007
20008
20009
20010
20011
20012
20013
20014
20015
20016
20017
20018
20019
20020
20021
20022
20023
20024
20025
20026
20027
20028
20029
20030
20031
20032
20033
20034
20035
20036
20037
20038
20039
20040
20041
20042
20043
20044
20045
20046
20047
20048
20049
20050
20051
20052
20053
20054
20055
20056
20057
20058
20059
20060
20061
20062
20063
20064
20065
20066
20067
20068
20069
20070
20071
20072
20073
20074
20075
20076
20077
20078
20079
20080
20081
20082
20083
20084
20085
20086
20087
20088
20089
20090
20091
20092
20093
20094
20095
20096
20097
20098
20099
20100
20101
20102
20103
20104
20105
20106
20107
20108
20109
20110
20111
20112
20113
20114
20115
20116
20117
20118
20119
20120
20121
20122
20123
20124
20125
20126
20127
20128
20129
20130
20131
20132
20133
20134
20135
20136
20137
20138
20139
20140
20141
20142
20143
20144
20145
20146
20147
20148
20149
20150
20151
20152
20153
20154
20155
20156
20157
20158
20159
20160
20161
20162
20163
20164
20165
20166
20167
20168
20169
20170
20171
20172
20173
20174
20175
20176
20177
20178
20179
20180
20181
20182
20183
20184
20185
20186
20187
20188
20189
20190
20191
20192
20193
20194
20195
20196
20197
20198
20199
20200
20201
20202
20203
20204
20205
20206
20207
20208
20209
20210
20211
20212
20213
20214
20215
20216
20217
20218
20219
20220
20221
20222
20223
20224
20225
20226
20227
20228
20229
20230
20231
20232
20233
20234
20235
20236
20237
20238
20239
20240
20241
20242
20243
20244
20245
20246
20247
20248
20249
20250
20251
20252
20253
20254
20255
20256
20257
20258
20259
20260
20261
20262
20263
20264
20265
20266
20267
20268
20269
20270
20271
20272
20273
20274
20275
20276
20277
20278
20279
20280
20281
20282
20283
20284
20285
20286
20287
20288
20289
20290
20291
20292
20293
20294
20295
20296
20297
20298
20299
20300
20301
20302
20303
20304
20305
20306
20307
20308
20309
20310
20311
20312
20313
20314
20315
20316
20317
20318
20319
20320
20321
20322
20323
20324
20325
20326
20327
20328
20329
20330
20331
20332
20333
20334
20335
20336
20337
20338
20339
20340
20341
20342
20343
20344
20345
20346
20347
20348
20349
20350
20351
20352
20353
20354
20355
20356
20357
20358
20359
20360
20361
20362
20363
20364
20365
20366
20367
20368
20369
20370
20371
20372
20373
20374
20375
20376
20377
20378
20379
20380
20381
20382
20383
20384
20385
20386
20387
20388
20389
20390
20391
20392
20393
20394
20395
20396
20397
20398
20399
20400
20401
20402
20403
20404
20405
20406
20407
20408
20409
20410
20411
20412
20413
20414
20415
20416
20417
20418
20419
20420
20421
20422
20423
20424
20425
20426
20427
20428
20429
20430
20431
20432
20433
20434
20435
20436
20437
20438
20439
20440
20441
20442
20443
20444
20445
20446
20447
20448
20449
20450
20451
20452
20453
20454
20455
20456
20457
20458
20459
20460
20461
20462
20463
20464
20465
20466
20467
20468
20469
20470
20471
20472
20473
20474
20475
20476
20477
20478
20479
20480
20481
20482
20483
20484
20485
20486
20487
20488
20489
20490
20491
20492
20493
20494
20495
20496
20497
20498
20499
20500
20501
20502
20503
20504
20505
20506
20507
20508
20509
20510
20511
20512
20513
20514
20515
20516
20517
20518
20519
20520
20521
20522
20523
20524
20525
20526
20527
20528
20529
20530
20531
20532
20533
20534
20535
20536
20537
20538
20539
20540
20541
20542
20543
20544
20545
20546
20547
20548
20549
20550
20551
20552
20553
20554
20555
20556
20557
20558
20559
20560
20561
20562
20563
20564
20565
20566
20567
20568
20569
20570
20571
20572
20573
20574
20575
20576
20577
20578
20579
20580
20581
20582
20583
20584
20585
20586
20587
20588
20589
20590
20591
20592
20593
20594
20595
20596
20597
20598
20599
20600
20601
20602
20603
20604
20605
20606
20607
20608
20609
20610
20611
20612
20613
20614
20615
20616
20617
20618
20619
20620
20621
20622
20623
20624
20625
20626
20627
20628
20629
20630
20631
20632
20633
20634
20635
20636
20637
20638
20639
20640
20641
20642
20643
20644
20645
20646
20647
20648
20649
20650
20651
20652
20653
20654
20655
20656
20657
20658
20659
20660
20661
20662
20663
20664
20665
20666
20667
20668
20669
20670
20671
20672
20673
20674
20675
20676
20677
20678
20679
20680
20681
20682
20683
20684
20685
20686
20687
20688
20689
20690
20691
20692
20693
20694
20695
20696
20697
20698
20699
20700
20701
20702
20703
20704
20705
20706
20707
20708
20709
20710
20711
20712
20713
20714
20715
20716
20717
20718
20719
20720
20721
20722
20723
20724
20725
20726
20727
20728
20729
20730
20731
20732
20733
20734
20735
20736
20737
20738
20739
20740
20741
20742
20743
20744
20745
20746
20747
20748
20749
20750
20751
20752
20753
20754
20755
20756
20757
20758
20759
20760
20761
20762
20763
20764
20765
20766
20767
20768
20769
20770
20771
20772
20773
20774
20775
20776
20777
20778
20779
20780
20781
20782
20783
20784
20785
20786
20787
20788
20789
20790
20791
20792
20793
20794
20795
20796
20797
20798
20799
20800
20801
20802
20803
20804
20805
20806
20807
20808
20809
20810
20811
20812
20813
20814
20815
20816
20817
20818
20819
20820
20821
20822
20823
20824
20825
20826
20827
20828
20829
20830
20831
20832
20833
20834
20835
20836
20837
20838
20839
20840
20841
20842
20843
20844
20845
20846
20847
20848
20849
20850
20851
20852
20853
20854
20855
20856
20857
20858
20859
20860
20861
20862
20863
20864
20865
20866
20867
20868
20869
20870
20871
20872
20873
20874
20875
20876
20877
20878
20879
20880
20881
20882
20883
20884
20885
20886
20887
20888
20889
20890
20891
20892
20893
20894
20895
20896
20897
20898
20899
20900
20901
20902
20903
20904
20905
20906
20907
20908
20909
20910
20911
20912
20913
20914
20915
20916
20917
20918
20919
20920
20921
20922
20923
20924
20925
20926
20927
20928
20929
20930
20931
20932
20933
20934
20935
20936
20937
20938
20939
20940
20941
20942
20943
20944
20945
20946
20947
20948
20949
20950
20951
20952
20953
20954
20955
20956
20957
20958
20959
20960
20961
20962
20963
20964
20965
20966
20967
20968
20969
20970
20971
20972
20973
20974
20975
20976
20977
20978
20979
20980
20981
20982
20983
20984
20985
20986
20987
20988
20989
20990
20991
20992
20993
20994
20995
20996
20997
20998
20999
21000
21001
21002
21003
21004
21005
21006
21007
21008
21009
21010
21011
21012
21013
21014
21015
21016
21017
21018
21019
21020
21021
21022
21023
21024
21025
21026
21027
21028
21029
21030
21031
21032
21033
21034
21035
21036
21037
21038
21039
21040
21041
21042
21043
21044
21045
21046
21047
21048
21049
21050
21051
21052
21053
21054
21055
21056
21057
21058
21059
21060
21061
21062
21063
21064
21065
21066
21067
21068
21069
21070
21071
21072
21073
21074
21075
21076
21077
21078
21079
21080
21081
21082
21083
21084
21085
21086
21087
21088
21089
21090
21091
21092
21093
21094
21095
21096
21097
21098
21099
21100
21101
21102
21103
21104
21105
21106
21107
21108
21109
21110
21111
21112
21113
21114
21115
21116
21117
21118
21119
21120
21121
21122
21123
21124
21125
21126
21127
21128
21129
21130
21131
21132
21133
21134
21135
21136
21137
21138
21139
21140
21141
21142
21143
21144
21145
21146
21147
21148
21149
21150
21151
21152
21153
21154
21155
21156
21157
21158
21159
21160
21161
21162
21163
21164
21165
21166
21167
21168
21169
21170
21171
21172
21173
21174
21175
21176
21177
21178
21179
21180
21181
21182
21183
21184
21185
21186
21187
21188
21189
21190
21191
21192
21193
21194
21195
21196
21197
21198
21199
21200
21201
21202
21203
21204
21205
21206
21207
21208
21209
21210
21211
21212
21213
21214
21215
21216
21217
21218
21219
21220
21221
21222
21223
21224
21225
21226
21227
21228
21229
21230
21231
21232
21233
21234
21235
21236
21237
21238
21239
21240
21241
21242
21243
21244
21245
21246
21247
21248
21249
21250
21251
21252
21253
21254
21255
21256
21257
21258
21259
21260
21261
21262
21263
21264
21265
21266
21267
21268
21269
21270
21271
21272
21273
21274
21275
21276
21277
21278
21279
21280
21281
21282
21283
21284
21285
21286
21287
21288
21289
21290
21291
21292
21293
21294
21295
21296
21297
21298
21299
21300
21301
21302
21303
21304
21305
21306
21307
21308
21309
21310
21311
21312
21313
21314
21315
21316
21317
21318
21319
21320
21321
21322
21323
21324
21325
21326
21327
21328
21329
21330
21331
21332
21333
21334
21335
21336
21337
21338
21339
21340
21341
21342
21343
21344
21345
21346
21347
21348
21349
21350
21351
21352
21353
21354
21355
21356
21357
21358
21359
21360
21361
21362
21363
21364
21365
21366
21367
21368
21369
21370
21371
21372
21373
21374
21375
21376
21377
21378
21379
21380
21381
21382
21383
21384
21385
21386
21387
21388
21389
21390
21391
21392
21393
21394
21395
21396
21397
21398
21399
21400
21401
21402
21403
21404
21405
21406
21407
21408
21409
21410
21411
21412
21413
21414
21415
21416
21417
21418
21419
21420
21421
21422
21423
21424
21425
21426
21427
21428
21429
21430
21431
21432
21433
21434
21435
21436
21437
21438
21439
21440
21441
21442
21443
21444
21445
21446
21447
21448
21449
21450
21451
21452
21453
21454
21455
21456
21457
21458
21459
21460
21461
21462
21463
21464
21465
21466
21467
21468
21469
21470
21471
21472
21473
21474
21475
21476
21477
21478
21479
21480
21481
21482
21483
21484
21485
21486
21487
21488
21489
21490
21491
21492
21493
21494
21495
21496
21497
21498
21499
21500
21501
21502
21503
21504
21505
21506
21507
21508
21509
21510
21511
21512
21513
21514
21515
21516
21517
21518
21519
21520
21521
21522
21523
21524
21525
21526
21527
21528
21529
21530
21531
21532
21533
21534
21535
21536
21537
21538
21539
21540
21541
21542
21543
21544
21545
21546
21547
21548
21549
21550
21551
21552
21553
21554
21555
21556
21557
21558
21559
21560
21561
21562
21563
21564
21565
21566
21567
21568
21569
21570
21571
21572
21573
21574
21575
21576
21577
21578
21579
21580
21581
21582
21583
21584
21585
21586
21587
21588
21589
21590
21591
21592
21593
21594
21595
21596
21597
21598
21599
21600
21601
21602
21603
21604
21605
21606
21607
21608
21609
21610
21611
21612
21613
21614
21615
21616
21617
21618
21619
21620
21621
21622
21623
21624
21625
21626
21627
21628
21629
21630
21631
21632
21633
21634
21635
21636
21637
21638
21639
21640
21641
21642
21643
21644
21645
21646
21647
21648
21649
21650
21651
21652
21653
21654
21655
21656
21657
21658
21659
21660
21661
21662
21663
21664
21665
21666
21667
21668
21669
21670
21671
21672
21673
21674
21675
21676
21677
21678
21679
21680
21681
21682
21683
21684
21685
21686
21687
21688
21689
21690
21691
21692
21693
21694
21695
21696
21697
21698
21699
21700
21701
21702
21703
21704
21705
21706
21707
21708
21709
21710
21711
21712
21713
21714
21715
21716
21717
21718
21719
21720
21721
21722
21723
21724
21725
21726
21727
21728
21729
21730
21731
21732
21733
21734
21735
21736
21737
21738
21739
21740
21741
21742
21743
21744
21745
21746
21747
21748
21749
21750
21751
21752
21753
21754
21755
21756
21757
21758
21759
21760
21761
21762
21763
21764
21765
21766
21767
21768
21769
21770
21771
21772
21773
21774
21775
21776
21777
21778
21779
21780
21781
21782
21783
21784
21785
21786
21787
21788
21789
21790
21791
21792
21793
21794
21795
21796
21797
21798
21799
21800
21801
21802
21803
21804
21805
21806
21807
21808
21809
21810
21811
21812
21813
21814
21815
21816
21817
21818
21819
21820
21821
21822
21823
21824
21825
21826
21827
21828
21829
21830
21831
21832
21833
21834
21835
21836
21837
21838
21839
21840
21841
21842
21843
21844
21845
21846
21847
21848
21849
21850
21851
21852
21853
21854
21855
21856
21857
21858
21859
21860
21861
21862
21863
21864
21865
21866
21867
21868
21869
21870
21871
21872
21873
21874
21875
21876
21877
21878
21879
21880
21881
21882
21883
21884
21885
21886
21887
21888
21889
21890
21891
21892
21893
21894
21895
21896
21897
21898
21899
21900
21901
21902
21903
21904
21905
21906
21907
21908
21909
21910
21911
21912
21913
21914
21915
21916
21917
21918
21919
21920
21921
21922
21923
21924
21925
21926
21927
21928
21929
21930
21931
21932
21933
21934
21935
21936
21937
21938
21939
21940
21941
21942
21943
21944
21945
21946
21947
21948
21949
21950
21951
21952
21953
21954
21955
21956
21957
21958
21959
21960
21961
21962
21963
21964
21965
21966
21967
21968
21969
21970
21971
21972
21973
21974
21975
21976
21977
21978
21979
21980
21981
21982
21983
21984
21985
21986
21987
21988
21989
21990
21991
21992
21993
21994
21995
21996
21997
21998
21999
22000
22001
22002
22003
22004
22005
22006
22007
22008
22009
22010
22011
22012
22013
22014
22015
22016
22017
22018
22019
22020
22021
22022
22023
22024
22025
22026
22027
22028
22029
22030
22031
22032
22033
22034
22035
22036
22037
22038
22039
22040
22041
22042
22043
22044
22045
22046
22047
22048
22049
22050
22051
22052
22053
22054
22055
22056
22057
22058
22059
22060
22061
22062
22063
22064
22065
22066
22067
22068
22069
22070
22071
22072
22073
22074
22075
22076
22077
22078
22079
22080
22081
22082
22083
22084
22085
22086
22087
22088
22089
22090
22091
22092
22093
22094
22095
22096
22097
22098
22099
22100
22101
22102
22103
22104
22105
22106
22107
22108
22109
22110
22111
22112
22113
22114
22115
22116
22117
22118
22119
22120
22121
22122
22123
22124
22125
22126
22127
22128
22129
22130
22131
22132
22133
22134
22135
22136
22137
22138
22139
22140
22141
22142
22143
22144
22145
22146
22147
22148
22149
22150
22151
22152
22153
22154
22155
22156
22157
22158
22159
22160
22161
22162
22163
22164
22165
22166
22167
22168
22169
22170
22171
22172
22173
22174
22175
22176
22177
22178
22179
22180
22181
22182
22183
22184
22185
22186
22187
22188
22189
22190
22191
22192
22193
22194
22195
22196
22197
22198
22199
22200
22201
22202
22203
22204
22205
22206
22207
22208
22209
22210
22211
22212
22213
22214
22215
22216
22217
22218
22219
22220
22221
22222
22223
22224
22225
22226
22227
22228
22229
22230
22231
22232
22233
22234
22235
22236
22237
22238
22239
22240
22241
22242
22243
22244
22245
22246
22247
22248
22249
22250
22251
22252
22253
22254
22255
22256
22257
22258
22259
22260
22261
22262
22263
22264
22265
22266
22267
22268
22269
22270
22271
22272
22273
22274
22275
22276
22277
22278
22279
22280
22281
22282
22283
22284
22285
22286
22287
22288
22289
22290
22291
22292
22293
22294
22295
22296
22297
22298
22299
22300
22301
22302
22303
22304
22305
22306
22307
22308
22309
22310
22311
22312
22313
22314
22315
22316
22317
22318
22319
22320
22321
22322
22323
22324
22325
22326
22327
22328
22329
22330
22331
22332
22333
22334
22335
22336
22337
22338
22339
22340
22341
22342
22343
22344
22345
22346
22347
22348
22349
22350
22351
22352
22353
22354
22355
22356
22357
22358
22359
22360
22361
22362
22363
22364
22365
22366
22367
22368
22369
22370
22371
22372
22373
22374
22375
22376
22377
22378
22379
22380
22381
22382
22383
22384
22385
22386
22387
22388
22389
22390
22391
22392
22393
22394
22395
22396
22397
22398
22399
22400
22401
22402
22403
22404
22405
22406
22407
22408
22409
22410
22411
22412
22413
22414
22415
22416
22417
22418
22419
22420
22421
22422
22423
22424
22425
22426
22427
22428
22429
22430
22431
22432
22433
22434
22435
22436
22437
22438
22439
22440
22441
22442
22443
22444
22445
22446
22447
22448
22449
22450
22451
22452
22453
22454
22455
22456
22457
22458
22459
22460
22461
22462
22463
22464
22465
22466
22467
22468
22469
22470
22471
22472
22473
22474
22475
22476
22477
22478
22479
22480
22481
22482
22483
22484
22485
22486
22487
22488
22489
22490
22491
22492
22493
22494
22495
22496
22497
22498
22499
22500
22501
22502
22503
22504
22505
22506
22507
22508
22509
22510
22511
22512
22513
22514
22515
22516
22517
22518
22519
22520
22521
22522
22523
22524
22525
22526
22527
22528
22529
22530
22531
22532
22533
22534
22535
22536
22537
22538
22539
22540
22541
22542
22543
22544
22545
22546
22547
22548
22549
22550
22551
22552
22553
22554
22555
22556
22557
22558
22559
22560
22561
22562
22563
22564
22565
22566
22567
22568
22569
22570
22571
22572
22573
22574
22575
22576
22577
22578
22579
22580
22581
22582
22583
22584
22585
22586
22587
22588
22589
22590
22591
22592
22593
22594
22595
22596
22597
22598
22599
22600
22601
22602
22603
22604
22605
22606
22607
22608
22609
22610
22611
22612
22613
22614
22615
22616
22617
22618
22619
22620
22621
22622
22623
22624
22625
22626
22627
22628
22629
22630
22631
22632
22633
22634
22635
22636
22637
22638
22639
22640
22641
22642
22643
22644
22645
22646
22647
22648
22649
22650
22651
22652
22653
22654
22655
22656
22657
22658
22659
22660
22661
22662
22663
22664
22665
22666
22667
22668
22669
22670
22671
22672
22673
22674
22675
22676
22677
22678
22679
22680
22681
22682
22683
22684
22685
22686
22687
22688
22689
22690
22691
22692
22693
22694
22695
22696
22697
22698
22699
22700
22701
22702
22703
22704
22705
22706
22707
22708
22709
22710
22711
22712
22713
22714
22715
22716
22717
22718
22719
22720
22721
22722
22723
22724
22725
22726
22727
22728
22729
22730
22731
22732
22733
22734
22735
22736
22737
22738
22739
22740
22741
22742
22743
22744
22745
22746
22747
22748
22749
22750
22751
22752
22753
22754
22755
22756
22757
22758
22759
22760
22761
22762
22763
22764
22765
22766
22767
22768
22769
22770
22771
22772
22773
22774
22775
22776
22777
22778
22779
22780
22781
22782
22783
22784
22785
22786
22787
22788
22789
22790
22791
22792
22793
22794
22795
22796
22797
22798
22799
22800
22801
22802
22803
22804
22805
22806
22807
22808
22809
22810
22811
22812
22813
22814
22815
22816
22817
22818
22819
22820
22821
22822
22823
22824
22825
22826
22827
22828
22829
22830
22831
22832
22833
22834
22835
22836
22837
22838
22839
22840
22841
22842
22843
22844
22845
22846
22847
22848
22849
22850
22851
22852
22853
22854
22855
22856
22857
22858
22859
22860
22861
22862
22863
22864
22865
22866
22867
22868
22869
22870
22871
22872
22873
22874
22875
22876
22877
22878
22879
22880
22881
22882
22883
22884
22885
22886
22887
22888
22889
22890
22891
22892
22893
22894
22895
22896
22897
22898
22899
22900
22901
22902
22903
22904
22905
22906
22907
22908
22909
22910
22911
22912
22913
22914
22915
22916
22917
22918
22919
22920
22921
22922
22923
22924
22925
22926
22927
22928
22929
22930
22931
22932
22933
22934
22935
22936
22937
22938
22939
22940
22941
22942
22943
22944
22945
22946
22947
22948
22949
22950
22951
22952
22953
22954
22955
22956
22957
22958
22959
22960
22961
22962
22963
22964
22965
22966
22967
22968
22969
22970
22971
22972
22973
22974
22975
22976
22977
22978
22979
22980
22981
22982
22983
22984
22985
22986
22987
22988
22989
22990
22991
22992
22993
22994
22995
22996
22997
22998
22999
23000
23001
23002
23003
23004
23005
23006
23007
23008
23009
23010
23011
23012
23013
23014
23015
23016
23017
23018
23019
23020
23021
23022
23023
23024
23025
23026
23027
23028
23029
23030
23031
23032
23033
23034
23035
23036
23037
23038
23039
23040
23041
23042
23043
23044
23045
23046
23047
23048
23049
23050
23051
23052
23053
23054
23055
23056
23057
23058
23059
23060
23061
23062
23063
23064
23065
23066
23067
23068
23069
23070
23071
23072
23073
23074
23075
23076
23077
23078
23079
23080
23081
23082
23083
23084
23085
23086
23087
23088
23089
23090
23091
23092
23093
23094
23095
23096
23097
23098
23099
23100
23101
23102
23103
23104
23105
23106
23107
23108
23109
23110
23111
23112
23113
23114
23115
23116
23117
23118
23119
23120
23121
23122
23123
23124
23125
23126
23127
23128
23129
23130
23131
23132
23133
23134
23135
23136
23137
23138
23139
23140
23141
23142
23143
23144
23145
23146
23147
23148
23149
23150
23151
23152
23153
23154
23155
23156
23157
23158
23159
23160
23161
23162
23163
23164
23165
23166
23167
23168
23169
23170
23171
23172
23173
23174
23175
23176
23177
23178
23179
23180
23181
23182
23183
23184
23185
23186
23187
23188
23189
23190
23191
23192
23193
23194
23195
23196
23197
23198
23199
23200
23201
23202
23203
23204
23205
23206
23207
23208
23209
23210
23211
23212
23213
23214
23215
23216
23217
23218
23219
23220
23221
23222
23223
23224
23225
23226
23227
23228
23229
23230
23231
23232
23233
23234
23235
23236
23237
23238
23239
23240
23241
23242
23243
23244
23245
23246
23247
23248
23249
23250
23251
23252
23253
23254
23255
23256
23257
23258
23259
23260
23261
23262
23263
23264
23265
23266
23267
23268
23269
23270
23271
23272
23273
23274
23275
23276
23277
23278
23279
23280
23281
23282
23283
23284
23285
23286
23287
23288
23289
23290
23291
23292
23293
23294
23295
23296
23297
23298
23299
23300
23301
23302
23303
23304
23305
23306
23307
23308
23309
23310
23311
23312
23313
23314
23315
23316
23317
23318
23319
23320
23321
23322
23323
23324
23325
23326
23327
23328
23329
23330
23331
23332
23333
23334
23335
23336
23337
23338
23339
23340
23341
23342
23343
23344
23345
23346
23347
23348
23349
23350
23351
23352
23353
23354
23355
23356
23357
23358
23359
23360
23361
23362
23363
23364
23365
23366
23367
23368
23369
23370
23371
23372
23373
23374
23375
23376
23377
23378
23379
23380
23381
23382
23383
23384
23385
23386
23387
23388
23389
23390
23391
23392
23393
23394
23395
23396
23397
23398
23399
23400
23401
23402
23403
23404
23405
23406
23407
23408
23409
23410
23411
23412
23413
23414
23415
23416
23417
23418
23419
23420
23421
23422
23423
23424
23425
23426
23427
23428
23429
23430
23431
23432
23433
23434
23435
23436
23437
23438
23439
23440
23441
23442
23443
23444
23445
23446
23447
23448
23449
23450
23451
23452
23453
23454
23455
23456
23457
23458
23459
23460
23461
23462
23463
23464
23465
23466
23467
23468
23469
23470
23471
23472
23473
23474
23475
23476
23477
23478
23479
23480
23481
23482
23483
23484
23485
23486
23487
23488
23489
23490
23491
23492
23493
23494
23495
23496
23497
23498
23499
23500
23501
23502
23503
23504
23505
23506
23507
23508
23509
23510
23511
23512
23513
23514
23515
23516
23517
23518
23519
23520
23521
23522
23523
23524
23525
23526
23527
23528
23529
23530
23531
23532
23533
23534
23535
23536
23537
23538
23539
23540
23541
23542
23543
23544
23545
23546
23547
23548
23549
23550
23551
23552
23553
23554
23555
23556
23557
23558
23559
23560
23561
23562
23563
23564
23565
23566
23567
23568
23569
23570
23571
23572
23573
23574
23575
23576
23577
23578
23579
23580
23581
23582
23583
23584
23585
23586
23587
23588
23589
23590
23591
23592
23593
23594
23595
23596
23597
23598
23599
23600
23601
23602
23603
23604
23605
23606
23607
23608
23609
23610
23611
23612
23613
23614
23615
23616
23617
23618
23619
23620
23621
23622
23623
23624
23625
23626
23627
23628
23629
23630
23631
23632
23633
23634
23635
23636
23637
23638
23639
23640
23641
23642
23643
23644
23645
23646
23647
23648
23649
23650
23651
23652
23653
23654
23655
23656
23657
23658
23659
23660
23661
23662
23663
23664
23665
23666
23667
23668
23669
23670
23671
23672
23673
23674
23675
23676
23677
23678
23679
23680
23681
23682
23683
23684
23685
23686
23687
23688
23689
23690
23691
23692
23693
23694
23695
23696
23697
23698
23699
23700
23701
23702
23703
23704
23705
23706
23707
23708
23709
23710
23711
23712
23713
23714
23715
23716
23717
23718
23719
23720
23721
23722
23723
23724
23725
23726
23727
23728
23729
23730
23731
23732
23733
23734
23735
23736
23737
23738
23739
23740
23741
23742
23743
23744
23745
23746
23747
23748
23749
23750
23751
23752
23753
23754
23755
23756
23757
23758
23759
23760
23761
23762
23763
23764
23765
23766
23767
23768
23769
23770
23771
23772
23773
23774
23775
23776
23777
23778
23779
23780
23781
23782
23783
23784
23785
23786
23787
23788
23789
23790
23791
23792
23793
23794
23795
23796
23797
23798
23799
23800
23801
23802
23803
23804
23805
23806
23807
23808
23809
23810
23811
23812
23813
23814
23815
23816
23817
23818
23819
23820
23821
23822
23823
23824
23825
23826
23827
23828
23829
23830
23831
23832
23833
23834
23835
23836
23837
23838
23839
23840
23841
23842
23843
23844
23845
23846
23847
23848
23849
23850
23851
23852
23853
23854
23855
23856
23857
23858
23859
23860
23861
23862
23863
23864
23865
23866
23867
23868
23869
23870
23871
23872
23873
23874
23875
23876
23877
23878
23879
23880
23881
23882
23883
23884
23885
23886
23887
23888
23889
23890
23891
23892
23893
23894
23895
23896
23897
23898
23899
23900
23901
23902
23903
23904
23905
23906
23907
23908
23909
23910
23911
23912
23913
23914
23915
23916
23917
23918
23919
23920
23921
23922
23923
23924
23925
23926
23927
23928
23929
23930
23931
23932
23933
23934
23935
23936
23937
23938
23939
23940
23941
23942
23943
23944
23945
23946
23947
23948
23949
23950
23951
23952
23953
23954
23955
23956
23957
23958
23959
23960
23961
23962
23963
23964
23965
23966
23967
23968
23969
23970
23971
23972
23973
23974
23975
23976
23977
23978
23979
23980
23981
23982
23983
23984
23985
23986
23987
23988
23989
23990
23991
23992
23993
23994
23995
23996
23997
23998
23999
24000
24001
24002
24003
24004
24005
24006
24007
24008
24009
24010
24011
24012
24013
24014
24015
24016
24017
24018
24019
24020
24021
24022
24023
24024
24025
24026
24027
24028
24029
24030
24031
24032
24033
24034
24035
24036
24037
24038
24039
24040
24041
24042
24043
24044
24045
24046
24047
24048
24049
24050
24051
24052
24053
24054
24055
24056
24057
24058
24059
24060
24061
24062
24063
24064
24065
24066
24067
24068
24069
24070
24071
24072
24073
24074
24075
24076
24077
24078
24079
24080
24081
24082
24083
24084
24085
24086
24087
24088
24089
24090
24091
24092
24093
24094
24095
24096
24097
24098
24099
24100
24101
24102
24103
24104
24105
24106
24107
24108
24109
24110
24111
24112
24113
24114
24115
24116
24117
24118
24119
24120
24121
24122
24123
24124
24125
24126
24127
24128
24129
24130
24131
24132
24133
24134
24135
24136
24137
24138
24139
24140
24141
24142
24143
24144
24145
24146
24147
24148
24149
24150
24151
24152
24153
24154
24155
24156
24157
24158
24159
24160
24161
24162
24163
24164
24165
24166
24167
24168
24169
24170
24171
24172
24173
24174
24175
24176
24177
24178
24179
24180
24181
24182
24183
24184
24185
24186
24187
24188
24189
24190
24191
24192
24193
24194
24195
24196
24197
24198
24199
24200
24201
24202
24203
24204
24205
24206
24207
24208
24209
24210
24211
24212
24213
24214
24215
24216
24217
24218
24219
24220
24221
24222
24223
24224
24225
24226
24227
24228
24229
24230
24231
24232
24233
24234
24235
24236
24237
24238
24239
24240
24241
24242
24243
24244
24245
24246
24247
24248
24249
24250
24251
24252
24253
24254
24255
24256
24257
24258
24259
24260
24261
24262
24263
24264
24265
24266
24267
24268
24269
24270
24271
24272
24273
24274
24275
24276
24277
24278
24279
24280
24281
24282
24283
24284
24285
24286
24287
24288
24289
24290
24291
24292
24293
24294
24295
24296
24297
24298
24299
24300
24301
24302
24303
24304
24305
24306
24307
24308
24309
24310
24311
24312
24313
24314
24315
24316
24317
24318
24319
24320
24321
24322
24323
24324
24325
24326
24327
24328
24329
24330
24331
24332
24333
24334
24335
24336
24337
24338
24339
24340
24341
24342
24343
24344
24345
24346
24347
24348
24349
24350
24351
24352
24353
24354
24355
24356
24357
24358
24359
24360
24361
24362
24363
24364
24365
24366
24367
24368
24369
24370
24371
24372
24373
24374
24375
24376
24377
24378
24379
24380
24381
24382
24383
24384
24385
24386
24387
24388
24389
24390
24391
24392
24393
24394
24395
24396
24397
24398
24399
24400
24401
24402
24403
24404
24405
24406
24407
24408
24409
24410
24411
24412
24413
24414
24415
24416
24417
24418
24419
24420
24421
24422
24423
24424
24425
24426
24427
24428
24429
24430
24431
24432
24433
24434
24435
24436
24437
24438
24439
24440
24441
24442
24443
24444
24445
24446
24447
24448
24449
24450
24451
24452
24453
24454
24455
24456
24457
24458
24459
24460
24461
24462
24463
24464
24465
24466
24467
24468
24469
24470
24471
24472
24473
24474
24475
24476
24477
24478
24479
24480
24481
24482
24483
24484
24485
24486
24487
24488
24489
24490
24491
24492
24493
24494
24495
24496
24497
24498
24499
24500
24501
24502
24503
24504
24505
24506
24507
24508
24509
24510
24511
24512
24513
24514
24515
24516
24517
24518
24519
24520
24521
24522
24523
24524
24525
24526
24527
24528
24529
24530
24531
24532
24533
24534
24535
24536
24537
24538
24539
24540
24541
24542
24543
24544
24545
24546
24547
24548
24549
24550
24551
24552
24553
24554
24555
24556
24557
24558
24559
24560
24561
24562
24563
24564
24565
24566
24567
24568
24569
24570
24571
24572
24573
24574
24575
24576
24577
24578
24579
24580
24581
24582
24583
24584
24585
24586
24587
24588
24589
24590
24591
24592
24593
24594
24595
24596
24597
24598
24599
24600
24601
24602
24603
24604
24605
24606
24607
24608
24609
24610
24611
24612
24613
24614
24615
24616
24617
24618
24619
24620
24621
24622
24623
24624
24625
24626
24627
24628
24629
24630
24631
24632
24633
24634
24635
24636
24637
24638
24639
24640
24641
24642
24643
24644
24645
24646
24647
24648
24649
24650
24651
24652
24653
24654
24655
24656
24657
24658
24659
24660
24661
24662
24663
24664
24665
24666
24667
24668
24669
24670
24671
24672
24673
24674
24675
24676
24677
24678
24679
24680
24681
24682
24683
24684
24685
24686
24687
24688
24689
24690
24691
24692
24693
24694
24695
24696
24697
24698
24699
24700
24701
24702
24703
24704
24705
24706
24707
24708
24709
24710
24711
24712
24713
24714
24715
24716
24717
24718
24719
24720
24721
24722
24723
24724
24725
24726
24727
24728
24729
24730
24731
24732
24733
24734
24735
24736
24737
24738
24739
24740
24741
24742
24743
24744
24745
24746
24747
24748
24749
24750
24751
24752
24753
24754
24755
24756
24757
24758
24759
24760
24761
24762
24763
24764
24765
24766
24767
24768
24769
24770
24771
24772
24773
24774
24775
24776
24777
24778
24779
24780
24781
24782
24783
24784
24785
24786
24787
24788
24789
24790
24791
24792
24793
24794
24795
24796
24797
24798
24799
24800
24801
24802
24803
24804
24805
24806
24807
24808
24809
24810
24811
24812
24813
24814
24815
24816
24817
24818
24819
24820
24821
24822
24823
24824
24825
24826
24827
24828
24829
24830
24831
24832
24833
24834
24835
24836
24837
24838
24839
24840
24841
24842
24843
24844
24845
24846
24847
24848
24849
24850
24851
24852
24853
24854
24855
24856
24857
24858
24859
24860
24861
24862
24863
24864
24865
24866
24867
24868
24869
24870
24871
24872
24873
24874
24875
24876
24877
24878
24879
24880
24881
24882
24883
24884
24885
24886
24887
24888
24889
24890
24891
24892
24893
24894
24895
24896
24897
24898
24899
24900
24901
24902
24903
24904
24905
24906
24907
24908
24909
24910
24911
24912
24913
24914
24915
24916
24917
24918
24919
24920
24921
24922
24923
24924
24925
24926
24927
24928
24929
24930
24931
24932
24933
24934
24935
24936
24937
24938
24939
24940
24941
24942
24943
24944
24945
24946
24947
24948
24949
24950
24951
24952
24953
24954
24955
24956
24957
24958
24959
24960
24961
24962
24963
24964
24965
24966
24967
24968
24969
24970
24971
24972
24973
24974
24975
24976
24977
24978
24979
24980
24981
24982
24983
24984
24985
24986
24987
24988
24989
24990
24991
24992
24993
24994
24995
24996
24997
24998
24999
25000
25001
25002
25003
25004
25005
25006
25007
25008
25009
25010
25011
25012
25013
25014
25015
25016
25017
25018
25019
25020
25021
25022
25023
25024
25025
25026
25027
25028
25029
25030
25031
25032
25033
25034
25035
25036
25037
25038
25039
25040
25041
25042
25043
25044
25045
25046
25047
25048
25049
25050
25051
25052
25053
25054
25055
25056
25057
25058
25059
25060
25061
25062
25063
25064
25065
25066
25067
25068
25069
25070
25071
25072
25073
25074
25075
25076
25077
25078
25079
25080
25081
25082
25083
25084
25085
25086
25087
25088
25089
25090
25091
25092
25093
25094
25095
25096
25097
25098
25099
25100
25101
25102
25103
25104
25105
25106
25107
25108
25109
25110
25111
25112
25113
25114
25115
25116
25117
25118
25119
25120
25121
25122
25123
25124
25125
25126
25127
25128
25129
25130
25131
25132
25133
25134
25135
25136
25137
25138
25139
25140
25141
25142
25143
25144
25145
25146
25147
25148
25149
25150
25151
25152
25153
25154
25155
25156
25157
25158
25159
25160
25161
25162
25163
25164
25165
25166
25167
25168
25169
25170
25171
25172
25173
25174
25175
25176
25177
25178
25179
25180
25181
25182
25183
25184
25185
25186
25187
25188
25189
25190
25191
25192
25193
25194
25195
25196
25197
25198
25199
25200
25201
25202
25203
25204
25205
25206
25207
25208
25209
25210
25211
25212
25213
25214
25215
25216
25217
25218
25219
25220
25221
25222
25223
25224
25225
25226
25227
25228
25229
25230
25231
25232
25233
25234
25235
25236
25237
25238
25239
25240
25241
25242
25243
25244
25245
25246
25247
25248
25249
25250
25251
25252
25253
25254
25255
25256
25257
25258
25259
25260
25261
25262
25263
25264
25265
25266
25267
25268
25269
25270
25271
25272
25273
25274
25275
25276
25277
25278
25279
25280
25281
25282
25283
25284
25285
25286
25287
25288
25289
25290
25291
25292
25293
25294
25295
25296
25297
25298
25299
25300
25301
25302
25303
25304
25305
25306
25307
25308
25309
25310
25311
25312
25313
25314
25315
25316
25317
25318
25319
25320
25321
25322
25323
25324
25325
25326
25327
25328
25329
25330
25331
25332
25333
25334
25335
25336
25337
25338
25339
25340
25341
25342
25343
25344
25345
25346
25347
25348
25349
25350
25351
25352
25353
25354
25355
25356
25357
25358
25359
25360
25361
25362
25363
25364
25365
25366
25367
25368
25369
25370
25371
25372
25373
25374
25375
25376
25377
25378
25379
25380
25381
25382
25383
25384
25385
25386
25387
25388
25389
25390
25391
25392
25393
25394
25395
25396
25397
25398
25399
25400
25401
25402
25403
25404
25405
25406
25407
25408
25409
25410
25411
25412
25413
25414
25415
25416
25417
25418
25419
25420
25421
25422
25423
25424
25425
25426
25427
25428
25429
25430
25431
25432
25433
25434
25435
25436
25437
25438
25439
25440
25441
25442
25443
25444
25445
25446
25447
25448
25449
25450
25451
25452
25453
25454
25455
25456
25457
25458
25459
25460
25461
25462
25463
25464
25465
25466
25467
25468
25469
25470
25471
25472
25473
25474
25475
25476
25477
25478
25479
25480
25481
25482
25483
25484
25485
25486
25487
25488
25489
25490
25491
25492
25493
25494
25495
25496
25497
25498
25499
25500
25501
25502
25503
25504
25505
25506
25507
25508
25509
25510
25511
25512
25513
25514
25515
25516
25517
25518
25519
25520
25521
25522
25523
25524
25525
25526
25527
25528
25529
25530
25531
25532
25533
25534
25535
25536
25537
25538
25539
25540
25541
25542
25543
25544
25545
25546
25547
25548
25549
25550
25551
25552
25553
25554
25555
25556
25557
25558
25559
25560
25561
25562
25563
25564
25565
25566
25567
25568
25569
25570
25571
25572
25573
25574
25575
25576
25577
25578
25579
25580
25581
25582
25583
25584
25585
25586
25587
25588
25589
25590
25591
25592
25593
25594
25595
25596
25597
25598
25599
25600
25601
25602
25603
25604
25605
25606
25607
25608
25609
25610
25611
25612
25613
25614
25615
25616
25617
25618
25619
25620
25621
25622
25623
25624
25625
25626
25627
25628
25629
25630
25631
25632
25633
25634
25635
25636
25637
25638
25639
25640
25641
25642
25643
25644
25645
25646
25647
25648
25649
25650
25651
25652
25653
25654
25655
25656
25657
25658
25659
25660
25661
25662
25663
25664
25665
25666
25667
25668
25669
25670
25671
25672
25673
25674
25675
25676
25677
25678
25679
25680
25681
25682
25683
25684
25685
25686
25687
25688
25689
25690
25691
25692
25693
25694
25695
25696
25697
25698
25699
25700
25701
25702
25703
25704
25705
25706
25707
25708
25709
25710
25711
25712
25713
25714
25715
25716
25717
25718
25719
25720
25721
25722
25723
25724
25725
25726
25727
25728
25729
25730
25731
25732
25733
25734
25735
25736
25737
25738
25739
25740
25741
25742
25743
25744
25745
25746
25747
25748
25749
25750
25751
25752
25753
25754
25755
25756
25757
25758
25759
25760
25761
25762
25763
25764
25765
25766
25767
25768
25769
25770
25771
25772
25773
25774
25775
25776
25777
25778
25779
25780
25781
25782
25783
25784
25785
25786
25787
25788
25789
25790
25791
25792
25793
25794
25795
25796
25797
25798
25799
25800
25801
25802
25803
25804
25805
25806
25807
25808
25809
25810
25811
25812
25813
25814
25815
25816
25817
25818
25819
25820
25821
25822
25823
25824
25825
25826
25827
25828
25829
25830
25831
25832
25833
25834
25835
25836
25837
25838
25839
25840
25841
25842
25843
25844
25845
25846
25847
25848
25849
25850
25851
25852
25853
25854
25855
25856
25857
25858
25859
25860
25861
25862
25863
25864
25865
25866
25867
25868
25869
25870
25871
25872
25873
25874
25875
25876
25877
25878
25879
25880
25881
25882
25883
25884
25885
25886
25887
25888
25889
25890
25891
25892
25893
25894
25895
25896
25897
25898
25899
25900
25901
25902
25903
25904
25905
25906
25907
25908
25909
25910
25911
25912
25913
25914
25915
25916
25917
25918
25919
25920
25921
25922
25923
25924
25925
25926
25927
25928
25929
25930
25931
25932
25933
25934
25935
25936
25937
25938
25939
25940
25941
25942
25943
25944
25945
25946
25947
25948
25949
25950
25951
25952
25953
25954
25955
25956
25957
25958
25959
25960
25961
25962
25963
25964
25965
25966
25967
25968
25969
25970
25971
25972
25973
25974
25975
25976
25977
25978
25979
25980
25981
25982
25983
25984
25985
25986
25987
25988
25989
25990
25991
25992
25993
25994
25995
25996
25997
25998
25999
26000
26001
26002
26003
26004
26005
26006
26007
26008
26009
26010
26011
26012
26013
26014
26015
26016
26017
26018
26019
26020
26021
26022
26023
26024
26025
26026
26027
26028
26029
26030
26031
26032
26033
26034
26035
26036
26037
26038
26039
26040
26041
26042
26043
26044
26045
26046
26047
26048
26049
26050
26051
26052
26053
26054
26055
26056
26057
26058
26059
26060
26061
26062
26063
26064
26065
26066
26067
26068
26069
26070
26071
26072
26073
26074
26075
26076
26077
26078
26079
26080
26081
26082
26083
26084
26085
26086
26087
26088
26089
26090
26091
26092
26093
26094
26095
26096
26097
26098
26099
26100
26101
26102
26103
26104
26105
26106
26107
26108
26109
26110
26111
26112
26113
26114
26115
26116
26117
26118
26119
26120
26121
26122
26123
26124
26125
26126
26127
26128
26129
26130
26131
26132
26133
26134
26135
26136
26137
26138
26139
26140
26141
26142
26143
26144
26145
26146
26147
26148
26149
26150
26151
26152
26153
26154
26155
26156
26157
26158
26159
26160
26161
26162
26163
26164
26165
26166
26167
26168
26169
26170
26171
26172
26173
26174
26175
26176
26177
26178
26179
26180
26181
26182
26183
26184
26185
26186
26187
26188
26189
26190
26191
26192
26193
26194
26195
26196
26197
26198
26199
26200
26201
26202
26203
26204
26205
26206
26207
26208
26209
26210
26211
26212
26213
26214
26215
26216
26217
26218
26219
26220
26221
26222
26223
26224
26225
26226
26227
26228
26229
26230
26231
26232
26233
26234
26235
26236
26237
26238
26239
26240
26241
26242
26243
26244
26245
26246
26247
26248
26249
26250
26251
26252
26253
26254
26255
26256
26257
26258
26259
26260
26261
26262
26263
26264
26265
26266
26267
26268
26269
26270
26271
26272
26273
26274
26275
26276
26277
26278
26279
26280
26281
26282
26283
26284
26285
26286
26287
26288
26289
26290
26291
26292
26293
26294
26295
26296
26297
26298
26299
26300
26301
26302
26303
26304
26305
26306
26307
26308
26309
26310
26311
26312
26313
26314
26315
26316
26317
26318
26319
26320
26321
26322
26323
26324
26325
26326
26327
26328
26329
26330
26331
26332
26333
26334
26335
26336
26337
26338
26339
26340
26341
26342
26343
26344
26345
26346
26347
26348
26349
26350
26351
26352
26353
26354
26355
26356
26357
26358
26359
26360
26361
26362
26363
26364
26365
26366
26367
26368
26369
26370
26371
26372
26373
26374
26375
26376
26377
26378
26379
26380
26381
26382
26383
26384
26385
26386
26387
26388
26389
26390
26391
26392
26393
26394
26395
26396
26397
26398
26399
26400
26401
26402
26403
26404
26405
26406
26407
26408
26409
26410
26411
26412
26413
26414
26415
26416
26417
26418
26419
26420
26421
26422
26423
26424
26425
26426
26427
26428
26429
26430
26431
26432
26433
26434
26435
26436
26437
26438
26439
26440
26441
26442
26443
26444
26445
26446
26447
26448
26449
26450
26451
26452
26453
26454
26455
26456
26457
26458
26459
26460
26461
26462
26463
26464
26465
26466
26467
26468
26469
26470
26471
26472
26473
26474
26475
26476
26477
26478
26479
26480
26481
26482
26483
26484
26485
26486
26487
26488
26489
26490
26491
26492
26493
26494
26495
26496
26497
26498
26499
26500
26501
26502
26503
26504
26505
26506
26507
26508
26509
26510
26511
26512
26513
26514
26515
26516
26517
26518
26519
26520
26521
26522
26523
26524
26525
26526
26527
26528
26529
26530
26531
26532
26533
26534
26535
26536
26537
26538
26539
26540
26541
26542
26543
26544
26545
26546
26547
26548
26549
26550
26551
26552
26553
26554
26555
26556
26557
26558
26559
26560
26561
26562
26563
26564
26565
26566
26567
26568
26569
26570
26571
26572
26573
26574
26575
26576
26577
26578
26579
26580
26581
26582
26583
26584
26585
26586
26587
26588
26589
26590
26591
26592
26593
26594
26595
26596
26597
26598
26599
26600
26601
26602
26603
26604
26605
26606
26607
26608
26609
26610
26611
26612
26613
26614
26615
26616
26617
26618
26619
26620
26621
26622
26623
26624
26625
26626
26627
26628
26629
26630
26631
26632
26633
26634
26635
26636
26637
26638
26639
26640
26641
26642
26643
26644
26645
26646
26647
26648
26649
26650
26651
26652
26653
26654
26655
26656
26657
26658
26659
26660
26661
26662
26663
26664
26665
26666
26667
26668
26669
26670
26671
26672
26673
26674
26675
26676
26677
26678
26679
26680
26681
26682
26683
26684
26685
26686
26687
26688
26689
26690
26691
26692
26693
26694
26695
26696
26697
26698
26699
26700
26701
26702
26703
26704
26705
26706
26707
26708
26709
26710
26711
26712
26713
26714
26715
26716
26717
26718
26719
26720
26721
26722
26723
26724
26725
26726
26727
26728
26729
26730
26731
26732
26733
26734
26735
26736
26737
26738
26739
26740
26741
26742
26743
26744
26745
26746
26747
26748
26749
26750
26751
26752
26753
26754
26755
26756
26757
26758
26759
26760
26761
26762
26763
26764
26765
26766
26767
26768
26769
26770
26771
26772
26773
26774
26775
26776
26777
26778
26779
26780
26781
26782
26783
26784
26785
26786
26787
26788
26789
26790
26791
26792
26793
26794
26795
26796
26797
26798
26799
26800
26801
26802
26803
26804
26805
26806
26807
26808
26809
26810
26811
26812
26813
26814
26815
26816
26817
26818
26819
26820
26821
26822
26823
26824
26825
26826
26827
26828
26829
26830
26831
26832
26833
26834
26835
26836
26837
26838
26839
26840
26841
26842
26843
26844
26845
26846
26847
26848
26849
26850
26851
26852
26853
26854
26855
26856
26857
26858
26859
26860
26861
26862
26863
26864
26865
26866
26867
26868
26869
26870
26871
26872
26873
26874
26875
26876
26877
26878
26879
26880
26881
26882
26883
26884
26885
26886
26887
26888
26889
26890
26891
26892
26893
26894
26895
26896
26897
26898
26899
26900
26901
26902
26903
26904
26905
26906
26907
26908
26909
26910
26911
26912
26913
26914
26915
26916
26917
26918
26919
26920
26921
26922
26923
26924
26925
26926
26927
26928
26929
26930
26931
26932
26933
26934
26935
26936
26937
26938
26939
26940
26941
26942
26943
26944
26945
26946
26947
26948
26949
26950
26951
26952
26953
26954
26955
26956
26957
26958
26959
26960
26961
26962
26963
26964
26965
26966
26967
26968
26969
26970
26971
26972
26973
26974
26975
26976
26977
26978
26979
26980
26981
26982
26983
26984
26985
26986
26987
26988
26989
26990
26991
26992
26993
26994
26995
26996
26997
26998
26999
27000
27001
27002
27003
27004
27005
27006
27007
27008
27009
27010
27011
27012
27013
27014
27015
27016
27017
27018
27019
27020
27021
27022
27023
27024
27025
27026
27027
27028
27029
27030
27031
27032
27033
27034
27035
27036
27037
27038
27039
27040
27041
27042
27043
27044
27045
27046
27047
27048
27049
27050
27051
27052
27053
27054
27055
27056
27057
27058
27059
27060
27061
27062
27063
27064
27065
27066
27067
27068
27069
27070
27071
27072
27073
27074
27075
27076
27077
27078
27079
27080
27081
27082
27083
27084
27085
27086
27087
27088
27089
27090
27091
27092
27093
27094
27095
27096
27097
27098
27099
27100
27101
27102
27103
27104
27105
27106
27107
27108
27109
27110
27111
27112
27113
27114
27115
27116
27117
27118
27119
27120
27121
27122
27123
27124
27125
27126
27127
27128
27129
27130
27131
27132
27133
27134
27135
27136
27137
27138
27139
27140
27141
27142
27143
27144
27145
27146
27147
27148
27149
27150
27151
27152
27153
27154
27155
27156
27157
27158
27159
27160
27161
27162
27163
27164
27165
27166
27167
27168
27169
27170
27171
27172
27173
27174
27175
27176
27177
27178
27179
27180
27181
27182
27183
27184
27185
27186
27187
27188
27189
27190
27191
27192
27193
27194
27195
27196
27197
27198
27199
27200
27201
27202
27203
27204
27205
27206
27207
27208
27209
27210
27211
27212
27213
27214
27215
27216
27217
27218
27219
27220
27221
27222
27223
27224
27225
27226
27227
27228
27229
27230
27231
27232
27233
27234
27235
27236
27237
27238
27239
27240
27241
27242
27243
27244
27245
27246
27247
27248
27249
27250
27251
27252
27253
27254
27255
27256
27257
27258
27259
27260
27261
27262
27263
27264
27265
27266
27267
27268
27269
27270
27271
27272
27273
27274
27275
27276
27277
27278
27279
27280
27281
27282
27283
27284
27285
27286
27287
27288
27289
27290
27291
27292
27293
27294
27295
27296
27297
27298
27299
27300
27301
27302
27303
27304
27305
27306
27307
27308
27309
27310
27311
27312
27313
27314
27315
27316
27317
27318
27319
27320
27321
27322
27323
27324
27325
27326
27327
27328
27329
27330
27331
27332
27333
27334
27335
27336
27337
27338
27339
27340
27341
27342
27343
27344
27345
27346
27347
27348
27349
27350
27351
27352
27353
27354
27355
27356
27357
27358
27359
27360
27361
27362
27363
27364
27365
27366
27367
27368
27369
27370
27371
27372
27373
27374
27375
27376
27377
27378
27379
27380
27381
27382
27383
27384
27385
27386
27387
27388
27389
27390
27391
27392
27393
27394
27395
27396
27397
27398
27399
27400
27401
27402
27403
27404
27405
27406
27407
27408
27409
27410
27411
27412
27413
27414
27415
27416
27417
27418
27419
27420
27421
27422
27423
27424
27425
27426
27427
27428
27429
27430
27431
27432
27433
27434
27435
27436
27437
27438
27439
27440
27441
27442
27443
27444
27445
27446
27447
27448
27449
27450
27451
27452
27453
27454
27455
27456
27457
27458
27459
27460
27461
27462
27463
27464
27465
27466
27467
27468
27469
27470
27471
27472
27473
27474
27475
27476
27477
27478
27479
27480
27481
27482
27483
27484
27485
27486
27487
27488
27489
27490
27491
27492
27493
27494
27495
27496
27497
27498
27499
27500
27501
27502
27503
27504
27505
27506
27507
27508
27509
27510
27511
27512
27513
27514
27515
27516
27517
27518
27519
27520
27521
27522
27523
27524
27525
27526
27527
27528
27529
27530
27531
27532
27533
27534
27535
27536
27537
27538
27539
27540
27541
27542
27543
27544
27545
27546
27547
27548
27549
27550
27551
27552
27553
27554
27555
27556
27557
27558
27559
27560
27561
27562
27563
27564
27565
27566
27567
27568
27569
27570
27571
27572
27573
27574
27575
27576
27577
27578
27579
27580
27581
27582
27583
27584
27585
27586
27587
27588
27589
27590
27591
27592
27593
27594
27595
27596
27597
27598
27599
27600
27601
27602
27603
27604
27605
27606
27607
27608
27609
27610
27611
27612
27613
27614
27615
27616
27617
27618
27619
27620
27621
27622
27623
27624
27625
27626
27627
27628
27629
27630
27631
27632
27633
27634
27635
27636
27637
27638
27639
27640
27641
27642
27643
27644
27645
27646
27647
27648
27649
27650
27651
27652
27653
27654
27655
27656
27657
27658
27659
27660
27661
27662
27663
27664
27665
27666
27667
27668
27669
27670
27671
27672
27673
27674
27675
27676
27677
27678
27679
27680
27681
27682
27683
27684
27685
27686
27687
27688
27689
27690
27691
27692
27693
27694
27695
27696
27697
27698
27699
27700
27701
27702
27703
27704
27705
27706
27707
27708
27709
27710
27711
27712
27713
27714
27715
27716
27717
27718
27719
27720
27721
27722
27723
27724
27725
27726
27727
27728
27729
27730
27731
27732
27733
27734
27735
27736
27737
27738
27739
27740
27741
27742
27743
27744
27745
27746
27747
27748
27749
27750
27751
27752
27753
27754
27755
27756
27757
27758
27759
27760
27761
27762
27763
27764
27765
27766
27767
27768
27769
27770
27771
27772
27773
27774
27775
27776
27777
27778
27779
27780
27781
27782
27783
27784
27785
27786
27787
27788
27789
27790
27791
27792
27793
27794
27795
27796
27797
27798
27799
27800
27801
27802
27803
27804
27805
27806
27807
27808
27809
27810
27811
27812
27813
27814
27815
27816
27817
27818
27819
27820
27821
27822
27823
27824
27825
27826
27827
27828
27829
27830
27831
27832
27833
27834
27835
27836
27837
27838
27839
27840
27841
27842
27843
27844
27845
27846
27847
27848
27849
27850
27851
27852
27853
27854
27855
27856
27857
27858
27859
27860
27861
27862
27863
27864
27865
27866
27867
27868
27869
27870
27871
27872
27873
27874
27875
27876
27877
27878
27879
27880
27881
27882
27883
27884
27885
27886
27887
27888
27889
27890
27891
27892
27893
27894
27895
27896
27897
27898
27899
27900
27901
27902
27903
27904
27905
27906
27907
27908
27909
27910
27911
27912
27913
27914
27915
27916
27917
27918
27919
27920
27921
27922
27923
27924
27925
27926
27927
27928
27929
27930
27931
27932
27933
27934
27935
27936
27937
27938
27939
27940
27941
27942
27943
27944
27945
27946
27947
27948
27949
27950
27951
27952
27953
27954
27955
27956
27957
27958
27959
27960
27961
27962
27963
27964
27965
27966
27967
27968
27969
27970
27971
27972
27973
27974
27975
27976
27977
27978
27979
27980
27981
27982
27983
27984
27985
27986
27987
27988
27989
27990
27991
27992
27993
27994
27995
27996
27997
27998
27999
28000
28001
28002
28003
28004
28005
28006
28007
28008
28009
28010
28011
28012
28013
28014
28015
28016
28017
28018
28019
28020
28021
28022
28023
28024
28025
28026
28027
28028
28029
28030
28031
28032
28033
28034
28035
28036
28037
28038
28039
28040
28041
28042
28043
28044
28045
28046
28047
28048
28049
28050
28051
28052
28053
28054
28055
28056
28057
28058
28059
28060
28061
28062
28063
28064
28065
28066
28067
28068
28069
28070
28071
28072
28073
28074
28075
28076
28077
28078
28079
28080
28081
28082
28083
28084
28085
28086
28087
28088
28089
28090
28091
28092
28093
28094
28095
28096
28097
28098
28099
28100
28101
28102
28103
28104
28105
28106
28107
28108
28109
28110
28111
28112
28113
28114
28115
28116
28117
28118
28119
28120
28121
28122
28123
28124
28125
28126
28127
28128
28129
28130
28131
28132
28133
28134
28135
28136
28137
28138
28139
28140
28141
28142
28143
28144
28145
28146
28147
28148
28149
28150
28151
28152
28153
28154
28155
28156
28157
28158
28159
28160
28161
28162
28163
28164
28165
28166
28167
28168
28169
28170
28171
28172
28173
28174
28175
28176
28177
28178
28179
28180
28181
28182
28183
28184
28185
28186
28187
28188
28189
28190
28191
28192
28193
28194
28195
28196
28197
28198
28199
28200
28201
28202
28203
28204
28205
28206
28207
28208
28209
28210
28211
28212
28213
28214
28215
28216
28217
28218
28219
28220
28221
28222
28223
28224
28225
28226
28227
28228
28229
28230
28231
28232
28233
28234
28235
28236
28237
28238
28239
28240
28241
28242
28243
28244
28245
28246
28247
28248
28249
28250
28251
28252
28253
28254
28255
28256
28257
28258
28259
28260
28261
28262
28263
28264
28265
28266
28267
28268
28269
28270
28271
28272
28273
28274
28275
28276
28277
28278
28279
28280
28281
28282
28283
28284
28285
28286
28287
28288
28289
28290
28291
28292
28293
28294
28295
28296
28297
28298
28299
28300
28301
28302
28303
28304
28305
28306
28307
28308
28309
28310
28311
28312
28313
28314
28315
28316
28317
28318
28319
28320
28321
28322
28323
28324
28325
28326
28327
28328
28329
28330
28331
28332
28333
28334
28335
28336
28337
28338
28339
28340
28341
28342
28343
28344
28345
28346
28347
28348
28349
28350
28351
28352
28353
28354
28355
28356
28357
28358
28359
28360
28361
28362
28363
28364
28365
28366
28367
28368
28369
28370
28371
28372
28373
28374
28375
28376
28377
28378
28379
28380
28381
28382
28383
28384
28385
28386
28387
28388
28389
28390
28391
28392
28393
28394
28395
28396
28397
28398
28399
28400
28401
28402
28403
28404
28405
28406
28407
28408
28409
28410
28411
28412
28413
28414
28415
28416
28417
28418
28419
28420
28421
28422
28423
28424
28425
28426
28427
28428
28429
28430
28431
28432
28433
28434
28435
28436
28437
28438
28439
28440
28441
28442
28443
28444
28445
28446
28447
28448
28449
28450
28451
28452
28453
28454
28455
28456
28457
28458
28459
28460
28461
28462
28463
28464
28465
28466
28467
28468
28469
28470
28471
28472
28473
28474
28475
28476
28477
28478
28479
28480
28481
28482
28483
28484
28485
28486
28487
28488
28489
28490
28491
28492
28493
28494
28495
28496
28497
28498
28499
28500
28501
28502
28503
28504
28505
28506
28507
28508
28509
28510
28511
28512
28513
28514
28515
28516
28517
28518
28519
28520
28521
28522
28523
28524
28525
28526
28527
28528
28529
28530
28531
28532
28533
28534
28535
28536
28537
28538
28539
28540
28541
28542
28543
28544
28545
28546
28547
28548
28549
28550
28551
28552
28553
28554
28555
28556
28557
28558
28559
28560
28561
28562
28563
28564
28565
28566
28567
28568
28569
28570
28571
28572
28573
28574
28575
28576
28577
28578
28579
28580
28581
28582
28583
28584
28585
28586
28587
28588
28589
28590
28591
28592
28593
28594
28595
28596
28597
28598
28599
28600
28601
28602
28603
28604
28605
28606
28607
28608
28609
28610
28611
28612
28613
28614
28615
28616
28617
28618
28619
28620
28621
28622
28623
28624
28625
28626
28627
28628
28629
28630
28631
28632
28633
28634
28635
28636
28637
28638
28639
28640
28641
28642
28643
28644
28645
28646
28647
28648
28649
28650
28651
28652
28653
28654
28655
28656
28657
28658
28659
28660
28661
28662
28663
28664
28665
28666
28667
28668
28669
28670
28671
28672
28673
28674
28675
28676
28677
28678
28679
28680
28681
28682
28683
28684
28685
28686
28687
28688
28689
28690
28691
28692
28693
28694
28695
28696
28697
28698
28699
28700
28701
28702
28703
28704
28705
28706
28707
28708
28709
28710
28711
28712
28713
28714
28715
28716
28717
28718
28719
28720
28721
28722
28723
28724
28725
28726
28727
28728
28729
28730
28731
28732
28733
28734
28735
28736
28737
28738
28739
28740
28741
28742
28743
28744
28745
28746
28747
28748
28749
28750
28751
28752
28753
28754
28755
28756
28757
28758
28759
28760
28761
28762
28763
28764
28765
28766
28767
28768
28769
28770
28771
28772
28773
28774
28775
28776
28777
28778
28779
28780
28781
28782
28783
28784
28785
28786
28787
28788
28789
28790
28791
28792
28793
28794
28795
28796
28797
28798
28799
28800
28801
28802
28803
28804
28805
28806
28807
28808
28809
28810
28811
28812
28813
28814
28815
28816
28817
28818
28819
28820
28821
28822
28823
28824
28825
28826
28827
28828
28829
28830
28831
28832
28833
28834
28835
28836
28837
28838
28839
28840
28841
28842
28843
28844
28845
28846
28847
28848
28849
28850
28851
28852
28853
28854
28855
28856
28857
28858
28859
28860
28861
28862
28863
28864
28865
28866
28867
28868
28869
28870
28871
28872
28873
28874
28875
28876
28877
28878
28879
28880
28881
28882
28883
28884
28885
28886
28887
28888
28889
28890
28891
28892
28893
28894
28895
28896
28897
28898
28899
28900
28901
28902
28903
28904
28905
28906
28907
28908
28909
28910
28911
28912
28913
28914
28915
28916
28917
28918
28919
28920
28921
28922
28923
28924
28925
28926
28927
28928
28929
28930
28931
28932
28933
28934
28935
28936
28937
28938
28939
28940
28941
28942
28943
28944
28945
28946
28947
28948
28949
28950
28951
28952
28953
28954
28955
28956
28957
28958
28959
28960
28961
28962
28963
28964
28965
28966
28967
28968
28969
28970
28971
28972
28973
28974
28975
28976
28977
28978
28979
28980
28981
28982
28983
28984
28985
28986
28987
28988
28989
28990
28991
28992
28993
28994
28995
28996
28997
28998
28999
29000
29001
29002
29003
29004
29005
29006
29007
29008
29009
29010
29011
29012
29013
29014
29015
29016
29017
29018
29019
29020
29021
29022
29023
29024
29025
29026
29027
29028
29029
29030
29031
29032
29033
29034
29035
29036
29037
29038
29039
29040
29041
29042
29043
29044
29045
29046
29047
29048
29049
29050
29051
29052
29053
29054
29055
29056
29057
29058
29059
29060
29061
29062
29063
29064
29065
29066
29067
29068
29069
29070
29071
29072
29073
29074
29075
29076
29077
29078
29079
29080
29081
29082
29083
29084
29085
29086
29087
29088
29089
29090
29091
29092
29093
29094
29095
29096
29097
29098
29099
29100
29101
29102
29103
29104
29105
29106
29107
29108
29109
29110
29111
29112
29113
29114
29115
29116
29117
29118
29119
29120
29121
29122
29123
29124
29125
29126
29127
29128
29129
29130
29131
29132
29133
29134
29135
29136
29137
29138
29139
29140
29141
29142
29143
29144
29145
29146
29147
29148
29149
29150
29151
29152
29153
29154
29155
29156
29157
29158
29159
29160
29161
29162
29163
29164
29165
29166
29167
29168
29169
29170
29171
29172
29173
29174
29175
29176
29177
29178
29179
29180
29181
29182
29183
29184
29185
29186
29187
29188
29189
29190
29191
29192
29193
29194
29195
29196
29197
29198
29199
29200
29201
29202
29203
29204
29205
29206
29207
29208
29209
29210
29211
29212
29213
29214
29215
29216
29217
29218
29219
29220
29221
29222
29223
29224
29225
29226
29227
29228
29229
29230
29231
29232
29233
29234
29235
29236
29237
29238
29239
29240
29241
29242
29243
29244
29245
29246
29247
29248
29249
29250
29251
29252
29253
29254
29255
29256
29257
29258
29259
29260
29261
29262
29263
29264
29265
29266
29267
29268
29269
29270
29271
29272
29273
29274
29275
29276
29277
29278
29279
29280
29281
29282
29283
29284
29285
29286
29287
29288
29289
29290
29291
29292
29293
29294
29295
29296
29297
29298
29299
29300
29301
29302
29303
29304
29305
29306
29307
29308
29309
29310
29311
29312
29313
29314
29315
29316
29317
29318
29319
29320
29321
29322
29323
29324
29325
29326
29327
29328
29329
29330
29331
29332
29333
29334
29335
29336
29337
29338
29339
29340
29341
29342
29343
29344
29345
29346
29347
29348
29349
29350
29351
29352
29353
29354
29355
29356
29357
29358
29359
29360
29361
29362
29363
29364
29365
29366
29367
29368
29369
29370
29371
29372
29373
29374
29375
29376
29377
29378
29379
29380
29381
29382
29383
29384
29385
29386
29387
29388
29389
29390
29391
29392
29393
29394
29395
29396
29397
29398
29399
29400
29401
29402
29403
29404
29405
29406
29407
29408
29409
29410
29411
29412
29413
29414
29415
29416
29417
29418
29419
29420
29421
29422
29423
29424
29425
29426
29427
29428
29429
29430
29431
29432
29433
29434
29435
29436
29437
29438
29439
29440
29441
29442
29443
29444
29445
29446
29447
29448
29449
29450
29451
29452
29453
29454
29455
29456
29457
29458
29459
29460
29461
29462
29463
29464
29465
29466
29467
29468
29469
29470
29471
29472
29473
29474
29475
29476
29477
29478
29479
29480
29481
29482
29483
29484
29485
29486
29487
29488
29489
29490
29491
29492
29493
29494
29495
29496
29497
29498
29499
29500
29501
29502
29503
29504
29505
29506
29507
29508
29509
29510
29511
29512
29513
29514
29515
29516
29517
29518
29519
29520
29521
29522
29523
29524
29525
29526
29527
29528
29529
29530
29531
29532
29533
29534
29535
29536
29537
29538
29539
29540
29541
29542
29543
29544
29545
29546
29547
29548
29549
29550
29551
29552
29553
29554
29555
29556
29557
29558
29559
29560
29561
29562
29563
29564
29565
29566
29567
29568
29569
29570
29571
29572
29573
29574
29575
29576
29577
29578
29579
29580
29581
29582
29583
29584
29585
29586
29587
29588
29589
29590
29591
29592
29593
29594
29595
29596
29597
29598
29599
29600
29601
29602
29603
29604
29605
29606
29607
29608
29609
29610
29611
29612
29613
29614
29615
29616
29617
29618
29619
29620
29621
29622
29623
29624
29625
29626
29627
29628
29629
29630
29631
29632
29633
29634
29635
29636
29637
29638
29639
29640
29641
29642
29643
29644
29645
29646
29647
29648
29649
29650
29651
29652
29653
29654
29655
29656
29657
29658
29659
29660
29661
29662
29663
29664
29665
29666
29667
29668
29669
29670
29671
29672
29673
29674
29675
29676
29677
29678
29679
29680
29681
29682
29683
29684
29685
29686
29687
29688
29689
29690
29691
29692
29693
29694
29695
29696
29697
29698
29699
29700
29701
29702
29703
29704
29705
29706
29707
29708
29709
29710
29711
29712
29713
29714
29715
29716
29717
29718
29719
29720
29721
29722
29723
29724
29725
29726
29727
29728
29729
29730
29731
29732
29733
29734
29735
29736
29737
29738
29739
29740
29741
29742
29743
29744
29745
29746
29747
29748
29749
29750
29751
29752
29753
29754
29755
29756
29757
29758
29759
29760
29761
29762
29763
29764
29765
29766
29767
29768
29769
29770
29771
29772
29773
29774
29775
29776
29777
29778
29779
29780
29781
29782
29783
29784
29785
29786
29787
29788
29789
29790
29791
29792
29793
29794
29795
29796
29797
29798
29799
29800
29801
29802
29803
29804
29805
29806
29807
29808
29809
29810
29811
29812
29813
29814
29815
29816
29817
29818
29819
29820
29821
29822
29823
29824
29825
29826
29827
29828
29829
29830
29831
29832
29833
29834
29835
29836
29837
29838
29839
29840
29841
29842
29843
29844
29845
29846
29847
29848
29849
29850
29851
29852
29853
29854
29855
29856
29857
29858
29859
29860
29861
29862
29863
29864
29865
29866
29867
29868
29869
29870
29871
29872
29873
29874
29875
29876
29877
29878
29879
29880
29881
29882
29883
29884
29885
29886
29887
29888
29889
29890
29891
29892
29893
29894
29895
29896
29897
29898
29899
29900
29901
29902
29903
29904
29905
29906
29907
29908
29909
29910
29911
29912
29913
29914
29915
29916
29917
29918
29919
29920
29921
29922
29923
29924
29925
29926
29927
29928
29929
29930
29931
29932
29933
29934
29935
29936
29937
29938
29939
29940
29941
29942
29943
29944
29945
29946
29947
29948
29949
29950
29951
29952
29953
29954
29955
29956
29957
29958
29959
29960
29961
29962
29963
29964
29965
29966
29967
29968
29969
29970
29971
29972
29973
29974
29975
29976
29977
29978
29979
29980
29981
29982
29983
29984
29985
29986
29987
29988
29989
29990
29991
29992
29993
29994
29995
29996
29997
29998
29999
30000
30001
30002
30003
30004
30005
30006
30007
30008
30009
30010
30011
30012
30013
30014
30015
30016
30017
30018
30019
30020
30021
30022
30023
30024
30025
30026
30027
30028
30029
30030
30031
30032
30033
30034
30035
30036
30037
30038
30039
30040
30041
30042
30043
30044
30045
30046
30047
30048
30049
30050
30051
30052
30053
30054
30055
30056
30057
30058
30059
30060
30061
30062
30063
30064
30065
30066
30067
30068
30069
30070
30071
30072
30073
30074
30075
30076
30077
30078
30079
30080
30081
30082
30083
30084
30085
30086
30087
30088
30089
30090
30091
30092
30093
30094
30095
30096
30097
30098
30099
30100
30101
30102
30103
30104
30105
30106
30107
30108
30109
30110
30111
30112
30113
30114
30115
30116
30117
30118
30119
30120
30121
30122
30123
30124
30125
30126
30127
30128
30129
30130
30131
30132
30133
30134
30135
30136
30137
30138
30139
30140
30141
30142
30143
30144
30145
30146
30147
30148
30149
30150
30151
30152
30153
30154
30155
30156
30157
30158
30159
30160
30161
30162
30163
30164
30165
30166
30167
30168
30169
30170
30171
30172
30173
30174
30175
30176
30177
30178
30179
30180
30181
30182
30183
30184
30185
30186
30187
30188
30189
30190
30191
30192
30193
30194
30195
30196
30197
30198
30199
30200
30201
30202
30203
30204
30205
30206
30207
30208
30209
30210
30211
30212
30213
30214
30215
30216
30217
30218
30219
30220
30221
30222
30223
30224
30225
30226
30227
30228
30229
30230
30231
30232
30233
30234
30235
30236
30237
30238
30239
30240
30241
30242
30243
30244
30245
30246
30247
30248
30249
30250
30251
30252
30253
30254
30255
30256
30257
30258
30259
30260
30261
30262
30263
30264
30265
30266
30267
30268
30269
30270
30271
30272
30273
30274
30275
30276
30277
30278
30279
30280
30281
30282
30283
30284
30285
30286
30287
30288
30289
30290
30291
30292
30293
30294
30295
30296
30297
30298
30299
30300
30301
30302
30303
30304
30305
30306
30307
30308
30309
30310
30311
30312
30313
30314
30315
30316
30317
30318
30319
30320
30321
30322
30323
30324
30325
30326
30327
30328
30329
30330
30331
30332
30333
30334
30335
30336
30337
30338
30339
30340
30341
30342
30343
30344
30345
30346
30347
30348
30349
30350
30351
30352
30353
30354
30355
30356
30357
30358
30359
30360
30361
30362
30363
30364
30365
30366
30367
30368
30369
30370
30371
30372
30373
30374
30375
30376
30377
30378
30379
30380
30381
30382
30383
30384
30385
30386
30387
30388
30389
30390
30391
30392
30393
30394
30395
30396
30397
30398
30399
30400
30401
30402
30403
30404
30405
30406
30407
30408
30409
30410
30411
30412
30413
30414
30415
30416
30417
30418
30419
30420
30421
30422
30423
30424
30425
30426
30427
30428
30429
30430
30431
30432
30433
30434
30435
30436
30437
30438
30439
30440
30441
30442
30443
30444
30445
30446
30447
30448
30449
30450
30451
30452
30453
30454
30455
30456
30457
30458
30459
30460
30461
30462
30463
30464
30465
30466
30467
30468
30469
30470
30471
30472
30473
30474
30475
30476
30477
30478
30479
30480
30481
30482
30483
30484
30485
30486
30487
30488
30489
30490
30491
30492
30493
30494
30495
30496
30497
30498
30499
30500
30501
30502
30503
30504
30505
30506
30507
30508
30509
30510
30511
30512
30513
30514
30515
30516
30517
30518
30519
30520
30521
30522
30523
30524
30525
30526
30527
30528
30529
30530
30531
30532
30533
30534
30535
30536
30537
30538
30539
30540
30541
30542
30543
30544
30545
30546
30547
30548
30549
30550
30551
30552
30553
30554
30555
30556
30557
30558
30559
30560
30561
30562
30563
30564
30565
30566
30567
30568
30569
30570
30571
30572
30573
30574
30575
30576
30577
30578
30579
30580
30581
30582
30583
30584
30585
30586
30587
30588
30589
30590
30591
30592
30593
30594
30595
30596
30597
30598
30599
30600
30601
30602
30603
30604
30605
30606
30607
30608
30609
30610
30611
30612
30613
30614
30615
30616
30617
30618
30619
30620
30621
30622
30623
30624
30625
30626
30627
30628
30629
30630
30631
30632
30633
30634
30635
30636
30637
30638
30639
30640
30641
30642
30643
30644
30645
30646
30647
30648
30649
30650
30651
30652
30653
30654
30655
30656
30657
30658
30659
30660
30661
30662
30663
30664
30665
30666
30667
30668
30669
30670
30671
30672
30673
30674
30675
30676
30677
30678
30679
30680
30681
30682
30683
30684
30685
30686
30687
30688
30689
30690
30691
30692
30693
30694
30695
30696
30697
30698
30699
30700
30701
30702
30703
30704
30705
30706
30707
30708
30709
30710
30711
30712
30713
30714
30715
30716
30717
30718
30719
30720
30721
30722
30723
30724
30725
30726
30727
30728
30729
30730
30731
30732
30733
30734
30735
30736
30737
30738
30739
30740
30741
30742
30743
30744
30745
30746
30747
30748
30749
30750
30751
30752
30753
30754
30755
30756
30757
30758
30759
30760
30761
30762
30763
30764
30765
30766
30767
30768
30769
30770
30771
30772
30773
30774
30775
30776
30777
30778
30779
30780
30781
30782
30783
30784
30785
30786
30787
30788
30789
30790
30791
30792
30793
30794
30795
30796
30797
30798
30799
30800
30801
30802
30803
30804
30805
30806
30807
30808
30809
30810
30811
30812
30813
30814
30815
30816
30817
30818
30819
30820
30821
30822
30823
30824
30825
30826
30827
30828
30829
30830
30831
30832
30833
30834
30835
30836
30837
30838
30839
30840
30841
30842
30843
30844
30845
30846
30847
30848
30849
30850
30851
30852
30853
30854
30855
30856
30857
30858
30859
30860
30861
30862
30863
30864
30865
30866
30867
30868
30869
30870
30871
30872
30873
30874
30875
30876
30877
30878
30879
30880
30881
30882
30883
30884
30885
30886
30887
30888
30889
30890
30891
30892
30893
30894
30895
30896
30897
30898
30899
30900
30901
30902
30903
30904
30905
30906
30907
30908
30909
30910
30911
30912
30913
30914
30915
30916
30917
30918
30919
30920
30921
30922
30923
30924
30925
30926
30927
30928
30929
30930
30931
30932
30933
30934
30935
30936
30937
30938
30939
30940
30941
30942
30943
30944
30945
30946
30947
30948
30949
30950
30951
30952
30953
30954
30955
30956
30957
30958
30959
30960
30961
30962
30963
30964
30965
30966
30967
30968
30969
30970
30971
30972
30973
30974
30975
30976
30977
30978
30979
30980
30981
30982
30983
30984
30985
30986
30987
30988
30989
30990
30991
30992
30993
30994
30995
30996
30997
30998
30999
31000
31001
31002
31003
31004
31005
31006
31007
31008
31009
31010
31011
31012
31013
31014
31015
31016
31017
31018
31019
31020
31021
31022
31023
31024
31025
31026
31027
31028
31029
31030
31031
31032
31033
31034
31035
31036
31037
31038
31039
31040
31041
31042
31043
31044
31045
31046
31047
31048
31049
31050
31051
31052
31053
31054
31055
31056
31057
31058
31059
31060
31061
31062
31063
31064
31065
31066
31067
31068
31069
31070
31071
31072
31073
31074
31075
31076
31077
31078
31079
31080
31081
31082
31083
31084
31085
31086
31087
31088
31089
31090
31091
31092
31093
31094
31095
31096
31097
31098
31099
31100
31101
31102
31103
31104
31105
31106
31107
31108
31109
31110
31111
31112
31113
31114
31115
31116
31117
31118
31119
31120
31121
31122
31123
31124
31125
31126
31127
31128
31129
31130
31131
31132
31133
31134
31135
31136
31137
31138
31139
31140
31141
31142
31143
31144
31145
31146
31147
31148
31149
31150
31151
31152
31153
31154
31155
31156
31157
31158
31159
31160
31161
31162
31163
31164
31165
31166
31167
31168
31169
31170
31171
31172
31173
31174
31175
31176
31177
31178
31179
31180
31181
31182
31183
31184
31185
31186
31187
31188
31189
31190
31191
31192
31193
31194
31195
31196
31197
31198
31199
31200
31201
31202
31203
31204
31205
31206
31207
31208
31209
31210
31211
31212
31213
31214
31215
31216
31217
31218
31219
31220
31221
31222
31223
31224
31225
31226
31227
31228
31229
31230
31231
31232
31233
31234
31235
31236
31237
31238
31239
31240
31241
31242
31243
31244
31245
31246
31247
31248
31249
31250
31251
31252
31253
31254
31255
31256
31257
31258
31259
31260
31261
31262
31263
31264
31265
31266
31267
31268
31269
31270
31271
31272
31273
31274
31275
31276
31277
31278
31279
31280
31281
31282
31283
31284
31285
31286
31287
31288
31289
31290
31291
31292
31293
31294
31295
31296
31297
31298
31299
31300
31301
31302
31303
31304
31305
31306
31307
31308
31309
31310
31311
31312
31313
31314
31315
31316
31317
31318
31319
31320
31321
31322
31323
31324
31325
31326
31327
31328
31329
31330
31331
31332
31333
31334
31335
31336
31337
31338
31339
31340
31341
31342
31343
31344
31345
31346
31347
31348
31349
31350
31351
31352
31353
31354
31355
31356
31357
31358
31359
31360
31361
31362
31363
31364
31365
31366
31367
31368
31369
31370
31371
31372
31373
31374
31375
31376
31377
31378
31379
31380
31381
31382
31383
31384
31385
31386
31387
31388
31389
31390
31391
31392
31393
31394
31395
31396
31397
31398
31399
31400
31401
31402
31403
31404
31405
31406
31407
31408
31409
31410
31411
31412
31413
31414
31415
31416
31417
31418
31419
31420
31421
31422
31423
31424
31425
31426
31427
31428
31429
31430
31431
31432
31433
31434
31435
31436
31437
31438
31439
31440
31441
31442
31443
31444
31445
31446
31447
31448
31449
31450
31451
31452
31453
31454
31455
31456
31457
31458
31459
31460
31461
31462
31463
31464
31465
31466
31467
31468
31469
31470
31471
31472
31473
31474
31475
31476
31477
31478
31479
31480
31481
31482
31483
31484
31485
31486
31487
31488
31489
31490
31491
31492
31493
31494
31495
31496
31497
31498
31499
31500
31501
31502
31503
31504
31505
31506
31507
31508
31509
31510
31511
31512
31513
31514
31515
31516
31517
31518
31519
31520
31521
31522
31523
31524
31525
31526
31527
31528
31529
31530
31531
31532
31533
31534
31535
31536
31537
31538
31539
31540
31541
31542
31543
31544
31545
31546
31547
31548
31549
31550
31551
31552
31553
31554
31555
31556
31557
31558
31559
31560
31561
31562
31563
31564
31565
31566
31567
31568
31569
31570
31571
31572
31573
31574
31575
31576
31577
31578
31579
31580
31581
31582
31583
31584
31585
31586
31587
31588
31589
31590
31591
31592
31593
31594
31595
31596
31597
31598
31599
31600
31601
31602
31603
31604
31605
31606
31607
31608
31609
31610
31611
31612
31613
31614
31615
31616
31617
31618
31619
31620
31621
31622
31623
31624
31625
31626
31627
31628
31629
31630
31631
31632
31633
31634
31635
31636
31637
31638
31639
31640
31641
31642
31643
31644
31645
31646
31647
31648
31649
31650
31651
31652
31653
31654
31655
31656
31657
31658
31659
31660
31661
31662
31663
31664
31665
31666
31667
31668
31669
31670
31671
31672
31673
31674
31675
31676
31677
31678
31679
31680
31681
31682
31683
31684
31685
31686
31687
31688
31689
31690
31691
31692
31693
31694
31695
31696
31697
31698
31699
31700
31701
31702
31703
31704
31705
31706
31707
31708
31709
31710
31711
31712
31713
31714
31715
31716
31717
31718
31719
31720
31721
31722
31723
31724
31725
31726
31727
31728
31729
31730
31731
31732
31733
31734
31735
31736
31737
31738
31739
31740
31741
31742
31743
31744
31745
31746
31747
31748
31749
31750
31751
31752
31753
31754
31755
31756
31757
31758
31759
31760
31761
31762
31763
31764
31765
31766
31767
31768
31769
31770
31771
31772
31773
31774
31775
31776
31777
31778
31779
31780
31781
31782
31783
31784
31785
31786
31787
31788
31789
31790
31791
31792
31793
31794
31795
31796
31797
31798
31799
31800
31801
31802
31803
31804
31805
31806
31807
31808
31809
31810
31811
31812
31813
31814
31815
31816
31817
31818
31819
31820
31821
31822
31823
31824
31825
31826
31827
31828
31829
31830
31831
31832
31833
31834
31835
31836
31837
31838
31839
31840
31841
31842
31843
31844
31845
31846
31847
31848
31849
31850
31851
31852
31853
31854
31855
31856
31857
31858
31859
31860
31861
31862
31863
31864
31865
31866
31867
31868
31869
31870
31871
31872
31873
31874
31875
31876
31877
31878
31879
31880
31881
31882
31883
31884
31885
31886
31887
31888
31889
31890
31891
31892
31893
31894
31895
31896
31897
31898
31899
31900
31901
31902
31903
31904
31905
31906
31907
31908
31909
31910
31911
31912
31913
31914
31915
31916
31917
31918
31919
31920
31921
31922
31923
31924
31925
31926
31927
31928
31929
31930
31931
31932
31933
31934
31935
31936
31937
31938
31939
31940
31941
31942
31943
31944
31945
31946
31947
31948
31949
31950
31951
31952
31953
31954
31955
31956
31957
31958
31959
31960
31961
31962
31963
31964
31965
31966
31967
31968
31969
31970
31971
31972
31973
31974
31975
31976
31977
31978
31979
31980
31981
31982
31983
31984
31985
31986
31987
31988
31989
31990
31991
31992
31993
31994
31995
31996
31997
31998
31999
32000
32001
32002
32003
32004
32005
32006
32007
32008
32009
32010
32011
32012
32013
32014
32015
32016
32017
32018
32019
32020
32021
32022
32023
32024
32025
32026
32027
32028
32029
32030
32031
32032
32033
32034
32035
32036
32037
32038
32039
32040
32041
32042
32043
32044
32045
32046
32047
32048
32049
32050
32051
32052
32053
32054
32055
32056
32057
32058
32059
32060
32061
32062
32063
32064
32065
32066
32067
32068
32069
32070
32071
32072
32073
32074
32075
32076
32077
32078
32079
32080
32081
32082
32083
32084
32085
32086
32087
32088
32089
32090
32091
32092
32093
32094
32095
32096
32097
32098
32099
32100
32101
32102
32103
32104
32105
32106
32107
32108
32109
32110
32111
32112
32113
32114
32115
32116
32117
32118
32119
32120
32121
32122
32123
32124
32125
32126
32127
32128
32129
32130
32131
32132
32133
32134
32135
32136
32137
32138
32139
32140
32141
32142
32143
32144
32145
32146
32147
32148
32149
32150
32151
32152
32153
32154
32155
32156
32157
32158
32159
32160
32161
32162
32163
32164
32165
32166
32167
32168
32169
32170
32171
32172
32173
32174
32175
32176
32177
32178
32179
32180
32181
32182
32183
32184
32185
32186
32187
32188
32189
32190
32191
32192
32193
32194
32195
32196
32197
32198
32199
32200
32201
32202
32203
32204
32205
32206
32207
32208
32209
32210
32211
32212
32213
32214
32215
32216
32217
32218
32219
32220
32221
32222
32223
32224
32225
32226
32227
32228
32229
32230
32231
32232
32233
32234
32235
32236
32237
32238
32239
32240
32241
32242
32243
32244
32245
32246
32247
32248
32249
32250
32251
32252
32253
32254
32255
32256
32257
32258
32259
32260
32261
32262
32263
32264
32265
32266
32267
32268
32269
32270
32271
32272
32273
32274
32275
32276
32277
32278
32279
32280
32281
32282
32283
32284
32285
32286
32287
32288
32289
32290
32291
32292
32293
32294
32295
32296
32297
32298
32299
32300
32301
32302
32303
32304
32305
32306
32307
32308
32309
32310
32311
32312
32313
32314
32315
32316
32317
32318
32319
32320
32321
32322
32323
32324
32325
32326
32327
32328
32329
32330
32331
32332
32333
32334
32335
32336
32337
32338
32339
32340
32341
32342
32343
32344
32345
32346
32347
32348
32349
32350
32351
32352
32353
32354
32355
32356
32357
32358
32359
32360
32361
32362
32363
32364
32365
32366
32367
32368
32369
32370
32371
32372
32373
32374
32375
32376
32377
32378
32379
32380
32381
32382
32383
32384
32385
32386
32387
32388
32389
32390
32391
32392
32393
32394
32395
32396
32397
32398
32399
32400
32401
32402
32403
32404
32405
32406
32407
32408
32409
32410
32411
32412
32413
32414
32415
32416
32417
32418
32419
32420
32421
32422
32423
32424
32425
32426
32427
32428
32429
32430
32431
32432
32433
32434
32435
32436
32437
32438
32439
32440
32441
32442
32443
32444
32445
32446
32447
32448
32449
32450
32451
32452
32453
32454
32455
32456
32457
32458
32459
32460
32461
32462
32463
32464
32465
32466
32467
32468
32469
32470
32471
32472
32473
32474
32475
32476
32477
32478
32479
32480
32481
32482
32483
32484
32485
32486
32487
32488
32489
32490
32491
32492
32493
32494
32495
32496
32497
32498
32499
32500
32501
32502
32503
32504
32505
32506
32507
32508
32509
32510
32511
32512
32513
32514
32515
32516
32517
32518
32519
32520
32521
32522
32523
32524
32525
32526
32527
32528
32529
32530
32531
32532
32533
32534
32535
32536
32537
32538
32539
32540
32541
32542
32543
32544
32545
32546
32547
32548
32549
32550
32551
32552
32553
32554
32555
32556
32557
32558
32559
32560
32561
32562
32563
32564
32565
32566
32567
32568
32569
32570
32571
32572
32573
32574
32575
32576
32577
32578
32579
32580
32581
32582
32583
32584
32585
32586
32587
32588
32589
32590
32591
32592
32593
32594
32595
32596
32597
32598
32599
32600
32601
32602
32603
32604
32605
32606
32607
32608
32609
32610
32611
32612
32613
32614
32615
32616
32617
32618
32619
32620
32621
32622
32623
32624
32625
32626
32627
32628
32629
32630
32631
32632
32633
32634
32635
32636
32637
32638
32639
32640
32641
32642
32643
32644
32645
32646
32647
32648
32649
32650
32651
32652
32653
32654
32655
32656
32657
32658
32659
32660
32661
32662
32663
32664
32665
32666
32667
32668
32669
32670
32671
32672
32673
32674
32675
32676
32677
32678
32679
32680
32681
32682
32683
32684
32685
32686
32687
32688
32689
32690
32691
32692
32693
32694
32695
32696
32697
32698
32699
32700
32701
32702
32703
32704
32705
32706
32707
32708
32709
32710
32711
32712
32713
32714
32715
32716
32717
32718
32719
32720
32721
32722
32723
32724
32725
32726
32727
32728
32729
32730
32731
32732
32733
32734
32735
32736
32737
32738
32739
32740
32741
32742
32743
32744
32745
32746
32747
32748
32749
32750
32751
32752
32753
32754
32755
32756
32757
32758
32759
32760
32761
32762
32763
32764
32765
32766
32767
32768
32769
32770
32771
32772
32773
32774
32775
32776
32777
32778
32779
32780
32781
32782
32783
32784
32785
32786
32787
32788
32789
32790
32791
32792
32793
32794
32795
32796
32797
32798
32799
32800
32801
32802
32803
32804
32805
32806
32807
32808
32809
32810
32811
32812
32813
32814
32815
32816
32817
32818
32819
32820
32821
32822
32823
32824
32825
32826
32827
32828
32829
32830
32831
32832
32833
32834
32835
32836
32837
32838
32839
32840
32841
32842
32843
32844
32845
32846
32847
32848
32849
32850
32851
32852
32853
32854
32855
32856
32857
32858
32859
32860
32861
32862
32863
32864
32865
32866
32867
32868
32869
32870
32871
32872
32873
32874
32875
32876
32877
32878
32879
32880
32881
32882
32883
32884
32885
32886
32887
32888
32889
32890
32891
32892
32893
32894
32895
32896
32897
32898
32899
32900
32901
32902
32903
32904
32905
32906
32907
32908
32909
32910
32911
32912
32913
32914
32915
32916
32917
32918
32919
32920
32921
32922
32923
32924
32925
32926
32927
32928
32929
32930
32931
32932
32933
32934
32935
32936
32937
32938
32939
32940
32941
32942
32943
32944
32945
32946
32947
32948
32949
32950
32951
32952
32953
32954
32955
32956
32957
32958
32959
32960
32961
32962
32963
32964
32965
32966
32967
32968
32969
32970
32971
32972
32973
32974
32975
32976
32977
32978
32979
32980
32981
32982
32983
32984
32985
32986
32987
32988
32989
32990
32991
32992
32993
32994
32995
32996
32997
32998
32999
33000
33001
33002
33003
33004
33005
33006
33007
33008
33009
33010
33011
33012
33013
33014
33015
33016
33017
33018
33019
33020
33021
33022
33023
33024
33025
33026
33027
33028
33029
33030
33031
33032
33033
33034
33035
33036
33037
33038
33039
33040
33041
33042
33043
33044
33045
33046
33047
33048
33049
33050
33051
33052
33053
33054
33055
33056
33057
33058
33059
33060
33061
33062
33063
33064
33065
33066
33067
33068
33069
33070
33071
33072
33073
33074
33075
33076
33077
33078
33079
33080
33081
33082
33083
33084
33085
33086
33087
33088
33089
33090
33091
33092
33093
33094
33095
33096
33097
33098
33099
33100
33101
33102
33103
33104
33105
33106
33107
33108
33109
33110
33111
33112
33113
33114
33115
33116
33117
33118
33119
33120
33121
33122
33123
33124
33125
33126
33127
33128
33129
33130
33131
33132
33133
33134
33135
33136
33137
33138
33139
33140
33141
33142
33143
33144
33145
33146
33147
33148
33149
33150
33151
33152
33153
33154
33155
33156
33157
33158
33159
33160
33161
33162
33163
33164
33165
33166
33167
33168
33169
33170
33171
33172
33173
33174
33175
33176
33177
33178
33179
33180
33181
33182
33183
33184
33185
33186
33187
33188
33189
33190
33191
33192
33193
33194
33195
33196
33197
33198
33199
33200
33201
33202
33203
33204
33205
33206
33207
33208
33209
33210
33211
33212
33213
33214
33215
33216
33217
33218
33219
33220
33221
33222
33223
33224
33225
33226
33227
33228
33229
33230
33231
33232
33233
33234
33235
33236
33237
33238
33239
33240
33241
33242
33243
33244
33245
33246
33247
33248
33249
33250
33251
33252
33253
33254
33255
33256
33257
33258
33259
33260
33261
33262
33263
33264
33265
33266
33267
33268
33269
33270
33271
33272
33273
33274
33275
33276
33277
33278
33279
33280
33281
33282
33283
33284
33285
33286
33287
33288
33289
33290
33291
33292
33293
33294
33295
33296
33297
33298
33299
33300
33301
33302
33303
33304
33305
33306
33307
33308
33309
33310
33311
33312
33313
33314
33315
33316
33317
33318
33319
33320
33321
33322
33323
33324
33325
33326
33327
33328
33329
33330
33331
33332
33333
33334
33335
33336
33337
33338
33339
33340
33341
33342
33343
33344
33345
33346
33347
33348
33349
33350
33351
33352
33353
33354
33355
33356
33357
33358
33359
33360
33361
33362
33363
33364
33365
33366
33367
33368
33369
33370
33371
33372
33373
33374
33375
33376
33377
33378
33379
33380
33381
33382
33383
33384
33385
33386
33387
33388
33389
33390
33391
33392
33393
33394
33395
33396
33397
33398
33399
33400
33401
33402
33403
33404
33405
33406
33407
33408
33409
33410
33411
33412
33413
33414
33415
33416
33417
33418
33419
33420
33421
33422
33423
33424
33425
33426
33427
33428
33429
33430
33431
33432
33433
33434
33435
33436
33437
33438
33439
33440
33441
33442
33443
33444
33445
33446
33447
33448
33449
33450
33451
33452
33453
33454
33455
33456
33457
33458
33459
33460
33461
33462
33463
33464
33465
33466
33467
33468
33469
33470
33471
33472
33473
33474
33475
33476
33477
33478
33479
33480
33481
33482
33483
33484
33485
33486
33487
33488
33489
33490
33491
33492
33493
33494
33495
33496
33497
33498
33499
33500
33501
33502
33503
33504
33505
33506
33507
33508
33509
33510
33511
33512
33513
33514
33515
33516
33517
33518
33519
33520
33521
33522
33523
33524
33525
33526
33527
33528
33529
33530
33531
33532
33533
33534
33535
33536
33537
33538
33539
33540
33541
33542
33543
33544
33545
33546
33547
33548
33549
33550
33551
33552
33553
33554
33555
33556
33557
33558
33559
33560
33561
33562
33563
33564
33565
33566
33567
33568
33569
33570
33571
33572
33573
33574
33575
33576
33577
33578
33579
33580
33581
33582
33583
33584
33585
33586
33587
33588
33589
33590
33591
33592
33593
33594
33595
33596
33597
33598
33599
33600
33601
33602
33603
33604
33605
33606
33607
33608
33609
33610
33611
33612
33613
33614
33615
33616
33617
33618
33619
33620
33621
33622
33623
33624
33625
33626
33627
33628
33629
33630
33631
33632
33633
33634
33635
33636
33637
33638
33639
33640
33641
33642
33643
33644
33645
33646
33647
33648
33649
33650
33651
33652
33653
33654
33655
33656
33657
33658
33659
33660
33661
33662
33663
33664
33665
33666
33667
33668
33669
33670
33671
33672
33673
33674
33675
33676
33677
33678
33679
33680
33681
33682
33683
33684
33685
33686
33687
33688
33689
33690
33691
33692
33693
33694
33695
33696
33697
33698
33699
33700
33701
33702
33703
33704
33705
33706
33707
33708
33709
33710
33711
33712
33713
33714
33715
33716
33717
33718
33719
33720
33721
33722
33723
33724
33725
33726
33727
33728
33729
33730
33731
33732
33733
33734
33735
33736
33737
33738
33739
33740
33741
33742
33743
33744
33745
33746
33747
33748
33749
33750
33751
33752
33753
33754
33755
33756
33757
33758
33759
33760
33761
33762
33763
33764
33765
33766
33767
33768
33769
33770
33771
33772
33773
33774
33775
33776
33777
33778
33779
33780
33781
33782
33783
33784
33785
33786
33787
33788
33789
33790
33791
33792
33793
33794
33795
33796
33797
33798
33799
33800
33801
33802
33803
33804
33805
33806
33807
33808
33809
33810
33811
33812
33813
33814
33815
33816
33817
33818
33819
33820
33821
33822
33823
33824
33825
33826
33827
33828
33829
33830
33831
33832
33833
33834
33835
33836
33837
33838
33839
33840
33841
33842
33843
33844
33845
33846
33847
33848
33849
33850
33851
33852
33853
33854
33855
33856
33857
33858
33859
33860
33861
33862
33863
33864
33865
33866
33867
33868
33869
33870
33871
33872
33873
33874
33875
33876
33877
33878
33879
33880
33881
33882
33883
33884
33885
33886
33887
33888
33889
33890
33891
33892
33893
33894
33895
33896
33897
33898
33899
33900
33901
33902
33903
33904
33905
33906
33907
33908
33909
33910
33911
33912
33913
33914
33915
33916
33917
33918
33919
33920
33921
33922
33923
33924
33925
33926
33927
33928
33929
33930
33931
33932
33933
33934
33935
33936
33937
33938
33939
33940
33941
33942
33943
33944
33945
33946
33947
33948
33949
33950
33951
33952
33953
33954
33955
33956
33957
33958
33959
33960
33961
33962
33963
33964
33965
33966
33967
33968
33969
33970
33971
33972
33973
33974
33975
33976
33977
33978
33979
33980
33981
33982
33983
33984
33985
33986
33987
33988
33989
33990
33991
33992
33993
33994
33995
33996
33997
33998
33999
34000
34001
34002
34003
34004
34005
34006
34007
34008
34009
34010
34011
34012
34013
34014
34015
34016
34017
34018
34019
34020
34021
34022
34023
34024
34025
34026
34027
34028
34029
34030
34031
34032
34033
34034
34035
34036
34037
34038
34039
34040
34041
34042
34043
34044
34045
34046
34047
34048
34049
34050
34051
34052
34053
34054
34055
34056
34057
34058
34059
34060
34061
34062
34063
34064
34065
34066
34067
34068
34069
34070
34071
34072
34073
34074
34075
34076
34077
34078
34079
34080
34081
34082
34083
34084
34085
34086
34087
34088
34089
34090
34091
34092
34093
34094
34095
34096
34097
34098
34099
34100
34101
34102
34103
34104
34105
34106
34107
34108
34109
34110
34111
34112
34113
34114
34115
34116
34117
34118
34119
34120
34121
34122
34123
34124
34125
34126
34127
34128
34129
34130
34131
34132
34133
34134
34135
34136
34137
34138
34139
34140
34141
34142
34143
34144
34145
34146
34147
34148
34149
34150
34151
34152
34153
34154
34155
34156
34157
34158
34159
34160
34161
34162
34163
34164
34165
34166
34167
34168
34169
34170
34171
34172
34173
34174
34175
34176
34177
34178
34179
34180
34181
34182
34183
34184
34185
34186
34187
34188
34189
34190
34191
34192
34193
34194
34195
34196
34197
34198
34199
34200
34201
34202
34203
34204
34205
34206
34207
34208
34209
34210
34211
34212
34213
34214
34215
34216
34217
34218
34219
34220
34221
34222
34223
34224
34225
34226
34227
34228
34229
34230
34231
34232
34233
34234
34235
34236
34237
34238
34239
34240
34241
34242
34243
34244
34245
34246
34247
34248
34249
34250
34251
34252
34253
34254
34255
34256
34257
34258
34259
34260
34261
34262
34263
34264
34265
34266
34267
34268
34269
34270
34271
34272
34273
34274
34275
34276
34277
34278
34279
34280
34281
34282
34283
34284
34285
34286
34287
34288
34289
34290
34291
34292
34293
34294
34295
34296
34297
34298
34299
34300
34301
34302
34303
34304
34305
34306
34307
34308
34309
34310
34311
34312
34313
34314
34315
34316
34317
34318
34319
34320
34321
34322
34323
34324
34325
34326
34327
34328
34329
34330
34331
34332
34333
34334
34335
34336
34337
34338
34339
34340
34341
34342
34343
34344
34345
34346
34347
34348
34349
34350
34351
34352
34353
34354
34355
34356
34357
34358
34359
34360
34361
34362
34363
34364
34365
34366
34367
34368
34369
34370
34371
34372
34373
34374
34375
34376
34377
34378
34379
34380
34381
34382
34383
34384
34385
34386
34387
34388
34389
34390
34391
34392
34393
34394
34395
34396
34397
34398
34399
34400
34401
34402
34403
34404
34405
34406
34407
34408
34409
34410
34411
34412
34413
34414
34415
34416
34417
34418
34419
34420
34421
34422
34423
34424
34425
34426
34427
34428
34429
34430
34431
34432
34433
34434
34435
34436
34437
34438
34439
34440
34441
34442
34443
34444
34445
34446
34447
34448
34449
34450
34451
34452
34453
34454
34455
34456
34457
34458
34459
34460
34461
34462
34463
34464
34465
34466
34467
34468
34469
34470
34471
34472
34473
34474
34475
34476
34477
34478
34479
34480
34481
34482
34483
34484
34485
34486
34487
34488
34489
34490
34491
34492
34493
34494
34495
34496
34497
34498
34499
34500
34501
34502
34503
34504
34505
34506
34507
34508
34509
34510
34511
34512
34513
34514
34515
34516
34517
34518
34519
34520
34521
34522
34523
34524
34525
34526
34527
34528
34529
34530
34531
34532
34533
34534
34535
34536
34537
34538
34539
34540
34541
34542
34543
34544
34545
34546
34547
34548
34549
34550
34551
34552
34553
34554
34555
34556
34557
34558
34559
34560
34561
34562
34563
34564
34565
34566
34567
34568
34569
34570
34571
34572
34573
34574
34575
34576
34577
34578
34579
34580
34581
34582
34583
34584
34585
34586
34587
34588
34589
34590
34591
34592
34593
34594
34595
34596
34597
34598
34599
34600
34601
34602
34603
34604
34605
34606
34607
34608
34609
34610
34611
34612
34613
34614
34615
34616
34617
34618
34619
34620
34621
34622
34623
34624
34625
34626
34627
34628
34629
34630
34631
34632
34633
34634
34635
34636
34637
34638
34639
34640
34641
34642
34643
34644
34645
34646
34647
34648
34649
34650
34651
34652
34653
34654
34655
34656
34657
34658
34659
34660
34661
34662
34663
34664
34665
34666
34667
34668
34669
34670
34671
34672
34673
34674
34675
34676
34677
34678
34679
34680
34681
34682
34683
34684
34685
34686
34687
34688
34689
34690
34691
34692
34693
34694
34695
34696
34697
34698
34699
34700
34701
34702
34703
34704
34705
34706
34707
34708
34709
34710
34711
34712
34713
34714
34715
34716
34717
34718
34719
34720
34721
34722
34723
34724
34725
34726
34727
34728
34729
34730
34731
34732
34733
34734
34735
34736
34737
34738
34739
34740
34741
34742
34743
34744
34745
34746
34747
34748
34749
34750
34751
34752
34753
34754
34755
34756
34757
34758
34759
34760
34761
34762
34763
34764
34765
34766
34767
34768
34769
34770
34771
34772
34773
34774
34775
34776
34777
34778
34779
34780
34781
34782
34783
34784
34785
34786
34787
34788
34789
34790
34791
34792
34793
34794
34795
34796
34797
34798
34799
34800
34801
34802
34803
34804
34805
34806
34807
34808
34809
34810
34811
34812
34813
34814
34815
34816
34817
34818
34819
34820
34821
34822
34823
34824
34825
34826
34827
34828
34829
34830
34831
34832
34833
34834
34835
34836
34837
34838
34839
34840
34841
34842
34843
34844
34845
34846
34847
34848
34849
34850
34851
34852
34853
34854
34855
34856
34857
34858
34859
34860
34861
34862
34863
34864
34865
34866
34867
34868
34869
34870
34871
34872
34873
34874
34875
34876
34877
34878
34879
34880
34881
34882
34883
34884
34885
34886
34887
34888
34889
34890
34891
34892
34893
34894
34895
34896
34897
34898
34899
34900
34901
34902
34903
34904
34905
34906
34907
34908
34909
34910
34911
34912
34913
34914
34915
34916
34917
34918
34919
34920
34921
34922
34923
34924
34925
34926
34927
34928
34929
34930
34931
34932
34933
34934
34935
34936
34937
34938
34939
34940
34941
34942
34943
34944
34945
34946
34947
34948
34949
34950
34951
34952
34953
34954
34955
34956
34957
34958
34959
34960
34961
34962
34963
34964
34965
34966
34967
34968
34969
34970
34971
34972
34973
34974
34975
34976
34977
34978
34979
34980
34981
34982
34983
34984
34985
34986
34987
34988
34989
34990
34991
34992
34993
34994
34995
34996
34997
34998
34999
35000
35001
35002
35003
35004
35005
35006
35007
35008
35009
35010
35011
35012
35013
35014
35015
35016
35017
35018
35019
35020
35021
35022
35023
35024
35025
35026
35027
35028
35029
35030
35031
35032
35033
35034
35035
35036
35037
35038
35039
35040
35041
35042
35043
35044
35045
35046
35047
35048
35049
35050
35051
35052
35053
35054
35055
35056
35057
35058
35059
35060
35061
35062
35063
35064
35065
35066
35067
35068
35069
35070
35071
35072
35073
35074
35075
35076
35077
35078
35079
35080
35081
35082
35083
35084
35085
35086
35087
35088
35089
35090
35091
35092
35093
35094
35095
35096
35097
35098
35099
35100
35101
35102
35103
35104
35105
35106
35107
35108
35109
35110
35111
35112
35113
35114
35115
35116
35117
35118
35119
35120
35121
35122
35123
35124
35125
35126
35127
35128
35129
35130
35131
35132
35133
35134
35135
35136
35137
35138
35139
35140
35141
35142
35143
35144
35145
35146
35147
35148
35149
35150
35151
35152
35153
35154
35155
35156
35157
35158
35159
35160
35161
35162
35163
35164
35165
35166
35167
35168
35169
35170
35171
35172
35173
35174
35175
35176
35177
35178
35179
35180
35181
35182
35183
35184
35185
35186
35187
35188
35189
35190
35191
35192
35193
35194
35195
35196
35197
35198
35199
35200
35201
35202
35203
35204
35205
35206
35207
35208
35209
35210
35211
35212
35213
35214
35215
35216
35217
35218
35219
35220
35221
35222
35223
35224
35225
35226
35227
35228
35229
35230
35231
35232
35233
35234
35235
35236
35237
35238
35239
35240
35241
35242
35243
35244
35245
35246
35247
35248
35249
35250
35251
35252
35253
35254
35255
35256
35257
35258
35259
35260
35261
35262
35263
35264
35265
35266
35267
35268
35269
35270
35271
35272
35273
35274
35275
35276
35277
35278
35279
35280
35281
35282
35283
35284
35285
35286
35287
35288
35289
35290
35291
35292
35293
35294
35295
35296
35297
35298
35299
35300
35301
35302
35303
35304
35305
35306
35307
35308
35309
35310
35311
35312
35313
35314
35315
35316
35317
35318
35319
35320
35321
35322
35323
35324
35325
35326
35327
35328
35329
35330
35331
35332
35333
35334
35335
35336
35337
35338
35339
35340
35341
35342
35343
35344
35345
35346
35347
35348
35349
35350
35351
35352
35353
35354
35355
35356
35357
35358
35359
35360
35361
35362
35363
35364
35365
35366
35367
35368
35369
35370
35371
35372
35373
35374
35375
35376
35377
35378
35379
35380
35381
35382
35383
35384
35385
35386
35387
35388
35389
35390
35391
35392
35393
35394
35395
35396
35397
35398
35399
35400
35401
35402
35403
35404
35405
35406
35407
35408
35409
35410
35411
35412
35413
35414
35415
35416
35417
35418
35419
35420
35421
35422
35423
35424
35425
35426
35427
35428
35429
35430
35431
35432
35433
35434
35435
35436
35437
35438
35439
35440
35441
35442
35443
35444
35445
35446
35447
35448
35449
35450
35451
35452
35453
35454
35455
35456
35457
35458
35459
35460
35461
35462
35463
35464
35465
35466
35467
35468
35469
35470
35471
35472
35473
35474
35475
35476
35477
35478
35479
35480
35481
35482
35483
35484
35485
35486
35487
35488
35489
35490
35491
35492
35493
35494
35495
35496
35497
35498
35499
35500
35501
35502
35503
35504
35505
35506
35507
35508
35509
35510
35511
35512
35513
35514
35515
35516
35517
35518
35519
35520
35521
35522
35523
35524
35525
35526
35527
35528
35529
35530
35531
35532
35533
35534
35535
35536
35537
35538
35539
35540
35541
35542
35543
35544
35545
35546
35547
35548
35549
35550
35551
35552
35553
35554
35555
35556
35557
35558
35559
35560
35561
35562
35563
35564
35565
35566
35567
35568
35569
35570
35571
35572
35573
35574
35575
35576
35577
35578
35579
35580
35581
35582
35583
35584
35585
35586
35587
35588
35589
35590
35591
35592
35593
35594
35595
35596
35597
35598
35599
35600
35601
35602
35603
35604
35605
35606
35607
35608
35609
35610
35611
35612
35613
35614
35615
35616
35617
35618
35619
35620
35621
35622
35623
35624
35625
35626
35627
35628
35629
35630
35631
35632
35633
35634
35635
35636
35637
35638
35639
35640
35641
35642
35643
35644
35645
35646
35647
35648
35649
35650
35651
35652
35653
35654
35655
35656
35657
35658
35659
35660
35661
35662
35663
35664
35665
35666
35667
35668
35669
35670
35671
35672
35673
35674
35675
35676
35677
35678
35679
35680
35681
35682
35683
35684
35685
35686
35687
35688
35689
35690
35691
35692
35693
35694
35695
35696
35697
35698
35699
35700
35701
35702
35703
35704
35705
35706
35707
35708
35709
35710
35711
35712
35713
35714
35715
35716
35717
35718
35719
35720
35721
35722
35723
35724
35725
35726
35727
35728
35729
35730
35731
35732
35733
35734
35735
35736
35737
35738
35739
35740
35741
35742
35743
35744
35745
35746
35747
35748
35749
35750
35751
35752
35753
35754
35755
35756
35757
35758
35759
35760
35761
35762
35763
35764
35765
35766
35767
35768
35769
35770
35771
35772
35773
35774
35775
35776
35777
35778
35779
35780
35781
35782
35783
35784
35785
35786
35787
35788
35789
35790
35791
35792
35793
35794
35795
35796
35797
35798
35799
35800
35801
35802
35803
35804
35805
35806
35807
35808
35809
35810
35811
35812
35813
35814
35815
35816
35817
35818
35819
35820
35821
35822
35823
35824
35825
35826
35827
35828
35829
35830
35831
35832
35833
35834
35835
35836
35837
35838
35839
35840
35841
35842
35843
35844
35845
35846
35847
35848
35849
35850
35851
35852
35853
35854
35855
35856
35857
35858
35859
35860
35861
35862
35863
35864
35865
35866
35867
35868
35869
35870
35871
35872
35873
35874
35875
35876
35877
35878
35879
35880
35881
35882
35883
35884
35885
35886
35887
35888
35889
35890
35891
35892
35893
35894
35895
35896
35897
35898
35899
35900
35901
35902
35903
35904
35905
35906
35907
35908
35909
35910
35911
35912
35913
35914
35915
35916
35917
35918
35919
35920
35921
35922
35923
35924
35925
35926
35927
35928
35929
35930
35931
35932
35933
35934
35935
35936
35937
35938
35939
35940
35941
35942
35943
35944
35945
35946
35947
35948
35949
35950
35951
35952
35953
35954
35955
35956
35957
35958
35959
35960
35961
35962
35963
35964
35965
35966
35967
35968
35969
35970
35971
35972
35973
35974
35975
35976
35977
35978
35979
35980
35981
35982
35983
35984
35985
35986
35987
35988
35989
35990
35991
35992
35993
35994
35995
35996
35997
35998
35999
36000
36001
36002
36003
36004
36005
36006
36007
36008
36009
36010
36011
36012
36013
36014
36015
36016
36017
36018
36019
36020
36021
36022
36023
36024
36025
36026
36027
36028
36029
36030
36031
36032
36033
36034
36035
36036
36037
36038
36039
36040
36041
36042
36043
36044
36045
36046
36047
36048
36049
36050
36051
36052
36053
36054
36055
36056
36057
36058
36059
36060
36061
36062
36063
36064
36065
36066
36067
36068
36069
36070
36071
36072
36073
36074
36075
36076
36077
36078
36079
36080
36081
36082
36083
36084
36085
36086
36087
36088
36089
36090
36091
36092
36093
36094
36095
36096
36097
36098
36099
36100
36101
36102
36103
36104
36105
36106
36107
36108
36109
36110
36111
36112
36113
36114
36115
36116
36117
36118
36119
36120
36121
36122
36123
36124
36125
36126
36127
36128
36129
36130
36131
36132
36133
36134
36135
36136
36137
36138
36139
36140
36141
36142
36143
36144
36145
36146
36147
36148
36149
36150
36151
36152
36153
36154
36155
36156
36157
36158
36159
36160
36161
36162
36163
36164
36165
36166
36167
36168
36169
36170
36171
36172
36173
36174
36175
36176
36177
36178
36179
36180
36181
36182
36183
36184
36185
36186
36187
36188
36189
36190
36191
36192
36193
36194
36195
36196
36197
36198
36199
36200
36201
36202
36203
36204
36205
36206
36207
36208
36209
36210
36211
36212
36213
36214
36215
36216
36217
36218
36219
36220
36221
36222
36223
36224
36225
36226
36227
36228
36229
36230
36231
36232
36233
36234
36235
36236
36237
36238
36239
36240
36241
36242
36243
36244
36245
36246
36247
36248
36249
36250
36251
36252
36253
36254
36255
36256
36257
36258
36259
36260
36261
36262
36263
36264
36265
36266
36267
36268
36269
36270
36271
36272
36273
36274
36275
36276
36277
36278
36279
36280
36281
36282
36283
36284
36285
36286
36287
36288
36289
36290
36291
36292
36293
36294
36295
36296
36297
36298
36299
36300
36301
36302
36303
36304
36305
36306
36307
36308
36309
36310
36311
36312
36313
36314
36315
36316
36317
36318
36319
36320
36321
36322
36323
36324
36325
36326
36327
36328
36329
36330
36331
36332
36333
36334
36335
36336
36337
36338
36339
36340
36341
36342
36343
36344
36345
36346
36347
36348
36349
36350
36351
36352
36353
36354
36355
36356
36357
36358
36359
36360
36361
36362
36363
36364
36365
36366
36367
36368
36369
36370
36371
36372
36373
36374
36375
36376
36377
36378
36379
36380
36381
36382
36383
36384
36385
36386
36387
36388
36389
36390
36391
36392
36393
36394
36395
36396
36397
36398
36399
36400
36401
36402
36403
36404
36405
36406
36407
36408
36409
36410
36411
36412
36413
36414
36415
36416
36417
36418
36419
36420
36421
36422
36423
36424
36425
36426
36427
36428
36429
36430
36431
36432
36433
36434
36435
36436
36437
36438
36439
36440
36441
36442
36443
36444
36445
36446
36447
36448
36449
36450
36451
36452
36453
36454
36455
36456
36457
36458
36459
36460
36461
36462
36463
36464
36465
36466
36467
36468
36469
36470
36471
36472
36473
36474
36475
36476
36477
36478
36479
36480
36481
36482
36483
36484
36485
36486
36487
36488
36489
36490
36491
36492
36493
36494
36495
36496
36497
36498
36499
36500
36501
36502
36503
36504
36505
36506
36507
36508
36509
36510
36511
36512
36513
36514
36515
36516
36517
36518
36519
36520
36521
36522
36523
36524
36525
36526
36527
36528
36529
36530
36531
36532
36533
36534
36535
36536
36537
36538
36539
36540
36541
36542
36543
36544
36545
36546
36547
36548
36549
36550
36551
36552
36553
36554
36555
36556
36557
36558
36559
36560
36561
36562
36563
36564
36565
36566
36567
36568
36569
36570
36571
36572
36573
36574
36575
36576
36577
36578
36579
36580
36581
36582
36583
36584
36585
36586
36587
36588
36589
36590
36591
36592
36593
36594
36595
36596
36597
36598
36599
36600
36601
36602
36603
36604
36605
36606
36607
36608
36609
36610
36611
36612
36613
36614
36615
36616
36617
36618
36619
36620
36621
36622
36623
36624
36625
36626
36627
36628
36629
36630
36631
36632
36633
36634
36635
36636
36637
36638
36639
36640
36641
36642
36643
36644
36645
36646
36647
36648
36649
36650
36651
36652
36653
36654
36655
36656
36657
36658
36659
36660
36661
36662
36663
36664
36665
36666
36667
36668
36669
36670
36671
36672
36673
36674
36675
36676
36677
36678
36679
36680
36681
36682
36683
36684
36685
36686
36687
36688
36689
36690
36691
36692
36693
36694
36695
36696
36697
36698
36699
36700
36701
36702
36703
36704
36705
36706
36707
36708
36709
36710
36711
36712
36713
36714
36715
36716
36717
36718
36719
36720
36721
36722
36723
36724
36725
36726
36727
36728
36729
36730
36731
36732
36733
36734
36735
36736
36737
36738
36739
36740
36741
36742
36743
36744
36745
36746
36747
36748
36749
36750
36751
36752
36753
36754
36755
36756
36757
36758
36759
36760
36761
36762
36763
36764
36765
36766
36767
36768
36769
36770
36771
36772
36773
36774
36775
36776
36777
36778
36779
36780
36781
36782
36783
36784
36785
36786
36787
36788
36789
36790
36791
36792
36793
36794
36795
36796
36797
36798
36799
36800
36801
36802
36803
36804
36805
36806
36807
36808
36809
36810
36811
36812
36813
36814
36815
36816
36817
36818
36819
36820
36821
36822
36823
36824
36825
36826
36827
36828
36829
36830
36831
36832
36833
36834
36835
36836
36837
36838
36839
36840
36841
36842
36843
36844
36845
36846
36847
36848
36849
36850
36851
36852
36853
36854
36855
36856
36857
36858
36859
36860
36861
36862
36863
36864
36865
36866
36867
36868
36869
36870
36871
36872
36873
36874
36875
36876
36877
36878
36879
36880
36881
36882
36883
36884
36885
36886
36887
36888
36889
36890
36891
36892
36893
36894
36895
36896
36897
36898
36899
36900
36901
36902
36903
36904
36905
36906
36907
36908
36909
36910
36911
36912
36913
36914
36915
36916
36917
36918
36919
36920
36921
36922
36923
36924
36925
36926
36927
36928
36929
36930
36931
36932
36933
36934
36935
36936
36937
36938
36939
36940
36941
36942
36943
36944
36945
36946
36947
36948
36949
36950
36951
36952
36953
36954
36955
36956
36957
36958
36959
36960
36961
36962
36963
36964
36965
36966
36967
36968
36969
36970
36971
36972
36973
36974
36975
36976
36977
36978
36979
36980
36981
36982
36983
36984
36985
36986
36987
36988
36989
36990
36991
36992
36993
36994
36995
36996
36997
36998
36999
37000
37001
37002
37003
37004
37005
37006
37007
37008
37009
37010
37011
37012
37013
37014
37015
37016
37017
37018
37019
37020
37021
37022
37023
37024
37025
37026
37027
37028
37029
37030
37031
37032
37033
37034
37035
37036
37037
37038
37039
37040
37041
37042
37043
37044
37045
37046
37047
37048
37049
37050
37051
37052
37053
37054
37055
37056
37057
37058
37059
37060
37061
37062
37063
37064
37065
37066
37067
37068
37069
37070
37071
37072
37073
37074
37075
37076
37077
37078
37079
37080
37081
37082
37083
37084
37085
37086
37087
37088
37089
37090
37091
37092
37093
37094
37095
37096
37097
37098
37099
37100
37101
37102
37103
37104
37105
37106
37107
37108
37109
37110
37111
37112
37113
37114
37115
37116
37117
37118
37119
37120
37121
37122
37123
37124
37125
37126
37127
37128
37129
37130
37131
37132
37133
37134
37135
37136
37137
37138
37139
37140
37141
37142
37143
37144
37145
37146
37147
37148
37149
37150
37151
37152
37153
37154
37155
37156
37157
37158
37159
37160
37161
37162
37163
37164
37165
37166
37167
37168
37169
37170
37171
37172
37173
37174
37175
37176
37177
37178
37179
37180
37181
37182
37183
37184
37185
37186
37187
37188
37189
37190
37191
37192
37193
37194
37195
37196
37197
37198
37199
37200
37201
37202
37203
37204
37205
37206
37207
37208
37209
37210
37211
37212
37213
37214
37215
37216
37217
37218
37219
37220
37221
37222
37223
37224
37225
37226
37227
37228
37229
37230
37231
37232
37233
37234
37235
37236
37237
37238
37239
37240
37241
37242
37243
37244
37245
37246
37247
37248
37249
37250
37251
37252
37253
37254
37255
37256
37257
37258
37259
37260
37261
37262
37263
37264
37265
37266
37267
37268
37269
37270
37271
37272
37273
37274
37275
37276
37277
37278
37279
37280
37281
37282
37283
37284
37285
37286
37287
37288
37289
37290
37291
37292
37293
37294
37295
37296
37297
37298
37299
37300
37301
37302
37303
37304
37305
37306
37307
37308
37309
37310
37311
37312
37313
37314
37315
37316
37317
37318
37319
37320
37321
37322
37323
37324
37325
37326
37327
37328
37329
37330
37331
37332
37333
37334
37335
37336
37337
37338
37339
37340
37341
37342
37343
37344
37345
37346
37347
37348
37349
37350
37351
37352
37353
37354
37355
37356
37357
37358
37359
37360
37361
37362
37363
37364
37365
37366
37367
37368
37369
37370
37371
37372
37373
37374
37375
37376
37377
37378
37379
37380
37381
37382
37383
37384
37385
37386
37387
37388
37389
37390
37391
37392
37393
37394
37395
37396
37397
37398
37399
37400
37401
37402
37403
37404
37405
37406
37407
37408
37409
37410
37411
37412
37413
37414
37415
37416
37417
37418
37419
37420
37421
37422
37423
37424
37425
37426
37427
37428
37429
37430
37431
37432
37433
37434
37435
37436
37437
37438
37439
37440
37441
37442
37443
37444
37445
37446
37447
37448
37449
37450
37451
37452
37453
37454
37455
37456
37457
37458
37459
37460
37461
37462
37463
37464
37465
37466
37467
37468
37469
37470
37471
37472
37473
37474
37475
37476
37477
37478
37479
37480
37481
37482
37483
37484
37485
37486
37487
37488
37489
37490
37491
37492
37493
37494
37495
37496
37497
37498
37499
37500
37501
37502
37503
37504
37505
37506
37507
37508
37509
37510
37511
37512
37513
37514
37515
37516
37517
37518
37519
37520
37521
37522
37523
37524
37525
37526
37527
37528
37529
37530
37531
37532
37533
37534
37535
37536
37537
37538
37539
37540
37541
37542
37543
37544
37545
37546
37547
37548
37549
37550
37551
37552
37553
37554
37555
37556
37557
37558
37559
37560
37561
37562
37563
37564
37565
37566
37567
37568
37569
37570
37571
37572
37573
37574
37575
37576
37577
37578
37579
37580
37581
37582
37583
37584
37585
37586
37587
37588
37589
37590
37591
37592
37593
37594
37595
37596
37597
37598
37599
37600
37601
37602
37603
37604
37605
37606
37607
37608
37609
37610
37611
37612
37613
37614
37615
37616
37617
37618
37619
37620
37621
37622
37623
37624
37625
37626
37627
37628
37629
37630
37631
37632
37633
37634
37635
37636
37637
37638
37639
37640
37641
37642
37643
37644
37645
37646
37647
37648
37649
37650
37651
37652
37653
37654
37655
37656
37657
37658
37659
37660
37661
37662
37663
37664
37665
37666
37667
37668
37669
37670
37671
37672
37673
37674
37675
37676
37677
37678
37679
37680
37681
37682
37683
37684
37685
37686
37687
37688
37689
37690
37691
37692
37693
37694
37695
37696
37697
37698
37699
37700
37701
37702
37703
37704
37705
37706
37707
37708
37709
37710
37711
37712
37713
37714
37715
37716
37717
37718
37719
37720
37721
37722
37723
37724
37725
37726
37727
37728
37729
37730
37731
37732
37733
37734
37735
37736
37737
37738
37739
37740
37741
37742
37743
37744
37745
37746
37747
37748
37749
37750
37751
37752
37753
37754
37755
37756
37757
37758
37759
37760
37761
37762
37763
37764
37765
37766
37767
37768
37769
37770
37771
37772
37773
37774
37775
37776
37777
37778
37779
37780
37781
37782
37783
37784
37785
37786
37787
37788
37789
37790
37791
37792
37793
37794
37795
37796
37797
37798
37799
37800
37801
37802
37803
37804
37805
37806
37807
37808
37809
37810
37811
37812
37813
37814
37815
37816
37817
37818
37819
37820
37821
37822
37823
37824
37825
37826
37827
37828
37829
37830
37831
37832
37833
37834
37835
37836
37837
37838
37839
37840
37841
37842
37843
37844
37845
37846
37847
37848
37849
37850
37851
37852
37853
37854
37855
37856
37857
37858
37859
37860
37861
37862
37863
37864
37865
37866
37867
37868
37869
37870
37871
37872
37873
37874
37875
37876
37877
37878
37879
37880
37881
37882
37883
37884
37885
37886
37887
37888
37889
37890
37891
37892
37893
37894
37895
37896
37897
37898
37899
37900
37901
37902
37903
37904
37905
37906
37907
37908
37909
37910
37911
37912
37913
37914
37915
37916
37917
37918
37919
37920
37921
37922
37923
37924
37925
37926
37927
37928
37929
37930
37931
37932
37933
37934
37935
37936
37937
37938
37939
37940
37941
37942
37943
37944
37945
37946
37947
37948
37949
37950
37951
37952
37953
37954
37955
37956
37957
37958
37959
37960
37961
37962
37963
37964
37965
37966
37967
37968
37969
37970
37971
37972
37973
37974
37975
37976
37977
37978
37979
37980
37981
37982
37983
37984
37985
37986
37987
37988
37989
37990
37991
37992
37993
37994
37995
37996
37997
37998
37999
38000
38001
38002
38003
38004
38005
38006
38007
38008
38009
38010
38011
38012
38013
38014
38015
38016
38017
38018
38019
38020
38021
38022
38023
38024
38025
38026
38027
38028
38029
38030
38031
38032
38033
38034
38035
38036
38037
38038
38039
38040
38041
38042
38043
38044
38045
38046
38047
38048
38049
38050
38051
38052
38053
38054
38055
38056
38057
38058
38059
38060
38061
38062
38063
38064
38065
38066
38067
38068
38069
38070
38071
38072
38073
38074
38075
38076
38077
38078
38079
38080
38081
38082
38083
38084
38085
38086
38087
38088
38089
38090
38091
38092
38093
38094
38095
38096
38097
38098
38099
38100
38101
38102
38103
38104
38105
38106
38107
38108
38109
38110
38111
38112
38113
38114
38115
38116
38117
38118
38119
38120
38121
38122
38123
38124
38125
38126
38127
38128
38129
38130
38131
38132
38133
38134
38135
38136
38137
38138
38139
38140
38141
38142
38143
38144
38145
38146
38147
38148
38149
38150
38151
38152
38153
38154
38155
38156
38157
38158
38159
38160
38161
38162
38163
38164
38165
38166
38167
38168
38169
38170
38171
38172
38173
38174
38175
38176
38177
38178
38179
38180
38181
38182
38183
38184
38185
38186
38187
38188
38189
38190
38191
38192
38193
38194
38195
38196
38197
38198
38199
38200
38201
38202
38203
38204
38205
38206
38207
38208
38209
38210
38211
38212
38213
38214
38215
38216
38217
38218
38219
38220
38221
38222
38223
38224
38225
38226
38227
38228
38229
38230
38231
38232
38233
38234
38235
38236
38237
38238
38239
38240
38241
38242
38243
38244
38245
38246
38247
38248
38249
38250
38251
38252
38253
38254
38255
38256
38257
38258
38259
38260
38261
38262
38263
38264
38265
38266
38267
38268
38269
38270
38271
38272
38273
38274
38275
38276
38277
38278
38279
38280
38281
38282
38283
38284
38285
38286
38287
38288
38289
38290
38291
38292
38293
38294
38295
38296
38297
38298
38299
38300
38301
38302
38303
38304
38305
38306
38307
38308
38309
38310
38311
38312
38313
38314
38315
38316
38317
38318
38319
38320
38321
38322
38323
38324
38325
38326
38327
38328
38329
38330
38331
38332
38333
38334
38335
38336
38337
38338
38339
38340
38341
38342
38343
38344
38345
38346
38347
38348
38349
38350
38351
38352
38353
38354
38355
38356
38357
38358
38359
38360
38361
38362
38363
38364
38365
38366
38367
38368
38369
38370
38371
38372
38373
38374
38375
38376
38377
38378
38379
38380
38381
38382
38383
38384
38385
38386
38387
38388
38389
38390
38391
38392
38393
38394
38395
38396
38397
38398
38399
38400
38401
38402
38403
38404
38405
38406
38407
38408
38409
38410
38411
38412
38413
38414
38415
38416
38417
38418
38419
38420
38421
38422
38423
38424
38425
38426
38427
38428
38429
38430
38431
38432
38433
38434
38435
38436
38437
38438
38439
38440
38441
38442
38443
38444
38445
38446
38447
38448
38449
38450
38451
38452
38453
38454
38455
38456
38457
38458
38459
38460
38461
38462
38463
38464
38465
38466
38467
38468
38469
38470
38471
38472
38473
38474
38475
38476
38477
38478
38479
38480
38481
38482
38483
38484
38485
38486
38487
38488
38489
38490
38491
38492
38493
38494
38495
38496
38497
38498
38499
38500
38501
38502
38503
38504
38505
38506
38507
38508
38509
38510
38511
38512
38513
38514
38515
38516
38517
38518
38519
38520
38521
38522
38523
38524
38525
38526
38527
38528
38529
38530
38531
38532
38533
38534
38535
38536
38537
38538
38539
38540
38541
38542
38543
38544
38545
38546
38547
38548
38549
38550
38551
38552
38553
38554
38555
38556
38557
38558
38559
38560
38561
38562
38563
38564
38565
38566
38567
38568
38569
38570
38571
38572
38573
38574
38575
38576
38577
38578
38579
38580
38581
38582
38583
38584
38585
38586
38587
38588
38589
38590
38591
38592
38593
38594
38595
38596
38597
38598
38599
38600
38601
38602
38603
38604
38605
38606
38607
38608
38609
38610
38611
38612
38613
38614
38615
38616
38617
38618
38619
38620
38621
38622
38623
38624
38625
38626
38627
38628
38629
38630
38631
38632
38633
38634
38635
38636
38637
38638
38639
38640
38641
38642
38643
38644
38645
38646
38647
38648
38649
38650
38651
38652
38653
38654
38655
38656
38657
38658
38659
38660
38661
38662
38663
38664
38665
38666
38667
38668
38669
38670
38671
38672
38673
38674
38675
38676
38677
38678
38679
38680
38681
38682
38683
38684
38685
38686
38687
38688
38689
38690
38691
38692
38693
38694
38695
38696
38697
38698
38699
38700
38701
38702
38703
38704
38705
38706
38707
38708
38709
38710
38711
38712
38713
38714
38715
38716
38717
38718
38719
38720
38721
38722
38723
38724
38725
38726
38727
38728
38729
38730
38731
38732
38733
38734
38735
38736
38737
38738
38739
38740
38741
38742
38743
38744
38745
38746
38747
38748
38749
38750
38751
38752
38753
38754
38755
38756
38757
38758
38759
38760
38761
38762
38763
38764
38765
38766
38767
38768
38769
38770
38771
38772
38773
38774
38775
38776
38777
38778
38779
38780
38781
38782
38783
38784
38785
38786
38787
38788
38789
38790
38791
38792
38793
38794
38795
38796
38797
38798
38799
38800
38801
38802
38803
38804
38805
38806
38807
38808
38809
38810
38811
38812
38813
38814
38815
38816
38817
38818
38819
38820
38821
38822
38823
38824
38825
38826
38827
38828
38829
38830
38831
38832
38833
38834
38835
38836
38837
38838
38839
38840
38841
38842
38843
38844
38845
38846
38847
38848
38849
38850
38851
38852
38853
38854
38855
38856
38857
38858
38859
38860
38861
38862
38863
38864
38865
38866
38867
38868
38869
38870
38871
38872
38873
38874
38875
38876
38877
38878
38879
38880
38881
38882
38883
38884
38885
38886
38887
38888
38889
38890
38891
38892
38893
38894
38895
38896
38897
38898
38899
38900
38901
38902
38903
38904
38905
38906
38907
38908
38909
38910
38911
38912
38913
38914
38915
38916
38917
38918
38919
38920
38921
38922
38923
38924
38925
38926
38927
38928
38929
38930
38931
38932
38933
38934
38935
38936
38937
38938
38939
38940
38941
38942
38943
38944
38945
38946
38947
38948
38949
38950
38951
38952
38953
38954
38955
38956
38957
38958
38959
38960
38961
38962
38963
38964
38965
38966
38967
38968
38969
38970
38971
38972
38973
38974
38975
38976
38977
38978
38979
38980
38981
38982
38983
38984
38985
38986
38987
38988
38989
38990
38991
38992
38993
38994
38995
38996
38997
38998
38999
39000
39001
39002
39003
39004
39005
39006
39007
39008
39009
39010
39011
39012
39013
39014
39015
39016
39017
39018
39019
39020
39021
39022
39023
39024
39025
39026
39027
39028
39029
39030
39031
39032
39033
39034
39035
39036
39037
39038
39039
39040
39041
39042
39043
39044
39045
39046
39047
39048
39049
39050
39051
39052
39053
39054
39055
39056
39057
39058
39059
39060
39061
39062
39063
39064
39065
39066
39067
39068
39069
39070
39071
39072
39073
39074
39075
39076
39077
39078
39079
39080
39081
39082
39083
39084
39085
39086
39087
39088
39089
39090
39091
39092
39093
39094
39095
39096
39097
39098
39099
39100
39101
39102
39103
39104
39105
39106
39107
39108
39109
39110
39111
39112
39113
39114
39115
39116
39117
39118
39119
39120
39121
39122
39123
39124
39125
39126
39127
39128
39129
39130
39131
39132
39133
39134
39135
39136
39137
39138
39139
39140
39141
39142
39143
39144
39145
39146
39147
39148
39149
39150
39151
39152
39153
39154
39155
39156
39157
39158
39159
39160
39161
39162
39163
39164
39165
39166
39167
39168
39169
39170
39171
39172
39173
39174
39175
39176
39177
39178
39179
39180
39181
39182
39183
39184
39185
39186
39187
39188
39189
39190
39191
39192
39193
39194
39195
39196
39197
39198
39199
39200
39201
39202
39203
39204
39205
39206
39207
39208
39209
39210
39211
39212
39213
39214
39215
39216
39217
39218
39219
39220
39221
39222
39223
39224
39225
39226
39227
39228
39229
39230
39231
39232
39233
39234
39235
39236
39237
39238
39239
39240
39241
39242
39243
39244
39245
39246
39247
39248
39249
39250
39251
39252
39253
39254
39255
39256
39257
39258
39259
39260
39261
39262
39263
39264
39265
39266
39267
39268
39269
39270
39271
39272
39273
39274
39275
39276
39277
39278
39279
39280
39281
39282
39283
39284
39285
39286
39287
39288
39289
39290
39291
39292
39293
39294
39295
39296
39297
39298
39299
39300
39301
39302
39303
39304
39305
39306
39307
39308
39309
39310
39311
39312
39313
39314
39315
39316
39317
39318
39319
39320
39321
39322
39323
39324
39325
39326
39327
39328
39329
39330
39331
39332
39333
39334
39335
39336
39337
39338
39339
39340
39341
39342
39343
39344
39345
39346
39347
39348
39349
39350
39351
39352
39353
39354
39355
39356
39357
39358
39359
39360
39361
39362
39363
39364
39365
39366
39367
39368
39369
39370
39371
39372
39373
39374
39375
39376
39377
39378
39379
39380
39381
39382
39383
39384
39385
39386
39387
39388
39389
39390
39391
39392
39393
39394
39395
39396
39397
39398
39399
39400
39401
39402
39403
39404
39405
39406
39407
39408
39409
39410
39411
39412
39413
39414
39415
39416
39417
39418
39419
39420
39421
39422
39423
39424
39425
39426
39427
39428
39429
39430
39431
39432
39433
39434
39435
39436
39437
39438
39439
39440
39441
39442
39443
39444
39445
39446
39447
39448
39449
39450
39451
39452
39453
39454
39455
39456
39457
39458
39459
39460
39461
39462
39463
39464
39465
39466
39467
39468
39469
39470
39471
39472
39473
39474
39475
39476
39477
39478
39479
39480
39481
39482
39483
39484
39485
39486
39487
39488
39489
39490
39491
39492
39493
39494
39495
39496
39497
39498
39499
39500
39501
39502
39503
39504
39505
39506
39507
39508
39509
39510
39511
39512
39513
39514
39515
39516
39517
39518
39519
39520
39521
39522
39523
39524
39525
39526
39527
39528
39529
39530
39531
39532
39533
39534
39535
39536
39537
39538
39539
39540
39541
39542
39543
39544
39545
39546
39547
39548
39549
39550
39551
39552
39553
39554
39555
39556
39557
39558
39559
39560
39561
39562
39563
39564
39565
39566
39567
39568
39569
39570
39571
39572
39573
39574
39575
39576
39577
39578
39579
39580
39581
39582
39583
39584
39585
39586
39587
39588
39589
39590
39591
39592
39593
39594
39595
39596
39597
39598
39599
39600
39601
39602
39603
39604
39605
39606
39607
39608
39609
39610
39611
39612
39613
39614
39615
39616
39617
39618
39619
39620
39621
39622
39623
39624
39625
39626
39627
39628
39629
39630
39631
39632
39633
39634
39635
39636
39637
39638
39639
39640
39641
39642
39643
39644
39645
39646
39647
39648
39649
39650
39651
39652
39653
39654
39655
39656
39657
39658
39659
39660
39661
39662
39663
39664
39665
39666
39667
39668
39669
39670
39671
39672
39673
39674
39675
39676
39677
39678
39679
39680
39681
39682
39683
39684
39685
39686
39687
39688
39689
39690
39691
39692
39693
39694
39695
39696
39697
39698
39699
39700
39701
39702
39703
39704
39705
39706
39707
39708
39709
39710
39711
39712
39713
39714
39715
39716
39717
39718
39719
39720
39721
39722
39723
39724
39725
39726
39727
39728
39729
39730
39731
39732
39733
39734
39735
39736
39737
39738
39739
39740
39741
39742
39743
39744
39745
39746
39747
39748
39749
39750
39751
39752
39753
39754
39755
39756
39757
39758
39759
39760
39761
39762
39763
39764
39765
39766
39767
39768
39769
39770
39771
39772
39773
39774
39775
39776
39777
39778
39779
39780
39781
39782
39783
39784
39785
39786
39787
39788
39789
39790
39791
39792
39793
39794
39795
39796
39797
39798
39799
39800
39801
39802
39803
39804
39805
39806
39807
39808
39809
39810
39811
39812
39813
39814
39815
39816
39817
39818
39819
39820
39821
39822
39823
39824
39825
39826
39827
39828
39829
39830
39831
39832
39833
39834
39835
39836
39837
39838
39839
39840
39841
39842
39843
39844
39845
39846
39847
39848
39849
39850
39851
39852
39853
39854
39855
39856
39857
39858
39859
39860
39861
39862
39863
39864
39865
39866
39867
39868
39869
39870
39871
39872
39873
39874
39875
39876
39877
39878
39879
39880
39881
39882
39883
39884
39885
39886
39887
39888
39889
39890
39891
39892
39893
39894
39895
39896
39897
39898
39899
39900
39901
39902
39903
39904
39905
39906
39907
39908
39909
39910
39911
39912
39913
39914
39915
39916
39917
39918
39919
39920
39921
39922
39923
39924
39925
39926
39927
39928
39929
39930
39931
39932
39933
39934
39935
39936
39937
39938
39939
39940
39941
39942
39943
39944
39945
39946
39947
39948
39949
39950
39951
39952
39953
39954
39955
39956
39957
39958
39959
39960
39961
39962
39963
39964
39965
39966
39967
39968
39969
39970
39971
39972
39973
39974
39975
39976
39977
39978
39979
39980
39981
39982
39983
39984
39985
39986
39987
39988
39989
39990
39991
39992
39993
39994
39995
39996
39997
39998
39999
40000
40001
40002
40003
40004
40005
40006
40007
40008
40009
40010
40011
40012
40013
40014
40015
40016
40017
40018
40019
40020
40021
40022
40023
40024
40025
40026
40027
40028
40029
40030
40031
40032
40033
40034
40035
40036
40037
40038
40039
40040
40041
40042
40043
40044
40045
40046
40047
40048
40049
40050
40051
40052
40053
40054
40055
40056
40057
40058
40059
40060
40061
40062
40063
40064
40065
40066
40067
40068
40069
40070
40071
40072
40073
40074
40075
40076
40077
40078
40079
40080
40081
40082
40083
40084
40085
40086
40087
40088
40089
40090
40091
40092
40093
40094
40095
40096
40097
40098
40099
40100
40101
40102
40103
40104
40105
40106
40107
40108
40109
40110
40111
40112
40113
40114
40115
40116
40117
40118
40119
40120
40121
40122
40123
40124
40125
40126
40127
40128
40129
40130
40131
40132
40133
40134
40135
40136
40137
40138
40139
40140
40141
40142
40143
40144
40145
40146
40147
40148
40149
40150
40151
40152
40153
40154
40155
40156
40157
40158
40159
40160
40161
40162
40163
40164
40165
40166
40167
40168
40169
40170
40171
40172
40173
40174
40175
40176
40177
40178
40179
40180
40181
40182
40183
40184
40185
40186
40187
40188
40189
40190
40191
40192
40193
40194
40195
40196
40197
40198
40199
40200
40201
40202
40203
40204
40205
40206
40207
40208
40209
40210
40211
40212
40213
40214
40215
40216
40217
40218
40219
40220
40221
40222
40223
40224
40225
40226
40227
40228
40229
40230
40231
40232
40233
40234
40235
40236
40237
40238
40239
40240
40241
40242
40243
40244
40245
40246
40247
40248
40249
40250
40251
40252
40253
40254
40255
40256
40257
40258
40259
40260
40261
40262
40263
40264
40265
40266
40267
40268
40269
40270
40271
40272
40273
40274
40275
40276
40277
40278
40279
40280
40281
40282
40283
40284
40285
40286
40287
40288
40289
40290
40291
40292
40293
40294
40295
40296
40297
40298
40299
40300
40301
40302
40303
40304
40305
40306
40307
40308
40309
40310
40311
40312
40313
40314
40315
40316
40317
40318
40319
40320
40321
40322
40323
40324
40325
40326
40327
40328
40329
40330
40331
40332
40333
40334
40335
40336
40337
40338
40339
40340
40341
40342
40343
40344
40345
40346
40347
40348
40349
40350
40351
40352
40353
40354
40355
40356
40357
40358
40359
40360
40361
40362
40363
40364
40365
40366
40367
40368
40369
40370
40371
40372
40373
40374
40375
40376
40377
40378
40379
40380
40381
40382
40383
40384
40385
40386
40387
40388
40389
40390
40391
40392
40393
40394
40395
40396
40397
40398
40399
40400
40401
40402
40403
40404
40405
40406
40407
40408
40409
40410
40411
40412
40413
40414
40415
40416
40417
40418
40419
40420
40421
40422
40423
40424
40425
40426
40427
40428
40429
40430
40431
40432
40433
40434
40435
40436
40437
40438
40439
40440
40441
40442
40443
40444
40445
40446
40447
40448
40449
40450
40451
40452
40453
40454
40455
40456
40457
40458
40459
40460
40461
40462
40463
40464
40465
40466
40467
40468
40469
40470
40471
40472
40473
40474
40475
40476
40477
40478
40479
40480
40481
40482
40483
40484
40485
40486
40487
40488
40489
40490
40491
40492
40493
40494
40495
40496
40497
40498
40499
40500
40501
40502
40503
40504
40505
40506
40507
40508
40509
40510
40511
40512
40513
40514
40515
40516
40517
40518
40519
40520
40521
40522
40523
40524
40525
40526
40527
40528
40529
40530
40531
40532
40533
40534
40535
40536
40537
40538
40539
40540
40541
40542
40543
40544
40545
40546
40547
40548
40549
40550
40551
40552
40553
40554
40555
40556
40557
40558
40559
40560
40561
40562
40563
40564
40565
40566
40567
40568
40569
40570
40571
40572
40573
40574
40575
40576
40577
40578
40579
40580
40581
40582
40583
40584
40585
40586
40587
40588
40589
40590
40591
40592
40593
40594
40595
40596
40597
40598
40599
40600
40601
40602
40603
40604
40605
40606
40607
40608
40609
40610
40611
40612
40613
40614
40615
40616
40617
40618
40619
40620
40621
40622
40623
40624
40625
40626
40627
40628
40629
40630
40631
40632
40633
40634
40635
40636
40637
40638
40639
40640
40641
40642
40643
40644
40645
40646
40647
40648
40649
40650
40651
40652
40653
40654
40655
40656
40657
40658
40659
40660
40661
40662
40663
40664
40665
40666
40667
40668
40669
40670
40671
40672
40673
40674
40675
40676
40677
40678
40679
40680
40681
40682
40683
40684
40685
40686
40687
40688
40689
40690
40691
40692
40693
40694
40695
40696
40697
40698
40699
40700
40701
40702
40703
40704
40705
40706
40707
40708
40709
40710
40711
40712
40713
40714
40715
40716
40717
40718
40719
40720
40721
40722
40723
40724
40725
40726
40727
40728
40729
40730
40731
40732
40733
40734
40735
40736
40737
40738
40739
40740
40741
40742
40743
40744
40745
40746
40747
40748
40749
40750
40751
40752
40753
40754
40755
40756
40757
40758
40759
40760
40761
40762
40763
40764
40765
40766
40767
40768
40769
40770
40771
40772
40773
40774
40775
40776
40777
40778
40779
40780
40781
40782
40783
40784
40785
40786
40787
40788
40789
40790
40791
40792
40793
40794
40795
40796
40797
40798
40799
40800
40801
40802
40803
40804
40805
40806
40807
40808
40809
40810
40811
40812
40813
40814
40815
40816
40817
40818
40819
40820
40821
40822
40823
40824
40825
40826
40827
40828
40829
40830
40831
40832
40833
40834
40835
40836
40837
40838
40839
40840
40841
40842
40843
40844
40845
40846
40847
40848
40849
40850
40851
40852
40853
40854
40855
40856
40857
40858
40859
40860
40861
40862
40863
40864
40865
40866
40867
40868
40869
40870
40871
40872
40873
40874
40875
40876
40877
40878
40879
40880
40881
40882
40883
40884
40885
40886
40887
40888
40889
40890
40891
40892
40893
40894
40895
40896
40897
40898
40899
40900
40901
40902
40903
40904
40905
40906
40907
40908
40909
40910
40911
40912
40913
40914
40915
40916
40917
40918
40919
40920
40921
40922
40923
40924
40925
40926
40927
40928
40929
40930
40931
40932
40933
40934
40935
40936
40937
40938
40939
40940
40941
40942
40943
40944
40945
40946
40947
40948
40949
40950
40951
40952
40953
40954
40955
40956
40957
40958
40959
40960
40961
40962
40963
40964
40965
40966
40967
40968
40969
40970
40971
40972
40973
40974
40975
40976
40977
40978
40979
40980
40981
40982
40983
40984
40985
40986
40987
40988
40989
40990
40991
40992
40993
40994
40995
40996
40997
40998
40999
41000
41001
41002
41003
41004
41005
41006
41007
41008
41009
41010
41011
41012
41013
41014
41015
41016
41017
41018
41019
41020
41021
41022
41023
41024
41025
41026
41027
41028
41029
41030
41031
41032
41033
41034
41035
41036
41037
41038
41039
41040
41041
41042
41043
41044
41045
41046
41047
41048
41049
41050
41051
41052
41053
41054
41055
41056
41057
41058
41059
41060
41061
41062
41063
41064
41065
41066
41067
41068
41069
41070
41071
41072
41073
41074
41075
41076
41077
41078
41079
41080
41081
41082
41083
41084
41085
41086
41087
41088
41089
41090
41091
41092
41093
41094
41095
41096
41097
41098
41099
41100
41101
41102
41103
41104
41105
41106
41107
41108
41109
41110
41111
41112
41113
41114
41115
41116
41117
41118
41119
41120
41121
41122
41123
41124
41125
41126
41127
41128
41129
41130
41131
41132
41133
41134
41135
41136
41137
41138
41139
41140
41141
41142
41143
41144
41145
41146
41147
41148
41149
41150
41151
41152
41153
41154
41155
41156
41157
41158
41159
41160
41161
41162
41163
41164
41165
41166
41167
41168
41169
41170
41171
41172
41173
41174
41175
41176
41177
41178
41179
41180
41181
41182
41183
41184
41185
41186
41187
41188
41189
41190
41191
41192
41193
41194
41195
41196
41197
41198
41199
41200
41201
41202
41203
41204
41205
41206
41207
41208
41209
41210
41211
41212
41213
41214
41215
41216
41217
41218
41219
41220
41221
41222
41223
41224
41225
41226
41227
41228
41229
41230
41231
41232
41233
41234
41235
41236
41237
41238
41239
41240
41241
41242
41243
41244
41245
41246
41247
41248
41249
41250
41251
41252
41253
41254
41255
41256
41257
41258
41259
41260
41261
41262
41263
41264
41265
41266
41267
41268
41269
41270
41271
41272
41273
41274
41275
41276
41277
41278
41279
41280
41281
41282
41283
41284
41285
41286
41287
41288
41289
41290
41291
41292
41293
41294
41295
41296
41297
41298
41299
41300
41301
41302
41303
41304
41305
41306
41307
41308
41309
41310
41311
41312
41313
41314
41315
41316
41317
41318
41319
41320
41321
41322
41323
41324
41325
41326
41327
41328
41329
41330
41331
41332
41333
41334
41335
41336
41337
41338
41339
41340
41341
41342
41343
41344
41345
41346
41347
41348
41349
41350
41351
41352
41353
41354
41355
41356
41357
41358
41359
41360
41361
41362
41363
41364
41365
41366
41367
41368
41369
41370
41371
41372
41373
41374
41375
41376
41377
41378
41379
41380
41381
41382
41383
41384
41385
41386
41387
41388
41389
41390
41391
41392
41393
41394
41395
41396
41397
41398
41399
41400
41401
41402
41403
41404
41405
41406
41407
41408
41409
41410
41411
41412
41413
41414
41415
41416
41417
41418
41419
41420
41421
41422
41423
41424
41425
41426
41427
41428
41429
41430
41431
41432
41433
41434
41435
41436
41437
41438
41439
41440
41441
41442
41443
41444
41445
41446
41447
41448
41449
41450
41451
41452
41453
41454
41455
41456
41457
41458
41459
41460
41461
41462
41463
41464
41465
41466
41467
41468
41469
41470
41471
41472
41473
41474
41475
41476
41477
41478
41479
41480
41481
41482
41483
41484
41485
41486
41487
41488
41489
41490
41491
41492
41493
41494
41495
41496
41497
41498
41499
41500
41501
41502
41503
41504
41505
41506
41507
41508
41509
41510
41511
41512
41513
41514
41515
41516
41517
41518
41519
41520
41521
41522
41523
41524
41525
41526
41527
41528
41529
41530
41531
41532
41533
41534
41535
41536
41537
41538
41539
41540
41541
41542
41543
41544
41545
41546
41547
41548
41549
41550
41551
41552
41553
41554
41555
41556
41557
41558
41559
41560
41561
41562
41563
41564
41565
41566
41567
41568
41569
41570
41571
41572
41573
41574
41575
41576
41577
41578
41579
41580
41581
41582
41583
41584
41585
41586
41587
41588
41589
41590
41591
41592
41593
41594
41595
41596
41597
41598
41599
41600
41601
41602
41603
41604
41605
41606
41607
41608
41609
41610
41611
41612
41613
41614
41615
41616
41617
41618
41619
41620
41621
41622
41623
41624
41625
41626
41627
41628
41629
41630
41631
41632
41633
41634
41635
41636
41637
41638
41639
41640
41641
41642
41643
41644
41645
41646
41647
41648
41649
41650
41651
41652
41653
41654
41655
41656
41657
41658
41659
41660
41661
41662
41663
41664
41665
41666
41667
41668
41669
41670
41671
41672
41673
41674
41675
41676
41677
41678
41679
41680
41681
41682
41683
41684
41685
41686
41687
41688
41689
41690
41691
41692
41693
41694
41695
41696
41697
41698
41699
41700
41701
41702
41703
41704
41705
41706
41707
41708
41709
41710
41711
41712
41713
41714
41715
41716
41717
41718
41719
41720
41721
41722
41723
41724
41725
41726
41727
41728
41729
41730
41731
41732
41733
41734
41735
41736
41737
41738
41739
41740
41741
41742
41743
41744
41745
41746
41747
41748
41749
41750
41751
41752
41753
41754
41755
41756
41757
41758
41759
41760
41761
41762
41763
41764
41765
41766
41767
41768
41769
41770
41771
41772
41773
41774
41775
41776
41777
41778
41779
41780
41781
41782
41783
41784
41785
41786
41787
41788
41789
41790
41791
41792
41793
41794
41795
41796
41797
41798
41799
41800
41801
41802
41803
41804
41805
41806
41807
41808
41809
41810
41811
41812
41813
41814
41815
41816
41817
41818
41819
41820
41821
41822
41823
41824
41825
41826
41827
41828
41829
41830
41831
41832
41833
41834
41835
41836
41837
41838
41839
41840
41841
41842
41843
41844
41845
41846
41847
41848
41849
41850
41851
41852
41853
41854
41855
41856
41857
41858
41859
41860
41861
41862
41863
41864
41865
41866
41867
41868
41869
41870
41871
41872
41873
41874
41875
41876
41877
41878
41879
41880
41881
41882
41883
41884
41885
41886
41887
41888
41889
41890
41891
41892
41893
41894
41895
41896
41897
41898
41899
41900
41901
41902
41903
41904
41905
41906
41907
41908
41909
41910
41911
41912
41913
41914
41915
41916
41917
41918
41919
41920
41921
41922
41923
41924
41925
41926
41927
41928
41929
41930
41931
41932
41933
41934
41935
41936
41937
41938
41939
41940
41941
41942
41943
41944
41945
41946
41947
41948
41949
41950
41951
41952
41953
41954
41955
41956
41957
41958
41959
41960
41961
41962
41963
41964
41965
41966
41967
41968
41969
41970
41971
41972
41973
41974
41975
41976
41977
41978
41979
41980
41981
41982
41983
41984
41985
41986
41987
41988
41989
41990
41991
41992
41993
41994
41995
41996
41997
41998
41999
42000
42001
42002
42003
42004
42005
42006
42007
42008
42009
42010
42011
42012
42013
42014
42015
42016
42017
42018
42019
42020
42021
42022
42023
42024
42025
42026
42027
42028
42029
42030
42031
42032
42033
42034
42035
42036
42037
42038
42039
42040
42041
42042
42043
42044
42045
42046
42047
42048
42049
42050
42051
42052
42053
42054
42055
42056
42057
42058
42059
42060
42061
42062
42063
42064
42065
42066
42067
42068
42069
42070
42071
42072
42073
42074
42075
42076
42077
42078
42079
42080
42081
42082
42083
42084
42085
42086
42087
42088
42089
42090
42091
42092
42093
42094
42095
42096
42097
42098
42099
42100
42101
42102
42103
42104
42105
42106
42107
42108
42109
42110
42111
42112
42113
42114
42115
42116
42117
42118
42119
42120
42121
42122
42123
42124
42125
42126
42127
42128
42129
42130
42131
42132
42133
42134
42135
42136
42137
42138
42139
42140
42141
42142
42143
42144
42145
42146
42147
42148
42149
42150
42151
42152
42153
42154
42155
42156
42157
42158
42159
42160
42161
42162
42163
42164
42165
42166
42167
42168
42169
42170
42171
42172
42173
42174
42175
42176
42177
42178
42179
42180
42181
42182
42183
42184
42185
42186
42187
42188
42189
42190
42191
42192
42193
42194
42195
42196
42197
42198
42199
42200
42201
42202
42203
42204
42205
42206
42207
42208
42209
42210
42211
42212
42213
42214
42215
42216
42217
42218
42219
42220
42221
42222
42223
42224
42225
42226
42227
42228
42229
42230
42231
42232
42233
42234
42235
42236
42237
42238
42239
42240
42241
42242
42243
42244
42245
42246
42247
42248
42249
42250
42251
42252
42253
42254
42255
42256
42257
42258
42259
42260
42261
42262
42263
42264
42265
42266
42267
42268
42269
42270
42271
42272
42273
42274
42275
42276
42277
42278
42279
42280
42281
42282
42283
42284
42285
42286
42287
42288
42289
42290
42291
42292
42293
42294
42295
42296
42297
42298
42299
42300
42301
42302
42303
42304
42305
42306
42307
42308
42309
42310
42311
42312
42313
42314
42315
42316
42317
42318
42319
42320
42321
42322
42323
42324
42325
42326
42327
42328
42329
42330
42331
42332
42333
42334
42335
42336
42337
42338
42339
42340
42341
42342
42343
42344
42345
42346
42347
42348
42349
42350
42351
42352
42353
42354
42355
42356
42357
42358
42359
42360
42361
42362
42363
42364
42365
42366
42367
42368
42369
42370
42371
42372
42373
42374
42375
42376
42377
42378
42379
42380
42381
42382
42383
42384
42385
42386
42387
42388
42389
42390
42391
42392
42393
42394
42395
42396
42397
42398
42399
42400
42401
42402
42403
42404
42405
42406
42407
42408
42409
42410
42411
42412
42413
42414
42415
42416
42417
42418
42419
42420
42421
42422
42423
42424
42425
42426
42427
42428
42429
42430
42431
42432
42433
42434
42435
42436
42437
42438
42439
42440
42441
42442
42443
42444
42445
42446
42447
42448
42449
42450
42451
42452
42453
42454
42455
42456
42457
42458
42459
42460
42461
42462
42463
42464
42465
42466
42467
42468
42469
42470
42471
42472
42473
42474
42475
42476
42477
42478
42479
42480
42481
42482
42483
42484
42485
42486
42487
42488
42489
42490
42491
42492
42493
42494
42495
42496
42497
42498
42499
42500
42501
42502
42503
42504
42505
42506
42507
42508
42509
42510
42511
42512
42513
42514
42515
42516
42517
42518
42519
42520
42521
42522
42523
42524
42525
42526
42527
42528
42529
42530
42531
42532
42533
42534
42535
42536
42537
42538
42539
42540
42541
42542
42543
42544
42545
42546
42547
42548
42549
42550
42551
42552
42553
42554
42555
42556
42557
42558
42559
42560
42561
42562
42563
42564
42565
42566
42567
42568
42569
42570
42571
42572
42573
42574
42575
42576
42577
42578
42579
42580
42581
42582
42583
42584
42585
42586
42587
42588
42589
42590
42591
42592
42593
42594
42595
42596
42597
42598
42599
42600
42601
42602
42603
42604
42605
42606
42607
42608
42609
42610
42611
42612
42613
42614
42615
42616
42617
42618
42619
42620
42621
42622
42623
42624
42625
42626
42627
42628
42629
42630
42631
42632
42633
42634
42635
42636
42637
42638
42639
42640
42641
42642
42643
42644
42645
42646
42647
42648
42649
42650
42651
42652
42653
42654
42655
42656
42657
42658
42659
42660
42661
42662
42663
42664
42665
42666
42667
42668
42669
42670
42671
42672
42673
42674
42675
42676
42677
42678
42679
42680
42681
42682
42683
42684
42685
42686
42687
42688
42689
42690
42691
42692
42693
42694
42695
42696
42697
42698
42699
42700
42701
42702
42703
42704
42705
42706
42707
42708
42709
42710
42711
42712
42713
42714
42715
42716
42717
42718
42719
42720
42721
42722
42723
42724
42725
42726
42727
42728
42729
42730
42731
42732
42733
42734
42735
42736
42737
42738
42739
42740
42741
42742
42743
42744
42745
42746
42747
42748
42749
42750
42751
42752
42753
42754
42755
42756
42757
42758
42759
42760
42761
42762
42763
42764
42765
42766
42767
42768
42769
42770
42771
42772
42773
42774
42775
42776
42777
42778
42779
42780
42781
42782
42783
42784
42785
42786
42787
42788
42789
42790
42791
42792
42793
42794
42795
42796
42797
42798
42799
42800
42801
42802
42803
42804
42805
42806
42807
42808
42809
42810
42811
42812
42813
42814
42815
42816
42817
42818
42819
42820
42821
42822
42823
42824
42825
42826
42827
42828
42829
42830
42831
42832
42833
42834
42835
42836
42837
42838
42839
42840
42841
42842
42843
42844
42845
42846
42847
42848
42849
42850
42851
42852
42853
42854
42855
42856
42857
42858
42859
42860
42861
42862
42863
42864
42865
42866
42867
42868
42869
42870
42871
42872
42873
42874
42875
42876
42877
42878
42879
42880
42881
42882
42883
42884
42885
42886
42887
42888
42889
42890
42891
42892
42893
42894
42895
42896
42897
42898
42899
42900
42901
42902
42903
42904
42905
42906
42907
42908
42909
42910
42911
42912
42913
42914
42915
42916
42917
42918
42919
42920
42921
42922
42923
42924
42925
42926
42927
42928
42929
42930
42931
42932
42933
42934
42935
42936
42937
42938
42939
42940
42941
42942
42943
42944
42945
42946
42947
42948
42949
42950
42951
42952
42953
42954
42955
42956
42957
42958
42959
42960
42961
42962
42963
42964
42965
42966
42967
42968
42969
42970
42971
42972
42973
42974
42975
42976
42977
42978
42979
42980
42981
42982
42983
42984
42985
42986
42987
42988
42989
42990
42991
42992
42993
42994
42995
42996
42997
42998
42999
43000
43001
43002
43003
43004
43005
43006
43007
43008
43009
43010
43011
43012
43013
43014
43015
43016
43017
43018
43019
43020
43021
43022
43023
43024
43025
43026
43027
43028
43029
43030
43031
43032
43033
43034
43035
43036
43037
43038
43039
43040
43041
43042
43043
43044
43045
43046
43047
43048
43049
43050
43051
43052
43053
43054
43055
43056
43057
43058
43059
43060
43061
43062
43063
43064
43065
43066
43067
43068
43069
43070
43071
43072
43073
43074
43075
43076
43077
43078
43079
43080
43081
43082
43083
43084
43085
43086
43087
43088
43089
43090
43091
43092
43093
43094
43095
43096
43097
43098
43099
43100
43101
43102
43103
43104
43105
43106
43107
43108
43109
43110
43111
43112
43113
43114
43115
43116
43117
43118
43119
43120
43121
43122
43123
43124
43125
43126
43127
43128
43129
43130
43131
43132
43133
43134
43135
43136
43137
43138
43139
43140
43141
43142
43143
43144
43145
43146
43147
43148
43149
43150
43151
43152
43153
43154
43155
43156
43157
43158
43159
43160
43161
43162
43163
43164
43165
43166
43167
43168
43169
43170
43171
43172
43173
43174
43175
43176
43177
43178
43179
43180
43181
43182
43183
43184
43185
43186
43187
43188
43189
43190
43191
43192
43193
43194
43195
43196
43197
43198
43199
43200
43201
43202
43203
43204
43205
43206
43207
43208
43209
43210
43211
43212
43213
43214
43215
43216
43217
43218
43219
43220
43221
43222
43223
43224
43225
43226
43227
43228
43229
43230
43231
43232
43233
43234
43235
43236
43237
43238
43239
43240
43241
43242
43243
43244
43245
43246
43247
43248
43249
43250
43251
43252
43253
43254
43255
43256
43257
43258
43259
43260
43261
43262
43263
43264
43265
43266
43267
43268
43269
43270
43271
43272
43273
43274
43275
43276
43277
43278
43279
43280
43281
43282
43283
43284
43285
43286
43287
43288
43289
43290
43291
43292
43293
43294
43295
43296
43297
43298
43299
43300
43301
43302
43303
43304
43305
43306
43307
43308
43309
43310
43311
43312
43313
43314
43315
43316
43317
43318
43319
43320
43321
43322
43323
43324
43325
43326
43327
43328
43329
43330
43331
43332
43333
43334
43335
43336
43337
43338
43339
43340
43341
43342
43343
43344
43345
43346
43347
43348
43349
43350
43351
43352
43353
43354
43355
43356
43357
43358
43359
43360
43361
43362
43363
43364
43365
43366
43367
43368
43369
43370
43371
43372
43373
43374
43375
43376
43377
43378
43379
43380
43381
43382
43383
43384
43385
43386
43387
43388
43389
43390
43391
43392
43393
43394
43395
43396
43397
43398
43399
43400
43401
43402
43403
43404
43405
43406
43407
43408
43409
43410
43411
43412
43413
43414
43415
43416
43417
43418
43419
43420
43421
43422
43423
43424
43425
43426
43427
43428
43429
43430
43431
43432
43433
43434
43435
43436
43437
43438
43439
43440
43441
43442
43443
43444
43445
43446
43447
43448
43449
43450
43451
43452
43453
43454
43455
43456
43457
43458
43459
43460
43461
43462
43463
43464
43465
43466
43467
43468
43469
43470
43471
43472
43473
43474
43475
43476
43477
43478
43479
43480
43481
43482
43483
43484
43485
43486
43487
43488
43489
43490
43491
43492
43493
43494
43495
43496
43497
43498
43499
43500
43501
43502
43503
43504
43505
43506
43507
43508
43509
43510
43511
43512
43513
43514
43515
43516
43517
43518
43519
43520
43521
43522
43523
43524
43525
43526
43527
43528
43529
43530
43531
43532
43533
43534
43535
43536
43537
43538
43539
43540
43541
43542
43543
43544
43545
43546
43547
43548
43549
43550
43551
43552
43553
43554
43555
43556
43557
43558
43559
43560
43561
43562
43563
43564
43565
43566
43567
43568
43569
43570
43571
43572
43573
43574
43575
43576
43577
43578
43579
43580
43581
43582
43583
43584
43585
43586
43587
43588
43589
43590
43591
43592
43593
43594
43595
43596
43597
43598
43599
43600
43601
43602
43603
43604
43605
43606
43607
43608
43609
43610
43611
43612
43613
43614
43615
43616
43617
43618
43619
43620
43621
43622
43623
43624
43625
43626
43627
43628
43629
43630
43631
43632
43633
43634
43635
43636
43637
43638
43639
43640
43641
43642
43643
43644
43645
43646
43647
43648
43649
43650
43651
43652
43653
43654
43655
43656
43657
43658
43659
43660
43661
43662
43663
43664
43665
43666
43667
43668
43669
43670
43671
43672
43673
43674
43675
43676
43677
43678
43679
43680
43681
43682
43683
43684
43685
43686
43687
43688
43689
43690
43691
43692
43693
43694
43695
43696
43697
43698
43699
43700
43701
43702
43703
43704
43705
43706
43707
43708
43709
43710
43711
43712
43713
43714
43715
43716
43717
43718
43719
43720
43721
43722
43723
43724
43725
43726
43727
43728
43729
43730
43731
43732
43733
43734
43735
43736
43737
43738
43739
43740
43741
43742
43743
43744
43745
43746
43747
43748
43749
43750
43751
43752
43753
43754
43755
43756
43757
43758
43759
43760
43761
43762
43763
43764
43765
43766
43767
43768
43769
43770
43771
43772
43773
43774
43775
43776
43777
43778
43779
43780
43781
43782
43783
43784
43785
43786
43787
43788
43789
43790
43791
43792
43793
43794
43795
43796
43797
43798
43799
43800
43801
43802
43803
43804
43805
43806
43807
43808
43809
43810
43811
43812
43813
43814
43815
43816
43817
43818
43819
43820
43821
43822
43823
43824
43825
43826
43827
43828
43829
43830
43831
43832
43833
43834
43835
43836
43837
43838
43839
43840
43841
43842
43843
43844
43845
43846
43847
43848
43849
43850
43851
43852
43853
43854
43855
43856
43857
43858
43859
43860
43861
43862
43863
43864
43865
43866
43867
43868
43869
43870
43871
43872
43873
43874
43875
43876
43877
43878
43879
43880
43881
43882
43883
43884
43885
43886
43887
43888
43889
43890
43891
43892
43893
43894
43895
43896
43897
43898
43899
43900
43901
43902
43903
43904
43905
43906
43907
43908
43909
43910
43911
43912
43913
43914
43915
43916
43917
43918
43919
43920
43921
43922
43923
43924
43925
43926
43927
43928
43929
43930
43931
43932
43933
43934
43935
43936
43937
43938
43939
43940
43941
43942
43943
43944
43945
43946
43947
43948
43949
43950
43951
43952
43953
43954
43955
43956
43957
43958
43959
43960
43961
43962
43963
43964
43965
43966
43967
43968
43969
43970
43971
43972
43973
43974
43975
43976
43977
43978
43979
43980
43981
43982
43983
43984
43985
43986
43987
43988
43989
43990
43991
43992
43993
43994
43995
43996
43997
43998
43999
44000
44001
44002
44003
44004
44005
44006
44007
44008
44009
44010
44011
44012
44013
44014
44015
44016
44017
44018
44019
44020
44021
44022
44023
44024
44025
44026
44027
44028
44029
44030
44031
44032
44033
44034
44035
44036
44037
44038
44039
44040
44041
44042
44043
44044
44045
44046
44047
44048
44049
44050
44051
44052
44053
44054
44055
44056
44057
44058
44059
44060
44061
44062
44063
44064
44065
44066
44067
44068
44069
44070
44071
44072
44073
44074
44075
44076
44077
44078
44079
44080
44081
44082
44083
44084
44085
44086
44087
44088
44089
44090
44091
44092
44093
44094
44095
44096
44097
44098
44099
44100
44101
44102
44103
44104
44105
44106
44107
44108
44109
44110
44111
44112
44113
44114
44115
44116
44117
44118
44119
44120
44121
44122
44123
44124
44125
44126
44127
44128
44129
44130
44131
44132
44133
44134
44135
44136
44137
44138
44139
44140
44141
44142
44143
44144
44145
44146
44147
44148
44149
44150
44151
44152
44153
44154
44155
44156
44157
44158
44159
44160
44161
44162
44163
44164
44165
44166
44167
44168
44169
44170
44171
44172
44173
44174
44175
44176
44177
44178
44179
44180
44181
44182
44183
44184
44185
44186
44187
44188
44189
44190
44191
44192
44193
44194
44195
44196
44197
44198
44199
44200
44201
44202
44203
44204
44205
44206
44207
44208
44209
44210
44211
44212
44213
44214
44215
44216
44217
44218
44219
44220
44221
44222
44223
44224
44225
44226
44227
44228
44229
44230
44231
44232
44233
44234
44235
44236
44237
44238
44239
44240
44241
44242
44243
44244
44245
44246
44247
44248
44249
44250
44251
44252
44253
44254
44255
44256
44257
44258
44259
44260
44261
44262
44263
44264
44265
44266
44267
44268
44269
44270
44271
44272
44273
44274
44275
44276
44277
44278
44279
44280
44281
44282
44283
44284
44285
44286
44287
44288
44289
44290
44291
44292
44293
44294
44295
44296
44297
44298
44299
44300
44301
44302
44303
44304
44305
44306
44307
44308
44309
44310
44311
44312
44313
44314
44315
44316
44317
44318
44319
44320
44321
44322
44323
44324
44325
44326
44327
44328
44329
44330
44331
44332
44333
44334
44335
44336
44337
44338
44339
44340
44341
44342
44343
44344
44345
44346
44347
44348
44349
44350
44351
44352
44353
44354
44355
44356
44357
44358
44359
44360
44361
44362
44363
44364
44365
44366
44367
44368
44369
44370
44371
44372
44373
44374
44375
44376
44377
44378
44379
44380
44381
44382
44383
44384
44385
44386
44387
44388
44389
44390
44391
44392
44393
44394
44395
44396
44397
44398
44399
44400
44401
44402
44403
44404
44405
44406
44407
44408
44409
44410
44411
44412
44413
44414
44415
44416
44417
44418
44419
44420
44421
44422
44423
44424
44425
44426
44427
44428
44429
44430
44431
44432
44433
44434
44435
44436
44437
44438
44439
44440
44441
44442
44443
44444
44445
44446
44447
44448
44449
44450
44451
44452
44453
44454
44455
44456
44457
44458
44459
44460
44461
44462
44463
44464
44465
44466
44467
44468
44469
44470
44471
44472
44473
44474
44475
44476
44477
44478
44479
44480
44481
44482
44483
44484
44485
44486
44487
44488
44489
44490
44491
44492
44493
44494
44495
44496
44497
44498
44499
44500
44501
44502
44503
44504
44505
44506
44507
44508
44509
44510
44511
44512
44513
44514
44515
44516
44517
44518
44519
44520
44521
44522
44523
44524
44525
44526
44527
44528
44529
44530
44531
44532
44533
44534
44535
44536
44537
44538
44539
44540
44541
44542
44543
44544
44545
44546
44547
44548
44549
44550
44551
44552
44553
44554
44555
44556
44557
44558
44559
44560
44561
44562
44563
44564
44565
44566
44567
44568
44569
44570
44571
44572
44573
44574
44575
44576
44577
44578
44579
44580
44581
44582
44583
44584
44585
44586
44587
44588
44589
44590
44591
44592
44593
44594
44595
44596
44597
44598
44599
44600
44601
44602
44603
44604
44605
44606
44607
44608
44609
44610
44611
44612
44613
44614
44615
44616
44617
44618
44619
44620
44621
44622
44623
44624
44625
44626
44627
44628
44629
44630
44631
44632
44633
44634
44635
44636
44637
44638
44639
44640
44641
44642
44643
44644
44645
44646
44647
44648
44649
44650
44651
44652
44653
44654
44655
44656
44657
44658
44659
44660
44661
44662
44663
44664
44665
44666
44667
44668
44669
44670
44671
44672
44673
44674
44675
44676
44677
44678
44679
44680
44681
44682
44683
44684
44685
44686
44687
44688
44689
44690
44691
44692
44693
44694
44695
44696
44697
44698
44699
44700
44701
44702
44703
44704
44705
44706
44707
44708
44709
44710
44711
44712
44713
44714
44715
44716
44717
44718
44719
44720
44721
44722
44723
44724
44725
44726
44727
44728
44729
44730
44731
44732
44733
44734
44735
44736
44737
44738
44739
44740
44741
44742
44743
44744
44745
44746
44747
44748
44749
44750
44751
44752
44753
44754
44755
44756
44757
44758
44759
44760
44761
44762
44763
44764
44765
44766
44767
44768
44769
44770
44771
44772
44773
44774
44775
44776
44777
44778
44779
44780
44781
44782
44783
44784
44785
44786
44787
44788
44789
44790
44791
44792
44793
44794
44795
44796
44797
44798
44799
44800
44801
44802
44803
44804
44805
44806
44807
44808
44809
44810
44811
44812
44813
44814
44815
44816
44817
44818
44819
44820
44821
44822
44823
44824
44825
44826
44827
44828
44829
44830
44831
44832
44833
44834
44835
44836
44837
44838
44839
44840
44841
44842
44843
44844
44845
44846
44847
44848
44849
44850
44851
44852
44853
44854
44855
44856
44857
44858
44859
44860
44861
44862
44863
44864
44865
44866
44867
44868
44869
44870
44871
44872
44873
44874
44875
44876
44877
44878
44879
44880
44881
44882
44883
44884
44885
44886
44887
44888
44889
44890
44891
44892
44893
44894
44895
44896
44897
44898
44899
44900
44901
44902
44903
44904
44905
44906
44907
44908
44909
44910
44911
44912
44913
44914
44915
44916
44917
44918
44919
44920
44921
44922
44923
44924
44925
44926
44927
44928
44929
44930
44931
44932
44933
44934
44935
44936
44937
44938
44939
44940
44941
44942
44943
44944
44945
44946
44947
44948
44949
44950
44951
44952
44953
44954
44955
44956
44957
44958
44959
44960
44961
44962
44963
44964
44965
44966
44967
44968
44969
44970
44971
44972
44973
44974
44975
44976
44977
44978
44979
44980
44981
44982
44983
44984
44985
44986
44987
44988
44989
44990
44991
44992
44993
44994
44995
44996
44997
44998
44999
45000
45001
45002
45003
45004
45005
45006
45007
45008
45009
45010
45011
45012
45013
45014
45015
45016
45017
45018
45019
45020
45021
45022
45023
45024
45025
45026
45027
45028
45029
45030
45031
45032
45033
45034
45035
45036
45037
45038
45039
45040
45041
45042
45043
45044
45045
45046
45047
45048
45049
45050
45051
45052
45053
45054
45055
45056
45057
45058
45059
45060
45061
45062
45063
45064
45065
45066
45067
45068
45069
45070
45071
45072
45073
45074
45075
45076
45077
45078
45079
45080
45081
45082
45083
45084
45085
45086
45087
45088
45089
45090
45091
45092
45093
45094
45095
45096
45097
45098
45099
45100
45101
45102
45103
45104
45105
45106
45107
45108
45109
45110
45111
45112
45113
45114
45115
45116
45117
45118
45119
45120
45121
45122
45123
45124
45125
45126
45127
45128
45129
45130
45131
45132
45133
45134
45135
45136
45137
45138
45139
45140
45141
45142
45143
45144
45145
45146
45147
45148
45149
45150
45151
45152
45153
45154
45155
45156
45157
45158
45159
45160
45161
45162
45163
45164
45165
45166
45167
45168
45169
45170
45171
45172
45173
45174
45175
45176
45177
45178
45179
45180
45181
45182
45183
45184
45185
45186
45187
45188
45189
45190
45191
45192
45193
45194
45195
45196
45197
45198
45199
45200
45201
45202
45203
45204
45205
45206
45207
45208
45209
45210
45211
45212
45213
45214
45215
45216
45217
45218
45219
45220
45221
45222
45223
45224
45225
45226
45227
45228
45229
45230
45231
45232
45233
45234
45235
45236
45237
45238
45239
45240
45241
45242
45243
45244
45245
45246
45247
45248
45249
45250
45251
45252
45253
45254
45255
45256
45257
45258
45259
45260
45261
45262
45263
45264
45265
45266
45267
45268
45269
45270
45271
45272
45273
45274
45275
45276
45277
45278
45279
45280
45281
45282
45283
45284
45285
45286
45287
45288
45289
45290
45291
45292
45293
45294
45295
45296
45297
45298
45299
45300
45301
45302
45303
45304
45305
45306
45307
45308
45309
45310
45311
45312
45313
45314
45315
45316
45317
45318
45319
45320
45321
45322
45323
45324
45325
45326
45327
45328
45329
45330
45331
45332
45333
45334
45335
45336
45337
45338
45339
45340
45341
45342
45343
45344
45345
45346
45347
45348
45349
45350
45351
45352
45353
45354
45355
45356
45357
45358
45359
45360
45361
45362
45363
45364
45365
45366
45367
45368
45369
45370
45371
45372
45373
45374
45375
45376
45377
45378
45379
45380
45381
45382
45383
45384
45385
45386
45387
45388
45389
45390
45391
45392
45393
45394
45395
45396
45397
45398
45399
45400
45401
45402
45403
45404
45405
45406
45407
45408
45409
45410
45411
45412
45413
45414
45415
45416
45417
45418
45419
45420
45421
45422
45423
45424
45425
45426
45427
45428
45429
45430
45431
45432
45433
45434
45435
45436
45437
45438
45439
45440
45441
45442
45443
45444
45445
45446
45447
45448
45449
45450
45451
45452
45453
45454
45455
45456
45457
45458
45459
45460
45461
45462
45463
45464
45465
45466
45467
45468
45469
45470
45471
45472
45473
45474
45475
45476
45477
45478
45479
45480
45481
45482
45483
45484
45485
45486
45487
45488
45489
45490
45491
45492
45493
45494
45495
45496
45497
45498
45499
45500
45501
45502
45503
45504
45505
45506
45507
45508
45509
45510
45511
45512
45513
45514
45515
45516
45517
45518
45519
45520
45521
45522
45523
45524
45525
45526
45527
45528
45529
45530
45531
45532
45533
45534
45535
45536
45537
45538
45539
45540
45541
45542
45543
45544
45545
45546
45547
45548
45549
45550
45551
45552
45553
45554
45555
45556
45557
45558
45559
45560
45561
45562
45563
45564
45565
45566
45567
45568
45569
45570
45571
45572
45573
45574
45575
45576
45577
45578
45579
45580
45581
45582
45583
45584
45585
45586
45587
45588
45589
45590
45591
45592
45593
45594
45595
45596
45597
45598
45599
45600
45601
45602
45603
45604
45605
45606
45607
45608
45609
45610
45611
45612
45613
45614
45615
45616
45617
45618
45619
45620
45621
45622
45623
45624
45625
45626
45627
45628
45629
45630
45631
45632
45633
45634
45635
45636
45637
45638
45639
45640
45641
45642
45643
45644
45645
45646
45647
45648
45649
45650
45651
45652
45653
45654
45655
45656
45657
45658
45659
45660
45661
45662
45663
45664
45665
45666
45667
45668
45669
45670
45671
45672
45673
45674
45675
45676
45677
45678
45679
45680
45681
45682
45683
45684
45685
45686
45687
45688
45689
45690
45691
45692
45693
45694
45695
45696
45697
45698
45699
45700
45701
45702
45703
45704
45705
45706
45707
45708
45709
45710
45711
45712
45713
45714
45715
45716
45717
45718
45719
45720
45721
45722
45723
45724
45725
45726
45727
45728
45729
45730
45731
45732
45733
45734
45735
45736
45737
45738
45739
45740
45741
45742
45743
45744
45745
45746
45747
45748
45749
45750
45751
45752
45753
45754
45755
45756
45757
45758
45759
45760
45761
45762
45763
45764
45765
45766
45767
45768
45769
45770
45771
45772
45773
45774
45775
45776
45777
45778
45779
45780
45781
45782
45783
45784
45785
45786
45787
45788
45789
45790
45791
45792
45793
45794
45795
45796
45797
45798
45799
45800
45801
45802
45803
45804
45805
45806
45807
45808
45809
45810
45811
45812
45813
45814
45815
45816
45817
45818
45819
45820
45821
45822
45823
45824
45825
45826
45827
45828
45829
45830
45831
45832
45833
45834
45835
45836
45837
45838
45839
45840
45841
45842
45843
45844
45845
45846
45847
45848
45849
45850
45851
45852
45853
45854
45855
45856
45857
45858
45859
45860
45861
45862
45863
45864
45865
45866
45867
45868
45869
45870
45871
45872
45873
45874
45875
45876
45877
45878
45879
45880
45881
45882
45883
45884
45885
45886
45887
45888
45889
45890
45891
45892
45893
45894
45895
45896
45897
45898
45899
45900
45901
45902
45903
45904
45905
45906
45907
45908
45909
45910
45911
45912
45913
45914
45915
45916
45917
45918
45919
45920
45921
45922
45923
45924
45925
45926
45927
45928
45929
45930
45931
45932
45933
45934
45935
45936
45937
45938
45939
45940
45941
45942
45943
45944
45945
45946
45947
45948
45949
45950
45951
45952
45953
45954
45955
45956
45957
45958
45959
45960
45961
45962
45963
45964
45965
45966
45967
45968
45969
45970
45971
45972
45973
45974
45975
45976
45977
45978
45979
45980
45981
45982
45983
45984
45985
45986
45987
45988
45989
45990
45991
45992
45993
45994
45995
45996
45997
45998
45999
46000
46001
46002
46003
46004
46005
46006
46007
46008
46009
46010
46011
46012
46013
46014
46015
46016
46017
46018
46019
46020
46021
46022
46023
46024
46025
46026
46027
46028
46029
46030
46031
46032
46033
46034
46035
46036
46037
46038
46039
46040
46041
46042
46043
46044
46045
46046
46047
46048
46049
46050
46051
46052
46053
46054
46055
46056
46057
46058
46059
46060
46061
46062
46063
46064
46065
46066
46067
46068
46069
46070
46071
46072
46073
46074
46075
46076
46077
46078
46079
46080
46081
46082
46083
46084
46085
46086
46087
46088
46089
46090
46091
46092
46093
46094
46095
46096
46097
46098
46099
46100
46101
46102
46103
46104
46105
46106
46107
46108
46109
46110
46111
46112
46113
46114
46115
46116
46117
46118
46119
46120
46121
46122
46123
46124
46125
46126
46127
46128
46129
46130
46131
46132
46133
46134
46135
46136
46137
46138
46139
46140
46141
46142
46143
46144
46145
46146
46147
46148
46149
46150
46151
46152
46153
46154
46155
46156
46157
46158
46159
46160
46161
46162
46163
46164
46165
46166
46167
46168
46169
46170
46171
46172
46173
46174
46175
46176
46177
46178
46179
46180
46181
46182
46183
46184
46185
46186
46187
46188
46189
46190
46191
46192
46193
46194
46195
46196
46197
46198
46199
46200
46201
46202
46203
46204
46205
46206
46207
46208
46209
46210
46211
46212
46213
46214
46215
46216
46217
46218
46219
46220
46221
46222
46223
46224
46225
46226
46227
46228
46229
46230
46231
46232
46233
46234
46235
46236
46237
46238
46239
46240
46241
46242
46243
46244
46245
46246
46247
46248
46249
46250
46251
46252
46253
46254
46255
46256
46257
46258
46259
46260
46261
46262
46263
46264
46265
46266
46267
46268
46269
46270
46271
46272
46273
46274
46275
46276
46277
46278
46279
46280
46281
46282
46283
46284
46285
46286
46287
46288
46289
46290
46291
46292
46293
46294
46295
46296
46297
46298
46299
46300
46301
46302
46303
46304
46305
46306
46307
46308
46309
46310
46311
46312
46313
46314
46315
46316
46317
46318
46319
46320
46321
46322
46323
46324
46325
46326
46327
46328
46329
46330
46331
46332
46333
46334
46335
46336
46337
46338
46339
46340
46341
46342
46343
46344
46345
46346
46347
46348
46349
46350
46351
46352
46353
46354
46355
46356
46357
46358
46359
46360
46361
46362
46363
46364
46365
46366
46367
46368
46369
46370
46371
46372
46373
46374
46375
46376
46377
46378
46379
46380
46381
46382
46383
46384
46385
46386
46387
46388
46389
46390
46391
46392
46393
46394
46395
46396
46397
46398
46399
46400
46401
46402
46403
46404
46405
46406
46407
46408
46409
46410
46411
46412
46413
46414
46415
46416
46417
46418
46419
46420
46421
46422
46423
46424
46425
46426
46427
46428
46429
46430
46431
46432
46433
46434
46435
46436
46437
46438
46439
46440
46441
46442
46443
46444
46445
46446
46447
46448
46449
46450
46451
46452
46453
46454
46455
46456
46457
46458
46459
46460
46461
46462
46463
46464
46465
46466
46467
46468
46469
46470
46471
46472
46473
46474
46475
46476
46477
46478
46479
46480
46481
46482
46483
46484
46485
46486
46487
46488
46489
46490
46491
46492
46493
46494
46495
46496
46497
46498
46499
46500
46501
46502
46503
46504
46505
46506
46507
46508
46509
46510
46511
46512
46513
46514
46515
46516
46517
46518
46519
46520
46521
46522
46523
46524
46525
46526
46527
46528
46529
46530
46531
46532
46533
46534
46535
46536
46537
46538
46539
46540
46541
46542
46543
46544
46545
46546
46547
46548
46549
46550
46551
46552
46553
46554
46555
46556
46557
46558
46559
46560
46561
46562
46563
46564
46565
46566
46567
46568
46569
46570
46571
46572
46573
46574
46575
46576
46577
46578
46579
46580
46581
46582
46583
46584
46585
46586
46587
46588
46589
46590
46591
46592
46593
46594
46595
46596
46597
46598
46599
46600
46601
46602
46603
46604
46605
46606
46607
46608
46609
46610
46611
46612
46613
46614
46615
46616
46617
46618
46619
46620
46621
46622
46623
46624
46625
46626
46627
46628
46629
46630
46631
46632
46633
46634
46635
46636
46637
46638
46639
46640
46641
46642
46643
46644
46645
46646
46647
46648
46649
46650
46651
46652
46653
46654
46655
46656
46657
46658
46659
46660
46661
46662
46663
46664
46665
46666
46667
46668
46669
46670
46671
46672
46673
46674
46675
46676
46677
46678
46679
46680
46681
46682
46683
46684
46685
46686
46687
46688
46689
46690
46691
46692
46693
46694
46695
46696
46697
46698
46699
46700
46701
46702
46703
46704
46705
46706
46707
46708
46709
46710
46711
46712
46713
46714
46715
46716
46717
46718
46719
46720
46721
46722
46723
46724
46725
46726
46727
46728
46729
46730
46731
46732
46733
46734
46735
46736
46737
46738
46739
46740
46741
46742
46743
46744
46745
46746
46747
46748
46749
46750
46751
46752
46753
46754
46755
46756
46757
46758
46759
46760
46761
46762
46763
46764
46765
46766
46767
46768
46769
46770
46771
46772
46773
46774
46775
46776
46777
46778
46779
46780
46781
46782
46783
46784
46785
46786
46787
46788
46789
46790
46791
46792
46793
46794
46795
46796
46797
46798
46799
46800
46801
46802
46803
46804
46805
46806
46807
46808
46809
46810
46811
46812
46813
46814
46815
46816
46817
46818
46819
46820
46821
46822
46823
46824
46825
46826
46827
46828
46829
46830
46831
46832
46833
46834
46835
46836
46837
46838
46839
46840
46841
46842
46843
46844
46845
46846
46847
46848
46849
46850
46851
46852
46853
46854
46855
46856
46857
46858
46859
46860
46861
46862
46863
46864
46865
46866
46867
46868
46869
46870
46871
46872
46873
46874
46875
46876
46877
46878
46879
46880
46881
46882
46883
46884
46885
46886
46887
46888
46889
46890
46891
46892
46893
46894
46895
46896
46897
46898
46899
46900
46901
46902
46903
46904
46905
46906
46907
46908
46909
46910
46911
46912
46913
46914
46915
46916
46917
46918
46919
46920
46921
46922
46923
46924
46925
46926
46927
46928
46929
46930
46931
46932
46933
46934
46935
46936
46937
46938
46939
46940
46941
46942
46943
46944
46945
46946
46947
46948
46949
46950
46951
46952
46953
46954
46955
46956
46957
46958
46959
46960
46961
46962
46963
46964
46965
46966
46967
46968
46969
46970
46971
46972
46973
46974
46975
46976
46977
46978
46979
46980
46981
46982
46983
46984
46985
46986
46987
46988
46989
46990
46991
46992
46993
46994
46995
46996
46997
46998
46999
47000
47001
47002
47003
47004
47005
47006
47007
47008
47009
47010
47011
47012
47013
47014
47015
47016
47017
47018
47019
47020
47021
47022
47023
47024
47025
47026
47027
47028
47029
47030
47031
47032
47033
47034
47035
47036
47037
47038
47039
47040
47041
47042
47043
47044
47045
47046
47047
47048
47049
47050
47051
47052
47053
47054
47055
47056
47057
47058
47059
47060
47061
47062
47063
47064
47065
47066
47067
47068
47069
47070
47071
47072
47073
47074
47075
47076
47077
47078
47079
47080
47081
47082
47083
47084
47085
47086
47087
47088
47089
47090
47091
47092
47093
47094
47095
47096
47097
47098
47099
47100
47101
47102
47103
47104
47105
47106
47107
47108
47109
47110
47111
47112
47113
47114
47115
47116
47117
47118
47119
47120
47121
47122
47123
47124
47125
47126
47127
47128
47129
47130
47131
47132
47133
47134
47135
47136
47137
47138
47139
47140
47141
47142
47143
47144
47145
47146
47147
47148
47149
47150
47151
47152
47153
47154
47155
47156
47157
47158
47159
47160
47161
47162
47163
47164
47165
47166
47167
47168
47169
47170
47171
47172
47173
47174
47175
47176
47177
47178
47179
47180
47181
47182
47183
47184
47185
47186
47187
47188
47189
47190
47191
47192
47193
47194
47195
47196
47197
47198
47199
47200
47201
47202
47203
47204
47205
47206
47207
47208
47209
47210
47211
47212
47213
47214
47215
47216
47217
47218
47219
47220
47221
47222
47223
47224
47225
47226
47227
47228
47229
47230
47231
47232
47233
47234
47235
47236
47237
47238
47239
47240
47241
47242
47243
47244
47245
47246
47247
47248
47249
47250
47251
47252
47253
47254
47255
47256
47257
47258
47259
47260
47261
47262
47263
47264
47265
47266
47267
47268
47269
47270
47271
47272
47273
47274
47275
47276
47277
47278
47279
47280
47281
47282
47283
47284
47285
47286
47287
47288
47289
47290
47291
47292
47293
47294
47295
47296
47297
47298
47299
47300
47301
47302
47303
47304
47305
47306
47307
47308
47309
47310
47311
47312
47313
47314
47315
47316
47317
47318
47319
47320
47321
47322
47323
47324
47325
47326
47327
47328
47329
47330
47331
47332
47333
47334
47335
47336
47337
47338
47339
47340
47341
47342
47343
47344
47345
47346
47347
47348
47349
47350
47351
47352
47353
47354
47355
47356
47357
47358
47359
47360
47361
47362
47363
47364
47365
47366
47367
47368
47369
47370
47371
47372
47373
47374
47375
47376
47377
47378
47379
47380
47381
47382
47383
47384
47385
47386
47387
47388
47389
47390
47391
47392
47393
47394
47395
47396
47397
47398
47399
47400
47401
47402
47403
47404
47405
47406
47407
47408
47409
47410
47411
47412
47413
47414
47415
47416
47417
47418
47419
47420
47421
47422
47423
47424
47425
47426
47427
47428
47429
47430
47431
47432
47433
47434
47435
47436
47437
47438
47439
47440
47441
47442
47443
47444
47445
47446
47447
47448
47449
47450
47451
47452
47453
47454
47455
47456
47457
47458
47459
47460
47461
47462
47463
47464
47465
47466
47467
47468
47469
47470
47471
47472
47473
47474
47475
47476
47477
47478
47479
47480
47481
47482
47483
47484
47485
47486
47487
47488
47489
47490
47491
47492
47493
47494
47495
47496
47497
47498
47499
47500
47501
47502
47503
47504
47505
47506
47507
47508
47509
47510
47511
47512
47513
47514
47515
47516
47517
47518
47519
47520
47521
47522
47523
47524
47525
47526
47527
47528
47529
47530
47531
47532
47533
47534
47535
47536
47537
47538
47539
47540
47541
47542
47543
47544
47545
47546
47547
47548
47549
47550
47551
47552
47553
47554
47555
47556
47557
47558
47559
47560
47561
47562
47563
47564
47565
47566
47567
47568
47569
47570
47571
47572
47573
47574
47575
47576
47577
47578
47579
47580
47581
47582
47583
47584
47585
47586
47587
47588
47589
47590
47591
47592
47593
47594
47595
47596
47597
47598
47599
47600
47601
47602
47603
47604
47605
47606
47607
47608
47609
47610
47611
47612
47613
47614
47615
47616
47617
47618
47619
47620
47621
47622
47623
47624
47625
47626
47627
47628
47629
47630
47631
47632
47633
47634
47635
47636
47637
47638
47639
47640
47641
47642
47643
47644
47645
47646
47647
47648
47649
47650
47651
47652
47653
47654
47655
47656
47657
47658
47659
47660
47661
47662
47663
47664
47665
47666
47667
47668
47669
47670
47671
47672
47673
47674
47675
47676
47677
47678
47679
47680
47681
47682
47683
47684
47685
47686
47687
47688
47689
47690
47691
47692
47693
47694
47695
47696
47697
47698
47699
47700
47701
47702
47703
47704
47705
47706
47707
47708
47709
47710
47711
47712
47713
47714
47715
47716
47717
47718
47719
47720
47721
47722
47723
47724
47725
47726
47727
47728
47729
47730
47731
47732
47733
47734
47735
47736
47737
47738
47739
47740
47741
47742
47743
47744
47745
47746
47747
47748
47749
47750
47751
47752
47753
47754
47755
47756
47757
47758
47759
47760
47761
47762
47763
47764
47765
47766
47767
47768
47769
47770
47771
47772
47773
47774
47775
47776
47777
47778
47779
47780
47781
47782
47783
47784
47785
47786
47787
47788
47789
47790
47791
47792
47793
47794
47795
47796
47797
47798
47799
47800
47801
47802
47803
47804
47805
47806
47807
47808
47809
47810
47811
47812
47813
47814
47815
47816
47817
47818
47819
47820
47821
47822
47823
47824
47825
47826
47827
47828
47829
47830
47831
47832
47833
47834
47835
47836
47837
47838
47839
47840
47841
47842
47843
47844
47845
47846
47847
47848
47849
47850
47851
47852
47853
47854
47855
47856
47857
47858
47859
47860
47861
47862
47863
47864
47865
47866
47867
47868
47869
47870
47871
47872
47873
47874
47875
47876
47877
47878
47879
47880
47881
47882
47883
47884
47885
47886
47887
47888
47889
47890
47891
47892
47893
47894
47895
47896
47897
47898
47899
47900
47901
47902
47903
47904
47905
47906
47907
47908
47909
47910
47911
47912
47913
47914
47915
47916
47917
47918
47919
47920
47921
47922
47923
47924
47925
47926
47927
47928
47929
47930
47931
47932
47933
47934
47935
47936
47937
47938
47939
47940
47941
47942
47943
47944
47945
47946
47947
47948
47949
47950
47951
47952
47953
47954
47955
47956
47957
47958
47959
47960
47961
47962
47963
47964
47965
47966
47967
47968
47969
47970
47971
47972
47973
47974
47975
47976
47977
47978
47979
47980
47981
47982
47983
47984
47985
47986
47987
47988
47989
47990
47991
47992
47993
47994
47995
47996
47997
47998
47999
48000
48001
48002
48003
48004
48005
48006
48007
48008
48009
48010
48011
48012
48013
48014
48015
48016
48017
48018
48019
48020
48021
48022
48023
48024
48025
48026
48027
48028
48029
48030
48031
48032
48033
48034
48035
48036
48037
48038
48039
48040
48041
48042
48043
48044
48045
48046
48047
48048
48049
48050
48051
48052
48053
48054
48055
48056
48057
48058
48059
48060
48061
48062
48063
48064
48065
48066
48067
48068
48069
48070
48071
48072
48073
48074
48075
48076
48077
48078
48079
48080
48081
48082
48083
48084
48085
48086
48087
48088
48089
48090
48091
48092
48093
48094
48095
48096
48097
48098
48099
48100
48101
48102
48103
48104
48105
48106
48107
48108
48109
48110
48111
48112
48113
48114
48115
48116
48117
48118
48119
48120
48121
48122
48123
48124
48125
48126
48127
48128
48129
48130
48131
48132
48133
48134
48135
48136
48137
48138
48139
48140
48141
48142
48143
48144
48145
48146
48147
48148
48149
48150
48151
48152
48153
48154
48155
48156
48157
48158
48159
48160
48161
48162
48163
48164
48165
48166
48167
48168
48169
48170
48171
48172
48173
48174
48175
48176
48177
48178
48179
48180
48181
48182
48183
48184
48185
48186
48187
48188
48189
48190
48191
48192
48193
48194
48195
48196
48197
48198
48199
48200
48201
48202
48203
48204
48205
48206
48207
48208
48209
48210
48211
48212
48213
48214
48215
48216
48217
48218
48219
48220
48221
48222
48223
48224
48225
48226
48227
48228
48229
48230
48231
48232
48233
48234
48235
48236
48237
48238
48239
48240
48241
48242
48243
48244
48245
48246
48247
48248
48249
48250
48251
48252
48253
48254
48255
48256
48257
48258
48259
48260
48261
48262
48263
48264
48265
48266
48267
48268
48269
48270
48271
48272
48273
48274
48275
48276
48277
48278
48279
48280
48281
48282
48283
48284
48285
48286
48287
48288
48289
48290
48291
48292
48293
48294
48295
48296
48297
48298
48299
48300
48301
48302
48303
48304
48305
48306
48307
48308
48309
48310
48311
48312
48313
48314
48315
48316
48317
48318
48319
48320
48321
48322
48323
48324
48325
48326
48327
48328
48329
48330
48331
48332
48333
48334
48335
48336
48337
48338
48339
48340
48341
48342
48343
48344
48345
48346
48347
48348
48349
48350
48351
48352
48353
48354
48355
48356
48357
48358
48359
48360
48361
48362
48363
48364
48365
48366
48367
48368
48369
48370
48371
48372
48373
48374
48375
48376
48377
48378
48379
48380
48381
48382
48383
48384
48385
48386
48387
48388
48389
48390
48391
48392
48393
48394
48395
48396
48397
48398
48399
48400
48401
48402
48403
48404
48405
48406
48407
48408
48409
48410
48411
48412
48413
48414
48415
48416
48417
48418
48419
48420
48421
48422
48423
48424
48425
48426
48427
48428
48429
48430
48431
48432
48433
48434
48435
48436
48437
48438
48439
48440
48441
48442
48443
48444
48445
48446
48447
48448
48449
48450
48451
48452
48453
48454
48455
48456
48457
48458
48459
48460
48461
48462
48463
48464
48465
48466
48467
48468
48469
48470
48471
48472
48473
48474
48475
48476
48477
48478
48479
48480
48481
48482
48483
48484
48485
48486
48487
48488
48489
48490
48491
48492
48493
48494
48495
48496
48497
48498
48499
48500
48501
48502
48503
48504
48505
48506
48507
48508
48509
48510
48511
48512
48513
48514
48515
48516
48517
48518
48519
48520
48521
48522
48523
48524
48525
48526
48527
48528
48529
48530
48531
48532
48533
48534
48535
48536
48537
48538
48539
48540
48541
48542
48543
48544
48545
48546
48547
48548
48549
48550
48551
48552
48553
48554
48555
48556
48557
48558
48559
48560
48561
48562
48563
48564
48565
48566
48567
48568
48569
48570
48571
48572
48573
48574
48575
48576
48577
48578
48579
48580
48581
48582
48583
48584
48585
48586
48587
48588
48589
48590
48591
48592
48593
48594
48595
48596
48597
48598
48599
48600
48601
48602
48603
48604
48605
48606
48607
48608
48609
48610
48611
48612
48613
48614
48615
48616
48617
48618
48619
48620
48621
48622
48623
48624
48625
48626
48627
48628
48629
48630
48631
48632
48633
48634
48635
48636
48637
48638
48639
48640
48641
48642
48643
48644
48645
48646
48647
48648
48649
48650
48651
48652
48653
48654
48655
48656
48657
48658
48659
48660
48661
48662
48663
48664
48665
48666
48667
48668
48669
48670
48671
48672
48673
48674
48675
48676
48677
48678
48679
48680
48681
48682
48683
48684
48685
48686
48687
48688
48689
48690
48691
48692
48693
48694
48695
48696
48697
48698
48699
48700
48701
48702
48703
48704
48705
48706
48707
48708
48709
48710
48711
48712
48713
48714
48715
48716
48717
48718
48719
48720
48721
48722
48723
48724
48725
48726
48727
48728
48729
48730
48731
48732
48733
48734
48735
48736
48737
48738
48739
48740
48741
48742
48743
48744
48745
48746
48747
48748
48749
48750
48751
48752
48753
48754
48755
48756
48757
48758
48759
48760
48761
48762
48763
48764
48765
48766
48767
48768
48769
48770
48771
48772
48773
48774
48775
48776
48777
48778
48779
48780
48781
48782
48783
48784
48785
48786
48787
48788
48789
48790
48791
48792
48793
48794
48795
48796
48797
48798
48799
48800
48801
48802
48803
48804
48805
48806
48807
48808
48809
48810
48811
48812
48813
48814
48815
48816
48817
48818
48819
48820
48821
48822
48823
48824
48825
48826
48827
48828
48829
48830
48831
48832
48833
48834
48835
48836
48837
48838
48839
48840
48841
48842
48843
48844
48845
48846
48847
48848
48849
48850
48851
48852
48853
48854
48855
48856
48857
48858
48859
48860
48861
48862
48863
48864
48865
48866
48867
48868
48869
48870
48871
48872
48873
48874
48875
48876
48877
48878
48879
48880
48881
48882
48883
48884
48885
48886
48887
48888
48889
48890
48891
48892
48893
48894
48895
48896
48897
48898
48899
48900
48901
48902
48903
48904
48905
48906
48907
48908
48909
48910
48911
48912
48913
48914
48915
48916
48917
48918
48919
48920
48921
48922
48923
48924
48925
48926
48927
48928
48929
48930
48931
48932
48933
48934
48935
48936
48937
48938
48939
48940
48941
48942
48943
48944
48945
48946
48947
48948
48949
48950
48951
48952
48953
48954
48955
48956
48957
48958
48959
48960
48961
48962
48963
48964
48965
48966
48967
48968
48969
48970
48971
48972
48973
48974
48975
48976
48977
48978
48979
48980
48981
48982
48983
48984
48985
48986
48987
48988
48989
48990
48991
48992
48993
48994
48995
48996
48997
48998
48999
49000
49001
49002
49003
49004
49005
49006
49007
49008
49009
49010
49011
49012
49013
49014
49015
49016
49017
49018
49019
49020
49021
49022
49023
49024
49025
49026
49027
49028
49029
49030
49031
49032
49033
49034
49035
49036
49037
49038
49039
49040
49041
49042
49043
49044
49045
49046
49047
49048
49049
49050
49051
49052
49053
49054
49055
49056
49057
49058
49059
49060
49061
49062
49063
49064
49065
49066
49067
49068
49069
49070
49071
49072
49073
49074
49075
49076
49077
49078
49079
49080
49081
49082
49083
49084
49085
49086
49087
49088
49089
49090
49091
49092
49093
49094
49095
49096
49097
49098
49099
49100
49101
49102
49103
49104
49105
49106
49107
49108
49109
49110
49111
49112
49113
49114
49115
49116
49117
49118
49119
49120
49121
49122
49123
49124
49125
49126
49127
49128
49129
49130
49131
49132
49133
49134
49135
49136
49137
49138
49139
49140
49141
49142
49143
49144
49145
49146
49147
49148
49149
49150
49151
49152
49153
49154
49155
49156
49157
49158
49159
49160
49161
49162
49163
49164
49165
49166
49167
49168
49169
49170
49171
49172
49173
49174
49175
49176
49177
49178
49179
49180
49181
49182
49183
49184
49185
49186
49187
49188
49189
49190
49191
49192
49193
49194
49195
49196
49197
49198
49199
49200
49201
49202
49203
49204
49205
49206
49207
49208
49209
49210
49211
49212
49213
49214
49215
49216
49217
49218
49219
49220
49221
49222
49223
49224
49225
49226
49227
49228
49229
49230
49231
49232
49233
49234
49235
49236
49237
49238
49239
49240
49241
49242
49243
49244
49245
49246
49247
49248
49249
49250
49251
49252
49253
49254
49255
49256
49257
49258
49259
49260
49261
49262
49263
49264
49265
49266
49267
49268
49269
49270
49271
49272
49273
49274
49275
49276
49277
49278
49279
49280
49281
49282
49283
49284
49285
49286
49287
49288
49289
49290
49291
49292
49293
49294
49295
49296
49297
49298
49299
49300
49301
49302
49303
49304
49305
49306
49307
49308
49309
49310
49311
49312
49313
49314
49315
49316
49317
49318
49319
49320
49321
49322
49323
49324
49325
49326
49327
49328
49329
49330
49331
49332
49333
49334
49335
49336
49337
49338
49339
49340
49341
49342
49343
49344
49345
49346
49347
49348
49349
49350
49351
49352
49353
49354
49355
49356
49357
49358
49359
49360
49361
49362
49363
49364
49365
49366
49367
49368
49369
49370
49371
49372
49373
49374
49375
49376
49377
49378
49379
49380
49381
49382
49383
49384
49385
49386
49387
49388
49389
49390
49391
49392
49393
49394
49395
49396
49397
49398
49399
49400
49401
49402
49403
49404
49405
49406
49407
49408
49409
49410
49411
49412
49413
49414
49415
49416
49417
49418
49419
49420
49421
49422
49423
49424
49425
49426
49427
49428
49429
49430
49431
49432
49433
49434
49435
49436
49437
49438
49439
49440
49441
49442
49443
49444
49445
49446
49447
49448
49449
49450
49451
49452
49453
49454
49455
49456
49457
49458
49459
49460
49461
49462
49463
49464
49465
49466
49467
49468
49469
49470
49471
49472
49473
49474
49475
49476
49477
49478
49479
49480
49481
49482
49483
49484
49485
49486
49487
49488
49489
49490
49491
49492
49493
49494
49495
49496
49497
49498
49499
49500
49501
49502
49503
49504
49505
49506
49507
49508
49509
49510
49511
49512
49513
49514
49515
49516
49517
49518
49519
49520
49521
49522
49523
49524
49525
49526
49527
49528
49529
49530
49531
49532
49533
49534
49535
49536
49537
49538
49539
49540
49541
49542
49543
49544
49545
49546
49547
49548
49549
49550
49551
49552
49553
49554
49555
49556
49557
49558
49559
49560
49561
49562
49563
49564
49565
49566
49567
49568
49569
49570
49571
49572
49573
49574
49575
49576
49577
49578
49579
49580
49581
49582
49583
49584
49585
49586
49587
49588
49589
49590
49591
49592
49593
49594
49595
49596
49597
49598
49599
49600
49601
49602
49603
49604
49605
49606
49607
49608
49609
49610
49611
49612
49613
49614
49615
49616
49617
49618
49619
49620
49621
49622
49623
49624
49625
49626
49627
49628
49629
49630
49631
49632
49633
49634
49635
49636
49637
49638
49639
49640
49641
49642
49643
49644
49645
49646
49647
49648
49649
49650
49651
49652
49653
49654
49655
49656
49657
49658
49659
49660
49661
49662
49663
49664
49665
49666
49667
49668
49669
49670
49671
49672
49673
49674
49675
49676
49677
49678
49679
49680
49681
49682
49683
49684
49685
49686
49687
49688
49689
49690
49691
49692
49693
49694
49695
49696
49697
49698
49699
49700
49701
49702
49703
49704
49705
49706
49707
49708
49709
49710
49711
49712
49713
49714
49715
49716
49717
49718
49719
49720
49721
49722
49723
49724
49725
49726
49727
49728
49729
49730
49731
49732
49733
49734
49735
49736
49737
49738
49739
49740
49741
49742
49743
49744
49745
49746
49747
49748
49749
49750
49751
49752
49753
49754
49755
49756
49757
49758
49759
49760
49761
49762
49763
49764
49765
49766
49767
49768
49769
49770
49771
49772
49773
49774
49775
49776
49777
49778
49779
49780
49781
49782
49783
49784
49785
49786
49787
49788
49789
49790
49791
49792
49793
49794
49795
49796
49797
49798
49799
49800
49801
49802
49803
49804
49805
49806
49807
49808
49809
49810
49811
49812
49813
49814
49815
49816
49817
49818
49819
49820
49821
49822
49823
49824
49825
49826
49827
49828
49829
49830
49831
49832
49833
49834
49835
49836
49837
49838
49839
49840
49841
49842
49843
49844
49845
49846
49847
49848
49849
49850
49851
49852
49853
49854
49855
49856
49857
49858
49859
49860
49861
49862
49863
49864
49865
49866
49867
49868
49869
49870
49871
49872
49873
49874
49875
49876
49877
49878
49879
49880
49881
49882
49883
49884
49885
49886
49887
49888
49889
49890
49891
49892
49893
49894
49895
49896
49897
49898
49899
49900
49901
49902
49903
49904
49905
49906
49907
49908
49909
49910
49911
49912
49913
49914
49915
49916
49917
49918
49919
49920
49921
49922
49923
49924
49925
49926
49927
49928
49929
49930
49931
49932
49933
49934
49935
49936
49937
49938
49939
49940
49941
49942
49943
49944
49945
49946
49947
49948
49949
49950
49951
49952
49953
49954
49955
49956
49957
49958
49959
49960
49961
49962
49963
49964
49965
49966
49967
49968
49969
49970
49971
49972
49973
49974
49975
49976
49977
49978
49979
49980
49981
49982
49983
49984
49985
49986
49987
49988
49989
49990
49991
49992
49993
49994
49995
49996
49997
49998
49999
50000
50001
50002
50003
50004
50005
50006
50007
50008
50009
50010
50011
50012
50013
50014
50015
50016
50017
50018
50019
50020
50021
50022
50023
50024
50025
50026
50027
50028
50029
50030
50031
50032
50033
50034
50035
50036
50037
50038
50039
50040
50041
50042
50043
50044
50045
50046
50047
50048
50049
50050
50051
50052
50053
50054
50055
50056
50057
50058
50059
50060
50061
50062
50063
50064
50065
50066
50067
50068
50069
50070
50071
50072
50073
50074
50075
50076
50077
50078
50079
50080
50081
50082
50083
50084
50085
50086
50087
50088
50089
50090
50091
50092
50093
50094
50095
50096
50097
50098
50099
50100
50101
50102
50103
50104
50105
50106
50107
50108
50109
50110
50111
50112
50113
50114
50115
50116
50117
50118
50119
50120
50121
50122
50123
50124
50125
50126
50127
50128
50129
50130
50131
50132
50133
50134
50135
50136
50137
50138
50139
50140
50141
50142
50143
50144
50145
50146
50147
50148
50149
50150
50151
50152
50153
50154
50155
50156
50157
50158
50159
50160
50161
50162
50163
50164
50165
50166
50167
50168
50169
50170
50171
50172
50173
50174
50175
50176
50177
50178
50179
50180
50181
50182
50183
50184
50185
50186
50187
50188
50189
50190
50191
50192
50193
50194
50195
50196
50197
50198
50199
50200
50201
50202
50203
50204
50205
50206
50207
50208
50209
50210
50211
50212
50213
50214
50215
50216
50217
50218
50219
50220
50221
50222
50223
50224
50225
50226
50227
50228
50229
50230
50231
50232
50233
50234
50235
50236
50237
50238
50239
50240
50241
50242
50243
50244
50245
50246
50247
50248
50249
50250
50251
50252
50253
50254
50255
50256
50257
50258
50259
50260
50261
50262
50263
50264
50265
50266
50267
50268
50269
50270
50271
50272
50273
50274
50275
50276
50277
50278
50279
50280
50281
50282
50283
50284
50285
50286
50287
50288
50289
50290
50291
50292
50293
50294
50295
50296
50297
50298
50299
50300
50301
50302
50303
50304
50305
50306
50307
50308
50309
50310
50311
50312
50313
50314
50315
50316
50317
50318
50319
50320
50321
50322
50323
50324
50325
50326
50327
50328
50329
50330
50331
50332
50333
50334
50335
50336
50337
50338
50339
50340
50341
50342
50343
50344
50345
50346
50347
50348
50349
50350
50351
50352
50353
50354
50355
50356
50357
50358
50359
50360
50361
50362
50363
50364
50365
50366
50367
50368
50369
50370
50371
50372
50373
50374
50375
50376
50377
50378
50379
50380
50381
50382
50383
50384
50385
50386
50387
50388
50389
50390
50391
50392
50393
50394
50395
50396
50397
50398
50399
50400
50401
50402
50403
50404
50405
50406
50407
50408
50409
50410
50411
50412
50413
50414
50415
50416
50417
50418
50419
50420
50421
50422
50423
50424
50425
50426
50427
50428
50429
50430
50431
50432
50433
50434
50435
50436
50437
50438
50439
50440
50441
50442
50443
50444
50445
50446
50447
50448
50449
50450
50451
50452
50453
50454
50455
50456
50457
50458
50459
50460
50461
50462
50463
50464
50465
50466
50467
50468
50469
50470
50471
50472
50473
50474
50475
50476
50477
50478
50479
50480
50481
50482
50483
50484
50485
50486
50487
50488
50489
50490
50491
50492
50493
50494
50495
50496
50497
50498
50499
50500
50501
50502
50503
50504
50505
50506
50507
50508
50509
50510
50511
50512
50513
50514
50515
50516
50517
50518
50519
50520
50521
50522
50523
50524
50525
50526
50527
50528
50529
50530
50531
50532
50533
50534
50535
50536
50537
50538
50539
50540
50541
50542
50543
50544
50545
50546
50547
50548
50549
50550
50551
50552
50553
50554
50555
50556
50557
50558
50559
50560
50561
50562
50563
50564
50565
50566
50567
50568
50569
50570
50571
50572
50573
50574
50575
50576
50577
50578
50579
50580
50581
50582
50583
50584
50585
50586
50587
50588
50589
50590
50591
50592
50593
50594
50595
50596
50597
50598
50599
50600
50601
50602
50603
50604
50605
50606
50607
50608
50609
50610
50611
50612
50613
50614
50615
50616
50617
50618
50619
50620
50621
50622
50623
50624
50625
50626
50627
50628
50629
50630
50631
50632
50633
50634
50635
50636
50637
50638
50639
50640
50641
50642
50643
50644
50645
50646
50647
50648
50649
50650
50651
50652
50653
50654
50655
50656
50657
50658
50659
50660
50661
50662
50663
50664
50665
50666
50667
50668
50669
50670
50671
50672
50673
50674
50675
50676
50677
50678
50679
50680
50681
50682
50683
50684
50685
50686
50687
50688
50689
50690
50691
50692
50693
50694
50695
50696
50697
50698
50699
50700
50701
50702
50703
50704
50705
50706
50707
50708
50709
50710
50711
50712
50713
50714
50715
50716
50717
50718
50719
50720
50721
50722
50723
50724
50725
50726
50727
50728
50729
50730
50731
50732
50733
50734
50735
50736
50737
50738
50739
50740
50741
50742
50743
50744
50745
50746
50747
50748
50749
50750
50751
50752
50753
50754
50755
50756
50757
50758
50759
50760
50761
50762
50763
50764
50765
50766
50767
50768
50769
50770
50771
50772
50773
50774
50775
50776
50777
50778
50779
50780
50781
50782
50783
50784
50785
50786
50787
50788
50789
50790
50791
50792
50793
50794
50795
50796
50797
50798
50799
50800
50801
50802
50803
50804
50805
50806
50807
50808
50809
50810
50811
50812
50813
50814
50815
50816
50817
50818
50819
50820
50821
50822
50823
50824
50825
50826
50827
50828
50829
50830
50831
50832
50833
50834
50835
50836
50837
50838
50839
50840
50841
50842
50843
50844
50845
50846
50847
50848
50849
50850
50851
50852
50853
50854
50855
50856
50857
50858
50859
50860
50861
50862
50863
50864
50865
50866
50867
50868
50869
50870
50871
50872
50873
50874
50875
50876
50877
50878
50879
50880
50881
50882
50883
50884
50885
50886
50887
50888
50889
50890
50891
50892
50893
50894
50895
50896
50897
50898
50899
50900
50901
50902
50903
50904
50905
50906
50907
50908
50909
50910
50911
50912
50913
50914
50915
50916
50917
50918
50919
50920
50921
50922
50923
50924
50925
50926
50927
50928
50929
50930
50931
50932
50933
50934
50935
50936
50937
50938
50939
50940
50941
50942
50943
50944
50945
50946
50947
50948
50949
50950
50951
50952
50953
50954
50955
50956
50957
50958
50959
50960
50961
50962
50963
50964
50965
50966
50967
50968
50969
50970
50971
50972
50973
50974
50975
50976
50977
50978
50979
50980
50981
50982
50983
50984
50985
50986
50987
50988
50989
50990
50991
50992
50993
50994
50995
50996
50997
50998
50999
51000
51001
51002
51003
51004
51005
51006
51007
51008
51009
51010
51011
51012
51013
51014
51015
51016
51017
51018
51019
51020
51021
51022
51023
51024
51025
51026
51027
51028
51029
51030
51031
51032
51033
51034
51035
51036
51037
51038
51039
51040
51041
51042
51043
51044
51045
51046
51047
51048
51049
51050
51051
51052
51053
51054
51055
51056
51057
51058
51059
51060
51061
51062
51063
51064
51065
51066
51067
51068
51069
51070
51071
51072
51073
51074
51075
51076
51077
51078
51079
51080
51081
51082
51083
51084
51085
51086
51087
51088
51089
51090
51091
51092
51093
51094
51095
51096
51097
51098
51099
51100
51101
51102
51103
51104
51105
51106
51107
51108
51109
51110
51111
51112
51113
51114
51115
51116
51117
51118
51119
51120
51121
51122
51123
51124
51125
51126
51127
51128
51129
51130
51131
51132
51133
51134
51135
51136
51137
51138
51139
51140
51141
51142
51143
51144
51145
51146
51147
51148
51149
51150
51151
51152
51153
51154
51155
51156
51157
51158
51159
51160
51161
51162
51163
51164
51165
51166
51167
51168
51169
51170
51171
51172
51173
51174
51175
51176
51177
51178
51179
51180
51181
51182
51183
51184
51185
51186
51187
51188
51189
51190
51191
51192
51193
51194
51195
51196
51197
51198
51199
51200
51201
51202
51203
51204
51205
51206
51207
51208
51209
51210
51211
51212
51213
51214
51215
51216
51217
51218
51219
51220
51221
51222
51223
51224
51225
51226
51227
51228
51229
51230
51231
51232
51233
51234
51235
51236
51237
51238
51239
51240
51241
51242
51243
51244
51245
51246
51247
51248
51249
51250
51251
51252
51253
51254
51255
51256
51257
51258
51259
51260
51261
51262
51263
51264
51265
51266
51267
51268
51269
51270
51271
51272
51273
51274
51275
51276
51277
51278
51279
51280
51281
51282
51283
51284
51285
51286
51287
51288
51289
51290
51291
51292
51293
51294
51295
51296
51297
51298
51299
51300
51301
51302
51303
51304
51305
51306
51307
51308
51309
51310
51311
51312
51313
51314
51315
51316
51317
51318
51319
51320
51321
51322
51323
51324
51325
51326
51327
51328
51329
51330
51331
51332
51333
51334
51335
51336
51337
51338
51339
51340
51341
51342
51343
51344
51345
51346
51347
51348
51349
51350
51351
51352
51353
51354
51355
51356
51357
51358
51359
51360
51361
51362
51363
51364
51365
51366
51367
51368
51369
51370
51371
51372
51373
51374
51375
51376
51377
51378
51379
51380
51381
51382
51383
51384
51385
51386
51387
51388
51389
51390
51391
51392
51393
51394
51395
51396
51397
51398
51399
51400
51401
51402
51403
51404
51405
51406
51407
51408
51409
51410
51411
51412
51413
51414
51415
51416
51417
51418
51419
51420
51421
51422
51423
51424
51425
51426
51427
51428
51429
51430
51431
51432
51433
51434
51435
51436
51437
51438
51439
51440
51441
51442
51443
51444
51445
51446
51447
51448
51449
51450
51451
51452
51453
51454
51455
51456
51457
51458
51459
51460
51461
51462
51463
51464
51465
51466
51467
51468
51469
51470
51471
51472
51473
51474
51475
51476
51477
51478
51479
51480
51481
51482
51483
51484
51485
51486
51487
51488
51489
51490
51491
51492
51493
51494
51495
51496
51497
51498
51499
51500
51501
51502
51503
51504
51505
51506
51507
51508
51509
51510
51511
51512
51513
51514
51515
51516
51517
51518
51519
51520
51521
51522
51523
51524
51525
51526
51527
51528
51529
51530
51531
51532
51533
51534
51535
51536
51537
51538
51539
51540
51541
51542
51543
51544
51545
51546
51547
51548
51549
51550
51551
51552
51553
51554
51555
51556
51557
51558
51559
51560
51561
51562
51563
51564
51565
51566
51567
51568
51569
51570
51571
51572
51573
51574
51575
51576
51577
51578
51579
51580
51581
51582
51583
51584
51585
51586
51587
51588
51589
51590
51591
51592
51593
51594
51595
51596
51597
51598
51599
51600
51601
51602
51603
51604
51605
51606
51607
51608
51609
51610
51611
51612
51613
51614
51615
51616
51617
51618
51619
51620
51621
51622
51623
51624
51625
51626
51627
51628
51629
51630
51631
51632
51633
51634
51635
51636
51637
51638
51639
51640
51641
51642
51643
51644
51645
51646
51647
51648
51649
51650
51651
51652
51653
51654
51655
51656
51657
51658
51659
51660
51661
51662
51663
51664
51665
51666
51667
51668
51669
51670
51671
51672
51673
51674
51675
51676
51677
51678
51679
51680
51681
51682
51683
51684
51685
51686
51687
51688
51689
51690
51691
51692
51693
51694
51695
51696
51697
51698
51699
51700
51701
51702
51703
51704
51705
51706
51707
51708
51709
51710
51711
51712
51713
51714
51715
51716
51717
51718
51719
51720
51721
51722
51723
51724
51725
51726
51727
51728
51729
51730
51731
51732
51733
51734
51735
51736
51737
51738
51739
51740
51741
51742
51743
51744
51745
51746
51747
51748
51749
51750
51751
51752
51753
51754
51755
51756
51757
51758
51759
51760
51761
51762
51763
51764
51765
51766
51767
51768
51769
51770
51771
51772
51773
51774
51775
51776
51777
51778
51779
51780
51781
51782
51783
51784
51785
51786
51787
51788
51789
51790
51791
51792
51793
51794
51795
51796
51797
51798
51799
51800
51801
51802
51803
51804
51805
51806
51807
51808
51809
51810
51811
51812
51813
51814
51815
51816
51817
51818
51819
51820
51821
51822
51823
51824
51825
51826
51827
51828
51829
51830
51831
51832
51833
51834
51835
51836
51837
51838
51839
51840
51841
51842
51843
51844
51845
51846
51847
51848
51849
51850
51851
51852
51853
51854
51855
51856
51857
51858
51859
51860
51861
51862
51863
51864
51865
51866
51867
51868
51869
51870
51871
51872
51873
51874
51875
51876
51877
51878
51879
51880
51881
51882
51883
51884
51885
51886
51887
51888
51889
51890
51891
51892
51893
51894
51895
51896
51897
51898
51899
51900
51901
51902
51903
51904
51905
51906
51907
51908
51909
51910
51911
51912
51913
51914
51915
51916
51917
51918
51919
51920
51921
51922
51923
51924
51925
51926
51927
51928
51929
51930
51931
51932
51933
51934
51935
51936
51937
51938
51939
51940
51941
51942
51943
51944
51945
51946
51947
51948
51949
51950
51951
51952
51953
51954
51955
51956
51957
51958
51959
51960
51961
51962
51963
51964
51965
51966
51967
51968
51969
51970
51971
51972
51973
51974
51975
51976
51977
51978
51979
51980
51981
51982
51983
51984
51985
51986
51987
51988
51989
51990
51991
51992
51993
51994
51995
51996
51997
51998
51999
52000
52001
52002
52003
52004
52005
52006
52007
52008
52009
52010
52011
52012
52013
52014
52015
52016
52017
52018
52019
52020
52021
52022
52023
52024
52025
52026
52027
52028
52029
52030
52031
52032
52033
52034
52035
52036
52037
52038
52039
52040
52041
52042
52043
52044
52045
52046
52047
52048
52049
52050
52051
52052
52053
52054
52055
52056
52057
52058
52059
52060
52061
52062
52063
52064
52065
52066
52067
52068
52069
52070
52071
52072
52073
52074
52075
52076
52077
52078
52079
52080
52081
52082
52083
52084
52085
52086
52087
52088
52089
52090
52091
52092
52093
52094
52095
52096
52097
52098
52099
52100
52101
52102
52103
52104
52105
52106
52107
52108
52109
52110
52111
52112
52113
52114
52115
52116
52117
52118
52119
52120
52121
52122
52123
52124
52125
52126
52127
52128
52129
52130
52131
52132
52133
52134
52135
52136
52137
52138
52139
52140
52141
52142
52143
52144
52145
52146
52147
52148
52149
52150
52151
52152
52153
52154
52155
52156
52157
52158
52159
52160
52161
52162
52163
52164
52165
52166
52167
52168
52169
52170
52171
52172
52173
52174
52175
52176
52177
52178
52179
52180
52181
52182
52183
52184
52185
52186
52187
52188
52189
52190
52191
52192
52193
52194
52195
52196
52197
52198
52199
52200
52201
52202
52203
52204
52205
52206
52207
52208
52209
52210
52211
52212
52213
52214
52215
52216
52217
52218
52219
52220
52221
52222
52223
52224
52225
52226
52227
52228
52229
52230
52231
52232
52233
52234
52235
52236
52237
52238
52239
52240
52241
52242
52243
52244
52245
52246
52247
52248
52249
52250
52251
52252
52253
52254
52255
52256
52257
52258
52259
52260
52261
52262
52263
52264
52265
52266
52267
52268
52269
52270
52271
52272
52273
52274
52275
52276
52277
52278
52279
52280
52281
52282
52283
52284
52285
52286
52287
52288
52289
52290
52291
52292
52293
52294
52295
52296
52297
52298
52299
52300
52301
52302
52303
52304
52305
52306
52307
52308
52309
52310
52311
52312
52313
52314
52315
52316
52317
52318
52319
52320
52321
52322
52323
52324
52325
52326
52327
52328
52329
52330
52331
52332
52333
52334
52335
52336
52337
52338
52339
52340
52341
52342
52343
52344
52345
52346
52347
52348
52349
52350
52351
52352
52353
52354
52355
52356
52357
52358
52359
52360
52361
52362
52363
52364
52365
52366
52367
52368
52369
52370
52371
52372
52373
52374
52375
52376
52377
52378
52379
52380
52381
52382
52383
52384
52385
52386
52387
52388
52389
52390
52391
52392
52393
52394
52395
52396
52397
52398
52399
52400
52401
52402
52403
52404
52405
52406
52407
52408
52409
52410
52411
52412
52413
52414
52415
52416
52417
52418
52419
52420
52421
52422
52423
52424
52425
52426
52427
52428
52429
52430
52431
52432
52433
52434
52435
52436
52437
52438
52439
52440
52441
52442
52443
52444
52445
52446
52447
52448
52449
52450
52451
52452
52453
52454
52455
52456
52457
52458
52459
52460
52461
52462
52463
52464
52465
52466
52467
52468
52469
52470
52471
52472
52473
52474
52475
52476
52477
52478
52479
52480
52481
52482
52483
52484
52485
52486
52487
52488
52489
52490
52491
52492
52493
52494
52495
52496
52497
52498
52499
52500
52501
52502
52503
52504
52505
52506
52507
52508
52509
52510
52511
52512
52513
52514
52515
52516
52517
52518
52519
52520
52521
52522
52523
52524
52525
52526
52527
52528
52529
52530
52531
52532
52533
52534
52535
52536
52537
52538
52539
52540
52541
52542
52543
52544
52545
52546
52547
52548
52549
52550
52551
52552
52553
52554
52555
52556
52557
52558
52559
52560
52561
52562
52563
52564
52565
52566
52567
52568
52569
52570
52571
52572
52573
52574
52575
52576
52577
52578
52579
52580
52581
52582
52583
52584
52585
52586
52587
52588
52589
52590
52591
52592
52593
52594
52595
52596
52597
52598
52599
52600
52601
52602
52603
52604
52605
52606
52607
52608
52609
52610
52611
52612
52613
52614
52615
52616
52617
52618
52619
52620
52621
52622
52623
52624
52625
52626
52627
52628
52629
52630
52631
52632
52633
52634
52635
52636
52637
52638
52639
52640
52641
52642
52643
52644
52645
52646
52647
52648
52649
52650
52651
52652
52653
52654
52655
52656
52657
52658
52659
52660
52661
52662
52663
52664
52665
52666
52667
52668
52669
52670
52671
52672
52673
52674
52675
52676
52677
52678
52679
52680
52681
52682
52683
52684
52685
52686
52687
52688
52689
52690
52691
52692
52693
52694
52695
52696
52697
52698
52699
52700
52701
52702
52703
52704
52705
52706
52707
52708
52709
52710
52711
52712
52713
52714
52715
52716
52717
52718
52719
52720
52721
52722
52723
52724
52725
52726
52727
52728
52729
52730
52731
52732
52733
52734
52735
52736
52737
52738
52739
52740
52741
52742
52743
52744
52745
52746
52747
52748
52749
52750
52751
52752
52753
52754
52755
52756
52757
52758
52759
52760
52761
52762
52763
52764
52765
52766
52767
52768
52769
52770
52771
52772
52773
52774
52775
52776
52777
52778
52779
52780
52781
52782
52783
52784
52785
52786
52787
52788
52789
52790
52791
52792
52793
52794
52795
52796
52797
52798
52799
52800
52801
52802
52803
52804
52805
52806
52807
52808
52809
52810
52811
52812
52813
52814
52815
52816
52817
52818
52819
52820
52821
52822
52823
52824
52825
52826
52827
52828
52829
52830
52831
52832
52833
52834
52835
52836
52837
52838
52839
52840
52841
52842
52843
52844
52845
52846
52847
52848
52849
52850
52851
52852
52853
52854
52855
52856
52857
52858
52859
52860
52861
52862
52863
52864
52865
52866
52867
52868
52869
52870
52871
52872
52873
52874
52875
52876
52877
52878
52879
52880
52881
52882
52883
52884
52885
52886
52887
52888
52889
52890
52891
52892
52893
52894
52895
52896
52897
52898
52899
52900
52901
52902
52903
52904
52905
52906
52907
52908
52909
52910
52911
52912
52913
52914
52915
52916
52917
52918
52919
52920
52921
52922
52923
52924
52925
52926
52927
52928
52929
52930
52931
52932
52933
52934
52935
52936
52937
52938
52939
52940
52941
52942
52943
52944
52945
52946
52947
52948
52949
52950
52951
52952
52953
52954
52955
52956
52957
52958
52959
52960
52961
52962
52963
52964
52965
52966
52967
52968
52969
52970
52971
52972
52973
52974
52975
52976
52977
52978
52979
52980
52981
52982
52983
52984
52985
52986
52987
52988
52989
52990
52991
52992
52993
52994
52995
52996
52997
52998
52999
53000
53001
53002
53003
53004
53005
53006
53007
53008
53009
53010
53011
53012
53013
53014
53015
53016
53017
53018
53019
53020
53021
53022
53023
53024
53025
53026
53027
53028
53029
53030
53031
53032
53033
53034
53035
53036
53037
53038
53039
53040
53041
53042
53043
53044
53045
53046
53047
53048
53049
53050
53051
53052
53053
53054
53055
53056
53057
53058
53059
53060
53061
53062
53063
53064
53065
53066
53067
53068
53069
53070
53071
53072
53073
53074
53075
53076
53077
53078
53079
53080
53081
53082
53083
53084
53085
53086
53087
53088
53089
53090
53091
53092
53093
53094
53095
53096
53097
53098
53099
53100
53101
53102
53103
53104
53105
53106
53107
53108
53109
53110
53111
53112
53113
53114
53115
53116
53117
53118
53119
53120
53121
53122
53123
53124
53125
53126
53127
53128
53129
53130
53131
53132
53133
53134
53135
53136
53137
53138
53139
53140
53141
53142
53143
53144
53145
53146
53147
53148
53149
53150
53151
53152
53153
53154
53155
53156
53157
53158
53159
53160
53161
53162
53163
53164
53165
53166
53167
53168
53169
53170
53171
53172
53173
53174
53175
53176
53177
53178
53179
53180
53181
53182
53183
53184
53185
53186
53187
53188
53189
53190
53191
53192
53193
53194
53195
53196
53197
53198
53199
53200
53201
53202
53203
53204
53205
53206
53207
53208
53209
53210
53211
53212
53213
53214
53215
53216
53217
53218
53219
53220
53221
53222
53223
53224
53225
53226
53227
53228
53229
53230
53231
53232
53233
53234
53235
53236
53237
53238
53239
53240
53241
53242
53243
53244
53245
53246
53247
53248
53249
53250
53251
53252
53253
53254
53255
53256
53257
53258
53259
53260
53261
53262
53263
53264
53265
53266
53267
53268
53269
53270
53271
53272
53273
53274
53275
53276
53277
53278
53279
53280
53281
53282
53283
53284
53285
53286
53287
53288
53289
53290
53291
53292
53293
53294
53295
53296
53297
53298
53299
53300
53301
53302
53303
53304
53305
53306
53307
53308
53309
53310
53311
53312
53313
53314
53315
53316
53317
53318
53319
53320
53321
53322
53323
53324
53325
53326
53327
53328
53329
53330
53331
53332
53333
53334
53335
53336
53337
53338
53339
53340
53341
53342
53343
53344
53345
53346
53347
53348
53349
53350
53351
53352
53353
53354
53355
53356
53357
53358
53359
53360
53361
53362
53363
53364
53365
53366
53367
53368
53369
53370
53371
53372
53373
53374
53375
53376
53377
53378
53379
53380
53381
53382
53383
53384
53385
53386
53387
53388
53389
53390
53391
53392
53393
53394
53395
53396
53397
53398
53399
53400
53401
53402
53403
53404
53405
53406
53407
53408
53409
53410
53411
53412
53413
53414
53415
53416
53417
53418
53419
53420
53421
53422
53423
53424
53425
53426
53427
53428
53429
53430
53431
53432
53433
53434
53435
53436
53437
53438
53439
53440
53441
53442
53443
53444
53445
53446
53447
53448
53449
53450
53451
53452
53453
53454
53455
53456
53457
53458
53459
53460
53461
53462
53463
53464
53465
53466
53467
53468
53469
53470
53471
53472
53473
53474
53475
53476
53477
53478
53479
53480
53481
53482
53483
53484
53485
53486
53487
53488
53489
53490
53491
53492
53493
53494
53495
53496
53497
53498
53499
53500
53501
53502
53503
53504
53505
53506
53507
53508
53509
53510
53511
53512
53513
53514
53515
53516
53517
53518
53519
53520
53521
53522
53523
53524
53525
53526
53527
53528
53529
53530
53531
53532
53533
53534
53535
53536
53537
53538
53539
53540
53541
53542
53543
53544
53545
53546
53547
53548
53549
53550
53551
53552
53553
53554
53555
53556
53557
53558
53559
53560
53561
53562
53563
53564
53565
53566
53567
53568
53569
53570
53571
53572
53573
53574
53575
53576
53577
53578
53579
53580
53581
53582
53583
53584
53585
53586
53587
53588
53589
53590
53591
53592
53593
53594
53595
53596
53597
53598
53599
53600
53601
53602
53603
53604
53605
53606
53607
53608
53609
53610
53611
53612
53613
53614
53615
53616
53617
53618
53619
53620
53621
53622
53623
53624
53625
53626
53627
53628
53629
53630
53631
53632
53633
53634
53635
53636
53637
53638
53639
53640
53641
53642
53643
53644
53645
53646
53647
53648
53649
53650
53651
53652
53653
53654
53655
53656
53657
53658
53659
53660
53661
53662
53663
53664
53665
53666
53667
53668
53669
53670
53671
53672
53673
53674
53675
53676
53677
53678
53679
53680
53681
53682
53683
53684
53685
53686
53687
53688
53689
53690
53691
53692
53693
53694
53695
53696
53697
53698
53699
53700
53701
53702
53703
53704
53705
53706
53707
53708
53709
53710
53711
53712
53713
53714
53715
53716
53717
53718
53719
53720
53721
53722
53723
53724
53725
53726
53727
53728
53729
53730
53731
53732
53733
53734
53735
53736
53737
53738
53739
53740
53741
53742
53743
53744
53745
53746
53747
53748
53749
53750
53751
53752
53753
53754
53755
53756
53757
53758
53759
53760
53761
53762
53763
53764
53765
53766
53767
53768
53769
53770
53771
53772
53773
53774
53775
53776
53777
53778
53779
53780
53781
53782
53783
53784
53785
53786
53787
53788
53789
53790
53791
53792
53793
53794
53795
53796
53797
53798
53799
53800
53801
53802
53803
53804
53805
53806
53807
53808
53809
53810
53811
53812
53813
53814
53815
53816
53817
53818
53819
53820
53821
53822
53823
53824
53825
53826
53827
53828
53829
53830
53831
53832
53833
53834
53835
53836
53837
53838
53839
53840
53841
53842
53843
53844
53845
53846
53847
53848
53849
53850
53851
53852
53853
53854
53855
53856
53857
53858
53859
53860
53861
53862
53863
53864
53865
53866
53867
53868
53869
53870
53871
53872
53873
53874
53875
53876
53877
53878
53879
53880
53881
53882
53883
53884
53885
53886
53887
53888
53889
53890
53891
53892
53893
53894
53895
53896
53897
53898
53899
53900
53901
53902
53903
53904
53905
53906
53907
53908
53909
53910
53911
53912
53913
53914
53915
53916
53917
53918
53919
53920
53921
53922
53923
53924
53925
53926
53927
53928
53929
53930
53931
53932
53933
53934
53935
53936
53937
53938
53939
53940
53941
53942
53943
53944
53945
53946
53947
53948
53949
53950
53951
53952
53953
53954
53955
53956
53957
53958
53959
53960
53961
53962
53963
53964
53965
53966
53967
53968
53969
53970
53971
53972
53973
53974
53975
53976
53977
53978
53979
53980
53981
53982
53983
53984
53985
53986
53987
53988
53989
53990
53991
53992
53993
53994
53995
53996
53997
53998
53999
54000
54001
54002
54003
54004
54005
54006
54007
54008
54009
54010
54011
54012
54013
54014
54015
54016
54017
54018
54019
54020
54021
54022
54023
54024
54025
54026
54027
54028
54029
54030
54031
54032
54033
54034
54035
54036
54037
54038
54039
54040
54041
54042
54043
54044
54045
54046
54047
54048
54049
54050
54051
54052
54053
54054
54055
54056
54057
54058
54059
54060
54061
54062
54063
54064
54065
54066
54067
54068
54069
54070
54071
54072
54073
54074
54075
54076
54077
54078
54079
54080
54081
54082
54083
54084
54085
54086
54087
54088
54089
54090
54091
54092
54093
54094
54095
54096
54097
54098
54099
54100
54101
54102
54103
54104
54105
54106
54107
54108
54109
54110
54111
54112
54113
54114
54115
54116
54117
54118
54119
54120
54121
54122
54123
54124
54125
54126
54127
54128
54129
54130
54131
54132
54133
54134
54135
54136
54137
54138
54139
54140
54141
54142
54143
54144
54145
54146
54147
54148
54149
54150
54151
54152
54153
54154
54155
54156
54157
54158
54159
54160
54161
54162
54163
54164
54165
54166
54167
54168
54169
54170
54171
54172
54173
54174
54175
54176
54177
54178
54179
54180
54181
54182
54183
54184
54185
54186
54187
54188
54189
54190
54191
54192
54193
54194
54195
54196
54197
54198
54199
54200
54201
54202
54203
54204
54205
54206
54207
54208
54209
54210
54211
54212
54213
54214
54215
54216
54217
54218
54219
54220
54221
54222
54223
54224
54225
54226
54227
54228
54229
54230
54231
54232
54233
54234
54235
54236
54237
54238
54239
54240
54241
54242
54243
54244
54245
54246
54247
54248
54249
54250
54251
54252
54253
54254
54255
54256
54257
54258
54259
54260
54261
54262
54263
54264
54265
54266
54267
54268
54269
54270
54271
54272
54273
54274
54275
54276
54277
54278
54279
54280
54281
54282
54283
54284
54285
54286
54287
54288
54289
54290
54291
54292
54293
54294
54295
54296
54297
54298
54299
54300
54301
54302
54303
54304
54305
54306
54307
54308
54309
54310
54311
54312
54313
54314
54315
54316
54317
54318
54319
54320
54321
54322
54323
54324
54325
54326
54327
54328
54329
54330
54331
54332
54333
54334
54335
54336
54337
54338
54339
54340
54341
54342
54343
54344
54345
54346
54347
54348
54349
54350
54351
54352
54353
54354
54355
54356
54357
54358
54359
54360
54361
54362
54363
54364
54365
54366
54367
54368
54369
54370
54371
54372
54373
54374
54375
54376
54377
54378
54379
54380
54381
54382
54383
54384
54385
54386
54387
54388
54389
54390
54391
54392
54393
54394
54395
54396
54397
54398
54399
54400
54401
54402
54403
54404
54405
54406
54407
54408
54409
54410
54411
54412
54413
54414
54415
54416
54417
54418
54419
54420
54421
54422
54423
54424
54425
54426
54427
54428
54429
54430
54431
54432
54433
54434
54435
54436
54437
54438
54439
54440
54441
54442
54443
54444
54445
54446
54447
54448
54449
54450
54451
54452
54453
54454
54455
54456
54457
54458
54459
54460
54461
54462
54463
54464
54465
54466
54467
54468
54469
54470
54471
54472
54473
54474
54475
54476
54477
54478
54479
54480
54481
54482
54483
54484
54485
54486
54487
54488
54489
54490
54491
54492
54493
54494
54495
54496
54497
54498
54499
54500
54501
54502
54503
54504
54505
54506
54507
54508
54509
54510
54511
54512
54513
54514
54515
54516
54517
54518
54519
54520
54521
54522
54523
54524
54525
54526
54527
54528
54529
54530
54531
54532
54533
54534
54535
54536
54537
54538
54539
54540
54541
54542
54543
54544
54545
54546
54547
54548
54549
54550
54551
54552
54553
54554
54555
54556
54557
54558
54559
54560
54561
54562
54563
54564
54565
54566
54567
54568
54569
54570
54571
54572
54573
54574
54575
54576
54577
54578
54579
54580
54581
54582
54583
54584
54585
54586
54587
54588
54589
54590
54591
54592
54593
54594
54595
54596
54597
54598
54599
54600
54601
54602
54603
54604
54605
54606
54607
54608
54609
54610
54611
54612
54613
54614
54615
54616
54617
54618
54619
54620
54621
54622
54623
54624
54625
54626
54627
54628
54629
54630
54631
54632
54633
54634
54635
54636
54637
54638
54639
54640
54641
54642
54643
54644
54645
54646
54647
54648
54649
54650
54651
54652
54653
54654
54655
54656
54657
54658
54659
54660
54661
54662
54663
54664
54665
54666
54667
54668
54669
54670
54671
54672
54673
54674
54675
54676
54677
54678
54679
54680
54681
54682
54683
54684
54685
54686
54687
54688
54689
54690
54691
54692
54693
54694
54695
54696
54697
54698
54699
54700
54701
54702
54703
54704
54705
54706
54707
54708
54709
54710
54711
54712
54713
54714
54715
54716
54717
54718
54719
54720
54721
54722
54723
54724
54725
54726
54727
54728
54729
54730
54731
54732
54733
54734
54735
54736
54737
54738
54739
54740
54741
54742
54743
54744
54745
54746
54747
54748
54749
54750
54751
54752
54753
54754
54755
54756
54757
54758
54759
54760
54761
54762
54763
54764
54765
54766
54767
54768
54769
54770
54771
54772
54773
54774
54775
54776
54777
54778
54779
54780
54781
54782
54783
54784
54785
54786
54787
54788
54789
54790
54791
54792
54793
54794
54795
54796
54797
54798
54799
54800
54801
54802
54803
54804
54805
54806
54807
54808
54809
54810
54811
54812
54813
54814
54815
54816
54817
54818
54819
54820
54821
54822
54823
54824
54825
54826
54827
54828
54829
54830
54831
54832
54833
54834
54835
54836
54837
54838
54839
54840
54841
54842
54843
54844
54845
54846
54847
54848
54849
54850
54851
54852
54853
54854
54855
54856
54857
54858
54859
54860
54861
54862
54863
54864
54865
54866
54867
54868
54869
54870
54871
54872
54873
54874
54875
54876
54877
54878
54879
54880
54881
54882
54883
54884
54885
54886
54887
54888
54889
54890
54891
54892
54893
54894
54895
54896
54897
54898
54899
54900
54901
54902
54903
54904
54905
54906
54907
54908
54909
54910
54911
54912
54913
54914
54915
54916
54917
54918
54919
54920
54921
54922
54923
54924
54925
54926
54927
54928
54929
54930
54931
54932
54933
54934
54935
54936
54937
54938
54939
54940
54941
54942
54943
54944
54945
54946
54947
54948
54949
54950
54951
54952
54953
54954
54955
54956
54957
54958
54959
54960
54961
54962
54963
54964
54965
54966
54967
54968
54969
54970
54971
54972
54973
54974
54975
54976
54977
54978
54979
54980
54981
54982
54983
54984
54985
54986
54987
54988
54989
54990
54991
54992
54993
54994
54995
54996
54997
54998
54999
55000
55001
55002
55003
55004
55005
55006
55007
55008
55009
55010
55011
55012
55013
55014
55015
55016
55017
55018
55019
55020
55021
55022
55023
55024
55025
55026
55027
55028
55029
55030
55031
55032
55033
55034
55035
55036
55037
55038
55039
55040
55041
55042
55043
55044
55045
55046
55047
55048
55049
55050
55051
55052
55053
55054
55055
55056
55057
55058
55059
55060
55061
55062
55063
55064
55065
55066
55067
55068
55069
55070
55071
55072
55073
55074
55075
55076
55077
55078
55079
55080
55081
55082
55083
55084
55085
55086
55087
55088
55089
55090
55091
55092
55093
55094
55095
55096
55097
55098
55099
55100
55101
55102
55103
55104
55105
55106
55107
55108
55109
55110
55111
55112
55113
55114
55115
55116
55117
55118
55119
55120
55121
55122
55123
55124
55125
55126
55127
55128
55129
55130
55131
55132
55133
55134
55135
55136
55137
55138
55139
55140
55141
55142
55143
55144
55145
55146
55147
55148
55149
55150
55151
55152
55153
55154
55155
55156
55157
55158
55159
55160
55161
55162
55163
55164
55165
55166
55167
55168
55169
55170
55171
55172
55173
55174
55175
55176
55177
55178
55179
55180
55181
55182
55183
55184
55185
55186
55187
55188
55189
55190
55191
55192
55193
55194
55195
55196
55197
55198
55199
55200
55201
55202
55203
55204
55205
55206
55207
55208
55209
55210
55211
55212
55213
55214
55215
55216
55217
55218
55219
55220
55221
55222
55223
55224
55225
55226
55227
55228
55229
55230
55231
55232
55233
55234
55235
55236
55237
55238
55239
55240
55241
55242
55243
55244
55245
55246
55247
55248
55249
55250
55251
55252
55253
55254
55255
55256
55257
55258
55259
55260
55261
55262
55263
55264
55265
55266
55267
55268
55269
55270
55271
55272
55273
55274
55275
55276
55277
55278
55279
55280
55281
55282
55283
55284
55285
55286
55287
55288
55289
55290
55291
55292
55293
55294
55295
55296
55297
55298
55299
55300
55301
55302
55303
55304
55305
55306
55307
55308
55309
55310
55311
55312
55313
55314
55315
55316
55317
55318
55319
55320
55321
55322
55323
55324
55325
55326
55327
55328
55329
55330
55331
55332
55333
55334
55335
55336
55337
55338
55339
55340
55341
55342
55343
55344
55345
55346
55347
55348
55349
55350
55351
55352
55353
55354
55355
55356
55357
55358
55359
55360
55361
55362
55363
55364
55365
55366
55367
55368
55369
55370
55371
55372
55373
55374
55375
55376
55377
55378
55379
55380
55381
55382
55383
55384
55385
55386
55387
55388
55389
55390
55391
55392
55393
55394
55395
55396
55397
55398
55399
55400
55401
55402
55403
55404
55405
55406
55407
55408
55409
55410
55411
55412
55413
55414
55415
55416
55417
55418
55419
55420
55421
55422
55423
55424
55425
55426
55427
55428
55429
55430
55431
55432
55433
55434
55435
55436
55437
55438
55439
55440
55441
55442
55443
55444
55445
55446
55447
55448
55449
55450
55451
55452
55453
55454
55455
55456
55457
55458
55459
55460
55461
55462
55463
55464
55465
55466
55467
55468
55469
55470
55471
55472
55473
55474
55475
55476
55477
55478
55479
55480
55481
55482
55483
55484
55485
55486
55487
55488
55489
55490
55491
55492
55493
55494
55495
55496
55497
55498
55499
55500
55501
55502
55503
55504
55505
55506
55507
55508
55509
55510
55511
55512
55513
55514
55515
55516
55517
55518
55519
55520
55521
55522
55523
55524
55525
55526
55527
55528
55529
55530
55531
55532
55533
55534
55535
55536
55537
55538
55539
55540
55541
55542
55543
55544
55545
55546
55547
55548
55549
55550
55551
55552
55553
55554
55555
55556
55557
55558
55559
55560
55561
55562
55563
55564
55565
55566
55567
55568
55569
55570
55571
55572
55573
55574
55575
55576
55577
55578
55579
55580
55581
55582
55583
55584
55585
55586
55587
55588
55589
55590
55591
55592
55593
55594
55595
55596
55597
55598
55599
55600
55601
55602
55603
55604
55605
55606
55607
55608
55609
55610
55611
55612
55613
55614
55615
55616
55617
55618
55619
55620
55621
55622
55623
55624
55625
55626
55627
55628
55629
55630
55631
55632
55633
55634
55635
55636
55637
55638
55639
55640
55641
55642
55643
55644
55645
55646
55647
55648
55649
55650
55651
55652
55653
55654
55655
55656
55657
55658
55659
55660
55661
55662
55663
55664
55665
55666
55667
55668
55669
55670
55671
55672
55673
55674
55675
55676
55677
55678
55679
55680
55681
55682
55683
55684
55685
55686
55687
55688
55689
55690
55691
55692
55693
55694
55695
55696
55697
55698
55699
55700
55701
55702
55703
55704
55705
55706
55707
55708
55709
55710
55711
55712
55713
55714
55715
55716
55717
55718
55719
55720
55721
55722
55723
55724
55725
55726
55727
55728
55729
55730
55731
55732
55733
55734
55735
55736
55737
55738
55739
55740
55741
55742
55743
55744
55745
55746
55747
55748
55749
55750
55751
55752
55753
55754
55755
55756
55757
55758
55759
55760
55761
55762
55763
55764
55765
55766
55767
55768
55769
55770
55771
55772
55773
55774
55775
55776
55777
55778
55779
55780
55781
55782
55783
55784
55785
55786
55787
55788
55789
55790
55791
55792
55793
55794
55795
55796
55797
55798
55799
55800
55801
55802
55803
55804
55805
55806
55807
55808
55809
55810
55811
55812
55813
55814
55815
55816
55817
55818
55819
55820
55821
55822
55823
55824
55825
55826
55827
55828
55829
55830
55831
55832
55833
55834
55835
55836
55837
55838
55839
55840
55841
55842
55843
55844
55845
55846
55847
55848
55849
55850
55851
55852
55853
55854
55855
55856
55857
55858
55859
55860
55861
55862
55863
55864
55865
55866
55867
55868
55869
55870
55871
55872
55873
55874
55875
55876
55877
55878
55879
55880
55881
55882
55883
55884
55885
55886
55887
55888
55889
55890
55891
55892
55893
55894
55895
55896
55897
55898
55899
55900
55901
55902
55903
55904
55905
55906
55907
55908
55909
55910
55911
55912
55913
55914
55915
55916
55917
55918
55919
55920
55921
55922
55923
55924
55925
55926
55927
55928
55929
55930
55931
55932
55933
55934
55935
55936
55937
55938
55939
55940
55941
55942
55943
55944
55945
55946
55947
55948
55949
55950
55951
55952
55953
55954
55955
55956
55957
55958
55959
55960
55961
55962
55963
55964
55965
55966
55967
55968
55969
55970
55971
55972
55973
55974
55975
55976
55977
55978
55979
55980
55981
55982
55983
55984
55985
55986
55987
55988
55989
55990
55991
55992
55993
55994
55995
55996
55997
55998
55999
56000
56001
56002
56003
56004
56005
56006
56007
56008
56009
56010
56011
56012
56013
56014
56015
56016
56017
56018
56019
56020
56021
56022
56023
56024
56025
56026
56027
56028
56029
56030
56031
56032
56033
56034
56035
56036
56037
56038
56039
56040
56041
56042
56043
56044
56045
56046
56047
56048
56049
56050
56051
56052
56053
56054
56055
56056
56057
56058
56059
56060
56061
56062
56063
56064
56065
56066
56067
56068
56069
56070
56071
56072
56073
56074
56075
56076
56077
56078
56079
56080
56081
56082
56083
56084
56085
56086
56087
56088
56089
56090
56091
56092
56093
56094
56095
56096
56097
56098
56099
56100
56101
56102
56103
56104
56105
56106
56107
56108
56109
56110
56111
56112
56113
56114
56115
56116
56117
56118
56119
56120
56121
56122
56123
56124
56125
56126
56127
56128
56129
56130
56131
56132
56133
56134
56135
56136
56137
56138
56139
56140
56141
56142
56143
56144
56145
56146
56147
56148
56149
56150
56151
56152
56153
56154
56155
56156
56157
56158
56159
56160
56161
56162
56163
56164
56165
56166
56167
56168
56169
56170
56171
56172
56173
56174
56175
56176
56177
56178
56179
56180
56181
56182
56183
56184
56185
56186
56187
56188
56189
56190
56191
56192
56193
56194
56195
56196
56197
56198
56199
56200
56201
56202
56203
56204
56205
56206
56207
56208
56209
56210
56211
56212
56213
56214
56215
56216
56217
56218
56219
56220
56221
56222
56223
56224
56225
56226
56227
56228
56229
56230
56231
56232
56233
56234
56235
56236
56237
56238
56239
56240
56241
56242
56243
56244
56245
56246
56247
56248
56249
56250
56251
56252
56253
56254
56255
56256
56257
56258
56259
56260
56261
56262
56263
56264
56265
56266
56267
56268
56269
56270
56271
56272
56273
56274
56275
56276
56277
56278
56279
56280
56281
56282
56283
56284
56285
56286
56287
56288
56289
56290
56291
56292
56293
56294
56295
56296
56297
56298
56299
56300
56301
56302
56303
56304
56305
56306
56307
56308
56309
56310
56311
56312
56313
56314
56315
56316
56317
56318
56319
56320
56321
56322
56323
56324
56325
56326
56327
56328
56329
56330
56331
56332
56333
56334
56335
56336
56337
56338
56339
56340
56341
56342
56343
56344
56345
56346
56347
56348
56349
56350
56351
56352
56353
56354
56355
56356
56357
56358
56359
56360
56361
56362
56363
56364
56365
56366
56367
56368
56369
56370
56371
56372
56373
56374
56375
56376
56377
56378
56379
56380
56381
56382
56383
56384
56385
56386
56387
56388
56389
56390
56391
56392
56393
56394
56395
56396
56397
56398
56399
56400
56401
56402
56403
56404
56405
56406
56407
56408
56409
56410
56411
56412
56413
56414
56415
56416
56417
56418
56419
56420
56421
56422
56423
56424
56425
56426
56427
56428
56429
56430
56431
56432
56433
56434
56435
56436
56437
56438
56439
56440
56441
56442
56443
56444
56445
56446
56447
56448
56449
56450
56451
56452
56453
56454
56455
56456
56457
56458
56459
56460
56461
56462
56463
56464
56465
56466
56467
56468
56469
56470
56471
56472
56473
56474
56475
56476
56477
56478
56479
56480
56481
56482
56483
56484
56485
56486
56487
56488
56489
56490
56491
56492
56493
56494
56495
56496
56497
56498
56499
56500
56501
56502
56503
56504
56505
56506
56507
56508
56509
56510
56511
56512
56513
56514
56515
56516
56517
56518
56519
56520
56521
56522
56523
56524
56525
56526
56527
56528
56529
56530
56531
56532
56533
56534
56535
56536
56537
56538
56539
56540
56541
56542
56543
56544
56545
56546
56547
56548
56549
56550
56551
56552
56553
56554
56555
56556
56557
56558
56559
56560
56561
56562
56563
56564
56565
56566
56567
56568
56569
56570
56571
56572
56573
56574
56575
56576
56577
56578
56579
56580
56581
56582
56583
56584
56585
56586
56587
56588
56589
56590
56591
56592
56593
56594
56595
56596
56597
56598
56599
56600
56601
56602
56603
56604
56605
56606
56607
56608
56609
56610
56611
56612
56613
56614
56615
56616
56617
56618
56619
56620
56621
56622
56623
56624
56625
56626
56627
56628
56629
56630
56631
56632
56633
56634
56635
56636
56637
56638
56639
56640
56641
56642
56643
56644
56645
56646
56647
56648
56649
56650
56651
56652
56653
56654
56655
56656
56657
56658
56659
56660
56661
56662
56663
56664
56665
56666
56667
56668
56669
56670
56671
56672
56673
56674
56675
56676
56677
56678
56679
56680
56681
56682
56683
56684
56685
56686
56687
56688
56689
56690
56691
56692
56693
56694
56695
56696
56697
56698
56699
56700
56701
56702
56703
56704
56705
56706
56707
56708
56709
56710
56711
56712
56713
56714
56715
56716
56717
56718
56719
56720
56721
56722
56723
56724
56725
56726
56727
56728
56729
56730
56731
56732
56733
56734
56735
56736
56737
56738
56739
56740
56741
56742
56743
56744
56745
56746
56747
56748
56749
56750
56751
56752
56753
56754
56755
56756
56757
56758
56759
56760
56761
56762
56763
56764
56765
56766
56767
56768
56769
56770
56771
56772
56773
56774
56775
56776
56777
56778
56779
56780
56781
56782
56783
56784
56785
56786
56787
56788
56789
56790
56791
56792
56793
56794
56795
56796
56797
56798
56799
56800
56801
56802
56803
56804
56805
56806
56807
56808
56809
56810
56811
56812
56813
56814
56815
56816
56817
56818
56819
56820
56821
56822
56823
56824
56825
56826
56827
56828
56829
56830
56831
56832
56833
56834
56835
56836
56837
56838
56839
56840
56841
56842
56843
56844
56845
56846
56847
56848
56849
56850
56851
56852
56853
56854
56855
56856
56857
56858
56859
56860
56861
56862
56863
56864
56865
56866
56867
56868
56869
56870
56871
56872
56873
56874
56875
56876
56877
56878
56879
56880
56881
56882
56883
56884
56885
56886
56887
56888
56889
56890
56891
56892
56893
56894
56895
56896
56897
56898
56899
56900
56901
56902
56903
56904
56905
56906
56907
56908
56909
56910
56911
56912
56913
56914
56915
56916
56917
56918
56919
56920
56921
56922
56923
56924
56925
56926
56927
56928
56929
56930
56931
56932
56933
56934
56935
56936
56937
56938
56939
56940
56941
56942
56943
56944
56945
56946
56947
56948
56949
56950
56951
56952
56953
56954
56955
56956
56957
56958
56959
56960
56961
56962
56963
56964
56965
56966
56967
56968
56969
56970
56971
56972
56973
56974
56975
56976
56977
56978
56979
56980
56981
56982
56983
56984
56985
56986
56987
56988
56989
56990
56991
56992
56993
56994
56995
56996
56997
56998
56999
57000
57001
57002
57003
57004
57005
57006
57007
57008
57009
57010
57011
57012
57013
57014
57015
57016
57017
57018
57019
57020
57021
57022
57023
57024
57025
57026
57027
57028
57029
57030
57031
57032
57033
57034
57035
57036
57037
57038
57039
57040
57041
57042
57043
57044
57045
57046
57047
57048
57049
57050
57051
57052
57053
57054
57055
57056
57057
57058
57059
57060
57061
57062
57063
57064
57065
57066
57067
57068
57069
57070
57071
57072
57073
57074
57075
57076
57077
57078
57079
57080
57081
57082
57083
57084
57085
57086
57087
57088
57089
57090
57091
57092
57093
57094
57095
57096
57097
57098
57099
57100
57101
57102
57103
57104
57105
57106
57107
57108
57109
57110
57111
57112
57113
57114
57115
57116
57117
57118
57119
57120
57121
57122
57123
57124
57125
57126
57127
57128
57129
57130
57131
57132
57133
57134
57135
57136
57137
57138
57139
57140
57141
57142
57143
57144
57145
57146
57147
57148
57149
57150
57151
57152
57153
57154
57155
57156
57157
57158
57159
57160
57161
57162
57163
57164
57165
57166
57167
57168
57169
57170
57171
57172
57173
57174
57175
57176
57177
57178
57179
57180
57181
57182
57183
57184
57185
57186
57187
57188
57189
57190
57191
57192
57193
57194
57195
57196
57197
57198
57199
57200
57201
57202
57203
57204
57205
57206
57207
57208
57209
57210
57211
57212
57213
57214
57215
57216
57217
57218
57219
57220
57221
57222
57223
57224
57225
57226
57227
57228
57229
57230
57231
57232
57233
57234
57235
57236
57237
57238
57239
57240
57241
57242
57243
57244
57245
57246
57247
57248
57249
57250
57251
57252
57253
57254
57255
57256
57257
57258
57259
57260
57261
57262
57263
57264
57265
57266
57267
57268
57269
57270
57271
57272
57273
57274
57275
57276
57277
57278
57279
57280
57281
57282
57283
57284
57285
57286
57287
57288
57289
57290
57291
57292
57293
57294
57295
57296
57297
57298
57299
57300
57301
57302
57303
57304
57305
57306
57307
57308
57309
57310
57311
57312
57313
57314
57315
57316
57317
57318
57319
57320
57321
57322
57323
57324
57325
57326
57327
57328
57329
57330
57331
57332
57333
57334
57335
57336
57337
57338
57339
57340
57341
57342
57343
57344
57345
57346
57347
57348
57349
57350
57351
57352
57353
57354
57355
57356
57357
57358
57359
57360
57361
57362
57363
57364
57365
57366
57367
57368
57369
57370
57371
57372
57373
57374
57375
57376
57377
57378
57379
57380
57381
57382
57383
57384
57385
57386
57387
57388
57389
57390
57391
57392
57393
57394
57395
57396
57397
57398
57399
57400
57401
57402
57403
57404
57405
57406
57407
57408
57409
57410
57411
57412
57413
57414
57415
57416
57417
57418
57419
57420
57421
57422
57423
57424
57425
57426
57427
57428
57429
57430
57431
57432
57433
57434
57435
57436
57437
57438
57439
57440
57441
57442
57443
57444
57445
57446
57447
57448
57449
57450
57451
57452
57453
57454
57455
57456
57457
57458
57459
57460
57461
57462
57463
57464
57465
57466
57467
57468
57469
57470
57471
57472
57473
57474
57475
57476
57477
57478
57479
57480
57481
57482
57483
57484
57485
57486
57487
57488
57489
57490
57491
57492
57493
57494
57495
57496
57497
57498
57499
57500
57501
57502
57503
57504
57505
57506
57507
57508
57509
57510
57511
57512
57513
57514
57515
57516
57517
57518
57519
57520
57521
57522
57523
57524
57525
57526
57527
57528
57529
57530
57531
57532
57533
57534
57535
57536
57537
57538
57539
57540
57541
57542
57543
57544
57545
57546
57547
57548
57549
57550
57551
57552
57553
57554
57555
57556
57557
57558
57559
57560
57561
57562
57563
57564
57565
57566
57567
57568
57569
57570
57571
57572
57573
57574
57575
57576
57577
57578
57579
57580
57581
57582
57583
57584
57585
57586
57587
57588
57589
57590
57591
57592
57593
57594
57595
57596
57597
57598
57599
57600
57601
57602
57603
57604
57605
57606
57607
57608
57609
57610
57611
57612
57613
57614
57615
57616
57617
57618
57619
57620
57621
57622
57623
57624
57625
57626
57627
57628
57629
57630
57631
57632
57633
57634
57635
57636
57637
57638
57639
57640
57641
57642
57643
57644
57645
57646
57647
57648
57649
57650
57651
57652
57653
57654
57655
57656
57657
57658
57659
57660
57661
57662
57663
57664
57665
57666
57667
57668
57669
57670
57671
57672
57673
57674
57675
57676
57677
57678
57679
57680
57681
57682
57683
57684
57685
57686
57687
57688
57689
57690
57691
57692
57693
57694
57695
57696
57697
57698
57699
57700
57701
57702
57703
57704
57705
57706
57707
57708
57709
57710
57711
57712
57713
57714
57715
57716
57717
57718
57719
57720
57721
57722
57723
57724
57725
57726
57727
57728
57729
57730
57731
57732
57733
57734
57735
57736
57737
57738
57739
57740
57741
57742
57743
57744
57745
57746
57747
57748
57749
57750
57751
57752
57753
57754
57755
57756
57757
57758
57759
57760
57761
57762
57763
57764
57765
57766
57767
57768
57769
57770
57771
57772
57773
57774
57775
57776
57777
57778
57779
57780
57781
57782
57783
57784
57785
57786
57787
57788
57789
57790
57791
57792
57793
57794
57795
57796
57797
57798
57799
57800
57801
57802
57803
57804
57805
57806
57807
57808
57809
57810
57811
57812
57813
57814
57815
57816
57817
57818
57819
57820
57821
57822
57823
57824
57825
57826
57827
57828
57829
57830
57831
57832
57833
57834
57835
57836
57837
57838
57839
57840
57841
57842
57843
57844
57845
57846
57847
57848
57849
57850
57851
57852
57853
57854
57855
57856
57857
57858
57859
57860
57861
57862
57863
57864
57865
57866
57867
57868
57869
57870
57871
57872
57873
57874
57875
57876
57877
57878
57879
57880
57881
57882
57883
57884
57885
57886
57887
57888
57889
57890
57891
57892
57893
57894
57895
57896
57897
57898
57899
57900
57901
57902
57903
57904
57905
57906
57907
57908
57909
57910
57911
57912
57913
57914
57915
57916
57917
57918
57919
57920
57921
57922
57923
57924
57925
57926
57927
57928
57929
57930
57931
57932
57933
57934
57935
57936
57937
57938
57939
57940
57941
57942
57943
57944
57945
57946
57947
57948
57949
57950
57951
57952
57953
57954
57955
57956
57957
57958
57959
57960
57961
57962
57963
57964
57965
57966
57967
57968
57969
57970
57971
57972
57973
57974
57975
57976
57977
57978
57979
57980
57981
57982
57983
57984
57985
57986
57987
57988
57989
57990
57991
57992
57993
57994
57995
57996
57997
57998
57999
58000
58001
58002
58003
58004
58005
58006
58007
58008
58009
58010
58011
58012
58013
58014
58015
58016
58017
58018
58019
58020
58021
58022
58023
58024
58025
58026
58027
58028
58029
58030
58031
58032
58033
58034
58035
58036
58037
58038
58039
58040
58041
58042
58043
58044
58045
58046
58047
58048
58049
58050
58051
58052
58053
58054
58055
58056
58057
58058
58059
58060
58061
58062
58063
58064
58065
58066
58067
58068
58069
58070
58071
58072
58073
58074
58075
58076
58077
58078
58079
58080
58081
58082
58083
58084
58085
58086
58087
58088
58089
58090
58091
58092
58093
58094
58095
58096
58097
58098
58099
58100
58101
58102
58103
58104
58105
58106
58107
58108
58109
58110
58111
58112
58113
58114
58115
58116
58117
58118
58119
58120
58121
58122
58123
58124
58125
58126
58127
58128
58129
58130
58131
58132
58133
58134
58135
58136
58137
58138
58139
58140
58141
58142
58143
58144
58145
58146
58147
58148
58149
58150
58151
58152
58153
58154
58155
58156
58157
58158
58159
58160
58161
58162
58163
58164
58165
58166
58167
58168
58169
58170
58171
58172
58173
58174
58175
58176
58177
58178
58179
58180
58181
58182
58183
58184
58185
58186
58187
58188
58189
58190
58191
58192
58193
58194
58195
58196
58197
58198
58199
58200
58201
58202
58203
58204
58205
58206
58207
58208
58209
58210
58211
58212
58213
58214
58215
58216
58217
58218
58219
58220
58221
58222
58223
58224
58225
58226
58227
58228
58229
58230
58231
58232
58233
58234
58235
58236
58237
58238
58239
58240
58241
58242
58243
58244
58245
58246
58247
58248
58249
58250
58251
58252
58253
58254
58255
58256
58257
58258
58259
58260
58261
58262
58263
58264
58265
58266
58267
58268
58269
58270
58271
58272
58273
58274
58275
58276
58277
58278
58279
58280
58281
58282
58283
58284
58285
58286
58287
58288
58289
58290
58291
58292
58293
58294
58295
58296
58297
58298
58299
58300
58301
58302
58303
58304
58305
58306
58307
58308
58309
58310
58311
58312
58313
58314
58315
58316
58317
58318
58319
58320
58321
58322
58323
58324
58325
58326
58327
58328
58329
58330
58331
58332
58333
58334
58335
58336
58337
58338
58339
58340
58341
58342
58343
58344
58345
58346
58347
58348
58349
58350
58351
58352
58353
58354
58355
58356
58357
58358
58359
58360
58361
58362
58363
58364
58365
58366
58367
58368
58369
58370
58371
58372
58373
58374
58375
58376
58377
58378
58379
58380
58381
58382
58383
58384
58385
58386
58387
58388
58389
58390
58391
58392
58393
58394
58395
58396
58397
58398
58399
58400
58401
58402
58403
58404
58405
58406
58407
58408
58409
58410
58411
58412
58413
58414
58415
58416
58417
58418
58419
58420
58421
58422
58423
58424
58425
58426
58427
58428
58429
58430
58431
58432
58433
58434
58435
58436
58437
58438
58439
58440
58441
58442
58443
58444
58445
58446
58447
58448
58449
58450
58451
58452
58453
58454
58455
58456
58457
58458
58459
58460
58461
58462
58463
58464
58465
58466
58467
58468
58469
58470
58471
58472
58473
58474
58475
58476
58477
58478
58479
58480
58481
58482
58483
58484
58485
58486
58487
58488
58489
58490
58491
58492
58493
58494
58495
58496
58497
58498
58499
58500
58501
58502
58503
58504
58505
58506
58507
58508
58509
58510
58511
58512
58513
58514
58515
58516
58517
58518
58519
58520
58521
58522
58523
58524
58525
58526
58527
58528
58529
58530
58531
58532
58533
58534
58535
58536
58537
58538
58539
58540
58541
58542
58543
58544
58545
58546
58547
58548
58549
58550
58551
58552
58553
58554
58555
58556
58557
58558
58559
58560
58561
58562
58563
58564
58565
58566
58567
58568
58569
58570
58571
58572
58573
58574
58575
58576
58577
58578
58579
58580
58581
58582
58583
58584
58585
58586
58587
58588
58589
58590
58591
58592
58593
58594
58595
58596
58597
58598
58599
58600
58601
58602
58603
58604
58605
58606
58607
58608
58609
58610
58611
58612
58613
58614
58615
58616
58617
58618
58619
58620
58621
58622
58623
58624
58625
58626
58627
58628
58629
58630
58631
58632
58633
58634
58635
58636
58637
58638
58639
58640
58641
58642
58643
58644
58645
58646
58647
58648
58649
58650
58651
58652
58653
58654
58655
58656
58657
58658
58659
58660
58661
58662
58663
58664
58665
58666
58667
58668
58669
58670
58671
58672
58673
58674
58675
58676
58677
58678
58679
58680
58681
58682
58683
58684
58685
58686
58687
58688
58689
58690
58691
58692
58693
58694
58695
58696
58697
58698
58699
58700
58701
58702
58703
58704
58705
58706
58707
58708
58709
58710
58711
58712
58713
58714
58715
58716
58717
58718
58719
58720
58721
58722
58723
58724
58725
58726
58727
58728
58729
58730
58731
58732
58733
58734
58735
58736
58737
58738
58739
58740
58741
58742
58743
58744
58745
58746
58747
58748
58749
58750
58751
58752
58753
58754
58755
58756
58757
58758
58759
58760
58761
58762
58763
58764
58765
58766
58767
58768
58769
58770
58771
58772
58773
58774
58775
58776
58777
58778
58779
58780
58781
58782
58783
58784
58785
58786
58787
58788
58789
58790
58791
58792
58793
58794
58795
58796
58797
58798
58799
58800
58801
58802
58803
58804
58805
58806
58807
58808
58809
58810
58811
58812
58813
58814
58815
58816
58817
58818
58819
58820
58821
58822
58823
58824
58825
58826
58827
58828
58829
58830
58831
58832
58833
58834
58835
58836
58837
58838
58839
58840
58841
58842
58843
58844
58845
58846
58847
58848
58849
58850
58851
58852
58853
58854
58855
58856
58857
58858
58859
58860
58861
58862
58863
58864
58865
58866
58867
58868
58869
58870
58871
58872
58873
58874
58875
58876
58877
58878
58879
58880
58881
58882
58883
58884
58885
58886
58887
58888
58889
58890
58891
58892
58893
58894
58895
58896
58897
58898
58899
58900
58901
58902
58903
58904
58905
58906
58907
58908
58909
58910
58911
58912
58913
58914
58915
58916
58917
58918
58919
58920
58921
58922
58923
58924
58925
58926
58927
58928
58929
58930
58931
58932
58933
58934
58935
58936
58937
58938
58939
58940
58941
58942
58943
58944
58945
58946
58947
58948
58949
58950
58951
58952
58953
58954
58955
58956
58957
58958
58959
58960
58961
58962
58963
58964
58965
58966
58967
58968
58969
58970
58971
58972
58973
58974
58975
58976
58977
58978
58979
58980
58981
58982
58983
58984
58985
58986
58987
58988
58989
58990
58991
58992
58993
58994
58995
58996
58997
58998
58999
59000
59001
59002
59003
59004
59005
59006
59007
59008
59009
59010
59011
59012
59013
59014
59015
59016
59017
59018
59019
59020
59021
59022
59023
59024
59025
59026
59027
59028
59029
59030
59031
59032
59033
59034
59035
59036
59037
59038
59039
59040
59041
59042
59043
59044
59045
59046
59047
59048
59049
59050
59051
59052
59053
59054
59055
59056
59057
59058
59059
59060
59061
59062
59063
59064
59065
59066
59067
59068
59069
59070
59071
59072
59073
59074
59075
59076
59077
59078
59079
59080
59081
59082
59083
59084
59085
59086
59087
59088
59089
59090
59091
59092
59093
59094
59095
59096
59097
59098
59099
59100
59101
59102
59103
59104
59105
59106
59107
59108
59109
59110
59111
59112
59113
59114
59115
59116
59117
59118
59119
59120
59121
59122
59123
59124
59125
59126
59127
59128
59129
59130
59131
59132
59133
59134
59135
59136
59137
59138
59139
59140
59141
59142
59143
59144
59145
59146
59147
59148
59149
59150
59151
59152
59153
59154
59155
59156
59157
59158
59159
59160
59161
59162
59163
59164
59165
59166
59167
59168
59169
59170
59171
59172
59173
59174
59175
59176
59177
59178
59179
59180
59181
59182
59183
59184
59185
59186
59187
59188
59189
59190
59191
59192
59193
59194
59195
59196
59197
59198
59199
59200
59201
59202
59203
59204
59205
59206
59207
59208
59209
59210
59211
59212
59213
59214
59215
59216
59217
59218
59219
59220
59221
59222
59223
59224
59225
59226
59227
59228
59229
59230
59231
59232
59233
59234
59235
59236
59237
59238
59239
59240
59241
59242
59243
59244
59245
59246
59247
59248
59249
59250
59251
59252
59253
59254
59255
59256
59257
59258
59259
59260
59261
59262
59263
59264
59265
59266
59267
59268
59269
59270
59271
59272
59273
59274
59275
59276
59277
59278
59279
59280
59281
59282
59283
59284
59285
59286
59287
59288
59289
59290
59291
59292
59293
59294
59295
59296
59297
59298
59299
59300
59301
59302
59303
59304
59305
59306
59307
59308
59309
59310
59311
59312
59313
59314
59315
59316
59317
59318
59319
59320
59321
59322
59323
59324
59325
59326
59327
59328
59329
59330
59331
59332
59333
59334
59335
59336
59337
59338
59339
59340
59341
59342
59343
59344
59345
59346
59347
59348
59349
59350
59351
59352
59353
59354
59355
59356
59357
59358
59359
59360
59361
59362
59363
59364
59365
59366
59367
59368
59369
59370
59371
59372
59373
59374
59375
59376
59377
59378
59379
59380
59381
59382
59383
59384
59385
59386
59387
59388
59389
59390
59391
59392
59393
59394
59395
59396
59397
59398
59399
59400
59401
59402
59403
59404
59405
59406
59407
59408
59409
59410
59411
59412
59413
59414
59415
59416
59417
59418
59419
59420
59421
59422
59423
59424
59425
59426
59427
59428
59429
59430
59431
59432
59433
59434
59435
59436
59437
59438
59439
59440
59441
59442
59443
59444
59445
59446
59447
59448
59449
59450
59451
59452
59453
59454
59455
59456
59457
59458
59459
59460
59461
59462
59463
59464
59465
59466
59467
59468
59469
59470
59471
59472
59473
59474
59475
59476
59477
59478
59479
59480
59481
59482
59483
59484
59485
59486
59487
59488
59489
59490
59491
59492
59493
59494
59495
59496
59497
59498
59499
59500
59501
59502
59503
59504
59505
59506
59507
59508
59509
59510
59511
59512
59513
59514
59515
59516
59517
59518
59519
59520
59521
59522
59523
59524
59525
59526
59527
59528
59529
59530
59531
59532
59533
59534
59535
59536
59537
59538
59539
59540
59541
59542
59543
59544
59545
59546
59547
59548
59549
59550
59551
59552
59553
59554
59555
59556
59557
59558
59559
59560
59561
59562
59563
59564
59565
59566
59567
59568
59569
59570
59571
59572
59573
59574
59575
59576
59577
59578
59579
59580
59581
59582
59583
59584
59585
59586
59587
59588
59589
59590
59591
59592
59593
59594
59595
59596
59597
59598
59599
59600
59601
59602
59603
59604
59605
59606
59607
59608
59609
59610
59611
59612
59613
59614
59615
59616
59617
59618
59619
59620
59621
59622
59623
59624
59625
59626
59627
59628
59629
59630
59631
59632
59633
59634
59635
59636
59637
59638
59639
59640
59641
59642
59643
59644
59645
59646
59647
59648
59649
59650
59651
59652
59653
59654
59655
59656
59657
59658
59659
59660
59661
59662
59663
59664
59665
59666
59667
59668
59669
59670
59671
59672
59673
59674
59675
59676
59677
59678
59679
59680
59681
59682
59683
59684
59685
59686
59687
59688
59689
59690
59691
59692
59693
59694
59695
59696
59697
59698
59699
59700
59701
59702
59703
59704
59705
59706
59707
59708
59709
59710
59711
59712
59713
59714
59715
59716
59717
59718
59719
59720
59721
59722
59723
59724
59725
59726
59727
59728
59729
59730
59731
59732
59733
59734
59735
59736
59737
59738
59739
59740
59741
59742
59743
59744
59745
59746
59747
59748
59749
59750
59751
59752
59753
59754
59755
59756
59757
59758
59759
59760
59761
59762
59763
59764
59765
59766
59767
59768
59769
59770
59771
59772
59773
59774
59775
59776
59777
59778
59779
59780
59781
59782
59783
59784
59785
59786
59787
59788
59789
59790
59791
59792
59793
59794
59795
59796
59797
59798
59799
59800
59801
59802
59803
59804
59805
59806
59807
59808
59809
59810
59811
59812
59813
59814
59815
59816
59817
59818
59819
59820
59821
59822
59823
59824
59825
59826
59827
59828
59829
59830
59831
59832
59833
59834
59835
59836
59837
59838
59839
59840
59841
59842
59843
59844
59845
59846
59847
59848
59849
59850
59851
59852
59853
59854
59855
59856
59857
59858
59859
59860
59861
59862
59863
59864
59865
59866
59867
59868
59869
59870
59871
59872
59873
59874
59875
59876
59877
59878
59879
59880
59881
59882
59883
59884
59885
59886
59887
59888
59889
59890
59891
59892
59893
59894
59895
59896
59897
59898
59899
59900
59901
59902
59903
59904
59905
59906
59907
59908
59909
59910
59911
59912
59913
59914
59915
59916
59917
59918
59919
59920
59921
59922
59923
59924
59925
59926
59927
59928
59929
59930
59931
59932
59933
59934
59935
59936
59937
59938
59939
59940
59941
59942
59943
59944
59945
59946
59947
59948
59949
59950
59951
59952
59953
59954
59955
59956
59957
59958
59959
59960
59961
59962
59963
59964
59965
59966
59967
59968
59969
59970
59971
59972
59973
59974
59975
59976
59977
59978
59979
59980
59981
59982
59983
59984
59985
59986
59987
59988
59989
59990
59991
59992
59993
59994
59995
59996
59997
59998
59999
60000
60001
60002
60003
60004
60005
60006
60007
60008
60009
60010
60011
60012
60013
60014
60015
60016
60017
60018
60019
60020
60021
60022
60023
60024
60025
60026
60027
60028
60029
60030
60031
60032
60033
60034
60035
60036
60037
60038
60039
60040
60041
60042
60043
60044
60045
60046
60047
60048
60049
60050
60051
60052
60053
60054
60055
60056
60057
60058
60059
60060
60061
60062
60063
60064
60065
60066
60067
60068
60069
60070
60071
60072
60073
60074
60075
60076
60077
60078
60079
60080
60081
60082
60083
60084
60085
60086
60087
60088
60089
60090
60091
60092
60093
60094
60095
60096
60097
60098
60099
60100
60101
60102
60103
60104
60105
60106
60107
60108
60109
60110
60111
60112
60113
60114
60115
60116
60117
60118
60119
60120
60121
60122
60123
60124
60125
60126
60127
60128
60129
60130
60131
60132
60133
60134
60135
60136
60137
60138
60139
60140
60141
60142
60143
60144
60145
60146
60147
60148
60149
60150
60151
60152
60153
60154
60155
60156
60157
60158
60159
60160
60161
60162
60163
60164
60165
60166
60167
60168
60169
60170
60171
60172
60173
60174
60175
60176
60177
60178
60179
60180
60181
60182
60183
60184
60185
60186
60187
60188
60189
60190
60191
60192
60193
60194
60195
60196
60197
60198
60199
60200
60201
60202
60203
60204
60205
60206
60207
60208
60209
60210
60211
60212
60213
60214
60215
60216
60217
60218
60219
60220
60221
60222
60223
60224
60225
60226
60227
60228
60229
60230
60231
60232
60233
60234
60235
60236
60237
60238
60239
60240
60241
60242
60243
60244
60245
60246
60247
60248
60249
60250
60251
60252
60253
60254
60255
60256
60257
60258
60259
60260
60261
60262
60263
60264
60265
60266
60267
60268
60269
60270
60271
60272
60273
60274
60275
60276
60277
60278
60279
60280
60281
60282
60283
60284
60285
60286
60287
60288
60289
60290
60291
60292
60293
60294
60295
60296
60297
60298
60299
60300
60301
60302
60303
60304
60305
60306
60307
60308
60309
60310
60311
60312
60313
60314
60315
60316
60317
60318
60319
60320
60321
60322
60323
60324
60325
60326
60327
60328
60329
60330
60331
60332
60333
60334
60335
60336
60337
60338
60339
60340
60341
60342
60343
60344
60345
60346
60347
60348
60349
60350
60351
60352
60353
60354
60355
60356
60357
60358
60359
60360
60361
60362
60363
60364
60365
60366
60367
60368
60369
60370
60371
60372
60373
60374
60375
60376
60377
60378
60379
60380
60381
60382
60383
60384
60385
60386
60387
60388
60389
60390
60391
60392
60393
60394
60395
60396
60397
60398
60399
60400
60401
60402
60403
60404
60405
60406
60407
60408
60409
60410
60411
60412
60413
60414
60415
60416
60417
60418
60419
60420
60421
60422
60423
60424
60425
60426
60427
60428
60429
60430
60431
60432
60433
60434
60435
60436
60437
60438
60439
60440
60441
60442
60443
60444
60445
60446
60447
60448
60449
60450
60451
60452
60453
60454
60455
60456
60457
60458
60459
60460
60461
60462
60463
60464
60465
60466
60467
60468
60469
60470
60471
60472
60473
60474
60475
60476
60477
60478
60479
60480
60481
60482
60483
60484
60485
60486
60487
60488
60489
60490
60491
60492
60493
60494
60495
60496
60497
60498
60499
60500
60501
60502
60503
60504
60505
60506
60507
60508
60509
60510
60511
60512
60513
60514
60515
60516
60517
60518
60519
60520
60521
60522
60523
60524
60525
60526
60527
60528
60529
60530
60531
60532
60533
60534
60535
60536
60537
60538
60539
60540
60541
60542
60543
60544
60545
60546
60547
60548
60549
60550
60551
60552
60553
60554
60555
60556
60557
60558
60559
60560
60561
60562
60563
60564
60565
60566
60567
60568
60569
60570
60571
60572
60573
60574
60575
60576
60577
60578
60579
60580
60581
60582
60583
60584
60585
60586
60587
60588
60589
60590
60591
60592
60593
60594
60595
60596
60597
60598
60599
60600
60601
60602
60603
60604
60605
60606
60607
60608
60609
60610
60611
60612
60613
60614
60615
60616
60617
60618
60619
60620
60621
60622
60623
60624
60625
60626
60627
60628
60629
60630
60631
60632
60633
60634
60635
60636
60637
60638
60639
60640
60641
60642
60643
60644
60645
60646
60647
60648
60649
60650
60651
60652
60653
60654
60655
60656
60657
60658
60659
60660
60661
60662
60663
60664
60665
60666
60667
60668
60669
60670
60671
60672
60673
60674
60675
60676
60677
60678
60679
60680
60681
60682
60683
60684
60685
60686
60687
60688
60689
60690
60691
60692
60693
60694
60695
60696
60697
60698
60699
60700
60701
60702
60703
60704
60705
60706
60707
60708
60709
60710
60711
60712
60713
60714
60715
60716
60717
60718
60719
60720
60721
60722
60723
60724
60725
60726
60727
60728
60729
60730
60731
60732
60733
60734
60735
60736
60737
60738
60739
60740
60741
60742
60743
60744
60745
60746
60747
60748
60749
60750
60751
60752
60753
60754
60755
60756
60757
60758
60759
60760
60761
60762
60763
60764
60765
60766
60767
60768
60769
60770
60771
60772
60773
60774
60775
60776
60777
60778
60779
60780
60781
60782
60783
60784
60785
60786
60787
60788
60789
60790
60791
60792
60793
60794
60795
60796
60797
60798
60799
60800
60801
60802
60803
60804
60805
60806
60807
60808
60809
60810
60811
60812
60813
60814
60815
60816
60817
60818
60819
60820
60821
60822
60823
60824
60825
60826
60827
60828
60829
60830
60831
60832
60833
60834
60835
60836
60837
60838
60839
60840
60841
60842
60843
60844
60845
60846
60847
60848
60849
60850
60851
60852
60853
60854
60855
60856
60857
60858
60859
60860
60861
60862
60863
60864
60865
60866
60867
60868
60869
60870
60871
60872
60873
60874
60875
60876
60877
60878
60879
60880
60881
60882
60883
60884
60885
60886
60887
60888
60889
60890
60891
60892
60893
60894
60895
60896
60897
60898
60899
60900
60901
60902
60903
60904
60905
60906
60907
60908
60909
60910
60911
60912
60913
60914
60915
60916
60917
60918
60919
60920
60921
60922
60923
60924
60925
60926
60927
60928
60929
60930
60931
60932
60933
60934
60935
60936
60937
60938
60939
60940
60941
60942
60943
60944
60945
60946
60947
60948
60949
60950
60951
60952
60953
60954
60955
60956
60957
60958
60959
60960
60961
60962
60963
60964
60965
60966
60967
60968
60969
60970
60971
60972
60973
60974
60975
60976
60977
60978
60979
60980
60981
60982
60983
60984
60985
60986
60987
60988
60989
60990
60991
60992
60993
60994
60995
60996
60997
60998
60999
61000
61001
61002
61003
61004
61005
61006
61007
61008
61009
61010
61011
61012
61013
61014
61015
61016
61017
61018
61019
61020
61021
61022
61023
61024
61025
61026
61027
61028
61029
61030
61031
61032
61033
61034
61035
61036
61037
61038
61039
61040
61041
61042
61043
61044
61045
61046
61047
61048
61049
61050
61051
61052
61053
61054
61055
61056
61057
61058
61059
61060
61061
61062
61063
61064
61065
61066
61067
61068
61069
61070
61071
61072
61073
61074
61075
61076
61077
61078
61079
61080
61081
61082
61083
61084
61085
61086
61087
61088
61089
61090
61091
61092
61093
61094
61095
61096
61097
61098
61099
61100
61101
61102
61103
61104
61105
61106
61107
61108
61109
61110
61111
61112
61113
61114
61115
61116
61117
61118
61119
61120
61121
61122
61123
61124
61125
61126
61127
61128
61129
61130
61131
61132
61133
61134
61135
61136
61137
61138
61139
61140
61141
61142
61143
61144
61145
61146
61147
61148
61149
61150
61151
61152
61153
61154
61155
61156
61157
61158
61159
61160
61161
61162
61163
61164
61165
61166
61167
61168
61169
61170
61171
61172
61173
61174
61175
61176
61177
61178
61179
61180
61181
61182
61183
61184
61185
61186
61187
61188
61189
61190
61191
61192
61193
61194
61195
61196
61197
61198
61199
61200
61201
61202
61203
61204
61205
61206
61207
61208
61209
61210
61211
61212
61213
61214
61215
61216
61217
61218
61219
61220
61221
61222
61223
61224
61225
61226
61227
61228
61229
61230
61231
61232
61233
61234
61235
61236
61237
61238
61239
61240
61241
61242
61243
61244
61245
61246
61247
61248
61249
61250
61251
61252
61253
61254
61255
61256
61257
61258
61259
61260
61261
61262
61263
61264
61265
61266
61267
61268
61269
61270
61271
61272
61273
61274
61275
61276
61277
61278
61279
61280
61281
61282
61283
61284
61285
61286
61287
61288
61289
61290
61291
61292
61293
61294
61295
61296
61297
61298
61299
61300
61301
61302
61303
61304
61305
61306
61307
61308
61309
61310
61311
61312
61313
61314
61315
61316
61317
61318
61319
61320
61321
61322
61323
61324
61325
61326
61327
61328
61329
61330
61331
61332
61333
61334
61335
61336
61337
61338
61339
61340
61341
61342
61343
61344
61345
61346
61347
61348
61349
61350
61351
61352
61353
61354
61355
61356
61357
61358
61359
61360
61361
61362
61363
61364
61365
61366
61367
61368
61369
61370
61371
61372
61373
61374
61375
61376
61377
61378
61379
61380
61381
61382
61383
61384
61385
61386
61387
61388
61389
61390
61391
61392
61393
61394
61395
61396
61397
61398
61399
61400
61401
61402
61403
61404
61405
61406
61407
61408
61409
61410
61411
61412
61413
61414
61415
61416
61417
61418
61419
61420
61421
61422
61423
61424
61425
61426
61427
61428
61429
61430
61431
61432
61433
61434
61435
61436
61437
61438
61439
61440
61441
61442
61443
61444
61445
61446
61447
61448
61449
61450
61451
61452
61453
61454
61455
61456
61457
61458
61459
61460
61461
61462
61463
61464
61465
61466
61467
61468
61469
61470
61471
61472
61473
61474
61475
61476
61477
61478
61479
61480
61481
61482
61483
61484
61485
61486
61487
61488
61489
61490
61491
61492
61493
61494
61495
61496
61497
61498
61499
61500
61501
61502
61503
61504
61505
61506
61507
61508
61509
61510
61511
61512
61513
61514
61515
61516
61517
61518
61519
61520
61521
61522
61523
61524
61525
61526
61527
61528
61529
61530
61531
61532
61533
61534
61535
61536
61537
61538
61539
61540
61541
61542
61543
61544
61545
61546
61547
61548
61549
61550
61551
61552
61553
61554
61555
61556
61557
61558
61559
61560
61561
61562
61563
61564
61565
61566
61567
61568
61569
61570
61571
61572
61573
61574
61575
61576
61577
61578
61579
61580
61581
61582
61583
61584
61585
61586
61587
61588
61589
61590
61591
61592
61593
61594
61595
61596
61597
61598
61599
61600
61601
61602
61603
61604
61605
61606
61607
61608
61609
61610
61611
61612
61613
61614
61615
61616
61617
61618
61619
61620
61621
61622
61623
61624
61625
61626
61627
61628
61629
61630
61631
61632
61633
61634
61635
61636
61637
61638
61639
61640
61641
61642
61643
61644
61645
61646
61647
61648
61649
61650
61651
61652
61653
61654
61655
61656
61657
61658
61659
61660
61661
61662
61663
61664
61665
61666
61667
61668
61669
61670
61671
61672
61673
61674
61675
61676
61677
61678
61679
61680
61681
61682
61683
61684
61685
61686
61687
61688
61689
61690
61691
61692
61693
61694
61695
61696
61697
61698
61699
61700
61701
61702
61703
61704
61705
61706
61707
61708
61709
61710
61711
61712
61713
61714
61715
61716
61717
61718
61719
61720
61721
61722
61723
61724
61725
61726
61727
61728
61729
61730
61731
61732
61733
61734
61735
61736
61737
61738
61739
61740
61741
61742
61743
61744
61745
61746
61747
61748
61749
61750
61751
61752
61753
61754
61755
61756
61757
61758
61759
61760
61761
61762
61763
61764
61765
61766
61767
61768
61769
61770
61771
61772
61773
61774
61775
61776
61777
61778
61779
61780
61781
61782
61783
61784
61785
61786
61787
61788
61789
61790
61791
61792
61793
61794
61795
61796
61797
61798
61799
61800
61801
61802
61803
61804
61805
61806
61807
61808
61809
61810
61811
61812
61813
61814
61815
61816
61817
61818
61819
61820
61821
61822
61823
61824
61825
61826
61827
61828
61829
61830
61831
61832
61833
61834
61835
61836
61837
61838
61839
61840
61841
61842
61843
61844
61845
61846
61847
61848
61849
61850
61851
61852
61853
61854
61855
61856
61857
61858
61859
61860
61861
61862
61863
61864
61865
61866
61867
61868
61869
61870
61871
61872
61873
61874
61875
61876
61877
61878
61879
61880
61881
61882
61883
61884
61885
61886
61887
61888
61889
61890
61891
61892
61893
61894
61895
61896
61897
61898
61899
61900
61901
61902
61903
61904
61905
61906
61907
61908
61909
61910
61911
61912
61913
61914
61915
61916
61917
61918
61919
61920
61921
61922
61923
61924
61925
61926
61927
61928
61929
61930
61931
61932
61933
61934
61935
61936
61937
61938
61939
61940
61941
61942
61943
61944
61945
61946
61947
61948
61949
61950
61951
61952
61953
61954
61955
61956
61957
61958
61959
61960
61961
61962
61963
61964
61965
61966
61967
61968
61969
61970
61971
61972
61973
61974
61975
61976
61977
61978
61979
61980
61981
61982
61983
61984
61985
61986
61987
61988
61989
61990
61991
61992
61993
61994
61995
61996
61997
61998
61999
62000
62001
62002
62003
62004
62005
62006
62007
62008
62009
62010
62011
62012
62013
62014
62015
62016
62017
62018
62019
62020
62021
62022
62023
62024
62025
62026
62027
62028
62029
62030
62031
62032
62033
62034
62035
62036
62037
62038
62039
62040
62041
62042
62043
62044
62045
62046
62047
62048
62049
62050
62051
62052
62053
62054
62055
62056
62057
62058
62059
62060
62061
62062
62063
62064
62065
62066
62067
62068
62069
62070
62071
62072
62073
62074
62075
62076
62077
62078
62079
62080
62081
62082
62083
62084
62085
62086
62087
62088
62089
62090
62091
62092
62093
62094
62095
62096
62097
62098
62099
62100
62101
62102
62103
62104
62105
62106
62107
62108
62109
62110
62111
62112
62113
62114
62115
62116
62117
62118
62119
62120
62121
62122
62123
62124
62125
62126
62127
62128
62129
62130
62131
62132
62133
62134
62135
62136
62137
62138
62139
62140
62141
62142
62143
62144
62145
62146
62147
62148
62149
62150
62151
62152
62153
62154
62155
62156
62157
62158
62159
62160
62161
62162
62163
62164
62165
62166
62167
62168
62169
62170
62171
62172
62173
62174
62175
62176
62177
62178
62179
62180
62181
62182
62183
62184
62185
62186
62187
62188
62189
62190
62191
62192
62193
62194
62195
62196
62197
62198
62199
62200
62201
62202
62203
62204
62205
62206
62207
62208
62209
62210
62211
62212
62213
62214
62215
62216
62217
62218
62219
62220
62221
62222
62223
62224
62225
62226
62227
62228
62229
62230
62231
62232
62233
62234
62235
62236
62237
62238
62239
62240
62241
62242
62243
62244
62245
62246
62247
62248
62249
62250
62251
62252
62253
62254
62255
62256
62257
62258
62259
62260
62261
62262
62263
62264
62265
62266
62267
62268
62269
62270
62271
62272
62273
62274
62275
62276
62277
62278
62279
62280
62281
62282
62283
62284
62285
62286
62287
62288
62289
62290
62291
62292
62293
62294
62295
62296
62297
62298
62299
62300
62301
62302
62303
62304
62305
62306
62307
62308
62309
62310
62311
62312
62313
62314
62315
62316
62317
62318
62319
62320
62321
62322
62323
62324
62325
62326
62327
62328
62329
62330
62331
62332
62333
62334
62335
62336
62337
62338
62339
62340
62341
62342
62343
62344
62345
62346
62347
62348
62349
62350
62351
62352
62353
62354
62355
62356
62357
62358
62359
62360
62361
62362
62363
62364
62365
62366
62367
62368
62369
62370
62371
62372
62373
62374
62375
62376
62377
62378
62379
62380
62381
62382
62383
62384
62385
62386
62387
62388
62389
62390
62391
62392
62393
62394
62395
62396
62397
62398
62399
62400
62401
62402
62403
62404
62405
62406
62407
62408
62409
62410
62411
62412
62413
62414
62415
62416
62417
62418
62419
62420
62421
62422
62423
62424
62425
62426
62427
62428
62429
62430
62431
62432
62433
62434
62435
62436
62437
62438
62439
62440
62441
62442
62443
62444
62445
62446
62447
62448
62449
62450
62451
62452
62453
62454
62455
62456
62457
62458
62459
62460
62461
62462
62463
62464
62465
62466
62467
62468
62469
62470
62471
62472
62473
62474
62475
62476
62477
62478
62479
62480
62481
62482
62483
62484
62485
62486
62487
62488
62489
62490
62491
62492
62493
62494
62495
62496
62497
62498
62499
62500
62501
62502
62503
62504
62505
62506
62507
62508
62509
62510
62511
62512
62513
62514
62515
62516
62517
62518
62519
62520
62521
62522
62523
62524
62525
62526
62527
62528
62529
62530
62531
62532
62533
62534
62535
62536
62537
62538
62539
62540
62541
62542
62543
62544
62545
62546
62547
62548
62549
62550
62551
62552
62553
62554
62555
62556
62557
62558
62559
62560
62561
62562
62563
62564
62565
62566
62567
62568
62569
62570
62571
62572
62573
62574
62575
62576
62577
62578
62579
62580
62581
62582
62583
62584
62585
62586
62587
62588
62589
62590
62591
62592
62593
62594
62595
62596
62597
62598
62599
62600
62601
62602
62603
62604
62605
62606
62607
62608
62609
62610
62611
62612
62613
62614
62615
62616
62617
62618
62619
62620
62621
62622
62623
62624
62625
62626
62627
62628
62629
62630
62631
62632
62633
62634
62635
62636
62637
62638
62639
62640
62641
62642
62643
62644
62645
62646
62647
62648
62649
62650
62651
62652
62653
62654
62655
62656
62657
62658
62659
62660
62661
62662
62663
62664
62665
62666
62667
62668
62669
62670
62671
62672
62673
62674
62675
62676
62677
62678
62679
62680
62681
62682
62683
62684
62685
62686
62687
62688
62689
62690
62691
62692
62693
62694
62695
62696
62697
62698
62699
62700
62701
62702
62703
62704
62705
62706
62707
62708
62709
62710
62711
62712
62713
62714
62715
62716
62717
62718
62719
62720
62721
62722
62723
62724
62725
62726
62727
62728
62729
62730
62731
62732
62733
62734
62735
62736
62737
62738
62739
62740
62741
62742
62743
62744
62745
62746
62747
62748
62749
62750
62751
62752
62753
62754
62755
62756
62757
62758
62759
62760
62761
62762
62763
62764
62765
62766
62767
62768
62769
62770
62771
62772
62773
62774
62775
62776
62777
62778
62779
62780
62781
62782
62783
62784
62785
62786
62787
62788
62789
62790
62791
62792
62793
62794
62795
62796
62797
62798
62799
62800
62801
62802
62803
62804
62805
62806
62807
62808
62809
62810
62811
62812
62813
62814
62815
62816
62817
62818
62819
62820
62821
62822
62823
62824
62825
62826
62827
62828
62829
62830
62831
62832
62833
62834
62835
62836
62837
62838
62839
62840
62841
62842
62843
62844
62845
62846
62847
62848
62849
62850
62851
62852
62853
62854
62855
62856
62857
62858
62859
62860
62861
62862
62863
62864
62865
62866
62867
62868
62869
62870
62871
62872
62873
62874
62875
62876
62877
62878
62879
62880
62881
62882
62883
62884
62885
62886
62887
62888
62889
62890
62891
62892
62893
62894
62895
62896
62897
62898
62899
62900
62901
62902
62903
62904
62905
62906
62907
62908
62909
62910
62911
62912
62913
62914
62915
62916
62917
62918
62919
62920
62921
62922
62923
62924
62925
62926
62927
62928
62929
62930
62931
62932
62933
62934
62935
62936
62937
62938
62939
62940
62941
62942
62943
62944
62945
62946
62947
62948
62949
62950
62951
62952
62953
62954
62955
62956
62957
62958
62959
62960
62961
62962
62963
62964
62965
62966
62967
62968
62969
62970
62971
62972
62973
62974
62975
62976
62977
62978
62979
62980
62981
62982
62983
62984
62985
62986
62987
62988
62989
62990
62991
62992
62993
62994
62995
62996
62997
62998
62999
63000
63001
63002
63003
63004
63005
63006
63007
63008
63009
63010
63011
63012
63013
63014
63015
63016
63017
63018
63019
63020
63021
63022
63023
63024
63025
63026
63027
63028
63029
63030
63031
63032
63033
63034
63035
63036
63037
63038
63039
63040
63041
63042
63043
63044
63045
63046
63047
63048
63049
63050
63051
63052
63053
63054
63055
63056
63057
63058
63059
63060
63061
63062
63063
63064
63065
63066
63067
63068
63069
63070
63071
63072
63073
63074
63075
63076
63077
63078
63079
63080
63081
63082
63083
63084
63085
63086
63087
63088
63089
63090
63091
63092
63093
63094
63095
63096
63097
63098
63099
63100
63101
63102
63103
63104
63105
63106
63107
63108
63109
63110
63111
63112
63113
63114
63115
63116
63117
63118
63119
63120
63121
63122
63123
63124
63125
63126
63127
63128
63129
63130
63131
63132
63133
63134
63135
63136
63137
63138
63139
63140
63141
63142
63143
63144
63145
63146
63147
63148
63149
63150
63151
63152
63153
63154
63155
63156
63157
63158
63159
63160
63161
63162
63163
63164
63165
63166
63167
63168
63169
63170
63171
63172
63173
63174
63175
63176
63177
63178
63179
63180
63181
63182
63183
63184
63185
63186
63187
63188
63189
63190
63191
63192
63193
63194
63195
63196
63197
63198
63199
63200
63201
63202
63203
63204
63205
63206
63207
63208
63209
63210
63211
63212
63213
63214
63215
63216
63217
63218
63219
63220
63221
63222
63223
63224
63225
63226
63227
63228
63229
63230
63231
63232
63233
63234
63235
63236
63237
63238
63239
63240
63241
63242
63243
63244
63245
63246
63247
63248
63249
63250
63251
63252
63253
63254
63255
63256
63257
63258
63259
63260
63261
63262
63263
63264
63265
63266
63267
63268
63269
63270
63271
63272
63273
63274
63275
63276
63277
63278
63279
63280
63281
63282
63283
63284
63285
63286
63287
63288
63289
63290
63291
63292
63293
63294
63295
63296
63297
63298
63299
63300
63301
63302
63303
63304
63305
63306
63307
63308
63309
63310
63311
63312
63313
63314
63315
63316
63317
63318
63319
63320
63321
63322
63323
63324
63325
63326
63327
63328
63329
63330
63331
63332
63333
63334
63335
63336
63337
63338
63339
63340
63341
63342
63343
63344
63345
63346
63347
63348
63349
63350
63351
63352
63353
63354
63355
63356
63357
63358
63359
63360
63361
63362
63363
63364
63365
63366
63367
63368
63369
63370
63371
63372
63373
63374
63375
63376
63377
63378
63379
63380
63381
63382
63383
63384
63385
63386
63387
63388
63389
63390
63391
63392
63393
63394
63395
63396
63397
63398
63399
63400
63401
63402
63403
63404
63405
63406
63407
63408
63409
63410
63411
63412
63413
63414
63415
63416
63417
63418
63419
63420
63421
63422
63423
63424
63425
63426
63427
63428
63429
63430
63431
63432
63433
63434
63435
63436
63437
63438
63439
63440
63441
63442
63443
63444
63445
63446
63447
63448
63449
63450
63451
63452
63453
63454
63455
63456
63457
63458
63459
63460
63461
63462
63463
63464
63465
63466
63467
63468
63469
63470
63471
63472
63473
63474
63475
63476
63477
63478
63479
63480
63481
63482
63483
63484
63485
63486
63487
63488
63489
63490
63491
63492
63493
63494
63495
63496
63497
63498
63499
63500
63501
63502
63503
63504
63505
63506
63507
63508
63509
63510
63511
63512
63513
63514
63515
63516
63517
63518
63519
63520
63521
63522
63523
63524
63525
63526
63527
63528
63529
63530
63531
63532
63533
63534
63535
63536
63537
63538
63539
63540
63541
63542
63543
63544
63545
63546
63547
63548
63549
63550
63551
63552
63553
63554
63555
63556
63557
63558
63559
63560
63561
63562
63563
63564
63565
63566
63567
63568
63569
63570
63571
63572
63573
63574
63575
63576
63577
63578
63579
63580
63581
63582
63583
63584
63585
63586
63587
63588
63589
63590
63591
63592
63593
63594
63595
63596
63597
63598
63599
63600
63601
63602
63603
63604
63605
63606
63607
63608
63609
63610
63611
63612
63613
63614
63615
63616
63617
63618
63619
63620
63621
63622
63623
63624
63625
63626
63627
63628
63629
63630
63631
63632
63633
63634
63635
63636
63637
63638
63639
63640
63641
63642
63643
63644
63645
63646
63647
63648
63649
63650
63651
63652
63653
63654
63655
63656
63657
63658
63659
63660
63661
63662
63663
63664
63665
63666
63667
63668
63669
63670
63671
63672
63673
63674
63675
63676
63677
63678
63679
63680
63681
63682
63683
63684
63685
63686
63687
63688
63689
63690
63691
63692
63693
63694
63695
63696
63697
63698
63699
63700
63701
63702
63703
63704
63705
63706
63707
63708
63709
63710
63711
63712
63713
63714
63715
63716
63717
63718
63719
63720
63721
63722
63723
63724
63725
63726
63727
63728
63729
63730
63731
63732
63733
63734
63735
63736
63737
63738
63739
63740
63741
63742
63743
63744
63745
63746
63747
63748
63749
63750
63751
63752
63753
63754
63755
63756
63757
63758
63759
63760
63761
63762
63763
63764
63765
63766
63767
63768
63769
63770
63771
63772
63773
63774
63775
63776
63777
63778
63779
63780
63781
63782
63783
63784
63785
63786
63787
63788
63789
63790
63791
63792
63793
63794
63795
63796
63797
63798
63799
63800
63801
63802
63803
63804
63805
63806
63807
63808
63809
63810
63811
63812
63813
63814
63815
63816
63817
63818
63819
63820
63821
63822
63823
63824
63825
63826
63827
63828
63829
63830
63831
63832
63833
63834
63835
63836
63837
63838
63839
63840
63841
63842
63843
63844
63845
63846
63847
63848
63849
63850
63851
63852
63853
63854
63855
63856
63857
63858
63859
63860
63861
63862
63863
63864
63865
63866
63867
63868
63869
63870
63871
63872
63873
63874
63875
63876
63877
63878
63879
63880
63881
63882
63883
63884
63885
63886
63887
63888
63889
63890
63891
63892
63893
63894
63895
63896
63897
63898
63899
63900
63901
63902
63903
63904
63905
63906
63907
63908
63909
63910
63911
63912
63913
63914
63915
63916
63917
63918
63919
63920
63921
63922
63923
63924
63925
63926
63927
63928
63929
63930
63931
63932
63933
63934
63935
63936
63937
63938
63939
63940
63941
63942
63943
63944
63945
63946
63947
63948
63949
63950
63951
63952
63953
63954
63955
63956
63957
63958
63959
63960
63961
63962
63963
63964
63965
63966
63967
63968
63969
63970
63971
63972
63973
63974
63975
63976
63977
63978
63979
63980
63981
63982
63983
63984
63985
63986
63987
63988
63989
63990
63991
63992
63993
63994
63995
63996
63997
63998
63999
64000
64001
64002
64003
64004
64005
64006
64007
64008
64009
64010
64011
64012
64013
64014
64015
64016
64017
64018
64019
64020
64021
64022
64023
64024
64025
64026
64027
64028
64029
64030
64031
64032
64033
64034
64035
64036
64037
64038
64039
64040
64041
64042
64043
64044
64045
64046
64047
64048
64049
64050
64051
64052
64053
64054
64055
64056
64057
64058
64059
64060
64061
64062
64063
64064
64065
64066
64067
64068
64069
64070
64071
64072
64073
64074
64075
64076
64077
64078
64079
64080
64081
64082
64083
64084
64085
64086
64087
64088
64089
64090
64091
64092
64093
64094
64095
64096
64097
64098
64099
64100
64101
64102
64103
64104
64105
64106
64107
64108
64109
64110
64111
64112
64113
64114
64115
64116
64117
64118
64119
64120
64121
64122
64123
64124
64125
64126
64127
64128
64129
64130
64131
64132
64133
64134
64135
64136
64137
64138
64139
64140
64141
64142
64143
64144
64145
64146
64147
64148
64149
64150
64151
64152
64153
64154
64155
64156
64157
64158
64159
64160
64161
64162
64163
64164
64165
64166
64167
64168
64169
64170
64171
64172
64173
64174
64175
64176
64177
64178
64179
64180
64181
64182
64183
64184
64185
64186
64187
64188
64189
64190
64191
64192
64193
64194
64195
64196
64197
64198
64199
64200
64201
64202
64203
64204
64205
64206
64207
64208
64209
64210
64211
64212
64213
64214
64215
64216
64217
64218
64219
64220
64221
64222
64223
64224
64225
64226
64227
64228
64229
64230
64231
64232
64233
64234
64235
64236
64237
64238
64239
64240
64241
64242
64243
64244
64245
64246
64247
64248
64249
64250
64251
64252
64253
64254
64255
64256
64257
64258
64259
64260
64261
64262
64263
64264
64265
64266
64267
64268
64269
64270
64271
64272
64273
64274
64275
64276
64277
64278
64279
64280
64281
64282
64283
64284
64285
64286
64287
64288
64289
64290
64291
64292
64293
64294
64295
64296
64297
64298
64299
64300
64301
64302
64303
64304
64305
64306
64307
64308
64309
64310
64311
64312
64313
64314
64315
64316
64317
64318
64319
64320
64321
64322
64323
64324
64325
64326
64327
64328
64329
64330
64331
64332
64333
64334
64335
64336
64337
64338
64339
64340
64341
64342
64343
64344
64345
64346
64347
64348
64349
64350
64351
64352
64353
64354
64355
64356
64357
64358
64359
64360
64361
64362
64363
64364
64365
64366
64367
64368
64369
64370
64371
64372
64373
64374
64375
64376
64377
64378
64379
64380
64381
64382
64383
64384
64385
64386
64387
64388
64389
64390
64391
64392
64393
64394
64395
64396
64397
64398
64399
64400
64401
64402
64403
64404
64405
64406
64407
64408
64409
64410
64411
64412
64413
64414
64415
64416
64417
64418
64419
64420
64421
64422
64423
64424
64425
64426
64427
64428
64429
64430
64431
64432
64433
64434
64435
64436
64437
64438
64439
64440
64441
64442
64443
64444
64445
64446
64447
64448
64449
64450
64451
64452
64453
64454
64455
64456
64457
64458
64459
64460
64461
64462
64463
64464
64465
64466
64467
64468
64469
64470
64471
64472
64473
64474
64475
64476
64477
64478
64479
64480
64481
64482
64483
64484
64485
64486
64487
64488
64489
64490
64491
64492
64493
64494
64495
64496
64497
64498
64499
64500
64501
64502
64503
64504
64505
64506
64507
64508
64509
64510
64511
64512
64513
64514
64515
64516
64517
64518
64519
64520
64521
64522
64523
64524
64525
64526
64527
64528
64529
64530
64531
64532
64533
64534
64535
64536
64537
64538
64539
64540
64541
64542
64543
64544
64545
64546
64547
64548
64549
64550
64551
64552
64553
64554
64555
64556
64557
64558
64559
64560
64561
64562
64563
64564
64565
64566
64567
64568
64569
64570
64571
64572
64573
64574
64575
64576
64577
64578
64579
64580
64581
64582
64583
64584
64585
64586
64587
64588
64589
64590
64591
64592
64593
64594
64595
64596
64597
64598
64599
64600
64601
64602
64603
64604
64605
64606
64607
64608
64609
64610
64611
64612
64613
64614
64615
64616
64617
64618
64619
64620
64621
64622
64623
64624
64625
64626
64627
64628
64629
64630
64631
64632
64633
64634
64635
64636
64637
64638
64639
64640
64641
64642
64643
64644
64645
64646
64647
64648
64649
64650
64651
64652
64653
64654
64655
64656
64657
64658
64659
64660
64661
64662
64663
64664
64665
64666
64667
64668
64669
64670
64671
64672
64673
64674
64675
64676
64677
64678
64679
64680
64681
64682
64683
64684
64685
64686
64687
64688
64689
64690
64691
64692
64693
64694
64695
64696
64697
64698
64699
64700
64701
64702
64703
64704
64705
64706
64707
64708
64709
64710
64711
64712
64713
64714
64715
64716
64717
64718
64719
64720
64721
64722
64723
64724
64725
64726
64727
64728
64729
64730
64731
64732
64733
64734
64735
64736
64737
64738
64739
64740
64741
64742
64743
64744
64745
64746
64747
64748
64749
64750
64751
64752
64753
64754
64755
64756
64757
64758
64759
64760
64761
64762
64763
64764
64765
64766
64767
64768
64769
64770
64771
64772
64773
64774
64775
64776
64777
64778
64779
64780
64781
64782
64783
64784
64785
64786
64787
64788
64789
64790
64791
64792
64793
64794
64795
64796
64797
64798
64799
64800
64801
64802
64803
64804
64805
64806
64807
64808
64809
64810
64811
64812
64813
64814
64815
64816
64817
64818
64819
64820
64821
64822
64823
64824
64825
64826
64827
64828
64829
64830
64831
64832
64833
64834
64835
64836
64837
64838
64839
64840
64841
64842
64843
64844
64845
64846
64847
64848
64849
64850
64851
64852
64853
64854
64855
64856
64857
64858
64859
64860
64861
64862
64863
64864
64865
64866
64867
64868
64869
64870
64871
64872
64873
64874
64875
64876
64877
64878
64879
64880
64881
64882
64883
64884
64885
64886
64887
64888
64889
64890
64891
64892
64893
64894
64895
64896
64897
64898
64899
64900
64901
64902
64903
64904
64905
64906
64907
64908
64909
64910
64911
64912
64913
64914
64915
64916
64917
64918
64919
64920
64921
64922
64923
64924
64925
64926
64927
64928
64929
64930
64931
64932
64933
64934
64935
64936
64937
64938
64939
64940
64941
64942
64943
64944
64945
64946
64947
64948
64949
64950
64951
64952
64953
64954
64955
64956
64957
64958
64959
64960
64961
64962
64963
64964
64965
64966
64967
64968
64969
64970
64971
64972
64973
64974
64975
64976
64977
64978
64979
64980
64981
64982
64983
64984
64985
64986
64987
64988
64989
64990
64991
64992
64993
64994
64995
64996
64997
64998
64999
65000
65001
65002
65003
65004
65005
65006
65007
65008
65009
65010
65011
65012
65013
65014
65015
65016
65017
65018
65019
65020
65021
65022
65023
65024
65025
65026
65027
65028
65029
65030
65031
65032
65033
65034
65035
65036
65037
65038
65039
65040
65041
65042
65043
65044
65045
65046
65047
65048
65049
65050
65051
65052
65053
65054
65055
65056
65057
65058
65059
65060
65061
65062
65063
65064
65065
65066
65067
65068
65069
65070
65071
65072
65073
65074
65075
65076
65077
65078
65079
65080
65081
65082
65083
65084
65085
65086
65087
65088
65089
65090
65091
65092
65093
65094
65095
65096
65097
65098
65099
65100
65101
65102
65103
65104
65105
65106
65107
65108
65109
65110
65111
65112
65113
65114
65115
65116
65117
65118
65119
65120
65121
65122
65123
65124
65125
65126
65127
65128
65129
65130
65131
65132
65133
65134
65135
65136
65137
65138
65139
65140
65141
65142
65143
65144
65145
65146
65147
65148
65149
65150
65151
65152
65153
65154
65155
65156
65157
65158
65159
65160
65161
65162
65163
65164
65165
65166
65167
65168
65169
65170
65171
65172
65173
65174
65175
65176
65177
65178
65179
65180
65181
65182
65183
65184
65185
65186
65187
65188
65189
65190
65191
65192
65193
65194
65195
65196
65197
65198
65199
65200
65201
65202
65203
65204
65205
65206
65207
65208
65209
65210
65211
65212
65213
65214
65215
65216
65217
65218
65219
65220
65221
65222
65223
65224
65225
65226
65227
65228
65229
65230
65231
65232
65233
65234
65235
65236
65237
65238
65239
65240
65241
65242
65243
65244
65245
65246
65247
65248
65249
65250
65251
65252
65253
65254
65255
65256
65257
65258
65259
65260
65261
65262
65263
65264
65265
65266
65267
65268
65269
65270
65271
65272
65273
65274
65275
65276
65277
65278
65279
65280
65281
65282
65283
65284
65285
65286
65287
65288
65289
65290
65291
65292
65293
65294
65295
65296
65297
65298
65299
65300
65301
65302
65303
65304
65305
65306
65307
65308
65309
65310
65311
65312
65313
65314
65315
65316
65317
65318
65319
65320
65321
65322
65323
65324
65325
65326
65327
65328
65329
65330
65331
65332
65333
65334
65335
65336
65337
65338
65339
65340
65341
65342
65343
65344
65345
65346
65347
65348
65349
65350
65351
65352
65353
65354
65355
65356
65357
65358
65359
65360
65361
65362
65363
65364
65365
65366
65367
65368
65369
65370
65371
65372
65373
65374
65375
65376
65377
65378
65379
65380
65381
65382
65383
65384
65385
65386
65387
65388
65389
65390
65391
65392
65393
65394
65395
65396
65397
65398
65399
65400
65401
65402
65403
65404
65405
65406
65407
65408
65409
65410
65411
65412
65413
65414
65415
65416
65417
65418
65419
65420
65421
65422
65423
65424
65425
65426
65427
65428
65429
65430
65431
65432
65433
65434
65435
65436
65437
65438
65439
65440
65441
65442
65443
65444
65445
65446
65447
65448
65449
65450
65451
65452
65453
65454
65455
65456
65457
65458
65459
65460
65461
65462
65463
65464
65465
65466
65467
65468
65469
65470
65471
65472
65473
65474
65475
65476
65477
65478
65479
65480
65481
65482
65483
65484
65485
65486
65487
65488
65489
65490
65491
65492
65493
65494
65495
65496
65497
65498
65499
65500
65501
65502
65503
65504
65505
65506
65507
65508
65509
65510
65511
65512
65513
65514
65515
65516
65517
65518
65519
65520
65521
65522
65523
65524
65525
65526
65527
65528
65529
65530
65531
65532
65533
65534
65535
65536
65537
65538
65539
65540
65541
65542
65543
65544
65545
65546
65547
65548
65549
65550
65551
65552
65553
65554
65555
65556
65557
65558
65559
65560
65561
65562
65563
65564
65565
65566
65567
65568
65569
65570
65571
65572
65573
65574
65575
65576
65577
65578
65579
65580
65581
65582
65583
65584
65585
65586
65587
65588
65589
65590
65591
65592
65593
65594
65595
65596
65597
65598
65599
65600
65601
65602
65603
65604
65605
65606
65607
65608
65609
65610
65611
65612
65613
65614
65615
65616
65617
65618
65619
65620
65621
65622
65623
65624
65625
65626
65627
65628
65629
65630
65631
65632
65633
65634
65635
65636
65637
65638
65639
65640
65641
65642
65643
65644
65645
65646
65647
65648
65649
65650
65651
65652
65653
65654
65655
65656
65657
65658
65659
65660
65661
65662
65663
65664
65665
65666
65667
65668
65669
65670
65671
65672
65673
65674
65675
65676
65677
65678
65679
65680
65681
65682
65683
65684
65685
65686
65687
65688
65689
65690
65691
65692
65693
65694
65695
65696
65697
65698
65699
65700
65701
65702
65703
65704
65705
65706
65707
65708
65709
65710
65711
65712
65713
65714
65715
65716
65717
65718
65719
65720
65721
65722
65723
65724
65725
65726
65727
65728
65729
65730
65731
65732
65733
65734
65735
65736
65737
65738
65739
65740
65741
65742
65743
65744
65745
65746
65747
65748
65749
65750
65751
65752
65753
65754
65755
65756
65757
65758
65759
65760
65761
65762
65763
65764
65765
65766
65767
65768
65769
65770
65771
65772
65773
65774
65775
65776
65777
65778
65779
65780
65781
65782
65783
65784
65785
65786
65787
65788
65789
65790
65791
65792
65793
65794
65795
65796
65797
65798
65799
65800
65801
65802
65803
65804
65805
65806
65807
65808
65809
65810
65811
65812
65813
65814
65815
65816
65817
65818
65819
65820
65821
65822
65823
65824
65825
65826
65827
65828
65829
65830
65831
65832
65833
65834
65835
65836
65837
65838
65839
65840
65841
65842
65843
65844
65845
65846
65847
65848
65849
65850
65851
65852
65853
65854
65855
65856
65857
65858
65859
65860
65861
65862
65863
65864
65865
65866
65867
65868
65869
65870
65871
65872
65873
65874
65875
65876
65877
65878
65879
65880
65881
65882
65883
65884
65885
65886
65887
65888
65889
65890
65891
65892
65893
65894
65895
65896
65897
65898
65899
65900
65901
65902
65903
65904
65905
65906
65907
65908
65909
65910
65911
65912
65913
65914
65915
65916
65917
65918
65919
65920
65921
65922
65923
65924
65925
65926
65927
65928
65929
65930
65931
65932
65933
65934
65935
65936
65937
65938
65939
65940
65941
65942
65943
65944
65945
65946
65947
65948
65949
65950
65951
65952
65953
65954
65955
65956
65957
65958
65959
65960
65961
65962
65963
65964
65965
65966
65967
65968
65969
65970
65971
65972
65973
65974
65975
65976
65977
65978
65979
65980
65981
65982
65983
65984
65985
65986
65987
65988
65989
65990
65991
65992
65993
65994
65995
65996
65997
65998
65999
66000
66001
66002
66003
66004
66005
66006
66007
66008
66009
66010
66011
66012
66013
66014
66015
66016
66017
66018
66019
66020
66021
66022
66023
66024
66025
66026
66027
66028
66029
66030
66031
66032
66033
66034
66035
66036
66037
66038
66039
66040
66041
66042
66043
66044
66045
66046
66047
66048
66049
66050
66051
66052
66053
66054
66055
66056
66057
66058
66059
66060
66061
66062
66063
66064
66065
66066
66067
66068
66069
66070
66071
66072
66073
66074
66075
66076
66077
66078
66079
66080
66081
66082
66083
66084
66085
66086
66087
66088
66089
66090
66091
66092
66093
66094
66095
66096
66097
66098
66099
66100
66101
66102
66103
66104
66105
66106
66107
66108
66109
66110
66111
66112
66113
66114
66115
66116
66117
66118
66119
66120
66121
66122
66123
66124
66125
66126
66127
66128
66129
66130
66131
66132
66133
66134
66135
66136
66137
66138
66139
66140
66141
66142
66143
66144
66145
66146
66147
66148
66149
66150
66151
66152
66153
66154
66155
66156
66157
66158
66159
66160
66161
66162
66163
66164
66165
66166
66167
66168
66169
66170
66171
66172
66173
66174
66175
66176
66177
66178
66179
66180
66181
66182
66183
66184
66185
66186
66187
66188
66189
66190
66191
66192
66193
66194
66195
66196
66197
66198
66199
66200
66201
66202
66203
66204
66205
66206
66207
66208
66209
66210
66211
66212
66213
66214
66215
66216
66217
66218
66219
66220
66221
66222
66223
66224
66225
66226
66227
66228
66229
66230
66231
66232
66233
66234
66235
66236
66237
66238
66239
66240
66241
66242
66243
66244
66245
66246
66247
66248
66249
66250
66251
66252
66253
66254
66255
66256
66257
66258
66259
66260
66261
66262
66263
66264
66265
66266
66267
66268
66269
66270
66271
66272
66273
66274
66275
66276
66277
66278
66279
66280
66281
66282
66283
66284
66285
66286
66287
66288
66289
66290
66291
66292
66293
66294
66295
66296
66297
66298
66299
66300
66301
66302
66303
66304
66305
66306
66307
66308
66309
66310
66311
66312
66313
66314
66315
66316
66317
66318
66319
66320
66321
66322
66323
66324
66325
66326
66327
66328
66329
66330
66331
66332
66333
66334
66335
66336
66337
66338
66339
66340
66341
66342
66343
66344
66345
66346
66347
66348
66349
66350
66351
66352
66353
66354
66355
66356
66357
66358
66359
66360
66361
66362
66363
66364
66365
66366
66367
66368
66369
66370
66371
66372
66373
66374
66375
66376
66377
66378
66379
66380
66381
66382
66383
66384
66385
66386
66387
66388
66389
66390
66391
66392
66393
66394
66395
66396
66397
66398
66399
66400
66401
66402
66403
66404
66405
66406
66407
66408
66409
66410
66411
66412
66413
66414
66415
66416
66417
66418
66419
66420
66421
66422
66423
66424
66425
66426
66427
66428
66429
66430
66431
66432
66433
66434
66435
66436
66437
66438
66439
66440
66441
66442
66443
66444
66445
66446
66447
66448
66449
66450
66451
66452
66453
66454
66455
66456
66457
66458
66459
66460
66461
66462
66463
66464
66465
66466
66467
66468
66469
66470
66471
66472
66473
66474
66475
66476
66477
66478
66479
66480
66481
66482
66483
66484
66485
66486
66487
66488
66489
66490
66491
66492
66493
66494
66495
66496
66497
66498
66499
66500
66501
66502
66503
66504
66505
66506
66507
66508
66509
66510
66511
66512
66513
66514
66515
66516
66517
66518
66519
66520
66521
66522
66523
66524
66525
66526
66527
66528
66529
66530
66531
66532
66533
66534
66535
66536
66537
66538
66539
66540
66541
66542
66543
66544
66545
66546
66547
66548
66549
66550
66551
66552
66553
66554
66555
66556
66557
66558
66559
66560
66561
66562
66563
66564
66565
66566
66567
66568
66569
66570
66571
66572
66573
66574
66575
66576
66577
66578
66579
66580
66581
66582
66583
66584
66585
66586
66587
66588
66589
66590
66591
66592
66593
66594
66595
66596
66597
66598
66599
66600
66601
66602
66603
66604
66605
66606
66607
66608
66609
66610
66611
66612
66613
66614
66615
66616
66617
66618
66619
66620
66621
66622
66623
66624
66625
66626
66627
66628
66629
66630
66631
66632
66633
66634
66635
66636
66637
66638
66639
66640
66641
66642
66643
66644
66645
66646
66647
66648
66649
66650
66651
66652
66653
66654
66655
66656
66657
66658
66659
66660
66661
66662
66663
66664
66665
66666
66667
66668
66669
66670
66671
66672
66673
66674
66675
66676
66677
66678
66679
66680
66681
66682
66683
66684
66685
66686
66687
66688
66689
66690
66691
66692
66693
66694
66695
66696
66697
66698
66699
66700
66701
66702
66703
66704
66705
66706
66707
66708
66709
66710
66711
66712
66713
66714
66715
66716
66717
66718
66719
66720
66721
66722
66723
66724
66725
66726
66727
66728
66729
66730
66731
66732
66733
66734
66735
66736
66737
66738
66739
66740
66741
66742
66743
66744
66745
66746
66747
66748
66749
66750
66751
66752
66753
66754
66755
66756
66757
66758
66759
66760
66761
66762
66763
66764
66765
66766
66767
66768
66769
66770
66771
66772
66773
66774
66775
66776
66777
66778
66779
66780
66781
66782
66783
66784
66785
66786
66787
66788
66789
66790
66791
66792
66793
66794
66795
66796
66797
66798
66799
66800
66801
66802
66803
66804
66805
66806
66807
66808
66809
66810
66811
66812
66813
66814
66815
66816
66817
66818
66819
66820
66821
66822
66823
66824
66825
66826
66827
66828
66829
66830
66831
66832
66833
66834
66835
66836
66837
66838
66839
66840
66841
66842
66843
66844
66845
66846
66847
66848
66849
66850
66851
66852
66853
66854
66855
66856
66857
66858
66859
66860
66861
66862
66863
66864
66865
66866
66867
66868
66869
66870
66871
66872
66873
66874
66875
66876
66877
66878
66879
66880
66881
66882
66883
66884
66885
66886
66887
66888
66889
66890
66891
66892
66893
66894
66895
66896
66897
66898
66899
66900
66901
66902
66903
66904
66905
66906
66907
66908
66909
66910
66911
66912
66913
66914
66915
66916
66917
66918
66919
66920
66921
66922
66923
66924
66925
66926
66927
66928
66929
66930
66931
66932
66933
66934
66935
66936
66937
66938
66939
66940
66941
66942
66943
66944
66945
66946
66947
66948
66949
66950
66951
66952
66953
66954
66955
66956
66957
66958
66959
66960
66961
66962
66963
66964
66965
66966
66967
66968
66969
66970
66971
66972
66973
66974
66975
66976
66977
66978
66979
66980
66981
66982
66983
66984
66985
66986
66987
66988
66989
66990
66991
66992
66993
66994
66995
66996
66997
66998
66999
67000
67001
67002
67003
67004
67005
67006
67007
67008
67009
67010
67011
67012
67013
67014
67015
67016
67017
67018
67019
67020
67021
67022
67023
67024
67025
67026
67027
67028
67029
67030
67031
67032
67033
67034
67035
67036
67037
67038
67039
67040
67041
67042
67043
67044
67045
67046
67047
67048
67049
67050
67051
67052
67053
67054
67055
67056
67057
67058
67059
67060
67061
67062
67063
67064
67065
67066
67067
67068
67069
67070
67071
67072
67073
67074
67075
67076
67077
67078
67079
67080
67081
67082
67083
67084
67085
67086
67087
67088
67089
67090
67091
67092
67093
67094
67095
67096
67097
67098
67099
67100
67101
67102
67103
67104
67105
67106
67107
67108
67109
67110
67111
67112
67113
67114
67115
67116
67117
67118
67119
67120
67121
67122
67123
67124
67125
67126
67127
67128
67129
67130
67131
67132
67133
67134
67135
67136
67137
67138
67139
67140
67141
67142
67143
67144
67145
67146
67147
67148
67149
67150
67151
67152
67153
67154
67155
67156
67157
67158
67159
67160
67161
67162
67163
67164
67165
67166
67167
67168
67169
67170
67171
67172
67173
67174
67175
67176
67177
67178
67179
67180
67181
67182
67183
67184
67185
67186
67187
67188
67189
67190
67191
67192
67193
67194
67195
67196
67197
67198
67199
67200
67201
67202
67203
67204
67205
67206
67207
67208
67209
67210
67211
67212
67213
67214
67215
67216
67217
67218
67219
67220
67221
67222
67223
67224
67225
67226
67227
67228
67229
67230
67231
67232
67233
67234
67235
67236
67237
67238
67239
67240
67241
67242
67243
67244
67245
67246
67247
67248
67249
67250
67251
67252
67253
67254
67255
67256
67257
67258
67259
67260
67261
67262
67263
67264
67265
67266
67267
67268
67269
67270
67271
67272
67273
67274
67275
67276
67277
67278
67279
67280
67281
67282
67283
67284
67285
67286
67287
67288
67289
67290
67291
67292
67293
67294
67295
67296
67297
67298
67299
67300
67301
67302
67303
67304
67305
67306
67307
67308
67309
67310
67311
67312
67313
67314
67315
67316
67317
67318
67319
67320
67321
67322
67323
67324
67325
67326
67327
67328
67329
67330
67331
67332
67333
67334
67335
67336
67337
67338
67339
67340
67341
67342
67343
67344
67345
67346
67347
67348
67349
67350
67351
67352
67353
67354
67355
67356
67357
67358
67359
67360
67361
67362
67363
67364
67365
67366
67367
67368
67369
67370
67371
67372
67373
67374
67375
67376
67377
67378
67379
67380
67381
67382
67383
67384
67385
67386
67387
67388
67389
67390
67391
67392
67393
67394
67395
67396
67397
67398
67399
67400
67401
67402
67403
67404
67405
67406
67407
67408
67409
67410
67411
67412
67413
67414
67415
67416
67417
67418
67419
67420
67421
67422
67423
67424
67425
67426
67427
67428
67429
67430
67431
67432
67433
67434
67435
67436
67437
67438
67439
67440
67441
67442
67443
67444
67445
67446
67447
67448
67449
67450
67451
67452
67453
67454
67455
67456
67457
67458
67459
67460
67461
67462
67463
67464
67465
67466
67467
67468
67469
67470
67471
67472
67473
67474
67475
67476
67477
67478
67479
67480
67481
67482
67483
67484
67485
67486
67487
67488
67489
67490
67491
67492
67493
67494
67495
67496
67497
67498
67499
67500
67501
67502
67503
67504
67505
67506
67507
67508
67509
67510
67511
67512
67513
67514
67515
67516
67517
67518
67519
67520
67521
67522
67523
67524
67525
67526
67527
67528
67529
67530
67531
67532
67533
67534
67535
67536
67537
67538
67539
67540
67541
67542
67543
67544
67545
67546
67547
67548
67549
67550
67551
67552
67553
67554
67555
67556
67557
67558
67559
67560
67561
67562
67563
67564
67565
67566
67567
67568
67569
67570
67571
67572
67573
67574
67575
67576
67577
67578
67579
67580
67581
67582
67583
67584
67585
67586
67587
67588
67589
67590
67591
67592
67593
67594
67595
67596
67597
67598
67599
67600
67601
67602
67603
67604
67605
67606
67607
67608
67609
67610
67611
67612
67613
67614
67615
67616
67617
67618
67619
67620
67621
67622
67623
67624
67625
67626
67627
67628
67629
67630
67631
67632
67633
67634
67635
67636
67637
67638
67639
67640
67641
67642
67643
67644
67645
67646
67647
67648
67649
67650
67651
67652
67653
67654
67655
67656
67657
67658
67659
67660
67661
67662
67663
67664
67665
67666
67667
67668
67669
67670
67671
67672
67673
67674
67675
67676
67677
67678
67679
67680
67681
67682
67683
67684
67685
67686
67687
67688
67689
67690
67691
67692
67693
67694
67695
67696
67697
67698
67699
67700
67701
67702
67703
67704
67705
67706
67707
67708
67709
67710
67711
67712
67713
67714
67715
67716
67717
67718
67719
67720
67721
67722
67723
67724
67725
67726
67727
67728
67729
67730
67731
67732
67733
67734
67735
67736
67737
67738
67739
67740
67741
67742
67743
67744
67745
67746
67747
67748
67749
67750
67751
67752
67753
67754
67755
67756
67757
67758
67759
67760
67761
67762
67763
67764
67765
67766
67767
67768
67769
67770
67771
67772
67773
67774
67775
67776
67777
67778
67779
67780
67781
67782
67783
67784
67785
67786
67787
67788
67789
67790
67791
67792
67793
67794
67795
67796
67797
67798
67799
67800
67801
67802
67803
67804
67805
67806
67807
67808
67809
67810
67811
67812
67813
67814
67815
67816
67817
67818
67819
67820
67821
67822
67823
67824
67825
67826
67827
67828
67829
67830
67831
67832
67833
67834
67835
67836
67837
67838
67839
67840
67841
67842
67843
67844
67845
67846
67847
67848
67849
67850
67851
67852
67853
67854
67855
67856
67857
67858
67859
67860
67861
67862
67863
67864
67865
67866
67867
67868
67869
67870
67871
67872
67873
67874
67875
67876
67877
67878
67879
67880
67881
67882
67883
67884
67885
67886
67887
67888
67889
67890
67891
67892
67893
67894
67895
67896
67897
67898
67899
67900
67901
67902
67903
67904
67905
67906
67907
67908
67909
67910
67911
67912
67913
67914
67915
67916
67917
67918
67919
67920
67921
67922
67923
67924
67925
67926
67927
67928
67929
67930
67931
67932
67933
67934
67935
67936
67937
67938
67939
67940
67941
67942
67943
67944
67945
67946
67947
67948
67949
67950
67951
67952
67953
67954
67955
67956
67957
67958
67959
67960
67961
67962
67963
67964
67965
67966
67967
67968
67969
67970
67971
67972
67973
67974
67975
67976
67977
67978
67979
67980
67981
67982
67983
67984
67985
67986
67987
67988
67989
67990
67991
67992
67993
67994
67995
67996
67997
67998
67999
68000
68001
68002
68003
68004
68005
68006
68007
68008
68009
68010
68011
68012
68013
68014
68015
68016
68017
68018
68019
68020
68021
68022
68023
68024
68025
68026
68027
68028
68029
68030
68031
68032
68033
68034
68035
68036
68037
68038
68039
68040
68041
68042
68043
68044
68045
68046
68047
68048
68049
68050
68051
68052
68053
68054
68055
68056
68057
68058
68059
68060
68061
68062
68063
68064
68065
68066
68067
68068
68069
68070
68071
68072
68073
68074
68075
68076
68077
68078
68079
68080
68081
68082
68083
68084
68085
68086
68087
68088
68089
68090
68091
68092
68093
68094
68095
68096
68097
68098
68099
68100
68101
68102
68103
68104
68105
68106
68107
68108
68109
68110
68111
68112
68113
68114
68115
68116
68117
68118
68119
68120
68121
68122
68123
68124
68125
68126
68127
68128
68129
68130
68131
68132
68133
68134
68135
68136
68137
68138
68139
68140
68141
68142
68143
68144
68145
68146
68147
68148
68149
68150
68151
68152
68153
68154
68155
68156
68157
68158
68159
68160
68161
68162
68163
68164
68165
68166
68167
68168
68169
68170
68171
68172
68173
68174
68175
68176
68177
68178
68179
68180
68181
68182
68183
68184
68185
68186
68187
68188
68189
68190
68191
68192
68193
68194
68195
68196
68197
68198
68199
68200
68201
68202
68203
68204
68205
68206
68207
68208
68209
68210
68211
68212
68213
68214
68215
68216
68217
68218
68219
68220
68221
68222
68223
68224
68225
68226
68227
68228
68229
68230
68231
68232
68233
68234
68235
68236
68237
68238
68239
68240
68241
68242
68243
68244
68245
68246
68247
68248
68249
68250
68251
68252
68253
68254
68255
68256
68257
68258
68259
68260
68261
68262
68263
68264
68265
68266
68267
68268
68269
68270
68271
68272
68273
68274
68275
68276
68277
68278
68279
68280
68281
68282
68283
68284
68285
68286
68287
68288
68289
68290
68291
68292
68293
68294
68295
68296
68297
68298
68299
68300
68301
68302
68303
68304
68305
68306
68307
68308
68309
68310
68311
68312
68313
68314
68315
68316
68317
68318
68319
68320
68321
68322
68323
68324
68325
68326
68327
68328
68329
68330
68331
68332
68333
68334
68335
68336
68337
68338
68339
68340
68341
68342
68343
68344
68345
68346
68347
68348
68349
68350
68351
68352
68353
68354
68355
68356
68357
68358
68359
68360
68361
68362
68363
68364
68365
68366
68367
68368
68369
68370
68371
68372
68373
68374
68375
68376
68377
68378
68379
68380
68381
68382
68383
68384
68385
68386
68387
68388
68389
68390
68391
68392
68393
68394
68395
68396
68397
68398
68399
68400
68401
68402
68403
68404
68405
68406
68407
68408
68409
68410
68411
68412
68413
68414
68415
68416
68417
68418
68419
68420
68421
68422
68423
68424
68425
68426
68427
68428
68429
68430
68431
68432
68433
68434
68435
68436
68437
68438
68439
68440
68441
68442
68443
68444
68445
68446
68447
68448
68449
68450
68451
68452
68453
68454
68455
68456
68457
68458
68459
68460
68461
68462
68463
68464
68465
68466
68467
68468
68469
68470
68471
68472
68473
68474
68475
68476
68477
68478
68479
68480
68481
68482
68483
68484
68485
68486
68487
68488
68489
68490
68491
68492
68493
68494
68495
68496
68497
68498
68499
68500
68501
68502
68503
68504
68505
68506
68507
68508
68509
68510
68511
68512
68513
68514
68515
68516
68517
68518
68519
68520
68521
68522
68523
68524
68525
68526
68527
68528
68529
68530
68531
68532
68533
68534
68535
68536
68537
68538
68539
68540
68541
68542
68543
68544
68545
68546
68547
68548
68549
68550
68551
68552
68553
68554
68555
68556
68557
68558
68559
68560
68561
68562
68563
68564
68565
68566
68567
68568
68569
68570
68571
68572
68573
68574
68575
68576
68577
68578
68579
68580
68581
68582
68583
68584
68585
68586
68587
68588
68589
68590
68591
68592
68593
68594
68595
68596
68597
68598
68599
68600
68601
68602
68603
68604
68605
68606
68607
68608
68609
68610
68611
68612
68613
68614
68615
68616
68617
68618
68619
68620
68621
68622
68623
68624
68625
68626
68627
68628
68629
68630
68631
68632
68633
68634
68635
68636
68637
68638
68639
68640
68641
68642
68643
68644
68645
68646
68647
68648
68649
68650
68651
68652
68653
68654
68655
68656
68657
68658
68659
68660
68661
68662
68663
68664
68665
68666
68667
68668
68669
68670
68671
68672
68673
68674
68675
68676
68677
68678
68679
68680
68681
68682
68683
68684
68685
68686
68687
68688
68689
68690
68691
68692
68693
68694
68695
68696
68697
68698
68699
68700
68701
68702
68703
68704
68705
68706
68707
68708
68709
68710
68711
68712
68713
68714
68715
68716
68717
68718
68719
68720
68721
68722
68723
68724
68725
68726
68727
68728
68729
68730
68731
68732
68733
68734
68735
68736
68737
68738
68739
68740
68741
68742
68743
68744
68745
68746
68747
68748
68749
68750
68751
68752
68753
68754
68755
68756
68757
68758
68759
68760
68761
68762
68763
68764
68765
68766
68767
68768
68769
68770
68771
68772
68773
68774
68775
68776
68777
68778
68779
68780
68781
68782
68783
68784
68785
68786
68787
68788
68789
68790
68791
68792
68793
68794
68795
68796
68797
68798
68799
68800
68801
68802
68803
68804
68805
68806
68807
68808
68809
68810
68811
68812
68813
68814
68815
68816
68817
68818
68819
68820
68821
68822
68823
68824
68825
68826
68827
68828
68829
68830
68831
68832
68833
68834
68835
68836
68837
68838
68839
68840
68841
68842
68843
68844
68845
68846
68847
68848
68849
68850
68851
68852
68853
68854
68855
68856
68857
68858
68859
68860
68861
68862
68863
68864
68865
68866
68867
68868
68869
68870
68871
68872
68873
68874
68875
68876
68877
68878
68879
68880
68881
68882
68883
68884
68885
68886
68887
68888
68889
68890
68891
68892
68893
68894
68895
68896
68897
68898
68899
68900
68901
68902
68903
68904
68905
68906
68907
68908
68909
68910
68911
68912
68913
68914
68915
68916
68917
68918
68919
68920
68921
68922
68923
68924
68925
68926
68927
68928
68929
68930
68931
68932
68933
68934
68935
68936
68937
68938
68939
68940
68941
68942
68943
68944
68945
68946
68947
68948
68949
68950
68951
68952
68953
68954
68955
68956
68957
68958
68959
68960
68961
68962
68963
68964
68965
68966
68967
68968
68969
68970
68971
68972
68973
68974
68975
68976
68977
68978
68979
68980
68981
68982
68983
68984
68985
68986
68987
68988
68989
68990
68991
68992
68993
68994
68995
68996
68997
68998
68999
69000
69001
69002
69003
69004
69005
69006
69007
69008
69009
69010
69011
69012
69013
69014
69015
69016
69017
69018
69019
69020
69021
69022
69023
69024
69025
69026
69027
69028
69029
69030
69031
69032
69033
69034
69035
69036
69037
69038
69039
69040
69041
69042
69043
69044
69045
69046
69047
69048
69049
69050
69051
69052
69053
69054
69055
69056
69057
69058
69059
69060
69061
69062
69063
69064
69065
69066
69067
69068
69069
69070
69071
69072
69073
69074
69075
69076
69077
69078
69079
69080
69081
69082
69083
69084
69085
69086
69087
69088
69089
69090
69091
69092
69093
69094
69095
69096
69097
69098
69099
69100
69101
69102
69103
69104
69105
69106
69107
69108
69109
69110
69111
69112
69113
69114
69115
69116
69117
69118
69119
69120
69121
69122
69123
69124
69125
69126
69127
69128
69129
69130
69131
69132
69133
69134
69135
69136
69137
69138
69139
69140
69141
69142
69143
69144
69145
69146
69147
69148
69149
69150
69151
69152
69153
69154
69155
69156
69157
69158
69159
69160
69161
69162
69163
69164
69165
69166
69167
69168
69169
69170
69171
69172
69173
69174
69175
69176
69177
69178
69179
69180
69181
69182
69183
69184
69185
69186
69187
69188
69189
69190
69191
69192
69193
69194
69195
69196
69197
69198
69199
69200
69201
69202
69203
69204
69205
69206
69207
69208
69209
69210
69211
69212
69213
69214
69215
69216
69217
69218
69219
69220
69221
69222
69223
69224
69225
69226
69227
69228
69229
69230
69231
69232
69233
69234
69235
69236
69237
69238
69239
69240
69241
69242
69243
69244
69245
69246
69247
69248
69249
69250
69251
69252
69253
69254
69255
69256
69257
69258
69259
69260
69261
69262
69263
69264
69265
69266
69267
69268
69269
69270
69271
69272
69273
69274
69275
69276
69277
69278
69279
69280
69281
69282
69283
69284
69285
69286
69287
69288
69289
69290
69291
69292
69293
69294
69295
69296
69297
69298
69299
69300
69301
69302
69303
69304
69305
69306
69307
69308
69309
69310
69311
69312
69313
69314
69315
69316
69317
69318
69319
69320
69321
69322
69323
69324
69325
69326
69327
69328
69329
69330
69331
69332
69333
69334
69335
69336
69337
69338
69339
69340
69341
69342
69343
69344
69345
69346
69347
69348
69349
69350
69351
69352
69353
69354
69355
69356
69357
69358
69359
69360
69361
69362
69363
69364
69365
69366
69367
69368
69369
69370
69371
69372
69373
69374
69375
69376
69377
69378
69379
69380
69381
69382
69383
69384
69385
69386
69387
69388
69389
69390
69391
69392
69393
69394
69395
69396
69397
69398
69399
69400
69401
69402
69403
69404
69405
69406
69407
69408
69409
69410
69411
69412
69413
69414
69415
69416
69417
69418
69419
69420
69421
69422
69423
69424
69425
69426
69427
69428
69429
69430
69431
69432
69433
69434
69435
69436
69437
69438
69439
69440
69441
69442
69443
69444
69445
69446
69447
69448
69449
69450
69451
69452
69453
69454
69455
69456
69457
69458
69459
69460
69461
69462
69463
69464
69465
69466
69467
69468
69469
69470
69471
69472
69473
69474
69475
69476
69477
69478
69479
69480
69481
69482
69483
69484
69485
69486
69487
69488
69489
69490
69491
69492
69493
69494
69495
69496
69497
69498
69499
69500
69501
69502
69503
69504
69505
69506
69507
69508
69509
69510
69511
69512
69513
69514
69515
69516
69517
69518
69519
69520
69521
69522
69523
69524
69525
69526
69527
69528
69529
69530
69531
69532
69533
69534
69535
69536
69537
69538
69539
69540
69541
69542
69543
69544
69545
69546
69547
69548
69549
69550
69551
69552
69553
69554
69555
69556
69557
69558
69559
69560
69561
69562
69563
69564
69565
69566
69567
69568
69569
69570
69571
69572
69573
69574
69575
69576
69577
69578
69579
69580
69581
69582
69583
69584
69585
69586
69587
69588
69589
69590
69591
69592
69593
69594
69595
69596
69597
69598
69599
69600
69601
69602
69603
69604
69605
69606
69607
69608
69609
69610
69611
69612
69613
69614
69615
69616
69617
69618
69619
69620
69621
69622
69623
69624
69625
69626
69627
69628
69629
69630
69631
69632
69633
69634
69635
69636
69637
69638
69639
69640
69641
69642
69643
69644
69645
69646
69647
69648
69649
69650
69651
69652
69653
69654
69655
69656
69657
69658
69659
69660
69661
69662
69663
69664
69665
69666
69667
69668
69669
69670
69671
69672
69673
69674
69675
69676
69677
69678
69679
69680
69681
69682
69683
69684
69685
69686
69687
69688
69689
69690
69691
69692
69693
69694
69695
69696
69697
69698
69699
69700
69701
69702
69703
69704
69705
69706
69707
69708
69709
69710
69711
69712
69713
69714
69715
69716
69717
69718
69719
69720
69721
69722
69723
69724
69725
69726
69727
69728
69729
69730
69731
69732
69733
69734
69735
69736
69737
69738
69739
69740
69741
69742
69743
69744
69745
69746
69747
69748
69749
69750
69751
69752
69753
69754
69755
69756
69757
69758
69759
69760
69761
69762
69763
69764
69765
69766
69767
69768
69769
69770
69771
69772
69773
69774
69775
69776
69777
69778
69779
69780
69781
69782
69783
69784
69785
69786
69787
69788
69789
69790
69791
69792
69793
69794
69795
69796
69797
69798
69799
69800
69801
69802
69803
69804
69805
69806
69807
69808
69809
69810
69811
69812
69813
69814
69815
69816
69817
69818
69819
69820
69821
69822
69823
69824
69825
69826
69827
69828
69829
69830
69831
69832
69833
69834
69835
69836
69837
69838
69839
69840
69841
69842
69843
69844
69845
69846
69847
69848
69849
69850
69851
69852
69853
69854
69855
69856
69857
69858
69859
69860
69861
69862
69863
69864
69865
69866
69867
69868
69869
69870
69871
69872
69873
69874
69875
69876
69877
69878
69879
69880
69881
69882
69883
69884
69885
69886
69887
69888
69889
69890
69891
69892
69893
69894
69895
69896
69897
69898
69899
69900
69901
69902
69903
69904
69905
69906
69907
69908
69909
69910
69911
69912
69913
69914
69915
69916
69917
69918
69919
69920
69921
69922
69923
69924
69925
69926
69927
69928
69929
69930
69931
69932
69933
69934
69935
69936
69937
69938
69939
69940
69941
69942
69943
69944
69945
69946
69947
69948
69949
69950
69951
69952
69953
69954
69955
69956
69957
69958
69959
69960
69961
69962
69963
69964
69965
69966
69967
69968
69969
69970
69971
69972
69973
69974
69975
69976
69977
69978
69979
69980
69981
69982
69983
69984
69985
69986
69987
69988
69989
69990
69991
69992
69993
69994
69995
69996
69997
69998
69999
70000
70001
70002
70003
70004
70005
70006
70007
70008
70009
70010
70011
70012
70013
70014
70015
70016
70017
70018
70019
70020
70021
70022
70023
70024
70025
70026
70027
70028
70029
70030
70031
70032
70033
70034
70035
70036
70037
70038
70039
70040
70041
70042
70043
70044
70045
70046
70047
70048
70049
70050
70051
70052
70053
70054
70055
70056
70057
70058
70059
70060
70061
70062
70063
70064
70065
70066
70067
70068
70069
70070
70071
70072
70073
70074
70075
70076
70077
70078
70079
70080
70081
70082
70083
70084
70085
70086
70087
70088
70089
70090
70091
70092
70093
70094
70095
70096
70097
70098
70099
70100
70101
70102
70103
70104
70105
70106
70107
70108
70109
70110
70111
70112
70113
70114
70115
70116
70117
70118
70119
70120
70121
70122
70123
70124
70125
70126
70127
70128
70129
70130
70131
70132
70133
70134
70135
70136
70137
70138
70139
70140
70141
70142
70143
70144
70145
70146
70147
70148
70149
70150
70151
70152
70153
70154
70155
70156
70157
70158
70159
70160
70161
70162
70163
70164
70165
70166
70167
70168
70169
70170
70171
70172
70173
70174
70175
70176
70177
70178
70179
70180
70181
70182
70183
70184
70185
70186
70187
70188
70189
70190
70191
70192
70193
70194
70195
70196
70197
70198
70199
70200
70201
70202
70203
70204
70205
70206
70207
70208
70209
70210
70211
70212
70213
70214
70215
70216
70217
70218
70219
70220
70221
70222
70223
70224
70225
70226
70227
70228
70229
70230
70231
70232
70233
70234
70235
70236
70237
70238
70239
70240
70241
70242
70243
70244
70245
70246
70247
70248
70249
70250
70251
70252
70253
70254
70255
70256
70257
70258
70259
70260
70261
70262
70263
70264
70265
70266
70267
70268
70269
70270
70271
70272
70273
70274
70275
70276
70277
70278
70279
70280
70281
70282
70283
70284
70285
70286
70287
70288
70289
70290
70291
70292
70293
70294
70295
70296
70297
70298
70299
70300
70301
70302
70303
70304
70305
70306
70307
70308
70309
70310
70311
70312
70313
70314
70315
70316
70317
70318
70319
70320
70321
70322
70323
70324
70325
70326
70327
70328
70329
70330
70331
70332
70333
70334
70335
70336
70337
70338
70339
70340
70341
70342
70343
70344
70345
70346
70347
70348
70349
70350
70351
70352
70353
70354
70355
70356
70357
70358
70359
70360
70361
70362
70363
70364
70365
70366
70367
70368
70369
70370
70371
70372
70373
70374
70375
70376
70377
70378
70379
70380
70381
70382
70383
70384
70385
70386
70387
70388
70389
70390
70391
70392
70393
70394
70395
70396
70397
70398
70399
70400
70401
70402
70403
70404
70405
70406
70407
70408
70409
70410
70411
70412
70413
70414
70415
70416
70417
70418
70419
70420
70421
70422
70423
70424
70425
70426
70427
70428
70429
70430
70431
70432
70433
70434
70435
70436
70437
70438
70439
70440
70441
70442
70443
70444
70445
70446
70447
70448
70449
70450
70451
70452
70453
70454
70455
70456
70457
70458
70459
70460
70461
70462
70463
70464
70465
70466
70467
70468
70469
70470
70471
70472
70473
70474
70475
70476
70477
70478
70479
70480
70481
70482
70483
70484
70485
70486
70487
70488
70489
70490
70491
70492
70493
70494
70495
70496
70497
70498
70499
70500
70501
70502
70503
70504
70505
70506
70507
70508
70509
70510
70511
70512
70513
70514
70515
70516
70517
70518
70519
70520
70521
70522
70523
70524
70525
70526
70527
70528
70529
70530
70531
70532
70533
70534
70535
70536
70537
70538
70539
70540
70541
70542
70543
70544
70545
70546
70547
70548
70549
70550
70551
70552
70553
70554
70555
70556
70557
70558
70559
70560
70561
70562
70563
70564
70565
70566
70567
70568
70569
70570
70571
70572
70573
70574
70575
70576
70577
70578
70579
70580
70581
70582
70583
70584
70585
70586
70587
70588
70589
70590
70591
70592
70593
70594
70595
70596
70597
70598
70599
70600
70601
70602
70603
70604
70605
70606
70607
70608
70609
70610
70611
70612
70613
70614
70615
70616
70617
70618
70619
70620
70621
70622
70623
70624
70625
70626
70627
70628
70629
70630
70631
70632
70633
70634
70635
70636
70637
70638
70639
70640
70641
70642
70643
70644
70645
70646
70647
70648
70649
70650
70651
70652
70653
70654
70655
70656
70657
70658
70659
70660
70661
70662
70663
70664
70665
70666
70667
70668
70669
70670
70671
70672
70673
70674
70675
70676
70677
70678
70679
70680
70681
70682
70683
70684
70685
70686
70687
70688
70689
70690
70691
70692
70693
70694
70695
70696
70697
70698
70699
70700
70701
70702
70703
70704
70705
70706
70707
70708
70709
70710
70711
70712
70713
70714
70715
70716
70717
70718
70719
70720
70721
70722
70723
70724
70725
70726
70727
70728
70729
70730
70731
70732
70733
70734
70735
70736
70737
70738
70739
70740
70741
70742
70743
70744
70745
70746
70747
70748
70749
70750
70751
70752
70753
70754
70755
70756
70757
70758
70759
70760
70761
70762
70763
70764
70765
70766
70767
70768
70769
70770
70771
70772
70773
70774
70775
70776
70777
70778
70779
70780
70781
70782
70783
70784
70785
70786
70787
70788
70789
70790
70791
70792
70793
70794
70795
70796
70797
70798
70799
70800
70801
70802
70803
70804
70805
70806
70807
70808
70809
70810
70811
70812
70813
70814
70815
70816
70817
70818
70819
70820
70821
70822
70823
70824
70825
70826
70827
70828
70829
70830
70831
70832
70833
70834
70835
70836
70837
70838
70839
70840
70841
70842
70843
70844
70845
70846
70847
70848
70849
70850
70851
70852
70853
70854
70855
70856
70857
70858
70859
70860
70861
70862
70863
70864
70865
70866
70867
70868
70869
70870
70871
70872
70873
70874
70875
70876
70877
70878
70879
70880
70881
70882
70883
70884
70885
70886
70887
70888
70889
70890
70891
70892
70893
70894
70895
70896
70897
70898
70899
70900
70901
70902
70903
70904
70905
70906
70907
70908
70909
70910
70911
70912
70913
70914
70915
70916
70917
70918
70919
70920
70921
70922
70923
70924
70925
70926
70927
70928
70929
70930
70931
70932
70933
70934
70935
70936
70937
70938
70939
70940
70941
70942
70943
70944
70945
70946
70947
70948
70949
70950
70951
70952
70953
70954
70955
70956
70957
70958
70959
70960
70961
70962
70963
70964
70965
70966
70967
70968
70969
70970
70971
70972
70973
70974
70975
70976
70977
70978
70979
70980
70981
70982
70983
70984
70985
70986
70987
70988
70989
70990
70991
70992
70993
70994
70995
70996
70997
70998
70999
71000
71001
71002
71003
71004
71005
71006
71007
71008
71009
71010
71011
71012
71013
71014
71015
71016
71017
71018
71019
71020
71021
71022
71023
71024
71025
71026
71027
71028
71029
71030
71031
71032
71033
71034
71035
71036
71037
71038
71039
71040
71041
71042
71043
71044
71045
71046
71047
71048
71049
71050
71051
71052
71053
71054
71055
71056
71057
71058
71059
71060
71061
71062
71063
71064
71065
71066
71067
71068
71069
71070
71071
71072
71073
71074
71075
71076
71077
71078
71079
71080
71081
71082
71083
71084
71085
71086
71087
71088
71089
71090
71091
71092
71093
71094
71095
71096
71097
71098
71099
71100
71101
71102
71103
71104
71105
71106
71107
71108
71109
71110
71111
71112
71113
71114
71115
71116
71117
71118
71119
71120
71121
71122
71123
71124
71125
71126
71127
71128
71129
71130
71131
71132
71133
71134
71135
71136
71137
71138
71139
71140
71141
71142
71143
71144
71145
71146
71147
71148
71149
71150
71151
71152
71153
71154
71155
71156
71157
71158
71159
71160
71161
71162
71163
71164
71165
71166
71167
71168
71169
71170
71171
71172
71173
71174
71175
71176
71177
71178
71179
71180
71181
71182
71183
71184
71185
71186
71187
71188
71189
71190
71191
71192
71193
71194
71195
71196
71197
71198
71199
71200
71201
71202
71203
71204
71205
71206
71207
71208
71209
71210
71211
71212
71213
71214
71215
71216
71217
71218
71219
71220
71221
71222
71223
71224
71225
71226
71227
71228
71229
71230
71231
71232
71233
71234
71235
71236
71237
71238
71239
71240
71241
71242
71243
71244
71245
71246
71247
71248
71249
71250
71251
71252
71253
71254
71255
71256
71257
71258
71259
71260
71261
71262
71263
71264
71265
71266
71267
71268
71269
71270
71271
71272
71273
71274
71275
71276
71277
71278
71279
71280
71281
71282
71283
71284
71285
71286
71287
71288
71289
71290
71291
71292
71293
71294
71295
71296
71297
71298
71299
71300
71301
71302
71303
71304
71305
71306
71307
71308
71309
71310
71311
71312
71313
71314
71315
71316
71317
71318
71319
71320
71321
71322
71323
71324
71325
71326
71327
71328
71329
71330
71331
71332
71333
71334
71335
71336
71337
71338
71339
71340
71341
71342
71343
71344
71345
71346
71347
71348
71349
71350
71351
71352
71353
71354
71355
71356
71357
71358
71359
71360
71361
71362
71363
71364
71365
71366
71367
71368
71369
71370
71371
71372
71373
71374
71375
71376
71377
71378
71379
71380
71381
71382
71383
71384
71385
71386
71387
71388
71389
71390
71391
71392
71393
71394
71395
71396
71397
71398
71399
71400
71401
71402
71403
71404
71405
71406
71407
71408
71409
71410
71411
71412
71413
71414
71415
71416
71417
71418
71419
71420
71421
71422
71423
71424
71425
71426
71427
71428
71429
71430
71431
71432
71433
71434
71435
71436
71437
71438
71439
71440
71441
71442
71443
71444
71445
71446
71447
71448
71449
71450
71451
71452
71453
71454
71455
71456
71457
71458
71459
71460
71461
71462
71463
71464
71465
71466
71467
71468
71469
71470
71471
71472
71473
71474
71475
71476
71477
71478
71479
71480
71481
71482
71483
71484
71485
71486
71487
71488
71489
71490
71491
71492
71493
71494
71495
71496
71497
71498
71499
71500
71501
71502
71503
71504
71505
71506
71507
71508
71509
71510
71511
71512
71513
71514
71515
71516
71517
71518
71519
71520
71521
71522
71523
71524
71525
71526
71527
71528
71529
71530
71531
71532
71533
71534
71535
71536
71537
71538
71539
71540
71541
71542
71543
71544
71545
71546
71547
71548
71549
71550
71551
71552
71553
71554
71555
71556
71557
71558
71559
71560
71561
71562
71563
71564
71565
71566
71567
71568
71569
71570
71571
71572
71573
71574
71575
71576
71577
71578
71579
71580
71581
71582
71583
71584
71585
71586
71587
71588
71589
71590
71591
71592
71593
71594
71595
71596
71597
71598
71599
71600
71601
71602
71603
71604
71605
71606
71607
71608
71609
71610
71611
71612
71613
71614
71615
71616
71617
71618
71619
71620
71621
71622
71623
71624
71625
71626
71627
71628
71629
71630
71631
71632
71633
71634
71635
71636
71637
71638
71639
71640
71641
71642
71643
71644
71645
71646
71647
71648
71649
71650
71651
71652
71653
71654
71655
71656
71657
71658
71659
71660
71661
71662
71663
71664
71665
71666
71667
71668
71669
71670
71671
71672
71673
71674
71675
71676
71677
71678
71679
71680
71681
71682
71683
71684
71685
71686
71687
71688
71689
71690
71691
71692
71693
71694
71695
71696
71697
71698
71699
71700
71701
71702
71703
71704
71705
71706
71707
71708
71709
71710
71711
71712
71713
71714
71715
71716
71717
71718
71719
71720
71721
71722
71723
71724
71725
71726
71727
71728
71729
71730
71731
71732
71733
71734
71735
71736
71737
71738
71739
71740
71741
71742
71743
71744
71745
71746
71747
71748
71749
71750
71751
71752
71753
71754
71755
71756
71757
71758
71759
71760
71761
71762
71763
71764
71765
71766
71767
71768
71769
71770
71771
71772
71773
71774
71775
71776
71777
71778
71779
71780
71781
71782
71783
71784
71785
71786
71787
71788
71789
71790
71791
71792
71793
71794
71795
71796
71797
71798
71799
71800
71801
71802
71803
71804
71805
71806
71807
71808
71809
71810
71811
71812
71813
71814
71815
71816
71817
71818
71819
71820
71821
71822
71823
71824
71825
71826
71827
71828
71829
71830
71831
71832
71833
71834
71835
71836
71837
71838
71839
71840
71841
71842
71843
71844
71845
71846
71847
71848
71849
71850
71851
71852
71853
71854
71855
71856
71857
71858
71859
71860
71861
71862
71863
71864
71865
71866
71867
71868
71869
71870
71871
71872
71873
71874
71875
71876
71877
71878
71879
71880
71881
71882
71883
71884
71885
71886
71887
71888
71889
71890
71891
71892
71893
71894
71895
71896
71897
71898
71899
71900
71901
71902
71903
71904
71905
71906
71907
71908
71909
71910
71911
71912
71913
71914
71915
71916
71917
71918
71919
71920
71921
71922
71923
71924
71925
71926
71927
71928
71929
71930
71931
71932
71933
71934
71935
71936
71937
71938
71939
71940
71941
71942
71943
71944
71945
71946
71947
71948
71949
71950
71951
71952
71953
71954
71955
71956
71957
71958
71959
71960
71961
71962
71963
71964
71965
71966
71967
71968
71969
71970
71971
71972
71973
71974
71975
71976
71977
71978
71979
71980
71981
71982
71983
71984
71985
71986
71987
71988
71989
71990
71991
71992
71993
71994
71995
71996
71997
71998
71999
72000
72001
72002
72003
72004
72005
72006
72007
72008
72009
72010
72011
72012
72013
72014
72015
72016
72017
72018
72019
72020
72021
72022
72023
72024
72025
72026
72027
72028
72029
72030
72031
72032
72033
72034
72035
72036
72037
72038
72039
72040
72041
72042
72043
72044
72045
72046
72047
72048
72049
72050
72051
72052
72053
72054
72055
72056
72057
72058
72059
72060
72061
72062
72063
72064
72065
72066
72067
72068
72069
72070
72071
72072
72073
72074
72075
72076
72077
72078
72079
72080
72081
72082
72083
72084
72085
72086
72087
72088
72089
72090
72091
72092
72093
72094
72095
72096
72097
72098
72099
72100
72101
72102
72103
72104
72105
72106
72107
72108
72109
72110
72111
72112
72113
72114
72115
72116
72117
72118
72119
72120
72121
72122
72123
72124
72125
72126
72127
72128
72129
72130
72131
72132
72133
72134
72135
72136
72137
72138
72139
72140
72141
72142
72143
72144
|
diff -Nur linux-3.4.113.orig/arch/nds32/boot/install.sh linux-3.4.113/arch/nds32/boot/install.sh
--- linux-3.4.113.orig/arch/nds32/boot/install.sh 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/boot/install.sh 2016-12-01 20:59:24.328611826 +0100
@@ -0,0 +1,47 @@
+#!/bin/sh
+#
+# arch/nds32/boot/install.sh
+#
+# This file is subject to the terms and conditions of the GNU General Public
+# License. See the file "COPYING" in the main directory of this archive
+# for more details.
+#
+# Copyright (C) 1995 by Linus Torvalds
+# Copyright (C) 2009 Andes Technology Corporation
+#
+# Adapted from code in arch/i386/boot/Makefile by H. Peter Anvin
+# Adapted from code in arch/i386/boot/install.sh by Russell King
+#
+# "make install" script for arm architecture
+#
+# Arguments:
+# $1 - kernel version
+# $2 - kernel image file
+# $3 - kernel map file
+# $4 - default install path (blank if root directory)
+#
+
+# User may have a custom install script
+if [ -x ~/bin/installkernel ]; then exec ~/bin/installkernel "$@"; fi
+if [ -x /sbin/installkernel ]; then exec /sbin/installkernel "$@"; fi
+
+# Normal install
+echo "Installing normal kernel"
+base=vmlinux
+
+if [ -f $4/$base-$1 ]; then
+ mv $4/$base-$1 $4/$base-$1.old
+fi
+cat $2 > $4/$base-$1
+
+# Install system map file
+if [ -f $4/System.map-$1 ]; then
+ mv $4/System.map-$1 $4/System.map-$1.old
+fi
+cp $3 $4/System.map-$1
+
+if [ -x /sbin/loadmap ]; then
+ /sbin/loadmap
+else
+ echo "You have to install it yourself"
+fi
diff -Nur linux-3.4.113.orig/arch/nds32/boot/Makefile linux-3.4.113/arch/nds32/boot/Makefile
--- linux-3.4.113.orig/arch/nds32/boot/Makefile 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/boot/Makefile 2016-12-01 20:59:24.328611826 +0100
@@ -0,0 +1,22 @@
+#
+# arch/nds32/boot/Makefile
+#
+# This file is subject to the terms and conditions of the GNU General Public
+# License. See the file "COPYING" in the main directory of this archive
+# for more details.
+#
+# Copyright (C) 1995-2002 Russell King
+# Copyright (C) 2009 Andes Technology Corporation
+#
+
+targets := Image
+
+$(obj)/Image: vmlinux FORCE
+ $(call if_changed,objcopy)
+ @echo ' Kernel: $@ is ready'
+
+.PHONY: FORCE
+install: $(obj)/Image
+ $(CONFIG_SHELL) $(srctree)/$(src)/install.sh $(KERNELRELEASE) \
+ $(obj)/Image System.map "$(INSTALL_PATH)"
+
diff -Nur linux-3.4.113.orig/arch/nds32/common/dmabounce.c linux-3.4.113/arch/nds32/common/dmabounce.c
--- linux-3.4.113.orig/arch/nds32/common/dmabounce.c 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/common/dmabounce.c 2016-12-01 20:59:24.328611826 +0100
@@ -0,0 +1,672 @@
+/*
+ * arch/nds32/common/dmabounce.c
+ *
+ * Special dma_{map/unmap/dma_sync}_* routines for systems that have
+ * limited DMA windows. These functions utilize bounce buffers to
+ * copy data to/from buffers located outside the DMA region. This
+ * only works for systems in which DMA memory is at the bottom of
+ * RAM and the remainder of memory is at the top an the DMA memory
+ * can be marked as ZONE_DMA. Anything beyond that such as discontigous
+ * DMA windows will require custom implementations that reserve memory
+ * areas at early bootup.
+ *
+ * Original version by Brad Parker (brad@heeltoe.com)
+ * Re-written by Christopher Hoover <ch@murgatroid.com>
+ * Made generic by Deepak Saxena <dsaxena@plexity.net>
+ *
+ * Copyright (C) 2002 Hewlett Packard Company.
+ * Copyright (C) 2004 MontaVista Software, Inc.
+ * Copyright (C) 2009 Andes Technology Corporation
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ */
+
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/slab.h>
+#include <linux/device.h>
+#include <linux/dma-mapping.h>
+#include <linux/dmapool.h>
+#include <linux/list.h>
+
+#undef DEBUG
+
+#undef STATS
+#ifdef STATS
+#define DO_STATS(X) do { X ; } while (0)
+#else
+#define DO_STATS(X) do { } while (0)
+#endif
+
+/* ************************************************** */
+
+struct safe_buffer {
+ struct list_head node;
+
+ /* original request */
+ void *ptr;
+ size_t size;
+ int direction;
+
+ /* safe buffer info */
+ struct dma_pool *pool;
+ void *safe;
+ dma_addr_t safe_dma_addr;
+};
+
+struct dmabounce_device_info {
+ struct list_head node;
+
+ struct device *dev;
+ struct dma_pool *small_buffer_pool;
+ struct dma_pool *large_buffer_pool;
+ struct list_head safe_buffers;
+ unsigned long small_buffer_size, large_buffer_size;
+#ifdef STATS
+ unsigned long sbp_allocs;
+ unsigned long lbp_allocs;
+ unsigned long total_allocs;
+ unsigned long map_op_count;
+ unsigned long bounce_count;
+#endif
+};
+
+static LIST_HEAD(dmabounce_devs);
+
+#ifdef STATS
+static void print_alloc_stats(struct dmabounce_device_info *device_info)
+{
+ printk(KERN_INFO
+ "%s: dmabounce: sbp: %lu, lbp: %lu, other: %lu, total: %lu\n",
+ device_info->dev->bus_id,
+ device_info->sbp_allocs, device_info->lbp_allocs,
+ device_info->total_allocs - device_info->sbp_allocs -
+ device_info->lbp_allocs, device_info->total_allocs);
+}
+#endif
+
+/* find the given device in the dmabounce device list */
+static inline struct dmabounce_device_info *find_dmabounce_dev(struct device
+ *dev)
+{
+ struct list_head *entry;
+
+ list_for_each(entry, &dmabounce_devs) {
+ struct dmabounce_device_info *d =
+ list_entry(entry, struct dmabounce_device_info, node);
+
+ if (d->dev == dev)
+ return d;
+ }
+ return NULL;
+}
+
+/* allocate a 'safe' buffer and keep track of it */
+static inline struct safe_buffer *alloc_safe_buffer(struct dmabounce_device_info
+ *device_info, void *ptr,
+ size_t size,
+ enum dma_data_direction dir)
+{
+ struct safe_buffer *buf;
+ struct dma_pool *pool;
+ struct device *dev = device_info->dev;
+ void *safe;
+ dma_addr_t safe_dma_addr;
+
+ dev_dbg(dev, "%s(ptr=%p, size=%d, dir=%d)\n", __func__, ptr, size, dir);
+
+ DO_STATS(device_info->total_allocs++);
+
+ buf = kmalloc(sizeof(struct safe_buffer), GFP_ATOMIC);
+ if (buf == NULL) {
+ dev_warn(dev, "%s: kmalloc failed\n", __func__);
+ return NULL;
+ }
+
+ if (size <= device_info->small_buffer_size) {
+ pool = device_info->small_buffer_pool;
+ safe = dma_pool_alloc(pool, GFP_ATOMIC, &safe_dma_addr);
+
+ DO_STATS(device_info->sbp_allocs++);
+ } else if (size <= device_info->large_buffer_size) {
+ pool = device_info->large_buffer_pool;
+ safe = dma_pool_alloc(pool, GFP_ATOMIC, &safe_dma_addr);
+
+ DO_STATS(device_info->lbp_allocs++);
+ } else {
+ pool = NULL;
+ safe =
+ dma_alloc_coherent(dev, size, &safe_dma_addr, GFP_ATOMIC);
+ }
+
+ if (safe == NULL) {
+ dev_warn(device_info->dev,
+ "%s: could not alloc dma memory (size=%d)\n",
+ __func__, size);
+ kfree(buf);
+ return NULL;
+ }
+#ifdef STATS
+ if (device_info->total_allocs % 1000 == 0)
+ print_alloc_stats(device_info);
+#endif
+
+ buf->ptr = ptr;
+ buf->size = size;
+ buf->direction = dir;
+ buf->pool = pool;
+ buf->safe = safe;
+ buf->safe_dma_addr = safe_dma_addr;
+
+ list_add(&buf->node, &device_info->safe_buffers);
+
+ return buf;
+}
+
+/* determine if a buffer is from our "safe" pool */
+static inline struct safe_buffer *find_safe_buffer(struct dmabounce_device_info
+ *device_info,
+ dma_addr_t safe_dma_addr)
+{
+ struct list_head *entry;
+
+ list_for_each(entry, &device_info->safe_buffers) {
+ struct safe_buffer *b =
+ list_entry(entry, struct safe_buffer, node);
+
+ if (b->safe_dma_addr == safe_dma_addr)
+ return b;
+ }
+
+ return NULL;
+}
+
+static inline void
+free_safe_buffer(struct dmabounce_device_info *device_info,
+ struct safe_buffer *buf)
+{
+ dev_dbg(device_info->dev, "%s(buf=%p)\n", __func__, buf);
+
+ list_del(&buf->node);
+
+ if (buf->pool)
+ dma_pool_free(buf->pool, buf->safe, buf->safe_dma_addr);
+ else
+ dma_free_coherent(device_info->dev, buf->size, buf->safe,
+ buf->safe_dma_addr);
+
+ kfree(buf);
+}
+
+/* ************************************************** */
+
+#ifdef STATS
+
+static void print_map_stats(struct dmabounce_device_info *device_info)
+{
+ printk(KERN_INFO
+ "%s: dmabounce: map_op_count=%lu, bounce_count=%lu\n",
+ device_info->dev->bus_id,
+ device_info->map_op_count, device_info->bounce_count);
+}
+#endif
+
+static inline dma_addr_t
+map_single(struct device *dev, void *ptr, size_t size,
+ enum dma_data_direction dir)
+{
+ struct dmabounce_device_info *device_info = find_dmabounce_dev(dev);
+ dma_addr_t dma_addr;
+ int needs_bounce = 0;
+
+ if (device_info)
+ DO_STATS(device_info->map_op_count++);
+
+ dma_addr = virt_to_dma(dev, ptr);
+
+ if (dev->dma_mask) {
+ unsigned long mask = *dev->dma_mask;
+ unsigned long limit;
+
+ limit = (mask + 1) & ~mask;
+ if (limit && size > limit) {
+ dev_err(dev, "DMA mapping too big (requested %#x "
+ "mask %#Lx)\n", size, *dev->dma_mask);
+ return ~0;
+ }
+
+ /*
+ * Figure out if we need to bounce from the DMA mask.
+ */
+ needs_bounce = (dma_addr | (dma_addr + size - 1)) & ~mask;
+ }
+
+ if (device_info
+ && (needs_bounce || dma_needs_bounce(dev, dma_addr, size))) {
+ struct safe_buffer *buf;
+
+ buf = alloc_safe_buffer(device_info, ptr, size, dir);
+ if (buf == 0) {
+ dev_err(dev, "%s: unable to map unsafe buffer %p!\n",
+ __func__, ptr);
+ return 0;
+ }
+
+ dev_dbg(dev,
+ "%s: unsafe buffer %p (phy=%p) mapped to %p (phy=%p)\n",
+ __func__, buf->ptr, (void *)virt_to_dma(dev, buf->ptr),
+ buf->safe, (void *)buf->safe_dma_addr);
+
+ if ((dir == DMA_TO_DEVICE) || (dir == DMA_BIDIRECTIONAL)) {
+ dev_dbg(dev, "%s: copy unsafe %p to safe %p, size %d\n",
+ __func__, ptr, buf->safe, size);
+ memcpy(buf->safe, ptr, size);
+ }
+ consistent_sync(buf->safe, size, dir);
+
+ dma_addr = buf->safe_dma_addr;
+ } else {
+ consistent_sync(ptr, size, dir);
+ }
+
+ return dma_addr;
+}
+
+static inline void
+unmap_single(struct device *dev, dma_addr_t dma_addr, size_t size,
+ enum dma_data_direction dir)
+{
+ struct dmabounce_device_info *device_info = find_dmabounce_dev(dev);
+ struct safe_buffer *buf = NULL;
+
+ /*
+ * Trying to unmap an invalid mapping
+ */
+ if (dma_addr == ~0) {
+ dev_err(dev, "Trying to unmap invalid mapping\n");
+ return;
+ }
+
+ if (device_info)
+ buf = find_safe_buffer(device_info, dma_addr);
+
+ if (buf) {
+ BUG_ON(buf->size != size);
+
+ dev_dbg(dev,
+ "%s: unsafe buffer %p (phy=%p) mapped to %p (phy=%p)\n",
+ __func__, buf->ptr, (void *)virt_to_dma(dev, buf->ptr),
+ buf->safe, (void *)buf->safe_dma_addr);
+
+ DO_STATS(device_info->bounce_count++);
+
+ if ((dir == DMA_FROM_DEVICE) || (dir == DMA_BIDIRECTIONAL)) {
+ dev_dbg(dev,
+ "%s: copy back safe %p to unsafe %p size %d\n",
+ __func__, buf->safe, buf->ptr, size);
+ memcpy(buf->ptr, buf->safe, size);
+ }
+ free_safe_buffer(device_info, buf);
+ }
+}
+
+static inline void
+sync_single(struct device *dev, dma_addr_t dma_addr, size_t size,
+ enum dma_data_direction dir)
+{
+ struct dmabounce_device_info *device_info = find_dmabounce_dev(dev);
+ struct safe_buffer *buf = NULL;
+
+ if (device_info)
+ buf = find_safe_buffer(device_info, dma_addr);
+
+ if (buf) {
+ /*
+ * Both of these checks from original code need to be
+ * commented out b/c some drivers rely on the following:
+ *
+ * 1) Drivers may map a large chunk of memory into DMA space
+ * but only sync a small portion of it. Good example is
+ * allocating a large buffer, mapping it, and then
+ * breaking it up into small descriptors. No point
+ * in syncing the whole buffer if you only have to
+ * touch one descriptor.
+ *
+ * 2) Buffers that are mapped as DMA_BIDIRECTIONAL are
+ * usually only synced in one dir at a time.
+ *
+ * See drivers/net/eepro100.c for examples of both cases.
+ *
+ * -ds
+ *
+ * BUG_ON(buf->size != size);
+ * BUG_ON(buf->direction != dir);
+ */
+
+ dev_dbg(dev,
+ "%s: unsafe buffer %p (phy=%p) mapped to %p (phy=%p)\n",
+ __func__, buf->ptr, (void *)virt_to_dma(dev, buf->ptr),
+ buf->safe, (void *)buf->safe_dma_addr);
+
+ DO_STATS(device_info->bounce_count++);
+
+ switch (dir) {
+ case DMA_FROM_DEVICE:
+ dev_dbg(dev,
+ "%s: copy back safe %p to unsafe %p size %d\n",
+ __func__, buf->safe, buf->ptr, size);
+ memcpy(buf->ptr, buf->safe, size);
+ break;
+ case DMA_TO_DEVICE:
+ dev_dbg(dev,
+ "%s: copy out unsafe %p to safe %p, size %d\n",
+ __func__, buf->ptr, buf->safe, size);
+ memcpy(buf->safe, buf->ptr, size);
+ break;
+ case DMA_BIDIRECTIONAL:
+ BUG(); /* is this allowed? what does it mean? */
+ default:
+ BUG();
+ }
+ consistent_sync(buf->safe, size, dir);
+ } else {
+ consistent_sync(dma_to_virt(dev, dma_addr), size, dir);
+ }
+}
+
+/* ************************************************** */
+
+/*
+ * see if a buffer address is in an 'unsafe' range. if it is
+ * allocate a 'safe' buffer and copy the unsafe buffer into it.
+ * substitute the safe buffer for the unsafe one.
+ * (basically move the buffer from an unsafe area to a safe one)
+ */
+dma_addr_t
+dma_map_single(struct device *dev, void *ptr, size_t size,
+ enum dma_data_direction dir)
+{
+ unsigned long flags;
+ dma_addr_t dma_addr;
+
+ dev_dbg(dev, "%s(ptr=%p,size=%d,dir=%x)\n", __func__, ptr, size, dir);
+
+ BUG_ON(dir == DMA_NONE);
+
+ local_irq_save(flags);
+
+ dma_addr = map_single(dev, ptr, size, dir);
+
+ local_irq_restore(flags);
+
+ return dma_addr;
+}
+
+/*
+ * see if a mapped address was really a "safe" buffer and if so, copy
+ * the data from the safe buffer back to the unsafe buffer and free up
+ * the safe buffer. (basically return things back to the way they
+ * should be)
+ */
+
+void
+dma_unmap_single(struct device *dev, dma_addr_t dma_addr, size_t size,
+ enum dma_data_direction dir)
+{
+ unsigned long flags;
+
+ dev_dbg(dev, "%s(ptr=%p,size=%d,dir=%x)\n",
+ __func__, (void *)dma_addr, size, dir);
+
+ BUG_ON(dir == DMA_NONE);
+
+ local_irq_save(flags);
+
+ unmap_single(dev, dma_addr, size, dir);
+
+ local_irq_restore(flags);
+}
+
+int
+dma_map_sg(struct device *dev, struct scatterlist *sg, int nents,
+ enum dma_data_direction dir)
+{
+ unsigned long flags;
+ int i;
+
+ dev_dbg(dev, "%s(sg=%p,nents=%d,dir=%x)\n", __func__, sg, nents, dir);
+
+ BUG_ON(dir == DMA_NONE);
+
+ local_irq_save(flags);
+
+ for (i = 0; i < nents; i++, sg++) {
+ struct page *page = sg->page;
+ unsigned int offset = sg->offset;
+ unsigned int length = sg->length;
+ void *ptr = page_address(page) + offset;
+
+ sg->dma_address = map_single(dev, ptr, length, dir);
+ }
+
+ local_irq_restore(flags);
+
+ return nents;
+}
+
+void
+dma_unmap_sg(struct device *dev, struct scatterlist *sg, int nents,
+ enum dma_data_direction dir)
+{
+ unsigned long flags;
+ int i;
+
+ dev_dbg(dev, "%s(sg=%p,nents=%d,dir=%x)\n", __func__, sg, nents, dir);
+
+ BUG_ON(dir == DMA_NONE);
+
+ local_irq_save(flags);
+
+ for (i = 0; i < nents; i++, sg++) {
+ dma_addr_t dma_addr = sg->dma_address;
+ unsigned int length = sg->length;
+
+ unmap_single(dev, dma_addr, length, dir);
+ }
+
+ local_irq_restore(flags);
+}
+
+void
+dma_sync_single_for_cpu(struct device *dev, dma_addr_t dma_addr, size_t size,
+ enum dma_data_direction dir)
+{
+ unsigned long flags;
+
+ dev_dbg(dev, "%s(ptr=%p,size=%d,dir=%x)\n",
+ __func__, (void *)dma_addr, size, dir);
+
+ local_irq_save(flags);
+
+ sync_single(dev, dma_addr, size, dir);
+
+ local_irq_restore(flags);
+}
+
+void
+dma_sync_single_for_device(struct device *dev, dma_addr_t dma_addr, size_t size,
+ enum dma_data_direction dir)
+{
+ unsigned long flags;
+
+ dev_dbg(dev, "%s(ptr=%p,size=%d,dir=%x)\n",
+ __func__, (void *)dma_addr, size, dir);
+
+ local_irq_save(flags);
+
+ sync_single(dev, dma_addr, size, dir);
+
+ local_irq_restore(flags);
+}
+
+void
+dma_sync_sg_for_cpu(struct device *dev, struct scatterlist *sg, int nents,
+ enum dma_data_direction dir)
+{
+ unsigned long flags;
+ int i;
+
+ dev_dbg(dev, "%s(sg=%p,nents=%d,dir=%x)\n", __func__, sg, nents, dir);
+
+ BUG_ON(dir == DMA_NONE);
+
+ local_irq_save(flags);
+
+ for (i = 0; i < nents; i++, sg++) {
+ dma_addr_t dma_addr = sg->dma_address;
+ unsigned int length = sg->length;
+
+ sync_single(dev, dma_addr, length, dir);
+ }
+
+ local_irq_restore(flags);
+}
+
+void
+dma_sync_sg_for_device(struct device *dev, struct scatterlist *sg, int nents,
+ enum dma_data_direction dir)
+{
+ unsigned long flags;
+ int i;
+
+ dev_dbg(dev, "%s(sg=%p,nents=%d,dir=%x)\n", __func__, sg, nents, dir);
+
+ BUG_ON(dir == DMA_NONE);
+
+ local_irq_save(flags);
+
+ for (i = 0; i < nents; i++, sg++) {
+ dma_addr_t dma_addr = sg->dma_address;
+ unsigned int length = sg->length;
+
+ sync_single(dev, dma_addr, length, dir);
+ }
+
+ local_irq_restore(flags);
+}
+
+int
+dmabounce_register_dev(struct device *dev, unsigned long small_buffer_size,
+ unsigned long large_buffer_size)
+{
+ struct dmabounce_device_info *device_info;
+
+ device_info = kmalloc(sizeof(struct dmabounce_device_info), GFP_ATOMIC);
+ if (!device_info) {
+ printk(KERN_ERR
+ "Could not allocated dmabounce_device_info for %s",
+ dev->bus_id);
+ return -ENOMEM;
+ }
+
+ device_info->small_buffer_pool =
+ dma_pool_create("small_dmabounce_pool",
+ dev, small_buffer_size, 0 /* byte alignment */ ,
+ 0 /* no page-crossing issues */ );
+ if (!device_info->small_buffer_pool) {
+ printk(KERN_ERR
+ "dmabounce: could not allocate small DMA pool for %s\n",
+ dev->bus_id);
+ kfree(device_info);
+ return -ENOMEM;
+ }
+
+ if (large_buffer_size) {
+ device_info->large_buffer_pool =
+ dma_pool_create("large_dmabounce_pool",
+ dev,
+ large_buffer_size, 0 /* byte alignment */ ,
+ 0 /* no page-crossing issues */ );
+ if (!device_info->large_buffer_pool) {
+ printk(KERN_ERR
+ "dmabounce: could not allocate large DMA pool for %s\n",
+ dev->bus_id);
+ dma_pool_destroy(device_info->small_buffer_pool);
+
+ return -ENOMEM;
+ }
+ }
+
+ device_info->dev = dev;
+ device_info->small_buffer_size = small_buffer_size;
+ device_info->large_buffer_size = large_buffer_size;
+ INIT_LIST_HEAD(&device_info->safe_buffers);
+
+#ifdef STATS
+ device_info->sbp_allocs = 0;
+ device_info->lbp_allocs = 0;
+ device_info->total_allocs = 0;
+ device_info->map_op_count = 0;
+ device_info->bounce_count = 0;
+#endif
+
+ list_add(&device_info->node, &dmabounce_devs);
+
+ printk(KERN_INFO "dmabounce: registered device %s on %s bus\n",
+ dev->bus_id, dev->bus->name);
+
+ return 0;
+}
+
+void dmabounce_unregister_dev(struct device *dev)
+{
+ struct dmabounce_device_info *device_info = find_dmabounce_dev(dev);
+
+ if (!device_info) {
+ printk(KERN_WARNING
+ "%s: Never registered with dmabounce but attempting"
+ "to unregister!\n", dev->bus_id);
+ return;
+ }
+
+ if (!list_empty(&device_info->safe_buffers)) {
+ printk(KERN_ERR
+ "%s: Removing from dmabounce with pending buffers!\n",
+ dev->bus_id);
+ BUG();
+ }
+
+ if (device_info->small_buffer_pool)
+ dma_pool_destroy(device_info->small_buffer_pool);
+ if (device_info->large_buffer_pool)
+ dma_pool_destroy(device_info->large_buffer_pool);
+
+#ifdef STATS
+ print_alloc_stats(device_info);
+ print_map_stats(device_info);
+#endif
+
+ list_del(&device_info->node);
+
+ kfree(device_info);
+
+ printk(KERN_INFO "dmabounce: device %s on %s bus unregistered\n",
+ dev->bus_id, dev->bus->name);
+}
+
+EXPORT_SYMBOL(dma_map_single);
+EXPORT_SYMBOL(dma_unmap_single);
+EXPORT_SYMBOL(dma_map_sg);
+EXPORT_SYMBOL(dma_unmap_sg);
+EXPORT_SYMBOL(dma_sync_single);
+EXPORT_SYMBOL(dma_sync_sg);
+EXPORT_SYMBOL(dmabounce_register_dev);
+EXPORT_SYMBOL(dmabounce_unregister_dev);
+
+MODULE_AUTHOR
+ ("Christopher Hoover <ch@hpl.hp.com>, Deepak Saxena <dsaxena@plexity.net>");
+MODULE_DESCRIPTION
+ ("Special dma_{map/unmap/dma_sync}_* routines for systems with limited DMA windows");
+MODULE_LICENSE("GPL");
diff -Nur linux-3.4.113.orig/arch/nds32/common/Makefile linux-3.4.113/arch/nds32/common/Makefile
--- linux-3.4.113.orig/arch/nds32/common/Makefile 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/common/Makefile 2016-12-01 20:59:24.328611826 +0100
@@ -0,0 +1,6 @@
+#
+# Makefile for the linux kernel.
+#
+
+obj-y += rtctime.o
+obj-$(CONFIG_DMABOUNCE) += dmabounce.o
diff -Nur linux-3.4.113.orig/arch/nds32/common/rtctime.c linux-3.4.113/arch/nds32/common/rtctime.c
--- linux-3.4.113.orig/arch/nds32/common/rtctime.c 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/common/rtctime.c 2016-12-01 20:59:24.328611826 +0100
@@ -0,0 +1,441 @@
+/*
+ * linux/arch/nds32/common/rtctime.c
+ *
+ * Copyright (C) 2003 Deep Blue Solutions Ltd.
+ * Based on sa1100-rtc.c, Nils Faerber, CIH, Nicolas Pitre.
+ * Based on rtc.c by Paul Gortmaker
+ * Copyright (C) 2009 Andes Technology Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/time.h>
+#include <linux/rtc.h>
+#include <linux/poll.h>
+#include <linux/proc_fs.h>
+#include <linux/miscdevice.h>
+#include <linux/spinlock.h>
+#include <linux/capability.h>
+#include <linux/device.h>
+#include <linux/mutex.h>
+#include <linux/rtc.h>
+
+#include <asm/rtc.h>
+#include <asm/semaphore.h>
+
+static DECLARE_WAIT_QUEUE_HEAD(rtc_wait);
+static struct fasync_struct *rtc_async_queue;
+
+/*
+ * rtc_lock protects rtc_irq_data
+ */
+static DEFINE_SPINLOCK(rtc_lock);
+static unsigned long rtc_irq_data;
+
+/*
+ * rtc_sem protects rtc_inuse and rtc_ops
+ */
+static DEFINE_MUTEX(rtc_mutex);
+static unsigned long rtc_inuse;
+static struct rtc_ops *rtc_ops;
+
+#define rtc_epoch 1900UL
+
+/*
+ * Calculate the next alarm time given the requested alarm time mask
+ * and the current time.
+ */
+void rtc_next_alarm_time(struct rtc_time *next, struct rtc_time *now,
+ struct rtc_time *alrm)
+{
+ unsigned long next_time;
+ unsigned long now_time;
+
+ next->tm_year = now->tm_year;
+ next->tm_mon = now->tm_mon;
+ next->tm_mday = now->tm_mday;
+ next->tm_hour = alrm->tm_hour;
+ next->tm_min = alrm->tm_min;
+ next->tm_sec = alrm->tm_sec;
+
+ rtc_tm_to_time(now, &now_time);
+ rtc_tm_to_time(next, &next_time);
+
+ if (next_time < now_time) {
+ /* Advance one day */
+ next_time += 60 * 60 * 24;
+ rtc_time_to_tm(next_time, next);
+ }
+}
+
+static inline int rtc_arm_read_time(struct rtc_ops *ops, struct rtc_time *tm)
+{
+ memset(tm, 0, sizeof(struct rtc_time));
+ return ops->read_time(tm);
+}
+
+static inline int rtc_arm_set_time(struct rtc_ops *ops, struct rtc_time *tm)
+{
+ int ret;
+
+ ret = rtc_valid_tm(tm);
+ if (ret == 0)
+ ret = ops->set_time(tm);
+
+ return ret;
+}
+
+static inline int rtc_arm_read_alarm(struct rtc_ops *ops,
+ struct rtc_wkalrm *alrm)
+{
+ int ret = -EINVAL;
+ if (ops->read_alarm) {
+ memset(alrm, 0, sizeof(struct rtc_wkalrm));
+ ret = ops->read_alarm(alrm);
+ }
+ return ret;
+}
+
+static inline int rtc_arm_set_alarm(struct rtc_ops *ops,
+ struct rtc_wkalrm *alrm)
+{
+ int ret = -EINVAL;
+ if (ops->set_alarm)
+ ret = ops->set_alarm(alrm);
+ return ret;
+}
+
+void rtc_update(unsigned long num, unsigned long events)
+{
+ spin_lock(&rtc_lock);
+ rtc_irq_data = (rtc_irq_data + (num << 8)) | events;
+ spin_unlock(&rtc_lock);
+
+ wake_up_interruptible(&rtc_wait);
+ kill_fasync(&rtc_async_queue, SIGIO, POLL_IN);
+}
+
+EXPORT_SYMBOL(rtc_update);
+
+static ssize_t
+rtc_read(struct file *file, char __user * buf, size_t count, loff_t * ppos)
+{
+ DECLARE_WAITQUEUE(wait, current);
+ unsigned long data;
+ ssize_t ret;
+
+ if (count < sizeof(unsigned long))
+ return -EINVAL;
+
+ add_wait_queue(&rtc_wait, &wait);
+ do {
+ __set_current_state(TASK_INTERRUPTIBLE);
+
+ spin_lock_irq(&rtc_lock);
+ data = rtc_irq_data;
+ rtc_irq_data = 0;
+ spin_unlock_irq(&rtc_lock);
+
+ if (data != 0) {
+ ret = 0;
+ break;
+ }
+ if (file->f_flags & O_NONBLOCK) {
+ ret = -EAGAIN;
+ break;
+ }
+ if (signal_pending(current)) {
+ ret = -ERESTARTSYS;
+ break;
+ }
+ schedule();
+ } while (1);
+ set_current_state(TASK_RUNNING);
+ remove_wait_queue(&rtc_wait, &wait);
+
+ if (ret == 0) {
+ ret = put_user(data, (unsigned long __user *)buf);
+ if (ret == 0)
+ ret = sizeof(unsigned long);
+ }
+ return ret;
+}
+
+static unsigned int rtc_poll(struct file *file, poll_table * wait)
+{
+ unsigned long data;
+
+ poll_wait(file, &rtc_wait, wait);
+
+ spin_lock_irq(&rtc_lock);
+ data = rtc_irq_data;
+ spin_unlock_irq(&rtc_lock);
+
+ return data != 0 ? POLLIN | POLLRDNORM : 0;
+}
+
+static int rtc_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
+ unsigned long arg)
+{
+ struct rtc_ops *ops = file->private_data;
+ struct rtc_time tm;
+ struct rtc_wkalrm alrm;
+ void __user *uarg = (void __user *)arg;
+ int ret = -EINVAL;
+
+ switch (cmd) {
+ case RTC_ALM_READ:
+ ret = rtc_arm_read_alarm(ops, &alrm);
+ if (ret)
+ break;
+ ret = copy_to_user(uarg, &alrm.time, sizeof(tm));
+ if (ret)
+ ret = -EFAULT;
+ break;
+
+ case RTC_ALM_SET:
+ ret = copy_from_user(&alrm.time, uarg, sizeof(tm));
+ if (ret) {
+ ret = -EFAULT;
+ break;
+ }
+ alrm.enabled = 0;
+ alrm.pending = 0;
+ alrm.time.tm_mday = -1;
+ alrm.time.tm_mon = -1;
+ alrm.time.tm_year = -1;
+ alrm.time.tm_wday = -1;
+ alrm.time.tm_yday = -1;
+ alrm.time.tm_isdst = -1;
+ ret = rtc_arm_set_alarm(ops, &alrm);
+ break;
+
+ case RTC_RD_TIME:
+ ret = rtc_arm_read_time(ops, &tm);
+ if (ret)
+ break;
+ ret = copy_to_user(uarg, &tm, sizeof(tm));
+ if (ret)
+ ret = -EFAULT;
+ break;
+
+ case RTC_SET_TIME:
+ if (!capable(CAP_SYS_TIME)) {
+ ret = -EACCES;
+ break;
+ }
+ ret = copy_from_user(&tm, uarg, sizeof(tm));
+ if (ret) {
+ ret = -EFAULT;
+ break;
+ }
+ ret = rtc_arm_set_time(ops, &tm);
+ break;
+
+ case RTC_EPOCH_SET:
+#ifndef rtc_epoch
+ /*
+ * There were no RTC clocks before 1900.
+ */
+ if (arg < 1900) {
+ ret = -EINVAL;
+ break;
+ }
+ if (!capable(CAP_SYS_TIME)) {
+ ret = -EACCES;
+ break;
+ }
+ rtc_epoch = arg;
+ ret = 0;
+#endif
+ break;
+
+ case RTC_EPOCH_READ:
+ ret = put_user(rtc_epoch, (unsigned long __user *)uarg);
+ break;
+
+ case RTC_WKALM_SET:
+ ret = copy_from_user(&alrm, uarg, sizeof(alrm));
+ if (ret) {
+ ret = -EFAULT;
+ break;
+ }
+ ret = rtc_arm_set_alarm(ops, &alrm);
+ break;
+
+ case RTC_WKALM_RD:
+ ret = rtc_arm_read_alarm(ops, &alrm);
+ if (ret)
+ break;
+ ret = copy_to_user(uarg, &alrm, sizeof(alrm));
+ if (ret)
+ ret = -EFAULT;
+ break;
+
+ default:
+ if (ops->ioctl)
+ ret = ops->ioctl(cmd, arg);
+ break;
+ }
+ return ret;
+}
+
+static int rtc_open(struct inode *inode, struct file *file)
+{
+ int ret;
+
+ mutex_lock(&rtc_mutex);
+
+ if (rtc_inuse) {
+ ret = -EBUSY;
+ } else if (!rtc_ops || !try_module_get(rtc_ops->owner)) {
+ ret = -ENODEV;
+ } else {
+ file->private_data = rtc_ops;
+
+ ret = rtc_ops->open ? rtc_ops->open() : 0;
+ if (ret == 0) {
+ spin_lock_irq(&rtc_lock);
+ rtc_irq_data = 0;
+ spin_unlock_irq(&rtc_lock);
+
+ rtc_inuse = 1;
+ }
+ }
+ mutex_unlock(&rtc_mutex);
+
+ return ret;
+}
+
+static int rtc_release(struct inode *inode, struct file *file)
+{
+ struct rtc_ops *ops = file->private_data;
+
+ if (ops->release)
+ ops->release();
+
+ spin_lock_irq(&rtc_lock);
+ rtc_irq_data = 0;
+ spin_unlock_irq(&rtc_lock);
+
+ module_put(rtc_ops->owner);
+ rtc_inuse = 0;
+
+ return 0;
+}
+
+static int rtc_fasync(int fd, struct file *file, int on)
+{
+ return fasync_helper(fd, file, on, &rtc_async_queue);
+}
+
+static struct file_operations rtc_fops = {
+ .owner = THIS_MODULE,
+ .llseek = no_llseek,
+ .read = rtc_read,
+ .poll = rtc_poll,
+ .ioctl = rtc_ioctl,
+ .open = rtc_open,
+ .release = rtc_release,
+ .fasync = rtc_fasync,
+};
+
+static struct miscdevice rtc_miscdev = {
+ .minor = RTC_MINOR,
+ .name = "rtc",
+ .fops = &rtc_fops,
+};
+
+static int rtc_read_proc(char *page, char **start, off_t off, int count,
+ int *eof, void *data)
+{
+ struct rtc_ops *ops = data;
+ struct rtc_wkalrm alrm;
+ struct rtc_time tm;
+ char *p = page;
+
+ if (rtc_arm_read_time(ops, &tm) == 0) {
+ p += sprintf(p,
+ "rtc_time\t: %02d:%02d:%02d\n"
+ "rtc_date\t: %04d-%02d-%02d\n"
+ "rtc_epoch\t: %04lu\n",
+ tm.tm_hour, tm.tm_min, tm.tm_sec,
+ tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
+ rtc_epoch);
+ }
+
+ if (rtc_arm_read_alarm(ops, &alrm) == 0) {
+ p += sprintf(p, "alrm_time\t: ");
+ if ((unsigned int)alrm.time.tm_hour <= 24)
+ p += sprintf(p, "%02d:", alrm.time.tm_hour);
+ else
+ p += sprintf(p, "**:");
+ if ((unsigned int)alrm.time.tm_min <= 59)
+ p += sprintf(p, "%02d:", alrm.time.tm_min);
+ else
+ p += sprintf(p, "**:");
+ if ((unsigned int)alrm.time.tm_sec <= 59)
+ p += sprintf(p, "%02d\n", alrm.time.tm_sec);
+ else
+ p += sprintf(p, "**\n");
+
+ p += sprintf(p, "alrm_date\t: ");
+ if ((unsigned int)alrm.time.tm_year <= 200)
+ p += sprintf(p, "%04d-", alrm.time.tm_year + 1900);
+ else
+ p += sprintf(p, "****-");
+ if ((unsigned int)alrm.time.tm_mon <= 11)
+ p += sprintf(p, "%02d-", alrm.time.tm_mon + 1);
+ else
+ p += sprintf(p, "**-");
+ if ((unsigned int)alrm.time.tm_mday <= 31)
+ p += sprintf(p, "%02d\n", alrm.time.tm_mday);
+ else
+ p += sprintf(p, "**\n");
+ p += sprintf(p, "alrm_wakeup\t: %s\n",
+ alrm.enabled ? "yes" : "no");
+ p += sprintf(p, "alrm_pending\t: %s\n",
+ alrm.pending ? "yes" : "no");
+ }
+
+ if (ops->proc)
+ p += ops->proc(p);
+
+ return p - page;
+}
+
+int register_rtc(struct rtc_ops *ops)
+{
+ int ret = -EBUSY;
+
+ mutex_lock(&rtc_mutex);
+ if (rtc_ops == NULL) {
+ rtc_ops = ops;
+
+ ret = misc_register(&rtc_miscdev);
+ if (ret == 0)
+ create_proc_read_entry("driver/rtc", 0, NULL,
+ rtc_read_proc, ops);
+ }
+ mutex_unlock(&rtc_mutex);
+
+ return ret;
+}
+
+EXPORT_SYMBOL(register_rtc);
+
+void unregister_rtc(struct rtc_ops *rtc)
+{
+ mutex_lock(&rtc_mutex);
+ if (rtc == rtc_ops) {
+ remove_proc_entry("driver/rtc", NULL);
+ misc_deregister(&rtc_miscdev);
+ rtc_ops = NULL;
+ }
+ mutex_unlock(&rtc_mutex);
+}
+
+EXPORT_SYMBOL(unregister_rtc);
diff -Nur linux-3.4.113.orig/arch/nds32/configs/orca_8k_defconfig linux-3.4.113/arch/nds32/configs/orca_8k_defconfig
--- linux-3.4.113.orig/arch/nds32/configs/orca_8k_defconfig 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/configs/orca_8k_defconfig 2016-12-01 20:59:24.328611826 +0100
@@ -0,0 +1,132 @@
+CONFIG_EXPERIMENTAL=y
+CONFIG_CROSS_COMPILE="nds32le-linux-"
+# CONFIG_LOCALVERSION_AUTO is not set
+CONFIG_SYSVIPC=y
+CONFIG_POSIX_MQUEUE=y
+CONFIG_BSD_PROCESS_ACCT=y
+CONFIG_BSD_PROCESS_ACCT_V3=y
+CONFIG_IKCONFIG=y
+CONFIG_IKCONFIG_PROC=y
+CONFIG_LOG_BUF_SHIFT=14
+CONFIG_BLK_DEV_INITRD=y
+CONFIG_CC_OPTIMIZE_FOR_SIZE=y
+CONFIG_SYSCTL_SYSCALL=y
+# CONFIG_HOTPLUG is not set
+# CONFIG_SIGNALFD is not set
+CONFIG_EMBEDDED=y
+# CONFIG_VM_EVENT_COUNTERS is not set
+CONFIG_PROFILING=y
+CONFIG_OPROFILE=y
+CONFIG_MODULES=y
+CONFIG_MODULE_UNLOAD=y
+# CONFIG_BLK_DEV_BSG is not set
+CONFIG_PLATFORM_AHBDMA=y
+CONFIG_PLATFORM_APBDMA=y
+CONFIG_SYS_CLK=30000000
+CONFIG_UART_CLK=14745600
+CONFIG_SDRAM_SIZE=0x40000000
+CONFIG_CPU_CACHE_NONALIASING=y
+CONFIG_ANDES_PAGE_SIZE_8KB=y
+CONFIG_HIGHMEM=y
+CONFIG_HZ_100=y
+CONFIG_CMDLINE="root=/dev/ram0 rw mem=1024M@0x0 initrd=0x1000000,8M earlyprintk=uart8250-32bit,0x99600000 console=ttyS0,38400n8 loglevel=7 rootfstype=ext2 init=/bin/busybox init -s user_debug=-1"
+# CONFIG_CORE_DUMP_DEFAULT_ELF_HEADERS is not set
+CONFIG_NET=y
+CONFIG_PACKET=y
+CONFIG_UNIX=y
+CONFIG_NET_KEY=y
+CONFIG_INET=y
+CONFIG_IP_MULTICAST=y
+# CONFIG_INET_XFRM_MODE_TRANSPORT is not set
+# CONFIG_INET_XFRM_MODE_TUNNEL is not set
+# CONFIG_INET_XFRM_MODE_BEET is not set
+# CONFIG_INET_LRO is not set
+# CONFIG_INET_DIAG is not set
+# CONFIG_IPV6 is not set
+CONFIG_BRIDGE=y
+CONFIG_MTD=y
+CONFIG_MTD_CMDLINE_PARTS=y
+CONFIG_MTD_CHAR=y
+CONFIG_MTD_BLOCK=y
+CONFIG_MTD_CFI=y
+CONFIG_MTD_CFI_INTELEXT=y
+CONFIG_MTD_PHYSMAP=y
+CONFIG_MTD_PHYSMAP_COMPAT=y
+CONFIG_MTD_PHYSMAP_START=0x80400000
+CONFIG_MTD_PHYSMAP_LEN=0x2000000
+CONFIG_MTD_PHYSMAP_BANKWIDTH=4
+CONFIG_BLK_DEV_LOOP=y
+CONFIG_BLK_DEV_RAM=y
+CONFIG_BLK_DEV_RAM_SIZE=8192
+CONFIG_NETDEVICES=y
+CONFIG_TUN=y
+CONFIG_FTMAC100=y
+# CONFIG_INPUT_MOUSEDEV is not set
+CONFIG_INPUT_EVDEV=y
+# CONFIG_INPUT_KEYBOARD is not set
+# CONFIG_INPUT_MOUSE is not set
+CONFIG_INPUT_TOUCHSCREEN=y
+CONFIG_TOUCHSCREEN_CPE_TS=y
+# CONFIG_SERIO is not set
+CONFIG_SERIAL_8250=y
+CONFIG_SERIAL_8250_CONSOLE=y
+CONFIG_SERIAL_8250_NR_UARTS=3
+CONFIG_SERIAL_8250_RUNTIME_UARTS=3
+# CONFIG_HW_RANDOM is not set
+CONFIG_GPIOLIB=y
+CONFIG_GPIO_SYSFS=y
+CONFIG_GPIO_FTGPIO010=y
+# CONFIG_HWMON is not set
+CONFIG_WATCHDOG=y
+CONFIG_FTWDT010_WATCHDOG=y
+CONFIG_FB=y
+CONFIG_FB_FTLCDC100=y
+# CONFIG_VGA_CONSOLE is not set
+CONFIG_FRAMEBUFFER_CONSOLE=y
+CONFIG_LOGO=y
+CONFIG_SOUND=y
+CONFIG_SND=y
+CONFIG_SND_PCM_OSS=y
+# CONFIG_SND_SUPPORT_OLD_API is not set
+# CONFIG_SND_VERBOSE_PROCFS is not set
+CONFIG_SND_FTSSP010=y
+# CONFIG_HID_SUPPORT is not set
+# CONFIG_USB_SUPPORT is not set
+CONFIG_MMC=y
+CONFIG_MMC_FTSDC010=y
+CONFIG_RTC_CLASS=y
+# CONFIG_RTC_HCTOSYS is not set
+CONFIG_RTC_DRV_FTRTC010=y
+CONFIG_EXT2_FS=y
+CONFIG_FUSE_FS=y
+CONFIG_MSDOS_FS=y
+CONFIG_VFAT_FS=y
+# CONFIG_PROC_PAGE_MONITOR is not set
+CONFIG_TMPFS=y
+CONFIG_JFFS2_FS=y
+CONFIG_NFS_FS=y
+CONFIG_NFS_V3=y
+CONFIG_NFS_V3_ACL=y
+CONFIG_NFS_V4=y
+CONFIG_NFS_V4_1=y
+CONFIG_NFS_USE_LEGACY_DNS=y
+CONFIG_NLS_CODEPAGE_437=y
+CONFIG_NLS_ISO8859_1=y
+CONFIG_MAGIC_SYSRQ=y
+CONFIG_DEBUG_FS=y
+CONFIG_DEBUG_SHIRQ=y
+CONFIG_SCHEDSTATS=y
+CONFIG_TIMER_STATS=y
+CONFIG_SLUB_DEBUG_ON=y
+CONFIG_DEBUG_RT_MUTEXES=y
+CONFIG_DEBUG_SPINLOCK=y
+CONFIG_DEBUG_MUTEXES=y
+CONFIG_DEBUG_INFO=y
+CONFIG_DEBUG_MEMORY_INIT=y
+CONFIG_DEBUG_LIST=y
+CONFIG_DEBUG_SG=y
+# CONFIG_FTRACE is not set
+CONFIG_DEBUG_USER=y
+CONFIG_DEBUG_ERRORS=y
+# CONFIG_CRYPTO_ANSI_CPRNG is not set
+# CONFIG_CRYPTO_HW is not set
diff -Nur linux-3.4.113.orig/arch/nds32/configs/orca_defconfig linux-3.4.113/arch/nds32/configs/orca_defconfig
--- linux-3.4.113.orig/arch/nds32/configs/orca_defconfig 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/configs/orca_defconfig 2016-12-01 20:59:24.328611826 +0100
@@ -0,0 +1,125 @@
+CONFIG_EXPERIMENTAL=y
+CONFIG_CROSS_COMPILE="nds32le-linux-"
+CONFIG_SYSVIPC=y
+CONFIG_POSIX_MQUEUE=y
+CONFIG_BSD_PROCESS_ACCT=y
+CONFIG_BSD_PROCESS_ACCT_V3=y
+CONFIG_IKCONFIG=y
+CONFIG_IKCONFIG_PROC=y
+CONFIG_LOG_BUF_SHIFT=14
+CONFIG_NAMESPACES=y
+CONFIG_SYSCTL_SYSCALL=y
+CONFIG_KALLSYMS_ALL=y
+# CONFIG_HOTPLUG is not set
+CONFIG_EMBEDDED=y
+# CONFIG_VM_EVENT_COUNTERS is not set
+CONFIG_PROFILING=y
+CONFIG_OPROFILE=y
+CONFIG_MODULES=y
+CONFIG_MODULE_UNLOAD=y
+# CONFIG_BLK_DEV_BSG is not set
+CONFIG_MEASURE_INTERRUPT_LATENCY=y
+CONFIG_PLATFORM_AHBDMA=y
+CONFIG_PLATFORM_APBDMA=y
+CONFIG_SYS_CLK=30000000
+CONFIG_UART_CLK=14745600
+CONFIG_SDRAM_SIZE=0x40000000
+CONFIG_MEMORY_START=0x0
+# CONFIG_HWZOL is not set
+CONFIG_IVIC=y
+CONFIG_HIGH_RES_TIMERS=y
+CONFIG_PREEMPT=y
+CONFIG_HZ_100=y
+# CONFIG_CORE_DUMP_DEFAULT_ELF_HEADERS is not set
+CONFIG_NET=y
+CONFIG_PACKET=y
+CONFIG_UNIX=y
+CONFIG_NET_KEY=y
+CONFIG_INET=y
+CONFIG_IP_MULTICAST=y
+# CONFIG_INET_XFRM_MODE_TRANSPORT is not set
+# CONFIG_INET_XFRM_MODE_TUNNEL is not set
+# CONFIG_INET_XFRM_MODE_BEET is not set
+# CONFIG_INET_LRO is not set
+# CONFIG_INET_DIAG is not set
+# CONFIG_IPV6 is not set
+CONFIG_BRIDGE=y
+CONFIG_MTD=y
+CONFIG_MTD_CMDLINE_PARTS=y
+CONFIG_MTD_CHAR=y
+CONFIG_MTD_BLOCK=y
+CONFIG_MTD_CFI=y
+CONFIG_MTD_CFI_INTELEXT=y
+CONFIG_MTD_PHYSMAP=y
+CONFIG_MTD_PHYSMAP_COMPAT=y
+CONFIG_MTD_PHYSMAP_START=0x80400000
+CONFIG_MTD_PHYSMAP_LEN=0x2000000
+CONFIG_MTD_PHYSMAP_BANKWIDTH=4
+CONFIG_BLK_DEV_LOOP=y
+CONFIG_BLK_DEV_RAM=y
+CONFIG_BLK_DEV_RAM_SIZE=8192
+CONFIG_NETDEVICES=y
+CONFIG_TUN=y
+CONFIG_FTMAC100=y
+# CONFIG_INPUT_MOUSEDEV is not set
+CONFIG_INPUT_EVDEV=y
+# CONFIG_INPUT_KEYBOARD is not set
+# CONFIG_INPUT_MOUSE is not set
+CONFIG_INPUT_TOUCHSCREEN=y
+CONFIG_TOUCHSCREEN_CPE_TS=m
+# CONFIG_SERIO is not set
+CONFIG_SERIAL_8250=y
+CONFIG_SERIAL_8250_CONSOLE=y
+CONFIG_SERIAL_8250_NR_UARTS=3
+CONFIG_SERIAL_8250_RUNTIME_UARTS=3
+# CONFIG_HW_RANDOM is not set
+CONFIG_GPIOLIB=y
+CONFIG_GPIO_SYSFS=y
+CONFIG_GPIO_FTGPIO010=m
+# CONFIG_HWMON is not set
+CONFIG_WATCHDOG=y
+CONFIG_FTWDT010_WATCHDOG=m
+CONFIG_FB=y
+CONFIG_FB_FTLCDC100=y
+# CONFIG_VGA_CONSOLE is not set
+CONFIG_FRAMEBUFFER_CONSOLE=y
+CONFIG_LOGO=y
+CONFIG_SOUND=y
+CONFIG_SND=y
+CONFIG_SND_PCM_OSS=y
+# CONFIG_SND_SUPPORT_OLD_API is not set
+# CONFIG_SND_VERBOSE_PROCFS is not set
+CONFIG_SND_FTSSP010=m
+# CONFIG_HID_SUPPORT is not set
+# CONFIG_USB_SUPPORT is not set
+CONFIG_MMC=y
+CONFIG_MMC_FTSDC010=y
+CONFIG_RTC_CLASS=y
+# CONFIG_RTC_HCTOSYS is not set
+CONFIG_RTC_DRV_FTRTC010=y
+CONFIG_EXT2_FS=y
+CONFIG_FUSE_FS=y
+CONFIG_MSDOS_FS=y
+CONFIG_VFAT_FS=y
+CONFIG_TMPFS=y
+CONFIG_TMPFS_POSIX_ACL=y
+CONFIG_CONFIGFS_FS=y
+CONFIG_JFFS2_FS=y
+CONFIG_NFS_FS=y
+CONFIG_NFS_V3=y
+CONFIG_NFS_V3_ACL=y
+CONFIG_NFS_V4=y
+CONFIG_NFS_V4_1=y
+CONFIG_NFS_USE_LEGACY_DNS=y
+CONFIG_NLS_CODEPAGE_437=y
+CONFIG_NLS_ISO8859_1=y
+CONFIG_MAGIC_SYSRQ=y
+CONFIG_HEADERS_CHECK=y
+CONFIG_DEBUG_SECTION_MISMATCH=y
+# CONFIG_SCHED_DEBUG is not set
+CONFIG_DEBUG_INFO=y
+# CONFIG_FTRACE is not set
+CONFIG_DEBUG_USER=y
+CONFIG_DEBUG_ERRORS=y
+# CONFIG_CRYPTO_ANSI_CPRNG is not set
+# CONFIG_CRYPTO_HW is not set
diff -Nur linux-3.4.113.orig/arch/nds32/configs/qemu_defconfig linux-3.4.113/arch/nds32/configs/qemu_defconfig
--- linux-3.4.113.orig/arch/nds32/configs/qemu_defconfig 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/configs/qemu_defconfig 2016-12-01 20:59:24.328611826 +0100
@@ -0,0 +1,98 @@
+CONFIG_EXPERIMENTAL=y
+# CONFIG_LOCALVERSION_AUTO is not set
+CONFIG_SYSVIPC=y
+CONFIG_BSD_PROCESS_ACCT=y
+CONFIG_BSD_PROCESS_ACCT_V3=y
+CONFIG_LOG_BUF_SHIFT=14
+CONFIG_BLK_DEV_INITRD=y
+CONFIG_CC_OPTIMIZE_FOR_SIZE=y
+CONFIG_SYSCTL_SYSCALL=y
+# CONFIG_HOTPLUG is not set
+# CONFIG_SIGNALFD is not set
+CONFIG_EMBEDDED=y
+# CONFIG_VM_EVENT_COUNTERS is not set
+CONFIG_PROFILING=y
+CONFIG_OPROFILE=y
+CONFIG_MODULES=y
+CONFIG_MODULE_UNLOAD=y
+# CONFIG_BLK_DEV_BSG is not set
+CONFIG_PLAT_QEMU=y
+CONFIG_SYS_CLK=40000000
+CONFIG_UART_CLK=14745600
+CONFIG_SDRAM_SIZE=0x10000000
+CONFIG_HZ_100=y
+CONFIG_CMDLINE="root=/dev/ram0 rw mem=1024M@0x0 initrd=0x1000000,8M earlyprintk=uart8250-32bit,0x99600000 console=ttyS0,38400n8 loglevel=7 rootfstype=ext2 init=/bin/busybox init -s user_debug=-1"
+# CONFIG_CORE_DUMP_DEFAULT_ELF_HEADERS is not set
+CONFIG_NET=y
+CONFIG_PACKET=y
+CONFIG_UNIX=y
+CONFIG_NET_KEY=y
+CONFIG_INET=y
+CONFIG_IP_MULTICAST=y
+# CONFIG_INET_XFRM_MODE_TRANSPORT is not set
+# CONFIG_INET_XFRM_MODE_TUNNEL is not set
+# CONFIG_INET_XFRM_MODE_BEET is not set
+# CONFIG_INET_LRO is not set
+# CONFIG_INET_DIAG is not set
+# CONFIG_IPV6 is not set
+CONFIG_BLK_DEV_LOOP=y
+CONFIG_BLK_DEV_RAM=y
+CONFIG_BLK_DEV_RAM_SIZE=8192
+CONFIG_FTSDC010=y
+CONFIG_NETDEVICES=y
+CONFIG_FTMAC100=y
+# CONFIG_INPUT_MOUSEDEV is not set
+CONFIG_INPUT_EVDEV=y
+# CONFIG_INPUT_KEYBOARD is not set
+# CONFIG_INPUT_MOUSE is not set
+CONFIG_INPUT_TOUCHSCREEN=y
+# CONFIG_SERIO is not set
+CONFIG_SERIAL_8250=y
+CONFIG_SERIAL_8250_CONSOLE=y
+CONFIG_SERIAL_8250_NR_UARTS=3
+CONFIG_SERIAL_8250_RUNTIME_UARTS=3
+# CONFIG_HW_RANDOM is not set
+# CONFIG_HWMON is not set
+CONFIG_FB=y
+# CONFIG_VGA_CONSOLE is not set
+CONFIG_FRAMEBUFFER_CONSOLE=y
+CONFIG_LOGO=y
+# CONFIG_HID_SUPPORT is not set
+# CONFIG_USB_SUPPORT is not set
+CONFIG_EXT2_FS=y
+CONFIG_EXT2_FS_XATTR=y
+CONFIG_EXT2_FS_POSIX_ACL=y
+CONFIG_EXT2_FS_SECURITY=y
+CONFIG_EXT2_FS_XIP=y
+CONFIG_EXT3_FS=y
+CONFIG_EXT3_FS_POSIX_ACL=y
+CONFIG_EXT3_FS_SECURITY=y
+CONFIG_EXT4_FS=y
+CONFIG_EXT4_FS_POSIX_ACL=y
+CONFIG_EXT4_FS_SECURITY=y
+CONFIG_EXT4_DEBUG=y
+CONFIG_FUSE_FS=y
+CONFIG_MSDOS_FS=y
+CONFIG_VFAT_FS=y
+# CONFIG_PROC_PAGE_MONITOR is not set
+CONFIG_TMPFS=y
+CONFIG_NFS_FS=y
+CONFIG_NFS_V3=y
+CONFIG_NLS_CODEPAGE_437=y
+CONFIG_NLS_ISO8859_1=y
+CONFIG_MAGIC_SYSRQ=y
+CONFIG_DEBUG_FS=y
+CONFIG_DEBUG_SHIRQ=y
+CONFIG_DETECT_HUNG_TASK=y
+CONFIG_SCHEDSTATS=y
+CONFIG_TIMER_STATS=y
+CONFIG_SLUB_DEBUG_ON=y
+CONFIG_DEBUG_RT_MUTEXES=y
+CONFIG_DEBUG_MUTEXES=y
+CONFIG_DEBUG_INFO=y
+CONFIG_DEBUG_LIST=y
+CONFIG_DEBUG_SG=y
+CONFIG_DEBUG_USER=y
+CONFIG_DEBUG_ERRORS=y
+# CONFIG_CRYPTO_ANSI_CPRNG is not set
+# CONFIG_CRYPTO_HW is not set
diff -Nur linux-3.4.113.orig/arch/nds32/configs/vep-be_defconfig linux-3.4.113/arch/nds32/configs/vep-be_defconfig
--- linux-3.4.113.orig/arch/nds32/configs/vep-be_defconfig 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/configs/vep-be_defconfig 2016-12-01 20:59:24.328611826 +0100
@@ -0,0 +1,777 @@
+#
+# Automatically generated make config: don't edit
+# Linux kernel version: 2.6.29
+# Mon Jul 13 11:42:57 2009
+#
+CONFIG_NDS32=y
+CONFIG_NO_IOPORT=y
+CONFIG_GENERIC_IOMAP=y
+CONFIG_RWSEM_GENERIC_SPINLOCK=y
+CONFIG_GENERIC_HWEIGHT=y
+CONFIG_GENERIC_FIND_NEXT_BIT=y
+CONFIG_GENERIC_CALIBRATE_DELAY=y
+CONFIG_GENERIC_HARDIRQS=y
+CONFIG_LOCKDEP_SUPPORT=y
+CONFIG_STACKTRACE_SUPPORT=y
+CONFIG_HAVE_LATENCYTOP_SUPPORT=y
+CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config"
+
+#
+# General setup
+#
+CONFIG_EXPERIMENTAL=y
+CONFIG_BROKEN_ON_SMP=y
+CONFIG_INIT_ENV_ARG_LIMIT=32
+CONFIG_LOCALVERSION=""
+# CONFIG_LOCALVERSION_AUTO is not set
+CONFIG_SWAP=y
+CONFIG_SYSVIPC=y
+CONFIG_SYSVIPC_SYSCTL=y
+# CONFIG_POSIX_MQUEUE is not set
+CONFIG_BSD_PROCESS_ACCT=y
+CONFIG_BSD_PROCESS_ACCT_V3=y
+# CONFIG_TASKSTATS is not set
+# CONFIG_AUDIT is not set
+
+#
+# RCU Subsystem
+#
+CONFIG_CLASSIC_RCU=y
+# CONFIG_TREE_RCU is not set
+# CONFIG_PREEMPT_RCU is not set
+# CONFIG_TREE_RCU_TRACE is not set
+# CONFIG_PREEMPT_RCU_TRACE is not set
+# CONFIG_IKCONFIG is not set
+CONFIG_LOG_BUF_SHIFT=14
+# CONFIG_GROUP_SCHED is not set
+# CONFIG_CGROUPS is not set
+# CONFIG_SYSFS_DEPRECATED_V2 is not set
+# CONFIG_RELAY is not set
+# CONFIG_NAMESPACES is not set
+CONFIG_BLK_DEV_INITRD=y
+CONFIG_INITRAMFS_SOURCE=""
+CONFIG_CC_OPTIMIZE_FOR_SIZE=y
+CONFIG_SYSCTL=y
+CONFIG_ANON_INODES=y
+CONFIG_EMBEDDED=y
+CONFIG_UID16=y
+CONFIG_SYSCTL_SYSCALL=y
+# CONFIG_KALLSYMS is not set
+# CONFIG_HOTPLUG is not set
+CONFIG_PRINTK=y
+CONFIG_BUG=y
+# CONFIG_ELF_CORE is not set
+CONFIG_BASE_FULL=y
+CONFIG_FUTEX=y
+CONFIG_EPOLL=y
+# CONFIG_SIGNALFD is not set
+CONFIG_TIMERFD=y
+CONFIG_EVENTFD=y
+CONFIG_SHMEM=y
+CONFIG_AIO=y
+# CONFIG_VM_EVENT_COUNTERS is not set
+CONFIG_SLUB_DEBUG=y
+CONFIG_COMPAT_BRK=y
+# CONFIG_SLAB is not set
+CONFIG_SLUB=y
+# CONFIG_SLOB is not set
+CONFIG_PROFILING=y
+CONFIG_TRACEPOINTS=y
+# CONFIG_MARKERS is not set
+CONFIG_OPROFILE=y
+CONFIG_HAVE_OPROFILE=y
+CONFIG_HAVE_KPROBES=y
+CONFIG_HAVE_KRETPROBES=y
+# CONFIG_HAVE_GENERIC_DMA_COHERENT is not set
+CONFIG_SLABINFO=y
+CONFIG_RT_MUTEXES=y
+CONFIG_BASE_SMALL=0
+CONFIG_MODULES=y
+# CONFIG_MODULE_FORCE_LOAD is not set
+CONFIG_MODULE_UNLOAD=y
+# CONFIG_MODULE_FORCE_UNLOAD is not set
+# CONFIG_MODVERSIONS is not set
+# CONFIG_MODULE_SRCVERSION_ALL is not set
+CONFIG_BLOCK=y
+# CONFIG_LBD is not set
+# CONFIG_BLK_DEV_IO_TRACE is not set
+# CONFIG_BLK_DEV_BSG is not set
+# CONFIG_BLK_DEV_INTEGRITY is not set
+
+#
+# IO Schedulers
+#
+CONFIG_IOSCHED_NOOP=y
+# CONFIG_IOSCHED_AS is not set
+# CONFIG_IOSCHED_DEADLINE is not set
+# CONFIG_IOSCHED_CFQ is not set
+# CONFIG_DEFAULT_AS is not set
+# CONFIG_DEFAULT_DEADLINE is not set
+# CONFIG_DEFAULT_CFQ is not set
+CONFIG_DEFAULT_NOOP=y
+CONFIG_DEFAULT_IOSCHED="noop"
+# CONFIG_FREEZER is not set
+
+#
+# System Type
+#
+# CONFIG_PLAT_FARADAY is not set
+CONFIG_PLAT_VEP=y
+# CONFIG_PLAT_AG101 is not set
+# CONFIG_PLAT_AG102 is not set
+# CONFIG_PLAT_AG101P is not set
+# CONFIG_PLAT_QEMU is not set
+CONFIG_PLATFORM_INTC=y
+
+#
+# VEP Platform Options
+#
+# CONFIG_CACHE_L2 is not set
+
+#
+# Common Platform Options
+#
+# CONFIG_PLATFORM_AHBDMA is not set
+# CONFIG_PLATFORM_APBDMA is not set
+CONFIG_SYS_CLK=67737600
+CONFIG_UART_CLK=36864000
+CONFIG_SDRAM_SIZE=0x10000000
+
+#
+# Processor Features
+#
+CONFIG_CPU_CUSTOM=y
+# CONFIG_FPU is not set
+# CONFIG_AUDIO is not set
+# CONFIG_EVIC is not set
+CONFIG_CPU_CONTEXT_ID=y
+CONFIG_ANDES_PAGE_SIZE_4KB=y
+# CONFIG_ANDES_PAGE_SIZE_8KB is not set
+# CONFIG_KERNEL_SPACE_LARGE_PAGE is not set
+# CONFIG_CPU_ICACHE_DISABLE is not set
+# CONFIG_CPU_DCACHE_DISABLE is not set
+# CONFIG_CPU_DCACHE_WRITETHROUGH is not set
+# CONFIG_ALIGNMENT_TRAP is not set
+CONFIG_MMU=y
+
+#
+# Kernel Features
+#
+CONFIG_PREEMPT_NONE=y
+# CONFIG_PREEMPT_VOLUNTARY is not set
+# CONFIG_PREEMPT is not set
+CONFIG_SELECT_MEMORY_MODEL=y
+CONFIG_FLATMEM_MANUAL=y
+# CONFIG_DISCONTIGMEM_MANUAL is not set
+# CONFIG_SPARSEMEM_MANUAL is not set
+CONFIG_FLATMEM=y
+CONFIG_FLAT_NODE_MEM_MAP=y
+CONFIG_PAGEFLAGS_EXTENDED=y
+CONFIG_SPLIT_PTLOCK_CPUS=4
+# CONFIG_PHYS_ADDR_T_64BIT is not set
+CONFIG_ZONE_DMA_FLAG=0
+CONFIG_VIRT_TO_BUS=y
+CONFIG_UNEVICTABLE_LRU=y
+CONFIG_FORCE_MAX_ZONEORDER=11
+CONFIG_HZ_100=y
+# CONFIG_HZ_250 is not set
+# CONFIG_HZ_300 is not set
+# CONFIG_HZ_1000 is not set
+CONFIG_HZ=100
+# CONFIG_SCHED_HRTICK is not set
+CONFIG_CMDLINE="root=/dev/ram0 rw mem=64M@0x0 initrd=0x1000000,8M console=ttyS0,38400n8 rootfstype=ext2 init=/bin/busybox init -s user_debug=-1"
+
+#
+# Power management options
+#
+CONFIG_SYS_SUPPORTS_APM_EMULATION=y
+CONFIG_ARCH_SUSPEND_POSSIBLE=y
+# CONFIG_PM is not set
+
+#
+# Bus options
+#
+# CONFIG_PCI is not set
+# CONFIG_ARCH_SUPPORTS_MSI is not set
+
+#
+# Executable file formats
+#
+CONFIG_BINFMT_ELF=y
+# CONFIG_HAVE_AOUT is not set
+# CONFIG_BINFMT_MISC is not set
+CONFIG_NET=y
+
+#
+# Networking options
+#
+CONFIG_COMPAT_NET_DEV_OPS=y
+CONFIG_PACKET=y
+# CONFIG_PACKET_MMAP is not set
+CONFIG_UNIX=y
+CONFIG_XFRM=y
+# CONFIG_XFRM_USER is not set
+# CONFIG_XFRM_SUB_POLICY is not set
+# CONFIG_XFRM_MIGRATE is not set
+# CONFIG_XFRM_STATISTICS is not set
+CONFIG_NET_KEY=y
+# CONFIG_NET_KEY_MIGRATE is not set
+CONFIG_INET=y
+CONFIG_IP_MULTICAST=y
+# CONFIG_IP_ADVANCED_ROUTER is not set
+CONFIG_IP_FIB_HASH=y
+# CONFIG_IP_PNP is not set
+# CONFIG_NET_IPIP is not set
+# CONFIG_NET_IPGRE is not set
+# CONFIG_IP_MROUTE is not set
+# CONFIG_ARPD is not set
+# CONFIG_SYN_COOKIES is not set
+# CONFIG_INET_AH is not set
+# CONFIG_INET_ESP is not set
+# CONFIG_INET_IPCOMP is not set
+# CONFIG_INET_XFRM_TUNNEL is not set
+# CONFIG_INET_TUNNEL is not set
+# CONFIG_INET_XFRM_MODE_TRANSPORT is not set
+# CONFIG_INET_XFRM_MODE_TUNNEL is not set
+# CONFIG_INET_XFRM_MODE_BEET is not set
+# CONFIG_INET_LRO is not set
+# CONFIG_INET_DIAG is not set
+# CONFIG_TCP_CONG_ADVANCED is not set
+CONFIG_TCP_CONG_CUBIC=y
+CONFIG_DEFAULT_TCP_CONG="cubic"
+# CONFIG_TCP_MD5SIG is not set
+# CONFIG_IPV6 is not set
+# CONFIG_NETWORK_SECMARK is not set
+# CONFIG_NETFILTER is not set
+# CONFIG_IP_DCCP is not set
+# CONFIG_IP_SCTP is not set
+# CONFIG_TIPC is not set
+# CONFIG_ATM is not set
+# CONFIG_BRIDGE is not set
+# CONFIG_NET_DSA is not set
+# CONFIG_VLAN_8021Q is not set
+# CONFIG_DECNET is not set
+# CONFIG_LLC2 is not set
+# CONFIG_IPX is not set
+# CONFIG_ATALK is not set
+# CONFIG_X25 is not set
+# CONFIG_LAPB is not set
+# CONFIG_ECONET is not set
+# CONFIG_WAN_ROUTER is not set
+# CONFIG_NET_SCHED is not set
+# CONFIG_DCB is not set
+
+#
+# Network testing
+#
+# CONFIG_NET_PKTGEN is not set
+# CONFIG_HAMRADIO is not set
+# CONFIG_CAN is not set
+# CONFIG_IRDA is not set
+# CONFIG_BT is not set
+# CONFIG_AF_RXRPC is not set
+# CONFIG_PHONET is not set
+CONFIG_WIRELESS=y
+# CONFIG_CFG80211 is not set
+CONFIG_WIRELESS_OLD_REGULATORY=y
+# CONFIG_WIRELESS_EXT is not set
+# CONFIG_LIB80211 is not set
+# CONFIG_MAC80211 is not set
+# CONFIG_WIMAX is not set
+# CONFIG_RFKILL is not set
+# CONFIG_NET_9P is not set
+
+#
+# Device Drivers
+#
+
+#
+# Generic Driver Options
+#
+CONFIG_STANDALONE=y
+CONFIG_PREVENT_FIRMWARE_BUILD=y
+# CONFIG_SYS_HYPERVISOR is not set
+# CONFIG_CONNECTOR is not set
+# CONFIG_MTD is not set
+# CONFIG_PARPORT is not set
+CONFIG_BLK_DEV=y
+# CONFIG_BLK_DEV_COW_COMMON is not set
+CONFIG_BLK_DEV_LOOP=y
+# CONFIG_BLK_DEV_CRYPTOLOOP is not set
+# CONFIG_BLK_DEV_NBD is not set
+CONFIG_BLK_DEV_RAM=y
+CONFIG_BLK_DEV_RAM_COUNT=16
+CONFIG_BLK_DEV_RAM_SIZE=8192
+# CONFIG_BLK_DEV_XIP is not set
+# CONFIG_CDROM_PKTCDVD is not set
+# CONFIG_ATA_OVER_ETH is not set
+# CONFIG_FTSDC010 is not set
+# CONFIG_FTCFC010 is not set
+# CONFIG_BLK_DEV_HD is not set
+# CONFIG_MISC_DEVICES is not set
+CONFIG_HAVE_IDE=y
+# CONFIG_IDE is not set
+
+#
+# SCSI device support
+#
+# CONFIG_RAID_ATTRS is not set
+# CONFIG_SCSI is not set
+# CONFIG_SCSI_DMA is not set
+# CONFIG_SCSI_NETLINK is not set
+# CONFIG_ATA is not set
+# CONFIG_MD is not set
+CONFIG_NETDEVICES=y
+# CONFIG_DUMMY is not set
+# CONFIG_BONDING is not set
+# CONFIG_MACVLAN is not set
+# CONFIG_EQUALIZER is not set
+# CONFIG_TUN is not set
+# CONFIG_VETH is not set
+# CONFIG_PHYLIB is not set
+CONFIG_NET_ETHERNET=y
+# CONFIG_MII is not set
+# CONFIG_SMC91X is not set
+# CONFIG_DNET is not set
+# CONFIG_IBM_NEW_EMAC_ZMII is not set
+# CONFIG_IBM_NEW_EMAC_RGMII is not set
+# CONFIG_IBM_NEW_EMAC_TAH is not set
+# CONFIG_IBM_NEW_EMAC_EMAC4 is not set
+# CONFIG_IBM_NEW_EMAC_NO_FLOW_CTRL is not set
+# CONFIG_IBM_NEW_EMAC_MAL_CLR_ICINTSTAT is not set
+# CONFIG_IBM_NEW_EMAC_MAL_COMMON_ERR is not set
+# CONFIG_B44 is not set
+CONFIG_FTMAC100=y
+# CONFIG_NETDEV_1000 is not set
+# CONFIG_NETDEV_10000 is not set
+
+#
+# Wireless LAN
+#
+# CONFIG_WLAN_PRE80211 is not set
+# CONFIG_WLAN_80211 is not set
+# CONFIG_IWLWIFI_LEDS is not set
+
+#
+# Enable WiMAX (Networking options) to see the WiMAX drivers
+#
+# CONFIG_WAN is not set
+# CONFIG_PPP is not set
+# CONFIG_SLIP is not set
+# CONFIG_NETCONSOLE is not set
+# CONFIG_NETPOLL is not set
+# CONFIG_NET_POLL_CONTROLLER is not set
+# CONFIG_ISDN is not set
+# CONFIG_PHONE is not set
+
+#
+# Input device support
+#
+CONFIG_INPUT=y
+# CONFIG_INPUT_FF_MEMLESS is not set
+# CONFIG_INPUT_POLLDEV is not set
+
+#
+# Userland interfaces
+#
+# CONFIG_INPUT_MOUSEDEV is not set
+# CONFIG_INPUT_JOYDEV is not set
+# CONFIG_INPUT_EVDEV is not set
+# CONFIG_INPUT_EVBUG is not set
+
+#
+# Input Device Drivers
+#
+# CONFIG_INPUT_KEYBOARD is not set
+# CONFIG_INPUT_MOUSE is not set
+# CONFIG_INPUT_JOYSTICK is not set
+# CONFIG_INPUT_TABLET is not set
+# CONFIG_INPUT_TOUCHSCREEN is not set
+# CONFIG_INPUT_MISC is not set
+
+#
+# Hardware I/O ports
+#
+# CONFIG_SERIO is not set
+# CONFIG_GAMEPORT is not set
+
+#
+# Character devices
+#
+CONFIG_VT=y
+CONFIG_CONSOLE_TRANSLATIONS=y
+CONFIG_VT_CONSOLE=y
+CONFIG_HW_CONSOLE=y
+# CONFIG_VT_HW_CONSOLE_BINDING is not set
+CONFIG_DEVKMEM=y
+# CONFIG_SERIAL_NONSTANDARD is not set
+
+#
+# Serial drivers
+#
+CONFIG_SERIAL_8250=y
+CONFIG_SERIAL_8250_CONSOLE=y
+CONFIG_SERIAL_8250_NR_UARTS=3
+CONFIG_SERIAL_8250_RUNTIME_UARTS=3
+# CONFIG_SERIAL_8250_EXTENDED is not set
+
+#
+# Non-8250 serial port support
+#
+CONFIG_SERIAL_CORE=y
+CONFIG_SERIAL_CORE_CONSOLE=y
+CONFIG_UNIX98_PTYS=y
+# CONFIG_DEVPTS_MULTIPLE_INSTANCES is not set
+CONFIG_LEGACY_PTYS=y
+CONFIG_LEGACY_PTY_COUNT=256
+# CONFIG_IPMI_HANDLER is not set
+# CONFIG_HW_RANDOM is not set
+# CONFIG_R3964 is not set
+# CONFIG_GPIO_FTGPIO010 is not set
+# CONFIG_RAW_DRIVER is not set
+# CONFIG_TCG_TPM is not set
+# CONFIG_I2C is not set
+# CONFIG_SPI is not set
+# CONFIG_W1 is not set
+# CONFIG_POWER_SUPPLY is not set
+# CONFIG_HWMON is not set
+# CONFIG_THERMAL is not set
+# CONFIG_THERMAL_HWMON is not set
+# CONFIG_WATCHDOG is not set
+CONFIG_SSB_POSSIBLE=y
+
+#
+# Sonics Silicon Backplane
+#
+# CONFIG_SSB is not set
+
+#
+# Multifunction device drivers
+#
+# CONFIG_MFD_CORE is not set
+# CONFIG_MFD_SM501 is not set
+# CONFIG_HTC_PASIC3 is not set
+# CONFIG_MFD_TMIO is not set
+# CONFIG_REGULATOR is not set
+
+#
+# Multimedia devices
+#
+
+#
+# Multimedia core support
+#
+# CONFIG_VIDEO_DEV is not set
+# CONFIG_DVB_CORE is not set
+# CONFIG_VIDEO_MEDIA is not set
+
+#
+# Multimedia drivers
+#
+# CONFIG_DAB is not set
+
+#
+# Graphics support
+#
+# CONFIG_VGASTATE is not set
+# CONFIG_VIDEO_OUTPUT_CONTROL is not set
+# CONFIG_FB is not set
+# CONFIG_BACKLIGHT_LCD_SUPPORT is not set
+
+#
+# Display device support
+#
+# CONFIG_DISPLAY_SUPPORT is not set
+
+#
+# Console display driver support
+#
+# CONFIG_VGA_CONSOLE is not set
+CONFIG_DUMMY_CONSOLE=y
+# CONFIG_SOUND is not set
+# CONFIG_HID_SUPPORT is not set
+# CONFIG_USB_SUPPORT is not set
+# CONFIG_MMC is not set
+# CONFIG_MEMSTICK is not set
+# CONFIG_NEW_LEDS is not set
+# CONFIG_ACCESSIBILITY is not set
+CONFIG_RTC_LIB=y
+# CONFIG_RTC_CLASS is not set
+# CONFIG_DMADEVICES is not set
+# CONFIG_UIO is not set
+# CONFIG_STAGING is not set
+
+#
+# File systems
+#
+CONFIG_EXT2_FS=y
+# CONFIG_EXT2_FS_XATTR is not set
+# CONFIG_EXT2_FS_XIP is not set
+# CONFIG_EXT3_FS is not set
+# CONFIG_EXT4_FS is not set
+# CONFIG_REISERFS_FS is not set
+# CONFIG_JFS_FS is not set
+# CONFIG_FS_POSIX_ACL is not set
+CONFIG_FILE_LOCKING=y
+# CONFIG_XFS_FS is not set
+# CONFIG_OCFS2_FS is not set
+# CONFIG_BTRFS_FS is not set
+CONFIG_DNOTIFY=y
+CONFIG_INOTIFY=y
+CONFIG_INOTIFY_USER=y
+# CONFIG_QUOTA is not set
+# CONFIG_AUTOFS_FS is not set
+# CONFIG_AUTOFS4_FS is not set
+CONFIG_FUSE_FS=y
+
+#
+# CD-ROM/DVD Filesystems
+#
+# CONFIG_ISO9660_FS is not set
+# CONFIG_UDF_FS is not set
+
+#
+# DOS/FAT/NT Filesystems
+#
+# CONFIG_MSDOS_FS is not set
+# CONFIG_VFAT_FS is not set
+# CONFIG_NTFS_FS is not set
+
+#
+# Pseudo filesystems
+#
+CONFIG_PROC_FS=y
+# CONFIG_PROC_KCORE is not set
+CONFIG_PROC_SYSCTL=y
+# CONFIG_PROC_PAGE_MONITOR is not set
+CONFIG_SYSFS=y
+CONFIG_TMPFS=y
+# CONFIG_TMPFS_POSIX_ACL is not set
+# CONFIG_HUGETLB_PAGE is not set
+# CONFIG_CONFIGFS_FS is not set
+CONFIG_MISC_FILESYSTEMS=y
+# CONFIG_ADFS_FS is not set
+# CONFIG_AFFS_FS is not set
+# CONFIG_HFS_FS is not set
+# CONFIG_HFSPLUS_FS is not set
+# CONFIG_BEFS_FS is not set
+# CONFIG_BFS_FS is not set
+# CONFIG_EFS_FS is not set
+# CONFIG_CRAMFS is not set
+# CONFIG_SQUASHFS is not set
+# CONFIG_VXFS_FS is not set
+# CONFIG_MINIX_FS is not set
+# CONFIG_OMFS_FS is not set
+# CONFIG_HPFS_FS is not set
+# CONFIG_QNX4FS_FS is not set
+# CONFIG_ROMFS_FS is not set
+# CONFIG_SYSV_FS is not set
+# CONFIG_UFS_FS is not set
+CONFIG_NETWORK_FILESYSTEMS=y
+CONFIG_NFS_FS=y
+CONFIG_NFS_V3=y
+# CONFIG_NFS_V3_ACL is not set
+# CONFIG_NFS_V4 is not set
+# CONFIG_NFSD is not set
+CONFIG_LOCKD=y
+CONFIG_LOCKD_V4=y
+CONFIG_NFS_COMMON=y
+CONFIG_SUNRPC=y
+# CONFIG_SUNRPC_REGISTER_V4 is not set
+# CONFIG_RPCSEC_GSS_KRB5 is not set
+# CONFIG_RPCSEC_GSS_SPKM3 is not set
+# CONFIG_SMB_FS is not set
+# CONFIG_CIFS is not set
+# CONFIG_NCP_FS is not set
+# CONFIG_CODA_FS is not set
+# CONFIG_AFS_FS is not set
+
+#
+# Partition Types
+#
+# CONFIG_PARTITION_ADVANCED is not set
+CONFIG_MSDOS_PARTITION=y
+CONFIG_NLS=y
+CONFIG_NLS_DEFAULT="iso8859-1"
+CONFIG_NLS_CODEPAGE_437=y
+# CONFIG_NLS_CODEPAGE_737 is not set
+# CONFIG_NLS_CODEPAGE_775 is not set
+# CONFIG_NLS_CODEPAGE_850 is not set
+# CONFIG_NLS_CODEPAGE_852 is not set
+# CONFIG_NLS_CODEPAGE_855 is not set
+# CONFIG_NLS_CODEPAGE_857 is not set
+# CONFIG_NLS_CODEPAGE_860 is not set
+# CONFIG_NLS_CODEPAGE_861 is not set
+# CONFIG_NLS_CODEPAGE_862 is not set
+# CONFIG_NLS_CODEPAGE_863 is not set
+# CONFIG_NLS_CODEPAGE_864 is not set
+# CONFIG_NLS_CODEPAGE_865 is not set
+# CONFIG_NLS_CODEPAGE_866 is not set
+# CONFIG_NLS_CODEPAGE_869 is not set
+# CONFIG_NLS_CODEPAGE_936 is not set
+# CONFIG_NLS_CODEPAGE_950 is not set
+# CONFIG_NLS_CODEPAGE_932 is not set
+# CONFIG_NLS_CODEPAGE_949 is not set
+# CONFIG_NLS_CODEPAGE_874 is not set
+# CONFIG_NLS_ISO8859_8 is not set
+# CONFIG_NLS_CODEPAGE_1250 is not set
+# CONFIG_NLS_CODEPAGE_1251 is not set
+# CONFIG_NLS_ASCII is not set
+CONFIG_NLS_ISO8859_1=y
+# CONFIG_NLS_ISO8859_2 is not set
+# CONFIG_NLS_ISO8859_3 is not set
+# CONFIG_NLS_ISO8859_4 is not set
+# CONFIG_NLS_ISO8859_5 is not set
+# CONFIG_NLS_ISO8859_6 is not set
+# CONFIG_NLS_ISO8859_7 is not set
+# CONFIG_NLS_ISO8859_9 is not set
+# CONFIG_NLS_ISO8859_13 is not set
+# CONFIG_NLS_ISO8859_14 is not set
+# CONFIG_NLS_ISO8859_15 is not set
+# CONFIG_NLS_KOI8_R is not set
+# CONFIG_NLS_KOI8_U is not set
+# CONFIG_NLS_UTF8 is not set
+# CONFIG_DLM is not set
+
+#
+# Kernel hacking
+#
+CONFIG_TRACE_IRQFLAGS_SUPPORT=y
+# CONFIG_PRINTK_TIME is not set
+CONFIG_ENABLE_WARN_DEPRECATED=y
+CONFIG_ENABLE_MUST_CHECK=y
+CONFIG_FRAME_WARN=1024
+# CONFIG_MAGIC_SYSRQ is not set
+# CONFIG_UNUSED_SYMBOLS is not set
+CONFIG_DEBUG_FS=y
+# CONFIG_HEADERS_CHECK is not set
+# CONFIG_DEBUG_KERNEL is not set
+# CONFIG_SLUB_DEBUG_ON is not set
+# CONFIG_SLUB_STATS is not set
+CONFIG_STACKTRACE=y
+# CONFIG_DEBUG_MEMORY_INIT is not set
+CONFIG_FRAME_POINTER=y
+# CONFIG_RCU_CPU_STALL_DETECTOR is not set
+# CONFIG_LATENCYTOP is not set
+CONFIG_SYSCTL_SYSCALL_CHECK=y
+CONFIG_NOP_TRACER=y
+CONFIG_RING_BUFFER=y
+CONFIG_TRACING=y
+
+#
+# Tracers
+#
+# CONFIG_DYNAMIC_PRINTK_DEBUG is not set
+# CONFIG_SAMPLES is not set
+CONFIG_HAVE_ARCH_KGDB=y
+CONFIG_DEBUG_USER=y
+# CONFIG_CCTL is not set
+CONFIG_ELFCHK_DEFAULT_ENABLE=y
+
+#
+# Security options
+#
+# CONFIG_KEYS is not set
+# CONFIG_SECURITY is not set
+# CONFIG_SECURITYFS is not set
+# CONFIG_SECURITY_FILE_CAPABILITIES is not set
+CONFIG_CRYPTO=y
+
+#
+# Crypto core or helper
+#
+# CONFIG_CRYPTO_FIPS is not set
+# CONFIG_CRYPTO_MANAGER is not set
+# CONFIG_CRYPTO_MANAGER2 is not set
+# CONFIG_CRYPTO_GF128MUL is not set
+# CONFIG_CRYPTO_NULL is not set
+# CONFIG_CRYPTO_CRYPTD is not set
+# CONFIG_CRYPTO_AUTHENC is not set
+# CONFIG_CRYPTO_TEST is not set
+
+#
+# Authenticated Encryption with Associated Data
+#
+# CONFIG_CRYPTO_CCM is not set
+# CONFIG_CRYPTO_GCM is not set
+# CONFIG_CRYPTO_SEQIV is not set
+
+#
+# Block modes
+#
+# CONFIG_CRYPTO_CBC is not set
+# CONFIG_CRYPTO_CTR is not set
+# CONFIG_CRYPTO_CTS is not set
+# CONFIG_CRYPTO_ECB is not set
+# CONFIG_CRYPTO_LRW is not set
+# CONFIG_CRYPTO_PCBC is not set
+# CONFIG_CRYPTO_XTS is not set
+
+#
+# Hash modes
+#
+# CONFIG_CRYPTO_HMAC is not set
+# CONFIG_CRYPTO_XCBC is not set
+
+#
+# Digest
+#
+# CONFIG_CRYPTO_CRC32C is not set
+# CONFIG_CRYPTO_MD4 is not set
+# CONFIG_CRYPTO_MD5 is not set
+# CONFIG_CRYPTO_MICHAEL_MIC is not set
+# CONFIG_CRYPTO_RMD128 is not set
+# CONFIG_CRYPTO_RMD160 is not set
+# CONFIG_CRYPTO_RMD256 is not set
+# CONFIG_CRYPTO_RMD320 is not set
+# CONFIG_CRYPTO_SHA1 is not set
+# CONFIG_CRYPTO_SHA256 is not set
+# CONFIG_CRYPTO_SHA512 is not set
+# CONFIG_CRYPTO_TGR192 is not set
+# CONFIG_CRYPTO_WP512 is not set
+
+#
+# Ciphers
+#
+# CONFIG_CRYPTO_AES is not set
+# CONFIG_CRYPTO_ANUBIS is not set
+# CONFIG_CRYPTO_ARC4 is not set
+# CONFIG_CRYPTO_BLOWFISH is not set
+# CONFIG_CRYPTO_CAMELLIA is not set
+# CONFIG_CRYPTO_CAST5 is not set
+# CONFIG_CRYPTO_CAST6 is not set
+# CONFIG_CRYPTO_DES is not set
+# CONFIG_CRYPTO_FCRYPT is not set
+# CONFIG_CRYPTO_KHAZAD is not set
+# CONFIG_CRYPTO_SALSA20 is not set
+# CONFIG_CRYPTO_SEED is not set
+# CONFIG_CRYPTO_SERPENT is not set
+# CONFIG_CRYPTO_TEA is not set
+# CONFIG_CRYPTO_TWOFISH is not set
+
+#
+# Compression
+#
+# CONFIG_CRYPTO_DEFLATE is not set
+# CONFIG_CRYPTO_LZO is not set
+
+#
+# Random Number Generation
+#
+# CONFIG_CRYPTO_ANSI_CPRNG is not set
+# CONFIG_CRYPTO_HW is not set
+
+#
+# Library routines
+#
+CONFIG_GENERIC_FIND_LAST_BIT=y
+# CONFIG_CRC_CCITT is not set
+# CONFIG_CRC16 is not set
+# CONFIG_CRC_T10DIF is not set
+# CONFIG_CRC_ITU_T is not set
+# CONFIG_CRC32 is not set
+# CONFIG_CRC7 is not set
+# CONFIG_LIBCRC32C is not set
+CONFIG_PLIST=y
+CONFIG_HAS_IOMEM=y
+CONFIG_HAS_DMA=y
diff -Nur linux-3.4.113.orig/arch/nds32/configs/vep-le_defconfig linux-3.4.113/arch/nds32/configs/vep-le_defconfig
--- linux-3.4.113.orig/arch/nds32/configs/vep-le_defconfig 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/configs/vep-le_defconfig 2016-12-01 20:59:24.328611826 +0100
@@ -0,0 +1,777 @@
+#
+# Automatically generated make config: don't edit
+# Linux kernel version: 2.6.29
+# Mon Jul 13 11:41:30 2009
+#
+CONFIG_NDS32=y
+CONFIG_NO_IOPORT=y
+CONFIG_GENERIC_IOMAP=y
+CONFIG_RWSEM_GENERIC_SPINLOCK=y
+CONFIG_GENERIC_HWEIGHT=y
+CONFIG_GENERIC_FIND_NEXT_BIT=y
+CONFIG_GENERIC_CALIBRATE_DELAY=y
+CONFIG_GENERIC_HARDIRQS=y
+CONFIG_LOCKDEP_SUPPORT=y
+CONFIG_STACKTRACE_SUPPORT=y
+CONFIG_HAVE_LATENCYTOP_SUPPORT=y
+CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config"
+
+#
+# General setup
+#
+CONFIG_EXPERIMENTAL=y
+CONFIG_BROKEN_ON_SMP=y
+CONFIG_INIT_ENV_ARG_LIMIT=32
+CONFIG_LOCALVERSION=""
+# CONFIG_LOCALVERSION_AUTO is not set
+CONFIG_SWAP=y
+CONFIG_SYSVIPC=y
+CONFIG_SYSVIPC_SYSCTL=y
+# CONFIG_POSIX_MQUEUE is not set
+CONFIG_BSD_PROCESS_ACCT=y
+CONFIG_BSD_PROCESS_ACCT_V3=y
+# CONFIG_TASKSTATS is not set
+# CONFIG_AUDIT is not set
+
+#
+# RCU Subsystem
+#
+CONFIG_CLASSIC_RCU=y
+# CONFIG_TREE_RCU is not set
+# CONFIG_PREEMPT_RCU is not set
+# CONFIG_TREE_RCU_TRACE is not set
+# CONFIG_PREEMPT_RCU_TRACE is not set
+# CONFIG_IKCONFIG is not set
+CONFIG_LOG_BUF_SHIFT=14
+# CONFIG_GROUP_SCHED is not set
+# CONFIG_CGROUPS is not set
+# CONFIG_SYSFS_DEPRECATED_V2 is not set
+# CONFIG_RELAY is not set
+# CONFIG_NAMESPACES is not set
+CONFIG_BLK_DEV_INITRD=y
+CONFIG_INITRAMFS_SOURCE=""
+CONFIG_CC_OPTIMIZE_FOR_SIZE=y
+CONFIG_SYSCTL=y
+CONFIG_ANON_INODES=y
+CONFIG_EMBEDDED=y
+CONFIG_UID16=y
+CONFIG_SYSCTL_SYSCALL=y
+# CONFIG_KALLSYMS is not set
+# CONFIG_HOTPLUG is not set
+CONFIG_PRINTK=y
+CONFIG_BUG=y
+# CONFIG_ELF_CORE is not set
+CONFIG_BASE_FULL=y
+CONFIG_FUTEX=y
+CONFIG_EPOLL=y
+# CONFIG_SIGNALFD is not set
+CONFIG_TIMERFD=y
+CONFIG_EVENTFD=y
+CONFIG_SHMEM=y
+CONFIG_AIO=y
+# CONFIG_VM_EVENT_COUNTERS is not set
+CONFIG_SLUB_DEBUG=y
+CONFIG_COMPAT_BRK=y
+# CONFIG_SLAB is not set
+CONFIG_SLUB=y
+# CONFIG_SLOB is not set
+CONFIG_PROFILING=y
+CONFIG_TRACEPOINTS=y
+# CONFIG_MARKERS is not set
+CONFIG_OPROFILE=y
+CONFIG_HAVE_OPROFILE=y
+CONFIG_HAVE_KPROBES=y
+CONFIG_HAVE_KRETPROBES=y
+# CONFIG_HAVE_GENERIC_DMA_COHERENT is not set
+CONFIG_SLABINFO=y
+CONFIG_RT_MUTEXES=y
+CONFIG_BASE_SMALL=0
+CONFIG_MODULES=y
+# CONFIG_MODULE_FORCE_LOAD is not set
+CONFIG_MODULE_UNLOAD=y
+# CONFIG_MODULE_FORCE_UNLOAD is not set
+# CONFIG_MODVERSIONS is not set
+# CONFIG_MODULE_SRCVERSION_ALL is not set
+CONFIG_BLOCK=y
+# CONFIG_LBD is not set
+# CONFIG_BLK_DEV_IO_TRACE is not set
+# CONFIG_BLK_DEV_BSG is not set
+# CONFIG_BLK_DEV_INTEGRITY is not set
+
+#
+# IO Schedulers
+#
+CONFIG_IOSCHED_NOOP=y
+# CONFIG_IOSCHED_AS is not set
+# CONFIG_IOSCHED_DEADLINE is not set
+# CONFIG_IOSCHED_CFQ is not set
+# CONFIG_DEFAULT_AS is not set
+# CONFIG_DEFAULT_DEADLINE is not set
+# CONFIG_DEFAULT_CFQ is not set
+CONFIG_DEFAULT_NOOP=y
+CONFIG_DEFAULT_IOSCHED="noop"
+# CONFIG_FREEZER is not set
+
+#
+# System Type
+#
+# CONFIG_PLAT_FARADAY is not set
+CONFIG_PLAT_VEP=y
+# CONFIG_PLAT_AG101 is not set
+# CONFIG_PLAT_AG102 is not set
+# CONFIG_PLAT_AG101P is not set
+# CONFIG_PLAT_QEMU is not set
+CONFIG_PLATFORM_INTC=y
+
+#
+# VEP Platform Options
+#
+# CONFIG_CACHE_L2 is not set
+
+#
+# Common Platform Options
+#
+# CONFIG_PLATFORM_AHBDMA is not set
+# CONFIG_PLATFORM_APBDMA is not set
+CONFIG_SYS_CLK=67737600
+CONFIG_UART_CLK=36864000
+CONFIG_SDRAM_SIZE=0x10000000
+
+#
+# Processor Features
+#
+CONFIG_CPU_CUSTOM=y
+# CONFIG_FPU is not set
+# CONFIG_AUDIO is not set
+# CONFIG_EVIC is not set
+CONFIG_CPU_CONTEXT_ID=y
+CONFIG_ANDES_PAGE_SIZE_4KB=y
+# CONFIG_ANDES_PAGE_SIZE_8KB is not set
+# CONFIG_KERNEL_SPACE_LARGE_PAGE is not set
+# CONFIG_CPU_ICACHE_DISABLE is not set
+# CONFIG_CPU_DCACHE_DISABLE is not set
+# CONFIG_CPU_DCACHE_WRITETHROUGH is not set
+# CONFIG_ALIGNMENT_TRAP is not set
+CONFIG_MMU=y
+
+#
+# Kernel Features
+#
+CONFIG_PREEMPT_NONE=y
+# CONFIG_PREEMPT_VOLUNTARY is not set
+# CONFIG_PREEMPT is not set
+CONFIG_SELECT_MEMORY_MODEL=y
+CONFIG_FLATMEM_MANUAL=y
+# CONFIG_DISCONTIGMEM_MANUAL is not set
+# CONFIG_SPARSEMEM_MANUAL is not set
+CONFIG_FLATMEM=y
+CONFIG_FLAT_NODE_MEM_MAP=y
+CONFIG_PAGEFLAGS_EXTENDED=y
+CONFIG_SPLIT_PTLOCK_CPUS=4
+# CONFIG_PHYS_ADDR_T_64BIT is not set
+CONFIG_ZONE_DMA_FLAG=0
+CONFIG_VIRT_TO_BUS=y
+CONFIG_UNEVICTABLE_LRU=y
+CONFIG_FORCE_MAX_ZONEORDER=11
+CONFIG_HZ_100=y
+# CONFIG_HZ_250 is not set
+# CONFIG_HZ_300 is not set
+# CONFIG_HZ_1000 is not set
+CONFIG_HZ=100
+# CONFIG_SCHED_HRTICK is not set
+CONFIG_CMDLINE="root=/dev/ram0 rw mem=64M@0x0 initrd=0x1000000,8M console=ttyS0,38400n8 rootfstype=ext2 init=/bin/busybox init -s user_debug=-1"
+
+#
+# Power management options
+#
+CONFIG_SYS_SUPPORTS_APM_EMULATION=y
+CONFIG_ARCH_SUSPEND_POSSIBLE=y
+# CONFIG_PM is not set
+
+#
+# Bus options
+#
+# CONFIG_PCI is not set
+# CONFIG_ARCH_SUPPORTS_MSI is not set
+
+#
+# Executable file formats
+#
+CONFIG_BINFMT_ELF=y
+# CONFIG_HAVE_AOUT is not set
+# CONFIG_BINFMT_MISC is not set
+CONFIG_NET=y
+
+#
+# Networking options
+#
+CONFIG_COMPAT_NET_DEV_OPS=y
+CONFIG_PACKET=y
+# CONFIG_PACKET_MMAP is not set
+CONFIG_UNIX=y
+CONFIG_XFRM=y
+# CONFIG_XFRM_USER is not set
+# CONFIG_XFRM_SUB_POLICY is not set
+# CONFIG_XFRM_MIGRATE is not set
+# CONFIG_XFRM_STATISTICS is not set
+CONFIG_NET_KEY=y
+# CONFIG_NET_KEY_MIGRATE is not set
+CONFIG_INET=y
+CONFIG_IP_MULTICAST=y
+# CONFIG_IP_ADVANCED_ROUTER is not set
+CONFIG_IP_FIB_HASH=y
+# CONFIG_IP_PNP is not set
+# CONFIG_NET_IPIP is not set
+# CONFIG_NET_IPGRE is not set
+# CONFIG_IP_MROUTE is not set
+# CONFIG_ARPD is not set
+# CONFIG_SYN_COOKIES is not set
+# CONFIG_INET_AH is not set
+# CONFIG_INET_ESP is not set
+# CONFIG_INET_IPCOMP is not set
+# CONFIG_INET_XFRM_TUNNEL is not set
+# CONFIG_INET_TUNNEL is not set
+# CONFIG_INET_XFRM_MODE_TRANSPORT is not set
+# CONFIG_INET_XFRM_MODE_TUNNEL is not set
+# CONFIG_INET_XFRM_MODE_BEET is not set
+# CONFIG_INET_LRO is not set
+# CONFIG_INET_DIAG is not set
+# CONFIG_TCP_CONG_ADVANCED is not set
+CONFIG_TCP_CONG_CUBIC=y
+CONFIG_DEFAULT_TCP_CONG="cubic"
+# CONFIG_TCP_MD5SIG is not set
+# CONFIG_IPV6 is not set
+# CONFIG_NETWORK_SECMARK is not set
+# CONFIG_NETFILTER is not set
+# CONFIG_IP_DCCP is not set
+# CONFIG_IP_SCTP is not set
+# CONFIG_TIPC is not set
+# CONFIG_ATM is not set
+# CONFIG_BRIDGE is not set
+# CONFIG_NET_DSA is not set
+# CONFIG_VLAN_8021Q is not set
+# CONFIG_DECNET is not set
+# CONFIG_LLC2 is not set
+# CONFIG_IPX is not set
+# CONFIG_ATALK is not set
+# CONFIG_X25 is not set
+# CONFIG_LAPB is not set
+# CONFIG_ECONET is not set
+# CONFIG_WAN_ROUTER is not set
+# CONFIG_NET_SCHED is not set
+# CONFIG_DCB is not set
+
+#
+# Network testing
+#
+# CONFIG_NET_PKTGEN is not set
+# CONFIG_HAMRADIO is not set
+# CONFIG_CAN is not set
+# CONFIG_IRDA is not set
+# CONFIG_BT is not set
+# CONFIG_AF_RXRPC is not set
+# CONFIG_PHONET is not set
+CONFIG_WIRELESS=y
+# CONFIG_CFG80211 is not set
+CONFIG_WIRELESS_OLD_REGULATORY=y
+# CONFIG_WIRELESS_EXT is not set
+# CONFIG_LIB80211 is not set
+# CONFIG_MAC80211 is not set
+# CONFIG_WIMAX is not set
+# CONFIG_RFKILL is not set
+# CONFIG_NET_9P is not set
+
+#
+# Device Drivers
+#
+
+#
+# Generic Driver Options
+#
+CONFIG_STANDALONE=y
+CONFIG_PREVENT_FIRMWARE_BUILD=y
+# CONFIG_SYS_HYPERVISOR is not set
+# CONFIG_CONNECTOR is not set
+# CONFIG_MTD is not set
+# CONFIG_PARPORT is not set
+CONFIG_BLK_DEV=y
+# CONFIG_BLK_DEV_COW_COMMON is not set
+CONFIG_BLK_DEV_LOOP=y
+# CONFIG_BLK_DEV_CRYPTOLOOP is not set
+# CONFIG_BLK_DEV_NBD is not set
+CONFIG_BLK_DEV_RAM=y
+CONFIG_BLK_DEV_RAM_COUNT=16
+CONFIG_BLK_DEV_RAM_SIZE=8192
+# CONFIG_BLK_DEV_XIP is not set
+# CONFIG_CDROM_PKTCDVD is not set
+# CONFIG_ATA_OVER_ETH is not set
+# CONFIG_FTSDC010 is not set
+# CONFIG_FTCFC010 is not set
+# CONFIG_BLK_DEV_HD is not set
+# CONFIG_MISC_DEVICES is not set
+CONFIG_HAVE_IDE=y
+# CONFIG_IDE is not set
+
+#
+# SCSI device support
+#
+# CONFIG_RAID_ATTRS is not set
+# CONFIG_SCSI is not set
+# CONFIG_SCSI_DMA is not set
+# CONFIG_SCSI_NETLINK is not set
+# CONFIG_ATA is not set
+# CONFIG_MD is not set
+CONFIG_NETDEVICES=y
+# CONFIG_DUMMY is not set
+# CONFIG_BONDING is not set
+# CONFIG_MACVLAN is not set
+# CONFIG_EQUALIZER is not set
+# CONFIG_TUN is not set
+# CONFIG_VETH is not set
+# CONFIG_PHYLIB is not set
+CONFIG_NET_ETHERNET=y
+# CONFIG_MII is not set
+# CONFIG_SMC91X is not set
+# CONFIG_DNET is not set
+# CONFIG_IBM_NEW_EMAC_ZMII is not set
+# CONFIG_IBM_NEW_EMAC_RGMII is not set
+# CONFIG_IBM_NEW_EMAC_TAH is not set
+# CONFIG_IBM_NEW_EMAC_EMAC4 is not set
+# CONFIG_IBM_NEW_EMAC_NO_FLOW_CTRL is not set
+# CONFIG_IBM_NEW_EMAC_MAL_CLR_ICINTSTAT is not set
+# CONFIG_IBM_NEW_EMAC_MAL_COMMON_ERR is not set
+# CONFIG_B44 is not set
+CONFIG_FTMAC100=y
+# CONFIG_NETDEV_1000 is not set
+# CONFIG_NETDEV_10000 is not set
+
+#
+# Wireless LAN
+#
+# CONFIG_WLAN_PRE80211 is not set
+# CONFIG_WLAN_80211 is not set
+# CONFIG_IWLWIFI_LEDS is not set
+
+#
+# Enable WiMAX (Networking options) to see the WiMAX drivers
+#
+# CONFIG_WAN is not set
+# CONFIG_PPP is not set
+# CONFIG_SLIP is not set
+# CONFIG_NETCONSOLE is not set
+# CONFIG_NETPOLL is not set
+# CONFIG_NET_POLL_CONTROLLER is not set
+# CONFIG_ISDN is not set
+# CONFIG_PHONE is not set
+
+#
+# Input device support
+#
+CONFIG_INPUT=y
+# CONFIG_INPUT_FF_MEMLESS is not set
+# CONFIG_INPUT_POLLDEV is not set
+
+#
+# Userland interfaces
+#
+# CONFIG_INPUT_MOUSEDEV is not set
+# CONFIG_INPUT_JOYDEV is not set
+# CONFIG_INPUT_EVDEV is not set
+# CONFIG_INPUT_EVBUG is not set
+
+#
+# Input Device Drivers
+#
+# CONFIG_INPUT_KEYBOARD is not set
+# CONFIG_INPUT_MOUSE is not set
+# CONFIG_INPUT_JOYSTICK is not set
+# CONFIG_INPUT_TABLET is not set
+# CONFIG_INPUT_TOUCHSCREEN is not set
+# CONFIG_INPUT_MISC is not set
+
+#
+# Hardware I/O ports
+#
+# CONFIG_SERIO is not set
+# CONFIG_GAMEPORT is not set
+
+#
+# Character devices
+#
+CONFIG_VT=y
+CONFIG_CONSOLE_TRANSLATIONS=y
+CONFIG_VT_CONSOLE=y
+CONFIG_HW_CONSOLE=y
+# CONFIG_VT_HW_CONSOLE_BINDING is not set
+CONFIG_DEVKMEM=y
+# CONFIG_SERIAL_NONSTANDARD is not set
+
+#
+# Serial drivers
+#
+CONFIG_SERIAL_8250=y
+CONFIG_SERIAL_8250_CONSOLE=y
+CONFIG_SERIAL_8250_NR_UARTS=3
+CONFIG_SERIAL_8250_RUNTIME_UARTS=3
+# CONFIG_SERIAL_8250_EXTENDED is not set
+
+#
+# Non-8250 serial port support
+#
+CONFIG_SERIAL_CORE=y
+CONFIG_SERIAL_CORE_CONSOLE=y
+CONFIG_UNIX98_PTYS=y
+# CONFIG_DEVPTS_MULTIPLE_INSTANCES is not set
+CONFIG_LEGACY_PTYS=y
+CONFIG_LEGACY_PTY_COUNT=256
+# CONFIG_IPMI_HANDLER is not set
+# CONFIG_HW_RANDOM is not set
+# CONFIG_R3964 is not set
+# CONFIG_GPIO_FTGPIO010 is not set
+# CONFIG_RAW_DRIVER is not set
+# CONFIG_TCG_TPM is not set
+# CONFIG_I2C is not set
+# CONFIG_SPI is not set
+# CONFIG_W1 is not set
+# CONFIG_POWER_SUPPLY is not set
+# CONFIG_HWMON is not set
+# CONFIG_THERMAL is not set
+# CONFIG_THERMAL_HWMON is not set
+# CONFIG_WATCHDOG is not set
+CONFIG_SSB_POSSIBLE=y
+
+#
+# Sonics Silicon Backplane
+#
+# CONFIG_SSB is not set
+
+#
+# Multifunction device drivers
+#
+# CONFIG_MFD_CORE is not set
+# CONFIG_MFD_SM501 is not set
+# CONFIG_HTC_PASIC3 is not set
+# CONFIG_MFD_TMIO is not set
+# CONFIG_REGULATOR is not set
+
+#
+# Multimedia devices
+#
+
+#
+# Multimedia core support
+#
+# CONFIG_VIDEO_DEV is not set
+# CONFIG_DVB_CORE is not set
+# CONFIG_VIDEO_MEDIA is not set
+
+#
+# Multimedia drivers
+#
+# CONFIG_DAB is not set
+
+#
+# Graphics support
+#
+# CONFIG_VGASTATE is not set
+# CONFIG_VIDEO_OUTPUT_CONTROL is not set
+# CONFIG_FB is not set
+# CONFIG_BACKLIGHT_LCD_SUPPORT is not set
+
+#
+# Display device support
+#
+# CONFIG_DISPLAY_SUPPORT is not set
+
+#
+# Console display driver support
+#
+# CONFIG_VGA_CONSOLE is not set
+CONFIG_DUMMY_CONSOLE=y
+# CONFIG_SOUND is not set
+# CONFIG_HID_SUPPORT is not set
+# CONFIG_USB_SUPPORT is not set
+# CONFIG_MMC is not set
+# CONFIG_MEMSTICK is not set
+# CONFIG_NEW_LEDS is not set
+# CONFIG_ACCESSIBILITY is not set
+CONFIG_RTC_LIB=y
+# CONFIG_RTC_CLASS is not set
+# CONFIG_DMADEVICES is not set
+# CONFIG_UIO is not set
+# CONFIG_STAGING is not set
+
+#
+# File systems
+#
+CONFIG_EXT2_FS=y
+# CONFIG_EXT2_FS_XATTR is not set
+# CONFIG_EXT2_FS_XIP is not set
+# CONFIG_EXT3_FS is not set
+# CONFIG_EXT4_FS is not set
+# CONFIG_REISERFS_FS is not set
+# CONFIG_JFS_FS is not set
+# CONFIG_FS_POSIX_ACL is not set
+CONFIG_FILE_LOCKING=y
+# CONFIG_XFS_FS is not set
+# CONFIG_OCFS2_FS is not set
+# CONFIG_BTRFS_FS is not set
+CONFIG_DNOTIFY=y
+CONFIG_INOTIFY=y
+CONFIG_INOTIFY_USER=y
+# CONFIG_QUOTA is not set
+# CONFIG_AUTOFS_FS is not set
+# CONFIG_AUTOFS4_FS is not set
+CONFIG_FUSE_FS=y
+
+#
+# CD-ROM/DVD Filesystems
+#
+# CONFIG_ISO9660_FS is not set
+# CONFIG_UDF_FS is not set
+
+#
+# DOS/FAT/NT Filesystems
+#
+# CONFIG_MSDOS_FS is not set
+# CONFIG_VFAT_FS is not set
+# CONFIG_NTFS_FS is not set
+
+#
+# Pseudo filesystems
+#
+CONFIG_PROC_FS=y
+# CONFIG_PROC_KCORE is not set
+CONFIG_PROC_SYSCTL=y
+# CONFIG_PROC_PAGE_MONITOR is not set
+CONFIG_SYSFS=y
+CONFIG_TMPFS=y
+# CONFIG_TMPFS_POSIX_ACL is not set
+# CONFIG_HUGETLB_PAGE is not set
+# CONFIG_CONFIGFS_FS is not set
+CONFIG_MISC_FILESYSTEMS=y
+# CONFIG_ADFS_FS is not set
+# CONFIG_AFFS_FS is not set
+# CONFIG_HFS_FS is not set
+# CONFIG_HFSPLUS_FS is not set
+# CONFIG_BEFS_FS is not set
+# CONFIG_BFS_FS is not set
+# CONFIG_EFS_FS is not set
+# CONFIG_CRAMFS is not set
+# CONFIG_SQUASHFS is not set
+# CONFIG_VXFS_FS is not set
+# CONFIG_MINIX_FS is not set
+# CONFIG_OMFS_FS is not set
+# CONFIG_HPFS_FS is not set
+# CONFIG_QNX4FS_FS is not set
+# CONFIG_ROMFS_FS is not set
+# CONFIG_SYSV_FS is not set
+# CONFIG_UFS_FS is not set
+CONFIG_NETWORK_FILESYSTEMS=y
+CONFIG_NFS_FS=y
+CONFIG_NFS_V3=y
+# CONFIG_NFS_V3_ACL is not set
+# CONFIG_NFS_V4 is not set
+# CONFIG_NFSD is not set
+CONFIG_LOCKD=y
+CONFIG_LOCKD_V4=y
+CONFIG_NFS_COMMON=y
+CONFIG_SUNRPC=y
+# CONFIG_SUNRPC_REGISTER_V4 is not set
+# CONFIG_RPCSEC_GSS_KRB5 is not set
+# CONFIG_RPCSEC_GSS_SPKM3 is not set
+# CONFIG_SMB_FS is not set
+# CONFIG_CIFS is not set
+# CONFIG_NCP_FS is not set
+# CONFIG_CODA_FS is not set
+# CONFIG_AFS_FS is not set
+
+#
+# Partition Types
+#
+# CONFIG_PARTITION_ADVANCED is not set
+CONFIG_MSDOS_PARTITION=y
+CONFIG_NLS=y
+CONFIG_NLS_DEFAULT="iso8859-1"
+CONFIG_NLS_CODEPAGE_437=y
+# CONFIG_NLS_CODEPAGE_737 is not set
+# CONFIG_NLS_CODEPAGE_775 is not set
+# CONFIG_NLS_CODEPAGE_850 is not set
+# CONFIG_NLS_CODEPAGE_852 is not set
+# CONFIG_NLS_CODEPAGE_855 is not set
+# CONFIG_NLS_CODEPAGE_857 is not set
+# CONFIG_NLS_CODEPAGE_860 is not set
+# CONFIG_NLS_CODEPAGE_861 is not set
+# CONFIG_NLS_CODEPAGE_862 is not set
+# CONFIG_NLS_CODEPAGE_863 is not set
+# CONFIG_NLS_CODEPAGE_864 is not set
+# CONFIG_NLS_CODEPAGE_865 is not set
+# CONFIG_NLS_CODEPAGE_866 is not set
+# CONFIG_NLS_CODEPAGE_869 is not set
+# CONFIG_NLS_CODEPAGE_936 is not set
+# CONFIG_NLS_CODEPAGE_950 is not set
+# CONFIG_NLS_CODEPAGE_932 is not set
+# CONFIG_NLS_CODEPAGE_949 is not set
+# CONFIG_NLS_CODEPAGE_874 is not set
+# CONFIG_NLS_ISO8859_8 is not set
+# CONFIG_NLS_CODEPAGE_1250 is not set
+# CONFIG_NLS_CODEPAGE_1251 is not set
+# CONFIG_NLS_ASCII is not set
+CONFIG_NLS_ISO8859_1=y
+# CONFIG_NLS_ISO8859_2 is not set
+# CONFIG_NLS_ISO8859_3 is not set
+# CONFIG_NLS_ISO8859_4 is not set
+# CONFIG_NLS_ISO8859_5 is not set
+# CONFIG_NLS_ISO8859_6 is not set
+# CONFIG_NLS_ISO8859_7 is not set
+# CONFIG_NLS_ISO8859_9 is not set
+# CONFIG_NLS_ISO8859_13 is not set
+# CONFIG_NLS_ISO8859_14 is not set
+# CONFIG_NLS_ISO8859_15 is not set
+# CONFIG_NLS_KOI8_R is not set
+# CONFIG_NLS_KOI8_U is not set
+# CONFIG_NLS_UTF8 is not set
+# CONFIG_DLM is not set
+
+#
+# Kernel hacking
+#
+CONFIG_TRACE_IRQFLAGS_SUPPORT=y
+# CONFIG_PRINTK_TIME is not set
+CONFIG_ENABLE_WARN_DEPRECATED=y
+CONFIG_ENABLE_MUST_CHECK=y
+CONFIG_FRAME_WARN=1024
+# CONFIG_MAGIC_SYSRQ is not set
+# CONFIG_UNUSED_SYMBOLS is not set
+CONFIG_DEBUG_FS=y
+# CONFIG_HEADERS_CHECK is not set
+# CONFIG_DEBUG_KERNEL is not set
+# CONFIG_SLUB_DEBUG_ON is not set
+# CONFIG_SLUB_STATS is not set
+CONFIG_STACKTRACE=y
+# CONFIG_DEBUG_MEMORY_INIT is not set
+CONFIG_FRAME_POINTER=y
+# CONFIG_RCU_CPU_STALL_DETECTOR is not set
+# CONFIG_LATENCYTOP is not set
+CONFIG_SYSCTL_SYSCALL_CHECK=y
+CONFIG_NOP_TRACER=y
+CONFIG_RING_BUFFER=y
+CONFIG_TRACING=y
+
+#
+# Tracers
+#
+# CONFIG_DYNAMIC_PRINTK_DEBUG is not set
+# CONFIG_SAMPLES is not set
+CONFIG_HAVE_ARCH_KGDB=y
+CONFIG_DEBUG_USER=y
+# CONFIG_CCTL is not set
+CONFIG_ELFCHK_DEFAULT_ENABLE=y
+
+#
+# Security options
+#
+# CONFIG_KEYS is not set
+# CONFIG_SECURITY is not set
+# CONFIG_SECURITYFS is not set
+# CONFIG_SECURITY_FILE_CAPABILITIES is not set
+CONFIG_CRYPTO=y
+
+#
+# Crypto core or helper
+#
+# CONFIG_CRYPTO_FIPS is not set
+# CONFIG_CRYPTO_MANAGER is not set
+# CONFIG_CRYPTO_MANAGER2 is not set
+# CONFIG_CRYPTO_GF128MUL is not set
+# CONFIG_CRYPTO_NULL is not set
+# CONFIG_CRYPTO_CRYPTD is not set
+# CONFIG_CRYPTO_AUTHENC is not set
+# CONFIG_CRYPTO_TEST is not set
+
+#
+# Authenticated Encryption with Associated Data
+#
+# CONFIG_CRYPTO_CCM is not set
+# CONFIG_CRYPTO_GCM is not set
+# CONFIG_CRYPTO_SEQIV is not set
+
+#
+# Block modes
+#
+# CONFIG_CRYPTO_CBC is not set
+# CONFIG_CRYPTO_CTR is not set
+# CONFIG_CRYPTO_CTS is not set
+# CONFIG_CRYPTO_ECB is not set
+# CONFIG_CRYPTO_LRW is not set
+# CONFIG_CRYPTO_PCBC is not set
+# CONFIG_CRYPTO_XTS is not set
+
+#
+# Hash modes
+#
+# CONFIG_CRYPTO_HMAC is not set
+# CONFIG_CRYPTO_XCBC is not set
+
+#
+# Digest
+#
+# CONFIG_CRYPTO_CRC32C is not set
+# CONFIG_CRYPTO_MD4 is not set
+# CONFIG_CRYPTO_MD5 is not set
+# CONFIG_CRYPTO_MICHAEL_MIC is not set
+# CONFIG_CRYPTO_RMD128 is not set
+# CONFIG_CRYPTO_RMD160 is not set
+# CONFIG_CRYPTO_RMD256 is not set
+# CONFIG_CRYPTO_RMD320 is not set
+# CONFIG_CRYPTO_SHA1 is not set
+# CONFIG_CRYPTO_SHA256 is not set
+# CONFIG_CRYPTO_SHA512 is not set
+# CONFIG_CRYPTO_TGR192 is not set
+# CONFIG_CRYPTO_WP512 is not set
+
+#
+# Ciphers
+#
+# CONFIG_CRYPTO_AES is not set
+# CONFIG_CRYPTO_ANUBIS is not set
+# CONFIG_CRYPTO_ARC4 is not set
+# CONFIG_CRYPTO_BLOWFISH is not set
+# CONFIG_CRYPTO_CAMELLIA is not set
+# CONFIG_CRYPTO_CAST5 is not set
+# CONFIG_CRYPTO_CAST6 is not set
+# CONFIG_CRYPTO_DES is not set
+# CONFIG_CRYPTO_FCRYPT is not set
+# CONFIG_CRYPTO_KHAZAD is not set
+# CONFIG_CRYPTO_SALSA20 is not set
+# CONFIG_CRYPTO_SEED is not set
+# CONFIG_CRYPTO_SERPENT is not set
+# CONFIG_CRYPTO_TEA is not set
+# CONFIG_CRYPTO_TWOFISH is not set
+
+#
+# Compression
+#
+# CONFIG_CRYPTO_DEFLATE is not set
+# CONFIG_CRYPTO_LZO is not set
+
+#
+# Random Number Generation
+#
+# CONFIG_CRYPTO_ANSI_CPRNG is not set
+# CONFIG_CRYPTO_HW is not set
+
+#
+# Library routines
+#
+CONFIG_GENERIC_FIND_LAST_BIT=y
+# CONFIG_CRC_CCITT is not set
+# CONFIG_CRC16 is not set
+# CONFIG_CRC_T10DIF is not set
+# CONFIG_CRC_ITU_T is not set
+# CONFIG_CRC32 is not set
+# CONFIG_CRC7 is not set
+# CONFIG_LIBCRC32C is not set
+CONFIG_PLIST=y
+CONFIG_HAS_IOMEM=y
+CONFIG_HAS_DMA=y
diff -Nur linux-3.4.113.orig/arch/nds32/configs/xc5_8k_defconfig linux-3.4.113/arch/nds32/configs/xc5_8k_defconfig
--- linux-3.4.113.orig/arch/nds32/configs/xc5_8k_defconfig 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/configs/xc5_8k_defconfig 2016-12-01 20:59:24.328611826 +0100
@@ -0,0 +1,1051 @@
+#
+# Automatically generated make config: don't edit
+# Linux kernel version: 2.6.29
+# Fri Oct 2 14:21:05 2009
+#
+CONFIG_NDS32=y
+# CONFIG_GENERIC_GPIO is not set
+CONFIG_NO_IOPORT=y
+CONFIG_GENERIC_IOMAP=y
+CONFIG_RWSEM_GENERIC_SPINLOCK=y
+CONFIG_GENERIC_HWEIGHT=y
+CONFIG_GENERIC_FIND_NEXT_BIT=y
+CONFIG_GENERIC_CALIBRATE_DELAY=y
+CONFIG_GENERIC_HARDIRQS=y
+CONFIG_LOCKDEP_SUPPORT=y
+CONFIG_STACKTRACE_SUPPORT=y
+CONFIG_HAVE_LATENCYTOP_SUPPORT=y
+CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config"
+
+#
+# General setup
+#
+CONFIG_EXPERIMENTAL=y
+CONFIG_BROKEN_ON_SMP=y
+CONFIG_INIT_ENV_ARG_LIMIT=32
+CONFIG_LOCALVERSION=""
+# CONFIG_LOCALVERSION_AUTO is not set
+CONFIG_SWAP=y
+CONFIG_SYSVIPC=y
+CONFIG_SYSVIPC_SYSCTL=y
+# CONFIG_POSIX_MQUEUE is not set
+CONFIG_BSD_PROCESS_ACCT=y
+CONFIG_BSD_PROCESS_ACCT_V3=y
+# CONFIG_TASKSTATS is not set
+# CONFIG_AUDIT is not set
+
+#
+# RCU Subsystem
+#
+CONFIG_CLASSIC_RCU=y
+# CONFIG_TREE_RCU is not set
+# CONFIG_PREEMPT_RCU is not set
+# CONFIG_TREE_RCU_TRACE is not set
+# CONFIG_PREEMPT_RCU_TRACE is not set
+# CONFIG_IKCONFIG is not set
+CONFIG_LOG_BUF_SHIFT=14
+# CONFIG_GROUP_SCHED is not set
+# CONFIG_CGROUPS is not set
+# CONFIG_SYSFS_DEPRECATED_V2 is not set
+# CONFIG_RELAY is not set
+# CONFIG_NAMESPACES is not set
+CONFIG_BLK_DEV_INITRD=y
+CONFIG_INITRAMFS_SOURCE=""
+CONFIG_CC_OPTIMIZE_FOR_SIZE=y
+CONFIG_SYSCTL=y
+CONFIG_ANON_INODES=y
+CONFIG_EMBEDDED=y
+CONFIG_UID16=y
+CONFIG_SYSCTL_SYSCALL=y
+CONFIG_KALLSYMS=y
+# CONFIG_KALLSYMS_ALL is not set
+CONFIG_KALLSYMS_EXTRA_PASS=y
+# CONFIG_HOTPLUG is not set
+CONFIG_PRINTK=y
+CONFIG_BUG=y
+CONFIG_ELF_CORE=y
+CONFIG_BASE_FULL=y
+CONFIG_FUTEX=y
+CONFIG_EPOLL=y
+# CONFIG_SIGNALFD is not set
+CONFIG_TIMERFD=y
+CONFIG_EVENTFD=y
+CONFIG_SHMEM=y
+CONFIG_AIO=y
+# CONFIG_VM_EVENT_COUNTERS is not set
+CONFIG_SLUB_DEBUG=y
+CONFIG_COMPAT_BRK=y
+# CONFIG_SLAB is not set
+CONFIG_SLUB=y
+# CONFIG_SLOB is not set
+CONFIG_PROFILING=y
+CONFIG_TRACEPOINTS=y
+# CONFIG_MARKERS is not set
+CONFIG_OPROFILE=y
+CONFIG_HAVE_OPROFILE=y
+# CONFIG_KPROBES is not set
+CONFIG_HAVE_KPROBES=y
+CONFIG_HAVE_KRETPROBES=y
+# CONFIG_HAVE_GENERIC_DMA_COHERENT is not set
+CONFIG_SLABINFO=y
+CONFIG_RT_MUTEXES=y
+CONFIG_BASE_SMALL=0
+CONFIG_MODULES=y
+# CONFIG_MODULE_FORCE_LOAD is not set
+CONFIG_MODULE_UNLOAD=y
+# CONFIG_MODULE_FORCE_UNLOAD is not set
+# CONFIG_MODVERSIONS is not set
+# CONFIG_MODULE_SRCVERSION_ALL is not set
+CONFIG_BLOCK=y
+# CONFIG_LBD is not set
+# CONFIG_BLK_DEV_IO_TRACE is not set
+# CONFIG_BLK_DEV_BSG is not set
+# CONFIG_BLK_DEV_INTEGRITY is not set
+
+#
+# IO Schedulers
+#
+CONFIG_IOSCHED_NOOP=y
+CONFIG_IOSCHED_AS=y
+CONFIG_IOSCHED_DEADLINE=y
+CONFIG_IOSCHED_CFQ=y
+# CONFIG_DEFAULT_AS is not set
+# CONFIG_DEFAULT_DEADLINE is not set
+CONFIG_DEFAULT_CFQ=y
+# CONFIG_DEFAULT_NOOP is not set
+CONFIG_DEFAULT_IOSCHED="cfq"
+# CONFIG_FREEZER is not set
+
+#
+# System Type
+#
+# CONFIG_PLAT_VEP is not set
+# CONFIG_PLAT_AG101 is not set
+# CONFIG_PLAT_AG102 is not set
+CONFIG_PLAT_AG101P=y
+# CONFIG_PLAT_QEMU is not set
+CONFIG_PLATFORM_INTC=y
+CONFIG_ARCH_WANT_OPTIONAL_GPIOLIB=y
+
+#
+# AG101P Platform Options
+#
+
+#
+# Common Platform Options
+#
+CONFIG_PLATFORM_AHBDMA=y
+CONFIG_PLATFORM_APBDMA=y
+CONFIG_SYS_CLK=40000000
+CONFIG_UART_CLK=14745600
+CONFIG_SDRAM_SIZE=0x10000000
+
+#
+# Processor Features
+#
+CONFIG_CPU_CUSTOM=y
+# CONFIG_FPU is not set
+# CONFIG_AUDIO is not set
+# CONFIG_EVIC is not set
+CONFIG_CPU_CONTEXT_ID=y
+# CONFIG_CPU_CACHE_NONALIASING is not set
+# CONFIG_ANDES_PAGE_SIZE_4KB is not set
+CONFIG_ANDES_PAGE_SIZE_8KB=y
+CONFIG_KERNEL_SPACE_LARGE_PAGE=y
+# CONFIG_CPU_ICACHE_DISABLE is not set
+# CONFIG_CPU_DCACHE_DISABLE is not set
+# CONFIG_CPU_DCACHE_WRITETHROUGH is not set
+# CONFIG_ABI1 is not set
+CONFIG_ALIGNMENT_TRAP=y
+CONFIG_GENERIC_TIME=y
+CONFIG_GENERIC_CLOCKEVENTS=y
+CONFIG_MMU=y
+
+#
+# Kernel Features
+#
+# CONFIG_NO_HZ is not set
+# CONFIG_HIGH_RES_TIMERS is not set
+CONFIG_GENERIC_CLOCKEVENTS_BUILD=y
+CONFIG_PREEMPT_NONE=y
+# CONFIG_PREEMPT_VOLUNTARY is not set
+# CONFIG_PREEMPT is not set
+CONFIG_SELECT_MEMORY_MODEL=y
+CONFIG_FLATMEM_MANUAL=y
+# CONFIG_DISCONTIGMEM_MANUAL is not set
+# CONFIG_SPARSEMEM_MANUAL is not set
+CONFIG_FLATMEM=y
+CONFIG_FLAT_NODE_MEM_MAP=y
+CONFIG_PAGEFLAGS_EXTENDED=y
+CONFIG_SPLIT_PTLOCK_CPUS=4
+# CONFIG_PHYS_ADDR_T_64BIT is not set
+CONFIG_ZONE_DMA_FLAG=0
+CONFIG_VIRT_TO_BUS=y
+CONFIG_UNEVICTABLE_LRU=y
+CONFIG_FORCE_MAX_ZONEORDER=11
+CONFIG_HZ_100=y
+# CONFIG_HZ_250 is not set
+# CONFIG_HZ_300 is not set
+# CONFIG_HZ_1000 is not set
+CONFIG_HZ=100
+# CONFIG_SCHED_HRTICK is not set
+CONFIG_CMDLINE="root=/dev/ram0 rw mem=128M@0x0 initrd=0x1000000,8M console=ttyS0,38400n8 rootfstype=ext2 init=/bin/busybox init -s user_debug=-1"
+
+#
+# Power management options
+#
+CONFIG_SYS_SUPPORTS_APM_EMULATION=y
+CONFIG_ARCH_SUSPEND_POSSIBLE=y
+# CONFIG_PM is not set
+
+#
+# Bus options
+#
+# CONFIG_PCI is not set
+# CONFIG_ARCH_SUPPORTS_MSI is not set
+
+#
+# Executable file formats
+#
+CONFIG_BINFMT_ELF=y
+# CONFIG_CORE_DUMP_DEFAULT_ELF_HEADERS is not set
+# CONFIG_HAVE_AOUT is not set
+# CONFIG_BINFMT_MISC is not set
+CONFIG_NET=y
+
+#
+# Networking options
+#
+CONFIG_COMPAT_NET_DEV_OPS=y
+CONFIG_PACKET=y
+# CONFIG_PACKET_MMAP is not set
+CONFIG_UNIX=y
+CONFIG_XFRM=y
+# CONFIG_XFRM_USER is not set
+# CONFIG_XFRM_SUB_POLICY is not set
+# CONFIG_XFRM_MIGRATE is not set
+# CONFIG_XFRM_STATISTICS is not set
+CONFIG_NET_KEY=y
+# CONFIG_NET_KEY_MIGRATE is not set
+CONFIG_INET=y
+CONFIG_IP_MULTICAST=y
+# CONFIG_IP_ADVANCED_ROUTER is not set
+CONFIG_IP_FIB_HASH=y
+# CONFIG_IP_PNP is not set
+# CONFIG_NET_IPIP is not set
+# CONFIG_NET_IPGRE is not set
+# CONFIG_IP_MROUTE is not set
+# CONFIG_ARPD is not set
+# CONFIG_SYN_COOKIES is not set
+# CONFIG_INET_AH is not set
+# CONFIG_INET_ESP is not set
+# CONFIG_INET_IPCOMP is not set
+# CONFIG_INET_XFRM_TUNNEL is not set
+# CONFIG_INET_TUNNEL is not set
+# CONFIG_INET_XFRM_MODE_TRANSPORT is not set
+# CONFIG_INET_XFRM_MODE_TUNNEL is not set
+# CONFIG_INET_XFRM_MODE_BEET is not set
+# CONFIG_INET_LRO is not set
+# CONFIG_INET_DIAG is not set
+# CONFIG_TCP_CONG_ADVANCED is not set
+CONFIG_TCP_CONG_CUBIC=y
+CONFIG_DEFAULT_TCP_CONG="cubic"
+# CONFIG_TCP_MD5SIG is not set
+# CONFIG_IPV6 is not set
+# CONFIG_NETWORK_SECMARK is not set
+# CONFIG_NETFILTER is not set
+# CONFIG_IP_DCCP is not set
+# CONFIG_IP_SCTP is not set
+# CONFIG_TIPC is not set
+# CONFIG_ATM is not set
+# CONFIG_BRIDGE is not set
+# CONFIG_NET_DSA is not set
+# CONFIG_VLAN_8021Q is not set
+# CONFIG_DECNET is not set
+# CONFIG_LLC2 is not set
+# CONFIG_IPX is not set
+# CONFIG_ATALK is not set
+# CONFIG_X25 is not set
+# CONFIG_LAPB is not set
+# CONFIG_ECONET is not set
+# CONFIG_WAN_ROUTER is not set
+# CONFIG_NET_SCHED is not set
+# CONFIG_DCB is not set
+
+#
+# Network testing
+#
+# CONFIG_NET_PKTGEN is not set
+# CONFIG_HAMRADIO is not set
+# CONFIG_CAN is not set
+# CONFIG_IRDA is not set
+# CONFIG_BT is not set
+# CONFIG_AF_RXRPC is not set
+# CONFIG_PHONET is not set
+CONFIG_WIRELESS=y
+# CONFIG_CFG80211 is not set
+CONFIG_WIRELESS_OLD_REGULATORY=y
+# CONFIG_WIRELESS_EXT is not set
+# CONFIG_LIB80211 is not set
+# CONFIG_MAC80211 is not set
+# CONFIG_WIMAX is not set
+# CONFIG_RFKILL is not set
+# CONFIG_NET_9P is not set
+
+#
+# Device Drivers
+#
+
+#
+# Generic Driver Options
+#
+CONFIG_STANDALONE=y
+CONFIG_PREVENT_FIRMWARE_BUILD=y
+# CONFIG_DEBUG_DRIVER is not set
+# CONFIG_DEBUG_DEVRES is not set
+# CONFIG_SYS_HYPERVISOR is not set
+# CONFIG_CONNECTOR is not set
+CONFIG_MTD=y
+# CONFIG_MTD_DEBUG is not set
+# CONFIG_MTD_CONCAT is not set
+CONFIG_MTD_PARTITIONS=y
+# CONFIG_MTD_TESTS is not set
+# CONFIG_MTD_REDBOOT_PARTS is not set
+CONFIG_MTD_CMDLINE_PARTS=y
+# CONFIG_MTD_AR7_PARTS is not set
+
+#
+# User Modules And Translation Layers
+#
+CONFIG_MTD_CHAR=y
+CONFIG_MTD_BLKDEVS=y
+CONFIG_MTD_BLOCK=y
+# CONFIG_FTL is not set
+# CONFIG_NFTL is not set
+# CONFIG_INFTL is not set
+# CONFIG_RFD_FTL is not set
+# CONFIG_SSFDC is not set
+# CONFIG_MTD_OOPS is not set
+
+#
+# RAM/ROM/Flash chip drivers
+#
+CONFIG_MTD_CFI=y
+# CONFIG_MTD_JEDECPROBE is not set
+CONFIG_MTD_GEN_PROBE=y
+# CONFIG_MTD_CFI_ADV_OPTIONS is not set
+CONFIG_MTD_MAP_BANK_WIDTH_1=y
+CONFIG_MTD_MAP_BANK_WIDTH_2=y
+CONFIG_MTD_MAP_BANK_WIDTH_4=y
+# CONFIG_MTD_MAP_BANK_WIDTH_8 is not set
+# CONFIG_MTD_MAP_BANK_WIDTH_16 is not set
+# CONFIG_MTD_MAP_BANK_WIDTH_32 is not set
+CONFIG_MTD_CFI_I1=y
+CONFIG_MTD_CFI_I2=y
+# CONFIG_MTD_CFI_I4 is not set
+# CONFIG_MTD_CFI_I8 is not set
+CONFIG_MTD_CFI_INTELEXT=y
+# CONFIG_MTD_CFI_AMDSTD is not set
+# CONFIG_MTD_CFI_STAA is not set
+CONFIG_MTD_CFI_UTIL=y
+# CONFIG_MTD_RAM is not set
+# CONFIG_MTD_ROM is not set
+# CONFIG_MTD_ABSENT is not set
+
+#
+# Mapping drivers for chip access
+#
+# CONFIG_MTD_COMPLEX_MAPPINGS is not set
+CONFIG_MTD_PHYSMAP=y
+CONFIG_MTD_PHYSMAP_COMPAT=y
+CONFIG_MTD_PHYSMAP_START=0x80400000
+CONFIG_MTD_PHYSMAP_LEN=0x2000000
+CONFIG_MTD_PHYSMAP_BANKWIDTH=4
+# CONFIG_MTD_PLATRAM is not set
+
+#
+# Self-contained MTD device drivers
+#
+# CONFIG_MTD_SLRAM is not set
+# CONFIG_MTD_PHRAM is not set
+# CONFIG_MTD_MTDRAM is not set
+# CONFIG_MTD_BLOCK2MTD is not set
+
+#
+# Disk-On-Chip Device Drivers
+#
+# CONFIG_MTD_DOC2000 is not set
+# CONFIG_MTD_DOC2001 is not set
+# CONFIG_MTD_DOC2001PLUS is not set
+# CONFIG_MTD_NAND is not set
+# CONFIG_MTD_ONENAND is not set
+
+#
+# LPDDR flash memory drivers
+#
+# CONFIG_MTD_LPDDR is not set
+
+#
+# UBI - Unsorted block images
+#
+# CONFIG_MTD_UBI is not set
+# CONFIG_PARPORT is not set
+CONFIG_BLK_DEV=y
+# CONFIG_BLK_DEV_COW_COMMON is not set
+CONFIG_BLK_DEV_LOOP=y
+# CONFIG_BLK_DEV_CRYPTOLOOP is not set
+# CONFIG_BLK_DEV_NBD is not set
+CONFIG_BLK_DEV_RAM=y
+CONFIG_BLK_DEV_RAM_COUNT=16
+CONFIG_BLK_DEV_RAM_SIZE=8192
+# CONFIG_BLK_DEV_XIP is not set
+# CONFIG_CDROM_PKTCDVD is not set
+# CONFIG_ATA_OVER_ETH is not set
+CONFIG_FTSDC010=y
+# CONFIG_FTCFC010 is not set
+# CONFIG_BLK_DEV_HD is not set
+# CONFIG_MISC_DEVICES is not set
+CONFIG_HAVE_IDE=y
+# CONFIG_IDE is not set
+
+#
+# SCSI device support
+#
+# CONFIG_RAID_ATTRS is not set
+# CONFIG_SCSI is not set
+# CONFIG_SCSI_DMA is not set
+# CONFIG_SCSI_NETLINK is not set
+# CONFIG_ATA is not set
+# CONFIG_MD is not set
+CONFIG_NETDEVICES=y
+# CONFIG_DUMMY is not set
+# CONFIG_BONDING is not set
+# CONFIG_MACVLAN is not set
+# CONFIG_EQUALIZER is not set
+# CONFIG_TUN is not set
+# CONFIG_VETH is not set
+# CONFIG_PHYLIB is not set
+CONFIG_NET_ETHERNET=y
+# CONFIG_MII is not set
+# CONFIG_SMC91X is not set
+# CONFIG_DNET is not set
+# CONFIG_IBM_NEW_EMAC_ZMII is not set
+# CONFIG_IBM_NEW_EMAC_RGMII is not set
+# CONFIG_IBM_NEW_EMAC_TAH is not set
+# CONFIG_IBM_NEW_EMAC_EMAC4 is not set
+# CONFIG_IBM_NEW_EMAC_NO_FLOW_CTRL is not set
+# CONFIG_IBM_NEW_EMAC_MAL_CLR_ICINTSTAT is not set
+# CONFIG_IBM_NEW_EMAC_MAL_COMMON_ERR is not set
+# CONFIG_B44 is not set
+CONFIG_FTMAC100=y
+# CONFIG_NETDEV_1000 is not set
+# CONFIG_NETDEV_10000 is not set
+
+#
+# Wireless LAN
+#
+# CONFIG_WLAN_PRE80211 is not set
+# CONFIG_WLAN_80211 is not set
+# CONFIG_IWLWIFI_LEDS is not set
+
+#
+# Enable WiMAX (Networking options) to see the WiMAX drivers
+#
+# CONFIG_WAN is not set
+# CONFIG_PPP is not set
+# CONFIG_SLIP is not set
+# CONFIG_NETCONSOLE is not set
+# CONFIG_NETPOLL is not set
+# CONFIG_NET_POLL_CONTROLLER is not set
+# CONFIG_ISDN is not set
+# CONFIG_PHONE is not set
+
+#
+# Input device support
+#
+CONFIG_INPUT=y
+# CONFIG_INPUT_FF_MEMLESS is not set
+# CONFIG_INPUT_POLLDEV is not set
+
+#
+# Userland interfaces
+#
+# CONFIG_INPUT_MOUSEDEV is not set
+# CONFIG_INPUT_JOYDEV is not set
+CONFIG_INPUT_EVDEV=y
+# CONFIG_INPUT_EVBUG is not set
+
+#
+# Input Device Drivers
+#
+# CONFIG_INPUT_KEYBOARD is not set
+# CONFIG_INPUT_MOUSE is not set
+# CONFIG_INPUT_JOYSTICK is not set
+# CONFIG_INPUT_TABLET is not set
+CONFIG_INPUT_TOUCHSCREEN=y
+CONFIG_TOUCHSCREEN_CPE_TS=y
+CONFIG_TOUCHSCREEN_CPE_TS_DEJITTER=y
+# CONFIG_TOUCHSCREEN_FUJITSU is not set
+# CONFIG_TOUCHSCREEN_GUNZE is not set
+# CONFIG_TOUCHSCREEN_ELO is not set
+# CONFIG_TOUCHSCREEN_WACOM_W8001 is not set
+# CONFIG_TOUCHSCREEN_MTOUCH is not set
+# CONFIG_TOUCHSCREEN_INEXIO is not set
+# CONFIG_TOUCHSCREEN_MK712 is not set
+# CONFIG_TOUCHSCREEN_PENMOUNT is not set
+# CONFIG_TOUCHSCREEN_TOUCHRIGHT is not set
+# CONFIG_TOUCHSCREEN_TOUCHWIN is not set
+# CONFIG_TOUCHSCREEN_TOUCHIT213 is not set
+# CONFIG_INPUT_MISC is not set
+
+#
+# Hardware I/O ports
+#
+# CONFIG_SERIO is not set
+# CONFIG_GAMEPORT is not set
+
+#
+# Character devices
+#
+CONFIG_VT=y
+CONFIG_CONSOLE_TRANSLATIONS=y
+CONFIG_VT_CONSOLE=y
+CONFIG_HW_CONSOLE=y
+# CONFIG_VT_HW_CONSOLE_BINDING is not set
+CONFIG_DEVKMEM=y
+# CONFIG_SERIAL_NONSTANDARD is not set
+
+#
+# Serial drivers
+#
+CONFIG_SERIAL_8250=y
+CONFIG_SERIAL_8250_CONSOLE=y
+CONFIG_SERIAL_8250_NR_UARTS=3
+CONFIG_SERIAL_8250_RUNTIME_UARTS=3
+# CONFIG_SERIAL_8250_EXTENDED is not set
+
+#
+# Non-8250 serial port support
+#
+CONFIG_SERIAL_CORE=y
+CONFIG_SERIAL_CORE_CONSOLE=y
+CONFIG_UNIX98_PTYS=y
+# CONFIG_DEVPTS_MULTIPLE_INSTANCES is not set
+CONFIG_LEGACY_PTYS=y
+CONFIG_LEGACY_PTY_COUNT=256
+# CONFIG_IPMI_HANDLER is not set
+# CONFIG_HW_RANDOM is not set
+# CONFIG_R3964 is not set
+# CONFIG_GPIO_FTGPIO010_OLD is not set
+# CONFIG_RAW_DRIVER is not set
+# CONFIG_TCG_TPM is not set
+# CONFIG_I2C is not set
+# CONFIG_SPI is not set
+# CONFIG_GPIOLIB is not set
+# CONFIG_W1 is not set
+# CONFIG_POWER_SUPPLY is not set
+# CONFIG_HWMON is not set
+# CONFIG_THERMAL is not set
+# CONFIG_THERMAL_HWMON is not set
+# CONFIG_WATCHDOG is not set
+CONFIG_SSB_POSSIBLE=y
+
+#
+# Sonics Silicon Backplane
+#
+# CONFIG_SSB is not set
+
+#
+# Multifunction device drivers
+#
+# CONFIG_MFD_CORE is not set
+# CONFIG_MFD_SM501 is not set
+# CONFIG_HTC_PASIC3 is not set
+# CONFIG_MFD_TMIO is not set
+# CONFIG_REGULATOR is not set
+
+#
+# Multimedia devices
+#
+
+#
+# Multimedia core support
+#
+# CONFIG_VIDEO_DEV is not set
+# CONFIG_DVB_CORE is not set
+# CONFIG_VIDEO_MEDIA is not set
+
+#
+# Multimedia drivers
+#
+# CONFIG_DAB is not set
+
+#
+# Graphics support
+#
+# CONFIG_VGASTATE is not set
+# CONFIG_VIDEO_OUTPUT_CONTROL is not set
+CONFIG_FB=y
+# CONFIG_FIRMWARE_EDID is not set
+# CONFIG_FB_DDC is not set
+# CONFIG_FB_BOOT_VESA_SUPPORT is not set
+CONFIG_FB_CFB_FILLRECT=y
+CONFIG_FB_CFB_COPYAREA=y
+CONFIG_FB_CFB_IMAGEBLIT=y
+# CONFIG_FB_CFB_REV_PIXELS_IN_BYTE is not set
+# CONFIG_FB_SYS_FILLRECT is not set
+# CONFIG_FB_SYS_COPYAREA is not set
+# CONFIG_FB_SYS_IMAGEBLIT is not set
+# CONFIG_FB_FOREIGN_ENDIAN is not set
+# CONFIG_FB_SYS_FOPS is not set
+# CONFIG_FB_SVGALIB is not set
+# CONFIG_FB_MACMODES is not set
+# CONFIG_FB_BACKLIGHT is not set
+# CONFIG_FB_MODE_HELPERS is not set
+# CONFIG_FB_TILEBLITTING is not set
+
+#
+# Frame buffer hardware drivers
+#
+# CONFIG_FB_S1D13XXX is not set
+CONFIG_FB_FTLCDC100=y
+CONFIG_PANEL_AUA036QN01=y
+# CONFIG_PANEL_CH7013A is not set
+# CONFIG_PANEL_AUA070VW04 is not set
+# CONFIG_PANEL_LW500AC9601 is not set
+CONFIG_FFB_MODE_RGB=y
+# CONFIG_FFB_MODE_YUV422 is not set
+# CONFIG_FFB_MODE_YUV420 is not set
+# CONFIG_FFB_MODE_8BPP is not set
+CONFIG_FFB_MODE_16BPP=y
+# CONFIG_FFB_MODE_24BPP is not set
+# CONFIG_FB_VIRTUAL is not set
+# CONFIG_FB_METRONOME is not set
+# CONFIG_FB_MB862XX is not set
+# CONFIG_BACKLIGHT_LCD_SUPPORT is not set
+
+#
+# Display device support
+#
+# CONFIG_DISPLAY_SUPPORT is not set
+
+#
+# Console display driver support
+#
+# CONFIG_VGA_CONSOLE is not set
+CONFIG_DUMMY_CONSOLE=y
+CONFIG_FRAMEBUFFER_CONSOLE=y
+# CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY is not set
+# CONFIG_FRAMEBUFFER_CONSOLE_ROTATION is not set
+# CONFIG_FONTS is not set
+CONFIG_FONT_8x8=y
+CONFIG_FONT_8x16=y
+CONFIG_LOGO=y
+CONFIG_LOGO_LINUX_MONO=y
+CONFIG_LOGO_LINUX_VGA16=y
+CONFIG_LOGO_LINUX_CLUT224=y
+CONFIG_SOUND=y
+CONFIG_SOUND_OSS_CORE=y
+CONFIG_SND=y
+CONFIG_SND_TIMER=y
+CONFIG_SND_PCM=y
+# CONFIG_SND_SEQUENCER is not set
+CONFIG_SND_OSSEMUL=y
+# CONFIG_SND_MIXER_OSS is not set
+CONFIG_SND_PCM_OSS=y
+CONFIG_SND_PCM_OSS_PLUGINS=y
+# CONFIG_SND_DYNAMIC_MINORS is not set
+# CONFIG_SND_SUPPORT_OLD_API is not set
+# CONFIG_SND_VERBOSE_PROCFS is not set
+# CONFIG_SND_VERBOSE_PRINTK is not set
+# CONFIG_SND_DEBUG is not set
+CONFIG_SND_DRIVERS=y
+# CONFIG_SND_DUMMY is not set
+# CONFIG_SND_MTPAV is not set
+# CONFIG_SND_SERIAL_U16550 is not set
+# CONFIG_SND_MPU401 is not set
+
+#
+# ALSA NDS32 devices
+#
+CONFIG_SND_FTSSP010=y
+CONFIG_SND_FTSSP010_AC97=y
+# CONFIG_SND_FTSSP010_I2S is not set
+# CONFIG_SND_SOC is not set
+# CONFIG_SOUND_PRIME is not set
+# CONFIG_HID_SUPPORT is not set
+# CONFIG_USB_SUPPORT is not set
+# CONFIG_MMC is not set
+# CONFIG_MEMSTICK is not set
+# CONFIG_NEW_LEDS is not set
+# CONFIG_ACCESSIBILITY is not set
+CONFIG_RTC_LIB=y
+CONFIG_RTC_CLASS=y
+# CONFIG_RTC_HCTOSYS is not set
+# CONFIG_RTC_DEBUG is not set
+
+#
+# RTC interfaces
+#
+CONFIG_RTC_INTF_SYSFS=y
+CONFIG_RTC_INTF_PROC=y
+CONFIG_RTC_INTF_DEV=y
+# CONFIG_RTC_INTF_DEV_UIE_EMUL is not set
+# CONFIG_RTC_DRV_TEST is not set
+
+#
+# SPI RTC drivers
+#
+
+#
+# Platform RTC drivers
+#
+# CONFIG_RTC_DRV_DS1286 is not set
+# CONFIG_RTC_DRV_DS1511 is not set
+# CONFIG_RTC_DRV_DS1553 is not set
+# CONFIG_RTC_DRV_DS1742 is not set
+# CONFIG_RTC_DRV_STK17TA8 is not set
+# CONFIG_RTC_DRV_M48T86 is not set
+# CONFIG_RTC_DRV_M48T35 is not set
+# CONFIG_RTC_DRV_M48T59 is not set
+# CONFIG_RTC_DRV_BQ4802 is not set
+# CONFIG_RTC_DRV_V3020 is not set
+
+#
+# on-CPU RTC drivers
+#
+CONFIG_RTC_DRV_FTRTC010=y
+# CONFIG_DMADEVICES is not set
+# CONFIG_UIO is not set
+# CONFIG_STAGING is not set
+
+#
+# File systems
+#
+CONFIG_EXT2_FS=y
+# CONFIG_EXT2_FS_XATTR is not set
+# CONFIG_EXT2_FS_XIP is not set
+# CONFIG_EXT3_FS is not set
+# CONFIG_EXT4_FS is not set
+# CONFIG_REISERFS_FS is not set
+# CONFIG_JFS_FS is not set
+# CONFIG_FS_POSIX_ACL is not set
+CONFIG_FILE_LOCKING=y
+# CONFIG_XFS_FS is not set
+# CONFIG_OCFS2_FS is not set
+# CONFIG_BTRFS_FS is not set
+CONFIG_DNOTIFY=y
+CONFIG_INOTIFY=y
+CONFIG_INOTIFY_USER=y
+# CONFIG_QUOTA is not set
+# CONFIG_AUTOFS_FS is not set
+# CONFIG_AUTOFS4_FS is not set
+CONFIG_FUSE_FS=y
+
+#
+# CD-ROM/DVD Filesystems
+#
+# CONFIG_ISO9660_FS is not set
+# CONFIG_UDF_FS is not set
+
+#
+# DOS/FAT/NT Filesystems
+#
+CONFIG_FAT_FS=y
+CONFIG_MSDOS_FS=y
+CONFIG_VFAT_FS=y
+CONFIG_FAT_DEFAULT_CODEPAGE=437
+CONFIG_FAT_DEFAULT_IOCHARSET="iso8859-1"
+# CONFIG_NTFS_FS is not set
+
+#
+# Pseudo filesystems
+#
+CONFIG_PROC_FS=y
+# CONFIG_PROC_KCORE is not set
+CONFIG_PROC_SYSCTL=y
+# CONFIG_PROC_PAGE_MONITOR is not set
+CONFIG_SYSFS=y
+CONFIG_TMPFS=y
+# CONFIG_TMPFS_POSIX_ACL is not set
+# CONFIG_HUGETLB_PAGE is not set
+# CONFIG_CONFIGFS_FS is not set
+CONFIG_MISC_FILESYSTEMS=y
+# CONFIG_ADFS_FS is not set
+# CONFIG_AFFS_FS is not set
+# CONFIG_HFS_FS is not set
+# CONFIG_HFSPLUS_FS is not set
+# CONFIG_BEFS_FS is not set
+# CONFIG_BFS_FS is not set
+# CONFIG_EFS_FS is not set
+CONFIG_JFFS2_FS=y
+CONFIG_JFFS2_FS_DEBUG=0
+CONFIG_JFFS2_FS_WRITEBUFFER=y
+# CONFIG_JFFS2_FS_WBUF_VERIFY is not set
+# CONFIG_JFFS2_SUMMARY is not set
+# CONFIG_JFFS2_FS_XATTR is not set
+# CONFIG_JFFS2_COMPRESSION_OPTIONS is not set
+CONFIG_JFFS2_ZLIB=y
+# CONFIG_JFFS2_LZO is not set
+CONFIG_JFFS2_RTIME=y
+# CONFIG_JFFS2_RUBIN is not set
+# CONFIG_CRAMFS is not set
+# CONFIG_SQUASHFS is not set
+# CONFIG_VXFS_FS is not set
+# CONFIG_MINIX_FS is not set
+# CONFIG_OMFS_FS is not set
+# CONFIG_HPFS_FS is not set
+# CONFIG_QNX4FS_FS is not set
+# CONFIG_ROMFS_FS is not set
+# CONFIG_SYSV_FS is not set
+# CONFIG_UFS_FS is not set
+CONFIG_NETWORK_FILESYSTEMS=y
+CONFIG_NFS_FS=y
+CONFIG_NFS_V3=y
+# CONFIG_NFS_V3_ACL is not set
+# CONFIG_NFS_V4 is not set
+# CONFIG_NFSD is not set
+CONFIG_LOCKD=y
+CONFIG_LOCKD_V4=y
+CONFIG_NFS_COMMON=y
+CONFIG_SUNRPC=y
+# CONFIG_SUNRPC_REGISTER_V4 is not set
+# CONFIG_RPCSEC_GSS_KRB5 is not set
+# CONFIG_RPCSEC_GSS_SPKM3 is not set
+# CONFIG_SMB_FS is not set
+# CONFIG_CIFS is not set
+# CONFIG_NCP_FS is not set
+# CONFIG_CODA_FS is not set
+# CONFIG_AFS_FS is not set
+
+#
+# Partition Types
+#
+# CONFIG_PARTITION_ADVANCED is not set
+CONFIG_MSDOS_PARTITION=y
+CONFIG_NLS=y
+CONFIG_NLS_DEFAULT="iso8859-1"
+CONFIG_NLS_CODEPAGE_437=y
+# CONFIG_NLS_CODEPAGE_737 is not set
+# CONFIG_NLS_CODEPAGE_775 is not set
+# CONFIG_NLS_CODEPAGE_850 is not set
+# CONFIG_NLS_CODEPAGE_852 is not set
+# CONFIG_NLS_CODEPAGE_855 is not set
+# CONFIG_NLS_CODEPAGE_857 is not set
+# CONFIG_NLS_CODEPAGE_860 is not set
+# CONFIG_NLS_CODEPAGE_861 is not set
+# CONFIG_NLS_CODEPAGE_862 is not set
+# CONFIG_NLS_CODEPAGE_863 is not set
+# CONFIG_NLS_CODEPAGE_864 is not set
+# CONFIG_NLS_CODEPAGE_865 is not set
+# CONFIG_NLS_CODEPAGE_866 is not set
+# CONFIG_NLS_CODEPAGE_869 is not set
+# CONFIG_NLS_CODEPAGE_936 is not set
+# CONFIG_NLS_CODEPAGE_950 is not set
+# CONFIG_NLS_CODEPAGE_932 is not set
+# CONFIG_NLS_CODEPAGE_949 is not set
+# CONFIG_NLS_CODEPAGE_874 is not set
+# CONFIG_NLS_ISO8859_8 is not set
+# CONFIG_NLS_CODEPAGE_1250 is not set
+# CONFIG_NLS_CODEPAGE_1251 is not set
+# CONFIG_NLS_ASCII is not set
+CONFIG_NLS_ISO8859_1=y
+# CONFIG_NLS_ISO8859_2 is not set
+# CONFIG_NLS_ISO8859_3 is not set
+# CONFIG_NLS_ISO8859_4 is not set
+# CONFIG_NLS_ISO8859_5 is not set
+# CONFIG_NLS_ISO8859_6 is not set
+# CONFIG_NLS_ISO8859_7 is not set
+# CONFIG_NLS_ISO8859_9 is not set
+# CONFIG_NLS_ISO8859_13 is not set
+# CONFIG_NLS_ISO8859_14 is not set
+# CONFIG_NLS_ISO8859_15 is not set
+# CONFIG_NLS_KOI8_R is not set
+# CONFIG_NLS_KOI8_U is not set
+# CONFIG_NLS_UTF8 is not set
+# CONFIG_DLM is not set
+
+#
+# Kernel hacking
+#
+CONFIG_TRACE_IRQFLAGS_SUPPORT=y
+# CONFIG_PRINTK_TIME is not set
+CONFIG_ENABLE_WARN_DEPRECATED=y
+CONFIG_ENABLE_MUST_CHECK=y
+CONFIG_FRAME_WARN=1024
+CONFIG_MAGIC_SYSRQ=y
+# CONFIG_UNUSED_SYMBOLS is not set
+CONFIG_DEBUG_FS=y
+# CONFIG_HEADERS_CHECK is not set
+CONFIG_DEBUG_KERNEL=y
+CONFIG_DEBUG_SHIRQ=y
+CONFIG_DETECT_SOFTLOCKUP=y
+# CONFIG_BOOTPARAM_SOFTLOCKUP_PANIC is not set
+CONFIG_BOOTPARAM_SOFTLOCKUP_PANIC_VALUE=0
+CONFIG_SCHED_DEBUG=y
+CONFIG_SCHEDSTATS=y
+CONFIG_TIMER_STATS=y
+# CONFIG_DEBUG_OBJECTS is not set
+# CONFIG_SLUB_DEBUG_ON is not set
+# CONFIG_SLUB_STATS is not set
+CONFIG_DEBUG_RT_MUTEXES=y
+CONFIG_DEBUG_PI_LIST=y
+# CONFIG_RT_MUTEX_TESTER is not set
+CONFIG_DEBUG_SPINLOCK=y
+CONFIG_DEBUG_MUTEXES=y
+# CONFIG_DEBUG_LOCK_ALLOC is not set
+# CONFIG_PROVE_LOCKING is not set
+# CONFIG_LOCK_STAT is not set
+CONFIG_DEBUG_SPINLOCK_SLEEP=y
+# CONFIG_DEBUG_LOCKING_API_SELFTESTS is not set
+CONFIG_STACKTRACE=y
+# CONFIG_DEBUG_KOBJECT is not set
+CONFIG_DEBUG_INFO=y
+# CONFIG_DEBUG_VM is not set
+# CONFIG_DEBUG_WRITECOUNT is not set
+# CONFIG_DEBUG_MEMORY_INIT is not set
+CONFIG_DEBUG_LIST=y
+CONFIG_DEBUG_SG=y
+# CONFIG_DEBUG_NOTIFIERS is not set
+CONFIG_FRAME_POINTER=y
+# CONFIG_BOOT_PRINTK_DELAY is not set
+# CONFIG_RCU_TORTURE_TEST is not set
+# CONFIG_RCU_CPU_STALL_DETECTOR is not set
+# CONFIG_BACKTRACE_SELF_TEST is not set
+# CONFIG_DEBUG_BLOCK_EXT_DEVT is not set
+# CONFIG_FAULT_INJECTION is not set
+# CONFIG_LATENCYTOP is not set
+CONFIG_SYSCTL_SYSCALL_CHECK=y
+CONFIG_NOP_TRACER=y
+CONFIG_RING_BUFFER=y
+CONFIG_TRACING=y
+
+#
+# Tracers
+#
+# CONFIG_IRQSOFF_TRACER is not set
+# CONFIG_SCHED_TRACER is not set
+# CONFIG_CONTEXT_SWITCH_TRACER is not set
+# CONFIG_BOOT_TRACER is not set
+# CONFIG_TRACE_BRANCH_PROFILING is not set
+# CONFIG_FTRACE_STARTUP_TEST is not set
+# CONFIG_DYNAMIC_PRINTK_DEBUG is not set
+# CONFIG_SAMPLES is not set
+CONFIG_HAVE_ARCH_KGDB=y
+# CONFIG_KGDB is not set
+CONFIG_DEBUG_USER=y
+CONFIG_DEBUG_ERRORS=y
+# CONFIG_DEBUG_LL is not set
+# CONFIG_CCTL is not set
+# CONFIG_ELFCHK_DEFAULT_ENABLE is not set
+
+#
+# Security options
+#
+# CONFIG_KEYS is not set
+# CONFIG_SECURITY is not set
+# CONFIG_SECURITYFS is not set
+# CONFIG_SECURITY_FILE_CAPABILITIES is not set
+CONFIG_CRYPTO=y
+
+#
+# Crypto core or helper
+#
+# CONFIG_CRYPTO_FIPS is not set
+# CONFIG_CRYPTO_MANAGER is not set
+# CONFIG_CRYPTO_MANAGER2 is not set
+# CONFIG_CRYPTO_GF128MUL is not set
+# CONFIG_CRYPTO_NULL is not set
+# CONFIG_CRYPTO_CRYPTD is not set
+# CONFIG_CRYPTO_AUTHENC is not set
+# CONFIG_CRYPTO_TEST is not set
+
+#
+# Authenticated Encryption with Associated Data
+#
+# CONFIG_CRYPTO_CCM is not set
+# CONFIG_CRYPTO_GCM is not set
+# CONFIG_CRYPTO_SEQIV is not set
+
+#
+# Block modes
+#
+# CONFIG_CRYPTO_CBC is not set
+# CONFIG_CRYPTO_CTR is not set
+# CONFIG_CRYPTO_CTS is not set
+# CONFIG_CRYPTO_ECB is not set
+# CONFIG_CRYPTO_LRW is not set
+# CONFIG_CRYPTO_PCBC is not set
+# CONFIG_CRYPTO_XTS is not set
+
+#
+# Hash modes
+#
+# CONFIG_CRYPTO_HMAC is not set
+# CONFIG_CRYPTO_XCBC is not set
+
+#
+# Digest
+#
+# CONFIG_CRYPTO_CRC32C is not set
+# CONFIG_CRYPTO_MD4 is not set
+# CONFIG_CRYPTO_MD5 is not set
+# CONFIG_CRYPTO_MICHAEL_MIC is not set
+# CONFIG_CRYPTO_RMD128 is not set
+# CONFIG_CRYPTO_RMD160 is not set
+# CONFIG_CRYPTO_RMD256 is not set
+# CONFIG_CRYPTO_RMD320 is not set
+# CONFIG_CRYPTO_SHA1 is not set
+# CONFIG_CRYPTO_SHA256 is not set
+# CONFIG_CRYPTO_SHA512 is not set
+# CONFIG_CRYPTO_TGR192 is not set
+# CONFIG_CRYPTO_WP512 is not set
+
+#
+# Ciphers
+#
+# CONFIG_CRYPTO_AES is not set
+# CONFIG_CRYPTO_ANUBIS is not set
+# CONFIG_CRYPTO_ARC4 is not set
+# CONFIG_CRYPTO_BLOWFISH is not set
+# CONFIG_CRYPTO_CAMELLIA is not set
+# CONFIG_CRYPTO_CAST5 is not set
+# CONFIG_CRYPTO_CAST6 is not set
+# CONFIG_CRYPTO_DES is not set
+# CONFIG_CRYPTO_FCRYPT is not set
+# CONFIG_CRYPTO_KHAZAD is not set
+# CONFIG_CRYPTO_SALSA20 is not set
+# CONFIG_CRYPTO_SEED is not set
+# CONFIG_CRYPTO_SERPENT is not set
+# CONFIG_CRYPTO_TEA is not set
+# CONFIG_CRYPTO_TWOFISH is not set
+
+#
+# Compression
+#
+# CONFIG_CRYPTO_DEFLATE is not set
+# CONFIG_CRYPTO_LZO is not set
+
+#
+# Random Number Generation
+#
+# CONFIG_CRYPTO_ANSI_CPRNG is not set
+# CONFIG_CRYPTO_HW is not set
+
+#
+# Library routines
+#
+CONFIG_BITREVERSE=y
+CONFIG_GENERIC_FIND_LAST_BIT=y
+# CONFIG_CRC_CCITT is not set
+# CONFIG_CRC16 is not set
+# CONFIG_CRC_T10DIF is not set
+# CONFIG_CRC_ITU_T is not set
+CONFIG_CRC32=y
+# CONFIG_CRC7 is not set
+# CONFIG_LIBCRC32C is not set
+CONFIG_ZLIB_INFLATE=y
+CONFIG_ZLIB_DEFLATE=y
+CONFIG_PLIST=y
+CONFIG_HAS_IOMEM=y
+CONFIG_HAS_DMA=y
diff -Nur linux-3.4.113.orig/arch/nds32/configs/xc5_defconfig linux-3.4.113/arch/nds32/configs/xc5_defconfig
--- linux-3.4.113.orig/arch/nds32/configs/xc5_defconfig 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/configs/xc5_defconfig 2016-12-01 20:59:24.328611826 +0100
@@ -0,0 +1,117 @@
+CONFIG_EXPERIMENTAL=y
+CONFIG_CROSS_COMPILE="nds32le-linux-"
+# CONFIG_LOCALVERSION_AUTO is not set
+CONFIG_SYSVIPC=y
+CONFIG_BSD_PROCESS_ACCT=y
+CONFIG_BSD_PROCESS_ACCT_V3=y
+CONFIG_IKCONFIG=y
+CONFIG_IKCONFIG_PROC=y
+CONFIG_LOG_BUF_SHIFT=14
+CONFIG_BLK_DEV_INITRD=y
+CONFIG_INITRAMFS_SOURCE="/home/users/greentime/os/ramdisk/disk-nds32le-linux-glibc-v3 /home/users/greentime/os/ramdisk/disk-nds32le-linux-glibc-v3/dev/initramfs.devnodes"
+CONFIG_CC_OPTIMIZE_FOR_SIZE=y
+CONFIG_SYSCTL_SYSCALL=y
+# CONFIG_HOTPLUG is not set
+# CONFIG_SIGNALFD is not set
+CONFIG_EMBEDDED=y
+# CONFIG_VM_EVENT_COUNTERS is not set
+CONFIG_PROFILING=y
+CONFIG_OPROFILE=y
+CONFIG_MODULES=y
+CONFIG_MODULE_UNLOAD=y
+# CONFIG_BLK_DEV_BSG is not set
+CONFIG_PLATFORM_AHBDMA=y
+CONFIG_PLATFORM_APBDMA=y
+CONFIG_SYS_CLK=30000000
+CONFIG_UART_CLK=14745600
+CONFIG_SDRAM_SIZE=0x8000000
+CONFIG_HZ_100=y
+CONFIG_CMDLINE="root=/dev/ram0 rw mem=128M@0x0 initrd=0x1000000,8M console=ttyS0,38400n8 earlyprintk=uart8250-32bit,0x99600000 rootfstype=ext2 init=/bin/busybox init -s user_debug=-1"
+# CONFIG_CORE_DUMP_DEFAULT_ELF_HEADERS is not set
+CONFIG_NET=y
+CONFIG_PACKET=y
+CONFIG_UNIX=y
+CONFIG_NET_KEY=y
+CONFIG_INET=y
+CONFIG_IP_MULTICAST=y
+# CONFIG_INET_XFRM_MODE_TRANSPORT is not set
+# CONFIG_INET_XFRM_MODE_TUNNEL is not set
+# CONFIG_INET_XFRM_MODE_BEET is not set
+# CONFIG_INET_LRO is not set
+# CONFIG_INET_DIAG is not set
+# CONFIG_IPV6 is not set
+CONFIG_BRIDGE=y
+CONFIG_MTD=y
+CONFIG_MTD_CMDLINE_PARTS=y
+CONFIG_MTD_CHAR=y
+CONFIG_MTD_BLOCK=y
+CONFIG_MTD_CFI=y
+CONFIG_MTD_CFI_INTELEXT=y
+CONFIG_MTD_PHYSMAP=y
+CONFIG_MTD_PHYSMAP_COMPAT=y
+CONFIG_MTD_PHYSMAP_START=0x80400000
+CONFIG_MTD_PHYSMAP_LEN=0x2000000
+CONFIG_MTD_PHYSMAP_BANKWIDTH=4
+CONFIG_BLK_DEV_LOOP=y
+CONFIG_BLK_DEV_RAM=y
+CONFIG_BLK_DEV_RAM_SIZE=8192
+CONFIG_NETDEVICES=y
+CONFIG_TUN=y
+CONFIG_FTMAC100=y
+# CONFIG_INPUT_MOUSEDEV is not set
+CONFIG_INPUT_EVDEV=y
+# CONFIG_INPUT_KEYBOARD is not set
+# CONFIG_INPUT_MOUSE is not set
+CONFIG_INPUT_TOUCHSCREEN=y
+# CONFIG_SERIO is not set
+CONFIG_SERIAL_8250=y
+CONFIG_SERIAL_8250_CONSOLE=y
+CONFIG_SERIAL_8250_NR_UARTS=3
+CONFIG_SERIAL_8250_RUNTIME_UARTS=3
+# CONFIG_HW_RANDOM is not set
+# CONFIG_HWMON is not set
+CONFIG_FB=y
+# CONFIG_VGA_CONSOLE is not set
+CONFIG_FRAMEBUFFER_CONSOLE=y
+CONFIG_LOGO=y
+CONFIG_SOUND=y
+CONFIG_SND=y
+CONFIG_SND_PCM_OSS=y
+# CONFIG_SND_SUPPORT_OLD_API is not set
+# CONFIG_SND_VERBOSE_PROCFS is not set
+# CONFIG_HID_SUPPORT is not set
+# CONFIG_USB_SUPPORT is not set
+CONFIG_MMC=y
+CONFIG_MMC_FTSDC010=y
+# CONFIG_MEMSTICK is not set
+# CONFIG_NEW_LEDS is not set
+# CONFIG_ACCESSIBILITY is not set
+CONFIG_RTC_LIB=y
+CONFIG_RTC_CLASS=y
+# CONFIG_RTC_HCTOSYS is not set
+CONFIG_EXT2_FS=y
+CONFIG_FUSE_FS=y
+CONFIG_MSDOS_FS=y
+CONFIG_VFAT_FS=y
+# CONFIG_PROC_PAGE_MONITOR is not set
+CONFIG_TMPFS=y
+CONFIG_JFFS2_FS=y
+CONFIG_NFS_FS=y
+CONFIG_NFS_V3=y
+CONFIG_NLS_CODEPAGE_437=y
+CONFIG_NLS_ISO8859_1=y
+CONFIG_MAGIC_SYSRQ=y
+CONFIG_DEBUG_FS=y
+CONFIG_DEBUG_SHIRQ=y
+CONFIG_SCHEDSTATS=y
+CONFIG_TIMER_STATS=y
+CONFIG_DEBUG_RT_MUTEXES=y
+CONFIG_DEBUG_SPINLOCK=y
+CONFIG_DEBUG_MUTEXES=y
+CONFIG_DEBUG_INFO=y
+CONFIG_DEBUG_LIST=y
+CONFIG_DEBUG_SG=y
+CONFIG_DEBUG_USER=y
+CONFIG_DEBUG_ERRORS=y
+# CONFIG_CRYPTO_ANSI_CPRNG is not set
+# CONFIG_CRYPTO_HW is not set
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/amic.h linux-3.4.113/arch/nds32/include/asm/amic.h
--- linux-3.4.113.orig/arch/nds32/include/asm/amic.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/amic.h 2016-12-01 20:59:24.328611826 +0100
@@ -0,0 +1,60 @@
+/*
+ * linux/arch/nds32/include/asm/amic.h
+ *
+ * Andes Multi-core Interrupt Controller Device Driver Interface
+ *
+ * Copyright (C) 2010 Andes Technology Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * ChangeLog
+ *
+ * Shawn Lin 09/02/2010 Created for Andes AG102 platform code.
+ */
+
+#ifndef __NDS32_AMIC_HEADER__
+#define __NDS32_AMIC_HEADER__
+
+#define IRQ_BASE 0x0
+#define IRQ_TOTAL 0x20
+#define DEFAULT_MODE 0x000ecc00
+#define DEFAULT_LEVEL 0xffffffff
+#define AMIC_BASE AMIC_VA_BASE
+#define CONFIG 0x00
+#define CPUDC 0x04
+#define CPUID0 0x08
+#define CPUID1 0x0c
+#define INTTRG 0x20
+#define INTLVL 0x24
+#define INTSRC 0x28
+#define IPITRG 0x40
+#define IPISTA 0x44
+#define IPIPTR 0x48
+#define IPIGST 0x4c
+#define IPIGPT 0x50
+#define INTEN 0x80
+#define INTSTA 0x84
+#define HW0STA 0x88
+#define HW1STA 0x8c
+#define HW2STA 0x90
+#define HW3STA 0x94
+#define HW4STA 0x98
+#define HW5STA 0x9c
+#define PRITY0 0xa0
+#define PRITY1 0xa4
+#define PRITY2 0xa8
+#define PRITY3 0xac
+
+#endif /* __NDS32_AMIC_HEADER__ */
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/asm-offsets.h linux-3.4.113/arch/nds32/include/asm/asm-offsets.h
--- linux-3.4.113.orig/arch/nds32/include/asm/asm-offsets.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/asm-offsets.h 2016-12-01 20:59:24.332611980 +0100
@@ -0,0 +1 @@
+#include <generated/asm-offsets.h>
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/assembler.h linux-3.4.113/arch/nds32/include/asm/assembler.h
--- linux-3.4.113.orig/arch/nds32/include/asm/assembler.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/assembler.h 2016-12-01 20:59:24.332611980 +0100
@@ -0,0 +1,141 @@
+/*
+ * linux/arch/nds32/include/asm/assembler.h
+ * Copyright (C) 2008 Andes Technology Corporation
+ */
+
+#ifndef __NDS32_ASSEMBLER_H__
+#define __NDS32_ASSEMBLER_H__
+
+/*
+ * Stack format
+ */
+
+#define S_PAD 0xac /* Padding for stack pointer 8-byte alignment. */
+#define S_FUCOP_CTL 0xa8
+#define S_LP 0xa4
+#define S_GP 0xa0
+#define S_FP 0x9c
+#define S_R25 0x98
+#define S_R24 0x94
+#define S_R23 0x90
+#define S_R22 0x8c
+#define S_R21 0x88
+#define S_R20 0x84
+#define S_R19 0x80
+#define S_R18 0x7c
+#define S_R17 0x78
+#define S_R16 0x74
+#define S_R15 0x70
+#define S_R14 0x6c
+#define S_R13 0x68
+#define S_R12 0x64
+#define S_R11 0x60
+#define S_R10 0x5c
+#define S_R9 0x58
+#define S_R8 0x54
+#define S_R7 0x50
+#define S_R6 0x4c
+#define S_R5 0x48
+#define S_R4 0x44
+#define S_R3 0x40
+#define S_R2 0x3c
+#define S_R1 0x38
+#define S_R0 0x34
+#define S_D1LO 0x30
+#define S_D1HI 0x2c
+#define S_D0LO 0x28
+#define S_D0HI 0x24
+#define S_PP1 0x20
+#define S_PP0 0x1c
+#define S_PIPC 0x18
+#define S_PIPSW 0x14
+#define S_ORIG_R0 0x10
+#define S_SP 0xc
+#define S_IPC 0x8
+#define S_IPSW 0x4
+#define S_IR0 0x0
+
+#if !defined(CONFIG_ABI1)
+#define S_OFF 0
+#else
+#define S_OFF 24
+#endif
+
+#ifdef __ASSEMBLY__
+.macro get_thread_info, rd
+ srli \rd, $sp, #13
+ slli \rd, \rd, #13
+.endm
+
+.macro gie_disable
+ setgie.d
+#ifdef CONFIG_CPU_N1213_43U1HA0
+ isb
+#else
+ dsb
+#endif
+.endm
+
+.macro gie_enable
+ setgie.e
+#ifdef CONFIG_CPU_N1213_43U1HA0
+ isb
+#else
+ dsb
+#endif
+.endm
+
+.macro gie_save oldpsw
+ mfsr \oldpsw, $ir0
+ setgie.d
+#ifdef CONFIG_CPU_N1213_43U1HA0
+ isb
+#else
+ dsb
+#endif
+.endm
+
+.macro gie_restore oldpsw
+ andi \oldpsw, \oldpsw, #0x1
+ beqz \oldpsw, 7001f
+ setgie.e
+#ifdef CONFIG_CPU_N1213_43U1HA0
+ isb
+#else
+ dsb
+#endif
+7001:
+.endm
+
+
+#define USER(insn, reg, addr, opr) \
+9999: insn reg, addr, opr; \
+ .section __ex_table,"a"; \
+ .align 3; \
+ .long 9999b, 9001f; \
+ .previous
+
+#else /* __ASSEMBLY__ */
+
+__asm__ (".macro gie_disable\n\t"
+ "setgie.d\n\t"
+#ifdef CONFIG_CPU_N1213_43U1HA0
+ "isb\n\t"
+#else
+ "dsb\n\t"
+#endif
+ ".endm\n\t"
+ );
+
+__asm__ (".macro gie_enable\n\t"
+ "setgie.e\n\t"
+#ifdef CONFIG_CPU_N1213_43U1HA0
+ "isb\n\t"
+#else
+ "dsb\n\t"
+#endif
+ ".endm\n\t"
+ );
+
+#endif /* !__ASSEMBLY__ */
+#endif /* __NDS32_ASSEMBLER_H__ */
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/atomic.h linux-3.4.113/arch/nds32/include/asm/atomic.h
--- linux-3.4.113.orig/arch/nds32/include/asm/atomic.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/atomic.h 2016-12-01 20:59:24.332611980 +0100
@@ -0,0 +1,267 @@
+/*
+ * linux/arch/nds32/include/asm/atomic.h
+ * Copyright (C) 2008 Andes Technology Corporation
+ */
+
+#ifndef __NDS32_ATOMIC_H__
+#define __NDS32_ATOMIC_H__
+
+#include <linux/types.h>
+#include <asm/barrier.h>
+#include <asm/cmpxchg.h>
+
+#if defined(CONFIG_SMP) || !defined(CONFIG_CPU_DCACHE_WRITETHROUGH)
+
+#define ATOMIC_INIT(i) { (i) }
+#define atomic_set(v,i) (((v)->counter) = (i))
+#define atomic_read(v) (*(volatile int *)&(v)->counter)
+
+static inline void atomic_add(int i, atomic_t *v)
+{
+ int temp;
+ __asm__ __volatile__(
+ "movi\t$r15, #0\n"
+ "1:\n"
+ "\tllw\t%0, [%1+$r15]\n"
+ "\tadd\t%0, %0, %2\n"
+ "\tscw\t%0, [%1+$r15]\n"
+ "\tbeqz\t%0, 1b\n"
+ : "=&r" (temp) : "r" (&v->counter), "r" (i));
+}
+
+static inline void atomic_sub(int i, atomic_t *v)
+{
+ int temp;
+ __asm__ __volatile__(
+ "movi\t$r15, #0\n"
+ "1:\n"
+ "\tllw\t%0, [%1+$r15]\n"
+ "\tsub\t%0, %0, %2\n"
+ "\tscw\t%0, [%1+$r15]\n"
+ "\tbeqz\t%0, 1b\n"
+ : "=&r" (temp) : "r" (&v->counter), "r" (i));
+}
+
+#define atomic_inc(v) atomic_add(1, v)
+#define atomic_dec(v) atomic_sub(1, v)
+
+static inline int atomic_inc_return(atomic_t *v)
+{
+ int temp1, temp2;
+ __asm__ __volatile__(
+ "movi\t$r15, #0\n"
+ "1:\n"
+ "\tllw\t%1, [%2+$r15]\n"
+ "\taddi\t%1, %1, #1\n"
+ "\tori\t%0, %1, #0\n"
+ "\tscw\t%1, [%2+$r15]\n"
+ "\tbeqz\t%1, 1b\n"
+ : "=&r" (temp2), "=&r" (temp1)
+ : "r" (&v->counter));
+ return temp2;
+}
+
+static inline int atomic_dec_return(atomic_t *v)
+{
+ int temp1, temp2;
+ __asm__ __volatile__(
+ "movi\t$r15, #0\n"
+ "1:\n"
+ "\tllw\t%1, [%2+$r15]\n"
+ "\taddi\t%1, %1, #-1\n"
+ "\tori\t%0, %1, #0\n"
+ "\tscw\t%1, [%2+$r15]\n"
+ "\tbeqz\t%1, 1b\n"
+ : "=&r" (temp2), "=&r" (temp1)
+ : "r" (&v->counter));
+ return temp2;
+}
+
+static inline int atomic_add_return(int i, atomic_t *v)
+{
+ int temp1, temp2;
+
+ smp_mb();
+
+ __asm__ __volatile__(
+ "movi\t$r15, #0\n"
+ "1:\n"
+ "\tllw\t%1, [%2+$r15]\n"
+ "\tadd\t%1, %1, %3\n"
+ "\tori\t%0, %1, #0\n"
+ "\tscw\t%1, [%2+$r15]\n"
+ "\tbeqz\t%1, 1b\n"
+ : "=&r" (temp2), "=&r" (temp1)
+ : "r" (&v->counter), "r" (i));
+
+ smp_mb();
+
+ return temp2;
+}
+
+static inline int atomic_sub_return(int i, atomic_t *v)
+{
+ int temp1, temp2;
+
+ smp_mb();
+
+ __asm__ __volatile__(
+ "movi\t$r15, #0\n"
+ "1:\n"
+ "\tllw\t%1, [%2+$r15]\n"
+ "\tsub\t%1, %1, %3\n"
+ "\tori\t%0, %1, #0\n"
+ "\tscw\t%1, [%2+$r15]\n"
+ "\tbeqz\t%1, 1b\n"
+ : "=&r" (temp2), "=&r" (temp1)
+ : "r" (&v->counter), "r" (i));
+
+ smp_mb();
+
+ return temp2;
+}
+
+/*
+ * atomic_dec_if_positive - conditionally subtract one from atomic variable
+ * @v: pointer of type atomic_t
+ *
+ * Atomically test @v and subtract one if @v is greater or equal than one.
+ * The function returns the old value of @v minus one.
+ */
+static inline int atomic_dec_if_positive(atomic_t * v)
+{
+ int temp1, temp2, temp3;
+ __asm__ __volatile__(
+ "movi\t$r15, #0\n"
+ "1:\n"
+ "\tllw\t%2, [%3+$r15]\n"
+ "\taddi\t%0, %2, #-1\n"
+ "\tslts\t%1, $r15, %2\n"
+ "\tsub\t%2, %2, %1\n"
+ "\tscw\t%2, [%3+$r15]\n"
+ "\tbeqz\t%2, 1b\n"
+ : "=&r" (temp3), "=&r" (temp2), "=&r" (temp1)
+ : "r" (&v->counter));
+ return temp3;
+}
+
+
+#define atomic_inc_and_test(v) (atomic_add_return(1, v) == 0)
+#define atomic_dec_and_test(v) (atomic_sub_return(1, v) == 0)
+#define atomic_sub_and_test(i,v) (atomic_sub_return((i),(v)) == 0)
+#define atomic_add_negative(i,v) (atomic_add_return((i),(v)) < 0)
+
+
+static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
+{
+ int temp1, temp2, temp3;
+
+ smp_mb();
+
+ __asm__ __volatile__(
+ "movi\t$r15, #0\n"
+ "1:\n"
+ "\tllw\t%0, [%3+$r15]\n"
+ "\tsub\t%2, %0, %5\n"
+ "\tcmovz\t%1, %4, %2\n"
+ "\tcmovn\t%1, %0, %2\n"
+ "\tscw\t%1, [%3+$r15]\n"
+ "\tbeqz\t%1, 1b\n"
+ : "=&r" (temp3), "=&r" (temp2), "=&r" (temp1)
+ : "r" (&v->counter), "r" (new), "r" (old));
+
+ smp_mb();
+
+ return temp3;
+}
+
+static inline int atomic_xchg(atomic_t *v, int new)
+{
+ int temp1, temp2;
+ __asm__ __volatile__(
+ "movi\t$r15, #0\n"
+ "1:\n"
+ "\tllw\t%0, [%2+$r15]\n"
+ "\tori\t%1, %3, #0\n"
+ "\tscw\t%1, [%2+$r15]\n"
+ "\tbeqz\t%1, 1b\n"
+ : "=&r" (temp2), "=&r" (temp1)
+ : "r" (&v->counter), "r" (new));
+ return temp2;
+}
+
+static inline int __atomic_add_unless(atomic_t *v, int a, int u)
+{
+ int c, old;
+
+ c = atomic_read(v);
+ while (c != u && (old = atomic_cmpxchg((v), c, c + a)) != c)
+ c = old;
+ return c;
+}
+
+static inline int atomic_inc_not_zero(atomic_t *v)
+{
+ int temp1, temp2;
+ __asm__ __volatile__(
+ "movi\t$r15, #0\n"
+ "1:\n"
+ "\tllw\t%1, [%2+$r15]\n"
+ "\tslt\t%0, $r15, %1\n"
+ "\tadd\t%1, %1, %0\n"
+ "\tscw\t%1, [%2+$r15]\n"
+ "\tbeqz\t%1, 1b\n"
+ : "=&r" (temp2), "=&r" (temp1)
+ : "r" (&v->counter));
+ return temp2;
+}
+
+#define smp_mb__before_atomic_dec() barrier()
+#define smp_mb__after_atomic_dec() barrier()
+#define smp_mb__before_atomic_inc() barrier()
+#define smp_mb__after_atomic_inc() barrier()
+
+//#include <asm-generic/atomic-long.h>
+#else /* CONFIG_SMP*/
+
+
+
+#define ATOMIC_INIT(i) { (i) }
+
+#ifdef __KERNEL__
+
+#include <asm-generic/atomic.h>
+
+static inline int atomic_dec_if_positive(atomic_t * v)
+{
+ unsigned long flags;
+ int result;
+
+ local_irq_save(flags);
+ result = v->counter;
+ result -= 1;
+ if (result >= 0)
+ v->counter = result;
+ local_irq_restore(flags);
+ return result;
+}
+
+/* Atomic operations are already serializing on ARM */
+#define smp_mb__before_atomic_dec() barrier()
+#define smp_mb__after_atomic_dec() barrier()
+#define smp_mb__before_atomic_inc() barrier()
+#define smp_mb__after_atomic_inc() barrier()
+
+#endif
+
+#endif /* CONFIG_SMP */
+
+#ifndef CONFIG_GENERIC_ATOMIC64
+typedef struct {
+ u64 __aligned(8) counter;
+} atomic64_t;
+#define ATOMIC64_INIT(i) { (i) }
+static inline u64 atomic64_add_return(u64 i, atomic64_t *v){ return 0; }
+#endif /* CONFIG_GENERIC_ATOMIC64 */
+
+#endif /* __NDS32_ATOMIC_H__ */
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/audio.h linux-3.4.113/arch/nds32/include/asm/audio.h
--- linux-3.4.113.orig/arch/nds32/include/asm/audio.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/audio.h 2016-12-01 20:59:24.332611980 +0100
@@ -0,0 +1,65 @@
+/*
+ * linux/arch/nds32/include/asm/audio.h
+ * Copyright (C) 2009 Andes Technology Corporation
+ */
+
+#ifndef __ASM_NDS32_AUDIO_H
+#define __ASM_NDS32_AUDIO_H
+
+#ifndef __ASSEMBLY__
+#include <linux/preempt.h>
+#include <asm/ptrace.h>
+
+extern void save_audio(struct task_struct *tsk);
+extern void audioload(struct audio_struct *audioregs);
+extern void save_audio(struct task_struct *__tsk);
+extern void do_audio_context_switch(unsigned long error_code, struct pt_regs *regs);
+
+#ifdef CONFIG_AUDIO
+
+#define test_tsk_audio(regs) (regs->NDS32_FUCOP_CTL & FUCOP_CTL_mskAUEN)
+
+struct task_struct;
+
+static inline void enable_audio(void)
+{
+ SET_FUCOP_CTL(GET_FUCOP_CTL() | FUCOP_CTL_mskAUEN);
+}
+
+static inline void disable_audio(void)
+{
+ SET_FUCOP_CTL(GET_FUCOP_CTL() & ~FUCOP_CTL_mskAUEN);
+}
+
+static inline void release_audio(struct pt_regs *regs)
+{
+ regs->NDS32_FUCOP_CTL &= ~FUCOP_CTL_mskAUEN;
+ regs->NDS32_ipsw &= ~PSW_mskAEN;
+}
+
+static inline void grab_audio(struct pt_regs *regs)
+{
+ regs->NDS32_FUCOP_CTL |= FUCOP_CTL_mskAUEN;
+ regs->NDS32_ipsw |= PSW_mskAEN;
+}
+#ifdef CONFIG_UNLAZY_AUDIO
+static inline void unlazy_audio(struct task_struct *tsk)
+{
+ preempt_disable();
+ if (test_tsk_audio(task_pt_regs(tsk)))
+ save_audio(tsk);
+ preempt_enable();
+}
+#endif
+static inline void clear_audio(struct pt_regs *regs)
+{
+ preempt_disable();
+ if (test_tsk_audio(regs)) {
+ release_audio(regs);
+ }
+ preempt_enable();
+}
+#endif /* CONFIG_AUDIO */
+#endif /* __ASSEMBLY__ */
+
+#endif /* __ASM_NDS32_AUDIO_H */
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/auxvec.h linux-3.4.113/arch/nds32/include/asm/auxvec.h
--- linux-3.4.113.orig/arch/nds32/include/asm/auxvec.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/auxvec.h 2016-12-01 20:59:24.332611980 +0100
@@ -0,0 +1,9 @@
+/*
+ * linux/arch/nds32/include/asm/auxvec.h
+ * Copyright (C) 2008 Andes Technology Corporation
+ */
+
+#ifndef __NDS32_AUXVEC_H__
+#define __NDS32_AUXVEC_H__
+
+#endif /*__NDS32_AUXVEC_H__ */
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/barrier.h linux-3.4.113/arch/nds32/include/asm/barrier.h
--- linux-3.4.113.orig/arch/nds32/include/asm/barrier.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/barrier.h 2016-12-01 20:59:24.332611980 +0100
@@ -0,0 +1,85 @@
+/* ============================================================================
+ *
+ * linux/arch/nds32/include/asm/system.h
+ *
+ * Copyright (C) 2007 Andes Technology Corporation
+ * This file is part of Linux and should be licensed under the GPL.
+ * See the file COPYING for conditions for redistribution.
+ *
+ * Abstract:
+ *
+ * This program is for NDS32 architecture.
+ *
+ * Revision History:
+ *
+ * Nov.26.2007 Initial ported by Tom, Shawn, and Steven,
+ * patched for KGDB and refined code by Harry.
+ *
+ * Note:
+ *
+ * ============================================================================
+ */
+#ifndef __ASM_NDS32_BARRIER_H
+#define __ASM_NDS32_BARRIER_H
+
+#ifdef __KERNEL__
+
+/*
+ * This is used to ensure the compiler did actually allocate the register we
+ * asked it for some inline assembly sequences. Apparently we can't trust
+ * the compiler from one version to another so a bit of paranoia won't hurt.
+ * This string is meant to be concatenated with the inline asm string and
+ * will cause compilation to stop on mismatch.
+ * (for details, see gcc PR 15089)
+ */
+#define __asmeq(x, y) ".ifnc " x "," y " ; .err ; .endif\n\t"
+
+#ifndef __ASSEMBLY__
+
+#include <linux/linkage.h>
+#include <linux/irqflags.h>
+
+struct thread_info;
+struct task_struct;
+
+struct pt_regs;
+
+void die(const char *msg, struct pt_regs *regs, int err)
+ __attribute__((noreturn));
+
+void die_if_kernel(const char *str, struct pt_regs *regs, int err);
+
+#include <asm/proc-fns.h>
+
+#define UDBG_UNDEFINED (1 << 0)
+#define UDBG_SYSCALL (1 << 1)
+#define UDBG_BADABORT (1 << 2)
+#define UDBG_SEGV (1 << 3)
+#define UDBG_BUS (1 << 4)
+
+extern unsigned int user_debug;
+
+#define mb() __asm__ __volatile__ ("" : : : "memory")
+#define rmb() mb()
+#define wmb() mb()
+#define read_barrier_depends() do { } while(0)
+#define set_mb(var, value) do { var = value; mb(); } while (0)
+#define set_wmb(var, value) do { var = value; wmb(); } while (0)
+
+#ifdef CONFIG_SMP
+#define smp_mb() mb()
+#define smp_rmb() rmb()
+#define smp_wmb() wmb()
+#define smp_read_barrier_depends() read_barrier_depends()
+#else
+#define smp_mb() barrier()
+#define smp_rmb() barrier()
+#define smp_wmb() barrier()
+#define smp_read_barrier_depends() do { } while(0)
+#endif
+
+#endif /* __ASSEMBLY__ */
+
+#endif /* __KERNEL__ */
+
+#endif //__ASM_NDS32_SYSTEM_H
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/bitfield.h linux-3.4.113/arch/nds32/include/asm/bitfield.h
--- linux-3.4.113.orig/arch/nds32/include/asm/bitfield.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/bitfield.h 2016-12-01 20:59:24.332611980 +0100
@@ -0,0 +1,895 @@
+/*
+ * linux/arch/nds32/include/asm/bitfield.h
+ * Copyright (C) 2008 Andes Technology Corporation
+ */
+
+#ifndef __NDS32_BITFIELD_H__
+#define __NDS32_BITFIELD_H__
+/******************************************************************************
+ * cr0: CPU_VER (CPU Version Register)
+ *****************************************************************************/
+#define CPU_VER_offCFGID 0 /* Minor configuration */
+#define CPU_VER_offREV 16 /* Revision of the CPU version */
+#define CPU_VER_offCPUID 24 /* Major CPU versions */
+
+#define CPU_VER_mskCFGID ( 0xFFFF << CPU_VER_offCFGID )
+#define CPU_VER_mskREV ( 0xFF << CPU_VER_offREV )
+#define CPU_VER_mskCPUID ( 0xFF << CPU_VER_offCPUID )
+
+/******************************************************************************
+ * cr1: ICM_CFG (Instruction Cache/Memory Configuration Register)
+ *****************************************************************************/
+#define ICM_CFG_offISET 0 /* I-cache sets (# of cache lines) per way */
+#define ICM_CFG_offIWAY 3 /* I-cache ways */
+#define ICM_CFG_offISZ 6 /* I-cache line size */
+#define ICM_CFG_offILCK 9 /* I-cache locking support */
+#define ICM_CFG_offILMB 10 /* On-chip ILM banks */
+#define ICM_CFG_offBSAV 13 /* ILM base register alignment version */
+/* bit 15:31 reserved */
+
+#define ICM_CFG_mskISET ( 0x7 << ICM_CFG_offISET )
+#define ICM_CFG_mskIWAY ( 0x7 << ICM_CFG_offIWAY )
+#define ICM_CFG_mskISZ ( 0x7 << ICM_CFG_offISZ )
+#define ICM_CFG_mskILCK ( 0x1 << ICM_CFG_offILCK )
+#define ICM_CFG_mskILMB ( 0x7 << ICM_CFG_offILMB )
+#define ICM_CFG_mskBSAV ( 0x3 << ICM_CFG_offBSAV )
+
+/******************************************************************************
+ * cr2: DCM_CFG (Data Cache/Memory Configuration Register)
+ *****************************************************************************/
+#define DCM_CFG_offDSET 0 /* D-cache sets (# of cache lines) per way */
+#define DCM_CFG_offDWAY 3 /* D-cache ways */
+#define DCM_CFG_offDSZ 6 /* D-cache line size */
+#define DCM_CFG_offDLCK 9 /* D-cache locking support */
+#define DCM_CFG_offDLMB 10 /* On-chip DLM banks */
+#define DCM_CFG_offBSAV 13 /* DLM base register alignment version */
+/* bit 15:31 reserved */
+
+#define DCM_CFG_mskDSET ( 0x7 << DCM_CFG_offDSET )
+#define DCM_CFG_mskDWAY ( 0x7 << DCM_CFG_offDWAY )
+#define DCM_CFG_mskDSZ ( 0x7 << DCM_CFG_offDSZ )
+#define DCM_CFG_mskDLCK ( 0x1 << DCM_CFG_offDLCK )
+#define DCM_CFG_mskDLMB ( 0x7 << DCM_CFG_offDLMB )
+#define DCM_CFG_mskBSAV ( 0x3 << DCM_CFG_offBSAV )
+
+/******************************************************************************
+ * cr3: MMU_CFG (MMU Configuration Register)
+ *****************************************************************************/
+#define MMU_CFG_offMMPS 0 /* Memory management protection scheme */
+#define MMU_CFG_offMMPV 2 /* Memory management protection version number */
+#define MMU_CFG_offFATB 7 /* Fully-associative or non-fully-associative TLB */
+
+#ifdef CONFIG_FULL_ASSOC
+#define MMU_CFG_offFATBSZ 8 /* TLB entries while using full-associative TLB */
+#else
+#define MMU_CFG_offTBW 8 /* TLB ways(non-associative) TBS */
+#define MMU_CFG_offTBS 11 /* TLB sets per way(non-associative) TBS */
+/* bit 14:14 reserved */
+#endif
+
+#define MMU_CFG_offEP8MIN4 15 /* 8KB page supported while minimum page is 4KB */
+#define MMU_CFG_offfEPSZ 16 /* Extra page size supported */
+#define MMU_CFG_offTLBLCK 24 /* TLB locking support */
+#define MMU_CFG_offHPTWK 25 /* Hardware Page Table Walker implemented */
+#define MMU_CFG_offDE 26 /* Default endian */
+#define MMU_CFG_offNTPT 27 /* Partitions for non-translated attributes */
+#define MMU_CFG_offIVTB 28 /* Invisible TLB */
+#define MMU_CFG_offVLPT 29 /* VLPT for fast TLB fill handling implemented */
+#define MMU_CFG_offNTME 30 /* Non-translated VA to PA mapping */
+/* bit 31 reserved */
+
+#define MMU_CFG_mskMMPS ( 0x3 << MMU_CFG_offMMPS )
+#define MMU_CFG_mskMMPV ( 0x1F << MMU_CFG_offMMPV )
+#define MMU_CFG_mskFATB ( 0x1 << MMU_CFG_offFATB )
+#ifdef CONFIG_FULL_ASSOC
+#define MMU_CFG_mskFATBSZ ( 0x7f << MMU_CFG_offFATBSZ )
+#else
+#define MMU_CFG_mskTBW ( 0x7 << MMU_CFG_offTBW )
+#define MMU_CFG_mskTBS ( 0x7 << MMU_CFG_offTBS )
+#endif
+#define MMU_CFG_mskEP8MIN4 ( 0x1 << MMU_CFG_offEP8MIN4 )
+#define MMU_CFG_mskfEPSZ ( 0xFF << MMU_CFG_offfEPSZ )
+#define MMU_CFG_mskTLBLCK ( 0x1 << MMU_CFG_offTLBLCK )
+#define MMU_CFG_mskHPTWK ( 0x1 << MMU_CFG_offHPTWK )
+#define MMU_CFG_mskDE ( 0x1 << MMU_CFG_offDE )
+#define MMU_CFG_mskNTPT ( 0x1 << MMU_CFG_offNTPT )
+#define MMU_CFG_mskIVTB ( 0x1 << MMU_CFG_offIVTB )
+#define MMU_CFG_mskVLPT ( 0x1 << MMU_CFG_offVLPT )
+#define MMU_CFG_mskNTME ( 0x1 << MMU_CFG_offNTME )
+
+/******************************************************************************
+ * cr4: MSC_CFG (Misc Configuration Register)
+ *****************************************************************************/
+#define MSC_CFG_offEDM 0
+#define MSC_CFG_offLMDMA 1
+#define MSC_CFG_offPFM 2
+#define MSC_CFG_offHSMP 3
+#define MSC_CFG_offTRACE 4
+#define MSC_CFG_offDIV 5
+#define MSC_CFG_offMAC 6
+#define MSC_CFG_offAUDIO 7
+#define MSC_CFG_offL2C 9
+#define MSC_CFG_offRDREG 10
+#define MSC_CFG_offADR24 11
+#define MSC_CFG_offINTLC 12
+#define MSC_CFG_offBASEV 13
+#define MSC_CFG_offNOD 16
+/* bit 13:31 reserved */
+
+#define MSC_CFG_mskEDM ( 0x1 << MSC_CFG_offEDM )
+#define MSC_CFG_mskLMDMA ( 0x1 << MSC_CFG_offLMDMA )
+#define MSC_CFG_mskPFM ( 0x1 << MSC_CFG_offPFM )
+#define MSC_CFG_mskHSMP ( 0x1 << MSC_CFG_offHSMP )
+#define MSC_CFG_mskTRACE ( 0x1 << MSC_CFG_offTRACE )
+#define MSC_CFG_mskDIV ( 0x1 << MSC_CFG_offDIV )
+#define MSC_CFG_mskMAC ( 0x1 << MSC_CFG_offMAC )
+#define MSC_CFG_mskAUDIO ( 0x3 << MSC_CFG_offAUDIO )
+#define MSC_CFG_mskL2C ( 0x1 << MSC_CFG_offL2C )
+#define MSC_CFG_mskRDREG ( 0x1 << MSC_CFG_offRDREG )
+#define MSC_CFG_mskADR24 ( 0x1 << MSC_CFG_offADR24 )
+#define MSC_CFG_mskINTLC ( 0x1 << MSC_CFG_offINTLC )
+#define MSC_CFG_mskBASEV ( 0x7 << MSC_CFG_offBASEV )
+#define MSC_CFG_mskNOD ( 0x1 << MSC_CFG_offNOD )
+
+/******************************************************************************
+ * cr5: CORE_CFG (Core Identification Register)
+ *****************************************************************************/
+#define CORE_ID_offCOREID 0
+/* bit 4:31 reserved */
+
+#define CORE_ID_mskCOREID ( 0xF << CORE_ID_offCOREID )
+
+/******************************************************************************
+ * cr6: FUCOP_EXIST (FPU and Coprocessor Existence Configuration Register)
+ *****************************************************************************/
+#define FUCOP_EXIST_offCP0EX 0
+#define FUCOP_EXIST_offCP1EX 1
+#define FUCOP_EXIST_offCP2EX 2
+#define FUCOP_EXIST_offCP3EX 3
+#define FUCOP_EXIST_offCP0ISFPU 31
+
+#define FUCOP_EXIST_mskCP0EX ( 0x1 << FUCOP_EXIST_offCP0EX )
+#define FUCOP_EXIST_mskCP1EX ( 0x1 << FUCOP_EXIST_offCP1EX )
+#define FUCOP_EXIST_mskCP2EX ( 0x1 << FUCOP_EXIST_offCP2EX )
+#define FUCOP_EXIST_mskCP3EX ( 0x1 << FUCOP_EXIST_offCP3EX )
+#define FUCOP_EXIST_mskCP0ISFPU ( 0x1 << FUCOP_EXIST_offCP0ISFPU )
+
+/******************************************************************************
+ * ir0: PSW (Processor Status Word Register)
+ * ir1: IPSW (Interruption PSW Register)
+ * ir2: P_IPSW (Previous IPSW Register)
+ *****************************************************************************/
+#define PSW_offGIE 0 /* Global Interrupt Enable */
+#define PSW_offINTL 1 /* Interruption Stack Level */
+#define PSW_offPOM 3 /* Processor Operation Mode, User/Superuser */
+#define PSW_offBE 5 /* Endianness for data memory access, 1:MSB, 0:LSB */
+#define PSW_offIT 6 /* Enable instruction address translation */
+#define PSW_offDT 7 /* Enable data address translation */
+#define PSW_offIME 8 /* Instruction Machine Error flag */
+#define PSW_offDME 9 /* Data Machine Error flag */
+#define PSW_offDEX 10 /* Debug Exception */
+#define PSW_offHSS 11 /* Hardware Single Stepping */
+#define PSW_offDRBE 12 /* Device Register Endian Mode */
+#define PSW_offAEN 13 /* Audio ISA special feature */
+#define PSW_offWBNA 14 /* Write Back Non-Allocate */
+#define PSW_offIFCON 15 /* IFC On */
+#define PSW_offCPL 16 /* Current Priority Level */
+/* bit 19:31 reserved */
+
+#define PSW_mskGIE ( 0x1 << PSW_offGIE )
+#define PSW_mskINTL ( 0x3 << PSW_offINTL )
+#define PSW_mskPOM ( 0x3 << PSW_offPOM )
+#define PSW_mskBE ( 0x1 << PSW_offBE )
+#define PSW_mskIT ( 0x1 << PSW_offIT )
+#define PSW_mskDT ( 0x1 << PSW_offDT )
+#define PSW_mskIME ( 0x1 << PSW_offIME )
+#define PSW_mskDME ( 0x1 << PSW_offDME )
+#define PSW_mskDEX ( 0x1 << PSW_offDEX )
+#define PSW_mskHSS ( 0x1 << PSW_offHSS )
+#define PSW_mskDRBE ( 0x1 << PSW_offDRBE )
+#define PSW_mskAEN ( 0x1 << PSW_offAEN )
+#define PSW_mskWBNA ( 0x1 << PSW_offWBNA )
+#define PSW_mskIFCON ( 0x1 << PSW_offIFCON )
+#define PSW_mskCPL ( 0x7 << PSW_offCPL )
+
+#define PSW_SYSTEM ( 1 << PSW_offPOM )
+#define PSW_INTL_1 ( 1 << PSW_offINTL )
+#define PSW_CPL_NO ( 0 << PSW_offCPL )
+#define PSW_CPL_ANY ( 7 << PSW_offCPL )
+/******************************************************************************
+ * ir3: IVB (Interruption Vector Base Register)
+ *****************************************************************************/
+/* bit 0:12 reserved */
+#define IVB_offNIVIC 1 /* Number of input for IVIC Controller */
+#define IVB_offIVIC_VER 11 /* IVIC Version */
+#define IVB_offEVIC 13 /* External Vector Interrupt Controller mode */
+#define IVB_offESZ 14 /* Size of each vector entry */
+#define IVB_offIVBASE 16 /* BasePA of interrupt vector table */
+
+#define IVB_mskNIVIC ( 0x7 << IVB_offNIVIC )
+#define IVB_mskIVIC_VER ( 0x3 << IVB_offIVIC_VER )
+#define IVB_mskEVIC ( 0x1 << IVB_offEVIC )
+#define IVB_mskESZ ( 0x3 << IVB_offESZ )
+#define IVB_mskIVBASE ( 0xFFFF << IVB_offIVBASE )
+
+/******************************************************************************
+ * ir4: EVA (Exception Virtual Address Register)
+ * ir5: P_EVA (Previous EVA Register)
+ *****************************************************************************/
+
+ /* This register contains the VA that causes the exception */
+
+/******************************************************************************
+ * ir6: ITYPE (Interruption Type Register)
+ * ir7: P_ITYPE (Previous ITYPE Register)
+ *****************************************************************************/
+#define ITYPE_offETYPE 0 /* Exception Type */
+#define ITYPE_offINST 4 /* Exception caused by insn fetch or data access */
+/* bit 5:15 reserved */
+#define ITYPE_offSWID 16 /* SWID of debugging exception */
+/* bit 31:31 reserved */
+
+#define ITYPE_mskETYPE ( 0xF << ITYPE_offETYPE )
+#define ITYPE_mskINST ( 0x1 << ITYPE_offINST )
+#define ITYPE_mskSWID ( 0x7FFF << ITYPE_offSWID )
+
+/* Additional definitions for ITYPE register */
+#define ITYPE_offSTYPE 16 /* Arithmetic Sub Type */
+#define ITYPE_offCPID 20 /* Co-Processor ID which generate the exception */
+
+#define ITYPE_mskSTYPE ( 0xF << ITYPE_offSTYPE )
+#define ITYPE_mskCPID ( 0x3 << ITYPE_offCPID )
+
+/******************************************************************************
+ * ir8: MERR (Machine Error Log Register)
+ *****************************************************************************/
+/* bit 0:30 reserved */
+#define MERR_offBUSERR 31 /* Bus error caused by a load insn */
+
+#define MERR_mskBUSERR ( 0x1 << MERR_offBUSERR )
+
+/******************************************************************************
+ * ir9: IPC (Interruption Program Counter Register)
+ * ir10: P_IPC (Previous IPC Register)
+ * ir11: OIPC (Overflow Interruption Program Counter Register)
+ *****************************************************************************/
+
+ /* This is the shadow stack register of the Program Counter */
+
+/******************************************************************************
+ * ir12: P_P0 (Previous P0 Register)
+ * ir13: P_P1 (Previous P1 Register)
+ *****************************************************************************/
+
+ /* These are shadow registers of $p0 and $p1 */
+
+/******************************************************************************
+ * ir14: INT_MASK (Interruption Masking Register)
+ *****************************************************************************/
+#define INT_MASK_offH0IM 0 /* Hardware Interrupt 0 Mask bit */
+#define INT_MASK_offH1IM 1 /* Hardware Interrupt 1 Mask bit */
+#define INT_MASK_offH2IM 2 /* Hardware Interrupt 2 Mask bit */
+#define INT_MASK_offH3IM 3 /* Hardware Interrupt 3 Mask bit */
+#define INT_MASK_offH4IM 4 /* Hardware Interrupt 4 Mask bit */
+#define INT_MASK_offH5IM 5 /* Hardware Interrupt 5 Mask bit */
+/* bit 6:15 reserved */
+#define INT_MASK_offSIM 16 /* Software Interrupt Mask bit */
+/* bit 17:29 reserved */
+#define INT_MASK_offIDIVZE 30 /* Enable detection for Divide-By-Zero */
+#define INT_MASK_offDSSIM 31 /* Default Single Stepping Interruption Mask */
+
+#define INT_MASK_mskH0IM ( 0x1 << INT_MASK_offH0IM )
+#define INT_MASK_mskH1IM ( 0x1 << INT_MASK_offH1IM )
+#define INT_MASK_mskH2IM ( 0x1 << INT_MASK_offH2IM )
+#define INT_MASK_mskH3IM ( 0x1 << INT_MASK_offH3IM )
+#define INT_MASK_mskH4IM ( 0x1 << INT_MASK_offH4IM )
+#define INT_MASK_mskH5IM ( 0x1 << INT_MASK_offH5IM )
+#define INT_MASK_mskSIM ( 0x1 << INT_MASK_offSIM )
+#define INT_MASK_mskIDIVZE ( 0x1 << INT_MASK_offIDIVZE )
+#define INT_MASK_mskDSSIM ( 0x1 << INT_MASK_offDSSIM )
+
+/******************************************************************************
+ * ir15: INT_PEND (Interrupt Pending Register)
+ *****************************************************************************/
+#define INT_PEND_offH0I 0 /* Hardware Interrupt 0 pending bit */
+#define INT_PEND_offH1I 1 /* Hardware Interrupt 1 pending bit */
+#define INT_PEND_offH2I 2 /* Hardware Interrupt 2 pending bit */
+#define INT_PEND_offH3I 3 /* Hardware Interrupt 3 pending bit */
+#define INT_PEND_offH4I 4 /* Hardware Interrupt 4 pending bit */
+#define INT_PEND_offH5I 5 /* Hardware Interrupt 5 pending bit */
+
+#define INT_PEND_offCIPL 0 /* Current Interrupt Priority Level */
+
+/* bit 6:15 reserved */
+#define INT_PEND_offSWI 16 /* Software Interrupt pending bit */
+/* bit 17:31 reserved */
+
+#define INT_PEND_mskH0I ( 0x1 << INT_PEND_offH0I )
+#define INT_PEND_mskH1I ( 0x1 << INT_PEND_offH1I )
+#define INT_PEND_mskH2I ( 0x1 << INT_PEND_offH2I )
+#define INT_PEND_mskH3I ( 0x1 << INT_PEND_offH3I )
+#define INT_PEND_mskH4I ( 0x1 << INT_PEND_offH4I )
+#define INT_PEND_mskH5I ( 0x1 << INT_PEND_offH5I )
+#define INT_PEND_mskCIPL ( 0x1 << INT_PEND_offCIPL )
+#define INT_PEND_mskSWI ( 0x1 << INT_PEND_offSWI )
+
+/******************************************************************************
+ * mr0: MMU_CTL (MMU Control Register)
+ *****************************************************************************/
+#define MMU_CTL_offD 0 /* Default minimum page size */
+#define MMU_CTL_offNTC0 1 /* Non-Translated Cachebility of partition 0 */
+#define MMU_CTL_offNTC1 3 /* Non-Translated Cachebility of partition 1 */
+#define MMU_CTL_offNTC2 5 /* Non-Translated Cachebility of partition 2 */
+#define MMU_CTL_offNTC3 7 /* Non-Translated Cachebility of partition 3 */
+#define MMU_CTL_offTBALCK 9 /* TLB all-lock resolution scheme */
+#define MMU_CTL_offMPZIU 10 /* Multiple Page Size In Use bit */
+#define MMU_CTL_offNTM0 11 /* Non-Translated VA to PA of partition 0 */
+#define MMU_CTL_offNTM1 13 /* Non-Translated VA to PA of partition 1 */
+#define MMU_CTL_offNTM2 15 /* Non-Translated VA to PA of partition 2 */
+#define MMU_CTL_offNTM3 17 /* Non-Translated VA to PA of partition 3 */
+/* bit 19:31 reserved */
+
+#define MMU_CTL_mskD ( 0x1 << MMU_CTL_offD )
+#define MMU_CTL_mskNTC0 ( 0x3 << MMU_CTL_offNTC0 )
+#define MMU_CTL_mskNTC1 ( 0x3 << MMU_CTL_offNTC1 )
+#define MMU_CTL_mskNTC2 ( 0x3 << MMU_CTL_offNTC2 )
+#define MMU_CTL_mskNTC3 ( 0x3 << MMU_CTL_offNTC3 )
+#define MMU_CTL_mskTBALCK ( 0x1 << MMU_CTL_offTBALCK )
+#define MMU_CTL_mskMPZIU ( 0x1 << MMU_CTL_offMPZIU )
+#define MMU_CTL_mskNTM0 ( 0x3 << MMU_CTL_offNTM0 )
+#define MMU_CTL_mskNTM1 ( 0x3 << MMU_CTL_offNTM1 )
+#define MMU_CTL_mskNTM2 ( 0x3 << MMU_CTL_offNTM2 )
+#define MMU_CTL_mskNTM3 ( 0x3 << MMU_CTL_offNTM3 )
+
+/******************************************************************************
+ * mr1: L1_PPTB (L1 Physical Page Table Base Register)
+ *****************************************************************************/
+#define L1_PPTB_offNV 0 /* Enable Hardware Page Table Walker (HPTWK) */
+/* bit 1:11 reserved */
+#define L1_PPTB_offBASE 12 /* First level physical page table base address */
+
+#define L1_PPTB_mskNV ( 0x1 << L1_PPTB_offNV )
+#define L1_PPTB_mskBASE ( 0xFFFFF << L1_PPTB_offBASE )
+
+/******************************************************************************
+ * mr2: TLB_VPN (TLB Access VPN Register)
+ *****************************************************************************/
+/* bit 0:11 reserved */
+#define TLB_VPN_offVPN 12 /* Virtual Page Number */
+
+#define TLB_VPN_mskVPN ( 0xFFFFF << TLB_VPN_offVPN )
+
+/******************************************************************************
+ * mr3: TLB_DATA (TLB Access Data Register)
+ *****************************************************************************/
+#define TLB_DATA_offV 0 /* PTE is valid and present */
+#define TLB_DATA_offM 1 /* Page read/write access privilege */
+#define TLB_DATA_offD 4 /* Dirty bit */
+#define TLB_DATA_offX 5 /* Executable bit */
+#define TLB_DATA_offA 6 /* Access bit */
+#define TLB_DATA_offG 7 /* Global page (shared across contexts) */
+#define TLB_DATA_offC 8 /* Cacheability atribute */
+/* bit 11:11 reserved */
+#define TLB_DATA_offPPN 12 /* Phisical Page Number */
+
+#define TLB_DATA_mskV ( 0x1 << TLB_DATA_offV )
+#define TLB_DATA_mskM ( 0x7 << TLB_DATA_offM )
+#define TLB_DATA_mskD ( 0x1 << TLB_DATA_offD )
+#define TLB_DATA_mskX ( 0x1 << TLB_DATA_offX )
+#define TLB_DATA_mskA ( 0x1 << TLB_DATA_offA )
+#define TLB_DATA_mskG ( 0x1 << TLB_DATA_offG )
+#define TLB_DATA_mskC ( 0x7 << TLB_DATA_offC )
+#define TLB_DATA_mskPPN ( 0xFFFFF << TLB_DATA_offPPN )
+
+/******************************************************************************
+ * mr4: TLB_MISC (TLB Access Misc Register)
+ *****************************************************************************/
+#define TLB_MISC_offACC_PSZ 0 /* Page size of a PTE entry */
+#define TLB_MISC_offCID 4 /* Context id */
+/* bit 13:31 reserved */
+
+#define TLB_MISC_mskACC_PSZ ( 0xF << TLB_MISC_offACC_PSZ )
+#define TLB_MISC_mskCID ( 0x1FF << TLB_MISC_offCID )
+
+/******************************************************************************
+ * mr5: VLPT_IDX (Virtual Linear Page Table Index Register)
+ *****************************************************************************/
+#define VLPT_IDX_offZERO 0 /* Always 0 */
+#define VLPT_IDX_offEVPN 2 /* Exception Virtual Page Number */
+#define VLPT_IDX_offVLPTB 22 /* Base VA of VLPT */
+
+#define VLPT_IDX_mskZERO ( 0x3 << VLPT_IDX_offZERO )
+#define VLPT_IDX_mskEVPN ( 0xFFFFF << VLPT_IDX_offEVPN )
+#define VLPT_IDX_mskVLPTB ( 0x3FF << VLPT_IDX_offVLPTB )
+
+/******************************************************************************
+ * mr6: ILMB (Instruction Local Memory Base Register)
+ *****************************************************************************/
+#define ILMB_offIEN 0 /* Enable ILM */
+#define ILMB_offILMSZ 1 /* Size of ILM */
+/* bit 5:19 reserved */
+#define ILMB_offIBPA 20 /* Base PA of ILM */
+
+#define ILMB_mskIEN ( 0x1 << ILMB_offIEN )
+#define ILMB_mskILMSZ ( 0xF << ILMB_offILMSZ )
+#define ILMB_mskIBPA ( 0xFFF << ILMB_offIBPA )
+
+/******************************************************************************
+ * mr7: DLMB (Data Local Memory Base Register)
+ *****************************************************************************/
+#define DLMB_offDEN 0 /* Enable DLM */
+#define DLMB_offDLMSZ 1 /* Size of DLM */
+#define DLMB_offDBM 5 /* Enable Double-Buffer Mode for DLM */
+#define DLMB_offDBB 6 /* Double-buffer bank which can be accessed by the processor */
+/* bit 7:19 reserved */
+#define DLMB_offDBPA 20 /* Base PA of DLM */
+
+#define DLMB_mskDEN ( 0x1 << DLMB_offDEN )
+#define DLMB_mskDLMSZ ( 0xF << DLMB_offDLMSZ )
+#define DLMB_mskDBM ( 0x1 << DLMB_offDBM )
+#define DLMB_mskDBB ( 0x1 << DLMB_offDBB )
+#define DLMB_mskDBPA ( 0xFFF << DLMB_offDBPA )
+
+/******************************************************************************
+ * mr8: CACHE_CTL (Cache Control Register)
+ *****************************************************************************/
+#define CACHE_CTL_offIC_EN 0 /* Enable I-cache */
+#define CACHE_CTL_offDC_EN 1 /* Enable D-cache */
+#define CACHE_CTL_offICALCK 2 /* I-cache all-lock resolution scheme */
+#define CACHE_CTL_offDCALCK 3 /* D-cache all-lock resolution scheme */
+#define CACHE_CTL_offDCCWF 4 /* Enable D-cache Critical Word Forwarding */
+#define CACHE_CTL_offDCPMW 5 /* Enable D-cache concurrent miss and write-back processing */
+/* bit 6:31 reserved */
+
+#define CACHE_CTL_mskIC_EN ( 0x1 << CACHE_CTL_offIC_EN )
+#define CACHE_CTL_mskDC_EN ( 0x1 << CACHE_CTL_offDC_EN )
+#define CACHE_CTL_mskICALCK ( 0x1 << CACHE_CTL_offICALCK )
+#define CACHE_CTL_mskDCALCK ( 0x1 << CACHE_CTL_offDCALCK )
+#define CACHE_CTL_mskDCCWF ( 0x1 << CACHE_CTL_offDCCWF )
+#define CACHE_CTL_mskDCPMW ( 0x1 << CACHE_CTL_offDCPMW )
+
+/******************************************************************************
+ * mr9: HSMP_SADDR (High Speed Memory Port Starting Address)
+ *****************************************************************************/
+#define HSMP_SADDR_offEN 0 /* Enable control bit for the High Speed Memory port */
+/* bit 1:19 reserved */
+
+#define HSMP_SADDR_offRANGE 1 /* Denote the address range (only defined in HSMP v2 ) */
+#define HSMP_SADDR_offSADDR 20 /* Starting base PA of the High Speed Memory Port region */
+
+#define HSMP_SADDR_mskEN ( 0x1 << HSMP_SADDR_offEN )
+#define HSMP_SADDR_mskRANGE ( 0xFFF << HSMP_SADDR_offRANGE )
+#define HSMP_SADDR_mskSADDR ( 0xFFF << HSMP_SADDR_offSADDR )
+
+/******************************************************************************
+ * mr10: HSMP_EADDR (High Speed Memory Port Ending Address)
+ *****************************************************************************/
+/* bit 0:19 reserved */
+#define HSMP_EADDR_offEADDR 20
+
+#define HSMP_EADDR_mskEADDR ( 0xFFF << HSMP_EADDR_offEADDR )
+
+/******************************************************************************
+ * dr0+(n*5): BPCn (n=0-7) (Breakpoint Control Register)
+ *****************************************************************************/
+#define BPC_offWP 0 /* Configuration of BPAn */
+#define BPC_offEL 1 /* Enable BPAn */
+#define BPC_offS 2 /* Data address comparison for a store instruction */
+#define BPC_offP 3 /* Compared data address is PA */
+#define BPC_offC 4 /* CID value is compared with the BPCIDn register */
+#define BPC_offBE0 5 /* Enable byte mask for the comparison with register */
+#define BPC_offBE1 6 /* Enable byte mask for the comparison with register */
+#define BPC_offBE2 7 /* Enable byte mask for the comparison with register */
+#define BPC_offBE3 8 /* Enable byte mask for the comparison with register */
+#define BPC_offT 9 /* Enable breakpoint Embedded Tracer triggering operation */
+
+#define BPC_mskWP ( 0x1 << BPC_offWP )
+#define BPC_mskEL ( 0x1 << BPC_offEL )
+#define BPC_mskS ( 0x1 << BPC_offS )
+#define BPC_mskP ( 0x1 << BPC_offP )
+#define BPC_mskC ( 0x1 << BPC_offC )
+#define BPC_mskBE0 ( 0x1 << BPC_offBE0 )
+#define BPC_mskBE1 ( 0x1 << BPC_offBE1 )
+#define BPC_mskBE2 ( 0x1 << BPC_offBE2 )
+#define BPC_mskBE3 ( 0x1 << BPC_offBE3 )
+#define BPC_mskT ( 0x1 << BPC_offT )
+
+/******************************************************************************
+ * dr1+(n*5): BPAn (n=0-7) (Breakpoint Address Register)
+ *****************************************************************************/
+
+ /* These registers contain break point address */
+
+/******************************************************************************
+ * dr2+(n*5): BPAMn (n=0-7) (Breakpoint Address Mask Register)
+ *****************************************************************************/
+
+ /* These registerd contain the address comparison mask for the BPAn register */
+
+/******************************************************************************
+ * dr3+(n*5): BPVn (n=0-7) Breakpoint Data Value Register
+ *****************************************************************************/
+
+ /* The BPVn register contains the data value that will be compared with the
+ * incoming load/store data value */
+
+/******************************************************************************
+ * dr4+(n*5): BPCIDn (n=0-7) (Breakpoint Context ID Register)
+ *****************************************************************************/
+#define BPCID_offCID 0 /* CID that will be compared with a process's CID */
+/* bit 9:31 reserved */
+
+#define BPCID_mskCID ( 0x1FF << BPCID_offCID )
+
+/******************************************************************************
+ * dr40: EDM_CFG (EDM Configuration Register)
+ *****************************************************************************/
+#define EDM_CFG_offBC 0 /* Number of hardware breakpoint sets implemented */
+#define EDM_CFG_offDIMU 3 /* Debug Instruction Memory Unit exists */
+/* bit 4:15 reserved */
+#define EDM_CFG_offVER 16 /* EDM version */
+
+#define EDM_CFG_mskBC ( 0x7 << EDM_CFG_offBC )
+#define EDM_CFG_mskDIMU ( 0x1 << EDM_CFG_offDIMU )
+#define EDM_CFG_mskVER ( 0xFFFF << EDM_CFG_offVER )
+
+/******************************************************************************
+ * dr41: EDMSW (EDM Status Word)
+ *****************************************************************************/
+#define EDMSW_offWV 0 /* Write Valid */
+#define EDMSW_offRV 1 /* Read Valid */
+#define EDMSW_offDE 2 /* Debug exception has occurred for this core */
+/* bit 3:31 reserved */
+
+#define EDMSW_mskWV ( 0x1 << EDMSW_offWV )
+#define EDMSW_mskRV ( 0x1 << EDMSW_offRV )
+#define EDMSW_mskDE ( 0x1 << EDMSW_offDE )
+
+/******************************************************************************
+ * dr42: EDM_CTL (EDM Control Register)
+ *****************************************************************************/
+/* bit 0:30 reserved */
+#define EDM_CTL_offV3_EDM_MODE 6 /* EDM compatibility control bit */
+#define EDM_CTL_offDEH_SEL 31 /* Controls where debug exception is directed to */
+
+#define EDM_CTL_mskV3_EDM_MODE ( 0x1 << EDM_CTL_offV3_EDM_MODE )
+#define EDM_CTL_mskDEH_SEL ( 0x1 << EDM_CTL_offDEH_SEL )
+
+/******************************************************************************
+ * dr43: EDM_DTR (EDM Data Transfer Register)
+ *****************************************************************************/
+
+ /* This is used to exchange data between the embedded EDM logic
+ * and the processor core */
+
+/******************************************************************************
+ * dr44: BPMTC (Breakpoint Match Trigger Counter Register)
+ *****************************************************************************/
+#define BPMTC_offBPMTC 0 /* Breakpoint match trigger counter value */
+/* bit 16:31 reserved */
+
+#define BPMTC_mskBPMTC ( 0xFFFF << BPMTC_offBPMTC )
+
+/******************************************************************************
+ * dr45: DIMBR (Debug Instruction Memory Base Register)
+ *****************************************************************************/
+/* bit 0:11 reserved */
+#define DIMBR_offDIMB 12 /* Base address of the Debug Instruction Memory (DIM) */
+#define DIMBR_mskDIMB ( 0xFFFFF << DIMBR_offDIMB )
+
+/******************************************************************************
+ * dr46: TECR0(Trigger Event Control register 0)
+ * dr47: TECR1 (Trigger Event Control register 1)
+ *****************************************************************************/
+#define TECR_offBP 0 /* Controld which BP is used as a trigger source */
+#define TECR_offNMI 8 /* Use NMI as a trigger source */
+#define TECR_offHWINT 9 /* Corresponding interrupt is used as a trigger source */
+#define TECR_offEVIC 15 /* Enable HWINT as a trigger source in EVIC mode */
+#define TECR_offSYS 16 /* Enable SYSCALL instruction as a trigger source */
+#define TECR_offDBG 17 /* Enable debug exception as a trigger source */
+#define TECR_offMRE 18 /* Enable MMU related exception as a trigger source */
+#define TECR_offE 19 /* An exception is used as a trigger source */
+/* bit 20:30 reserved */
+#define TECR_offL 31 /* Link/Cascade TECR0 trigger event to TECR1 trigger event */
+
+#define TECR_mskBP ( 0xFF << TECR_offBP )
+#define TECR_mskNMI ( 0x1 << TECR_offBNMI )
+#define TECR_mskHWINT ( 0x3F << TECR_offBHWINT )
+#define TECR_mskEVIC ( 0x1 << TECR_offBEVIC )
+#define TECR_mskSYS ( 0x1 << TECR_offBSYS )
+#define TECR_mskDBG ( 0x1 << TECR_offBDBG )
+#define TECR_mskMRE ( 0x1 << TECR_offBMRE )
+#define TECR_mskE ( 0x1 << TECR_offE )
+#define TECR_mskL ( 0x1 << TECR_offL )
+
+/******************************************************************************
+ * pfr0-2: PFMC0-2 (Performance Counter Register 0-2)
+ *****************************************************************************/
+
+ /* These registers contains performance event count */
+
+/******************************************************************************
+ * pfr3: PFM_CTL (Performance Counter Control Register)
+ *****************************************************************************/
+#define PFM_CTL_offEN0 0 /* Enable PFMC0 */
+#define PFM_CTL_offEN1 1 /* Enable PFMC1 */
+#define PFM_CTL_offEN2 2 /* Enable PFMC2 */
+#define PFM_CTL_offIE0 3 /* Enable interrupt for PFMC0 */
+#define PFM_CTL_offIE1 4 /* Enable interrupt for PFMC1 */
+#define PFM_CTL_offIE2 5 /* Enable interrupt for PFMC2 */
+#define PFM_CTL_offOVF0 6 /* Overflow bit of PFMC0 */
+#define PFM_CTL_offOVF1 7 /* Overflow bit of PFMC1 */
+#define PFM_CTL_offOVF2 8 /* Overflow bit of PFMC2 */
+#define PFM_CTL_offKS0 9 /* Enable superuser mode event counting for PFMC0 */
+#define PFM_CTL_offKS1 10 /* Enable superuser mode event counting for PFMC1 */
+#define PFM_CTL_offKS2 11 /* Enable superuser mode event counting for PFMC2 */
+#define PFM_CTL_offKU0 12 /* Enable user mode event counting for PFMC0 */
+#define PFM_CTL_offKU1 13 /* Enable user mode event counting for PFMC1 */
+#define PFM_CTL_offKU2 14 /* Enable user mode event counting for PFMC2 */
+#define PFM_CTL_offSEL0 15 /* The event selection for PFMC0 */
+#define PFM_CTL_offSEL1 21 /* The event selection for PFMC1 */
+#define PFM_CTL_offSEL2 27 /* The event selection for PFMC2 */
+/* bit 28:31 reserved */
+
+#define PFM_CTL_mskEN0 ( 0x01 << PFM_CTL_offEN0 )
+#define PFM_CTL_mskEN1 ( 0x01 << PFM_CTL_offEN1 )
+#define PFM_CTL_mskEN2 ( 0x01 << PFM_CTL_offEN2 )
+#define PFM_CTL_mskIE0 ( 0x01 << PFM_CTL_offIE0 )
+#define PFM_CTL_mskIE1 ( 0x01 << PFM_CTL_offIE1 )
+#define PFM_CTL_mskIE2 ( 0x01 << PFM_CTL_offIE2 )
+#define PFM_CTL_mskOVF0 ( 0x01 << PFM_CTL_offOVF0 )
+#define PFM_CTL_mskOVF1 ( 0x01 << PFM_CTL_offOVF1 )
+#define PFM_CTL_mskOVF2 ( 0x01 << PFM_CTL_offOVF2 )
+#define PFM_CTL_mskKS0 ( 0x01 << PFM_CTL_offKS0 )
+#define PFM_CTL_mskKS1 ( 0x01 << PFM_CTL_offKS1 )
+#define PFM_CTL_mskKS2 ( 0x01 << PFM_CTL_offKS2 )
+#define PFM_CTL_mskKU0 ( 0x01 << PFM_CTL_offKU0 )
+#define PFM_CTL_mskKU1 ( 0x01 << PFM_CTL_offKU1 )
+#define PFM_CTL_mskKU2 ( 0x01 << PFM_CTL_offKU2 )
+#define PFM_CTL_mskSEL0 ( 0x01 << PFM_CTL_offSEL0 )
+#define PFM_CTL_mskSEL1 ( 0x3F << PFM_CTL_offSEL1 )
+#define PFM_CTL_mskSEL2 ( 0x3F << PFM_CTL_offSEL2 )
+
+/******************************************************************************
+ * SDZ_CTL (Structure Downsizing Control Register)
+ *****************************************************************************/
+#define SDZ_CTL_offICDZ 0 /* I-cache downsizing control */
+#define SDZ_CTL_offDCDZ 3 /* D-cache downsizing control */
+#define SDZ_CTL_offMTBDZ 6 /* MTLB downsizing control */
+#define SDZ_CTL_offBTBDZ 9 /* Branch Target Table downsizing control */
+/* bit 12:31 reserved */
+#define SDZ_CTL_mskICDZ ( 0x07 << SDZ_CTL_offICDZ )
+#define SDZ_CTL_mskDCDZ ( 0x07 << SDZ_CTL_offDCDZ )
+#define SDZ_CTL_mskMTBDZ ( 0x07 << SDZ_CTL_offMTBDZ )
+#define SDZ_CTL_mskBTBDZ ( 0x07 << SDZ_CTL_offBTBDZ )
+
+/******************************************************************************
+ * N12MISC_CTL (N12 Miscellaneous Control Register)
+ *****************************************************************************/
+#define N12MISC_CTL_offBTB 0 /* Disable Branch Target Buffer */
+#define N12MISC_CTL_offRTP 1 /* Disable Return Target Predictor */
+#define N12MISC_CTL_offPTEPF 2 /* Disable HPTWK L2 PTE pefetch */
+/* bit 3:31 reserved */
+
+#define N12MISC_CTL_makBTB ( 0x1 << N12MISC_CTL_offBTB )
+#define N12MISC_CTL_makRTP ( 0x1 << N12MISC_CTL_offRTP )
+#define N12MISC_CTL_makPTEPF ( 0x1 << N12MISC_CTL_offPTEPF )
+
+/******************************************************************************
+ * PRUSR_ACC_CTL (Privileged Resource User Access Control Registers)
+ *****************************************************************************/
+#define PRUSR_ACC_CTL_offDMA_EN 0 /* Allow user mode access of DMA registers */
+#define PRUSR_ACC_CTL_offPFM_EN 1 /* Allow user mode access of PFM registers */
+
+#define PRUSR_ACC_CTL_mskDMA_EN ( 0x1 << PRUSR_ACC_CTL_offDMA_EN )
+#define PRUSR_ACC_CTL_mskPFM_EN ( 0x1 << PRUSR_ACC_CTL_offPFM_EN )
+
+/******************************************************************************
+ * dmar0: DMA_CFG (DMA Configuration Register)
+ *****************************************************************************/
+#define DMA_CFG_offNCHN 0 /* The number of DMA channels implemented */
+#define DMA_CFG_offUNEA 2 /* Un-aligned External Address transfer feature */
+#define DMA_CFG_off2DET 3 /* 2-D Element Transfer feature */
+/* bit 4:15 reserved */
+#define DMA_CFG_offVER 16 /* DMA architecture and implementation version */
+
+#define DMA_CFG_mskNCHN ( 0x3 << DMA_CFG_offNCHN )
+#define DMA_CFG_mskUNEA ( 0x1 << DMA_CFG_offUNEA )
+#define DMA_CFG_msk2DET ( 0x1 << DMA_CFG_off2DET )
+#define DMA_CFG_mskVER ( 0xFFFF << DMA_CFG_offVER )
+
+/******************************************************************************
+ * dmar1: DMA_GCSW (DMA Global Control and Status Word Register)
+ *****************************************************************************/
+#define DMA_GCSW_offC0STAT 0 /* DMA channel 0 state */
+#define DMA_GCSW_offC1STAT 3 /* DMA channel 1 state */
+/* bit 6:11 reserved */
+#define DMA_GCSW_offC0INT 12 /* DMA channel 0 generate interrupt */
+#define DMA_GCSW_offC1INT 13 /* DMA channel 1 generate interrupt */
+/* bit 14:30 reserved */
+#define DMA_GCSW_offEN 31 /* Enable DMA engine */
+
+#define DMA_GCSW_mskC0STAT ( 0x7 << DMA_GCSW_offC0STAT )
+#define DMA_GCSW_mskC1STAT ( 0x7 << DMA_GCSW_offC1STAT )
+#define DMA_GCSW_mskC0INT ( 0x1 << DMA_GCSW_offC0INT )
+#define DMA_GCSW_mskC1INT ( 0x1 << DMA_GCSW_offC1INT )
+#define DMA_GCSW_mskEN ( 0x1 << DMA_GCSW_offEN )
+
+/******************************************************************************
+ * dmar2: DMA_CHNSEL (DMA Channel Selection Register)
+ *****************************************************************************/
+#define DMA_CHNSEL_offCHAN 0 /* Selected channel number */
+/* bit 2:31 reserved */
+
+#define DMA_CHNSEL_mskCHAN ( 0x3 << DMA_CHNSEL_offCHAN )
+
+/******************************************************************************
+ * dmar3: DMA_ACT (DMA Action Register)
+ *****************************************************************************/
+#define DMA_ACT_offACMD 0 /* DMA Action Command */
+/* bit 2:31 reserved */
+#define DMA_ACT_mskACMD ( 0x3 << DMA_ACT_offACMD )
+
+/******************************************************************************
+ * dmar4: DMA_SETUP (DMA Setup Register)
+ *****************************************************************************/
+#define DMA_SETUP_offLM 0 /* Local Memory Selection */
+#define DMA_SETUP_offTDIR 1 /* Transfer Direction */
+#define DMA_SETUP_offTES 2 /* Transfer Element Size */
+#define DMA_SETUP_offESTR 4 /* External memory transfer Stride */
+#define DMA_SETUP_offCIE 16 /* Interrupt Enable on Completion */
+#define DMA_SETUP_offSIE 17 /* Interrupt Enable on explicit Stop */
+#define DMA_SETUP_offEIE 18 /* Interrupt Enable on Error */
+#define DMA_SETUP_offUE 19 /* Enable the Un-aligned External Address */
+#define DMA_SETUP_off2DE 20 /* Enable the 2-D External Transfer */
+#define DMA_SETUP_offCOA 21 /* Transfer Coalescable */
+/* bit 22:31 reserved */
+
+#define DMA_SETUP_mskLM ( 0x1 << DMA_SETUP_offLM )
+#define DMA_SETUP_mskTDIR ( 0x1 << DMA_SETUP_offTDIR )
+#define DMA_SETUP_mskTES ( 0x3 << DMA_SETUP_offTES )
+#define DMA_SETUP_mskESTR ( 0xFFF << DMA_SETUP_offESTR )
+#define DMA_SETUP_mskCIE ( 0x1 << DMA_SETUP_offCIE )
+#define DMA_SETUP_mskSIE ( 0x1 << DMA_SETUP_offSIE )
+#define DMA_SETUP_mskEIE ( 0x1 << DMA_SETUP_offEIE )
+#define DMA_SETUP_mskUE ( 0x1 << DMA_SETUP_offUE )
+#define DMA_SETUP_msk2DE ( 0x1 << DMA_SETUP_off2DE )
+#define DMA_SETUP_mskCOA ( 0x1 << DMA_SETUP_offCOA )
+
+/******************************************************************************
+ * dmar5: DMA_ISADDR (DMA Internal Start Address Register)
+ *****************************************************************************/
+#define DMA_ISADDR_offISADDR 0 /* Internal Start Address */
+/* bit 20:31 reserved */
+#define DMA_ISADDR_mskISADDR ( 0xFFFFF << DMA_ISADDR_offISADDR )
+
+/******************************************************************************
+ * dmar6: DMA_ESADDR (DMA External Start Address Register)
+ *****************************************************************************/
+/* This register holds External Start Address */
+
+/******************************************************************************
+ * dmar7: DMA_TCNT (DMA Transfer Element Count Register)
+ *****************************************************************************/
+#define DMA_TCNT_offTCNT 0 /* DMA transfer element count */
+/* bit 18:31 reserved */
+#define DMA_TCNT_mskTCNT ( 0x3FFFF << DMA_TCNT_offTCNT )
+
+/******************************************************************************
+ * dmar8: DMA_STATUS (DMA Status Register)
+ *****************************************************************************/
+#define DMA_STATUS_offSTAT 0 /* DMA channel state */
+#define DMA_STATUS_offSTUNA 3 /* Un-aligned error on External Stride value */
+#define DMA_STATUS_offDERR 4 /* DMA Transfer Disruption Error */
+#define DMA_STATUS_offEUNA 5 /* Un-aligned error on the External address */
+#define DMA_STATUS_offIUNA 6 /* Un-aligned error on the Internal address */
+#define DMA_STATUS_offIOOR 7 /* Out-Of-Range error on the Internal address */
+#define DMA_STATUS_offEBUS 8 /* Bus Error on an External DMA transfer */
+#define DMA_STATUS_offESUP 9 /* DMA setup error */
+/* bit 10:31 reserved */
+
+#define DMA_STATUS_mskSTAT ( 0x7 << DMA_STATUS_offSTAT )
+#define DMA_STATUS_mskSTUNA ( 0x1 << DMDMA_STATUS_offSTUNA )
+#define DMA_STATUS_mskDERR ( 0x1 << DMDMA_STATUS_offDERR )
+#define DMA_STATUS_mskEUNA ( 0x1 << DMDMA_STATUS_offEUNA )
+#define DMA_STATUS_mskIUNA ( 0x1 << DMDMA_STATUS_offIUNA )
+#define DMA_STATUS_mskIOOR ( 0x1 << DMDMA_STATUS_offIOOR )
+#define DMA_STATUS_mskEBUS ( 0x1 << DMDMA_STATUS_offEBUS )
+#define DMA_STATUS_mskESUP ( 0x1 << DMDMA_STATUS_offESUP )
+
+/******************************************************************************
+ * dmar9: DMA_2DSET (DMA 2D Setup Register)
+ *****************************************************************************/
+#define DMA_2DSET_offWECNT 0 /* The Width Element Count for a 2-D region */
+#define DMA_2DSET_offHTSTR 16 /* The Height Stride for a 2-D region */
+
+#define DMA_2DSET_mskHTSTR ( 0xFFFF << DMA_2DSET_offHTSTR )
+#define DMA_2DSET_mskWECNT ( 0xFFFF << DMA_2DSET_offWECNT )
+
+/******************************************************************************
+ * dmar10: DMA_2DSCTL (DMA 2D Startup Control Register)
+ *****************************************************************************/
+#define DMA_2DSCTL_offSTWECNT 0 /* Startup Width Element Count for a 2-D region */
+/* bit 16:31 reserved */
+
+#define DMA_2DSCTL_mskSTWECNT ( 0xFFFF << DMA_2DSCTL_offSTWECNT )
+
+/******************************************************************************
+ * fpcsr: FPCSR (Floating-Point Control Status Register)
+ *****************************************************************************/
+#define FPCSR_offRM 0
+#define FPCSR_offIVO 2
+#define FPCSR_offDBZ 3
+#define FPCSR_offOVF 4
+#define FPCSR_offUDF 5
+#define FPCSR_offIEX 6
+#define FPCSR_offIVOE 7
+#define FPCSR_offDBZE 8
+#define FPCSR_offOVFE 9
+#define FPCSR_offUDFE 10
+#define FPCSR_offIEXE 11
+#define FPCSR_offDNZ 12
+#define FPCSR_offIVOT 13
+#define FPCSR_offDBZT 14
+#define FPCSR_offOVFT 15
+#define FPCSR_offUDFT 16
+#define FPCSR_offIEXT 17
+#define FPCSR_offDNIT 18
+#define FPCSR_offRIT 19
+
+#define FPCSR_mskRM ( 0x3 << FPCSR_offRM )
+#define FPCSR_mskIVO ( 0x1 << FPCSR_offIVO )
+#define FPCSR_mskDBZ ( 0x1 << FPCSR_offDBZ )
+#define FPCSR_mskOVF ( 0x1 << FPCSR_offOVF )
+#define FPCSR_mskUDF ( 0x1 << FPCSR_offUDF )
+#define FPCSR_mskIEX ( 0x1 << FPCSR_offIEX )
+#define FPCSR_mskIVOE ( 0x1 << FPCSR_offIVOE )
+#define FPCSR_mskDBZE ( 0x1 << FPCSR_offDBZE )
+#define FPCSR_mskOVFE ( 0x1 << FPCSR_offOVFE )
+#define FPCSR_mskUDFE ( 0x1 << FPCSR_offUDFE )
+#define FPCSR_mskIEXE ( 0x1 << FPCSR_offIEXE )
+#define FPCSR_mskDNZ ( 0x1 << FPCSR_offDNZ )
+#define FPCSR_mskIVOT ( 0x1 << FPCSR_offIVOT )
+#define FPCSR_mskDBZT ( 0x1 << FPCSR_offDBZT )
+#define FPCSR_mskOVFT ( 0x1 << FPCSR_offOVFT )
+#define FPCSR_mskUDFT ( 0x1 << FPCSR_offUDFT )
+#define FPCSR_mskIEXT ( 0x1 << FPCSR_offIEXT )
+#define FPCSR_mskDNIT ( 0x1 << FPCSR_offDNIT )
+#define FPCSR_mskRIT ( 0x1 << FPCSR_offRIT )
+#define FPCSR_mskALL (FPCSR_mskIVO | FPCSR_mskDBZ | FPCSR_mskOVF | FPCSR_mskUDF | FPCSR_mskIEX)
+#define FPCSR_mskALLE (FPCSR_mskIVOE | FPCSR_mskDBZE | FPCSR_mskOVFE | FPCSR_mskUDFE | FPCSR_mskIEXE)
+#define FPCSR_mskALLT (FPCSR_mskIVOT | FPCSR_mskDBZT | FPCSR_mskOVFT | FPCSR_mskUDFT | FPCSR_mskIEXT |FPCSR_mskDNIT | FPCSR_mskRIT)
+
+/******************************************************************************
+ * fpcfg: FPCFG (Floating-Point Configuration Register)
+ *****************************************************************************/
+#define FPCFG_offSP 0
+#define FPCFG_offDP 1
+#define FPCFG_offFREG 2
+#define FPCFG_offFMA 4
+#define FPCFG_offIMVER 22
+#define FPCFG_offAVER 27
+
+#define FPCFG_mskSP ( 0x1 << FPCFG_offSP )
+#define FPCFG_mskDP ( 0x1 << FPCFG_offDP )
+#define FPCFG_mskFREG ( 0x3 << FPCFG_offFREG )
+#define FPCFG_mskFMA ( 0x1 << FPCFG_offFMA )
+#define FPCFG_mskIMVER ( 0x1F << FPCFG_offIMVER )
+#define FPCFG_mskAVER ( 0x1F << FPCFG_offAVER )
+
+/******************************************************************************
+ * fucpr: FUCOP_CTL (FPU and Coprocessor Enable Control Register)
+ *****************************************************************************/
+#define FUCOP_CTL_offCP0EN 0
+#define FUCOP_CTL_offCP1EN 1
+#define FUCOP_CTL_offCP2EN 2
+#define FUCOP_CTL_offCP3EN 3
+#define FUCOP_CTL_offAUEN 31
+
+#define FUCOP_CTL_mskCP0EN ( 0x1 << FUCOP_CTL_offCP0EN )
+#define FUCOP_CTL_mskCP1EN ( 0x1 << FUCOP_CTL_offCP1EN )
+#define FUCOP_CTL_mskCP2EN ( 0x1 << FUCOP_CTL_offCP2EN )
+#define FUCOP_CTL_mskCP3EN ( 0x1 << FUCOP_CTL_offCP3EN )
+#define FUCOP_CTL_mskAUEN ( 0x1 << FUCOP_CTL_offAUEN )
+
+#endif /* __NDS32_BITFIELD_H__ */
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/bitops.h linux-3.4.113/arch/nds32/include/asm/bitops.h
--- linux-3.4.113.orig/arch/nds32/include/asm/bitops.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/bitops.h 2016-12-01 20:59:24.332611980 +0100
@@ -0,0 +1,256 @@
+/*
+ * linux/arch/nds32/include/asm/bitops.h
+ * Copyright (C) 2008 Andes Technology Corporation
+ */
+
+#ifndef __NDS32_BITOPS_H__
+#define __NDS32_BITOPS_H__
+
+#if defined(CONFIG_SMP) || !defined(CONFIG_CPU_DCACHE_WRITETHROUGH)
+
+/*
+#include <linux/irqflags.h>
+
+static inline void ____atomic_set_bit(unsigned int bit, volatile unsigned long *p)
+{
+ unsigned long flags;
+ unsigned long mask = 1UL << (bit & 31);
+
+ p += bit >> 5;
+
+ raw_local_irq_save(flags);
+ *p |= mask;
+ raw_local_irq_restore(flags);
+}
+
+static inline void ____atomic_clear_bit(unsigned int bit, volatile unsigned long *p)
+{
+ unsigned long flags;
+ unsigned long mask = 1UL << (bit & 31);
+
+ p += bit >> 5;
+
+ raw_local_irq_save(flags);
+ *p &= ~mask;
+ raw_local_irq_restore(flags);
+}
+
+static inline void ____atomic_change_bit(unsigned int bit, volatile unsigned long *p)
+{
+ unsigned long flags;
+ unsigned long mask = 1UL << (bit & 31);
+
+ p += bit >> 5;
+
+ raw_local_irq_save(flags);
+ *p ^= mask;
+ raw_local_irq_restore(flags);
+}
+
+static inline int
+____atomic_test_and_set_bit(unsigned int bit, volatile unsigned long *p)
+{
+ unsigned long flags;
+ unsigned int res;
+ unsigned long mask = 1UL << (bit & 31);
+
+ p += bit >> 5;
+
+ raw_local_irq_save(flags);
+ res = *p;
+ *p = res | mask;
+ raw_local_irq_restore(flags);
+
+ return (res & mask) != 0;
+}
+static inline int
+____atomic_test_and_clear_bit(unsigned int bit, volatile unsigned long *p)
+{
+ unsigned long flags;
+ unsigned int res;
+ unsigned long mask = 1UL << (bit & 31);
+
+ p += bit >> 5;
+
+ raw_local_irq_save(flags);
+ res = *p;
+ *p = res & ~mask;
+ raw_local_irq_restore(flags);
+
+ return (res & mask) != 0;
+}
+
+static inline int
+____atomic_test_and_change_bit(unsigned int bit, volatile unsigned long *p)
+{
+ unsigned long flags;
+ unsigned int res;
+ unsigned long mask = 1UL << (bit & 31);
+
+ p += bit >> 5;
+
+ raw_local_irq_save(flags);
+ res = *p;
+ *p = res ^ mask;
+ raw_local_irq_restore(flags);
+
+ return (res & mask) != 0;
+}
+
+#include <asm-generic/bitops/non-atomic.h>
+#ifndef CONFIG_SMP
+#define ATOMIC_BITOP(name,nr,p) \
+ (__builtin_constant_p(nr) ? ____atomic_##name(nr, p) : _##name(nr,p))
+#else
+#define ATOMIC_BITOP(name,nr,p) _##name(nr,p)
+#endif
+
+#define set_bit(nr,p) ATOMIC_BITOP(set_bit,nr,p)
+*/
+
+static inline void set_bit(int nr,volatile unsigned long *addr)
+{
+ unsigned long mask = BIT_MASK(nr);
+ unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr);
+ unsigned long tmp;
+
+ __asm__ __volatile__(
+ "xor\t$r15, $r15, $r15\n"
+ "1:\n"
+ "\tllw\t%0, [%1+$r15]\n"
+ "\tor\t%0, %0, %2\n"
+ "\tscw\t%0, [%1+$r15]\n"
+ "\tbeqz\t%0, 1b\n"
+ : "=&r" (tmp)
+ : "r" (p), "r" (mask)
+ : "memory");
+}
+
+static inline void clear_bit(int nr, volatile unsigned long *addr)
+{
+ unsigned long mask = BIT_MASK(nr);
+ unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr);
+ unsigned long tmp;
+
+ mask = ~mask;
+ __asm__ __volatile__(
+ "xor\t$r15, $r15, $r15\n"
+ "1:\n"
+ "\tllw\t%0, [%1+$r15]\n"
+ "\tand\t%0, %0, %2\n"
+ "\tscw\t%0, [%1+$r15]\n"
+ "\tbeqz\t%0, 1b\n"
+ : "=&r" (tmp)
+ : "r" (p), "r" (mask)
+ : "memory");
+}
+
+static inline void change_bit(int nr, volatile unsigned long *addr)
+{
+ unsigned long mask = BIT_MASK(nr);
+ unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr);
+ unsigned long tmp;
+
+ __asm__ __volatile__(
+ "xor\t$r15, $r15, $r15\n"
+ "1:\n"
+ "\tllw\t%0, [%1+$r15]\n"
+ "\txor\t%0, %0, %2\n"
+ "\tscw\t%0, [%1+$r15]\n"
+ "\tbeqz\t%0, 1b\n"
+ : "=&r" (tmp)
+ : "r" (p), "r" (mask)
+ : "memory");
+}
+
+static inline int test_and_set_bit(int nr, volatile unsigned long *addr)
+{
+ unsigned long mask = BIT_MASK(nr);
+ unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr);
+ unsigned long tmp ,ret;
+
+ __asm__ __volatile__(
+ "xor\t$r15, $r15, $r15\n"
+ "1:\n"
+ "\tllw\t%0, [%2+$r15]\n"
+ "\tor\t%1, %0, %3\n"
+ "\tscw\t%1, [%2+$r15]\n"
+ "\tbeqz\t%1, 1b\n"
+ : "=&r" (ret), "=&r" (tmp)
+ : "r" (p), "r" (mask)
+ : "memory");
+ return (ret & mask) != 0;
+}
+
+static inline int test_and_clear_bit(int nr, volatile unsigned long *addr)
+{
+ unsigned long mask = BIT_MASK(nr);
+ unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr);
+ unsigned long tmp, ret;
+ unsigned long mask2 = ~mask;
+
+ __asm__ __volatile__(
+ "xor\t$r15, $r15, $r15\n"
+ "1:\n"
+ "\tllw\t%0, [%2+$r15]\n"
+ "\tand\t%1, %0, %3\n"
+ "\tscw\t%1, [%2+$r15]\n"
+ "\tbeqz\t%1, 1b\n"
+ : "=&r" (ret), "=&r" (tmp)
+ : "r" (p), "r" (mask2)
+ : "memory");
+ return (ret & mask) != 0;
+}
+
+static inline int test_and_change_bit(int nr, volatile unsigned long *addr)
+{
+ unsigned long mask = BIT_MASK(nr);
+ unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr);
+ unsigned long tmp, ret;
+
+ __asm__ __volatile__(
+ "xor\t$r15, $r15, $r15\n"
+ "1:\n"
+ "\tllw\t%0, [%2+$r15]\n"
+ "\txor\t%1, %0, %3\n"
+ "\tscw\t%1, [%2+$r15]\n"
+ "\tbeqz\t%1, 1b\n"
+ : "=&r" (ret), "=&r" (tmp)
+ : "r" (p), "r" (mask)
+ : "memory");
+ return (ret & mask) != 0;
+}
+#else
+#include <linux/irqflags.h>
+#include <asm-generic/bitops/atomic.h>
+#endif
+
+#include <linux/compiler.h>
+#include <asm-generic/bitops/non-atomic.h>
+#include <asm-generic/bitops/__ffs.h>
+#include <asm-generic/bitops/ffz.h>
+#include <asm-generic/bitops/fls.h>
+#include <asm-generic/bitops/__fls.h>
+#include <asm-generic/bitops/fls64.h>
+#include <asm-generic/bitops/find.h>
+
+#ifdef __KERNEL__
+
+#include <asm-generic/bitops/sched.h>
+#include <asm-generic/bitops/ffs.h>
+#include <asm-generic/bitops/hweight.h>
+#include <asm-generic/bitops/lock.h>
+
+#include <asm-generic/bitops/le.h>
+
+/*
+ * Ext2 is defined to use little-endian byte ordering.
+ */
+#include <asm-generic/bitops/ext2-atomic-setbit.h>
+
+#endif /* __KERNEL__ */
+
+#define smp_mb__before_clear_bit() barrier()
+#define smp_mb__after_clear_bit() barrier()
+
+#endif /* __NDS32_BITOPS_H__ */
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/bitsperlong.h linux-3.4.113/arch/nds32/include/asm/bitsperlong.h
--- linux-3.4.113.orig/arch/nds32/include/asm/bitsperlong.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/bitsperlong.h 2016-12-01 20:59:24.332611980 +0100
@@ -0,0 +1 @@
+#include <asm-generic/bitsperlong.h>
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/bug.h linux-3.4.113/arch/nds32/include/asm/bug.h
--- linux-3.4.113.orig/arch/nds32/include/asm/bug.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/bug.h 2016-12-01 20:59:24.332611980 +0100
@@ -0,0 +1,18 @@
+/*
+ * linux/arch/nds32/include/asm/bug.h
+ * Copyright (C) 2008 Andes Technology Corporation
+ */
+
+#ifndef __NDS32_BUG_H__
+#define __NDS32_BUG_H__
+
+#define HAVE_ARCH_BUG
+#include <asm-generic/bug.h>
+
+#define BUG() do { \
+ dump_stack(); \
+ printk("BUG: failure at %s:%d/%s()!\n", __FILE__, __LINE__, __FUNCTION__); \
+ panic("BUG!"); \
+} while (0)
+
+#endif /* __NDS32_BUG_H__ */
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/bugs.h linux-3.4.113/arch/nds32/include/asm/bugs.h
--- linux-3.4.113.orig/arch/nds32/include/asm/bugs.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/bugs.h 2016-12-01 20:59:24.332611980 +0100
@@ -0,0 +1,11 @@
+/*
+ * linux/arch/nds32/include/asm/bugs.h
+ * Copyright (C) 2008 Andes Technology Corporation
+ */
+
+#ifndef __NDS32_BUGS_H__
+#define __NDS32_BUGS_H__
+
+static inline void check_bugs(void) {}
+
+#endif /* __NDS32_BUGS_H__ */
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/byteorder.h linux-3.4.113/arch/nds32/include/asm/byteorder.h
--- linux-3.4.113.orig/arch/nds32/include/asm/byteorder.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/byteorder.h 2016-12-01 20:59:24.332611980 +0100
@@ -0,0 +1,15 @@
+/*
+ * linux/arch/nds32/include/asm/byteorder.h
+ * Copyright (C) 2008 Andes Technology Corporation
+ */
+
+#ifndef __NDS32_BYTEORDER_H__
+#define __NDS32_BYTEORDER_H__
+
+#ifdef __NDS32_EB__
+#include <linux/byteorder/big_endian.h>
+#else
+#include <linux/byteorder/little_endian.h>
+#endif
+
+#endif /* __NDS32_BYTEORDER_H__ */
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/cacheflush.h linux-3.4.113/arch/nds32/include/asm/cacheflush.h
--- linux-3.4.113.orig/arch/nds32/include/asm/cacheflush.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/cacheflush.h 2016-12-01 20:59:24.332611980 +0100
@@ -0,0 +1,55 @@
+/*
+ * linux/arch/nds32/include/asm/cacheflush.h
+ * Copyright (C) 2008 Andes Technology Corporation
+ */
+
+#ifndef __NDS32_CACHEFLUSH_H__
+#define __NDS32_CACHEFLUSH_H__
+
+#include <linux/mm.h>
+
+#define PG_dcache_dirty PG_arch_1
+
+void flush_cache_mm(struct mm_struct *mm);
+
+void flush_cache_dup_mm(struct mm_struct *mm);
+
+void flush_cache_range(struct vm_area_struct *vma,
+ unsigned long start, unsigned long end);
+
+void flush_cache_page(struct vm_area_struct *vma,
+ unsigned long addr, unsigned long pfn);
+
+void flush_cache_kmaps(void);
+
+void flush_cache_vmap(unsigned long start, unsigned long end);
+
+void flush_cache_vunmap(unsigned long start, unsigned long end);
+
+
+void flush_dcache_page(struct page *page);
+
+void copy_to_user_page(struct vm_area_struct *vma, struct page *page,
+ unsigned long vaddr, void *dst, void *src, int len);
+
+void copy_from_user_page(struct vm_area_struct *vma, struct page *page,
+ unsigned long vaddr, void *dst, void *src, int len);
+
+#ifndef CONFIG_CPU_CACHE_NONALIASING
+#define ARCH_HAS_FLUSH_ANON_PAGE
+void flush_anon_page(struct vm_area_struct *vma,
+ struct page *page, unsigned long vaddr);
+
+#define ARCH_HAS_FLUSH_KERNEL_DCACHE_PAGE
+void flush_kernel_dcache_page(struct page *page);
+#endif
+
+void flush_icache_range(unsigned long start, unsigned long end);
+
+void flush_icache_page(struct vm_area_struct *vma, struct page *page);
+
+#define flush_dcache_mmap_lock(mapping) spin_lock_irq(&(mapping)->tree_lock)
+#define flush_dcache_mmap_unlock(mapping) spin_unlock_irq(&(mapping)->tree_lock)
+
+#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 1
+#endif /* __NDS32_CACHEFLUSH_H__ */
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/cache.h linux-3.4.113/arch/nds32/include/asm/cache.h
--- linux-3.4.113.orig/arch/nds32/include/asm/cache.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/cache.h 2016-12-01 20:59:24.332611980 +0100
@@ -0,0 +1,22 @@
+/*
+ * linux/arch/nds32/include/asm/cache.h
+ * Copyright (C) 2008 Andes Technology Corporation
+ */
+
+#ifndef __NDS32_CACHE_H__
+#define __NDS32_CACHE_H__
+
+#define L1_CACHE_BYTES 32
+#define L1_CACHE_SHIFT 5
+
+/*
+ * * Memory returned by kmalloc() may be used for DMA, so we must make
+ * * sure that all such allocations are cache aligned. Otherwise,
+ * * unrelated code may cause parts of the buffer to be read into the
+ * * cache before the transfer is done, causing old data to be seen by
+ * * the CPU.
+ * */
+#define ARCH_DMA_MINALIGN L1_CACHE_BYTES
+
+
+#endif /* __NDS32_CACHE_H__ */
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/cache_info.h linux-3.4.113/arch/nds32/include/asm/cache_info.h
--- linux-3.4.113.orig/arch/nds32/include/asm/cache_info.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/cache_info.h 2016-12-01 20:59:24.332611980 +0100
@@ -0,0 +1,17 @@
+/*
+ * linux/arch/nds32/include/asm/cache.h
+ * Copyright (C) 2008 Andes Technology Corporation
+ */
+struct cache_info {
+ unsigned char cache_type;
+ unsigned char ways;
+ unsigned char way_bits;
+ unsigned char line_bits;
+ unsigned char line_size;
+ unsigned char set_bits;
+ unsigned short sets;
+ unsigned short size;
+ unsigned short aliasing_num;
+ unsigned int aliasing_mask;
+ unsigned int not_aliasing_mask;
+};
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/checksum.h linux-3.4.113/arch/nds32/include/asm/checksum.h
--- linux-3.4.113.orig/arch/nds32/include/asm/checksum.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/checksum.h 2016-12-01 20:59:24.332611980 +0100
@@ -0,0 +1,173 @@
+/*
+ * This file is subject to the terms and conditions of the GNU General Public
+ * License. See the file "COPYING" in the main directory of this archive
+ * for more details.
+ *
+ * Copyright (C) 1995, 96, 97, 98, 99, 2001 by Ralf Baechle
+ * Copyright (C) 1999 Silicon Graphics, Inc.
+ * Copyright (C) 2001 Thiemo Seufer.
+ * Copyright (C) 2002 Maciej W. Rozycki
+ * Copyright (C) 2008 Andes Technology Corporation
+ */
+#ifndef _ASM_CHECKSUM_H
+#define _ASM_CHECKSUM_H
+
+#include <linux/in6.h>
+
+#include <asm/uaccess.h>
+
+/*
+ * computes the checksum of a memory block at buff, length len,
+ * and adds in "sum" (32-bit)
+ *
+ * returns a 32-bit number suitable for feeding into itself
+ * or csum_tcpudp_magic
+ *
+ * this function must be called with even lengths, except
+ * for the last fragment, which may be odd
+ *
+ * it's best to have buff aligned on a 32-bit boundary
+ */
+unsigned int csum_partial(const void *buff, int len, unsigned int sum);
+
+/*
+ * this is a new version of the above that records errors it finds in *errp,
+ * but continues and zeros the rest of the buffer.
+ */
+unsigned int csum_partial_copy_from_user(const unsigned char *src, unsigned char *dst, int len,
+ unsigned int sum, int *errp);
+
+/*
+ * Copy and checksum to user
+ */
+#define HAVE_CSUM_COPY_USER
+static inline unsigned int csum_and_copy_to_user (const unsigned char *src,
+ unsigned char __user *dst,
+ int len, int sum,
+ int *err_ptr)
+{
+ sum = csum_partial(src, len, sum);
+
+ if (copy_to_user(dst, src, len)) {
+ *err_ptr = -EFAULT;
+ return -1;
+ }
+
+ return sum;
+}
+
+/*
+ * the same as csum_partial, but copies from user space (but on MIPS
+ * we have just one address space, so this is identical to the above)
+ */
+unsigned int csum_partial_copy_nocheck(const unsigned char *src, unsigned char *dst,
+ int len, unsigned int sum);
+
+/*
+ * Fold a partial checksum without adding pseudo headers
+ */
+static inline unsigned short int csum_fold(unsigned int sum)
+{
+ __asm__(
+ "slli\t$p1,%0,16\n\t"
+ "add\t%0,%0,$p1\n\t"
+ "slt\t$p1,%0,$p1\n\t"
+ "srli\t%0,%0,16\n\t"
+ "add\t%0,%0,$p1\n\t"
+ "movi\t$p1,0xffff\n\t"
+ "xor\t%0,%0,$p1"
+ : "=r" (sum)
+ : "0" (sum));
+
+ return sum;
+}
+
+/*
+ * This is a version of ip_compute_csum() optimized for IP headers,
+ * which always checksum on 4 octet boundaries.
+ *
+ * By Jorge Cwik <jorge@laser.satlink.net>, adapted for linux by
+ * Arnt Gulbrandsen.
+ */
+static inline unsigned short ip_fast_csum(unsigned char *iph, unsigned int ihl)
+{
+ unsigned int *word = (unsigned int *) iph;
+ unsigned int *stop = word + ihl;
+ unsigned int csum;
+ int carry;
+
+ csum = word[0];
+ csum += word[1];
+ carry = (csum < word[1]);
+ csum += carry;
+
+ csum += word[2];
+ carry = (csum < word[2]);
+ csum += carry;
+
+ csum += word[3];
+ carry = (csum < word[3]);
+ csum += carry;
+
+ word += 4;
+ do {
+ csum += *word;
+ carry = (csum < *word);
+ csum += carry;
+ word++;
+ } while (word != stop);
+
+ return csum_fold(csum);
+}
+
+static inline unsigned int csum_tcpudp_nofold(unsigned long saddr,
+ unsigned long daddr, unsigned short len, unsigned short proto,
+ unsigned int sum)
+{
+ __asm__(
+ "add\t%0, %0, %2\n\t"
+ "slt\t$p1, %0, %2\n\t"
+ "add\t%0, %0, $p1\n\t"
+
+ "add\t%0, %0, %3\n\t"
+ "slt\t$p1, %0, %3\n\t"
+ "add\t%0, %0, $p1\n\t"
+
+ "add\t%0, %0, %4\n\t"
+ "slt\t$p1, %0, %4\n\t"
+ "add\t%0, %0, $p1"
+ : "=r" (sum)
+ : "0" (daddr), "r"(saddr),
+#ifdef __NDS32_EL__
+ "r" (((unsigned long)htons(len)<<16) + proto*256),
+#else
+ "r" (((unsigned long)(proto)<<16) + len),
+#endif
+ "r" ((__force unsigned long)sum));
+
+ return sum;
+}
+
+/*
+ * computes the checksum of the TCP/UDP pseudo-header
+ * returns a 16-bit checksum, already complemented
+ */
+static inline unsigned short int csum_tcpudp_magic(unsigned long saddr,
+ unsigned long daddr,
+ unsigned short len,
+ unsigned short proto,
+ unsigned int sum)
+{
+ return csum_fold(csum_tcpudp_nofold(saddr, daddr, len, proto, sum));
+}
+
+/*
+ * this routine is used for miscellaneous IP-like checksums, mainly
+ * in icmp.c
+ */
+static inline unsigned short ip_compute_csum(const void * buff, int len)
+{
+ return csum_fold(csum_partial(buff, len, 0));
+}
+
+#endif /* _ASM_CHECKSUM_H */
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/cmpxchg.h linux-3.4.113/arch/nds32/include/asm/cmpxchg.h
--- linux-3.4.113.orig/arch/nds32/include/asm/cmpxchg.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/cmpxchg.h 2016-12-01 20:59:24.332611980 +0100
@@ -0,0 +1,88 @@
+#ifndef __ASM_NDS32_CMPXCHG_H
+#define __ASM_NDS32_CMPXCHG_H
+
+#include <asm/barrier.h>
+
+#define xchg(ptr,x) \
+ ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
+
+static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size)
+{
+ extern void __bad_xchg(volatile void *, int);
+ unsigned long ret;
+ unsigned long flags;
+
+ switch (size) {
+ case 4:
+#if defined(CONFIG_SMP) || !defined(CONFIG_CPU_DCACHE_WRITETHROUGH)
+ __asm__ __volatile__(
+ "xor\t$r15, $r15, $r15\n"
+ "1:\n"
+ "\tllw\t%0, [%2+$r15]\n"
+ "\tori\t%1, %3, #0x0\n"
+ "\tscw\t%1, [%2+$r15]\n"
+ "\tbeqz\t%1, 1b\n"
+ : "=&r" (ret), "=&r" (flags)
+ : "r" (ptr), "r" (x)
+ : "memory");
+#else
+ raw_local_irq_save(flags);
+ ret = *(volatile unsigned long *)ptr;
+ *(volatile unsigned long *)ptr = x;
+ raw_local_irq_restore(flags);
+#endif
+ break;
+ default:
+ __bad_xchg(ptr, size);
+ ret = 0;
+ }
+ return ret;
+}
+
+
+#define __HAVE_ARCH_CMPXCHG 1
+
+static inline unsigned long __cmpxchg(volatile void * ptr, unsigned long old,
+ unsigned long new, int size)
+{
+ extern void __cmpxchg_called_with_bad_pointer(void); /*nonexistence */
+ unsigned long retval, tmp;
+ unsigned long flags;
+ switch (size) {
+ case 4:
+#if defined(CONFIG_SMP) || !defined(CONFIG_CPU_DCACHE_WRITETHROUGH)
+ __asm__ __volatile__(
+ "xor\t$r15, $r15, $r15\n"
+ "1:\n"
+ "\tllw\t%0, [%3+$r15]\n"
+ "\tsub\t%2, %0, %5\n"
+ "\tcmovz\t%1, %4, %2\n"
+ "\tcmovn\t%1, %0, %2\n"
+ "\tscw\t%1, [%3+$r15]\n"
+ "\tbeqz\t%1, 1b\n"
+ : "=&r" (retval), "=&r" (flags), "=&r" (tmp)
+ : "r" (ptr), "r" (new), "r" (old));
+#else
+ raw_local_irq_save(flags);
+ retval = *(volatile unsigned long *)ptr;
+ if (retval == old)
+ *(volatile unsigned long *)ptr = new;
+ raw_local_irq_restore(flags);
+#endif
+ break;
+ default:
+ __cmpxchg_called_with_bad_pointer();
+ tmp = 0;
+ }
+ return retval;
+}
+
+#define cmpxchg(ptr,o,n) \
+ ({ \
+ __typeof__(*(ptr)) _o_ = (o); \
+ __typeof__(*(ptr)) _n_ = (n); \
+ (__typeof__(*(ptr))) __cmpxchg((ptr), (unsigned long)_o_, \
+ (unsigned long)_n_, sizeof(*(ptr))); \
+ })
+
+#endif
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/cpu.h linux-3.4.113/arch/nds32/include/asm/cpu.h
--- linux-3.4.113.orig/arch/nds32/include/asm/cpu.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/cpu.h 2016-12-01 20:59:24.332611980 +0100
@@ -0,0 +1,25 @@
+/*
+ * linux/arch/nds32/include/asm/cpu.h
+ *
+ * Copyright (C) 2004-2005 ARM Ltd.
+ * Copyright (C) 2008 Andes Technology Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+#ifndef __ASM_NDS32_CPU_H
+#define __ASM_NDS32_CPU_H
+
+#include <linux/percpu.h>
+
+struct cpuinfo_nds32 {
+ struct cpu cpu;
+#ifdef CONFIG_SMP
+ unsigned int loops_per_jiffy;
+#endif
+};
+
+DECLARE_PER_CPU(struct cpuinfo_nds32, cpu_data);
+
+#endif
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/cputime.h linux-3.4.113/arch/nds32/include/asm/cputime.h
--- linux-3.4.113.orig/arch/nds32/include/asm/cputime.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/cputime.h 2016-12-01 20:59:24.332611980 +0100
@@ -0,0 +1,11 @@
+/*
+ * linux/arch/nds32/include/asm/cputime.h
+ * Copyright (C) 2008 Andes Technology Corporation
+ */
+
+#ifndef __NDS32_CPUTIME_H__
+#define __NDS32_CPUTIME_H__
+
+#include <asm-generic/cputime.h>
+
+#endif
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/cpuver.h linux-3.4.113/arch/nds32/include/asm/cpuver.h
--- linux-3.4.113.orig/arch/nds32/include/asm/cpuver.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/cpuver.h 2016-12-01 20:59:24.332611980 +0100
@@ -0,0 +1,34 @@
+/*
+ * linux/arch/nds32/include/asm/cpuver.h
+ * Copyright (C) 2008 Andes Technology Corporation
+ */
+
+#ifndef __NDS32_CPUVER_H__
+#define __NDS32_CPUVER_H__
+
+#include <asm/bitfield.h>
+#include <asm/reg_access.h>
+
+#define GET_CPU_ID()\
+ (( GET_CPU_VER() & CPU_VER_mskCPUID) >> CPU_VER_offCPUID)
+
+#define GET_CPU_REV()\
+ (( GET_CPU_VER() & CPU_VER_mskREV) >> CPU_VER_offREV)
+
+#define GET_CPU_CFGID()\
+ (( GET_CPU_VER() & CPU_VER_mskCFGID) >> CPU_VER_offCFGID)
+
+#define CPU_IS_N1213_43U1HA0()\
+ (((GET_CPU_VER() & CPU_VER_mskCPUID) == 0x0c000000) &&\
+ ((GET_CPU_VER() & CPU_VER_mskREV) == 0x00010000))
+
+#define CPU_IS_N1213_43U1HB0()\
+ (((GET_CPU_VER() & CPU_VER_mskCPUID) == 0x0c000000) &&\
+ ((GET_CPU_VER() & CPU_VER_mskREV) == 0x00020000))
+
+#define CPU_IS_N1033_S()\
+ (((GET_CPU_VER() & CPU_VER_mskCPUID) == 0x0a000000) &&\
+ ((GET_CPU_VER() & CPU_VER_mskREV) == 0x000c0000))
+
+#endif
+
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/current.h linux-3.4.113/arch/nds32/include/asm/current.h
--- linux-3.4.113.orig/arch/nds32/include/asm/current.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/current.h 2016-12-01 20:59:24.332611980 +0100
@@ -0,0 +1,18 @@
+/*
+ * linux/arch/nds32/include/asm/current.h
+ * Copyright (C) 2008 Andes Technology Corporation
+ */
+
+#ifndef __NDS32_CURRENT_H__
+#define __NDS32_CURRENT_H__
+
+#include <linux/thread_info.h>
+
+static inline struct task_struct *get_current(void)
+{
+ return current_thread_info()->task;
+}
+
+#define current get_current()
+
+#endif
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/delay.h linux-3.4.113/arch/nds32/include/asm/delay.h
--- linux-3.4.113.orig/arch/nds32/include/asm/delay.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/delay.h 2016-12-01 20:59:24.332611980 +0100
@@ -0,0 +1,39 @@
+/*
+ * linux/arch/nds32/include/asm/delay.h
+ * Copyright (C) 2008 Andes Technology Corporation
+ */
+
+#ifndef __NDS32_DELAY_H__
+#define __NDS32_DELAY_H__
+
+#include <asm/param.h>
+
+static inline void __delay(unsigned long loops)
+{
+ __asm__ __volatile__ (
+ "1:\n"
+ "\taddi\t%0, %0, -1\n"
+ "\tbgtz\t%0, 1b\n"
+ : "=r" (loops) : "0" (loops));
+}
+
+static inline void __udelay(unsigned long usecs, unsigned long lpj)
+{
+ usecs *= (unsigned long) (((0x8000000000000000ULL / (500000 / HZ)) +
+ 0x80000000ULL) >> 32);
+ usecs=(unsigned long)(((unsigned long long)usecs*lpj)>>32);
+ __delay(usecs);
+}
+
+#define udelay(usecs) __udelay((usecs), loops_per_jiffy)
+
+/* make sure "usecs *= ..." in udelay do not overflow. */
+#if HZ >= 1000
+#define MAX_UDELAY_MS 1
+#elif HZ <= 200
+#define MAX_UDELAY_MS 5
+#else
+#define MAX_UDELAY_MS (1000 / HZ)
+#endif
+
+#endif
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/device.h linux-3.4.113/arch/nds32/include/asm/device.h
--- linux-3.4.113.orig/arch/nds32/include/asm/device.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/device.h 2016-12-01 20:59:24.332611980 +0100
@@ -0,0 +1,11 @@
+/*
+ * linux/arch/nds32/include/asm/device.h
+ * Copyright (C) 2008 Andes Technology Corporation
+ */
+
+#ifndef __NDS32_DEVICE_H__
+#define __NDS32_DEVICE_H__
+
+#include <asm-generic/device.h>
+
+#endif /* __NDS32_DEVICE_H__ */
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/div64.h linux-3.4.113/arch/nds32/include/asm/div64.h
--- linux-3.4.113.orig/arch/nds32/include/asm/div64.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/div64.h 2016-12-01 20:59:24.332611980 +0100
@@ -0,0 +1,11 @@
+/*
+ * linux/arch/nds32/include/asm/div64.h
+ * Copyright (C) 2008 Andes Technology Corporation
+ */
+
+#ifndef __NDS32_DIV64_H__
+#define __NDS32_DIV64_H__
+
+#include <asm-generic/div64.h>
+
+#endif
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/dmad.h linux-3.4.113/arch/nds32/include/asm/dmad.h
--- linux-3.4.113.orig/arch/nds32/include/asm/dmad.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/dmad.h 2016-12-01 20:59:24.332611980 +0100
@@ -0,0 +1,1071 @@
+/*
+ * Copyright Andes Technology Corporation 2007-2008
+ * All Rights Reserved.
+ *
+ * Revision History:
+ *
+ * Aug.21.2007 Created.
+ *
+ * DESCRIPTION
+ *
+ * DMA controller driver internal supplement library.
+ *
+ */
+
+#ifndef __NDS_DMAD_INC__
+#define __NDS_DMAD_INC__
+
+#include <asm/spec.h>
+
+/*****************************************************************************
+ * Configuration section
+*****************************************************************************/
+
+/* Debug trace enable switch */
+#define DMAD_ERROR_TRACE 1 /* message for fatal errors */
+//MOD by river 2010.10.19
+#define DMAD_DEBUG_TRACE 0 /* message for debug trace */
+//End MOD by river 2010.10.19
+
+//#ifndef addr_t
+typedef u32 addr_t;
+//#endif
+/* for amerald */
+#define AMERALD_PRODUCT_ID 0x41471000
+#define AMERALD_MASK 0xFFFFF000
+
+/*****************************************************************************
+ * DMAC - AG101 AHB
+*****************************************************************************/
+/* Device base address */
+#define DMAC_BASE DMAC_FTDMAC020_0_VA_BASE
+
+/* DMA controller registers (8-bit width) */
+#define DMAC_INT (DMAC_BASE + 0x00)
+#define DMAC_INT_TC (DMAC_BASE + 0x04)
+#define DMAC_INT_TC_CLR (DMAC_BASE + 0x08)
+#define DMAC_INT_ERRABT (DMAC_BASE + 0x0c)
+#define DMAC_INT_ERRABT_CLR (DMAC_BASE + 0x10)
+#define DMAC_TC (DMAC_BASE + 0x14)
+#define DMAC_ERRABT (DMAC_BASE + 0x18)
+#define DMAC_CH_EN (DMAC_BASE + 0x1c)
+#define DMAC_CH_BUSY (DMAC_BASE + 0x20)
+#define DMAC_CSR (DMAC_BASE + 0x24)
+#define DMAC_SYNC (DMAC_BASE + 0x28)
+
+/* DMA channel registers base address */
+#define DMAC_C0_OFFSET 0x100
+#define DMAC_C1_OFFSET 0x120
+#define DMAC_C2_OFFSET 0x140
+#define DMAC_C3_OFFSET 0x160
+#define DMAC_C4_OFFSET 0x180
+#define DMAC_C5_OFFSET 0x1a0
+#define DMAC_C6_OFFSET 0x1c0
+#define DMAC_C7_OFFSET 0x1e0
+
+#define DMAC_C0_BASE (DMAC_BASE + DMAC_C0_OFFSET)
+#define DMAC_C1_BASE (DMAC_BASE + DMAC_C1_OFFSET)
+#define DMAC_C2_BASE (DMAC_BASE + DMAC_C2_OFFSET)
+#define DMAC_C3_BASE (DMAC_BASE + DMAC_C3_OFFSET)
+#define DMAC_C4_BASE (DMAC_BASE + DMAC_C4_OFFSET)
+#define DMAC_C5_BASE (DMAC_BASE + DMAC_C5_OFFSET)
+#define DMAC_C6_BASE (DMAC_BASE + DMAC_C6_OFFSET)
+#define DMAC_C7_BASE (DMAC_BASE + DMAC_C7_OFFSET)
+
+#define DMAC_MAX_CHANNELS 8
+#define DMAC_BASE_CH(n) (DMAC_C0_BASE + \
+ (DMAC_C1_OFFSET - DMAC_C0_OFFSET) * \
+ (addr_t)(n)) /* n = 0 ~ 3 */
+
+#define DMAC_CSR_OFFSET 0x00
+#define DMAC_CFG_OFFSET 0x04
+#define DMAC_SRC_ADDR_OFFSET 0x08
+#define DMAC_DST_ADDR_OFFSET 0x0c
+#define DMAC_LLP_OFFSET 0x10
+#define DMAC_SIZE_OFFSET 0x14
+
+/* DMA channel 0 registers (32-bit width) */
+#define DMAC_C0_CSR (DMAC_C0_BASE + DMAC_CSR_OFFSET)
+#define DMAC_C0_CFG (DMAC_C0_BASE + DMAC_CFG_OFFSET)
+#define DMAC_C0_SRC_ADDR (DMAC_C0_BASE + DMAC_SRC_ADDR_OFFSET)
+#define DMAC_C0_DST_ADDR (DMAC_C0_BASE + DMAC_DST_ADDR_OFFSET)
+#define DMAC_C0_LLP (DMAC_C0_BASE + DMAC_LLP_OFFSET)
+#define DMAC_C0_SIZE (DMAC_C0_BASE + DMAC_SIZE_OFFSET)
+
+/* DMA channel 1 registers (32-bit width) */
+#define DMAC_C1_CSR (DMAC_C1_BASE + DMAC_CSR_OFFSET)
+#define DMAC_C1_CFG (DMAC_C1_BASE + DMAC_CFG_OFFSET)
+#define DMAC_C1_SRC_ADDR (DMAC_C1_BASE + DMAC_SRC_ADDR_OFFSET)
+#define DMAC_C1_DST_ADDR (DMAC_C1_BASE + DMAC_DST_ADDR_OFFSET)
+#define DMAC_C1_LLP (DMAC_C1_BASE + DMAC_LLP_OFFSET)
+#define DMAC_C1_SIZE (DMAC_C1_BASE + DMAC_SIZE_OFFSET)
+
+/* DMA channel 2 registers (32-bit width) */
+#define DMAC_C2_CSR (DMAC_C2_BASE + DMAC_CSR_OFFSET)
+#define DMAC_C2_CFG (DMAC_C2_BASE + DMAC_CFG_OFFSET)
+#define DMAC_C2_SRC_ADDR (DMAC_C2_BASE + DMAC_SRC_ADDR_OFFSET)
+#define DMAC_C2_DST_ADDR (DMAC_C2_BASE + DMAC_DST_ADDR_OFFSET)
+#define DMAC_C2_LLP (DMAC_C2_BASE + DMAC_LLP_OFFSET)
+#define DMAC_C2_SIZE (DMAC_C2_BASE + DMAC_SIZE_OFFSET)
+
+/* DMA channel 3 registers (32-bit width) */
+#define DMAC_C3_CSR (DMAC_C3_BASE + DMAC_CSR_OFFSET)
+#define DMAC_C3_CFG (DMAC_C3_BASE + DMAC_CFG_OFFSET)
+#define DMAC_C3_SRC_ADDR (DMAC_C3_BASE + DMAC_SRC_ADDR_OFFSET)
+#define DMAC_C3_DST_ADDR (DMAC_C3_BASE + DMAC_DST_ADDR_OFFSET)
+#define DMAC_C3_LLP (DMAC_C3_BASE + DMAC_LLP_OFFSET)
+#define DMAC_C3_SIZE (DMAC_C3_BASE + DMAC_SIZE_OFFSET)
+
+/* DMA channel 4 registers (32-bit width) */
+#define DMAC_C4_CSR (DMAC_C4_BASE + DMAC_CSR_OFFSET)
+#define DMAC_C4_CFG (DMAC_C4_BASE + DMAC_CFG_OFFSET)
+#define DMAC_C4_SRC_ADDR (DMAC_C4_BASE + DMAC_SRC_ADDR_OFFSET)
+#define DMAC_C4_DST_ADDR (DMAC_C4_BASE + DMAC_DST_ADDR_OFFSET)
+#define DMAC_C4_LLP (DMAC_C4_BASE + DMAC_LLP_OFFSET)
+#define DMAC_C4_SIZE (DMAC_C4_BASE + DMAC_SIZE_OFFSET)
+
+/* DMA channel 5 registers (32-bit width) */
+#define DMAC_C5_CSR (DMAC_C5_BASE + DMAC_CSR_OFFSET)
+#define DMAC_C5_CFG (DMAC_C5_BASE + DMAC_CFG_OFFSET)
+#define DMAC_C5_SRC_ADDR (DMAC_C5_BASE + DMAC_SRC_ADDR_OFFSET)
+#define DMAC_C5_DST_ADDR (DMAC_C5_BASE + DMAC_DST_ADDR_OFFSET)
+#define DMAC_C5_LLP (DMAC_C5_BASE + DMAC_LLP_OFFSET)
+#define DMAC_C5_SIZE (DMAC_C5_BASE + DMAC_SIZE_OFFSET)
+
+/* DMA channel 6 registers (32-bit width) */
+#define DMAC_C6_CSR (DMAC_C6_BASE + DMAC_CSR_OFFSET)
+#define DMAC_C6_CFG (DMAC_C6_BASE + DMAC_CFG_OFFSET)
+#define DMAC_C6_SRC_ADDR (DMAC_C6_BASE + DMAC_SRC_ADDR_OFFSET)
+#define DMAC_C6_DST_ADDR (DMAC_C6_BASE + DMAC_DST_ADDR_OFFSET)
+#define DMAC_C6_LLP (DMAC_C6_BASE + DMAC_LLP_OFFSET)
+#define DMAC_C6_SIZE (DMAC_C6_BASE + DMAC_SIZE_OFFSET)
+
+/* DMA channel 7 registers (32-bit width) */
+#define DMAC_C7_CSR (DMAC_C7_BASE + DMAC_CSR_OFFSET)
+#define DMAC_C7_CFG (DMAC_C7_BASE + DMAC_CFG_OFFSET)
+#define DMAC_C7_SRC_ADDR (DMAC_C7_BASE + DMAC_SRC_ADDR_OFFSET)
+#define DMAC_C7_DST_ADDR (DMAC_C7_BASE + DMAC_DST_ADDR_OFFSET)
+#define DMAC_C7_LLP (DMAC_C7_BASE + DMAC_LLP_OFFSET)
+#define DMAC_C7_SIZE (DMAC_C7_BASE + DMAC_SIZE_OFFSET)
+
+/*****************************************************************************
+ * DMAC defs - AG101 AHB
+*****************************************************************************/
+
+/* Interrupt status register (+00) */
+#define DMAC_INT0_MASK 0x01
+#define DMAC_INT0_BIT 0
+#define DMAC_INT1_MASK 0x02
+#define DMAC_INT1_BIT 1
+#define DMAC_INT2_MASK 0x04
+#define DMAC_INT2_BIT 2
+#define DMAC_INT3_MASK 0x08
+#define DMAC_INT3_BIT 3
+
+/* Interrupt for terminal count status register (+0x04) */
+#define DMAC_INT_TC0_MASK 0x01
+#define DMAC_INT_TC0_BIT 0
+#define DMAC_INT_TC1_MASK 0x02
+#define DMAC_INT_TC1_BIT 1
+#define DMAC_INT_TC2_MASK 0x04
+#define DMAC_INT_TC2_BIT 2
+#define DMAC_INT_TC3_MASK 0x08
+#define DMAC_INT_TC3_BIT 3
+#define DMAC_INT_TC4_MASK 0x01
+#define DMAC_INT_TC4_BIT 0
+#define DMAC_INT_TC5_MASK 0x02
+#define DMAC_INT_TC5_BIT 1
+#define DMAC_INT_TC6_MASK 0x04
+#define DMAC_INT_TC6_BIT 2
+#define DMAC_INT_TC7_MASK 0x08
+#define DMAC_INT_TC7_BIT 3
+
+#define DMAC_INT_TC_MASK 0xff
+#define DMAC_INT_TC_SHIFT 0
+
+/* Interrupt for terminal count clear register (+0x08) */
+#define DMAC_INT_TC0_CLR_MASK 0x01
+#define DMAC_INT_TC0_CLR_BIT 0
+#define DMAC_INT_TC1_CLR_MASK 0x02
+#define DMAC_INT_TC1_CLR_BIT 1
+#define DMAC_INT_TC2_CLR_MASK 0x04
+#define DMAC_INT_TC2_CLR_BIT 2
+#define DMAC_INT_TC3_CLR_MASK 0x08
+#define DMAC_INT_TC3_CLR_BIT 3
+
+#define DMAC_INT_TC_CLR_MASK 0x0f
+#define DMAC_INT_TC_CLR_SHIFT 0
+
+/* Interrupt for error/abort status register (+0x0c, 32-bits width) */
+#define DMAC_INT_ERR0_MASK 0x00000001
+#define DMAC_INT_ERR0_BIT 0
+#define DMAC_INT_ERR1_MASK 0x00000002
+#define DMAC_INT_ERR1_BIT 1
+#define DMAC_INT_ERR2_MASK 0x00000004
+#define DMAC_INT_ERR2_BIT 2
+#define DMAC_INT_ERR3_MASK 0x00000008
+#define DMAC_INT_ERR3_BIT 3
+
+#define DMAC_INT_ERR_MASK 0x0000000f
+#define DMAC_INT_ERR_SHIFT 0
+
+#define DMAC_INT_ABT0_MASK 0x00010000
+#define DMAC_INT_ABT0_BIT 16
+#define DMAC_INT_ABT1_MASK 0x00020000
+#define DMAC_INT_ABT1_BIT 17
+#define DMAC_INT_ABT2_MASK 0x00040000
+#define DMAC_INT_ABT2_BIT 18
+#define DMAC_INT_ABT3_MASK 0x00080000
+#define DMAC_INT_ABT3_BIT 19
+
+#define DMAC_INT_ABT_MASK 0x000f0000
+#define DMAC_INT_ABT_SHIFT 16
+
+/* Interrupt for error/abort status clear register (+0x10, 32-bits width) */
+#define DMAC_INT_ERR0_CLR_MASK 0x00000001
+#define DMAC_INT_ERR0_CLR_BIT 0
+#define DMAC_INT_ERR1_CLR_MASK 0x00000002
+#define DMAC_INT_ERR1_CLR_BIT 1
+#define DMAC_INT_ERR2_CLR_MASK 0x00000004
+#define DMAC_INT_ERR2_CLR_BIT 2
+#define DMAC_INT_ERR3_CLR_MASK 0x00000008
+#define DMAC_INT_ERR3_CLR_BIT 3
+
+#define DMAC_INT_ERR_CLR_MASK 0x0000000f
+#define DMAC_INT_ERR_CLR_SHIFT 0
+
+#define DMAC_INT_ABT0_CLR_MASK 0x00010000
+#define DMAC_INT_ABT0_CLR_BIT 16
+#define DMAC_INT_ABT1_CLR_MASK 0x00020000
+#define DMAC_INT_ABT1_CLR_BIT 17
+#define DMAC_INT_ABT2_CLR_MASK 0x00040000
+#define DMAC_INT_ABT2_CLR_BIT 18
+#define DMAC_INT_ABT3_CLR_MASK 0x00080000
+#define DMAC_INT_ABT3_CLR_BIT 19
+
+#define DMAC_INT_ABT_CLR_MASK 0x000f0000
+#define DMAC_INT_ABT_CLR_SHIFT 16
+
+/* Terminal count status register (+0x14) */
+#define DMAC_TC0_MASK 0x01
+#define DMAC_TC0_BIT 0
+#define DMAC_TC1_MASK 0x02
+#define DMAC_TC1_BIT 1
+#define DMAC_TC2_MASK 0x04
+#define DMAC_TC2_BIT 2
+#define DMAC_TC3_MASK 0x08
+#define DMAC_TC3_BIT 3
+
+/* Error/abort status register (+0x18, 32-bits width) */
+#define DMAC_ERR0_MASK 0x00000001
+#define DMAC_ERR0_BIT 0
+#define DMAC_ERR1_MASK 0x00000002
+#define DMAC_ERR1_BIT 1
+#define DMAC_ERR2_MASK 0x00000004
+#define DMAC_ERR2_BIT 2
+#define DMAC_ERR3_MASK 0x00000008
+#define DMAC_ERR3_BIT 3
+
+#define DMAC_ABT0_MASK 0x00010000
+#define DMAC_ABT0_BIT 16
+#define DMAC_ABT1_MASK 0x00020000
+#define DMAC_ABT1_BIT 17
+#define DMAC_ABT2_MASK 0x00040000
+#define DMAC_ABT2_BIT 18
+#define DMAC_ABT3_MASK 0x00080000
+#define DMAC_ABT3_BIT 19
+
+/* Channel enable status register (+0x1c) */
+#define DMAC_CH0_EN_MASK 0x01
+#define DMAC_CH0_EN_BIT 0
+#define DMAC_CH1_EN_MASK 0x02
+#define DMAC_CH1_EN_BIT 1
+#define DMAC_CH2_EN_MASK 0x04
+#define DMAC_CH2_EN_BIT 2
+#define DMAC_CH3_EN_MASK 0x08
+#define DMAC_CH3_EN_BIT 3
+
+/* Channel busy status register (+0x20) */
+#define DMAC_CH0_BUSY_MASK 0x01
+#define DMAC_CH0_BUSY_BIT 0
+#define DMAC_CH1_BUSY_MASK 0x02
+#define DMAC_CH1_BUSY_BIT 1
+#define DMAC_CH2_BUSY_MASK 0x04
+#define DMAC_CH2_BUSY_BIT 2
+#define DMAC_CH3_BUSY_MASK 0x08
+#define DMAC_CH3_BUSY_BIT 3
+
+/* Main configuration status register (+0x24) */
+#define DMAC_DMACEN_MASK 0x01
+#define DMAC_DMACEN_BIT 0
+#define DMAC_M0ENDIAN_MASK 0x02
+#define DMAC_M0ENDIAN_BIT 1
+#define DMAC_M1ENDIAN_MASK 0x04
+#define DMAC_M1ENDIAN_BIT 2
+
+ #define DMAC_ENDIAN_LITTLE 0
+ #define DMAC_ENDIAN_BIG 1
+
+/* Sync register (+0x28) */
+#define DMAC_SYNC0_MASK 0x01
+#define DMAC_SYNC0_BIT 0
+#define DMAC_SYNC1_MASK 0x02
+#define DMAC_SYNC1_BIT 1
+#define DMAC_SYNC2_MASK 0x04
+#define DMAC_SYNC2_BIT 2
+#define DMAC_SYNC3_MASK 0x08
+#define DMAC_SYNC3_BIT 3
+
+/* DMA channel 0~n Control Registers (CH[n]_BASE + 0x00) */
+#define DMAC_CSR_CH_EN_MASK 0x00000001
+#define DMAC_CSR_CH_EN_BIT 0
+
+#define DMAC_CSR_DST_SEL_MASK 0x00000002
+#define DMAC_CSR_DST_SEL_BIT 1
+#define DMAC_CSR_SRC_SEL_MASK 0x00000004
+#define DMAC_CSR_SRC_SEL_BIT 2
+ #define DMAC_CSR_SEL_MASTER0 0x00
+ #define DMAC_CSR_SEL_MASTER1 0x01
+
+#define DMAC_CSR_DSTAD_CTL_MASK 0x00000018
+#define DMAC_CSR_DSTAD_CTL_SHIFT 3
+#define DMAC_CSR_SRCAD_CTL_MASK 0x00000060
+#define DMAC_CSR_SRCAD_CTL_SHIFT 5
+ #define DMAC_CSR_AD_INC 0x00
+ #define DMAC_CSR_AD_DEC 0x01
+ #define DMAC_CSR_AD_FIX 0x02
+
+#define DMAC_CSR_MODE_MASK 0x00000080
+#define DMAC_CSR_MODE_BIT 7
+ #define DMAC_CSR_MODE_NORMAL 0x00
+ #define DMAC_CSR_MODE_HSHK 0x01
+
+#define DMAC_CSR_DST_WIDTH_MASK 0x00000700
+#define DMAC_CSR_DST_WIDTH_SHIFT 8
+#define DMAC_CSR_SRC_WIDTH_MASK 0x00003800
+#define DMAC_CSR_SRC_WIDTH_SHIFT 11
+ #define DMAC_CSR_WIDTH_8 0x00
+ #define DMAC_CSR_WIDTH_16 0x01
+ #define DMAC_CSR_WIDTH_32 0x02
+
+#ifdef CONFIG_PLATFORM_AHBDMA
+#define DMAC_CYCLE_TO_BYTES(cycle, width) ((cycle) << (width))
+#define DMAC_BYTES_TO_CYCLE(bytes, width) ((bytes) >> (width))
+#else
+#define DMAC_CYCLE_TO_BYTES(cycle, width) 0
+#define DMAC_BYTES_TO_CYCLE(bytes, width) 0
+#endif /* CONFIG_PLATFORM_AHBDMA */
+
+#define DMAC_CSR_ABT 0x00008000
+#define DMAC_CSR_ABT_BIT 15
+
+#define DMAC_CSR_SRC_SIZE_MASK 0x00070000
+#define DMAC_CSR_SRC_SIZE_SHIFT 16
+ #define DMAC_CSR_SIZE_1 0x00
+ #define DMAC_CSR_SIZE_4 0x01
+ #define DMAC_CSR_SIZE_8 0x02
+ #define DMAC_CSR_SIZE_16 0x03
+ #define DMAC_CSR_SIZE_32 0x04
+ #define DMAC_CSR_SIZE_64 0x05
+ #define DMAC_CSR_SIZE_128 0x06
+ #define DMAC_CSR_SIZE_256 0x07
+
+#define DMAC_CSR_PROT1 0x00080000
+#define DMAC_CSR_PROT1_BIT 19
+#define DMAC_CSR_PROT2 0x00100000
+#define DMAC_CSR_PROT2_BIT 20
+#define DMAC_CSR_PROT3 0x00200000
+#define DMAC_CSR_PROT3_BIT 21
+
+#define DMAC_CSR_CHPRI_MASK 0x00c00000
+#define DMAC_CSR_CHPRI_SHIFT 22
+ #define DMAC_CSR_CHPRI_0 0x00
+ #define DMAC_CSR_CHPRI_1 0x01
+ #define DMAC_CSR_CHPRI_2 0x02
+ #define DMAC_CSR_CHPRI_3 0x03
+
+#define DMAC_CSR_FF_TH_MASK 0x07000000
+#define DMAC_CSR_FF_TH_SHIFT 24
+ #define DMAC_CSR_FF_TH_1 0x00
+ #define DMAC_CSR_FF_TH_2 0x01
+ #define DMAC_CSR_FF_TH_4 0x02
+ #define DMAC_CSR_FF_TH_8 0x03
+ #define DMAC_CSR_FF_TH_16 0x04
+
+#define DMAC_CSR_TC_MSK_MSK 0x80000000
+#define DMAC_CSR_TC_MSK_BIT 31
+
+/* DMA channel 0~n Configuration Registers (CH[n]_BASE + 0x04) */
+#define DMAC_CFG_INT_TC_MSK 0x00000001
+#define DMAC_CFG_INT_TC_MSK_BIT 0
+#define DMAC_CFG_INT_ERR_MSK 0x00000002
+#define DMAC_CFG_INT_ERR_MSK_BIT 1
+#define DMAC_CFG_INT_ABT_MSK 0x00000004
+#define DMAC_CFG_INT_ABT_MSK_BIT 2
+
+#define DMAC_CFG_INT_SRC_RS_MASK 0x00000078
+#define DMAC_CFG_INT_SRC_RS_SHIFT 3
+#define DMAC_CFG_INT_SRC_HE_MASK 0x00000080
+#define DMAC_CFG_INT_SRC_HE_BIT 7
+
+#define DMAC_CFG_BUSY_MASK 0x00000100
+#define DMAC_CFG_BUSY_BIT 8
+
+#define DMAC_CFG_INT_DST_RS_MASK 0x00001e00
+#define DMAC_CFG_INT_DST_RS_SHIFT 9
+#define DMAC_CFG_INT_DST_HE_MASK 0x00002000
+#define DMAC_CFG_INT_DST_HE_BIT 13
+
+#ifdef CONFIG_PLAT_AG102
+ #define DMAC_REQN_IDERX 0
+ #define DMAC_REQN_IDETX 1
+ #define DMAC_REQN_I2SAC97RX 2
+ #define DMAC_REQN_I2SAC97TX 3
+ #define DMAC_REQN_UART2RX 4
+ #define DMAC_REQN_UART2TX 5
+ #define DMAC_REQN_UART1RX 6
+ #define DMAC_REQN_UART1TX 7
+ #define DMAC_REQN_SDC 8
+ #define DMAC_REQN_CFC 9
+ #define DMAC_REQN_LPCREQ0 10
+ #define DMAC_REQN_LPCREQ1 11
+ #define DMAC_REQN_LPCREQ2 12
+ #define DMAC_REQN_LPCREQ3 13
+ #define DMAC_REQN_NONE 14
+ #define DMAC_REQN_LPCREQ5 15
+ #define DMAC_REQN_MAX 15
+#else
+ #define DMAC_REQN_NONE PMU_REQN_NONE
+ #define DMAC_REQN_CFC PMU_REQN_CFC
+ #define DMAC_REQN_SSP PMU_REQN_SSP
+ #define DMAC_REQN_UART1TX PMU_REQN_UART1TX
+ #define DMAC_REQN_UART1RX PMU_REQN_UART1RX
+ #define DMAC_REQN_UART2TX PMU_REQN_UART2TX
+ #define DMAC_REQN_UART2RX PMU_REQN_UART2RX
+ #define DMAC_REQN_SDC PMU_REQN_SDC
+ #define DMAC_REQN_I2SAC97TX PMU_REQN_I2SAC97TX
+ #define DMAC_REQN_I2SAC97RX PMU_REQN_I2SAC97RX
+/* for amerald ac97 ssp2 */
+ #define DMAC_REQN_I2SAC97TX_AMERALD PMU_REQN_I2SAC97TX_AMERALD
+ #define DMAC_REQN_I2SAC97RX_AMERALD PMU_REQN_I2SAC97RX_AMERALD
+ #define DMAC_REQN_USB PMU_REQN_USB
+ #define DMAC_REQN_EXT0 PMU_REQN_EXT0
+ #define DMAC_REQN_EXT1 PMU_REQN_EXT1
+ #define DMAC_REQN_MAX PMU_REQN_MAX
+#endif
+#define DMAC_CFG_INT_LLPCNT_MASK 0x000f0000
+#define DMAC_CFG_INT_LLPCNT_SHIFT 16
+
+/* DMA channel 0~n Linked List Descriptor Registers (CH[n]_BASE + 0x10) */
+#define DMAC_LLP_ADDR_MASK 0xfffffffc
+#define DMAC_LLP_ADDR_SHIFT 2
+#define DMAC_LLP_MASTER_MASK 0x00000001
+#define DMAC_LLP_MASTER_BIT 0
+ #define DMAC_LLP_MASTER_0 0
+ #define DMAC_LLP_MASTER_1 1
+
+/* DMA channel 0~3 Transfer Size Registers (CH[n]_BASE + 0x14) */
+#define DMAC_TOT_SIZE_MASK 0x003fffff
+#define DMAC_TOT_SIZE_SHIFT 0
+
+
+/*****************************************************************************
+ * APBBR - AG101 AHB to APB Bridge
+*****************************************************************************/
+/* Device base address */
+#ifdef CONFIG_PLAT_AG102
+#define APBBR_BASE APBBR_VA_BASE
+#else
+#define APBBR_BASE APBBRG_FTAPBBRG020S_0_VA_BASE
+#endif
+
+/* DMA channel A registers (32-bit width) */
+#define APBBR_DMAA_BASE (APBBR_BASE + 0x80)
+#define APBBR_DMAB_BASE (APBBR_BASE + 0x90)
+#define APBBR_DMAC_BASE (APBBR_BASE + 0xa0)
+#define APBBR_DMAD_BASE (APBBR_BASE + 0xb0)
+
+#define APBBR_DMA_MAX_CHANNELS APBBRG_FTAPBBRG020S_IRQ_COUNT
+/* n = 0 ~ APBBRG_FTAPBBRG020S_IRQ_COUNT */
+#define APBBR_DMA_BASE_CH(n) (APBBR_DMAA_BASE + \
+ (APBBR_DMAB_BASE - APBBR_DMAA_BASE) * \
+ (addr_t)(n))
+
+#define APBBR_DMA_SAD_OFFSET 0x00
+#define APBBR_DMA_DAD_OFFSET 0x04
+#define APBBR_DMA_CYC_OFFSET 0x08
+#define APBBR_DMA_CMD_OFFSET 0x0c
+
+
+/*****************************************************************************
+ * APBBR defs - AG101 AHB to APB Bridge
+*****************************************************************************/
+
+/* APBBR slave#n (n = 1~6, 8, 11, 16~23) base/size register */
+#define APBBR_SLAVE_SIZE_MASK 0x000f0000 /* Size of address space */
+#define APBBR_SLAVE_SIZE_SHIFT 16
+ #define APBBR_SIZE_1M 0
+ #define APBBR_SIZE_2M 1
+ #define APBBR_SIZE_4M 2
+ #define APBBR_SIZE_8M 3
+ #define APBBR_SIZE_16M 4
+ #define APBBR_SIZE_32M 5
+ #define APBBR_SIZE_64M 6
+ #define APBBR_SIZE_128M 7
+ #define APBBR_SIZE_256M 8
+
+#define APBBR_SLAVE_BASE_MASK 0x3ff00000
+#define APBBR_SLAVE_BASE_SHIFT 20
+
+/* APBBR DMA channel transfer cycles register
+ * DMA cycles (data size), 1 or 4 bus data transfer cycles per DMA cycle
+ * => transfer size = cycles * data_width * burst(1 or 4)
+ * so, max = 16M*4*4 = 256M
+ */
+#define APBBR_DMA_CYC_MASK 0x00ffffff
+#define APBBR_DMA_CYC_SHIFT 0
+
+/* APBBR DMA channel command register */
+#define APBBR_DMA_CHEN_MASK 0x00000001
+#define APBBR_DMA_CHEN_BIT 0
+
+#define APBBR_DMA_FINTST_MASK 0x00000002
+#define APBBR_DMA_FINTST_BIT 1
+#define APBBR_DMA_FINTEN_MASK 0x00000004
+#define APBBR_DMA_FINTEN_BIT 2
+
+#define APBBR_DMA_BURST_MASK 0x00000008
+#define APBBR_DMA_BURST_BIT 3
+
+#define APBBR_DMA_ERRINTST_MASK 0x00000010
+#define APBBR_DMA_ERRINTST_BIT 4
+#define APBBR_DMA_ERRINTEN_MASK 0x00000020
+#define APBBR_DMA_ERRINTEN_BIT 5
+
+#define APBBR_DMA_SRCADDRSEL_MASK 0x00000040
+#define APBBR_DMA_SRCADDRSEL_BIT 6
+#define APBBR_DMA_DSTADDRSEL_MASK 0x00000080
+#define APBBR_DMA_DSTADDRSEL_BIT 7
+ #define APBBR_ADDRSEL_APB 0
+ #define APBBR_ADDRSEL_AHB 1
+
+#define APBBR_DMA_SRCADDRINC_MASK 0x00000700
+#define APBBR_DMA_SRCADDRINC_SHIFT 8
+#define APBBR_DMA_DSTADDRINC_MASK 0x00007000
+#define APBBR_DMA_DSTADDRINC_SHIFT 12
+ #define APBBR_ADDRINC_FIXED 0 /* no increment */
+ #define APBBR_ADDRINC_I1X 1 /* +1, +4 (burst) */
+ #define APBBR_ADDRINC_I2X 2 /* +2, +8 (burst) */
+ #define APBBR_ADDRINC_I4X 3 /* +4, +16 (burst) */
+ #define APBBR_ADDRINC_D1 5 /* -1 */
+ #define APBBR_ADDRINC_D2 6 /* -2 */
+ #define APBBR_ADDRINC_D4 7 /* -4 */
+
+#define APBBR_DMA_DREQSEL_MASK 0x000f0000
+#define APBBR_DMA_DREQSEL_SHIFT 16
+#define APBBR_DMA_SREQSEL_MASK 0x0f000000
+#define APBBR_DMA_SREQSEL_SHIFT 24
+
+#ifdef CONFIG_PLAT_AG102
+ #define APBBR_REQN_NONE 0
+ #define APBBR_REQN_CFC 1
+ #define APBBR_REQN_SSP 2
+ #define APBBR_REQN_SDC 8
+ #define APBBR_REQN_I2SAC97TX 6
+ #define APBBR_REQN_SSP2 8
+ #define APBBR_REQN_STUART 9
+ #define APBBR_REQN_BTUART 10
+ #define APBBR_REQN_IRDA 11
+ #define APBBR_REQN_SMMC 12
+// #define APBBR_REQN_USB 0
+ #define APBBR_REQN_I2SAC97RX 13
+ #define APBBR_REQN_FUSB220 14
+ #define APBBR_REQN_MMSC 15
+ #define APBBR_REQN_MAX 15
+#else
+ #define APBBR_REQN_NONE 0
+ #define APBBR_REQN_CFC 1
+ #define APBBR_REQN_SSP 2
+ #define APBBR_REQN_SDC 5
+/* for amerald sd */
+ #define APBBR_REQN_SDC_AMERALD 7
+/* for amerald ac97 ssp2 */
+ #define APBBR_REQN_I2SAC97TX_AMERALD 8
+ #define APBBR_REQN_I2SAC97RX_AMERALD 9
+
+ #define APBBR_REQN_I2SAC97TX 6
+ #define APBBR_REQN_SSP2 8
+ #define APBBR_REQN_STUART 9 /* UART1 ? */
+ #define APBBR_REQN_BTUART 10 /* UART2 ? */
+ #define APBBR_REQN_IRDA 11
+ #define APBBR_REQN_SMMC 12
+ //#define APBBR_REQN_USB 13
+ #define APBBR_REQN_I2SAC97RX 13
+ #define APBBR_REQN_FUSB220 14
+ #define APBBR_REQN_MMSC 15
+ #define APBBR_REQN_MAX 15
+#endif
+
+#define APBBR_DMA_DATAWIDTH_MASK 0x00300000 /* Data width of transfer */
+#define APBBR_DMA_DATAWIDTH_SHIFT 20
+ #define APBBR_DATAWIDTH_4 0 /* word */
+ #define APBBR_DATAWIDTH_2 1 /* half-word */
+ #define APBBR_DATAWIDTH_1 2 /* byte */
+
+#ifdef CONFIG_PLATFORM_APBDMA
+#define APBBR_DMA_CYCLE_TO_BYTES(cycle, width) ((cycle) << (2-(width)))
+#define APBBR_DMA_BYTES_TO_CYCLE(bytes, width) ((bytes) >> (2-(width)))
+#else
+#define APBBR_DMA_CYCLE_TO_BYTES(cycle, width) 0
+#define APBBR_DMA_BYTES_TO_CYCLE(bytes, width) 0
+#endif /* CONFIG_PLATFORM_APBDMA */
+
+
+#ifdef CONFIG_PLAT_AG102
+
+/*****************************************************************************
+ * PCU - AG102 Core APB
+*****************************************************************************/
+/* Device base address */
+#define PCU_BASE PCU_VA_BASE
+/* PMU registers (32-bit width) */
+/* Add by Dennis on 2011.03.09 */
+#define PCU_DMA_SEL (PCU_BASE+ 0x38)
+
+#else /* CONFIG_PLAT_AG102 */
+
+/*****************************************************************************
+ * PMU - AG101 Core APB
+*****************************************************************************/
+/* Device base address */
+#define PMU_BASE PMU_FTPMU010_0_VA_BASE
+
+/* PMU registers (32-bit width) */
+#define PMU_AHBDMA_REQACK (PMU_BASE + 0x90)
+
+#define PMU_CFC_REQACK_CFG (PMU_BASE + 0xa0)
+#define PMU_SSP1_REQACK_CFG (PMU_BASE + 0xa4)
+#define PMU_UART1TX_REQACK_CFG (PMU_BASE + 0xa8)
+#define PMU_UART1RX_REQACK_CFG (PMU_BASE + 0xac)
+#define PMU_UART2TX_REQACK_CFG (PMU_BASE + 0xb0)
+#define PMU_UART2RX_REQACK_CFG (PMU_BASE + 0xb4)
+#define PMU_SDC_REQACK_CFG (PMU_BASE + 0xb8)
+#define PMU_I2SAC97TX_REQACK_CFG (PMU_BASE + 0xbc)
+#define PMU_I2SAC97RX_REQACK_CFG (PMU_BASE + 0xc4)
+#define PMU_UART3TX_REQACK_CFG (PMU_BASE + 0xc0)
+#define PMU_UART3RX_REQACK_CFG (PMU_BASE + 0xcc)
+#define PMU_USB_REQACK_CFG (PMU_BASE + 0xc8)
+#define PMU_IRDA_REQACK_CFG (PMU_BASE + 0xd0)
+#define PMU_EXT0_REQACK_CFG (PMU_BASE + 0xd4)
+#define PMU_EXT1_REQACK_CFG (PMU_BASE + 0xd8)
+
+
+/*****************************************************************************
+ * PMU - AG101 Core APB
+*****************************************************************************/
+
+/* Driving capability and slew rate control register 2 (+0x48) */
+#define PMU_STUART_DCSR_MASK 0x0000000f
+#define PMU_STUART_DCSR_SHIFT 0
+#define PMU_BTUART_DCSR_MASK 0x00000f00
+#define PMU_BTUART_DCSR_SHIFT 8
+/*#define PMU_FFUART_DCSR_MASK 0x0000f000*/
+/*#define PMU_FFUART_DCSR_SHIFT 12 */
+#define PMU_PMU_DCSR_MASK 0x000f0000
+#define PMU_PMU_DCSR_SHIFT 16
+#define PMU_I2SAC97_DCSR_MASK 0x00f00000
+#define PMU_I2SAC97_DCSR_SHIFT 20
+#define PMU_SSP_DCSR_MASK 0x0f000000
+#define PMU_SSP_DCSR_SHIFT 24
+#define PMU_SD_DCSR_MASK 0xf0000000
+#define PMU_SD_DCSR_SHIFT 28
+
+/* AHB DMA REQ/ACK connection configuration status register (+0x90) */
+#define PMU_CH0_REQACK_MASK 0x0000000f
+#define PMU_CH0_REQACK_SHIFT 0
+#define PMU_CH1_REQACK_MASK 0x000000f0
+#define PMU_CH1_REQACK_SHIFT 4
+#define PMU_CH2_REQACK_MASK 0x00000f00
+#define PMU_CH2_REQACK_SHIFT 8
+#define PMU_CH3_REQACK_MASK 0x0000f000
+#define PMU_CH3_REQACK_SHIFT 12
+#define PMU_CH4_REQACK_MASK 0x000f0000
+#define PMU_CH4_REQACK_SHIFT 16
+#define PMU_CH5_REQACK_MASK 0x00f00000
+#define PMU_CH5_REQACK_SHIFT 20
+#define PMU_CH6_REQACK_MASK 0x0f000000
+#define PMU_CH6_REQACK_SHIFT 24
+#define PMU_CH7_REQACK_MASK 0xf0000000
+#define PMU_CH7_REQACK_SHIFT 28
+
+ #define PMU_REQN_NONE 0
+ #define PMU_REQN_CFC 1
+ #define PMU_REQN_SSP 2
+ #define PMU_REQN_UART1TX 3
+ #define PMU_REQN_UART1RX 4
+ #define PMU_REQN_UART2TX 5
+ #define PMU_REQN_UART2RX 6
+ #define PMU_REQN_SDC 7
+ #define PMU_REQN_I2SAC97TX 8
+ #define PMU_REQN_I2SAC97RX 10
+/* for amerald ac97 ssp2 */
+ #define PMU_REQN_I2SAC97TX_AMERALD 8
+ #define PMU_REQN_I2SAC97RX_AMERALD 9
+ #define PMU_REQN_USB 11
+ #define PMU_REQN_EXT0 14
+ #define PMU_REQN_EXT1 15
+ #define PMU_REQN_MAX 15
+
+/* CFC ..., etc, REQ/ACK connection configuration registers (0xa0 ~ 0xd8) */
+#define PMU_CHANNEL_MASK 0x00000007
+#define PMU_CHANNEL_SHIFT 0
+#define PMU_DMACUSED_MASK 0x00000008
+#define PMU_DMACUSED_BIT 3
+
+#endif /* CONFIG_PLAT_AG102 */
+
+
+/*****************************************************************************
+ * DMAD globals section
+ */
+
+enum DMAD_DMAC_CORE {
+ DMAD_DMAC_AHB_CORE,
+ DMAD_DMAC_APB_CORE
+};
+
+enum DMAD_CHREG_FLAGS {
+ DMAD_FLAGS_NON_BLOCK = 0x00000000,
+ DMAD_FLAGS_SLEEP_BLOCK = 0x00000001,
+ DMAD_FLAGS_SPIN_BLOCK = 0x00000002,
+ DMAD_FLAGS_RING_MODE = 0x00000008, /* ring submission mode */
+ DMAD_FLAGS_BIDIRECTION = 0x00000010, /* indicates both tx and rx */
+};
+
+enum DMAD_CHDIR
+{
+ DMAD_DIR_A0_TO_A1 = 0,
+ DMAD_DIR_A1_TO_A0 = 1,
+};
+
+/* AHB Channel Request
+ *
+ * Notes for developers:
+ * These should be channel-only properties. Controller-specific properties
+ * should be separated as other driver structure or driver buildin-hardcode.
+ * If controller properties are embeded in this union, request for a channel
+ * may unexpectedly override the controller setting of the request of other
+ * channels.
+ */
+typedef struct dmad_ahb_chreq
+{
+ /* channel property */
+ u32 sync; /* (in) different clock domain */
+ u32 priority; /* (in) DMAC_CSR_CHPRI_xxx */
+ u32 hw_handshake; /* (in) hardware handshaking on/off */
+ u32 burst_size; /* (in) DMAC_CSR_SIZE_xxx */
+
+ /* source property */
+ union {
+ u32 src_width; /* (in) DMAC_CSR_WIDTH_xxx */
+ u32 addr0_width; /* (in) bi-direction mode alias */
+ u32 ring_width; /* (in) ring-mode alias */
+ };
+ union {
+ u32 src_ctrl; /* (in) DMAC_CSR_AD_xxx */
+ u32 addr0_ctrl; /* (in) bi-direction mode alias */
+ u32 ring_ctrl; /* (in) ring-mode alias */
+ };
+ union {
+ u32 src_reqn; /* (in) DMAC_REQN_xxx */
+ u32 addr0_reqn; /* (in) bi-direction mode alias */
+ u32 ring_reqn; /* (in) ring-mode alias */
+ };
+
+ /* destination property */
+ union {
+ u32 dst_width; /* (in) DMAC_CSR_WIDTH_xxx */
+ u32 addr1_width; /* (in) bi-direction mode alias */
+ u32 dev_width; /* (in) ring-mode alias */
+ };
+ union {
+ u32 dst_ctrl; /* (in) DMAC_CSR_AD_xxx */
+ u32 addr1_ctrl; /* (in) bi-direction mode alias */
+ u32 dev_ctrl; /* (in) ring-mode alias */
+ };
+ union {
+ u32 dst_reqn; /* (in) DMAC_REQN_xxx */
+ u32 addr1_reqn; /* (in) bi-direction mode alias */
+ u32 dev_reqn; /* (in) ring-mode alias */
+ };
+
+ /* (in) transfer direction, valid only if following flags were set ...
+ * DMAD_FLAGS_BIDIRECTION or
+ * DMAD_FLAGS_RING_MODE
+ * value:
+ * 0 (addr0 -> addr1, or ring-buff to device)
+ * 1 (addr0 <- addr1, or device to ring-buff)
+ */
+ u32 tx_dir;
+
+} dmad_ahb_chreq;
+
+/* APB Channel Request
+ *
+ * Notes for developers:
+ * These should be channel-only properties. Controller-specific properties
+ * should be separated as other driver structure or driver buildin-hardcode.
+ * If controller properties are embeded in this union, request for a channel
+ * may unexpectedly override the controller setting of the request of other
+ * channels.
+ */
+typedef struct dmad_apb_chreq
+{
+ /* controller property (removed! should not exist in this struct) */
+
+ /* channel property */
+ u32 burst_mode; /* (in) Burst mode (0/1) */
+ u32 data_width; /* (in) APBBR_DATAWIDTH_xxx */
+
+ /* source property */
+ union {
+ u32 src_ctrl; /* (in) APBBR_ADDRINC_xxx */
+ u32 addr0_ctrl; /* (in) bi-direction mode alias */
+ u32 ring_ctrl; /* (in) ring-mode alias */
+ };
+ union {
+ u32 src_reqn; /* (in) APBBR_REQN_xxx */
+ u32 addr0_reqn; /* (in) bi-direction mode alias */
+ u32 ring_reqn; /* (in) ring-mode alias */
+ };
+
+ /* destination property */
+ union {
+ u32 dst_ctrl; /* (in) APBBR_ADDRINC_xxx */
+ u32 addr1_ctrl; /* (in) bi-direction mode alias */
+ u32 dev_ctrl; /* (in) ring-mode alias */
+ };
+ union {
+ u32 dst_reqn; /* (in) APBBR_REQN_xxx */
+ u32 addr1_reqn; /* (in) bi-direction mode alias */
+ u32 dev_reqn; /* (in) ring-mode alias */
+ };
+
+ /* (in) transfer direction, valid only if following flags were set ...
+ * DMAD_FLAGS_BIDIRECTION or
+ * DMAD_FLAGS_RING_MODE
+ * value:
+ * 0 (addr0 -> addr1, or ring-buff to device)
+ * 1 (addr0 <- addr1, or device to ring-buff)
+ */
+ u32 tx_dir;
+
+} dmad_apb_chreq;
+
+/* Channel Request Descriptor */
+typedef struct dmad_chreq
+{
+ /* common fields */
+ u32 controller; /* (in) enum DMAD_DMAC_CORE */
+ u32 flags; /* (in) enum DMAD_CHREQ_FLAGS */
+
+ /**********************************************************************
+ * ring mode specific fields (valid only for DMAD_FLAGS_RING_MODE)
+ * note:
+ * - size fields are in unit of data width
+ * * for AHB, ring size is limited to 4K * data_width of data if
+ * hw-LLP is not used
+ * * for AHB, ring size is limited to 4K * data_width * LLP-count
+ * hw-if LLP is used
+ * * for APB, ring size is limited to 16M * data_width of data
+ * - currently sw ring mode dma supports only fixed or incremental
+ * src/dst addressing
+ * - ring_size shoule >= periods * period_size
+ */
+ dma_addr_t ring_base; /* (in) ring buffer base (pa) */
+ dma_addr_t ring_size; /* (in) unit of data width */
+ addr_t dev_addr; /* (in) device data port address */
+ dma_addr_t periods; /* (in) number of ints per ring */
+ dma_addr_t period_size; /* (in) size per int, data-width */
+
+
+ /* channel-wise completion callback - called when hw-ptr catches sw-ptr
+ * (i.e., channel stops)
+ *
+ * completion_cb: (in) client supplied callback function, executed in
+ * interrupt context.
+ * completion_data: (in) client private data to be passed to data
+ * argument of completion_cb().
+ */
+ void (*completion_cb)(int channel, u16 status, void *data);
+ void *completion_data;
+ /*********************************************************************/
+
+ /* channel allocation output */
+ u32 channel; /* (out) allocated channel */
+ void *drq; /* (out) internal use (DMAD_DRQ *)*/
+
+ /* channel-alloc parameters (channel-wise properties) */
+ union {
+#ifdef CONFIG_PLATFORM_AHBDMA
+ dmad_ahb_chreq ahb_req; /* (in) for AHB DMA parameters */
+#endif
+#ifdef CONFIG_PLATFORM_APBDMA
+ dmad_apb_chreq apb_req; /* (in) APB Bridge DMA params */
+#endif
+ };
+
+} dmad_chreq;
+
+/* drb states are mutual exclusive */
+enum DMAD_DRB_STATE
+{
+ DMAD_DRB_STATE_FREE = 0,
+ DMAD_DRB_STATE_READY = 0x00000001,
+ DMAD_DRB_STATE_SUBMITTED = 0x00000002,
+ DMAD_DRB_STATE_EXECUTED = 0x00000004,
+ DMAD_DRB_STATE_COMPLETED = 0x00000008,
+ //DMAD_DRB_STATE_ERROR = 0x00000010,
+ DMAD_DRB_STATE_ABORT = 0x00000020,
+};
+
+/* DMA request block
+ * todo: replaced link with kernel struct list_head ??
+ */
+typedef struct dmad_drb
+{
+ u32 prev; /* (internal) previous node */
+ u32 next; /* (internal) next node */
+ u32 node; /* (internal) this node */
+
+ u32 state; /* (out) DRB's current state */
+
+ union {
+ dma_addr_t src_addr; /* (in) source pa */
+ dma_addr_t addr0; /* (in) bi-direction mode alias */
+ };
+
+ union {
+ dma_addr_t dst_addr; /* (in) destination pa */
+ dma_addr_t addr1; /* (in) bi-direction mode alias */
+ };
+
+ /* (in) AHB DMA (22 bits): 0 ~ 4M-1, unit is "data width"
+ * APB DMA (24 bits): 0 ~ 16M-1, unit is "data width * burst size"
+ * => for safe without mistakes, use dmad_make_req_cycles() to
+ * compose this value if the addressing mode is incremental
+ * mode (not working yet for decremental mode).
+ */
+ dma_addr_t req_cycle;
+
+ /* (in) if non-null, this sync object will be signaled upon dma
+ * completion (for blocked-waiting dma completion)
+ */
+ struct completion *sync;
+
+} dmad_drb;
+
+
+/******************************************************************************
+ * Debug Trace Mechanism
+ */
+#if (DMAD_ERROR_TRACE)
+#define dmad_err(format, arg...) printk(KERN_ERR format , ## arg)
+#else
+#define dmad_err(format, arg...) (void)(0)
+#endif
+
+#if (DMAD_DEBUG_TRACE)
+#define dmad_dbg(format, arg...) printk(KERN_INFO format , ## arg)
+#else
+#define dmad_dbg(format, arg...) (void)(0)
+#endif
+
+#if (defined(CONFIG_PLATFORM_AHBDMA) || defined(CONFIG_PLATFORM_APBDMA))
+
+/******************************************************************************
+ * DMAD Driver Interface
+******************************************************************************/
+
+extern int dmad_channel_alloc(dmad_chreq *ch_req);
+extern int dmad_channel_free(dmad_chreq *ch_req);
+extern int dmad_channel_enable(const dmad_chreq *ch_req, u8 enable);
+extern u32 dmad_max_size_per_drb(dmad_chreq *ch_req);
+extern u32 dmad_bytes_to_cycles(dmad_chreq *ch_req, u32 byte_size);
+
+extern int dmad_kickoff_requests(dmad_chreq *ch_req);
+extern int dmad_drain_requests(dmad_chreq *ch_req, u8 shutdown);
+
+/* for performance reason, these two functions are platform-specific */
+#ifdef CONFIG_PLATFORM_AHBDMA
+extern int dmad_probe_irq_source_ahb(void);
+#endif
+#ifdef CONFIG_PLATFORM_APBDMA
+extern int dmad_probe_irq_source_apb(void);
+#endif
+
+/* note: hw_ptr here is phyical address of dma source or destination */
+extern dma_addr_t dmad_probe_hw_ptr_src(dmad_chreq *ch_req);
+extern dma_addr_t dmad_probe_hw_ptr_dst(dmad_chreq *ch_req);
+
+/*****************************************************************************
+ * routines only valid in discrete (non-ring) mode
+ */
+extern int dmad_config_channel_dir(dmad_chreq *ch_req, u8 dir);
+extern int dmad_alloc_drb(dmad_chreq *ch_req, dmad_drb **drb);
+extern int dmad_free_drb(dmad_chreq *ch_req, dmad_drb *drb);
+extern int dmad_submit_request(dmad_chreq *ch_req,
+ dmad_drb *drb, u8 keep_fired);
+extern int dmad_withdraw_request(dmad_chreq *ch_req, dmad_drb *drb);
+/****************************************************************************/
+
+/*****************************************************************************
+ * routines only valid in ring mode
+ * note: sw_ptr and hw_ptr are values offset from the ring buffer base
+ * unit of sw_ptr is data-width
+ * unit of hw_ptr returned is byte
+ */
+extern int dmad_update_ring(dmad_chreq *ch_req);
+extern int dmad_update_ring_sw_ptr(dmad_chreq *ch_req,
+ dma_addr_t sw_ptr, u8 keep_fired);
+extern dma_addr_t dmad_probe_ring_hw_ptr(dmad_chreq *ch_req);
+/****************************************************************************/
+
+#else /* CONFIG_PLATFORM_AHBDMA || CONFIG_PLATFORM_APBDMA */
+
+static inline int dmad_channel_alloc(dmad_chreq *ch_req) { return -EFAULT; }
+static inline int dmad_channel_free(dmad_chreq *ch_req) { return -EFAULT; }
+static inline int dmad_channel_enable(const dmad_chreq *ch_req, u8 enable)
+ { return -EFAULT; }
+static inline u32 dmad_max_size_per_drb(dmad_chreq *ch_req) { return 0; }
+static inline u32 dmad_bytes_to_cycles(dmad_chreq *ch_req, u32 byte_size)
+ { return 0; }
+static inline int dmad_kickoff_requests(dmad_chreq *ch_req) { return -EFAULT; }
+static inline int dmad_drain_requests(dmad_chreq *ch_req, u8 shutdown)
+ { return -EFAULT; }
+static inline int dmad_probe_irq_source_ahb(void) { return -EFAULT; }
+static inline int dmad_probe_irq_source_apb(void) { return -EFAULT; }
+static inline dma_addr_t dmad_probe_hw_ptr_src(dmad_chreq *ch_req)
+ { return (dma_addr_t)NULL; }
+static inline dma_addr_t dmad_probe_hw_ptr_dst(dmad_chreq *ch_req)
+ { return (dma_addr_t)NULL; }
+static inline int dmad_config_channel_dir(dmad_chreq *ch_req, u8 dir)
+ { return -EFAULT; }
+static inline int dmad_alloc_drb(dmad_chreq *ch_req, dmad_drb **drb)
+ { return -EFAULT; }
+static inline int dmad_free_drb(dmad_chreq *ch_req, dmad_drb *drb)
+ { return -EFAULT; }
+static inline int dmad_submit_request(dmad_chreq *ch_req,
+ dmad_drb *drb, u8 keep_fired) { return -EFAULT; }
+static inline int dmad_withdraw_request(dmad_chreq *ch_req, dmad_drb *drb)
+ { return -EFAULT; }
+static inline int dmad_update_ring(dmad_chreq *ch_req)
+ { return -EFAULT; }
+static inline int dmad_update_ring_sw_ptr(dmad_chreq *ch_req,
+ dma_addr_t sw_ptr, u8 keep_fired) { return -EFAULT; }
+static inline dma_addr_t dmad_probe_ring_hw_ptr(dmad_chreq *ch_req)
+ { return (dma_addr_t)NULL; }
+
+#endif /* CONFIG_PLATFORM_AHBDMA || CONFIG_PLATFORM_APBDMA */
+
+#endif /* __NDS_DMAD_INC__ */
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/dma.h linux-3.4.113/arch/nds32/include/asm/dma.h
--- linux-3.4.113.orig/arch/nds32/include/asm/dma.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/dma.h 2016-12-01 20:59:24.336612134 +0100
@@ -0,0 +1,17 @@
+/*
+ * linux/arch/nds32/include/asm/dma.h
+ * Copyright (C) 2008 Andes Technology Corporation
+ */
+
+#ifndef __NDS32_DMA_H__
+#define __NDS32_DMA_H__
+
+#define MAX_DMA_ADDRESS 0xffffffff
+
+#ifdef CONFIG_PCI
+extern int isa_dma_bridge_buggy;
+#else
+#define isa_dma_bridge_buggy (0)
+#endif
+
+#endif
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/dma-mapping.h linux-3.4.113/arch/nds32/include/asm/dma-mapping.h
--- linux-3.4.113.orig/arch/nds32/include/asm/dma-mapping.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/dma-mapping.h 2016-12-01 20:59:24.336612134 +0100
@@ -0,0 +1,453 @@
+/*
+ * linux/arch/nds32/include/asm/dma-mapping.h
+ * Copyright (C) 2008 Andes Technology Corporation
+ */
+
+#ifndef ASMNDS32_DMA_MAPPING_H
+#define ASMNDS32_DMA_MAPPING_H
+
+#ifdef __KERNEL__
+
+#include <linux/mm.h> /* need struct page */
+#include <linux/highmem.h>
+
+#include <asm/scatterlist.h>
+
+/*
+ * DMA-consistent mapping functions. These allocate/free a region of
+ * uncached, unwrite-buffered mapped memory space for use with DMA
+ * devices. This is the "generic" version. The PCI specific version
+ * is in pci.h
+ */
+extern void consistent_sync(void *kaddr, size_t size, int rw);
+
+/*
+ * Return whether the given device DMA address mask can be supported
+ * properly. For example, if your device can only drive the low 24-bits
+ * during bus mastering, then you would pass 0x00ffffff as the mask
+ * to this function.
+ */
+static inline int dma_supported(struct device *dev, u64 mask)
+{
+ return dev->dma_mask && *dev->dma_mask != 0;
+}
+
+static inline int dma_set_mask(struct device *dev, u64 dma_mask)
+{
+ if (!dev->dma_mask || !dma_supported(dev, dma_mask))
+ return -EIO;
+
+ *dev->dma_mask = dma_mask;
+
+ return 0;
+}
+
+static inline int dma_is_consistent(dma_addr_t handle)
+{
+ return 0;
+}
+
+/*
+ * DMA errors are defined by all-bits-set in the DMA address.
+ */
+static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
+{
+ return dma_addr == ~0;
+}
+
+/*
+ * Dummy noncoherent implementation. We don't provide a dma_cache_sync
+ * function so drivers using this API are highlighted with build warnings.
+ */
+static inline void *
+dma_alloc_noncoherent(struct device *dev, size_t size, dma_addr_t *handle, gfp_t gfp)
+{
+ return NULL;
+}
+
+static inline void
+dma_free_noncoherent(struct device *dev, size_t size, void *cpu_addr,
+ dma_addr_t handle)
+{
+}
+
+/**
+ * dma_alloc_coherent - allocate consistent memory for DMA
+ * @dev: valid struct device pointer, or NULL for ISA and EISA-like devices
+ * @size: required memory size
+ * @handle: bus-specific DMA address
+ *
+ * Allocate some uncached, unbuffered memory for a device for
+ * performing DMA. This function allocates pages, and will
+ * return the CPU-viewed address, and sets @handle to be the
+ * device-viewed address.
+ */
+extern void *
+dma_alloc_coherent(struct device *dev, size_t size, dma_addr_t *handle, gfp_t gfp);
+
+/**
+ * dma_free_coherent - free memory allocated by dma_alloc_coherent
+ * @dev: valid struct device pointer, or NULL for ISA and EISA-like devices
+ * @size: size of memory originally requested in dma_alloc_coherent
+ * @cpu_addr: CPU-view address returned from dma_alloc_coherent
+ * @handle: device-view address returned from dma_alloc_coherent
+ *
+ * Free (and unmap) a DMA buffer previously allocated by
+ * dma_alloc_coherent().
+ *
+ * References to memory and mappings associated with cpu_addr/handle
+ * during and after this call executing are illegal.
+ */
+extern void
+dma_free_coherent(struct device *dev, size_t size, void *cpu_addr,
+ dma_addr_t handle);
+
+/**
+ * dma_mmap_coherent - map a coherent DMA allocation into user space
+ * @dev: valid struct device pointer, or NULL for ISA and EISA-like devices
+ * @vma: vm_area_struct describing requested user mapping
+ * @cpu_addr: kernel CPU-view address returned from dma_alloc_coherent
+ * @handle: device-view address returned from dma_alloc_coherent
+ * @size: size of memory originally requested in dma_alloc_coherent
+ *
+ * Map a coherent DMA buffer previously allocated by dma_alloc_coherent
+ * into user space. The coherent DMA buffer must not be freed by the
+ * driver until the user space mapping has been released.
+ */
+int dma_mmap_coherent(struct device *dev, struct vm_area_struct *vma,
+ void *cpu_addr, dma_addr_t handle, size_t size);
+
+
+/**
+ * dma_alloc_writecombine - allocate writecombining memory for DMA
+ * @dev: valid struct device pointer, or NULL for ISA and EISA-like devices
+ * @size: required memory size
+ * @handle: bus-specific DMA address
+ *
+ * Allocate some uncached, buffered memory for a device for
+ * performing DMA. This function allocates pages, and will
+ * return the CPU-viewed address, and sets @handle to be the
+ * device-viewed address.
+ */
+extern void *
+dma_alloc_writecombine(struct device *dev, size_t size, dma_addr_t *handle, gfp_t gfp);
+
+#define dma_free_writecombine(dev,size,cpu_addr,handle) \
+ dma_free_coherent(dev,size,cpu_addr,handle)
+
+int dma_mmap_writecombine(struct device *dev, struct vm_area_struct *vma,
+ void *cpu_addr, dma_addr_t handle, size_t size);
+
+
+/**
+ * dma_map_single - map a single buffer for streaming DMA
+ * @dev: valid struct device pointer, or NULL for ISA and EISA-like devices
+ * @cpu_addr: CPU direct mapped address of buffer
+ * @size: size of buffer to map
+ * @dir: DMA transfer direction
+ *
+ * Ensure that any data held in the cache is appropriately discarded
+ * or written back.
+ *
+ * The device owns this memory once this call has completed. The CPU
+ * can regain ownership by calling dma_unmap_single() or
+ * dma_sync_single_for_cpu().
+ */
+#ifndef CONFIG_DMABOUNCE
+static inline dma_addr_t
+dma_map_single(struct device *dev, void *cpu_addr, size_t size,
+ enum dma_data_direction dir)
+{
+ consistent_sync(cpu_addr, size, dir);
+ return virt_to_dma(dev, (unsigned long)cpu_addr);
+}
+#else
+extern dma_addr_t dma_map_single(struct device *,void *, size_t, enum dma_data_direction);
+#endif
+
+/**
+ * dma_map_page - map a portion of a page for streaming DMA
+ * @dev: valid struct device pointer, or NULL for ISA and EISA-like devices
+ * @page: page that buffer resides in
+ * @offset: offset into page for start of buffer
+ * @size: size of buffer to map
+ * @dir: DMA transfer direction
+ *
+ * Ensure that any data held in the cache is appropriately discarded
+ * or written back.
+ *
+ * The device owns this memory once this call has completed. The CPU
+ * can regain ownership by calling dma_unmap_page() or
+ * dma_sync_single_for_cpu().
+ */
+static inline dma_addr_t
+dma_map_page(struct device *dev, struct page *page,
+ unsigned long offset, size_t size,
+ enum dma_data_direction dir)
+{
+ return dma_map_single(dev, page_address(page) + offset, size, (int)dir);
+}
+
+/**
+ * dma_unmap_single - unmap a single buffer previously mapped
+ * @dev: valid struct device pointer, or NULL for ISA and EISA-like devices
+ * @handle: DMA address of buffer
+ * @size: size of buffer to map
+ * @dir: DMA transfer direction
+ *
+ * Unmap a single streaming mode DMA translation. The handle and size
+ * must match what was provided in the previous dma_map_single() call.
+ * All other usages are undefined.
+ *
+ * After this call, reads by the CPU to the buffer are guaranteed to see
+ * whatever the device wrote there.
+ */
+#ifndef CONFIG_DMABOUNCE
+static inline void
+dma_unmap_single(struct device *dev, dma_addr_t handle, size_t size,
+ enum dma_data_direction dir)
+{
+ /* nothing to do */
+}
+#else
+extern void dma_unmap_single(struct device *, dma_addr_t, size_t, enum dma_data_direction);
+#endif
+
+/**
+ * dma_unmap_page - unmap a buffer previously mapped through dma_map_page()
+ * @dev: valid struct device pointer, or NULL for ISA and EISA-like devices
+ * @handle: DMA address of buffer
+ * @size: size of buffer to map
+ * @dir: DMA transfer direction
+ *
+ * Unmap a single streaming mode DMA translation. The handle and size
+ * must match what was provided in the previous dma_map_single() call.
+ * All other usages are undefined.
+ *
+ * After this call, reads by the CPU to the buffer are guaranteed to see
+ * whatever the device wrote there.
+ */
+static inline void
+dma_unmap_page(struct device *dev, dma_addr_t handle, size_t size,
+ enum dma_data_direction dir)
+{
+ dma_unmap_single(dev, handle, size, (int)dir);
+}
+
+/**
+ * dma_map_sg - map a set of SG buffers for streaming mode DMA
+ * @dev: valid struct device pointer, or NULL for ISA and EISA-like devices
+ * @sg: list of buffers
+ * @nents: number of buffers to map
+ * @dir: DMA transfer direction
+ *
+ * Map a set of buffers described by scatterlist in streaming
+ * mode for DMA. This is the scatter-gather version of the
+ * above dma_map_single interface. Here the scatter gather list
+ * elements are each tagged with the appropriate dma address
+ * and length. They are obtained via sg_dma_{address,length}(SG).
+ *
+ * NOTE: An implementation may be able to use a smaller number of
+ * DMA address/length pairs than there are SG table elements.
+ * (for example via virtual mapping capabilities)
+ * The routine returns the number of addr/length pairs actually
+ * used, at most nents.
+ *
+ * Device ownership issues as mentioned above for dma_map_single are
+ * the same here.
+ */
+#ifndef CONFIG_DMABOUNCE
+static inline int
+dma_map_sg(struct device *dev, struct scatterlist *sg, int nents,
+ enum dma_data_direction dir)
+{
+ int i;
+
+ for (i = 0; i < nents; i++, sg++) {
+ void *virt;
+ unsigned long pfn;
+ struct page *page = sg_page(sg);
+
+ sg->dma_address = page_to_dma(dev, page) + sg->offset;
+ pfn = page_to_pfn(page) + sg->offset / PAGE_SIZE;
+ page = pfn_to_page(pfn);
+ if (PageHighMem(page)) {
+ virt = kmap_atomic(page);
+ consistent_sync(virt, sg->length, dir);
+ kunmap_atomic(virt);
+ } else {
+ if (sg->offset > PAGE_SIZE)
+ panic("sg->offset:%08x > PAGE_SIZE\n", sg->offset);
+ virt = page_address(page) + sg->offset;
+ consistent_sync(virt, sg->length, dir);
+ }
+ }
+ return nents;
+}
+#else
+extern int dma_map_sg(struct device *, struct scatterlist *, int, enum dma_data_direction);
+#endif
+
+/**
+ * dma_unmap_sg - unmap a set of SG buffers mapped by dma_map_sg
+ * @dev: valid struct device pointer, or NULL for ISA and EISA-like devices
+ * @sg: list of buffers
+ * @nents: number of buffers to map
+ * @dir: DMA transfer direction
+ *
+ * Unmap a set of streaming mode DMA translations.
+ * Again, CPU read rules concerning calls here are the same as for
+ * dma_unmap_single() above.
+ */
+#ifndef CONFIG_DMABOUNCE
+static inline void
+dma_unmap_sg(struct device *dev, struct scatterlist *sg, int nents,
+ enum dma_data_direction dir)
+{
+
+ /* nothing to do */
+}
+#else
+extern void dma_unmap_sg(struct device *, struct scatterlist *, int, enum dma_data_direction);
+#endif
+
+
+/**
+ * dma_sync_single_for_cpu
+ * @dev: valid struct device pointer, or NULL for ISA and EISA-like devices
+ * @handle: DMA address of buffer
+ * @size: size of buffer to map
+ * @dir: DMA transfer direction
+ *
+ * Make physical memory consistent for a single streaming mode DMA
+ * translation after a transfer.
+ *
+ * If you perform a dma_map_single() but wish to interrogate the
+ * buffer using the cpu, yet do not wish to teardown the PCI dma
+ * mapping, you must call this function before doing so. At the
+ * next point you give the PCI dma address back to the card, you
+ * must first the perform a dma_sync_for_device, and then the
+ * device again owns the buffer.
+ */
+#ifndef CONFIG_DMABOUNCE
+static inline void
+dma_sync_single_for_cpu(struct device *dev, dma_addr_t handle, size_t size,
+ enum dma_data_direction dir)
+{
+ consistent_sync((void *)dma_to_virt(dev, handle), size, dir);
+}
+
+static inline void
+dma_sync_single_for_device(struct device *dev, dma_addr_t handle, size_t size,
+ enum dma_data_direction dir)
+{
+ consistent_sync((void *)dma_to_virt(dev, handle), size, dir);
+}
+#else
+extern void dma_sync_single_for_cpu(struct device*, dma_addr_t, size_t, enum dma_data_direction);
+extern void dma_sync_single_for_device(struct device*, dma_addr_t, size_t, enum dma_data_direction);
+#endif
+
+
+/**
+ * dma_sync_sg_for_cpu
+ * @dev: valid struct device pointer, or NULL for ISA and EISA-like devices
+ * @sg: list of buffers
+ * @nents: number of buffers to map
+ * @dir: DMA transfer direction
+ *
+ * Make physical memory consistent for a set of streaming
+ * mode DMA translations after a transfer.
+ *
+ * The same as dma_sync_single_for_* but for a scatter-gather list,
+ * same rules and usage.
+ */
+#ifndef CONFIG_DMABOUNCE
+static inline void
+dma_sync_sg_for_cpu(struct device *dev, struct scatterlist *sg, int nents,
+ enum dma_data_direction dir)
+{
+ int i;
+
+ for (i = 0; i < nents; i++, sg++) {
+ char *virt = page_address( (struct page *)sg->page_link) + sg->offset;
+ consistent_sync(virt, sg->length, dir);
+ }
+}
+
+static inline void
+dma_sync_sg_for_device(struct device *dev, struct scatterlist *sg, int nents,
+ enum dma_data_direction dir)
+{
+ int i;
+
+ for (i = 0; i < nents; i++, sg++) {
+ char *virt = page_address( (struct page *)sg->page_link) + sg->offset;
+ consistent_sync(virt, sg->length, dir);
+ }
+}
+#else
+extern void dma_sync_sg_for_cpu(struct device*, struct scatterlist*, int, enum dma_data_direction);
+extern void dma_sync_sg_for_device(struct device*, struct scatterlist*, int, enum dma_data_direction);
+#endif
+
+#ifdef CONFIG_DMABOUNCE
+/*
+ * For SA-1111, IXP425, and ADI systems the dma-mapping functions are "magic"
+ * and utilize bounce buffers as needed to work around limited DMA windows.
+ *
+ * On the SA-1111, a bug limits DMA to only certain regions of RAM.
+ * On the IXP425, the PCI inbound window is 64MB (256MB total RAM)
+ * On some ADI engineering systems, PCI inbound window is 32MB (12MB total RAM)
+ *
+ * The following are helper functions used by the dmabounce subystem
+ *
+ */
+
+/**
+ * dmabounce_register_dev
+ *
+ * @dev: valid struct device pointer
+ * @small_buf_size: size of buffers to use with small buffer pool
+ * @large_buf_size: size of buffers to use with large buffer pool (can be 0)
+ *
+ * This function should be called by low-level platform code to register
+ * a device as requireing DMA buffer bouncing. The function will allocate
+ * appropriate DMA pools for the device.
+ *
+ */
+extern int dmabounce_register_dev(struct device *, unsigned long, unsigned long);
+
+/**
+ * dmabounce_unregister_dev
+ *
+ * @dev: valid struct device pointer
+ *
+ * This function should be called by low-level platform code when device
+ * that was previously registered with dmabounce_register_dev is removed
+ * from the system.
+ *
+ */
+extern void dmabounce_unregister_dev(struct device *);
+
+/**
+ * dma_needs_bounce
+ *
+ * @dev: valid struct device pointer
+ * @dma_handle: dma_handle of unbounced buffer
+ * @size: size of region being mapped
+ *
+ * Platforms that utilize the dmabounce mechanism must implement
+ * this function.
+ *
+ * The dmabounce routines call this function whenever a dma-mapping
+ * is requested to determine whether a given buffer needs to be bounced
+ * or not. The function must return 0 if the buffer is OK for
+ * DMA access and 1 if the buffer needs to be bounced.
+ *
+ */
+extern int dma_needs_bounce(struct device*, dma_addr_t, size_t);
+#endif /* CONFIG_DMABOUNCE */
+
+#endif /* __KERNEL__ */
+#endif
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/elf.h linux-3.4.113/arch/nds32/include/asm/elf.h
--- linux-3.4.113.orig/arch/nds32/include/asm/elf.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/elf.h 2016-12-01 20:59:24.336612134 +0100
@@ -0,0 +1,145 @@
+/*
+ * linux/arch/nds32/include/asm/elf.h
+ * Copyright (C) 2008 Andes Technology Corporation
+ */
+
+#ifndef __ASMNDS32_ELF_H
+#define __ASMNDS32_ELF_H
+
+/*
+ * ELF register definitions..
+ */
+
+#include <asm/ptrace.h>
+#include <asm/user.h>
+
+typedef unsigned long elf_greg_t;
+typedef unsigned long elf_freg_t[3];
+
+extern unsigned int elf_hwcap;
+
+#define EM_NDS32 167
+
+
+#define R_NDS32_NONE 0
+#define R_NDS32_16_RELA 19
+#define R_NDS32_32_RELA 20
+#define R_NDS32_9_PCREL_RELA 22
+#define R_NDS32_15_PCREL_RELA 23
+#define R_NDS32_17_PCREL_RELA 24
+#define R_NDS32_25_PCREL_RELA 25
+#define R_NDS32_HI20_RELA 26
+#define R_NDS32_LO12S3_RELA 27
+#define R_NDS32_LO12S2_RELA 28
+#define R_NDS32_LO12S1_RELA 29
+#define R_NDS32_LO12S0_RELA 30
+#define R_NDS32_SDA15S3_RELA 31
+#define R_NDS32_SDA15S2_RELA 32
+#define R_NDS32_SDA15S1_RELA 33
+#define R_NDS32_SDA15S0_RELA 34
+#define R_NDS32_GOT20 37
+#define R_NDS32_25_PLTREL 38
+#define R_NDS32_COPY 39
+#define R_NDS32_GLOB_DAT 40
+#define R_NDS32_JMP_SLOT 41
+#define R_NDS32_RELATIVE 42
+#define R_NDS32_GOTOFF 43
+#define R_NDS32_GOTPC20 44
+#define R_NDS32_GOT_HI20 45
+#define R_NDS32_GOT_LO12 46
+#define R_NDS32_GOTPC_HI20 47
+#define R_NDS32_GOTPC_LO12 48
+#define R_NDS32_GOTOFF_HI20 49
+#define R_NDS32_GOTOFF_LO12 50
+#define R_NDS32_INSN16 51
+#define R_NDS32_LABEL 52
+#define R_NDS32_LONGCALL1 53
+#define R_NDS32_LONGCALL2 54
+#define R_NDS32_LONGCALL3 55
+#define R_NDS32_LONGJUMP1 56
+#define R_NDS32_LONGJUMP2 57
+#define R_NDS32_LONGJUMP3 58
+#define R_NDS32_LOADSTORE 59
+#define R_NDS32_9_FIXED_RELA 60
+#define R_NDS32_15_FIXED_RELA 61
+#define R_NDS32_17_FIXED_RELA 62
+#define R_NDS32_25_FIXED_RELA 63
+#define R_NDS32_PLTREL_HI20 64
+#define R_NDS32_PLTREL_LO12 65
+#define R_NDS32_PLT_GOTREL_HI20 66
+#define R_NDS32_PLT_GOTREL_LO12 67
+#define R_NDS32_LO12S0_ORI_RELA 72
+#define R_NDS32_DWARF2_OP1_RELA 77
+#define R_NDS32_DWARF2_OP2_RELA 78
+#define R_NDS32_DWARF2_LEB_RELA 79
+#define R_NDS32_WORD_9_PCREL_RELA 94
+#define R_NDS32_LONGCALL4 107
+#define R_NDS32_RELA_NOP_MIX 192
+#define R_NDS32_RELA_NOP_MAX 255
+
+#define ELF_NGREG (sizeof (struct pt_regs) / sizeof(elf_greg_t))
+typedef elf_greg_t elf_gregset_t[ELF_NGREG];
+
+typedef struct user_fp elf_fpregset_t;
+
+struct elf32_hdr;
+extern int elf_check_arch(const struct elf32_hdr *hdr);
+
+/*
+ * These are used to set parameters in the core dumps.
+ */
+#define ELF_CLASS ELFCLASS32
+#ifdef __NDS32_EB__
+#define ELF_DATA ELFDATA2MSB;
+#else
+#define ELF_DATA ELFDATA2LSB;
+#endif
+#define ELF_ARCH EM_NDS32
+#define USE_ELF_CORE_DUMP
+#define ELF_EXEC_PAGESIZE PAGE_SIZE
+
+/* This is the location that an ET_DYN program is loaded if exec'ed. Typical
+ use of this is to invoke "./ld.so someprog" to test out a new version of
+ the loader. We need to make sure that it is out of the way of the program
+ that it will "exec", and that there is sufficient room for the brk. */
+
+#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
+
+/* When the program starts, a1 contains a pointer to a function to be
+ registered with atexit, as per the SVR4 ABI. A value of 0 means we
+ have no such handler. */
+#define ELF_PLAT_INIT(_r, load_addr) (_r)->NDS32_r0 = 0
+
+/* This yields a mask that user programs can use to figure out what
+ instruction set this cpu supports. */
+
+#define ELF_HWCAP (elf_hwcap)
+
+/* This yields a string that ld.so will use to load implementation
+ specific libraries for optimization. This is more specific in
+ intent than poking at uname or /proc/cpuinfo. */
+
+/* For now we just provide a fairly general string that describes the
+ processor family. This could be made more specific later if someone
+ implemented optimisations that require it. 26-bit CPUs give you
+ "v1l" for ARM2 (no SWP) and "v2l" for anything else (ARM1 isn't
+ supported). 32-bit CPUs give you "v3[lb]" for anything based on an
+ ARM6 or ARM7 core and "armv4[lb]" for anything based on a StrongARM-1
+ core. */
+
+#define ELF_PLATFORM_SIZE 16
+extern char elf_platform[];
+#define ELF_PLATFORM (elf_platform)
+
+#ifdef __KERNEL__
+
+/* Old NetWinder binaries were compiled in such a way that the iBCS
+ heuristic always trips on them. Until these binaries become uncommon
+ enough not to care, don't trust the `ibcs' flag here. In any case
+ there is no other ELF system currently supported by iBCS.
+ @@ Could print a warning message to encourage users to upgrade. */
+#define SET_PERSONALITY(ex) set_personality(PER_LINUX)
+
+#endif
+
+#endif
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/emergency-restart.h linux-3.4.113/arch/nds32/include/asm/emergency-restart.h
--- linux-3.4.113.orig/arch/nds32/include/asm/emergency-restart.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/emergency-restart.h 2016-12-01 20:59:24.336612134 +0100
@@ -0,0 +1,11 @@
+/*
+ * linux/arch/nds32/include/asm/emergency-restart.h
+ * Copyright (C) 2008 Andes Technology Corporation
+ */
+
+#ifndef __NDS32_EMERGENCY_RESTART_H__
+#define __NDS32_EMERGENCY_RESTART_H__
+
+#include <asm-generic/emergency-restart.h>
+
+#endif
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/errno.h linux-3.4.113/arch/nds32/include/asm/errno.h
--- linux-3.4.113.orig/arch/nds32/include/asm/errno.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/errno.h 2016-12-01 20:59:24.336612134 +0100
@@ -0,0 +1,11 @@
+/*
+ * linux/arch/nds32/include/asm/errno.h
+ * Copyright (C) 2008 Andes Technology Corporation
+ */
+
+#ifndef __NDS32_ERRNO_H__
+#define __NDS32_ERRNO_H__
+
+#include <asm-generic/errno.h>
+
+#endif
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/exec.h linux-3.4.113/arch/nds32/include/asm/exec.h
--- linux-3.4.113.orig/arch/nds32/include/asm/exec.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/exec.h 2016-12-01 20:59:24.336612134 +0100
@@ -0,0 +1,6 @@
+#ifndef __ASM_NDS32_EXEC_H
+#define __ASM_NDS32_EXEC_H
+
+#define arch_align_stack(x) (x)
+
+#endif /* __ASM_ARM_EXEC_H */
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/fb.h linux-3.4.113/arch/nds32/include/asm/fb.h
--- linux-3.4.113.orig/arch/nds32/include/asm/fb.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/fb.h 2016-12-01 20:59:24.336612134 +0100
@@ -0,0 +1,25 @@
+/*
+ * linux/arch/nds32/include/asm/fb.h
+ * Copyright (C) 2008 Andes Technology Corporation
+ */
+
+#ifndef __NDS32_FB_H__
+#define __NDS32_FB_H__
+
+
+#include <linux/fb.h>
+#include <linux/fs.h>
+#include <asm/page.h>
+
+static inline void fb_pgprotect(struct file *file, struct vm_area_struct *vma,
+ unsigned long off)
+{
+ vma->vm_page_prot = pgprot_writecombine(vma->vm_page_prot);
+}
+
+static inline int fb_is_primary_device(struct fb_info *info)
+{
+ return 0;
+}
+
+#endif /* __NDS32_FB_H__ */
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/fcntl.h linux-3.4.113/arch/nds32/include/asm/fcntl.h
--- linux-3.4.113.orig/arch/nds32/include/asm/fcntl.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/fcntl.h 2016-12-01 20:59:24.336612134 +0100
@@ -0,0 +1,37 @@
+/*
+ * This file is subject to the terms and conditions of the GNU General Public
+ * License. See the file "COPYING" in the main directory of this archive
+ * for more details.
+ *
+ * Copyright (C) 1995, 96, 97, 98, 99, 2003, 05 Ralf Baechle
+ */
+#ifndef _ASM_FCNTL_H
+#define _ASM_FCNTL_H
+
+/*
+ * The flavours of struct flock. "struct flock" is the ABI compliant
+ * variant. Finally struct flock64 is the LFS variant of struct flock. As
+ * a historic accident and inconsistence with the ABI definition it doesn't
+ * contain all the same fields as struct flock.
+ */
+
+#ifdef CONFIG_32BIT
+#include <linux/types.h>
+
+struct flock {
+ short l_type;
+ short l_whence;
+ off_t l_start;
+ off_t l_len;
+ long l_sysid;
+ __kernel_pid_t l_pid;
+ long pad[4];
+};
+
+#define HAVE_ARCH_STRUCT_FLOCK
+
+#endif /* CONFIG_32BIT */
+
+#include <asm-generic/fcntl.h>
+
+#endif /* _ASM_FCNTL_H */
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/fixmap.h linux-3.4.113/arch/nds32/include/asm/fixmap.h
--- linux-3.4.113.orig/arch/nds32/include/asm/fixmap.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/fixmap.h 2016-12-01 20:59:24.336612134 +0100
@@ -0,0 +1,88 @@
+/*
+ * fixmap.h: compile-time virtual memory allocation
+ *
+ * This file is subject to the terms and conditions of the GNU General Public
+ * License. See the file "COPYING" in the main directory of this archive
+ * for more details.
+ *
+ * Copyright (C) 1998 Ingo Molnar
+ *
+ * Support of BIGMEM added by Gerhard Wichert, Siemens AG, July 1999
+ */
+
+#ifndef __ASM_NDS32_FIXMAP_H
+#define __ASM_NDS32_FIXMAP_H
+
+#ifdef CONFIG_HIGHMEM
+#include <linux/threads.h>
+#include <asm/kmap_types.h>
+#endif
+
+/*
+ * Here we define all the compile-time 'special' virtual
+ * addresses. The point is to have a constant address at
+ * compile time, but to set the physical address only
+ * in the boot process. We allocate these special addresses
+ * from the end of the consistent memory region backwards.
+ * Also this lets us do fail-safe vmalloc(), we
+ * can guarantee that these special addresses and
+ * vmalloc()-ed addresses never overlap.
+ *
+ * these 'compile-time allocated' memory buffers are
+ * fixed-size 4k pages. (or larger if used with an increment
+ * higher than 1) use fixmap_set(idx,phys) to associate
+ * physical memory with fixmap indices.
+ *
+ * TLB entries of such buffers will not be flushed across
+ * task switches.
+ */
+enum fixed_addresses {
+ FIX_KMAP_RESERVED,
+ FIX_KMAP_BEGIN,
+#ifdef CONFIG_HIGHMEM
+ FIX_KMAP_END = FIX_KMAP_BEGIN + (KM_TYPE_NR * NR_CPUS),
+#endif
+#ifdef CONFIG_EARLY_PRINTK
+ FIX_EARLY_DEBUG,
+#endif
+ FIX_RETURN_SYSCALL,
+ __end_of_fixed_addresses
+};
+#define FIXADDR_TOP ((unsigned long) (-(16 * PAGE_SIZE)))
+#define FIXADDR_SIZE ((__end_of_fixed_addresses) << PAGE_SHIFT)
+#define FIXADDR_START (FIXADDR_TOP - FIXADDR_SIZE)
+
+#define __fix_to_virt(x) (FIXADDR_TOP - ((x) << PAGE_SHIFT))
+#define __virt_to_fix(x) ((FIXADDR_TOP - ((x)&PAGE_MASK)) >> PAGE_SHIFT)
+
+#define __this_fixmap_does_not_exist() WARN_ON(1)
+/*
+ * 'index to address' translation. If anyone tries to use the idx
+ * directly without tranlation, we catch the bug with a NULL-deference
+ * kernel oops. Illegal ranges of incoming indices are caught too.
+ */
+
+static inline unsigned long fix_to_virt(const unsigned int idx)
+{
+ /*
+ * this branch gets completely eliminated after inlining,
+ * except when someone tries to use fixaddr indices in an
+ * illegal way. (such as mixing up address types or using
+ * out-of-range indices).
+ *
+ * If it doesn't get removed, the linker will complain
+ * loudly with a reasonably clear error message..
+ */
+ if (idx >= __end_of_fixed_addresses)
+ __this_fixmap_does_not_exist();
+
+ return __fix_to_virt(idx);
+}
+
+static inline unsigned long virt_to_fix(const unsigned long vaddr)
+{
+ BUG_ON(vaddr >= FIXADDR_TOP || vaddr < FIXADDR_START);
+ return __virt_to_fix(vaddr);
+}
+
+#endif /* __ASM_NDS32_FIXMAP_H */
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/fpu.h linux-3.4.113/arch/nds32/include/asm/fpu.h
--- linux-3.4.113.orig/arch/nds32/include/asm/fpu.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/fpu.h 2016-12-01 20:59:24.336612134 +0100
@@ -0,0 +1,100 @@
+/*
+ * linux/arch/nds32/include/asm/fpu.h
+ * Copyright (C) 2008 Andes Technology Corporation
+ */
+
+#ifndef __ASM_NDS32_FPU_H
+#define __ASM_NDS32_FPU_H
+
+#ifndef __ASSEMBLY__
+#include <linux/preempt.h>
+#include <asm/ptrace.h>
+
+extern void save_fpu(struct task_struct *__tsk);
+extern void fpload(struct fpu_struct *fpregs);
+extern void do_fpu_exception(unsigned long error_code, struct pt_regs *regs);
+extern int do_fpu_inst(unsigned short, struct pt_regs *);
+
+#ifdef CONFIG_FPU
+
+#define test_tsk_fpu(regs) (regs->NDS32_FUCOP_CTL & FUCOP_CTL_mskCP0EN)
+
+struct task_struct;
+
+static inline void release_fpu(struct pt_regs *regs)
+{
+ regs->NDS32_FUCOP_CTL &= ~FUCOP_CTL_mskCP0EN;
+}
+
+static inline void grab_fpu(struct pt_regs *regs)
+{
+ regs->NDS32_FUCOP_CTL |= FUCOP_CTL_mskCP0EN;
+}
+
+static inline void enable_fpu(void)
+{
+ SET_FUCOP_CTL(GET_FUCOP_CTL() | FUCOP_CTL_mskCP0EN);
+}
+
+static inline void disable_fpu(void)
+{
+ SET_FUCOP_CTL(GET_FUCOP_CTL() & ~FUCOP_CTL_mskCP0EN);
+}
+
+static inline void lose_fpu(int save)
+{
+ preempt_disable();
+ if (test_tsk_fpu(task_pt_regs(current))) {
+ if (save)
+ {
+ save_fpu(current);
+# ifndef CONFIG_UNLAZY_FPU
+ last_task_used_math=NULL;
+# endif
+ }
+ release_fpu(task_pt_regs(current));
+ }
+ preempt_enable();
+}
+
+static inline void own_fpu(int restore)
+{
+ preempt_disable();
+ if (!test_tsk_fpu(task_pt_regs(current))) {
+ if (restore)
+ {
+# ifdef CONFIG_UNLAZY_FPU
+ fpload(¤t->thread.fpu);
+# else
+ if((last_task_used_math!=NULL)
+ &&(last_task_used_math!=current))
+ save_fpu(last_task_used_math);
+ fpload(¤t->thread.fpu);
+ last_task_used_math=current;
+#endif
+ }
+ grab_fpu(task_pt_regs(current));
+ }
+ preempt_enable();
+}
+# ifdef CONFIG_UNLAZY_FPU
+static inline void unlazy_fpu(struct task_struct *tsk)
+{
+ preempt_disable();
+ if (test_tsk_fpu(task_pt_regs(tsk)))
+ save_fpu(tsk);
+ preempt_enable();
+}
+# endif /* CONFIG_UNLAZY_FPU */
+static inline void clear_fpu(struct pt_regs *regs)
+{
+ preempt_disable();
+ if (test_tsk_fpu(regs)) {
+ release_fpu(regs);
+ }
+ preempt_enable();
+}
+#endif /* CONFIG_FPU */
+#endif /* __ASSEMBLY__ */
+
+#endif /* __ASM_NDS32_FPU_H */
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/ftpci.h linux-3.4.113/arch/nds32/include/asm/ftpci.h
--- linux-3.4.113.orig/arch/nds32/include/asm/ftpci.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/ftpci.h 2016-12-01 20:59:24.336612134 +0100
@@ -0,0 +1,30 @@
+/*
+ * linux/arch/nds32/include/asm/ftpci.h
+ *
+ * Faraday FTPCI010 PCI Bridge Device Driver Interface
+ *
+ * Copyright (C) 2005 Faraday Corp. (http://www.faraday-tech.com)
+ * Copyright (C) 2008 Andes Technology Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * ChangeLog
+ *
+ * Peter Liao 09/26/2005 Created, heavily modified from Faraday A320 platform code.
+ */
+
+#ifndef __FARADAY_PLATFORM_PCI_HEADER__
+#define __FARADAY_PLATFORM_PCI_HEADER__
+
+
+#define PCI_BRIDGE_DEVID 0x4321
+#define PCI_BRIDGE_VENID 0x159b
+
+extern int ftpci_probed;
+extern void ftpci_clear_irq(unsigned int irq);
+extern void ftpci_mask_irq(unsigned int irq);
+extern void ftpci_unmask_irq(unsigned int irq);
+extern int ftpci_get_irq(void);
+#endif /* __FARADAY_PLATFORM_PCI_HEADER__ */
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/ftrace.h linux-3.4.113/arch/nds32/include/asm/ftrace.h
--- linux-3.4.113.orig/arch/nds32/include/asm/ftrace.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/ftrace.h 2016-12-01 20:59:24.336612134 +0100
@@ -0,0 +1,17 @@
+#ifndef _ASM_POWERPC_FTRACE
+#define _ASM_POWERPC_FTRACE
+
+#ifdef CONFIG_FUNCTION_TRACER
+#define MCOUNT_ADDR ((long)(_mcount))
+#define MCOUNT_INSN_SIZE 4 /* sizeof mcount call */
+
+#ifdef __ASSEMBLY__
+
+#else /* !__ASSEMBLY__ */
+extern void _mcount(void);
+
+#endif /* __ASSEMBLY__ */
+
+#endif
+
+#endif /* _ASM_POWERPC_FTRACE */
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/futex.h linux-3.4.113/arch/nds32/include/asm/futex.h
--- linux-3.4.113.orig/arch/nds32/include/asm/futex.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/futex.h 2016-12-01 20:59:24.336612134 +0100
@@ -0,0 +1,11 @@
+/*
+ * linux/arch/nds32/include/asm/futex.h
+ * Copyright (C) 2008 Andes Technology Corporation
+ */
+
+#ifndef __NDS32_FUTEX_H__
+#define __NDS32_FUTEX_H__
+
+#include <asm-generic/futex.h>
+
+#endif
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/glue.h linux-3.4.113/arch/nds32/include/asm/glue.h
--- linux-3.4.113.orig/arch/nds32/include/asm/glue.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/glue.h 2016-12-01 20:59:24.336612134 +0100
@@ -0,0 +1,26 @@
+/*
+ * linux/arch/nds32/include/asm/glue.h
+ *
+ * Copyright (C) 1997-1999 Russell King
+ * Copyright (C) 2000-2002 Deep Blue Solutions Ltd.
+ * Copyright (C) 2008 Andes Technology Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This file provides the glue to stick the processor-specific bits
+ * into the kernel in an efficient manner. The idea is to use branches
+ * when we're only targetting one class of TLB, or indirect calls
+ * when we're targetting multiple classes of TLBs.
+ */
+#ifdef __KERNEL__
+
+#ifdef __STDC__
+#define ____glue(name,fn) name##fn
+#else
+#define ____glue(name,fn) name/**/fn
+#endif
+#define __glue(name,fn) ____glue(name,fn)
+
+#endif
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/gpio.h linux-3.4.113/arch/nds32/include/asm/gpio.h
--- linux-3.4.113.orig/arch/nds32/include/asm/gpio.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/gpio.h 2016-12-01 20:59:24.336612134 +0100
@@ -0,0 +1,10 @@
+#ifndef _ARCH_NDS32_GPIO_H
+#define _ARCH_NDS32_GPIO_H
+
+#include <asm-generic/gpio.h>
+#define gpio_get_value __gpio_get_value
+#define gpio_set_value __gpio_set_value
+#define gpio_cansleep __gpio_cansleep
+#define gpio_to_irq __gpio_to_irq
+
+#endif /* _ARCH_NDS32_GPIO_H */
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/hardirq.h linux-3.4.113/arch/nds32/include/asm/hardirq.h
--- linux-3.4.113.orig/arch/nds32/include/asm/hardirq.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/hardirq.h 2016-12-01 20:59:24.336612134 +0100
@@ -0,0 +1,36 @@
+/*
+ * linux/arch/nds32/include/asm/hardirq.h
+ * Copyright (C) 2008 Andes Technology Corporation
+ */
+#ifndef __ASM_HARDIRQ_H
+#define __ASM_HARDIRQ_H
+
+#include <linux/cache.h>
+#include <linux/threads.h>
+#include <asm/irq.h>
+
+typedef struct {
+ unsigned int __softirq_pending;
+} ____cacheline_aligned irq_cpustat_t;
+
+#include <linux/irq_cpustat.h> /* Standard mappings for irq_cpustat_t above */
+
+#if NR_IRQS > 256
+#define HARDIRQ_BITS 9
+#else
+#define HARDIRQ_BITS 8
+#endif
+
+/*
+ * The hardirq mask has to be large enough to have space
+ * for potentially all IRQ sources in the system nesting
+ * on a single CPU:
+ */
+#if (1 << HARDIRQ_BITS) < NR_IRQS
+# error HARDIRQ_BITS is too low!
+#endif
+
+#define __ARCH_IRQ_EXIT_IRQS_DISABLED 1
+
+extern void ack_bad_irq(unsigned int irq);
+#endif /* __ASM_HARDIRQ_H */
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/hardware.h linux-3.4.113/arch/nds32/include/asm/hardware.h
--- linux-3.4.113.orig/arch/nds32/include/asm/hardware.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/hardware.h 2016-12-01 20:59:24.336612134 +0100
@@ -0,0 +1,61 @@
+/*
+ * linux/arch/nds32/include/asm/hardware.h
+ *
+ * Faraday Platform Independent Hardware Configuration
+ *
+ * Copyright (C) 2005 Faraday Corp. (http://www.faraday-tech.com)
+ * Copyright (C) 2008 Andes Technology Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * ChangeLog
+ *
+ * Luke Lee 09/16/2005 Created.
+ * Peter Liao 10/04/2005 Modified for uClinux
+ * Harry Pan 11/02/2007 Added REGxx macros.
+ */
+
+#ifndef __FARADAY_PLATFORM_HARDWARE_HEADER__
+#define __FARADAY_PLATFORM_HARDWARE_HEADER__
+
+#include <asm/spec.h>
+
+#ifndef PCIBIOS_MIN_IO
+/* the mini io address is 0x6000,that is IO will allocate from 0-0x6000 offset*/
+#define PCIBIOS_MIN_IO 0x0
+#endif
+
+#ifndef PCIBIOS_MIN_MEM
+/* the mini MEM address is 0x100000,that is MEM will allocate from 0-0x100000 offset*/
+#define PCIBIOS_MIN_MEM 0x0
+#endif
+
+#define pcibios_assign_all_busses() 1
+
+/* Pliauo add 5 to resolve __alloc_bootmem_core return NULL pointer in bootmem.c */
+#if defined(CPU_MEM_PA_BASE) && defined(CPU_MEM_PA_SIZE)
+ #define PA_SDRAM_BASE (CPU_MEM_PA_BASE)
+#else
+ #define PA_SDRAM_BASE (0x00000000)
+#endif
+
+/*
+ * Define a simple register accessing method by Harry@Nov.02.2007
+ */
+#define REG32(a) (*(volatile unsigned int *)(a))
+#define REG16(a) (*(volatile unsigned short *)(a))
+#define REG8(a) (*(volatile unsigned char *)(a))
+
+#endif /* __FARADAY_PLATFORM_HARDWARE_HEADER__ */
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/highmem.h linux-3.4.113/arch/nds32/include/asm/highmem.h
--- linux-3.4.113.orig/arch/nds32/include/asm/highmem.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/highmem.h 2016-12-01 20:59:24.336612134 +0100
@@ -0,0 +1,61 @@
+#ifndef _ASM_HIGHMEM_H
+#define _ASM_HIGHMEM_H
+
+#include <asm/kmap_types.h>
+#include <asm/fixmap.h>
+#include <asm/pgtable.h>
+
+/*
+ * Right now we initialize only a single pte table. It can be extended
+ * easily, subsequent pte tables have to be allocated in one physical
+ * chunk of RAM.
+ */
+/*
+ * Ordering is (from lower to higher memory addresses):
+ *
+ * high_memory
+ * Persistent kmap area
+ * PKMAP_BASE
+ * fixed_addresses
+ * FIXADDR_START
+ * FIXADDR_TOP
+ * Vmalloc area
+ * VMALLOC_START
+ * VMALLOC_END
+ */
+#define PKMAP_BASE ((FIXADDR_START - PGDIR_SIZE) & (PGDIR_MASK))
+#define LAST_PKMAP PTRS_PER_PTE
+#define LAST_PKMAP_MASK (LAST_PKMAP - 1)
+#define PKMAP_NR(virt) (((virt) - (PKMAP_BASE)) >> PAGE_SHIFT)
+#define PKMAP_ADDR(nr) (PKMAP_BASE + ((nr) << PAGE_SHIFT))
+#define kmap_prot PAGE_KERNEL
+
+static inline void flush_cache_kmaps(void)
+{
+ cpu_dcache_wbinval_all();
+}
+
+/* declarations for highmem.c */
+extern unsigned long highstart_pfn, highend_pfn;
+
+extern pte_t *pkmap_page_table;
+
+extern void *kmap_high(struct page *page);
+extern void kunmap_high(struct page *page);
+
+extern void kmap_init(void);
+
+/*
+ * The following functions are already defined by <linux/highmem.h>
+ * when CONFIG_HIGHMEM is not set.
+ */
+#ifdef CONFIG_HIGHMEM
+extern void *kmap(struct page *page);
+extern void kunmap(struct page *page);
+extern void *kmap_atomic(struct page *page);
+extern void __kunmap_atomic(void *kvaddr);
+extern void *kmap_atomic_pfn(unsigned long pfn);
+extern struct page *kmap_atomic_to_page(void *ptr);
+#endif
+
+#endif
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/hw_irq.h linux-3.4.113/arch/nds32/include/asm/hw_irq.h
--- linux-3.4.113.orig/arch/nds32/include/asm/hw_irq.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/hw_irq.h 2016-12-01 20:59:24.336612134 +0100
@@ -0,0 +1,11 @@
+/*
+ * linux/arch/nds32/include/asm/hw_irq.h
+ * Copyright (C) 2008 Andes Technology Corporation
+ */
+
+#ifndef __NDS32_HW_IRQ_H__
+#define __NDS32_HW_IRQ_H__
+
+
+#endif /* __NDS32_HW_IRQ_H__ */
+
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/intc.h linux-3.4.113/arch/nds32/include/asm/intc.h
--- linux-3.4.113.orig/arch/nds32/include/asm/intc.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/intc.h 2016-12-01 20:59:24.336612134 +0100
@@ -0,0 +1,45 @@
+/*
+ * linux/arch/nds32/include/asm/intc.h
+ *
+ * Faraday FTINTC010 Interrupt Controller Device Driver Interface
+ *
+ * Copyright (C) 2005 Faraday Corp. (http://www.faraday-tech.com)
+ * Copyright (C) 2008 Andes Technology Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * ChangeLog
+ *
+ * Luke Lee 09/14/2005 Created, heavily modified from Faraday CPE platform code.
+ */
+
+#ifndef __FARADAY_INTC_FTINTC010_HEADER__
+#define __FARADAY_INTC_FTINTC010_HEADER__
+
+#define IRQ_SOURCE_REG 0
+#define IRQ_MASK_REG 0x04
+#define IRQ_CLEAR_REG 0x08
+#define IRQ_MODE_REG 0x0c
+#define IRQ_LEVEL_REG 0x10
+#define IRQ_STATUS_REG 0x14
+
+#define FIQ_SOURCE_REG 0x20
+#define FIQ_MASK_REG 0x24
+#define FIQ_CLEAR_REG 0x28
+#define FIQ_MODE_REG 0x2c
+#define FIQ_LEVEL_REG 0x30
+#define FIQ_STATUS_REG 0x34
+
+#endif /* __FARADAY_INTC_FTINTC010_HEADER__ */
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/ioctl.h linux-3.4.113/arch/nds32/include/asm/ioctl.h
--- linux-3.4.113.orig/arch/nds32/include/asm/ioctl.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/ioctl.h 2016-12-01 20:59:24.336612134 +0100
@@ -0,0 +1,11 @@
+/*
+ * linux/arch/nds32/include/asm/ioctl.h
+ * Copyright (C) 2008 Andes Technology Corporation
+ */
+
+#ifndef __NDS32_IOCTL_H__
+#define __NDS32_IOCTL_H__
+
+#include <asm-generic/ioctl.h>
+
+#endif
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/ioctls.h linux-3.4.113/arch/nds32/include/asm/ioctls.h
--- linux-3.4.113.orig/arch/nds32/include/asm/ioctls.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/ioctls.h 2016-12-01 20:59:24.336612134 +0100
@@ -0,0 +1,13 @@
+/*
+ * linux/arch/nds32/include/asm/ioctls.h
+ * Copyright (C) 2008 Andes Technology Corporation
+ */
+
+#ifndef __ASM_NDS32_IOCTLS_H
+#define __ASM_NDS32_IOCTLS_H
+
+#define FIOQSIZE 0x545E
+
+#include <asm-generic/ioctls.h>
+
+#endif
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/io.h linux-3.4.113/arch/nds32/include/asm/io.h
--- linux-3.4.113.orig/arch/nds32/include/asm/io.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/io.h 2016-12-01 20:59:24.336612134 +0100
@@ -0,0 +1,343 @@
+/*
+ * linux/arch/nds32/include/asm/io.h
+ *
+ * Copyright (C) 1996-2000 Russell King
+ * Copyright (C) 2008 Andes Technology Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Modifications:
+ * 16-Sep-1996 RMK Inlined the inx/outx functions & optimised for both
+ * constant addresses and variable addresses.
+ * 04-Dec-1997 RMK Moved a lot of this stuff to the new architecture
+ * specific IO header files.
+ * 27-Mar-1999 PJB Second parameter of memcpy_toio is const..
+ * 04-Apr-1999 PJB Added check_signature.
+ * 12-Dec-1999 RMK More cleanups
+ * 18-Jun-2000 RMK Removed virt_to_* and friends definitions
+ * 05-Oct-2004 BJD Moved memory string functions to use void __iomem
+ */
+#ifndef __ASM_NDS32_IO_H
+#define __ASM_NDS32_IO_H
+
+#ifdef __KERNEL__
+
+#include <linux/types.h>
+#include <asm/byteorder.h>
+#include <asm/memory.h>
+#include <asm/hardware.h>
+#include <asm-generic/iomap.h>
+
+
+/*
+ * ISA I/O bus memory addresses are 1:1 with the physical address.
+ */
+#define isa_virt_to_bus virt_to_phys
+#define isa_page_to_bus page_to_phys
+#define isa_bus_to_virt phys_to_virt
+
+/*
+ * Generic IO read/write. These perform native-endian accesses. Note
+ * that some architectures will want to re-define __raw_{read,write}w.
+ */
+
+#define __raw_writeb(v,a) (*(volatile unsigned char __force *)(a) = (v))
+#define __raw_writew(v,a) (*(volatile unsigned short __force *)(a) = (v))
+#define __raw_writel(v,a) (*(volatile unsigned int __force *)(a) = (v))
+
+#define __raw_readb(a) (*(volatile unsigned char __force *)(a))
+#define __raw_readw(a) (*(volatile unsigned short __force *)(a))
+#define __raw_readl(a) (*(volatile unsigned int __force *)(a))
+
+/*
+ * Bad read/write accesses...
+ */
+extern void __readwrite_bug(const char *fn);
+
+/*
+ * Now, pick up the machine-defined IO definitions
+ */
+#ifndef __FARADAY_PLATFORM_IO_HEADER__
+#define __FARADAY_PLATFORM_IO_HEADER__
+
+#include <linux/compiler.h>
+#include <asm/spec.h>
+
+#ifndef IO_SPACE_LIMIT
+#define IO_SPACE_LIMIT 0xffffffff
+#endif
+
+#ifndef __io
+#define __io(a) ((void __iomem *)(a))
+#endif
+#define IO_ADDRESS(a) __io(a)
+#ifndef __mem_pci
+#define __mem_pci(a) (a)
+#endif
+
+#endif
+
+#ifdef __io_pci
+#warning machine class uses buggy __io_pci
+#endif
+#if defined(__arch_putb) || defined(__arch_putw) || defined(__arch_putl) || \
+ defined(__arch_getb) || defined(__arch_getw) || defined(__arch_getl)
+//-Tom for debug
+//#warning machine class uses old __arch_putw or __arch_getw
+#endif
+
+/*
+ * IO port access primitives
+ * -------------------------
+ *
+ * The ARM doesn't have special IO access instructions; all IO is memory
+ * mapped. Note that these are defined to perform little endian accesses
+ * only. Their primary purpose is to access PCI and ISA peripherals.
+ *
+ * Note that for a big endian machine, this implies that the following
+ * big endian mode connectivity is in place, as described by numerious
+ * ARM documents:
+ *
+ * PCI: D0-D7 D8-D15 D16-D23 D24-D31
+ * ARM: D24-D31 D16-D23 D8-D15 D0-D7
+ *
+ * The machine specific io.h include defines __io to translate an "IO"
+ * address to a memory address.
+ *
+ * Note that we prevent GCC re-ordering or caching values in expressions
+ * by introducing sequence points into the in*() definitions. Note that
+ * __raw_* do not guarantee this behaviour.
+ *
+ * The {in,out}[bwl] macros are for emulating x86-style PCI/ISA IO space.
+ */
+#ifdef __io
+#ifdef __NDS32_EB__
+#define inw(p) ({ unsigned int __v = be16_to_cpu(__raw_readw(__io(p))); __v; })
+#define inl(p) ({ unsigned int __v = be32_to_cpu(__raw_readl(__io(p))); __v; })
+#define outw(v,p) __raw_writew(cpu_to_be16(v),__io(p))
+#define outl(v,p) __raw_writel(cpu_to_be32(v),__io(p))
+#else
+#define inw(p) ({ unsigned int __v = le16_to_cpu(__raw_readw(__io(p))); __v; })
+#define inl(p) ({ unsigned int __v = le32_to_cpu(__raw_readl(__io(p))); __v; })
+#define outw(v,p) __raw_writew(cpu_to_le16(v),__io(p))
+#define outl(v,p) __raw_writel(cpu_to_le32(v),__io(p))
+#endif
+
+#define inb(p) ({ unsigned int __v = __raw_readb(__io(p)); __v; })
+#define outb(v,p) __raw_writeb(v,__io(p))
+
+#endif
+
+#define outb_p(val,port) outb((val),(port))
+#define outw_p(val,port) outw((val),(port))
+#define outl_p(val,port) outl((val),(port))
+#define inb_p(port) inb((port))
+#define inw_p(port) inw((port))
+#define inl_p(port) inl((port))
+
+/*
+ * String version of IO memory access ops:
+ */
+extern void _memcpy_fromio(void *, const volatile void __iomem *, size_t);
+extern void _memcpy_toio(volatile void __iomem *, const void *, size_t);
+extern void _memset_io(volatile void __iomem *, int, size_t);
+
+#define mmiowb()
+
+/*
+ * Memory access primitives
+ * ------------------------
+ *
+ * These perform PCI memory accesses via an ioremap region. They don't
+ * take an address as such, but a cookie.
+ *
+ * Again, this are defined to perform little endian accesses. See the
+ * IO port primitives for more information.
+ */
+#ifdef __mem_pci
+#ifdef __NDS32_EB__
+#define readw(c) ({ unsigned int __v = be16_to_cpu(__raw_readw(__mem_pci(c))); __v; })
+#define readl(c) ({ unsigned int __v = be32_to_cpu(__raw_readl(__mem_pci(c))); __v; })
+#define writew(v,c) __raw_writew(cpu_to_be16(v),__mem_pci(c))
+#define writel(v,c) __raw_writel(cpu_to_be32(v),__mem_pci(c))
+#else
+#define readw(c) ({ unsigned int __v = le16_to_cpu(__raw_readw(__mem_pci(c))); __v; })
+#define readl(c) ({ unsigned int __v = le32_to_cpu(__raw_readl(__mem_pci(c))); __v; })
+#define writew(v,c) __raw_writew(cpu_to_le16(v),__mem_pci(c))
+#define writel(v,c) __raw_writel(cpu_to_le32(v),__mem_pci(c))
+#endif
+
+#define readb(c) ({ unsigned int __v = __raw_readb(__mem_pci(c)); __v; })
+#define writeb(v,c) __raw_writeb(v,__mem_pci(c))
+
+#define readb_relaxed(addr) readb(addr)
+#define readw_relaxed(addr) readw(addr)
+#define readl_relaxed(addr) readl(addr)
+
+#define memset_io(c,v,l) _memset_io(__mem_pci(c),(v),(l))
+#define memcpy_fromio(a,c,l) _memcpy_fromio((a),__mem_pci(c),(l))
+#define memcpy_toio(c,a,l) _memcpy_toio(__mem_pci(c),(a),(l))
+
+#define eth_io_copy_and_sum(s,c,l,b) \
+ eth_copy_and_sum((s),__mem_pci(c),(l),(b))
+
+#elif !defined(readb)
+
+#define readb(c) (__readwrite_bug("readb"),0)
+#define readw(c) (__readwrite_bug("readw"),0)
+#define readl(c) (__readwrite_bug("readl"),0)
+#define writeb(v,c) __readwrite_bug("writeb")
+#define writew(v,c) __readwrite_bug("writew")
+#define writel(v,c) __readwrite_bug("writel")
+
+#define eth_io_copy_and_sum(s,c,l,b) __readwrite_bug("eth_io_copy_and_sum")
+
+#endif /* __mem_pci */
+
+/*
+ * If this architecture has ISA IO, then define the isa_read/isa_write
+ * macros.
+ */
+#ifdef __mem_isa
+
+#define isa_readb(addr) __raw_readb(__mem_isa(addr))
+#define isa_readw(addr) __raw_readw(__mem_isa(addr))
+#define isa_readl(addr) __raw_readl(__mem_isa(addr))
+#define isa_writeb(val,addr) __raw_writeb(val,__mem_isa(addr))
+#define isa_writew(val,addr) __raw_writew(val,__mem_isa(addr))
+#define isa_writel(val,addr) __raw_writel(val,__mem_isa(addr))
+#define isa_memset_io(a,b,c) _memset_io(__mem_isa(a),(b),(c))
+#define isa_memcpy_fromio(a,b,c) _memcpy_fromio((a),__mem_isa(b),(c))
+#define isa_memcpy_toio(a,b,c) _memcpy_toio(__mem_isa((a)),(b),(c))
+
+#define isa_eth_io_copy_and_sum(a,b,c,d) \
+ eth_copy_and_sum((a),__mem_isa(b),(c),(d))
+
+#else /* __mem_isa */
+
+#define isa_readb(addr) (__readwrite_bug("isa_readb"),0)
+#define isa_readw(addr) (__readwrite_bug("isa_readw"),0)
+#define isa_readl(addr) (__readwrite_bug("isa_readl"),0)
+#define isa_writeb(val,addr) __readwrite_bug("isa_writeb")
+#define isa_writew(val,addr) __readwrite_bug("isa_writew")
+#define isa_writel(val,addr) __readwrite_bug("isa_writel")
+#define isa_memset_io(a,b,c) __readwrite_bug("isa_memset_io")
+#define isa_memcpy_fromio(a,b,c) __readwrite_bug("isa_memcpy_fromio")
+#define isa_memcpy_toio(a,b,c) __readwrite_bug("isa_memcpy_toio")
+
+#define isa_eth_io_copy_and_sum(a,b,c,d) \
+ __readwrite_bug("isa_eth_io_copy_and_sum")
+
+#endif /* __mem_isa */
+
+/*
+ * ioremap and friends.
+ *
+ * ioremap takes a PCI memory address, as specified in
+ * Documentation/IO-mapping.txt.
+ */
+extern void __iomem * __ioremap(unsigned long, size_t, unsigned long, unsigned long);
+extern void __iounmap(void __iomem *addr);
+
+#ifndef __arch_ioremap
+#define ioremap(cookie,size) __ioremap(cookie,size,0,1)
+#define ioremap_nocache(cookie,size) __ioremap(cookie,size,0,1)
+#define iounmap(cookie) __iounmap(cookie)
+#else
+#define ioremap(cookie,size) __arch_ioremap((cookie),(size),0,1)
+#define ioremap_nocache(cookie,size) __arch_ioremap((cookie),(size),0,1)
+#define iounmap(cookie) __arch_iounmap(cookie)
+#endif
+
+/*
+ * can the hardware map this into one segment or not, given no other
+ * constraints.
+ */
+#define BIOVEC_MERGEABLE(vec1, vec2) \
+ ((bvec_to_phys((vec1)) + (vec1)->bv_len) == bvec_to_phys((vec2)))
+
+/*
+ * Convert a physical pointer to a virtual kernel pointer for /dev/mem
+ * access
+ */
+#define xlate_dev_mem_ptr(p) __va(p)
+
+/*
+ * Convert a virtual cached pointer to an uncached pointer
+ */
+#define xlate_dev_kmem_ptr(p) p
+static inline void readsb(const void __iomem *addr, void * data, int bytelen)
+{
+ unsigned char *ptr = (unsigned char *)addr;
+ unsigned char *ptr2 = (unsigned char *)data;
+ while(bytelen) {
+ *ptr2 = *ptr;
+ ptr2++;
+ bytelen--;
+ }
+}
+
+static inline void readsw(const void __iomem *addr, void * data, int wordlen)
+{
+ unsigned short *ptr = (unsigned short *)addr;
+ unsigned short *ptr2 = (unsigned short *)data;
+ while(wordlen) {
+ *ptr2 = *ptr;
+ ptr2++;
+ wordlen--;
+ }
+}
+
+static inline void readsl(const void __iomem *addr, void * data, int longlen)
+{
+ unsigned int *ptr = (unsigned int *)addr;
+ unsigned int *ptr2 = (unsigned int *)data;
+ while(longlen) {
+ *ptr2 = *ptr;
+ ptr2++;
+ longlen--;
+ }
+}
+static inline void writesb(void __iomem *addr, const void * data, int bytelen)
+{
+ unsigned char *ptr = (unsigned char *)addr;
+ unsigned char *ptr2 = (unsigned char *)data;
+ while(bytelen) {
+ *ptr = *ptr2;
+ ptr2++;
+ bytelen--;
+ }
+}
+static inline void writesw(void __iomem *addr, const void * data, int wordlen)
+{
+ unsigned short *ptr = (unsigned short *)addr;
+ unsigned short *ptr2 = (unsigned short *)data;
+ while(wordlen) {
+ *ptr = *ptr2;
+ ptr2++;
+ wordlen--;
+ }
+}
+static inline void writesl(void __iomem *addr, const void * data, int longlen)
+{
+ unsigned int *ptr = (unsigned int *)addr;
+ unsigned int *ptr2 = (unsigned int *)data;
+ while(longlen) {
+ *ptr = *ptr2;
+ ptr2++;
+ longlen--;
+ }
+}
+
+
+#define insb(p,d,l) BUG()
+#define insw(p,d,l) BUG()
+#define insl(p,d,l) BUG()
+#define outsb(p,d,l) BUG()
+#define outsw(p,d,l) BUG()
+#define outsl(p,d,l) BUG()
+
+#endif /* __KERNEL__ */
+#endif /* __ASM_NDS32_IO_H */
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/ipcbuf.h linux-3.4.113/arch/nds32/include/asm/ipcbuf.h
--- linux-3.4.113.orig/arch/nds32/include/asm/ipcbuf.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/ipcbuf.h 2016-12-01 20:59:24.336612134 +0100
@@ -0,0 +1,34 @@
+/*
+ * linux/arch/nds32/include/asm/ipcbuf.h
+ * Copyright (C) 2008 Andes Technology Corporation
+ */
+
+#ifndef __ASMNDS32_IPCBUF_H
+#define __ASMNDS32_IPCBUF_H
+
+/*
+ * The ipc64_perm structure for arm architecture.
+ * Note extra padding because this structure is passed back and forth
+ * between kernel and user space.
+ *
+ * Pad space is left for:
+ * - 32-bit mode_t and seq
+ * - 2 miscellaneous 32-bit values
+ */
+
+struct ipc64_perm
+{
+ __kernel_key_t key;
+ __kernel_uid32_t uid;
+ __kernel_gid32_t gid;
+ __kernel_uid32_t cuid;
+ __kernel_gid32_t cgid;
+ __kernel_mode_t mode;
+ unsigned short __pad1;
+ unsigned short seq;
+ unsigned short __pad2;
+ unsigned long __unused1;
+ unsigned long __unused2;
+};
+
+#endif /* __ASMNDS32_IPCBUF_H */
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/irqflags.h linux-3.4.113/arch/nds32/include/asm/irqflags.h
--- linux-3.4.113.orig/arch/nds32/include/asm/irqflags.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/irqflags.h 2016-12-01 20:59:24.336612134 +0100
@@ -0,0 +1,65 @@
+/*
+ * linux/arch/nds32/include/asm/irqflags.h
+ * Copyright (C) 2008 Andes Technology Corporation
+ */
+
+#include <asm/nds32.h>
+#include <asm/assembler.h>
+
+#define arch_local_irq_disable() \
+ GIE_DISABLE();
+
+#define arch_local_irq_enable() \
+ GIE_ENABLE();
+static inline unsigned long arch_local_irq_save(void)
+{
+ unsigned long flags;
+ __asm__ __volatile__(
+ "mfsr %0, $PSW\n"
+ "andi %0, %0, #0x1\n"
+ "gie_disable\n"
+ : "=r" (flags) );
+ return flags;
+}
+static inline unsigned long arch_local_save_flags(void)
+{
+ unsigned long flags;
+ __asm__ __volatile__(
+ "mfsr %0, $PSW\n"
+ "andi %0, %0, #0x1"
+ : "=r" (flags) );
+ return flags;
+}
+static inline void arch_local_irq_restore(unsigned long flags)
+{
+ __asm__ __volatile__(
+ "beqz %0, 1f\n"
+ "gie_enable\n"
+ "1:"
+ :: "r" (flags) );
+}
+static inline int arch_irqs_disabled_flags(unsigned long flags)
+{
+ return !flags;
+}
+#if 0
+#define raw_local_irq_save(x) \
+ __asm__ __volatile__( \
+ "mfsr %0, $PSW\n" \
+ "andi %0, %0, #0x1\n" \
+ "gie_disable\n" \
+ : "=r" (x) )
+#define raw_local_save_flags(x) \
+ __asm__ __volatile__( \
+ "mfsr %0, $PSW\n" \
+ "andi %0, %0, #0x1" \
+ : "=r" (x) )
+#define raw_local_irq_restore(x) \
+ __asm__ __volatile__( \
+ "beqz %0, 1f\n" \
+ "gie_enable\n" \
+ "1:" \
+ :: "r" (x) )
+
+#define raw_irqs_disabled_flags(x) !(x)
+#endif
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/irq.h linux-3.4.113/arch/nds32/include/asm/irq.h
--- linux-3.4.113.orig/arch/nds32/include/asm/irq.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/irq.h 2016-12-01 20:59:24.336612134 +0100
@@ -0,0 +1,50 @@
+/*
+ * linux/arch/nds32/include/asm/irq.h
+ * Copyright (C) 2008 Andes Technology Corporation
+ */
+
+#ifndef __ASM_NDS32_IRQ_H
+#define __ASM_NDS32_IRQ_H
+
+#include <asm/spec.h>
+
+#ifndef irq_canonicalize
+#define irq_canonicalize(i) (i)
+#endif
+
+#ifndef NR_IRQS
+#define NR_IRQS 128
+#endif
+
+/*
+ * Use this value to indicate lack of interrupt
+ * capability
+ */
+#ifndef NO_IRQ
+#define NO_IRQ ((unsigned int)(-1))
+#endif
+
+struct irqaction;
+
+extern void disable_irq_nosync(unsigned int);
+extern void disable_irq(unsigned int);
+extern void enable_irq(unsigned int);
+
+#define __IRQT_FALEDGE IRQ_TYPE_EDGE_FALLING
+#define __IRQT_RISEDGE IRQ_TYPE_EDGE_RISING
+#define __IRQT_LOWLVL IRQ_TYPE_LEVEL_LOW
+#define __IRQT_HIGHLVL IRQ_TYPE_LEVEL_HIGH
+
+#define IRQT_NOEDGE (0)
+#define IRQT_RISING (__IRQT_RISEDGE)
+#define IRQT_FALLING (__IRQT_FALEDGE)
+#define IRQT_BOTHEDGE (__IRQT_RISEDGE|__IRQT_FALEDGE)
+#define IRQT_LOW (__IRQT_LOWLVL)
+#define IRQT_HIGH (__IRQT_HIGHLVL)
+#define IRQT_PROBE IRQ_TYPE_PROBE
+
+struct irqaction;
+struct pt_regs;
+
+#endif
+
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/irq_regs.h linux-3.4.113/arch/nds32/include/asm/irq_regs.h
--- linux-3.4.113.orig/arch/nds32/include/asm/irq_regs.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/irq_regs.h 2016-12-01 20:59:24.336612134 +0100
@@ -0,0 +1,9 @@
+/*
+ * linux/arch/nds32/include/asm/irq_regs.h
+ * Copyright (C) 2008 Andes Technology Corporation
+ */
+
+#ifndef __NDS32_IRQ_REGS_H__
+#define __NDS32_IRQ_REGS_H__
+#include <asm-generic/irq_regs.h>
+#endif /* __NDS32_IRQ_REGS_H__ */
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/Kbuild linux-3.4.113/arch/nds32/include/asm/Kbuild
--- linux-3.4.113.orig/arch/nds32/include/asm/Kbuild 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/Kbuild 2016-12-01 20:59:24.336612134 +0100
@@ -0,0 +1,3 @@
+include include/asm-generic/Kbuild.asm
+
+header-y += pfm.h
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/kdebug.h linux-3.4.113/arch/nds32/include/asm/kdebug.h
--- linux-3.4.113.orig/arch/nds32/include/asm/kdebug.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/kdebug.h 2016-12-01 20:59:24.336612134 +0100
@@ -0,0 +1,14 @@
+/*
+ * linux/arch/nds32/include/asm/kdebug.h
+ * Copyright (C) 2008 Andes Technology Corporation
+ */
+
+#ifndef __NDS32_KDEBUG_H__
+#define __NDS32_KDEBUG_H__
+
+enum die_val {
+ DIE_OOPS = 1,
+ DIE_DEBUG,
+};
+
+#endif /* __NDS32_KDEBUG_H__ */
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/kexec.h linux-3.4.113/arch/nds32/include/asm/kexec.h
--- linux-3.4.113.orig/arch/nds32/include/asm/kexec.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/kexec.h 2016-12-01 20:59:24.336612134 +0100
@@ -0,0 +1,31 @@
+#ifndef _NDS32_KEXEC_H
+#define _NDS32_KEXEC_H
+
+#ifdef CONFIG_KEXEC
+
+/* Maximum physical address we can use pages from */
+#define KEXEC_SOURCE_MEMORY_LIMIT (-1UL)
+/* Maximum address we can reach in physical address mode */
+#define KEXEC_DESTINATION_MEMORY_LIMIT (-1UL)
+/* Maximum address we can use for the control code buffer */
+#define KEXEC_CONTROL_MEMORY_LIMIT (-1UL)
+
+#define KEXEC_CONTROL_PAGE_SIZE 4096
+
+#define KEXEC_ARCH KEXEC_ARCH_NDS32
+
+#define KEXEC_NDS32_ATAGS_OFFSET 0x1000
+#define KEXEC_NDS32_ZIMAGE_OFFSET 0x500000
+
+#ifndef __ASSEMBLY__
+
+struct kimage;
+/* Provide a dummy definition to avoid build failures. */
+static inline void crash_setup_regs(struct pt_regs *newregs,
+ struct pt_regs *oldregs) { }
+
+#endif /* __ASSEMBLY__ */
+
+#endif /* CONFIG_KEXEC */
+
+#endif /* _NDS32_KEXEC_H */
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/kgdb.h linux-3.4.113/arch/nds32/include/asm/kgdb.h
--- linux-3.4.113.orig/arch/nds32/include/asm/kgdb.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/kgdb.h 2016-12-01 20:59:24.336612134 +0100
@@ -0,0 +1,90 @@
+/* ============================================================================
+ *
+ * linux/arch/nds32/include/asm/kgdb.h
+ *
+ * Copyright (C) 2007 Andes Technology Corporation
+ * This file is part of Linux and should be licensed under the GPL.
+ * See the file COPYING for conditions for redistribution.
+ *
+ * Abstract:
+ *
+ * This program is for NDS32 KGDB support.
+ *
+ * Author: Harry Pan
+ *
+ * Revision History:
+ *
+ * Jul.14.2007 Initial ported by Harry.
+ *
+ * Note:
+ *
+ * ============================================================================
+ */
+#ifndef __ASM_NDS32_KGDB_H__
+#define __ASM_NDS32_KGDB_H__
+
+#include <asm/ptrace.h>
+
+#define BREAK_INSTR_SIZE 2
+#define CACHE_FLUSH_IS_SAFE 1
+
+#ifndef __ASSEMBLY__
+
+/*
+ * Define numbers of registers we have in NDS32 arch
+ */
+#define NDS32_NUM_GR 32 // general registers.
+#define NDS32_NUM_SPR 5 // special registers. (PC, D0, D1)
+#define NDS32_NUM_CR 6 // ctrl registers.
+#define NDS32_NUM_IR 16 // interruption registers.
+#define NDS32_NUM_MR 11 // MMU registers.
+#define NDS32_NUM_DR 48 // debug registers.
+#define NDS32_NUM_PFR 4 // performance monitoring registers.
+#define NDS32_NUM_DMAR 11 // local memory DMA registers
+#define NDS32_NUM_RACR 1 // resource access control registers.
+#define NDS32_NUM_IDR 2 // implementation dependent registers.
+#define NDS32_NUM_SR (NDS32_NUM_CR + NDS32_NUM_IR + NDS32_NUM_MR + \
+ NDS32_NUM_DR + NDS32_NUM_PFR + NDS32_NUM_DMAR + \
+ NDS32_NUM_RACR + NDS32_NUM_IDR)
+#define NDS32_NUM_REGS (NDS32_NUM_GR + NDS32_NUM_SPR + NDS32_NUM_SR)
+
+#define KGDB_MAX_NO_CPUS 1
+#define BUFMAX 2048
+#define NUMREGBYTES (NDS32_NUM_REGS << 2)
+
+/*
+ * NDS32 virtual registers layout for GDB.
+ */
+enum nds32_regnum
+{
+ NDS32_R0_REGNUM = 0, // first integer-like argument.
+ NDS32_R5_REGNUM = 5, // last integer-like argument.
+ NDS32_FP_REGNUM = 28, // frame register
+ NDS32_LP_REGNUM = 30, // link pointer
+ NDS32_SP_REGNUM = 31, // address of stack top.
+ NDS32_PC_REGNUM = 32,
+ NDS32_D0LO_REGNUM = 33,
+ NDS32_D0HI_REGNUM = 34,
+ NDS32_D1LO_REGNUM = 35,
+ NDS32_D1HI_REGNUM = 36,
+ NDS32_CR0_REGNUM = 37,
+ NDS32_IR0_REGNUM = (NDS32_CR0_REGNUM + NDS32_NUM_CR),
+ NDS32_MR0_REGNUM = (NDS32_IR0_REGNUM + NDS32_NUM_IR),
+ NDS32_DR0_REGNUM = (NDS32_MR0_REGNUM + NDS32_NUM_MR),
+ NDS32_PFR0_REGNUM = (NDS32_DR0_REGNUM + NDS32_NUM_DR),
+ NDS32_DMAR0_REGNUM = (NDS32_PFR0_REGNUM + NDS32_NUM_PFR),
+ NDS32_RACR0_REGNUM = (NDS32_DMAR0_REGNUM + NDS32_NUM_DMAR),
+ NDS32_IDR0_REGNUM = (NDS32_RACR0_REGNUM + NDS32_NUM_RACR),
+ /* nds32 calling convention. */
+ NDS32_ARG0_REGNUM = NDS32_R0_REGNUM,
+ NDS32_ARGN_REGNUM = NDS32_R5_REGNUM,
+ NDS32_RET_REGNUM = NDS32_R0_REGNUM,
+};
+
+static inline void arch_kgdb_breakpoint(void)
+{
+ asm __volatile__ ( "break 0x1ff\n" );
+}
+
+#endif /* !__ASSEMBLY__ */
+#endif /* __ASM_NDS32_KGDB_H__ */
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/kmap_types.h linux-3.4.113/arch/nds32/include/asm/kmap_types.h
--- linux-3.4.113.orig/arch/nds32/include/asm/kmap_types.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/kmap_types.h 2016-12-01 20:59:24.336612134 +0100
@@ -0,0 +1,29 @@
+/*
+ * linux/arch/nds32/include/asm/kmap-types.h
+ * Copyright (C) 2008 Andes Technology Corporation
+ */
+
+#ifndef __NDS32_KMAP_TYPES_H
+#define __NDS32_KMAP_TYPES_H
+
+/*
+ * This is the "bare minimum". AIO seems to require this.
+ */
+enum km_type {
+ KM_BOUNCE_READ,
+ KM_SKB_SUNRPC_DATA,
+ KM_SKB_DATA_SOFTIRQ,
+ KM_USER0,
+ KM_USER1,
+ KM_BIO_SRC_IRQ,
+ KM_BIO_DST_IRQ,
+ KM_PTE0,
+ KM_PTE1,
+ KM_IRQ0,
+ KM_IRQ1,
+ KM_SOFTIRQ0,
+ KM_SOFTIRQ1,
+ KM_TYPE_NR
+};
+
+#endif
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/kprobes.h linux-3.4.113/arch/nds32/include/asm/kprobes.h
--- linux-3.4.113.orig/arch/nds32/include/asm/kprobes.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/kprobes.h 2016-12-01 20:59:24.340612287 +0100
@@ -0,0 +1,86 @@
+#ifndef _ASM_ANDES_KPROBES_H
+#define _ASM_ANDES_KPROBES_H
+/*
+ * Kernel Probes (KProbes)
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * Copyright (C) IBM Corporation, 2002, 2004
+ *
+ * See arch/x86/kernel/kprobes.c for x86 kprobes history.
+ */
+#include <linux/types.h>
+#include <linux/ptrace.h>
+#include <linux/percpu.h>
+
+#define __ARCH_WANT_KPROBES_INSN_SLOT
+
+struct pt_regs;
+struct kprobe;
+
+typedef unsigned short kprobe_opcode_t;
+
+#define MAX_INSN_SIZE 2
+#define MAX_STACK_SIZE 64
+#define MIN_STACK_SIZE(ADDR) \
+ (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
+ THREAD_SIZE - (unsigned long)(ADDR))) \
+ ? (MAX_STACK_SIZE) \
+ : (((unsigned long)current_thread_info()) + \
+ THREAD_SIZE - (unsigned long)(ADDR)))
+#define regs_return_value(regs) ((regs)->NDS32_r0)
+#define flush_insn_slot(p) do { } while (0)
+#define kretprobe_blacklist_size 0
+
+void arch_remove_kprobe(struct kprobe *p);
+void kretprobe_trampoline(void);
+
+/* Architecture specific copy of original instruction*/
+struct arch_specific_insn {
+ /* copy of the original instruction */
+ kprobe_opcode_t *insn;
+ /*
+ * boostable = -1: This instruction type is not boostable.
+ * boostable = 0: This instruction type is boostable.
+ * boostable = 1: This instruction has been boosted: we have
+ * added a relative jump after the instruction copy in insn,
+ * so no single-step and fixup are needed (unless there's
+ * a post_handler or break_handler).
+ */
+ int boostable;
+};
+
+struct prev_kprobe {
+ struct kprobe *kp;
+ unsigned long status;
+ unsigned long old_flags;
+ unsigned long saved_flags;
+};
+
+/* per-cpu kprobe control block */
+struct kprobe_ctlblk {
+ unsigned long kprobe_status;
+ unsigned long kprobe_old_flags;
+ unsigned long kprobe_saved_flags;
+ unsigned long *jprobe_saved_sp;
+ struct pt_regs jprobe_saved_regs;
+ kprobe_opcode_t jprobes_stack[MAX_STACK_SIZE];
+ struct prev_kprobe prev_kprobe;
+};
+
+extern int kprobe_fault_handler(struct pt_regs *regs, int trapnr);
+extern int kprobe_exceptions_notify(struct notifier_block *self,
+ unsigned long val, void *data);
+#endif /* _ASM_ANDES_KPROBES_H */
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/kvm.h linux-3.4.113/arch/nds32/include/asm/kvm.h
--- linux-3.4.113.orig/arch/nds32/include/asm/kvm.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/kvm.h 2016-12-01 20:59:24.340612287 +0100
@@ -0,0 +1,9 @@
+/*
+ * linux/arch/nds32/include/asm/kvm.h
+ * Copyright (C) 2008 Andes Technology Corporation
+ */
+
+#ifndef __NDS32_KVM_H__
+#define __NDS32_KVM_H__
+
+#endif /* __NDS32_KVM_H__ */
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/l2_cache.h linux-3.4.113/arch/nds32/include/asm/l2_cache.h
--- linux-3.4.113.orig/arch/nds32/include/asm/l2_cache.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/l2_cache.h 2016-12-01 20:59:24.340612287 +0100
@@ -0,0 +1,134 @@
+/*
+ * linux/arch/nds32/include/asm/l2_cache.h
+ * Copyright (C) 2008 Andes Technology Corporation
+ */
+
+#ifndef L2_CACHE_H
+#define L2_CACHE_H
+
+// CCTL_CMD_OP
+#define L2_CA_CONF_OFF 0x0
+#define L2_IF_CONF_OFF 0x4
+#define L2CC_SETUP_OFF 0x8
+#define L2CC_PROT_OFF 0xC
+#define L2CC_CTRL_OFF 0x10
+#define L2_INT_EN_OFF 0x20
+#define L2_STA_OFF 0x24
+#define RDERR_ADDR_OFF 0x28
+#define WRERR_ADDR_OFF 0x2c
+#define EVDPTERR_ADDR_OFF 0x30
+#define IMPL3ERR_ADDR_OFF 0x34
+#define L2_CNT0_CTRL_OFF 0x40
+#define L2_EVNT_CNT0_OFF 0x44
+#define L2_CNT1_CTRL_OFF 0x48
+#define L2_EVNT_CNT1_OFF 0x4c
+#define L2_CCTL_CMD_OFF 0x60
+#define L2_CCTL_STATUS_OFF 0x64
+#define L2_LINE_TAG_OFF 0x68
+#define L2_LINE_DPT_OFF 0x70
+
+#define CCTL_CMD_L2_IX_INVAL 0x0
+#define CCTL_CMD_L2_PA_INVAL 0x1
+#define CCTL_CMD_L2_IX_WB 0x2
+#define CCTL_CMD_L2_PA_WB 0x3
+#define CCTL_CMD_L2_PA_WBINVAL 0x5
+#define CCTL_CMD_L2_SYNC 0xa
+// CCTL_CMD_TYPE
+#define CCTL_SINGLE_CMD 0
+#define CCTL_BLOCK_CMD 0x10
+#define CCTL_ALL_CMD 0x10
+
+/******************************************************************************
+ * L2_CA_CONF (Cache architecture configuration)
+ *****************************************************************************/
+#define L2_CA_CONF_offL2SET 0
+#define L2_CA_CONF_offL2WAY 4
+#define L2_CA_CONF_offL2CLSZ 8
+#define L2_CA_CONF_offL2DW 11
+#define L2_CA_CONF_offL2PT 14
+#define L2_CA_CONF_offL2VER 16
+
+#define L2_CA_CONF_mskL2SET (0xFUL << L2_CA_CONF_offL2SET)
+#define L2_CA_CONF_mskL2WAY (0xFUL << L2_CA_CONF_offL2WAY)
+#define L2_CA_CONF_mskL2CLSZ (0x7UL << L2_CA_CONF_offL2CLSZ)
+#define L2_CA_CONF_mskL2DW (0x7UL << L2_CA_CONF_offL2DW)
+#define L2_CA_CONF_mskL2PT (0x3UL << L2_CA_CONF_offL2PT)
+#define L2_CA_CONF_mskL2VER (0xFFFFUL << L2_CA_CONF_offL2VER)
+
+/******************************************************************************
+ * L2CC_SETUP (L2CC Setup register)
+ *****************************************************************************/
+#define L2CC_SETUP_offPART 0
+#define L2CC_SETUP_mskPART (0x3UL << L2CC_SETUP_offPART)
+#define L2CC_SETUP_offDDLATC 4
+#define L2CC_SETUP_mskDDLATC (0x3UL << L2CC_SETUP_offDDLATC)
+#define L2CC_SETUP_offTDLATC 8
+#define L2CC_SETUP_mskTDLATC (0x3UL << L2CC_SETUP_offTDLATC)
+
+/******************************************************************************
+ * L2CC_PROT (L2CC Protect register)
+ *****************************************************************************/
+#define L2CC_PROT_offMRWEN 31
+#define L2CC_PROT_mskMRWEN (0x1UL << L2CC_PROT_offMRWEN)
+//TODO finish this table
+//
+/******************************************************************************
+ * L2_CCTL_STATUS_Mn (The L2CCTL command working status for Master n)
+ *****************************************************************************/
+#define L2CC_CTRL_offEN 31
+#define L2CC_CTRL_mskEN (0x1UL << L2CC_CTRL_offEN)
+
+/******************************************************************************
+ * L2_CCTL_STATUS_Mn (The L2CCTL command working status for Master n)
+ *****************************************************************************/
+#define L2_CCTL_STATUS_offCMD_COMP 31
+#define L2_CCTL_STATUS_mskCMD_COMP (0x1 << L2_CCTL_STATUS_offCMD_COMP)
+//TODO finish this table
+
+#ifndef __ASSEMBLY__
+
+#include <linux/smp.h>
+#include <asm/io.h>
+#include <asm/bitfield.h>
+
+#define L2C_R_REG(offset) inl(L2CC_VA_BASE + offset)
+#define L2C_W_REG(offset, value) outl(value, L2CC_VA_BASE + offset)
+
+#define L2_CMD_RDY() \
+ do{;}while((L2C_R_REG(L2_CCTL_STATUS_OFF) & L2_CCTL_STATUS_mskCMD_COMP) == 0)
+
+static inline unsigned long L2_CACHE_SET(void){
+ return 64 << ( ( L2C_R_REG(L2_CA_CONF_OFF) & L2_CA_CONF_mskL2SET) >> L2_CA_CONF_offL2SET);
+}
+
+static inline unsigned long L2_CACHE_WAY(void){
+ return 1 + ( ( L2C_R_REG(L2_CA_CONF_OFF) & L2_CA_CONF_mskL2WAY) >> L2_CA_CONF_offL2WAY);
+}
+
+static inline unsigned long L2_CACHE_LINE_SIZE(void){
+
+ return 4 << ( ( L2C_R_REG(L2_CA_CONF_OFF) & L2_CA_CONF_mskL2CLSZ) >> L2_CA_CONF_offL2CLSZ);
+}
+
+static inline unsigned long GET_L2CC_CTRL_CPU(unsigned long cpu){
+ if(cpu == smp_processor_id())
+ return L2C_R_REG(L2CC_CTRL_OFF);
+ return L2C_R_REG(L2CC_CTRL_OFF+(cpu<<8));
+}
+
+static inline void SET_L2CC_CTRL_CPU(unsigned long cpu , unsigned long val){
+ if(cpu == smp_processor_id())
+ L2C_W_REG(L2CC_CTRL_OFF,val);
+ else
+ L2C_W_REG(L2CC_CTRL_OFF+(cpu<<8),val);
+}
+
+static inline unsigned long GET_L2CC_STATUS_CPU(unsigned long cpu){
+ if(cpu == smp_processor_id())
+ return L2C_R_REG(L2_CCTL_STATUS_OFF);
+ return L2C_R_REG(L2_CCTL_STATUS_OFF+(cpu<<8));
+}
+
+#endif
+
+#endif //L2_CACHE_H
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/leds.h linux-3.4.113/arch/nds32/include/asm/leds.h
--- linux-3.4.113.orig/arch/nds32/include/asm/leds.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/leds.h 2016-12-01 20:59:24.340612287 +0100
@@ -0,0 +1,51 @@
+/*
+ * linux/arch/nds32/include/asm/leds.h
+ *
+ * Copyright (C) 1998 Russell King
+ * Copyright (C) 2008 Andes Technology Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Event-driven interface for LEDs on machines
+ * Added led_start and led_stop- Alex Holden, 28th Dec 1998.
+ */
+#ifndef ASM_NDS32_LEDS_H
+#define ASM_NDS32_LEDS_H
+
+
+typedef enum {
+ led_idle_start,
+ led_idle_end,
+ led_timer,
+ led_start,
+ led_stop,
+ led_claim, /* override idle & timer leds */
+ led_release, /* restore idle & timer leds */
+ led_start_timer_mode,
+ led_stop_timer_mode,
+ led_green_on,
+ led_green_off,
+ led_amber_on,
+ led_amber_off,
+ led_red_on,
+ led_red_off,
+ led_blue_on,
+ led_blue_off,
+ /*
+ * I want this between led_timer and led_start, but
+ * someone has decided to export this to user space
+ */
+ led_halted
+} led_event_t;
+
+/* Use this routine to handle LEDs */
+
+#ifdef CONFIG_LEDS
+extern void (*leds_event)(led_event_t);
+#else
+#define leds_event(e)
+#endif
+
+#endif
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/limits.h linux-3.4.113/arch/nds32/include/asm/limits.h
--- linux-3.4.113.orig/arch/nds32/include/asm/limits.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/limits.h 2016-12-01 20:59:24.340612287 +0100
@@ -0,0 +1,16 @@
+/*
+ * linux/arch/nds32/include/asm/limits.h
+ * Copyright (C) 2008 Andes Technology Corporation
+ */
+
+#ifndef __ASM_PIPE_H
+#define __ASM_PIPE_H
+
+#ifndef PAGE_SIZE
+#include <asm/page.h>
+#endif
+
+#define PIPE_BUF PAGE_SIZE
+
+#endif
+
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/linkage.h linux-3.4.113/arch/nds32/include/asm/linkage.h
--- linux-3.4.113.orig/arch/nds32/include/asm/linkage.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/linkage.h 2016-12-01 20:59:24.340612287 +0100
@@ -0,0 +1,12 @@
+/*
+ * linux/arch/nds32/include/asm/linkage.h
+ * Copyright (C) 2008 Andes Technology Corporation
+ */
+
+#ifndef __NDS32_LINKAGE_H__
+#define __NDS32_LINKAGE_H__
+
+#define __ALIGN .align 2
+#define __ALIGN_STR ".align 2"
+
+#endif
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/local.h linux-3.4.113/arch/nds32/include/asm/local.h
--- linux-3.4.113.orig/arch/nds32/include/asm/local.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/local.h 2016-12-01 20:59:24.340612287 +0100
@@ -0,0 +1,11 @@
+/*
+ * linux/arch/nds32/include/asm/local.h
+ * Copyright (C) 2008 Andes Technology Corporation
+ */
+
+#ifndef __NDS32_LOCAL_H__
+#define __NDS32_LOCAL_H__
+
+#include <asm-generic/local.h>
+
+#endif
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/mach/arch.h linux-3.4.113/arch/nds32/include/asm/mach/arch.h
--- linux-3.4.113.orig/arch/nds32/include/asm/mach/arch.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/mach/arch.h 2016-12-01 20:59:24.340612287 +0100
@@ -0,0 +1,86 @@
+/*
+ * linux/arch/nds32/include/asm/mach/arch.h
+ *
+ * Copyright (C) 2000 Russell King
+ * Copyright (C) 2008 Andes Technology Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#ifndef __ASSEMBLY__
+
+struct tag;
+struct meminfo;
+struct sys_timer;
+
+struct machine_desc {
+ /*
+ * Note! The first four elements are used
+ * by assembler code in head-armv.S
+ */
+ unsigned int nr; /* architecture number */
+
+ const char *name; /* architecture name */
+ unsigned int param_offset; /* parameter page */
+
+ unsigned int video_start; /* start of video RAM */
+ unsigned int video_end; /* end of video RAM */
+
+ unsigned int reserve_lp0 :1; /* never has lp0 */
+ unsigned int reserve_lp1 :1; /* never has lp1 */
+ unsigned int reserve_lp2 :1; /* never has lp2 */
+ unsigned int soft_reboot :1; /* soft reboot */
+ void (*fixup)(struct machine_desc *,
+ struct tag *, char **,
+ struct meminfo *);
+ void (*map_io)(void);/* IO mapping function */
+ void (*init_irq)(void);
+ struct sys_timer *timer; /* system tick timer */
+ void (*init_machine)(void);
+};
+
+/*
+ * * Current machine - only accessible during boot.
+ * */
+extern struct machine_desc *machine_desc;
+
+/*
+ * Set of macros to define architecture features. This is built into
+ * a table by the linker.
+ */
+#define MACHINE_START(_type,_name) \
+const struct machine_desc __mach_desc_##_type \
+ __attribute__((__section__(".arch.info"))) = { \
+ .nr = MACH_TYPE_##_type, \
+ .name = _name,
+
+#define MAINTAINER(n)
+
+#define BOOT_PARAMS(_params) \
+ .param_offset = _params,
+
+#define VIDEO(_start,_end) \
+ .video_start = _start, \
+ .video_end = _end,
+
+#define DISABLE_PARPORT(_n) \
+ .reserve_lp##_n = 1,
+
+#define SOFT_REBOOT \
+ .soft_reboot = 1,
+
+#define MAPIO(_func) \
+ .map_io = _func,
+
+#define INITIRQ(_func) \
+ .init_irq = _func,
+
+#define INIT_MACHINE(_func) \
+ .init_machine = _func,
+
+#define MACHINE_END \
+};
+
+#endif
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/mach/dma.h linux-3.4.113/arch/nds32/include/asm/mach/dma.h
--- linux-3.4.113.orig/arch/nds32/include/asm/mach/dma.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/mach/dma.h 2016-12-01 20:59:24.340612287 +0100
@@ -0,0 +1,56 @@
+/*
+ * linux/arch/nds32/include/asm/mach/dma.h
+ *
+ * Copyright (C) 1998-2000 Russell King
+ * Copyright (C) 2008 Andes Technology Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This header file describes the interface between the generic DMA handler
+ * (dma.c) and the architecture-specific DMA backends (dma-*.c)
+ */
+
+struct dma_struct;
+typedef struct dma_struct dma_t;
+
+struct dma_ops {
+ int (*request)(dmach_t, dma_t *); /* optional */
+ void (*free)(dmach_t, dma_t *); /* optional */
+ void (*enable)(dmach_t, dma_t *); /* mandatory */
+ void (*disable)(dmach_t, dma_t *); /* mandatory */
+ int (*residue)(dmach_t, dma_t *); /* optional */
+ int (*setspeed)(dmach_t, dma_t *, int); /* optional */
+ char *type;
+};
+
+struct dma_struct {
+ struct scatterlist buf; /* single DMA */
+ int sgcount; /* number of DMA SG */
+ struct scatterlist *sg; /* DMA Scatter-Gather List */
+
+ unsigned int active:1; /* Transfer active */
+ unsigned int invalid:1; /* Address/Count changed */
+ unsigned int using_sg:1; /* using scatter list? */
+ dmamode_t dma_mode; /* DMA mode */
+ int speed; /* DMA speed */
+
+ unsigned int lock; /* Device is allocated */
+ const char *device_id; /* Device name */
+
+ unsigned int dma_base; /* Controller base address */
+ int dma_irq; /* Controller IRQ */
+ struct scatterlist cur_sg; /* Current controller buffer */
+ unsigned int state;
+
+ struct dma_ops *d_ops;
+};
+
+/* Prototype: void arch_dma_init(dma)
+ * Purpose : Initialise architecture specific DMA
+ * Params : dma - pointer to array of DMA structures
+ */
+extern void arch_dma_init(dma_t *dma);
+
+extern void isa_init_dma(dma_t *dma);
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/mach/flash.h linux-3.4.113/arch/nds32/include/asm/mach/flash.h
--- linux-3.4.113.orig/arch/nds32/include/asm/mach/flash.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/mach/flash.h 2016-12-01 20:59:24.340612287 +0100
@@ -0,0 +1,35 @@
+/*
+ * linux/arch/nds32/include/asm/mach/flash.h
+ *
+ * Copyright (C) 2003 Russell King, All Rights Reserved.
+ * Copyright (C) 2008 Andes Technology Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+#ifndef ASMNDS32_MACH_FLASH_H
+#define ASMNDS32_MACH_FLASH_H
+
+struct mtd_partition;
+
+/*
+ * map_name: the map probe function name
+ * width: width of mapped device
+ * init: method called at driver/device initialisation
+ * exit: method called at driver/device removal
+ * set_vpp: method called to enable or disable VPP
+ * parts: optional array of mtd_partitions for static partitioning
+ * nr_parts: number of mtd_partitions for static partitoning
+ */
+struct flash_platform_data {
+ const char *map_name;
+ unsigned int width;
+ int (*init)(void);
+ void (*exit)(void);
+ void (*set_vpp)(int on);
+ struct mtd_partition *parts;
+ unsigned int nr_parts;
+};
+
+#endif
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/mach/irda.h linux-3.4.113/arch/nds32/include/asm/mach/irda.h
--- linux-3.4.113.orig/arch/nds32/include/asm/mach/irda.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/mach/irda.h 2016-12-01 20:59:24.340612287 +0100
@@ -0,0 +1,21 @@
+/*
+ * linux/arch/nds32/include/asm/mach/irda.h
+ *
+ * Copyright (C) 2004 Russell King.
+ * Copyright (C) 2008 Andes Technology Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+#ifndef __ASM_NDS32_MACH_IRDA_H
+#define __ASM_NDS32_MACH_IRDA_H
+
+struct irda_platform_data {
+ int (*startup)(struct device *);
+ void (*shutdown)(struct device *);
+ int (*set_power)(struct device *, unsigned int state);
+ void (*set_speed)(struct device *, unsigned int speed);
+};
+
+#endif
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/mach/map.h linux-3.4.113/arch/nds32/include/asm/mach/map.h
--- linux-3.4.113.orig/arch/nds32/include/asm/mach/map.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/mach/map.h 2016-12-01 20:59:24.340612287 +0100
@@ -0,0 +1,37 @@
+/*
+ * linux/arch/nds32/include/asm/mach/map.h
+ *
+ * Copyright (C) 1999-2000 Russell King
+ * Copyright (C) 2008 Andes Technology Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Page table mapping constructs and function prototypes
+ */
+struct map_desc {
+ unsigned long virtual;
+ unsigned long physical;
+ unsigned long length;
+ unsigned int type;
+};
+
+struct meminfo;
+
+#define MT_DEVICE_NCB MT_DEVICE
+#define MT_DEVICE_NCNB MT_DEVICE
+#define MT_DEVICE 0
+#define MT_CACHECLEAN 1
+#define MT_MINICLEAN 2
+#define MT_CACHE_L1 3
+#define MT_UXKRWX_V1 4
+#define MT_UXKRWX_V2 5
+#define MT_MEMORY 6
+#define MT_ROM 7
+#define MT_ILM 8
+#define MT_DLM 9
+
+extern void create_memmap_holes(struct meminfo *);
+extern void iotable_init(struct map_desc *, int);
+extern void setup_io_desc(void);
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/mach/mmc.h linux-3.4.113/arch/nds32/include/asm/mach/mmc.h
--- linux-3.4.113.orig/arch/nds32/include/asm/mach/mmc.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/mach/mmc.h 2016-12-01 20:59:24.340612287 +0100
@@ -0,0 +1,16 @@
+/*
+ * linux/arch/nds32/include/asm/mach/mmc.h
+ * Copyright (C) 2008 Andes Technology Corporation
+ */
+#ifndef ASMNDS32_MACH_MMC_H
+#define ASMNDS32_MACH_MMC_H
+
+#include <linux/mmc/protocol.h>
+
+struct mmc_platform_data {
+ unsigned int ocr_mask; /* available voltages */
+ u32 (*translate_vdd)(struct device *, unsigned int);
+ unsigned int (*status)(struct device *);
+};
+
+#endif
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/mach/pci.h linux-3.4.113/arch/nds32/include/asm/mach/pci.h
--- linux-3.4.113.orig/arch/nds32/include/asm/mach/pci.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/mach/pci.h 2016-12-01 20:59:24.340612287 +0100
@@ -0,0 +1,76 @@
+/*
+ * linux/arch/nds32/include/asm/mach/pci.h
+ *
+ * Copyright (C) 2000 Russell King
+ * Copyright (C) 2008 Andes Technology Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+struct pci_sys_data;
+struct pci_bus;
+
+struct hw_pci {
+ struct list_head buses;
+ int nr_controllers;
+ int (*setup)(int nr, struct pci_sys_data *);
+ struct pci_bus *(*scan)(int nr, struct pci_sys_data *);
+ void (*preinit)(void);
+ void (*postinit)(void);
+ u8 (*swizzle)(struct pci_dev *dev, u8 *pin);
+ int (*map_irq)(struct pci_dev *dev, u8 slot, u8 pin);
+};
+
+/*
+ * Per-controller structure
+ */
+struct pci_sys_data {
+ struct list_head node;
+ int busnr; /* primary bus number */
+ unsigned long mem_offset; /* bus->cpu memory mapping offset */
+ unsigned long io_offset; /* bus->cpu IO mapping offset */
+ struct pci_bus *bus; /* PCI bus */
+ struct resource *resource[3]; /* Primary PCI bus resources */
+ /* Bridge swizzling */
+ u8 (*swizzle)(struct pci_dev *, u8 *);
+ /* IRQ mapping */
+ int (*map_irq)(struct pci_dev *, u8, u8);
+ struct hw_pci *hw;
+};
+
+/*
+ * This is the standard PCI-PCI bridge swizzling algorithm.
+ */
+u8 pci_std_swizzle(struct pci_dev *dev, u8 *pinp);
+
+/*
+ * Call this with your hw_pci struct to initialise the PCI system.
+ */
+void pci_common_init(struct hw_pci *);
+
+/*
+ * PCI controllers
+ */
+extern int iop321_setup(int nr, struct pci_sys_data *);
+extern struct pci_bus *iop321_scan_bus(int nr, struct pci_sys_data *);
+extern void iop321_init(void);
+
+extern int iop331_setup(int nr, struct pci_sys_data *);
+extern struct pci_bus *iop331_scan_bus(int nr, struct pci_sys_data *);
+extern void iop331_init(void);
+
+extern int dc21285_setup(int nr, struct pci_sys_data *);
+extern struct pci_bus *dc21285_scan_bus(int nr, struct pci_sys_data *);
+extern void dc21285_preinit(void);
+extern void dc21285_postinit(void);
+
+extern int via82c505_setup(int nr, struct pci_sys_data *);
+extern struct pci_bus *via82c505_scan_bus(int nr, struct pci_sys_data *);
+extern void via82c505_init(void *sysdata);
+
+extern int pci_v3_setup(int nr, struct pci_sys_data *);
+extern struct pci_bus *pci_v3_scan_bus(int nr, struct pci_sys_data *);
+extern void pci_v3_preinit(void);
+extern void pci_v3_postinit(void);
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/mach/serial_sa1100.h linux-3.4.113/arch/nds32/include/asm/mach/serial_sa1100.h
--- linux-3.4.113.orig/arch/nds32/include/asm/mach/serial_sa1100.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/mach/serial_sa1100.h 2016-12-01 20:59:24.340612287 +0100
@@ -0,0 +1,31 @@
+/*
+ * linux/include/asm-arm/mach/serial_sa1100.h
+ *
+ * Author: Nicolas Pitre
+ *
+ * Moved to include/asm-arm/mach and changed lots, Russell King
+ *
+ * Low level machine dependent UART functions.
+ */
+
+struct uart_port;
+struct uart_info;
+
+/*
+ * This is a temporary structure for registering these
+ * functions; it is intended to be discarded after boot.
+ */
+struct sa1100_port_fns {
+ void (*set_mctrl)(struct uart_port *, u_int);
+ u_int (*get_mctrl)(struct uart_port *);
+ void (*pm)(struct uart_port *, u_int, u_int);
+ int (*set_wake)(struct uart_port *, u_int);
+};
+
+#ifdef CONFIG_SERIAL_SA1100
+void sa1100_register_uart_fns(struct sa1100_port_fns *fns);
+void sa1100_register_uart(int idx, int port);
+#else
+#define sa1100_register_uart_fns(fns) do { } while (0)
+#define sa1100_register_uart(idx,port) do { } while (0)
+#endif
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/mach/time.h linux-3.4.113/arch/nds32/include/asm/mach/time.h
--- linux-3.4.113.orig/arch/nds32/include/asm/mach/time.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/mach/time.h 2016-12-01 20:59:24.340612287 +0100
@@ -0,0 +1,62 @@
+/*
+ * linux/arch/nds32/include/asm/mach/time.h
+ *
+ * Copyright (C) 2004 MontaVista Software, Inc.
+ * Copyright (C) 2008 Andes Technology Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+#ifndef __ASM_NDS32_MACH_TIME_H
+#define __ASM_NDS32_MACH_TIME_H
+
+//#include <linux/sysdev.h>
+
+/*
+ * This is our kernel timer structure.
+ *
+ * - init
+ * Initialise the kernels jiffy timer source, claim interrupt
+ * using setup_irq. This is called early on during initialisation
+ * while interrupts are still disabled on the local CPU.
+ * - suspend
+ * Suspend the kernel jiffy timer source, if necessary. This
+ * is called with interrupts disabled, after all normal devices
+ * have been suspended. If no action is required, set this to
+ * NULL.
+ * - resume
+ * Resume the kernel jiffy timer source, if necessary. This
+ * is called with interrupts disabled before any normal devices
+ * are resumed. If no action is required, set this to NULL.
+ * - offset
+ * Return the timer offset in microseconds since the last timer
+ * interrupt. Note: this must take account of any unprocessed
+ * timer interrupt which may be pending.
+ */
+
+/* + Tom from newlib
+ * Have the 32 bit jiffies value wrap 5 minutes after boot
+ * so jiffies wrap bugs show up earlier.
+ */
+//#define INITIAL_JIFFIES ((unsigned long)(unsigned int) (-300*HZ))
+
+struct sys_timer {
+// struct sys_device dev;
+ void (*init)(void);
+ void (*suspend)(void);
+ void (*resume)(void);
+ unsigned long (*offset)(void);
+};
+
+extern struct sys_timer *system_timer;
+extern void timer_tick( void);
+
+/*
+ * Kernel time keeping support.
+ */
+extern int (*set_rtc)(void);
+extern void save_time_delta(struct timespec *delta, struct timespec *rtc);
+extern void restore_time_delta(struct timespec *delta, struct timespec *rtc);
+
+#endif
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/mach-types.h linux-3.4.113/arch/nds32/include/asm/mach-types.h
--- linux-3.4.113.orig/arch/nds32/include/asm/mach-types.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/mach-types.h 2016-12-01 20:59:24.340612287 +0100
@@ -0,0 +1,14 @@
+#ifndef __ASSEMBLY__
+/* The type of machine we're running on */
+extern unsigned int __machine_arch_type;
+#endif
+
+#define MACH_TYPE_FARADAY 758
+
+# ifdef machine_arch_type
+# undef machine_arch_type
+# define machine_arch_type __machine_arch_type
+# else
+# define machine_arch_type MACH_TYPE_FARADAY
+# endif
+# define machine_is_faraday() (machine_arch_type == MACH_TYPE_FARADAY)
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/memory.h linux-3.4.113/arch/nds32/include/asm/memory.h
--- linux-3.4.113.orig/arch/nds32/include/asm/memory.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/memory.h 2016-12-01 20:59:24.340612287 +0100
@@ -0,0 +1,218 @@
+/*
+ * linux/arch/nds32/include/asm/memory.h
+ *
+ * Copyright (C) 2000-2002 Russell King
+ * Copyright (C) 2008 Andes Technology Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Note: this file should not be included by non-asm/.h files
+ */
+#ifndef __ASM_NDS32_MEMORY_H
+#define __ASM_NDS32_MEMORY_H
+
+#include <linux/compiler.h>
+#ifndef __FARADAY_PLATFORM_INDEPENDENT_MEMORY_HEADER__
+#define __FARADAY_PLATFORM_INDEPENDENT_MEMORY_HEADER__
+
+#include <asm/spec.h>
+
+#ifndef __ASSEMBLY__
+#include <asm/page.h>
+#endif
+
+#ifndef PHYS_OFFSET
+#define PHYS_OFFSET CPU_MEM_PA_BASE
+#endif
+
+#ifndef PAGE_OFFSET
+#define PAGE_OFFSET (0xC0000000)
+#endif
+
+#ifndef END_MEM
+#define END_MEM (CPU_MEM_PA_LIMIT)
+#endif
+
+#ifndef __virt_to_bus
+#define __virt_to_bus __virt_to_phys
+#endif
+
+#ifndef __bus_to_virt
+#define __bus_to_virt __phys_to_virt
+#endif
+
+#endif /* __FARADAY_PLATFORM_INDEPENDENT_MEMORY_HEADER__ */
+
+#ifndef TASK_SIZE
+/*
+ * TASK_SIZE - the maximum size of a user space task.
+ * TASK_UNMAPPED_BASE - the lower boundary of the mmap VM area
+ */
+#define TASK_SIZE (0xbf000000UL)
+#define TASK_UNMAPPED_BASE (0x40000000UL)
+#endif
+
+/*
+ * Page offset: 3GB
+ */
+#ifndef PAGE_OFFSET
+#define PAGE_OFFSET (0xc0000000)
+#endif
+
+/*
+ * Physical vs virtual RAM address space conversion. These are
+ * private definitions which should NOT be used outside memory.h
+ * files. Use virt_to_phys/phys_to_virt/__pa/__va instead.
+ */
+#ifndef __virt_to_phys
+#define __virt_to_phys(x) ((x) - PAGE_OFFSET + PHYS_OFFSET)
+#define __phys_to_virt(x) ((x) - PHYS_OFFSET + PAGE_OFFSET)
+#endif
+
+/*
+ * The module space lives between the addresses given by TASK_SIZE
+ * and PAGE_OFFSET - it must be within 32MB of the kernel text.
+ */
+#define MODULES_END (PAGE_OFFSET)
+#define MODULES_VADDR (MODULES_END - 16*1048576)
+
+#if TASK_SIZE > MODULES_VADDR
+#error Top of user space clashes with start of module space
+#endif
+
+#ifndef __ASSEMBLY__
+
+/*
+ * The DMA mask corresponding to the maximum bus address allocatable
+ * using GFP_DMA. The default here places no restriction on DMA
+ * allocations. This must be the smallest DMA mask in the system,
+ * so a successful GFP_DMA allocation will always satisfy this.
+ */
+#ifndef ISA_DMA_THRESHOLD
+#define ISA_DMA_THRESHOLD (0xffffffffULL)
+#endif
+
+#ifndef arch_adjust_zones
+#define arch_adjust_zones(node,size,holes) do { } while (0)
+#endif
+
+/*
+ * PFNs are used to describe any physical page; this means
+ * PFN 0 == physical address 0.
+ *
+ * This is the PFN of the first RAM page in the kernel
+ * direct-mapped view. We assume this is the first page
+ * of RAM in the mem_map as well.
+ */
+#define PHYS_PFN_OFFSET (PHYS_OFFSET >> PAGE_SHIFT)
+
+/*
+ * These are *only* valid on the kernel direct mapped RAM memory.
+ * Note: Drivers should NOT use these. They are the wrong
+ * translation for translating DMA addresses. Use the driver
+ * DMA support - see dma-mapping.h.
+ */
+static inline unsigned long virt_to_phys(void *x)
+{
+ return __virt_to_phys((unsigned long)(x));
+}
+
+static inline void *phys_to_virt(unsigned long x)
+{
+ return (void *)(__phys_to_virt((unsigned long)(x)));
+}
+
+/*
+ * Drivers should NOT use these either.
+ */
+#define __pa(x) __virt_to_phys((unsigned long)(x))
+#define __va(x) ((void *)__phys_to_virt((unsigned long)(x)))
+
+/*
+ * Virtual <-> DMA view memory address translations
+ * Again, these are *only* valid on the kernel direct mapped RAM
+ * memory. Use of these is *deprecated* (and that doesn't mean
+ * use the __ prefixed forms instead.) See dma-mapping.h.
+ */
+static inline __deprecated unsigned long virt_to_bus(void *x)
+{
+ return __virt_to_bus((unsigned long)x);
+}
+
+static inline __deprecated void *bus_to_virt(unsigned long x)
+{
+ return (void *)__bus_to_virt(x);
+}
+
+/*
+ * Conversion between a struct page and a physical address.
+ *
+ * Note: when converting an unknown physical address to a
+ * struct page, the resulting pointer must be validated
+ * using VALID_PAGE(). It must return an invalid struct page
+ * for any physical address not corresponding to a system
+ * RAM address.
+ *
+ * pfn_valid(pfn) indicates whether a PFN number is valid
+ *
+ * virt_to_page(k) convert a _valid_ virtual address to struct page *
+ * virt_addr_valid(k) indicates whether a virtual address is valid
+ */
+#ifndef CONFIG_DISCONTIGMEM
+
+#define ARCH_PFN_OFFSET PHYS_PFN_OFFSET
+#define pfn_valid(pfn) ((pfn) >= PHYS_PFN_OFFSET && (pfn) < (PHYS_PFN_OFFSET + max_mapnr))
+
+#define virt_to_page(kaddr) (pfn_to_page(__pa(kaddr) >> PAGE_SHIFT))
+#define virt_addr_valid(kaddr) ((unsigned long)(kaddr) >= PAGE_OFFSET && (unsigned long)(kaddr) < (unsigned long)high_memory)
+
+#define PHYS_TO_NID(addr) (0)
+
+#else /* CONFIG_DISCONTIGMEM */
+
+/*
+ * This is more complex. We have a set of mem_map arrays spread
+ * around in memory.
+ */
+#include <linux/numa.h>
+
+#define pfn_valid(pfn) (PFN_TO_NID(pfn) < MAX_NUMNODES)
+
+#define virt_to_page(kaddr) \
+ (ADDR_TO_MAPBASE(kaddr) + LOCAL_MAP_NR(kaddr))
+#define virt_addr_valid(kaddr) (KVADDR_TO_NID(kaddr) < MAX_NUMNODES)
+
+/*
+ * Common discontigmem stuff.
+ * PHYS_TO_NID is used by the NDS32 kernel/setup.c
+ */
+#define PHYS_TO_NID(addr) PFN_TO_NID((addr) >> PAGE_SHIFT)
+
+#endif /* !CONFIG_DISCONTIGMEM */
+
+/*
+ * For BIO. "will die". Kill me when bio_to_phys() and bvec_to_phys() die.
+ */
+#define page_to_phys(page) (page_to_pfn(page) << PAGE_SHIFT)
+
+/*
+ * Optional device DMA address remapping. Do _not_ use directly!
+ * We should really eliminate virt_to_bus() here - it's deprecated.
+ */
+#ifndef __arch_page_to_dma
+#define page_to_dma(dev, page) ((dma_addr_t)__virt_to_bus((unsigned long)page_address(page)))
+#define dma_to_virt(dev, addr) ((void *)__bus_to_virt(addr))
+#define virt_to_dma(dev, addr) ((dma_addr_t)__virt_to_bus((unsigned long)(addr)))
+#else
+#define page_to_dma(dev, page) (__arch_page_to_dma(dev, page))
+#define dma_to_virt(dev, addr) (__arch_dma_to_virt(dev, addr))
+#define virt_to_dma(dev, addr) (__arch_virt_to_dma(dev, addr))
+#endif
+
+#endif
+
+#include <asm-generic/memory_model.h>
+
+#endif
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/misc_spec.h linux-3.4.113/arch/nds32/include/asm/misc_spec.h
--- linux-3.4.113.orig/arch/nds32/include/asm/misc_spec.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/misc_spec.h 2016-12-01 20:59:24.340612287 +0100
@@ -0,0 +1,75 @@
+/*
+ * linux/arch/nds32/include/asm/misc_spec.h
+ *
+ * Faraday A320D platform dependent definitions
+ *
+ * Copyright (C) 2005 Faraday Corp. (http://www.faraday-tech.com)
+ * Copyright (C) 2008 Andes Technology Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * ChangeLog
+ *
+ * Luke Lee 09/14/2005 Created
+ * Luke Lee 10/06/2005 Modified for automatic system clock rate
+ */
+
+#ifndef __A320_PLATFORM_MANUAL_DEFINITION__
+#define __A320_PLATFORM_MANUAL_DEFINITION__
+
+#define BOOT_PARAMETER_PA_BASE (PHYS_OFFSET + 0x400)
+
+#ifdef CONFIG_AUTO_SYS_CLK
+
+#ifndef __ASSEMBLY__
+extern int ag101_get_ahb_clk(void);
+extern int ag102_get_ahb_clk(void);
+
+#if defined(CONFIG_PLAT_AG101)
+#define AHB_CLK_IN ag101_get_ahb_clk()
+#elif defined(CONFIG_PLAT_AG102)
+#define AHB_CLK_IN ag102_get_ahb_clk()
+
+#endif
+
+#endif
+#define TIMER_CLK_IN (CONFIG_SYS_CLK/2)
+
+#else
+
+/* Timer clock input is APB CLOCK */
+#define TIMER_CLK_IN (CONFIG_SYS_CLK/2)
+#define AHB_CLK_IN (CONFIG_SYS_CLK)
+
+#endif
+
+#ifndef __ASSEMBLY__
+#include <linux/init.h>
+
+#ifdef CONFIG_PLATFORM_INTC
+extern void __init intc_ftintc010_init_irq(void);
+#define platform_init_irq intc_ftintc010_init_irq
+#endif
+
+#ifdef CONFIG_PLATFORM_NOINTC
+extern void __init nointc_init_irq(void);
+#define platform_init_irq nointc_init_irq
+#endif
+
+#endif
+
+#define daughter_platform_init_irq(x) /* NOP */
+
+#endif /*__A320_PLATFORM_MANUAL_DEFINITION__ */
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/mman.h linux-3.4.113/arch/nds32/include/asm/mman.h
--- linux-3.4.113.orig/arch/nds32/include/asm/mman.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/mman.h 2016-12-01 20:59:24.340612287 +0100
@@ -0,0 +1,22 @@
+/*
+ * linux/arch/nds32/include/asm/mman.h
+ * Copyright (C) 2008 Andes Technology Corporation
+ */
+
+#ifndef __NDS32_MMAN_H__
+#define __NDS32_MMAN_H__
+
+#include <asm-generic/mman.h>
+
+#define MAP_GROWSDOWN 0x0100 /* stack-like segment */
+#define MAP_DENYWRITE 0x0800 /* ETXTBSY */
+#define MAP_EXECUTABLE 0x1000 /* mark it as an executable */
+#define MAP_LOCKED 0x2000 /* pages are locked */
+#define MAP_NORESERVE 0x4000 /* don't check for reservations */
+#define MAP_POPULATE 0x8000 /* populate (prefault) page tables */
+#define MAP_NONBLOCK 0x10000 /* do not block on IO */
+
+#define MCL_CURRENT 1 /* lock all current mappings */
+#define MCL_FUTURE 2 /* lock all future mappings */
+
+#endif /* __NDS32_MMAN_H__ */
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/mmu_context.h linux-3.4.113/arch/nds32/include/asm/mmu_context.h
--- linux-3.4.113.orig/arch/nds32/include/asm/mmu_context.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/mmu_context.h 2016-12-01 20:59:24.340612287 +0100
@@ -0,0 +1,84 @@
+/*
+ * linux/arch/nds32/include/asm/mmu_context.h
+ *
+ * Copyright (C) 1996 Russell King.
+ * Copyright (C) 2008 Andes Technology Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Changelog:
+ * 27-06-1996 RMK Created
+ */
+#ifndef __ASM_NDS32_MMU_CONTEXT_H
+#define __ASM_NDS32_MMU_CONTEXT_H
+
+#include <linux/spinlock.h>
+#include <asm/tlbflush.h>
+#include <asm-generic/mm_hooks.h>
+
+static inline int
+init_new_context(struct task_struct *tsk, struct mm_struct *mm)
+{
+ mm->context.id = 0;
+ return 0;
+}
+
+#define destroy_context(mm) do { } while(0)
+
+#ifndef CONFIG_CPU_NO_CONTEXT_ID
+#define CID_BITS 9
+extern spinlock_t cid_lock;
+extern unsigned int cpu_last_cid;
+
+static inline void
+__new_context(struct mm_struct *mm)
+{
+ unsigned int cid;
+ unsigned long flags;
+
+ spin_lock_irqsave(&cid_lock, flags);
+ cid = cpu_last_cid;
+ cpu_last_cid += 1 << TLB_MISC_offCID;
+ if (cpu_last_cid == 0)
+ cpu_last_cid = 1 << TLB_MISC_offCID << CID_BITS;
+ spin_unlock_irqrestore(&cid_lock, flags);
+
+ if ((cid & TLB_MISC_mskCID ) == 0)
+ flush_tlb_all();
+
+ mm->context.id = cid;
+}
+
+static inline void
+check_context(struct mm_struct *mm)
+{
+ if (unlikely((mm->context.id ^ cpu_last_cid) >> TLB_MISC_offCID >> CID_BITS))
+ __new_context(mm);
+}
+#else
+#define check_context(m)
+#endif
+
+static inline void
+enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
+{
+}
+
+static inline void
+switch_mm(struct mm_struct *prev, struct mm_struct *next,
+ struct task_struct *tsk)
+{
+ unsigned int cpu = smp_processor_id();
+
+ if (!cpumask_test_and_set_cpu(cpu, mm_cpumask(next)) || prev != next) {
+ check_context(next);
+ cpu_switch_mm(next);
+ }
+}
+
+#define deactivate_mm(tsk,mm) do { } while (0)
+#define activate_mm(prev,next) switch_mm(prev, next, NULL)
+
+#endif
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/mmu.h linux-3.4.113/arch/nds32/include/asm/mmu.h
--- linux-3.4.113.orig/arch/nds32/include/asm/mmu.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/mmu.h 2016-12-01 20:59:24.340612287 +0100
@@ -0,0 +1,42 @@
+/*
+ * linux/arch/nds32/include/asm/mmu.h
+ * Copyright (C) 2008 Andes Technology Corporation
+ */
+
+#ifndef __NDS32_MMU_H
+#define __NDS32_MMU_H
+
+typedef struct {
+ unsigned int id;
+} mm_context_t;
+
+#define ASID(mm) ((mm)->context.id & (TLB_MISC_mskCID >> TLB_MISC_offCID))
+inline static unsigned long ACC_PSZ(unsigned long page_size)
+{
+ switch(page_size) {
+ case(1<<12):
+ return 0;
+ case(1<<13):
+ return 1;
+ case(1<<14):
+ return 2;
+ case(1<<16):
+ return 3;
+ case(1<<18):
+ return 4;
+ case(1<<20):
+ return 5;
+ case(1<<22):
+ return 6;
+ case(1<<24):
+ return 7;
+ case(1<<26):
+ return 8;
+ case(1<<28):
+ return 9;
+ default:
+ printk("Huge Page Size is not supported \n");
+ return 0xffffffff;
+ }
+}
+#endif
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/module.h linux-3.4.113/arch/nds32/include/asm/module.h
--- linux-3.4.113.orig/arch/nds32/include/asm/module.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/module.h 2016-12-01 20:59:24.340612287 +0100
@@ -0,0 +1,23 @@
+/*
+ * linux/arch/nds32/include/asm/module.h
+ * Copyright (C) 2008 Andes Technology Corporation
+ */
+
+#ifndef _ASM_NDS32_MODULE_H
+#define _ASM_NDS32_MODULE_H
+
+struct mod_arch_specific
+{
+ int foo;
+};
+
+#define Elf_Shdr Elf32_Shdr
+#define Elf_Sym Elf32_Sym
+#define Elf_Ehdr Elf32_Ehdr
+
+/*
+ * Include the ARM architecture version.
+ */
+#define MODULE_ARCH_VERMAGIC "NDS32vN10" __stringify(__LINUX_NDS32_ARCH__) " "
+
+#endif /* _ASM_NDS32_MODULE_H */
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/msgbuf.h linux-3.4.113/arch/nds32/include/asm/msgbuf.h
--- linux-3.4.113.orig/arch/nds32/include/asm/msgbuf.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/msgbuf.h 2016-12-01 20:59:24.340612287 +0100
@@ -0,0 +1,36 @@
+/*
+ * linux/arch/nds32/include/asm/msgbuf.h
+ * Copyright (C) 2008 Andes Technology Corporation
+ */
+
+#ifndef _ASMNDS32_MSGBUF_H
+#define _ASMNDS32_MSGBUF_H
+
+/*
+ * The msqid64_ds structure for arm architecture.
+ * Note extra padding because this structure is passed back and forth
+ * between kernel and user space.
+ *
+ * Pad space is left for:
+ * - 64-bit time_t to solve y2038 problem
+ * - 2 miscellaneous 32-bit values
+ */
+
+struct msqid64_ds {
+ struct ipc64_perm msg_perm;
+ __kernel_time_t msg_stime; /* last msgsnd time */
+ unsigned long __unused1;
+ __kernel_time_t msg_rtime; /* last msgrcv time */
+ unsigned long __unused2;
+ __kernel_time_t msg_ctime; /* last change time */
+ unsigned long __unused3;
+ unsigned long msg_cbytes; /* current number of bytes on queue */
+ unsigned long msg_qnum; /* number of messages in queue */
+ unsigned long msg_qbytes; /* max number of bytes on queue */
+ __kernel_pid_t msg_lspid; /* pid of last msgsnd */
+ __kernel_pid_t msg_lrpid; /* last receive pid */
+ unsigned long __unused4;
+ unsigned long __unused5;
+};
+
+#endif /* _ASMNDS32_MSGBUF_H */
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/mutex.h linux-3.4.113/arch/nds32/include/asm/mutex.h
--- linux-3.4.113.orig/arch/nds32/include/asm/mutex.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/mutex.h 2016-12-01 20:59:24.340612287 +0100
@@ -0,0 +1,11 @@
+/*
+ * linux/arch/nds32/include/asm/mutex.h
+ * Copyright (C) 2008 Andes Technology Corporation
+ */
+
+#ifndef __NDS32_MUTEX_H__
+#define __NDS32_MUTEX_H__
+
+#include <asm-generic/mutex-dec.h>
+
+#endif
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/namei.h linux-3.4.113/arch/nds32/include/asm/namei.h
--- linux-3.4.113.orig/arch/nds32/include/asm/namei.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/namei.h 2016-12-01 20:59:24.340612287 +0100
@@ -0,0 +1,11 @@
+/*
+ * linux/arch/nds32/include/asm/namei.h
+ * Copyright (C) 2008 Andes Technology Corporation
+ */
+
+#ifndef __NDS32_NAMEI_H__
+#define __NDS32_NAMEI_H__
+
+#define __emul_prefix() NULL
+
+#endif
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/nds32.h linux-3.4.113/arch/nds32/include/asm/nds32.h
--- linux-3.4.113.orig/arch/nds32/include/asm/nds32.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/nds32.h 2016-12-01 20:59:24.340612287 +0100
@@ -0,0 +1,90 @@
+/*
+ * linux/arch/nds32/include/asm/nds32.h -- Andes NDS32 processor register interface
+ *
+ * This file is subject to the terms and conditions of the GNU General Public
+ * License. See the file "COPYING" in the main directory of this archive
+ * for more details.
+ *
+ * Copyright (C) 2006 Andes Technology Corporation
+ *
+ */
+#ifndef _ASM_NDS32_NDS32_H_
+#define _ASM_NDS32_NDS32_H_
+
+#include <asm/bitfield.h>
+#include <asm/reg_access.h>
+
+#define MSYNC( subtype) __asm__ ("\n\tmsync "#subtype);
+#define STANDBY( cond) __asm__ ("\n\tstandby "#cond);
+
+#ifndef __ASSEMBLY__
+
+static inline void ISB( void) { __asm__ ("\n\tisb"); }
+static inline void DSB( void) { __asm__ ("\n\tdsb"); }
+
+static inline void GIE_ENABLE( void)
+{
+ __asm__ ("gie_enable\n\t");
+}
+
+static inline void GIE_DISABLE( void)
+{
+ __asm__ ("gie_disable\n\t");
+}
+
+enum cache_t{ ICACHE, DCACHE};
+
+static inline unsigned long CACHE_SET( enum cache_t cache){
+
+ if( cache == ICACHE)
+ return 64 << ( ( GET_ICM_CFG() & ICM_CFG_mskISET) >> ICM_CFG_offISET);
+ else
+ return 64 << ( ( GET_DCM_CFG() & DCM_CFG_mskDSET) >> DCM_CFG_offDSET);
+}
+
+static inline unsigned long CACHE_WAY( enum cache_t cache){
+
+ if( cache == ICACHE)
+ return 1 + ( ( GET_ICM_CFG() & ICM_CFG_mskIWAY) >> ICM_CFG_offIWAY);
+ else
+ return 1 + ( ( GET_DCM_CFG() & DCM_CFG_mskDWAY) >> DCM_CFG_offDWAY);
+}
+
+static inline unsigned long CACHE_LINE_SIZE( enum cache_t cache){
+
+ if( cache == ICACHE)
+ return 8 << ( ( ( GET_ICM_CFG() & ICM_CFG_mskISZ) >> ICM_CFG_offISZ) - 1);
+ else
+ return 8 << ( ( ( GET_DCM_CFG() & DCM_CFG_mskDSZ) >> DCM_CFG_offDSZ) - 1);
+}
+
+static inline void GIE_SAVE( unsigned long *var){
+
+ *var = GET_PSW();
+ GIE_DISABLE();
+}
+
+static inline void GIE_RESTORE( unsigned long var){
+
+ if( var & PSW_mskGIE){
+ GIE_ENABLE();
+ }
+}
+
+#endif /* __ASSEMBLY__ */
+
+#define IVB_BASE PHYS_OFFSET /* in user space for intr/exc/trap/break table base, 64KB aligned
+ * We defined at the start of the physical memory */
+
+/* The following dispatching entry */
+#define ENTRY_TLB_MISC (IVB_BASE + nrTLB_MISC*vENTRY_SZ) /* TLB misc eh# */
+/* dispatched sub-entry exception handler numbering */
+#define RD_PROT 0 /* read protrection */
+#define WRT_PROT 1 /* write protection */
+#define NOEXEC 2 /* non executable */
+#define PAGE_MODIFY 3 /* page modified */
+#define ACC_BIT 4 /* access bit */
+#define RESVED_PTE 5 /* reserved PTE attribute */
+/* reserved 6 ~ 16 */
+
+#endif /* _ASM_NDS32_NDS32_H_ */
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/numnodes.h linux-3.4.113/arch/nds32/include/asm/numnodes.h
--- linux-3.4.113.orig/arch/nds32/include/asm/numnodes.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/numnodes.h 2016-12-01 20:59:24.340612287 +0100
@@ -0,0 +1,25 @@
+/*
+ * linux/arch/nds32/include/asm/numnodes.h
+ *
+ * Copyright (C) 2002 Russell King
+ * Copyright (C) 2008 Andes Technology Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+/* This declaration for the size of the NUMA (CONFIG_DISCONTIGMEM)
+ * memory node table is the default.
+ *
+ * A good place to override this value is include/asm/arch/memory.h.
+ */
+
+#ifndef __ASM_NDS32_NUMNODES_H
+#define __ASM_NDS32_NUMNODES_H
+
+#ifndef NODES_SHIFT
+# define NODES_SHIFT 2 /* Normally, Max 4 Nodes */
+#endif
+
+#endif
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/page.h linux-3.4.113/arch/nds32/include/asm/page.h
--- linux-3.4.113.orig/arch/nds32/include/asm/page.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/page.h 2016-12-01 20:59:24.340612287 +0100
@@ -0,0 +1,153 @@
+/*
+ * linux/arch/nds32/include/asm/page.h
+ *
+ * Copyright (C) 1995-2003 Russell King
+ * Copyright (C) 2008 Andes Technology Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+#ifndef _ASMNDS32_PAGE_H
+#define _ASMNDS32_PAGE_H
+
+
+#ifdef CONFIG_ANDES_PAGE_SIZE_4KB
+#define PAGE_SHIFT 12
+#endif
+#ifdef CONFIG_ANDES_PAGE_SIZE_8KB
+#define PAGE_SHIFT 13
+#endif
+#include <linux/const.h>
+#define PAGE_SIZE (_AC(1,UL) << PAGE_SHIFT)
+#define PAGE_MASK (~(PAGE_SIZE-1))
+#define PTE_MASK PAGE_MASK
+
+/* PAGE_SHIFT determines the page size */
+#define EXEC_PAGESIZE PAGE_SIZE
+
+#ifdef CONFIG_ANDES_HUGETLB_PAGE_SIZE_16KB
+#define LARGE_PAGE_SHIFT 14
+#define HPAGE_SHIFT 14
+#endif
+
+#ifdef CONFIG_ANDES_HUGETLB_PAGE_SIZE_64KB
+#define LARGE_PAGE_SHIFT 16
+#define HPAGE_SHIFT 16
+#endif
+
+#ifdef CONFIG_ANDES_HUGETLB_PAGE_SIZE_256KB
+#define LARGE_PAGE_SHIFT 18
+#define HPAGE_SHIFT 18
+#endif
+#ifdef CONFIG_ANDES_HUGETLB_PAGE_SIZE_1MB
+#define LARGE_PAGE_SHIFT 20
+#define HPAGE_SHIFT 20
+#endif
+
+#ifdef CONFIG_ANDES_HUGETLB_PAGE_SIZE_4MB
+#define LARGE_PAGE_SHIFT 22
+#define HPAGE_SHIFT 22
+#endif
+
+#ifdef CONFIG_ANDES_HUGETLB_PAGE_SIZE_16MB
+#define LARGE_PAGE_SHIFT 24
+#define HPAGE_SHIFT 24
+#endif
+
+#ifdef CONFIG_ANDES_HUGETLB_PAGE_SIZE_64MB
+#define LARGE_PAGE_SHIFT 26
+#define HPAGE_SHIFT 26
+#endif
+
+#ifdef CONFIG_ANDES_HUGETLB_PAGE_SIZE_256MB
+#define LARGE_PAGE_SHIFT 28
+#define HPAGE_SHIFT 28
+#endif
+
+#ifdef CONFIG_HUGETLB_PAGE
+// taken for i386 style
+#define LARGE_PAGE_SIZE (1UL << LARGE_PAGE_SHIFT)
+#define LARGE_PAGE_MASK (~(LARGE_PAGE_SIZE-1))
+// taken for SH style
+#define HPAGE_SIZE (1UL << HPAGE_SHIFT)
+#define HPAGE_MASK (~(HPAGE_SIZE-1))
+#define HUGETLB_PAGE_ORDER (HPAGE_SHIFT-PAGE_SHIFT)
+#endif
+
+
+#ifdef __KERNEL__
+
+#ifndef __ASSEMBLY__
+
+struct page;
+struct vm_area_struct;
+#ifndef CONFIG_CPU_CACHE_NONALIASING
+extern void copy_user_highpage(struct page *to, struct page *from,
+ unsigned long vaddr, struct vm_area_struct *vma);
+extern void clear_user_highpage(struct page *page, unsigned long vaddr);
+
+#define __HAVE_ARCH_COPY_USER_HIGHPAGE
+#define clear_user_highpage clear_user_highpage
+#else
+#define clear_user_page(page, vaddr, pg) clear_page(page)
+#define copy_user_page(to, from, vaddr, pg) copy_page(to, from)
+#endif
+
+void clear_page(void *page);
+void copy_page(void *to, void *from);
+
+#undef STRICT_MM_TYPECHECKS
+
+#ifdef STRICT_MM_TYPECHECKS
+/*
+ * These are used to make use of C type-checking..
+ */
+typedef struct { unsigned long pte; } pte_t;
+typedef struct { unsigned long pmd; } pmd_t;
+typedef struct { unsigned long pgd; } pgd_t;
+typedef struct { unsigned long pgprot; } pgprot_t;
+
+#define pte_val(x) ((x).pte)
+#define pmd_val(x) ((x).pmd)
+#define pgd_val(x) ((x).pgd)
+#define pgprot_val(x) ((x).pgprot)
+
+#define __pte(x) ((pte_t) { (x) } )
+#define __pmd(x) ((pmd_t) { (x) } )
+#define __pgd(x) ((pgd_t) { (x) } )
+#define __pgprot(x) ((pgprot_t) { (x) } )
+
+#else
+/*
+ * .. while these make it easier on the compiler
+ */
+typedef unsigned long pte_t;
+typedef unsigned long pmd_t;
+typedef unsigned long pgd_t;
+typedef unsigned long pgprot_t;
+
+#define pte_val(x) (x)
+#define pmd_val(x) (x)
+#define pgd_val(x) (x)
+#define pgprot_val(x) (x)
+
+#define __pte(x) (x)
+#define __pmd(x) (x)
+#define __pgd(x) (x)
+#define __pgprot(x) (x)
+
+#endif /* STRICT_MM_TYPECHECKS */
+typedef struct page *pgtable_t;
+
+#include <asm/memory.h>
+#include <asm-generic/getorder.h>
+
+#endif /* !__ASSEMBLY__ */
+
+#define VM_DATA_DEFAULT_FLAGS (VM_READ | VM_WRITE | VM_EXEC | \
+ VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
+
+#endif /* __KERNEL__ */
+
+#endif
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/param.h linux-3.4.113/arch/nds32/include/asm/param.h
--- linux-3.4.113.orig/arch/nds32/include/asm/param.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/param.h 2016-12-01 20:59:24.340612287 +0100
@@ -0,0 +1,36 @@
+/*
+ * linux/arch/nds32/include/asm/param.h
+ *
+ * Copyright (C) 1995-1999 Russell King
+ * Copyright (C) 2008 Andes Technology Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+#ifndef __ASM_PARAM_H
+#define __ASM_PARAM_H
+
+#ifdef __KERNEL__
+
+# ifndef HZ
+# define HZ CONFIG_HZ /* Internal kernel timer frequency */
+# endif
+
+# define USER_HZ HZ /* User interfaces are in "ticks" */
+# define CLOCKS_PER_SEC (USER_HZ) /* like times() */
+#else
+# define HZ 100
+#endif
+
+//#define EXEC_PAGESIZE 4096
+
+#ifndef NOGROUP
+#define NOGROUP (-1)
+#endif
+
+/* max length of hostname */
+#define MAXHOSTNAMELEN 64
+
+#endif
+
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/parport.h linux-3.4.113/arch/nds32/include/asm/parport.h
--- linux-3.4.113.orig/arch/nds32/include/asm/parport.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/parport.h 2016-12-01 20:59:24.340612287 +0100
@@ -0,0 +1,19 @@
+/*
+ * linux/arch/nds32/include/asm/parport.h: NDS32-specific parport initialisation
+ *
+ * Copyright (C) 1999, 2000 Tim Waugh <tim@cyberelk.demon.co.uk>
+ * Copyright (C) 2008 Andes Technology Corporation
+ *
+ * This file should only be included by drivers/parport/parport_pc.c.
+ */
+
+#ifndef __ASMNDS32_PARPORT_H
+#define __ASMNDS32_PARPORT_H
+
+static int __devinit parport_pc_find_isa_ports (int autoirq, int autodma);
+static int __devinit parport_pc_find_nonpci_ports (int autoirq, int autodma)
+{
+ return parport_pc_find_isa_ports (autoirq, autodma);
+}
+
+#endif /* !(_ASMNDS32_PARPORT_H) */
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/pci.h linux-3.4.113/arch/nds32/include/asm/pci.h
--- linux-3.4.113.orig/arch/nds32/include/asm/pci.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/pci.h 2016-12-01 20:59:24.340612287 +0100
@@ -0,0 +1,77 @@
+/*
+ * linux/arch/nds32/include/asm/pci.h
+ * Copyright (C) 2008 Andes Technology Corporation
+ */
+
+#ifndef ASMNDS32_PCI_H
+#define ASMNDS32_PCI_H
+
+#ifdef __KERNEL__
+#include <asm-generic/pci-dma-compat.h>
+
+#include <asm/hardware.h> /* for PCIBIOS_MIN_* */
+
+#define pcibios_scan_all_fns(a, b) 0
+
+static inline void pcibios_set_master(struct pci_dev *dev)
+{
+ /* No special bus mastering setup handling */
+}
+
+static inline void pcibios_penalize_isa_irq(int irq)
+{
+ /* We don't do dynamic PCI IRQ allocation */
+}
+
+/*
+ * The PCI address space does equal the physical memory address space.
+ * The networking and block device layers use this boolean for bounce
+ * buffer decisions.
+ */
+#define PCI_DMA_BUS_IS_PHYS (0)
+
+/*
+ * Whether pci_unmap_{single,page} is a nop depends upon the
+ * configuration.
+ */
+#define DECLARE_PCI_UNMAP_ADDR(ADDR_NAME) dma_addr_t ADDR_NAME;
+#define DECLARE_PCI_UNMAP_LEN(LEN_NAME) __u32 LEN_NAME;
+#define pci_unmap_addr(PTR, ADDR_NAME) ((PTR)->ADDR_NAME)
+#define pci_unmap_addr_set(PTR, ADDR_NAME, VAL) (((PTR)->ADDR_NAME) = (VAL))
+#define pci_unmap_len(PTR, LEN_NAME) ((PTR)->LEN_NAME)
+#define pci_unmap_len_set(PTR, LEN_NAME, VAL) (((PTR)->LEN_NAME) = (VAL))
+
+#define HAVE_PCI_MMAP
+extern int pci_mmap_page_range(struct pci_dev *dev, struct vm_area_struct *vma,
+ enum pci_mmap_state mmap_state, int write_combine);
+
+extern void
+pcibios_resource_to_bus(struct pci_dev *dev, struct pci_bus_region *region,
+ struct resource *res);
+
+extern void
+pcibios_bus_to_resource(struct pci_dev *dev, struct resource *res,
+ struct pci_bus_region *region);
+
+static inline struct resource *
+pcibios_select_root(struct pci_dev *pdev, struct resource *res)
+{
+ struct resource *root = NULL;
+
+ if (res->flags & IORESOURCE_IO)
+ root = &ioport_resource;
+ if (res->flags & IORESOURCE_MEM)
+ root = &iomem_resource;
+
+ return root;
+}
+
+#endif /* __KERNEL__ */
+
+/* Chances are this interrupt is wired PC-style ... */
+static inline int pci_get_legacy_ide_irq(struct pci_dev *dev, int channel)
+{
+ return channel ? 15 : 14;
+}
+
+#endif
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/percpu.h linux-3.4.113/arch/nds32/include/asm/percpu.h
--- linux-3.4.113.orig/arch/nds32/include/asm/percpu.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/percpu.h 2016-12-01 20:59:24.340612287 +0100
@@ -0,0 +1,11 @@
+/*
+ * linux/arch/nds32/include/asm/percpu.h
+ * Copyright (C) 2008 Andes Technology Corporation
+ */
+
+#ifndef __NDS32_PERCPU
+#define __NDS32_PERCPU
+
+#include <asm-generic/percpu.h>
+
+#endif
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/pfm.h linux-3.4.113/arch/nds32/include/asm/pfm.h
--- linux-3.4.113.orig/arch/nds32/include/asm/pfm.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/pfm.h 2016-12-01 20:59:24.340612287 +0100
@@ -0,0 +1,16 @@
+#ifndef __PFM_H_
+#define __PFM_H_
+
+struct pcounter {
+ unsigned long long pfm0; /* value of $PFMC0 */
+ unsigned long long pfm1; /* value of $PFMC1 */
+ unsigned long long pfm2; /* value of $PFMC2 */
+};
+
+#ifdef __KERNEL__
+void sys_pfmctl(int event0, int event1, int event2, int start);
+int sys_getpfm(struct pcounter __user *p);
+int sys_setpfm(int pfm0, int pfm1, int pfm2, struct pcounter __user *p);
+#endif
+
+#endif
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/pgalloc.h linux-3.4.113/arch/nds32/include/asm/pgalloc.h
--- linux-3.4.113.orig/arch/nds32/include/asm/pgalloc.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/pgalloc.h 2016-12-01 20:59:24.344612443 +0100
@@ -0,0 +1,104 @@
+/*
+ * linux/arch/nds32/include/asm/pgalloc.h
+ *
+ * Copyright (C) 2000-2001 Russell King
+ * Copyright (C) 2008 Andes Technology Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+#ifndef _ASMNDS32_PGALLOC_H
+#define _ASMNDS32_PGALLOC_H
+
+#include <asm/processor.h>
+#include <asm/cacheflush.h>
+#include <asm/tlbflush.h>
+
+/*
+ * Since we have only two-level page tables, these are trivial
+ */
+#define pmd_alloc_one(mm, addr) ({ BUG(); ((pmd_t *)2); })
+#define pmd_free(mm, pmd) do { } while (0)
+#define pgd_populate(mm, pmd, pte) BUG()
+#define pmd_pgtable(pmd) pmd_page(pmd)
+
+extern pgd_t *get_pgd_slow(struct mm_struct *mm);
+extern void free_pgd_slow(struct mm_struct *mm, pgd_t *pgd);
+
+#define pgd_alloc(mm) get_pgd_slow(mm)
+#define pgd_free(mm, pgd) free_pgd_slow(mm, pgd)
+
+#define check_pgt_cache() do { } while (0)
+
+static inline pte_t *
+pte_alloc_one_kernel(struct mm_struct *mm, unsigned long addr)
+{
+ pte_t *pte;
+
+ pte = (pte_t *)__get_free_page(GFP_KERNEL|__GFP_REPEAT|__GFP_ZERO);
+
+ return pte;
+}
+
+static inline pgtable_t
+pte_alloc_one(struct mm_struct *mm, unsigned long addr)
+{
+ pgtable_t pte;
+
+ pte = alloc_pages(GFP_KERNEL|__GFP_REPEAT|__GFP_ZERO, 0);
+ if (pte)
+ cpu_dcache_wb_page((unsigned long)page_address(pte));
+
+ return pte;
+}
+
+/*
+ * Free one PTE table.
+ */
+static inline void pte_free_kernel(struct mm_struct *mm, pte_t *pte)
+{
+ if (pte) {
+ free_page((unsigned long)pte);
+ }
+}
+
+static inline void pte_free(struct mm_struct *mm, pgtable_t pte)
+{
+ __free_page(pte);
+}
+
+/*
+ * Populate the pmdp entry with a pointer to the pte. This pmd is part
+ * of the mm address space.
+ *
+ * Ensure that we always set both PMD entries.
+ */
+static inline void
+pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmdp, pte_t *ptep)
+{
+ unsigned long pte_ptr = (unsigned long)ptep;
+ unsigned long pmdval;
+
+ BUG_ON(mm != &init_mm);
+
+ /*
+ * The pmd must be loaded with the physical
+ * address of the PTE table
+ */
+ pmdval = __pa(pte_ptr) | _PAGE_KERNEL_TABLE;
+ set_pmd(pmdp, __pmd(pmdval));
+}
+
+static inline void
+pmd_populate(struct mm_struct *mm, pmd_t *pmdp, pgtable_t ptep)
+{
+ unsigned long pmdval;
+
+ BUG_ON(mm == &init_mm);
+
+ pmdval = page_to_pfn(ptep) << PAGE_SHIFT | _PAGE_USER_TABLE;
+ set_pmd(pmdp, __pmd(pmdval));
+}
+
+#endif
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/pgtable.h linux-3.4.113/arch/nds32/include/asm/pgtable.h
--- linux-3.4.113.orig/arch/nds32/include/asm/pgtable.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/pgtable.h 2016-12-01 20:59:24.344612443 +0100
@@ -0,0 +1,429 @@
+/*
+ * linux/arch/nds32/include/asm/pgtable.h
+ *
+ * Copyright (C) 1995-2002 Russell King
+ * Copyright (C) 2008 Andes Technology Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+#ifndef _ASMNDS32_PGTABLE_H
+#define _ASMNDS32_PGTABLE_H
+
+#include <asm-generic/4level-fixup.h>
+#include <asm-generic/sizes.h>
+
+#include <asm/memory.h>
+#include <asm/vmalloc.h>
+#include <asm/nds32.h>
+#ifndef __ASSEMBLY__
+#include <asm/fixmap.h>
+#endif
+
+#ifdef CONFIG_CACHE_L2
+#include <asm/l2_cache.h>
+#endif
+
+#ifdef CONFIG_ANDES_PAGE_SIZE_4KB
+#define PGDIR_SHIFT 22
+#define PTRS_PER_PGD 1024
+#define PMD_SHIFT 22
+#define PTRS_PER_PMD 1
+#define PTRS_PER_PTE 1024
+#endif
+
+#ifdef CONFIG_ANDES_PAGE_SIZE_8KB
+#define PGDIR_SHIFT 24
+#define PTRS_PER_PGD 256
+#define PMD_SHIFT 24
+#define PTRS_PER_PMD 1
+#define PTRS_PER_PTE 2048
+#endif
+
+#ifndef __ASSEMBLY__
+extern void __pte_error(const char *file, int line, unsigned long val);
+extern void __pmd_error(const char *file, int line, unsigned long val);
+extern void __pgd_error(const char *file, int line, unsigned long val);
+
+#define pte_ERROR(pte) __pte_error(__FILE__, __LINE__, pte_val(pte))
+#define pmd_ERROR(pmd) __pmd_error(__FILE__, __LINE__, pmd_val(pmd))
+#define pgd_ERROR(pgd) __pgd_error(__FILE__, __LINE__, pgd_val(pgd))
+#endif /* !__ASSEMBLY__ */
+
+#define PMD_SIZE (1UL << PMD_SHIFT)
+#define PMD_MASK (~(PMD_SIZE-1))
+#define PGDIR_SIZE (1UL << PGDIR_SHIFT)
+#define PGDIR_MASK (~(PGDIR_SIZE-1))
+
+/*
+ * This is the lowest virtual address we can permit any user space
+ * mapping to be mapped at. This is particularly important for
+ * non-high vector CPUs.
+ */
+#define FIRST_USER_ADDRESS 0x8000
+
+#define VMALLOC_OFFSET (8 * 1024 * 1024)
+#define VMALLOC_START (((unsigned long)high_memory + VMALLOC_OFFSET) & ~(VMALLOC_OFFSET-1))
+#define VMALLOC_VMADDR(x) ((unsigned long)(x))
+
+
+#ifdef CONFIG_HIGHMEM
+#define CONSISTENT_BASE ((PKMAP_BASE) - (SZ_2M))
+#define CONSISTENT_END (PKMAP_BASE)
+#else
+#define CONSISTENT_BASE (FIXADDR_START - SZ_2M)
+#define CONSISTENT_END (FIXADDR_START)
+#endif
+#define CONSISTENT_OFFSET(x) (((unsigned long)(x) - CONSISTENT_BASE) >> PAGE_SHIFT)
+
+#ifdef CONFIG_HIGHMEM
+#ifndef __ASSEMBLY__
+#include <asm/highmem.h>
+#endif
+#endif
+
+//# define VMALLOC_END (CONSISTENT_START - PAGE_SIZE)
+# define VMALLOC_END (0xf9000000)
+
+#define VMALLOC_RESERVE (128 << 20)
+#define MAXMEM (VMALLOC_END - PAGE_OFFSET - VMALLOC_RESERVE)
+#define MAXMEM_PFN PFN_DOWN(MAXMEM)
+
+#define FIRST_USER_PGD_NR 0
+#define USER_PTRS_PER_PGD ((TASK_SIZE/PGDIR_SIZE) + FIRST_USER_PGD_NR)
+
+/* L2 PTE */
+#define _PAGE_V (1UL << 0)
+
+#define _PAGE_M_XKRW (0UL << 1)
+#define _PAGE_M_UR_KR (1UL << 1)
+#define _PAGE_M_UR_KRW (2UL << 1)
+#define _PAGE_M_URW_KRW (3UL << 1)
+#define _PAGE_M_KR (5UL << 1)
+#define _PAGE_M_KRW (7UL << 1)
+
+#define _PAGE_D (1UL << 4)
+#define _PAGE_E (1UL << 5)
+#define _PAGE_A (1UL << 6)
+#define _PAGE_G (1UL << 7)
+
+#define _PAGE_C_DEV (0UL << 8)
+#define _PAGE_C_DEV_WB (1UL << 8)
+#define _PAGE_C_MEM (2UL << 8)
+#define _PAGE_C_MEM_SHRD_WB (4UL << 8)
+#define _PAGE_C_MEM_SHRD_WT (5UL << 8)
+#define _PAGE_C_MEM_WB (6UL << 8)
+#define _PAGE_C_MEM_WT (7UL << 8)
+
+#define _PAGE_L (1UL << 11)
+
+#ifndef CONFIG_NO_KERNEL_LARGE_PAGE
+#define _HAVE_PAGE_L (_PAGE_L)
+#else
+#define _HAVE_PAGE_L 0
+#endif
+#define _PAGE_FILE (1UL << 1)
+#define _PAGE_YOUNG 0
+#define _PAGE_M_MASK _PAGE_M_KRW
+#define _PAGE_C_MASK _PAGE_C_MEM_WT
+
+#ifdef CONFIG_SMP
+#ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
+#define _PAGE_CACHE_SHRD _PAGE_C_MEM_SHRD_WT
+#else
+#define _PAGE_CACHE_SHRD _PAGE_C_MEM_SHRD_WB
+#endif
+#else
+#ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
+#define _PAGE_CACHE_SHRD _PAGE_C_MEM_WT
+#else
+#define _PAGE_CACHE_SHRD _PAGE_C_MEM_WB
+#endif
+#endif
+
+#ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
+#define _PAGE_CACHE _PAGE_C_MEM_WT
+#else
+#define _PAGE_CACHE _PAGE_C_MEM_WB
+#endif
+
+/*
+ * + Level 1 descriptor (PMD)
+ */
+#define PMD_TYPE_TABLE 0
+
+#ifndef __ASSEMBLY__
+
+#define _PAGE_USER_TABLE PMD_TYPE_TABLE
+#define _PAGE_KERNEL_TABLE PMD_TYPE_TABLE
+
+#define PAGE_EXEC __pgprot(_PAGE_V | _PAGE_M_XKRW | _PAGE_E)
+#define PAGE_NONE __pgprot(_PAGE_V | _PAGE_M_KRW | _PAGE_A)
+#define PAGE_READ __pgprot(_PAGE_V | _PAGE_M_UR_KR)
+#define PAGE_RDWR __pgprot(_PAGE_V | _PAGE_M_URW_KRW | _PAGE_D)
+#define PAGE_COPY __pgprot(_PAGE_V | _PAGE_M_UR_KR)
+
+#define PAGE_UXKRWX_V1 __pgprot(_PAGE_V | _PAGE_M_KRW | _PAGE_D | _PAGE_E | _PAGE_G | _PAGE_CACHE_SHRD)
+#define PAGE_UXKRWX_V2 __pgprot(_PAGE_V | _PAGE_M_XKRW | _PAGE_D | _PAGE_E | _PAGE_G | _PAGE_CACHE_SHRD)
+#define PAGE_CACHE_L1 __pgprot(_HAVE_PAGE_L | _PAGE_V | _PAGE_M_KRW | _PAGE_D | _PAGE_E | _PAGE_G | _PAGE_CACHE)
+#define PAGE_MEMORY __pgprot(_HAVE_PAGE_L | _PAGE_V | _PAGE_M_KRW | _PAGE_D | _PAGE_E | _PAGE_G | _PAGE_CACHE_SHRD)
+#define PAGE_KERNEL __pgprot(_PAGE_V | _PAGE_M_KRW | _PAGE_D | _PAGE_E | _PAGE_G | _PAGE_CACHE_SHRD)
+#define PAGE_DEVICE __pgprot(_PAGE_V | _PAGE_M_KRW | _PAGE_D | _PAGE_G | _PAGE_C_DEV)
+#endif /* __ASSEMBLY__ */
+
+/* xwr */
+#define __P000 (PAGE_NONE | _PAGE_CACHE_SHRD)
+#define __P001 (PAGE_READ | _PAGE_CACHE_SHRD)
+#define __P010 (PAGE_COPY | _PAGE_CACHE_SHRD)
+#define __P011 (PAGE_COPY | _PAGE_CACHE_SHRD)
+#define __P100 (PAGE_EXEC | _PAGE_CACHE_SHRD)
+#define __P101 (PAGE_READ | _PAGE_E | _PAGE_CACHE_SHRD)
+#define __P110 (PAGE_COPY | _PAGE_E | _PAGE_CACHE_SHRD)
+#define __P111 (PAGE_COPY | _PAGE_E | _PAGE_CACHE_SHRD)
+
+#define __S000 (PAGE_NONE | _PAGE_CACHE_SHRD)
+#define __S001 (PAGE_READ | _PAGE_CACHE_SHRD)
+#define __S010 (PAGE_RDWR | _PAGE_CACHE_SHRD)
+#define __S011 (PAGE_RDWR | _PAGE_CACHE_SHRD)
+#define __S100 (PAGE_EXEC | _PAGE_CACHE_SHRD)
+#define __S101 (PAGE_READ | _PAGE_E | _PAGE_CACHE_SHRD)
+#define __S110 (PAGE_RDWR | _PAGE_E | _PAGE_CACHE_SHRD)
+#define __S111 (PAGE_RDWR | _PAGE_E | _PAGE_CACHE_SHRD)
+
+#ifndef __ASSEMBLY__
+/*
+ * ZERO_PAGE is a global shared page that is always zero: used
+ * for zero-mapped memory areas etc..
+ */
+extern struct page *empty_zero_page;
+#define ZERO_PAGE(vaddr) (empty_zero_page)
+
+#define pte_pfn(pte) (pte_val(pte) >> PAGE_SHIFT)
+#define pfn_pte(pfn,prot) (__pte(((pfn) << PAGE_SHIFT) | pgprot_val(prot)))
+
+#define pte_none(pte) !(pte_val(pte))
+#define pte_clear(mm,addr,ptep) set_pte_at((mm),(addr),(ptep), __pte(0))
+#define pte_page(pte) (pfn_to_page(pte_pfn(pte)))
+
+#define pte_index(address) (((address) >> PAGE_SHIFT) & (PTRS_PER_PTE - 1))
+#define pte_offset_kernel(dir, address) ((pte_t *)pmd_page_kernel(*(dir)) + pte_index(address))
+#define pte_offset_map(dir, address) ((pte_t *)page_address(pmd_page(*(dir))) + pte_index(address))
+#define pte_offset_map_nested(dir, address) pte_offset_map(dir, address)
+#define pmd_page_kernel(pmd) ((unsigned long) __va(pmd_val(pmd) & PAGE_MASK))
+
+#define pte_unmap(pte) do { } while (0)
+#define pte_unmap_nested(pte) do { } while (0)
+
+#define set_pte_at(mm,addr,ptep,pteval) set_pte(ptep,pteval)
+
+static inline pgd_t *get_pgd( void){
+
+ return ( pgd_t *)phys_to_virt( GET_L1_PPTB() & L1_PPTB_mskBASE);
+}
+
+static inline void set_pgd( pgd_t *pgdp, pgd_t pgd){
+
+ /* TODO */
+}
+/*
+ * Set a level 1 translation table entry, and clean it out of
+ * any caches such that the MMUs can load it correctly.
+ */
+static inline void set_pmd( pmd_t *pmdp, pmd_t pmd){
+
+ *pmdp = pmd;
+#if !defined(CONFIG_CPU_DCACHE_DISABLE) && !defined(CONFIG_CPU_DCACHE_WRITETHROUGH)
+ __asm__ volatile ( "\n\tcctl %0, L1D_VA_WB" ::"r" ( pmdp) :"memory");
+ MSYNC( all);
+ DSB();
+#endif
+}
+
+/*
+ * Set a PTE and flush it out
+ */
+static inline void set_pte( pte_t *ptep, pte_t pte){
+
+ *ptep = pte;
+#if !defined(CONFIG_CPU_DCACHE_DISABLE) && !defined(CONFIG_CPU_DCACHE_WRITETHROUGH)
+ __asm__ volatile ( "\n\tcctl %0, L1D_VA_WB" ::"r" ( ptep) :"memory");
+ MSYNC( all);
+ DSB();
+#endif
+}
+
+
+/*
+ * The following only work if pte_present() is true.
+ * Undefined behaviour if not..
+ */
+
+/*
+ * pte_write: this page is writeable for user mode
+ * pte_read: this page is readable for user mode
+ * pte_kernel_write: this page is writeable for kernel mode
+ *
+ * We don't have pte_kernel_read because kernel always can read.
+ *
+ * */
+
+#define pte_present(pte) (pte_val(pte) & _PAGE_V)
+#define pte_write(pte) ((pte_val(pte) & _PAGE_M_MASK) == _PAGE_M_URW_KRW)
+#define pte_read(pte) (((pte_val(pte) & _PAGE_M_MASK) == _PAGE_M_UR_KR) || \
+ ((pte_val(pte) & _PAGE_M_MASK) == _PAGE_M_UR_KRW) || \
+ ((pte_val(pte) & _PAGE_M_MASK) == _PAGE_M_URW_KRW))
+#define pte_kernel_write(pte) (((pte_val(pte) & _PAGE_M_MASK) == _PAGE_M_URW_KRW) || \
+ ((pte_val(pte) & _PAGE_M_MASK) == _PAGE_M_UR_KRW) || \
+ ((pte_val(pte) & _PAGE_M_MASK) == _PAGE_M_KRW) || \
+ (((pte_val(pte) & _PAGE_M_MASK) == _PAGE_M_XKRW) && pte_exec(pte)))
+#define pte_exec(pte) (pte_val(pte) & _PAGE_E)
+#define pte_dirty(pte) (pte_val(pte) & _PAGE_D)
+#define pte_young(pte) (pte_val(pte) & _PAGE_YOUNG)
+
+/*
+ * The following only works if pte_present() is not true.
+ */
+#define pte_file(pte) (pte_val(pte) & _PAGE_FILE)
+#define pte_to_pgoff(x) (pte_val(x) >> 2)
+#define pgoff_to_pte(x) __pte(((x) << 2) | _PAGE_FILE)
+
+#define PTE_FILE_MAX_BITS 29
+
+#define PTE_BIT_FUNC(fn,op) \
+static inline pte_t pte_##fn(pte_t pte) { pte_val(pte) op; return pte; }
+
+static inline pte_t pte_wrprotect(pte_t pte)
+{
+ pte_val(pte) = pte_val(pte) & ~_PAGE_M_MASK;
+ pte_val(pte) = pte_val(pte) | _PAGE_M_UR_KR;
+ return pte;
+}
+
+static inline pte_t pte_mkwrite(pte_t pte)
+{
+ pte_val(pte) = pte_val(pte) & ~_PAGE_M_MASK;
+ pte_val(pte) = pte_val(pte) | _PAGE_M_URW_KRW;
+ return pte;
+}
+
+PTE_BIT_FUNC(exprotect, &= ~_PAGE_E);
+PTE_BIT_FUNC(mkexec, |= _PAGE_E);
+PTE_BIT_FUNC(mkclean, &= ~_PAGE_D);
+PTE_BIT_FUNC(mkdirty, |= _PAGE_D);
+PTE_BIT_FUNC(mkold, &= ~_PAGE_YOUNG);
+PTE_BIT_FUNC(mkyoung, |= _PAGE_YOUNG);
+static inline int pte_special(pte_t pte) { return 0; }
+static inline pte_t pte_mkspecial(pte_t pte) { return pte; }
+
+/*
+ * Mark the prot value as uncacheable and unbufferable.
+ */
+#define pgprot_noncached(prot) __pgprot((pgprot_val(prot)&~_PAGE_C_MASK) | _PAGE_C_DEV)
+#define pgprot_writecombine(prot) __pgprot((pgprot_val(prot)&~_PAGE_C_MASK) | _PAGE_C_DEV_WB)
+
+#define pmd_none(pmd) (pmd_val(pmd)&0x1)
+#define pmd_present(pmd) (!pmd_none(pmd))
+#define pmd_bad(pmd) pmd_none(pmd)
+
+#define copy_pmd(pmdpd,pmdps) set_pmd((pmdpd), *(pmdps))
+#define pmd_clear(pmdp) set_pmd((pmdp), __pmd(1))
+
+static inline pmd_t __mk_pmd(pte_t *ptep, unsigned long prot)
+{
+ unsigned long ptr = (unsigned long)ptep;
+ pmd_t pmd;
+
+ /*
+ * The pmd must be loaded with the physical
+ * address of the PTE table
+ */
+
+ pmd_val(pmd) = __virt_to_phys(ptr) | prot;
+ return pmd;
+}
+
+
+#define pmd_page(pmd) virt_to_page(__va(pmd_val(pmd)))
+
+/*
+ * Permanent address of a page. We never have highmem, so this is trivial.
+ */
+#define pages_to_mb(x) ((x) >> (20 - PAGE_SHIFT))
+
+/*
+ * Conversion functions: convert a page and protection to a page entry,
+ * and a page entry and page directory to the page they refer to.
+ */
+#define mk_pte(page,prot) pfn_pte(page_to_pfn(page),prot)
+
+/*
+ * The "pgd_xxx()" functions here are trivial for a folded two-level
+ * setup: the pgd is never bad, and a pmd always exists (as it's folded
+ * into the pgd entry)
+ */
+#define pgd_none(pgd) (0)
+#define pgd_bad(pgd) (0)
+#define pgd_present(pgd) (1)
+#define pgd_clear(pgdp) do { } while (0)
+
+#define page_pte_prot(page,prot) mk_pte(page, prot)
+#define page_pte(page) mk_pte(page, __pgprot(0))
+/* Tom:
+ * L1PTE = $mr1 + ((virt >> PMD_SHIFT) << 2);
+ * L2PTE = (((virt >> PAGE_SHIFT) & (PTRS_PER_PTE -1 )) << 2);
+ * PPN = (phys & 0xfffff000);
+ *
+*/
+
+/* to find an entry in a page-table-directory */
+#define pgd_index(address) (((address) >> PGDIR_SHIFT) & (PTRS_PER_PGD - 1))
+#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
+/* to find an entry in a kernel page-table-directory */
+#define pgd_offset_k(addr) pgd_offset(&init_mm, addr)
+
+/* Find an entry in the second-level page table.. */
+#define pmd_offset(dir, addr) ((pmd_t *)(dir))
+
+static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
+{
+ const unsigned long mask = 0xfff;
+ pte_val(pte) = (pte_val(pte) & ~mask) | (pgprot_val(newprot) & mask);
+ return pte;
+}
+
+extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
+
+/* Encode and decode a swap entry.
+ *
+ * We support up to 32GB of swap on 4k machines
+ */
+#define __swp_type(x) (((x).val >> 2) & 0x7f)
+#define __swp_offset(x) ((x).val >> 9)
+#define __swp_entry(type,offset) ((swp_entry_t) { ((type) << 2) | ((offset) << 9) })
+#define __pte_to_swp_entry(pte) ((swp_entry_t) { pte_val(pte) })
+#define __swp_entry_to_pte(swp) ((pte_t) { (swp).val })
+
+/* Needs to be defined here and not in linux/mm.h, as it is arch dependent */
+/* FIXME: this is not correct */
+#define kern_addr_valid(addr) (1)
+
+#include <asm-generic/pgtable.h>
+
+/*
+ * We provide our own arch_get_unmapped_area to cope with VIPT caches.
+ */
+#define HAVE_ARCH_UNMAPPED_AREA
+
+/*
+ * remap a physical address `phys' of size `size' with page protection `prot'
+ * into virtual address `from'
+ */
+#define io_remap_pfn_range(vma,from,pfn,size,prot) \
+ remap_pfn_range(vma, from, pfn, size, prot)
+
+#define pgtable_cache_init() do { } while (0)
+
+#endif /* !__ASSEMBLY__ */
+
+#endif /* _ASMNDS32_PGTABLE_H */
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/poll.h linux-3.4.113/arch/nds32/include/asm/poll.h
--- linux-3.4.113.orig/arch/nds32/include/asm/poll.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/poll.h 2016-12-01 20:59:24.344612443 +0100
@@ -0,0 +1,11 @@
+/*
+ * linux/arch/nds32/include/asm/poll.h
+ * Copyright (C) 2008 Andes Technology Corporation
+ */
+
+#ifndef __ASMNDS32_POLL_H
+#define __ASMNDS32_POLL_H
+
+#include <asm-generic/poll.h>
+
+#endif
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/posix_types.h linux-3.4.113/arch/nds32/include/asm/posix_types.h
--- linux-3.4.113.orig/arch/nds32/include/asm/posix_types.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/posix_types.h 2016-12-01 20:59:24.344612443 +0100
@@ -0,0 +1,40 @@
+/*
+ * arch/arm/include/asm/posix_types.h
+ *
+ * Copyright (C) 1996-1998 Russell King.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Changelog:
+ * 27-06-1996 RMK Created
+ */
+#ifndef __ARCH_NDS32_POSIX_TYPES_H
+#define __ARCH_NDS32_POSIX_TYPES_H
+
+/*
+ * This file is generally used by user-level software, so you need to
+ * be a little careful about namespace pollution etc. Also, we cannot
+ * assume GCC is being used.
+ */
+
+typedef unsigned short __kernel_mode_t;
+#define __kernel_mode_t __kernel_mode_t
+
+typedef unsigned short __kernel_nlink_t;
+#define __kernel_nlink_t __kernel_nlink_t
+
+typedef unsigned short __kernel_ipc_pid_t;
+#define __kernel_ipc_pid_t __kernel_ipc_pid_t
+
+typedef unsigned short __kernel_uid_t;
+typedef unsigned short __kernel_gid_t;
+#define __kernel_uid_t __kernel_uid_t
+
+typedef unsigned short __kernel_old_dev_t;
+#define __kernel_old_dev_t __kernel_old_dev_t
+
+#include <asm-generic/posix_types.h>
+
+#endif
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/processor.h linux-3.4.113/arch/nds32/include/asm/processor.h
--- linux-3.4.113.orig/arch/nds32/include/asm/processor.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/processor.h 2016-12-01 20:59:24.344612443 +0100
@@ -0,0 +1,133 @@
+/*
+ * linux/arch/nds32/include/asm/processor.h
+ */
+/* Copyright (C) 1995-1999 Russell King
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+/* ============================================================================
+ * Copyright (C) 2007 Andes Technology Corporation
+ * This file is part of Linux and should be licensed under the GPL.
+ * See the file COPYING for conditions for redistribution.
+ *
+ * Abstract:
+ *
+ * This program is ptrace relative code for Andes NDS32 architecture.
+ * Original referred from ARM, fit to NDS32.
+ *
+ * Revision History:
+ *
+ * Oct.03.2007 Original from Tom, Shawn and Steven, refined by Harry.
+ *
+ * Note:
+ *
+ * ============================================================================
+ */
+#ifndef __ASM_NDS32_PROCESSOR_H
+#define __ASM_NDS32_PROCESSOR_H
+
+/*
+ * Default implementation of macro that returns current
+ * instruction pointer ("program counter").
+ */
+#define current_text_addr() ({ __label__ _l; _l: &&_l;})
+
+#ifdef __KERNEL__
+
+#include <asm/ptrace.h>
+#include <asm/procinfo.h>
+#include <asm/types.h>
+#include <asm/cpuver.h>
+#include <asm/sigcontext.h>
+
+#define KERNEL_STACK_SIZE PAGE_SIZE
+#define STACK_TOP TASK_SIZE
+#define STACK_TOP_MAX TASK_SIZE
+
+struct debug_info {
+ u32 address;
+ u16 insn;
+ u8 valid;
+};
+
+struct thread_struct {
+ /* fault info */
+ unsigned long address;
+ unsigned long trap_no;
+ unsigned long error_code;
+
+ struct fpu_struct fpu; /* Saved fpu/fpu emulator stuff. */
+ struct audio_struct audio;
+ struct debug_info debug; /* debugging */
+};
+
+#define INIT_THREAD { }
+
+#ifdef __NDS32_EB__
+#define PSW_DE PSW_mskBE
+#else
+#define PSW_DE 0x0
+#endif
+
+#ifdef CONFIG_WBNA
+#define PSW_valWBNA PSW_mskWBNA
+#else
+#define PSW_valWBNA 0x0
+#endif
+
+#define start_thread(regs,pc,sp) \
+({ \
+ unsigned long *stack = (unsigned long *)sp; \
+ set_fs(USER_DS); \
+ memzero(regs->uregs, sizeof(regs->uregs)); \
+ regs->NDS32_ipsw = (PSW_CPL_ANY | PSW_valWBNA | PSW_mskDT | PSW_mskIT | PSW_DE | PSW_mskGIE); \
+ regs->NDS32_ir0 = (PSW_CPL_ANY | PSW_valWBNA | PSW_mskDT | PSW_mskIT | PSW_DE | PSW_SYSTEM | PSW_INTL_1); \
+ regs->NDS32_ipc = pc; /* pc */ \
+ regs->NDS32_sp = sp; /* $sp */ \
+ regs->NDS32_r2 = stack[4]; /* $r2 (envp) */ \
+ regs->NDS32_r1 = stack[1]; /* $r1 (argv) */ \
+ regs->NDS32_r0 = stack[0]; /* $r0 (argc) */ \
+})
+
+
+/* Forward declaration, a strange C thing */
+struct task_struct;
+
+/* Free all resources held by a thread. */
+extern void release_thread(struct task_struct *);
+#ifdef CONFIG_FPU
+#ifndef CONFIG_UNLAZU_FPU //lazy fpu
+extern struct task_struct *last_task_used_math;
+#endif
+#endif
+#ifdef CONFIG_AUDIO
+#ifndef CONFIG_UNLAZY_AUDIO //lazy audio
+extern struct task_struct *last_task_used_audio;
+#endif
+#endif
+
+/* Prepare to copy thread state - unlazy all lazy status */
+#define prepare_to_copy(tsk) do { } while (0)
+
+unsigned long get_wchan(struct task_struct *p);
+
+#define cpu_relax() barrier()
+
+#define task_pt_regs(task) \
+ ((struct pt_regs *) (task_stack_page(task) + THREAD_SIZE \
+ - 8) - 1)
+
+/*
+ * Create a new kernel thread
+ */
+extern int kernel_thread(int (*fn)(void *), void *arg, unsigned long flags);
+
+#define KSTK_EIP(tsk) (((unsigned long *)(4096+(unsigned long)task_thread_info(tsk)))[1019])
+#define KSTK_ESP(tsk) (((unsigned long *)(4096+(unsigned long)task_thread_info(tsk)))[1017])
+
+
+#endif
+
+#endif /* __ASM_NDS32_PROCESSOR_H */
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/proc-fns.h linux-3.4.113/arch/nds32/include/asm/proc-fns.h
--- linux-3.4.113.orig/arch/nds32/include/asm/proc-fns.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/proc-fns.h 2016-12-01 20:59:24.344612443 +0100
@@ -0,0 +1,88 @@
+/*
+ * linux/arch/nds32/include/asm/proc-fns.h
+ * Copyright (C) 2008 Andes Technology Corporation
+ */
+
+#ifndef __NDS32_PROCFNS_H__
+#define __NDS32_PROCFNS_H__
+
+#define CPU_NAME n12
+
+#ifdef __KERNEL__
+
+#ifdef __STDC__
+#define ____cpu_fn(name,fn) name##fn
+#else
+#define ____cpu_fn(name,fn) name/**/fn
+#endif
+#define __cpu_fn(name,fn) ____cpu_fn(name,fn)
+
+#define cpu_proc_init __cpu_fn( CPU_NAME, _proc_init)
+#define cpu_proc_fin __cpu_fn( CPU_NAME, _proc_fin)
+#define cpu_do_idle __cpu_fn( CPU_NAME, _do_idle)
+#define cpu_reset __cpu_fn( CPU_NAME, _reset)
+#define cpu_switch_mm __cpu_fn( CPU_NAME, _switch_mm)
+
+#define cpu_dcache_inval_all __cpu_fn( CPU_NAME, _dcache_inval_all)
+#define cpu_dcache_wbinval_all __cpu_fn( CPU_NAME, _dcache_wbinval_all)
+#define cpu_dcache_inval_page __cpu_fn( CPU_NAME, _dcache_inval_page)
+#define cpu_dcache_wb_page __cpu_fn( CPU_NAME, _dcache_wb_page)
+#define cpu_dcache_wbinval_page __cpu_fn( CPU_NAME, _dcache_wbinval_page)
+#define cpu_dcache_inval_range __cpu_fn( CPU_NAME, _dcache_inval_range)
+#define cpu_dcache_wb_range __cpu_fn( CPU_NAME, _dcache_wb_range)
+#define cpu_dcache_wbinval_range __cpu_fn( CPU_NAME, _dcache_wbinval_range)
+
+#define cpu_icache_inval_all __cpu_fn( CPU_NAME, _icache_inval_all)
+#define cpu_icache_inval_page __cpu_fn( CPU_NAME, _icache_inval_page)
+#define cpu_icache_inval_range __cpu_fn( CPU_NAME, _icache_inval_range)
+
+#define cpu_cache_wbinval_page __cpu_fn( CPU_NAME, _cache_wbinval_page)
+#define cpu_cache_wbinval_range __cpu_fn( CPU_NAME, _cache_wbinval_range)
+#define cpu_cache_wbinval_range_check __cpu_fn( CPU_NAME, _cache_wbinval_range_check)
+
+#define cpu_dma_wb_range __cpu_fn( CPU_NAME, _dma_wb_range)
+#define cpu_dma_inval_range __cpu_fn( CPU_NAME, _dma_inval_range)
+#define cpu_dma_wbinval_range __cpu_fn( CPU_NAME, _dma_wbinval_range)
+
+#include <asm/page.h>
+
+struct mm_struct;
+struct vm_area_struct;
+extern void cpu_proc_init(void);
+extern void cpu_proc_fin(void);
+extern void cpu_do_idle(void);
+extern void cpu_reset(unsigned long reset);
+extern void cpu_switch_mm(struct mm_struct *mm);
+
+extern void cpu_dcache_inval_all(void);
+extern void cpu_dcache_wbinval_all(void);
+extern void cpu_dcache_inval_page(unsigned long page);
+extern void cpu_dcache_wb_page(unsigned long page);
+extern void cpu_dcache_wbinval_page(unsigned long page);
+extern void cpu_dcache_inval_range(unsigned long start, unsigned long end);
+extern void cpu_dcache_wb_range(unsigned long start, unsigned long end);
+extern void cpu_dcache_wbinval_range(unsigned long start, unsigned long end);
+
+extern void cpu_icache_inval_all(void);
+extern void cpu_icache_inval_page(unsigned long page);
+extern void cpu_icache_inval_range(unsigned long start, unsigned long end);
+
+extern void cpu_cache_wbinval_page(unsigned long page, int flushi);
+extern void cpu_cache_wbinval_range(unsigned long start,
+ unsigned long end, int flushi);
+extern void cpu_cache_wbinval_range_check(struct vm_area_struct *vma,
+ unsigned long start, unsigned long end);
+
+extern void cpu_dma_wb_range(unsigned long start, unsigned long end);
+extern void cpu_dma_inval_range(unsigned long start, unsigned long end);
+extern void cpu_dma_wbinval_range(unsigned long start, unsigned long end);
+
+#ifdef CONFIG_CACHE_L2
+#define cpu_L2cache_inval __cpu_fn(CPU_NAME, _L2cache_inval)
+#define cpu_L2cache_wb __cpu_fn(CPU_NAME, _L2cache_wb)
+extern void cpu_L2cache_inval(void);
+extern void cpu_L2cache_wb(void);
+#endif
+
+#endif /* __KERNEL__ */
+#endif /* __NDS32_PROCFNS_H__ */
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/procinfo.h linux-3.4.113/arch/nds32/include/asm/procinfo.h
--- linux-3.4.113.orig/arch/nds32/include/asm/procinfo.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/procinfo.h 2016-12-01 20:59:24.344612443 +0100
@@ -0,0 +1,71 @@
+/*
+ * linux/arch/nds32/include/asm/procinfo.h
+ *
+ * Copyright (C) 1996-1999 Russell King
+ * Copyright (C) 2008 Andes Technology Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+#ifndef __ASM_PROCINFO_H
+#define __ASM_PROCINFO_H
+
+#ifndef __ASSEMBLY__
+
+/*
+ * These structure are defined in assembly
+ * ( nds32/mm/proc-nds32.S)
+ */
+struct proc_info_item {
+
+ const char *manufacturer;
+ const char *cpu_name;
+};
+
+/*
+ * Note! struct processor is always defined if we're
+ * using MULTI_CPU, otherwise this entry is unused,
+ * but still exists.
+ *
+ * NOTE! The following structure is defined by assembly
+ * language, NOT C code. For more information, check:
+ * arch/arm/mm/proc-*.S and arch/arm/kernel/head.S
+ */
+struct proc_info_list {
+
+ unsigned int cpu_val;
+ unsigned int cpu_mask;
+ const char *arch_name;
+ const char *elf_name;
+ unsigned int elf_hwcap;
+ struct proc_info_item *info;
+};
+
+extern unsigned int elf_hwcap;
+
+#endif /* __ASSEMBLY__ */
+
+#define HWCAP_MFUSR_PC 0x000001
+#define HWCAP_EXT 0x000002
+#define HWCAP_EXT2 0x000004
+#define HWCAP_FPU 0x000008
+#define HWCAP_AUDIO 0x000010
+#define HWCAP_BASE16 0x000020
+#define HWCAP_STRING 0x000040
+#define HWCAP_REDUCED_REGS 0x000080
+#define HWCAP_VIDEO 0x000100
+#define HWCAP_ENCRYPT 0x000200
+#define HWCAP_EDM 0x000400
+#define HWCAP_LMDMA 0x000800
+#define HWCAP_PFM 0x001000
+#define HWCAP_HSMP 0x002000
+#define HWCAP_TRACE 0x004000
+#define HWCAP_DIV 0x008000
+#define HWCAP_MAC 0x010000
+#define HWCAP_L2C 0x020000
+#define HWCAP_FPU_DP 0x040000
+#define HWCAP_V2 0x080000
+#define HWCAP_DX_REGS 0x100000
+
+#endif
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/ptrace.h linux-3.4.113/arch/nds32/include/asm/ptrace.h
--- linux-3.4.113.orig/arch/nds32/include/asm/ptrace.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/ptrace.h 2016-12-01 20:59:24.344612443 +0100
@@ -0,0 +1,119 @@
+/*
+ * linux/arch/nds32/include/asm/ptrace.h
+ *
+ * Copyright (C) 1996-2003 Russell King
+ * Copyright (C) 2008 Andes Technology Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+#ifndef __ASM_NDS32_PTRACE_H
+#define __ASM_NDS32_PTRACE_H
+
+#define PTRACE_GETREGS 12
+#define PTRACE_SETREGS 13
+#define PTRACE_GETFPREGS 14
+#define PTRACE_SETFPREGS 15
+#define PTRACE_GETAUREGS 18
+#define PTRACE_SETAUREGS 19
+
+#define PTRACE_OLDSETOPTIONS 21
+
+#define PTRACE_GET_THREAD_AREA 22
+
+#ifndef __ASSEMBLY__
+/* this struct defines the way the registers are stored on the
+ stack during a system call. */
+
+struct pt_regs {
+#if defined(CONFIG_ABI1)
+ long dummy[6];
+#endif
+ long uregs[44];
+};
+#define NDS32_osp uregs[43]
+#define NDS32_FUCOP_CTL uregs[42]
+#define NDS32_lp uregs[41]
+#define NDS32_gp uregs[40]
+#define NDS32_fp uregs[39]
+#define NDS32_r25 uregs[38]
+#define NDS32_r24 uregs[37]
+#define NDS32_r23 uregs[36]
+#define NDS32_r22 uregs[35]
+#define NDS32_r21 uregs[34]
+#define NDS32_r20 uregs[33]
+#define NDS32_r19 uregs[32]
+#define NDS32_r18 uregs[31]
+#define NDS32_r17 uregs[30]
+#define NDS32_r16 uregs[29]
+#define NDS32_r15 uregs[28]
+#define NDS32_r14 uregs[27]
+#define NDS32_r13 uregs[26]
+#define NDS32_r12 uregs[25]
+#define NDS32_r11 uregs[24]
+#define NDS32_r10 uregs[23]
+#define NDS32_r9 uregs[22]
+#define NDS32_r8 uregs[21]
+#define NDS32_r7 uregs[20]
+#define NDS32_r6 uregs[19]
+#define NDS32_r5 uregs[18]
+#define NDS32_r4 uregs[17]
+#define NDS32_r3 uregs[16]
+#define NDS32_r2 uregs[15]
+#define NDS32_r1 uregs[14]
+#define NDS32_r0 uregs[13]
+#if defined(CONFIG_HWZOL)
+#define NDS32_lc uregs[11]
+#define NDS32_le uregs[10]
+#define NDS32_lb uregs[9]
+#endif
+#define NDS32_pp1 uregs[8]
+#define NDS32_pp0 uregs[7]
+#define NDS32_pipc uregs[6]
+#define NDS32_pipsw uregs[5]
+#define NDS32_ORIG_r0 uregs[4]
+#define NDS32_sp uregs[3]
+#define NDS32_ipc uregs[2]
+#define NDS32_ipsw uregs[1]
+#define NDS32_ir0 uregs[0]
+
+#ifdef __KERNEL__
+#include <asm/bitfield.h>
+
+#define arch_has_single_step() (1)
+struct task_struct;
+extern void user_enable_single_step(struct task_struct *);
+extern void user_disable_single_step(struct task_struct *);
+
+#define user_mode(regs) (((regs)->NDS32_ipsw & PSW_mskPOM) == 0)
+
+#define interrupts_enabled(regs) (!((regs)->NDS32_ipsw & ~PSW_mskGIE))
+
+extern void show_regs(struct pt_regs *);
+
+/* Are the current registers suitable for user mode?
+ * (used to maintain security in signal handlers)
+ */
+static inline int valid_user_regs(struct pt_regs *regs)
+{
+ return user_mode(regs) && ((regs->NDS32_ipsw & PSW_mskGIE) == 1);
+}
+
+static inline unsigned long regs_return_value(struct pt_regs *regs)
+{
+ return regs->NDS32_r0;
+}
+
+
+#define instruction_pointer(regs) ((regs)->NDS32_ipc)
+
+#ifdef CONFIG_SMP
+extern unsigned long profile_pc(struct pt_regs *regs);
+#else
+#define profile_pc(regs) instruction_pointer(regs)
+#endif
+
+#endif /* __KERNEL__ */
+#endif /* __ASSEMBLY__ */
+#endif
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/reg_access.h linux-3.4.113/arch/nds32/include/asm/reg_access.h
--- linux-3.4.113.orig/arch/nds32/include/asm/reg_access.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/reg_access.h 2016-12-01 20:59:24.344612443 +0100
@@ -0,0 +1,153 @@
+/*
+ * linux/arch/nds32/include/asm/reg_access.h
+ * Copyright (C) 2008 Andes Technology Corporation
+ */
+
+#ifndef __NDS32_REG_ACCESS_H__
+#define __NDS32_REG_ACCESS_H__
+
+#ifndef __ASSEMBLY__
+#define DEFINE_GET_SYS_REG( reg) \
+inline static unsigned long GET_##reg( void){ \
+ unsigned long val; \
+ __asm__ volatile ( "mfsr %0, $"#reg :"=&r" (val) ::"memory"); \
+ return val; \
+}
+
+#define DEFINE_PUT_SYS_REG( reg) \
+inline static void SET_##reg( unsigned long val){ \
+ __asm__ volatile ( "\n\tmtsr %0, $"#reg \
+ "\n\tdsb" ::"r" ( val) :"memory"); \
+}
+
+#define DEFINE_PUT_SYS_REG_i( reg) \
+inline static void SET_##reg( unsigned long val){ \
+ __asm__ volatile ( "\n\tmtsr %0, $"#reg \
+ "\n\tisb" ::"r" ( val) :"memory"); \
+}
+#define DEFINE_SYS_REG_OP( reg) \
+DEFINE_GET_SYS_REG( reg); \
+DEFINE_PUT_SYS_REG( reg);
+
+#define DEFINE_SYS_REG_OP_i( reg) \
+DEFINE_GET_SYS_REG( reg); \
+DEFINE_PUT_SYS_REG_i( reg);
+
+DEFINE_SYS_REG_OP( CPU_VER);
+DEFINE_SYS_REG_OP( ICM_CFG);
+DEFINE_SYS_REG_OP( DCM_CFG);
+DEFINE_SYS_REG_OP( MMU_CFG);
+DEFINE_SYS_REG_OP( MSC_CFG);
+DEFINE_SYS_REG_OP( CORE_ID);
+DEFINE_SYS_REG_OP( FUCOP_EXIST);
+
+DEFINE_SYS_REG_OP_i( PSW);
+DEFINE_SYS_REG_OP( IPSW);
+DEFINE_SYS_REG_OP( P_IPSW);
+DEFINE_SYS_REG_OP( IVB);
+DEFINE_SYS_REG_OP( EVA);
+DEFINE_SYS_REG_OP( P_EVA);
+DEFINE_SYS_REG_OP( ITYPE);
+DEFINE_SYS_REG_OP( P_ITYPE);
+DEFINE_SYS_REG_OP( MERR);
+DEFINE_SYS_REG_OP( IPC);
+DEFINE_SYS_REG_OP( P_IPC);
+DEFINE_SYS_REG_OP( OIPC);
+DEFINE_SYS_REG_OP( P_P0);
+DEFINE_SYS_REG_OP( P_P1);
+DEFINE_SYS_REG_OP( INT_MASK);
+DEFINE_SYS_REG_OP( INT_PEND);
+DEFINE_SYS_REG_OP( INT_MASK2);
+DEFINE_SYS_REG_OP( INT_PEND2);
+DEFINE_SYS_REG_OP( INT_TRIGGER);
+
+DEFINE_SYS_REG_OP( MMU_CTL);
+DEFINE_SYS_REG_OP( L1_PPTB);
+DEFINE_SYS_REG_OP( TLB_VPN);
+DEFINE_SYS_REG_OP( TLB_DATA);
+DEFINE_SYS_REG_OP( TLB_MISC);
+DEFINE_SYS_REG_OP( VLPT_IDX);
+DEFINE_SYS_REG_OP( ILMB);
+DEFINE_SYS_REG_OP( DLMB);
+DEFINE_SYS_REG_OP( CACHE_CTL);
+DEFINE_SYS_REG_OP( HSMP_SADDR);
+DEFINE_SYS_REG_OP( HSMP_EADDR);
+
+DEFINE_SYS_REG_OP( EDM_CFG);
+DEFINE_SYS_REG_OP( EDMSW);
+DEFINE_SYS_REG_OP( EDM_CTL);
+DEFINE_SYS_REG_OP( EDM_DTR);
+DEFINE_SYS_REG_OP( BPMTC);
+DEFINE_SYS_REG_OP( DIMBR);
+DEFINE_SYS_REG_OP( TECR0);
+DEFINE_SYS_REG_OP( TECR1);
+
+DEFINE_SYS_REG_OP( BPC0);
+DEFINE_SYS_REG_OP( BPA0);
+DEFINE_SYS_REG_OP( BPAM0);
+DEFINE_SYS_REG_OP( BPV0);
+DEFINE_SYS_REG_OP( BPCID0);
+DEFINE_SYS_REG_OP( BPC1);
+DEFINE_SYS_REG_OP( BPA1);
+DEFINE_SYS_REG_OP( BPAM1);
+DEFINE_SYS_REG_OP( BPV1);
+DEFINE_SYS_REG_OP( BPCID1);
+DEFINE_SYS_REG_OP( BPC2);
+DEFINE_SYS_REG_OP( BPA2);
+DEFINE_SYS_REG_OP( BPAM2);
+DEFINE_SYS_REG_OP( BPV2);
+DEFINE_SYS_REG_OP( BPCID2);
+DEFINE_SYS_REG_OP( BPC3);
+DEFINE_SYS_REG_OP( BPA3);
+DEFINE_SYS_REG_OP( BPAM3);
+DEFINE_SYS_REG_OP( BPV3);
+DEFINE_SYS_REG_OP( BPCID3);
+DEFINE_SYS_REG_OP( BPC4);
+DEFINE_SYS_REG_OP( BPA4);
+DEFINE_SYS_REG_OP( BPAM4);
+DEFINE_SYS_REG_OP( BPV4);
+DEFINE_SYS_REG_OP( BPCID4);
+DEFINE_SYS_REG_OP( BPC5);
+DEFINE_SYS_REG_OP( BPA5);
+DEFINE_SYS_REG_OP( BPAM5);
+DEFINE_SYS_REG_OP( BPV5);
+DEFINE_SYS_REG_OP( BPCID5);
+DEFINE_SYS_REG_OP( BPC6);
+DEFINE_SYS_REG_OP( BPA6);
+DEFINE_SYS_REG_OP( BPAM6);
+DEFINE_SYS_REG_OP( BPV6);
+DEFINE_SYS_REG_OP( BPCID6);
+DEFINE_SYS_REG_OP( BPC7);
+DEFINE_SYS_REG_OP( BPA7);
+DEFINE_SYS_REG_OP( BPAM7);
+DEFINE_SYS_REG_OP( BPV7);
+DEFINE_SYS_REG_OP( BPCID7);
+
+DEFINE_SYS_REG_OP( PFMC0);
+DEFINE_SYS_REG_OP( PFMC1);
+DEFINE_SYS_REG_OP( PFMC2);
+DEFINE_SYS_REG_OP( PFM_CTL);
+
+DEFINE_SYS_REG_OP( SDZ_CTL);
+DEFINE_SYS_REG_OP( N12MISC_CTL);
+DEFINE_SYS_REG_OP( PRUSR_ACC_CTL);
+
+DEFINE_SYS_REG_OP( DMA_CFG);
+DEFINE_SYS_REG_OP( DMA_GCSW);
+DEFINE_SYS_REG_OP( DMA_CHNSEL);
+DEFINE_SYS_REG_OP( DMA_ACT);
+DEFINE_SYS_REG_OP( DMA_SETUP);
+DEFINE_SYS_REG_OP( DMA_ISADDR);
+DEFINE_SYS_REG_OP( DMA_ESADDR);
+DEFINE_SYS_REG_OP( DMA_TCNT);
+DEFINE_SYS_REG_OP( DMA_STATUS);
+DEFINE_SYS_REG_OP( DMA_2DSET);
+DEFINE_SYS_REG_OP( DMA_2DSCTL);
+
+DEFINE_SYS_REG_OP( FPCSR);
+DEFINE_SYS_REG_OP( FPCFG);
+DEFINE_SYS_REG_OP( FUCOP_CTL);
+
+#endif /* !__ASSEMBLY__ */
+
+#endif /* __NDS32_REG_ACCESS_H__ */
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/resource.h linux-3.4.113/arch/nds32/include/asm/resource.h
--- linux-3.4.113.orig/arch/nds32/include/asm/resource.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/resource.h 2016-12-01 20:59:24.344612443 +0100
@@ -0,0 +1,11 @@
+/*
+ * linux/arch/nds32/include/asm/resource.h
+ * Copyright (C) 2008 Andes Technology Corporation
+ */
+
+#ifndef __NDS32_RESOURCE_H__
+#define __NDS32_RESOURCE_H__
+
+#include <asm-generic/resource.h>
+
+#endif
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/rtc.h linux-3.4.113/arch/nds32/include/asm/rtc.h
--- linux-3.4.113.orig/arch/nds32/include/asm/rtc.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/rtc.h 2016-12-01 20:59:24.344612443 +0100
@@ -0,0 +1,43 @@
+/*
+ * linux/arch/nds32/include/asm/rtc.h
+ *
+ * Copyright (C) 2003 Deep Blue Solutions Ltd.
+ * Copyright (C) 2008 Andes Technology Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+#ifndef ASMNDS32_RTC_H
+#define ASMNDS32_RTC_H
+
+struct module;
+
+struct rtc_ops {
+ struct module *owner;
+ int (*open)(void);
+ void (*release)(void);
+ int (*ioctl)(unsigned int, unsigned long);
+
+ int (*read_time)(struct rtc_time *);
+ int (*set_time)(struct rtc_time *);
+ int (*read_alarm)(struct rtc_wkalrm *);
+ int (*set_alarm)(struct rtc_wkalrm *);
+ int (*proc)(char *buf);
+};
+
+void rtc_update(unsigned long, unsigned long);
+int register_rtc(struct rtc_ops *);
+void unregister_rtc(struct rtc_ops *);
+
+static inline int rtc_periodic_alarm(struct rtc_time *tm)
+{
+ return (tm->tm_year == -1) ||
+ ((unsigned)tm->tm_mon >= 12) ||
+ ((unsigned)(tm->tm_mday - 1) >= 31) ||
+ ((unsigned)tm->tm_hour > 23) ||
+ ((unsigned)tm->tm_min > 59) ||
+ ((unsigned)tm->tm_sec > 59);
+}
+
+#endif
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/scatterlist.h linux-3.4.113/arch/nds32/include/asm/scatterlist.h
--- linux-3.4.113.orig/arch/nds32/include/asm/scatterlist.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/scatterlist.h 2016-12-01 20:59:24.344612443 +0100
@@ -0,0 +1,35 @@
+/*
+ * linux/arch/nds32/include/asm/scatterlist.h
+ * Copyright (C) 2008 Andes Technology Corporation
+ */
+
+#ifndef _ASMNDS32_SCATTERLIST_H
+#define _ASMNDS32_SCATTERLIST_H
+
+#include <asm/memory.h>
+#include <asm/types.h>
+#include <asm-generic/scatterlist.h>
+
+#if 0
+struct scatterlist {
+#ifdef CONFIG_DEBUG_SG
+ unsigned long sg_magic;
+#endif
+ unsigned long page_link;
+ unsigned int offset; /* buffer offset */
+ dma_addr_t dma_address; /* dma address */
+ unsigned int length; /* length */
+};
+
+/*
+ * These macros should be used after a pci_map_sg call has been done
+ * to get bus addresses of each of the SG entries and their lengths.
+ * You should only work with the number of sg entries pci_map_sg
+ * returns, or alternatively stop on the first sg_dma_len(sg) which
+ * is 0.
+ */
+#define sg_dma_address(sg) ((sg)->dma_address)
+#define sg_dma_len(sg) ((sg)->length)
+#endif
+
+#endif /* _ASMNDS32_SCATTERLIST_H */
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/sections.h linux-3.4.113/arch/nds32/include/asm/sections.h
--- linux-3.4.113.orig/arch/nds32/include/asm/sections.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/sections.h 2016-12-01 20:59:24.344612443 +0100
@@ -0,0 +1,11 @@
+/*
+ * linux/arch/nds32/include/asm/sections.h
+ * Copyright (C) 2008 Andes Technology Corporation
+ */
+
+#ifndef __NDS32_SECTIONS_H__
+#define __NDS32_SECTIONS_H__
+
+#include <asm-generic/sections.h>
+
+#endif
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/segment.h linux-3.4.113/arch/nds32/include/asm/segment.h
--- linux-3.4.113.orig/arch/nds32/include/asm/segment.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/segment.h 2016-12-01 20:59:24.344612443 +0100
@@ -0,0 +1,16 @@
+/*
+ * linux/arch/nds32/include/asm/segment.h
+ * Copyright (C) 2008 Andes Technology Corporation
+ */
+
+#ifndef __ASM_NDS32_SEGMENT_H
+#define __ASM_NDS32_SEGMENT_H
+
+#define __KERNEL_CS 0x0
+#define __KERNEL_DS 0x0
+
+#define __USER_CS 0x1
+#define __USER_DS 0x1
+
+#endif /* __ASM_NDS32_SEGMENT_H */
+
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/semaphore.h linux-3.4.113/arch/nds32/include/asm/semaphore.h
--- linux-3.4.113.orig/arch/nds32/include/asm/semaphore.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/semaphore.h 2016-12-01 20:59:24.344612443 +0100
@@ -0,0 +1,6 @@
+/*
+ * linux/arch/nds32/include/asm/semaphore.h
+ * Copyright (C) 2008 Andes Technology Corporation
+ */
+
+#include <linux/semaphore.h>
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/semaphore-helper.h linux-3.4.113/arch/nds32/include/asm/semaphore-helper.h
--- linux-3.4.113.orig/arch/nds32/include/asm/semaphore-helper.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/semaphore-helper.h 2016-12-01 20:59:24.344612443 +0100
@@ -0,0 +1,89 @@
+/*
+ * linux/arch/nds32/include/asm/semaphore-helper.h
+ * Copyright (C) 2008 Andes Technology Corporation
+ */
+
+#ifndef ASMNDS32_SEMAPHORE_HELPER_H
+#define ASMNDS32_SEMAPHORE_HELPER_H
+
+/*
+ * These two _must_ execute atomically wrt each other.
+ */
+static inline void wake_one_more(struct semaphore * sem)
+{
+ unsigned long flags;
+
+ spin_lock_irqsave(&semaphore_wake_lock, flags);
+ if (atomic_read(&sem->count) <= 0)
+ sem->waking++;
+ spin_unlock_irqrestore(&semaphore_wake_lock, flags);
+}
+
+static inline int waking_non_zero(struct semaphore *sem)
+{
+ unsigned long flags;
+ int ret = 0;
+
+ spin_lock_irqsave(&semaphore_wake_lock, flags);
+ if (sem->waking > 0) {
+ sem->waking--;
+ ret = 1;
+ }
+ spin_unlock_irqrestore(&semaphore_wake_lock, flags);
+ return ret;
+}
+
+/*
+ * waking non zero interruptible
+ * 1 got the lock
+ * 0 go to sleep
+ * -EINTR interrupted
+ *
+ * We must undo the sem->count down_interruptible() increment while we are
+ * protected by the spinlock in order to make this atomic_inc() with the
+ * atomic_read() in wake_one_more(), otherwise we can race. -arca
+ */
+static inline int waking_non_zero_interruptible(struct semaphore *sem,
+ struct task_struct *tsk)
+{
+ unsigned long flags;
+ int ret = 0;
+
+ spin_lock_irqsave(&semaphore_wake_lock, flags);
+ if (sem->waking > 0) {
+ sem->waking--;
+ ret = 1;
+ } else if (signal_pending(tsk)) {
+ atomic_inc(&sem->count);
+ ret = -EINTR;
+ }
+ spin_unlock_irqrestore(&semaphore_wake_lock, flags);
+ return ret;
+}
+
+/*
+ * waking_non_zero_try_lock:
+ * 1 failed to lock
+ * 0 got the lock
+ *
+ * We must undo the sem->count down_interruptible() increment while we are
+ * protected by the spinlock in order to make this atomic_inc() with the
+ * atomic_read() in wake_one_more(), otherwise we can race. -arca
+ */
+static inline int waking_non_zero_trylock(struct semaphore *sem)
+{
+ unsigned long flags;
+ int ret = 1;
+
+ spin_lock_irqsave(&semaphore_wake_lock, flags);
+ if (sem->waking <= 0)
+ atomic_inc(&sem->count);
+ else {
+ sem->waking--;
+ ret = 0;
+ }
+ spin_unlock_irqrestore(&semaphore_wake_lock, flags);
+ return ret;
+}
+
+#endif
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/sembuf.h linux-3.4.113/arch/nds32/include/asm/sembuf.h
--- linux-3.4.113.orig/arch/nds32/include/asm/sembuf.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/sembuf.h 2016-12-01 20:59:24.344612443 +0100
@@ -0,0 +1,30 @@
+/*
+ * linux/arch/nds32/include/asm/sembuf.h
+ * Copyright (C) 2008 Andes Technology Corporation
+ */
+
+#ifndef _ASMNDS32_SEMBUF_H
+#define _ASMNDS32_SEMBUF_H
+
+/*
+ * The semid64_ds structure for arm architecture.
+ * Note extra padding because this structure is passed back and forth
+ * between kernel and user space.
+ *
+ * Pad space is left for:
+ * - 64-bit time_t to solve y2038 problem
+ * - 2 miscellaneous 32-bit values
+ */
+
+struct semid64_ds {
+ struct ipc64_perm sem_perm; /* permissions .. see ipc.h */
+ __kernel_time_t sem_otime; /* last semop time */
+ unsigned long __unused1;
+ __kernel_time_t sem_ctime; /* last change time */
+ unsigned long __unused2;
+ unsigned long sem_nsems; /* no. of semaphores in array */
+ unsigned long __unused3;
+ unsigned long __unused4;
+};
+
+#endif /* _ASMNDS32_SEMBUF_H */
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/serial.h linux-3.4.113/arch/nds32/include/asm/serial.h
--- linux-3.4.113.orig/arch/nds32/include/asm/serial.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/serial.h 2016-12-01 20:59:24.344612443 +0100
@@ -0,0 +1,20 @@
+/*
+ * linux/arch/nds32/include/asm/serial.h
+ *
+ * Copyright (C) 1996 Russell King.
+ * Copyright (C) 2008 Andes Technology Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Changelog:
+ * 15-10-1996 RMK Created
+ */
+
+#ifndef __ASM_SERIAL_H
+#define __ASM_SERIAL_H
+
+#define BASE_BAUD (CONFIG_UART_CLK / 16)
+
+#endif
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/setup.h linux-3.4.113/arch/nds32/include/asm/setup.h
--- linux-3.4.113.orig/arch/nds32/include/asm/setup.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/setup.h 2016-12-01 20:59:24.344612443 +0100
@@ -0,0 +1,232 @@
+/*
+ * linux/arch/nds32/include/asm/setup.h
+ *
+ * Copyright (C) 1997-1999 Russell King
+ * Copyright (C) 2008 Andes Technology Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Structure passed to kernel to tell it about the
+ * hardware it's running on. See Documentation/arm/Setup
+ * for more info.
+ */
+#ifndef __ASMNDS32_SETUP_H
+#define __ASMNDS32_SETUP_H
+
+#define COMMAND_LINE_SIZE 256
+
+/* The list ends with an ATAG_NONE node. */
+#define ATAG_NONE 0x00000000
+
+struct tag_header {
+ u32 size;
+ u32 tag;
+};
+
+/* The list must start with an ATAG_CORE node */
+#define ATAG_CORE 0x54410001
+
+struct tag_core {
+ u32 flags; /* bit 0 = read-only */
+ u32 pagesize;
+ u32 rootdev;
+};
+
+/* it is allowed to have multiple ATAG_MEM nodes */
+#define ATAG_MEM 0x54410002
+
+struct tag_mem32 {
+ u32 size;
+ u32 start; /* physical start address */
+};
+
+/* VGA text type displays */
+#define ATAG_VIDEOTEXT 0x54410003
+
+struct tag_videotext {
+ u8 x;
+ u8 y;
+ u16 video_page;
+ u8 video_mode;
+ u8 video_cols;
+ u16 video_ega_bx;
+ u8 video_lines;
+ u8 video_isvga;
+ u16 video_points;
+};
+
+/* describes how the ramdisk will be used in kernel */
+#define ATAG_RAMDISK 0x54410004
+
+struct tag_ramdisk {
+ u32 flags; /* bit 0 = load, bit 1 = prompt */
+ u32 size; /* decompressed ramdisk size in _kilo_ bytes */
+ u32 start; /* starting block of floppy-based RAM disk image */
+};
+
+/*M Tom
+ * this one accidentally used virtual addresses - as such,
+ * it's deprecated.
+ * describes where the compressed ramdisk image lives (virtual address)
+ */
+#define ATAG_INITRD 0x54410005
+
+/* describes where the compressed ramdisk image lives (physical address) */
+#define ATAG_INITRD2 0x54420005
+
+struct tag_initrd {
+ u32 start; //M Tom va of start addr /* physical start address */
+ u32 size; //M Tom unzipped size /* size of compressed ramdisk image in bytes */
+};
+
+/* board serial number. "64 bits should be enough for everybody" */
+#define ATAG_SERIAL 0x54410006
+
+struct tag_serialnr {
+ u32 low;
+ u32 high;
+};
+
+/* board revision */
+#define ATAG_REVISION 0x54410007
+
+struct tag_revision {
+ u32 rev;
+};
+
+/* initial values for vesafb-type framebuffers. see struct screen_info
+ * in include/linux/tty.h
+ */
+#define ATAG_VIDEOLFB 0x54410008
+
+struct tag_videolfb {
+ u16 lfb_width;
+ u16 lfb_height;
+ u16 lfb_depth;
+ u16 lfb_linelength;
+ u32 lfb_base;
+ u32 lfb_size;
+ u8 red_size;
+ u8 red_pos;
+ u8 green_size;
+ u8 green_pos;
+ u8 blue_size;
+ u8 blue_pos;
+ u8 rsvd_size;
+ u8 rsvd_pos;
+};
+
+/* command line: \0 terminated string */
+#define ATAG_CMDLINE 0x54410009
+
+struct tag_cmdline {
+ char cmdline[COMMAND_LINE_SIZE];//M Tom
+};
+
+/* acorn RiscPC specific information */
+/*-d Tom
+#define ATAG_ACORN 0x41000101
+
+struct tag_acorn {
+ u32 memc_control_reg;
+ u32 vram_pages;
+ u8 sounddefault;
+ u8 adfsdrives;
+};
+*/
+#define ATAG_CPE 0x41000101
+struct tag_cpe {
+ u32 memc_control_reg;
+ u32 vram_pages;
+ u8 sounddefault;
+ u8 adfsdrives;
+};
+
+
+/* footbridge memory clock, see arch/arm/mach-footbridge/arch.c */
+#define ATAG_MEMCLK 0x41000402
+
+struct tag_memclk {
+ u32 fmemclk;
+};
+
+struct tag {
+ struct tag_header hdr;
+ union {
+ struct tag_core core;
+ struct tag_mem32 mem;
+ struct tag_videotext videotext;
+ struct tag_ramdisk ramdisk;
+ struct tag_initrd initrd;
+ struct tag_serialnr serialnr;
+ struct tag_revision revision;
+ struct tag_videolfb videolfb;
+ struct tag_cmdline cmdline;
+
+ /*
+ * Andes specific
+ */
+ struct tag_cpe cpe;
+
+ /*
+ * DC21285 specific
+ */
+ struct tag_memclk memclk;
+ } u;
+};
+
+struct tagtable {
+ u32 tag;
+ int (*parse)(const struct tag *);
+};
+
+#define tag_member_present(tag,member) \
+ ((unsigned long)(&((struct tag *)0L)->member + 1) \
+ <= (tag)->hdr.size * 4)
+
+#define tag_next(t) ((struct tag *)((u32 *)(t) + (t)->hdr.size))
+#define tag_size(type) ((sizeof(struct tag_header) + sizeof(struct type)) >> 2)
+
+#define for_each_tag(t,base) \
+ for (t = base; t->hdr.size; t = tag_next(t))
+
+#ifdef __KERNEL__
+
+#define __tag __used __attribute__((__section__(".taglist")))
+#define __tagtable(tag, fn) \
+static struct tagtable __tagtable_##fn __tag = { tag, fn }
+
+/*
+ * Memory map description
+ */
+#ifdef CONFIG_ARCH_LH7A40X
+# define NR_BANKS 16
+#else
+# define NR_BANKS 8
+#endif
+
+struct meminfo {
+ int nr_banks;
+ struct {
+ unsigned long start;
+ unsigned long size;
+ int node;
+ } bank[NR_BANKS];
+};
+
+/*
+ * Early command line parameters.
+ */
+struct early_params {
+ const char *arg;
+ void (*fn)(char **p);
+};
+
+#define __early_param(name,fn) \
+static struct early_params __early_##fn __used \
+__attribute__((__section__("__early_param"))) = { name, fn }
+
+#endif
+#endif
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/shmbuf.h linux-3.4.113/arch/nds32/include/asm/shmbuf.h
--- linux-3.4.113.orig/arch/nds32/include/asm/shmbuf.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/shmbuf.h 2016-12-01 20:59:24.344612443 +0100
@@ -0,0 +1,47 @@
+/*
+ * linux/arch/nds32/include/asm/shmbuf.h
+ * Copyright (C) 2008 Andes Technology Corporation
+ */
+
+#ifndef _ASMNDS32_SHMBUF_H
+#define _ASMNDS32_SHMBUF_H
+
+/*
+ * The shmid64_ds structure for arm architecture.
+ * Note extra padding because this structure is passed back and forth
+ * between kernel and user space.
+ *
+ * Pad space is left for:
+ * - 64-bit time_t to solve y2038 problem
+ * - 2 miscellaneous 32-bit values
+ */
+
+struct shmid64_ds {
+ struct ipc64_perm shm_perm; /* operation perms */
+ size_t shm_segsz; /* size of segment (bytes) */
+ __kernel_time_t shm_atime; /* last attach time */
+ unsigned long __unused1;
+ __kernel_time_t shm_dtime; /* last detach time */
+ unsigned long __unused2;
+ __kernel_time_t shm_ctime; /* last change time */
+ unsigned long __unused3;
+ __kernel_pid_t shm_cpid; /* pid of creator */
+ __kernel_pid_t shm_lpid; /* pid of last operator */
+ unsigned long shm_nattch; /* no. of current attaches */
+ unsigned long __unused4;
+ unsigned long __unused5;
+};
+
+struct shminfo64 {
+ unsigned long shmmax;
+ unsigned long shmmin;
+ unsigned long shmmni;
+ unsigned long shmseg;
+ unsigned long shmall;
+ unsigned long __unused1;
+ unsigned long __unused2;
+ unsigned long __unused3;
+ unsigned long __unused4;
+};
+
+#endif /* _ASMNDS32_SHMBUF_H */
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/shmparam.h linux-3.4.113/arch/nds32/include/asm/shmparam.h
--- linux-3.4.113.orig/arch/nds32/include/asm/shmparam.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/shmparam.h 2016-12-01 20:59:24.344612443 +0100
@@ -0,0 +1,27 @@
+/*
+ * linux/arch/nds32/include/asm/shmparam.h
+ * Copyright (C) 2008 Andes Technology Corporation
+ */
+
+#ifndef _ASMNDS32_SHMPARAM_H
+#define _ASMNDS32_SHMPARAM_H
+
+/*
+ * This should be the size of the virtually indexed cache/ways,
+ * whichever is greater since the cache aliases every size/ways
+ * bytes.
+ */
+/*
+ * Reference ARM architecture, retain the previous code
+ * #define SHMLBA 0x4000
+ * #define REALSHMLBA (CACHE_SET( DCACHE) * CACHE_LINE_SIZE( DCACHE))
+ */
+#define SHMLBA (4 * PAGE_SIZE) /* attach addr a multiple of this */
+#define REALSHMLBA SHMLBA
+
+/*
+ * Enforce SHMLBA in shmat
+ */
+#define __ARCH_FORCE_SHMLBA
+
+#endif /* _ASMNDS32_SHMPARAM_H */
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/sigcontext.h linux-3.4.113/arch/nds32/include/asm/sigcontext.h
--- linux-3.4.113.orig/arch/nds32/include/asm/sigcontext.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/sigcontext.h 2016-12-01 20:59:24.344612443 +0100
@@ -0,0 +1,81 @@
+/*
+ * linux/arch/nds32/include/asm/sigcontext.h
+ * Copyright (C) 2008 Andes Technology Corporation
+ */
+
+#ifndef _ASMNDS32_SIGCONTEXT_H
+#define _ASMNDS32_SIGCONTEXT_H
+
+/*
+ * Signal context structure - contains all info to do with the state
+ * before the signal handler was invoked. Note: only add new entries
+ * to the end of the structure.
+ */
+struct fpu_struct {
+ unsigned long fs_regs[32];
+ unsigned long long fd_regs[16];
+ unsigned long fpcsr;
+};
+
+struct audio_struct {
+ unsigned long auregs[32];
+};
+
+struct zol_struct {
+ unsigned long nds32_lc; /* $LC */
+ unsigned long nds32_le; /* $LE */
+ unsigned long nds32_lb; /* $LB */
+};
+
+struct sigcontext {
+ unsigned long trap_no;
+ unsigned long error_code;
+ unsigned long oldmask;
+ unsigned long nds32_r0;
+ unsigned long nds32_r1;
+ unsigned long nds32_r2;
+ unsigned long nds32_r3;
+ unsigned long nds32_r4;
+ unsigned long nds32_r5;
+ unsigned long nds32_r6;
+ unsigned long nds32_r7;
+ unsigned long nds32_r8;
+ unsigned long nds32_r9;
+ unsigned long nds32_r10;
+ unsigned long nds32_r11;
+ unsigned long nds32_r12;
+ unsigned long nds32_r13;
+ unsigned long nds32_r14;
+ unsigned long nds32_r15;
+ unsigned long nds32_r16;
+ unsigned long nds32_r17;
+ unsigned long nds32_r18;
+ unsigned long nds32_r19;
+ unsigned long nds32_r20;
+ unsigned long nds32_r21;
+ unsigned long nds32_r22;
+ unsigned long nds32_r23;
+ unsigned long nds32_r24;
+ unsigned long nds32_r25;
+ unsigned long nds32_fp; /* $r28 */
+ unsigned long nds32_gp; /* $r29 */
+ unsigned long nds32_lr; /* $r30 */
+ unsigned long nds32_sp; /* $r31 */
+ unsigned long nds32_ipc;
+ unsigned long fault_address;
+#if defined(CONFIG_FPU)
+ unsigned long used_math_flag;
+ /* FPU Registers */
+ struct fpu_struct fpu;
+#endif
+ /* Audio Registers */
+#if defined(CONFIG_AUDIO)
+ unsigned long used_audio_flag;
+ struct audio_struct audio;
+#endif
+#if defined(CONFIG_HWZOL)
+ struct zol_struct zol;
+#endif
+};
+
+#endif
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/siginfo.h linux-3.4.113/arch/nds32/include/asm/siginfo.h
--- linux-3.4.113.orig/arch/nds32/include/asm/siginfo.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/siginfo.h 2016-12-01 20:59:24.344612443 +0100
@@ -0,0 +1,11 @@
+/*
+ * linux/arch/nds32/include/asm/siginfo.h
+ * Copyright (C) 2008 Andes Technology Corporation
+ */
+
+#ifndef _ASMNDS32_SIGINFO_H
+#define _ASMNDS32_SIGINFO_H
+
+#include <asm-generic/siginfo.h>
+
+#endif
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/signal.h linux-3.4.113/arch/nds32/include/asm/signal.h
--- linux-3.4.113.orig/arch/nds32/include/asm/signal.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/signal.h 2016-12-01 20:59:24.344612443 +0100
@@ -0,0 +1,173 @@
+/*
+ * linux/arch/nds32/include/asm/signal.h
+ * Copyright (C) 2008 Andes Technology Corporation
+ */
+
+#ifndef _ASMNDS32_SIGNAL_H
+#define _ASMNDS32_SIGNAL_H
+
+#include <linux/types.h>
+
+/* Avoid too many header ordering problems. */
+struct siginfo;
+
+#ifdef __KERNEL__
+/* Most things should be clean enough to redefine this at will, if care
+ is taken to make libc match. */
+
+#define _NSIG 64
+#define _NSIG_BPW 32
+#define _NSIG_WORDS (_NSIG / _NSIG_BPW)
+
+typedef unsigned long old_sigset_t; /* at least 32 bits */
+
+typedef struct {
+ unsigned long sig[_NSIG_WORDS];
+} sigset_t;
+
+#else
+/* Here we must cater to libcs that poke about in kernel headers. */
+
+#define NSIG 32
+typedef unsigned long sigset_t;
+
+#endif /* __KERNEL__ */
+
+#define SIGHUP 1
+#define SIGINT 2
+#define SIGQUIT 3
+#define SIGILL 4
+#define SIGTRAP 5
+#define SIGABRT 6
+#define SIGIOT 6
+#define SIGBUS 7
+#define SIGFPE 8
+#define SIGKILL 9
+#define SIGUSR1 10
+#define SIGSEGV 11
+#define SIGUSR2 12
+#define SIGPIPE 13
+#define SIGALRM 14
+#define SIGTERM 15
+#define SIGSTKFLT 16
+#define SIGCHLD 17
+#define SIGCONT 18
+#define SIGSTOP 19
+#define SIGTSTP 20
+#define SIGTTIN 21
+#define SIGTTOU 22
+#define SIGURG 23
+#define SIGXCPU 24
+#define SIGXFSZ 25
+#define SIGVTALRM 26
+#define SIGPROF 27
+#define SIGWINCH 28
+#define SIGIO 29
+#define SIGPOLL SIGIO
+/*
+#define SIGLOST 29
+*/
+#define SIGPWR 30
+#define SIGSYS 31
+#define SIGUNUSED 31
+
+/* These should not be considered constants from userland. */
+#define SIGRTMIN 32
+#define SIGRTMAX _NSIG
+
+#define SIGSWI 32
+
+/*
+ * SA_FLAGS values:
+ *
+ * SA_NOCLDSTOP flag to turn off SIGCHLD when children stop.
+ * SA_NOCLDWAIT flag on SIGCHLD to inhibit zombies.
+ * SA_SIGINFO deliver the signal with SIGINFO structs
+ * SA_THIRTYTWO delivers the signal in 32-bit mode, even if the task
+ * is running in 26-bit.
+ * SA_ONSTACK allows alternate signal stacks (see sigaltstack(2)).
+ * SA_RESTART flag to get restarting signals (which were the default long ago)
+ * SA_NODEFER prevents the current signal from being masked in the handler.
+ * SA_RESETHAND clears the handler when the signal is delivered.
+ *
+ * SA_ONESHOT and SA_NOMASK are the historical Linux names for the Single
+ * Unix names RESETHAND and NODEFER respectively.
+ */
+#define SA_NOCLDSTOP 0x00000001
+#define SA_NOCLDWAIT 0x00000002
+#define SA_SIGINFO 0x00000004
+#define SA_THIRTYTWO 0x02000000
+#define SA_RESTORER 0x04000000
+#define SA_ONSTACK 0x08000000
+#define SA_RESTART 0x10000000
+#define SA_NODEFER 0x40000000
+#define SA_RESETHAND 0x80000000
+
+#define SA_NOMASK SA_NODEFER
+#define SA_ONESHOT SA_RESETHAND
+
+
+/*
+ * sigaltstack controls
+ */
+#define SS_ONSTACK 1
+#define SS_DISABLE 2
+
+#define MINSIGSTKSZ 2048
+#define SIGSTKSZ 8192
+
+#ifdef __KERNEL__
+#define SA_IRQNOMASK 0x08000000
+#endif
+
+#include <asm-generic/signal-defs.h>
+
+#ifdef __KERNEL__
+struct old_sigaction {
+ __sighandler_t sa_handler;
+ old_sigset_t sa_mask;
+ unsigned long sa_flags;
+ __sigrestore_t sa_restorer;
+};
+
+struct sigaction {
+ __sighandler_t sa_handler;
+ unsigned long sa_flags;
+ __sigrestore_t sa_restorer;
+ sigset_t sa_mask; /* mask last for extensibility */
+};
+
+struct k_sigaction {
+ struct sigaction sa;
+};
+
+#else
+/* Here we must cater to libcs that poke about in kernel headers. */
+
+struct sigaction {
+ union {
+ __sighandler_t _sa_handler;
+ void (*_sa_sigaction)(int, struct siginfo *, void *);
+ } _u;
+ sigset_t sa_mask;
+ unsigned long sa_flags;
+ void (*sa_restorer)(void);
+};
+
+#define sa_handler _u._sa_handler
+#define sa_sigaction _u._sa_sigaction
+
+#endif /* __KERNEL__ */
+
+typedef struct sigaltstack {
+ void __user *ss_sp;
+ int ss_flags;
+ size_t ss_size;
+} stack_t;
+
+#ifdef __KERNEL__
+#include <asm/sigcontext.h>
+#define ptrace_signal_deliver(regs, cookie) do { } while (0)
+#endif
+
+#endif
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/sizes.h linux-3.4.113/arch/nds32/include/asm/sizes.h
--- linux-3.4.113.orig/arch/nds32/include/asm/sizes.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/sizes.h 2016-12-01 20:59:24.344612443 +0100
@@ -0,0 +1,53 @@
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+/* DO NOT EDIT!! - this file automatically generated
+ * from .s file by awk -f s2h.awk
+ */
+/* Size definitions
+ * Copyright (C) ARM Limited 1998. All rights reserved.
+ * Copyright (C) 2008 Andes Technology Corporation
+ */
+
+#ifndef __sizes_h
+#define __sizes_h 1
+
+/* handy sizes */
+#define SZ_1K 0x00000400
+#define SZ_4K 0x00001000
+#define SZ_8K 0x00002000
+#define SZ_16K 0x00004000
+#define SZ_64K 0x00010000
+#define SZ_128K 0x00020000
+#define SZ_256K 0x00040000
+#define SZ_512K 0x00080000
+
+#define SZ_1M 0x00100000
+#define SZ_2M 0x00200000
+#define SZ_4M 0x00400000
+#define SZ_8M 0x00800000
+#define SZ_16M 0x01000000
+#define SZ_32M 0x02000000
+#define SZ_64M 0x04000000
+#define SZ_128M 0x08000000
+#define SZ_256M 0x10000000
+#define SZ_512M 0x20000000
+
+#define SZ_1G 0x40000000
+#define SZ_2G 0x80000000
+
+#endif
+
+/* END */
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/smp.h linux-3.4.113/arch/nds32/include/asm/smp.h
--- linux-3.4.113.orig/arch/nds32/include/asm/smp.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/smp.h 2016-12-01 20:59:24.344612443 +0100
@@ -0,0 +1,42 @@
+/*
+ * linux/arch/nds32/include/asm/smp.h
+ *
+ * Copyright (C) 2004-2005 ARM Ltd.
+ * Copyright (C) 2008 Andes Technology Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+#ifndef __ASM_NDS32_SMP_H
+#define __ASM_NDS32_SMP_H
+
+#include <linux/threads.h>
+#include <linux/cpumask.h>
+#include <linux/thread_info.h>
+
+#ifndef CONFIG_SMP
+# error "<asm-nds32/smp.h> included in non-SMP build"
+#endif
+
+/*
+ * at the moment, there's not a big penalty for changing CPUs
+ * (the >big< penalty is running SMP in the first place)
+ */
+#define PROC_CHANGE_PENALTY 15
+
+struct seq_file;
+
+/*
+ * Move global data into per-processor storage.
+ */
+extern void smp_store_cpu_info(unsigned int cpuid);
+
+#define raw_smp_processor_id() (unsigned int)(GET_CORE_ID()&CORE_ID_mskCOREID)
+
+extern void smp_init_cpus(void);
+extern void smp_send_timer(void);
+extern void arch_send_call_function_single_ipi(int cpu);
+extern void arch_send_call_function_ipi_mask(const struct cpumask *mask);
+
+#endif /* ifndef __ASM_NDS32_SMP_H */
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/socket.h linux-3.4.113/arch/nds32/include/asm/socket.h
--- linux-3.4.113.orig/arch/nds32/include/asm/socket.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/socket.h 2016-12-01 20:59:24.344612443 +0100
@@ -0,0 +1,11 @@
+/*
+ * linux/arch/nds32/include/asm/socket.h
+ * Copyright (C) 2008 Andes Technology Corporation
+ */
+
+#ifndef _ASMNDS32_SOCKET_H
+#define _ASMNDS32_SOCKET_H
+
+#include <asm-generic/socket.h>
+
+#endif /* _ASMNDS32_SOCKET_H */
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/sockios.h linux-3.4.113/arch/nds32/include/asm/sockios.h
--- linux-3.4.113.orig/arch/nds32/include/asm/sockios.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/sockios.h 2016-12-01 20:59:24.344612443 +0100
@@ -0,0 +1,18 @@
+/*
+ * linux/arch/nds32/include/asm/sockios.h
+ * Copyright (C) 2008 Andes Technology Corporation
+ */
+
+#ifndef __ARCH_NDS32_SOCKIOS_H
+#define __ARCH_NDS32_SOCKIOS_H
+
+/* Socket-level I/O control calls. */
+#define FIOSETOWN 0x8901
+#define SIOCSPGRP 0x8902
+#define FIOGETOWN 0x8903
+#define SIOCGPGRP 0x8904
+#define SIOCATMARK 0x8905
+#define SIOCGSTAMP 0x8906 /* Get stamp */
+#define SIOCGSTAMPNS 0x8907 /* Get stamp (timespec) */
+
+#endif
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/spec-ag101.h linux-3.4.113/arch/nds32/include/asm/spec-ag101.h
--- linux-3.4.113.orig/arch/nds32/include/asm/spec-ag101.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/spec-ag101.h 2016-12-01 20:59:24.344612443 +0100
@@ -0,0 +1,237 @@
+#ifndef __NDS32_AG101_SPECIFICATION_H__
+#define __NDS32_AG101_SPECIFICATION_H__
+
+#define UART0_PA_BASE 0x99600000
+#define UART0_VA_BASE 0xF9960000
+#define UART0_IRQ 7
+#define UART1_PA_BASE 0x98300000
+#define UART1_VA_BASE 0xF9830000
+#define UART1_IRQ 11
+#define CFC_FTCFC010_0_PA_BASE 0x98D00000
+#define CFC_FTCFC010_0_VA_BASE 0xF98D0000
+#define SDC_FTSDC010_0_PA_BASE 0x98e00000
+#define SDC_FTSDC010_0_VA_BASE 0xF98e0000
+#define SDMC_FTSDMC021_PA_BASE 0x90300000
+#define SDMC_FTSDMC021_VA_BASE 0xF9030000
+#define PCIC_FTPCI100_0_PA_BASE 0x90C00000
+#define PCIC_FTPCI100_0_VA_BASE 0xF90C0000
+#define PCIC_FTPCI100_0_VA_LIMIT 0xF90CFFFF
+#define PCIIO_PA_BASE 0x90C01000
+#define PCIIO_VA_BASE 0xFE901000
+#define PCIIO_0_PA_BASE 0x90C01000
+#define PCIIO_0_VA_BASE 0xFE901000
+#define PCIIO_VA_LIMIT 0xFE9FFFFF
+#define AHB_ATFAHBC020S_0_PA_BASE 0x90100000
+#define AHB_ATFAHBC020S_0_VA_BASE 0xF9010000
+
+/* DMAC */
+#define DMAC_FTDMAC020_PA_COUNT 1
+#define DMAC_FTDMAC020_PA_BASE 0x90400000
+#define DMAC_FTDMAC020_PA_LIMIT 0x90400FFF
+#define DMAC_FTDMAC020_PA_SIZE 0x00001000
+#define DMAC_FTDMAC020_0_PA_BASE 0x90400000
+#define DMAC_FTDMAC020_0_PA_LIMIT 0x90400FFF
+#define DMAC_FTDMAC020_0_PA_SIZE 0x00001000
+#define DMAC_FTDMAC020_VA_COUNT 1
+#define DMAC_FTDMAC020_VA_BASE 0xF9040000
+#define DMAC_FTDMAC020_VA_LIMIT 0xF9040FFF
+#define DMAC_FTDMAC020_VA_SIZE 0x00001000
+#define DMAC_FTDMAC020_0_VA_BASE 0xF9040000
+#define DMAC_FTDMAC020_0_VA_LIMIT 0xF9040FFF
+#define DMAC_FTDMAC020_0_VA_SIZE 0x00001000
+
+/* TIMER */
+#define TIMER_FTTMR010_PA_COUNT 1
+#define TIMER_FTTMR010_PA_BASE 0x98400000
+#define TIMER_FTTMR010_PA_LIMIT 0x98400FFF
+#define TIMER_FTTMR010_PA_SIZE 0x00001000
+#define TIMER_FTTMR010_0_PA_BASE 0x98400000
+#define TIMER_FTTMR010_0_PA_LIMIT 0x98400FFF
+#define TIMER_FTTMR010_0_PA_SIZE 0x00001000
+#define TIMER_FTTMR010_VA_COUNT 1
+#define TIMER_FTTMR010_VA_BASE 0xF9840000
+#define TIMER_FTTMR010_VA_LIMIT 0xF9840FFF
+#define TIMER_FTTMR010_VA_SIZE 0x00001000
+#define TIMER_FTTMR010_0_VA_BASE 0xF9840000
+#define TIMER_FTTMR010_0_VA_LIMIT 0xF9840FFF
+#define TIMER_FTTMR010_0_VA_SIZE 0x00001000
+
+/* RTC */
+#define RTC_FTRTC010_PA_COUNT 1
+#define RTC_FTRTC010_PA_BASE 0x98600000
+#define RTC_FTRTC010_PA_LIMIT 0x98600FFF
+#define RTC_FTRTC010_PA_SIZE 0x00001000
+#define RTC_FTRTC010_0_PA_BASE 0x98600000
+#define RTC_FTRTC010_0_PA_LIMIT 0x98600FFF
+#define RTC_FTRTC010_0_PA_SIZE 0x00001000
+#define RTC_FTRTC010_VA_COUNT 1
+#define RTC_FTRTC010_VA_BASE 0xF9860000
+#define RTC_FTRTC010_VA_LIMIT 0xF9860FFF
+#define RTC_FTRTC010_VA_SIZE 0x00001000
+#define RTC_FTRTC010_0_VA_BASE 0xF9860000
+#define RTC_FTRTC010_0_VA_LIMIT 0xF9860FFF
+#define RTC_FTRTC010_0_VA_SIZE 0x00001000
+
+/* WDT */
+#define WDT_FTWDT010_PA_COUNT 1
+#define WDT_FTWDT010_PA_BASE 0x98500000
+#define WDT_FTWDT010_PA_LIMIT 0x98500FFF
+#define WDT_FTWDT010_PA_SIZE 0x00001000
+#define WDT_FTWDT010_0_PA_BASE 0x98500000
+#define WDT_FTWDT010_0_PA_LIMIT 0x98500FFF
+#define WDT_FTWDT010_0_PA_SIZE 0x00001000
+#define WDT_FTWDT010_VA_COUNT 1
+#define WDT_FTWDT010_VA_BASE 0xF9850000
+#define WDT_FTWDT010_VA_LIMIT 0xF9850FFF
+#define WDT_FTWDT010_VA_SIZE 0x00001000
+#define WDT_FTWDT010_0_VA_BASE 0xF9850000
+#define WDT_FTWDT010_0_VA_LIMIT 0xF9850FFF
+#define WDT_FTWDT010_0_VA_SIZE 0x00001000
+
+/* GPIO */
+#define GPIO_FTGPIO010_PA_COUNT 1
+#define GPIO_FTGPIO010_PA_BASE 0x98700000
+#define GPIO_FTGPIO010_PA_LIMIT 0x98700FFF
+#define GPIO_FTGPIO010_PA_SIZE 0x00001000
+#define GPIO_FTGPIO010_0_PA_BASE 0x98700000
+#define GPIO_FTGPIO010_0_PA_LIMIT 0x98700FFF
+#define GPIO_FTGPIO010_0_PA_SIZE 0x00001000
+#define GPIO_FTGPIO010_VA_COUNT 1
+#define GPIO_FTGPIO010_VA_BASE 0xF9870000
+#define GPIO_FTGPIO010_VA_LIMIT 0xF9870FFF
+#define GPIO_FTGPIO010_VA_SIZE 0x00001000
+#define GPIO_FTGPIO010_0_VA_BASE 0xF9870000
+#define GPIO_FTGPIO010_0_VA_LIMIT 0xF9870FFF
+#define GPIO_FTGPIO010_0_VA_SIZE 0x00001000
+
+
+/* USB OTG */
+#define USB_FOTG2XX_0_PA_COUNT 1
+#define USB_FOTG2XX_0_PA_BASE 0x90B00000
+#define USB_FOTG2XX_0_PA_LIMIT 0x90B00FFF
+#define USB_FOTG2XX_0_PA_SIZE 0x00001000
+#define USB_FOTG2XX_0_VA_BASE 0xF90B0000
+#define USB_FOTG2XX_0_VA_LIMIT 0xF90B0FFF
+#define USB_FOTG2XX_0_VA_SIZE 0x00001000
+#define USB_FOTG2XX_0_IRQ 26
+#define USB_FOTG2XX_PA_COUNT 1
+#define USB_FOTG2XX_PA_BASE 0x90B00000
+#define USB_FOTG2XX_PA_LIMIT 0x90B00FFF
+#define USB_FOTG2XX_PA_SIZE 0x00001000
+#define USB_FOTG2XX_VA_BASE 0xF90B0000
+#define USB_FOTG2XX_VA_LIMIT 0xF90B0FFF
+#define USB_FOTG2XX_VA_SIZE 0x00001000
+#define USB_FOTG2XX_IRQ 26
+#define USB_FOTG2XX_IRQ_COUNT 1
+
+/* SSP */
+#define SSP_FTSSP010_PA_COUNT 1
+#define SSP_FTSSP010_PA_BASE 0x99400000
+#define SSP_FTSSP010_PA_LIMIT 0x99400FFF
+#define SSP_FTSSP010_PA_SIZE 0x00001000
+#define SSP_FTSSP010_0_PA_BASE 0x99400000
+#define SSP_FTSSP010_0_PA_LIMIT 0x99400FFF
+#define SSP_FTSSP010_0_PA_SIZE 0x00001000
+#define SSP_FTSSP010_VA_COUNT 1
+#define SSP_FTSSP010_VA_BASE 0xF9940000
+#define SSP_FTSSP010_VA_LIMIT 0xF9940FFF
+#define SSP_FTSSP010_VA_SIZE 0x00001000
+#define SSP_FTSSP010_0_VA_BASE 0xF9940000
+#define SSP_FTSSP010_0_VA_LIMIT 0xF9940FFF
+#define SSP_FTSSP010_0_VA_SIZE 0x00001000
+
+/* APBBRG */
+#define APBBRG_FTAPBBRG020S_PA_COUNT 1
+#define APBBRG_FTAPBBRG020S_PA_BASE 0x90500000
+#define APBBRG_FTAPBBRG020S_PA_LIMIT 0x90500FFF
+#define APBBRG_FTAPBBRG020S_PA_SIZE 0x00001000
+#define APBBRG_FTAPBBRG020S_0_PA_BASE 0x90500000
+#define APBBRG_FTAPBBRG020S_0_PA_LIMIT 0x90500FFF
+#define APBBRG_FTAPBBRG020S_0_PA_SIZE 0x00001000
+#define APBBRG_FTAPBBRG020S_1_PA_BASE 0x90E00000
+#define APBBRG_FTAPBBRG020S_1_PA_LIMIT 0x90E00FFF
+#define APBBRG_FTAPBBRG020S_1_PA_SIZE 0x00001000
+#define APBBRG_FTAPBBRG020S_VA_COUNT 1
+#define APBBRG_FTAPBBRG020S_VA_BASE 0xF9050000
+#define APBBRG_FTAPBBRG020S_VA_LIMIT 0xF9050FFF
+#define APBBRG_FTAPBBRG020S_VA_SIZE 0x00001000
+#define APBBRG_FTAPBBRG020S_0_VA_BASE 0xF9050000
+#define APBBRG_FTAPBBRG020S_0_VA_LIMIT 0xF9050FFF
+#define APBBRG_FTAPBBRG020S_0_VA_SIZE 0x00001000
+#define APBBRG_FTAPBBRG020S_1_VA_BASE 0xF90E0000
+#define APBBRG_FTAPBBRG020S_1_VA_LIMIT 0xF90E0FFF
+#define APBBRG_FTAPBBRG020S_1_VA_SIZE 0x00001000
+
+/* I2C */
+#define I2C_FTI2C010_PA_COUNT 1
+#define I2C_FTI2C010_PA_BASE 0x98A00000
+#define I2C_FTI2C010_PA_LIMIT 0x98A00FFF
+#define I2C_FTI2C010_PA_SIZE 0x00001000
+#define I2C_FTI2C010_0_PA_BASE 0x98A00000
+#define I2C_FTI2C010_0_PA_LIMIT 0x98A00FFF
+#define I2C_FTI2C010_0_PA_SIZE 0x00001000
+#define I2C_FTI2C010_VA_COUNT 1
+#define I2C_FTI2C010_VA_BASE 0xF98A0000
+#define I2C_FTI2C010_VA_LIMIT 0xF98A0FFF
+#define I2C_FTI2C010_VA_SIZE 0x00001000
+#define I2C_FTI2C010_0_VA_BASE 0xF98A0000
+#define I2C_FTI2C010_0_VA_LIMIT 0xF98A0FFF
+#define I2C_FTI2C010_0_VA_SIZE 0x00001000
+
+/* L2CC */
+#define L2CC_PA_BASE 0x90F00000 /* reserved */
+#define L2CC_VA_BASE 0xF90F0000 /* FIXME */
+
+#define LED_PA_COUNT 1
+#define LED_PA_BASE 0x902FF000
+#define LED_PA_LIMIT 0x90200FFF
+#define LED_PA_SIZE 0x00001000
+#define LED_0_PA_BASE 0x90200000
+#define LED_0_PA_LIMIT 0x90200FFF
+#define LED_0_PA_SIZE 0x00001000
+#define LED_VA_COUNT 1
+#define LED_VA_BASE 0xF9020000
+#define LED_VA_LIMIT 0xF9020000
+#define LED_VA_SIZE 0x00001000
+#define LED_0_VA_BASE 0xF9020000
+#define LED_0_VA_LIMIT 0xF9020000
+#define LED_0_VA_SIZE 0x00001000
+
+/* MAC */
+#define MAC_FTMAC100_PA_COUNT 1
+#define MAC_FTMAC100_PA_BASE 0x90900000
+#define MAC_FTMAC100_PA_LIMIT 0x90900FFF
+#define MAC_FTMAC100_PA_SIZE 0x00001000
+#define MAC_FTMAC100_0_PA_BASE 0x90900000
+#define MAC_FTMAC100_0_PA_LIMIT 0x90900FFF
+#define MAC_FTMAC100_0_PA_SIZE 0x00001000
+#define MAC_FTMAC100_1_PA_BASE 0x92000000
+#define MAC_FTMAC100_1_PA_LIMIT 0x92000FFF
+#define MAC_FTMAC100_1_PA_SIZE 0x00001000
+#define MAC_FTMAC100_VA_COUNT 1
+#define MAC_FTMAC100_VA_BASE 0xF9090000
+#define MAC_FTMAC100_VA_LIMIT 0xF9090FFF
+#define MAC_FTMAC100_VA_SIZE 0x00001000
+#define MAC_FTMAC100_0_VA_BASE 0xF9090000
+#define MAC_FTMAC100_0_VA_LIMIT 0xF9090FFF
+#define MAC_FTMAC100_0_VA_SIZE 0x00001000
+#define MAC_FTMAC100_1_VA_BASE 0xF9200000
+#define MAC_FTMAC100_1_VA_LIMIT 0xF9200FFF
+#define MAC_FTMAC100_1_VA_SIZE 0x00001000
+
+/* LCD */
+#define LCD_FTLCDC100_PA_COUNT 1
+#define LCD_FTLCDC100_PA_BASE 0x90600000
+#define LCD_FTLCDC100_PA_LIMIT 0x90600FFF
+#define LCD_FTLCDC100_PA_SIZE 0x00001000
+#define LCD_FTLCDC100_0_PA_BASE 0x90600000
+#define LCD_FTLCDC100_0_PA_LIMIT 0x90600FFF
+#define LCD_FTLCDC100_0_PA_SIZE 0x00001000
+#define LCD_FTLCDC100_VA_COUNT 1
+#define LCD_FTLCDC100_VA_BASE 0xF9060000
+#define LCD_FTLCDC100_VA_LIMIT 0xF9060FFF
+#define LCD_FTLCDC100_VA_SIZE 0x00001000
+#define LCD_FTLCDC100_0_VA_BASE 0xF9060000
+#define LCD_FTLCDC100_0_VA_LIMIT 0xF9060FFF
+#define LCD_FTLCDC100_0_VA_SIZE 0x00001000
+#endif
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/spec-ag102.h linux-3.4.113/arch/nds32/include/asm/spec-ag102.h
--- linux-3.4.113.orig/arch/nds32/include/asm/spec-ag102.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/spec-ag102.h 2016-12-01 20:59:24.344612443 +0100
@@ -0,0 +1,167 @@
+#ifndef __NDS32_AG102_SPECIFICATION_H__
+#define __NDS32_AG102_SPECIFICATION_H__
+
+#define UART0_PA_BASE 0x94200000
+#define UART0_VA_BASE 0xF9420000
+#define UART0_IRQ 10
+#define UART1_PA_BASE 0x94600000
+#define UART1_VA_BASE 0xF9460000
+#define UART1_IRQ 11
+#define AMIC_PA_BASE 0x90F00000
+#define AMIC_VA_BASE 0xF90F0000
+#define GMAC_PA_BASE 0x90B00000
+#define GMAC_VA_BASE 0xF90B0000
+#define APBBR_PA_BASE 0x90D00000
+#define APBBR_VA_BASE 0xF90D0000
+#define GMAC_IRQ 25
+#define TIMER_PA_BASE 0x94900000
+#define TIMER_VA_BASE 0xF9490000
+#define L2CC_PA_BASE 0x90900000
+#define L2CC_VA_BASE 0xF9090000
+#define CFC_FTCFC010_0_PA_BASE 0x94000000
+#define CFC_FTCFC010_0_VA_BASE 0xF9400000
+#define SDC_FTSDC010_0_PA_BASE 0x94400000
+#define SDC_FTSDC010_0_VA_BASE 0xF9440000
+#define PCU_PA_BASE 0x94800000
+#define PCU_VA_BASE 0xF9480000
+#define PCIC_FTPCI100_0_PA_BASE 0x90000000
+#define PCIC_FTPCI100_0_VA_BASE 0xF9000000
+#define PCIC_FTPCI100_0_VA_LIMIT 0xF9000FFF
+#define PCIIO_PA_BASE 0x90001000
+#define PCIIO_VA_BASE 0xF8901000
+#define PCIIO_0_PA_BASE 0x90001000
+#define PCIIO_0_VA_BASE 0xF8901000
+#define PCIIO_VA_LIMIT 0xF89FFFFF
+#define LPC_IO_PA_BASE 0x90100000
+#define LPC_IO_VA_BASE 0xF9010000
+#define LPC_REG_PA_BASE 0x90200000
+#define LPC_REG_VA_BASE 0xF9020000
+#define LPC_IRQ 29
+#define GPU_PA_BASE 0x90A00000
+#define GPU_VA_BASE 0xFEA00000
+#define IDE_FTIDE020_VA_BASE 0xF9070000
+#define IDE_FTIDE020_PA_BASE 0x90700000
+#define IDE_FTIDE020_IRQ 1
+#define USB_FOTG2XX_0_PA_BASE 0x90800000
+#define USB_FOTG2XX_0_VA_BASE 0xF9080000
+#define USB_FOTG2XX_0_IRQ 26
+#define DDR2C_PA_BASE 0x90500000
+#define DDR2C_VA_BASE 0xF9050000
+#define GPIO_VA_BASE 0xF94C0000
+#define GPIO_PA_BASE 0x94C00000
+
+#define PLATFORM_LPC_IRQ_BASE 180
+#define PLATFORM_LPC_IRQ_TOTALCOUNT 22
+
+/* DMAC */
+#define DMAC_FTDMAC020_PA_COUNT 1
+#define DMAC_FTDMAC020_PA_BASE 0x90600000
+#define DMAC_FTDMAC020_PA_LIMIT 0x90600FFF
+#define DMAC_FTDMAC020_PA_SIZE 0x00001000
+#define DMAC_FTDMAC020_0_PA_BASE 0x90600000
+#define DMAC_FTDMAC020_0_PA_LIMIT 0x90600FFF
+#define DMAC_FTDMAC020_0_PA_SIZE 0x00001000
+#define DMAC_FTDMAC020_VA_COUNT 1
+#define DMAC_FTDMAC020_VA_BASE 0xF9060000
+#define DMAC_FTDMAC020_VA_LIMIT 0xF9060FFF
+#define DMAC_FTDMAC020_VA_SIZE 0x00001000
+#define DMAC_FTDMAC020_0_VA_BASE 0xF9060000
+#define DMAC_FTDMAC020_0_VA_LIMIT 0xF9060FFF
+#define DMAC_FTDMAC020_0_VA_SIZE 0x00001000
+
+/* TIMER */
+#define TIMER_FTTMR010_PA_COUNT 1
+#define TIMER_FTTMR010_PA_BASE 0x94900000
+#define TIMER_FTTMR010_PA_LIMIT 0x94900FFF
+#define TIMER_FTTMR010_PA_SIZE 0x00001000
+#define TIMER_FTTMR010_0_PA_BASE 0x94900000
+#define TIMER_FTTMR010_0_PA_LIMIT 0x94900FFF
+#define TIMER_FTTMR010_0_PA_SIZE 0x00001000
+#define TIMER_FTTMR010_VA_COUNT 1
+#define TIMER_FTTMR010_VA_BASE 0xF9490000
+#define TIMER_FTTMR010_VA_LIMIT 0xF9490FFF
+#define TIMER_FTTMR010_VA_SIZE 0x00001000
+#define TIMER_FTTMR010_0_VA_BASE 0xF9490000
+#define TIMER_FTTMR010_0_VA_LIMIT 0xF9490FFF
+#define TIMER_FTTMR010_0_VA_SIZE 0x00001000
+
+/* WDT */
+#define WDT_FTWDT010_PA_COUNT 1
+#define WDT_FTWDT010_PA_BASE 0x94A00000
+#define WDT_FTWDT010_PA_LIMIT 0x94A00FFF
+#define WDT_FTWDT010_PA_SIZE 0x00001000
+#define WDT_FTWDT010_0_PA_BASE 0x94A00000
+#define WDT_FTWDT010_0_PA_LIMIT 0x94A00FFF
+#define WDT_FTWDT010_0_PA_SIZE 0x00001000
+#define WDT_FTWDT010_VA_COUNT 1
+#define WDT_FTWDT010_VA_BASE 0xF94A0000
+#define WDT_FTWDT010_VA_LIMIT 0xF94A0FFF
+#define WDT_FTWDT010_VA_SIZE 0x00001000
+#define WDT_FTWDT010_0_VA_BASE 0xF94A0000
+#define WDT_FTWDT010_0_VA_LIMIT 0xF94A0FFF
+#define WDT_FTWDT010_0_VA_SIZE 0x00001000
+
+/* RTC */
+#define RTC_FTRTC010_PA_COUNT 1
+#define RTC_FTRTC010_PA_BASE 0x94B00000
+#define RTC_FTRTC010_PA_LIMIT 0x94B00FFF
+#define RTC_FTRTC010_PA_SIZE 0x00001000
+#define RTC_FTRTC010_0_PA_BASE 0x94B00000
+#define RTC_FTRTC010_0_PA_LIMIT 0x94B00FFF
+#define RTC_FTRTC010_0_PA_SIZE 0x00001000
+#define RTC_FTRTC010_VA_COUNT 1
+#define RTC_FTRTC010_VA_BASE 0xF94B0000
+#define RTC_FTRTC010_VA_LIMIT 0xF94B0FFF
+#define RTC_FTRTC010_VA_SIZE 0x00001000
+#define RTC_FTRTC010_0_VA_BASE 0xF94B0000
+#define RTC_FTRTC010_0_VA_LIMIT 0xF94B0FFF
+#define RTC_FTRTC010_0_VA_SIZE 0x00001000
+
+/* GPIO */
+#define GPIO_FTGPIO010_PA_COUNT 1
+#define GPIO_FTGPIO010_PA_BASE 0x94C00000
+#define GPIO_FTGPIO010_PA_LIMIT 0x94C00FFF
+#define GPIO_FTGPIO010_PA_SIZE 0x00001000
+#define GPIO_FTGPIO010_0_PA_BASE 0x94C00000
+#define GPIO_FTGPIO010_0_PA_LIMIT 0x94C00FFF
+#define GPIO_FTGPIO010_0_PA_SIZE 0x00001000
+#define GPIO_FTGPIO010_VA_COUNT 1
+#define GPIO_FTGPIO010_VA_BASE 0xF94C0000
+#define GPIO_FTGPIO010_VA_LIMIT 0xF94C0FFF
+#define GPIO_FTGPIO010_VA_SIZE 0x00001000
+#define GPIO_FTGPIO010_0_VA_BASE 0xF94C0000
+#define GPIO_FTGPIO010_0_VA_LIMIT 0xF94C0FFF
+#define GPIO_FTGPIO010_0_VA_SIZE 0x00001000
+
+/* SSP */
+#define SSP_FTSSP010_PA_BASE 0x94500000
+#define SSP_FTSSP010_0_PA_BASE 0x94500000
+#define SSP_FTSSP010_VA_BASE 0xF9450000
+#define SSP_FTSSP010_0_VA_BASE 0xF9450000
+
+/* SPI */
+#define SPI_FTSSP010_PA_BASE 0x94100000
+#define SPI_FTSSP010_0_PA_BASE 0x94100000
+#define SPI_FTSSP010_VA_BASE 0xF9410000
+#define SPI_FTSSP010_0_VA_BASE 0xF9410000
+
+/* AHB Controller */
+#define AHB_ATFAHBC020S_0_PA_BASE 0x90C00000
+#define AHB_ATFAHBC020S_0_VA_BASE 0xF90C0000
+
+#define I2C_FTI2C010_PA_COUNT 1
+#define I2C_FTI2C010_PA_BASE 0x94E00000
+#define I2C_FTI2C010_PA_LIMIT 0x94E00FFF
+#define I2C_FTI2C010_PA_SIZE 0x00001000
+#define I2C_FTI2C010_0_PA_BASE 0x94E00000
+#define I2C_FTI2C010_0_PA_LIMIT 0x94E00FFF
+#define I2C_FTI2C010_0_PA_SIZE 0x00001000
+#define I2C_FTI2C010_VA_COUNT 1
+#define I2C_FTI2C010_VA_BASE 0xF94E0000
+#define I2C_FTI2C010_VA_LIMIT 0xF94E0FFF
+#define I2C_FTI2C010_VA_SIZE 0x00001000
+#define I2C_FTI2C010_0_VA_BASE 0xF94E0000
+#define I2C_FTI2C010_0_VA_LIMIT 0xF94E0FFF
+#define I2C_FTI2C010_0_VA_SIZE 0x00001000
+
+#endif
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/spec.h linux-3.4.113/arch/nds32/include/asm/spec.h
--- linux-3.4.113.orig/arch/nds32/include/asm/spec.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/spec.h 2016-12-01 20:59:24.348612597 +0100
@@ -0,0 +1,510 @@
+/*
+ * linux/arch/nds32/include/asm/spec.h
+ *
+ * AG101 Platform Independent Specification
+ *
+ * Copyright (C) 2005 Faraday Corp. (http://www.faraday-tech.com)
+ * Copyright (C) 2008 Andes Technology Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * ChangeLog
+ *
+ * Luke Lee 09/14/2005 Created.
+ * 09/15/2005 Completed.
+ */
+
+#ifndef __FARADAY_PLATFORM_INDEPENDENT_SPECIFICATION__
+#define __FARADAY_PLATFORM_INDEPENDENT_SPECIFICATION__
+
+#include <asm/glue.h>
+#ifdef CONFIG_PLAT_AG102
+#include <asm/spec-ag102.h>
+#else
+#include <asm/spec-ag101.h>
+#endif
+
+/*
+ * Platform dependent specification
+ */
+#define PLATFORM_NAME "Andes AG101"
+
+/*
+ * Component counts
+ */
+
+/* INTC */
+#define INTC_COUNT 2
+#define INTC_FTINTC010_COUNT 2
+/* TIMER */
+#define TIMER_COUNT 1
+#define TIMER_FTTMR010_COUNT 1
+/* SSP */
+#define SSP_COUNT 1
+#define SSP_FTSSP010_COUNT 1
+/* PMU */
+#define PMU_COUNT 1
+#define PMU_FTPMU010_COUNT 1
+/* MAC */
+#define MAC_COUNT 1
+#define MAC_FTMAC100_COUNT 1
+
+/* SDC */
+#define SDC_COUNT 1
+#define SDC_FTSDC010_COUNT 1
+/* AHBDMA */
+#define AHBDMA_COUNT 1
+/* APBDMA */
+#define APBDMA_COUNT 1
+/* RTC */
+#define RTC_COUNT 1
+#define RTC_FTRTC010_COUNT 1
+/* WDT */
+#define WDT_COUNT 1
+#define WDT_FTWDT010_COUNT 1
+/* GPIO */
+#define GPIO_COUNT 1
+#define GPIO_FTGPIO010_COUNT 1
+/* CFC */
+#define CFC_COUNT 1
+#define CFC_FTCFC010_COUNT 1
+/* LCD */
+#define LCD_COUNT 1
+#define LCD_FTLCDC100_COUNT 1
+/* I2C */
+#define I2C_COUNT 1
+#define I2C_FTI2C010_COUNT 1
+/* USB */
+#define USB_COUNT 3
+#define USB_FOTG2XX_COUNT 1
+#define USB_FUSBH200_COUNT 1
+#define USB_FUSB220_COUNT 1
+/* DMAC */
+#define DMAC_COUNT 1
+#define DMAC_FTDMAC020_COUNT 1
+/* KMI */
+#define KMI_COUNT 2
+#define KMI_FTKBC010_COUNT 2
+/* PCI */
+#define PCI_COUNT 1
+/* PCIMEM */
+#define PCIMEM_COUNT 1
+/* PCIIO */
+#define PCIIO_COUNT 1
+/* PCIC */
+#define PCIC_COUNT 1
+#define PCIC_FTPCI100_COUNT 1
+
+/*
+ * Hierarchial Component IDs
+ */
+
+#define PLATFORM_AHBDMA_DMAC_FTDMAC020_ID 0
+#define PLATFORM_APBDMA_APBBRG_FTAPBBRG020S_ID 0
+
+/*
+ * Number of interrupts
+ */
+
+#define PLATFORM_IRQ_TOTALCOUNT 32
+#define PLATFORM_AHBDMA_IRQ_TOTALCOUNT 8
+#define PLATFORM_APBDMA_IRQ_TOTALCOUNT 4
+
+#define PLATFORM_IRQ_BASE 0
+#define PLATFORM_AHBDMA_IRQ_BASE 64
+#define PLATFORM_APBDMA_IRQ_BASE 72
+#define PLATFORM_PCI_IRQ_BASE 176
+#define PLATFORM_INTERRUPTS 202
+
+/*
+ * IRQ trigger level and trigger mode
+ */
+
+#define PLATFORM_IRQ_TRIGGER_MODE 0x000EC880
+#define PLATFORM_IRQ_TRIGGER_LEVEL 0x10000000
+#define PLATFORM_AHBDMA_IRQ_TRIGGER_MODE 0x00000000
+#define PLATFORM_AHBDMA_IRQ_TRIGGER_LEVEL 0xFFFFFFFF
+#define PLATFORM_APBDMA_IRQ_TRIGGER_MODE 0x00000000
+#define PLATFORM_APBDMA_IRQ_TRIGGER_LEVEL 0xFFFFFFFF
+
+/*
+ * Interrupt numbers of Hierarchical Architecture
+ */
+
+/* AHBDMA */
+#define PLATFORM_AHBDMA_IRQ 21
+
+/* APBDMA */
+#define PLATFORM_APBDMA_IRQ 24
+
+/* PCI */
+#ifdef CONFIG_XC5_PCI
+#define PLATFORM_PCI_IRQ 10
+#else
+#define PLATFORM_PCI_IRQ 28
+#endif
+
+
+/*
+ * Interrrupt numbers
+ */
+
+/* TIMER */
+#define TIMER_FTTMR010_IRQ_COUNT 3
+#define TIMER_FTTMR010_IRQ0 19
+#define TIMER_FTTMR010_0_IRQ0 19
+#define TIMER_FTTMR010_IRQ1 14
+#define TIMER_FTTMR010_0_IRQ1 14
+#define TIMER_FTTMR010_IRQ2 15
+#define TIMER_FTTMR010_0_IRQ2 15
+
+/* SSP */
+#define SSP_FTSSP010_IRQ_COUNT 1
+#define SSP_FTSSP010_IRQ 6
+#define SSP_FTSSP010_0_IRQ 6
+
+/* MAC */
+#define MAC_FTMAC100_IRQ_COUNT 1
+#define MAC_FTMAC100_IRQ 25
+#define MAC_FTMAC100_0_IRQ 25
+#define MAC_FTMAC100_1_IRQ 133
+
+/* SDC */
+#define SDC_FTSDC010_IRQ_COUNT 1
+#define SDC_FTSDC010_IRQ 5
+#define SDC_FTSDC010_0_IRQ 5
+
+/* RTC */
+#define RTC_FTRTC010_IRQ_COUNT 2
+#define RTC_FTRTC010_IRQ0 17
+#define RTC_FTRTC010_0_IRQ0 17
+#define RTC_FTRTC010_IRQ1 18
+#define RTC_FTRTC010_0_IRQ1 18
+
+/* WDT */
+#define WDT_FTWDT010_IRQ_COUNT 1
+#define WDT_FTWDT010_IRQ 16
+#define WDT_FTWDT010_0_IRQ 16
+
+/* GPIO */
+#define GPIO_FTGPIO010_IRQ_COUNT 1
+#define GPIO_FTGPIO010_IRQ 13
+#define GPIO_FTGPIO010_0_IRQ 13
+
+/* CFC */
+#define CFC_FTCFC010_IRQ_COUNT 2
+#define CFC_FTCFC010_IRQ0 0
+#define CFC_FTCFC010_0_IRQ0 0
+#define CFC_FTCFC010_IRQ1 1
+#define CFC_FTCFC010_0_IRQ1 1
+
+/* LCD */
+#define LCD_FTLCDC100_IRQ_COUNT 1
+#define LCD_FTLCDC100_IRQ 20
+#define LCD_FTLCDC100_0_IRQ 20
+
+/* I2C */
+#define I2C_FTI2C010_IRQ_COUNT 1
+#define I2C_FTI2C010_IRQ 3
+#define I2C_FTI2C010_0_IRQ 3
+
+/* USB */
+#define USB_FUSBH200_IRQ_COUNT 1
+#define USB_FUSBH200_IRQ 29
+#define USB_FUSBH200_0_IRQ 29
+#define USB_FUSB220_IRQ_COUNT 1
+#define USB_FUSB220_IRQ 26
+#define USB_FUSB220_0_IRQ 26
+
+/* DMAC */
+#define DMAC_FTDMAC020_IRQ_COUNT 8
+#define DMAC_FTDMAC020_IRQ0 64
+#define DMAC_FTDMAC020_0_IRQ0 64
+#define DMAC_FTDMAC020_IRQ1 65
+#define DMAC_FTDMAC020_0_IRQ1 65
+#define DMAC_FTDMAC020_IRQ2 66
+#define DMAC_FTDMAC020_0_IRQ2 66
+#define DMAC_FTDMAC020_IRQ3 67
+#define DMAC_FTDMAC020_0_IRQ3 67
+#define DMAC_FTDMAC020_IRQ4 68
+#define DMAC_FTDMAC020_0_IRQ4 68
+#define DMAC_FTDMAC020_IRQ5 69
+#define DMAC_FTDMAC020_0_IRQ5 69
+#define DMAC_FTDMAC020_IRQ6 70
+#define DMAC_FTDMAC020_0_IRQ6 70
+#define DMAC_FTDMAC020_IRQ7 71
+#define DMAC_FTDMAC020_0_IRQ7 71
+
+/* APBBRG */
+#define APBBRG_FTAPBBRG020S_IRQ_COUNT 4
+#define APBBRG_FTAPBBRG020S_IRQ0 72
+#define APBBRG_FTAPBBRG020S_0_IRQ0 72
+#define APBBRG_FTAPBBRG020S_IRQ1 73
+#define APBBRG_FTAPBBRG020S_0_IRQ1 73
+#define APBBRG_FTAPBBRG020S_IRQ2 74
+#define APBBRG_FTAPBBRG020S_0_IRQ2 74
+#define APBBRG_FTAPBBRG020S_IRQ3 75
+#define APBBRG_FTAPBBRG020S_0_IRQ3 75
+#define APBBRG_FTAPBBRG020S_1_IRQ0 172
+#define APBBRG_FTAPBBRG020S_1_IRQ1 173
+#define APBBRG_FTAPBBRG020S_1_IRQ2 174
+#define APBBRG_FTAPBBRG020S_1_IRQ3 175
+
+/* KMI */
+#define KMI_FTKBC010_IRQ_COUNT 1
+#define KMI_FTKBC010_IRQ 30
+#define KMI_FTKBC010_0_IRQ 30
+#define KMI_FTKBC010_1_IRQ 31
+
+/* PCIC */
+#define PCIC_FTPCI100_IRQ_COUNT 4
+#define PCIC_FTPCI100_IRQ0 176
+#define PCIC_FTPCI100_0_IRQ0 176
+#define PCIC_FTPCI100_IRQ1 177
+#define PCIC_FTPCI100_0_IRQ1 177
+#define PCIC_FTPCI100_IRQ2 178
+#define PCIC_FTPCI100_0_IRQ2 178
+#define PCIC_FTPCI100_IRQ3 179
+#define PCIC_FTPCI100_0_IRQ3 179
+
+/*
+ * Base addresses
+ */
+
+/* CPU */
+#define CPU_MEM_PA_BASE CONFIG_MEMORY_START
+
+
+/* INTC */
+#define INTC_FTINTC010_PA_COUNT 1
+#define INTC_FTINTC010_PA_BASE 0x98800000
+#define INTC_FTINTC010_PA_LIMIT 0x98800FFF
+#define INTC_FTINTC010_PA_SIZE 0x00001000
+#define INTC_FTINTC010_0_PA_BASE 0x98800000
+#define INTC_FTINTC010_0_PA_LIMIT 0x98800FFF
+#define INTC_FTINTC010_0_PA_SIZE 0x00001000
+#define INTC_FTINTC010_1_PA_BASE 0xB0800000
+#define INTC_FTINTC010_1_PA_LIMIT 0xB0800FFF
+#define INTC_FTINTC010_1_PA_SIZE 0x00001000
+#define INTC_FTINTC010_VA_COUNT 1
+#define INTC_FTINTC010_VA_BASE 0xF9880000
+#define INTC_FTINTC010_VA_LIMIT 0xF9880FFF
+#define INTC_FTINTC010_VA_SIZE 0x00001000
+#define INTC_FTINTC010_0_VA_BASE 0xF9880000
+#define INTC_FTINTC010_0_VA_LIMIT 0xF9880FFF
+#define INTC_FTINTC010_0_VA_SIZE 0x00001000
+#define INTC_FTINTC010_1_VA_BASE 0xFB080000
+#define INTC_FTINTC010_1_VA_LIMIT 0xFB080FFF
+#define INTC_FTINTC010_1_VA_SIZE 0x00001000
+
+/* PMU */
+#define PMU_FTPMU010_PA_COUNT 1
+#define PMU_FTPMU010_PA_BASE 0x98100000
+#define PMU_FTPMU010_PA_LIMIT 0x98100FFF
+#define PMU_FTPMU010_PA_SIZE 0x00001000
+#define PMU_FTPMU010_0_PA_BASE 0x98100000
+#define PMU_FTPMU010_0_PA_LIMIT 0x98100FFF
+#define PMU_FTPMU010_0_PA_SIZE 0x00001000
+#define PMU_FTPMU010_VA_COUNT 1
+#define PMU_FTPMU010_VA_BASE 0xF9810000
+#define PMU_FTPMU010_VA_LIMIT 0xF9810FFF
+#define PMU_FTPMU010_VA_SIZE 0x00001000
+#define PMU_FTPMU010_0_VA_BASE 0xF9810000
+#define PMU_FTPMU010_0_VA_LIMIT 0xF9810FFF
+#define PMU_FTPMU010_0_VA_SIZE 0x00001000
+
+/* USB */
+#define USB_FUSBH200_PA_COUNT 1
+#define USB_FUSBH200_PA_BASE 0x92000000
+#define USB_FUSBH200_PA_LIMIT 0x92000FFF
+#define USB_FUSBH200_PA_SIZE 0x00001000
+#define USB_FUSBH200_0_PA_BASE 0x92000000
+#define USB_FUSBH200_0_PA_LIMIT 0x92000FFF
+#define USB_FUSBH200_0_PA_SIZE 0x00001000
+#define USB_FUSBH200_VA_COUNT 1
+#define USB_FUSBH200_VA_BASE 0xF9200000
+#define USB_FUSBH200_VA_LIMIT 0xF9200FFF
+#define USB_FUSBH200_VA_SIZE 0x00001000
+#define USB_FUSBH200_0_VA_BASE 0xF9200000
+#define USB_FUSBH200_0_VA_LIMIT 0xF9200FFF
+#define USB_FUSBH200_0_VA_SIZE 0x00001000
+#define USB_FUSB220_PA_COUNT 1
+#define USB_FUSB220_PA_BASE 0x90B00000
+#define USB_FUSB220_PA_LIMIT 0x90B00FFF
+#define USB_FUSB220_PA_SIZE 0x00001000
+#define USB_FUSB220_0_PA_BASE 0x90B00000
+#define USB_FUSB220_0_PA_LIMIT 0x90B00FFF
+#define USB_FUSB220_0_PA_SIZE 0x00001000
+#define USB_FUSB220_VA_COUNT 1
+#define USB_FUSB220_VA_BASE 0xF90B0000
+#define USB_FUSB220_VA_LIMIT 0xF90B0FFF
+#define USB_FUSB220_VA_SIZE 0x00001000
+#define USB_FUSB220_0_VA_BASE 0xF90B0000
+#define USB_FUSB220_0_VA_LIMIT 0xF90B0FFF
+#define USB_FUSB220_0_VA_SIZE 0x00001000
+
+/* KMI */
+#define KMI_FTKBC010_PA_COUNT 1
+#define KMI_FTKBC010_PA_BASE 0x97200000
+#define KMI_FTKBC010_PA_LIMIT 0x97200FFF
+#define KMI_FTKBC010_PA_SIZE 0x00001000
+#define KMI_FTKBC010_0_PA_BASE 0x97200000
+#define KMI_FTKBC010_0_PA_LIMIT 0x97200FFF
+#define KMI_FTKBC010_0_PA_SIZE 0x00001000
+#define KMI_FTKBC010_1_PA_BASE 0x97300000
+#define KMI_FTKBC010_1_PA_LIMIT 0x97300FFF
+#define KMI_FTKBC010_1_PA_SIZE 0x00001000
+#define KMI_FTKBC010_VA_COUNT 1
+#define KMI_FTKBC010_VA_BASE 0xF9720000
+#define KMI_FTKBC010_VA_LIMIT 0xF9720FFF
+#define KMI_FTKBC010_VA_SIZE 0x00001000
+#define KMI_FTKBC010_0_VA_BASE 0xF9720000
+#define KMI_FTKBC010_0_VA_LIMIT 0xF9720FFF
+#define KMI_FTKBC010_0_VA_SIZE 0x00001000
+#define KMI_FTKBC010_1_VA_BASE 0xF9730000
+#define KMI_FTKBC010_1_VA_LIMIT 0xF9730FFF
+#define KMI_FTKBC010_1_VA_SIZE 0x00001000
+
+/* PCIMEM */
+#define PCIMEM_PA_COUNT 1
+#define PCIMEM_PA_BASE 0xA0000000
+#define PCIMEM_PA_LIMIT 0xAFFFFFFF
+#define PCIMEM_PA_SIZE 0x10000000
+#define PCIMEM_0_PA_BASE 0xA0000000
+#define PCIMEM_0_PA_LIMIT 0xAFFFFFFF
+#define PCIMEM_0_PA_SIZE 0x10000000
+
+
+#ifdef CONFIG_PLATFORM_AHBDMA_MODULE
+#define CONFIG_PLATFORM_AHBDMA
+#endif
+
+#ifdef CONFIG_PLATFORM_APBDMA_MODULE
+#define CONFIG_PLATFORM_APBDMA
+#endif
+
+#include <asm/misc_spec.h> /* Manual defined spec */
+
+/*
+ * Platform independent specification
+ */
+
+#define NR_IRQS PLATFORM_INTERRUPTS
+
+#ifndef TIMER_CLK_IN
+#error Missing platform dependent symbol TIMER_CLK_IN in <asm/arch/platform/misc_spec.h> file.
+#endif
+
+/*
+ * Macros for retrieving IP related information
+ */
+#define IP_IDENTIFIER __glue(__glue(IPMODULE,_),__glue(IPNAME,_))
+
+#define IP_COUNT __glue(IP_IDENTIFIER,COUNT)
+
+#define IP_IRQ_COUNT __glue(IP_IDENTIFIER,IRQ_COUNT)
+#define IP_IRQ(n) __glue(__glue(IP_IDENTIFIER,n),_IRQ)
+#define IP_irq __glue(IP_IDENTIFIER,irq)
+
+#define IP_PA_COUNT __glue(IP_IDENTIFIER,PA_COUNT)
+#define IP_PA_BASE(n) __glue(__glue(IP_IDENTIFIER,n),_PA_BASE)
+#define IP_PA_LIMIT(n) __glue(__glue(IP_IDENTIFIER,n),_PA_LIMIT)
+#define IP_PA_SIZE(n) __glue(__glue(IP_IDENTIFIER,n),_PA_SIZE)
+#define IP_pa_base __glue(IP_IDENTIFIER,pa_base)
+#define IP_pa_limit __glue(IP_IDENTIFIER,pa_limit)
+#define IP_pa_size __glue(IP_IDENTIFIER,pa_size)
+
+#define IP_VA_COUNT __glue(IP_IDENTIFIER,VA_COUNT)
+#define IP_VA_BASE(n) __glue(__glue(IP_IDENTIFIER,n),_VA_BASE)
+#define IP_VA_LIMIT(n) __glue(__glue(IP_IDENTIFIER,n),_VA_LIMIT)
+#define IP_VA_SIZE(n) __glue(__glue(IP_IDENTIFIER,n),_VA_SIZE)
+#define IP_va_base __glue(IP_IDENTIFIER,va_base)
+#define IP_va_limit __glue(IP_IDENTIFIER,va_limit)
+#define IP_va_size __glue(IP_IDENTIFIER,va_size)
+
+/*
+ * Facility macros
+ */
+/* IRQ0~7 */
+#define IP_IRQ0(n) __glue(__glue(IP_IDENTIFIER,n),_IRQ0)
+#define IP_IRQ1(n) __glue(__glue(IP_IDENTIFIER,n),_IRQ1)
+#define IP_IRQ2(n) __glue(__glue(IP_IDENTIFIER,n),_IRQ2)
+#define IP_IRQ3(n) __glue(__glue(IP_IDENTIFIER,n),_IRQ3)
+#define IP_IRQ4(n) __glue(__glue(IP_IDENTIFIER,n),_IRQ4)
+#define IP_IRQ5(n) __glue(__glue(IP_IDENTIFIER,n),_IRQ5)
+#define IP_IRQ6(n) __glue(__glue(IP_IDENTIFIER,n),_IRQ6)
+#define IP_IRQ7(n) __glue(__glue(IP_IDENTIFIER,n),_IRQ7)
+
+/* PA_BASE0~7 */
+#define IP_PA_BASE0(n) __glue(__glue(IP_IDENTIFIER,n),_PA_BASE0)
+#define IP_PA_BASE1(n) __glue(__glue(IP_IDENTIFIER,n),_PA_BASE1)
+#define IP_PA_BASE2(n) __glue(__glue(IP_IDENTIFIER,n),_PA_BASE2)
+#define IP_PA_BASE3(n) __glue(__glue(IP_IDENTIFIER,n),_PA_BASE3)
+#define IP_PA_BASE4(n) __glue(__glue(IP_IDENTIFIER,n),_PA_BASE4)
+#define IP_PA_BASE5(n) __glue(__glue(IP_IDENTIFIER,n),_PA_BASE5)
+#define IP_PA_BASE6(n) __glue(__glue(IP_IDENTIFIER,n),_PA_BASE6)
+#define IP_PA_BASE7(n) __glue(__glue(IP_IDENTIFIER,n),_PA_BASE7)
+
+/* PA_LIMIT0~7 */
+#define IP_PA_LIMIT0(n) __glue(__glue(IP_IDENTIFIER,n),_PA_LIMIT0)
+#define IP_PA_LIMIT1(n) __glue(__glue(IP_IDENTIFIER,n),_PA_LIMIT1)
+#define IP_PA_LIMIT2(n) __glue(__glue(IP_IDENTIFIER,n),_PA_LIMIT2)
+#define IP_PA_LIMIT3(n) __glue(__glue(IP_IDENTIFIER,n),_PA_LIMIT3)
+#define IP_PA_LIMIT4(n) __glue(__glue(IP_IDENTIFIER,n),_PA_LIMIT4)
+#define IP_PA_LIMIT5(n) __glue(__glue(IP_IDENTIFIER,n),_PA_LIMIT5)
+#define IP_PA_LIMIT6(n) __glue(__glue(IP_IDENTIFIER,n),_PA_LIMIT6)
+#define IP_PA_LIMIT7(n) __glue(__glue(IP_IDENTIFIER,n),_PA_LIMIT7)
+
+/* PA_SIZE0~7 */
+#define IP_PA_SIZE0(n) __glue(__glue(IP_IDENTIFIER,n),_PA_SIZE0)
+#define IP_PA_SIZE1(n) __glue(__glue(IP_IDENTIFIER,n),_PA_SIZE1)
+#define IP_PA_SIZE2(n) __glue(__glue(IP_IDENTIFIER,n),_PA_SIZE2)
+#define IP_PA_SIZE3(n) __glue(__glue(IP_IDENTIFIER,n),_PA_SIZE3)
+#define IP_PA_SIZE4(n) __glue(__glue(IP_IDENTIFIER,n),_PA_SIZE4)
+#define IP_PA_SIZE5(n) __glue(__glue(IP_IDENTIFIER,n),_PA_SIZE5)
+#define IP_PA_SIZE6(n) __glue(__glue(IP_IDENTIFIER,n),_PA_SIZE6)
+#define IP_PA_SIZE7(n) __glue(__glue(IP_IDENTIFIER,n),_PA_SIZE7)
+
+/* VA_BASE0~7 */
+#define IP_VA_BASE0(n) __glue(__glue(IP_IDENTIFIER,n),_VA_BASE0)
+#define IP_VA_BASE1(n) __glue(__glue(IP_IDENTIFIER,n),_VA_BASE1)
+#define IP_VA_BASE2(n) __glue(__glue(IP_IDENTIFIER,n),_VA_BASE2)
+#define IP_VA_BASE3(n) __glue(__glue(IP_IDENTIFIER,n),_VA_BASE3)
+#define IP_VA_BASE4(n) __glue(__glue(IP_IDENTIFIER,n),_VA_BASE4)
+#define IP_VA_BASE5(n) __glue(__glue(IP_IDENTIFIER,n),_VA_BASE5)
+#define IP_VA_BASE6(n) __glue(__glue(IP_IDENTIFIER,n),_VA_BASE6)
+#define IP_VA_BASE7(n) __glue(__glue(IP_IDENTIFIER,n),_VA_BASE7)
+
+/* VA_LIMIT0~7 */
+#define IP_VA_LIMIT0(n) __glue(__glue(IP_IDENTIFIER,n),_VA_LIMIT0)
+#define IP_VA_LIMIT1(n) __glue(__glue(IP_IDENTIFIER,n),_VA_LIMIT1)
+#define IP_VA_LIMIT2(n) __glue(__glue(IP_IDENTIFIER,n),_VA_LIMIT2)
+#define IP_VA_LIMIT3(n) __glue(__glue(IP_IDENTIFIER,n),_VA_LIMIT3)
+#define IP_VA_LIMIT4(n) __glue(__glue(IP_IDENTIFIER,n),_VA_LIMIT4)
+#define IP_VA_LIMIT5(n) __glue(__glue(IP_IDENTIFIER,n),_VA_LIMIT5)
+#define IP_VA_LIMIT6(n) __glue(__glue(IP_IDENTIFIER,n),_VA_LIMIT6)
+#define IP_VA_LIMIT7(n) __glue(__glue(IP_IDENTIFIER,n),_VA_LIMIT7)
+
+/* VA_SIZE0~7 */
+#define IP_VA_SIZE0(n) __glue(__glue(IP_IDENTIFIER,n),_VA_SIZE0)
+#define IP_VA_SIZE1(n) __glue(__glue(IP_IDENTIFIER,n),_VA_SIZE1)
+#define IP_VA_SIZE2(n) __glue(__glue(IP_IDENTIFIER,n),_VA_SIZE2)
+#define IP_VA_SIZE3(n) __glue(__glue(IP_IDENTIFIER,n),_VA_SIZE3)
+#define IP_VA_SIZE4(n) __glue(__glue(IP_IDENTIFIER,n),_VA_SIZE4)
+#define IP_VA_SIZE5(n) __glue(__glue(IP_IDENTIFIER,n),_VA_SIZE5)
+#define IP_VA_SIZE6(n) __glue(__glue(IP_IDENTIFIER,n),_VA_SIZE6)
+#define IP_VA_SIZE7(n) __glue(__glue(IP_IDENTIFIER,n),_VA_SIZE7)
+
+#endif /* __FARADAY_PLATFORM_INDEPENDENT_SPECIFICATION__ */
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/spinlock.h linux-3.4.113/arch/nds32/include/asm/spinlock.h
--- linux-3.4.113.orig/arch/nds32/include/asm/spinlock.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/spinlock.h 2016-12-01 20:59:24.348612597 +0100
@@ -0,0 +1,183 @@
+/*
+ * linux/arch/nds32/include/asm/spinlock.h
+ * Copyright (C) 2008 Andes Technology Corporation
+ */
+
+#ifndef __ASM_SPINLOCK_H
+#define __ASM_SPINLOCK_H
+
+#include <asm/processor.h>
+
+#define arch_spin_is_locked(x) ((x)->lock != 0)
+
+#define arch_spin_unlock_wait(lock) \
+ do { while (arch_spin_is_locked(lock)) cpu_relax(); } while (0)
+
+#define arch_spin_lock_flags(lock, flags) arch_spin_lock(lock)
+
+static inline void arch_spin_lock(arch_spinlock_t *lock)
+{
+ unsigned long tmp;
+
+ __asm__ __volatile__(
+ "xor\t$r15, $r15, $r15\n"
+ "1:\n"
+ "\tllw\t%0, [%1+$r15]\n"
+ "\tbnez\t%0, 1b\n"
+ "\tmovi\t%0, #0x1\n"
+ "\tscw\t%0, [%1+$r15]\n"
+ "\tbeqz\t%0, 1b\n"
+ : "=&r" (tmp)
+ : "r" (&lock->lock)
+ : "memory");
+}
+
+static inline int arch_spin_trylock(arch_spinlock_t *lock)
+{
+ unsigned long ret, tmp;
+
+ __asm__ __volatile__(
+ "xor\t$r15, $r15, $r15\n"
+ "1:\n"
+ "\tllw\t%0, [%2+$r15]\n"
+ "\tmovi\t%1, #0x1\n"
+ "\tscw\t%1, [%2+$r15]\n"
+ "\tbeqz\t%1, 1b\n"
+ : "=&r" (ret), "=&r" (tmp)
+ : "r" (&lock->lock)
+ : "memory");
+
+ return ret == 0;
+}
+
+static inline void arch_spin_unlock(arch_spinlock_t *lock)
+{
+ __asm__ __volatile__(
+ "xor\t$r15, $r15, $r15\n"
+ "\tswi\t$r15, [%0]\n"
+ :
+ : "r" (&lock->lock)
+ : "memory");
+}
+
+static inline void arch_write_lock(arch_rwlock_t *rw)
+{
+ unsigned long tmp;
+
+ __asm__ __volatile__(
+ "xor\t$r15, $r15, $r15\n"
+ "1:\n"
+ "\tllw\t%0, [%1+$r15]\n"
+ "\tbnez\t%0, 1b\n"
+ "\tsethi\t%0, 0x80000\n"
+ "\tscw\t%0, [%1+$r15]\n"
+ "\tbeqz\t%0, 1b\n"
+ : "=&r" (tmp)
+ : "r" (&rw->lock)
+ : "memory");
+}
+
+static inline void arch_write_unlock(arch_rwlock_t *rw)
+{
+ __asm__ __volatile__(
+ "xor\t$r15, $r15, $r15\n"
+ "\tswi\t$r15, [%0]\n"
+ :
+ : "r" (&rw->lock)
+ : "memory");
+}
+
+#define arch_write_can_lock(x) ((x)->lock == 0)
+static inline void arch_read_lock(arch_rwlock_t *rw)
+{
+ int tmp;
+
+ __asm__ __volatile__(
+ "xor\t$r15, $r15, $r15\n"
+ "1:\n"
+ "\tllw\t%0, [%1+$r15]\n"
+ "\tbltz\t%0, 1b\n"
+ "\taddi\t%0, %0, #1\n"
+ "\tscw\t%0, [%1+$r15]\n"
+ "\tbeqz\t%0, 1b\n"
+ : "=&r" (tmp)
+ : "r" (&rw->lock)
+ : "memory");
+}
+
+static inline void arch_read_unlock(arch_rwlock_t *rw)
+{
+ unsigned long tmp;
+
+ __asm__ __volatile__(
+ "xor\t$r15, $r15, $r15\n"
+ "1:\n"
+ "\tllw\t%0, [%1+$r15]\n"
+ "\taddi\t%0, %0, #-1\n"
+ "\tscw\t%0, [%1+$r15]\n"
+ "\tbeqz\t%0, 1b\n"
+ : "=&r" (tmp)
+ : "r" (&rw->lock)
+ : "memory");
+}
+
+static inline int arch_read_trylock(arch_rwlock_t *rw)
+{
+ unsigned long ret, tmp;
+
+ __asm__ __volatile__(
+ "xor\t$r15, $r15, $r15\n"
+ "\tmovi\t%0, #0x0\n"
+ "1:\n"
+ "\tllw\t%1, [%2+$r15]\n"
+ "\tbltz\t%1, 2f\n"
+ "\taddi\t%1, %1, #1\n"
+ "\tscw\t%1, [%2+$r15]\n"
+ "\tbeqz\t%1, 1b\n"
+ "\tmovi\t%0, #0x1\n"
+ "\tj\t3f\n"
+ "2:\n"
+ "\tscw\t%1, [%2+$r15]\n"
+ "3:\n"
+ : "=&r" (ret), "=&r" (tmp)
+ : "r" (&rw->lock)
+ : "memory");
+
+ return ret;
+}
+
+static inline int arch_write_trylock(arch_rwlock_t *rw)
+{
+ unsigned long ret, tmp;
+
+ __asm__ __volatile__(
+ "xor\t$r15, $r15, $r15\n"
+ "\tmovi\t%0, #0x0\n"
+ "1:\n"
+ "\tllw\t%1, [%2+$r15]\n"
+ "\tbnez\t%1, 2f\n"
+ "\tsethi\t%1, 0x80000\n"
+ "\tscw\t%1, [%2+$r15]\n"
+ "\tbeqz\t%1, 1b\n"
+ "\tmovi\t%0, #0x1\n"
+ "\tj\t3f\n"
+ "2:\n"
+ "\tscw\t%1, [%2+$r15]\n"
+ "3:\n"
+ : "=&r" (ret), "=&r" (tmp)
+ : "r" (&rw->lock)
+ : "memory");
+
+ return ret;
+}
+
+#define arch_read_lock_flags(lock, flags) arch_read_lock(lock)
+#define arch_write_lock_flags(lock, flags) arch_write_lock(lock)
+
+#define arch_read_can_lock(x) ((x)->lock < 0x80000000)
+
+#define arch_spin_relax(lock) cpu_relax()
+#define arch_read_relax(lock) cpu_relax()
+#define arch_write_relax(lock) cpu_relax()
+
+#endif /* __ASM_SPINLOCK_H */
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/spinlock_types.h linux-3.4.113/arch/nds32/include/asm/spinlock_types.h
--- linux-3.4.113.orig/arch/nds32/include/asm/spinlock_types.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/spinlock_types.h 2016-12-01 20:59:24.348612597 +0100
@@ -0,0 +1,25 @@
+/*
+ * linux/arch/nds32/include/asm/spinlock_types.h
+ * Copyright (C) 2008 Andes Technology Corporation
+ */
+
+#ifndef _ASM_SPINLOCK_TYPES_H
+#define _ASM_SPINLOCK_TYPES_H
+
+#ifndef __LINUX_SPINLOCK_TYPES_H
+# error "please don't include this file directly"
+#endif
+
+typedef struct {
+ volatile unsigned int lock;
+} arch_spinlock_t;
+
+#define __ARCH_SPIN_LOCK_UNLOCKED { 0 }
+
+typedef struct {
+ volatile unsigned int lock;
+} arch_rwlock_t;
+
+#define __ARCH_RW_LOCK_UNLOCKED { 0 }
+
+#endif
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/statfs.h linux-3.4.113/arch/nds32/include/asm/statfs.h
--- linux-3.4.113.orig/arch/nds32/include/asm/statfs.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/statfs.h 2016-12-01 20:59:24.348612597 +0100
@@ -0,0 +1,11 @@
+/*
+ * linux/arch/nds32/include/asm/statfs.h
+ * Copyright (C) 2008 Andes Technology Corporation
+ */
+
+#ifndef _ASMNDS32_STATFS_H
+#define _ASMNDS32_STATFS_H
+
+#include <asm-generic/statfs.h>
+
+#endif
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/stat.h linux-3.4.113/arch/nds32/include/asm/stat.h
--- linux-3.4.113.orig/arch/nds32/include/asm/stat.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/stat.h 2016-12-01 20:59:24.348612597 +0100
@@ -0,0 +1,101 @@
+/*
+ * linux/arch/nds32/include/asm/stat.h
+ * Copyright (C) 2008 Andes Technology Corporation
+ */
+
+#ifndef _ASMNDS32_STAT_H
+#define _ASMNDS32_STAT_H
+
+struct __old_kernel_stat {
+ unsigned short st_dev;
+ unsigned short st_ino;
+ unsigned short st_mode;
+ unsigned short st_nlink;
+ unsigned short st_uid;
+ unsigned short st_gid;
+ unsigned short st_rdev;
+ unsigned long st_size;
+ unsigned long st_atime;
+ unsigned long st_mtime;
+ unsigned long st_ctime;
+};
+
+#define STAT_HAVE_NSEC
+
+struct stat {
+#if defined(__NDS32_EB__)
+ unsigned short st_dev;
+ unsigned short __pad1;
+#else
+ unsigned long st_dev;
+#endif
+ unsigned long st_ino;
+ unsigned short st_mode;
+ unsigned short st_nlink;
+ unsigned short st_uid;
+ unsigned short st_gid;
+#if defined(__NDS32_EB__)
+ unsigned short st_rdev;
+ unsigned short __pad2;
+#else
+ unsigned long st_rdev;
+#endif
+ unsigned long st_size;
+ unsigned long st_blksize;
+ unsigned long st_blocks;
+ unsigned long st_atime;
+ unsigned long st_atime_nsec;
+ unsigned long st_mtime;
+ unsigned long st_mtime_nsec;
+ unsigned long st_ctime;
+ unsigned long st_ctime_nsec;
+ unsigned long __unused4;
+ unsigned long __unused5;
+};
+
+/* This matches struct stat64 in glibc2.1, hence the absolutely
+ * insane amounts of padding around dev_t's.
+ * Note: The kernel zero's the padded region because glibc might read them
+ * in the hope that the kernel has stretched to using larger sizes.
+ */
+
+struct stat64 {
+ unsigned long long st_dev;
+ unsigned long __pad0;
+
+#define STAT64_HAS_BROKEN_ST_INO 1
+ unsigned long __st_ino;
+ unsigned int st_mode;
+ unsigned int st_nlink;
+
+ unsigned long st_uid;
+ unsigned long st_gid;
+
+ unsigned long long st_rdev;
+ unsigned int __pad3;
+
+ unsigned long long st_size;
+ unsigned long st_blksize;
+
+//#if defined(__NDS32EB__)
+// unsigned long __pad4; // Future possible st_blocks hi bits
+ unsigned long long st_blocks; // Number 512-byte blocks allocated.
+//#else // Must be little
+// unsigned long st_blocks; // Number 512-byte blocks allocated.
+// unsigned long __pad4; // Future possible st_blocks hi bits
+//#endif
+
+ unsigned long st_atime;
+ unsigned long st_atime_nsec;
+
+ unsigned long st_mtime;
+ unsigned long st_mtime_nsec;
+
+ unsigned long st_ctime;
+ unsigned long st_ctime_nsec;
+
+ unsigned long long st_ino;
+};
+
+
+#endif
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/string.h linux-3.4.113/arch/nds32/include/asm/string.h
--- linux-3.4.113.orig/arch/nds32/include/asm/string.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/string.h 2016-12-01 20:59:24.348612597 +0100
@@ -0,0 +1,45 @@
+/*
+ * linux/arch/nds32/include/asm/string.h
+ * Copyright (C) 2008 Andes Technology Corporation
+ */
+
+#ifndef __ASM_NDS32_STRING_H
+#define __ASM_NDS32_STRING_H
+
+/*
+ * We don't do inline string functions, since the
+ * optimised inline asm versions are not small.
+ */
+
+#define __HAVE_ARCH_STRRCHR
+extern char * strrchr(const char * s, int c);
+
+#define __HAVE_ARCH_STRCHR
+extern char * strchr(const char * s, int c);
+
+#define __HAVE_ARCH_MEMCPY
+extern void * memcpy(void *, const void *, __kernel_size_t);
+
+#define __HAVE_ARCH_MEMMOVE
+extern void * memmove(void *, const void *, __kernel_size_t);
+
+#define __HAVE_ARCH_MEMZERO
+#define __HAVE_ARCH_MEMSET
+extern void * memset(void *, int, __kernel_size_t);
+
+extern void __memzero(void *ptr, __kernel_size_t n);
+
+#define memset(p,v,n) \
+ ({ \
+ if ((n) != 0) { \
+ if (__builtin_constant_p((v)) && (v) == 0) \
+ __memzero((p),(n)); \
+ else \
+ memset((p),(v),(n)); \
+ } \
+ (p); \
+ })
+
+#define memzero(p,n) ({ if ((n) != 0) __memzero((p),(n)); (p); })
+
+#endif
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/suspend.h linux-3.4.113/arch/nds32/include/asm/suspend.h
--- linux-3.4.113.orig/arch/nds32/include/asm/suspend.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/suspend.h 2016-12-01 20:59:24.348612597 +0100
@@ -0,0 +1,9 @@
+/*
+ * linux/arch/nds32/include/asm/suspend.h
+ * Copyright (C) 2008 Andes Technology Corporation
+ */
+
+#ifndef _ASMNDS32_SUSPEND_H
+#define _ASMNDS32_SUSPEND_H
+
+#endif
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/swab.h linux-3.4.113/arch/nds32/include/asm/swab.h
--- linux-3.4.113.orig/arch/nds32/include/asm/swab.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/swab.h 2016-12-01 20:59:24.348612597 +0100
@@ -0,0 +1,34 @@
+/*
+ * include/asm/byteorder.h
+ * Copyright (C) 2008 Andes Technology, Inc.
+ */
+
+#ifndef __NDS32_SWAB_H__
+#define __NDS32_SWAB_H__
+
+#include <linux/types.h>
+#include <linux/compiler.h>
+
+static __inline__ __attribute_const__ __u32 ___arch__swab32(__u32 x)
+{
+ __asm__("wsbh %0, %0\n\t" /* word swap byte within halfword */
+ "rotri %0, %0, #16\n"
+ : "=r" (x) : "0" (x));
+ return x;
+}
+
+static __inline__ __attribute_const__ __u16 ___arch__swab16(__u16 x)
+{
+ __asm__("wsbh %0, %0\n" /* word swap byte within halfword */
+ : "=r" (x) : "0" (x));
+ return x;
+}
+#define __arch_swab32(x) ___arch__swab32(x)
+#define __arch_swab16(x) ___arch__swab16(x)
+
+#if !defined(__STRICT_ANSI__) || defined(__KERNEL__)
+# define __BYTEORDER_HAS_U64__
+# define __SWAB_64_THRU_32__
+#endif
+
+#endif /* __NDS32_SWAB_H__ */
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/switch_to.h linux-3.4.113/arch/nds32/include/asm/switch_to.h
--- linux-3.4.113.orig/arch/nds32/include/asm/switch_to.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/switch_to.h 2016-12-01 20:59:24.348612597 +0100
@@ -0,0 +1,18 @@
+#ifndef __ASM_NDS32_SWITCH_TO_H
+#define __ASM_NDS32_SWITCH_TO_H
+
+#include <linux/thread_info.h>
+
+/*
+ * switch_to(prev, next) should switch from task `prev' to `next'
+ * `prev' will never be the same as `next'. schedule() itself
+ * contains the memory barrier to tell GCC not to cache `current'.
+ */
+extern struct task_struct *__switch_to(struct task_struct *, struct thread_info *, struct thread_info *);
+
+#define switch_to( prev, next, last) \
+do { \
+ last = __switch_to( prev, task_thread_info( prev), task_thread_info( next)); \
+} while (0)
+
+#endif
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/system.h linux-3.4.113/arch/nds32/include/asm/system.h
--- linux-3.4.113.orig/arch/nds32/include/asm/system.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/system.h 2016-12-01 20:59:24.348612597 +0100
@@ -0,0 +1,4 @@
+/* FILE TO BE DELETED. DO NOT ADD STUFF HERE! */
+#include <asm/barrier.h>
+#include <asm/switch_to.h>
+
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/termbits.h linux-3.4.113/arch/nds32/include/asm/termbits.h
--- linux-3.4.113.orig/arch/nds32/include/asm/termbits.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/termbits.h 2016-12-01 20:59:24.348612597 +0100
@@ -0,0 +1,198 @@
+#ifndef __ASM_NDS32_TERMBITS_H
+#define __ASM_NDS32_TERMBITS_H
+
+typedef unsigned char cc_t;
+typedef unsigned int speed_t;
+typedef unsigned int tcflag_t;
+
+#define NCCS 19
+struct termios {
+ tcflag_t c_iflag; /* input mode flags */
+ tcflag_t c_oflag; /* output mode flags */
+ tcflag_t c_cflag; /* control mode flags */
+ tcflag_t c_lflag; /* local mode flags */
+ cc_t c_line; /* line discipline */
+ cc_t c_cc[NCCS]; /* control characters */
+};
+
+struct termios2 {
+ tcflag_t c_iflag; /* input mode flags */
+ tcflag_t c_oflag; /* output mode flags */
+ tcflag_t c_cflag; /* control mode flags */
+ tcflag_t c_lflag; /* local mode flags */
+ cc_t c_line; /* line discipline */
+ cc_t c_cc[NCCS]; /* control characters */
+ speed_t c_ispeed; /* input speed */
+ speed_t c_ospeed; /* output speed */
+};
+
+struct ktermios {
+ tcflag_t c_iflag; /* input mode flags */
+ tcflag_t c_oflag; /* output mode flags */
+ tcflag_t c_cflag; /* control mode flags */
+ tcflag_t c_lflag; /* local mode flags */
+ cc_t c_line; /* line discipline */
+ cc_t c_cc[NCCS]; /* control characters */
+ speed_t c_ispeed; /* input speed */
+ speed_t c_ospeed; /* output speed */
+};
+
+
+/* c_cc characters */
+#define VINTR 0
+#define VQUIT 1
+#define VERASE 2
+#define VKILL 3
+#define VEOF 4
+#define VTIME 5
+#define VMIN 6
+#define VSWTC 7
+#define VSTART 8
+#define VSTOP 9
+#define VSUSP 10
+#define VEOL 11
+#define VREPRINT 12
+#define VDISCARD 13
+#define VWERASE 14
+#define VLNEXT 15
+#define VEOL2 16
+
+/* c_iflag bits */
+#define IGNBRK 0000001
+#define BRKINT 0000002
+#define IGNPAR 0000004
+#define PARMRK 0000010
+#define INPCK 0000020
+#define ISTRIP 0000040
+#define INLCR 0000100
+#define IGNCR 0000200
+#define ICRNL 0000400
+#define IUCLC 0001000
+#define IXON 0002000
+#define IXANY 0004000
+#define IXOFF 0010000
+#define IMAXBEL 0020000
+#define IUTF8 0040000
+
+/* c_oflag bits */
+#define OPOST 0000001
+#define OLCUC 0000002
+#define ONLCR 0000004
+#define OCRNL 0000010
+#define ONOCR 0000020
+#define ONLRET 0000040
+#define OFILL 0000100
+#define OFDEL 0000200
+#define NLDLY 0000400
+#define NL0 0000000
+#define NL1 0000400
+#define CRDLY 0003000
+#define CR0 0000000
+#define CR1 0001000
+#define CR2 0002000
+#define CR3 0003000
+#define TABDLY 0014000
+#define TAB0 0000000
+#define TAB1 0004000
+#define TAB2 0010000
+#define TAB3 0014000
+#define XTABS 0014000
+#define BSDLY 0020000
+#define BS0 0000000
+#define BS1 0020000
+#define VTDLY 0040000
+#define VT0 0000000
+#define VT1 0040000
+#define FFDLY 0100000
+#define FF0 0000000
+#define FF1 0100000
+
+/* c_cflag bit meaning */
+#define CBAUD 0010017
+#define B0 0000000 /* hang up */
+#define B50 0000001
+#define B75 0000002
+#define B110 0000003
+#define B134 0000004
+#define B150 0000005
+#define B200 0000006
+#define B300 0000007
+#define B600 0000010
+#define B1200 0000011
+#define B1800 0000012
+#define B2400 0000013
+#define B4800 0000014
+#define B9600 0000015
+#define B19200 0000016
+#define B38400 0000017
+#define EXTA B19200
+#define EXTB B38400
+#define CSIZE 0000060
+#define CS5 0000000
+#define CS6 0000020
+#define CS7 0000040
+#define CS8 0000060
+#define CSTOPB 0000100
+#define CREAD 0000200
+#define PARENB 0000400
+#define PARODD 0001000
+#define HUPCL 0002000
+#define CLOCAL 0004000
+#define CBAUDEX 0010000
+#define BOTHER 0010000
+#define B57600 0010001
+#define B115200 0010002
+#define B230400 0010003
+#define B460800 0010004
+#define B500000 0010005
+#define B576000 0010006
+#define B921600 0010007
+#define B1000000 0010010
+#define B1152000 0010011
+#define B1500000 0010012
+#define B2000000 0010013
+#define B2500000 0010014
+#define B3000000 0010015
+#define B3500000 0010016
+#define B4000000 0010017
+#define CIBAUD 002003600000 /* input baud rate */
+#define CMSPAR 010000000000 /* mark or space (stick) parity */
+#define CRTSCTS 020000000000 /* flow control */
+
+#define IBSHIFT 16
+
+/* c_lflag bits */
+#define ISIG 0000001
+#define ICANON 0000002
+#define XCASE 0000004
+#define ECHO 0000010
+#define ECHOE 0000020
+#define ECHOK 0000040
+#define ECHONL 0000100
+#define NOFLSH 0000200
+#define TOSTOP 0000400
+#define ECHOCTL 0001000
+#define ECHOPRT 0002000
+#define ECHOKE 0004000
+#define FLUSHO 0010000
+#define PENDIN 0040000
+#define IEXTEN 0100000
+#define EXTPROC 0200000
+
+/* tcflow() and TCXONC use these */
+#define TCOOFF 0
+#define TCOON 1
+#define TCIOFF 2
+#define TCION 3
+
+/* tcflush() and TCFLSH use these */
+#define TCIFLUSH 0
+#define TCOFLUSH 1
+#define TCIOFLUSH 2
+
+/* tcsetattr uses these */
+#define TCSANOW 0
+#define TCSADRAIN 1
+#define TCSAFLUSH 2
+
+#endif /* __ASM_NDS32_TERMBITS_H */
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/termios.h linux-3.4.113/arch/nds32/include/asm/termios.h
--- linux-3.4.113.orig/arch/nds32/include/asm/termios.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/termios.h 2016-12-01 20:59:24.348612597 +0100
@@ -0,0 +1,116 @@
+/*
+ * linux/arch/nds32/include/asm/termios.h
+ * Copyright (C) 2008 Andes Technology Corporation
+ */
+
+#ifndef __ASM_NDS32_TERMIOS_H
+#define __ASM_NDS32_TERMIOS_H
+
+#include <asm/termbits.h>
+#include <asm/ioctls.h>
+
+struct winsize {
+ unsigned short ws_row;
+ unsigned short ws_col;
+ unsigned short ws_xpixel;
+ unsigned short ws_ypixel;
+};
+
+#define NCC 8
+struct termio {
+ unsigned short c_iflag; /* input mode flags */
+ unsigned short c_oflag; /* output mode flags */
+ unsigned short c_cflag; /* control mode flags */
+ unsigned short c_lflag; /* local mode flags */
+ unsigned char c_line; /* line discipline */
+ unsigned char c_cc[NCC]; /* control characters */
+};
+
+#ifdef __KERNEL__
+/* intr=^C quit=^| erase=del kill=^U
+ eof=^D vtime=\0 vmin=\1 sxtc=\0
+ start=^Q stop=^S susp=^Z eol=\0
+ reprint=^R discard=^U werase=^W lnext=^V
+ eol2=\0
+*/
+#define INIT_C_CC "\003\034\177\025\004\0\1\0\021\023\032\0\022\017\027\026\0"
+#endif
+
+/* modem lines */
+#define TIOCM_LE 0x001
+#define TIOCM_DTR 0x002
+#define TIOCM_RTS 0x004
+#define TIOCM_ST 0x008
+#define TIOCM_SR 0x010
+#define TIOCM_CTS 0x020
+#define TIOCM_CAR 0x040
+#define TIOCM_RNG 0x080
+#define TIOCM_DSR 0x100
+#define TIOCM_CD TIOCM_CAR
+#define TIOCM_RI TIOCM_RNG
+#define TIOCM_OUT1 0x2000
+#define TIOCM_OUT2 0x4000
+#define TIOCM_LOOP 0x8000
+
+/* ioctl (fd, TIOCSERGETLSR, &result) where result may be as below */
+
+/* line disciplines */
+#define N_TTY 0
+#define N_SLIP 1
+#define N_MOUSE 2
+#define N_PPP 3
+#define N_STRIP 4
+#define N_AX25 5
+#define N_X25 6 /* X.25 async */
+#define N_6PACK 7
+#define N_MASC 8 /* Reserved for Mobitex module <kaz@cafe.net> */
+#define N_R3964 9 /* Reserved for Simatic R3964 module */
+#define N_PROFIBUS_FDL 10 /* Reserved for Profibus <Dave@mvhi.com> */
+#define N_IRDA 11 /* Linux IrDa - http://irda.sourceforge.net/ */
+#define N_SMSBLOCK 12 /* SMS block mode - for talking to GSM data cards about SMS messages */
+#define N_HDLC 13 /* synchronous HDLC */
+#define N_SYNC_PPP 14
+#define N_HCI 15 /* Bluetooth HCI UART */
+
+#ifdef __KERNEL__
+
+/*
+ * Translate a "termio" structure into a "termios". Ugh.
+ */
+#define SET_LOW_TERMIOS_BITS(termios, termio, x) { \
+ unsigned short __tmp; \
+ get_user(__tmp,&(termio)->x); \
+ *(unsigned short *) &(termios)->x = __tmp; \
+}
+
+#define user_termio_to_kernel_termios(termios, termio) \
+({ \
+ SET_LOW_TERMIOS_BITS(termios, termio, c_iflag); \
+ SET_LOW_TERMIOS_BITS(termios, termio, c_oflag); \
+ SET_LOW_TERMIOS_BITS(termios, termio, c_cflag); \
+ SET_LOW_TERMIOS_BITS(termios, termio, c_lflag); \
+ copy_from_user((termios)->c_cc, (termio)->c_cc, NCC); \
+})
+
+/*
+ * Translate a "termios" structure into a "termio". Ugh.
+ */
+#define kernel_termios_to_user_termio(termio, termios) \
+({ \
+ put_user((termios)->c_iflag, &(termio)->c_iflag); \
+ put_user((termios)->c_oflag, &(termio)->c_oflag); \
+ put_user((termios)->c_cflag, &(termio)->c_cflag); \
+ put_user((termios)->c_lflag, &(termio)->c_lflag); \
+ put_user((termios)->c_line, &(termio)->c_line); \
+ copy_to_user((termio)->c_cc, (termios)->c_cc, NCC); \
+})
+
+#define user_termios_to_kernel_termios(k, u) copy_from_user(k, u, sizeof(struct termios))
+#define kernel_termios_to_user_termios(u, k) copy_to_user(u, k, sizeof(struct termios))
+
+#define user_termios_to_kernel_termios_1(k, u) copy_from_user(k, u, sizeof(struct termios))
+#define kernel_termios_to_user_termios_1(u, k) copy_to_user(u, k, sizeof(struct termios))
+
+#endif /* __KERNEL__ */
+
+#endif /* __ASM_NDS32_TERMIOS_H */
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/thread_info.h linux-3.4.113/arch/nds32/include/asm/thread_info.h
--- linux-3.4.113.orig/arch/nds32/include/asm/thread_info.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/thread_info.h 2016-12-01 20:59:24.348612597 +0100
@@ -0,0 +1,145 @@
+/*
+ * linux/arch/nds32/include/asm/thread_info.h
+ *
+ * Copyright (C) 2002 Russell King.
+ * Copyright (C) 2008 Andes Technology Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+#ifndef __ASM_NDS32_THREAD_INFO_H
+#define __ASM_NDS32_THREAD_INFO_H
+
+#ifdef __KERNEL__
+
+#define THREAD_SHIFT (13)
+#define THREAD_SIZE (1 << THREAD_SHIFT)
+
+#ifndef __ASSEMBLY__
+
+struct task_struct;
+struct exec_domain;
+
+#include <asm/ptrace.h>
+#include <asm/types.h>
+
+
+typedef struct {
+ unsigned long seg;
+} mm_segment_t;
+//typedef unsigned long mm_segment_t;
+
+struct cpu_context_save {
+ unsigned long r6;
+ unsigned long r7;
+ unsigned long r8;
+ unsigned long r9;
+ unsigned long r10;
+ unsigned long r11;
+ unsigned long r12;
+ unsigned long r13;
+ unsigned long r14;
+ unsigned long fp;
+ unsigned long pc;
+};
+
+/*
+ * low level task data that entry.S needs immediate access to.
+ * __switch_to() assumes cpu_context follows immediately after cpu_domain.
+ */
+struct thread_info {
+ unsigned long flags; /* low level flags */
+ __s32 preempt_count; /* 0 => preemptable, <0 => bug */
+ mm_segment_t addr_limit; /* address limit */
+ struct task_struct *task; /* main task structure */
+ struct exec_domain *exec_domain; /* execution domain */
+ __u32 cpu; /* cpu */
+ struct cpu_context_save* sp_save; /* cpu context */
+ struct restart_block restart_block;
+};
+
+#define INIT_THREAD_INFO(tsk) \
+{ \
+ .task = &tsk, \
+ .exec_domain = &default_exec_domain, \
+ .flags = 0, \
+ .cpu = 0, \
+ .preempt_count = 1, \
+ .addr_limit = KERNEL_DS, \
+ .restart_block = { \
+ .fn = do_no_restart_syscall, \
+ }, \
+}
+
+#define init_thread_info (init_thread_union.thread_info)
+#define init_stack (init_thread_union.stack)
+
+
+/*
+ * how to get the thread information struct from C
+ */
+static inline struct thread_info *current_thread_info(void) __attribute_const__;
+
+static inline struct thread_info *current_thread_info(void)
+{
+ register unsigned long sp asm ("$sp"); //M Tom asm -> __asm__ __volatile__
+ return (struct thread_info *)(sp & ~(THREAD_SIZE - 1));
+}
+
+#define get_thread_info(ti) get_task_struct((ti)->task)
+#define put_thread_info(ti) put_task_struct((ti)->task)
+
+#define thread_saved_pc(tsk) \
+ ((unsigned long)(task_thread_info(tsk)->sp_save->pc))
+#define thread_saved_fp(tsk) \
+ ((unsigned long)(task_thread_info(tsk)->sp_save->fp))
+#endif
+
+#define THREAD_SIZE_ORDER (1)
+/*
+ * We use bit 30 of the preempt_count to indicate that kernel
+ * preemption is occuring. See include/asm-arm/hardirq.h.
+ */
+#define PREEMPT_ACTIVE 0x40000000
+
+/*
+ * thread information flags:
+ * TIF_SYSCALL_TRACE - syscall trace active
+ * TIF_NOTIFY_RESUME - resumption notification requested
+ * TIF_SIGPENDING - signal pending
+ * TIF_NEED_RESCHED - rescheduling necessary
+ * TIF_USEDFPU - FPU was used by this task this quantum (SMP)
+ * TIF_POLLING_NRFLAG - true if poll_idle() is polling TIF_NEED_RESCHED
+ * TIF_USEDAUDIO - Audio has been used by this task and no need to init the regs
+ */
+#define TIF_SIGPENDING 1
+#define TIF_NEED_RESCHED 2
+#define TIF_SINGLESTEP 3
+#define TIF_NOTIFY_RESUME 5
+#define TIF_SYSCALL_TRACE 8
+#define TIF_RESTORE_SIGMASK 9
+#define TIF_USEDFPU 16
+#define TIF_POLLING_NRFLAG 17
+#define TIF_MEMDIE 18
+#define TIF_FREEZE 19
+#define TIF_USEDAUDIO 20
+
+#define _TIF_SIGPENDING (1 << TIF_SIGPENDING)
+#define _TIF_NEED_RESCHED (1 << TIF_NEED_RESCHED)
+#define _TIF_SINGLESTEP (1 << TIF_SINGLESTEP)
+#define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
+#define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
+#define _TIF_RESTORE_SIGMASK (1 << TIF_RESTORE_SIGMASK)
+#define _TIF_POLLING_NRFLAG (1 << TIF_POLLING_NRFLAG)
+#define _TIF_FREEZE (1 << TIF_FREEZE)
+
+/*
+ * Change these and you break ASM code in entry-common.S
+ */
+#define _TIF_WORK_MASK 0x000000ff
+#define _TIF_WORK_SYSCALL_ENTRY (_TIF_SYSCALL_TRACE | _TIF_SINGLESTEP)
+#define _TIF_WORK_SYSCALL_LEAVE (_TIF_SYSCALL_TRACE | _TIF_SINGLESTEP)
+
+#endif /* __KERNEL__ */
+#endif /* __ASM_NDS32_THREAD_INFO_H */
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/timer.h linux-3.4.113/arch/nds32/include/asm/timer.h
--- linux-3.4.113.orig/arch/nds32/include/asm/timer.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/timer.h 2016-12-01 20:59:24.348612597 +0100
@@ -0,0 +1,94 @@
+/*
+ * include/arch/nds32/include/asm/timer.h
+ *
+ * Faraday FTTMR010 Timer Device Driver Interface
+ *
+ * Copyright (C) 2005 Faraday Corp. (http://www.faraday-tech.com)
+ * Copyright (C) 2008 Andes Technology Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Note
+ *
+ * As IP_COUNT might be greater than one, timer ID is computed as follows:
+ * id=0~2 : Timer 1~3 of the first FTTMR010 IP
+ * id=3~5 : Timer 1~3 of the second FTTMR010 IP
+ * ...
+ * Therefore:
+ * (id / 3) : Compute which IP
+ * (id % 3) : Compute which timer in this IP
+ * Notice:
+ * For simplicity's sake, all code does not check for invalid timer id
+ *
+ * ChangeLog
+ *
+ * Luke Lee 09/14/2005 Created, heavily modified from Faraday CPE platform code.
+ */
+
+
+#ifndef __FARADAY_TIMER_FTTMR010_HEADER__
+#define __FARADAY_TIMER_FTTMR010_HEADER__
+
+/*
+ * Definition of register offsets
+ */
+
+#define TIMER1_COUNT 0x0
+#define TIMER1_LOAD 0x4
+#define TIMER1_MATCH1 0x8
+#define TIMER1_MATCH2 0xC
+
+#define TIMER2_COUNT 0x10
+#define TIMER2_LOAD 0x14
+#define TIMER2_MATCH1 0x18
+#define TIMER2_MATCH2 0x1C
+
+#define TIMER3_COUNT 0x20
+#define TIMER3_LOAD 0x24
+#define TIMER3_MATCH1 0x28
+#define TIMER3_MATCH2 0x2C
+
+#define TIMER_TMCR 0x30
+#define TIMER_INTRSTATE 0x34
+#define TIMER_INTRMASK 0x38
+
+/* Each timer's register address is offset by 0x10 */
+#define TIMER_OFFSET 0x10
+
+/*
+ * Definition of TMCR bits
+ */
+
+#define TM1ENABLE 1
+#define TM1CLOCK (1<<1)
+#define TM1OFENABLE (1<<2)
+
+#define TM2ENABLE (1<<3)
+#define TM2CLOCK (1<<4)
+#define TM2OFENABLE (1<<5)
+
+#define TM3ENABLE (1<<6)
+#define TM3CLOCK (1<<7)
+#define TM3OFENABLE (1<<8)
+
+#define TM1UPDOWN (1<<9)
+#define TM2UPDOWN (1<<10)
+#define TM3UPDOWN (1<<11)
+
+
+#define TM1MATCH1 (1 << 0)
+#define TM1MATCH2 (1 << 1)
+#define TM1OVERFLOW (1 << 2)
+#define TM2MATCH1 (1 << 3)
+#define TM2MATCH2 (1 << 4)
+#define TM2OVERFLOW (1 << 5)
+#define TM3MATCH1 (1 << 6)
+#define TM3MATCH2 (1 << 7)
+#define TM3OVERFLOW (1 << 8)
+
+struct sys_timer;
+extern struct sys_timer platform_timer;
+
+#endif // __FARADAY_TIMER_FTTMR010_HEADER__
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/timex.h linux-3.4.113/arch/nds32/include/asm/timex.h
--- linux-3.4.113.orig/arch/nds32/include/asm/timex.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/timex.h 2016-12-01 20:59:24.348612597 +0100
@@ -0,0 +1,36 @@
+/*
+ * linux/arch/nds32/include/asm/timex.h
+ *
+ * Copyright (C) 1997,1998 Russell King
+ * Copyright (C) 2008 Andes Technology Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Architecture Specific TIME specifications
+ */
+#ifndef _ASMNDS32_TIMEX_H
+#define _ASMNDS32_TIMEX_H
+
+#ifndef __FARADAY_PLATFORM_INDEPENDENT_TIMEX_HEADER__
+#define __FARADAY_PLATFORM_INDEPENDENT_TIMEX_HEADER__
+
+#include <asm/spec.h>
+
+#ifndef CLOCK_TICK_RATE
+#define CLOCK_TICK_RATE (TIMER_CLK_IN)
+#endif
+
+#endif /* __FARADAY_PLATFORM_INDEPENDENT_TIMEX_HEADER__ */
+
+typedef unsigned long cycles_t;
+
+extern cycles_t cacheflush_time;
+
+static inline cycles_t get_cycles (void)
+{
+ return 0;
+}
+
+#endif
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/tlbflush.h linux-3.4.113/arch/nds32/include/asm/tlbflush.h
--- linux-3.4.113.orig/arch/nds32/include/asm/tlbflush.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/tlbflush.h 2016-12-01 20:59:24.348612597 +0100
@@ -0,0 +1,80 @@
+/*
+ * linux/arch/nds32/include/asm/tlbflush.h
+ * Copyright (C) 2008 Andes Technology Corporation
+ */
+
+#ifndef _ASMNDS32_TLBFLUSH_H
+#define _ASMNDS32_TLBFLUSH_H
+
+#include <linux/spinlock.h>
+#include <linux/mm.h>
+#include <nds32_intrinsic.h>
+
+static inline void local_flush_tlb_all(void)
+{
+ asm("tlbop FLUA\n");
+ __nds32__isb();
+}
+static inline void local_flush_tlb_mm(struct mm_struct *mm)
+{
+ asm("tlbop FLUA\n");
+ __nds32__isb();
+}
+static inline void local_flush_tlb_kernel_range(unsigned long start,
+ unsigned long end)
+{
+ while(start < end) {
+ asm("tlbop %0, INV"::"r" (start));
+ __nds32__isb();
+ start += PAGE_SIZE;
+ }
+}
+
+#ifndef CONFIG_CPU_NO_CONTEXT_ID
+void local_flush_tlb_range(struct vm_area_struct *vma,
+ unsigned long start, unsigned long end);
+void local_flush_tlb_page(struct vm_area_struct *vma, unsigned long addr);
+#else
+static inline void local_flush_tlb_range(struct vm_area_struct *vma,
+ unsigned long start, unsigned long end)
+{
+ if ((end - start) > 0x400000) {
+ asm("tlbop FLUA");
+ __nds32__isb();
+ return ;
+ }
+ while(start < end) {
+ asm("tlbop %0, INV"::"r" (start));
+ __nds32__isb();
+ start += PAGE_SIZE;
+ }
+}
+
+static inline void local_flush_tlb_page(struct vm_area_struct *vma,
+ unsigned long addr)
+{
+ asm("tlbop %0, INV"::"r" (addr));
+ __nds32__isb();
+}
+#endif
+
+#ifndef CONFIG_SMP
+#define flush_tlb_all local_flush_tlb_all
+#define flush_tlb_mm local_flush_tlb_mm
+#define flush_tlb_range local_flush_tlb_range
+#define flush_tlb_page local_flush_tlb_page
+#define flush_tlb_kernel_range local_flush_tlb_kernel_range
+#else
+void flush_tlb_all(void);
+void flush_tlb_mm(struct mm_struct *mm);
+void flush_tlb_range(struct vm_area_struct *vma,
+ unsigned long start, unsigned long end);
+void flush_tlb_page(struct vm_area_struct *vma, unsigned long addr);
+void flush_tlb_kernel_range(unsigned long start, unsigned long end);
+#endif
+
+void update_mmu_cache(struct vm_area_struct *vma,
+ unsigned long address, pte_t* pte);
+void tlb_migrate_finish(struct mm_struct *mm);
+
+#endif
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/tlb.h linux-3.4.113/arch/nds32/include/asm/tlb.h
--- linux-3.4.113.orig/arch/nds32/include/asm/tlb.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/tlb.h 2016-12-01 20:59:24.348612597 +0100
@@ -0,0 +1,30 @@
+/*
+ * linux/arch/nds32/include/asm/tlb.h
+ * Copyright (C) 2009 Andes Technology Corporation
+ */
+
+#ifndef __ASMNDS32_TLB_H
+#define __ASMNDS32_TLB_H
+
+#define tlb_start_vma(tlb,vma) \
+ do { \
+ if (!tlb->fullmm) \
+ flush_cache_range(vma, vma->vm_start, vma->vm_end); \
+ } while (0)
+
+#define tlb_end_vma(tlb,vma) \
+ do { \
+ if(!tlb->fullmm) \
+ flush_tlb_range(vma, vma->vm_start, vma->vm_end); \
+ } while (0)
+
+#define __tlb_remove_tlb_entry(tlb, pte, addr) do { } while (0)
+
+#define tlb_flush(tlb) flush_tlb_mm((tlb)->mm)
+
+#include <asm-generic/tlb.h>
+
+#define __pte_free_tlb(tlb, pte, addr) pte_free((tlb)->mm, pte)
+#define __pmd_free_tlb(tlb, pmd, addr) pmd_free((tln)->mm, pmd)
+
+#endif
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/topology.h linux-3.4.113/arch/nds32/include/asm/topology.h
--- linux-3.4.113.orig/arch/nds32/include/asm/topology.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/topology.h 2016-12-01 20:59:24.348612597 +0100
@@ -0,0 +1,11 @@
+/*
+ * linux/arch/nds32/include/asm/topology.h
+ * Copyright (C) 2008 Andes Technology Corporation
+ */
+
+#ifndef _ASM_NDS32_TOPOLOGY_H
+#define _ASM_NDS32_TOPOLOGY_H
+
+#include <asm-generic/topology.h>
+
+#endif /* _ASM_NDS32_TOPOLOGY_H */
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/traps.h linux-3.4.113/arch/nds32/include/asm/traps.h
--- linux-3.4.113.orig/arch/nds32/include/asm/traps.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/traps.h 2016-12-01 20:59:24.348612597 +0100
@@ -0,0 +1,25 @@
+/*
+ * linux/arch/nds32/include/asm/traps.h
+ * Copyright (C) 2008 Andes Technology Corporation
+ */
+
+#ifndef _ASMNDS32_TRAP_H
+#define _ASMNDS32_TRAP_H
+
+#include <linux/list.h>
+
+struct undef_hook {
+ struct list_head node;
+ u32 instr_mask;
+ u32 instr_val;
+ u32 cpsr_mask;
+ u32 cpsr_val;
+ int (*fn)(struct pt_regs *regs, unsigned int instr);
+};
+
+void register_undef_hook(struct undef_hook *hook);
+void unregister_undef_hook(struct undef_hook *hook);
+
+extern void __init early_trap_init(void);
+
+#endif
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/types.h linux-3.4.113/arch/nds32/include/asm/types.h
--- linux-3.4.113.orig/arch/nds32/include/asm/types.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/types.h 2016-12-01 20:59:24.348612597 +0100
@@ -0,0 +1,16 @@
+#ifndef __ASM_NDS32_TYPES_H
+#define __ASM_NDS32_TYPES_H
+
+#include <asm-generic/int-ll64.h>
+
+/*
+ * These aren't exported outside the kernel to avoid name space clashes
+ */
+#ifdef __KERNEL__
+
+#define BITS_PER_LONG 32
+
+#endif /* __KERNEL__ */
+
+#endif
+
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/uaccess.h linux-3.4.113/arch/nds32/include/asm/uaccess.h
--- linux-3.4.113.orig/arch/nds32/include/asm/uaccess.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/uaccess.h 2016-12-01 20:59:24.348612597 +0100
@@ -0,0 +1,428 @@
+/*
+ * linux/arch/nds32/include/asm/uaccess.h
+ *
+ * Copyright (C) 2008 Andes Technology Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+#ifndef _ASMANDES_UACCESS_H
+#define _ASMANDES_UACCESS_H
+
+/*
+ * User space memory access functions
+ */
+#include <linux/sched.h>
+#include <asm/errno.h>
+#include <asm/memory.h>
+#include <asm/system.h>
+#include <asm/types.h>
+#include <linux/mm.h>
+
+#define VERIFY_READ 0
+#define VERIFY_WRITE 1
+
+/*
+ * The exception table consists of pairs of addresses: the first is the
+ * address of an instruction that is allowed to fault, and the second is
+ * the address at which the program should continue. No registers are
+ * modified, so it is entirely up to the continuation code to figure out
+ * what to do.
+ *
+ * All the routines below use bits of fixup code that are out of line
+ * with the main instruction path. This means when everything is well,
+ * we don't even have to jump over them. Further, they do not intrude
+ * on our cache or tlb entries.
+ */
+
+struct exception_table_entry
+{
+ unsigned long insn, fixup;
+};
+
+extern int fixup_exception(struct pt_regs *regs);
+
+#define KERNEL_DS ((mm_segment_t) { ~0UL })
+#define USER_DS ((mm_segment_t) {TASK_SIZE - 1})
+
+#define get_ds() (KERNEL_DS)
+#define get_fs() (current_thread_info()->addr_limit)
+
+static inline void set_fs (mm_segment_t fs)
+{
+ current_thread_info()->addr_limit = fs;
+}
+
+#define segment_eq(a, b) ((a.seg) == (b.seg))
+
+#define __range_ok(addr, size) (size <= get_fs().seg && addr <= (get_fs().seg -size))
+
+#define access_ok(type, addr, size) \
+ __range_ok((unsigned long)addr, (unsigned long)size)
+/*
+ * Single-value transfer routines. They automatically use the right
+ * size if we just have the right pointer type. Note that the functions
+ * which read from user space (*get_*) need to take care not to leak
+ * kernel data even if the calling code is buggy and fails to check
+ * the return value. This means zeroing out the destination variable
+ * or buffer on error. Normally this is done out of line by the
+ * fixup code, but there are a few places where it intrudes on the
+ * main code path. When we only write to user space, there is no
+ * problem.
+ *
+ * The "__xxx" versions of the user access functions do not verify the
+ * address space - it must have been done previously with a separate
+ * "access_ok()" call.
+ *
+ * The "xxx_error" versions set the third argument to EFAULT if an
+ * error occurs, and leave it unchanged on success. Note that these
+ * versions are void (ie, don't return a value as such).
+ */
+
+extern int __get_user_1(void *);
+extern int __get_user_2(void *);
+extern int __get_user_4(void *);
+extern int __get_user_8(void *);
+extern int __get_user_bad(void);
+
+#define __get_user_x(__r2,__p,__e,__s,__i...) \
+ __asm__ __volatile__ ( \
+ __asmeq("%0", "$r0") __asmeq("%1", "$r2") \
+ "bal __get_user_" #__s \
+ : "=&r" (__e), "=r" (__r2) \
+ : "0" (__p) \
+ : __i, "cc")
+
+#define get_user(x,p) \
+ ({ \
+ const register typeof(*(p)) __user *__p asm("$r0") = (p);\
+ register unsigned long __r2 asm("$r2"); \
+ register int __e asm("$r0"); \
+ switch (sizeof(*(__p))) { \
+ case 1: \
+ __get_user_x(__r2, __p, __e, 1, "$lp"); \
+ break; \
+ case 2: \
+ __get_user_x(__r2, __p, __e, 2, "$r3", "$lp"); \
+ break; \
+ case 4: \
+ __get_user_x(__r2, __p, __e, 4, "$lp"); \
+ break; \
+ case 8: \
+ __get_user_x(__r2, __p, __e, 8, "$lp"); \
+ break; \
+ default: __e = __get_user_bad(); break; \
+ } \
+ x = (typeof(*(p))) __r2; \
+ __e; \
+ })
+
+#define __get_user(x,ptr) \
+({ \
+ long __gu_err = 0; \
+ __get_user_err((x),(ptr),__gu_err); \
+ __gu_err; \
+})
+
+#define __get_user_error(x,ptr,err) \
+({ \
+ __get_user_err((x),(ptr),err); \
+ (void) 0; \
+})
+
+#define __get_user_err(x,ptr,err) \
+do { \
+ unsigned long __gu_addr = (unsigned long)(ptr); \
+ unsigned long __gu_val; \
+ __chk_user_ptr(ptr); \
+ switch (sizeof(*(ptr))) { \
+ case 1: __get_user_asm_byte(__gu_val,__gu_addr,err); break; \
+ case 2: __get_user_asm_half(__gu_val,__gu_addr,err); break; \
+ case 4: __get_user_asm_word(__gu_val,__gu_addr,err); break; \
+ default: (__gu_val) = __get_user_bad(); \
+ } \
+ (x) = (__typeof__(*(ptr)))__gu_val; \
+} while (0)
+
+#define __get_user_asm_byte(x,addr,err) \
+ __asm__ __volatile__( \
+ "1: lbi %1,[%2]\n" \
+ "2:\n" \
+ " .section .fixup,\"ax\"\n" \
+ " .align 2\n" \
+ "3: move %0, %3\n" \
+ " move %1, #0\n" \
+ " b 2b\n" \
+ " .previous\n" \
+ " .section __ex_table,\"a\"\n" \
+ " .align 3\n" \
+ " .long 1b, 3b\n" \
+ " .previous" \
+ : "+r" (err), "=&r" (x) \
+ : "r" (addr), "i" (-EFAULT) \
+ : "cc")
+
+#ifndef __NDS32_EB__
+#define __get_user_asm_half(x,__gu_addr,err) \
+({ \
+ unsigned long __b1, __b2; \
+ __get_user_asm_byte(__b1, __gu_addr, err); \
+ __get_user_asm_byte(__b2, __gu_addr + 1, err); \
+ (x) = __b1 | (__b2 << 8); \
+})
+#else
+#define __get_user_asm_half(x,__gu_addr,err) \
+({ \
+ unsigned long __b1, __b2; \
+ __get_user_asm_byte(__b1, __gu_addr, err); \
+ __get_user_asm_byte(__b2, __gu_addr + 1, err); \
+ (x) = (__b1 << 8) | __b2; \
+})
+#endif
+
+#define __get_user_asm_word(x,addr,err) \
+ __asm__ __volatile__( \
+ "1: lwi %1,[%2]\n" \
+ "2:\n" \
+ " .section .fixup,\"ax\"\n" \
+ " .align 2\n" \
+ "3: move %0, %3\n" \
+ " move %1, #0\n" \
+ " b 2b\n" \
+ " .previous\n" \
+ " .section __ex_table,\"a\"\n" \
+ " .align 3\n" \
+ " .long 1b, 3b\n" \
+ " .previous" \
+ : "+r" (err), "=&r" (x) \
+ : "r" (addr), "i" (-EFAULT) \
+ : "cc")
+
+extern int __put_user_1(void *, unsigned int);
+extern int __put_user_2(void *, unsigned int);
+extern int __put_user_4(void *, unsigned int);
+extern int __put_user_8(void *, unsigned long long);
+extern int __put_user_bad(void);
+
+#ifdef _GCC444
+#define __put_user_x(__r2,__p,__e,__s) \
+ __asm__ __volatile__ ( \
+ __asmeq("%0", "$r0") __asmeq("%2", "$r2") \
+ "bal __put_user_" #__s \
+ : "=&r" (__e) \
+ : "0" (__p), "r" (__r2) \
+ : "$p0", "$lp", "cc")
+#else
+#define __put_user_x(__r2,__p,__e,__s) \
+ __asm__ __volatile__ ( \
+ __asmeq("%0", "$r0") __asmeq("%2", "$r2") \
+ "bal __put_user_" #__s \
+ : "=&r" (__e) \
+ : "0" (__p), "r" (__r2) \
+ : "$r26", "$lp", "cc")
+#endif
+
+#define put_user(x,p) \
+ ({ \
+ const register typeof(*(p)) __r2 asm("$r2") = (x); \
+ const register typeof(*(p)) __user *__p asm("$r0") = (p);\
+ register int __e asm("$r0"); \
+ switch (sizeof(*(__p))) { \
+ case 1: \
+ __put_user_x(__r2, __p, __e, 1); \
+ break; \
+ case 2: \
+ __put_user_x(__r2, __p, __e, 2); \
+ break; \
+ case 4: \
+ __put_user_x(__r2, __p, __e, 4); \
+ break; \
+ case 8: \
+ __put_user_x(__r2, __p, __e, 8); \
+ break; \
+ default: __e = __put_user_bad(); break; \
+ } \
+ __e; \
+ })
+
+#define __put_user(x,ptr) \
+({ \
+ long __pu_err = 0; \
+ __put_user_err((x),(ptr),__pu_err); \
+ __pu_err; \
+})
+
+#define __put_user_error(x,ptr,err) \
+({ \
+ __put_user_err((x),(ptr),err); \
+ (void) 0; \
+})
+
+#define __put_user_err(x,ptr,err) \
+do { \
+ unsigned long __pu_addr = (unsigned long)(ptr); \
+ __typeof__(*(ptr)) __pu_val = (x); \
+ __chk_user_ptr(ptr); \
+ switch (sizeof(*(ptr))) { \
+ case 1: __put_user_asm_byte(__pu_val,__pu_addr,err); break; \
+ case 2: __put_user_asm_half(__pu_val,__pu_addr,err); break; \
+ case 4: __put_user_asm_word(__pu_val,__pu_addr,err); break; \
+ case 8: __put_user_asm_dword(__pu_val,__pu_addr,err); break; \
+ default: __put_user_bad(); \
+ } \
+} while (0)
+
+#define __put_user_asm_byte(x,__pu_addr,err) \
+ __asm__ __volatile__( \
+ "1: sbi %1,[%2]\n" \
+ "2:\n" \
+ " .section .fixup,\"ax\"\n" \
+ " .align 2\n" \
+ "3: move %0, %3\n" \
+ " b 2b\n" \
+ " .previous\n" \
+ " .section __ex_table,\"a\"\n" \
+ " .align 3\n" \
+ " .long 1b, 3b\n" \
+ " .previous" \
+ : "+r" (err) \
+ : "r" (x), "r" (__pu_addr), "i" (-EFAULT) \
+ : "cc")
+
+#ifndef __NDS32_EB__
+#define __put_user_asm_half(x,__pu_addr,err) \
+({ \
+ unsigned long __temp = (unsigned long)(x); \
+ __put_user_asm_byte(__temp, __pu_addr, err); \
+ __put_user_asm_byte(__temp >> 8, __pu_addr + 1, err); \
+})
+#else
+#define __put_user_asm_half(x,__pu_addr,err) \
+({ \
+ unsigned long __temp = (unsigned long)(x); \
+ __put_user_asm_byte(__temp >> 8, __pu_addr, err); \
+ __put_user_asm_byte(__temp, __pu_addr + 1, err); \
+})
+#endif
+
+#define __put_user_asm_word(x,__pu_addr,err) \
+ __asm__ __volatile__( \
+ "1: swi %1,[%2]\n" \
+ "2:\n" \
+ " .section .fixup,\"ax\"\n" \
+ " .align 2\n" \
+ "3: move %0, %3\n" \
+ " b 2b\n" \
+ " .previous\n" \
+ " .section __ex_table,\"a\"\n" \
+ " .align 3\n" \
+ " .long 1b, 3b\n" \
+ " .previous" \
+ : "+r" (err) \
+ : "r" (x), "r" (__pu_addr), "i" (-EFAULT) \
+ : "cc")
+
+#ifdef __NDS32_EB__
+#define __reg_oper0 "%H2"
+#define __reg_oper1 "%L2"
+#else
+#define __reg_oper0 "%L2"
+#define __reg_oper1 "%H2"
+#endif
+
+#define __put_user_asm_dword(x, __pu_addr, __pu_err) \
+ __asm__ __volatile__ ( \
+ "\n1:\tswi " __reg_oper0 ",[%1]\n" \
+ "\n2:\tswi " __reg_oper1 ",[%1+4]\n" \
+ "3:\n" \
+ " .section .fixup,\"ax\"\n" \
+ " .align 2\n" \
+ "4: move %0, %3\n" \
+ " b 3b\n" \
+ " .previous\n" \
+ " .section __ex_table,\"a\"\n" \
+ " .align 3\n" \
+ " .long 1b, 4b\n" \
+ " .long 2b, 4b\n" \
+ " .previous" \
+ : "+r"(__pu_err) \
+ : "r"(__pu_addr), "r"(x), "i"(-EFAULT) \
+ : "cc")
+extern unsigned long __arch_copy_from_user(void *to, const void __user *from, unsigned long n);
+extern unsigned long __arch_copy_to_user(void __user *to, const void *from, unsigned long n);
+extern unsigned long __arch_clear_user(void __user *addr, unsigned long n);
+extern unsigned long __arch_strncpy_from_user(char *to, const char __user *from, unsigned long count);
+extern unsigned long __arch_strnlen_user(const char __user *s, long n);
+
+static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
+{
+ if (access_ok(VERIFY_READ, from, n))
+ n = __arch_copy_from_user(to, from, n);
+ else /* security hole - plug it */
+ memzero(to, n);
+ return n;
+}
+
+static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
+{
+ return __arch_copy_from_user(to, from, n);
+}
+
+static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
+{
+ if (access_ok(VERIFY_WRITE, to, n))
+ n = __arch_copy_to_user(to, from, n);
+ return n;
+}
+
+static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
+{
+ return __arch_copy_to_user(to, from, n);
+}
+
+#define __copy_to_user_inatomic __copy_to_user
+#define __copy_from_user_inatomic __copy_from_user
+
+static inline unsigned long clear_user (void __user *to, unsigned long n)
+{
+ if (access_ok(VERIFY_WRITE, to, n))
+ n = __arch_clear_user(to, n);
+ return n;
+}
+
+static inline unsigned long __clear_user (void __user *to, unsigned long n)
+{
+ return __arch_clear_user(to, n);
+}
+
+/*
+ * We check the flags of vma here before __arch_strncpy_from_user().
+ * An alternative way to do it is using lwup instruction in __arch_strncpy_from_user().
+ * TODO: Should perform performance evaluation of the two.
+ */
+static inline long strncpy_from_user (char *dst, const char __user *src, long count)
+{
+ long res = -EFAULT;
+ if (access_ok(VERIFY_READ, src, 1))
+ res = __arch_strncpy_from_user(dst, src, count);
+ return res;
+}
+
+static inline long __strncpy_from_user (char *dst, const char __user *src, long count)
+{
+ return __arch_strncpy_from_user(dst, src, count);
+}
+
+#define strlen_user(s) strnlen_user(s, ~0UL >> 1)
+
+static inline long strnlen_user(const char __user *s, long n)
+{
+ unsigned long res = 0;
+
+ if (segment_eq(get_fs(),KERNEL_DS) || ((unsigned long)s < get_fs().seg))
+ res = __arch_strnlen_user(s, n);
+
+ return res;
+}
+#endif /* _ASMNDS32_UACCESS_H */
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/ucontext.h linux-3.4.113/arch/nds32/include/asm/ucontext.h
--- linux-3.4.113.orig/arch/nds32/include/asm/ucontext.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/ucontext.h 2016-12-01 20:59:24.348612597 +0100
@@ -0,0 +1,17 @@
+/*
+ * linux/arch/nds32/include/asm/ucontext.h
+ * Copyright (C) 2008 Andes Technology Corporation
+ */
+
+#ifndef _ASMNDS32_UCONTEXT_H
+#define _ASMNDS32_UCONTEXT_H
+
+struct ucontext {
+ unsigned long uc_flags;
+ struct ucontext *uc_link;
+ stack_t uc_stack;
+ struct sigcontext uc_mcontext;
+ sigset_t uc_sigmask; /* mask last for extensibility */
+};
+
+#endif /* !_ASMNDS32_UCONTEXT_H */
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/unaligned.h linux-3.4.113/arch/nds32/include/asm/unaligned.h
--- linux-3.4.113.orig/arch/nds32/include/asm/unaligned.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/unaligned.h 2016-12-01 20:59:24.348612597 +0100
@@ -0,0 +1,24 @@
+/*
+ * linux/arch/nds32/include/asm/unaligned.h
+ * Copyright (C) 2008 Andes Technology Corporation
+ */
+
+#ifndef __ASM_NDS32_UNALIGNED_H
+#define __ASM_NDS32_UNALIGNED_H
+
+#include <linux/unaligned/le_byteshift.h>
+#include <linux/unaligned/be_byteshift.h>
+#include <linux/unaligned/generic.h>
+
+/*
+ * Select endianness
+ */
+#if defined(__NDS32_EB__)
+#define get_unaligned __get_unaligned_be
+#define put_unaligned __put_unaligned_be
+#else
+#define get_unaligned __get_unaligned_le
+#define put_unaligned __put_unaligned_le
+#endif
+
+#endif /* __ASM_NDS32_UNALIGNED_H */
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/uncompress.h linux-3.4.113/arch/nds32/include/asm/uncompress.h
--- linux-3.4.113.orig/arch/nds32/include/asm/uncompress.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/uncompress.h 2016-12-01 20:59:24.348612597 +0100
@@ -0,0 +1,65 @@
+/*
+ * linux/arch/nds32/include/asm/uncompress.h
+ *
+ * Faraday Linux Boot Loader UART (FTUART010) Routines
+ *
+ * Copyright (C) 2005 Faraday Corp. (http://www.faraday-tech.com)
+ * Copyright (C) 2008 Andes Technology Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Note
+ *
+ * The first UART (FTUART010) in the system is used for dumping debug messages.
+ *
+ * ChangeLog
+ *
+ * Luke Lee 09/21/2005 Created. Heavily modified from Faraday CPE port.
+ */
+
+#include <asm/spec.h>
+
+#ifdef CONFIG_PLAT_AG102
+#define UART_PA_BASE 0x94200000
+#else
+#define UART_PA_BASE 0x99600000
+#endif
+
+#define arch_decomp_setup()
+#define arch_decomp_wdog()
+
+#ifndef STANDALONE_DEBUG
+#define putstr debug_puts
+#endif
+
+#define SERIAL_THR 0x00
+#define SERIAL_LSR 0x14
+#define SERIAL_LSR_THRE 0x20
+
+static inline void uncompress_puts(const char *s)
+{
+ volatile unsigned *status = (volatile unsigned *)(UART_PA_BASE+SERIAL_LSR);
+ while (*s) {
+ while ((*status & SERIAL_LSR_THRE)==0);
+
+ *(volatile unsigned*)(UART_PA_BASE+SERIAL_THR) = (unsigned)*s;
+
+ if (*s == '\n') {
+ while ((*status & SERIAL_LSR_THRE)==0);
+ *(volatile unsigned*)(UART_PA_BASE+SERIAL_THR) = '\r';
+ }
+ s++;
+ }
+}
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/unistd.h linux-3.4.113/arch/nds32/include/asm/unistd.h
--- linux-3.4.113.orig/arch/nds32/include/asm/unistd.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/unistd.h 2016-12-01 20:59:24.348612597 +0100
@@ -0,0 +1,468 @@
+/*
+ * linux/arch/nds32/include/asm/unistd.h
+ *
+ * Copyright (C) 2001-2003 Russell King
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Please forward _all_ changes to this file to rmk@arm.linux.org.uk,
+ * no matter what the change is. Thanks!
+ */
+/* ============================================================================
+ *
+ * linux/arch/nds32/include/asm/unistd.h
+ *
+ * Copyright (C) 2007 Andes Technology Corporation
+ * This file is part of Linux and should be licensed under the GPL.
+ * See the file COPYING for conditions for redistribution.
+ *
+ * Abstract:
+ *
+ * This program is syscall scheme for Andes NDS32 architecture.
+ *
+ * Revision History:
+ *
+ * Jul.07.2007 Original from Shawn and Tom, refined by Harry.
+ *
+ * Note:
+ *
+ * ============================================================================
+ */
+
+#ifndef __ASM_NDS32_UNISTD_H
+#define __ASM_NDS32_UNISTD_H
+
+#define __NR_SYSCALL_BASE 0x5000
+#define __NR_NDS32_BASE 0x7000
+/*
+ * This file contains the system call numbers.
+ */
+
+#define __NR_restart_syscall (__NR_SYSCALL_BASE+ 0)
+#define __NR_exit (__NR_SYSCALL_BASE+ 1)
+#define __NR_fork (__NR_SYSCALL_BASE+ 2)
+#define __NR_read (__NR_SYSCALL_BASE+ 3)
+#define __NR_write (__NR_SYSCALL_BASE+ 4)
+#define __NR_open (__NR_SYSCALL_BASE+ 5)
+#define __NR_close (__NR_SYSCALL_BASE+ 6)
+#define __NR_waitpid (__NR_SYSCALL_BASE+ 7)
+ /* 7 was sys_waitpid */
+#define __NR_creat (__NR_SYSCALL_BASE+ 8)
+#define __NR_link (__NR_SYSCALL_BASE+ 9)
+#define __NR_unlink (__NR_SYSCALL_BASE+ 10)
+#define __NR_execve (__NR_SYSCALL_BASE+ 11)
+#define __NR_chdir (__NR_SYSCALL_BASE+ 12)
+#define __NR_time (__NR_SYSCALL_BASE+ 13)
+#define __NR_mknod (__NR_SYSCALL_BASE+ 14)
+#define __NR_chmod (__NR_SYSCALL_BASE+ 15)
+#define __NR_lchown (__NR_SYSCALL_BASE+ 16)
+ /* 17 was sys_break */
+ /* 18 was sys_oldstat */
+#define __NR_lseek (__NR_SYSCALL_BASE+ 19)
+#define __NR_getpid (__NR_SYSCALL_BASE+ 20)
+#define __NR_mount (__NR_SYSCALL_BASE+ 21)
+#define __NR_umount (__NR_SYSCALL_BASE+ 22)
+#define __NR_setuid (__NR_SYSCALL_BASE+ 23)
+#define __NR_getuid (__NR_SYSCALL_BASE+ 24)
+#define __NR_stime (__NR_SYSCALL_BASE+ 25)
+#define __NR_ptrace (__NR_SYSCALL_BASE+ 26)
+#define __NR_alarm (__NR_SYSCALL_BASE+ 27)
+ /* 28 was sys_oldfstat */
+#define __NR_pause (__NR_SYSCALL_BASE+ 29)
+#define __NR_utime (__NR_SYSCALL_BASE+ 30)
+ /* 31 was sys_stty */
+ /* 32 was sys_gtty */
+#define __NR_access (__NR_SYSCALL_BASE+ 33)
+#define __NR_nice (__NR_SYSCALL_BASE+ 34)
+ /* 35 was sys_ftime */
+#define __NR_sync (__NR_SYSCALL_BASE+ 36)
+#define __NR_kill (__NR_SYSCALL_BASE+ 37)
+#define __NR_rename (__NR_SYSCALL_BASE+ 38)
+#define __NR_mkdir (__NR_SYSCALL_BASE+ 39)
+#define __NR_rmdir (__NR_SYSCALL_BASE+ 40)
+#define __NR_dup (__NR_SYSCALL_BASE+ 41)
+#define __NR_pipe (__NR_SYSCALL_BASE+ 42)
+#define __NR_times (__NR_SYSCALL_BASE+ 43)
+ /* 44 was sys_prof */
+#define __NR_brk (__NR_SYSCALL_BASE+ 45)
+#define __NR_setgid (__NR_SYSCALL_BASE+ 46)
+#define __NR_getgid (__NR_SYSCALL_BASE+ 47)
+ /* 48 was sys_signal */
+#define __NR_geteuid (__NR_SYSCALL_BASE+ 49)
+#define __NR_getegid (__NR_SYSCALL_BASE+ 50)
+#define __NR_acct (__NR_SYSCALL_BASE+ 51)
+#define __NR_umount2 (__NR_SYSCALL_BASE+ 52)
+ /* 53 was sys_lock */
+#define __NR_ioctl (__NR_SYSCALL_BASE+ 54)
+#define __NR_fcntl (__NR_SYSCALL_BASE+ 55)
+ /* 56 was sys_mpx */
+#define __NR_setpgid (__NR_SYSCALL_BASE+ 57)
+ /* 58 was sys_ulimit */
+ /* 59 was sys_olduname */
+#define __NR_umask (__NR_SYSCALL_BASE+ 60)
+#define __NR_chroot (__NR_SYSCALL_BASE+ 61)
+#define __NR_ustat (__NR_SYSCALL_BASE+ 62)
+#define __NR_dup2 (__NR_SYSCALL_BASE+ 63)
+#define __NR_getppid (__NR_SYSCALL_BASE+ 64)
+#define __NR_getpgrp (__NR_SYSCALL_BASE+ 65)
+#define __NR_setsid (__NR_SYSCALL_BASE+ 66)
+#define __NR_sigaction (__NR_SYSCALL_BASE+ 67)
+ /* 68 was sys_sgetmask */
+ /* 69 was sys_ssetmask */
+#define __NR_setreuid (__NR_SYSCALL_BASE+ 70)
+#define __NR_setregid (__NR_SYSCALL_BASE+ 71)
+#define __NR_sigsuspend (__NR_SYSCALL_BASE+ 72)
+#define __NR_sigpending (__NR_SYSCALL_BASE+ 73)
+#define __NR_sethostname (__NR_SYSCALL_BASE+ 74)
+#define __NR_setrlimit (__NR_SYSCALL_BASE+ 75)
+#define __NR_getrlimit (__NR_SYSCALL_BASE+ 76) /* Back compat 2GB limited rlimit */
+#define __NR_getrusage (__NR_SYSCALL_BASE+ 77)
+#define __NR_gettimeofday (__NR_SYSCALL_BASE+ 78)
+#define __NR_settimeofday (__NR_SYSCALL_BASE+ 79)
+#define __NR_getgroups (__NR_SYSCALL_BASE+ 80)
+#define __NR_setgroups (__NR_SYSCALL_BASE+ 81)
+#define __NR_select (__NR_SYSCALL_BASE+ 82)
+#define __NR_symlink (__NR_SYSCALL_BASE+ 83)
+ /* 84 was sys_lstat */
+#define __NR_readlink (__NR_SYSCALL_BASE+ 85)
+#define __NR_uselib (__NR_SYSCALL_BASE+ 86)
+#define __NR_swapon (__NR_SYSCALL_BASE+ 87)
+#define __NR_reboot (__NR_SYSCALL_BASE+ 88)
+#define __NR_readdir (__NR_SYSCALL_BASE+ 89)
+#define __NR_mmap (__NR_SYSCALL_BASE+ 90)
+#define __NR_munmap (__NR_SYSCALL_BASE+ 91)
+#define __NR_truncate (__NR_SYSCALL_BASE+ 92)
+#define __NR_ftruncate (__NR_SYSCALL_BASE+ 93)
+#define __NR_fchmod (__NR_SYSCALL_BASE+ 94)
+#define __NR_fchown (__NR_SYSCALL_BASE+ 95)
+#define __NR_getpriority (__NR_SYSCALL_BASE+ 96)
+#define __NR_setpriority (__NR_SYSCALL_BASE+ 97)
+ /* 98 was sys_profil */
+#define __NR_statfs (__NR_SYSCALL_BASE+ 99)
+#define __NR_fstatfs (__NR_SYSCALL_BASE+100)
+ /* 101 was sys_ioperm */
+#define __NR_socketcall (__NR_SYSCALL_BASE+102)
+#define __NR_syslog (__NR_SYSCALL_BASE+103)
+#define __NR_setitimer (__NR_SYSCALL_BASE+104)
+#define __NR_getitimer (__NR_SYSCALL_BASE+105)
+#define __NR_stat (__NR_SYSCALL_BASE+106)
+#define __NR_lstat (__NR_SYSCALL_BASE+107)
+#define __NR_fstat (__NR_SYSCALL_BASE+108)
+ /* 109 was sys_uname */
+ /* 110 was sys_iopl */
+#define __NR_vhangup (__NR_SYSCALL_BASE+111)
+ /* 112 was sys_idle */
+#define __NR_syscall (__NR_SYSCALL_BASE+113) /* syscall to call a syscall! */
+#define __NR_wait4 (__NR_SYSCALL_BASE+114)
+#define __NR_swapoff (__NR_SYSCALL_BASE+115)
+#define __NR_sysinfo (__NR_SYSCALL_BASE+116)
+#define __NR_ipc (__NR_SYSCALL_BASE+117)
+#define __NR_fsync (__NR_SYSCALL_BASE+118)
+#define __NR_sigreturn (__NR_SYSCALL_BASE+119)
+#define __NR_clone (__NR_SYSCALL_BASE+120)
+#define __NR_setdomainname (__NR_SYSCALL_BASE+121)
+#define __NR_uname (__NR_SYSCALL_BASE+122)
+ /* 123 was sys_modify_ldt */
+#define __NR_adjtimex (__NR_SYSCALL_BASE+124)
+#define __NR_mprotect (__NR_SYSCALL_BASE+125)
+#define __NR_sigprocmask (__NR_SYSCALL_BASE+126)
+ /* 127 was sys_create_module */
+#define __NR_init_module (__NR_SYSCALL_BASE+128)
+#define __NR_delete_module (__NR_SYSCALL_BASE+129)
+ /* 130 was sys_get_kernel_syms */
+#define __NR_quotactl (__NR_SYSCALL_BASE+131)
+#define __NR_getpgid (__NR_SYSCALL_BASE+132)
+#define __NR_fchdir (__NR_SYSCALL_BASE+133)
+#define __NR_bdflush (__NR_SYSCALL_BASE+134)
+#define __NR_sysfs (__NR_SYSCALL_BASE+135)
+#define __NR_personality (__NR_SYSCALL_BASE+136)
+ /* 137 was sys_afs_syscall */
+#define __NR_setfsuid (__NR_SYSCALL_BASE+138)
+#define __NR_setfsgid (__NR_SYSCALL_BASE+139)
+#define __NR__llseek (__NR_SYSCALL_BASE+140)
+#define __NR_getdents (__NR_SYSCALL_BASE+141)
+#define __NR__newselect (__NR_SYSCALL_BASE+142)
+#define __NR_flock (__NR_SYSCALL_BASE+143)
+#define __NR_msync (__NR_SYSCALL_BASE+144)
+#define __NR_readv (__NR_SYSCALL_BASE+145)
+#define __NR_writev (__NR_SYSCALL_BASE+146)
+#define __NR_getsid (__NR_SYSCALL_BASE+147)
+#define __NR_fdatasync (__NR_SYSCALL_BASE+148)
+#define __NR__sysctl (__NR_SYSCALL_BASE+149)
+#define __NR_mlock (__NR_SYSCALL_BASE+150)
+#define __NR_munlock (__NR_SYSCALL_BASE+151)
+#define __NR_mlockall (__NR_SYSCALL_BASE+152)
+#define __NR_munlockall (__NR_SYSCALL_BASE+153)
+#define __NR_sched_setparam (__NR_SYSCALL_BASE+154)
+#define __NR_sched_getparam (__NR_SYSCALL_BASE+155)
+#define __NR_sched_setscheduler (__NR_SYSCALL_BASE+156)
+#define __NR_sched_getscheduler (__NR_SYSCALL_BASE+157)
+#define __NR_sched_yield (__NR_SYSCALL_BASE+158)
+#define __NR_sched_get_priority_max (__NR_SYSCALL_BASE+159)
+#define __NR_sched_get_priority_min (__NR_SYSCALL_BASE+160)
+#define __NR_sched_rr_get_interval (__NR_SYSCALL_BASE+161)
+#define __NR_nanosleep (__NR_SYSCALL_BASE+162)
+#define __NR_mremap (__NR_SYSCALL_BASE+163)
+#define __NR_setresuid (__NR_SYSCALL_BASE+164)
+#define __NR_getresuid (__NR_SYSCALL_BASE+165)
+#define __NR_getpagesize (__NR_SYSCALL_BASE+166)
+ /* 167 was sys_query_module */
+#define __NR_poll (__NR_SYSCALL_BASE+168)
+#define __NR_nfsservctl (__NR_SYSCALL_BASE+169)
+#define __NR_setresgid (__NR_SYSCALL_BASE+170)
+#define __NR_getresgid (__NR_SYSCALL_BASE+171)
+#define __NR_prctl (__NR_SYSCALL_BASE+172)
+#define __NR_rt_sigreturn (__NR_SYSCALL_BASE+173)
+#define __NR_rt_sigaction (__NR_SYSCALL_BASE+174)
+#define __NR_rt_sigprocmask (__NR_SYSCALL_BASE+175)
+#define __NR_rt_sigpending (__NR_SYSCALL_BASE+176)
+#define __NR_rt_sigtimedwait (__NR_SYSCALL_BASE+177)
+#define __NR_rt_sigqueueinfo (__NR_SYSCALL_BASE+178)
+#define __NR_rt_sigsuspend (__NR_SYSCALL_BASE+179)
+#define __NR_pread64 (__NR_SYSCALL_BASE+180)
+#define __NR_pwrite64 (__NR_SYSCALL_BASE+181)
+#define __NR_chown (__NR_SYSCALL_BASE+182)
+#define __NR_getcwd (__NR_SYSCALL_BASE+183)
+#define __NR_capget (__NR_SYSCALL_BASE+184)
+#define __NR_capset (__NR_SYSCALL_BASE+185)
+#define __NR_sigaltstack (__NR_SYSCALL_BASE+186)
+#define __NR_sendfile (__NR_SYSCALL_BASE+187)
+ /* 188 reserved */
+ /* 189 reserved */
+#define __NR_vfork (__NR_SYSCALL_BASE+190)
+#define __NR_ugetrlimit (__NR_SYSCALL_BASE+191) /* SuS compliant getrlimit */
+#define __NR_mmap2 (__NR_SYSCALL_BASE+192)
+#define __NR_truncate64 (__NR_SYSCALL_BASE+193)
+#define __NR_ftruncate64 (__NR_SYSCALL_BASE+194)
+#define __NR_stat64 (__NR_SYSCALL_BASE+195)
+#define __NR_lstat64 (__NR_SYSCALL_BASE+196)
+#define __NR_fstat64 (__NR_SYSCALL_BASE+197)
+#define __NR_lchown32 (__NR_SYSCALL_BASE+198)
+#define __NR_getuid32 (__NR_SYSCALL_BASE+199)
+#define __NR_getgid32 (__NR_SYSCALL_BASE+200)
+#define __NR_geteuid32 (__NR_SYSCALL_BASE+201)
+#define __NR_getegid32 (__NR_SYSCALL_BASE+202)
+#define __NR_setreuid32 (__NR_SYSCALL_BASE+203)
+#define __NR_setregid32 (__NR_SYSCALL_BASE+204)
+#define __NR_getgroups32 (__NR_SYSCALL_BASE+205)
+#define __NR_setgroups32 (__NR_SYSCALL_BASE+206)
+#define __NR_fchown32 (__NR_SYSCALL_BASE+207)
+#define __NR_setresuid32 (__NR_SYSCALL_BASE+208)
+#define __NR_getresuid32 (__NR_SYSCALL_BASE+209)
+#define __NR_setresgid32 (__NR_SYSCALL_BASE+210)
+#define __NR_getresgid32 (__NR_SYSCALL_BASE+211)
+#define __NR_chown32 (__NR_SYSCALL_BASE+212)
+#define __NR_setuid32 (__NR_SYSCALL_BASE+213)
+#define __NR_setgid32 (__NR_SYSCALL_BASE+214)
+#define __NR_setfsuid32 (__NR_SYSCALL_BASE+215)
+#define __NR_setfsgid32 (__NR_SYSCALL_BASE+216)
+#define __NR_getdents64 (__NR_SYSCALL_BASE+217)
+#define __NR_pivot_root (__NR_SYSCALL_BASE+218)
+#define __NR_mincore (__NR_SYSCALL_BASE+219)
+#define __NR_madvise (__NR_SYSCALL_BASE+220)
+#define __NR_fcntl64 (__NR_SYSCALL_BASE+221)
+ /* 222 for tux */
+ /* 223 is unused */
+#define __NR_gettid (__NR_SYSCALL_BASE+224)
+#define __NR_readahead (__NR_SYSCALL_BASE+225)
+#define __NR_setxattr (__NR_SYSCALL_BASE+226)
+#define __NR_lsetxattr (__NR_SYSCALL_BASE+227)
+#define __NR_fsetxattr (__NR_SYSCALL_BASE+228)
+#define __NR_getxattr (__NR_SYSCALL_BASE+229)
+#define __NR_lgetxattr (__NR_SYSCALL_BASE+230)
+#define __NR_fgetxattr (__NR_SYSCALL_BASE+231)
+#define __NR_listxattr (__NR_SYSCALL_BASE+232)
+#define __NR_llistxattr (__NR_SYSCALL_BASE+233)
+#define __NR_flistxattr (__NR_SYSCALL_BASE+234)
+#define __NR_removexattr (__NR_SYSCALL_BASE+235)
+#define __NR_lremovexattr (__NR_SYSCALL_BASE+236)
+#define __NR_fremovexattr (__NR_SYSCALL_BASE+237)
+#define __NR_tkill (__NR_SYSCALL_BASE+238)
+#define __NR_sendfile64 (__NR_SYSCALL_BASE+239)
+#define __NR_futex (__NR_SYSCALL_BASE+240)
+#define __NR_sched_setaffinity (__NR_SYSCALL_BASE+241)
+#define __NR_sched_getaffinity (__NR_SYSCALL_BASE+242)
+#define __NR_io_setup (__NR_SYSCALL_BASE+243)
+#define __NR_io_destroy (__NR_SYSCALL_BASE+244)
+#define __NR_io_getevents (__NR_SYSCALL_BASE+245)
+#define __NR_io_submit (__NR_SYSCALL_BASE+246)
+#define __NR_io_cancel (__NR_SYSCALL_BASE+247)
+#define __NR_exit_group (__NR_SYSCALL_BASE+248)
+#define __NR_lookup_dcookie (__NR_SYSCALL_BASE+249)
+#define __NR_epoll_create (__NR_SYSCALL_BASE+250)
+#define __NR_epoll_ctl (__NR_SYSCALL_BASE+251)
+#define __NR_epoll_wait (__NR_SYSCALL_BASE+252)
+#define __NR_remap_file_pages (__NR_SYSCALL_BASE+253)
+ /* 254 for set_thread_area */
+ /* 255 for get_thread_area */
+#define __NR_set_tid_address (__NR_SYSCALL_BASE+256)
+#define __NR_timer_create (__NR_SYSCALL_BASE+257)
+#define __NR_timer_settime (__NR_SYSCALL_BASE+258)
+#define __NR_timer_gettime (__NR_SYSCALL_BASE+259)
+#define __NR_timer_getoverrun (__NR_SYSCALL_BASE+260)
+#define __NR_timer_delete (__NR_SYSCALL_BASE+261)
+#define __NR_clock_settime (__NR_SYSCALL_BASE+262)
+#define __NR_clock_gettime (__NR_SYSCALL_BASE+263)
+#define __NR_clock_getres (__NR_SYSCALL_BASE+264)
+#define __NR_clock_nanosleep (__NR_SYSCALL_BASE+265)
+#define __NR_statfs64 (__NR_SYSCALL_BASE+266)
+#define __NR_fstatfs64 (__NR_SYSCALL_BASE+267)
+#define __NR_tgkill (__NR_SYSCALL_BASE+268)
+#define __NR_utimes (__NR_SYSCALL_BASE+269)
+#define __NR_fadvise64_64 (__NR_SYSCALL_BASE+270)
+#define __NR_pciconfig_iobase (__NR_SYSCALL_BASE+271)
+#define __NR_pciconfig_read (__NR_SYSCALL_BASE+272)
+#define __NR_pciconfig_write (__NR_SYSCALL_BASE+273)
+#define __NR_mq_open (__NR_SYSCALL_BASE+274)
+#define __NR_mq_unlink (__NR_SYSCALL_BASE+275)
+#define __NR_mq_timedsend (__NR_SYSCALL_BASE+276)
+#define __NR_mq_timedreceive (__NR_SYSCALL_BASE+277)
+#define __NR_mq_notify (__NR_SYSCALL_BASE+278)
+#define __NR_mq_getsetattr (__NR_SYSCALL_BASE+279)
+#define __NR_waitid (__NR_SYSCALL_BASE+280)
+#define __NR_add_key (__NR_SYSCALL_BASE+281)
+#define __NR_request_key (__NR_SYSCALL_BASE+282)
+#define __NR_keyctl (__NR_SYSCALL_BASE+283)
+#define __NR_ioprio_set (__NR_SYSCALL_BASE+284)
+#define __NR_ioprio_get (__NR_SYSCALL_BASE+285)
+#define __NR_inotify_init (__NR_SYSCALL_BASE+286)
+#define __NR_inotify_add_watch (__NR_SYSCALL_BASE+287)
+#define __NR_inotify_rm_watch (__NR_SYSCALL_BASE+288)
+#define __NR_migrate_pages (__NR_SYSCALL_BASE+289)
+#define __NR_openat (__NR_SYSCALL_BASE+290)
+#define __NR_mkdirat (__NR_SYSCALL_BASE+291)
+#define __NR_mknodat (__NR_SYSCALL_BASE+292)
+#define __NR_fchownat (__NR_SYSCALL_BASE+293)
+#define __NR_futimesat (__NR_SYSCALL_BASE+294)
+#define __NR_fstatat64 (__NR_SYSCALL_BASE+295)
+#define __NR_unlinkat (__NR_SYSCALL_BASE+296)
+#define __NR_renameat (__NR_SYSCALL_BASE+297)
+#define __NR_linkat (__NR_SYSCALL_BASE+298)
+#define __NR_symlinkat (__NR_SYSCALL_BASE+299)
+#define __NR_readlinkat (__NR_SYSCALL_BASE+300)
+#define __NR_fchmodat (__NR_SYSCALL_BASE+301)
+#define __NR_faccessat (__NR_SYSCALL_BASE+302)
+#define __NR_pselect6 (__NR_SYSCALL_BASE+303)
+#define __NR_ppoll (__NR_SYSCALL_BASE+304)
+#define __NR_unshare (__NR_SYSCALL_BASE+305)
+#define __NR_set_robust_list (__NR_SYSCALL_BASE+306)
+#define __NR_get_robust_list (__NR_SYSCALL_BASE+307)
+#define __NR_splice (__NR_SYSCALL_BASE+308)
+#define __NR_sync_file_range2 (__NR_SYSCALL_BASE+309)
+#define __NR_tee (__NR_SYSCALL_BASE+310)
+#define __NR_vmsplice (__NR_SYSCALL_BASE+311)
+#define __NR_move_pages (__NR_SYSCALL_BASE+312)
+#define __NR_fadvise64 (__NR_SYSCALL_BASE+313)
+#define __NR_utimensat (__NR_SYSCALL_BASE+314)
+#define __NR_signalfd (__NR_SYSCALL_BASE+315)
+#define __NR_timerfd_create (__NR_SYSCALL_BASE+316)
+#define __NR_eventfd (__NR_SYSCALL_BASE+317)
+#define __NR_fallocate (__NR_SYSCALL_BASE+318)
+#define __NR_timerfd_settime (__NR_SYSCALL_BASE+319)
+#define __NR_timerfd_gettime (__NR_SYSCALL_BASE+320)
+#define __NR_getcpu (__NR_SYSCALL_BASE+321)
+#define __NR_signalfd4 (__NR_SYSCALL_BASE+322)
+#define __NR_eventfd2 (__NR_SYSCALL_BASE+323)
+#define __NR_epoll_create1 (__NR_SYSCALL_BASE+324)
+#define __NR_dup3 (__NR_SYSCALL_BASE+325)
+#define __NR_pipe2 (__NR_SYSCALL_BASE+326)
+#define __NR_inotify_init1 (__NR_SYSCALL_BASE+327)
+#define __NR_kexec_load (__NR_SYSCALL_BASE+328)
+#define __NR_accept (__NR_SYSCALL_BASE+329)
+#define __NR_bind (__NR_SYSCALL_BASE+330)
+#define __NR_connect (__NR_SYSCALL_BASE+331)
+#define __NR_getpeername (__NR_SYSCALL_BASE+332)
+#define __NR_getsockname (__NR_SYSCALL_BASE+333)
+#define __NR_getsockopt (__NR_SYSCALL_BASE+334)
+#define __NR_listen (__NR_SYSCALL_BASE+335)
+#define __NR_recv (__NR_SYSCALL_BASE+336)
+#define __NR_recvfrom (__NR_SYSCALL_BASE+337)
+#define __NR_recvmsg (__NR_SYSCALL_BASE+338)
+#define __NR_send (__NR_SYSCALL_BASE+339)
+#define __NR_sendmsg (__NR_SYSCALL_BASE+340)
+#define __NR_sendto (__NR_SYSCALL_BASE+341)
+#define __NR_setsockopt (__NR_SYSCALL_BASE+342)
+#define __NR_shutdown (__NR_SYSCALL_BASE+343)
+#define __NR_socket (__NR_SYSCALL_BASE+344)
+#define __NR_socketpair (__NR_SYSCALL_BASE+345)
+#define __NR_prlimit64 (__NR_SYSCALL_BASE+346)
+#define __NR_accept4 (__NR_SYSCALL_BASE+347)
+#define __NR_recvmmsg (__NR_SYSCALL_BASE+348)
+#define __NR_sendmmsg (__NR_SYSCALL_BASE+349)
+#define __NR_fanotify_init (__NR_SYSCALL_BASE+350)
+#define __NR_fanotify_mark (__NR_SYSCALL_BASE+351)
+#define __NR_msgget (__NR_SYSCALL_BASE+352)
+#define __NR_msgctl (__NR_SYSCALL_BASE+353)
+#define __NR_msgrcv (__NR_SYSCALL_BASE+354)
+#define __NR_msgsnd (__NR_SYSCALL_BASE+355)
+#define __NR_semget (__NR_SYSCALL_BASE+356)
+#define __NR_semctl (__NR_SYSCALL_BASE+357)
+#define __NR_semtimedop (__NR_SYSCALL_BASE+358)
+#define __NR_semop (__NR_SYSCALL_BASE+359)
+#define __NR_shmget (__NR_SYSCALL_BASE+360)
+#define __NR_shmctl (__NR_SYSCALL_BASE+361)
+#define __NR_shmat (__NR_SYSCALL_BASE+362)
+#define __NR_shmdt (__NR_SYSCALL_BASE+363)
+#define __NR_syncfs (__NR_SYSCALL_BASE+364)
+#define __NR_setns (__NR_SYSCALL_BASE+365)
+#define __NR_name_to_handle_at (__NR_SYSCALL_BASE+366)
+#define __NR_open_by_handle_at (__NR_SYSCALL_BASE+367)
+#define __NR_process_vm_readv (__NR_SYSCALL_BASE+368)
+#define __NR_process_vm_writev (__NR_SYSCALL_BASE+369)
+#define __NR_clock_adjtime (__NR_SYSCALL_BASE+370)
+#define __NR_get_mempolicy (__NR_SYSCALL_BASE+371)
+#define __NR_mbind (__NR_SYSCALL_BASE+372)
+#define __NR_perf_event_open (__NR_SYSCALL_BASE+373)
+#define __NR_preadv (__NR_SYSCALL_BASE+374)
+#define __NR_pwritev (__NR_SYSCALL_BASE+375)
+#define __NR_rt_tgsigqueueinfo (__NR_SYSCALL_BASE+376)
+#define __NR_set_mempolicy (__NR_SYSCALL_BASE+377)
+#define __NR_epoll_pwait (__NR_SYSCALL_BASE+378)
+
+
+
+
+#define __NR_lmmap (__NR_NDS32_BASE+ 1)
+#define __NR_lmunmap (__NR_NDS32_BASE+ 2)
+#define __NR_lmdma (__NR_NDS32_BASE+ 3)
+#define __NR_pfmctl (__NR_NDS32_BASE+ 4)
+#define __NR_getpfm (__NR_NDS32_BASE+ 5)
+#define __NR_setpfm (__NR_NDS32_BASE+ 6)
+#define __NR_wbna (__NR_NDS32_BASE+ 7)
+
+
+
+#ifdef __KERNEL__
+
+#define __ARCH_WANT_IPC_PARSE_VERSION
+#define __ARCH_WANT_OLD_READDIR
+#define __ARCH_WANT_STAT64
+#define __ARCH_WANT_SYS_ALARM
+#define __ARCH_WANT_SYS_GETHOSTNAME
+#define __ARCH_WANT_SYS_PAUSE
+#define __ARCH_WANT_SYS_TIME
+#define __ARCH_WANT_SYS_UTIME
+#define __ARCH_WANT_SYS_SOCKETCALL
+#define __ARCH_WANT_SYS_FADVISE64
+#define __ARCH_WANT_SYS_GETPGRP
+#define __ARCH_WANT_SYS_LLSEEK
+#define __ARCH_WANT_SYS_NICE
+#define __ARCH_WANT_SYS_OLD_GETRLIMIT
+#define __ARCH_WANT_SYS_OLD_MMAP
+#define __ARCH_WANT_SYS_OLDUMOUNT
+#define __ARCH_WANT_SYS_SIGPENDING
+#define __ARCH_WANT_SYS_SIGPROCMASK
+#define __ARCH_WANT_SYS_RT_SIGACTION
+
+/*
+ * "Conditional" syscalls
+ *
+ * What we want is __attribute__((weak,alias("sys_ni_syscall"))),
+ * but it doesn't work on all toolchains, so we just do it by hand
+ */
+#define cond_syscall(x) asm(".weak\t" #x "\n\t.set\t" #x ",sys_ni_syscall");
+
+#endif
+#endif /* __ASM_NDS32_UNISTD_H */
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/user.h linux-3.4.113/arch/nds32/include/asm/user.h
--- linux-3.4.113.orig/arch/nds32/include/asm/user.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/user.h 2016-12-01 20:59:24.348612597 +0100
@@ -0,0 +1,89 @@
+/*
+ * linux/arch/nds32/include/asm/user.h
+ * Copyright (C) 2008 Andes Technology Corporation
+ */
+
+#ifndef _NDS32_USER_H
+#define _NDS32_USER_H
+
+#include <asm/page.h>
+#include <asm/ptrace.h>
+/* Core file format: The core file is written in such a way that gdb
+ can understand it and provide useful information to the user (under
+ linux we use the 'trad-core' bfd). There are quite a number of
+ obstacles to being able to view the contents of the floating point
+ registers, and until these are solved you will not be able to view the
+ contents of them. Actually, you can read in the core file and look at
+ the contents of the user struct to find out what the floating point
+ registers contain.
+ The actual file contents are as follows:
+ UPAGE: 1 page consisting of a user struct that tells gdb what is present
+ in the file. Directly after this is a copy of the task_struct, which
+ is currently not used by gdb, but it may come in useful at some point.
+ All of the registers are stored as part of the upage. The upage should
+ always be only one page.
+ DATA: The data area is stored. We use current->end_text to
+ current->brk to pick up all of the user variables, plus any memory
+ that may have been malloced. No attempt is made to determine if a page
+ is demand-zero or if a page is totally unused, we just cover the entire
+ range. All of the addresses are rounded in such a way that an integral
+ number of pages is written.
+ STACK: We need the stack information in order to get a meaningful
+ backtrace. We need to write the data from (esp) to
+ current->start_stack, so we round each of these off in order to be able
+ to write an integer number of pages.
+ The minimum core file size is 3 pages, or 12288 bytes.
+*/
+
+struct user_fp {
+ struct fp_reg {
+ unsigned int sign1:1;
+ unsigned int unused:15;
+ unsigned int sign2:1;
+ unsigned int exponent:14;
+ unsigned int j:1;
+ unsigned int mantissa1:31;
+ unsigned int mantissa0:32;
+ } fpregs[8];
+ unsigned int fpsr:32;
+ unsigned int fpcr:32;
+ unsigned char ftype[8];
+ unsigned int init_flag;
+};
+
+/* When the kernel dumps core, it starts by dumping the user struct -
+ this will be used by gdb to figure out where the data and stack segments
+ are within the file, and what virtual addresses to use. */
+struct user{
+/* We start with the registers, to mimic the way that "memory" is returned
+ from the ptrace(3,...) function. */
+ struct pt_regs regs; /* Where the registers are actually stored */
+/* ptrace does not yet supply these. Someday.... */
+ int u_fpvalid; /* True if math co-processor being used. */
+ /* for this mess. Not yet used. */
+/* The rest of this junk is to help gdb figure out what goes where */
+ unsigned long int u_tsize; /* Text segment size (pages). */
+ unsigned long int u_dsize; /* Data segment size (pages). */
+ unsigned long int u_ssize; /* Stack segment size (pages). */
+ unsigned long start_code; /* Starting virtual address of text. */
+ unsigned long start_stack; /* Starting virtual address of stack area.
+ This is actually the bottom of the stack,
+ the top of the stack is always found in the
+ esp register. */
+ long int signal; /* Signal that caused the core dump. */
+ int reserved; /* No longer used */
+ struct pt_regs * u_ar0; /* Used by gdb to help find the values for */
+ /* the registers. */
+ unsigned long magic; /* To uniquely identify a core file */
+ char u_comm[32]; /* User command that was responsible */
+ int u_debugreg[8];
+ struct user_fp u_fp; /* FP state */
+ struct user_fp_struct * u_fp0;/* Used by gdb to help find the values for */
+ /* the FP registers. */
+};
+#define NBPG PAGE_SIZE
+#define UPAGES 1
+#define HOST_TEXT_START_ADDR (u.start_code)
+#define HOST_STACK_END_ADDR (u.start_stack + u.u_ssize * NBPG)
+
+#endif /* _NDS32_USER_H */
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/vga.h linux-3.4.113/arch/nds32/include/asm/vga.h
--- linux-3.4.113.orig/arch/nds32/include/asm/vga.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/vga.h 2016-12-01 20:59:24.348612597 +0100
@@ -0,0 +1,17 @@
+/*
+ * linux/arch/nds32/include/asm/vga.h
+ * Copyright (C) 2008 Andes Technology Corporation
+ */
+
+#ifndef ASMNDS32_VGA_H
+#define ASMNDS32_VGA_H
+
+#include <asm/hardware.h>
+#include <asm/io.h>
+
+#define VGA_MAP_MEM(x) (PCIMEM_BASE + (x))
+
+#define vga_readb(x) (*((volatile unsigned char *)x))
+#define vga_writeb(x,y) (*((volatile unsigned char *)y) = (x))
+
+#endif
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/vmalloc.h linux-3.4.113/arch/nds32/include/asm/vmalloc.h
--- linux-3.4.113.orig/arch/nds32/include/asm/vmalloc.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/vmalloc.h 2016-12-01 20:59:24.352612751 +0100
@@ -0,0 +1,31 @@
+/*
+ * linux/arch/nds32/include/asm/vmalloc.h
+ *
+ * Faraday Platform Independent Virtual Memory Configuration
+ *
+ * Copyright (C) 2005 Faraday Corp. (http://www.faraday-tech.com)
+ * Copyright (C) 2008 Andes Technology Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * ChangeLog
+ *
+ * Luke Lee 09/16/2005 Copy from Faraday CPE codes.
+ */
+
+#ifndef __FARADAY_PLATFORM_INDEPENDENT_VMALLOC_HEADER__
+#define __FARADAY_PLATFORM_INDEPENDENT_VMALLOC_HEADER__
+
+#endif /* __FARADAY_PLATFORM_INDEPENDENT_VMALLOC_HEADER__ */
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/xor.h linux-3.4.113/arch/nds32/include/asm/xor.h
--- linux-3.4.113.orig/arch/nds32/include/asm/xor.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/include/asm/xor.h 2016-12-01 20:59:24.352612751 +0100
@@ -0,0 +1,157 @@
+/*
+ * linux/arch/nds32/include/asm/xor.h
+ *
+ * Copyright (C) 2001 Russell King
+ * Copyright (C) 2008 Andes Technology Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+#include <asm-generic/xor.h>
+
+#define __XOR(a1, a2) a1 ^= a2
+
+
+#define GET_BLOCK_2(dst) \
+ __asm__( \
+ " lmw.bim %1, [%0], %2 \n"\
+ : "=r" (dst), "=r" (a1), "=r" (a2) \
+ : "0" (dst))
+
+#define GET_BLOCK_4(dst) \
+ __asm__( \
+ " lmw.bim %1, [%0], %1 \n" \ //ldmia %0, {%1, %2, %3, %4}
+ " lmw.bim %2, [%0], %2 \n" \
+ " lmw.bim %3, [%0], %3 \n" \
+ " lmw.bim %4, [%0], %4 \n" \
+ : "=r" (dst), "=r" (a1), "=r" (a2), "=r" (a3), "=r" (a4) \
+ : "0" (dst))
+
+#define XOR_BLOCK_2(src) \
+ __asm__(\
+ " lmw.bim %1, [%0], %2 \n " \
+ " lmw.bim %2, [%0], %2 \n" \
+ : "=r" (src), "=r" (b1), "=r" (b2) \
+ : "0" (src)); \
+ __XOR(a1, b1); __XOR(a2, b2);
+
+
+#define XOR_BLOCK_4(src) \
+ __asm__(\
+ "lmw.bim %1, [%0], %1 \n " \ // ldmia %0!, {%1, %2, %3, %4}
+ "lmw.bim %2, [%0], %2 \n " \
+ "lmw.bim %3, [%0], %3 \n " \
+ "lmw.bim %4, [%0], %4 \n " \
+ : "=r" (src), "=r" (b1), "=r" (b2), "=r" (b3), "=r" (b4) \
+ : "0" (src)); \
+ __XOR(a1, b1); __XOR(a2, b2); __XOR(a3, b3); __XOR(a4, b4)
+
+#define PUT_BLOCK_2(dst) \
+ __asm__ __volatile__( \
+ " smw.bim %2, [%0], %3" \
+ : "=r" (dst) \
+ : "0" (dst), "r" (a1), "r" (a2))
+
+#define PUT_BLOCK_4(dst) \
+ __asm__ __volatile__( \
+ " smw.bim %2, [%0], %5 \n" \
+ : "=r" (dst) \
+ : "0" (dst), "r" (a1), "r" (a2), "r" (a3), "r" (a4))
+
+static void
+xor_nds32regs_2(unsigned long bytes, unsigned long *p1, unsigned long *p2)
+{
+ unsigned int lines = bytes / sizeof(unsigned long) / 4;
+ register unsigned int a1 __asm__("r4");
+ register unsigned int a2 __asm__("r5");
+ register unsigned int a3 __asm__("r6");
+ register unsigned int a4 __asm__("r7");
+ register unsigned int b1 __asm__("r8");
+ register unsigned int b2 __asm__("r9");
+ register unsigned int b3 __asm__("p0");
+ register unsigned int b4 __asm__("ra");
+
+ do {
+ GET_BLOCK_4(p1);
+ XOR_BLOCK_4(p2);
+ PUT_BLOCK_4(p1);
+ } while (--lines);
+}
+
+static void
+xor_nds32regs_3(unsigned long bytes, unsigned long *p1, unsigned long *p2,
+ unsigned long *p3)
+{
+ unsigned int lines = bytes / sizeof(unsigned long) / 4;
+ register unsigned int a1 __asm__("r4");
+ register unsigned int a2 __asm__("r5");
+ register unsigned int a3 __asm__("r6");
+ register unsigned int a4 __asm__("r7");
+ register unsigned int b1 __asm__("r8");
+ register unsigned int b2 __asm__("r9");
+ register unsigned int b3 __asm__("p0");
+ register unsigned int b4 __asm__("ra");
+
+ do {
+ GET_BLOCK_4(p1);
+ XOR_BLOCK_4(p2);
+ XOR_BLOCK_4(p3);
+ PUT_BLOCK_4(p1);
+ } while (--lines);
+}
+
+static void
+xor_nds32regs_4(unsigned long bytes, unsigned long *p1, unsigned long *p2,
+ unsigned long *p3, unsigned long *p4)
+{
+ unsigned int lines = bytes / sizeof(unsigned long) / 2;
+ register unsigned int a1 __asm__("r8");
+ register unsigned int a2 __asm__("r9");
+ register unsigned int b1 __asm__("p0");
+ register unsigned int b2 __asm__("ra");
+
+ do {
+ GET_BLOCK_2(p1);
+ XOR_BLOCK_2(p2);
+ XOR_BLOCK_2(p3);
+ XOR_BLOCK_2(p4);
+ PUT_BLOCK_2(p1);
+ } while (--lines);
+}
+
+static void
+xor_nds32regs_5(unsigned long bytes, unsigned long *p1, unsigned long *p2,
+ unsigned long *p3, unsigned long *p4, unsigned long *p5)
+{
+ unsigned int lines = bytes / sizeof(unsigned long) / 2;
+ register unsigned int a1 __asm__("r8");
+ register unsigned int a2 __asm__("r9");
+ register unsigned int b1 __asm__("p0");
+ register unsigned int b2 __asm__("ra");
+
+ do {
+ GET_BLOCK_2(p1);
+ XOR_BLOCK_2(p2);
+ XOR_BLOCK_2(p3);
+ XOR_BLOCK_2(p4);
+ XOR_BLOCK_2(p5);
+ PUT_BLOCK_2(p1);
+ } while (--lines);
+}
+
+static struct xor_block_template xor_block_nds32regs = {
+ .name = "nds32regs",
+ .do_2 = xor_nds32regs_2,
+ .do_3 = xor_nds32regs_3,
+ .do_4 = xor_nds32regs_4,
+ .do_5 = xor_nds32regs_5,
+};
+
+#undef XOR_TRY_TEMPLATES
+#define XOR_TRY_TEMPLATES \
+ do { \
+ xor_speed(&xor_block_nds32regs); \
+ xor_speed(&xor_block_8regs); \
+ xor_speed(&xor_block_32regs); \
+ } while (0)
diff -Nur linux-3.4.113.orig/arch/nds32/Kconfig linux-3.4.113/arch/nds32/Kconfig
--- linux-3.4.113.orig/arch/nds32/Kconfig 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/Kconfig 2016-12-01 20:59:24.352612751 +0100
@@ -0,0 +1,249 @@
+#
+# For a description of the syntax of this configuration file,
+# see Documentation/kbuild/kconfig-language.txt.
+#
+
+config NDS32
+ bool
+ default y
+ select RTC_LIB
+ select HAVE_OPROFILE
+ select HAVE_ARCH_KGDB
+ select HAVE_KPROBES
+ select HAVE_KRETPROBES
+ select HAVE_FUNCTION_TRACER
+ select HAVE_FUNCTION_GRAPH_TRACER
+ select HAVE_FUNCTION_TRACE_MCOUNT_TEST
+ select SYS_SUPPORTS_APM_EMULATION
+ select HAVE_IDE
+ select HAVE_MEMBLOCK
+ select HAVE_MEMBLOCK_NODE_MAP
+
+config GENERIC_GPIO
+ bool
+ default n
+
+config GENERIC_TIME
+ bool
+ default y
+
+config GENERIC_CLOCKEVENTS
+ bool
+ default y
+
+config NO_IOPORT
+ bool
+ default y
+
+config GENERIC_IOMAP
+ def_bool y
+
+config GENERIC_LOCKBREAK
+ bool
+ default y
+ depends on SMP && PREEMPT
+
+config RWSEM_GENERIC_SPINLOCK
+ bool
+ default y
+
+config RWSEM_XCHGADD_ALGORITHM
+ bool
+
+config GENERIC_HWEIGHT
+ bool
+ default y
+
+config GENERIC_FIND_NEXT_BIT
+ bool
+ default y
+
+config GENERIC_CALIBRATE_DELAY
+ bool
+ default y
+
+config GENERIC_BUST_SPINLOCK
+ bool
+
+config GENERIC_HARDIRQS
+ bool
+ default y
+
+config GENERIC_HARDIRQS_NO__DO_IRQ
+ def_bool y
+
+config LOCKDEP_SUPPORT
+ bool
+ default y
+
+config STACKTRACE_SUPPORT
+ bool
+ default y
+
+config HAVE_LATENCYTOP_SUPPORT
+ def_bool y
+
+source "init/Kconfig"
+source "kernel/Kconfig.freezer"
+
+menu "System Type"
+source "arch/nds32/platforms/Kconfig"
+source "arch/nds32/Kconfig.cpu"
+
+config VECTORS_BASE
+ hex
+ default 0xfeff0000 if MMU || CPU_HIGH_VECTOR
+ default DRAM_BASE if REMAP_VECTORS_TO_RAM
+ default 0x00000000
+ help
+ The base address of exception vectors.
+
+config MMU
+ bool
+ default y
+
+endmenu
+
+menu "Kernel Features"
+source "kernel/time/Kconfig"
+
+config SMP
+ bool "Symmetric Multi-Processing"
+ depends on PLATFORM_AMIC
+ select USE_GENERIC_SMP_HELPERS
+ help
+ This enables support for systems with more than one CPU. If you have
+ a system with only one CPU, like most personal computers, say N. If
+ you have a system with more than one CPU, say Y.
+
+ If you say N here, the kernel will run on single and multiprocessor
+ machines, but will use only one CPU of a multiprocessor machine. If
+ you say Y here, the kernel will run on many, but not all, single
+ processor machines. On a single processor machine, the kernel will
+ run faster if you say N here.
+
+ See also the <file:Documentation/smp.tex>,
+ <file:Documentation/smp.txt>, <file:Documentation/i386/IO-APIC.txt>,
+ <file:Documentation/nmi_watchdog.txt> and the SMP-HOWTO available at
+ <http://www.linuxdoc.org/docs.html#howto>.
+
+ If you don't know what to do here, say N.
+
+config NR_CPUS
+ int "Maximum number of CPUs (2-32)"
+ depends on SMP
+ default "4"
+
+source "kernel/Kconfig.preempt"
+source "mm/Kconfig"
+
+config FORCE_MAX_ZONEORDER
+ int "MAX_ORDER for the Page Allocator"
+ default "11"
+
+source "kernel/Kconfig.hz"
+
+config CMDLINE
+ string "Default kernel command string"
+ default "mem=64M@0x0 initrd=0x800000,8M root=/dev/ram0 rw console=ttyS0,38400n8 rootfstype=ext2 init=/sbin/init -s"
+
+endmenu
+
+menu "Power management options"
+
+config SYS_SUPPORTS_APM_EMULATION
+ bool
+
+config ARCH_SUSPEND_POSSIBLE
+ def_bool y
+
+source "kernel/power/Kconfig"
+
+if PLAT_AG101 || PLAT_AG102
+source "drivers/cpufreq/Kconfig"
+
+if PLAT_AG101
+choice
+ prompt "Default CPUFreq Implementation"
+ depends on CPU_FREQ
+ default AG101_CPU_FREQ_SCALING_MODE
+ help
+ This option sets which CPUFreq governor shall be loaded at
+ startup. If in doubt, select 'performance'.
+config AG101_CPU_FREQ_SCALING_MODE
+ bool "AG101 Frequency Scaling Mode"
+ help
+ Rescale CPU frequency and Bus clock without changing PLL.
+
+config AG101_CPU_FREQ_FCS
+ bool "AG101 Frequency Change Sequence (FCS)"
+ help
+ The Frequency Change Sequence (FCS) is used to change the system
+ clock frequency. While in the FCS, the system clocks stop. This
+ mode is intended for setting a different frequency to overwrite
+ the default value at initial boot-up. This can be used as a powr-
+ saving feature that allows the AG101 to run at the minimum required
+ frequency
+endchoice
+endif
+
+if PLAT_AG102
+choice
+ prompt "Default CPUFreq Implementation"
+ depends on CPU_FREQ
+ default AG102_CPU_FREQ_SCALING_MODE
+ help
+ This option sets which CPUFreq governor shall be loaded at
+ startup. If in doubt, select 'performance'.
+config AG102_CPU_FREQ_SCALING_MODE
+ bool "AG102 Frequency Scaling Mode"
+ help
+ Rescale CPU frequency and Bus clock without changing PLL.
+
+config AG102_CPU_FREQ_FCS
+ bool "AG102 Frequency Change Sequence (FCS)"
+ help
+ The Frequency Change Sequence (FCS) is used to change the system
+ clock frequency. While in the FCS, the system clocks stop. This
+ mode is intended for setting a different frequency to overwrite
+ the default value at initial boot-up. This can be used as a powr-
+ saving feature that allows the AG101 to run at the minimum required
+ frequency
+endchoice
+endif
+
+
+endif
+
+endmenu
+
+menu "Bus options"
+
+config PCI
+ bool "PCI support"
+ help
+ Find out whether you have a PCI motherboard. PCI is the name of a
+ bus system, i.e. the way the CPU talks to the other stuff inside
+ your box. Other bus systems are ISA, EISA, MicroChannel (MCA) or
+ VESA. If you have PCI, say Y, otherwise N.
+
+ The PCI-HOWTO, available from
+ <http://www.tldp.org/docs.html#howto>, contains valuable
+ information about which PCI hardware does work under Linux and which
+ doesn't.
+
+source "drivers/pci/Kconfig"
+
+endmenu
+
+menu "Executable file formats"
+source "fs/Kconfig.binfmt"
+endmenu
+
+source "net/Kconfig"
+source "drivers/Kconfig"
+source "fs/Kconfig"
+source "arch/nds32/Kconfig.debug"
+source "security/Kconfig"
+source "crypto/Kconfig"
+source "lib/Kconfig"
diff -Nur linux-3.4.113.orig/arch/nds32/Kconfig.cpu linux-3.4.113/arch/nds32/Kconfig.cpu
--- linux-3.4.113.orig/arch/nds32/Kconfig.cpu 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/Kconfig.cpu 2016-12-01 20:59:24.352612751 +0100
@@ -0,0 +1,148 @@
+comment "Processor Features"
+config CPU_N1213
+ bool
+
+config CPU_N1213_43U1HA0
+ bool
+
+config CPU_N1233F
+ bool
+
+config CPU_CUSTOM
+ bool
+
+config FPU
+ bool "fpu support"
+
+config UNLAZY_FPU
+ bool "Unlazy FPU support"
+ depends on FPU
+ help
+ Say Y here to enable unlazy FPU and disable lazy FPU.
+
+
+config AUDIO
+ bool "audio support" if CPU_CUSTOM
+
+config HWZOL
+ bool "hardware zero overhead loop support"
+ default y
+
+config UNLAZY_AUDIO
+ bool "Unlazy audio support"
+ depends on AUDIO
+ help
+ Say Y here to enable unlazy audio and disable lazy audio.
+choice
+ prompt "Vector Interrupt Controller mode"
+ default IVIC_INTC
+config IVIC_INTC
+ bool "IVIC mode with Interrupt Controller"
+config IVIC
+ bool "IVIC mode"
+config EVIC
+ bool "EVIC mode"
+endchoice
+
+config CPU_NO_CONTEXT_ID
+ def_bool CPU_N1213_43U1HA0 || SMP
+
+config CPU_CACHE_NONALIASING
+ bool "Non-aliasing cache"
+
+choice
+ prompt "Paging -- page size "
+ default ANDES_PAGE_SIZE_4KB
+config ANDES_PAGE_SIZE_4KB
+ bool "use 4KB page size"
+config ANDES_PAGE_SIZE_8KB
+ bool "use 8KB page size"
+endchoice
+
+config NO_KERNEL_LARGE_PAGE
+ def_bool CPU_N1213_43U1HA0 || SMP
+
+config CPU_ICACHE_DISABLE
+ bool "Disable I-Cache"
+ help
+ Say Y here to disable the processor instruction cache. Unless
+ you have a reason not to or are unsure, say N.
+
+config CPU_DCACHE_DISABLE
+ bool "Disable D-Cache"
+ help
+ Say Y here to disable the processor data cache. Unless
+ you have a reason not to or are unsure, say N.
+
+config CPU_DCACHE_WRITETHROUGH
+ bool "Force write through D-cache"
+ depends on !CPU_DCACHE_DISABLE
+ help
+ Say Y here to use the data cache in writethrough mode. Unless you
+ specifically require this or are unsure, say N.
+
+config KEXEC
+ bool "Kexec system call (EXPERIMENTAL)"
+ depends on EXPERIMENTAL
+ help
+ kexec is a system call that implements the ability to shutdown your
+ current kernel, and to start another kernel. It is like a reboot
+ but it is independent of the system firmware. And like a reboot
+ you can start any kernel with it, not just Linux.
+
+ It is an ongoing process to be certain the hardware in a machine
+ is properly shutdown, so do not be surprised if this code does not
+ initially work for you. It may help to enable device hotplugging
+ support.
+
+config ABI1
+ bool "Allow ABI 1 binaries to run with this kernel (EXPERIMENTAL)"
+ depends on EXPERIMENTAL
+ default n
+ help
+ This option preserves the old syscall interface of ABI 1. If
+ you know you'll be using ABI 2 or 2fp then you can say N here.
+ If this option is not selected and you attempt to execute a
+ legacy ABI binary then the result will be UNPREDICTABLE
+ (in fact it can be predicted that it won't work at all). If
+ in doubt say Y.
+
+config WBNA
+ bool "WBNA"
+ default n
+ help
+ Say Y here to enable write-back memory with no-write-allocation policy.
+
+config HSS
+ bool "Using Hardware Single-Step (HSS) instead of software breakpoint"
+ default y
+
+config ALIGNMENT_TRAP
+ tristate "Kernel support unaligned access handling"
+ depends on EXPERIMENTAL
+ default y
+ help
+ Andes processors cannot fetch/store information which is not
+ naturally aligned on the bus, i.e., a 4 byte fetch must start at an
+ address divisible by 4. On 32-bit Andes processors, these non-aligned
+ fetch/store instructions will be emulated in software if you say
+ here, which has a severe performance impact. This is necessary for
+ correct operation of some network protocols. With an IP-only
+ configuration it is safe to say N, otherwise say Y.
+
+config HIGHMEM
+ bool "High Memory Support"
+ depends on MMU
+ help
+ The address space of ARM processors is only 4 Gigabytes large
+ and it has to accommodate user address space, kernel address
+ space as well as some memory mapped IO. That means that, if you
+ have a large amount of physical memory and/or IO, not all of the
+ memory can be "permanently mapped" by the kernel. The physical
+ memory that is not permanently mapped is called "high memory".
+
+ Depending on the selected kernel/user memory split, minimum
+ vmalloc space and actual amount of RAM, you may not need this
+ option which should result in a slightly faster kernel.
+
+ If unsure, say n.
diff -Nur linux-3.4.113.orig/arch/nds32/Kconfig.debug linux-3.4.113/arch/nds32/Kconfig.debug
--- linux-3.4.113.orig/arch/nds32/Kconfig.debug 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/Kconfig.debug 2016-12-01 20:59:24.352612751 +0100
@@ -0,0 +1,82 @@
+menu "Kernel hacking"
+
+config TRACE_IRQFLAGS_SUPPORT
+ bool
+ default y
+
+source "lib/Kconfig.debug"
+
+config FRAME_POINTER
+ bool
+ default y
+ help
+ If you say N here, the resulting kernel will be slightly smaller and
+ faster. However, when a problem occurs with the kernel, the
+ information that is reported is severely limited. Most people
+ should say Y here.
+
+config DEBUG_USER
+ bool "Verbose user fault messages"
+ help
+ When a user program crashes due to an exception, the kernel can
+ print a brief message explaining what the problem was. This is
+ sometimes helpful for debugging but serves no purpose on a
+ production system. Most people should say N here.
+
+ In addition, you need to pass user_debug=N on the kernel command
+ line to enable this feature. N consists of the sum of:
+
+ 1 - undefined instruction events
+ 2 - system calls
+ 4 - invalid data aborts
+ 8 - SIGSEGV faults
+ 16 - SIGBUS faults
+
+config DEBUG_ERRORS
+ bool "Verbose kernel error messages"
+ depends on DEBUG_KERNEL
+ help
+ This option controls verbose debugging information which can be
+ printed when the kernel detects an internal error. This debugging
+ information is useful to kernel hackers when tracking down problems,
+ but mostly meaningless to other people. It's safe to say Y unless
+ you are concerned with the code size or don't want to see these
+ messages.
+
+config DEBUG_LL
+ bool "Kernel low-level debugging functions"
+ depends on DEBUG_KERNEL
+ help
+ Say Y here to include definitions of printascii, printchar, printhex
+ in the kernel. This is helpful if you are debugging code that
+ executes before the console is initialized.
+
+config CCTL
+ tristate "User space cache control support (EXPERIMENTAL)"
+ depends on EXPERIMENTAL
+ help
+ export cache control to user space via /proc
+
+ If unsure, say N.
+
+config ELFCHK_DEFAULT_ENABLE
+ bool "Enable ELF-Core Checking by default"
+ default n
+ select PROC_FS
+ help
+ ELF-Core Checking is a mechanism which prevents ELF binary from
+ being loaded if it requires any feature that the underlying platform
+ doesn't support.
+
+ If you say Y here, the resulting kernel enables ELF-Core Checking
+ mechanism by default.
+config EARLY_PRINTK
+ bool "Early printk support"
+ default y
+ help
+ Say Y here if you want to have an early console using the
+ earlyprintk=<name>[,<addr>][,<options>] kernel parameter. It
+ is assumed that the early console device has been initialised
+ by the boot loader prior to starting the Linux kernel.
+
+endmenu
diff -Nur linux-3.4.113.orig/arch/nds32/kernel/asm-offsets.c linux-3.4.113/arch/nds32/kernel/asm-offsets.c
--- linux-3.4.113.orig/arch/nds32/kernel/asm-offsets.c 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/kernel/asm-offsets.c 2016-12-01 20:59:24.352612751 +0100
@@ -0,0 +1,72 @@
+/*
+ * Copyright (C) 1995-2003 Russell King
+ * 2001-2002 Keith Owens
+ * Copyright (C) 2009 Andes Technology Corporation
+ *
+ * Generate definitions needed by assembly language modules.
+ * This code generates raw asm output which is post-processed to extract
+ * and format the required data.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+#include <linux/sched.h>
+#include <linux/mm.h>
+#include <asm/mach/arch.h>
+#include <asm/thread_info.h>
+#include <asm/memory.h>
+#include <asm/procinfo.h>
+
+/*
+ * Make sure that the compiler and target are compatible.
+ */
+
+#if __GNUC__ < 3 || \
+ (__GNUC__ == 3 && __GNUC_MINOR__ < 4) || \
+ (__GNUC__ == 3 && __GNUC_MINOR__ == 4 && __GNUC_PATCHLEVEL__ != 0 && \
+ __GNUC_PATCHLEVEL__ < 4) || \
+ (__GNUC__ == 4 && __GNUC_MINOR__ < 2)
+#error Your compiler is too buggy; it is known to miscompile kernels.
+#error Known good compilers: 3.4.4, 4.2
+#endif
+
+/* Use marker if you need to separate the values later */
+
+#define DEFINE(sym, val) \
+ asm volatile("\n->" #sym " %0 " #val : : "i" (val))
+
+#define BLANK() asm volatile("\n->" : : )
+
+int main(void)
+{
+ DEFINE(TSK_ACTIVE_MM, offsetof(struct task_struct, active_mm));
+ BLANK();
+ DEFINE(TI_FLAGS, offsetof(struct thread_info, flags));
+ DEFINE(TI_PREEMPT, offsetof(struct thread_info, preempt_count));
+ DEFINE(TI_ADDR_LIMIT, offsetof(struct thread_info, addr_limit));
+ DEFINE(TI_TASK, offsetof(struct thread_info, task));
+ DEFINE(TI_EXEC_DOMAIN, offsetof(struct thread_info, exec_domain));
+ DEFINE(TI_CPU, offsetof(struct thread_info, cpu));
+// DEFINE(TI_TP_VALUE, offsetof(struct thread_info, tp_value));
+ DEFINE(TI_SP_SAVE, offsetof(struct thread_info, sp_save));
+ BLANK();
+ DEFINE(S_FRAME_SIZE, sizeof(struct pt_regs));
+ BLANK();
+ DEFINE(MM_CONTEXT_ID, offsetof(struct mm_struct, context.id));
+ BLANK();
+ DEFINE(VMA_VM_MM, offsetof(struct vm_area_struct, vm_mm));
+ DEFINE(VMA_VM_FLAGS, offsetof(struct vm_area_struct, vm_flags));
+ BLANK();
+ DEFINE(VM_EXEC, VM_EXEC);
+ BLANK();
+ DEFINE(VIRT_OFFSET, PAGE_OFFSET);
+ BLANK();
+ DEFINE(SIZEOF_MACHINE_DESC, sizeof(struct machine_desc));
+ DEFINE(MACHINFO_TYPE, offsetof(struct machine_desc, nr));
+ DEFINE(MACHINFO_NAME, offsetof(struct machine_desc, name));
+ BLANK();
+ DEFINE(PROC_INFO_SZ, sizeof(struct proc_info_list));
+
+ return 0;
+}
diff -Nur linux-3.4.113.orig/arch/nds32/kernel/audio.c linux-3.4.113/arch/nds32/kernel/audio.c
--- linux-3.4.113.orig/arch/nds32/kernel/audio.c 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/kernel/audio.c 2016-12-01 20:59:24.352612751 +0100
@@ -0,0 +1,218 @@
+/*
+ * arch/nds32/kernel/audio.c
+ *
+ * Copyright (C) 2001 Manuela Cirronis, Paolo Alberelli
+ * Copyright (C) 2002 STMicroelectronics Limited
+ * Author : Stuart Menefy
+ * Copyright (C) 2009 Andes Technology Corporation
+ *
+ * Started from SH4 version:
+ * Copyright (C) 1999, 2000 Kaz Kojima & Niibe Yutaka
+ *
+ * This file is subject to the terms and conditions of the GNU General Public
+ * License. See the file "COPYING" in the main directory of this archive
+ * for more details.
+ */
+#include <linux/sched.h>
+#include <linux/signal.h>
+#include <asm/processor.h>
+#include <asm/user.h>
+#include <asm/io.h>
+#include <asm/bitfield.h>
+#include <asm/audio.h>
+#include "audio.h"
+/*
+ * Initially load the audio with signalling NANS. This bit pattern
+ * has the property that no matter whether considered as single or as
+ * double precision, it still represents a signalling NAN.
+ */
+
+static struct audio_struct init_audioregs = {
+ .auregs = {[0...31] = NAN32}
+};
+
+void save_audio(struct task_struct *tsk)
+{
+ unsigned int tmp;
+ enable_audio();
+ asm volatile ("mfsr %0, $MSC_CFG\n\t"
+ "andi %0, %0, %2\n\t"
+ "srli %0, %0, %3\n\t"
+ "slti %0, %0, 2\n\t"
+ "bnez %0, 99f\n\t"
+ "amfar %0, $D0.L24\n\t"
+ "swi %0, [%1+0x0]\n\t"
+ "amfar %0, $D1.L24\n\t"
+ "swi %0, [%1+0x4]\n\t"
+ "99:\n\t"
+ "amfar %0, $I0\n\t"
+ "swi %0, [%1+0x8]\n\t"
+ "amfar %0, $I1\n\t"
+ "swi %0, [%1+0xc]\n\t"
+ "amfar %0, $I2\n\t"
+ "swi %0, [%1+0x10]\n\t"
+ "amfar %0, $I3\n\t"
+ "swi %0, [%1+0x14]\n\t"
+ "amfar %0, $I4\n\t"
+ "swi %0, [%1+0x18]\n\t"
+ "amfar %0, $I5\n\t"
+ "swi %0, [%1+0x1c]\n\t"
+ "amfar %0, $I6\n\t"
+ "swi %0, [%1+0x20]\n\t"
+ "amfar %0, $I7\n\t"
+ "swi %0, [%1+0x24]\n\t"
+ "amfar %0, $M1\n\t"
+ "swi %0, [%1+0x28]\n\t"
+ "amfar %0, $M2\n\t"
+ "swi %0, [%1+0x2c]\n\t"
+ "amfar %0, $M3\n\t"
+ "swi %0, [%1+0x30]\n\t"
+ "amfar %0, $M5\n\t"
+ "swi %0, [%1+0x34]\n\t"
+ "amfar %0, $M6\n\t"
+ "swi %0, [%1+0x38]\n\t"
+ "amfar %0, $M7\n\t"
+ "swi %0, [%1+0x3c]\n\t"
+ "amfar %0, $MOD\n\t"
+ "swi %0, [%1+0x40]\n\t"
+ "amfar %0, $LB\n\t"
+ "swi %0, [%1+0x44]\n\t"
+ "amfar %0, $LE\n\t"
+ "swi %0, [%1+0x48]\n\t"
+ "amfar %0, $LC\n\t"
+ "swi %0, [%1+0x4c]\n\t"
+ "amfar %0, $ADM_VBASE\n\t"
+ "swi %0, [%1+0x50]\n\t"
+ "amfar %0, $SHFT_CTL0\n\t"
+ "swi %0, [%1+0x54]\n\t"
+ "amfar %0, $SHFT_CTL1\n\t"
+ "swi %0, [%1+0x58]\n\t"
+ "amfar2 %0, $CB_CTL\n\t"
+ "swi %0, [%1+0x5c]\n\t"
+ "amfar2 %0, $CBB0\n\t"
+ "swi %0, [%1+0x60]\n\t"
+ "amfar2 %0, $CBB1\n\t"
+ "swi %0, [%1+0x64]\n\t"
+ "amfar2 %0, $CBB2\n\t"
+ "swi %0, [%1+0x68]\n\t"
+ "amfar2 %0, $CBB3\n\t"
+ "swi %0, [%1+0x6c]\n\t"
+ "amfar2 %0, $CBE0\n\t"
+ "swi %0, [%1+0x70]\n\t"
+ "amfar2 %0, $CBE1\n\t"
+ "swi %0, [%1+0x74]\n\t"
+ "amfar2 %0, $CBE2\n\t"
+ "swi %0, [%1+0x78]\n\t"
+ "amfar2 %0, $CBE3\n\t"
+ "swi %0, [%1+0x7c]\n\t":"=&r" (tmp)
+ :"r"(&tsk->thread.audio), "i"(MSC_CFG_mskAUDIO),
+ "i"(MSC_CFG_offAUDIO)
+ :"memory");
+ disable_audio();
+}
+
+void audioload(struct audio_struct *audioregs)
+{
+ unsigned int tmp;
+ enable_audio();
+ asm volatile ("mfsr %0, $MSC_CFG\n\t"
+ "andi %0, %0, %2\n\t"
+ "srli %0, %0, %3\n\t"
+ "slti %0, %0, 2\n\t"
+ "bnez %0, 98f\n\t"
+ "lwi %0, [%1+0x0]\n\t"
+ "amtar %0, $D0.L24\n\t"
+ "lwi %0, [%1+0x4]\n\t"
+ "amtar %0, $D1.L24\n\t"
+ "98:\n\t"
+ "lwi %0, [%1+0x8]\n\t"
+ "amtar %0, $I0\n\t"
+ "lwi %0, [%1+0xc]\n\t"
+ "amtar %0, $I1\n\t"
+ "lwi %0, [%1+0x10]\n\t"
+ "amtar %0, $I2\n\t"
+ "lwi %0, [%1+0x14]\n\t"
+ "amtar %0, $I3\n\t"
+ "lwi %0, [%1+0x18]\n\t"
+ "amtar %0, $I4\n\t"
+ "lwi %0, [%1+0x1c]\n\t"
+ "amtar %0, $I5\n\t"
+ "lwi %0, [%1+0x20]\n\t"
+ "amtar %0, $I6\n\t"
+ "lwi %0, [%1+0x24]\n\t"
+ "amtar %0, $I7\n\t"
+ "lwi %0, [%1+0x28]\n\t"
+ "amtar %0, $M1\n\t"
+ "lwi %0, [%1+0x2c]\n\t"
+ "amtar %0, $M2\n\t"
+ "lwi %0, [%1+0x30]\n\t"
+ "amtar %0, $M3\n\t"
+ "lwi %0, [%1+0x34]\n\t"
+ "amtar %0, $M5\n\t"
+ "lwi %0, [%1+0x38]\n\t"
+ "amtar %0, $M6\n\t"
+ "lwi %0, [%1+0x3c]\n\t"
+ "amtar %0, $M7\n\t"
+ "lwi %0, [%1+0x40]\n\t"
+ "amtar %0, $MOD\n\t"
+ "lwi %0, [%1+0x44]\n\t"
+ "amtar %0, $LB\n\t"
+ "lwi %0, [%1+0x48]\n\t"
+ "amtar %0, $LE\n\t"
+ "lwi %0, [%1+0x4c]\n\t"
+ "amtar %0, $LC\n\t"
+ "lwi %0, [%1+0x50]\n\t"
+ "amtar %0, $ADM_VBASE\n\t"
+ "lwi %0, [%1+0x54]\n\t"
+ "amtar %0, $SHFT_CTL0\n\t"
+ "lwi %0, [%1+0x58]\n\t"
+ "amtar %0, $SHFT_CTL1\n\t"
+ "lwi %0, [%1+0x5c]\n\t"
+ "amtar2 %0, $CB_CTL\n\t"
+ "lwi %0, [%1+0x60]\n\t"
+ "amtar2 %0, $CBB0\n\t"
+ "lwi %0, [%1+0x64]\n\t"
+ "amtar2 %0, $CBB1\n\t"
+ "lwi %0, [%1+0x68]\n\t"
+ "amtar2 %0, $CBB2\n\t"
+ "lwi %0, [%1+0x6c]\n\t"
+ "amtar2 %0, $CBB3\n\t"
+ "lwi %0, [%1+0x70]\n\t"
+ "amtar2 %0, $CBE0\n\t"
+ "lwi %0, [%1+0x74]\n\t"
+ "amtar2 %0, $CBE1\n\t"
+ "lwi %0, [%1+0x78]\n\t"
+ "amtar2 %0, $CBE2\n\t"
+ "lwi %0, [%1+0x7c]\n\t"
+ "amtar2 %0, $CBE3\n\t":"=&r" (tmp)
+ :"r"(audioregs), "i"(MSC_CFG_mskAUDIO),
+ "i"(MSC_CFG_offAUDIO));
+ disable_audio();
+}
+
+void do_audio_context_switch(unsigned long error_code, struct pt_regs *regs)
+{
+ struct task_struct *tsk = current;
+
+ if (!user_mode(regs))
+ die("Audio used in kernel", regs, error_code);
+
+ /* Enable to use audio. */
+ grab_audio(regs);
+#ifndef CONFIG_UNLAZY_AUDIO //Lazy audio is used
+ if (last_task_used_audio == current)
+ return;
+
+ if (last_task_used_audio != NULL)
+ /* Other processes audio state, save away */
+ save_audio(last_task_used_audio);
+ last_task_used_audio = current;
+#endif
+ if (test_tsk_thread_flag(tsk, TIF_USEDAUDIO)) {
+ audioload(¤t->thread.audio);
+ } else {
+ /* First time audio user. */
+ audioload(&init_audioregs);
+ set_tsk_thread_flag(tsk, TIF_USEDAUDIO);
+ }
+}
diff -Nur linux-3.4.113.orig/arch/nds32/kernel/audio.h linux-3.4.113/arch/nds32/kernel/audio.h
--- linux-3.4.113.orig/arch/nds32/kernel/audio.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/kernel/audio.h 2016-12-01 20:59:24.352612751 +0100
@@ -0,0 +1,2 @@
+
+#define NAN32 0x0UL
diff -Nur linux-3.4.113.orig/arch/nds32/kernel/bios32.c linux-3.4.113/arch/nds32/kernel/bios32.c
--- linux-3.4.113.orig/arch/nds32/kernel/bios32.c 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/kernel/bios32.c 2016-12-01 20:59:24.352612751 +0100
@@ -0,0 +1,711 @@
+/*
+ * linux/arch/nds32/kernel/bios32.c
+ *
+ * PCI bios-type initialisation for PCI machines
+ *
+ * Bits taken from various places.
+ *
+ * Copyright (C) 2009 Andes Technology Corporation
+ */
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/pci.h>
+#include <linux/slab.h>
+#include <linux/init.h>
+
+#include <asm/io.h>
+#include <asm/mach-types.h>
+#include <asm/mach/pci.h>
+
+static int debug_pci;
+static int use_firmware;
+
+/*
+ * We can't use pci_find_device() here since we are
+ * called from interrupt context.
+ */
+static void pcibios_bus_report_status(struct pci_bus *bus, u_int status_mask,
+ int warn)
+{
+ struct pci_dev *dev;
+
+ list_for_each_entry(dev, &bus->devices, bus_list) {
+ u16 status;
+
+ /*
+ * ignore host bridge - we handle
+ * that separately
+ */
+ if (dev->bus->number == 0 && dev->devfn == 0)
+ continue;
+
+ pci_read_config_word(dev, PCI_STATUS, &status);
+ if (status == 0xffff)
+ continue;
+
+ if ((status & status_mask) == 0)
+ continue;
+
+ /* clear the status errors */
+ pci_write_config_word(dev, PCI_STATUS, status & status_mask);
+
+ if (warn)
+ printk("(%s: %04X) ", pci_name(dev), status);
+ }
+
+ list_for_each_entry(dev, &bus->devices, bus_list)
+ if (dev->subordinate)
+ pcibios_bus_report_status(dev->subordinate, status_mask, warn);
+}
+
+void pcibios_report_status(u_int status_mask, int warn)
+{
+ struct list_head *l;
+
+ list_for_each(l, &pci_root_buses) {
+ struct pci_bus *bus = pci_bus_b(l);
+
+ pcibios_bus_report_status(bus, status_mask, warn);
+ }
+}
+
+/*
+ * We don't use this to fix the device, but initialisation of it.
+ * It's not the correct use for this, but it works.
+ * Note that the arbiter/ISA bridge appears to be buggy, specifically in
+ * the following area:
+ * 1. park on CPU
+ * 2. ISA bridge ping-pong
+ * 3. ISA bridge master handling of target RETRY
+ *
+ * Bug 3 is responsible for the sound DMA grinding to a halt. We now
+ * live with bug 2.
+ */
+static void __devinit pci_fixup_83c553(struct pci_dev *dev)
+{
+ /*
+ * Set memory region to start at address 0, and enable IO
+ */
+ pci_write_config_dword(dev, PCI_BASE_ADDRESS_0,
+ PCI_BASE_ADDRESS_SPACE_MEMORY);
+ pci_write_config_word(dev, PCI_COMMAND, PCI_COMMAND_IO);
+
+ dev->resource[0].end -= dev->resource[0].start;
+ dev->resource[0].start = 0;
+
+ /*
+ * All memory requests from ISA to be channelled to PCI
+ */
+ pci_write_config_byte(dev, 0x48, 0xff);
+
+ /*
+ * Enable ping-pong on bus master to ISA bridge transactions.
+ * This improves the sound DMA substantially. The fixed
+ * priority arbiter also helps (see below).
+ */
+ pci_write_config_byte(dev, 0x42, 0x01);
+
+ /*
+ * Enable PCI retry
+ */
+ pci_write_config_byte(dev, 0x40, 0x22);
+
+ /*
+ * We used to set the arbiter to "park on last master" (bit
+ * 1 set), but unfortunately the CyberPro does not park the
+ * bus. We must therefore park on CPU. Unfortunately, this
+ * may trigger yet another bug in the 553.
+ */
+ pci_write_config_byte(dev, 0x83, 0x02);
+
+ /*
+ * Make the ISA DMA request lowest priority, and disable
+ * rotating priorities completely.
+ */
+ pci_write_config_byte(dev, 0x80, 0x11);
+ pci_write_config_byte(dev, 0x81, 0x00);
+
+ /*
+ * Route INTA input to IRQ 11, and set IRQ11 to be level
+ * sensitive.
+ */
+ pci_write_config_word(dev, 0x44, 0xb000);
+ outb(0x08, 0x4d1);
+}
+
+DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_WINBOND, PCI_DEVICE_ID_WINBOND_83C553,
+ pci_fixup_83c553);
+
+static void __devinit pci_fixup_unassign(struct pci_dev *dev)
+{
+ dev->resource[0].end -= dev->resource[0].start;
+ dev->resource[0].start = 0;
+}
+
+DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_WINBOND2, PCI_DEVICE_ID_WINBOND2_89C940F,
+ pci_fixup_unassign);
+
+/*
+ * Prevent the PCI layer from seeing the resources allocated to this device
+ * if it is the host bridge by marking it as such. These resources are of
+ * no consequence to the PCI layer (they are handled elsewhere).
+ */
+static void __devinit pci_fixup_dec21285(struct pci_dev *dev)
+{
+ int i;
+
+ if (dev->devfn == 0) {
+ dev->class &= 0xff;
+ dev->class |= PCI_CLASS_BRIDGE_HOST << 8;
+ for (i = 0; i < PCI_NUM_RESOURCES; i++) {
+ dev->resource[i].start = 0;
+ dev->resource[i].end = 0;
+ dev->resource[i].flags = 0;
+ }
+ }
+}
+
+DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_DEC, PCI_DEVICE_ID_DEC_21285,
+ pci_fixup_dec21285);
+
+/*
+ * PCI IDE controllers use non-standard I/O port decoding, respect it.
+ */
+static void __devinit pci_fixup_ide_bases(struct pci_dev *dev)
+{
+ struct resource *r;
+ int i;
+
+ if ((dev->class >> 8) != PCI_CLASS_STORAGE_IDE)
+ return;
+
+ for (i = 0; i < PCI_NUM_RESOURCES; i++) {
+ r = dev->resource + i;
+ if ((r->start & ~0x80) == 0x374) {
+ r->start |= 2;
+ r->end = r->start;
+ }
+ }
+}
+
+DECLARE_PCI_FIXUP_HEADER(PCI_ANY_ID, PCI_ANY_ID, pci_fixup_ide_bases);
+
+/*
+ * Put the DEC21142 to sleep
+ */
+static void __devinit pci_fixup_dec21142(struct pci_dev *dev)
+{
+ pci_write_config_dword(dev, 0x40, 0x80000000);
+}
+
+DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_DEC, PCI_DEVICE_ID_DEC_21142,
+ pci_fixup_dec21142);
+
+/*
+ * The CY82C693 needs some rather major fixups to ensure that it does
+ * the right thing. Idea from the Alpha people, with a few additions.
+ *
+ * We ensure that the IDE base registers are set to 1f0/3f4 for the
+ * primary bus, and 170/374 for the secondary bus. Also, hide them
+ * from the PCI subsystem view as well so we won't try to perform
+ * our own auto-configuration on them.
+ *
+ * In addition, we ensure that the PCI IDE interrupts are routed to
+ * IRQ 14 and IRQ 15 respectively.
+ *
+ * The above gets us to a point where the IDE on this device is
+ * functional. However, The CY82C693U _does not work_ in bus
+ * master mode without locking the PCI bus solid.
+ */
+static void __devinit pci_fixup_cy82c693(struct pci_dev *dev)
+{
+ if ((dev->class >> 8) == PCI_CLASS_STORAGE_IDE) {
+ u32 base0, base1;
+
+ if (dev->class & 0x80) { /* primary */
+ base0 = 0x1f0;
+ base1 = 0x3f4;
+ } else { /* secondary */
+ base0 = 0x170;
+ base1 = 0x374;
+ }
+
+ pci_write_config_dword(dev, PCI_BASE_ADDRESS_0,
+ base0 | PCI_BASE_ADDRESS_SPACE_IO);
+ pci_write_config_dword(dev, PCI_BASE_ADDRESS_1,
+ base1 | PCI_BASE_ADDRESS_SPACE_IO);
+
+ dev->resource[0].start = 0;
+ dev->resource[0].end = 0;
+ dev->resource[0].flags = 0;
+
+ dev->resource[1].start = 0;
+ dev->resource[1].end = 0;
+ dev->resource[1].flags = 0;
+ } else if (PCI_FUNC(dev->devfn) == 0) {
+ /*
+ * Setup IDE IRQ routing.
+ */
+ pci_write_config_byte(dev, 0x4b, 14);
+ pci_write_config_byte(dev, 0x4c, 15);
+
+ /*
+ * Disable FREQACK handshake, enable USB.
+ */
+ pci_write_config_byte(dev, 0x4d, 0x41);
+
+ /*
+ * Enable PCI retry, and PCI post-write buffer.
+ */
+ pci_write_config_byte(dev, 0x44, 0x17);
+
+ /*
+ * Enable ISA master and DMA post write buffering.
+ */
+ pci_write_config_byte(dev, 0x45, 0x03);
+ }
+}
+
+DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_CONTAQ, PCI_DEVICE_ID_CONTAQ_82C693,
+ pci_fixup_cy82c693);
+
+void __devinit pcibios_update_irq(struct pci_dev *dev, int irq)
+{
+ if (debug_pci)
+ printk("PCI: Assigning IRQ %02d to %s\n", irq, pci_name(dev));
+ pci_write_config_byte(dev, PCI_INTERRUPT_LINE, irq);
+}
+
+/*
+ * If the bus contains any of these devices, then we must not turn on
+ * parity checking of any kind. Currently this is CyberPro 20x0 only.
+ */
+static inline int pdev_bad_for_parity(struct pci_dev *dev)
+{
+ return (dev->vendor == PCI_VENDOR_ID_INTERG &&
+ (dev->device == PCI_DEVICE_ID_INTERG_2000 ||
+ dev->device == PCI_DEVICE_ID_INTERG_2010));
+}
+
+/*
+ * Adjust the device resources from bus-centric to Linux-centric.
+ */
+static void __devinit
+pdev_fixup_device_resources(struct pci_sys_data *root, struct pci_dev *dev)
+{
+ resource_size_t offset;
+ int i;
+
+ for (i = 0; i < PCI_NUM_RESOURCES; i++) {
+ if (dev->resource[i].start == 0)
+ continue;
+ if (dev->resource[i].flags & IORESOURCE_MEM)
+ offset = root->mem_offset;
+ else
+ offset = root->io_offset;
+
+ dev->resource[i].start += offset;
+ dev->resource[i].end += offset;
+ }
+}
+
+static void __devinit
+pbus_assign_bus_resources(struct pci_bus *bus, struct pci_sys_data *root)
+{
+ struct pci_dev *dev = bus->self;
+ int i;
+
+ if (!dev) {
+ /*
+ * Assign root bus resources.
+ */
+ for (i = 0; i < 3; i++)
+ bus->resource[i] = root->resource[i];
+ }
+}
+
+/*
+ * pcibios_fixup_bus - Called after each bus is probed,
+ * but before its children are examined.
+ */
+void __devinit pcibios_fixup_bus(struct pci_bus *bus)
+{
+ struct pci_sys_data *root = bus->sysdata;
+ struct pci_dev *dev;
+ u16 features =
+ PCI_COMMAND_SERR | PCI_COMMAND_PARITY | PCI_COMMAND_FAST_BACK;
+
+ pbus_assign_bus_resources(bus, root);
+
+ /*
+ * Walk the devices on this bus, working out what we can
+ * and can't support.
+ */
+ list_for_each_entry(dev, &bus->devices, bus_list) {
+ u16 status;
+
+ pdev_fixup_device_resources(root, dev);
+
+ pci_read_config_word(dev, PCI_STATUS, &status);
+
+ /*
+ * If any device on this bus does not support fast back
+ * to back transfers, then the bus as a whole is not able
+ * to support them. Having fast back to back transfers
+ * on saves us one PCI cycle per transaction.
+ */
+ if (!(status & PCI_STATUS_FAST_BACK))
+ features &= ~PCI_COMMAND_FAST_BACK;
+
+ if (pdev_bad_for_parity(dev))
+ features &= ~(PCI_COMMAND_SERR | PCI_COMMAND_PARITY);
+
+ switch (dev->class >> 8) {
+#if defined(CONFIG_ISA) || defined(CONFIG_EISA)
+ case PCI_CLASS_BRIDGE_ISA:
+ case PCI_CLASS_BRIDGE_EISA:
+ /*
+ * If this device is an ISA bridge, set isa_bridge
+ * to point at this device. We will then go looking
+ * for things like keyboard, etc.
+ */
+ isa_bridge = dev;
+ break;
+#endif
+ case PCI_CLASS_BRIDGE_PCI:
+ pci_read_config_word(dev, PCI_BRIDGE_CONTROL, &status);
+ status |=
+ PCI_BRIDGE_CTL_PARITY | PCI_BRIDGE_CTL_MASTER_ABORT;
+ status &=
+ ~(PCI_BRIDGE_CTL_BUS_RESET |
+ PCI_BRIDGE_CTL_FAST_BACK);
+ pci_write_config_word(dev, PCI_BRIDGE_CONTROL, status);
+ break;
+
+ case PCI_CLASS_BRIDGE_CARDBUS:
+ pci_read_config_word(dev, PCI_CB_BRIDGE_CONTROL,
+ &status);
+ status |=
+ PCI_CB_BRIDGE_CTL_PARITY |
+ PCI_CB_BRIDGE_CTL_MASTER_ABORT;
+ pci_write_config_word(dev, PCI_CB_BRIDGE_CONTROL,
+ status);
+ break;
+ }
+ }
+
+ /*
+ * Now walk the devices again, this time setting them up.
+ */
+ list_for_each_entry(dev, &bus->devices, bus_list) {
+ u16 cmd;
+
+ pci_read_config_word(dev, PCI_COMMAND, &cmd);
+ cmd |= features;
+ pci_write_config_word(dev, PCI_COMMAND, cmd);
+
+ pci_write_config_byte(dev, PCI_CACHE_LINE_SIZE,
+ L1_CACHE_BYTES >> 2);
+ }
+
+ /*
+ * Propagate the flags to the PCI bridge.
+ */
+ if (bus->self && bus->self->hdr_type == PCI_HEADER_TYPE_BRIDGE) {
+ if (features & PCI_COMMAND_FAST_BACK)
+ bus->bridge_ctl |= PCI_BRIDGE_CTL_FAST_BACK;
+ if (features & PCI_COMMAND_PARITY)
+ bus->bridge_ctl |= PCI_BRIDGE_CTL_PARITY;
+ }
+
+ /*
+ * Report what we did for this bus
+ */
+ printk(KERN_INFO "PCI: bus%d: Fast back to back transfers %sabled\n",
+ bus->number, (features & PCI_COMMAND_FAST_BACK) ? "en" : "dis");
+}
+
+/*
+ * Convert from Linux-centric to bus-centric addresses for bridge devices.
+ */
+void
+pcibios_resource_to_bus(struct pci_dev *dev, struct pci_bus_region *region,
+ struct resource *res)
+{
+ struct pci_sys_data *root = dev->sysdata;
+ unsigned long offset = 0;
+
+ if (res->flags & IORESOURCE_IO)
+ offset = root->io_offset;
+ if (res->flags & IORESOURCE_MEM)
+ offset = root->mem_offset;
+
+ region->start = res->start - offset;
+ region->end = res->end - offset;
+}
+
+void __devinit
+pcibios_bus_to_resource(struct pci_dev *dev, struct resource *res,
+ struct pci_bus_region *region)
+{
+ struct pci_sys_data *root = dev->sysdata;
+ unsigned long offset = 0;
+
+ if (res->flags & IORESOURCE_IO)
+ offset = root->io_offset;
+ if (res->flags & IORESOURCE_MEM)
+ offset = root->mem_offset;
+
+ res->start = region->start + offset;
+ res->end = region->end + offset;
+}
+
+#ifdef CONFIG_HOTPLUG
+EXPORT_SYMBOL(pcibios_fixup_bus);
+EXPORT_SYMBOL(pcibios_resource_to_bus);
+EXPORT_SYMBOL(pcibios_bus_to_resource);
+#endif
+
+/*
+ * This is the standard PCI-PCI bridge swizzling algorithm:
+ *
+ * Dev: 0 1 2 3
+ * A A B C D
+ * B B C D A
+ * C C D A B
+ * D D A B C
+ * ^^^^^^^^^^ irq pin on bridge
+ */
+u8 __devinit pci_std_swizzle(struct pci_dev *dev, u8 * pinp)
+{
+ int pin = *pinp - 1;
+
+ while (dev->bus->self) {
+ pin = (pin + PCI_SLOT(dev->devfn)) & 3;
+ /*
+ * move up the chain of bridges,
+ * swizzling as we go.
+ */
+ dev = dev->bus->self;
+ }
+ *pinp = pin + 1;
+
+ return PCI_SLOT(dev->devfn);
+}
+
+/*
+ * Swizzle the device pin each time we cross a bridge.
+ * This might update pin and returns the slot number.
+ */
+static u8 __devinit pcibios_swizzle(struct pci_dev *dev, u8 * pin)
+{
+ struct pci_sys_data *sys = dev->sysdata;
+ int slot = 0, oldpin = *pin;
+
+ if (sys->swizzle)
+ slot = sys->swizzle(dev, pin);
+
+ if (debug_pci)
+ printk("PCI: %s swizzling pin %d => pin %d slot %d\n",
+ pci_name(dev), oldpin, *pin, slot);
+
+ return slot;
+}
+
+/*
+ * Map a slot/pin to an IRQ.
+ */
+static int pcibios_map_irq(struct pci_dev *dev, u8 slot, u8 pin)
+{
+ struct pci_sys_data *sys = dev->sysdata;
+ int irq = -1;
+
+ if (sys->map_irq)
+ irq = sys->map_irq(dev, slot, pin);
+
+ if (debug_pci)
+ printk("PCI: %s mapping slot %d pin %d => irq %d\n",
+ pci_name(dev), slot, pin, irq);
+
+ return irq;
+}
+
+static void __init pcibios_init_hw(struct hw_pci *hw)
+{
+ struct pci_sys_data *sys = NULL;
+ int ret;
+ int nr, busnr;
+
+ for (nr = busnr = 0; nr < hw->nr_controllers; nr++) {
+ sys = kmalloc(sizeof(struct pci_sys_data), GFP_KERNEL);
+ if (!sys)
+ panic("PCI: unable to allocate sys data!");
+
+ memset(sys, 0, sizeof(struct pci_sys_data));
+
+ sys->hw = hw;
+ sys->busnr = busnr;
+ sys->swizzle = hw->swizzle;
+ sys->map_irq = hw->map_irq;
+ sys->resource[0] = &ioport_resource;
+ sys->resource[1] = &iomem_resource;
+
+ ret = hw->setup(nr, sys);
+
+ if (ret > 0) {
+ sys->bus = hw->scan(nr, sys);
+
+ if (!sys->bus)
+ panic("PCI: unable to scan bus!");
+
+ busnr = sys->bus->subordinate + 1;
+
+ list_add(&sys->node, &hw->buses);
+ } else {
+ kfree(sys);
+ if (ret < 0)
+ break;
+ }
+ }
+}
+
+void __init pci_common_init(struct hw_pci *hw)
+{
+ struct pci_sys_data *sys;
+
+ INIT_LIST_HEAD(&hw->buses);
+
+ if (hw->preinit)
+ hw->preinit();
+ pcibios_init_hw(hw);
+ if (hw->postinit)
+ hw->postinit();
+
+ pci_fixup_irqs(pcibios_swizzle, pcibios_map_irq);
+
+ list_for_each_entry(sys, &hw->buses, node) {
+ struct pci_bus *bus = sys->bus;
+
+ if (!use_firmware) {
+ /*
+ * Size the bridge windows.
+ */
+ pci_bus_size_bridges(bus);
+
+ /*
+ * Assign resources.
+ */
+ pci_bus_assign_resources(bus);
+ }
+
+ /*
+ * Tell drivers about devices found.
+ */
+ pci_bus_add_devices(bus);
+ }
+}
+
+char *__devinit pcibios_setup(char *str)
+{
+ if (!strcmp(str, "debug")) {
+ debug_pci = 1;
+ return NULL;
+ } else if (!strcmp(str, "firmware")) {
+ use_firmware = 1;
+ return NULL;
+ }
+ return str;
+}
+
+/*
+ * From arch/i386/kernel/pci-i386.c:
+ *
+ * We need to avoid collisions with `mirrored' VGA ports
+ * and other strange ISA hardware, so we always want the
+ * addresses to be allocated in the 0x000-0x0ff region
+ * modulo 0x400.
+ *
+ * Why? Because some silly external IO cards only decode
+ * the low 10 bits of the IO address. The 0x00-0xff region
+ * is reserved for motherboard devices that decode all 16
+ * bits, so it's ok to allocate at, say, 0x2800-0x28ff,
+ * but we want to try to avoid allocating at 0x2900-0x2bff
+ * which might be mirrored at 0x0100-0x03ff..
+ */
+void pcibios_align_resource(void *data, struct resource *res,
+ resource_size_t size, resource_size_t align)
+{
+ resource_size_t start = res->start;
+
+ if (res->flags & IORESOURCE_IO && start & 0x300)
+ start = (start + 0x3ff) & ~0x3ff;
+
+ res->start = (start + align - 1) & ~(align - 1);
+}
+
+/**
+ * pcibios_enable_device - Enable I/O and memory.
+ * @dev: PCI device to be enabled
+ */
+int pcibios_enable_device(struct pci_dev *dev, int mask)
+{
+ u16 cmd, old_cmd;
+ int idx;
+ struct resource *r;
+
+ pci_read_config_word(dev, PCI_COMMAND, &cmd);
+ old_cmd = cmd;
+ for (idx = 0; idx < 6; idx++) {
+ /* Only set up the requested stuff */
+ if (!(mask & (1 << idx)))
+ continue;
+
+ r = dev->resource + idx;
+ if (!r->start && r->end) {
+ printk(KERN_ERR "PCI: Device %s not available because"
+ " of resource collisions\n", pci_name(dev));
+ return -EINVAL;
+ }
+ if (r->flags & IORESOURCE_IO)
+ cmd |= PCI_COMMAND_IO;
+ if (r->flags & IORESOURCE_MEM)
+ cmd |= PCI_COMMAND_MEMORY;
+ }
+
+ /*
+ * Bridges (eg, cardbus bridges) need to be fully enabled
+ */
+ if ((dev->class >> 16) == PCI_BASE_CLASS_BRIDGE)
+ cmd |= PCI_COMMAND_IO | PCI_COMMAND_MEMORY;
+
+ if (cmd != old_cmd) {
+ printk("PCI: enabling device %s (%04x -> %04x)\n",
+ pci_name(dev), old_cmd, cmd);
+ pci_write_config_word(dev, PCI_COMMAND, cmd);
+ }
+ return 0;
+}
+
+int pci_mmap_page_range(struct pci_dev *dev, struct vm_area_struct *vma,
+ enum pci_mmap_state mmap_state, int write_combine)
+{
+ struct pci_sys_data *root = dev->sysdata;
+ unsigned long phys;
+
+ if (mmap_state == pci_mmap_io) {
+ return -EINVAL;
+ } else {
+ phys = vma->vm_pgoff + (root->mem_offset >> PAGE_SHIFT);
+ }
+
+ /*
+ * Mark this as IO
+ */
+ vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
+
+ if (remap_pfn_range(vma, vma->vm_start, phys,
+ vma->vm_end - vma->vm_start, vma->vm_page_prot))
+ return -EAGAIN;
+
+ return 0;
+}
diff -Nur linux-3.4.113.orig/arch/nds32/kernel/calls.S linux-3.4.113/arch/nds32/kernel/calls.S
--- linux-3.4.113.orig/arch/nds32/kernel/calls.S 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/kernel/calls.S 2016-12-01 20:59:24.352612751 +0100
@@ -0,0 +1,400 @@
+/*
+ * linux/arch/nds32/kernel/calls.S
+ *
+ * Copyright (C) 1995-2004 Russell King
+ * Copyright (C) 2009 Andes Technology Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This file is included twice in entry-common.S
+ */
+
+/* 0 */ CALL(sys_restart_syscall)
+ CALL(sys_exit)
+ CALL(sys_fork_wrapper)
+ CALL(sys_read)
+ CALL(sys_write)
+/* 5 */ CALL(sys_open)
+ CALL(sys_close)
+ CALL(sys_waitpid)
+ CALL(sys_creat)
+ CALL(sys_link)
+/* 10 */ CALL(sys_unlink)
+ CALL(sys_execve_wrapper)
+ CALL(sys_chdir)
+ CALL(sys_time) /* used by libc4 */
+ CALL(sys_mknod)
+/* 15 */ CALL(sys_chmod)
+ CALL(sys_lchown16)
+ CALL(sys_ni_syscall) /* was sys_break */
+ CALL(sys_ni_syscall) /* was sys_stat */
+ CALL(sys_lseek)
+/* 20 */ CALL(sys_getpid)
+ CALL(sys_mount)
+ CALL(sys_oldumount) /* used by libc4 */
+ CALL(sys_setuid16)
+ CALL(sys_getuid16)
+/* 25 */ CALL(sys_stime)
+ CALL(sys_ptrace)
+ CALL(sys_alarm) /* used by libc4 */
+ CALL(sys_ni_syscall) /* was sys_fstat */
+ CALL(sys_pause)
+/* 30 */ CALL(sys_utime) /* used by libc4 */
+ CALL(sys_ni_syscall) /* was sys_stty */
+ CALL(sys_ni_syscall) /* was sys_getty */
+ CALL(sys_access)
+ CALL(sys_nice)
+/* 35 */ CALL(sys_ni_syscall) /* was sys_ftime */
+ CALL(sys_sync)
+ CALL(sys_kill)
+ CALL(sys_rename)
+ CALL(sys_mkdir)
+/* 40 */ CALL(sys_rmdir)
+ CALL(sys_dup)
+ CALL(sys_pipe)
+ CALL(sys_times)
+ CALL(sys_ni_syscall) /* was sys_prof */
+/* 45 */ CALL(sys_brk)
+ CALL(sys_setgid16)
+ CALL(sys_getgid16)
+ CALL(sys_ni_syscall) /* was sys_signal */
+ CALL(sys_geteuid16)
+/* 50 */ CALL(sys_getegid16)
+ CALL(sys_acct)
+ CALL(sys_umount)
+ CALL(sys_ni_syscall) /* was sys_lock */
+ CALL(sys_ioctl)
+/* 55 */ CALL(sys_fcntl)
+ CALL(sys_ni_syscall) /* was sys_mpx */
+ CALL(sys_setpgid)
+ CALL(sys_ni_syscall) /* was sys_ulimit */
+ CALL(sys_cacheflush) /* was sys_olduname */
+/* 60 */ CALL(sys_umask)
+ CALL(sys_chroot)
+ CALL(sys_ustat)
+ CALL(sys_dup2)
+ CALL(sys_getppid)
+/* 65 */ CALL(sys_getpgrp)
+ CALL(sys_setsid)
+ CALL(sys_sigaction)
+ CALL(sys_ni_syscall) /* was sys_sgetmask */
+ CALL(sys_ni_syscall) /* was sys_ssetmask */
+/* 70 */ CALL(sys_setreuid16)
+ CALL(sys_setregid16)
+ CALL(sys_sigsuspend_wrapper)
+ CALL(sys_sigpending)
+ CALL(sys_sethostname)
+/* 75 */ CALL(sys_setrlimit)
+ CALL(sys_old_getrlimit) /* used by libc4 */
+ CALL(sys_getrusage)
+ CALL(sys_gettimeofday)
+ CALL(sys_settimeofday)
+/* 80 */ CALL(sys_getgroups16)
+ CALL(sys_setgroups16)
+ CALL(old_select) /* used by libc4 */
+ CALL(sys_symlink)
+ CALL(sys_ni_syscall) /* was sys_lstat */
+/* 85 */ CALL(sys_readlink)
+ CALL(sys_uselib)
+ CALL(sys_swapon)
+ CALL(sys_reboot)
+ CALL(sys_old_readdir) /* used by libc4 */
+/* 90 */ CALL(sys_old_mmap) /* used by libc4 */
+ CALL(sys_munmap)
+ CALL(sys_truncate)
+ CALL(sys_ftruncate)
+ CALL(sys_fchmod)
+/* 95 */ CALL(sys_fchown16)
+ CALL(sys_getpriority)
+ CALL(sys_setpriority)
+ CALL(sys_ni_syscall) /* was sys_profil */
+ CALL(sys_statfs)
+/* 100 */ CALL(sys_fstatfs)
+ CALL(sys_ni_syscall)
+ CALL(sys_socketcall)
+ CALL(sys_syslog)
+ CALL(sys_setitimer)
+/* 105 */ CALL(sys_getitimer)
+ CALL(sys_newstat)
+ CALL(sys_newlstat)
+ CALL(sys_newfstat)
+ CALL(sys_ni_syscall) /* was sys_uname */
+/* 110 */ CALL(sys_ni_syscall) /* was sys_iopl */
+ CALL(sys_vhangup)
+ CALL(sys_ni_syscall)
+ CALL(sys_syscall) /* call a syscall */
+ CALL(sys_wait4)
+/* 115 */ CALL(sys_swapoff)
+ CALL(sys_sysinfo)
+ CALL(sys_ipc)
+ CALL(sys_fsync)
+ CALL(sys_sigreturn_wrapper)
+/* 120 */ CALL(sys_clone_wrapper)
+ CALL(sys_setdomainname)
+ CALL(sys_newuname)
+ CALL(sys_ni_syscall)
+ CALL(sys_adjtimex)
+/* 125 */ CALL(sys_mprotect)
+ CALL(sys_sigprocmask)
+ CALL(sys_ni_syscall) /* was sys_create_module */
+ CALL(sys_init_module)
+ CALL(sys_delete_module)
+/* 130 */ CALL(sys_ni_syscall) /* was sys_get_kernel_syms */
+ CALL(sys_quotactl)
+ CALL(sys_getpgid)
+ CALL(sys_fchdir)
+ CALL(sys_bdflush)
+/* 135 */ CALL(sys_sysfs)
+ CALL(sys_personality)
+ CALL(sys_ni_syscall) /* was _sys_afs_syscall */
+ CALL(sys_setfsuid16)
+ CALL(sys_setfsgid16)
+/* 140 */ CALL(sys_llseek)
+ CALL(sys_getdents)
+ CALL(sys_select)
+ CALL(sys_flock)
+ CALL(sys_msync)
+/* 145 */ CALL(sys_readv)
+ CALL(sys_writev)
+ CALL(sys_getsid)
+ CALL(sys_fdatasync)
+ CALL(sys_sysctl)
+/* 150 */ CALL(sys_mlock)
+ CALL(sys_munlock)
+ CALL(sys_mlockall)
+ CALL(sys_munlockall)
+ CALL(sys_sched_setparam)
+/* 155 */ CALL(sys_sched_getparam)
+ CALL(sys_sched_setscheduler)
+ CALL(sys_sched_getscheduler)
+ CALL(sys_sched_yield)
+ CALL(sys_sched_get_priority_max)
+/* 160 */ CALL(sys_sched_get_priority_min)
+ CALL(sys_sched_rr_get_interval)
+ CALL(sys_nanosleep)
+ CALL(sys_nds32_mremap)
+ CALL(sys_setresuid16)
+/* 165 */ CALL(sys_getresuid16)
+ CALL(sys_getpagesize)
+ CALL(sys_ni_syscall) /* was sys_query_module */
+ CALL(sys_poll)
+ CALL(sys_ni_syscall) /* was nfsservctl */
+/* 170 */ CALL(sys_setresgid16)
+ CALL(sys_getresgid16)
+ CALL(sys_prctl)
+ CALL(sys_rt_sigreturn_wrapper)
+ CALL(sys_rt_sigaction)
+/* 175 */ CALL(sys_rt_sigprocmask)
+ CALL(sys_rt_sigpending)
+ CALL(sys_rt_sigtimedwait)
+ CALL(sys_rt_sigqueueinfo)
+ CALL(sys_rt_sigsuspend_wrapper)
+/* 180 */ CALL(sys_pread64)
+ CALL(sys_pwrite64)
+ CALL(sys_chown16)
+ CALL(sys_getcwd)
+ CALL(sys_capget)
+/* 185 */ CALL(sys_capset)
+ CALL(sys_sigaltstack_wrapper)
+ CALL(sys_sendfile)
+ CALL(sys_ni_syscall)
+ CALL(sys_ni_syscall)
+/* 190 */ CALL(sys_vfork_wrapper)
+ CALL(sys_getrlimit)
+ CALL(sys_mmap2)
+ CALL(sys_truncate64)
+ CALL(sys_ftruncate64)
+/* 195 */ CALL(sys_stat64)
+ CALL(sys_lstat64)
+ CALL(sys_fstat64)
+ CALL(sys_lchown)
+ CALL(sys_getuid)
+/* 200 */ CALL(sys_getgid)
+ CALL(sys_geteuid)
+ CALL(sys_getegid)
+ CALL(sys_setreuid)
+ CALL(sys_setregid)
+/* 205 */ CALL(sys_getgroups)
+ CALL(sys_setgroups)
+ CALL(sys_fchown)
+ CALL(sys_setresuid)
+ CALL(sys_getresuid)
+/* 210 */ CALL(sys_setresgid)
+ CALL(sys_getresgid)
+ CALL(sys_chown)
+ CALL(sys_setuid)
+ CALL(sys_setgid)
+/* 215 */ CALL(sys_setfsuid)
+ CALL(sys_setfsgid)
+ CALL(sys_getdents64)
+ CALL(sys_pivot_root)
+ CALL(sys_mincore)
+/* 220 */ CALL(sys_madvise)
+ CALL(sys_fcntl64)
+ CALL(sys_ni_syscall) /* TUX */
+ CALL(sys_ni_syscall)
+ CALL(sys_gettid)
+/* 225 */ CALL(sys_readahead)
+ CALL(sys_setxattr)
+ CALL(sys_lsetxattr)
+ CALL(sys_fsetxattr)
+ CALL(sys_getxattr)
+/* 230 */ CALL(sys_lgetxattr)
+ CALL(sys_fgetxattr)
+ CALL(sys_listxattr)
+ CALL(sys_llistxattr)
+ CALL(sys_flistxattr)
+/* 235 */ CALL(sys_removexattr)
+ CALL(sys_lremovexattr)
+ CALL(sys_fremovexattr)
+ CALL(sys_tkill)
+ CALL(sys_sendfile64)
+/* 240 */ CALL(sys_futex_wrapper)
+ CALL(sys_sched_setaffinity)
+ CALL(sys_sched_getaffinity)
+ CALL(sys_io_setup)
+ CALL(sys_io_destroy)
+/* 245 */ CALL(sys_io_getevents)
+ CALL(sys_io_submit)
+ CALL(sys_io_cancel)
+ CALL(sys_exit_group)
+ CALL(sys_lookup_dcookie)
+/* 250 */ CALL(sys_epoll_create)
+ CALL(sys_epoll_ctl)
+ CALL(sys_epoll_wait)
+ CALL(sys_remap_file_pages)
+ CALL(sys_ni_syscall) /* sys_set_thread_area */
+/* 255 */ CALL(sys_ni_syscall) /* sys_get_thread_area */
+ CALL(sys_set_tid_address)
+ CALL(sys_timer_create)
+ CALL(sys_timer_settime)
+ CALL(sys_timer_gettime)
+/* 260 */ CALL(sys_timer_getoverrun)
+ CALL(sys_timer_delete)
+ CALL(sys_clock_settime)
+ CALL(sys_clock_gettime)
+ CALL(sys_clock_getres)
+/* 265 */ CALL(sys_clock_nanosleep)
+ CALL(sys_statfs64)
+ CALL(sys_fstatfs64)
+ CALL(sys_tgkill)
+ CALL(sys_utimes)
+/* 270 */ CALL(sys_fadvise64_64_wrapper)
+ CALL(sys_pciconfig_iobase)
+ CALL(sys_pciconfig_read)
+ CALL(sys_pciconfig_write)
+ CALL(sys_mq_open)
+/* 275 */ CALL(sys_mq_unlink)
+ CALL(sys_mq_timedsend)
+ CALL(sys_mq_timedreceive)
+ CALL(sys_mq_notify)
+ CALL(sys_mq_getsetattr)
+/* 280 */ CALL(sys_waitid)
+ CALL(sys_add_key)
+ CALL(sys_request_key)
+ CALL(sys_keyctl)
+ CALL(sys_ioprio_set)
+/* 285 */ CALL(sys_ioprio_get)
+ CALL(sys_inotify_init)
+ CALL(sys_inotify_add_watch)
+ CALL(sys_inotify_rm_watch)
+ CALL(sys_migrate_pages)
+/* 290 */ CALL(sys_openat)
+ CALL(sys_mkdirat)
+ CALL(sys_mknodat)
+ CALL(sys_fchownat)
+ CALL(sys_futimesat)
+/* 295 */ CALL(sys_fstatat64)
+ CALL(sys_unlinkat)
+ CALL(sys_renameat)
+ CALL(sys_linkat)
+ CALL(sys_symlinkat)
+/* 300 */ CALL(sys_readlinkat)
+ CALL(sys_fchmodat)
+ CALL(sys_faccessat)
+ CALL(sys_pselect6) /* sys_pselect6 */
+ CALL(sys_ppoll) /* sys_ppoll */
+/* 305 */ CALL(sys_unshare)
+ CALL(sys_set_robust_list)
+ CALL(sys_get_robust_list)
+ CALL(sys_splice)
+ CALL(sys_sync_file_range2)
+/* 310 */ CALL(sys_tee)
+ CALL(sys_vmsplice)
+ CALL(sys_move_pages)
+ CALL(sys_fadvise64)
+ CALL(sys_utimensat)
+/* 315 */ CALL(sys_signalfd)
+ CALL(sys_timerfd_create)
+ CALL(sys_eventfd)
+ CALL(sys_fallocate)
+ CALL(sys_timerfd_settime)
+/* 320 */ CALL(sys_timerfd_gettime)
+ CALL(sys_getcpu)
+ CALL(sys_signalfd4)
+ CALL(sys_eventfd2)
+ CALL(sys_epoll_create1)
+/* 325 */ CALL(sys_dup3)
+ CALL(sys_pipe2)
+ CALL(sys_inotify_init1)
+ CALL(sys_kexec_load)
+ CALL(sys_accept)
+/* 330 */ CALL(sys_bind)
+ CALL(sys_connect)
+ CALL(sys_getpeername)
+ CALL(sys_getsockname)
+ CALL(sys_getsockopt)
+/* 335 */ CALL(sys_listen)
+ CALL(sys_recv)
+ CALL(sys_recvfrom)
+ CALL(sys_recvmsg)
+ CALL(sys_send)
+/* 340 */ CALL(sys_sendmsg)
+ CALL(sys_sendto)
+ CALL(sys_setsockopt)
+ CALL(sys_shutdown)
+ CALL(sys_socket)
+/* 345 */ CALL(sys_socketpair)
+ CALL(sys_prlimit64)
+ CALL(sys_accept4)
+ CALL(sys_recvmmsg)
+ CALL(sys_sendmmsg)
+/* 350 */ CALL(sys_fanotify_init)
+ CALL(sys_fanotify_mark)
+ CALL(sys_msgget)
+ CALL(sys_msgctl)
+ CALL(sys_msgrcv)
+/* 355 */ CALL(sys_msgsnd)
+ CALL(sys_semget)
+ CALL(sys_semctl)
+ CALL(sys_semtimedop)
+ CALL(sys_semop)
+/* 360 */ CALL(sys_shmget)
+ CALL(sys_shmctl)
+ CALL(sys_shmat)
+ CALL(sys_shmdt)
+ CALL(sys_syncfs)
+/* 365 */ CALL(sys_setns)
+ CALL(sys_name_to_handle_at)
+ CALL(sys_open_by_handle_at)
+ CALL(sys_process_vm_readv)
+ CALL(sys_process_vm_writev)
+/* 370 */ CALL(sys_clock_adjtime)
+ CALL(sys_get_mempolicy)
+ CALL(sys_mbind)
+ CALL(sys_perf_event_open)
+ CALL(sys_preadv)
+/* 375 */ CALL(sys_pwritev)
+ CALL(sys_rt_tgsigqueueinfo)
+ CALL(sys_set_mempolicy)
+ CALL(sys_epoll_pwait)
+
+#ifndef syscalls_counted
+.equ syscalls_padding, ((NR_syscalls + 3) & ~3) - NR_syscalls
+#define syscalls_counted
+#endif
+ .rept syscalls_padding
+ CALL(sys_ni_syscall)
+ .endr
diff -Nur linux-3.4.113.orig/arch/nds32/kernel/early_printk.c linux-3.4.113/arch/nds32/kernel/early_printk.c
--- linux-3.4.113.orig/arch/nds32/kernel/early_printk.c 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/kernel/early_printk.c 2016-12-01 20:59:24.352612751 +0100
@@ -0,0 +1,126 @@
+/*
+ * Earlyprintk support.
+ *
+ * Copyright (C) 2012 ARM Ltd.
+ * Author: Catalin Marinas <catalin.marinas@arm.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+#include <linux/kernel.h>
+#include <linux/console.h>
+#include <linux/init.h>
+#include <linux/string.h>
+#include <linux/mm.h>
+#include <linux/io.h>
+
+#include <linux/serial_reg.h>
+#include <asm/setup.h>
+
+extern void __iomem *early_io_map(phys_addr_t phys);
+static void __iomem *early_base;
+static void (*printch) (char ch);
+
+/*
+ * 8250/16550 (8-bit aligned registers) single character TX.
+ */
+static void uart8250_8bit_printch(char ch)
+{
+ while (!(readb(early_base + UART_LSR) & UART_LSR_THRE)) ;
+ writeb(ch, early_base + UART_TX);
+}
+
+/*
+ * 8250/16550 (32-bit aligned registers) single character TX.
+ */
+static void uart8250_32bit_printch(char ch)
+{
+ while (!(readl(early_base + (UART_LSR << 2)) & UART_LSR_THRE)) ;
+ writel(ch, early_base + (UART_TX << 2));
+}
+
+struct earlycon_match {
+ const char *name;
+ void (*printch) (char ch);
+};
+
+static const struct earlycon_match earlycon_match[] __initconst = {
+ {.name = "uart8250-8bit",.printch = uart8250_8bit_printch,},
+ {.name = "uart8250-32bit",.printch = uart8250_32bit_printch,},
+ {}
+};
+
+static void early_write(struct console *con, const char *s, unsigned n)
+{
+ while (n-- > 0) {
+ if (*s == '\n')
+ printch('\r');
+ printch(*s);
+ s++;
+ }
+}
+
+static struct console early_console_dev = {
+ .name = "earlycon",
+ .write = early_write,
+ .flags = CON_PRINTBUFFER | CON_BOOT,
+ .index = -1,
+};
+
+/*
+ * Parse earlyprintk=... parameter in the format:
+ *
+ * <name>[,<addr>][,<options>]
+ *
+ * and register the early console. It is assumed that the UART has been
+ * initialised by the bootloader already.
+ */
+static int __init setup_early_printk(char *buf)
+{
+ const struct earlycon_match *match = earlycon_match;
+ phys_addr_t paddr = 0;
+
+ if (!buf) {
+ pr_warning("No earlyprintk arguments passed.\n");
+ return 0;
+ }
+
+ while (match->name) {
+ size_t len = strlen(match->name);
+ if (!strncmp(buf, match->name, len)) {
+ buf += len;
+ break;
+ }
+ match++;
+ }
+ if (!match->name) {
+ pr_warning("Unknown earlyprintk arguments: %s\n", buf);
+ return 0;
+ }
+
+ /* I/O address */
+ if (!strncmp(buf, ",0x", 3)) {
+ char *e;
+ paddr = simple_strtoul(buf + 1, &e, 16);
+ buf = e;
+ }
+
+ if (paddr)
+ early_base = early_io_map(paddr);
+ printch = match->printch;
+ //early_console = &early_console_dev;
+ register_console(&early_console_dev);
+
+ return 0;
+}
+
+early_param("earlyprintk", setup_early_printk);
diff -Nur linux-3.4.113.orig/arch/nds32/kernel/elfchk.c linux-3.4.113/arch/nds32/kernel/elfchk.c
--- linux-3.4.113.orig/arch/nds32/kernel/elfchk.c 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/kernel/elfchk.c 2016-12-01 20:59:24.352612751 +0100
@@ -0,0 +1,190 @@
+#include <linux/module.h>
+#include <linux/kallsyms.h>
+#include <asm/hardware.h>
+#include <asm/uaccess.h>
+#include <asm/elf.h>
+#include <asm/fpu.h>
+#include <asm/audio.h>
+#include <linux/elf.h>
+#include <linux/proc_fs.h>
+
+#define ELF_CHECKING_OS
+#include "nds32-elf.h"
+
+extern struct proc_dir_entry *proc_dir_cpu;
+
+#ifdef CONFIG_ELFCHK_DEFAULT_ENABLE
+static int elf_check_en = 1;
+#else
+static int elf_check_en = 0;
+#endif
+
+struct reg_struct {
+
+ const char *name;
+ int idx;
+};
+
+static struct reg_struct regs[] = {
+
+ {"cpu_ver", CPU_SR_INDEX(0, 0, 0)},
+ {"icm_cfg", CPU_SR_INDEX(0, 1, 0)},
+ {"dcm_cfg", CPU_SR_INDEX(0, 2, 0)},
+ {"mmu_cfg", CPU_SR_INDEX(0, 3, 0)},
+ {"msc_cfg", CPU_SR_INDEX(0, 4, 0)},
+#ifdef CONFIG_FPU
+ {"fucop_exist", CPU_SR_INDEX(0, 5, 0)}
+#endif
+};
+
+#ifdef CONFIG_FPU
+static unsigned int read_fpu_fpcfg(void)
+{
+ unsigned int fpcfg = 0;
+
+ enable_fpu();
+ asm volatile ("fmfcfg %0\n\t":"=&r" (fpcfg));
+ disable_fpu();
+
+ return fpcfg;
+}
+#endif
+
+static unsigned int read_cpu_sr(unsigned int idx)
+{
+ switch (idx) {
+
+ case CPU_SR_INDEX(0, 0, 0):
+ return GET_CPU_VER();
+ case CPU_SR_INDEX(0, 1, 0):
+ return GET_ICM_CFG();
+ case CPU_SR_INDEX(0, 2, 0):
+ return GET_DCM_CFG();
+ case CPU_SR_INDEX(0, 3, 0):
+ return GET_MMU_CFG();
+ case CPU_SR_INDEX(0, 4, 0):
+ return GET_MSC_CFG();
+ case CPU_SR_INDEX(0, 5, 0):
+ return GET_FUCOP_EXIST();
+
+ default:
+ printk(KERN_ERR
+ "%s: invalid system register index (%d, %d, %d)\n",
+ __func__, (idx >> 7) & 0x7, (idx >> 3) & 0xf, idx & 0x7);
+
+ return SR_NOT_EXIST;
+ }
+}
+
+static unsigned int reg_read_callback(unsigned int idx)
+{
+ if (HW_IS_CPU(idx)) {
+
+ return read_cpu_sr(SR_INDEX(idx));
+ } else if (HW_IS_FPU(idx)) {
+
+#ifdef CONFIG_FPU
+ if (SR_FPU_FPCFG == SR_INDEX(idx))
+ return read_fpu_fpcfg();
+ else
+ return SR_NOT_EXIST;
+#endif
+ } else if (HW_IS_AUDIO(idx)) {
+
+ return SR_NOT_EXIST;
+ }
+
+ return SR_NOT_EXIST;
+}
+
+#define BUFLEN 1024
+
+int do_elf_check_arch(const struct elf32_hdr *hdr)
+{
+ static char msg_buf[BUFLEN];
+ unsigned int err;
+ int buf_status = 0;
+
+ if (!elf_check_en)
+ return 1;
+
+ err =
+ elf_check((void *)hdr, reg_read_callback, msg_buf, BUFLEN,
+ &buf_status);
+
+ if (err)
+ printk(KERN_WARNING "%s", msg_buf);
+
+ return !err;
+}
+
+static int proc_elf_check_read(char *page, char **start, off_t off, int count,
+ int *eof, void *data)
+{
+ return sprintf(page, "%d\n", elf_check_en);
+}
+
+#define INPUTLEN 10
+static int proc_elf_check_write(struct file *file, const char __user * buffer,
+ unsigned long count, void *data)
+{
+ unsigned long en;
+ char inbuf[INPUTLEN];
+
+ if (count > INPUTLEN - 1)
+ count = INPUTLEN - 1;
+
+ if (copy_from_user(inbuf, buffer, count))
+ return -EFAULT;
+
+ inbuf[count] = '\0';
+
+ if (!sscanf(inbuf, "%lu", &en) || en > 3)
+ return -EFAULT;
+
+ elf_check_en = en & 0x01;
+
+ return count;
+}
+
+static int proc_elf_check_read_reg(char *page, char **start,
+ off_t off, int count, int *eof, void *data)
+{
+ unsigned long val = read_cpu_sr(*(int *)data);
+
+ return sprintf(page, "0x%08lx\n", val);
+}
+
+int __init elf_check_init(void)
+{
+ static struct proc_dir_entry *res_elf_check;
+ int i;
+
+ if (!proc_dir_cpu) {
+ if (!(proc_dir_cpu = proc_mkdir("cpu", NULL)))
+ return -ENOMEM;
+ }
+
+ res_elf_check =
+ create_proc_entry("elf_core_checking", S_IWUSR | S_IRUGO,
+ proc_dir_cpu);
+ if (!res_elf_check)
+ return -ENOMEM;
+
+ res_elf_check->read_proc = proc_elf_check_read;
+ res_elf_check->write_proc = proc_elf_check_write;
+
+ for (i = 0; i < ARRAY_SIZE(regs); i++) {
+
+ if (!create_proc_read_entry(regs[i].name, S_IWUSR | S_IRUGO,
+ proc_dir_cpu,
+ proc_elf_check_read_reg,
+ ®s[i].idx))
+
+ return -ENOMEM;
+ }
+
+ return 0;
+}
+
+module_init(elf_check_init);
diff -Nur linux-3.4.113.orig/arch/nds32/kernel/ex-entry.S linux-3.4.113/arch/nds32/kernel/ex-entry.S
--- linux-3.4.113.orig/arch/nds32/kernel/ex-entry.S 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/kernel/ex-entry.S 2016-12-01 20:59:24.352612751 +0100
@@ -0,0 +1,294 @@
+#include <linux/linkage.h>
+#include <asm/memory.h>
+#include <asm/nds32.h>
+#include <asm/assembler.h>
+#include <asm/errno.h>
+#include <asm/asm-offsets.h>
+#include <asm/page.h>
+
+ .macro push_zol
+#ifdef CONFIG_HWZOL
+ mfusr $r10, $LB
+ mfusr $r11, $LE
+ mfusr $r12, $LC
+#endif
+ .endm
+ .macro save_user_regs
+ /* $p1 is VA of percpu data */
+ sethi $p0, hi20(PAGE_OFFSET - PHYS_OFFSET)
+ add $p1, $p1, $p0
+
+ /* change to kernel stack */
+ mfsr $p0, $IPSW
+ andi $p0, $p0, #PSW_mskPOM
+ cmovz $sp, $r25, $p0
+
+ /* 8 byte aligned */
+ movi $r25, #~7
+ and $r25, $sp, $r25
+ smw.adm $sp, [$r25], $sp, #0x1
+ move $sp, $r25
+
+#if defined(CONFIG_FPU) || defined(CONFIG_AUDIO)
+ mfsr $r25, $FUCOP_CTL
+ push $r25
+ bclr $r25, $r25, #FUCOP_CTL_offCP0EN
+ mtsr $r25, $FUCOP_CTL
+#else
+ addi $sp, $sp, -4
+#endif
+ pushm $r28, $r30
+
+ /* zero fp if user mode*/
+ movi $r25, #0x0
+ cmovz $fp, $r25, $p0
+
+ lwi $r25, [$p1+#0x0]
+ pushm $r0, $r25
+#ifdef CONFIG_HWZOL
+ push_zol
+#endif
+ mfsr $r9, $P_P1
+ mfsr $r8, $P_P0
+ mfsr $r7, $P_IPC
+ mfsr $r6, $P_IPSW
+ mfsr $r18, $IPC
+ mfsr $r17, $IPSW
+ mfsr $r16, $PSW
+ pushm $r6, $r13
+ push $r0
+ lwi $p0, [$p1+#0x8]
+ push $p0
+ pushm $r16, $r18
+
+ andi $r19, $r16, #PSW_mskINTL
+ slti $r20, $r19, #4
+ bnez $r20, 1f
+ addi $r21, $r16, #-2
+ mtsr $r21, $PSW
+ isb
+1:
+ addi $sp, $sp, -S_OFF
+ .endm
+
+ .text
+
+/*
+ * Exception Vector
+ */
+exception_handlers:
+ .long unhandled_exceptions !Reset/NMI
+ .long unhandled_exceptions !TLB fill
+ .long do_page_fault !PTE not present
+ .long do_dispatch_tlb_misc !TLB misc
+ .long unhandled_exceptions !TLB VLPT
+ .long unhandled_exceptions !Machine Error
+ .long do_debug_trap !Debug related
+ .long do_dispatch_general !General exception
+ .long eh_syscall !Syscall
+ .long asm_do_IRQ !IRQ
+
+common_exception_handler:
+ save_user_regs
+ lwi $p0, [$p1+#0x4]
+ andi $p1, $p0, #0x78
+ bnez $p1, 1f
+ sethi $lp, hi20(ret_from_exception)
+ ori $lp, $lp, lo12(ret_from_exception)
+ sethi $p1, hi20(exception_handlers)
+ ori $p1, $p1, lo12(exception_handlers)
+ lw $p1, [$p1+$p0<<2]
+ move $r0, $p0
+ mfsr $r1, $EVA
+ mfsr $r2, $ITYPE
+ move $r3, $sp
+ mfsr $r4, $OIPC
+ /* enable gie if it is enabled in IPSW. */
+ mfsr $r21, $PSW
+ andi $r17, $r17, #0x1
+ or $r21, $r21, $r17
+ mtsr $r21, $PSW
+ dsb
+ jr $p1
+
+ /* syscall */
+1:
+ addi $p1, $p0, #-8
+ bnez $p1, 2f
+ sethi $lp, hi20(ret_from_exception)
+ ori $lp, $lp, lo12(ret_from_exception)
+ sethi $p1, hi20(exception_handlers)
+ ori $p1, $p1, lo12(exception_handlers)
+ lwi $p1, [$p1+#0x8<<2]
+ jr $p1
+
+ /* interrupt */
+2:
+#ifdef CONFIG_TRACE_IRQFLAGS
+ jal arch_trace_hardirqs_off
+#endif
+#if defined(CONFIG_EVIC) || defined(CONFIG_IVIC)
+ addi $r0, $p0, #-9
+#else
+# ifdef CONFIG_IVIC_INTC
+ jal get_IntSrc
+# else
+# error "Not configure Vector Interrupt Controller mode"
+# endif
+#endif
+ move $r1, $sp
+ sethi $lp, hi20(ret_from_intr)
+ ori $lp, $lp, lo12(ret_from_intr)
+ sethi $p0, hi20(exception_handlers)
+ ori $p0, $p0, lo12(exception_handlers)
+ lwi $p0, [$p0+#0x9<<2]
+ jr $p0
+
+ .macro EXCEPTION_VECTOR, num
+ .align 6
+ .ifc \num, 6
+ mfsr $p0, $EDM_CTL
+ andi $p0, $p0, EDM_CTL_mskV3_EDM_MODE
+ tnez $p0, 0x1a
+ .endif
+ /* $p1 is PA of percpu data */
+#ifdef CONFIG_CPU_N1213_43U1HA0
+ movi $p1, #0x0
+#else
+ mfsr $p1, $CORE_ID
+#endif
+ slli $p1, $p1, #0x9
+ li $p0, #(PHYS_OFFSET+0x6000)
+ or $p1, $p1, $p0
+
+ /*
+ * 0x0 saved $r25
+ * 0x4 vector number
+ * 0x8 user stack pointer
+ * 0xc kernel stack pointer
+ */
+ swi $r25, [$p1+0x0]
+ movi $p0, \num
+ swi $p0, [$p1+#0x4]
+ swi $sp, [$p1+#0x8]
+ lwi $r25, [$p1+#0xc]
+ sethi $p0, hi20(common_exception_handler)
+ ori $p0, $p0, lo12(common_exception_handler)
+ jral.ton $p0, $p0
+ .endm
+
+ .macro IPI_VECTOR, num
+ .align 6
+#ifdef CONFIG_CPU_N1213_43U1HA0
+ movi $p1, #0x0
+#else
+ mfsr $p1, $CORE_ID
+#endif
+ slli $p1, $p1, #0x9
+ li $p0, #(PHYS_OFFSET+0x6000)
+ or $p1, $p1, $p0
+
+ /*
+ * 0x10 indicator of CPU is initialized
+ * 0x14 CPU init function
+ */
+ swi $r25, [$p1+0x0]
+ movi $p0, \num
+ swi $p0, [$p1+#0x4]
+ swi $sp, [$p1+#0x8]
+ lwi $r25, [$p1+#0xc]
+ lwi $p0, [$p1+#0x10]
+ beqz $p0, 1f
+ sethi $p0, hi20(common_exception_handler)
+ ori $p0, $p0, lo12(common_exception_handler)
+ jral.ton $p0, $p0
+1:
+ lwi $p0, [$p1+#0x14]
+ jr $p0
+
+ .endm
+
+ .section ".text.init", #alloc, #execinstr
+ .global exception_vector
+exception_vector:
+ EXCEPTION_VECTOR 0
+ EXCEPTION_VECTOR 1
+ EXCEPTION_VECTOR 2
+ EXCEPTION_VECTOR 3
+ EXCEPTION_VECTOR 4
+ EXCEPTION_VECTOR 5
+ EXCEPTION_VECTOR 6
+ EXCEPTION_VECTOR 7
+ EXCEPTION_VECTOR 8
+#ifdef CONFIG_EVIC
+ EXCEPTION_VECTOR 9
+#else
+ IPI_VECTOR 9
+#endif
+ EXCEPTION_VECTOR 10
+ EXCEPTION_VECTOR 11
+ EXCEPTION_VECTOR 12
+ EXCEPTION_VECTOR 13
+ EXCEPTION_VECTOR 14
+ EXCEPTION_VECTOR 15
+ EXCEPTION_VECTOR 16
+ EXCEPTION_VECTOR 17
+ EXCEPTION_VECTOR 18
+ EXCEPTION_VECTOR 19
+ EXCEPTION_VECTOR 20
+ EXCEPTION_VECTOR 21
+ EXCEPTION_VECTOR 22
+ EXCEPTION_VECTOR 23
+ EXCEPTION_VECTOR 24
+ EXCEPTION_VECTOR 25
+ EXCEPTION_VECTOR 26
+ EXCEPTION_VECTOR 27
+ EXCEPTION_VECTOR 28
+ EXCEPTION_VECTOR 29
+ EXCEPTION_VECTOR 30
+ EXCEPTION_VECTOR 31
+ EXCEPTION_VECTOR 32
+ EXCEPTION_VECTOR 33
+ EXCEPTION_VECTOR 34
+ EXCEPTION_VECTOR 35
+ EXCEPTION_VECTOR 36
+ EXCEPTION_VECTOR 37
+ EXCEPTION_VECTOR 38
+ EXCEPTION_VECTOR 39
+ EXCEPTION_VECTOR 40
+#ifdef CONFIG_EVIC
+ IPI_VECTOR 41
+#else
+ EXCEPTION_VECTOR 41
+#endif
+ EXCEPTION_VECTOR 42
+ EXCEPTION_VECTOR 43
+ EXCEPTION_VECTOR 44
+ EXCEPTION_VECTOR 45
+ EXCEPTION_VECTOR 46
+ EXCEPTION_VECTOR 47
+ EXCEPTION_VECTOR 48
+ EXCEPTION_VECTOR 49
+ EXCEPTION_VECTOR 50
+ EXCEPTION_VECTOR 51
+ EXCEPTION_VECTOR 52
+ EXCEPTION_VECTOR 53
+ EXCEPTION_VECTOR 54
+ EXCEPTION_VECTOR 55
+ EXCEPTION_VECTOR 56
+ EXCEPTION_VECTOR 57
+ EXCEPTION_VECTOR 58
+ EXCEPTION_VECTOR 59
+ EXCEPTION_VECTOR 60
+ EXCEPTION_VECTOR 61
+ EXCEPTION_VECTOR 62
+ EXCEPTION_VECTOR 63
+ EXCEPTION_VECTOR 64
+ EXCEPTION_VECTOR 65
+ EXCEPTION_VECTOR 66
+ EXCEPTION_VECTOR 67
+ EXCEPTION_VECTOR 68
+ EXCEPTION_VECTOR 69
+ EXCEPTION_VECTOR 70
+ EXCEPTION_VECTOR 71
+ EXCEPTION_VECTOR 72
diff -Nur linux-3.4.113.orig/arch/nds32/kernel/ex-exit.S linux-3.4.113/arch/nds32/kernel/ex-exit.S
--- linux-3.4.113.orig/arch/nds32/kernel/ex-exit.S 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/kernel/ex-exit.S 2016-12-01 20:59:24.352612751 +0100
@@ -0,0 +1,220 @@
+#include <linux/linkage.h>
+#include <asm/unistd.h>
+#include <asm/assembler.h>
+#include <asm/nds32.h>
+#include <asm/asm-offsets.h>
+#include <asm/thread_info.h>
+
+#define why $r8 // Linux syscall (!= 0)
+#define tsk $r9 // current thread_info
+
+
+ .macro pop_zol
+#ifdef CONFIG_HWZOL
+ mtusr $r10, $LB
+ mtusr $r11, $LE
+ mtusr $r12, $LC
+#endif
+ .endm
+
+ .macro restore_user_regs_first
+ setgie.d
+ isb
+ /* $p1 is VA of percpu data */
+#ifdef CONFIG_CPU_N1213_43U1HA0
+ movi $p1, #0x0
+#else
+ mfsr $p1, $CORE_ID
+#endif
+ andi $p1, $p1, #0x3
+ slli $p1, $p1, #0x9
+ sethi $p0, #0xc0006
+ or $p1, $p1, $p0
+
+ addi $sp, $sp, S_OFF
+ popm $r16, $r18
+ mtsr $r16, $PSW
+ pop $r16
+ swi $r16, [$p1+#0x8]
+ addi $sp, $sp, #4 !pop $r0
+ popm $r6, $r13
+ mtsr $r17, $IPSW
+ mtsr $r18, $IPC
+ mtsr $r6, $P_IPSW
+ mtsr $r7, $P_IPC
+ mtsr $r8, $P_P0
+ mtsr $r9, $P_P1
+#ifdef CONFIG_HWZOL
+ pop_zol
+#endif
+ .endm
+
+ .macro restore_user_regs_last
+ popm $r28, $r30
+#if defined(CONFIG_FPU) || defined(CONFIG_AUDIO)
+ pop $p0
+ mtsr $p0, $FUCOP_CTL
+#else
+ addi $sp, $sp, 4
+#endif
+
+ pop $p0
+ cmovn $sp, $p0, $p0
+
+ mfsr $p0, $IPSW
+ andi $p0, $p0, #PSW_mskPOM
+ bnez $p0, 1f
+ swi $sp, [$p1+#0xc]
+ lwi $sp, [$p1+#0x8]
+1:
+ // This is SW workaround for Bug #6294
+ li $p0, 0xc0000000
+ cctl $p0, L1D_VA_INVAL
+ lwi $p1, [$p0]
+
+ iret
+ nop
+
+ .endm
+
+ .macro restore_user_regs
+ restore_user_regs_first
+ popm $r0, $r25
+ restore_user_regs_last
+ .endm
+
+ .macro fast_restore_user_regs
+ restore_user_regs_first
+ addi $sp, $sp, #4
+ popm $r1, $r25
+ restore_user_regs_last
+ .endm
+
+#ifdef CONFIG_PREEMPT
+ .macro preempt_stop
+ .endm
+#else
+ .macro preempt_stop
+ setgie.d
+ isb
+ .endm
+#define resume_kernel no_work_pending
+#endif
+
+ENTRY(ret_from_exception)
+ preempt_stop
+ENTRY(ret_from_intr)
+ get_thread_info tsk
+ move why, #0 ! not system call
+
+/*
+ * judge Kernel or user mode
+ *
+ */
+ lwi $p0, [$sp+(#S_IPSW+#S_OFF)]
+! mfsr $p0, $IPSW ! Check if in nested interrupt
+ andi $p0, $p0, #PSW_mskINTL
+ bnez $p0, resume_kernel ! done with iret
+ j resume_userspace
+
+
+/*
+ * This is the fast syscall return path. We do as little as
+ * possible here, and this includes saving $r0 back into the SVC
+ * stack.
+ * fixed: tsk - $r9, why - $r8, $r7 - syscall #, $r8 - syscall table pointer
+ */
+ENTRY(ret_fast_syscall)
+ gie_disable
+ lwi $r1, [tsk+#TI_FLAGS]
+ andi $p1, $r1, #_TIF_WORK_MASK
+ bnez $p1, fast_work_pending
+ fast_restore_user_regs ! iret
+
+/*
+ * Ok, we need to do extra processing,
+ * enter the slow path returning from syscall, while pending work.
+ */
+fast_work_pending:
+ swi $r0, [$sp+(#S_R0+#S_OFF)] ! what is different from ret_from_exception
+ ! addi $sp, $sp, S_OFF
+ move why, #1 ! come from a syscall
+work_pending:
+ andi $p1, $r1, #_TIF_NEED_RESCHED
+ bnez $p1, work_resched
+
+ andi $p1, $r1, #_TIF_SIGPENDING|#_TIF_NOTIFY_RESUME
+ beqz $p1, no_work_pending
+
+ move $r0, $sp ! 'regs'
+ move $r2, why
+ gie_enable
+ bal do_notify_resume
+
+ b ret_slow_syscall ! return from slow_restore_user_regs
+
+work_resched:
+ bal schedule ! path, return to user mode
+
+/*
+ * "slow" syscall return path.
+ * "why" tells us if this was a real syscall.
+ */
+ENTRY(resume_userspace)
+ENTRY(ret_slow_syscall)
+ gie_disable
+ lwi $p0, [$sp+(#S_IPSW+#S_OFF)]
+! mfsr $p0, $IPSW ! Check if in nested interrupt
+ andi $p0, $p0, #PSW_mskINTL
+ bnez $p0, no_work_pending ! done with iret
+ lwi $r1, [tsk+#TI_FLAGS]
+ andi $p1, $r1, #_TIF_WORK_MASK
+ bnez $p1, work_pending ! handle work_resched, sig_pend
+
+no_work_pending:
+#ifdef CONFIG_TRACE_IRQFLAGS
+ lwi $p0, [$sp+(#S_IPSW+#S_OFF)]
+ andi $p0, $p0, #0x1
+ la $r10, arch_trace_hardirqs_off
+ la $r9, arch_trace_hardirqs_on
+ cmovz $r9, $p0, $r10
+ jral $r9
+#endif
+ restore_user_regs ! return from iret
+
+
+/*
+ * preemptive kernel
+ */
+#ifdef CONFIG_PREEMPT
+resume_kernel:
+ gie_disable
+ lwi $t0, [tsk+#TI_PREEMPT]
+ bnez $t0, no_work_pending
+need_resched:
+ lwi $t0, [tsk+#TI_FLAGS]
+ andi $p1, $t0, #_TIF_NEED_RESCHED
+ beqz $p1, no_work_pending
+
+ lwi $t0, [$sp+(#S_IPSW+#S_OFF)] ! Interrupts off?
+ andi $t0, $t0, #1
+ beqz $t0, no_work_pending
+
+ jal preempt_schedule_irq
+ b need_resched
+#endif
+
+/*
+ * This is how we return from a fork.
+ */
+ENTRY(ret_from_fork)
+ bal schedule_tail
+ get_thread_info tsk
+ lwi $r1, [tsk+#TI_FLAGS] ! check for syscall tracing
+ move why, #1
+ andi $p1, $r1, #_TIF_WORK_SYSCALL_LEAVE ! are we tracing syscalls?
+ beqz $p1, ret_slow_syscall
+ move $r0, $sp
+ bal syscall_trace_leave
+ b ret_slow_syscall
+
diff -Nur linux-3.4.113.orig/arch/nds32/kernel/ex-scall.S linux-3.4.113/arch/nds32/kernel/ex-scall.S
--- linux-3.4.113.orig/arch/nds32/kernel/ex-scall.S 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/kernel/ex-scall.S 2016-12-01 20:59:24.352612751 +0100
@@ -0,0 +1,288 @@
+#include <linux/linkage.h>
+#include <asm/unistd.h>
+#include <asm/assembler.h>
+#include <asm/nds32.h>
+#include <asm/asm-offsets.h>
+#include <asm/thread_info.h>
+
+/*
+ * $r0 = previous task_struct,
+ * $r1 = previous thread_info,
+ * $r2 = next thread_info
+ * previous and next are guaranteed not to be the same.
+ */
+
+ENTRY(_switch)
+ smw.adm $r6, [$sp], $r14, #0xa
+ swi $sp, [$r1+ TI_SP_SAVE] /* Save $sp to task structure */
+ lwi $sp, [$r2+ TI_SP_SAVE] /* Get $sp from task structure */
+ lmw.bim $r6, [$sp], $r14, #0xa
+ ret
+
+/*
+ * These are the registers used in the syscall handler, and allow us
+ * to have in theory up to 6 arguments to a function - $r0 to $r5.
+ * $r7 is reserved for the system call number for Andes architecture.
+ *
+ * Note that tbl == why is intentional.
+ * We must set at least "tsk" and "why" when calling ret_with_reschedule.
+ */
+#define tbl $r8 // syscall table pointer
+#define why $r8 // Linux syscall (!= 0)
+#define tsk $r9 // current thread_info
+
+/*
+ * Get the system call number. let $r7 take a system call nr.
+ *
+ * if it is called from library function, $r7 is filled by library call
+ * when user program make a system call. and swid bitfield of $ir6 will
+ * always be encoded as 0x7fff.
+ *
+ * if it is called from kernel code, $r7 will be writen as syscall nr
+ * by retrieving from $ir6 'swid' bitfiled
+ */
+ .macro get_scno
+ mfsr $r7, $ITYPE
+#ifdef CONFIG_PLAT_QEMU
+ slli $r7, $r7, #1
+ srli $r7, $r7, #ITYPE_offSWID+1
+#else
+ srli $r7, $r7, #ITYPE_offSWID
+#endif
+ .endm
+
+ .macro updateipc
+ addi $r17, $r18, #4
+ swi $r17, [$sp + S_OFF + S_IPC]
+ .endm
+
+ .equ NR_syscalls,0
+#define CALL(x) .equ NR_syscalls,NR_syscalls+1
+#include "calls.S"
+#undef CALL
+#define CALL(x) .long x
+
+ENTRY(eh_syscall)
+ updateipc
+
+ get_scno
+ gie_enable
+ get_thread_info tsk
+ lwi $p0, [tsk+#TI_FLAGS] ! check for syscall tracing
+
+ andi $p1, $p0, #_TIF_WORK_SYSCALL_ENTRY ! are we tracing syscalls?
+ bnez $p1, __sys_trace
+
+ la $lp, ret_fast_syscall ! return address
+
+ li $p0, __NR_NDS32_BASE
+ addi $p0, $p0, -1
+ slt $p0, $p0, $r7
+ beqz $p0, 1f
+ addi $r1, $SP, #0
+ move $r0, $r7
+ b nds32_syscall
+1:
+ ! check upper syscall limit,
+ andi $r7, $r7, #0xfff
+ addi $p1, $r7, #-NR_syscalls ! syscall number of syscall instruction is guarded by addembler
+ bgez $p1, _SCNO_EXCEED ! call sys_* routine
+ la tbl, sys_call_table ! load syscall table pointer
+ slli $p1, $r7, #2
+ add $p1, tbl, $p1
+ lwi $p1, [$p1]
+ jr $p1 ! no return
+
+_SCNO_EXCEED:
+ ori $r0, $r7, #0
+ ori $r1, $sp, #0
+ b bad_syscall
+
+/*
+ * This is the really slow path. We're going to be doing
+ * context switches, and waiting for our parent to respond.
+ */
+__sys_trace:
+ move $r1, $sp
+ move $r0, $r7 ! trace entry [IP = 0]
+ bal syscall_trace_enter
+ move $r7, $r0
+ la $lp, __sys_trace_return ! return address
+
+ li $p0, __NR_NDS32_BASE
+ addi $p0, $p0, -1
+ slt $p0, $p0, $r7
+ beqz $p0, 1f
+ addi $r1, $SP, #0
+ b nds32_syscall
+1:
+ andi $r7, $r7, #0xfff
+ addi $p1, $sp, #S_R0+S_OFF ! pointer to regs
+ addi $p0, $r7, -#NR_syscalls ! check upper syscall limit
+ bgez $p0, _SCNO_EXCEED
+ lmw.bi $r0, [$p1], $r5 ! have to reload $r0 - $r5
+
+ slli $p0, $r7, #2 ! call sys_* routine
+ la tbl, sys_call_table ! load syscall table pointer
+ add $p0, tbl, $p0
+ lwi $p0, [$p0]
+ jr $p0
+
+__sys_trace_return:
+ swi $r0, [$sp+(#S_R0+S_OFF)] ! T: save returned $r0
+ bal syscall_trace_leave
+ b ret_slow_syscall
+
+ .type sys_call_table, #object
+ENTRY(sys_call_table)
+#include "calls.S"
+
+/*
+ * Special system call wrappers
+ *
+ * $r0 = syscall number
+ * $r8 = syscall table
+ */
+ .type sys_syscall, #function
+sys_syscall:
+
+ li $p0, __NR_NDS32_BASE
+ addi $p0, $p0, -1
+ slt $p0, $p0, $r0
+ beqz $p0, 1f
+ addi $r1, $SP, #0
+ b nds32_syscall
+1:
+ bltz $r0, 3f ! Guard whether syscall number is between 0~0x7fff.
+ andi $r0, $r0, #0xfff
+ addi $p1, $r0, #-NR_syscalls
+ bgtz $p1, 3f
+ move $p1, $r0
+ move $r0, $r1
+ move $r1, $r2
+ move $r2, $r3
+ move $r3, $r4
+ move $r4, $r5
+! add for syscall 6 args
+ lwi $r5, [$sp + (#S_SP + #S_OFF) ]
+ lwi $r5, [$r5 + #S_OFF]
+! ~add for syscall 6 args
+
+ lw $p1, [tbl+$p1<<2]
+ jr $p1
+3: b sys_ni_syscall
+
+sys_fork_wrapper:
+ addi $r0, $sp, #0
+ b sys_fork
+
+sys_vfork_wrapper:
+ addi $r0, $sp, #0
+ b sys_vfork
+
+sys_execve_wrapper:
+ addi $r3, $sp, #0
+ b sys_execve
+
+sys_clone_wrapper:
+ addi $r5, $SP, #0
+ b sys_clone
+
+sys_sigsuspend_wrapper:
+ addi $r3, $sp, #0
+ b sys_sigsuspend
+
+sys_rt_sigsuspend_wrapper:
+ addi $r2, $sp, #0
+ b sys_rt_sigsuspend
+
+sys_sigreturn_wrapper:
+ addi $r0, $sp, #0
+ b sys_sigreturn
+
+sys_rt_sigreturn_wrapper:
+ addi $r0, $sp, #0
+ b sys_rt_sigreturn
+
+sys_sigaltstack_wrapper:
+ lwi $r2, [$sp+(#S_OFF + S_SP)]
+ b do_sigaltstack
+
+sys_futex_wrapper:
+ b sys_futex
+
+#ifdef CONFIG_FUNCTION_TRACER
+ .global _mcount
+ .global ftrace_stub
+_mcount:
+ sethi $r15, hi20(function_trace_stop)
+ lwi $r15, [$r15 + lo12(function_trace_stop)]
+ bnez $r15, _ftrace_stub
+
+ sethi $r15, hi20(ftrace_trace_function)
+ lwi $p0, [$r15 + lo12(ftrace_trace_function)]
+ sethi $r15, hi20(ftrace_stub)
+ ori $r15, $r15, lo12(ftrace_stub)
+ bne $r15, $p0, trace
+
+#ifdef CONFIG_FUNCTION_GRAPH_TRACER
+ sethi $p0, hi20(ftrace_graph_return)
+ lwi $p0, [$p0 + lo12(ftrace_graph_return)]
+ bne $r15, $p0, _ftrace_graph_caller
+
+ sethi $r15, hi20(ftrace_graph_entry)
+ lwi $r15, [$r15 + lo12(ftrace_graph_entry)]
+ sethi $p0, hi20(ftrace_graph_entry_stub)
+ ori $p0, $p0, lo12(ftrace_graph_entry_stub)
+ bne $r15, $p0, _ftrace_graph_caller
+#endif
+
+_ftrace_stub:
+ftrace_stub:
+ ret
+
+trace:
+ smw.adm $r0, [$sp], $r5, #10
+ move $r0, $lp
+ sethi $r15, hi20(get_selfpc)
+ ori $r15, $r15, lo12(get_selfpc)
+ jral $r15
+ move $r1, $r0
+ lwi $r0, [$sp+36]
+ jral $p0
+ lmw.bim $r0, [$sp], $r5, #10
+ ret
+#endif
+
+#ifdef CONFIG_FUNCTION_GRAPH_TRACER
+ .global ftrace_graph_caller
+ .global return_to_handler
+_ftrace_graph_caller:
+ftrace_graph_caller:
+ sethi $p1, hi20(function_trace_stop)
+ lwi $p1, [$p1 + lo12(function_trace_stop)]
+ bnez $p1, ftrace_stub
+
+ sethi $p1, hi20(prepare_ftrace_return)
+ ori $p1, $p1, lo12(prepare_ftrace_return)
+
+ smw.adm $r0, [$sp], $r5, #10
+ move $r0, $lp
+ sethi $p0, hi20(get_selfpc)
+ ori $p0, $p0, lo12(get_selfpc)
+ jral $p0
+ move $r1, $r0
+ addi $r0, $sp, #36
+ jral $p1
+ lmw.bim $r0, [$sp], $r5, #10
+ ret
+
+return_to_handler:
+ smw.adm $r0, [$sp], $r5, #10
+ sethi $r15, hi20(ftrace_return_to_handler)
+ ori $r15, $r15, lo12(ftrace_return_to_handler)
+ jral $r15
+ move $r15, $r0
+ lmw.bim $r0, [$sp], $r5, #10
+ jr $r15
+#endif
diff -Nur linux-3.4.113.orig/arch/nds32/kernel/fpu.c linux-3.4.113/arch/nds32/kernel/fpu.c
--- linux-3.4.113.orig/arch/nds32/kernel/fpu.c 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/kernel/fpu.c 2016-12-01 20:59:24.352612751 +0100
@@ -0,0 +1,306 @@
+/*
+ * arch/nds32/kernel/fpu.c
+ *
+ * Copyright (C) 2001 Manuela Cirronis, Paolo Alberelli
+ * Copyright (C) 2002 STMicroelectronics Limited
+ * Author : Stuart Menefy
+ * Copyright (C) 2009 Andes Technology Corporation
+ *
+ * Started from SH4 version:
+ * Copyright (C) 1999, 2000 Kaz Kojima & Niibe Yutaka
+ *
+ * This file is subject to the terms and conditions of the GNU General Public
+ * License. See the file "COPYING" in the main directory of this archive
+ * for more details.
+ */
+#include <linux/sched.h>
+#include <linux/signal.h>
+#include <asm/processor.h>
+#include <asm/user.h>
+#include <asm/io.h>
+#include <asm/bitfield.h>
+#include <asm/fpu.h>
+#include "fpu.h"
+
+extern void do_revinsn(struct pt_regs *regs);
+extern int do_fpu_denorm(struct pt_regs *regs, struct fpu_struct *fpu);
+
+static struct fpu_struct init_fpuregs = {
+ .fs_regs = {[0 ... 31] = sNAN32},
+ .fd_regs = {[0 ... 15] = sNAN64},
+ .fpcsr = FPCSR_INIT
+};
+
+void save_fpu(struct task_struct *tsk)
+{
+ unsigned int fpcfg, fpcsr;
+ enable_fpu();
+ asm volatile ("fmfcfg %0\n\t":"=&r" (fpcfg));
+ fpcfg = ((fpcfg & FPCFG_mskFREG) >> FPCFG_offFREG);
+
+ switch (fpcfg) {
+ case 3:
+ asm volatile ("fsdi $fd31, [%0+0xf8]\n\t"
+ "fsdi $fd30, [%0+0xf0]\n\t"
+ "fsdi $fd29, [%0+0xe8]\n\t"
+ "fsdi $fd28, [%0+0xe0]\n\t"
+ "fsdi $fd27, [%0+0xd8]\n\t"
+ "fsdi $fd26, [%0+0xd0]\n\t"
+ "fsdi $fd25, [%0+0xc8]\n\t"
+ "fsdi $fd24, [%0+0xc0]\n\t"
+ "fsdi $fd23, [%0+0xb8]\n\t"
+ "fsdi $fd22, [%0+0xb0]\n\t"
+ "fsdi $fd21, [%0+0xa8]\n\t"
+ "fsdi $fd20, [%0+0xa0]\n\t"
+ "fsdi $fd19, [%0+0x98]\n\t"
+ "fsdi $fd18, [%0+0x90]\n\t"
+ "fsdi $fd17, [%0+0x88]\n\t"
+ "fsdi $fd16, [%0+0x80]\n\t"
+ : /* no output */
+ :"r" (&tsk->thread.fpu)
+ :"memory");
+ /* fall through */
+ case 2:
+ asm volatile ("fssi $fs31, [%0+0x7c]\n\t"
+ "fssi $fs30, [%0+0x78]\n\t"
+ "fssi $fs29, [%0+0x74]\n\t"
+ "fssi $fs28, [%0+0x70]\n\t"
+ "fssi $fs27, [%0+0x6c]\n\t"
+ "fssi $fs26, [%0+0x68]\n\t"
+ "fssi $fs25, [%0+0x64]\n\t"
+ "fssi $fs24, [%0+0x60]\n\t"
+ "fssi $fs23, [%0+0x5c]\n\t"
+ "fssi $fs22, [%0+0x58]\n\t"
+ "fssi $fs21, [%0+0x54]\n\t"
+ "fssi $fs20, [%0+0x50]\n\t"
+ "fssi $fs19, [%0+0x4c]\n\t"
+ "fssi $fs18, [%0+0x48]\n\t"
+ "fssi $fs17, [%0+0x44]\n\t"
+ "fssi $fs16, [%0+0x40]\n\t"
+ : /* no output */
+ :"r" (&tsk->thread.fpu)
+ :"memory");
+ /* fall through */
+ case 1:
+ asm volatile ("fssi $fs15, [%0+0x3c]\n\t"
+ "fssi $fs14, [%0+0x38]\n\t"
+ "fssi $fs13, [%0+0x34]\n\t"
+ "fssi $fs12, [%0+0x30]\n\t"
+ "fssi $fs11, [%0+0x2c]\n\t"
+ "fssi $fs10, [%0+0x28]\n\t"
+ "fssi $fs9, [%0+0x24]\n\t"
+ "fssi $fs8, [%0+0x20]\n\t"
+ : /* no output */
+ :"r" (&tsk->thread.fpu)
+ :"memory");
+ /* fall through */
+ case 0:
+ asm volatile ("fssi $fs7, [%1+0x1c]\n\t"
+ "fssi $fs6, [%1+0x18]\n\t"
+ "fssi $fs5, [%1+0x14]\n\t"
+ "fssi $fs4, [%1+0x10]\n\t"
+ "fssi $fs3, [%1+0xc]\n\t"
+ "fssi $fs2, [%1+0x8]\n\t"
+ "fssi $fs1, [%1+0x4]\n\t"
+ "fssi $fs0, [%1+0x0]\n\t"
+ "fmfcsr %0\n\t"
+ "swi %0, [%1+0x100]\n\t"
+ :"=&r" (fpcsr)
+ :"r"(&tsk->thread.fpu)
+ :"memory");
+ }
+ disable_fpu();
+}
+
+void fpload(struct fpu_struct *fpregs)
+{
+ unsigned int fpcfg, fpcsr;
+ enable_fpu();
+
+ asm volatile ("fmfcfg %0\n\t":"=&r" (fpcfg));
+ fpcfg = ((fpcfg & FPCFG_mskFREG) >> FPCFG_offFREG);
+
+ switch (fpcfg) {
+ case 3:
+ asm volatile ("fldi $fd31, [%0+0xf8]\n\t"
+ "fldi $fd30, [%0+0xf0]\n\t"
+ "fldi $fd29, [%0+0xe8]\n\t"
+ "fldi $fd28, [%0+0xe0]\n\t"
+ "fldi $fd27, [%0+0xd8]\n\t"
+ "fldi $fd26, [%0+0xd0]\n\t"
+ "fldi $fd25, [%0+0xc8]\n\t"
+ "fldi $fd24, [%0+0xc0]\n\t"
+ "fldi $fd23, [%0+0xb8]\n\t"
+ "fldi $fd22, [%0+0xb0]\n\t"
+ "fldi $fd21, [%0+0xa8]\n\t"
+ "fldi $fd20, [%0+0xa0]\n\t"
+ "fldi $fd19, [%0+0x98]\n\t"
+ "fldi $fd18, [%0+0x90]\n\t"
+ "fldi $fd17, [%0+0x88]\n\t"
+ "fldi $fd16, [%0+0x80]\n\t"
+ : /* no output */
+ :"r" (fpregs));
+ /* fall through */
+ case 2:
+ asm volatile ("flsi $fs31, [%0+0x7c]\n\t"
+ "flsi $fs30, [%0+0x78]\n\t"
+ "flsi $fs29, [%0+0x74]\n\t"
+ "flsi $fs28, [%0+0x70]\n\t"
+ "flsi $fs27, [%0+0x6c]\n\t"
+ "flsi $fs26, [%0+0x68]\n\t"
+ "flsi $fs25, [%0+0x64]\n\t"
+ "flsi $fs24, [%0+0x60]\n\t"
+ "flsi $fs23, [%0+0x5c]\n\t"
+ "flsi $fs22, [%0+0x58]\n\t"
+ "flsi $fs21, [%0+0x54]\n\t"
+ "flsi $fs20, [%0+0x50]\n\t"
+ "flsi $fs19, [%0+0x4c]\n\t"
+ "flsi $fs18, [%0+0x48]\n\t"
+ "flsi $fs17, [%0+0x44]\n\t"
+ "flsi $fs16, [%0+0x40]\n\t"
+ : /* no output */
+ :"r" (fpregs));
+ /* fall through */
+ case 1:
+ asm volatile ("flsi $fs15, [%0+0x3c]\n\t"
+ "flsi $fs14, [%0+0x38]\n\t"
+ "flsi $fs13, [%0+0x34]\n\t"
+ "flsi $fs12, [%0+0x30]\n\t"
+ "flsi $fs11, [%0+0x2c]\n\t"
+ "flsi $fs10, [%0+0x28]\n\t"
+ "flsi $fs9, [%0+0x24]\n\t"
+ "flsi $fs8, [%0+0x20]\n\t"
+ : /* no output */
+ :"r" (fpregs));
+ /* fall through */
+ case 0:
+ asm volatile ("flsi $fs7, [%1+0x1c]\n\t"
+ "flsi $fs6, [%1+0x18]\n\t"
+ "flsi $fs5, [%1+0x14]\n\t"
+ "flsi $fs4, [%1+0x10]\n\t"
+ "flsi $fs3, [%1+0xc]\n\t"
+ "flsi $fs2, [%1+0x8]\n\t"
+ "flsi $fs1, [%1+0x4]\n\t"
+ "flsi $fs0, [%1+0x0]\n\t"
+ "lwi %0, [%1+0x100]\n\t"
+ "fmtcsr %0\n\t":"=&r" (fpcsr)
+ :"r"(fpregs));
+ }
+ disable_fpu();
+}
+
+void do_fpu_context_switch(unsigned long error_code, struct pt_regs *regs)
+{
+ /* Enable to use FPU. */
+
+ if (!user_mode(regs)) {
+ printk(KERN_ERR "BUG: FPU is used in kernel mode.\n");
+ BUG();
+ return;
+ }
+
+ grab_fpu(regs);
+#ifndef CONFIG_UNLAZY_FPU //Lazy FPU is used
+ if (last_task_used_math == current)
+ return;
+ if (last_task_used_math != NULL)
+ /* Other processes fpu state, save away */
+ save_fpu(last_task_used_math);
+ last_task_used_math = current;
+#endif
+ if (used_math()) {
+ fpload(¤t->thread.fpu);
+ } else {
+ /* First time FPU user. */
+ fpload(&init_fpuregs);
+ set_used_math();
+ }
+
+}
+
+void do_fpu_exception(unsigned long error_code, struct pt_regs *regs)
+{
+ unsigned int subtype =
+ ((GET_ITYPE() & ITYPE_mskSTYPE) >> ITYPE_offSTYPE);
+ unsigned int cpid = ((GET_ITYPE() & ITYPE_mskCPID) >> ITYPE_offCPID);
+
+ /* FPU */
+ if ((cpid == 0) && (GET_FUCOP_EXIST() & FUCOP_EXIST_mskCP0ISFPU)) {
+ /* Coprocessor disabled exception */
+ if (subtype == 1) {
+ preempt_disable();
+ do_fpu_context_switch(error_code, regs);
+ preempt_enable();
+ }
+ /* Coprocessor exception */
+ else if (subtype == 2) {
+ siginfo_t si = { 0 };
+ unsigned int fpcsr;
+ enable_fpu();
+ asm volatile ("fmfcsr %0\n\t":"=&r" (fpcsr));
+ disable_fpu();
+
+ if (fpcsr & FPCSR_mskALLT) {
+ si.si_signo = SIGFPE;
+ /* Exception handling, denorm input, UDF and OVF */
+ if (fpcsr & FPCSR_mskDNIT) {
+ unsigned int rfpcsr;
+ lose_fpu(1);
+ si.si_signo =
+ do_fpu_denorm(regs,
+ ¤t->thread.fpu);
+ own_fpu(1);
+
+ if (si.si_signo == SIGFPE) {
+ rfpcsr =
+ current->thread.fpu.fpcsr;
+
+ if (rfpcsr & FPCSR_mskIVO)
+ si.si_code = FPE_FLTINV;
+ if (rfpcsr & FPCSR_mskDBZ)
+ si.si_code = FPE_FLTDIV;
+ if (rfpcsr & FPCSR_mskOVF)
+ si.si_code = FPE_FLTOVF;
+ if (rfpcsr & FPCSR_mskUDF)
+ si.si_code = FPE_FLTUND;
+ if (rfpcsr & FPCSR_mskIEX)
+ si.si_code = FPE_FLTRES;
+ } else if (si.si_code == SIGILL)
+ show_regs(regs);
+ else if (si.si_code == SIGBUS)
+ si.si_code = BUS_ADRERR;
+ } else if (fpcsr & FPCSR_mskRIT) {
+ printk("Reserved Instruction\n");
+ show_regs(regs);
+ if (!user_mode(regs))
+ do_exit(SIGILL);
+ si.si_signo = SIGILL;
+ } else if (fpcsr & FPCSR_mskUDFT)
+ si.si_code = FPE_FLTUND;
+ else if (fpcsr & FPCSR_mskOVFT)
+ si.si_code = FPE_FLTOVF;
+ else if (fpcsr & FPCSR_mskIVOT)
+ si.si_code = FPE_FLTINV;
+ else if (fpcsr & FPCSR_mskDBZT)
+ si.si_code = FPE_FLTDIV;
+ else if (fpcsr & FPCSR_mskIEXT)
+ si.si_code = FPE_FLTRES;
+ /* If something went wrong, signal */
+ if (si.si_signo) {
+ if (si.si_code == SIGILL) {
+ force_sig(si.si_signo, current);
+ } else {
+ si.si_addr =
+ (void __user *)
+ instruction_pointer(regs);
+ force_sig_info(si.si_signo, &si,
+ current);
+ }
+ }
+ } else {
+ printk("Bad FPU exception\n");
+ BUG();
+ }
+ }
+ }
+}
diff -Nur linux-3.4.113.orig/arch/nds32/kernel/fpu.h linux-3.4.113/arch/nds32/kernel/fpu.h
--- linux-3.4.113.orig/arch/nds32/kernel/fpu.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/kernel/fpu.h 2016-12-01 20:59:24.352612751 +0100
@@ -0,0 +1,13 @@
+
+
+/*
+ * Initially load the FPU with signalling NANS. This bit pattern
+ * has the property that no matter whether considered as single or as
+ * double precision, it still represents a signalling NAN.
+ */
+
+ #define sNAN64 0xFFFFFFFFFFFFFFFFULL
+ #define sNAN32 0xFFFFFFFFUL
+
+ #define FPCSR_INIT 0x0 /* Hardware reset value */
+
diff -Nur linux-3.4.113.orig/arch/nds32/kernel/ftrace.c linux-3.4.113/arch/nds32/kernel/ftrace.c
--- linux-3.4.113.orig/arch/nds32/kernel/ftrace.c 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/kernel/ftrace.c 2016-12-01 20:59:24.352612751 +0100
@@ -0,0 +1,219 @@
+/*
+ * Code for replacing ftrace calls with jumps.
+ *
+ * Copyright (C) 2007-2008 Steven Rostedt <srostedt@redhat.com>
+ *
+ * Thanks goes out to P.A. Semi, Inc for supplying me with a PPC64 box.
+ *
+ * Added function graph tracer code, taken from x86 that was written
+ * by Frederic Weisbecker, and ported to PPC by Steven Rostedt.
+ *
+ */
+
+#include <linux/spinlock.h>
+#include <linux/hardirq.h>
+#include <linux/uaccess.h>
+#include <linux/module.h>
+#include <linux/ftrace.h>
+#include <linux/percpu.h>
+#include <linux/init.h>
+#include <linux/list.h>
+
+#include <asm/cacheflush.h>
+#include <asm/ftrace.h>
+
+# define GET_ADDR(addr) (*(unsigned long *)addr)
+
+#ifdef CONFIG_DYNAMIC_FTRACE
+static unsigned int ftrace_nop_replace(void)
+{
+// return PPC_INST_NOP;
+ return 0;
+}
+
+static unsigned int
+ftrace_call_replace(unsigned long ip, unsigned long addr, int link)
+{
+ unsigned int op;
+
+ addr = GET_ADDR(addr);
+
+ /* if (link) set op to 'bl' else 'b' */
+// op = create_branch((unsigned int *)ip, addr, link ? 1 : 0);
+
+ return op;
+}
+
+static int
+ftrace_modify_code(unsigned long ip, unsigned int old, unsigned int new)
+{
+ unsigned int replaced;
+
+ /*
+ * Note: Due to modules and __init, code can
+ * disappear and change, we need to protect against faulting
+ * as well as code changing. We do this by using the
+ * probe_kernel_* functions.
+ *
+ * No real locking needed, this code is run through
+ * kstop_machine, or before SMP starts.
+ */
+
+ /* read the text we want to modify */
+ if (probe_kernel_read(&replaced, (void *)ip, MCOUNT_INSN_SIZE))
+ return -EFAULT;
+
+ /* Make sure it is what we expect it to be */
+ if (replaced != old)
+ return -EINVAL;
+
+ /* replace the text with the new text */
+ if (probe_kernel_write((void *)ip, &new, MCOUNT_INSN_SIZE))
+ return -EPERM;
+
+ flush_icache_range(ip, ip + 8);
+
+ return 0;
+}
+
+int ftrace_make_nop(struct module *mod,
+ struct dyn_ftrace *rec, unsigned long addr)
+{
+ unsigned long ip = rec->ip;
+ unsigned int old, new;
+
+ old = ftrace_call_replace(ip, addr, 1);
+ new = ftrace_nop_replace();
+ return ftrace_modify_code(ip, old, new);
+}
+
+int ftrace_make_call(struct dyn_ftrace *rec, unsigned long addr)
+{
+ unsigned long ip = rec->ip;
+ unsigned int old, new;
+
+ old = ftrace_nop_replace();
+ new = ftrace_call_replace(ip, addr, 1);
+ return ftrace_modify_code(ip, old, new);
+}
+
+int ftrace_update_ftrace_func(ftrace_func_t func)
+{
+ unsigned long ip = (unsigned long)(&ftrace_call);
+ unsigned int old, new;
+ int ret;
+
+ old = *(unsigned int *)&ftrace_call;
+ new = ftrace_call_replace(ip, (unsigned long)func, 1);
+ ret = ftrace_modify_code(ip, old, new);
+
+ return ret;
+}
+
+int __init ftrace_dyn_arch_init(void *data)
+{
+ /* caller expects data to be zero */
+ unsigned long *p = data;
+
+ *p = 0;
+
+ return 0;
+}
+#endif /* CONFIG_DYNAMIC_FTRACE */
+
+#ifdef CONFIG_FUNCTION_GRAPH_TRACER
+
+#ifdef CONFIG_DYNAMIC_FTRACE
+extern void ftrace_graph_call(void);
+extern void ftrace_graph_stub(void);
+
+int ftrace_enable_ftrace_graph_caller(void)
+{
+ unsigned long ip = (unsigned long)(&ftrace_graph_call);
+ unsigned long addr = (unsigned long)(&ftrace_graph_caller);
+ unsigned long stub = (unsigned long)(&ftrace_graph_stub);
+ unsigned int old, new;
+
+ old = ftrace_call_replace(ip, stub, 0);
+ new = ftrace_call_replace(ip, addr, 0);
+
+ return ftrace_modify_code(ip, old, new);
+}
+
+int ftrace_disable_ftrace_graph_caller(void)
+{
+ unsigned long ip = (unsigned long)(&ftrace_graph_call);
+ unsigned long addr = (unsigned long)(&ftrace_graph_caller);
+ unsigned long stub = (unsigned long)(&ftrace_graph_stub);
+ unsigned int old, new;
+
+ old = ftrace_call_replace(ip, addr, 0);
+ new = ftrace_call_replace(ip, stub, 0);
+
+ return ftrace_modify_code(ip, old, new);
+}
+#endif /* CONFIG_DYNAMIC_FTRACE */
+int get_selfpc(unsigned long mcount_lp)
+{
+ unsigned long symbol_size, offset;
+ kallsyms_lookup_size_offset(mcount_lp, &symbol_size, &offset);
+ return mcount_lp - offset;
+}
+
+/*
+ * Hook the return address and push it in the stack of return addrs
+ * in current thread info.
+ */
+void prepare_ftrace_return(unsigned long *parent, unsigned long self_addr)
+{
+ unsigned long old;
+ int faulted;
+ struct ftrace_graph_ent trace;
+ unsigned long return_hooker = (unsigned long)&return_to_handler;
+
+ if (unlikely(atomic_read(¤t->tracing_graph_pause)))
+ return;
+
+ /*
+ * Protect against fault, even if it shouldn't
+ * happen. This tool is too much intrusive to
+ * ignore such a protection.
+ */
+ asm volatile ("1: lwi %[old], [%[parent]]\n"
+ "2: swi %[return_hooker], [%[parent]]\n"
+ " movi %[faulted], 0\n"
+ "3:\n"
+ ".section .fixup, \"ax\"\n"
+ ".align 2 \n"
+ "4: movi %[faulted], 1\n"
+ " b 3b\n"
+ ".previous\n"
+ ".section __ex_table,\"a\"\n"
+ ".align 3 \n"
+ ".long 1b,4b\n"
+ ".long 2b,4b\n"
+ ".previous":[old] "=&r"(old),[faulted] "=r"(faulted)
+ :[parent] "r"(parent),[return_hooker] "r"(return_hooker)
+ :"memory");
+
+ if (unlikely(faulted)) {
+ ftrace_graph_stop();
+ WARN_ON(1);
+ return;
+ }
+
+ trace.func = self_addr;
+ trace.depth = current->curr_ret_stack + 1;
+
+ /* Only trace if the calling function expects to */
+ if (!ftrace_graph_entry(&trace)) {
+ *parent = old;
+ return;
+ }
+
+ if (ftrace_push_return_trace(old, self_addr, &trace.depth, 0) == -EBUSY) {
+ *parent = old;
+ return;
+ }
+}
+#endif /* CONFIG_FUNCTION_GRAPH_TRACER */
diff -Nur linux-3.4.113.orig/arch/nds32/kernel/head.S linux-3.4.113/arch/nds32/kernel/head.S
--- linux-3.4.113.orig/arch/nds32/kernel/head.S 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/kernel/head.S 2016-12-01 20:59:24.352612751 +0100
@@ -0,0 +1,350 @@
+/*
+ * arch/nds32/kernel/head.S
+ *
+ * NDS32 Kernel startup code
+ *
+ * Copyright (C) 2007 Andes Technology Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ */
+#include <linux/linkage.h>
+#include <linux/init.h>
+#include <asm/assembler.h>
+#include <asm/mach-types.h>
+#include <asm/procinfo.h>
+#include <asm/ptrace.h>
+#include <asm/asm-offsets.h>
+//#include <asm/system.h>
+#include <asm/page.h>
+#include <asm/pgtable.h>
+#include <asm/l2_cache.h>
+#include <asm/sizes.h>
+
+/*
+ * We place the page tables 16K below TEXTADDR. Therefore, we must make sure
+ * that TEXTADDR is correctly set. Currently, we expect the least significant
+ * 16 bits to be 0x8000, but we could probably relax this restriction to
+ * TEXTADDR >= PAGE_OFFSET + 0x4000
+ *
+ * Note that swapper_pg_dir is the virtual address of the page tables, and
+ * pgtbl gives us a position-independent reference to these tables. We can
+ * do this because _stext == TEXTADDR
+ */
+
+ .globl swapper_pg_dir
+ .equ swapper_pg_dir, TEXTADDR - 0x4000
+
+/*
+ * Kernel startup entry point.
+ * ---------------------------
+ *
+ * This is normally called from the decompressor code. The requirements
+ * are: MMU = off, D-cache = off, I-cache = dont care, $r0 = 0,
+ * $r1 = machine nr.
+ *
+ * This code is mostly position independent, so if you link the kernel at
+ * 0xc0008000, you call this at __pa(0xc0008000).
+ *
+ * See linux/arch/nds32/tools/mach-types for the complete list of machine
+ * numbers for $r1.
+ *
+ * We're trying to keep crap to a minimum; DO NOT add any machine specific
+ * crap here - that's what the boot loader (or in extreme, well justified
+ * circumstances, zImage) is for.
+ */
+ .section ".head.text", "ax"
+ .type _stext, %function
+ENTRY(_stext)
+ setgie.d ! Disable interrupt
+ isb
+ move $r1, #MACH_TYPE_FARADAY ! Note: as far, we are in the Superuser mode
+ jal __lookup_processor_type ! get processor id, $r5=procinfo, $r9=cpuid, invalid processor $r5=0
+ li $r2, 'p'
+ beqz $r5, __error ! yes, error 'p'
+ jal __lookup_machine_type ! $r5=machinfo
+ li $r2, 'a'
+ beqz $r5, __error
+
+/*
+ * Create a temporary mapping area for booting, before start_kernel
+ */
+ sethi $r4, hi20(swapper_pg_dir)
+ li $p0, (PAGE_OFFSET - PHYS_OFFSET)
+ sub $r4, $r4, $p0
+ tlbop FlushAll ! invalidate TLB\n"
+ isb
+ mtsr $r4, $L1_PPTB ! load page table pointer\n"
+
+/* set NTC0 cacheable/writeback, mutliple page size in use */
+ mfsr $r3, $MMU_CTL
+ li $r0, ~0x6
+ and $r3, $r3, $r0
+ ori $r3, $r3, 0x404
+ mtsr $r3, $MMU_CTL
+ isb
+
+#ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
+ li $r2, #(PHYS_OFFSET + 0x7bf)
+#else
+ li $r2, #(PHYS_OFFSET + 0x6bf) ! to remember here
+#endif
+ movi $r3, #0x5
+ mtsr $r3, $TLB_MISC
+
+ sethi $r3, hi20(PAGE_OFFSET)
+ li $r0, #PHYS_OFFSET
+ sethi $r5, hi20(SZ_1M) ! Use 1MB pages
+ sethi $r6, hi20(PHYS_OFFSET+SZ_32M) ! Create 32MB first, leave the rest in paging_init()
+_tlb:
+ mtsr $r3, $TLB_VPN
+ dsb
+ tlbop $r2, RWR
+ isb
+ add $r0, $r0, $r5
+ add $r3, $r3, $r5
+ add $r2, $r2, $r5
+ bne $r0, $r6, _tlb
+
+ mtsr $r3, $TLB_MISC ! setup access page size
+ li $r2, #~0xf
+ and $r3, $r3, $r2
+#ifdef CONFIG_ANDES_PAGE_SIZE_8KB
+ ori $r3, $r3, #0x1
+#endif
+ mtsr $r3, $TLB_MISC
+
+ mfsr $r0, $MISC_CTL ! Enable BTB and RTP
+ li $r1, #~0x3
+ and $r0, $r0, $r1
+ mtsr $r0, $MISC_CTL
+
+/*
+ * Disable L2CC and wait until L2CC registers are mapped into memory to use L2$.
+ */
+#ifdef CONFIG_CACHE_L2
+ li $p0, L2CC_PA_BASE
+ li $p1, 0
+ swi $p1, [$p0 + L2CC_CTRL_OFF]
+#endif
+
+#ifdef CONFIG_PLAT_AG102
+/*
+ * Set GPUBA to 0x0c000006. GPUB 0x1c000000, FB size 64MB.
+ */
+ li $p0, DDR2C_PA_BASE + 0x02a4
+ li $p1, 0x0c000006
+ swi $p1, [$p0]
+#endif
+
+ mfsr $p1, $PSW
+ li $r15, #~0x43df ! clear WBNA|DME|IME|DT|IT|POM|INTL|GIE
+ and $p1, $p1, $r15
+#ifdef __NDS32_EB__
+ #ifdef CONFIG_WBNA
+ ori $p1, $p1, #0x40ea ! set WBNA|DT|IT|BE|POM:super|INTL:1
+ #else
+ ori $p1, $p1, #0xea ! set ----|DT|IT|BE|POM:super|INTL:1
+ #endif
+#else
+ #ifdef CONFIG_WBNA
+ ori $p1, $p1, #0x40ca ! set WBNA|DT|IT|--|POM:super|INTL:1
+ #else
+ ori $p1, $p1, #0xca ! set ----|DT|IT|--|POM:super|INTL:1
+ #endif
+#endif
+
+ mtsr $p1, $IPSW ! when iret, it will automatically enable MMU
+ la $lp, __mmap_switched
+ mtsr $lp, $IPC
+ iret
+ nop
+
+ .type __switch_data, %object
+__switch_data:
+ .long __mmap_switched
+ .long _sdata ! $r5
+ .long __bss_start ! $r6
+ .long _end ! $r7
+ .long __machine_arch_type ! $r5
+ .long init_thread_union + 8192 ! $sp
+
+
+/*
+ * The following fragment of code is executed with the MMU on in MMU mode,
+ * and uses absolute addresses; this is not position independent.
+ *
+ * $r0
+ * $r10 = points to proc info
+ * $r8 = points to machine info,
+ * $r1 = machine ID, 0x2c8 for Andes AG101 board
+ * $r9 = processor ID of value in version register
+ */
+ .align
+ .type __mmap_switched, %function
+__mmap_switched:
+ la $r3, __switch_data + 4
+ lmw.bim $r5, [$r3], $r7
+
+ move $fp, #0 ! Clear BSS (and zero $fp)
+ beq $r7, $r6, _RRT
+1: swi.bi $fp, [$r6], #4
+ bne $r7, $r6, 1b
+
+_RRT:
+ lmw.bim $r4, [$r3], $r4, #0b0001
+ sw $r1, [$r4] ! Save machine type to memory
+ b start_kernel
+
+
+/*
+ * Read processor ID register (CP#15, $CR0), and look up in the linker-built
+ * supported processor list. Note that we can't use the absolute addresses
+ * for the __proc_info lists since we aren't running with the MMU on
+ * (and therefore, we are not in the correct address space). We have to
+ * calculate the offset.
+ *
+ * $r9 = cpuid, get from $CPU_VER
+ * Returns:
+ * $r3, $r4, $r6 corrupted
+ * $r5 = proc_info pointer in physical address space
+ * $r9 = cpuid
+ */
+
+ .type __lookup_processor_type, %function
+__lookup_processor_type:
+ la $r5, __proc_info_begin
+ la $r6, __proc_info_end
+ mfsr $r9, $CPU_VER ! get cpu version
+ li $p0, (PAGE_OFFSET - PHYS_OFFSET)
+1:
+ sub $p1, $r5, $p0
+ lmw.bi $r3, [$p1], $r4 ! value, mask
+ and $r4, $r4, $r9 ! mask wanted bits
+ xor $p1, $r3, $r4
+ beqz $p1, 2f
+ addi $r5, $r5, #PROC_INFO_SZ ! sizeof(proc_info_list)
+ bne $r5, $r6, 1b
+
+ move $r5, #0 ! unknown processor -> exit
+2: ret
+
+
+
+/*
+ * Lookup machine architecture in the linker-build list of architectures.
+ * Note that we can't use the absolute addresses for the __arch_info
+ * lists since we aren't running with the MMU on (and therefore, we are
+ * not in the correct address space). We have to calculate the offset.
+ *
+ * $r1 = machine architecture number
+ * Returns:
+ * $r3, $r4, $r6 corrupted
+ * $r5 = mach_info pointer in physical address space
+ */
+ .type __lookup_machine_type, %function
+__lookup_machine_type:
+ la $r5, __arch_info_begin
+ la $r6, __arch_info_end
+1:
+ li $p0, (PAGE_OFFSET - PHYS_OFFSET)
+ sub $p1, $r5, $p0
+ lwi $r3, [$p1] ! use PA to get machine type
+ xor $p1, $r3, $r1 ! matches loader number?
+ beqz $p1, 2f ! found
+ addi $r5, $r5, #SIZEOF_MACHINE_DESC ! next machine_desc
+ bne $r5, $r6, 1b
+ move $r5, #0 ! unknown machine
+2: ret
+
+
+/*
+ * Exception handling. Something went wrong and we can't proceed. We
+ * ought to tell the user, but since we don't have any guarantee that
+ * we're even running on the right architecture, we do virtually nothing.
+ *
+ * a = invalid architecture
+ * p = invalid processor
+ *
+ * Generally, only serious errors cause this.
+ */
+__error:
+ li $r1, UART0_PA_BASE
+ sw $r2, [$r1]
+die: b die
+
+
+
+#ifdef CONFIG_SMP
+
+ .type secondary_startup, %function
+ENTRY(secondary_startup)
+ /*
+ * Common entry point for secondary CPUs.
+ *
+ * Lookup the processor type - there is no need to check the
+ * machine type as it has already been validated by the
+ * primary processor.
+ */
+ mfsr $r0, $MMU_CTL
+ ori $r0, $r0, #4
+#ifndef CONFIG_NO_KERNEL_LARGE_PAGE
+ ori $r0, $r0, #0x400
+#endif
+ mtsr $r0, $MMU_CTL
+
+ movi $r15, #0x01
+ swi $r15, [$p1+#0x10]
+ lwi $sp, [$p1+#0x18]
+
+ /*
+ * Set stack, L1_PPTB, and enable mmu
+ */
+ sethi $r4, hi20(swapper_pg_dir)
+ li $p0, (PAGE_OFFSET - PHYS_OFFSET)
+ sub $r4, $r4, $p0
+
+ tlbop FlushAll
+ isb
+ mtsr $r4, $L1_PPTB
+
+#ifdef CONFIG_CACHE_L2
+ li $r0, #0x1801
+ mtsr $r0, $HSMP_SADDR
+ isb
+ li $r0, #(L2CC_PA_BASE+0x10) ! L2CC Control
+ lwi $r1, [$r0]
+ li $r2, #~(0xf << 28)
+ and $r1, $r1, $r2
+ bset $r1, $r1, #29
+ bset $r1, $r1, #31
+ swi $r1, [$r0]
+#endif
+
+ move $fp, #0
+
+ mfsr $p1, $PSW
+ li $r15, #~0x43df ! clear WBNA|DME|IME|DT|IT|POM|INTL|GIE
+ and $p1, $p1, $r15
+#ifdef __NDS32_EB__
+ #ifdef CONFIG_WBNA
+ ori $p1, $p1, #0x40ea ! set WBNA|DT|IT|BE|POM:super|INTL:1
+ #else
+ ori $p1, $p1, #0xea ! set ----|DT|IT|BE|POM:super|INTL:1
+ #endif
+#else
+ #ifdef CONFIG_WBNA
+ ori $p1, $p1, #0x40ca ! set WBNA|DT|IT|--|POM:super|INTL:1
+ #else
+ ori $p1, $p1, #0xca ! set ----|DT|IT|--|POM:super|INTL:1
+ #endif
+#endif
+
+ mtsr $p1, $IPSW ! when iret, it will automatically enable MMU
+ la $lp, secondary_start_kernel
+ mtsr $lp, $IPC
+ iret
+ nop
+#endif
diff -Nur linux-3.4.113.orig/arch/nds32/kernel/init_task.c linux-3.4.113/arch/nds32/kernel/init_task.c
--- linux-3.4.113.orig/arch/nds32/kernel/init_task.c 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/kernel/init_task.c 2016-12-01 20:59:24.352612751 +0100
@@ -0,0 +1,25 @@
+/*
+ * linux/arch/nds32/kernel/init_task.c
+ *
+ * Copyright (C) 2009 Andes Technology Corporation
+ */
+#include <linux/module.h>
+#include <linux/init_task.h>
+#include <linux/mqueue.h>
+#include <linux/fs.h>
+
+#include <asm/uaccess.h>
+
+static struct signal_struct init_signals = INIT_SIGNALS(init_signals);
+static struct sighand_struct init_sighand = INIT_SIGHAND(init_sighand);
+
+/* Initial task structure */
+struct task_struct init_task = INIT_TASK(init_task);
+EXPORT_SYMBOL(init_task);
+
+/*
+ * Initial thread structure. Alignment of this is handled by a special
+ * linker map entry.
+ */
+union thread_union init_thread_union __init_task_data =
+ { INIT_THREAD_INFO(init_task) };
diff -Nur linux-3.4.113.orig/arch/nds32/kernel/io.c linux-3.4.113/arch/nds32/kernel/io.c
--- linux-3.4.113.orig/arch/nds32/kernel/io.c 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/kernel/io.c 2016-12-01 20:59:24.352612751 +0100
@@ -0,0 +1,51 @@
+#include <linux/module.h>
+#include <linux/types.h>
+
+#include <asm/io.h>
+
+/*
+ * Copy data from IO memory space to "real" memory space.
+ * This needs to be optimized.
+ */
+void _memcpy_fromio(void *to, const volatile void __iomem * from, size_t count)
+{
+ unsigned char *t = to;
+ while (count) {
+ count--;
+ *t = readb(from);
+ t++;
+ from++;
+ }
+}
+
+/*
+ * Copy data from "real" memory space to IO memory space.
+ * This needs to be optimized.
+ */
+void _memcpy_toio(volatile void __iomem * to, const void *from, size_t count)
+{
+ const unsigned char *f = from;
+ while (count) {
+ count--;
+ writeb(*f, to);
+ f++;
+ to++;
+ }
+}
+
+/*
+ * "memset" on IO memory space.
+ * This needs to be optimized.
+ */
+void _memset_io(volatile void __iomem * dst, int c, size_t count)
+{
+ while (count) {
+ count--;
+ writeb(c, dst);
+ dst++;
+ }
+}
+
+EXPORT_SYMBOL(_memcpy_fromio);
+EXPORT_SYMBOL(_memcpy_toio);
+EXPORT_SYMBOL(_memset_io);
diff -Nur linux-3.4.113.orig/arch/nds32/kernel/irq.c linux-3.4.113/arch/nds32/kernel/irq.c
--- linux-3.4.113.orig/arch/nds32/kernel/irq.c 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/kernel/irq.c 2016-12-01 20:59:24.352612751 +0100
@@ -0,0 +1,122 @@
+/*
+ * linux/arch/nds32/kernel/irq.c
+ *
+ * Copyright (C) 1992 Linus Torvalds
+ * Modifications for ARM processor Copyright (C) 1995-2000 Russell King.
+ * Copyright (C) 2009 Andes Technology Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This file contains the code used by various IRQ handling routines:
+ * asking for different IRQ's should be done through these routines
+ * instead of just grabbing them. Thus setups with different IRQ numbers
+ * shouldn't result in any weird surprises, and installing new handlers
+ * should be easier.
+ *
+ * IRQ's are in fact implemented a bit like signal handlers for the kernel.
+ * Naturally it's not a 1:1 relation, but there are similarities.
+ */
+#include <linux/kernel_stat.h>
+#include <linux/module.h>
+#include <linux/interrupt.h>
+#include <linux/irq.h>
+#include <linux/slab.h>
+#include <linux/random.h>
+#include <linux/seq_file.h>
+#include <linux/kallsyms.h>
+
+void (*init_arch_irq) (void)__initdata = NULL;
+unsigned long irq_err_count;
+
+void ack_bad_irq(unsigned int irq)
+{
+ printk("bad IRQ %d\n", irq);
+}
+
+int show_interrupts(struct seq_file *p, void *v)
+{
+ int i = *(loff_t *) v, cpu;
+ struct irqaction *action;
+ unsigned long flags;
+
+ if (i == 0) {
+ char cpuname[12];
+
+ seq_printf(p, " ");
+ for_each_present_cpu(cpu) {
+ sprintf(cpuname, "CPU%d", cpu);
+ seq_printf(p, " %10s", cpuname);
+ }
+ seq_putc(p, '\n');
+ }
+
+ if (i < NR_IRQS) {
+ raw_spin_lock_irqsave(&irq_desc[i].lock, flags);
+ action = irq_desc[i].action;
+ if (!action)
+ goto unlock;
+
+ seq_printf(p, "%3d: ", i);
+ for_each_present_cpu(cpu)
+ seq_printf(p, "%10u ", kstat_irqs_cpu(i, cpu));
+ seq_printf(p, " %s", action->name);
+ for (action = action->next; action; action = action->next)
+ seq_printf(p, ", %s", action->name);
+
+ seq_putc(p, '\n');
+unlock:
+ raw_spin_unlock_irqrestore(&irq_desc[i].lock, flags);
+ } else if (i == NR_IRQS) {
+ seq_printf(p, "Err: %10lu\n", irq_err_count);
+ }
+ return 0;
+}
+
+/*
+ * do_IRQ handles all hardware IRQ's. Decoded IRQs should not
+ * come via this function. Instead, they should provide their
+ * own 'handler'
+ */
+asmlinkage void asm_do_IRQ(unsigned int irq, struct pt_regs *regs)
+{
+ struct pt_regs *old_regs = set_irq_regs(regs);
+
+ /*
+ * Some hardware gives randomly wrong interrupts. Rather
+ * than crashing, do something sensible.
+ */
+ if (unlikely(irq >= NR_IRQS)) {
+ printk(KERN_EMERG "IRQ exceeds NR_IRQS\n");
+ BUG();
+ }
+
+ irq_enter();
+ generic_handle_irq(irq);
+ irq_exit();
+ set_irq_regs(old_regs);
+
+}
+
+void __init init_IRQ(void)
+{
+ int irq;
+
+ for (irq = 0; irq < NR_IRQS; irq++)
+ irq_set_noprobe(irq);
+
+ init_arch_irq();
+}
+
+#ifdef CONFIG_TRACE_IRQFLAGS
+void notrace arch_trace_hardirqs_on(void)
+{
+ trace_hardirqs_on();
+}
+
+void notrace arch_trace_hardirqs_off(void)
+{
+ trace_hardirqs_off();
+}
+#endif
diff -Nur linux-3.4.113.orig/arch/nds32/kernel/kgdb.c linux-3.4.113/arch/nds32/kernel/kgdb.c
--- linux-3.4.113.orig/arch/nds32/kernel/kgdb.c 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/kernel/kgdb.c 2016-12-01 20:59:24.352612751 +0100
@@ -0,0 +1,291 @@
+/* ============================================================================
+ *
+ * arch/nds32/kernel/kgdb.c
+ *
+ * Copyright (C) 2007 Andes Technology Corporation
+ * This file is part of Linux and should be licensed under the GPL.
+ * See the file COPYING for conditions for redistribution.
+ *
+ * Abstract:
+ *
+ * This program is for NDS32 KGDB support.
+ *
+ * Author: Harry Pan
+ *
+ * Revision History:
+ *
+ * Nov.23.2007 Initial ported by Harry,
+ * inherited from the KGDB in 2.6.11 and 2.4.35.
+ *
+ * Note:
+ *
+ * ============================================================================
+ */
+#include <linux/types.h>
+#include <linux/kernel.h>
+#include <linux/signal.h>
+#include <linux/sched.h>
+#include <linux/mm.h>
+#include <linux/spinlock.h>
+#include <linux/personality.h>
+#include <linux/ptrace.h>
+#include <linux/elf.h>
+#include <linux/interrupt.h>
+#include <linux/init.h>
+#include <linux/kgdb.h>
+#include <linux/kdebug.h>
+
+#include <asm/atomic.h>
+#include <asm/io.h>
+#include <asm/pgtable.h>
+#include <asm/system.h>
+#include <asm/uaccess.h>
+#include <asm/unistd.h>
+#include <asm/ptrace.h>
+#include <asm/traps.h>
+
+// ============================================================================
+// regs_to_gdb_regs()
+//
+// Make a local copy of the registers passed into the handler (bletch).
+// ============================================================================
+void pt_regs_to_gdb_regs(unsigned long *gregs, struct pt_regs *kregs)
+{
+ int regno;
+
+ /* Initialize all to zero (??) */
+ for (regno = 0; regno < NDS32_NUM_REGS; regno++)
+ gregs[regno] = 0;
+
+ gregs[0] = kregs->NDS32_r0;
+ gregs[1] = kregs->NDS32_r1;
+ gregs[2] = kregs->NDS32_r2;
+ gregs[3] = kregs->NDS32_r3;
+ gregs[4] = kregs->NDS32_r4;
+ gregs[5] = kregs->NDS32_r5;
+ gregs[6] = kregs->NDS32_r6;
+ gregs[7] = kregs->NDS32_r7;
+ gregs[8] = kregs->NDS32_r8;
+ gregs[9] = kregs->NDS32_r9;
+ gregs[10] = kregs->NDS32_r10;
+ gregs[11] = kregs->NDS32_r11;
+ gregs[12] = kregs->NDS32_r12;
+ gregs[13] = kregs->NDS32_r13;
+ gregs[14] = kregs->NDS32_r14;
+ gregs[15] = kregs->NDS32_r15;
+ gregs[16] = kregs->NDS32_r16;
+ gregs[17] = kregs->NDS32_r17;
+ gregs[18] = kregs->NDS32_r18;
+ gregs[19] = kregs->NDS32_r19;
+ gregs[20] = kregs->NDS32_r20;
+ gregs[21] = kregs->NDS32_r21;
+ gregs[22] = kregs->NDS32_r22;
+ gregs[23] = kregs->NDS32_r23;
+ gregs[24] = kregs->NDS32_r24;
+ gregs[25] = kregs->NDS32_r25;
+ gregs[26] = kregs->NDS32_pp0;
+ gregs[27] = kregs->NDS32_pp1;
+ gregs[28] = kregs->NDS32_fp;
+ gregs[29] = kregs->NDS32_gp;
+ gregs[30] = kregs->NDS32_lp;
+ gregs[31] = kregs->NDS32_sp;
+ gregs[32] = kregs->NDS32_ipc;
+ gregs[33] = kregs->NDS32_d0lo;
+ gregs[34] = kregs->NDS32_d0hi;
+ gregs[35] = kregs->NDS32_d1lo;
+ gregs[36] = kregs->NDS32_d1hi;
+ gregs[NDS32_IR0_REGNUM] = kregs->NDS32_ipsw;
+}
+
+// ============================================================================
+// gdb_regs_to_regs()
+//
+// Copy local gdb registers back to kgdb regs, for later copy to kernel.
+// ============================================================================
+void gdb_regs_to_pt_regs(unsigned long *gregs, struct pt_regs *kregs)
+{
+ kregs->NDS32_r0 = gregs[0];
+ kregs->NDS32_r1 = gregs[1];
+ kregs->NDS32_r2 = gregs[2];
+ kregs->NDS32_r3 = gregs[3];
+ kregs->NDS32_r4 = gregs[4];
+ kregs->NDS32_r5 = gregs[5];
+ kregs->NDS32_r6 = gregs[6];
+ kregs->NDS32_r7 = gregs[7];
+ kregs->NDS32_r8 = gregs[8];
+ kregs->NDS32_r9 = gregs[9];
+ kregs->NDS32_r10 = gregs[10];
+ kregs->NDS32_r11 = gregs[11];
+ kregs->NDS32_r12 = gregs[12];
+ kregs->NDS32_r13 = gregs[13];
+ kregs->NDS32_r14 = gregs[14];
+ kregs->NDS32_r15 = gregs[15];
+ kregs->NDS32_r16 = gregs[16];
+ kregs->NDS32_r17 = gregs[17];
+ kregs->NDS32_r18 = gregs[18];
+ kregs->NDS32_r19 = gregs[19];
+ kregs->NDS32_r20 = gregs[20];
+ kregs->NDS32_r21 = gregs[21];
+ kregs->NDS32_r22 = gregs[22];
+ kregs->NDS32_r23 = gregs[23];
+ kregs->NDS32_r24 = gregs[24];
+ kregs->NDS32_r25 = gregs[25];
+ kregs->NDS32_pp0 = gregs[26];
+ kregs->NDS32_pp1 = gregs[27];
+ kregs->NDS32_fp = gregs[28];
+ kregs->NDS32_gp = gregs[29];
+ kregs->NDS32_lp = gregs[30];
+ kregs->NDS32_sp = gregs[31];
+ kregs->NDS32_ipc = gregs[32];
+ kregs->NDS32_d0lo = gregs[33];
+ kregs->NDS32_d0hi = gregs[34];
+ kregs->NDS32_d1lo = gregs[35];
+ kregs->NDS32_d1hi = gregs[36];
+ kregs->NDS32_ipsw = gregs[NDS32_IR0_REGNUM];
+}
+
+// ----------------------------------------------------------------------------
+// kgdb_get_user_regs()
+//
+// Get user process registers.
+// ----------------------------------------------------------------------------
+static inline struct pt_regs *kgdb_get_user_regs(struct task_struct *task)
+{
+ return (struct pt_regs *)
+ ((unsigned long)task_thread_info(task) + THREAD_SIZE -
+ 8 - sizeof(struct pt_regs));
+}
+
+// ============================================================================
+// sleeping_thread_to_gdb_regs()
+//
+// ============================================================================
+void sleeping_thread_to_gdb_regs(unsigned long *gregs, struct task_struct *task)
+{
+ int regno;
+ struct pt_regs *tregs;
+
+ /* Just making sure... */
+ if (task == NULL)
+ return;
+
+ /* Initialize to zero */
+ for (regno = 0; regno < NDS32_NUM_REGS; regno++)
+ gregs[regno] = 0;
+
+ /* Otherwise, we have only some registers from switch_to() */
+ tregs = kgdb_get_user_regs(task);
+
+ gregs[0] = tregs->NDS32_r0;
+ gregs[1] = tregs->NDS32_r1;
+ gregs[2] = tregs->NDS32_r2;
+ gregs[3] = tregs->NDS32_r3;
+ gregs[4] = tregs->NDS32_r4;
+ gregs[5] = tregs->NDS32_r5;
+ gregs[6] = tregs->NDS32_r6;
+ gregs[7] = tregs->NDS32_r7;
+ gregs[8] = tregs->NDS32_r8;
+ gregs[9] = tregs->NDS32_r9;
+ gregs[10] = tregs->NDS32_r10;
+ gregs[11] = tregs->NDS32_r11;
+ gregs[12] = tregs->NDS32_r12;
+ gregs[13] = tregs->NDS32_r13;
+ gregs[14] = tregs->NDS32_r14;
+ gregs[15] = tregs->NDS32_r15;
+ gregs[16] = tregs->NDS32_r16;
+ gregs[17] = tregs->NDS32_r17;
+ gregs[18] = tregs->NDS32_r18;
+ gregs[19] = tregs->NDS32_r19;
+ gregs[20] = tregs->NDS32_r20;
+ gregs[21] = tregs->NDS32_r21;
+ gregs[22] = tregs->NDS32_r22;
+ gregs[23] = tregs->NDS32_r23;
+ gregs[24] = tregs->NDS32_r24;
+ gregs[25] = tregs->NDS32_r25;
+ gregs[26] = tregs->NDS32_pp0;
+ gregs[27] = tregs->NDS32_pp1;
+ gregs[28] = tregs->NDS32_fp;
+ gregs[29] = tregs->NDS32_gp;
+ gregs[30] = tregs->NDS32_lp;
+ gregs[31] = tregs->NDS32_sp;
+ gregs[32] = tregs->NDS32_ipc;
+ gregs[33] = tregs->NDS32_d0lo;
+ gregs[34] = tregs->NDS32_d0hi;
+ gregs[35] = tregs->NDS32_d1lo;
+ gregs[36] = tregs->NDS32_d1hi;
+ gregs[NDS32_IR0_REGNUM] = tregs->NDS32_ipsw;
+}
+
+int kgdb_arch_handle_exception(int exception_vector, int signo,
+ int err_code, char *remcom_in_buffer,
+ char *remcom_out_buffer,
+ struct pt_regs *linux_regs)
+{
+ long addr;
+ char *ptr;
+
+ if (0 == atomic_dec_if_positive(&kgdb_setting_breakpoint))
+ linux_regs->NDS32_ipc += 2;
+
+ switch (remcom_in_buffer[0]) {
+ case 'k':
+ case 'D':
+ case 'c':
+ case 's':
+ kgdb_contthread = NULL;
+
+ /*
+ * Try to read optional parameter, pc unchanged if no parm.
+ * If this was a compiled breakpoint, we need to move
+ * to the next instruction or we will just breakpoint
+ * over and over again.
+ */
+ ptr = &remcom_in_buffer[1];
+ if (kgdb_hex2long(&ptr, &addr)) {
+ linux_regs->NDS32_ipc = addr;
+ }
+ linux_regs->NDS32_ipsw &= ~0x800;
+ if (remcom_in_buffer[0] == 's') {
+ linux_regs->NDS32_ipsw |= 0x800;
+ }
+
+ return 0;
+ }
+
+ return -1;
+}
+
+static int kgdb_notify(struct notifier_block *self,
+ unsigned long cmd, void *ptr)
+{
+ struct die_args *args = ptr;
+ unsigned long addr = args->err;
+ if (addr > TASK_SIZE) {
+ kgdb_handle_exception(args->trapnr, args->signr,
+ args->err, args->regs);
+ return NOTIFY_STOP;
+ }
+ return NOTIFY_DONE;
+}
+
+static struct notifier_block kgdb_notifier = {
+ .notifier_call = kgdb_notify,
+};
+
+int kgdb_arch_init(void)
+{
+ register_die_notifier(&kgdb_notifier);
+}
+
+void kgdb_arch_exit(void)
+{
+ unregister_die_notifier(&kgdb_notifier);
+}
+
+struct kgdb_arch arch_kgdb_ops = {
+#ifdef __NDS32_EL__
+ .gdb_bpt_instr = {0xeb, 0xff}
+#else
+ .gdb_bpt_instr = {0xff, 0xeb}
+#endif
+};
diff -Nur linux-3.4.113.orig/arch/nds32/kernel/kprobes.c linux-3.4.113/arch/nds32/kernel/kprobes.c
--- linux-3.4.113.orig/arch/nds32/kernel/kprobes.c 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/kernel/kprobes.c 2016-12-01 20:59:24.356612904 +0100
@@ -0,0 +1,869 @@
+/*
+ * Kernel Probes (KProbes)
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * Copyright (C) IBM Corporation, 2002, 2004
+ *
+ * 2002-Oct Created by Vamsi Krishna S <vamsi_krishna@in.ibm.com> Kernel
+ * Probes initial implementation ( includes contributions from
+ * Rusty Russell).
+ * 2004-July Suparna Bhattacharya <suparna@in.ibm.com> added jumper probes
+ * interface to access function arguments.
+ * 2004-Oct Jim Keniston <jkenisto@us.ibm.com> and Prasanna S Panchamukhi
+ * <prasanna@in.ibm.com> adapted for x86_64 from i386.
+ * 2005-Mar Roland McGrath <roland@redhat.com>
+ * Fixed to handle %rip-relative addressing mode correctly.
+ * 2005-May Hien Nguyen <hien@us.ibm.com>, Jim Keniston
+ * <jkenisto@us.ibm.com> and Prasanna S Panchamukhi
+ * <prasanna@in.ibm.com> added function-return probes.
+ * 2005-May Rusty Lynch <rusty.lynch@intel.com>
+ * Added function return probes functionality
+ * 2006-Feb Masami Hiramatsu <hiramatu@sdl.hitachi.co.jp> added
+ * kprobe-booster and kretprobe-booster for i386.
+ * 2007-Dec Masami Hiramatsu <mhiramat@redhat.com> added kprobe-booster
+ * and kretprobe-booster for x86-64
+ * 2007-Dec Masami Hiramatsu <mhiramat@redhat.com>, Arjan van de Ven
+ * <arjan@infradead.org> and Jim Keniston <jkenisto@us.ibm.com>
+ * unified x86 kprobes code.
+ */
+
+#include <linux/kprobes.h>
+#include <linux/ptrace.h>
+#include <linux/string.h>
+#include <linux/slab.h>
+#include <linux/hardirq.h>
+#include <linux/preempt.h>
+#include <linux/module.h>
+#include <linux/kdebug.h>
+
+#include <asm/cacheflush.h>
+#include <asm/uaccess.h>
+
+#ifdef __NDS32_EL__
+#define SZINSN(insn) (((insn & 0x00000080) == 0) ? 4 : 2)
+#define BREAK16_1FE 0xFEEB
+#else
+#define SZINSN(insn) (((insn & 0x80000000) == 0) ? 4 : 2)
+#define BREAK16_1FE 0xEBFE
+#endif
+
+void jprobe_return_point(void);
+
+DEFINE_PER_CPU(struct kprobe *, current_kprobe) = NULL;
+DEFINE_PER_CPU(struct kprobe_ctlblk, kprobe_ctlblk);
+
+#if 0
+/* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
+static void __kprobes set_jmp_op(void *from, void *to)
+{
+ struct __arch_jmp_op {
+ char op;
+ s32 raddr;
+ } __attribute__ ((packed)) * jop;
+ jop = (struct __arch_jmp_op *)from;
+ jop->raddr = (s32) ((long)(to) - ((long)(from) + 5));
+ jop->op = RELATIVEJUMP_INSTRUCTION;
+}
+
+/*
+ * Check for the REX prefix which can only exist on X86_64
+ * X86_32 always returns 0
+ */
+static int __kprobes is_REX_prefix(kprobe_opcode_t * insn)
+{
+#ifdef CONFIG_X86_64
+ if ((*insn & 0xf0) == 0x40)
+ return 1;
+#endif
+ return 0;
+}
+
+/*
+ * Returns non-zero if opcode is boostable.
+ * RIP relative instructions are adjusted at copying time in 64 bits mode
+ */
+static int __kprobes can_boost(kprobe_opcode_t * opcodes)
+{
+ kprobe_opcode_t opcode;
+ kprobe_opcode_t *orig_opcodes = opcodes;
+
+ if (search_exception_tables(opcodes))
+ return 0; /* Page fault may occur on this address. */
+
+retry:
+ if (opcodes - orig_opcodes > MAX_INSN_SIZE - 1)
+ return 0;
+ opcode = *(opcodes++);
+
+ /* 2nd-byte opcode */
+ if (opcode == 0x0f) {
+ if (opcodes - orig_opcodes > MAX_INSN_SIZE - 1)
+ return 0;
+ return test_bit(*opcodes,
+ (unsigned long *)twobyte_is_boostable);
+ }
+
+ switch (opcode & 0xf0) {
+#ifdef CONFIG_X86_64
+ case 0x40:
+ goto retry; /* REX prefix is boostable */
+#endif
+ case 0x60:
+ if (0x63 < opcode && opcode < 0x67)
+ goto retry; /* prefixes */
+ /* can't boost Address-size override and bound */
+ return (opcode != 0x62 && opcode != 0x67);
+ case 0x70:
+ return 0; /* can't boost conditional jump */
+ case 0xc0:
+ /* can't boost software-interruptions */
+ return (0xc1 < opcode && opcode < 0xcc) || opcode == 0xcf;
+ case 0xd0:
+ /* can boost AA* and XLAT */
+ return (opcode == 0xd4 || opcode == 0xd5 || opcode == 0xd7);
+ case 0xe0:
+ /* can boost in/out and absolute jmps */
+ return ((opcode & 0x04) || opcode == 0xea);
+ case 0xf0:
+ if ((opcode & 0x0c) == 0 && opcode != 0xf1)
+ goto retry; /* lock/rep(ne) prefix */
+ /* clear and set flags are boostable */
+ return (opcode == 0xf5 || (0xf7 < opcode && opcode < 0xfe));
+ default:
+ /* segment override prefixes are boostable */
+ if (opcode == 0x26 || opcode == 0x36 || opcode == 0x3e)
+ goto retry; /* prefixes */
+ /* CS override prefix and call are not boostable */
+ return (opcode != 0x2e && opcode != 0x9a);
+ }
+}
+
+/*
+ * Returns non-zero if opcode modifies the interrupt flag.
+ */
+static int __kprobes is_IF_modifier(kprobe_opcode_t * insn)
+{
+ switch (*insn) {
+ case 0xfa: /* cli */
+ case 0xfb: /* sti */
+ case 0xcf: /* iret/iretd */
+ case 0x9d: /* popf/popfd */
+ return 1;
+ }
+
+ /*
+ * on X86_64, 0x40-0x4f are REX prefixes so we need to look
+ * at the next byte instead.. but of course not recurse infinitely
+ */
+ if (is_REX_prefix(insn))
+ return is_IF_modifier(++insn);
+
+ return 0;
+}
+
+/*
+ * Adjust the displacement if the instruction uses the %rip-relative
+ * addressing mode.
+ * If it does, Return the address of the 32-bit displacement word.
+ * If not, return null.
+ * Only applicable to 64-bit x86.
+ */
+static void __kprobes fix_riprel(struct kprobe *p)
+{
+#ifdef CONFIG_X86_64
+ u8 *insn = p->ainsn.insn;
+ s64 disp;
+ int need_modrm;
+
+ /* Skip legacy instruction prefixes. */
+ while (1) {
+ switch (*insn) {
+ case 0x66:
+ case 0x67:
+ case 0x2e:
+ case 0x3e:
+ case 0x26:
+ case 0x64:
+ case 0x65:
+ case 0x36:
+ case 0xf0:
+ case 0xf3:
+ case 0xf2:
+ ++insn;
+ continue;
+ }
+ break;
+ }
+
+ /* Skip REX instruction prefix. */
+ if (is_REX_prefix(insn))
+ ++insn;
+
+ if (*insn == 0x0f) {
+ /* Two-byte opcode. */
+ ++insn;
+ need_modrm = test_bit(*insn,
+ (unsigned long *)twobyte_has_modrm);
+ } else
+ /* One-byte opcode. */
+ need_modrm = test_bit(*insn,
+ (unsigned long *)onebyte_has_modrm);
+
+ if (need_modrm) {
+ u8 modrm = *++insn;
+ if ((modrm & 0xc7) == 0x05) {
+ /* %rip+disp32 addressing mode */
+ /* Displacement follows ModRM byte. */
+ ++insn;
+ /*
+ * The copied instruction uses the %rip-relative
+ * addressing mode. Adjust the displacement for the
+ * difference between the original location of this
+ * instruction and the location of the copy that will
+ * actually be run. The tricky bit here is making sure
+ * that the sign extension happens correctly in this
+ * calculation, since we need a signed 32-bit result to
+ * be sign-extended to 64 bits when it's added to the
+ * %rip value and yield the same 64-bit result that the
+ * sign-extension of the original signed 32-bit
+ * displacement would have given.
+ */
+ disp = (u8 *) p->addr + *((s32 *) insn) -
+ (u8 *) p->ainsn.insn;
+ BUG_ON((s64) (s32) disp != disp); /* Sanity check. */
+ *(s32 *) insn = (s32) disp;
+ }
+ }
+#endif
+}
+#endif
+
+static void __kprobes arch_copy_kprobe(struct kprobe *p)
+{
+ memcpy(p->ainsn.insn, p->addr, MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
+ flush_icache_range((unsigned long)p->ainsn.insn,
+ (unsigned long)p->ainsn.insn +
+ MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
+
+// fix_riprel(p);
+
+// if (can_boost(p->addr))
+// p->ainsn.boostable = 0;
+// else
+ p->ainsn.boostable = -1;
+
+ p->opcode = *p->addr;
+}
+
+int __kprobes arch_prepare_kprobe(struct kprobe *p)
+{
+ /* insn: must be on special executable page on x86. */
+ p->ainsn.insn = get_insn_slot();
+ if (!p->ainsn.insn)
+ return -ENOMEM;
+ arch_copy_kprobe(p);
+ return 0;
+}
+
+void __kprobes arch_arm_kprobe(struct kprobe *p)
+{
+ *p->addr = BREAK16_1FE;
+ flush_icache_range((unsigned long)p->addr,
+ (unsigned long)p->addr + sizeof(kprobe_opcode_t));
+}
+
+void __kprobes arch_disarm_kprobe(struct kprobe *p)
+{
+ *p->addr = p->opcode;
+ flush_icache_range((unsigned long)p->addr,
+ (unsigned long)p->addr + sizeof(kprobe_opcode_t));
+}
+
+void __kprobes arch_remove_kprobe(struct kprobe *p)
+{
+ if (p->ainsn.insn) {
+ free_insn_slot(p->ainsn.insn, (p->ainsn.boostable == 1));
+ p->ainsn.insn = NULL;
+ }
+}
+
+static void __kprobes save_previous_kprobe(struct kprobe_ctlblk *kcb)
+{
+ kcb->prev_kprobe.kp = kprobe_running();
+ kcb->prev_kprobe.status = kcb->kprobe_status;
+ kcb->prev_kprobe.old_flags = kcb->kprobe_old_flags;
+ kcb->prev_kprobe.saved_flags = kcb->kprobe_saved_flags;
+}
+
+static void __kprobes restore_previous_kprobe(struct kprobe_ctlblk *kcb)
+{
+ __get_cpu_var(current_kprobe) = kcb->prev_kprobe.kp;
+ kcb->kprobe_status = kcb->prev_kprobe.status;
+ kcb->kprobe_old_flags = kcb->prev_kprobe.old_flags;
+ kcb->kprobe_saved_flags = kcb->prev_kprobe.saved_flags;
+}
+
+static void __kprobes set_current_kprobe(struct kprobe *p, struct pt_regs *regs,
+ struct kprobe_ctlblk *kcb)
+{
+ __get_cpu_var(current_kprobe) = p;
+// kcb->kprobe_saved_flags = kcb->kprobe_old_flags
+// = regs->NDS32_ipsw & PSW_mskHSS;
+}
+
+static void __kprobes prepare_singlestep(struct kprobe *p, struct pt_regs *regs)
+{
+ regs->NDS32_ipsw |= PSW_mskHSS;
+ /* single step inline if the instruction is an int3 */
+// if (p->opcode == BREAK16_1FE)
+// regs->NDS32_ipc = (unsigned long)p->addr;
+// else
+ regs->NDS32_ipc = (unsigned long)p->ainsn.insn;
+}
+
+void __kprobes arch_prepare_kretprobe(struct kretprobe_instance *ri,
+ struct pt_regs *regs)
+{
+ ri->ret_addr = (kprobe_opcode_t *) regs->NDS32_lp;
+ regs->NDS32_lp = (unsigned long)&kretprobe_trampoline;
+}
+
+static void __kprobes setup_singlestep(struct kprobe *p, struct pt_regs *regs,
+ struct kprobe_ctlblk *kcb)
+{
+#if !defined(CONFIG_PREEMPT) || defined(CONFIG_FREEZER)
+ if (p->ainsn.boostable == 1 && !p->post_handler) {
+ /* Boost up -- we can execute copied instructions directly */
+ reset_current_kprobe();
+ regs->NDS32_ipc = (unsigned long)p->ainsn.insn;
+ preempt_enable_no_resched();
+ return;
+ }
+#endif
+ prepare_singlestep(p, regs);
+ kcb->kprobe_status = KPROBE_HIT_SS;
+}
+
+/*
+ * We have reentered the kprobe_handler(), since another probe was hit while
+ * within the handler. We save the original kprobes variables and just single
+ * step on the instruction of the new probe without calling any user handlers.
+ */
+static int __kprobes reenter_kprobe(struct kprobe *p, struct pt_regs *regs,
+ struct kprobe_ctlblk *kcb)
+{
+ switch (kcb->kprobe_status) {
+#if 0
+ case KPROBE_HIT_SSDONE:
+#ifdef CONFIG_X86_64
+ /* TODO: Provide re-entrancy from post_kprobes_handler() and
+ * avoid exception stack corruption while single-stepping on
+ * the instruction of the new probe.
+ */
+ arch_disarm_kprobe(p);
+ regs->ip = (unsigned long)p->addr;
+ reset_current_kprobe();
+ preempt_enable_no_resched();
+ break;
+#endif
+#endif
+ case KPROBE_HIT_ACTIVE:
+ save_previous_kprobe(kcb);
+ set_current_kprobe(p, regs, kcb);
+ kprobes_inc_nmissed_count(p);
+ prepare_singlestep(p, regs);
+ kcb->kprobe_status = KPROBE_REENTER;
+ break;
+ case KPROBE_HIT_SS:
+ if (p == kprobe_running()) {
+ regs->NDS32_ipc &= ~PSW_mskHSS;
+// regs->NDS32_ipc |= kcb->kprobe_saved_flags;
+ return 0;
+ } else {
+ /* A probe has been hit in the codepath leading up
+ * to, or just after, single-stepping of a probed
+ * instruction. This entire codepath should strictly
+ * reside in .kprobes.text section. Raise a warning
+ * to highlight this peculiar case.
+ */
+ }
+ default:
+ /* impossible cases */
+ WARN_ON(1);
+ return 0;
+ }
+
+ return 1;
+}
+
+/*
+ * Interrupts are disabled on entry as trap3 is an interrupt gate and they
+ * remain disabled thorough out this function.
+ */
+static int __kprobes kprobe_handler(struct pt_regs *regs)
+{
+ kprobe_opcode_t *addr;
+ struct kprobe *p;
+ struct kprobe_ctlblk *kcb;
+
+ addr = (kprobe_opcode_t *) regs->NDS32_ipc;
+ if (*addr != BREAK16_1FE) {
+ /*
+ * The breakpoint instruction was removed right
+ * after we hit it. Another cpu has removed
+ * either a probepoint or a debugger breakpoint
+ * at this address. In either case, no further
+ * handling of this interrupt is appropriate.
+ * Back up over the (now missing) int3 and run
+ * the original instruction.
+ */
+ return 1;
+ }
+
+ /*
+ * We don't want to be preempted for the entire
+ * duration of kprobe processing. We conditionally
+ * re-enable preemption at the end of this function,
+ * and also in reenter_kprobe() and setup_singlestep().
+ */
+ preempt_disable();
+
+ kcb = get_kprobe_ctlblk();
+ p = get_kprobe(addr);
+
+ if (p) {
+ if (kprobe_running()) {
+ if (reenter_kprobe(p, regs, kcb))
+ return 1;
+ } else {
+ set_current_kprobe(p, regs, kcb);
+ kcb->kprobe_status = KPROBE_HIT_ACTIVE;
+
+ /*
+ * If we have no pre-handler or it returned 0, we
+ * continue with normal processing. If we have a
+ * pre-handler and it returned non-zero, it prepped
+ * for calling the break_handler below on re-entry
+ * for jprobe processing, so get out doing nothing
+ * more here.
+ */
+ if (!p->pre_handler || !p->pre_handler(p, regs))
+ setup_singlestep(p, regs, kcb);
+ return 1;
+ }
+ } else if (kprobe_running()) {
+ p = __get_cpu_var(current_kprobe);
+ if (p->break_handler && p->break_handler(p, regs)) {
+ setup_singlestep(p, regs, kcb);
+ return 1;
+ }
+ }
+ /* else: not a kprobe fault; let the kernel handle it */
+ preempt_enable_no_resched();
+ return 0;
+}
+
+/*
+ * When a retprobed function returns, this code saves registers and
+ * calls trampoline_handler() runs, which calls the kretprobe's handler.
+ */
+static void __used __kprobes kretprobe_trampoline_holder(void)
+{
+ asm volatile (".global kretprobe_trampoline \n"
+ "kretprobe_trampoline: \n"
+ "smw.adm $r15, [$sp], $r15, #0x0\n"
+ "smw.adm $r0, [$sp], $r5, #0x1 \n"
+ "addi $r0, $sp, #-76 \n"
+ "bal trampoline_handler \n"
+ "move $lp, $r0 \n"
+ "lmw.bim $r0, [$sp], $r5, #0x1 \n"
+ "lmw.bim $r15, [$sp], $r15, #0x0\n"
+ "ret \n");
+}
+
+/*
+ * Called from kretprobe_trampoline
+ */
+static __used __kprobes void *trampoline_handler(struct pt_regs *regs)
+{
+ struct kretprobe_instance *ri = NULL;
+ struct hlist_head *head, empty_rp;
+ struct hlist_node *node, *tmp;
+ unsigned long flags, orig_ret_address = 0;
+ unsigned long trampoline_address = (unsigned long)&kretprobe_trampoline;
+
+ INIT_HLIST_HEAD(&empty_rp);
+ kretprobe_hash_lock(current, &head, &flags);
+
+ /*
+ * It is possible to have multiple instances associated with a given
+ * task either because multiple functions in the call path have
+ * return probes installed on them, and/or more than one
+ * return probe was registered for a target function.
+ *
+ * We can handle this because:
+ * - instances are always pushed into the head of the list
+ * - when multiple return probes are registered for the same
+ * function, the (chronologically) first instance's ret_addr
+ * will be the real return address, and all the rest will
+ * point to kretprobe_trampoline.
+ */
+ hlist_for_each_entry_safe(ri, node, tmp, head, hlist) {
+ if (ri->task != current)
+ /* another task is sharing our hash bucket */
+ continue;
+
+ if (ri->rp && ri->rp->handler) {
+ __get_cpu_var(current_kprobe) = &ri->rp->kp;
+ get_kprobe_ctlblk()->kprobe_status = KPROBE_HIT_ACTIVE;
+ ri->rp->handler(ri, regs);
+ __get_cpu_var(current_kprobe) = NULL;
+ }
+
+ orig_ret_address = (unsigned long)ri->ret_addr;
+ recycle_rp_inst(ri, &empty_rp);
+
+ if (orig_ret_address != trampoline_address)
+ /*
+ * This is the real return address. Any other
+ * instances associated with this task are for
+ * other calls deeper on the call stack
+ */
+ break;
+ }
+
+ kretprobe_assert(ri, orig_ret_address, trampoline_address);
+
+ kretprobe_hash_unlock(current, &flags);
+
+ hlist_for_each_entry_safe(ri, node, tmp, &empty_rp, hlist) {
+ hlist_del(&ri->hlist);
+ kfree(ri);
+ }
+ return (void *)orig_ret_address;
+}
+
+/*
+ * Called after single-stepping. p->addr is the address of the
+ * instruction whose first byte has been replaced by the "int 3"
+ * instruction. To avoid the SMP problems that can occur when we
+ * temporarily put back the original opcode to single-step, we
+ * single-stepped a copy of the instruction. The address of this
+ * copy is p->ainsn.insn.
+ *
+ * This function prepares to return from the post-single-step
+ * interrupt. We have to fix up the stack as follows:
+ *
+ * 0) Except in the case of absolute or indirect jump or call instructions,
+ * the new ip is relative to the copied instruction. We need to make
+ * it relative to the original instruction.
+ *
+ * 1) If the single-stepped instruction was pushfl, then the TF and IF
+ * flags are set in the just-pushed flags, and may need to be cleared.
+ *
+ * 2) If the single-stepped instruction was a call, the return address
+ * that is atop the stack is the address following the copied instruction.
+ * We need to make it the address following the original instruction.
+ *
+ * If this is the first time we've single-stepped the instruction at
+ * this probepoint, and the instruction is boostable, boost it: add a
+ * jump instruction after the copied instruction, that jumps to the next
+ * instruction after the probepoint.
+ */
+static void __kprobes resume_execution(struct kprobe *p,
+ struct pt_regs *regs,
+ struct kprobe_ctlblk *kcb)
+{
+// unsigned long *tos = stack_addr(regs);
+// unsigned long copy_ip = (unsigned long)p->ainsn.insn;
+// unsigned long orig_ip = (unsigned long)p->addr;
+ kprobe_opcode_t *insn = p->ainsn.insn;
+ unsigned long rawinsn = *(unsigned long *)insn;
+ int size = SZINSN(rawinsn);
+ regs->NDS32_ipc = (unsigned long)p->addr + size;
+ regs->NDS32_ipsw &= ~PSW_mskHSS;
+#if 0
+
+ /*skip the REX prefix */
+ if (is_REX_prefix(insn))
+ insn++;
+
+ regs->flags &= ~X86_EFLAGS_TF;
+ switch (*insn) {
+ case 0x9c: /* pushfl */
+ *tos &= ~(X86_EFLAGS_TF | X86_EFLAGS_IF);
+ *tos |= kcb->kprobe_old_flags;
+ break;
+ case 0xc2: /* iret/ret/lret */
+ case 0xc3:
+ case 0xca:
+ case 0xcb:
+ case 0xcf:
+ case 0xea: /* jmp absolute -- ip is correct */
+ /* ip is already adjusted, no more changes required */
+ p->ainsn.boostable = 1;
+ goto no_change;
+ case 0xe8: /* call relative - Fix return addr */
+ *tos = orig_ip + (*tos - copy_ip);
+ break;
+#ifdef CONFIG_X86_32
+ case 0x9a: /* call absolute -- same as call absolute, indirect */
+ *tos = orig_ip + (*tos - copy_ip);
+ goto no_change;
+#endif
+ case 0xff:
+ if ((insn[1] & 0x30) == 0x10) {
+ /*
+ * call absolute, indirect
+ * Fix return addr; ip is correct.
+ * But this is not boostable
+ */
+ *tos = orig_ip + (*tos - copy_ip);
+ goto no_change;
+ } else if (((insn[1] & 0x31) == 0x20) ||
+ ((insn[1] & 0x31) == 0x21)) {
+ /*
+ * jmp near and far, absolute indirect
+ * ip is correct. And this is boostable
+ */
+ p->ainsn.boostable = 1;
+ goto no_change;
+ }
+ default:
+ break;
+ }
+
+ if (p->ainsn.boostable == 0) {
+ if ((regs->ip > copy_ip) &&
+ (regs->ip - copy_ip) + 5 < MAX_INSN_SIZE) {
+ /*
+ * These instructions can be executed directly if it
+ * jumps back to correct address.
+ */
+ set_jmp_op((void *)regs->ip,
+ (void *)orig_ip + (regs->ip - copy_ip));
+ p->ainsn.boostable = 1;
+ } else {
+ p->ainsn.boostable = -1;
+ }
+ }
+
+ regs->ip += orig_ip - copy_ip;
+
+no_change:
+ restore_btf();
+#endif
+}
+
+/*
+ * Interrupts are disabled on entry as trap1 is an interrupt gate and they
+ * remain disabled thoroughout this function.
+ */
+static int __kprobes post_kprobe_handler(struct pt_regs *regs)
+{
+ struct kprobe *cur = kprobe_running();
+ struct kprobe_ctlblk *kcb = get_kprobe_ctlblk();
+
+ if (!cur)
+ return 0;
+
+ resume_execution(cur, regs, kcb);
+ regs->NDS32_ipsw |= kcb->kprobe_saved_flags;
+
+ if ((kcb->kprobe_status != KPROBE_REENTER) && cur->post_handler) {
+ kcb->kprobe_status = KPROBE_HIT_SSDONE;
+ cur->post_handler(cur, regs, 0);
+ }
+
+ /* Restore back the original saved kprobes variables and continue. */
+ if (kcb->kprobe_status == KPROBE_REENTER) {
+ restore_previous_kprobe(kcb);
+ goto out;
+ }
+ reset_current_kprobe();
+out:
+ preempt_enable_no_resched();
+
+ /*
+ * if somebody else is singlestepping across a probe point, flags
+ * will have TF set, in which case, continue the remaining processing
+ * of do_debug, as if this is not a probe hit.
+ */
+ if (regs->NDS32_ipsw & PSW_mskHSS)
+ return 0;
+
+ return 1;
+}
+
+int __kprobes kprobe_fault_handler(struct pt_regs *regs, int trapnr)
+{
+ struct kprobe *cur = kprobe_running();
+ struct kprobe_ctlblk *kcb = get_kprobe_ctlblk();
+
+ switch (kcb->kprobe_status) {
+ case KPROBE_HIT_SS:
+ case KPROBE_REENTER:
+ /*
+ * We are here because the instruction being single
+ * stepped caused a page fault. We reset the current
+ * kprobe and the ip points back to the probe address
+ * and allow the page fault handler to continue as a
+ * normal page fault.
+ */
+ regs->NDS32_ipc = (unsigned long)cur->addr;
+ regs->NDS32_ipsw |= kcb->kprobe_old_flags;
+ if (kcb->kprobe_status == KPROBE_REENTER)
+ restore_previous_kprobe(kcb);
+ else
+ reset_current_kprobe();
+ preempt_enable_no_resched();
+ break;
+ case KPROBE_HIT_ACTIVE:
+ case KPROBE_HIT_SSDONE:
+ /*
+ * We increment the nmissed count for accounting,
+ * we can also use npre/npostfault count for accounting
+ * these specific fault cases.
+ */
+ kprobes_inc_nmissed_count(cur);
+
+ /*
+ * We come here because instructions in the pre/post
+ * handler caused the page_fault, this could happen
+ * if handler tries to access user space by
+ * copy_from_user(), get_user() etc. Let the
+ * user-specified handler try to fix it first.
+ */
+ if (cur->fault_handler && cur->fault_handler(cur, regs, trapnr))
+ return 1;
+
+ /*
+ * In case the user-specified fault handler returned
+ * zero, try to fix up.
+ */
+ if (fixup_exception(regs))
+ return 1;
+
+ /*
+ * fixup routine could not handle it,
+ * Let do_page_fault() fix it.
+ */
+ break;
+ default:
+ break;
+ }
+ return 0;
+}
+
+/*
+ * Wrapper routine for handling exceptions.
+ */
+int __kprobes kprobe_exceptions_notify(struct notifier_block *self,
+ unsigned long val, void *data)
+{
+ struct die_args *args = data;
+ int ret = NOTIFY_DONE;
+ int why = args->trapnr & 0xf;
+
+ if (args->regs && user_mode(args->regs))
+ return ret;
+
+ switch (why) {
+ case 1:
+ if (kprobe_handler(args->regs))
+ ret = NOTIFY_STOP;
+ break;
+ case 7:
+ if (post_kprobe_handler(args->regs))
+ ret = NOTIFY_STOP;
+ break;
+ default:
+ break;
+ }
+ return ret;
+}
+
+int __kprobes setjmp_pre_handler(struct kprobe *p, struct pt_regs *regs)
+{
+ struct jprobe *jp = container_of(p, struct jprobe, kp);
+ unsigned long addr;
+ struct kprobe_ctlblk *kcb = get_kprobe_ctlblk();
+
+ kcb->jprobe_saved_regs = *regs;
+ kcb->jprobe_saved_sp = regs->NDS32_sp;
+ addr = (unsigned long)(kcb->jprobe_saved_sp);
+
+ /*
+ * As Linus pointed out, gcc assumes that the callee
+ * owns the argument space and could overwrite it, e.g.
+ * tailcall optimization. So, to be absolutely safe
+ * we also save and restore enough stack bytes to cover
+ * the argument area.
+ */
+ memcpy(kcb->jprobes_stack, (kprobe_opcode_t *) addr,
+ MIN_STACK_SIZE(addr));
+ regs->NDS32_ipsw &= ~PSW_mskGIE;
+ trace_hardirqs_off();
+ regs->NDS32_ipc = (unsigned long)(jp->entry);
+ return 1;
+}
+
+void __kprobes jprobe_return(void)
+{
+ struct kprobe_ctlblk *kcd = get_kprobe_ctlblk();
+ asm volatile (" move $sp, %0\n"
+ " .globl jprobe_return_point\n"
+ " jprobe_return_point: \n"
+ " break #0x1fe \n"::"r" (kcd->
+ jprobe_saved_sp));
+}
+
+int __kprobes longjmp_break_handler(struct kprobe *p, struct pt_regs *regs)
+{
+ struct kprobe_ctlblk *kcb = get_kprobe_ctlblk();
+ struct jprobe *jp = container_of(p, struct jprobe, kp);
+
+ if (regs->NDS32_ipc == jprobe_return_point) {
+ if (regs->NDS32_sp != kcb->jprobe_saved_sp) {
+ struct pt_regs *saved_regs = &kcb->jprobe_saved_regs;
+ printk(KERN_ERR
+ "current sp %p does not match saved sp %p\n",
+ regs->NDS32_sp, kcb->jprobe_saved_sp);
+ printk(KERN_ERR "Saved registers for jprobe %p\n", jp);
+ show_regs(saved_regs);
+ printk(KERN_ERR "Current registers\n");
+ show_regs(regs);
+ BUG();
+ }
+ *regs = kcb->jprobe_saved_regs;
+ memcpy((kprobe_opcode_t *) (kcb->jprobe_saved_sp),
+ kcb->jprobes_stack,
+ MIN_STACK_SIZE(kcb->jprobe_saved_sp));
+ preempt_enable_no_resched();
+ return 1;
+ }
+ return 0;
+}
+
+int __init arch_init_kprobes(void)
+{
+ return 0;
+}
+
+int __kprobes arch_trampoline_kprobe(struct kprobe *p)
+{
+ return 0;
+}
diff -Nur linux-3.4.113.orig/arch/nds32/kernel/machine_kexec.c linux-3.4.113/arch/nds32/kernel/machine_kexec.c
--- linux-3.4.113.orig/arch/nds32/kernel/machine_kexec.c 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/kernel/machine_kexec.c 2016-12-01 20:59:24.356612904 +0100
@@ -0,0 +1,80 @@
+/*
+ * machine_kexec.c - handle transition of Linux booting another kernel
+ */
+
+#include <linux/mm.h>
+#include <linux/kexec.h>
+#include <linux/delay.h>
+#include <linux/reboot.h>
+#include <linux/io.h>
+#include <asm/pgtable.h>
+#include <asm/pgalloc.h>
+#include <asm/mmu_context.h>
+#include <asm/cacheflush.h>
+#include <asm/mach-types.h>
+
+extern const unsigned char relocate_new_kernel[];
+extern const unsigned int relocate_new_kernel_size;
+
+extern void setup_mm_for_reboot(char mode);
+
+extern unsigned long kexec_start_address;
+extern unsigned long kexec_indirection_page;
+extern unsigned long kexec_mach_type;
+extern unsigned long kexec_boot_atags;
+
+/*
+ * Provide a dummy crash_notes definition while crash dump arrives to nds32.
+ * This prevents breakage of crash_notes attribute in kernel/ksysfs.c.
+ */
+
+int machine_kexec_prepare(struct kimage *image)
+{
+ return 0;
+}
+
+void machine_kexec_cleanup(struct kimage *image)
+{
+}
+
+void machine_shutdown(void)
+{
+}
+
+void machine_crash_shutdown(struct pt_regs *regs)
+{
+}
+
+void machine_kexec(struct kimage *image)
+{
+ unsigned long page_list;
+ unsigned long reboot_code_buffer_phys;
+ void *reboot_code_buffer;
+
+ page_list = image->head & PAGE_MASK;
+
+ /* we need both effective and real address here */
+ reboot_code_buffer_phys =
+ page_to_pfn(image->control_code_page) << PAGE_SHIFT;
+ reboot_code_buffer = page_address(image->control_code_page);
+
+ /* Prepare parameters for reboot_code_buffer */
+ kexec_start_address = image->start;
+ kexec_indirection_page = page_list;
+ kexec_mach_type = machine_arch_type;
+ kexec_boot_atags =
+ image->start - KEXEC_NDS32_ZIMAGE_OFFSET + KEXEC_NDS32_ATAGS_OFFSET;
+
+ /* copy our kernel relocation code to the control code page */
+ memcpy(reboot_code_buffer,
+ relocate_new_kernel, relocate_new_kernel_size);
+
+ flush_icache_range((unsigned long)reboot_code_buffer,
+ (unsigned long)reboot_code_buffer +
+ KEXEC_CONTROL_PAGE_SIZE);
+ printk(KERN_INFO "Bye!\n");
+
+ cpu_proc_fin();
+ setup_mm_for_reboot(0); /* mode is not used, so just pass 0 */
+ cpu_reset(reboot_code_buffer_phys);
+}
diff -Nur linux-3.4.113.orig/arch/nds32/kernel/Makefile linux-3.4.113/arch/nds32/kernel/Makefile
--- linux-3.4.113.orig/arch/nds32/kernel/Makefile 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/kernel/Makefile 2016-12-01 20:59:24.356612904 +0100
@@ -0,0 +1,45 @@
+#
+# Makefile for the linux kernel.
+#
+
+CPPFLAGS_vmlinux.lds +=-DTEXTADDR=$(TEXTADDR) -DDATAADDR=$(DATAADDR)
+AFLAGS_head.o := -DTEXTADDR=$(TEXTADDR) -DDATAADDR=$(DATAADDR)
+
+# Object file lists.
+
+obj-y := ex-entry.o ex-exit.o ex-scall.o irq.o \
+ process.o ptrace.o setup.o signal.o \
+ sys_nds32.o time.o traps.o io.o proc.o \
+ elfchk.o
+ifdef CONFIG_FUNCTION_TRACER
+CFLAGS_REMOVE_ftrace.o = -pg
+CFLAGS_REMOVE_ex-entry.o = -pg
+CFLAGS_REMOVE_ex-exit.o = -pg
+CFLAGS_REMOVE_ex-scall.o = -pg
+CFLAGS_REMOVE_stacktrace.o = -pg
+CFLAGS_REMOVE_traps.o = -pg
+endif
+
+obj-$(CONFIG_MODULES) += nds32_ksyms.o module.o
+obj-$(CONFIG_ISA_DMA) += dma-isa.o
+obj-$(CONFIG_PCI) += bios32.o
+obj-$(CONFIG_SMP) += smp.o
+obj-$(CONFIG_KGDB) += kgdb.o
+obj-$(CONFIG_STACKTRACE) += stacktrace.o
+obj-$(CONFIG_KPROBES) += kprobes.o
+obj-$(CONFIG_FPU) += fpu.o
+obj-$(CONFIG_AUDIO) += audio.o
+obj-$(CONFIG_FUNCTION_GRAPH_TRACER) += ftrace.o
+obj-$(CONFIG_KEXEC) += machine_kexec.o relocate_kernel.o
+obj-$(CONFIG_EARLY_PRINTK) += early_printk.o
+
+extra-y := head.o init_task.o vmlinux.lds
+
+CFLAGS_fpu.o += \
+ $(shell $(CC) -E -dM -xc /dev/null | grep -o -m1 NDS32_EXT_FPU_SP | sed -e 's/NDS32_EXT_FPU_SP/-mext-fpu-sp/') \
+ $(shell $(CC) -E -dM -xc /dev/null | grep -o -m1 NDS32_EXT_FPU_DP | sed -e 's/NDS32_EXT_FPU_DP/-mext-fpu-dp/')
+ifdef CONFIG_FPU
+CFLAGS_elfchk.o += \
+ $(shell $(CC) -E -dM -xc /dev/null | grep -o -m1 NDS32_EXT_FPU_SP | sed -e 's/NDS32_EXT_FPU_SP/-mext-fpu-sp/') \
+ $(shell $(CC) -E -dM -xc /dev/null | grep -o -m1 NDS32_EXT_FPU_DP | sed -e 's/NDS32_EXT_FPU_DP/-mext-fpu-dp/')
+endif
diff -Nur linux-3.4.113.orig/arch/nds32/kernel/module.c linux-3.4.113/arch/nds32/kernel/module.c
--- linux-3.4.113.orig/arch/nds32/kernel/module.c 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/kernel/module.c 2016-12-01 20:59:24.356612904 +0100
@@ -0,0 +1,314 @@
+/*
+ * linux/arch/nds32/kernel/module.c
+ *
+ * Copyright (C) 2002 Russell King.
+ * Copyright (C) 2009 Andes Technology Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Module allocation method suggested by Andi Kleen.
+ */
+#include <linux/module.h>
+#include <linux/elf.h>
+#include <linux/vmalloc.h>
+#include <linux/slab.h>
+#include <linux/mm.h>
+
+#include <asm/pgtable.h>
+
+#define DEBUG 0
+#if DEBUG
+#define PRINTK printk
+#else
+#define PRINTK(x...)
+#endif
+
+void *module_alloc(unsigned long size)
+{
+#ifdef CONFIG_KPROBES
+ if (size == 0)
+ return NULL;
+ return vmalloc_exec(size);
+#else
+ return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
+ GFP_KERNEL, PAGE_KERNEL, -1,
+ __builtin_return_address(0));
+#endif
+}
+
+void module_free(struct module *module, void *region)
+{
+ vfree(region);
+}
+
+int module_frob_arch_sections(Elf_Ehdr * hdr,
+ Elf_Shdr * sechdrs,
+ char *secstrings, struct module *mod)
+{
+ return 0;
+}
+
+void do_reloc16(unsigned int val, unsigned int *loc, unsigned int val_mask,
+ unsigned int val_shift, unsigned int loc_mask,
+ unsigned int partial_in_place, unsigned int swap)
+{
+ unsigned int tmp = 0, tmp2 = 0;
+
+ __asm__ __volatile__("\tlhi.bi\t%0, [%2], 0\n"
+ "\tbeqz\t%3, 1f\n"
+ "\twsbh\t%0, %1\n"
+ "1:\n":"=r"(tmp):"0"(tmp), "r"(loc), "r"(swap)
+ );
+
+ tmp2 = tmp & loc_mask;
+ if (partial_in_place) {
+ tmp &= (!loc_mask);
+ tmp =
+ tmp2 | ((tmp + ((val & val_mask) >> val_shift)) & val_mask);
+ } else {
+ tmp = tmp2 | ((val & val_mask) >> val_shift);
+ }
+
+ __asm__ __volatile__("\tbeqz\t%3, 2f\n"
+ "\twsbh\t%0, %1\n"
+ "2:\n"
+ "\tshi.bi\t%0, [%2], 0\n":"=r"(tmp):"0"(tmp),
+ "r"(loc), "r"(swap)
+ );
+}
+
+void do_reloc32(unsigned int val, unsigned int *loc, unsigned int val_mask,
+ unsigned int val_shift, unsigned int loc_mask,
+ unsigned int partial_in_place, unsigned int swap)
+{
+ unsigned int tmp = 0, tmp2 = 0;
+
+ __asm__ __volatile__("\tlmw.bi\t%0, [%2], %0, 0\n"
+ "\tbeqz\t%3, 1f\n"
+ "\twsbh\t%0, %1\n"
+ "\trotri\t%0, %1, 16\n"
+ "1:\n":"=r"(tmp):"0"(tmp), "r"(loc), "r"(swap)
+ );
+
+ tmp2 = tmp & loc_mask;
+ if (partial_in_place) {
+ tmp &= (!loc_mask);
+ tmp =
+ tmp2 | ((tmp + ((val & val_mask) >> val_shift)) & val_mask);
+ } else {
+ tmp = tmp2 | ((val & val_mask) >> val_shift);
+ }
+
+ __asm__ __volatile__("\tbeqz\t%3, 2f\n"
+ "\twsbh\t%0, %1\n"
+ "\trotri\t%0, %1, 16\n"
+ "2:\n"
+ "\tsmw.bi\t%0, [%2], %0, 0\n":"=r"(tmp):"0"(tmp),
+ "r"(loc), "r"(swap)
+ );
+}
+
+static inline int exceed_limit(int offset, unsigned int val_mask,
+ struct module *module, Elf32_Rela * rel,
+ unsigned int relindex, unsigned int reloc_order)
+{
+ int abs_off = offset < 0 ? ~offset : offset;
+
+ if (abs_off & (~val_mask)) {
+ printk(KERN_ERR "\n%s: relocation type %d out of range.\n"
+ "please rebuild the kernel module with gcc option \"-Wa,-mno-small-text\".\n",
+ module->name, ELF32_R_TYPE(rel->r_info));
+ PRINTK("section %d reloc %d offset 0x%x relative 0x%x.\n"
+ relindex, reloc_order, rel->r_offset, offset);
+ return true;
+ }
+ return false;
+}
+
+#ifdef __NDS32_EL__
+#define NEED_SWAP 1
+#else
+#define NEED_SWAP 0
+#endif
+
+int
+apply_relocate_add(Elf32_Shdr * sechdrs, const char *strtab,
+ unsigned int symindex, unsigned int relindex,
+ struct module *module)
+{
+ Elf32_Shdr *symsec = sechdrs + symindex;
+ Elf32_Shdr *relsec = sechdrs + relindex;
+ Elf32_Shdr *dstsec = sechdrs + relsec->sh_info;
+ Elf32_Rela *rel = (void *)relsec->sh_addr;
+ unsigned int i;
+
+ for (i = 0; i < relsec->sh_size / sizeof(Elf32_Rela); i++, rel++) {
+ Elf32_Addr *loc;
+ Elf32_Sym *sym;
+ Elf32_Addr v;
+ s32 offset;
+
+ offset = ELF32_R_SYM(rel->r_info);
+ if (offset < 0
+ || offset > (symsec->sh_size / sizeof(Elf32_Sym))) {
+ printk(KERN_ERR "%s: bad relocation\n", module->name);
+ PRINTK("section %d reloc %d\n", module->name, relindex,
+ i);
+ return -ENOEXEC;
+ }
+
+ sym = ((Elf32_Sym *) symsec->sh_addr) + offset;
+
+ if (rel->r_offset < 0
+ || rel->r_offset > dstsec->sh_size - sizeof(u16)) {
+ printk(KERN_ERR "%s: out of bounds relocation\n",
+ module->name);
+ PRINTK("section %d reloc %d offset 0x%0x size %d\n",
+ relindex, i, rel->r_offset, dstsec->sh_size);
+ return -ENOEXEC;
+ }
+
+ loc = (Elf32_Addr *) (dstsec->sh_addr + rel->r_offset);
+ v = sym->st_value + rel->r_addend;
+
+ switch (ELF32_R_TYPE(rel->r_info)) {
+ case R_NDS32_NONE:
+ case R_NDS32_INSN16:
+ case R_NDS32_LABEL:
+ case R_NDS32_LONGCALL1:
+ case R_NDS32_LONGCALL2:
+ case R_NDS32_LONGCALL3:
+ case R_NDS32_LONGCALL4:
+ case R_NDS32_LONGJUMP1:
+ case R_NDS32_LONGJUMP2:
+ case R_NDS32_LONGJUMP3:
+ case R_NDS32_9_FIXED_RELA:
+ case R_NDS32_15_FIXED_RELA:
+ case R_NDS32_17_FIXED_RELA:
+ case R_NDS32_25_FIXED_RELA:
+ case R_NDS32_LOADSTORE:
+ case R_NDS32_DWARF2_OP1_RELA:
+ case R_NDS32_DWARF2_OP2_RELA:
+ case R_NDS32_DWARF2_LEB_RELA:
+ case R_NDS32_RELA_NOP_MIX...R_NDS32_RELA_NOP_MAX:
+ break;
+
+ case R_NDS32_32_RELA:
+ do_reloc32(v, loc, 0xffffffff, 0, 0, 0, 0);
+ break;
+
+ case R_NDS32_HI20_RELA:
+ do_reloc32(v, loc, 0xfffff000, 12, 0xfff00000, 0,
+ NEED_SWAP);
+ break;
+
+ case R_NDS32_LO12S3_RELA:
+ do_reloc32(v, loc, 0x00000fff, 3, 0xfffff000, 0,
+ NEED_SWAP);
+ break;
+
+ case R_NDS32_LO12S2_RELA:
+ do_reloc32(v, loc, 0x00000fff, 2, 0xfffff000, 0,
+ NEED_SWAP);
+ break;
+
+ case R_NDS32_LO12S1_RELA:
+ do_reloc32(v, loc, 0x00000fff, 1, 0xfffff000, 0,
+ NEED_SWAP);
+ break;
+
+ case R_NDS32_LO12S0_RELA:
+ case R_NDS32_LO12S0_ORI_RELA:
+ do_reloc32(v, loc, 0x00000fff, 0, 0xfffff000, 0,
+ NEED_SWAP);
+ break;
+
+ case R_NDS32_9_PCREL_RELA:
+ if (exceed_limit
+ ((v - (Elf32_Addr) loc), 0x000000ff, module, rel,
+ relindex, i))
+ return -ENOEXEC;
+ do_reloc16(v - (Elf32_Addr) loc, loc, 0x000001ff, 1,
+ 0xffffff00, 0, NEED_SWAP);
+ break;
+
+ case R_NDS32_15_PCREL_RELA:
+ if (exceed_limit
+ ((v - (Elf32_Addr) loc), 0x00003fff, module, rel,
+ relindex, i))
+ return -ENOEXEC;
+ do_reloc32(v - (Elf32_Addr) loc, loc, 0x00007fff, 1,
+ 0xffffc000, 0, NEED_SWAP);
+ break;
+
+ case R_NDS32_17_PCREL_RELA:
+ if (exceed_limit
+ ((v - (Elf32_Addr) loc), 0x0000ffff, module, rel,
+ relindex, i))
+ return -ENOEXEC;
+ do_reloc32(v - (Elf32_Addr) loc, loc, 0x0001ffff, 1,
+ 0xffff0000, 0, NEED_SWAP);
+ break;
+
+ case R_NDS32_25_PCREL_RELA:
+ if (exceed_limit
+ ((v - (Elf32_Addr) loc), 0x00ffffff, module, rel,
+ relindex, i))
+ return -ENOEXEC;
+ do_reloc32(v - (Elf32_Addr) loc, loc, 0x01ffffff, 1,
+ 0xff000000, 0, NEED_SWAP);
+ break;
+ case R_NDS32_WORD_9_PCREL_RELA:
+ if (exceed_limit
+ ((v - (Elf32_Addr) loc), 0x000000ff, module, rel,
+ relindex, i))
+ return -ENOEXEC;
+ do_reloc32(v - (Elf32_Addr) loc, loc, 0x000001ff, 1,
+ 0xffffff00, 0, NEED_SWAP);
+ break;
+
+ case R_NDS32_SDA15S3_RELA:
+ case R_NDS32_SDA15S2_RELA:
+ case R_NDS32_SDA15S1_RELA:
+ case R_NDS32_SDA15S0_RELA:
+ printk(KERN_ERR "%s: unsupported relocation type %d.\n",
+ module->name, ELF32_R_TYPE(rel->r_info));
+ printk(KERN_ERR
+ "Small data section access doesn't work in the kernel space; "
+ "please rebuild the kernel module with gcc option -G0.\n");
+ PRINTK("section %d reloc %d offset 0x%x size %d\n",
+ relindex, i, rel->r_offset, dstsec->sh_size);
+ break;
+
+ default:
+ printk(KERN_ERR "%s: unsupported relocation type %d.\n",
+ module->name, ELF32_R_TYPE(rel->r_info));
+ PRINTK("section %d reloc %d offset 0x%x size %d\n",
+ relindex, i, rel->r_offset, dstsec->sh_size);
+ }
+ }
+ return 0;
+}
+
+int
+apply_relocate(Elf32_Shdr * sechdrs, const char *strtab,
+ unsigned int symindex, unsigned int relsec,
+ struct module *module)
+{
+// printk(KERN_ERR "module %s: non-ADD RELOCATION unsupported\n", module->name);
+// return -ENOEXEC;
+ return 0;
+}
+
+int
+module_finalize(const Elf32_Ehdr * hdr, const Elf_Shdr * sechdrs,
+ struct module *module)
+{
+ return 0;
+}
+
+void module_arch_cleanup(struct module *mod)
+{
+}
diff -Nur linux-3.4.113.orig/arch/nds32/kernel/nds32-elf.h linux-3.4.113/arch/nds32/kernel/nds32-elf.h
--- linux-3.4.113.orig/arch/nds32/kernel/nds32-elf.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/kernel/nds32-elf.h 2016-12-01 20:59:24.356612904 +0100
@@ -0,0 +1,855 @@
+#ifndef _NDS32_ELF_CHECK
+#define _NDS32_ELF_CHECK
+
+//#define TEST_ELF_CHECK_FUNC
+#ifdef TEST_ELF_CHECK_FUNC
+#include <stdio.h>
+#include <stdlib.h>
+#endif
+
+//#include <stdio.h>
+//#include <stdarg.h>
+
+#ifdef __cplusplus
+extern "C"
+{
+#else
+#include <stdbool.h>
+#endif //#ifdef __cplusplus
+
+
+ enum ELF_HEADER_FLAG_FIELD
+ {
+ EHFF_ARCH_VER = 0xF0000000, EHFF_ARCH_VER_SHIFT = 28,
+ //EHFF_RESERVED = 0x08000000,
+ EHFF_HAS_ZOL = 0x04000000,
+ EHFF_ISA_DSP = 0x02000000,
+ EHFF_ISA_FPU_MAC = 0x01000000,
+ EHFF_FPU_REG = 0x00C00000, EHFF_FPU_REG_SHIFT = 22,
+ EHFF_ISA_L2C = 0x00200000,
+ EHFF_ISA_NO_MAC = 0x00100000,
+ EHFF_ISA_MAC_DX = 0x00100000,
+ EHFF_ISA_FPU_DP = 0x00080000,
+ //EHFF_RESERVED = 0x00040000,
+ EHFF_ISA_SATURATION = 0x00020000,
+ EHFF_REDUCED_REGS = 0x00010000,
+ EHFF_ISA_STRING = 0x00008000,
+ EHFF_ISA_16BIT = 0x00004000,
+ EHFF_ISA_IFC = 0x00004000,
+ EHFF_ISA_DIV = 0x00002000,
+ EHFF_ISA_DIV_DX = 0x00002000,
+ EHFF_ISA_AUDIO = 0x00001000,
+ EHFF_ISA_FPU_SP = 0x00000800,
+ EHFF_ISA_EXT2 = 0x00000400,
+ EHFF_ISA_EXT = 0x00000200,
+ EHFF_ISA_EIT = 0x00000100,
+ EHFF_ISA_MFUSR_PC = 0x00000100,
+ EHFF_ABI_VER = 0x000000F0,
+ EHFF_ELF_VER = 0x0000000F, EHFF_ELF_VER_SHIFT = 0,
+ };
+
+
+ enum ELF_HEADER_FLAG_FIELD_ARCH_VER
+ {
+ EHFF_ARCH_VER_RESERVED = 0x0,
+ EHFF_ARCH_VER_V1 = 0x1,
+ EHFF_ARCH_VER_V2 = 0x2,
+ EHFF_ARCH_VER_V3 = 0x3,
+ EHFF_ARCH_VER_V3M = 0x4,
+ };
+
+ static const char *EHFF_ARCH_VER_MSG[] =
+ {
+ "RESERVED",
+ "BASE V1",
+ "BASE V2",
+ "BASE V3",
+ "BASE V3M",
+ };
+
+
+
+
+ /* ----------------------------------------------------------- */
+ /* 4-bit for ABI signature, allow up to 16 ABIs */
+ /* 0 : for OLD ABI V0, phase out
+ * 1 : for V1 , starting with V0 toolchain
+ * 2 : for V2
+ * 3 : for V2FP (fs0, fs1 as function parameter)
+ * 4 : for AABI */
+ /* only old N1213HC use V0 */
+ /* New ABI is used due to return register is changed to r0 from r5 */
+ /* ----------------------------------------------------------- */
+#define E_NDS_ABI_V0 0x00000000
+#define E_NDS_ABI_V1 0x00000010
+#define E_NDS_ABI_V2 0x00000020
+#define E_NDS_ABI_V2FP 0x00000030
+#define E_NDS_ABI_AABI 0x00000040
+#define E_NDS_ABI_V2FP_PLUS 0x00000050
+
+ /* ---------------------------------------------------------------------------- */
+ /* This flag signifies the version of Andes ELF */
+ /* note : */
+ /* 1. v1.3.1 and beyond is accompanying with Baseline ISA 1.0b/2.0/... in ELF. */
+ /* 2. v1.3.1 is accompanying with Baseline ISA 1.0b in ELF. */
+ /* ... | MAC | ... | DIV | ... */
+ /* 3. v1.3.1 is accompanying with Baseline ISA 2.0 and beyond in ELF. */
+ /* ... | MAC_DX | ... | DIV_DX | ... */
+ /* ---------------------------------------------------------------------------- */
+
+ enum ELF_HEADER_FLAG_FIELD_ELF_VER
+ {
+ EHFF_ELF_VER_1_3_0 = 0x0,
+ EHFF_ELF_VER_1_3_1 = 0x1,
+ EHFF_ELF_VER_1_4_0 = 0x2,
+ };
+
+ static const char *EHFF_ELF_VER_MSG[] =
+ {
+ "1.3.0",
+ "1.3.1",
+ "1.4.0",
+ };
+ /* */
+ /* sr layout : */
+ /* sr[14..10] : hardware components */
+ /* cpu / fpu / audio / ... */
+ /* sr[9..0] : sr index number dedicated for sr[14..10] */
+ /* */
+
+ //
+ // sr[14..10] definition:
+ // 0 : cpu
+ // 1 : fpu
+ // 2 : audio
+#define INDEX_HW_MASK 0x00007c00
+#define INDEX_HW_CPU 0x00000000
+#define INDEX_HW_FPU 0x00000400
+#define INDEX_HW_AUDIO 0x00000800
+#define HW_IS_CPU(sr) ((sr & INDEX_HW_MASK) == INDEX_HW_CPU)
+#define HW_IS_FPU(sr) ((sr & INDEX_HW_MASK) == INDEX_HW_FPU)
+#define HW_IS_AUDIO(sr) ((sr & INDEX_HW_MASK) == INDEX_HW_AUDIO)
+
+ //
+ // sr[9..0] definition:
+ // if (HW_IS_CPU(sr)) // cpu score
+ // sr[9..0] defined in chap 9 of Andes-Privilege-Architecture spec.
+ // else if (HW_IS_FPU(sr)) // fpu score
+ // sr[9..0] == SR_FPU_FPCFG, FPCFG defined in FPU_ISA_EXT spec.
+ // else if (HW_IS_AUDIO(sr)) // audio score
+ // //none register is used in loader checking mechanism
+ //
+#define SR_INDEX_MASK 0x000003ff
+#define SR_INDEX(sr) (sr & SR_INDEX_MASK)
+#define CPU_SR_INDEX(x,y,z) ((x << 7) + (y << 3) + z)
+#define FPU_SR_FPCFG() (INDEX_HW_FPU)
+
+ //FPU-belonged system registers
+#define SR_FPU_FPCFG 0x00
+
+#define SR_NOT_EXIST 0xffffffff
+
+ typedef unsigned int (* CALLBACK_FUNC) (unsigned int index);
+
+
+ static const char *NEC_MSG_FPU_reg[5] =
+ {
+ "N/A",
+ " 8SP/ 4DP",
+ "16SP/ 8DP",
+ "32SP/16DP",
+ "32SP/32DP"
+ };
+ static const char *NEC_MSG_endian[2] =
+ {
+ "little",
+ "big"
+ };
+
+#define EM_NDS32 167
+#if defined elf_check_swap_2 || defined elf_check_swap_4
+#error "ERROR : elf_check_swap_2 and elf_check_swap_4 are multiple defined"
+#endif
+#define elf_check_swap_2(data) (((data&0x0000ff00)>>8) | ((data&0x000000ff)<<8))
+#define elf_check_swap_4(data) (((data&0xff000000)>>24) | \
+ ((data&0x00ff0000)>>8) | \
+ ((data&0x0000ff00)<<8) | \
+ ((data&0x000000ff)<<24))
+
+#define MSC_CFG_BASEV 0x0000e000
+
+#define CPU_VER_EXT 0x00000001
+#define CPU_VER_A16 0x00000002
+#define CPU_VER_EXT2 0x00000004
+#define CPU_VER_FPU 0x00000008
+#define CPU_VER_STRING 0x00000010
+#define CPU_VER_SATURATION 0x00000020
+
+#define MSC_CFG_DIV 0x00000020
+#define MSC_CFG_MAC 0x00000040
+#define MSC_CFG_L2C 0x00000200
+#define MSC_CFG_REDUCED_REG 0x00000400
+#define MSC_CFG_NOD 0x00010000
+#define MSC_CFG_AUDIO 0x00000180
+#define MSC_CFG_AUDIO_NONE 0x00000000
+#define MSC_CFG_IFC 0x00080000
+#define MSC_CFG_MCU 0x00100000
+#define MSC_CFG_EX9IT 0x01000000
+#define MSC_CFG_MSC_EXT 0xc0000000
+
+#define MSC_CFG2_DSPPF 0x00000018
+#define MSC_CFG2_ZOL 0x00000020
+
+#define MMU_CFG_DE 0x04000000
+
+ typedef struct nds32_elfinfo_s
+ {
+ unsigned int endian; // 1.local-used constant definition
+ // 0 : little , 1 : big
+ // 2.system-used constant definition
+ // little / big depends on system definition
+ unsigned int machine; //magic number (167 for nds32 machine)
+ unsigned int mfusr_pc; //reclaim in baseline v2
+ unsigned int abi; // abi version
+ unsigned int base16; // 0 : not support , 1 : support
+ unsigned int pex1;
+ unsigned int div; //reclaim in baseline v2
+ unsigned int pex2;
+ unsigned int fpu; //fpu single precision
+ unsigned int audio;
+ unsigned int string;
+ unsigned int reduced_regs;
+ unsigned int saturation;
+ unsigned int ifc;
+ unsigned int elf_ver; //elf version number, 0 for v1.3.0, 1 for v1.3.1
+ unsigned int l2c;
+ unsigned int mac; //reclaim in baseline v2
+ //unsigned int isa_ver;//0x0, baseline = baseline V1 - 16 bit ISA
+ //0x1, baseline = baseline V1
+ //0x2, baseline = baseline V1 + V2 extension ISA
+ //unsigned int fpu_sp; //fpu double precision
+ //unsigned int fpu_reg; //fpu registers capacity
+ } nds32_elfinfo_t;
+
+ typedef enum nds32_elfchk_e
+ {
+ endian_chk = 0,
+ machine_chk,
+ isa_chk,
+ abi_chk
+ } nds32_elfchk_t;
+
+ typedef enum ELF_Fail_Type
+ {
+ EFT_NONE,
+ EFT_WARNING,
+ EFT_ERROR
+ }ELF_Fail_Type;
+
+ static inline void NEC_itoa(unsigned int value, char *buf, const unsigned int base)
+ {
+ char temp[10] = "\0", ch;
+ int len = 1, index;
+
+ while(value > 0)
+ {
+ ch = value%base;
+ value = value/base;
+ if(ch >= 10)
+ ch = ch+'a'-10;
+ else
+ ch = ch+'0';
+ temp[len++] = ch;
+ }
+ len--;
+
+ index = len;
+ while(index >= 0)
+ {
+ buf[index] = temp[len-index];
+ index--;
+ }
+ }
+
+ static inline void NEC_format(char *buf, unsigned int width)
+ {
+ unsigned int len = strlen(buf);
+ memmove(buf+(width-len), buf, len+1);
+ memset(buf, ' ', (width-len));
+ }
+
+ static void NEC_sprintf(char *buf, const char *str, ...)
+ {
+ int width, len = 0;
+ va_list ap;
+ char token, temp[100];
+ buf[0] = '\0';
+
+
+ va_start(ap, str);
+ while(*str != '\0')
+ {
+ if(*str != '%')
+ buf[len++] = *str;
+ else //*str == '%'
+ {
+ token = *(++str);
+
+ width = 0;
+ while(token >= '0' && token <= '9')
+ {
+ width *= 10;
+ width += token-'0';
+ token = *(++str);
+ }
+
+ switch(token)
+ {
+ case 'd':
+ NEC_itoa(va_arg(ap, unsigned int), temp, 10);
+ break;
+ case 'x':
+ NEC_itoa(va_arg(ap, unsigned int), temp, 16);
+ break;
+ case 's':
+ strcpy(temp, va_arg(ap, char *));
+ break;
+ }
+
+ if(width != 0)
+ NEC_format(temp, width);
+
+ buf[len++] = '\0';
+ strcat(buf, temp);
+ len = strlen(buf);
+ }
+
+ str++;
+ }
+ buf[len] = '\0';
+ }
+
+ //NDS32 strcat for avoiding buf overflow
+ static inline void NEC_strcat_safety(char *destination, unsigned int destination_size, char *source)
+ {
+ strncat(destination, source, destination_size - strlen(destination) - 1);
+ }
+
+ //NDS32 Elf Check print
+ static inline void NEC_print(char *buf, unsigned int len, ELF_Fail_Type type, const char *name, const char *cpu, const char *elf, const char *error_message)
+ {
+ char temp[100];
+ switch(type)
+ {
+ case EFT_NONE:
+ NEC_sprintf(temp, "\t | %9s | %9s | %14s\n", cpu, elf, name);
+ break;
+ case EFT_WARNING:
+ NEC_sprintf(temp, "\t?| %9s | %9s | %14s Warning: %s\n", cpu, elf, name, error_message);
+ break;
+ case EFT_ERROR:
+ NEC_sprintf(temp, "\t!| %9s | %9s | %14s Error: %s\n", cpu, elf, name, error_message);
+ break;
+ }
+ NEC_strcat_safety(buf, len, temp);
+ }
+
+ static inline bool NEC_check_bool(char *buf, unsigned int len, ELF_Fail_Type type, const char *isa, bool cpu, bool elf)
+ {
+ bool code;
+ const char *NEC_MSG_ISA[2] = { "OFF", "ON" };
+ if(!cpu && elf)
+ code = 1;
+ else
+ {
+ code = 0;
+ type = EFT_NONE;
+ }
+ NEC_print(buf, len, type, isa, NEC_MSG_ISA[cpu], NEC_MSG_ISA[elf], "Not supported by CPU");
+ return code;
+ }
+
+ static inline ELF_Fail_Type elf_ver_and_arch_ver_compatibility_check(unsigned int elf_ver, unsigned int arch_ver)
+ {
+ switch(elf_ver)
+ {
+ case EHFF_ELF_VER_1_3_0:
+ switch(arch_ver)
+ {
+ case EHFF_ARCH_VER_V1:
+ return EFT_NONE;
+ default:
+ return EFT_ERROR;
+ }
+ case EHFF_ELF_VER_1_3_1:
+ switch(arch_ver)
+ {
+ case EHFF_ARCH_VER_V1:
+ case EHFF_ARCH_VER_V2:
+ case EHFF_ARCH_VER_V3M:
+ return EFT_NONE;
+ default:
+ return EFT_ERROR;
+ }
+ case EHFF_ELF_VER_1_4_0:
+ switch(arch_ver)
+ {
+ case EHFF_ARCH_VER_V1:
+ case EHFF_ARCH_VER_V2:
+ case EHFF_ARCH_VER_V3:
+ case EHFF_ARCH_VER_V3M:
+ return EFT_NONE;
+ default:
+ return EFT_ERROR;
+ }
+ }
+ return EFT_ERROR;
+ }
+
+
+ static inline ELF_Fail_Type arch_ver_check(unsigned int CPU, unsigned int ELF)
+ {
+ switch(CPU)
+ {
+ case EHFF_ARCH_VER_V1:
+ switch(ELF)
+ {
+ case EHFF_ARCH_VER_V1:
+ return EFT_NONE;
+ default:
+ return EFT_ERROR;
+ }
+ case EHFF_ARCH_VER_V2:
+ switch(ELF)
+ {
+ case EHFF_ARCH_VER_V1:
+ case EHFF_ARCH_VER_V2:
+ return EFT_NONE;
+ default:
+ return EFT_ERROR;
+ }
+ case EHFF_ARCH_VER_V3:
+ switch(ELF)
+ {
+ case EHFF_ARCH_VER_V1:
+ case EHFF_ARCH_VER_V2:
+ case EHFF_ARCH_VER_V3:
+ case EHFF_ARCH_VER_V3M:
+ return EFT_NONE;
+ default:
+ return EFT_ERROR;
+ }
+ case EHFF_ARCH_VER_V3M:
+ switch(ELF)
+ {
+ case EHFF_ARCH_VER_V3M:
+ return EFT_NONE;
+ default:
+ return EFT_ERROR;
+ }
+ }
+ return EFT_ERROR;
+ }
+
+ // buf : buffer of char*, put Target Isa Info into *buf
+ // len : length of buffer (at least 300 chars in length)
+ // buf_status : status of buffer
+ // 0 : ok
+ // 1 : overflow
+#define TARGET_ISA_INFO_LEN 2000
+ static inline unsigned int elf_check (unsigned char *ehdr, CALLBACK_FUNC reg_read_callback, char *buf, unsigned int len, unsigned int *buf_status)
+ {
+ unsigned int SR_msc_cfg, SR_msc_cfg2 = 0, SR_cpu_ver, SR_mmu_cfg, fpcfg, fucop_exist, fpu_mount;
+ unsigned int CPU_DIV_DX_ISA, CPU_MAC_DX_ISA;
+ unsigned int eflag, ELF_arch_ver, ELF_elf_ver, CPU_arch_ver;
+ unsigned short machine;
+ unsigned char big_endian_elf = 0, big_endian_cpu;
+
+ char temp[100];
+ char temp_cpu[10];
+ char temp_elf[10];
+ int n_error, n_warning;
+ int CPU_support;
+ unsigned char FPU_reg_elf, FPU_reg_cpu;
+ ELF_Fail_Type error_type;
+
+
+
+ n_error = 0;
+ n_warning = 0;
+
+ buf[0] = '\0';
+ *buf_status = 0;
+
+ SR_cpu_ver = reg_read_callback(CPU_SR_INDEX(0,0,0));
+ SR_msc_cfg = reg_read_callback(CPU_SR_INDEX(0,4,0));
+ SR_mmu_cfg = reg_read_callback(CPU_SR_INDEX(0,3,0));
+
+ if (SR_msc_cfg & MSC_CFG_MSC_EXT)
+ SR_msc_cfg2 = reg_read_callback(CPU_SR_INDEX(0,4,1));
+
+ switch(*((char*)(ehdr+5)))
+ {
+ case 1:
+ big_endian_elf = 0;
+ break;
+ case 2:
+ big_endian_elf = 1;
+ break;
+ }
+
+ if(SR_mmu_cfg & MMU_CFG_DE)
+ big_endian_cpu = 1;
+ else
+ big_endian_cpu = 0;
+
+
+ /* 20091106 note :
+ * 1. In term of OS, elf_check() would be used in OS kernel and ld.so
+ * 2. Since OS is running on SID, eflag/machine did not need endian conversion for big endian format.
+ * 3. Later, elf_check interface is going to cover "OS" case by adding a new parameter.
+ *
+ */
+#ifdef ELF_CHECKING_OS
+ eflag = *((unsigned int *)(ehdr+36));
+ machine = *((unsigned short*)(ehdr+18));
+#else // GDB loader / SID loader
+ eflag = (big_endian_elf == 0)? *((unsigned int *)(ehdr+36)) : elf_check_swap_4(*((unsigned int *)(ehdr+36)));
+ machine = (big_endian_elf == 0)? *((unsigned short*)(ehdr+18)) : elf_check_swap_2(*((unsigned short*)(ehdr+18)));
+#endif
+
+ ELF_arch_ver = (eflag & EHFF_ARCH_VER) >> EHFF_ARCH_VER_SHIFT;
+ ELF_elf_ver = (eflag & EHFF_ELF_VER) >> EHFF_ELF_VER_SHIFT;
+
+ CPU_arch_ver = ((SR_msc_cfg & MSC_CFG_BASEV) >> 13) + 1;
+ if(CPU_arch_ver == 3)
+ if(SR_msc_cfg & MSC_CFG_MCU)
+ CPU_arch_ver = 4;
+
+ /*Basic version check
+
+ 1.ELF version check
+ 2.Architecture version check
+ 3.Machine check
+ */
+ if(ELF_elf_ver > EHFF_ELF_VER_1_4_0)
+ {
+ NEC_sprintf(temp, "Error: unsupport ELF version: 0x%x\n", ELF_elf_ver);
+ NEC_strcat_safety(buf, len, temp);
+ return 1;
+ }
+ NEC_sprintf(temp, "ELF version: %s\n", EHFF_ELF_VER_MSG[ELF_elf_ver]);
+ NEC_strcat_safety(buf, len, temp);
+
+
+ if(elf_ver_and_arch_ver_compatibility_check(ELF_elf_ver, ELF_arch_ver) == EFT_ERROR)
+ {
+ NEC_sprintf(temp, "Error: architecture version is not supported in this ELF version: %s\n", EHFF_ARCH_VER_MSG[ELF_arch_ver]);
+ NEC_strcat_safety(buf, len, temp);
+ return 1;
+ }
+
+ NEC_sprintf(temp, "\t %9s %9s \n", "CPU", "ELF");
+ NEC_strcat_safety(buf, len, temp);
+ if(big_endian_cpu != big_endian_elf)
+ {
+ error_type = EFT_ERROR;
+ n_error++;
+ }
+ else
+ error_type = EFT_NONE;
+ NEC_print(buf, len, error_type, "endianess", NEC_MSG_endian[big_endian_cpu], NEC_MSG_endian[big_endian_elf], "endianess mismatch");
+
+
+
+
+ if (EM_NDS32 != machine)
+ {
+ error_type = EFT_ERROR;
+ n_error++;
+ }
+ else
+ error_type = EFT_NONE;
+ NEC_sprintf(temp_cpu, "%d", EM_NDS32);
+ NEC_sprintf(temp_elf, "%d", machine);
+ NEC_print(buf, len, error_type, "machine", temp_cpu, temp_elf, "wrong machine");
+
+
+ error_type = arch_ver_check(CPU_arch_ver, ELF_arch_ver);
+ if(error_type == EFT_ERROR)
+ n_error++;
+ NEC_print(buf, len, error_type, "BASELINE ISA", EHFF_ARCH_VER_MSG[CPU_arch_ver], EHFF_ARCH_VER_MSG[ELF_arch_ver], "BASELINE ISA mismatch");
+
+ /*Prepare reference variables
+
+ 1.DIV, MAC, DX
+ 2.FPU
+ */
+
+ CPU_MAC_DX_ISA = 0;
+ CPU_DIV_DX_ISA = 0;
+ switch(CPU_arch_ver)
+ {
+ case EHFF_ARCH_VER_V1:
+ if (SR_msc_cfg & MSC_CFG_MAC)
+ CPU_MAC_DX_ISA = 1;
+ if (SR_msc_cfg & MSC_CFG_DIV)
+ CPU_DIV_DX_ISA = 1;
+ break;
+ case EHFF_ARCH_VER_V2:
+ case EHFF_ARCH_VER_V3:
+ case EHFF_ARCH_VER_V3M:
+ if (!(SR_msc_cfg & MSC_CFG_NOD))
+ {
+ CPU_MAC_DX_ISA = 1;
+ CPU_DIV_DX_ISA = 1;
+ }
+ break;
+ }
+ fpu_mount = 0;
+ if (SR_cpu_ver & CPU_VER_FPU)
+ {
+ fucop_exist = reg_read_callback(CPU_SR_INDEX(0,5,0));
+ if (fucop_exist & 0x80000000)
+ {
+ fpu_mount = 1;
+ fpcfg = reg_read_callback(FPU_SR_FPCFG());
+ }
+ else
+ fpu_mount = 0;
+ }
+
+ //Parse Configuration field (bit 27~8)
+
+ //bit 27 Reserved
+ //bit 26 ZOL
+ CPU_support = 0;
+ if ((SR_msc_cfg & MSC_CFG_MSC_EXT) && (SR_msc_cfg2 & MSC_CFG2_ZOL))
+ CPU_support = 1;
+ if (ELF_elf_ver == EHFF_ELF_VER_1_4_0)
+ n_error += NEC_check_bool(buf, len, EFT_ERROR, "ZOL", CPU_support, eflag & EHFF_HAS_ZOL);
+
+ //bit 25 DSP
+ CPU_support = 0;
+ if ((SR_msc_cfg & MSC_CFG_MSC_EXT) && (SR_msc_cfg2 & MSC_CFG2_DSPPF))
+ CPU_support = 1;
+ if (ELF_elf_ver == EHFF_ELF_VER_1_4_0)
+ n_error += NEC_check_bool(buf, len, EFT_ERROR, "DSP ISA", CPU_support, eflag & EHFF_ISA_DSP);
+
+ //bit 24
+ CPU_support = 0;
+ if(fpu_mount)
+ if(fpcfg & 0x00000010)
+ CPU_support = 1;
+ n_error += NEC_check_bool(buf, len, EFT_ERROR, "FPU MAC ISA", CPU_support, eflag & EHFF_ISA_FPU_MAC);
+
+ //bit 23~22
+ if(fpu_mount)
+ FPU_reg_cpu = ((fpcfg >> 2) & 0x3) + 1;
+ else
+ FPU_reg_cpu = 0;
+
+ if(eflag & (EHFF_ISA_FPU_SP | EHFF_ISA_FPU_DP | EHFF_ISA_FPU_MAC))
+ FPU_reg_elf = ((eflag & EHFF_FPU_REG) >> EHFF_FPU_REG_SHIFT) + 1;
+ else
+ FPU_reg_elf = 0;
+ if(FPU_reg_elf > FPU_reg_cpu)
+ {
+ error_type = EFT_ERROR;
+ n_error++;
+ }
+ else
+ error_type = EFT_NONE;
+ NEC_print(buf, len, error_type, "FPU REGISTER", NEC_MSG_FPU_reg[FPU_reg_cpu], NEC_MSG_FPU_reg[FPU_reg_elf],
+ "FPU REGISTERS not supported by CPU");
+ //bit 21
+ n_error += NEC_check_bool(buf, len, EFT_ERROR, "L2C ISA", SR_msc_cfg & MSC_CFG_L2C, eflag & EHFF_ISA_L2C);
+
+ //bit 20
+ //MAC_DX check
+ // Target Machine certainly has MAC_DX under the following conditions:
+ // 1. Baseline V1 ISA && MSC_CFG.MAC (softcore version)
+ // 2. Baseline V2 ISA && D0/D1 support
+ // 3. Baseline V3 ISA && D0/D1 support
+
+ switch(ELF_arch_ver)
+ {
+ case EHFF_ARCH_VER_V1:
+ n_error += NEC_check_bool(buf, len, EFT_ERROR, "MAC/MAC DX ISA", CPU_MAC_DX_ISA, !(eflag & EHFF_ISA_NO_MAC));
+ break;
+ case EHFF_ARCH_VER_V2:
+ case EHFF_ARCH_VER_V3:
+ case EHFF_ARCH_VER_V3M:
+ n_error += NEC_check_bool(buf, len, EFT_ERROR, "MAC DX ISA", CPU_MAC_DX_ISA, eflag & EHFF_ISA_MAC_DX);
+ break;
+ }
+ //bit 19
+ CPU_support = 0;
+ if(fpu_mount)
+ if(fpcfg & 0x00000002)
+ CPU_support = 1;
+ n_error += NEC_check_bool(buf, len, EFT_ERROR, "FPU DP ISA", CPU_support, eflag & EHFF_ISA_FPU_DP);
+
+
+ //bit 18 Reserved
+ //bit 17
+ switch(ELF_elf_ver)
+ {
+ case EHFF_ELF_VER_1_3_0:
+ case EHFF_ELF_VER_1_3_1:
+ break;
+ case EHFF_ELF_VER_1_4_0:
+ switch(ELF_arch_ver)
+ {
+ case EHFF_ARCH_VER_V3:
+ case EHFF_ARCH_VER_V3M:
+ n_error += NEC_check_bool(buf, len, EFT_ERROR, "SATURATION ISA", SR_cpu_ver & CPU_VER_SATURATION, eflag & EHFF_ISA_SATURATION);
+ break;
+ }
+ break;
+ }
+ //bit 16
+ if(SR_msc_cfg & MSC_CFG_REDUCED_REG)
+ CPU_support = 0;
+ else
+ CPU_support = 1;
+ n_error += NEC_check_bool(buf, len, EFT_ERROR, "32 GPR", CPU_support, (eflag & EHFF_REDUCED_REGS) == 0);
+
+ //bit 15
+ n_error += NEC_check_bool(buf, len, EFT_ERROR, "STRING ISA", SR_cpu_ver & CPU_VER_STRING, eflag & EHFF_ISA_STRING);
+
+ //bit 14
+ switch(ELF_elf_ver)
+ {
+ case EHFF_ELF_VER_1_3_0:
+ case EHFF_ELF_VER_1_3_1:
+ n_error += NEC_check_bool(buf, len, EFT_ERROR, "16-BIT ISA", SR_cpu_ver & CPU_VER_A16, eflag & EHFF_ISA_16BIT);
+ break;
+ case EHFF_ELF_VER_1_4_0:
+ switch(ELF_arch_ver)
+ {
+ case EHFF_ARCH_VER_V1:
+ case EHFF_ARCH_VER_V2:
+ n_error += NEC_check_bool(buf, len, EFT_ERROR, "16-BIT ISA", SR_cpu_ver & CPU_VER_A16, eflag & EHFF_ISA_16BIT);
+ break;
+ case EHFF_ARCH_VER_V3:
+ case EHFF_ARCH_VER_V3M:
+ n_error += NEC_check_bool(buf, len, EFT_ERROR, "IFC ISA", SR_msc_cfg & MSC_CFG_IFC, eflag & EHFF_ISA_IFC);
+ break;
+ }
+ break;
+ }
+
+ //bit 13
+ switch(ELF_arch_ver)
+ {
+ case EHFF_ARCH_VER_V1:
+ n_error += NEC_check_bool(buf, len, EFT_ERROR, "DIV DX ISA", CPU_DIV_DX_ISA, eflag & EHFF_ISA_DIV);
+ break;
+ case EHFF_ARCH_VER_V2:
+ case EHFF_ARCH_VER_V3:
+ case EHFF_ARCH_VER_V3M:
+ n_error += NEC_check_bool(buf, len, EFT_ERROR, "DIV DX ISA", CPU_DIV_DX_ISA, eflag & EHFF_ISA_DIV_DX);
+ break;
+ }
+ //bit 12
+ n_error += NEC_check_bool(buf, len, EFT_ERROR, "AUDIO/DSP ISA", SR_msc_cfg & MSC_CFG_AUDIO, eflag & EHFF_ISA_AUDIO);
+ //bit 11
+ CPU_support = 0;
+ if(fpu_mount)
+ if(fpcfg & 0x00000001)
+ CPU_support = 1;
+ n_error += NEC_check_bool(buf, len, EFT_ERROR, "FPU SP ISA", CPU_support, eflag & EHFF_ISA_FPU_SP);
+
+ //bit 10
+ n_error += NEC_check_bool(buf, len, EFT_ERROR, "PEX2 ISA", SR_cpu_ver & CPU_VER_EXT2, eflag & EHFF_ISA_EXT2);
+
+ //bit 9
+ n_error += NEC_check_bool(buf, len, EFT_ERROR, "PEX1 ISA", SR_cpu_ver & CPU_VER_EXT, eflag & EHFF_ISA_EXT);
+
+ //bit 8
+ CPU_support = 0;
+ if(CPU_arch_ver == EHFF_ARCH_VER_V3M)
+ CPU_support = 1;
+ switch(ELF_elf_ver)
+ {
+ case EHFF_ELF_VER_1_3_0:
+ case EHFF_ELF_VER_1_3_1:
+ n_error += NEC_check_bool(buf, len, EFT_ERROR, "MFUSR_PC ISA", CPU_support, eflag & EHFF_ISA_MFUSR_PC);
+ break;
+ case EHFF_ELF_VER_1_4_0:
+ switch(ELF_arch_ver)
+ {
+ case EHFF_ARCH_VER_V1:
+ case EHFF_ARCH_VER_V2:
+ n_error += NEC_check_bool(buf, len, EFT_ERROR, "MFUSR_PC ISA", CPU_support, eflag & EHFF_ISA_MFUSR_PC);
+ break;
+ case EHFF_ARCH_VER_V3:
+ case EHFF_ARCH_VER_V3M:
+ n_error += NEC_check_bool(buf, len, EFT_ERROR, "EIT ISA", SR_msc_cfg & MSC_CFG_EX9IT, eflag & EHFF_ISA_EIT);
+ break;
+ }
+ break;
+ }
+
+ if(n_error)
+ {
+ NEC_strcat_safety(buf, len, (char*)"Error: ELF and CPU mismatch\n");
+ NEC_sprintf(temp, "Total Error: %d\n", n_error);
+ NEC_strcat_safety(buf, len, temp);
+
+ NEC_strcat_safety(buf, len, (char*)"Usage error, Consult Andes Toolchains and their compatible Andes cores for the Toolchain-CPU compatibility.\n");
+ NEC_strcat_safety(buf, len, (char*)"The Loader Checking can be disabled under Debug Configuration.\n");
+ }
+ else
+ NEC_strcat_safety(buf, len, (char*)"NDS32 ELF checking pass\n");
+
+ if(n_warning)
+ {
+ NEC_sprintf(temp, "Total Warning: %d\n", n_warning);
+ NEC_strcat_safety(buf, len, temp);
+ }
+
+
+ // checking buf overflow
+ if(strlen(buf) >= len)
+ *buf_status = 1;
+
+ return n_error;
+ } //end of elf_check
+
+#undef elf_check_swap_2
+#undef elf_check_swap_4
+
+#undef MSC_CFG_BASEV
+
+#undef CPU_VER_STRING
+#undef CPU_VER_EXT
+#undef CPU_VER_A16
+#undef CPU_VER_EXT2
+#undef CPU_VER_FPU
+#undef CPU_VER_SATURATION
+
+#undef MSC_CFG_DIV
+#undef MSC_CFG_MAC
+#undef MSC_CFG_L2C
+#undef MSC_CFG_REDUCED_REG
+#undef MSC_CFG_NOD
+#undef MSC_CFG_AUDIO
+#undef MSC_CFG_AUDIO_NONE
+#undef MSC_CFG_IFC
+#undef MSC_CFG_MCU
+#undef MSC_CFG_EX9IT
+#undef MSC_CFG_MSC_EXT
+
+#undef MSC_CFG2_DSPPF
+#undef MSC_CFG2_ZOL
+
+#undef MMU_CFG_DE
+
+#ifdef __cplusplus
+}
+#endif //#ifdef __cplusplus
+
+#endif //end of _NDS32_ELF_CHECK
+
diff -Nur linux-3.4.113.orig/arch/nds32/kernel/nds32_ksyms.c linux-3.4.113/arch/nds32/kernel/nds32_ksyms.c
--- linux-3.4.113.orig/arch/nds32/kernel/nds32_ksyms.c 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/kernel/nds32_ksyms.c 2016-12-01 20:59:24.356612904 +0100
@@ -0,0 +1,103 @@
+/*
+ * arch/nds32/kernel/nds32_ksyms.c
+ * Copyright (C) 2008 Andes Technology Corporation
+ */
+
+#include <linux/module.h>
+#include <linux/string.h>
+#include <linux/delay.h>
+#include <linux/in6.h>
+#include <linux/syscalls.h>
+
+#include <asm/checksum.h>
+#include <asm/io.h>
+#include <asm/system.h>
+#include <asm/uaccess.h>
+
+/*
+ * libgcc functions - functions that are used internally by the
+ * compiler... (prototypes are not correct though, but that
+ * doesn't really matter since they're not versioned).
+ */
+extern void __ashldi3(void);
+extern void __ashrdi3(void);
+extern void __divsi3(void);
+extern void __lshrdi3(void);
+extern void __modsi3(void);
+extern void __muldi3(void);
+extern void __ucmpdi2(void);
+extern void __udivdi3(void);
+extern void __umoddi3(void);
+extern void __udivmoddi4(void);
+extern void __udivsi3(void);
+extern void __umodsi3(void);
+
+/*
+ * This has a special calling convention; it doesn't
+ * modify any of the usual registers, except for LR.
+ */
+#define EXPORT_SYMBOL_ALIAS(sym,orig) \
+ const struct kernel_symbol __ksymtab_##sym \
+ __attribute__((section("__ksymtab"))) = \
+ { (unsigned long)&orig, #sym };
+
+/*
+ * floating point math emulator support.
+ * These symbols will never change their calling convention...
+ */
+
+/* networking */
+EXPORT_SYMBOL(csum_partial);
+EXPORT_SYMBOL(csum_partial_copy_nocheck);
+
+/* string / mem functions */
+EXPORT_SYMBOL(strchr);
+EXPORT_SYMBOL(strrchr);
+EXPORT_SYMBOL(memset);
+EXPORT_SYMBOL(memcpy);
+EXPORT_SYMBOL(memmove);
+EXPORT_SYMBOL(__memzero);
+
+/* user mem (segment) */
+EXPORT_SYMBOL(__arch_copy_from_user);
+EXPORT_SYMBOL(__arch_copy_to_user);
+EXPORT_SYMBOL(__arch_clear_user);
+EXPORT_SYMBOL(__arch_strnlen_user);
+EXPORT_SYMBOL(__arch_strncpy_from_user);
+
+EXPORT_SYMBOL(__get_user_1);
+EXPORT_SYMBOL(__get_user_2);
+EXPORT_SYMBOL(__get_user_4);
+EXPORT_SYMBOL(__get_user_8);
+
+EXPORT_SYMBOL(__put_user_1);
+EXPORT_SYMBOL(__put_user_2);
+EXPORT_SYMBOL(__put_user_4);
+EXPORT_SYMBOL(__put_user_8);
+
+/* gcc lib functions */
+EXPORT_SYMBOL(__ashldi3);
+EXPORT_SYMBOL(__ashrdi3);
+EXPORT_SYMBOL(__divsi3);
+EXPORT_SYMBOL(__lshrdi3);
+EXPORT_SYMBOL(__modsi3);
+EXPORT_SYMBOL(__muldi3);
+EXPORT_SYMBOL(__ucmpdi2);
+EXPORT_SYMBOL(__udivdi3);
+EXPORT_SYMBOL(__umoddi3);
+EXPORT_SYMBOL(__udivmoddi4);
+EXPORT_SYMBOL(__udivsi3);
+EXPORT_SYMBOL(__umodsi3);
+
+/* syscalls */
+EXPORT_SYMBOL(sys_write);
+EXPORT_SYMBOL(sys_lseek);
+EXPORT_SYMBOL(sys_exit);
+EXPORT_SYMBOL(sys_wait4);
+
+/* cache handling */
+
+EXPORT_SYMBOL(cpu_icache_inval_all);
+EXPORT_SYMBOL(cpu_dcache_wbinval_all);
+EXPORT_SYMBOL(cpu_dma_inval_range);
+EXPORT_SYMBOL(cpu_dma_wb_range);
diff -Nur linux-3.4.113.orig/arch/nds32/kernel/proc.c linux-3.4.113/arch/nds32/kernel/proc.c
--- linux-3.4.113.orig/arch/nds32/kernel/proc.c 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/kernel/proc.c 2016-12-01 20:59:24.356612904 +0100
@@ -0,0 +1,81 @@
+/*
+ * linux/arch/nds32/kernel/setup.c
+ *
+ * Copyright (C) 1995-2001 Russell King
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+/* ============================================================================
+ * Copyright (C) 2007 Andes Technology Corporation
+ * This file is part of Linux and should be licensed under the GPL.
+ * See the file COPYING for conditions for redistribution.
+ *
+ * Abstract:
+ *
+ * This program is for Andes NDS32 architecture.
+ *
+ * Revision History:
+ *
+ * Jul.05.2007 Initial ported by Tom, revised and patched for KGDB
+ * by Harry.
+ *
+ * Note:
+ *
+ * ============================================================================
+ */
+
+#include <asm/procinfo.h>
+
+struct proc_info_item info_item = {
+ "AndesCore",
+#ifndef CONFIG_CPU_ICACHE_DISABLE
+ "I"
+#endif
+#ifndef CONFIG_CPU_DCACHE_DISABLE
+ "D"
+#ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
+ "(wt)"
+#else
+ "(wb)"
+#endif
+#endif
+};
+
+struct proc_info_list n10_proc_info
+ __attribute__ ((section(".proc.info.init"))) = {
+.cpu_val = 0x0a000000,.cpu_mask = 0xff000000,.arch_name =
+ "NDS32 N10",.elf_name = "NDS32 ELF",.elf_hwcap = 0,.info =
+ &info_item,};
+
+struct proc_info_list n12_proc_info
+ __attribute__ ((section(".proc.info.init"))) = {
+.cpu_val = 0x0c000000,.cpu_mask = 0xff000000,.arch_name =
+ "NDS32 N12",.elf_name = "NDS32 ELF",.elf_hwcap = 0,.info =
+ &info_item,};
+
+struct proc_info_list n13_proc_info
+ __attribute__ ((section(".proc.info.init"))) = {
+.cpu_val = 0x0d000000,.cpu_mask = 0xff000000,.arch_name =
+ "NDS32 N13",.elf_name = "NDS32 ELF",.elf_hwcap = 0,.info =
+ &info_item,};
+
+struct proc_info_list n968_proc_info
+ __attribute__ ((section(".proc.info.init"))) = {
+.cpu_val = 0x19000000,.cpu_mask = 0xff000000,.arch_name =
+ "NDS32 N968",.elf_name = "NDS32 ELF",.elf_hwcap = 0,.info =
+ &info_item,};
+
+struct proc_info_list n1068_proc_info
+ __attribute__ ((section(".proc.info.init"))) = {
+.cpu_val = 0x1a000000,.cpu_mask = 0xff000000,.arch_name =
+ "NDS32 N1068",.elf_name = "NDS32 ELF",.elf_hwcap = 0,.info =
+ &info_item,};
+
+// the last one (a roust way to do so)
+struct proc_info_list nXX_proc_info
+ __attribute__ ((section(".proc.info.init"))) = {
+.cpu_val = 0x00000000,.cpu_mask = 0x00000000,.arch_name =
+ "NDS32 N??",.elf_name = "NDS32 ELF",.elf_hwcap = 0,.info =
+ &info_item,};
diff -Nur linux-3.4.113.orig/arch/nds32/kernel/process.c linux-3.4.113/arch/nds32/kernel/process.c
--- linux-3.4.113.orig/arch/nds32/kernel/process.c 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/kernel/process.c 2016-12-01 20:59:24.356612904 +0100
@@ -0,0 +1,630 @@
+/*
+ * linux/arch/nds32/kernel/process.c
+ */
+/* Copyright (C) 1996-2000 Russell King - Converted to ARM.
+ * Original Copyright (C) 1995 Linus Torvalds
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+/* ============================================================================
+ * Copyright (C) 2007 Andes Technology Corporation
+ * This file is part of Linux and should be licensed under the GPL.
+ * See the file COPYING for conditions for redistribution.
+ *
+ * Abstract:
+ *
+ * This program is process implementation for NDS32 architecture, and it
+ * is original referred from ARM.
+ *
+ * Revision History:
+ *
+ * Oct.02.2007 Initial ported by Tom, Shawn, Steven, and Harry.
+ * Oct.03.2007 Updated get_wchan() for info under /proc.
+ *
+ * Note:
+ *
+ * ============================================================================
+ */
+#include <linux/module.h>
+#include <linux/sched.h>
+#include <linux/delay.h>
+#include <linux/kallsyms.h>
+#include <asm/hardware.h>
+#include <asm/leds.h>
+#include <asm/uaccess.h>
+#include <asm/elf.h>
+#include <asm/fpu.h>
+#include <asm/audio.h>
+#include <linux/elf.h>
+#include <linux/tick.h>
+#include <linux/proc_fs.h>
+
+extern const char *processor_modes[];
+extern void setup_mm_for_reboot(char mode);
+extern struct task_struct *_switch(struct task_struct *last,
+ struct thread_info *prev,
+ struct thread_info *next);
+
+#ifndef CONFIG_UNLAZY_FPU
+struct task_struct *last_task_used_math = NULL;
+#endif
+#ifndef CONFIG_UNLAZY_AUDIO
+struct task_struct *last_task_used_audio = NULL;
+#endif
+static volatile int hlt_counter;
+
+#ifdef CONFIG_PROC_FS
+struct proc_dir_entry *proc_dir_cpu;
+EXPORT_SYMBOL(proc_dir_cpu);
+#endif
+
+extern inline void arch_reset(char mode)
+{
+ if (mode == 's') {
+ /* Use cpu handler, jump to 0 */
+ cpu_reset(0);
+ } else {
+ /*
+ * Suppose there should be HW function.
+ * Here we used one tick watchdog as a trick.
+ * It is not very good idea in the view of SoC
+ * design, but smart in firmware functionality.
+ * Harry@Jan,08.2008
+ */
+ REG32(WDT_FTWDT010_0_VA_BASE + 0x0C) = 0; // WdCR
+ REG32(WDT_FTWDT010_0_VA_BASE + 0x04) = 1; // WdLoad
+ REG32(WDT_FTWDT010_0_VA_BASE + 0x08) = 0x5AB9; // WdRestart
+ REG32(WDT_FTWDT010_0_VA_BASE + 0x0C) = 0x13; // Go...
+ }
+}
+
+#ifndef arch_idle
+static inline void arch_idle(void)
+{
+ cpu_do_idle();
+}
+#endif
+
+void disable_hlt(void)
+{
+ hlt_counter++;
+}
+
+EXPORT_SYMBOL(disable_hlt);
+
+void enable_hlt(void)
+{
+ hlt_counter--;
+}
+
+EXPORT_SYMBOL(enable_hlt);
+
+static int __init nohlt_setup(char *__unused)
+{
+ hlt_counter = 1;
+ return 1;
+}
+
+static int __init hlt_setup(char *__unused)
+{
+ hlt_counter = 0;
+ return 1;
+}
+
+__setup("nohlt", nohlt_setup);
+__setup("hlt", hlt_setup);
+
+/*
+ * The following aren't currently used.
+ */
+
+void (*pm_idle) (void) = NULL;
+EXPORT_SYMBOL(pm_idle);
+
+void (*pm_power_off) (void);
+EXPORT_SYMBOL(pm_power_off);
+
+/*
+ * This is our default idle handler. We need to disable
+ * interrupts here to ensure we don't miss a wakeup call.
+ */
+void default_idle(void)
+{
+ local_irq_disable();
+ if (!need_resched() && !hlt_counter)
+ arch_idle();
+ local_irq_enable();
+}
+
+/*
+ * The idle thread. We try to conserve power, while trying to keep
+ * overall latency low. The architecture specific idle is passed
+ * a value to indicate the level of "idleness" of the system.
+ */
+void cpu_idle(void)
+{
+
+ /* endless idle loop with no priority at all */
+ while (1) {
+ void (*idle) (void) = pm_idle;
+
+ if (!idle)
+ idle = default_idle;
+ tick_nohz_idle_enter();
+ leds_event(led_idle_start);
+ while (!need_resched())
+ idle();
+ leds_event(led_idle_end);
+ tick_nohz_idle_exit();
+ preempt_enable_no_resched();
+ schedule();
+ preempt_disable();
+ }
+}
+
+static char reboot_mode = 'h';
+
+int __init reboot_setup(char *str)
+{
+ reboot_mode = str[0];
+ return 1;
+}
+
+#ifdef CONFIG_PLAT_AG102
+static int cpub_pwroff(void)
+{
+ //PCU_SET_REG(PCS9_PARA,
+ // PCU_PREPARE(PCS9_PARA, IE, 0x0) |
+ // PCU_PREPARE(PCS9_PARA, CMD, PCS_CMD_SCALING) |
+ // PCU_PREPARE(PCS9_PARA, SYNC, PCS_SYNC_SRC) |
+ // PCU_PREPARE(PCS9_PARA, NXTPAR, 0x1b) // turn off cpub power
+ //);
+ //printk("cpub Power off: ok!!!OKOKOK\n");
+ //REG32(PCU_VA_BASE + 0x1A4) = (0x0000001B & 0x00FFFFFF)| ((0x2 << 24) & 0x0F000000) | ((0x1 << 28) & 0x70000000) | 0x00000000;
+ //__asm__ volatile ("standby wait_done\n");
+ //PCU_SET_REG(PCS9_ST1, 0x0); // clear status
+ //REG32(PCU_VA_BASE + 0x1A8) = 0x0;
+
+ //par = PCS_POWER_CPUB;
+ //PCU_SET_REG(PCS9_PARA,
+ //PCU_PREPARE(PCS9_PARA, IE, 0x1) |
+ //PCU_PREPARE(PCS9_PARA, CMD, PCS_CMD_PW_DOWN) |
+ //PCU_PREPARE(PCS9_PARA, SYNC, PCS_SYNC_SRC) |
+ //PCU_PREPARE(PCS9_PARA, NXTPAR, 0x6) // turn off all power
+
+ //printk("cpua Power off: ok!!!YAYAYA\n");
+ //printk("The value = 0x%08x\n", (0x00000006 & 0x00FFFFFF)| ((0x1 << 24) & 0x0F000000) | ((0x2 << 28) & 0x70000000) | 0x80000000);
+ REG32(PCU_VA_BASE + 0x1A4) =
+ (0x00000006 & 0x00FFFFFF) | ((0x1 << 24) & 0x0F000000) |
+ ((0x2 << 28) & 0x70000000) | 0x80000000;
+ __asm__ volatile ("standby wake_grant\n");
+ return (0);
+}
+#else
+static int cpub_pwroff(void)
+{
+ return 0;
+}
+
+#endif
+
+__setup("reboot=", reboot_setup);
+
+void machine_halt(void)
+{
+ //ADD by river 2011.04.14
+ cpub_pwroff();
+}
+
+EXPORT_SYMBOL(machine_halt);
+
+void machine_power_off(void)
+{
+ if (pm_power_off)
+ pm_power_off();
+}
+
+EXPORT_SYMBOL(machine_power_off);
+
+void machine_restart(char *__unused)
+{
+ /*
+ * Clean and disable cache, and turn off interrupts
+ */
+ cpu_proc_fin();
+
+ /*
+ * Tell the mm system that we are going to reboot -
+ * we may need it to insert some 1:1 mappings so that
+ * soft boot works.
+ */
+ setup_mm_for_reboot(reboot_mode);
+
+ /*
+ * Now call the architecture specific reboot code.
+ */
+ arch_reset(reboot_mode);
+
+ /*
+ * Whoops - the architecture was unable to reboot.
+ * Tell the user!
+ */
+ mdelay(1000);
+ printk("Reboot failed -- System halted\n");
+ while (1) ;
+}
+
+EXPORT_SYMBOL(machine_restart);
+
+void show_regs(struct pt_regs *regs)
+{
+ print_symbol("PC is at %s\n", instruction_pointer(regs));
+ print_symbol("LR is at %s\n", regs->NDS32_lp);
+ printk("pc : [<%08lx>] lp : [<%08lx>] %s\n"
+ "sp : %08lx fp : %08lx gp : %08lx\n",
+ instruction_pointer(regs),
+ regs->NDS32_lp, print_tainted(), regs->NDS32_sp,
+ regs->NDS32_fp, regs->NDS32_gp);
+ printk("r25: %08lx r24 : %08lx\n", regs->NDS32_r25, regs->NDS32_r24);
+
+ printk("r23: %08lx r22: %08lx r21: %08lx r20: %08lx\n",
+ regs->NDS32_r23, regs->NDS32_r22,
+ regs->NDS32_r21, regs->NDS32_r20);
+ printk("r19: %08lx r18: %08lx r17: %08lx r16: %08lx\n",
+ regs->NDS32_r19, regs->NDS32_r18,
+ regs->NDS32_r17, regs->NDS32_r16);
+ printk("r15: %08lx r14: %08lx r13: %08lx r12: %08lx\n",
+ regs->NDS32_r15, regs->NDS32_r14,
+ regs->NDS32_r13, regs->NDS32_r12);
+ printk("r11: %08lx r10: %08lx r9 : %08lx r8 : %08lx\n",
+ regs->NDS32_r11, regs->NDS32_r10,
+ regs->NDS32_r9, regs->NDS32_r8);
+ printk("r7 : %08lx r6 : %08lx r5 : %08lx r4 : %08lx\n",
+ regs->NDS32_r7, regs->NDS32_r6, regs->NDS32_r5, regs->NDS32_r4);
+ printk("r3 : %08lx r2 : %08lx r1 : %08lx r0 : %08lx\n",
+ regs->NDS32_r3, regs->NDS32_r2, regs->NDS32_r1, regs->NDS32_r0);
+ printk(" IRQs o%s Segment %s\n",
+ interrupts_enabled(regs) ? "n" : "ff",
+ segment_eq(get_fs(), get_ds())? "kernel" : "user");
+}
+
+void show_fpregs(struct user_fp *regs)
+{
+ int i;
+
+ for (i = 0; i < 8; i++) {
+ unsigned long *p;
+ char type;
+
+ p = (unsigned long *)(regs->fpregs + i);
+
+ switch (regs->ftype[i]) {
+ case 1:
+ type = 'f';
+ break;
+ case 2:
+ type = 'd';
+ break;
+ case 3:
+ type = 'e';
+ break;
+ default:
+ type = '?';
+ break;
+ }
+ if (regs->init_flag)
+ type = '?';
+
+ printk(" f%d(%c): %08lx %08lx %08lx%c",
+ i, type, p[0], p[1], p[2], i & 1 ? '\n' : ' ');
+ }
+
+ printk("FPSR: %08lx FPCR: %08lx\n",
+ (unsigned long)regs->fpsr, (unsigned long)regs->fpcr);
+}
+
+/*
+ * Task structure and kernel stack allocation.
+ */
+static unsigned long *thread_info_head;
+static unsigned int nr_thread_info;
+
+#define EXTRA_TASK_STRUCT 4
+#define ll_alloc_task_struct() ((struct thread_info *) __get_free_pages(GFP_KERNEL,1))
+#define ll_free_task_struct(p) free_pages((unsigned long)(p),1)
+
+struct thread_info *alloc_thread_info(struct task_struct *task)
+{
+ struct thread_info *thread = NULL;
+
+ if (EXTRA_TASK_STRUCT) {
+ unsigned long *p = thread_info_head;
+
+ if (p) {
+ thread_info_head = (unsigned long *)p[0];
+ nr_thread_info -= 1;
+ }
+ thread = (struct thread_info *)p;
+ }
+
+ if (!thread)
+ thread = ll_alloc_task_struct();
+
+#ifdef CONFIG_MAGIC_SYSRQ
+ /*
+ * The stack must be cleared if you want SYSRQ-T to
+ * give sensible stack usage information
+ */
+ if (thread) {
+ char *p = (char *)thread;
+ memzero(p + KERNEL_STACK_SIZE, KERNEL_STACK_SIZE);
+ }
+#endif
+ return thread;
+}
+
+void free_thread_info(struct thread_info *thread)
+{
+ if (EXTRA_TASK_STRUCT && nr_thread_info < EXTRA_TASK_STRUCT) {
+ unsigned long *p = (unsigned long *)thread;
+ p[0] = (unsigned long)thread_info_head;
+ thread_info_head = p;
+ nr_thread_info += 1;
+ } else
+ ll_free_task_struct(thread);
+}
+
+/*
+ * Free current thread data structures etc..
+ */
+void exit_thread(void)
+{
+#if defined(CONFIG_FPU)
+# ifndef CONFIG_UNLAZY_FPU
+ if (last_task_used_math == current) {
+ last_task_used_math = NULL;
+ }
+# endif
+#endif
+#if defined(CONFIG_AUDIO)
+# ifndef CONFIG_UNLAZY_AUDIO
+ if (last_task_used_audio == current) {
+ last_task_used_audio = NULL;
+ }
+# endif
+#endif
+}
+
+void flush_thread(void)
+{
+ struct task_struct *tsk = current;
+
+ memset(&tsk->thread.debug, 0, sizeof(struct debug_info));
+#if defined(CONFIG_FPU)
+ clear_fpu(task_pt_regs(tsk));
+ clear_used_math();
+# ifndef CONFIG_UNLAZY_FPU
+ if (last_task_used_math == current) {
+ last_task_used_math = NULL;
+ }
+# endif
+#endif
+
+#if defined(CONFIG_AUDIO)
+ clear_audio(task_pt_regs(tsk));
+ clear_tsk_thread_flag(tsk, TIF_USEDAUDIO);
+# ifndef CONFIG_UNLAZY_AUDIO
+ if (last_task_used_audio == current) {
+ last_task_used_audio = NULL;
+ }
+# endif
+#endif
+
+}
+
+void release_thread(struct task_struct *dead_task)
+{
+}
+
+asmlinkage void ret_from_fork(void) __asm__("ret_from_fork");
+
+/*
+ * Shuffle the argument into the correct register before calling the
+ * thread function. $r1 is the thread argument, $r2 is the pointer to
+ * the thread function, and $r3 points to the exit function.
+ */
+extern void kernel_thread_helper(void);
+asm(".section .text\n"
+ " .align\n"
+ " .type kernel_thread_helper, #function\n"
+ "kernel_thread_helper:\n"
+ " move $r2, $lp\n"
+ " move $r0, $r1\n"
+ " move $lp, $r3\n"
+ " jr $r2 \n"
+ " .size kernel_thread_helper, . - kernel_thread_helper\n"
+ " .previous");
+
+pid_t kernel_thread(int (*fn) (void *), void *arg, unsigned long flags)
+{
+ struct pt_regs regs;
+
+ memset(®s, 0, sizeof(regs));
+
+ regs.NDS32_r1 = (unsigned long)arg;
+ regs.NDS32_r2 = (unsigned long)fn;
+ /* to apply right path */
+ regs.NDS32_lp = regs.NDS32_r2;
+ regs.NDS32_r3 = (unsigned long)do_exit;
+ regs.NDS32_ipc = (unsigned long)kernel_thread_helper;
+
+#ifdef __NDS32_EB__
+#define PSW_DE PSW_mskBE
+#else
+#define PSW_DE 0x0
+#endif
+
+#ifdef CONFIG_WBNA
+#define PSW_valWBNA PSW_mskWBNA
+#else
+#define PSW_valWBNA 0x0
+#endif
+
+ regs.NDS32_ipsw =
+ (PSW_CPL_ANY | PSW_valWBNA | PSW_mskDT | PSW_mskIT | PSW_DE |
+ PSW_SYSTEM | PSW_INTL_1 | PSW_mskGIE);
+ regs.NDS32_ir0 =
+ (PSW_CPL_ANY | PSW_valWBNA | PSW_mskDT | PSW_mskIT | PSW_DE |
+ PSW_SYSTEM | PSW_INTL_1);
+
+ return do_fork(flags | CLONE_VM | CLONE_UNTRACED, 0, ®s, 0, NULL,
+ NULL);
+}
+
+EXPORT_SYMBOL(kernel_thread);
+
+int
+copy_thread(unsigned long clone_flags, unsigned long stack_start,
+ unsigned long stk_sz, struct task_struct *p, struct pt_regs *regs)
+{
+ struct thread_info *thread = task_thread_info(p);
+ struct pt_regs *childregs;
+
+ childregs =
+ ((struct pt_regs *)((unsigned long)thread + THREAD_SIZE - 8)) - 1;
+
+ *childregs = *regs;
+ childregs->NDS32_r0 = 0; /* child get zero as ret. */
+ childregs->NDS32_sp = stack_start;
+ childregs->NDS32_osp = 0;
+
+ thread->sp_save = ((struct cpu_context_save *)(childregs)) - 1;
+ /* cpu context switching */
+ thread->sp_save->pc = (unsigned long)ret_from_fork;
+ if (clone_flags & CLONE_SETTLS)
+ childregs->NDS32_r25 = regs->NDS32_r3;
+
+#ifdef CONFIG_FPU
+ if (used_math()) {
+# ifdef CONFIG_UNLAZY_FPU
+ unlazy_fpu(current);
+# else
+ preempt_disable();
+ if (last_task_used_math == current)
+ save_fpu(current);
+ preempt_enable();
+# endif
+ p->thread.fpu = current->thread.fpu;
+ clear_fpu(task_pt_regs(p));
+ set_stopped_child_used_math(p);
+ }
+#endif
+
+#ifdef CONFIG_AUDIO
+ if (test_tsk_thread_flag(current, TIF_USEDAUDIO)) {
+# ifdef CONFIG_UNLAZY_AUDIO
+ unlazy_audio(current);
+# else
+ preempt_disable();
+ if (last_task_used_audio == current)
+ save_audio(current);
+ preempt_enable();
+# endif
+ p->thread.audio = current->thread.audio;
+ clear_audio(childregs);
+ set_tsk_thread_flag(p, TIF_USEDAUDIO);
+ }
+#endif
+
+#ifdef CONFIG_HWZOL
+ childregs->NDS32_lb = 0;
+ childregs->NDS32_le = 0;
+ childregs->NDS32_lc = 0;
+#endif
+
+ return 0;
+}
+
+struct task_struct *__switch_to(struct task_struct *last,
+ struct thread_info *prev,
+ struct thread_info *next)
+{
+#if defined(CONFIG_FPU) || defined(CONFIG_AUDIO)
+# ifdef CONFIG_UNLAZY_FPU
+ unlazy_fpu(prev->task);
+# endif
+# ifdef CONFIG_UNLAZY_AUDIO
+ unlazy_audio(prev->task);
+# endif
+ if (!(next->task->flags & PF_KTHREAD)) {
+#ifdef CONFIG_FPU
+ clear_fpu(task_pt_regs(next->task));
+#endif
+#ifdef CONFIG_AUDIO
+ clear_audio(task_pt_regs(next->task));
+#endif
+ }
+#endif
+ return _switch(last, prev, next);
+}
+
+/*
+ * fill in the fpe structure for a core dump...
+ */
+int dump_fpu(struct pt_regs *regs, elf_fpregset_t * fpu)
+{
+ int fpvalid = 0;
+
+#if 0 // XXX defined(CONFIG_FPU)
+ struct task_struct *tsk = current;
+
+ fpvalid = !!tsk_used_math(tsk);
+ if (fpvalid) {
+ unlazy_fpu(tsk, regs);
+ memcpy(fpu, &tsk->thread.fpu, sizeof(*fpu));
+ }
+#endif
+
+ return fpvalid;
+}
+
+EXPORT_SYMBOL(dump_fpu);
+
+unsigned long get_wchan(struct task_struct *p)
+{
+ unsigned long fp, lr;
+ unsigned long stack_start, stack_end;
+ int count = 0;
+
+ if (!p || p == current || p->state == TASK_RUNNING)
+ return 0;
+
+#ifdef CONFIG_FRAME_POINTER
+ stack_start = (unsigned long)end_of_stack(p);
+ stack_end = (unsigned long)task_stack_page(p) + THREAD_SIZE;
+
+ fp = thread_saved_fp(p);
+ do {
+ if (fp < stack_start || fp > stack_end)
+ return 0;
+ lr = ((unsigned long *)fp)[0];
+ if (!in_sched_functions(lr))
+ return lr;
+ fp = *(unsigned long *)(fp + 4);
+ } while (count++ < 16);
+ return 0;
+#else
+ return 0;
+#endif
+}
+
+EXPORT_SYMBOL(get_wchan);
+
+extern int do_elf_check_arch(const struct elf32_hdr *hdr);
+
+int elf_check_arch(const struct elf32_hdr *hdr)
+{
+ return do_elf_check_arch(hdr);
+}
diff -Nur linux-3.4.113.orig/arch/nds32/kernel/ptrace.c linux-3.4.113/arch/nds32/kernel/ptrace.c
--- linux-3.4.113.orig/arch/nds32/kernel/ptrace.c 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/kernel/ptrace.c 2016-12-01 20:59:24.356612904 +0100
@@ -0,0 +1,919 @@
+/*
+ * linux/arch/nds32/kernel/ptrace.c
+ */
+/* By Ross Biro 1/23/92
+ * edited by Linus Torvalds
+ * ARM modifications Copyright (C) 2000 Russell King
+ * NDS32 modifications Copyright (C) 2007 Harry Pan
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+/* ============================================================================
+ * Copyright (C) 2007 Andes Technology Corporation
+ * This file is part of Linux and should be licensed under the GPL.
+ * See the file COPYING for conditions for redistribution.
+ *
+ * Abstract:
+ *
+ * This program is for Andes NDS32 architecture.
+ *
+ * Revision History:
+ *
+ * Jul.31.2007 Initial ported by Tom, Shawn, and Steven,
+ * revised by Harry.
+ * Current implmentation is based on Andes Instruction
+ * Set Architecture Specification (AS-0001-0001)
+ * version:3.7 date:7-20-2007.
+ * It is original taken from ARM, then fit to NDS32.
+ * Aug.15.2007 Mainly updated breakpoint handling base on NDS32 ISA.
+ * I also did code revise.
+ * Nov.14.2007 Fixed up ptrace_set_bpt() while handling 16-bit insn.
+ * Nov.27.2007 Added checking duplicate breakpoints in
+ * add_breakpoint(), based on Shawn's idea.
+ * Dec.06.2007 Added get_user_gpr().
+ * Apr.17.2009 Added support for FPU and Audio regs.
+ * Added support for PTRACE_GETFPREGS, PTRACE_SETFPREGS,
+ * PTRACE_GETAUREGS, PTRACE_SETAUREGS
+ *
+ * Note:
+ *
+ * Current layout: 0-31 GR, 32-34 SPR, 35-... SR, index start from zero.
+ *
+ * +----------+-----+--------------+---+--------+
+ * | GR | SPR | SR |...| Audio |
+ * +----------+-----+--------------+---+--------+
+ * 0 32 35 ...500 531
+ *
+ * ============================================================================
+ */
+#include <linux/kernel.h>
+#include <linux/sched.h>
+#include <linux/mm.h>
+#include <linux/smp.h>
+#include <linux/ptrace.h>
+#include <linux/user.h>
+#include <linux/security.h>
+#include <linux/init.h>
+
+#include <asm/uaccess.h>
+#include <asm/pgtable.h>
+#include <asm/system.h>
+#include <asm/traps.h>
+#include <asm/fpu.h>
+#include <asm/audio.h>
+
+#include "ptrace.h"
+
+#ifdef __NDS32_EL__
+#define BREAKINST 0x01EA
+#else
+#define BREAKINST 0xEA01
+#endif
+
+/* get_user_reg()
+ *
+ * This routine will get a word off of the processes privileged stack.
+ * the offset is how far from the base addr as stored in the THREAD.
+ * this routine assumes that all the privileged stacks are in our
+ * data space.
+ */
+static inline unsigned int get_user_reg(struct task_struct *task, int offset)
+{
+ return task_pt_regs(task)->uregs[offset];
+}
+
+#if !defined(CONFIG_HSS)
+/* get_user_gpr()
+ *
+ */
+static unsigned int get_user_gpr(struct task_struct *task, int idx)
+{
+ unsigned int ret;
+
+ if (idx < 26) // r0 to r25
+ ret = get_user_reg(task, idx + 13);
+ else if (idx == 26 || idx == 27) // p0, p1
+ ret = get_user_reg(task, idx - 26 + 7);
+ else if (idx > 27 && idx < 31) // fp, gp, lp
+ ret = get_user_reg(task, idx + 11);
+ else if (idx == 31) // sp
+ ret = get_user_reg(task, 3);
+ else
+ ret = 0;
+
+ return ret;
+}
+#endif
+
+/* put_user_reg()
+ *
+ * this routine will put a word on the processes privileged stack.
+ * the offset is how far from the base addr as stored in the THREAD.
+ * this routine assumes that all the privileged stacks are in our
+ * data space.
+ */
+static inline int put_user_reg(struct task_struct *task, int offset, long data)
+{
+ struct pt_regs newregs, *regs = task_pt_regs(task);
+ int ret = -EINVAL;
+
+ newregs = *regs;
+ newregs.uregs[offset] = data;
+
+ if (valid_user_regs(&newregs)) {
+ regs->uregs[offset] = data;
+ ret = 0;
+ }
+
+ return ret;
+}
+
+#if !defined(CONFIG_HSS)
+/*
+ * Read instruction.
+ */
+static inline int
+read_insn(struct task_struct *task, unsigned long addr, u32 * res)
+{
+ int ret;
+ *res = 0;
+ ret = access_process_vm(task, addr, res, 2, 0);
+ if (ret != 2)
+ return 0;
+#ifdef __NDS32_EL__
+ *res = swab16(*res);
+#endif
+ if ((*res) & 0x8000)
+ return 2;
+
+ ret = access_process_vm(task, addr, res, 4, 0);
+ if (ret != 4)
+ return 0;
+#ifdef __NDS32_EL__
+ *res = swab32(*res);
+#endif
+ return 4;
+}
+
+/* get_branch_address()
+ *
+ * Decode branch instructions and destination.
+ */
+static unsigned long
+get_branch_address(struct task_struct *child,
+ unsigned long pc, unsigned long insn, unsigned int size)
+{
+ unsigned int tpc = 0;
+
+ /*
+ * TODO: COLE
+ * would it be simpler if we use two BREAKs,
+ * one for take, one for not
+ */
+
+ if (size == 4) {
+ /* 32-bit instruction */
+ if ((insn & 0x7e000000) == 0x4c000000) // BR1
+ {
+ int cond, imm14s;
+ unsigned int rt, ra;
+
+ rt = (insn >> 20) & 0x1f;
+ ra = (insn >> 15) & 0x1f;
+ cond = (insn >> 14) & 0x01;
+ imm14s = insn & 0x00003fff;
+
+ if (imm14s & 0x00002000) // sign extend
+ imm14s -= (0x00002000 << 1);
+
+ rt = get_user_gpr(child, rt);
+ ra = get_user_gpr(child, ra);
+
+ if (((cond == 1) && (rt != ra)) || // bne
+ ((cond == 0) && (rt == ra))) // beq
+ tpc = pc + (imm14s << 1);
+ } else if ((insn & 0x7e000000) == 0x4e000000) // BR2
+ {
+ int cond, imm16s, taken = 0;
+ int rt;
+
+ rt = (insn >> 20) & 0x1f;
+ cond = (insn >> 16) & 0x0f;
+ imm16s = insn & 0x0000ffff;
+
+ if (imm16s & 0x00008000) // sign extend
+ imm16s -= (0x00008000 << 1);
+
+ rt = get_user_gpr(child, rt);
+
+ switch (cond) {
+ case 0x02: // beqz
+ if (rt == 0)
+ taken = 1;
+ break;
+ case 0x03: // bnez
+ if (rt != 0)
+ taken = 1;
+ break;
+ case 0x06: // bgtz
+ if (rt > 0)
+ taken = 1;
+ break;
+ case 0x07: // blez
+ if (rt <= 0)
+ taken = 1;
+ break;
+ case 0x04: // bgez
+ case 0x0c: // bgezal
+ if (rt >= 0)
+ taken = 1;
+ break;
+ case 0x05: // bltz
+ case 0x0d: // bltzal
+ if (rt < 0)
+ taken = 1;
+ break;
+ default:
+ printk(KERN_WARNING
+ "ptrace: unknown conditional branch.\n");
+ break;
+ }
+
+ if (taken)
+ tpc = pc + (imm16s << 1);
+ } else if ((insn & 0x7e000000) == 0x48000000) // JI
+ {
+ int imm24s;
+
+ imm24s = insn & 0x00ffffff;
+
+ if (imm24s & 0x00800000) // sign extend
+ imm24s -= (0x00800000 << 1);
+
+ tpc = pc + (imm24s << 1);
+ } else if ((insn & 0x7e000000) == 0x4a000000) // JREG
+ {
+ unsigned int rb = (insn >> 10) & 0x1f;
+
+ tpc = get_user_gpr(child, rb);
+ }
+
+ } else {
+ /* 16-bit instruction */
+
+ if ((insn & 0xf800) == 0xc000) // beqz38
+ {
+ unsigned int rt3;
+
+ rt3 = (insn >> 8) & 0x07;
+
+ rt3 = get_user_gpr(child, rt3);
+
+ if (rt3 == 0) {
+ int imm8s;
+
+ imm8s = insn & 0x00ff;
+
+ if (imm8s & 0x0080) // sign extend
+ imm8s -= (0x0080 << 1);
+
+ tpc = pc + (imm8s << 1);
+ }
+ }
+
+ if ((insn & 0xf800) == 0xc800) // bnez38
+ {
+ unsigned int rt3;
+
+ rt3 = (insn >> 8) & 0x07;
+
+ rt3 = get_user_gpr(child, rt3);
+
+ if (rt3 != 0) {
+ int imm8s;
+
+ imm8s = insn & 0x00ff;
+
+ if (imm8s & 0x0080) // sign extend
+ imm8s -= (0x0080 << 1);
+
+ tpc = pc + (imm8s << 1);
+ }
+ }
+
+ if ((insn & 0xf800) == 0xd000) // beqs38, j8
+ {
+ unsigned int rt3, r5;
+
+ rt3 = (insn >> 8) & 0x07;
+
+ rt3 = get_user_gpr(child, rt3);
+ r5 = get_user_gpr(child, 5);
+
+ if (r5 == rt3) {
+ int imm8s;
+ imm8s = insn & 0x00ff;
+
+ if (imm8s & 0x0080) // sign extend
+ imm8s -= (0x0080 << 1);
+
+ tpc = pc + (imm8s << 1);
+ }
+ }
+
+ if ((insn & 0xf800) == 0xd800) // bnes38
+ {
+ unsigned int rt3, r5;
+
+ rt3 = (insn >> 8) & 0x07;
+
+ r5 = get_user_gpr(child, 5);
+ rt3 = get_user_gpr(child, rt3);
+
+ if (r5 != rt3) {
+ int imm8s;
+
+ imm8s = insn & 0x00ff;
+
+ if (imm8s & 0x0080) // sign extend
+ imm8s -= (0x0080 << 1);
+
+ tpc = pc + (imm8s << 1);
+ }
+ }
+
+ if ((insn & 0xffe0) == 0xdd00 || // jr5
+ (insn & 0xffe0) == 0xdd80 || // ret5
+ (insn & 0xffe0) == 0xdd20) // jral5
+ {
+ unsigned int rb5;
+
+ rb5 = insn & 0x1f;
+
+ tpc = get_user_gpr(child, rb5);
+ }
+
+ if ((insn & 0xfe00) == 0xe800) {
+ int taken = 0;
+ unsigned int r15;
+
+ r15 = get_user_gpr(child, 15);
+
+ if (insn & 0x0100) // bnezs8
+ {
+ if (r15 != 0)
+ taken = 1;
+ } else // beqzs8
+ {
+ if (r15 == 0)
+ taken = 1;
+ }
+
+ if (taken) {
+ int imm8s;
+
+ imm8s = insn & 0x00ff;
+
+ if (imm8s & 0x0080) // sign extend
+ imm8s -= (0x0080 << 1);
+
+ tpc = pc + (imm8s << 1);
+ }
+ }
+ }
+
+ return tpc;
+}
+
+/*
+ * Swap instructions in the user program.
+ * swap in new_insn. save orignal value in old_insn
+ * assume new_insn is 2-bytes long
+ */
+static int
+swap_insn(struct task_struct *task, unsigned long addr,
+ u16 * old_insn, u16 * new_insn)
+{
+ int ret;
+
+ ret = access_process_vm(task, addr, old_insn, 2, 0);
+ if (ret == 2)
+ ret = access_process_vm(task, addr, new_insn, 2, 1);
+
+ return ret;
+}
+
+/*
+ * Add one breakpoint in the user program.
+ */
+static void
+add_breakpoint(struct task_struct *task, struct debug_info *dbg,
+ unsigned long addr)
+{
+ u16 new_insn = BREAKINST;
+ int res;
+
+ if (dbg->valid) {
+ printk(KERN_ERR "ptrace: too many breakpoints\n");
+ return;
+ }
+
+ dbg->address = addr;
+ res = swap_insn(task, addr, &dbg->insn, &new_insn);
+ if (res == 2)
+ dbg->valid = 1;
+ if (!dbg->valid)
+ printk(KERN_ERR "ptrace: fail to add breakpoint\n");
+}
+
+/*
+ * Clear one software breakpoint in the user program.
+ */
+static void clear_breakpoint(struct task_struct *task, struct debug_info *dbg)
+{
+ int ret;
+ unsigned int addr = dbg->address;
+ u16 old_insn;
+
+ if (!dbg->valid) {
+ return;
+ }
+ dbg->valid = 0;
+
+ ret = swap_insn(task, addr, &old_insn, &dbg->insn);
+
+ if (ret != 2 || old_insn != BREAKINST) {
+ printk(KERN_ERR "ptrace: %s:%d: corrupted NDS16 breakpoint at "
+ "0x%08x (0x%04x)\n", task->comm, task->pid,
+ addr, old_insn);
+ }
+}
+
+/*
+ * ptrace_set_swbk
+ * Set breakpoint in user program.
+ */
+void ptrace_set_swbk(struct task_struct *child)
+{
+ struct pt_regs *regs;
+ unsigned long pc;
+ unsigned int size;
+ u32 insn;
+
+ /*
+ * always clear before set,
+ * since in some sepcial case, it may fail to hit
+ */
+ ptrace_cancel_swbk(child);
+ regs = task_pt_regs(child);
+ pc = instruction_pointer(regs);
+ size = read_insn(child, pc, &insn);
+
+ printk(KERN_DEBUG " STEP.size=%d\n", size);
+
+ if (size > 0) {
+ struct debug_info *dbg = &child->thread.debug;
+ unsigned int tpc;
+
+ /* Predict next PC. */
+ tpc = get_branch_address(child, pc, insn, size);
+
+ if (tpc) {
+ printk(KERN_DEBUG " STEP.addr=0x%x\n", tpc);
+ add_breakpoint(child, dbg, tpc);
+ } else {
+ if (size == 4) {
+ printk(KERN_DEBUG " STEP.addr=0x%x\n",
+ (unsigned int)(pc + 4));
+ add_breakpoint(child, dbg, pc + 4);
+ } else if (size == 2) {
+ printk(KERN_DEBUG " STEP.addr=0x%x\n",
+ (unsigned int)(pc + 2));
+ add_breakpoint(child, dbg, pc + 2);
+ } else {
+ printk(KERN_ERR
+ "ptrace: bad step address, pc + %d\n",
+ size);
+ }
+ }
+ }
+}
+
+/*
+ * Ensure no single-step breakpoint is pending. Returns non-zero
+ * value if child was being single-stepped.
+ */
+void ptrace_cancel_swbk(struct task_struct *child)
+{
+ if (!child->thread.debug.valid) {
+ return;
+ }
+
+ clear_breakpoint(child, &child->thread.debug);
+}
+#endif /* end of !defined (CONFIG_HSS) */
+
+/*
+ * Called by kernel/ptrace.c when detaching..
+ *
+ * Make sure the single step bit is not set.
+ */
+void ptrace_disable(struct task_struct *child)
+{
+ user_disable_single_step(child);
+}
+
+/*
+ * Handle hitting a breakpoint.
+ */
+void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
+ int error_code, int si_code)
+{
+ struct siginfo info;
+
+#if !defined (CONFIG_HSS)
+ /* clear the swbk; otherwise the user will see it */
+ ptrace_cancel_swbk(tsk);
+#endif
+
+ tsk->thread.trap_no = 1;
+ tsk->thread.error_code = error_code;
+
+ memset(&info, 0, sizeof(info));
+ info.si_signo = SIGTRAP;
+ info.si_code = si_code;
+
+ info.si_addr = (void __user *)instruction_pointer(regs);
+
+ /* Send us the fake SIGTRAP */
+ force_sig_info(SIGTRAP, &info, tsk);
+}
+
+/* ptrace_read_user()
+ *
+ * Read the word at offset "off" into the "struct user". We
+ * actually access the pt_regs stored on the kernel stack.
+ */
+static int
+ptrace_read_user(struct task_struct *tsk, unsigned long off,
+ unsigned long __user * ret)
+{
+ unsigned long tmp = 0;
+
+ if (off < 500) {
+ if (off & 3 || off >= sizeof(struct user))
+ return -EIO;
+
+ if (off < sizeof(struct pt_regs))
+ tmp = get_user_reg(tsk, off >> 2);
+
+ return put_user(tmp, ret);
+ } else if (off < 532) {
+#ifdef CONFIG_AUDIO
+ off -= 500;
+ if (test_tsk_thread_flag(tsk, TIF_USEDAUDIO)) {
+#ifdef CONFIG_UNLAZY_AUDIO
+ unlazy_audio(tsk);
+#else
+ preempt_disable();
+ if (last_task_used_audio == tsk)
+ save_audio(tsk);
+ preempt_enable();
+#endif
+ tmp = tsk->thread.audio.auregs[off];
+ }
+#endif
+ return put_user(tmp, ret);
+ } else
+ return -EIO;
+}
+
+/* ptrace_write_user()
+ *
+ * Write the word at offset "off" into "struct user". We
+ * actually access the pt_regs stored on the kernel stack.
+ */
+static int
+ptrace_write_user(struct task_struct *tsk, unsigned long off, unsigned long val)
+{
+ if (off < 500) {
+ if (off & 3 || off >= sizeof(struct user))
+ return -EIO;
+
+ if (off >= sizeof(struct pt_regs))
+ return 0;
+
+ return put_user_reg(tsk, off >> 2, val);
+ } else if (off < 532) {
+#ifdef CONFIG_AUDIO
+ off -= 500;
+ if (!test_tsk_thread_flag(tsk, TIF_USEDAUDIO)) {
+ /* First time Audio user. */
+ memset(&tsk->thread.audio, 0,
+ sizeof(struct audio_struct));
+ set_tsk_thread_flag(tsk, TIF_USEDAUDIO);
+ } else {
+#ifdef CONFIG_UNLAZY_AUDIO
+ unlazy_audio(tsk);
+#else
+ if (last_task_used_audio == tsk) {
+ preempt_disable();
+ save_audio(tsk);
+ preempt_enable();
+ }
+#endif
+ /* Let the lazy mechanism do the restore. */
+ clear_audio(task_pt_regs(tsk));
+ }
+ tsk->thread.audio.auregs[off] = val;
+#endif
+ return 0;
+ } else
+ return -EIO;
+}
+
+/* ptrace_getregs()
+ *
+ * Get all user integer registers.
+ */
+static int ptrace_getregs(struct task_struct *tsk, void __user * uregs)
+{
+ struct pt_regs *regs = task_pt_regs(tsk);
+
+ return copy_to_user(uregs, regs, sizeof(struct pt_regs)) ? -EFAULT : 0;
+}
+
+/* ptrace_setregs()
+ *
+ * Set all user integer registers.
+ */
+static int ptrace_setregs(struct task_struct *tsk, void __user * uregs)
+{
+ struct pt_regs newregs;
+ int ret;
+
+ ret = -EFAULT;
+ if (copy_from_user(&newregs, uregs, sizeof(struct pt_regs)) == 0) {
+ struct pt_regs *regs = task_pt_regs(tsk);
+
+ ret = -EINVAL;
+ if (valid_user_regs(&newregs)) {
+ *regs = newregs;
+ ret = 0;
+ }
+ }
+
+ return ret;
+}
+
+/* ptrace_getfpregs()
+ *
+ * Get the child FPU state.
+ */
+static int ptrace_getfpregs(struct task_struct *tsk, void __user * ufpregs)
+{
+#ifdef CONFIG_FPU
+ if (used_math()) {
+# ifdef CONFIG_UNLAZY_FPU
+ unlazy_fpu(tsk);
+# else
+ preempt_disable();
+ if (last_task_used_math == tsk)
+ save_fpu(tsk);
+ preempt_enable();
+# endif
+ return copy_to_user(ufpregs, &tsk->thread.fpu,
+ sizeof(struct fpu_struct)) ? -EFAULT : 0;
+ } else {
+ /* First time FPU user. */
+ memset(ufpregs, -1, sizeof(struct fpu_struct));
+ return 0;
+ }
+
+#else
+ return -EFAULT;
+#endif
+}
+
+/*
+ * Set the child FPU state.
+ */
+static int ptrace_setfpregs(struct task_struct *tsk, void __user * ufpregs)
+{
+#ifdef CONFIG_FPU
+ int ret;
+
+# ifndef CONFIG_UNLAZY_FPU
+ if (last_task_used_math == tsk)
+# endif
+ clear_fpu(task_pt_regs(tsk));
+
+ ret =
+ copy_from_user(&tsk->thread.fpu, ufpregs,
+ sizeof(struct fpu_struct)) ? -EFAULT : 0;
+
+ if (!ret && !used_math()) {
+ /* First time Audio user. */
+ set_used_math();
+ }
+
+ return ret;
+#else
+ return -EFAULT;
+#endif
+}
+
+/* ptrace_getauregs()
+ *
+ * Get the child Audio state.
+ */
+static int ptrace_getauregs(struct task_struct *tsk, void __user * uauregs)
+{
+#ifdef CONFIG_AUDIO
+ if (test_tsk_thread_flag(tsk, TIF_USEDAUDIO)) {
+#ifdef CONFIG_UNLAZY_AUDIO
+ unlazy_audio(tsk);
+#else
+ preempt_disable();
+ if (last_task_used_audio == tsk)
+ save_audio(tsk);
+ preempt_enable();
+#endif
+ return copy_to_user(uauregs, &tsk->thread.audio,
+ sizeof(struct audio_struct)) ? -EFAULT : 0;
+ } else {
+ /* First time Audio user. */
+ memset(uauregs, 0, sizeof(struct audio_struct));
+ return 0;
+ }
+
+#else
+ return -EFAULT;
+#endif
+}
+
+/*
+ * Set the child Audio state.
+ */
+static int ptrace_setauregs(struct task_struct *tsk, void __user * uauregs)
+{
+#ifdef CONFIG_AUDIO
+ int ret;
+
+#ifdef CONFIG_UNLAZY_AUDIO
+ clear_audio(task_pt_regs(tsk));
+#else
+ if (last_task_used_audio == tsk)
+ clear_audio(task_pt_regs(tsk));
+#endif
+ ret =
+ copy_from_user(&tsk->thread.audio, uauregs,
+ sizeof(struct audio_struct)) ? -EFAULT : 0;
+
+ if (!ret && !test_tsk_thread_flag(tsk, TIF_USEDAUDIO)) {
+ /* First time Audio user. */
+ set_tsk_thread_flag(tsk, TIF_USEDAUDIO);
+ }
+
+ return ret;
+#else
+ return -EFAULT;
+#endif
+}
+
+/* do_ptrace()
+ *
+ * Provide ptrace defined service.
+ */
+long arch_ptrace(struct task_struct *child, long request, unsigned long addr,
+ unsigned long data)
+{
+ int ret;
+
+ switch (request) {
+ case PTRACE_PEEKUSR:
+ ret =
+ ptrace_read_user(child, addr, (unsigned long __user *)data);
+ break;
+
+ case PTRACE_POKEUSR:
+ ret = ptrace_write_user(child, addr, data);
+ break;
+
+ case PTRACE_GETREGS:
+ ret = ptrace_getregs(child, (void __user *)data);
+ break;
+
+ case PTRACE_SETREGS:
+ ret = ptrace_setregs(child, (void __user *)data);
+ break;
+
+ case PTRACE_GETFPREGS:
+ ret = ptrace_getfpregs(child, (void __user *)data);
+ break;
+
+ case PTRACE_SETAUREGS:
+ ret = ptrace_setauregs(child, (void __user *)data);
+ break;
+
+ case PTRACE_GETAUREGS:
+ ret = ptrace_getauregs(child, (void __user *)data);
+ break;
+
+ case PTRACE_SETFPREGS:
+ ret = ptrace_setfpregs(child, (void __user *)data);
+ break;
+/*
+ case PTRACE_GET_THREAD_AREA:
+ ret = put_user(task_thread_info(child)->tp_value,
+ (unsigned long __user *) data);
+ break;
+*/
+
+ default:
+ ret = ptrace_request(child, request, addr, data);
+ break;
+ }
+
+ return ret;
+}
+
+void user_enable_single_step(struct task_struct *child)
+{
+ struct pt_regs *regs;
+ regs = task_pt_regs(child);
+#ifdef CONFIG_HSS
+ regs->NDS32_ipsw |= PSW_mskHSS;
+#else
+ ptrace_set_swbk(child);
+#endif
+ set_tsk_thread_flag(child, TIF_SINGLESTEP);
+}
+
+void user_disable_single_step(struct task_struct *child)
+{
+ struct pt_regs *regs;
+ regs = task_pt_regs(child);
+#ifdef CONFIG_HSS
+ regs->NDS32_ipsw &= ~PSW_mskHSS;
+#else
+ ptrace_cancel_swbk(child);
+#endif
+ clear_tsk_thread_flag(child, TIF_SINGLESTEP);
+}
+
+/* sys_trace()
+ *
+ * syscall trace handler.
+ */
+static inline void do_syscall_trace(void)
+{
+ if (!test_thread_flag(TIF_SYSCALL_TRACE))
+ return;
+ if (!(current->ptrace & PT_PTRACED))
+ return;
+
+ /* the 0x80 provides a way for the tracing parent to distinguish
+ between a syscall stop and SIGTRAP delivery */
+ ptrace_notify(SIGTRAP | ((current->ptrace & PT_TRACESYSGOOD)
+ ? 0x80 : 0));
+ /*
+ * this isn't the same as continuing with a signal, but it will do
+ * for normal use. strace only continues with a signal if the
+ * stopping signal is not SIGTRAP. -brl
+ */
+ if (current->exit_code) {
+ send_sig(current->exit_code, current, 1);
+ current->exit_code = 0;
+ }
+}
+
+asmlinkage int syscall_trace_enter(int syscall, struct pt_regs *regs)
+{
+ int orig_r0;
+
+ orig_r0 = regs->NDS32_ORIG_r0;
+ regs->NDS32_ORIG_r0 = syscall;
+ do_syscall_trace();
+ syscall = regs->NDS32_ORIG_r0;
+ regs->NDS32_ORIG_r0 = orig_r0;
+ return syscall & 0xfff;
+}
+
+asmlinkage void syscall_trace_leave(struct pt_regs *regs)
+{
+ do_syscall_trace();
+
+ /* synthsize a single-step */
+#if !defined(CONFIG_HSS)
+ /* for SWBK, break should be remove */
+ ptrace_cancel_swbk(current);
+#endif
+ if (test_thread_flag(TIF_SINGLESTEP)) {
+ printk(KERN_INFO "synthsize trap (tf=0x%0x\n",
+ (unsigned int)current_thread_info()->flags);
+ send_sigtrap(current, regs, 0, TRAP_BRKPT);
+ }
+}
diff -Nur linux-3.4.113.orig/arch/nds32/kernel/ptrace.h linux-3.4.113/arch/nds32/kernel/ptrace.h
--- linux-3.4.113.orig/arch/nds32/kernel/ptrace.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/kernel/ptrace.h 2016-12-01 20:59:24.356612904 +0100
@@ -0,0 +1,48 @@
+/*
+ * linux/arch/nds32/kernel/ptrace.h
+ */
+/* Copyright (C) 2000-2003 Russell King
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+/* ============================================================================
+ * Copyright (C) 2007 Andes Technology Corporation
+ * This file is part of Linux and should be licensed under the GPL.
+ * See the file COPYING for conditions for redistribution.
+ *
+ * Abstract:
+ *
+ * This program is for Andes NDS32 architecture.
+ *
+ * Revision History:
+ *
+ * Jul.31.2007 Initial ported by Tom, Shawn, and Steven,
+ * revised by Harry.
+ * Current implmentation is based on Andes Instruction
+ * Set Architecture Specification (AS-0001-0001)
+ * version:3.7 date:7-20-2007.
+ * It is original taken from ARM, then fit to NDS32.
+ *
+ * Note:
+ *
+ * Current layout: 0-31 GR, 32-34 SPR, 35-... SR, index start from zero.
+ *
+ * +----------+-----+--------------+
+ * | GR | SPR | SR |
+ * +-------------------------------+
+ * 0 32 35 ...
+ *
+ * ============================================================================
+ */
+#ifndef __KERNEL_PTRACE_H__
+#define __KERNEL_PTRACE_H__
+
+extern void ptrace_cancel_swbk(struct task_struct *);
+extern void ptrace_set_swbk(struct task_struct *);
+extern void ptrace_break(struct task_struct *, struct pt_regs *);
+extern void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
+ int error_code, int si_code);
+
+#endif // __KERNEL_PTRACE_H__
diff -Nur linux-3.4.113.orig/arch/nds32/kernel/relocate_kernel.S linux-3.4.113/arch/nds32/kernel/relocate_kernel.S
--- linux-3.4.113.orig/arch/nds32/kernel/relocate_kernel.S 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/kernel/relocate_kernel.S 2016-12-01 20:59:24.356612904 +0100
@@ -0,0 +1,89 @@
+/*
+ * relocate_kernel.S - put the kernel image in place to boot
+ */
+
+#include <asm/kexec.h>
+
+ .globl relocate_new_kernel
+relocate_new_kernel:
+ la $r0, kexec_indirection_page
+ slli $r0, $r0, 2
+ srli $r0, $r0, 2
+ lwi $r0, [$r0]
+ la $r1, kexec_start_address
+ slli $r1, $r1, 2
+ srli $r1, $r1, 2
+ lwi $r1, [$r1]
+
+0: /* top, read another word for the indirection page */
+ lwi.bi $r3, [$r0], #4
+
+ /* Is it a destination page. Put destination address to r4 */
+ andi $p0, $r3, #1
+ beqz $p0, 1f
+ li $p0, ~#1
+ and $r4, $r3, $p0
+ b 0b
+1:
+ /* Is it an indirection page */
+ andi $p0, $r3, #2
+ beqz $p0, 1f
+ li $p0, ~#2
+ and $r0, $r3, $p0
+ b 0b
+1:
+ /* are we done ? */
+ andi $p0, $r3, #4
+ beqz $p0, 1f
+ b 2f
+1:
+ /* is it source ? */
+ andi $p0, $r3, #8
+ beqz $p0, 0b
+ li $p0, ~#8
+ and $r3, $r3, $p0
+ li $r6, #(1024/16) /* 16 words per loop */
+9:
+ lmw.bim $r7, [$r3], $r22
+ smw.bim $r7, [$r4], $r22
+ addi $r6, $r6, -1
+ bnez $r6, 9b
+ b 0b
+2:
+ /* Jump to relocated kernel */
+ move $lp, $r1
+ li $r0, 0
+ la $r1, kexec_mach_type
+ slli $r1, $r1, 2
+ srli $r1, $r1, 2
+ lwi $r1, [$r1]
+ la $r2, kexec_boot_atags
+ slli $r2, $r2, 2
+ srli $r2, $r2, 2
+ lwi $r2, [$r2]
+ ret
+
+ .globl kexec_start_address
+kexec_start_address:
+ .long 0x0
+
+ .globl kexec_indirection_page
+kexec_indirection_page:
+ .long 0x0
+
+ .globl kexec_mach_type
+kexec_mach_type:
+ .long 0x0
+
+ /* phy addr of the atags for the new kernel */
+ .globl kexec_boot_atags
+kexec_boot_atags:
+ .long 0x0
+
+relocate_new_kernel_end:
+
+ .globl relocate_new_kernel_size
+relocate_new_kernel_size:
+ .long relocate_new_kernel_end - relocate_new_kernel
+
+
diff -Nur linux-3.4.113.orig/arch/nds32/kernel/setup.c linux-3.4.113/arch/nds32/kernel/setup.c
--- linux-3.4.113.orig/arch/nds32/kernel/setup.c 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/kernel/setup.c 2016-12-01 20:59:24.356612904 +0100
@@ -0,0 +1,1049 @@
+/*
+ * linux/arch/nds32/kernel/setup.c
+ *
+ * Copyright (C) 1995-2001 Russell King
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+/* ============================================================================
+ * Copyright (C) 2007 Andes Technology Corporation
+ * This file is part of Linux and should be licensed under the GPL.
+ * See the file COPYING for conditions for redistribution.
+ *
+ * Abstract:
+ *
+ * This program is for Andes NDS32 architecture.
+ *
+ * Revision History:
+ *
+ * Jul.05.2007 Initial ported by Tom, revised and patched for KGDB
+ * by Harry.
+ * Aug.26.2008 Some reworks on CPU info output for SMP.
+ *
+ * Note:
+ *
+ * ============================================================================
+ */
+#include <linux/module.h>
+#include <linux/ioport.h>
+#include <linux/delay.h>
+#include <linux/utsname.h>
+#include <linux/initrd.h>
+#include <linux/console.h>
+#include <linux/bootmem.h>
+#include <linux/seq_file.h>
+#include <linux/screen_info.h>
+#include <linux/root_dev.h>
+#include <linux/cpu.h>
+#include <linux/fs.h>
+#include <linux/memblock.h>
+#include <asm/cpu.h>
+#include <asm/setup.h>
+#include <asm/mach-types.h>
+#include <asm/cacheflush.h>
+#include <asm/mach/arch.h>
+#include <asm/mach/time.h>
+#include <asm/cpuver.h>
+#include <asm/procinfo.h>
+#include <asm/traps.h>
+#include <asm/fpu.h>
+#include <asm/cache_info.h>
+#include <nds32_intrinsic.h>
+
+#ifndef MEM_SIZE
+#define MEM_SIZE CONFIG_SDRAM_SIZE
+#endif
+
+#ifndef RAMDISK_SIZE
+#define RAMDISK_SIZE CONFIG_BLK_DEV_RAM_SIZE
+#endif
+
+extern void (*init_arch_irq) (void);
+
+extern void paging_init(struct machine_desc *desc);
+extern void reboot_setup(char *str);
+extern int root_mountflags;
+extern unsigned long _stext, _text, _etext, _sdata, _edata, _end;
+extern unsigned int ag101_cpufreq_get(unsigned int dummy);
+
+unsigned long cpu_id, cpu_rev, cpu_cfgid;
+char *endianness = NULL;
+
+unsigned int __machine_arch_type;
+EXPORT_SYMBOL(__machine_arch_type);
+
+unsigned int elf_hwcap;
+EXPORT_SYMBOL(elf_hwcap);
+
+unsigned char aux_device_present;
+
+char elf_platform[ELF_PLATFORM_SIZE];
+EXPORT_SYMBOL(elf_platform);
+
+unsigned long phys_initrd_start __initdata = 0;
+unsigned long phys_initrd_size __initdata = 0;
+
+static struct meminfo meminfo __initdata = { 0, };
+
+static const char *machine_name;
+static struct proc_info_item proc_info;
+static char command_line[COMMAND_LINE_SIZE];
+
+struct machine_desc *machine_desc __initdata;
+
+static char default_command_line[COMMAND_LINE_SIZE] __initdata = CONFIG_CMDLINE;
+
+DEFINE_PER_CPU(struct cpuinfo_nds32, cpu_data);
+
+/*
+ * Standard memory resources
+ */
+static struct resource mem_res[] = {
+ {
+ .name = "Video RAM",
+ .start = 0,
+ .end = 0,
+ .flags = IORESOURCE_MEM},
+ {
+ .name = "Kernel text",
+ .start = 0,
+ .end = 0,
+ .flags = IORESOURCE_MEM},
+ {
+ .name = "Kernel data",
+ .start = 0,
+ .end = 0,
+ .flags = IORESOURCE_MEM}
+};
+
+#define video_ram mem_res[0]
+#define kernel_code mem_res[1]
+#define kernel_data mem_res[2]
+
+static struct resource io_res[] = {
+ {
+ .name = "reserved",
+ .start = 0x3bc,
+ .end = 0x3be,
+ .flags = IORESOURCE_IO | IORESOURCE_BUSY},
+ {
+ .name = "reserved",
+ .start = 0x378,
+ .end = 0x37f,
+ .flags = IORESOURCE_IO | IORESOURCE_BUSY},
+ {
+ .name = "reserved",
+ .start = 0x278,
+ .end = 0x27f,
+ .flags = IORESOURCE_IO | IORESOURCE_BUSY}
+};
+
+#define lp0 io_res[0]
+#define lp1 io_res[1]
+#define lp2 io_res[2]
+
+/*
+ * The following string table, must sync with HWCAP_xx bitmask,
+ * which is defined in <asm/procinfo.h>
+ */
+static const char *hwcap_str[] = {
+ "mfusr_pc",
+ "perf1",
+ "perf2",
+ "fpu",
+ "audio",
+ "16b",
+ "string",
+ "reduced_regs",
+ "video",
+ "encrypt",
+ "edm",
+ "lmdma",
+ "pfm",
+ "hsmp",
+ "trace",
+ "div",
+ "mac",
+ "l2c",
+ "dx_regs",
+ "v2",
+ NULL,
+};
+
+static void __init squash_mem_tags(struct tag *tag)
+{
+ for (; tag->hdr.size; tag = tag_next(tag))
+ if (tag->hdr.tag == ATAG_MEM)
+ tag->hdr.tag = ATAG_NONE;
+}
+
+struct cache_info L1_cache_info[2];
+
+static void __init dump_cpu_info(int cpu)
+{
+ int i = 0, aliasing_num;
+#ifdef CONFIG_CACHE_L2
+ unsigned long l2set, l2way, l2clsz;
+#endif
+ printk("CPU%d Features: ", cpu);
+
+ for (i = 0; hwcap_str[i]; i++) {
+ if (elf_hwcap & (1 << i))
+ printk("%s ", hwcap_str[i]);
+ }
+
+ printk("\n");
+
+ L1_cache_info[ICACHE].cache_type = ICACHE;
+ L1_cache_info[ICACHE].ways = CACHE_WAY(ICACHE);
+ L1_cache_info[ICACHE].way_bits = ilog2(CACHE_WAY(ICACHE));
+ L1_cache_info[ICACHE].line_size = CACHE_LINE_SIZE(ICACHE);
+ L1_cache_info[ICACHE].line_bits = ilog2(CACHE_LINE_SIZE(ICACHE));
+ L1_cache_info[ICACHE].sets = CACHE_SET(ICACHE);
+ L1_cache_info[ICACHE].set_bits = ilog2(CACHE_SET(ICACHE));
+ L1_cache_info[ICACHE].size =
+ CACHE_SET(ICACHE) * CACHE_WAY(ICACHE) * CACHE_LINE_SIZE(ICACHE) /
+ 1024;
+ printk("L1I:%dKB/%dS/%dW/%dB\n", L1_cache_info[ICACHE].size,
+ L1_cache_info[ICACHE].sets, L1_cache_info[ICACHE].ways,
+ L1_cache_info[ICACHE].line_size);
+ aliasing_num =
+ L1_cache_info[ICACHE].size * 1024 / PAGE_SIZE /
+ L1_cache_info[ICACHE].ways;
+ if (aliasing_num & 1 && aliasing_num != 1)
+ printk
+ ("%s: not alising:%d, it should be multiple of 2 if it ia aliasing cache.\n",
+ __func__, aliasing_num);
+ L1_cache_info[ICACHE].aliasing_num = aliasing_num;
+ L1_cache_info[ICACHE].aliasing_mask = (aliasing_num - 1) << PAGE_SHIFT;
+ L1_cache_info[ICACHE].not_aliasing_mask =
+ ~L1_cache_info[ICACHE].aliasing_mask;
+ L1_cache_info[DCACHE].cache_type = DCACHE;
+ L1_cache_info[DCACHE].ways = CACHE_WAY(DCACHE);
+ L1_cache_info[DCACHE].way_bits = ilog2(CACHE_WAY(DCACHE));
+ L1_cache_info[DCACHE].line_size = CACHE_LINE_SIZE(DCACHE);
+ L1_cache_info[DCACHE].line_bits = ilog2(CACHE_LINE_SIZE(DCACHE));
+ L1_cache_info[DCACHE].sets = CACHE_SET(DCACHE);
+ L1_cache_info[DCACHE].set_bits = ilog2(CACHE_SET(DCACHE));
+ L1_cache_info[DCACHE].size =
+ CACHE_SET(DCACHE) * CACHE_WAY(DCACHE) * CACHE_LINE_SIZE(DCACHE) /
+ 1024;
+ printk("L1D:%dKB/%dS/%dW/%dB\n", L1_cache_info[DCACHE].size,
+ L1_cache_info[DCACHE].sets, L1_cache_info[DCACHE].ways,
+ L1_cache_info[DCACHE].line_size);
+ aliasing_num =
+ L1_cache_info[DCACHE].size * 1024 / PAGE_SIZE /
+ L1_cache_info[DCACHE].ways;
+#ifdef CONFIG_HIGHMEM
+ if (aliasing_num > 1 && CONFIG_HIGHMEM)
+ WARN(1,
+ "%s: HIGHMEM is not supported for alising VIPT cache. aliasing_num:%d\n",
+ __func__, aliasing_num);
+#else
+ if (aliasing_num & 1 && aliasing_num != 1)
+ printk
+ ("%s: not alising:%d, it should be multiple of 2 if it ia aliasing cache.\n",
+ __func__, aliasing_num);
+#endif
+ L1_cache_info[DCACHE].aliasing_num = aliasing_num;
+ L1_cache_info[DCACHE].aliasing_mask = (aliasing_num - 1) << PAGE_SHIFT;
+ L1_cache_info[DCACHE].not_aliasing_mask =
+ ~L1_cache_info[DCACHE].aliasing_mask;
+#ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
+ printk("L1 D-Cache is WRITE-THROUGH\n");
+#else
+ printk("L1 D-Cache is WRITE-BACK\n");
+#endif
+
+
+#ifdef CONFIG_CACHE_L2
+ /* Here translation is on but I/O address is not mapped yet. */
+ SET_PSW(GET_PSW() & ~PSW_mskDT);
+ DSB();
+ l2set =
+ 64 << ((inl(L2CC_PA_BASE + L2_CA_CONF_OFF) & L2_CA_CONF_mskL2SET) >>
+ L2_CA_CONF_offL2SET);
+ l2way =
+ 1 +
+ ((inl(L2CC_PA_BASE + L2_CA_CONF_OFF) & L2_CA_CONF_mskL2WAY) >>
+ L2_CA_CONF_offL2WAY);
+ l2clsz =
+ 4 << ((inl(L2CC_PA_BASE + L2_CA_CONF_OFF) & L2_CA_CONF_mskL2CLSZ) >>
+ L2_CA_CONF_offL2CLSZ);
+ SET_PSW(GET_PSW() | PSW_mskDT);
+ DSB();
+
+ printk("L2:%luKB/%luS/%luW/%luB\n",
+ l2set * l2way * l2clsz / 1024, l2set, l2way, l2clsz);
+#endif
+#ifdef CONFIG_FPU
+ /* Disable fpu and enable when it is used. */
+ disable_fpu();
+ printk("FPU is able to use.\n");
+#endif
+}
+
+static void __init setup_processor(void)
+{
+ unsigned long tmp = 0;
+ struct proc_info_list *list;
+ extern struct proc_info_list __proc_info_begin, __proc_info_end;
+
+ register unsigned coreid = GET_CPU_VER();
+ for (list = &__proc_info_begin; list < &__proc_info_end; list++)
+// if (list->cpu_val == (GET_CPU_VER() & CPU_VER_mskCPUID))
+ if (list->cpu_val == (coreid & list->cpu_mask))
+ break;
+ /*
+ * If the architecture type is not recognised, then we
+ * can co nothing...
+ */
+ if (list >= &__proc_info_end) {
+ printk
+ ("Processor configuration botched (CPU_VER 0x%lx), unable to continue.\n",
+ GET_CPU_VER());
+ while (1) ;
+ }
+
+ proc_info = *list->info;
+
+ cpu_dcache_inval_all(); // XXX head.S turn $$ on, need change.
+ cpu_icache_inval_all();
+ DSB();
+ ISB();
+
+ cpu_id = GET_CPU_ID();
+ cpu_rev = GET_CPU_REV();
+ cpu_cfgid = GET_CPU_CFGID();
+
+ printk("CPU: %s, %s %s, CPU_VER 0x%08lx(id %lu, rev %lu, cfg %lu)\n",
+ list->arch_name,
+ proc_info.manufacturer, proc_info.cpu_name,
+ GET_CPU_VER(), cpu_id, cpu_rev, cpu_cfgid);
+
+ elf_hwcap |= HWCAP_MFUSR_PC;
+
+ if (((GET_MSC_CFG() & MSC_CFG_mskBASEV) >> MSC_CFG_offBASEV) == 0) {
+ if (CPU_IS_N1213_43U1HA0() || CPU_IS_N1213_43U1HB0())
+ elf_hwcap &= ~HWCAP_MFUSR_PC;
+
+ if (GET_MSC_CFG() & MSC_CFG_mskDIV)
+ elf_hwcap |= HWCAP_DIV;
+
+ if ((GET_MSC_CFG() & MSC_CFG_mskMAC)
+ || (cpu_id == 12 && cpu_rev < 4))
+ elf_hwcap |= HWCAP_MAC;
+ } else {
+ elf_hwcap |= HWCAP_V2;
+ elf_hwcap |= HWCAP_DIV;
+ elf_hwcap |= HWCAP_MAC;
+ }
+
+ if (cpu_cfgid & 0x0001)
+ elf_hwcap |= HWCAP_EXT;
+
+ if (cpu_cfgid & 0x0002)
+ elf_hwcap |= HWCAP_BASE16;
+
+ if (cpu_cfgid & 0x0004)
+ elf_hwcap |= HWCAP_EXT2;
+
+ if (cpu_cfgid & 0x0008)
+ elf_hwcap |= HWCAP_FPU;
+
+ if (cpu_cfgid & 0x0010)
+ elf_hwcap |= HWCAP_STRING;
+
+ if (GET_MMU_CFG() & MMU_CFG_mskDE)
+ endianness = "MSB";
+ else
+ endianness = "LSB";
+
+ if (GET_MSC_CFG() & MSC_CFG_mskEDM)
+ elf_hwcap |= HWCAP_EDM;
+
+ if (GET_MSC_CFG() & MSC_CFG_mskLMDMA)
+ elf_hwcap |= HWCAP_LMDMA;
+
+ if (GET_MSC_CFG() & MSC_CFG_mskPFM)
+ elf_hwcap |= HWCAP_PFM;
+
+ if (GET_MSC_CFG() & MSC_CFG_mskHSMP)
+ elf_hwcap |= HWCAP_HSMP;
+
+ if (GET_MSC_CFG() & MSC_CFG_mskTRACE)
+ elf_hwcap |= HWCAP_TRACE;
+
+ if (GET_MSC_CFG() & MSC_CFG_mskAUDIO)
+ elf_hwcap |= HWCAP_AUDIO;
+
+ if (GET_MSC_CFG() & MSC_CFG_mskL2C)
+ elf_hwcap |= HWCAP_L2C;
+
+#ifdef CONFIG_ANDES_PAGE_SIZE_4KB
+ if (CPU_IS_N1213_43U1HA0()) {
+ /*
+ * Downsize dcache to bypass N1213-43u1h inconsistent
+ * use of PA and VA in fill-buffer logic issue.
+ */
+
+ if ((CACHE_SET(DCACHE) * CACHE_LINE_SIZE(DCACHE)) > 4096)
+ tmp |= 0x02 << SDZ_CTL_offDCDZ;
+
+ if ((CACHE_SET(ICACHE) * CACHE_LINE_SIZE(ICACHE)) > 4096)
+ tmp |= 0x02 << SDZ_CTL_offICDZ;
+
+ SET_SDZ_CTL(tmp);
+ ISB();
+ printk("CPU%i enabled dcache downsizing to half set/4-way.\n",
+ smp_processor_id());
+ }
+#endif /* CONFIG_ANDES_PAGE_SIZE_4KB */
+
+#ifdef CONFIG_CACHE_L2
+#ifdef CONFIG_PLAT_AG102
+ SET_HSMP_SADDR((CPU_MEM_PA_BASE & HSMP_SADDR_mskSADDR) |
+ (0xC00 << HSMP_SADDR_offRANGE) | HSMP_SADDR_mskEN);
+#endif
+
+ /* Here translation is on but I/O address is not mapped yet. */
+ SET_PSW(GET_PSW() & ~PSW_mskDT);
+ DSB();
+
+ /* This is the time when we enable L2$. */
+ /* All masters can't write another master register */
+ tmp = inl(L2CC_PA_BASE + L2CC_PROT_OFF);
+ tmp &= ~L2CC_PROT_mskMRWEN;
+ outl(tmp, L2CC_PA_BASE + L2CC_PROT_OFF);
+
+ /* All masters share the whole cache memory space */
+ tmp = inl(L2CC_PA_BASE + L2CC_SETUP_OFF);
+ tmp &= ~L2CC_SETUP_mskPART;
+ outl(tmp, L2CC_PA_BASE + L2CC_SETUP_OFF);
+
+ /* each master access self master, does not add master base */
+ tmp = inl(L2CC_PA_BASE + L2CC_CTRL_OFF);
+ tmp |= L2CC_CTRL_mskEN;
+ outl(tmp, L2CC_PA_BASE + L2CC_CTRL_OFF);
+
+ SET_PSW(GET_PSW() | PSW_mskDT);
+ ISB();
+#endif
+ tmp = GET_CACHE_CTL();
+#ifndef CONFIG_CPU_DCACHE_DISABLE
+ tmp |= CACHE_CTL_mskDC_EN;
+#endif
+
+#ifndef CONFIG_CPU_ICACHE_DISABLE
+ tmp |= CACHE_CTL_mskIC_EN;
+#endif
+ SET_CACHE_CTL(tmp);
+ DSB();
+ ISB();
+
+ sprintf(elf_platform, "%s %s", list->elf_name, endianness);
+
+ dump_cpu_info(smp_processor_id());
+}
+
+static struct machine_desc *__init setup_machine(unsigned int nr)
+{
+ struct machine_desc *list;
+
+ extern struct machine_desc __arch_info_begin, __arch_info_end;
+ /*
+ * locate machine in the list of supported machines.
+ */
+ for (list = &__arch_info_begin; list < &__arch_info_end; list++)
+ if (list->nr == nr)
+ break;
+ /*
+ * If the architecture type is not recognised, then we
+ * can co nothing...
+ */
+ if (list >= &__arch_info_end) {
+ printk("Architecture configuration botched (nr 0x%x), unable "
+ "to continue.\n", nr);
+ while (1) ;
+ }
+
+ printk(KERN_INFO "Machine: %s\n", list->name);
+
+ return list;
+}
+
+static void __init early_initrd(char **p)
+{
+ unsigned long start, size;
+
+ start = memparse(*p, p);
+ if (**p == ',') {
+ size = memparse((*p) + 1, p);
+
+ phys_initrd_start = start; //pa
+ phys_initrd_size = size;
+ }
+ printk(KERN_INFO
+ "phys_initrd_start at 0x%08lx, phys_initrd_size:0x%08lx\n",
+ phys_initrd_start, phys_initrd_size);
+ //memblock_reserve(phys_initrd_start, phys_initrd_size);
+}
+
+__early_param("initrd=", early_initrd);
+
+/*
+ * Pick out the memory size. We look for mem=size@start,
+ * where start and size are "size[KkMm]"
+ */
+static void __init early_mem(char **p)
+{
+ static int usermem __initdata = 0;
+ unsigned long size, start;
+
+ /*
+ * If the user specifies memory size, we
+ * blow away any automatically generated
+ * size.
+ */
+ if (usermem == 0) {
+ usermem = 1;
+ meminfo.nr_banks = 0;
+ }
+
+ start = PHYS_OFFSET; //Tom 0x0
+ size = memparse(*p, p);
+ if (**p == '@')
+ start = memparse(*p + 1, p);
+
+ meminfo.bank[meminfo.nr_banks].start = start;
+ meminfo.bank[meminfo.nr_banks].size = size;
+ meminfo.bank[meminfo.nr_banks].node = PHYS_TO_NID(start);
+ memblock_add_node(meminfo.bank[meminfo.nr_banks].start,
+ meminfo.bank[meminfo.nr_banks].size, 0);
+ meminfo.nr_banks += 1;
+
+}
+
+__early_param("mem=", early_mem);
+
+/*
+ * Initial parsing of the command line.
+ */
+void __init parse_cmdline(char **cmdline_p, char *from)
+{
+ char c = ' ', *to = command_line;
+ int len = 0;
+
+ for (;;) {
+ if (c == ' ') {
+ extern struct early_params __early_begin, __early_end;
+ struct early_params *p;
+
+ for (p = &__early_begin; p < &__early_end; p++) {
+ int len = strlen(p->arg);
+
+ if (memcmp(from, p->arg, len) == 0) {
+ if (to != command_line)
+ to -= 1;
+ from += len;
+ p->fn(&from);
+
+ while (*from != ' ' && *from != '\0')
+ from++;
+ break;
+ }
+ }
+ }
+ c = *from++;
+ if (!c)
+ break;
+ if (COMMAND_LINE_SIZE <= ++len)
+ break;
+ *to++ = c;
+ }
+ *to = '\0';
+ *cmdline_p = command_line;
+}
+
+static void __init
+setup_ramdisk(int doload, int prompt, int image_start, unsigned int rd_sz)
+{
+#ifdef CONFIG_BLK_DEV_RAM
+ extern int rd_size, rd_image_start, rd_prompt, rd_doload;
+
+ rd_image_start = image_start;
+ rd_prompt = prompt;
+ rd_doload = doload;
+
+ if (rd_sz)
+ rd_size = rd_sz;
+#endif
+}
+
+static void __init
+request_standard_resources(struct meminfo *mi, struct machine_desc *mdesc)
+{
+ struct resource *res;
+ int i;
+
+ kernel_code.start = virt_to_phys(&_text);
+ kernel_code.end = virt_to_phys(&_etext - 1);
+ kernel_data.start = virt_to_phys(&_sdata);
+ kernel_data.end = virt_to_phys(&_end - 1);
+
+ for (i = 0; i < mi->nr_banks; i++) {
+ unsigned long virt_start, virt_end;
+
+ if (mi->bank[i].size == 0)
+ continue;
+
+ virt_start = __phys_to_virt(mi->bank[i].start);
+ virt_end = virt_start + mi->bank[i].size - 1;
+
+ res = alloc_bootmem_low(sizeof(*res));
+ res->name = "System RAM";
+ res->start = __virt_to_phys(virt_start);
+ res->end = __virt_to_phys(virt_end);
+ res->flags = IORESOURCE_MEM | IORESOURCE_BUSY;
+
+ request_resource(&iomem_resource, res);
+
+ if (kernel_code.start >= res->start &&
+ kernel_code.end <= res->end)
+ request_resource(res, &kernel_code);
+ if (kernel_data.start >= res->start &&
+ kernel_data.end <= res->end)
+ request_resource(res, &kernel_data);
+ }
+
+ if (mdesc->video_start) {
+ video_ram.start = mdesc->video_start;
+ video_ram.end = mdesc->video_end;
+ request_resource(&iomem_resource, &video_ram);
+ }
+
+ /*
+ * Some machines don't have the possibility of ever
+ * possessing lp0, lp1 or lp2
+ */
+ if (mdesc->reserve_lp0)
+ request_resource(&ioport_resource, &lp0);
+ if (mdesc->reserve_lp1)
+ request_resource(&ioport_resource, &lp1);
+ if (mdesc->reserve_lp2)
+ request_resource(&ioport_resource, &lp2);
+}
+
+/*
+ * Tag parsing.
+ *
+ * This is the new way of passing data to the kernel at boot time. Rather
+ * than passing a fixed inflexible structure to the kernel, we pass a list
+ * of variable-sized tags to the kernel. The first tag must be a ATAG_CORE
+ * tag for the list to be recognised (to distinguish the tagged list from
+ * a param_struct). The list is terminated with a zero-length tag (this tag
+ * is not parsed in any way).
+ */
+//flag bit 0 = read-only
+static int __init parse_tag_core(const struct tag *tag)
+{
+ if (tag->hdr.size > 2) {
+ if ((tag->u.core.flags & 1) == 0)
+ root_mountflags &= ~MS_RDONLY;
+ ROOT_DEV = old_decode_dev(tag->u.core.rootdev);
+ }
+ return 0;
+}
+
+__tagtable(ATAG_CORE, parse_tag_core);
+
+static int __init parse_tag_mem32(const struct tag *tag)
+{
+ if (meminfo.nr_banks >= NR_BANKS) {
+ printk(KERN_WARNING
+ "Ignoring memory bank 0x%08x size %dKB\n",
+ tag->u.mem.start, tag->u.mem.size / 1024);
+ return -EINVAL;
+ }
+ meminfo.bank[meminfo.nr_banks].start = tag->u.mem.start;
+ meminfo.bank[meminfo.nr_banks].size = tag->u.mem.size;
+ memblock_add_node(meminfo.bank[meminfo.nr_banks].start,
+ meminfo.bank[meminfo.nr_banks].size, 0);
+ meminfo.bank[meminfo.nr_banks].node = PHYS_TO_NID(tag->u.mem.start);
+ meminfo.nr_banks += 1;
+
+ return 0;
+}
+
+__tagtable(ATAG_MEM, parse_tag_mem32);
+
+#if defined(CONFIG_VGA_CONSOLE) || defined(CONFIG_DUMMY_CONSOLE)
+struct screen_info screen_info = {
+ .orig_video_lines = 30,
+ .orig_video_cols = 80,
+ .orig_video_mode = 0,
+ .orig_video_ega_bx = 0,
+ .orig_video_isVGA = 1,
+ .orig_video_points = 8
+};
+
+static int __init parse_tag_videotext(const struct tag *tag)
+{
+ screen_info.orig_x = tag->u.videotext.x;
+ screen_info.orig_y = tag->u.videotext.y;
+ screen_info.orig_video_page = tag->u.videotext.video_page;
+ screen_info.orig_video_mode = tag->u.videotext.video_mode;
+ screen_info.orig_video_cols = tag->u.videotext.video_cols;
+ screen_info.orig_video_ega_bx = tag->u.videotext.video_ega_bx;
+ screen_info.orig_video_lines = tag->u.videotext.video_lines;
+ screen_info.orig_video_isVGA = tag->u.videotext.video_isvga;
+ screen_info.orig_video_points = tag->u.videotext.video_points;
+ return 0;
+}
+
+__tagtable(ATAG_VIDEOTEXT, parse_tag_videotext);
+#endif
+
+static int __init parse_tag_ramdisk(const struct tag *tag)
+{
+ setup_ramdisk((tag->u.ramdisk.flags & 1) == 0,
+ (tag->u.ramdisk.flags & 2) == 0,
+ tag->u.ramdisk.start, tag->u.ramdisk.size);
+ return 0;
+}
+
+__tagtable(ATAG_RAMDISK, parse_tag_ramdisk);
+
+static int __init parse_tag_initrd(const struct tag *tag)
+{
+ printk(KERN_WARNING "ATAG_INITRD is deprecated; "
+ "please update your bootloader.\n");
+ phys_initrd_start = __virt_to_phys(tag->u.initrd.start);
+ phys_initrd_size = tag->u.initrd.size;
+ return 0;
+}
+
+__tagtable(ATAG_INITRD, parse_tag_initrd);
+
+static int __init parse_tag_initrd2(const struct tag *tag)
+{
+ phys_initrd_start = tag->u.initrd.start;
+ phys_initrd_size = tag->u.initrd.size;
+ return 0;
+}
+
+__tagtable(ATAG_INITRD2, parse_tag_initrd2);
+
+static int __init parse_tag_revision(const struct tag *tag)
+{
+ return 0;
+}
+
+__tagtable(ATAG_REVISION, parse_tag_revision);
+
+static int __init parse_tag_cmdline(const struct tag *tag)
+{
+ strlcpy(default_command_line, tag->u.cmdline.cmdline,
+ COMMAND_LINE_SIZE);
+ return 0;
+}
+
+__tagtable(ATAG_CMDLINE, parse_tag_cmdline);
+
+/*
+ * Scan the tag table for this tag, and call its parse function.
+ * The tag table is built by the linker from all the __tagtable
+ * declarations.
+ */
+static int __init parse_tag(const struct tag *tag)
+{
+ extern struct tagtable __tagtable_begin, __tagtable_end;
+ struct tagtable *t;
+
+ for (t = &__tagtable_begin; t < &__tagtable_end; t++)
+ if (tag->hdr.tag == t->tag) {
+ t->parse(tag);
+ break;
+ }
+
+ return t < &__tagtable_end;
+}
+
+/*
+ * Parse all tags in the list, checking both the global and architecture
+ * specific tag tables.
+ */
+static void __init parse_tags(const struct tag *t)
+{
+ for (; t->hdr.size; t = tag_next(t))
+ if (!parse_tag(t))
+ printk(KERN_WARNING
+ "Ignoring unrecognised tag 0x%08x\n",
+ t->hdr.tag);
+}
+
+/*
+ * This holds our defaults.
+ */
+static struct init_tags {
+ struct tag_header hdr1;
+ struct tag_core core;
+ struct tag_header hdr2;
+ struct tag_mem32 mem;
+ struct tag_header hdr3;
+} init_tags __initdata = {
+ {tag_size(tag_core), ATAG_CORE}, //hdr1
+ {0, PAGE_SIZE, 0xff},
+ {tag_size(tag_mem32), ATAG_MEM}, //hdr2
+ {MEM_SIZE, PHYS_OFFSET},
+ {0, ATAG_NONE}
+};
+
+static unsigned long __init setup_memory(void)
+{
+ unsigned long bootmap_size;
+ unsigned long ram_start_pfn;
+ unsigned long free_ram_start_pfn;
+ phys_addr_t memory_start, memory_end;
+ struct memblock_region *region;
+
+ memory_end = memory_start = 0;
+
+ /* Find main memory where is the kernel */
+ for_each_memblock(memory, region) {
+ memory_start = region->base;
+ memory_end = region->base + region->size;
+ printk(KERN_INFO "%s: Memory: 0x%x-0x%x\n", __func__,
+ memory_start, memory_end);
+ }
+
+ if (!memory_end) {
+ panic("No memory!");
+ }
+
+ ram_start_pfn = PFN_UP(memblock_start_of_DRAM());
+ /* free_ram_start_pfn is first page after kernel */
+ free_ram_start_pfn = PFN_UP(__pa(&_end));
+ max_pfn = PFN_DOWN(memblock_end_of_DRAM());
+
+ /* it could update max_pfn */
+ if (max_pfn - ram_start_pfn <= MAXMEM_PFN)
+ max_low_pfn = max_pfn;
+ else {
+ max_low_pfn = MAXMEM_PFN + ram_start_pfn;
+#ifndef CONFIG_HIGHMEM
+ max_pfn = MAXMEM_PFN + ram_start_pfn;
+#endif
+ }
+ /* high_memory is related with VMALLOC */
+ high_memory = (void *)__va(max_low_pfn * PAGE_SIZE);
+ min_low_pfn = free_ram_start_pfn;
+
+ /*
+ * initialize the boot-time allocator (with low memory only).
+ *
+ * This makes the memory from the end of the kernel to the end of
+ * RAM usable.
+ * init_bootmem sets the global values min_low_pfn, max_low_pfn.
+ */
+ bootmap_size = init_bootmem_node(NODE_DATA(0), free_ram_start_pfn,
+ ram_start_pfn, max_low_pfn);
+ free_bootmem(PFN_PHYS(free_ram_start_pfn),
+ (max_low_pfn - free_ram_start_pfn) << PAGE_SHIFT);
+ reserve_bootmem(PFN_PHYS(free_ram_start_pfn), bootmap_size,
+ BOOTMEM_DEFAULT);
+
+ for_each_memblock(reserved, region) {
+ if (region->size != 0) {
+ printk(KERN_INFO "Reserved - 0x%08x-0x%08x\n",
+ (u32) region->base, (u32) region->size);
+ reserve_bootmem(region->base, region->size,
+ BOOTMEM_DEFAULT);
+ }
+ }
+ return max_low_pfn;
+}
+
+void __init setup_arch(char **cmdline_p)
+{
+ struct tag *tags = (struct tag *)&init_tags;
+ struct machine_desc *mdesc;
+ char *from = default_command_line;
+
+ setup_processor();
+ mdesc = setup_machine(machine_arch_type);
+ machine_desc = mdesc;
+ machine_name = mdesc->name;
+
+ if (mdesc->soft_reboot)
+ reboot_setup("s");
+
+ if (mdesc->param_offset)
+ tags = phys_to_virt(mdesc->param_offset);
+
+ if (tags->hdr.tag != ATAG_CORE)
+ tags = (struct tag *)&init_tags;
+
+ if (tags->hdr.tag == ATAG_CORE) {
+ if (meminfo.nr_banks != 0)
+ squash_mem_tags(tags);
+ parse_tags(tags);
+ }
+
+ init_mm.start_code = (unsigned long)&_text;
+ init_mm.end_code = (unsigned long)&_etext;
+ init_mm.end_data = (unsigned long)&_edata;
+ init_mm.brk = (unsigned long)&_end;
+
+ memcpy(boot_command_line, from, COMMAND_LINE_SIZE);
+ boot_command_line[COMMAND_LINE_SIZE - 1] = '\0';
+ parse_cmdline(cmdline_p, from);
+
+ /* use generic way to parse */
+ parse_early_param();
+
+ /* setup bootmem allocator */
+ setup_memory();
+
+ strlcpy(command_line, from, COMMAND_LINE_SIZE);
+ *cmdline_p = command_line;
+
+ paging_init(mdesc);
+ request_standard_resources(&meminfo, mdesc); //- for test only
+
+#ifdef CONFIG_SMP
+ smp_init_cpus();
+#endif
+
+ /*
+ * Set up various architecture-specific pointers
+ */
+ init_arch_irq = mdesc->init_irq;
+ system_timer = mdesc->timer;
+ if (mdesc->init_machine)
+ mdesc->init_machine();
+
+#if defined(CONFIG_VT)
+#if defined(CONFIG_VGA_CONSOLE)
+ conswitchp = &vga_con;
+#elif defined(CONFIG_DUMMY_CONSOLE)
+ conswitchp = &dummy_con; //+ Tom: we will reach here
+#endif
+#endif
+
+ early_trap_init();
+}
+
+/*
+ * cpu_init - initialise one CPU.
+ *
+ * cpu_init dumps the cache information, initialises SMP specific
+ * information.
+ */
+
+void __init cpu_init(void)
+{
+ unsigned int cpu = smp_processor_id(), tmp = 0;
+
+ if (cpu >= NR_CPUS) {
+ printk(KERN_CRIT "CPU%u: bad primary CPU number\n", cpu);
+ BUG();
+ }
+
+ if (system_state == SYSTEM_BOOTING)
+ dump_cpu_info(cpu);
+
+ tmp = 1 << IVB_offESZ;
+#ifdef CONFIG_EVIC
+ tmp |= 1 << IVB_offEVIC;
+#endif
+ SET_IVB(tmp | IVB_BASE);
+ tmp = 0x10003;
+ SET_INT_MASK(tmp);
+ ISB();
+}
+
+static int __init topology_init(void)
+{
+ int cpu;
+
+ for_each_possible_cpu(cpu)
+ register_cpu(&per_cpu(cpu_data, cpu).cpu, cpu);
+
+ return 0;
+}
+
+subsys_initcall(topology_init);
+
+static int c_show(struct seq_file *m, void *v)
+{
+ int i;
+
+ seq_printf(m, "Processor\t: %s %s (id %lu, rev %lu, cfg %lu)\n",
+ proc_info.manufacturer, proc_info.cpu_name,
+ cpu_id, cpu_rev, cpu_cfgid);
+#if defined(CONFIG_AG101_CPU_FREQ_SCALING_MODE) || defined(CONFIG_AG101_CPU_FREQ_FCS)
+ seq_printf(m, "MHz\t\t: %u\n", ag101_cpufreq_get(1) / 1000);
+#endif
+
+ seq_printf(m, "L1I\t\t: %luKB/%luS/%luW/%luB\n",
+ CACHE_SET(ICACHE) * CACHE_WAY(ICACHE) *
+ CACHE_LINE_SIZE(ICACHE) / 1024, CACHE_SET(ICACHE),
+ CACHE_WAY(ICACHE), CACHE_LINE_SIZE(ICACHE));
+
+ seq_printf(m, "L1D\t\t: %luKB/%luS/%luW/%luB\n",
+ CACHE_SET(DCACHE) * CACHE_WAY(DCACHE) *
+ CACHE_LINE_SIZE(DCACHE) / 1024, CACHE_SET(DCACHE),
+ CACHE_WAY(DCACHE), CACHE_LINE_SIZE(DCACHE));
+
+#if defined(CONFIG_SMP)
+ for_each_online_cpu(i) {
+ seq_printf(m, "Processor\t: %d\n", i);
+ seq_printf(m, "BogoMIPS\t: %lu.%02lu\n\n",
+ per_cpu(cpu_data,
+ i).loops_per_jiffy / (500000UL / HZ),
+ (per_cpu(cpu_data, i).loops_per_jiffy /
+ (5000UL / HZ)) % 100);
+ }
+#else /* CONFIG_SMP */
+ seq_printf(m, "BogoMIPS\t: %lu.%02lu\n",
+ loops_per_jiffy / (500000 / HZ),
+ (loops_per_jiffy / (5000 / HZ)) % 100);
+#endif
+
+ /* dump out the processor features */
+ seq_puts(m, "Features\t: ");
+
+ for (i = 0; hwcap_str[i]; i++)
+ if (elf_hwcap & (1 << i))
+ seq_printf(m, "%s ", hwcap_str[i]);
+
+ seq_puts(m, "\n\n");
+ seq_printf(m, "Hardware\t: %s\n", elf_platform);
+
+ return 0;
+}
+
+static void *c_start(struct seq_file *m, loff_t * pos)
+{
+ return *pos < 1 ? (void *)1 : NULL;
+}
+
+static void *c_next(struct seq_file *m, void *v, loff_t * pos)
+{
+ ++*pos;
+ return NULL;
+}
+
+static void c_stop(struct seq_file *m, void *v)
+{
+}
+
+struct seq_operations cpuinfo_op = {
+ .start = c_start,
+ .next = c_next,
+ .stop = c_stop,
+ .show = c_show
+};
diff -Nur linux-3.4.113.orig/arch/nds32/kernel/signal.c linux-3.4.113/arch/nds32/kernel/signal.c
--- linux-3.4.113.orig/arch/nds32/kernel/signal.c 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/kernel/signal.c 2016-12-01 20:59:27.776744798 +0100
@@ -0,0 +1,850 @@
+/*
+ * linux/arch/nds32/kernel/signal.c
+ *
+ * Copyright (C) 1995-2002 Russell King
+ * Copyright (C) 2009 Andes Technology Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+#include <linux/errno.h>
+#include <linux/signal.h>
+#include <linux/ptrace.h>
+#include <linux/personality.h>
+#include <linux/freezer.h>
+#include <linux/tracehook.h>
+
+#include <asm/cacheflush.h>
+#include <asm/ucontext.h>
+#include <asm/uaccess.h>
+#include <asm/unistd.h>
+#include <asm/fpu.h>
+#include <asm/audio.h>
+
+#include "ptrace.h"
+#include "signal.h"
+#include "fpu.h"
+#include "audio.h"
+
+#define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
+
+/*
+ * For NDS32 syscalls, we encode the syscall number into the instruction.
+ */
+#if defined( __NDS32_EL__)
+#define SWI_SYS_SIGRETURN (0xeb0e0a64)
+#define SWI_SYS_RT_SIGRETURN (0xab150a64)
+#define SWI_SYS_RESTART (0x0b000a64) /* syscall __NR_restart_syscall */
+#define SWI_SYS_RESTART_LWIBI (0x0180af0d) /* lwi.bi $p0, [$sp], 4 */
+#define SWI_SYS_RESTART_JRP0 (0x0068004a) /* jr $p0 */
+#elif defined(__NDS32_EB__)
+#define SWI_SYS_SIGRETURN (0x6400000b|(__NR_sigreturn<<5))
+#define SWI_SYS_RT_SIGRETURN (0x6400000b|(__NR_rt_sigreturn<<5))
+#define SWI_SYS_RESTART (0x640a000b) /* syscall __NR_restart_syscall */
+#define SWI_SYS_RESTART_LWIBI (0x0daf8001) /* lwi.bi $p0, [$sp], 4 */
+#define SWI_SYS_RESTART_JRP0 (0x4a006800) /* jr $p0 */
+#else
+#error "NDS32, but neither __NDS32_EB__, nor __NDS32_EL__???"
+#endif
+
+#ifdef CONFIG_FPU
+static struct fpu_struct init_fpuregs = {
+ .fs_regs = {[0 ... 31] = sNAN32},
+ .fd_regs = {[0 ... 15] = sNAN64},
+ .fpcsr = FPCSR_INIT
+};
+#endif
+#ifdef CONFIG_AUDIO
+static struct audio_struct init_audioregs = {
+ .auregs = {[0...31] = NAN32}
+};
+#endif
+const unsigned long retcodes[2] = {
+ SWI_SYS_SIGRETURN,
+ SWI_SYS_RT_SIGRETURN
+};
+
+const unsigned long syscall_restart_code[3] = {
+ SWI_SYS_RESTART, /* syscall __NR_restart_syscall */
+ SWI_SYS_RESTART_LWIBI, /* lwi.bi $p0, [$sp], 4 */
+ SWI_SYS_RESTART_JRP0 /* jr $p0 */
+};
+
+static int do_signal(sigset_t * oldset, struct pt_regs *regs, int syscall);
+
+/*
+ * atomically swap in the new signal mask, and wait for a signal.
+ */
+asmlinkage int sys_sigsuspend(int restart, unsigned long oldmask,
+ old_sigset_t mask, struct pt_regs *regs)
+{
+ sigset_t blocked;
+
+ mask &= _BLOCKABLE;
+ current->saved_sigmask = current->blocked;
+ siginitset(&blocked, mask);
+ set_current_blocked(&blocked);
+
+ current->state = TASK_INTERRUPTIBLE;
+ schedule();
+ set_thread_flag(TIF_RESTORE_SIGMASK);
+ return -ERESTARTNOHAND;
+}
+
+asmlinkage int sys_rt_sigsuspend(sigset_t __user * unewset, size_t sigsetsize,
+ struct pt_regs *regs)
+{
+ sigset_t newset;
+
+ /* XXX: Don't preclude handling different sized sigset_t's. */
+ if (sigsetsize != sizeof(sigset_t))
+ return -EINVAL;
+
+ if (copy_from_user(&newset, unewset, sizeof(newset)))
+ return -EFAULT;
+ sigdelsetmask(&newset, ~_BLOCKABLE);
+ current->saved_sigmask = current->blocked;
+ set_current_blocked(&newset);
+ current->state = TASK_INTERRUPTIBLE;
+ schedule();
+ set_thread_flag(TIF_RESTORE_SIGMASK);
+ return -ERESTARTNOHAND;
+}
+
+asmlinkage int sys_sigaction(int sig, const struct old_sigaction __user * act,
+ struct old_sigaction __user * oact)
+{
+ struct k_sigaction new_ka, old_ka;
+ int ret;
+
+ if (act) {
+ old_sigset_t mask;
+ if (!access_ok(VERIFY_READ, act, sizeof(*act)) ||
+ __get_user(new_ka.sa.sa_handler, &act->sa_handler) ||
+ __get_user(new_ka.sa.sa_restorer, &act->sa_restorer)) {
+
+ return -EFAULT;
+ }
+ __get_user(new_ka.sa.sa_flags, &act->sa_flags);
+ __get_user(mask, &act->sa_mask);
+
+ siginitset(&new_ka.sa.sa_mask, mask);
+ }
+
+ ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
+
+ if (!ret && oact) {
+
+ if (!access_ok(VERIFY_WRITE, oact, sizeof(*oact)) ||
+ __put_user(old_ka.sa.sa_handler, &oact->sa_handler) ||
+ __put_user(old_ka.sa.sa_restorer, &oact->sa_restorer)) {
+
+ return -EFAULT;
+ }
+ __put_user(old_ka.sa.sa_flags, &oact->sa_flags);
+ __put_user(old_ka.sa.sa_mask.sig[0], &oact->sa_mask);
+ }
+
+ return ret;
+}
+
+/*
+ * Auxiliary signal frame. This saves stuff like FP state.
+ * The layout of this structure is not part of the user ABI.
+ */
+struct aux_sigframe {
+};
+
+/*
+ * Do a signal return; undo the signal stack. These are aligned to 64-bit.
+ */
+struct sigframe {
+ struct sigcontext sc;
+ unsigned long extramask[_NSIG_WORDS - 1];
+ unsigned long retcode;
+ struct aux_sigframe aux __attribute__ ((aligned(8)));
+};
+
+struct rt_sigframe {
+ struct siginfo __user *pinfo;
+ void __user *puc;
+ struct siginfo info;
+ struct ucontext uc;
+ unsigned long retcode;
+ struct aux_sigframe aux __attribute__ ((aligned(8)));
+};
+
+#ifdef CONFIG_FPU
+static inline int restore_sigcontext_fpu(struct pt_regs *regs,
+ struct sigcontext __user * sc)
+{
+ struct task_struct *tsk = current;
+ unsigned long used_math_flag;
+ int ret = 0;
+
+ if (!(GET_FUCOP_EXIST() & FUCOP_EXIST_mskCP0ISFPU))
+ return 0;
+
+ __get_user_error(used_math_flag, &sc->used_math_flag, ret);
+
+ if (!used_math_flag)
+ return 0;
+
+ set_used_math();
+
+#ifdef CONFIG_UNLAZY_FPU
+ clear_fpu(regs);
+#else
+ preempt_disable();
+ if (current == last_task_used_math) {
+ last_task_used_math = NULL;
+ release_fpu(regs);
+ }
+ preempt_enable();
+#endif
+
+ return __copy_from_user(&tsk->thread.fpu, &sc->fpu,
+ sizeof(struct fpu_struct));
+}
+
+static inline int setup_sigcontext_fpu(struct pt_regs *regs,
+ struct sigcontext __user * sc)
+{
+ struct task_struct *tsk = current;
+ int ret = 0;
+
+ if (!(GET_FUCOP_EXIST() & FUCOP_EXIST_mskCP0ISFPU))
+ return 0;
+
+ __put_user_error(used_math(), &sc->used_math_flag, ret);
+
+ if (!used_math())
+ return ret;
+
+ preempt_disable();
+#ifdef CONFIG_UNLAZY_FPU
+ unlazy_fpu(tsk);
+#else
+ if (last_task_used_math != NULL)
+ save_fpu(last_task_used_math);
+#endif
+ ret = __copy_to_user(&sc->fpu, &tsk->thread.fpu,
+ sizeof(struct fpu_struct));
+
+ grab_fpu(task_pt_regs(tsk));
+ fpload(&init_fpuregs);
+#ifndef CONFIG_UNLAZY_FPU //Lazy FPU
+ last_task_used_math = current;
+#endif
+ preempt_enable();
+ return ret;
+}
+#else
+static inline int
+restore_sigcontext_fpu(struct pt_regs *regs, struct sigcontext __user * sc)
+{
+ return 0;
+}
+
+static inline int
+setup_sigcontext_fpu(struct pt_regs *regs, struct sigcontext __user * sc)
+{
+ return 0;
+}
+#endif /* CONFIG_FPU */
+
+#ifdef CONFIG_AUDIO
+static inline int restore_sigcontext_audio(struct pt_regs *regs,
+ struct sigcontext __user * sc)
+{
+ struct task_struct *tsk = current;
+ unsigned long used_audio_flag;
+ int ret = 0;
+
+ if (!(GET_MSC_CFG() & MSC_CFG_mskAUDIO))
+ return 0;
+
+ __get_user_error(used_audio_flag, &sc->used_audio_flag, ret);
+
+ if (!used_audio_flag)
+ return 0;
+
+ set_tsk_thread_flag(tsk, TIF_USEDAUDIO);
+#ifdef CONFIG_UNLAZY_AUDIO
+ clear_audio(regs);
+#else
+ preempt_disable();
+ if (current == last_task_used_audio) {
+ last_task_used_audio = NULL;
+ clear_audio(regs);
+ }
+ preempt_enable();
+#endif
+
+ return __copy_from_user(&tsk->thread.audio, &sc->audio,
+ sizeof(struct audio_struct));
+}
+
+static inline int setup_sigcontext_audio(struct pt_regs *regs,
+ struct sigcontext __user * sc)
+{
+ struct task_struct *tsk = current;
+ int ret = 0;
+
+ if (!(GET_MSC_CFG() & MSC_CFG_mskAUDIO))
+ return 0;
+
+ __put_user_error(test_tsk_thread_flag(tsk, TIF_USEDAUDIO),
+ &sc->used_audio_flag, ret);
+
+ if (!test_tsk_thread_flag(tsk, TIF_USEDAUDIO))
+ return ret;
+
+ preempt_disable();
+#ifdef CONFIG_UNLAZY_AUDIO
+ unlazy_audio(tsk);
+#else
+ if (NULL != last_task_used_audio) {
+ save_audio(tsk);
+ }
+#endif
+ ret = __copy_to_user(&sc->audio, &tsk->thread.audio,
+ sizeof(struct audio_struct));
+
+ grab_audio(task_pt_regs(tsk));
+ audioload(&init_audioregs);
+#ifndef CONFIG_UNLAZY_AUDIO //Lazy audio
+ last_task_used_audio = current;
+#endif
+ preempt_enable();
+ return ret;
+}
+#else /*CONFIG_AUDIO */
+static inline int
+restore_sigcontext_audio(struct pt_regs *regs, struct sigcontext __user * sc)
+{
+ return 0;
+}
+
+static inline int
+setup_sigcontext_audio(struct pt_regs *regs, struct sigcontext __user * sc)
+{
+ return 0;
+}
+#endif
+
+static int restore_sigcontext(struct pt_regs *regs,
+ struct sigcontext __user * sc,
+ struct aux_sigframe __user * aux)
+{
+ int err = 0;
+
+ __get_user_error(regs->NDS32_r0, &sc->nds32_r0, err);
+ __get_user_error(regs->NDS32_r1, &sc->nds32_r1, err);
+ __get_user_error(regs->NDS32_r2, &sc->nds32_r2, err);
+ __get_user_error(regs->NDS32_r3, &sc->nds32_r3, err);
+ __get_user_error(regs->NDS32_r4, &sc->nds32_r4, err);
+ __get_user_error(regs->NDS32_r5, &sc->nds32_r5, err);
+ __get_user_error(regs->NDS32_r6, &sc->nds32_r6, err);
+ __get_user_error(regs->NDS32_r7, &sc->nds32_r7, err);
+ __get_user_error(regs->NDS32_r8, &sc->nds32_r8, err);
+ __get_user_error(regs->NDS32_r9, &sc->nds32_r9, err);
+ __get_user_error(regs->NDS32_r10, &sc->nds32_r10, err);
+ __get_user_error(regs->NDS32_r11, &sc->nds32_r11, err);
+ __get_user_error(regs->NDS32_r12, &sc->nds32_r12, err);
+ __get_user_error(regs->NDS32_r13, &sc->nds32_r13, err);
+ __get_user_error(regs->NDS32_r14, &sc->nds32_r14, err);
+ __get_user_error(regs->NDS32_r15, &sc->nds32_r15, err);
+ __get_user_error(regs->NDS32_r16, &sc->nds32_r16, err);
+ __get_user_error(regs->NDS32_r17, &sc->nds32_r17, err);
+ __get_user_error(regs->NDS32_r18, &sc->nds32_r18, err);
+ __get_user_error(regs->NDS32_r19, &sc->nds32_r19, err);
+ __get_user_error(regs->NDS32_r20, &sc->nds32_r20, err);
+
+ __get_user_error(regs->NDS32_r21, &sc->nds32_r21, err);
+ __get_user_error(regs->NDS32_r22, &sc->nds32_r22, err);
+ __get_user_error(regs->NDS32_r23, &sc->nds32_r23, err);
+ __get_user_error(regs->NDS32_r24, &sc->nds32_r24, err);
+ __get_user_error(regs->NDS32_r25, &sc->nds32_r25, err);
+ __get_user_error(regs->NDS32_fp, &sc->nds32_fp, err);
+ __get_user_error(regs->NDS32_gp, &sc->nds32_gp, err);
+ __get_user_error(regs->NDS32_lp, &sc->nds32_lp, err);
+ __get_user_error(regs->NDS32_sp, &sc->nds32_sp, err);
+
+ __get_user_error(regs->NDS32_ipc, &sc->nds32_ipc, err);
+#if defined(CONFIG_HWZOL)
+ __get_user_error(regs->NDS32_lc, &sc->zol.nds32_lc, err);
+ __get_user_error(regs->NDS32_le, &sc->zol.nds32_le, err);
+ __get_user_error(regs->NDS32_lb, &sc->zol.nds32_lb, err);
+#endif
+
+ err |= !valid_user_regs(regs);
+ err |= restore_sigcontext_audio(regs, sc);
+ err |= restore_sigcontext_fpu(regs, sc);
+
+ return err;
+}
+
+asmlinkage int sys_sigreturn(struct pt_regs *regs)
+{
+ struct sigframe __user *frame;
+ sigset_t set;
+
+ /* Always make any pending restarted system calls return -EINTR */
+ current_thread_info()->restart_block.fn = do_no_restart_syscall;
+
+ /*
+ * Since we stacked the signal on a 64-bit boundary,
+ * then 'sp' should be word aligned here. If it's
+ * not, then the user is trying to mess with us.
+ */
+ if (regs->NDS32_sp & 7)
+ goto badframe;
+
+ frame = (struct sigframe __user *)regs->NDS32_sp;
+
+ if (!access_ok(VERIFY_READ, frame, sizeof(*frame)))
+ goto badframe;
+
+ if (__get_user(set.sig[0], &frame->sc.oldmask)
+ || (_NSIG_WORDS > 1
+ && __copy_from_user(&set.sig[1], &frame->extramask,
+ sizeof(frame->extramask))))
+ goto badframe;
+
+ sigdelsetmask(&set, ~_BLOCKABLE);
+ spin_lock_irq(¤t->sighand->siglock);
+ current->blocked = set;
+ recalc_sigpending();
+ spin_unlock_irq(¤t->sighand->siglock);
+
+ if (restore_sigcontext(regs, &frame->sc, &frame->aux))
+ goto badframe;
+
+ return regs->NDS32_r0;
+
+badframe:
+ force_sig(SIGSEGV, current);
+ return 0;
+}
+
+asmlinkage int sys_rt_sigreturn(struct pt_regs *regs)
+{
+ struct rt_sigframe __user *frame;
+ sigset_t set;
+
+ /* Always make any pending restarted system calls return -EINTR */
+ current_thread_info()->restart_block.fn = do_no_restart_syscall;
+
+ /*
+ * Since we stacked the signal on a 64-bit boundary,
+ * then 'sp' should be word aligned here. If it's
+ * not, then the user is trying to mess with us.
+ */
+ if (regs->NDS32_sp & 7)
+ goto badframe;
+
+ frame = (struct rt_sigframe __user *)regs->NDS32_sp;
+
+ if (!access_ok(VERIFY_READ, frame, sizeof(*frame)))
+ goto badframe;
+
+ if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set)))
+ goto badframe;
+
+ sigdelsetmask(&set, ~_BLOCKABLE);
+ spin_lock_irq(¤t->sighand->siglock);
+ current->blocked = set;
+ recalc_sigpending();
+ spin_unlock_irq(¤t->sighand->siglock);
+
+ if (restore_sigcontext(regs, &frame->uc.uc_mcontext, &frame->aux))
+ goto badframe;
+
+ if (do_sigaltstack(&frame->uc.uc_stack, NULL, regs->NDS32_sp) ==
+ -EFAULT)
+ goto badframe;
+
+ return regs->NDS32_r0;
+
+badframe:
+ force_sig(SIGSEGV, current);
+ return 0;
+}
+
+static int setup_sigcontext(struct sigcontext __user * sc,
+ struct aux_sigframe __user * aux,
+ struct pt_regs *regs, unsigned long mask)
+{
+ int err = 0;
+
+ err |= setup_sigcontext_fpu(regs, sc);
+ err |= setup_sigcontext_audio(regs, sc);
+
+ __put_user_error(regs->NDS32_r0, &sc->nds32_r0, err);
+ __put_user_error(regs->NDS32_r1, &sc->nds32_r1, err);
+ __put_user_error(regs->NDS32_r2, &sc->nds32_r2, err);
+ __put_user_error(regs->NDS32_r3, &sc->nds32_r3, err);
+ __put_user_error(regs->NDS32_r4, &sc->nds32_r4, err);
+ __put_user_error(regs->NDS32_r5, &sc->nds32_r5, err);
+ __put_user_error(regs->NDS32_r6, &sc->nds32_r6, err);
+ __put_user_error(regs->NDS32_r7, &sc->nds32_r7, err);
+ __put_user_error(regs->NDS32_r8, &sc->nds32_r8, err);
+ __put_user_error(regs->NDS32_r9, &sc->nds32_r9, err);
+ __put_user_error(regs->NDS32_r10, &sc->nds32_r10, err);
+ __put_user_error(regs->NDS32_r11, &sc->nds32_r11, err);
+ __put_user_error(regs->NDS32_r12, &sc->nds32_r12, err);
+ __put_user_error(regs->NDS32_r13, &sc->nds32_r13, err);
+ __put_user_error(regs->NDS32_r14, &sc->nds32_r14, err);
+ __put_user_error(regs->NDS32_r15, &sc->nds32_r15, err);
+ __put_user_error(regs->NDS32_r16, &sc->nds32_r16, err);
+ __put_user_error(regs->NDS32_r17, &sc->nds32_r17, err);
+ __put_user_error(regs->NDS32_r18, &sc->nds32_r18, err);
+ __put_user_error(regs->NDS32_r19, &sc->nds32_r19, err);
+ __put_user_error(regs->NDS32_r20, &sc->nds32_r20, err);
+
+ __put_user_error(regs->NDS32_r21, &sc->nds32_r21, err);
+ __put_user_error(regs->NDS32_r22, &sc->nds32_r22, err);
+ __put_user_error(regs->NDS32_r23, &sc->nds32_r23, err);
+ __put_user_error(regs->NDS32_r24, &sc->nds32_r24, err);
+ __put_user_error(regs->NDS32_r25, &sc->nds32_r25, err);
+ __put_user_error(regs->NDS32_fp, &sc->nds32_fp, err);
+ __put_user_error(regs->NDS32_gp, &sc->nds32_gp, err);
+ __put_user_error(regs->NDS32_lp, &sc->nds32_lp, err);
+ __put_user_error(regs->NDS32_sp, &sc->nds32_sp, err);
+ __put_user_error(regs->NDS32_ipc, &sc->nds32_ipc, err);
+#if defined(CONFIG_HWZOL)
+ __get_user_error(regs->NDS32_lc, &sc->zol.nds32_lc, err);
+ __get_user_error(regs->NDS32_le, &sc->zol.nds32_le, err);
+ __get_user_error(regs->NDS32_lb, &sc->zol.nds32_lb, err);
+#endif
+
+ __put_user_error(current->thread.trap_no, &sc->trap_no, err);
+ __put_user_error(current->thread.error_code, &sc->error_code, err);
+ __put_user_error(current->thread.address, &sc->fault_address, err);
+ __put_user_error(mask, &sc->oldmask, err);
+
+ return err;
+}
+
+static inline void __user *get_sigframe(struct k_sigaction *ka,
+ struct pt_regs *regs, int framesize)
+{
+ unsigned long sp = regs->NDS32_sp;
+ void __user *frame;
+
+ /*
+ * This is the X/Open sanctioned signal stack switching.
+ */
+ if ((ka->sa.sa_flags & SA_ONSTACK) && !sas_ss_flags(sp))
+ sp = current->sas_ss_sp + current->sas_ss_size;
+
+ /*
+ * ATPCS B01 mandates 8-byte alignment
+ */
+ frame = (void __user *)((sp - framesize) & ~7);
+
+ /*
+ * Check that we can actually write to the signal frame.
+ */
+ if (!access_ok(VERIFY_WRITE, frame, framesize))
+ frame = NULL;
+
+ return frame;
+}
+
+static int setup_return(struct pt_regs *regs, struct k_sigaction *ka,
+ unsigned long __user * rc, void __user * frame,
+ int usig)
+{
+ unsigned long handler = (unsigned long)ka->sa.sa_handler;
+ unsigned long retcode;
+ struct sigframe *sf = (struct sigframe *)frame;
+
+ /*
+ * Maybe we need to deliver a 32-bit signal to a 26-bit task.
+ */
+ if (ka->sa.sa_flags & SA_RESTORER) {
+ retcode = (unsigned long)ka->sa.sa_restorer;
+ } else {
+
+ unsigned int idx = 0; //thumb;
+ unsigned long line_size = CACHE_LINE_SIZE(ICACHE);
+ unsigned long start, end;
+
+ if (ka->sa.sa_flags & SA_SIGINFO)
+ idx++;
+
+ if (__put_user(retcodes[idx], rc))
+ return 1;
+
+ /*
+ * Ensure that the instruction cache sees
+ * the return code written onto the stack.
+ */
+ start = (unsigned long)rc & ~(line_size - 1);
+ end = start + line_size;
+ flush_icache_range(start, end);
+
+ retcode = KERN_SIGRETURN_CODE + (idx << 2);
+ }
+
+ regs->NDS32_r0 = usig;
+ regs->NDS32_r1 = 0;
+ regs->NDS32_r2 = (unsigned long)&sf->sc;
+ regs->NDS32_sp = (unsigned long)frame;
+ regs->NDS32_lp = retcode;
+ regs->NDS32_ipc = handler;
+ /* Also store handler address in r15 for updating GP in the handler. */
+ regs->NDS32_r15 = handler;
+
+ return 0;
+}
+
+static int setup_frame(int usig, struct k_sigaction *ka, sigset_t * set,
+ struct pt_regs *regs)
+{
+ struct sigframe __user *frame = get_sigframe(ka, regs, sizeof(*frame));
+ int err = 0;
+
+ if (!frame)
+ return 1;
+
+ err |= setup_sigcontext(&frame->sc, &frame->aux, regs, set->sig[0]);
+
+ if (_NSIG_WORDS > 1) {
+ err |= __copy_to_user(frame->extramask, &set->sig[1],
+ sizeof(frame->extramask));
+ }
+
+ if (err == 0)
+ err = setup_return(regs, ka, &frame->retcode, frame, usig);
+
+ return err;
+}
+
+static int setup_rt_frame(int usig, struct k_sigaction *ka, siginfo_t * info,
+ sigset_t * set, struct pt_regs *regs)
+{
+ struct rt_sigframe __user *frame =
+ get_sigframe(ka, regs, sizeof(*frame));
+ stack_t stack;
+ int err = 0;
+
+ if (!frame)
+ return 1;
+
+ __put_user_error(&frame->info, &frame->pinfo, err);
+ __put_user_error(&frame->uc, &frame->puc, err);
+ err |= copy_siginfo_to_user(&frame->info, info);
+
+ __put_user_error(0, &frame->uc.uc_flags, err);
+ __put_user_error(NULL, &frame->uc.uc_link, err);
+
+ memset(&stack, 0, sizeof(stack));
+ stack.ss_sp = (void __user *)current->sas_ss_sp;
+ stack.ss_flags = sas_ss_flags(regs->NDS32_sp); //NDS32_sp
+ stack.ss_size = current->sas_ss_size;
+ err |= __copy_to_user(&frame->uc.uc_stack, &stack, sizeof(stack));
+
+ err |= setup_sigcontext(&frame->uc.uc_mcontext, &frame->aux,
+ regs, set->sig[0]);
+ err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
+
+ if (err == 0)
+ err = setup_return(regs, ka, &frame->retcode, frame, usig);
+
+ if (err == 0) {
+ /*
+ * For realtime signals we must also set the second and third
+ * arguments for the signal handler.
+ * -- Peter Maydell <pmaydell@chiark.greenend.org.uk> 2000-12-06
+ */
+ regs->NDS32_r1 = (unsigned long)&frame->info;
+ regs->NDS32_r2 = (unsigned long)&frame->uc;
+ }
+
+ return err;
+}
+
+static inline void setup_restart_syscall(struct pt_regs *regs)
+{
+ regs->NDS32_r0 = regs->NDS32_ORIG_r0;
+ regs->NDS32_ipc -= 4;
+}
+
+/*
+ * OK, we're invoking a handler
+ */
+static void handle_signal(unsigned long sig, struct k_sigaction *ka,
+ siginfo_t * info, sigset_t * oldset,
+ struct pt_regs *regs, int syscall)
+{
+ struct thread_info *thread = current_thread_info();
+ struct task_struct *tsk = current;
+ int usig = sig;
+ int ret;
+
+ /*
+ * If we were from a system call, check for system call restarting...
+ */
+ if (syscall) {
+ switch (regs->NDS32_r0) {
+ case -ERESTART_RESTARTBLOCK:
+ case -ERESTARTNOHAND:
+ regs->NDS32_r0 = -EINTR;
+ break;
+ case -ERESTARTSYS:
+ if (!(ka->sa.sa_flags & SA_RESTART)) {
+ regs->NDS32_r0 = -EINTR;
+ break;
+ }
+ /* fallthrough */
+ case -ERESTARTNOINTR:
+ setup_restart_syscall(regs);
+ }
+ }
+
+ /*
+ * translate the signal
+ */
+ if (usig < 32 && thread->exec_domain
+ && thread->exec_domain->signal_invmap)
+ usig = thread->exec_domain->signal_invmap[usig];
+
+ /*
+ * Set up the stack frame
+ */
+ if (ka->sa.sa_flags & SA_SIGINFO)
+ ret = setup_rt_frame(usig, ka, info, oldset, regs);
+ else
+ ret = setup_frame(usig, ka, oldset, regs);
+
+ /*
+ * Check that the resulting registers are actually sane.
+ */
+ ret |= !valid_user_regs(regs);
+
+ /*
+ * Block the signal if we were unsuccessful.
+ */
+ if (ret == 0) {
+ spin_lock_irq(&tsk->sighand->siglock);
+ sigorsets(&tsk->blocked, &tsk->blocked, &ka->sa.sa_mask);
+ if (!(ka->sa.sa_flags & SA_NODEFER))
+ sigaddset(&tsk->blocked, sig);
+ recalc_sigpending();
+ spin_unlock_irq(&tsk->sighand->siglock);
+#if 0 & defined(CONFIG_HSS)
+ /* COLE: i marked this tempory.
+ It doesn't behave the same as x86 */
+ /* Clear HSS when entering the signal handler,
+ User should be step into signal handler */
+ if (regs->NDS32_ipsw & PSW_mskHSS) {
+ regs->NDS32_ipsw &= ~PSW_mskHSS;
+ printk(KERN_INFO "clear for sig %d. pc=0x%08x\n", sig,
+ regs->NDS32_ipc);
+ }
+#endif
+ return;
+ }
+
+ force_sigsegv(sig, tsk);
+}
+
+/*
+ * Note that 'init' is a special process: it doesn't get signals it doesn't
+ * want to handle. Thus you cannot kill init even with a SIGKILL even by
+ * mistake.
+ *
+ * Note that we go through the signals twice: once to check the signals that
+ * the kernel can handle, and then we build all the user-level signal handling
+ * stack-frames in one go after that.
+ */
+asmlinkage int do_signal(sigset_t * oldset, struct pt_regs *regs, int syscall)
+{
+ struct k_sigaction ka;
+ siginfo_t info;
+ int signr;
+
+ /*
+ * We want the common case to go fast, which
+ * is why we may in certain cases get here from
+ * kernel mode. Just return without doing anything
+ * if so.
+ */
+
+ if (!user_mode(regs))
+ return 0;
+
+ if (try_to_freeze())
+ goto no_signal;
+
+ if (test_thread_flag(TIF_RESTORE_SIGMASK))
+ oldset = ¤t->saved_sigmask;
+
+ signr = get_signal_to_deliver(&info, &ka, regs, NULL);
+
+ if (signr > 0) {
+ handle_signal(signr, &ka, &info, oldset, regs, syscall);
+ /*
+ * A signal was successfully delivered; the saved
+ * sigmask will have been stored in the signal frame,
+ * and will be restored by sigreturn, so we can simply
+ * clear the TIF_RESTORE_SIGMASK flag.
+ */
+ if (test_thread_flag(TIF_RESTORE_SIGMASK))
+ clear_thread_flag(TIF_RESTORE_SIGMASK);
+ return 1;
+ }
+
+no_signal:
+ /*
+ * No signal to deliver to the process - restart the syscall.
+ */
+ if (syscall) {
+ switch (regs->NDS32_r0) {
+ u32 __user *usp;
+
+ case -ERESTART_RESTARTBLOCK:
+ regs->NDS32_sp -= 4;
+ usp = (u32 __user *) regs->NDS32_sp;
+
+ if (put_user(regs->NDS32_ipc, usp) == 0)
+ regs->NDS32_ipc = KERN_RESTART_CODE;
+ else {
+ regs->NDS32_sp += 4;
+ force_sigsegv(0, current);
+ }
+ regs->NDS32_r0 = regs->NDS32_ORIG_r0;
+ break;
+
+ case -ERESTARTNOHAND:
+ case -ERESTARTSYS:
+ case -ERESTARTNOINTR:
+
+ setup_restart_syscall(regs);
+ break;
+ }
+ if (test_thread_flag(TIF_RESTORE_SIGMASK)) {
+ clear_thread_flag(TIF_RESTORE_SIGMASK);
+ sigprocmask(SIG_SETMASK, ¤t->saved_sigmask, NULL);
+ }
+ }
+
+ return 0;
+}
+
+asmlinkage void do_notify_resume(struct pt_regs *regs,
+ unsigned int thread_flags, int syscall)
+{
+ if (thread_flags & _TIF_SIGPENDING)
+ do_signal(¤t->blocked, regs, syscall);
+ if (thread_flags & _TIF_NOTIFY_RESUME) {
+ clear_thread_flag(TIF_NOTIFY_RESUME);
+ tracehook_notify_resume(regs);
+ if (current->replacement_session_keyring)
+ key_replace_session_keyring();
+ }
+}
diff -Nur linux-3.4.113.orig/arch/nds32/kernel/signal.h linux-3.4.113/arch/nds32/kernel/signal.h
--- linux-3.4.113.orig/arch/nds32/kernel/signal.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/kernel/signal.h 2016-12-01 20:59:24.356612904 +0100
@@ -0,0 +1,20 @@
+/*
+ * linux/arch/arm/kernel/signal.h
+ *
+ * Copyright (C) 2005-2009 Russell King.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include <asm/fixmap.h>
+
+#define RETURN_SYSCALL_BASE (0x2000)
+#define RETURN_SYSCALL_PA_BASE (PHYS_OFFSET | RETURN_SYSCALL_BASE)
+
+#define KERN_SIGRETURN_CODE (fix_to_virt(FIX_RETURN_SYSCALL))
+#define KERN_RESTART_CODE (KERN_SIGRETURN_CODE + sizeof(retcodes))
+
+extern const unsigned long retcodes[2];
+extern const unsigned long syscall_restart_code[3];
diff -Nur linux-3.4.113.orig/arch/nds32/kernel/smp.c linux-3.4.113/arch/nds32/kernel/smp.c
--- linux-3.4.113.orig/arch/nds32/kernel/smp.c 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/kernel/smp.c 2016-12-01 20:59:24.356612904 +0100
@@ -0,0 +1,335 @@
+/*
+ * linux/arch/nds32/kernel/smp.c
+ *
+ * Copyright (C) 2002 ARM Limited, All Rights Reserved.
+ * Copyright (C) 2009 Andes Technology Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+#include <linux/delay.h>
+#include <linux/init.h>
+#include <linux/spinlock.h>
+#include <linux/sched.h>
+#include <linux/irq.h>
+#include <linux/interrupt.h>
+#include <linux/cache.h>
+#include <linux/profile.h>
+#include <linux/errno.h>
+#include <linux/mm.h>
+#include <linux/cpu.h>
+#include <linux/smp.h>
+#include <linux/seq_file.h>
+#include <asm/atomic.h>
+#include <asm/cacheflush.h>
+#include <asm/cpu.h>
+#include <asm/processor.h>
+#include <asm/tlbflush.h>
+#include <asm/ptrace.h>
+#include <linux/err.h>
+#include <asm/irq_regs.h>
+#include <asm/mmu_context.h>
+#include <asm/mmu.h>
+
+void smp_init_cpus(void)
+{
+ int i;
+ for (i = 0; i < NR_CPUS; i++)
+ cpu_set(i, cpu_possible_map);
+}
+
+int setup_profiling_timer(unsigned int multiplier)
+{
+ return 0;
+}
+
+struct tlb_data {
+ struct vm_area_struct *vma;
+ unsigned long start;
+ unsigned long end;
+};
+
+static void ipi_flush_tlb_all(void *data)
+{
+ local_flush_tlb_all();
+}
+
+void flush_tlb_all(void)
+{
+ on_each_cpu(ipi_flush_tlb_all, NULL, 1);
+}
+
+static void ipi_flush_tlb_mm(void *data)
+{
+ struct mm_struct *mm = (struct mm_struct *)data;
+ local_flush_tlb_mm(mm);
+}
+
+void flush_tlb_mm(struct mm_struct *mm)
+{
+ on_each_cpu(ipi_flush_tlb_mm, mm, 1);
+}
+
+static void ipi_flush_tlb_page(void *data)
+{
+ struct tlb_data *t = (struct tlb_data *)data;
+ local_flush_tlb_page(t->vma, t->start);
+}
+
+void flush_tlb_page(struct vm_area_struct *vma, unsigned long addr)
+{
+ struct tlb_data data;
+
+ data.vma = vma;
+ data.start = addr;
+ on_each_cpu(ipi_flush_tlb_page, &data, 1);
+}
+
+static void ipi_flush_tlb_range(void *data)
+{
+ struct tlb_data *t = (struct tlb_data *)data;
+ local_flush_tlb_range(t->vma, t->start, t->end);
+}
+
+void flush_tlb_range(struct vm_area_struct *vma,
+ unsigned long start, unsigned long end)
+{
+ struct tlb_data data;
+
+ data.vma = vma;
+ data.start = start;
+ data.end = end;
+ on_each_cpu(ipi_flush_tlb_range, &data, 1);
+}
+
+static void ipi_flush_tlb_kernel_range(void *data)
+{
+ struct tlb_data *t = (struct tlb_data *)data;
+ local_flush_tlb_kernel_range(t->start, t->end);
+}
+
+void flush_tlb_kernel_range(unsigned long start, unsigned long end)
+{
+ struct tlb_data data;
+
+ data.start = start;
+ data.end = end;
+ on_each_cpu(ipi_flush_tlb_kernel_range, &data, 1);
+}
+
+/* IPI implementation */
+static inline unsigned long read_ipi_trigger(void)
+{
+ /* AMIC IPI trigger register */
+ return *(volatile unsigned long *)(AMIC_VA_BASE + 0x40);
+}
+
+static inline void write_ipi_trigger(const struct cpumask *mask)
+{
+ unsigned long data = *cpus_addr(*mask);
+ *(volatile unsigned long *)(AMIC_VA_BASE + 0x40) = data;
+}
+
+static inline void clear_ipi_status(void)
+{
+ *(volatile unsigned long *)(AMIC_VA_BASE + 0x44) = 0xf;
+ asm("msync store\nisb");
+}
+
+static void __init send_IPI_boot(int cpu, struct task_struct *tsk)
+{
+ extern void secondary_startup(void);
+ unsigned long *ptr = (unsigned long *)(0xc0006000 + (cpu << 9));
+ ptr[5] = virt_to_phys(secondary_startup);
+ ptr[6] = (unsigned long)task_stack_page(tsk) + THREAD_SIZE - 8;
+ asm("cctl %0, L1D_VA_WB, alevel\n"::"r"(ptr));
+ asm("cctl %0, L1D_VA_INVAL, alevel\nmsync\ndsb\n"::"r"(ptr));
+ write_ipi_trigger(get_cpu_mask(cpu));
+}
+
+static int __init wait_cpu_boot_done(int cpu)
+{
+ int i, state;
+ for (i = 0; i < 10000; i++) {
+ state = read_ipi_trigger();
+ if ((state & (1 << cpu)) == 0)
+ break;
+ udelay(100);
+ }
+ return (i == 10000) ? -1 : 0;
+}
+
+void __init secondary_start_kernel(void)
+{
+ unsigned long tmp;
+ unsigned int cpu = smp_processor_id();
+
+ atomic_inc(&init_mm.mm_count);
+ current->active_mm = &init_mm;
+
+ /*
+ * enable cache.
+ */
+
+#ifdef CONFIG_ANDES_PAGE_SIZE_4KB
+ if (CPU_IS_N1213_43U1HA0()) {
+ /* Downsize cache to bypass cache aliasing issue */
+
+ if ((CACHE_SET(ICACHE) * CACHE_LINE_SIZE(ICACHE)) > 4096)
+ tmp = 0x02 << SDZ_CTL_offICDZ;
+
+ if ((CACHE_SET(DCACHE) * CACHE_LINE_SIZE(DCACHE)) > 4096)
+ tmp |= 0x02 << SDZ_CTL_offDCDZ;
+
+ SET_SDZ_CTL(tmp);
+ ISB();
+// printk("CPU%d enabled cache downsizing.\n", cpu);
+ }
+#endif /* CONFIG_ANDES_PAGE_SIZE_4KB */
+
+ tmp = GET_CACHE_CTL();
+#ifndef CONFIG_CPU_DCACHE_DISABLE
+ tmp |= CACHE_CTL_mskDC_EN;
+#endif
+
+#ifndef CONFIG_CPU_ICACHE_DISABLE
+ tmp |= CACHE_CTL_mskIC_EN;
+#endif
+ SET_CACHE_CTL(tmp);
+ DSB();
+ ISB();
+
+ preempt_disable();
+ local_irq_enable();
+
+ //assume all of cores runs the same speed
+ //calibrate_delay();
+ /* store cpu info ot the second cpu */
+ smp_store_cpu_info(cpu);
+
+ clear_ipi_status();
+ cpu_idle();
+}
+
+/*
+ * Called by both boot and secondaries to move global data into
+ * per-processor storage.
+ */
+void __init smp_store_cpu_info(unsigned int cpuid)
+{
+ struct cpuinfo_nds32 *cpu_info = &per_cpu(cpu_data, cpuid);
+
+ cpu_info->loops_per_jiffy = loops_per_jiffy;
+}
+
+/* functions be used by generic layer */
+void arch_send_call_function_single_ipi(int cpu)
+{
+ write_ipi_trigger(get_cpu_mask(cpu));
+}
+
+void arch_send_call_function_ipi_mask(const struct cpumask *mask)
+{
+ write_ipi_trigger(mask);
+}
+
+static void __init smp_boot_one_cpu(int cpu)
+{
+ struct task_struct *idle;
+ int ret;
+
+ idle = fork_idle(cpu);
+ if (IS_ERR(idle))
+ panic(KERN_ERR "Fork failed for CPU %d", cpu);
+
+ send_IPI_boot(cpu, idle);
+ ret = wait_cpu_boot_done(cpu);
+ if (ret == 0)
+ cpu_set(cpu, cpu_online_map);
+ else
+ put_task_struct(idle);
+}
+
+static void ipi_timer(void *data)
+{
+ profile_tick(CPU_PROFILING);
+ update_process_times(user_mode(get_irq_regs()));
+}
+
+void smp_send_timer(void)
+{
+ smp_call_function(ipi_timer, NULL, 0);
+}
+
+static void ipi_stop(void *data)
+{
+ cpu_clear(smp_processor_id(), cpu_online_map);
+ local_irq_enable();
+ for (;;) ;
+}
+
+void smp_send_stop(void)
+{
+ smp_call_function(ipi_stop, NULL, 0);
+}
+
+void smp_send_reschedule(int cpu)
+{
+ write_ipi_trigger(get_cpu_mask(cpu));
+}
+
+static void ipi_handler(unsigned int irq, struct irq_desc *desc)
+{
+ clear_ipi_status();
+ generic_smp_call_function_single_interrupt();
+ generic_smp_call_function_interrupt();
+}
+
+void __init smp_prepare_cpus(unsigned int max_cpus)
+{
+ /*
+ * XXX detect how many cores exist
+ */
+ int i;
+ unsigned int cpu = smp_processor_id();
+
+ /* store master core cpu info */
+ smp_store_cpu_info(cpu);
+ for (i = 0; i < max_cpus; i++)
+ cpu_set(i, cpu_present_map);
+
+ /* setup IPI handler */
+ set_irq_chip(32, &dummy_irq_chip);
+ set_irq_chained_handler(32, ipi_handler);
+}
+
+int __cpuinit __cpu_up(unsigned int cpu)
+{
+ smp_boot_one_cpu(cpu);
+ return cpu_online(cpu) ? 0 : -ENOSYS;
+}
+
+void __init smp_cpus_done(unsigned int max_cpus)
+{
+ int cpu;
+ unsigned long bogosum = 0;
+
+ for_each_online_cpu(cpu)
+ bogosum += per_cpu(cpu_data, cpu).loops_per_jiffy;
+
+ printk(KERN_INFO "SMP: Total of %d processors activated "
+ "(%lu.%02lu BogoMIPS).\n",
+ num_online_cpus(),
+ bogosum / (500000 / HZ), (bogosum / (5000 / HZ)) % 100);
+
+ /* now we can set all interruption don't cared */
+ *(volatile unsigned long *)(AMIC_VA_BASE + 0x4) = 0xffffffff;
+}
+
+void __init smp_prepare_boot_cpu(void)
+{
+ unsigned int cpu = smp_processor_id();
+ unsigned long *ptr = (unsigned long *)(0xc0006000 + (cpu << 9));
+ ptr[4] = 1;
+}
diff -Nur linux-3.4.113.orig/arch/nds32/kernel/stacktrace.c linux-3.4.113/arch/nds32/kernel/stacktrace.c
--- linux-3.4.113.orig/arch/nds32/kernel/stacktrace.c 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/kernel/stacktrace.c 2016-12-01 20:59:24.356612904 +0100
@@ -0,0 +1,41 @@
+#include <linux/sched.h>
+#include <linux/stacktrace.h>
+void save_stack_trace(struct stack_trace *trace)
+{
+ save_stack_trace_tsk(current, trace);
+}
+
+void save_stack_trace_tsk(struct task_struct *tsk, struct stack_trace *trace)
+{
+ unsigned long *fpn;
+ int skip = trace->skip;
+ int savesched;
+
+ if (tsk == current) {
+ __asm__ __volatile__("\tori\t%0, $fp, #0\n":"=r"(fpn));
+ savesched = 1;
+ } else {
+ fpn = (unsigned long *)thread_saved_fp(tsk);
+ savesched = 0;
+ }
+
+ while (!kstack_end(fpn) && !((unsigned long)fpn & 0x3)
+ && (fpn >= (unsigned long *)TASK_SIZE)) {
+ unsigned long lpp, fpp;
+ lpp = fpn[0];
+ fpp = fpn[-1];
+ if (!__kernel_text_address(lpp))
+ break;
+
+ if (savesched || !in_sched_functions(lpp)) {
+ if (skip) {
+ skip--;
+ } else {
+ trace->entries[trace->nr_entries++] = lpp;
+ if (trace->nr_entries >= trace->max_entries)
+ break;
+ }
+ }
+ fpn = (unsigned long *)fpp;
+ }
+}
diff -Nur linux-3.4.113.orig/arch/nds32/kernel/sys_nds32.c linux-3.4.113/arch/nds32/kernel/sys_nds32.c
--- linux-3.4.113.orig/arch/nds32/kernel/sys_nds32.c 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/kernel/sys_nds32.c 2016-12-01 20:59:24.356612904 +0100
@@ -0,0 +1,331 @@
+/*
+ * linux/arch/nds32/kernel/sys_nds32.c
+ *
+ * Copyright (C) People who wrote linux/arch/i386/kernel/sys_i386.c
+ * Copyright (C) 2007 Andes Technology Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This file contains various random system calls that
+ * have a non-standard calling sequence on the Linux/nds32
+ * platform.
+ */
+#include <linux/module.h>
+#include <linux/errno.h>
+#include <linux/sched.h>
+#include <linux/slab.h>
+#include <linux/mm.h>
+#include <linux/sem.h>
+#include <linux/msg.h>
+#include <linux/shm.h>
+#include <linux/stat.h>
+#include <linux/syscalls.h>
+#include <linux/mman.h>
+#include <linux/fs.h>
+#include <linux/file.h>
+#include <linux/utsname.h>
+#include <linux/ipc.h>
+
+#include <asm/uaccess.h>
+#include <asm/unistd.h>
+#include <asm/pfm.h>
+
+extern unsigned long do_mremap(unsigned long addr, unsigned long old_len,
+ unsigned long new_len, unsigned long flags,
+ unsigned long new_addr);
+
+struct mmap_arg_struct {
+ unsigned long addr;
+ unsigned long len;
+ unsigned long prot;
+ unsigned long flags;
+ unsigned long fd;
+ unsigned long offset;
+};
+
+asmlinkage unsigned long sys_mmap2(unsigned long addr, unsigned long len,
+ unsigned long prot, unsigned long flags,
+ unsigned long fd, unsigned long pgoff)
+{
+ if (pgoff & (~PAGE_MASK >> 12))
+ return -EINVAL;
+
+ return sys_mmap_pgoff(addr, len, prot, flags, fd,
+ pgoff >> (PAGE_SHIFT - 12));
+}
+
+asmlinkage unsigned long
+sys_nds32_mremap(unsigned long addr, unsigned long old_len,
+ unsigned long new_len, unsigned long flags,
+ unsigned long new_addr)
+{
+ unsigned long ret = -EINVAL;
+
+ if (flags & MREMAP_FIXED && new_addr < FIRST_USER_ADDRESS)
+ goto out;
+
+ down_write(¤t->mm->mmap_sem);
+ ret = do_mremap(addr, old_len, new_len, flags, new_addr);
+ up_write(¤t->mm->mmap_sem);
+
+out:
+ return ret;
+}
+
+/*
+ * Perform the select(nd, in, out, ex, tv) and mmap() system
+ * calls.
+ */
+
+struct sel_arg_struct {
+ unsigned long n;
+ fd_set __user *inp, *outp, *exp;
+ struct timeval __user *tvp;
+};
+
+asmlinkage int old_select(struct sel_arg_struct __user * arg)
+{
+ struct sel_arg_struct a;
+
+ if (copy_from_user(&a, arg, sizeof(a)))
+ return -EFAULT;
+ /* sys_select() does the appropriate kernel locking */
+ return sys_select(a.n, a.inp, a.outp, a.exp, a.tvp);
+}
+
+/*
+ * sys_ipc() is the de-multiplexer for the SysV IPC calls..
+ *
+ * This is really horribly ugly.
+ */
+asmlinkage long sys_ipc(unsigned int call, int first, unsigned long second,
+ unsigned long third, void __user * ptr, long fifth)
+{
+ int version, ret;
+
+ version = call >> 16; /* hack for backward compatibility */
+ call &= 0xffff;
+
+ switch (call) {
+ case SEMOP:
+ return sys_semtimedop(first, (struct sembuf __user *)ptr,
+ second, NULL);
+ case SEMTIMEDOP:
+ return sys_semtimedop(first, (struct sembuf __user *)ptr,
+ second,
+ (const struct timespec __user *)fifth);
+
+ case SEMGET:
+ return sys_semget(first, second, third);
+ case SEMCTL:{
+ union semun fourth;
+ if (!ptr)
+ return -EINVAL;
+ if (get_user(fourth.__pad, (void __user * __user *)ptr))
+ return -EFAULT;
+ return sys_semctl(first, second, third, fourth);
+ }
+
+ case MSGSND:
+ return sys_msgsnd(first, (struct msgbuf __user *)ptr,
+ second, third);
+ case MSGRCV:
+ switch (version) {
+ case 0:{
+ struct ipc_kludge tmp;
+ if (!ptr)
+ return -EINVAL;
+ if (copy_from_user
+ (&tmp, (struct ipc_kludge __user *)ptr,
+ sizeof(tmp)))
+ return -EFAULT;
+ return sys_msgrcv(first, tmp.msgp, second,
+ tmp.msgtyp, third);
+ }
+ default:
+ return sys_msgrcv(first,
+ (struct msgbuf __user *)ptr,
+ second, fifth, third);
+ }
+ case MSGGET:
+ return sys_msgget((key_t) first, second);
+ case MSGCTL:
+ return sys_msgctl(first, second, (struct msqid_ds __user *)ptr);
+
+ case SHMAT:
+ switch (version) {
+ default:{
+ ulong raddr;
+ ret =
+ do_shmat(first, (char __user *)ptr, second,
+ &raddr);
+ if (ret)
+ return ret;
+ return put_user(raddr, (ulong __user *) third);
+ }
+ case 1: /* Of course, we don't support iBCS2! */
+ return -EINVAL;
+ }
+ case SHMDT:
+ return sys_shmdt((char __user *)ptr);
+ case SHMGET:
+ return sys_shmget(first, second, third);
+ case SHMCTL:
+ return sys_shmctl(first, second, (struct shmid_ds __user *)ptr);
+ default:
+ return -ENOSYS;
+ }
+}
+
+/* Fork a new task - this creates a new program thread.
+ * This is called indirectly via a small wrapper
+ */
+asmlinkage int sys_fork(struct pt_regs *regs)
+{
+ return do_fork(SIGCHLD, regs->NDS32_sp, regs, 0, NULL, NULL);
+}
+
+/* Clone a task - this clones the calling program thread.
+ * This is called indirectly via a small wrapper
+ */
+asmlinkage int sys_clone(unsigned long clone_flags, unsigned long newsp,
+ int __user * parent_tidptr, int tls_val,
+ int __user * child_tidptr, struct pt_regs *regs)
+{
+ if (!newsp)
+ newsp = regs->NDS32_sp;
+
+ return do_fork(clone_flags, newsp, regs, 0, parent_tidptr,
+ child_tidptr);
+}
+
+asmlinkage int sys_vfork(struct pt_regs *regs)
+{
+ return do_fork(CLONE_VFORK | CLONE_VM | SIGCHLD, regs->NDS32_sp, regs,
+ 0, NULL, NULL);
+}
+
+/* sys_execve() executes a new program.
+ * This is called indirectly via a small wrapper
+ */
+asmlinkage int sys_execve(const char __user * filenamei,
+ const char __user * const __user * argv,
+ const char __user * const __user * envp,
+ struct pt_regs *regs)
+{
+ int error;
+ char *filename;
+
+ filename = getname(filenamei);
+ error = PTR_ERR(filename);
+ if (IS_ERR(filename))
+ goto out;
+
+ error = do_execve(filename, argv, envp, regs);
+ putname(filename);
+
+out:
+ return error;
+}
+
+asmlinkage unsigned long sys_getpagesize(void)
+{
+ return PAGE_SIZE; /* Possibly older binaries want 8192 on sun4's? */
+}
+
+int kernel_execve(const char *filename, const char *const argv[],
+ const char *const envp[])
+{
+ struct pt_regs regs;
+ int ret;
+
+ memset(®s, 0, sizeof(struct pt_regs));
+ ret = do_execve(filename, argv, envp, ®s);
+
+ if (ret < 0) {
+ goto out;
+ }
+ /*
+ * Save argc to the register structure for userspace.
+ */
+ regs.NDS32_r0 = ret;
+
+ /*
+ * We were successful. We won't be returning to our caller, but
+ * instead to user space by manipulating the kernel stack.
+ */
+ asm("addi $r0, %0, %1\n\t"
+ "move $r1, %2\n\t"
+ "move $r2, %3\n\t"
+ "bal memmove\n\t" /* copy regs to top of stack */
+ "move $r8, #0\n\t" /* not a syscall */
+ "move $r9, %0\n\t" /* thread structure */
+ "move $sp, $r0\n\t" /* reposition stack pointer */
+"b resume_userspace":
+: "r"(current_thread_info()),
+ "ir"(THREAD_SIZE - 8 - sizeof(regs)),
+ "r"(®s), "ir"(sizeof(regs))
+#ifdef _GCC444
+: "$r0", "$r1", "$r2", "$r4", "$r5", "$r8", "$r9", "$p0", "$p1",
+ "memory");
+#else
+: "$r0", "$r1", "$r2", "$r4", "$r5", "$r8", "$r9", "$r26", "$r27",
+ "memory");
+#endif
+out:
+ return ret;
+}
+
+EXPORT_SYMBOL(kernel_execve);
+
+int sys_cacheflush(unsigned int start, unsigned int end)
+{
+ struct vm_area_struct *vma;
+
+ vma = find_vma(current->mm, start);
+ if (!vma)
+ return 0;
+ cpu_cache_wbinval_range_check(vma, start, end);
+ return 0;
+}
+
+asmlinkage long sys_fadvise64_64_wrapper(int fd, int advice, loff_t offset,
+ loff_t len)
+{
+ return sys_fadvise64_64(fd, offset, len, advice);
+}
+
+asmlinkage int nds32_syscall(int number, struct pt_regs *regs)
+{
+ switch (number) {
+ case 0x7000: /* cacheflush */
+ return sys_cacheflush(regs->NDS32_r1, regs->NDS32_r2);
+
+#ifdef CONFIG_OPROFILE
+ case __NR_pfmctl:
+ sys_pfmctl(regs->NDS32_r1, regs->NDS32_r2, regs->NDS32_r3,
+ regs->NDS32_r4);
+ return 0;
+
+ case __NR_getpfm:
+ return sys_getpfm((struct pcounter __user *)regs->NDS32_r1);
+
+ case __NR_setpfm:
+ return sys_setpfm(regs->NDS32_r1, regs->NDS32_r2,
+ regs->NDS32_r3,
+ (struct pcounter __user *)regs->NDS32_r4);
+#endif
+ case __NR_wbna:
+ if (regs->NDS32_r1)
+ regs->NDS32_ipsw |= PSW_mskWBNA;
+ else
+ regs->NDS32_ipsw &= ~PSW_mskWBNA;
+ return 0;
+
+ default:
+ return -ENOSYS;
+ }
+ return -ENOSYS;
+}
diff -Nur linux-3.4.113.orig/arch/nds32/kernel/time.c linux-3.4.113/arch/nds32/kernel/time.c
--- linux-3.4.113.orig/arch/nds32/kernel/time.c 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/kernel/time.c 2016-12-01 20:59:24.356612904 +0100
@@ -0,0 +1,94 @@
+/*
+ * linux/arch/nds32/kernel/time.c
+ *
+ * Copyright (C) 1991, 1992, 1995 Linus Torvalds
+ * Modifications for ARM (C) 1994-2001 Russell King
+ * Copyright (C) 2009 Andes Technology Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This file contains the ARM-specific time handling details:
+ * reading the RTC at bootup, etc...
+ *
+ * 1994-07-02 Alan Modra
+ * fixed set_rtc_mmss, fixed time.year for >= 2000, new mktime
+ * 1998-12-20 Updated NTP code according to technical memorandum Jan '96
+ * "A Kernel Model for Precision Timekeeping" by Dave Mills
+ */
+#include <linux/sched.h>
+#include <linux/profile.h>
+#include <linux/timer.h>
+#include <asm/irq_regs.h>
+#include <linux/syscore_ops.h>
+
+#include <asm/mach/arch.h>
+#include <asm/mach/time.h>
+
+/*
+ * Our system timer.
+ */
+struct sys_timer *system_timer;
+
+#ifdef CONFIG_SMP
+unsigned long profile_pc(struct pt_regs *regs)
+{
+ unsigned long fp, pc = instruction_pointer(regs);
+
+ if (in_lock_functions(pc)) {
+ fp = regs->NDS32_fp;
+ pc = ((unsigned long *)fp)[-1];
+ }
+
+ return pc;
+}
+
+EXPORT_SYMBOL(profile_pc);
+#endif
+#if defined(CONFIG_PM) && !defined(CONFIG_GENERIC_CLOCKEVENTS)
+static int timer_suspend(void)
+{
+ if (system_timer->suspend)
+ system_timer->suspend();
+
+ return 0;
+}
+
+static void timer_resume(void)
+{
+ if (system_timer->resume)
+ system_timer->resume();
+}
+#else
+#define timer_suspend NULL
+#define timer_resume NULL
+#endif
+#ifdef CONFIG_ARCH_USES_GETTIMEOFFSET
+u32 arch_gettimeoffset(void)
+{
+ if (system_timer->offset != NULL)
+ return system_timer->offset() * 1000;
+
+ return 0;
+}
+#endif /* CONFIG_ARCH_USES_GETTIMEOFFSET */
+static struct syscore_ops timer_syscore_ops = {
+ .suspend = timer_suspend,
+ .resume = timer_resume,
+};
+
+static int __init timer_init_syscore_ops(void)
+{
+ register_syscore_ops(&timer_syscore_ops);
+
+ return 0;
+}
+
+device_initcall(timer_init_syscore_ops);
+
+void __init time_init(void)
+{
+ system_timer = machine_desc->timer;
+ system_timer->init(); // link to cpe_timer_init
+}
diff -Nur linux-3.4.113.orig/arch/nds32/kernel/traps.c linux-3.4.113/arch/nds32/kernel/traps.c
--- linux-3.4.113.orig/arch/nds32/kernel/traps.c 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/kernel/traps.c 2016-12-01 20:59:24.360613059 +0100
@@ -0,0 +1,733 @@
+/*
+ * linux/arch/nds32/kernel/traps.c
+ *
+ * Copyright (C) 1995-2002 Russell King
+ * Fragments that appear the same as linux/arch/i386/kernel/traps.c (C) Linus Torvalds
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * 'traps.c' handles hardware exceptions after we have saved some state in
+ * 'linux/arch/nds32/lib/traps.S'. Mostly a debugging aid, but will probably
+ * kill the offending process.
+ */
+/* ============================================================================
+ *
+ * linux/arch/nds32/kernel/traps.c
+ *
+ * Copyright (C) 2007 Andes Technology Corporation
+ * This file is part of Linux and should be licensed under the GPL.
+ * See the file COPYING for conditions for redistribution.
+ *
+ * Abstract:
+ *
+ * This program is trap handling for NDS32 core, initial refer from ARM.
+ *
+ * Revision History:
+ *
+ * Jul.16.2007 Initial ported by Tom, revised for KGDB by Harry.
+ *
+ * Note:
+ *
+ * ============================================================================
+ */
+#include <linux/module.h>
+#include <linux/personality.h>
+#include <linux/kallsyms.h>
+#include <linux/hardirq.h>
+#include <linux/kdebug.h>
+
+#include <asm/cacheflush.h>
+#include <asm/uaccess.h>
+#include <asm/unistd.h>
+#include <asm/traps.h>
+#include <asm/fpu.h>
+#include <asm/audio.h>
+
+#include <linux/ptrace.h>
+#include <nds32_intrinsic.h>
+#include "ptrace.h"
+#include "signal.h"
+
+extern void show_pte(struct mm_struct *mm, unsigned long addr);
+
+#ifdef CONFIG_DEBUG_USER
+unsigned int user_debug;
+
+static int __init user_debug_setup(char *str)
+{
+ get_option(&str, &user_debug);
+ return 1;
+}
+
+__setup("user_debug=", user_debug_setup);
+#endif
+
+/*
+ * Dump out the contents of some memory nicely...
+ */
+void dump_mem(const char *str, unsigned long bottom, unsigned long top)
+{
+ unsigned long p = bottom & ~31;
+ mm_segment_t fs;
+ int i;
+
+ /*
+ * We need to switch to kernel mode so that we can use __get_user
+ * to safely read from kernel space. Note that we now dump the
+ * code first, just in case the backtrace kills us.
+ */
+ fs = get_fs();
+ set_fs(KERNEL_DS);
+
+ printk("%s(0x%08lx to 0x%08lx)\n", str, bottom, top);
+
+ for (p = bottom & ~31; p < top;) {
+ printk("%04lx: ", p & 0xffff);
+
+ for (i = 0; i < 8; i++, p += 4) {
+ unsigned int val;
+
+ if (p < bottom || p >= top)
+ printk(" ");
+ else {
+ __get_user(val, (unsigned long *)p);
+ printk("%08x ", val);
+ }
+ }
+ printk("\n");
+ }
+
+ set_fs(fs);
+}
+
+EXPORT_SYMBOL(dump_mem);
+
+/* These intrinsic functions are not supported in V2 toolchains of BSP321. */
+#ifndef __NDS32_BASELINE_V2__
+#define DEBUG_TLB_CACHE
+#endif
+#ifdef DEBUG_TLB_CACHE
+/* This is the number of TLB entries. User should change it if necessary. */
+#define TLB_NUM 128
+unsigned int tlb_misc_new[TLB_NUM], tlb_vpn_new[TLB_NUM], tlb_data_new[TLB_NUM];
+/* To get the whole TLB contents once it uses va=0x0 */
+void dump_tlb(unsigned long va)
+{
+ unsigned int rd_num, tlb_vpn, tlb_misc, tlb_data, mmu_cfg, tlb_num;
+
+ /* save tlb system registers */
+ tlb_vpn = __nds32__mfsr(NDS32_SR_TLB_VPN);
+ tlb_misc = __nds32__mfsr(NDS32_SR_TLB_MISC);
+ tlb_data = __nds32__mfsr(NDS32_SR_TLB_DATA);
+ mmu_cfg = __nds32__mfsr(NDS32_SR_MMU_CFG);
+ tlb_num =
+ (((mmu_cfg & MMU_CFG_mskTBW) >> MMU_CFG_offTBW) +
+ 1) * (1 << (((mmu_cfg & MMU_CFG_mskTBS) >> MMU_CFG_offTBS) + 2));
+
+ for (rd_num = 0; rd_num < tlb_num; rd_num++) {
+ /* read tlb entry with index */
+ __nds32__tlbop_trd(rd_num);
+ __nds32__dsb();
+ tlb_vpn_new[rd_num] = __nds32__mfsr(NDS32_SR_TLB_VPN);
+ tlb_misc_new[rd_num] = __nds32__mfsr(NDS32_SR_TLB_MISC);
+ tlb_data_new[rd_num] = __nds32__mfsr(NDS32_SR_TLB_DATA);
+ }
+
+ /* restore tlb system registers */
+ __nds32__mtsr(tlb_vpn, NDS32_SR_TLB_VPN);
+ __nds32__mtsr(tlb_misc, NDS32_SR_TLB_MISC);
+ __nds32__dsb();
+
+ printk("cur VPN:%08x, MISC:%08x, DATA:%08x\n", tlb_vpn, tlb_misc,
+ tlb_data);
+ /* to read out all the data */
+ for (rd_num = 0; rd_num < tlb_num; rd_num++) {
+ /*unsigned int vpn = tlb_vpn_new[rd_num] & PAGE_MASK; */
+ if (tlb_data_new[rd_num] & 0x1)
+ if (va == 0x0
+ || (va != 0x0
+ && (tlb_vpn_new[rd_num] == (va & PAGE_MASK))))
+ printk
+ ("idx:0x%08x, VPN:%08x, MISC:%08x, DATA:%08x\n",
+ rd_num, tlb_vpn_new[rd_num],
+ tlb_misc_new[rd_num],
+ tlb_data_new[rd_num]);
+ }
+}
+
+EXPORT_SYMBOL(dump_tlb);
+
+struct cache_element {
+ unsigned int pa;
+ unsigned int wd;
+ unsigned int cacheline[8];
+ unsigned char dirty;
+ unsigned char valid;
+ unsigned char lock;
+};
+
+/* This is the number of cache entries. User should change it if necessary. */
+#define CACHE_SET_NUM 0x100
+#define CACHE_WAY_NUM 0x4
+volatile struct cache_element ce[CACHE_SET_NUM][CACHE_WAY_NUM];
+#define CCTL_mskDIRTY 0x400000
+#define CCTL_offDIRTY 22
+#define CCTL_mskVALID 0x2
+#define CCTL_offVALID 1
+#define CCTL_mskLOCK 0x1
+#define CCTL_offLOCK 0
+#define CCTL_mskTAG 0x3ffffc
+#define CCTL_offTAG 0x2
+extern unsigned long va2idx(unsigned long va, unsigned int cache_type,
+ unsigned long *way_offset);
+#include <asm/cache_info.h>
+extern struct cache_info L1_cache_info[2];
+void dump_cache(unsigned int cache_type)
+{
+ volatile unsigned long idx, way, ra, tag, i;
+ unsigned long sets, ways, line_size, set_bits, way_bits, line_bits,
+ way_offset;
+
+ ways = L1_cache_info[DCACHE].ways;
+ sets = L1_cache_info[DCACHE].sets;
+ set_bits = L1_cache_info[cache_type].set_bits;
+ way_bits = L1_cache_info[cache_type].way_bits;
+ line_bits = L1_cache_info[cache_type].line_bits;
+ line_size = L1_cache_info[cache_type].line_size;
+ way_offset = set_bits + line_bits;
+
+ if (cache_type != ICACHE && cache_type != DCACHE) {
+ printk("%s not supported cache_type:%x\n", __func__,
+ cache_type);
+ return;
+ }
+
+ /* NDS32_CCTL_L1I_IX_RTAG Read tag L1I cache */
+ /* NDS32_CCTL_L1I_IX_RWD Read word data L1I cache */
+
+ for (idx = 0; idx < sets; idx++) {
+ for (way = 0; way < ways; way++) {
+ ra = (way << way_offset) | (idx << line_bits);
+ if (cache_type == ICACHE)
+ tag =
+ __nds32__cctlidx_read
+ (NDS32_CCTL_L1I_IX_RTAG, ra);
+ else
+ tag =
+ __nds32__cctlidx_read
+ (NDS32_CCTL_L1D_IX_RTAG, ra);
+ ce[idx][way].dirty =
+ (unsigned char)(tag & CCTL_mskDIRTY) >>
+ CCTL_offDIRTY;
+ ce[idx][way].valid =
+ (unsigned char)(tag & CCTL_mskVALID) >>
+ CCTL_offVALID;
+ ce[idx][way].lock =
+ (unsigned char)(tag & CCTL_mskLOCK) >> CCTL_offLOCK;
+ ce[idx][way].pa =
+ (tag & CCTL_mskTAG) >> CCTL_offTAG << PAGE_SHIFT;
+ for (i = 0; i < line_size / 4; i++) {
+ if (cache_type == ICACHE)
+ ce[idx][way].cacheline[i] =
+ __nds32__cctlidx_read
+ (NDS32_CCTL_L1I_IX_RWD,
+ (ra | i << 2));
+ else
+ ce[idx][way].cacheline[i] =
+ __nds32__cctlidx_read
+ (NDS32_CCTL_L1D_IX_RWD,
+ (ra | i << 2));
+ }
+ }
+ }
+ printk("dump %s\n", cache_type ? "DCACHE" : "ICACHE");
+ printk("%8s %4s %4s %1s %1s %1s %8s %8s %8s %8s %8s %8s %8s %8s\n",
+ "ADDRESS", "SET", "WAY", "V", "D", "L", "00", "04", "08", "0C",
+ "10", "14", "18", "1C");
+ for (idx = 0; idx < sets; idx++) {
+ for (way = 0; way < ways; way++) {
+ printk("%08lx %04lx %04lx %1u %1u %1u ",
+ ce[idx][way].pa +
+ ((idx * line_size) % PAGE_SIZE), idx, way,
+ ce[idx][way].valid, ce[idx][way].dirty,
+ ce[idx][way].lock);
+ for (i = 0; i < line_size / 4; i++) {
+ printk("%08x ", ce[idx][way].cacheline[i]);
+ }
+ printk("\n");
+ }
+ }
+}
+
+EXPORT_SYMBOL(dump_cache);
+
+void dump_cache_va(unsigned int cache_type, unsigned int va)
+{
+ volatile struct cache_element cache_entry[4];
+ volatile unsigned long idx, way, tag, ra, i;
+ unsigned long ways, line_size, set_bits, line_bits, way_offset;
+
+ ways = L1_cache_info[cache_type].ways;
+ line_size = CACHE_LINE_SIZE(cache_type);
+ set_bits = L1_cache_info[cache_type].set_bits;
+ line_bits = L1_cache_info[cache_type].line_bits;
+
+ if (cache_type != ICACHE && cache_type != DCACHE) {
+ printk("%s not supported cache_type:%x\n", __func__,
+ cache_type);
+ return;
+ }
+ idx = va2idx(va, cache_type, &way_offset);
+ //idx = (va & (((1 << set_bits) - 1) << line_bits)) >> line_bits;
+ for (way = 0; way < ways; way++) {
+ ra = (way << way_offset) | idx;
+ if (cache_type == ICACHE)
+ tag = __nds32__cctlidx_read(NDS32_CCTL_L1I_IX_RTAG, ra);
+ else
+ tag = __nds32__cctlidx_read(NDS32_CCTL_L1D_IX_RTAG, ra);
+ cache_entry[way].dirty =
+ (unsigned char)(tag & CCTL_mskDIRTY) >> CCTL_offDIRTY;
+ cache_entry[way].valid =
+ (unsigned char)(tag & CCTL_mskVALID) >> CCTL_offVALID;
+ cache_entry[way].lock =
+ (unsigned char)(tag & CCTL_mskLOCK) >> CCTL_offLOCK;
+ cache_entry[way].pa =
+ (tag & CCTL_mskTAG) >> CCTL_offTAG << PAGE_SHIFT;
+ for (i = 0; i < line_size / 4; i++) {
+ if (cache_type == ICACHE)
+ cache_entry[way].cacheline[i] =
+ __nds32__cctlidx_read(NDS32_CCTL_L1I_IX_RWD,
+ (ra | i << 2));
+ else
+ cache_entry[way].cacheline[i] =
+ __nds32__cctlidx_read(NDS32_CCTL_L1D_IX_RWD,
+ (ra | i << 2));
+ }
+ }
+ printk("dump %s va:%x\n", cache_type ? "DCACHE" : "ICACHE", va);
+
+ printk("%8s %4s %4s %1s %1s %1s %8s %8s %8s %8s %8s %8s %8s %8s\n",
+ "ADDRESS", "SET", "WAY", "V", "D", "L", "00", "04", "08", "0C",
+ "10", "14", "18", "1C");
+ for (way = 0; way < ways; way++) {
+ printk("%08lx %04lx %04lx %1u %1u %1u ",
+ cache_entry[way].pa +
+ (((idx >> line_bits) * line_size) % PAGE_SIZE),
+ (idx >> line_bits), way, cache_entry[way].valid,
+ cache_entry[way].dirty, cache_entry[way].lock);
+ for (i = 0; i < 8; i++) {
+ printk("%08x ", cache_entry[way].cacheline[i]);
+ }
+ printk("\n");
+ }
+}
+
+EXPORT_SYMBOL(dump_cache_va);
+#endif
+
+static void dump_instr(struct pt_regs *regs)
+{
+ unsigned long addr = instruction_pointer(regs);
+ const int width = 8;
+ mm_segment_t fs;
+ int i;
+
+ return;
+ /*
+ * We need to switch to kernel mode so that we can use __get_user
+ * to safely read from kernel space. Note that we now dump the
+ * code first, just in case the backtrace kills us.
+ */
+ fs = get_fs();
+ set_fs(KERNEL_DS);
+
+ printk("Code: ");
+ for (i = -4; i < 1; i++) {
+ unsigned int val, bad;
+
+ bad = __get_user(val, &((u32 *) addr)[i]);
+
+ if (!bad)
+ printk(i == 0 ? "(%0*x) " : "%0*x ", width, val);
+ else {
+ printk("bad PC value.");
+ break;
+ }
+ }
+ printk("\n");
+
+ set_fs(fs);
+}
+
+#define LOOP_TIMES (100)
+void dump_stack(void)
+{
+ int cnt = LOOP_TIMES;
+#ifndef CONFIG_FRAME_POINTER
+ unsigned long *stack;
+ unsigned long addr;
+
+ __asm__ __volatile__("\tori\t%0, $sp, #0\n":"=r"(stack));
+ printk("Call Trace:\n");
+ while (!kstack_end(stack)) {
+ addr = *stack++;
+ if (__kernel_text_address(addr)) {
+ printk("[<%08lx>] ", addr);
+ print_symbol("%s\n", addr);
+ }
+ cnt--;
+ if (cnt < 0)
+ break;
+ }
+ printk("\n");
+#else
+ unsigned long *fpn;
+ __asm__ __volatile__("\tori\t%0, $fp, #0\n":"=r"(fpn));
+ printk("Call Trace:\n");
+ while (!kstack_end((void *)fpn) && !((unsigned long)fpn & 0x3)
+ && ((unsigned long)fpn >= TASK_SIZE)) {
+ unsigned long lpp, fpp;
+#if !defined(NDS32_ABI_2)
+ lpp = fpn[0];
+ fpp = fpn[1];
+#else
+ lpp = fpn[0];
+ fpp = fpn[-1];
+#endif
+ if (__kernel_text_address(lpp)) {
+ printk("[<%08lx>] ", lpp);
+ print_symbol("%s\n", lpp);
+ fpn = (unsigned long *)fpp;
+ }
+ cnt--;
+ if (cnt < 0)
+ break;
+ }
+ printk("\n");
+#endif
+}
+
+EXPORT_SYMBOL(dump_stack);
+
+void show_stack(struct task_struct *tsk, unsigned long *sp)
+{
+ unsigned long fp;
+
+ if (!tsk)
+ tsk = current;
+
+ if (tsk != current)
+ fp = thread_saved_fp(tsk);
+ else
+ asm("move %0, $fp":"=r"(fp));
+
+ dump_stack();
+ barrier();
+}
+
+DEFINE_SPINLOCK(die_lock);
+
+/*
+ * This function is protected against re-entrancy.
+ */
+void die(const char *str, struct pt_regs *regs, int err)
+{
+ struct task_struct *tsk = current;
+ static int die_counter;
+
+ console_verbose();
+ spin_lock_irq(&die_lock);
+ bust_spinlocks(1);
+
+ printk("Internal error: %s: %x [#%d]\n", str, err, ++die_counter);
+ print_modules();
+ printk("CPU: %i\n", smp_processor_id());
+ show_regs(regs);
+ printk("Process %s (pid: %d, stack limit = 0x%p)\n",
+ tsk->comm, tsk->pid, task_thread_info(tsk) + 1);
+
+ if (!user_mode(regs) || in_interrupt()) {
+ dump_mem("Stack: ", regs->NDS32_sp,
+ 8192 + (unsigned long)task_thread_info(tsk));
+ dump_instr(regs);
+ dump_stack();
+ }
+
+ bust_spinlocks(0);
+ spin_unlock_irq(&die_lock);
+ do_exit(SIGSEGV);
+}
+
+void die_if_kernel(const char *str, struct pt_regs *regs, int err)
+{
+ if (user_mode(regs))
+ return;
+
+ die(str, regs, err);
+}
+
+int bad_syscall(int n, struct pt_regs *regs)
+{
+ struct thread_info *thread = current_thread_info();
+ siginfo_t info;
+
+ if (current->personality != PER_LINUX && thread->exec_domain->handler) {
+ thread->exec_domain->handler(n, regs);
+ return regs->NDS32_r0;
+ }
+#ifdef CONFIG_DEBUG_USER
+ if (user_debug & UDBG_SYSCALL) {
+ printk(KERN_ERR "[%d] %s: obsolete system call %08x.\n",
+ current->pid, current->comm, n);
+ dump_instr(regs);
+ }
+#endif
+
+ info.si_signo = SIGILL;
+ info.si_errno = 0;
+ info.si_code = ILL_ILLTRP;
+ info.si_addr = (void __user *)instruction_pointer(regs) - 4;
+
+ force_sig_info(SIGILL, &info, current);
+ die_if_kernel("Oops - bad syscall", regs, n);
+ return regs->NDS32_r0;
+}
+
+void __pte_error(const char *file, int line, unsigned long val)
+{
+ printk("%s:%d: bad pte %08lx.\n", file, line, val);
+}
+
+void __pmd_error(const char *file, int line, unsigned long val)
+{
+ printk("%s:%d: bad pmd %08lx.\n", file, line, val);
+}
+
+void __pgd_error(const char *file, int line, unsigned long val)
+{
+ printk("%s:%d: bad pgd %08lx.\n", file, line, val);
+}
+
+extern char exception_vector[73][64];
+void __init trap_init(void)
+{
+ return;
+}
+
+void __init early_trap_init(void)
+{
+ unsigned long ivb = 0;
+ unsigned long base = 0xc0000000;
+
+ memcpy((unsigned long *)base, (unsigned long *)exception_vector,
+ sizeof(exception_vector));
+ ivb = __nds32__mfsr(NDS32_SR_IVB);
+#ifdef CONFIG_EVIC
+ __nds32__mtsr((ivb & ~IVB_mskESZ) | (2 << IVB_offESZ) |
+ (1 << IVB_offEVIC) | IVB_BASE, NDS32_SR_IVB);
+#else
+ /* Check platform support. */
+# if defined (CONFIG_IVIC_INTC)
+ if (((ivb & IVB_mskNIVIC) >> IVB_offNIVIC) >= 2)
+ panic
+ ("IVIC mode is not allowed on the platform with interrupt controller\n");
+# elif defined(CONFIG_IVIC)
+ if (((ivb & IVB_mskNIVIC) >> IVB_offNIVIC) < 2)
+ panic
+ ("IVIC mode is not allowed on the platform without interrupt controller\n");
+# endif
+ __nds32__mtsr((ivb & ~IVB_mskESZ) | (2 << IVB_offESZ) | IVB_BASE,
+ NDS32_SR_IVB);
+#endif
+ __nds32__mtsr(0x10003, NDS32_SR_INT_MASK);
+ /*
+ * Copy signal return handlers into the vector page, and
+ * set sigreturn to be a pointer to these.
+ */
+ memcpy((void *)KERN_SIGRETURN_CODE, retcodes, sizeof(retcodes));
+ memcpy((void *)KERN_RESTART_CODE, syscall_restart_code,
+ sizeof(syscall_restart_code));
+
+ /*
+ * 0x2000 is 8K-aligned of 0x1240 = 73 vectors * 64byte
+ * 0x1000 is page saving sigreturn & restart code
+ */
+ flush_icache_range(base, base + 0x3000);
+}
+
+#if 0
+COLE:use send_sigtrap instread
+ static __inline__ void do_trap(int trapnr, int signr, const char *str,
+ struct pt_regs *regs,
+ unsigned long error_code, siginfo_t * info)
+{
+ if (user_mode(regs)) {
+ /* trap_signal */
+ struct task_struct *tsk = current;
+ tsk->thread.error_code = error_code;
+ tsk->thread.trap_no = trapnr;
+ if (info)
+ force_sig_info(signr, info, tsk);
+ else
+ force_sig(signr, tsk);
+ return;
+ } else {
+ /* kernel_trap */
+ if (!fixup_exception(regs))
+ die(str, regs, error_code);
+ return;
+ }
+}
+#endif
+
+/*
+ * I modified original debug_trap to apply KGDB stuff,
+ * Harry@Jul.18.2007
+ */
+void do_debug_trap(unsigned long entry, unsigned long addr,
+ unsigned long type, struct pt_regs *regs)
+{
+ if (notify_die(DIE_DEBUG, "debug", regs, addr, type, SIGTRAP)
+ == NOTIFY_STOP)
+ return;
+
+#if !defined(CONFIG_HSS)
+ /* clear the swbk; otherwise the user will see it */
+ if (test_tsk_thread_flag(current, TIF_SINGLESTEP))
+ ptrace_cancel_swbk(current);
+#endif
+
+ /* do_trap(1, SIGTRAP, 0, regs, 0, NULL); */
+ if (user_mode(regs)) {
+ /* trap_signal */
+ send_sigtrap(current, regs, 0, TRAP_BRKPT);
+ } else {
+ /* kernel_trap */
+ if (!fixup_exception(regs))
+ die("unexpected kernel_trap", regs, 0);
+ }
+}
+
+void unhandled_interruption(struct pt_regs *regs)
+{
+ siginfo_t si;
+ printk("unhandled_interruption\n");
+ show_regs(regs);
+ if (!user_mode(regs))
+ do_exit(SIGKILL);
+ si.si_signo = SIGKILL;
+ si.si_errno = 0;
+ force_sig_info(SIGKILL, &si, current);
+}
+
+void unhandled_exceptions(unsigned long entry, unsigned long addr,
+ unsigned long type, struct pt_regs *regs)
+{
+ siginfo_t si;
+ printk("Unhandled Exception: entry: %lx addr:%lx itype:%lx\n", entry,
+ addr, type);
+ show_regs(regs);
+ if (!user_mode(regs))
+ do_exit(SIGKILL);
+ si.si_signo = SIGKILL;
+ si.si_errno = 0;
+ si.si_addr = (void *)addr;
+ force_sig_info(SIGKILL, &si, current);
+}
+
+extern int do_page_fault(unsigned long entry, unsigned long addr,
+ unsigned int error_code, struct pt_regs *regs);
+
+/*
+ * 2:DEF dispatch for TLB MISC exception handler
+*/
+
+void do_dispatch_tlb_misc(unsigned long entry, unsigned long addr,
+ unsigned long type, struct pt_regs *regs)
+{
+ type = type & (ITYPE_mskINST | ITYPE_mskETYPE);
+ if ((type & 0xf) < 5)
+ do_page_fault(entry, addr, type, regs);
+ else
+ unhandled_exceptions(entry, addr, type, regs);
+}
+
+int (*do_unaligned_access) (unsigned long entry, unsigned long addr,
+ unsigned long type, struct pt_regs * regs) = NULL;
+
+EXPORT_SYMBOL(do_unaligned_access);
+
+void do_revinsn(struct pt_regs *regs)
+{
+ siginfo_t si;
+ printk("Reserved Instruction\n");
+ show_regs(regs);
+ if (!user_mode(regs))
+ do_exit(SIGILL);
+ si.si_signo = SIGILL;
+ si.si_errno = 0;
+ force_sig_info(SIGILL, &si, current);
+}
+
+/*
+ * 7:DEF dispatch for General exception handler
+ */
+void do_dispatch_general(unsigned long entry, unsigned long addr,
+ unsigned long itype, struct pt_regs *regs,
+ unsigned long oipc)
+{
+ unsigned int swid = itype >> ITYPE_offSWID;
+ unsigned long type = itype & (ITYPE_mskINST | ITYPE_mskETYPE);
+ if (type == 0) { /* Alignment check */
+
+ if (do_unaligned_access) {
+
+ int ret = do_unaligned_access(entry, addr, type, regs);
+
+ if (ret == 0)
+ return;
+
+ if (ret == -EFAULT)
+ printk
+ ("Unhandled unaligned access exception\n");
+ }
+ do_page_fault(entry, addr, type, regs);
+ } else if (type == 1) /* Reserved instruction */
+ do_revinsn(regs);
+ else if (type == 6) { /* Coprocessor */
+ if (((GET_ITYPE() & ITYPE_mskSTYPE) >> ITYPE_offSTYPE) == 3) {
+#ifdef CONFIG_AUDIO
+ preempt_disable();
+ do_audio_context_switch(type, regs);
+ preempt_enable();
+#else
+ unhandled_exceptions(entry, addr, type, regs);
+#endif
+ } else {
+#ifdef CONFIG_FPU
+ do_fpu_exception(type, regs);
+#else
+ unhandled_exceptions(entry, addr, type, regs);
+#endif
+ }
+ } else if (type == 2 && swid == 0x1a) {
+ /* trap, used on v3 EDM target debugging workaround */
+ /*
+ * DIPC(OIPC) is passed as parameter before
+ * interrupt is enabled, so the DIPC will not be corrupted
+ * even though interrupts are coming in
+ */
+ /*
+ * 1. update ipc
+ * 2. update pt_regs ipc with oipc
+ * 3. update pt_regs ipsw (clear DEX)
+ */
+ __asm__ volatile ("mtsr %0, $IPC\n\t"::"r" (oipc));
+ regs->NDS32_ipc = oipc;
+ regs->NDS32_ipsw &= ~0x400;
+ do_debug_trap(entry, addr, itype, regs);
+ } else
+ unhandled_exceptions(entry, addr, type, regs);
+}
diff -Nur linux-3.4.113.orig/arch/nds32/kernel/vmlinux.lds.S linux-3.4.113/arch/nds32/kernel/vmlinux.lds.S
--- linux-3.4.113.orig/arch/nds32/kernel/vmlinux.lds.S 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/kernel/vmlinux.lds.S 2016-12-01 20:59:24.360613059 +0100
@@ -0,0 +1,74 @@
+#include <asm/page.h>
+#include <asm/thread_info.h>
+#include <asm/cache.h>
+#include <asm/memory.h>
+
+#define LOAD_OFFSET (PAGE_OFFSET - PHYS_OFFSET)
+#include <asm-generic/vmlinux.lds.h>
+
+OUTPUT_ARCH(nds32)
+ENTRY(_stext_lma)
+jiffies = jiffies_64;
+
+SECTIONS
+{
+ _stext_lma = TEXTADDR - LOAD_OFFSET;
+ . = TEXTADDR;
+ __init_begin = .;
+ HEAD_TEXT_SECTION
+ INIT_TEXT_SECTION(PAGE_SIZE)
+ /* These sections are arch specific. */
+ .arch_info : AT(ADDR(.arch_info) - LOAD_OFFSET) {
+ . = ALIGN(4);
+ VMLINUX_SYMBOL(__proc_info_begin) = .;
+ *(.proc.info.init)
+ VMLINUX_SYMBOL(__proc_info_end) = .;
+ __arch_info_begin = .;
+ *(.arch.info)
+ __arch_info_end = .;
+ __tagtable_begin = .;
+ *(.taglist)
+ __tagtable_end = .;
+ . = ALIGN(16);
+ __pv_table_begin = .;
+ *(.pv_table)
+ __pv_table_end = .;
+ __early_begin = .;
+ *(__early_param)
+ __early_end = .;
+ }
+
+ INIT_DATA_SECTION(16)
+ PERCPU_SECTION(L1_CACHE_BYTES)
+ __init_end = .;
+
+ . = ALIGN(PAGE_SIZE);
+ _stext = .;
+ /* Real text segment */
+ .text : AT(ADDR(.text) - LOAD_OFFSET) {
+ _text = .; /* Text and read-only data */
+ TEXT_TEXT
+ SCHED_TEXT
+ LOCK_TEXT
+ KPROBES_TEXT
+ IRQENTRY_TEXT
+ *(.fixup)
+ }
+
+ _etext = .; /* End of text and rodata section */
+
+ _sdata = .;
+ RO_DATA_SECTION(PAGE_SIZE)
+ RW_DATA_SECTION(L1_CACHE_BYTES, PAGE_SIZE, THREAD_SIZE)
+ _edata = .;
+
+ EXCEPTION_TABLE(16)
+ NOTES
+ BSS_SECTION(4, 4, 4)
+ _end = .;
+
+ STABS_DEBUG
+ DWARF_DEBUG
+
+ DISCARDS
+}
diff -Nur linux-3.4.113.orig/arch/nds32/lib/copy_page.S linux-3.4.113/arch/nds32/lib/copy_page.S
--- linux-3.4.113.orig/arch/nds32/lib/copy_page.S 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/lib/copy_page.S 2016-12-01 20:59:24.360613059 +0100
@@ -0,0 +1,36 @@
+/*
+ * linux/arch/nds32/lib/copypage.S
+ * Copyright (C) 2009 Andes Technology Corporation
+ */
+#include <linux/linkage.h>
+#include <asm/page.h>
+
+ .text
+ENTRY(copy_page)
+ pushm $r2, $r10
+ movi $r2, PAGE_SIZE >> 5
+.Lcopy_loop:
+ lmw.bim $r3, [$r1], $r10
+ smw.bim $r3, [$r0], $r10
+ subi45 $r2, #1
+ bnez38 $r2, .Lcopy_loop
+ popm $r2, $r10
+ ret
+
+ENTRY(clear_page)
+ pushm $r1, $r9
+ movi $r1, PAGE_SIZE >> 5
+ movi55 $r2, #0
+ movi55 $r3, #0
+ movi55 $r4, #0
+ movi55 $r5, #0
+ movi55 $r6, #0
+ movi55 $r7, #0
+ movi55 $r8, #0
+ movi55 $r9, #0
+.Lclear_loop:
+ smw.bim $r2, [$r0], $r9
+ subi45 $r1, #1
+ bnez38 $r1, .Lclear_loop
+ popm $r1, $r9
+ ret
diff -Nur linux-3.4.113.orig/arch/nds32/lib/csum_partial.c linux-3.4.113/arch/nds32/lib/csum_partial.c
--- linux-3.4.113.orig/arch/nds32/lib/csum_partial.c 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/lib/csum_partial.c 2016-12-01 20:59:24.360613059 +0100
@@ -0,0 +1,135 @@
+/*
+ * INET An implementation of the TCP/IP protocol suite for the LINUX
+ * operating system. INET is implemented using the BSD Socket
+ * interface as the means of communication with the user level.
+ *
+ * MIPS specific IP/TCP/UDP checksumming routines
+ *
+ * Authors: Ralf Baechle, <ralf@waldorf-gmbh.de>
+ * Lots of code moved from tcp.c and ip.c; see those files
+ * for more names.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version
+ * 2 of the License, or (at your option) any later version.
+ */
+#include <linux/module.h>
+#include <linux/types.h>
+
+#include <net/checksum.h>
+#include <asm/byteorder.h>
+#include <asm/string.h>
+#include <asm/uaccess.h>
+
+#define addc(_t,_r) \
+ __asm__ __volatile__ ( \
+ "add\t%0, %0, %1\n\t" \
+ "slt\t$p1, %0, %1\n\t" \
+ "add\r%0, %0, $p1\n\t" \
+ : "=r"(_t) \
+ : "r"(_r), "0"(_t));
+
+static inline unsigned short from32to16(unsigned int x)
+{
+ /* 32 bits --> 16 bits + carry */
+ x = (x & 0xffff) + (x >> 16);
+ /* 16 bits + carry --> 16 bits including carry */
+ x = (x & 0xffff) + (x >> 16);
+ return (unsigned short)x;
+}
+
+static inline unsigned int do_csum(const unsigned char *buff, int len)
+{
+ int odd;
+ register unsigned int result = 0;
+ register unsigned int count;
+ if (len <= 0)
+ goto out;
+ odd = 1 & (unsigned long)buff;
+ if (odd) {
+ result = be16_to_cpu(*buff);
+ len--;
+ buff++;
+ }
+ count = len >> 1; /* nr of 16-bit words.. */
+ if (count) {
+ if (2 & (unsigned long)buff) {
+ result += *(unsigned short *)buff;
+ count--;
+ len -= 2;
+ buff += 2;
+ }
+ count >>= 1; /* nr of 32-bit words.. */
+ if (count) {
+ while (count >= 8) {
+ __asm__
+ __volatile__("lmw.bi $r17, [%1], $r24\n\t"
+ "add\t%0, %0, $r17\n\t"
+ "slt\t$p1, %0, $r17\n\t"
+ "add\r%0, %0, $p1\n\t"
+ "add\t%0, %0, $r18\n\t"
+ "slt\t$p1, %0, $r18\n\t"
+ "add\r%0, %0, $p1\n\t"
+ "add\t%0, %0, $r19\n\t"
+ "slt\t$p1, %0, $r19\n\t"
+ "add\r%0, %0, $p1\n\t"
+ "add\t%0, %0, $r20\n\t"
+ "slt\t$p1, %0, $r20\n\t"
+ "add\r%0, %0, $p1\n\t"
+ "add\t%0, %0, $r21\n\t"
+ "slt\t$p1, %0, $r21\n\t"
+ "add\r%0, %0, $p1\n\t"
+ "add\t%0, %0, $r22\n\t"
+ "slt\t$p1, %0, $r22\n\t"
+ "add\r%0, %0, $p1\n\t"
+ "add\t%0, %0, $r23\n\t"
+ "slt\t$p1, %0, $r23\n\t"
+ "add\r%0, %0, $p1\n\t"
+ "add\t%0, %0, $r24\n\t"
+ "slt\t$p1, %0, $r24\n\t"
+ "add\r%0, %0, $p1\n\t":"=r"
+ (result)
+ :"r"(buff), "0"(result)
+ :"$r17", "$r18", "$r19",
+ "$r20", "$r21", "$r22", "$r23",
+ "$r24");
+ count -= 8;
+ buff += 32;
+ }
+ while (count) {
+ unsigned int w = *(unsigned int *)buff;
+ count--;
+ buff += 4;
+ addc(result, w);
+ }
+ result = (result & 0xffff) + (result >> 16);
+ }
+ if (len & 2) {
+ result += *(unsigned short *)buff;
+ buff += 2;
+ }
+ }
+ if (len & 1)
+ result += le16_to_cpu(*buff);
+ result = from32to16(result);
+ if (odd)
+ result = swab16(result);
+out:
+ return result;
+}
+
+/*
+ * computes a partial checksum, e.g. for TCP/UDP fragments
+ */
+/*
+ * why bother folding?
+ */
+unsigned int csum_partial(const void *buff, int len, unsigned int sum)
+{
+ unsigned int result = 0;
+// printk("csum_partial %x %x %x\n", buff, len, sum);
+ result = do_csum(buff, len);
+ addc(result, sum);
+ return (unsigned short)from32to16(result);
+}
diff -Nur linux-3.4.113.orig/arch/nds32/lib/csum_partial_copy.c linux-3.4.113/arch/nds32/lib/csum_partial_copy.c
--- linux-3.4.113.orig/arch/nds32/lib/csum_partial_copy.c 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/lib/csum_partial_copy.c 2016-12-01 20:59:24.360613059 +0100
@@ -0,0 +1,58 @@
+/*
+ * INET An implementation of the TCP/IP protocol suite for the LINUX
+ * operating system. INET is implemented using the BSD Socket
+ * interface as the means of communication with the user level.
+ *
+ * MIPS specific IP/TCP/UDP checksumming routines
+ *
+ * Authors: Ralf Baechle, <ralf@waldorf-gmbh.de>
+ * Lots of code moved from tcp.c and ip.c; see those files
+ * for more names.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version
+ * 2 of the License, or (at your option) any later version.
+ */
+#include <linux/kernel.h>
+#include <net/checksum.h>
+#include <linux/types.h>
+#include <asm/byteorder.h>
+#include <asm/string.h>
+#include <asm/uaccess.h>
+
+/*
+ * copy while checksumming, otherwise like csum_partial
+ */
+unsigned int csum_partial_copy_nocheck(const unsigned char *src,
+ unsigned char *dst, int len,
+ unsigned int sum)
+{
+ /*
+ * It's 2:30 am and I don't feel like doing it real ...
+ * This is lots slower than the real thing (tm)
+ */
+ sum = csum_partial(src, len, sum);
+ memcpy(dst, src, len);
+
+ return sum;
+}
+
+/*
+ * Copy from userspace and compute checksum. If we catch an exception
+ * then zero the rest of the buffer.
+ */
+unsigned int csum_partial_copy_from_user(const unsigned char *src,
+ unsigned char *dst, int len,
+ unsigned int sum, int *err_ptr)
+{
+ int missing;
+
+ missing = copy_from_user(dst, src, len);
+ if (missing) {
+ memset(dst + len - missing, 0, missing);
+ *err_ptr = -EFAULT;
+ }
+
+ return csum_partial(dst, len, sum);
+}
diff -Nur linux-3.4.113.orig/arch/nds32/lib/divmod.c linux-3.4.113/arch/nds32/lib/divmod.c
--- linux-3.4.113.orig/arch/nds32/lib/divmod.c 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/lib/divmod.c 2016-12-01 20:59:24.360613059 +0100
@@ -0,0 +1,46 @@
+extern unsigned long udivmodsi4(unsigned long num, unsigned long den,
+ int modwanted);
+
+long __divsi3(long a, long b)
+{
+ int neg = 0;
+ long res;
+
+ if (a < 0) {
+ a = -a;
+ neg = !neg;
+ }
+
+ if (b < 0) {
+ b = -b;
+ neg = !neg;
+ }
+
+ res = udivmodsi4(a, b, 0);
+
+ if (neg)
+ res = -res;
+
+ return res;
+}
+
+long __modsi3(long a, long b)
+{
+ int neg = 0;
+ long res;
+
+ if (a < 0) {
+ a = -a;
+ neg = 1;
+ }
+
+ if (b < 0)
+ b = -b;
+
+ res = udivmodsi4(a, b, 1);
+
+ if (neg)
+ res = -res;
+
+ return res;
+}
diff -Nur linux-3.4.113.orig/arch/nds32/lib/findbit.S linux-3.4.113/arch/nds32/lib/findbit.S
--- linux-3.4.113.orig/arch/nds32/lib/findbit.S 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/lib/findbit.S 2016-12-01 20:59:24.360613059 +0100
@@ -0,0 +1,108 @@
+/*
+ * linux/arch/nds32/lib/findbit.S
+ *
+ * Copyright (C) 1995-2000 Russell King
+ * Copyright (C) 2006 Andes Technology Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include <linux/linkage.h>
+
+ .text
+
+/*
+ * Purpose : Find a 'zero' bit
+ * Prototype: int find_first_zero_bit(void *addr, int maxbit);
+ */
+ENTRY(_find_first_zero_bit)
+ move $r2, #0
+ move $p0, #0 ! Reset bit count
+next_word:
+ move $r4, #4
+ lmw.bim $p1, [$r0], $p1
+ li $r3, #0xffffffff ! Inversion mask
+ xor $p1, $p1, $r3 ! Inverted the word
+ addi $p0, $p0, #32
+ beqz $p1, next_word
+ addi $p0, $p0, #-32
+next_byte:
+ beqz $r4, next_word
+ andi $r3, $p1, #0xff ! Get the next byte
+ bnez $r3, found ! Found zero bit in this byte
+ addi $p0, $p0, #8 ! Update bit count
+ addi $r4, $r4, #-1
+ srli $p1, $p1, #8
+ bgt $r1, $p0, next_byte
+ addi $r0, $r1, #1 ! Return not found
+ ret
+
+/*
+ * Purpose : Find next 'zero' bit
+ * Prototype: int find_next_zero_bit(void *addr, int maxbit, int offset)
+ */
+ENTRY(_find_next_zero_bit)
+ beqz $r2, _find_first_zero_bit ! If offset=0, goto find_first_zero_bit
+ srli $p0, $r2, #5 ! Get offset byte count
+ slli $p0, $p0, #2
+ add $r0, $r0, $p0 ! $r0 is the first word to load
+ lmw.bim $p1, [$r0], $p1
+ li $p0, #0xffffffff ! Inversion mask
+ xor $p1, $p1, $p0 ! Inverted the word
+ andi $r4, $r2, #31 ! Left bits in offset
+ srl $p1, $p1, $r4 ! Shift out the left bits
+ xor $p0, $p0, $p0
+ subri $r4, $r4, #31
+loop:
+ andi $r3, $p1, #0xff ! The first byte to check
+ bnez $r3, found ! Found zero bit in this byte
+ addi $p0, $p0, #8
+ addi $r4, $r4, #-8
+ srli $p1, $p1, #8 ! Move on to the next byte
+ bgtz $r4, loop
+ b next_word
+
+/*
+ * One or more bits in the LSB of $p1 are assumed to be set.
+ */
+
+found:
+ move $p1, $r3
+ xor $r4, $r4, $r4
+ andi $r5, $p1, #0x0f ! Get bits 0-3
+ move $r3, #4 ! For 0 case (no set bit found)
+ cmovn $r3, $r4, $r5 ! Not 0 case (There's set bit in these 4 bits)
+ add $p0, $p0, $r3 ! Update bit count
+ slli $r3, $p1, #4 ! Not 0 case (Find set bit in these 4 bits)
+ cmovn $p1, $r3, $r5 ! For 0 case (Find set bit in the rest 4 bits)
+ andi $r5, $p1, #0x30 ! Get 4-5
+ move $r3, #2 ! For 0 case (no set bit found)
+ cmovn $r3, $r4, $r5 ! Not 0 case (There's set bit in these 2 bits)
+ add $p0, $p0, $r3 ! Update bit count
+ slli $r3, $p1, #2 ! Not 0 case (Find set bit in these 2 bits)
+ cmovn $p1, $r3, $r5 ! For 0 case (Find set bit in the rest 2 bits)
+ andi $r5, $p1, #0x40 ! Get bit 6
+ move $r3, #1 ! For 0 case (bit 6 is not set)
+ cmovn $r3, $r4, $r5 ! Not 0 case (bit 6 is set bit)
+ add $r5, $p0, $r3
+ add $r0, $r5, $r2
+ ret
+
+ENTRY(_ext2_find_first_zero_bit)
+ pushm $r2, $r4
+ move $r2, #0
+ move $p0, #0 ! Reset bit count
+1:
+ lbi.bi $r3, [$r0], #1
+ xori $r3, $r3, #0xff
+ addi $p0, $p0, #8
+ beqz $r3, 1b
+ addi $p0, $p0, #-8
+
+2:
+ b found ! No return
+ popm $r2, $r4
+ ret
+
diff -Nur linux-3.4.113.orig/arch/nds32/lib/getuser.S linux-3.4.113/arch/nds32/lib/getuser.S
--- linux-3.4.113.orig/arch/nds32/lib/getuser.S 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/lib/getuser.S 2016-12-01 20:59:24.360613059 +0100
@@ -0,0 +1,79 @@
+/*
+ * linux/arch/nds32/lib/getuser.S
+ *
+ * Copyright (C) 2001 Russell King
+ * Copyright (C) 2009 Andes Technology Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Idea from x86 version, (C) Copyright 1998 Linus Torvalds
+ *
+ * These functions have a non-standard call interface to make them more
+ * efficient, especially as they return an error value in addition to
+ * the "real" return value.
+ *
+ * __get_user_X
+ *
+ * Inputs: $r0 contains the address
+ * Outputs: $r0 is the error code
+ * $r2, $r3 contains the zero-extended value
+ * lr corrupted
+ *
+ * No other registers must be altered. (see include/asm-nds32/uaccess.h
+ * for specific ASM register usage).
+ *
+ * Note that ADDR_LIMIT is either 0 or 0xc0000000.
+ * Note also that it is intended that __get_user_bad is not global.
+ */
+#include <asm/asm-offsets.h>
+#include <asm/thread_info.h>
+#include <asm/errno.h>
+#include <linux/linkage.h>
+
+
+ENTRY(__get_user_1)
+1: lbi $r2, [$r0]
+ move $r0, #0
+ ret
+
+ENTRY(__get_user_2)
+2: lbi.bi $r2, [$r0], #1
+3: lbi $r3, [$r0]
+#ifndef __NDS32_EB__
+ slli $p1, $r3, #8
+ or $r2, $r2, $p1
+#else
+ slli $p1, $r2, #8
+ or $r2, $r3, $p1
+#endif
+ move $r0, #0
+ ret
+
+ENTRY(__get_user_4)
+4: lwi $r2, [$r0]
+ move $r0, #0
+ ret
+
+ENTRY(__get_user_8)
+5: lwi.bi $r2, [$r0], #4
+6: lwi $r3, [$r0]
+ move $r0, #0
+ ret
+
+__get_user_bad_8:
+ move $r3, #0
+__get_user_bad:
+ move $r2, #0
+ move $r0, #-EFAULT
+ ret
+
+.section __ex_table, "a"
+ .long 1b, __get_user_bad
+ .long 2b, __get_user_bad
+ .long 3b, __get_user_bad
+ .long 4b, __get_user_bad
+ .long 5b, __get_user_bad_8
+ .long 6b, __get_user_bad_8
+.previous
diff -Nur linux-3.4.113.orig/arch/nds32/lib/libgcc2.c linux-3.4.113/arch/nds32/lib/libgcc2.c
--- linux-3.4.113.orig/arch/nds32/lib/libgcc2.c 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/lib/libgcc2.c 2016-12-01 20:59:24.360613059 +0100
@@ -0,0 +1,351 @@
+#define BITS_PER_UNIT 8
+#include "longlong.h"
+typedef unsigned int UQItype __attribute__ ((mode(QI)));
+typedef int SItype __attribute__ ((mode(SI)));
+typedef unsigned int USItype __attribute__ ((mode(SI)));
+typedef int DItype __attribute__ ((mode(DI)));
+typedef unsigned int UDItype __attribute__ ((mode(DI)));
+
+typedef int word_type __attribute__ ((mode(__word__)));
+
+#define Wtype SItype
+#define UWtype USItype
+#define DWtype DItype
+#define UDWtype UDItype
+
+#ifdef __NDS32_EB__
+struct DWstruct {
+ Wtype high, low;
+};
+#else
+struct DWstruct {
+ Wtype low, high;
+};
+#endif
+
+typedef union {
+ struct DWstruct s;
+ DWtype ll;
+} DWunion;
+DWtype __negdi2(DWtype u)
+{
+ const DWunion uu = {.ll = u };
+ const DWunion w = { {.low = -uu.s.low,
+ .high = -uu.s.high - ((UWtype) - uu.s.low > 0)}
+ };
+
+ return w.ll;
+}
+
+DWtype __lshrdi3(DWtype u, word_type b)
+{
+ const DWunion uu = {.ll = u };
+ const word_type bm = (sizeof(Wtype) * BITS_PER_UNIT) - b;
+ DWunion w;
+
+ if (b == 0)
+ return u;
+
+ if (bm <= 0) {
+ w.s.high = 0;
+ w.s.low = (UWtype) uu.s.high >> -bm;
+ } else {
+ const UWtype carries = (UWtype) uu.s.high << bm;
+
+ w.s.high = (UWtype) uu.s.high >> b;
+ w.s.low = ((UWtype) uu.s.low >> b) | carries;
+ }
+
+ return w.ll;
+}
+
+DWtype __ashldi3(DWtype u, word_type b)
+{
+ const DWunion uu = {.ll = u };
+ const word_type bm = (sizeof(Wtype) * BITS_PER_UNIT) - b;
+ DWunion w;
+
+ if (b == 0)
+ return u;
+
+ if (bm <= 0) {
+ w.s.low = 0;
+ w.s.high = (UWtype) uu.s.low << -bm;
+ } else {
+ const UWtype carries = (UWtype) uu.s.low >> bm;
+
+ w.s.low = (UWtype) uu.s.low << b;
+ w.s.high = ((UWtype) uu.s.high << b) | carries;
+ }
+
+ return w.ll;
+}
+
+DWtype __ashrdi3(DWtype u, word_type b)
+{
+ const DWunion uu = {.ll = u };
+ const word_type bm = (sizeof(Wtype) * BITS_PER_UNIT) - b;
+ DWunion w;
+
+ if (b == 0)
+ return u;
+
+ if (bm <= 0) {
+ /* w.s.high = 1..1 or 0..0 */
+ w.s.high = uu.s.high >> (sizeof(Wtype) * BITS_PER_UNIT - 1);
+ w.s.low = uu.s.high >> -bm;
+ } else {
+ const UWtype carries = (UWtype) uu.s.high << bm;
+
+ w.s.high = uu.s.high >> b;
+ w.s.low = ((UWtype) uu.s.low >> b) | carries;
+ }
+
+ return w.ll;
+}
+
+DWtype __muldi3(DWtype u, DWtype v)
+{
+ const DWunion uu = {.ll = u };
+ const DWunion vv = {.ll = v };
+ DWunion w = {.ll = __umulsidi3(uu.s.low, vv.s.low) };
+
+ w.s.high += ((UWtype) uu.s.low * (UWtype) vv.s.high
+ + (UWtype) uu.s.high * (UWtype) vv.s.low);
+
+ return w.ll;
+}
+
+const UQItype __clz_tab[] = {
+ 0, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5,
+ 5, 5, 5, 5, 5, 5, 5, 5,
+ 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
+ 6, 6, 6, 6, 6, 6, 6, 6,
+ 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
+ 7, 7, 7, 7, 7, 7, 7, 7,
+ 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
+ 7, 7, 7, 7, 7, 7, 7, 7,
+ 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
+ 8, 8, 8, 8, 8, 8, 8, 8,
+ 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
+ 8, 8, 8, 8, 8, 8, 8, 8,
+ 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
+ 8, 8, 8, 8, 8, 8, 8, 8,
+ 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
+ 8, 8, 8, 8, 8, 8, 8, 8,
+};
+
+UDWtype __udivmoddi4(UDWtype n, UDWtype d, UDWtype * rp)
+{
+ const DWunion nn = {.ll = n };
+ const DWunion dd = {.ll = d };
+ DWunion rr;
+ UWtype d0, d1, n0, n1, n2;
+ UWtype q0, q1;
+ UWtype b, bm;
+ DWunion ww;
+
+ d0 = dd.s.low;
+ d1 = dd.s.high;
+ n0 = nn.s.low;
+ n1 = nn.s.high;
+
+#if !UDIV_NEEDS_NORMALIZATION
+ if (d1 == 0) {
+ if (d0 > n1) {
+ /* 0q = nn / 0D */
+
+ udiv_qrnnd(q0, n0, n1, n0, d0);
+ q1 = 0;
+
+ /* Remainder in n0. */
+ } else {
+ /* qq = NN / 0d */
+
+ if (d0 == 0)
+ d0 = 1 / d0; /* Divide intentionally by zero. */
+
+ udiv_qrnnd(q1, n1, 0, n1, d0);
+ udiv_qrnnd(q0, n0, n1, n0, d0);
+
+ /* Remainder in n0. */
+ }
+
+ if (rp != 0) {
+ rr.s.low = n0;
+ rr.s.high = 0;
+ *rp = rr.ll;
+ }
+ }
+#else /* UDIV_NEEDS_NORMALIZATION */
+
+ if (d1 == 0) {
+ if (d0 > n1) {
+ /* 0q = nn / 0D */
+
+ count_leading_zeros(bm, d0);
+
+ if (bm != 0) {
+ /* Normalize, i.e. make the most significant bit of the
+ denominator set. */
+
+ d0 = d0 << bm;
+ n1 = (n1 << bm) | (n0 >> (W_TYPE_SIZE - bm));
+ n0 = n0 << bm;
+ }
+
+ udiv_qrnnd(q0, n0, n1, n0, d0);
+ q1 = 0;
+
+ /* Remainder in n0 >> bm. */
+ } else {
+ /* qq = NN / 0d */
+
+ if (d0 == 0)
+ d0 = 1 / d0; /* Divide intentionally by zero. */
+
+ count_leading_zeros(bm, d0);
+
+ if (bm == 0) {
+ /* From (n1 >= d0) /\ (the most significant bit of d0 is set),
+ conclude (the most significant bit of n1 is set) /\ (the
+ leading quotient digit q1 = 1).
+
+ This special case is necessary, not an optimization.
+ (Shifts counts of W_TYPE_SIZE are undefined.) */
+
+ n1 -= d0;
+ q1 = 1;
+ } else {
+ /* Normalize. */
+
+ b = W_TYPE_SIZE - bm;
+
+ d0 = d0 << bm;
+ n2 = n1 >> b;
+ n1 = (n1 << bm) | (n0 >> b);
+ n0 = n0 << bm;
+
+ udiv_qrnnd(q1, n1, n2, n1, d0);
+ }
+
+ /* n1 != d0... */
+
+ udiv_qrnnd(q0, n0, n1, n0, d0);
+
+ /* Remainder in n0 >> bm. */
+ }
+
+ if (rp != 0) {
+ rr.s.low = n0 >> bm;
+ rr.s.high = 0;
+ *rp = rr.ll;
+ }
+ }
+#endif /* UDIV_NEEDS_NORMALIZATION */
+
+ else {
+ if (d1 > n1) {
+ /* 00 = nn / DD */
+
+ q0 = 0;
+ q1 = 0;
+
+ /* Remainder in n1n0. */
+ if (rp != 0) {
+ rr.s.low = n0;
+ rr.s.high = n1;
+ *rp = rr.ll;
+ }
+ } else {
+ /* 0q = NN / dd */
+
+ count_leading_zeros(bm, d1);
+ if (bm == 0) {
+ /* From (n1 >= d1) /\ (the most significant bit of d1 is set),
+ conclude (the most significant bit of n1 is set) /\ (the
+ quotient digit q0 = 0 or 1).
+
+ This special case is necessary, not an optimization. */
+
+ /* The condition on the next line takes advantage of that
+ n1 >= d1 (true due to program flow). */
+ if (n1 > d1 || n0 >= d0) {
+ q0 = 1;
+ sub_ddmmss(n1, n0, n1, n0, d1, d0);
+ } else
+ q0 = 0;
+
+ q1 = 0;
+
+ if (rp != 0) {
+ rr.s.low = n0;
+ rr.s.high = n1;
+ *rp = rr.ll;
+ }
+ } else {
+ UWtype m1, m0;
+ /* Normalize. */
+
+ b = W_TYPE_SIZE - bm;
+
+ d1 = (d1 << bm) | (d0 >> b);
+ d0 = d0 << bm;
+ n2 = n1 >> b;
+ n1 = (n1 << bm) | (n0 >> b);
+ n0 = n0 << bm;
+
+ udiv_qrnnd(q0, n1, n2, n1, d1);
+ umul_ppmm(m1, m0, q0, d0);
+
+ if (m1 > n1 || (m1 == n1 && m0 > n0)) {
+ q0--;
+ sub_ddmmss(m1, m0, m1, m0, d1, d0);
+ }
+
+ q1 = 0;
+
+ /* Remainder in (n1n0 - m1m0) >> bm. */
+ if (rp != 0) {
+ sub_ddmmss(n1, n0, n1, n0, m1, m0);
+ rr.s.low = (n1 << b) | (n0 >> bm);
+ rr.s.high = n1 >> bm;
+ *rp = rr.ll;
+ }
+ }
+ }
+ }
+
+ ww.s.low = q0, ww.s.high = q1;
+ return ww.ll;
+}
+
+UDWtype __umoddi3(UDWtype u, UDWtype v)
+{
+ UDWtype w;
+
+ (void)__udivmoddi4(u, v, &w);
+
+ return w;
+}
+
+UDWtype __udivdi3(UDWtype n, UDWtype d)
+{
+ return __udivmoddi4(n, d, (UDWtype *) 0);
+}
+
+word_type __ucmpdi2(DWtype a, DWtype b)
+{
+ const DWunion au = {.ll = a };
+ const DWunion bu = {.ll = b };
+
+ if ((UWtype) au.s.high < (UWtype) bu.s.high)
+ return 0;
+ else if ((UWtype) au.s.high > (UWtype) bu.s.high)
+ return 2;
+ if ((UWtype) au.s.low < (UWtype) bu.s.low)
+ return 0;
+ else if ((UWtype) au.s.low > (UWtype) bu.s.low)
+ return 2;
+ return 1;
+}
diff -Nur linux-3.4.113.orig/arch/nds32/lib/longlong.h linux-3.4.113/arch/nds32/lib/longlong.h
--- linux-3.4.113.orig/arch/nds32/lib/longlong.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/lib/longlong.h 2016-12-01 20:59:24.360613059 +0100
@@ -0,0 +1,105 @@
+#define __BITS4 (W_TYPE_SIZE / 4)
+#define __ll_B ((UWtype) 1 << (W_TYPE_SIZE / 2))
+#define __ll_lowpart(t) ((UWtype) (t) & (__ll_B - 1))
+#define __ll_highpart(t) ((UWtype) (t) >> (W_TYPE_SIZE / 2))
+
+#define W_TYPE_SIZE (4 * 8)
+#define UHWtype USItype
+
+#define sub_ddmmss(sh, sl, ah, al, bh, bl) \
+ do { \
+ UWtype __x; \
+ __x = (al) - (bl); \
+ (sh) = (ah) - (bh) - (__x > (al)); \
+ (sl) = __x; \
+ } while (0)
+
+#define umul_ppmm(w1, w0, u, v) \
+ do { \
+ UWtype __x0, __x1, __x2, __x3; \
+ UHWtype __ul, __vl, __uh, __vh; \
+ \
+ __ul = __ll_lowpart (u); \
+ __uh = __ll_highpart (u); \
+ __vl = __ll_lowpart (v); \
+ __vh = __ll_highpart (v); \
+ \
+ __x0 = (UWtype) __ul * __vl; \
+ __x1 = (UWtype) __ul * __vh; \
+ __x2 = (UWtype) __uh * __vl; \
+ __x3 = (UWtype) __uh * __vh; \
+ \
+ __x1 += __ll_highpart (__x0);/* this can't give carry */ \
+ __x1 += __x2; /* but this indeed can */ \
+ if (__x1 < __x2) /* did we get it? */ \
+ __x3 += __ll_B; /* yes, add it in the proper pos. */ \
+ \
+ (w1) = __x3 + __ll_highpart (__x1); \
+ (w0) = __ll_lowpart (__x1) * __ll_B + __ll_lowpart (__x0); \
+ } while (0)
+
+#define __umulsidi3(u, v) \
+ ({DWunion __w; \
+ umul_ppmm (__w.s.high, __w.s.low, u, v); \
+ __w.ll; })
+
+#define __udiv_qrnnd_c(q, r, n1, n0, d) \
+ do { \
+ UWtype __d1, __d0, __q1, __q0; \
+ UWtype __r1, __r0, __m; \
+ __d1 = __ll_highpart (d); \
+ __d0 = __ll_lowpart (d); \
+ \
+ __r1 = (n1) % __d1; \
+ __q1 = (n1) / __d1; \
+ __m = (UWtype) __q1 * __d0; \
+ __r1 = __r1 * __ll_B | __ll_highpart (n0); \
+ if (__r1 < __m) \
+ { \
+ __q1--, __r1 += (d); \
+ if (__r1 >= (d)) /* i.e. we didn't get carry when adding to __r1 */\
+ if (__r1 < __m) \
+ __q1--, __r1 += (d); \
+ } \
+ __r1 -= __m; \
+ \
+ __r0 = __r1 % __d1; \
+ __q0 = __r1 / __d1; \
+ __m = (UWtype) __q0 * __d0; \
+ __r0 = __r0 * __ll_B | __ll_lowpart (n0); \
+ if (__r0 < __m) \
+ { \
+ __q0--, __r0 += (d); \
+ if (__r0 >= (d)) \
+ if (__r0 < __m) \
+ __q0--, __r0 += (d); \
+ } \
+ __r0 -= __m; \
+ \
+ (q) = (UWtype) __q1 * __ll_B | __q0; \
+ (r) = __r0; \
+ } while (0)
+
+#define UDIV_NEEDS_NORMALIZATION 1
+#define udiv_qrnnd __udiv_qrnnd_c
+
+#define count_leading_zeros(count, x) \
+ do { \
+ UWtype __xr = (x); \
+ UWtype __a; \
+ \
+ if (W_TYPE_SIZE <= 32) \
+ { \
+ __a = __xr < ((UWtype)1<<2*__BITS4) \
+ ? (__xr < ((UWtype)1<<__BITS4) ? 0 : __BITS4) \
+ : (__xr < ((UWtype)1<<3*__BITS4) ? 2*__BITS4 : 3*__BITS4); \
+ } \
+ else \
+ { \
+ for (__a = W_TYPE_SIZE - 8; __a > 0; __a -= 8) \
+ if (((__xr >> __a) & 0xff) != 0) \
+ break; \
+ } \
+ \
+ (count) = W_TYPE_SIZE - (__clz_tab[__xr >> __a] + __a); \
+ } while (0)
diff -Nur linux-3.4.113.orig/arch/nds32/lib/Makefile linux-3.4.113/arch/nds32/lib/Makefile
--- linux-3.4.113.orig/arch/nds32/lib/Makefile 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/lib/Makefile 2016-12-01 20:59:24.360613059 +0100
@@ -0,0 +1,19 @@
+#
+# linux/arch/nds32/lib/Makefile
+#
+# Copyright (C) 2006 Andes Technology Corporation
+#
+
+lib-y := csum_partial_copy.o csum_partial.o \
+ copy_page.o memcpy.o memmove.o \
+ memset.o memzero.o strncpy_from_user.o \
+ strnlen_user.o strchr.o strrchr.o \
+ uaccess.o getuser.o \
+ putuser.o libgcc2.o divmod.o udivmod.o udivmodsi4.o
+
+ifdef CONFIG_FUNCTION_TRACER
+CFLAGS_REMOVE_libgcc2.o = -pg
+CFLAGS_REMOVE_divmod.o = -pg
+CFLAGS_REMOVE_udivmod.o = -pg
+CFLAGS_REMOVE_udivmodsi4.o = -pg
+endif
diff -Nur linux-3.4.113.orig/arch/nds32/lib/memcpy.S linux-3.4.113/arch/nds32/lib/memcpy.S
--- linux-3.4.113.orig/arch/nds32/lib/memcpy.S 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/lib/memcpy.S 2016-12-01 20:59:24.360613059 +0100
@@ -0,0 +1,101 @@
+/*
+ * linux/arch/nds32/lib/memcpy.S -- Memory copy function.
+ *
+ * This file is subject to the terms and conditions of the GNU General Public
+ * License. See the file "COPYING" in the main directory of this archive
+ * for more details.
+ *
+ * Copyright (C) 2001 Hiroyuki Kondo, and Hirokazu Takata
+ * Copyright (C) 2004 Hirokazu Takata
+ * Copyright (C) 2009 Andes Technology Corporation
+ *
+ */
+
+#include <linux/linkage.h>
+
+/*
+ void *memcpy(void *dst, const void *src, int n);
+
+ dst: $r0
+ src: $r1
+ n : $r2
+ ret: $r0 - pointer to the memory area dst.
+*/
+
+#include <linux/linkage.h>
+
+ .text
+
+ENTRY(memcpy)
+ move $r5, $r0
+ beq $r0, $r1, quit_memcpy
+ beqz $r2, quit_memcpy
+ srli $r3, $r2, #5 ! check if len < cache-line size 32
+ beqz $r3, word_copy_entry
+ andi $r4, $r0, #0x3 ! check byte-align
+ beqz $r4, unalign_word_copy_entry
+
+ addi $r4, $r4,#-4
+ abs $r4, $r4 ! check how many un-align byte to copy
+ sub $r2, $r2, $r4 ! update $R2
+
+unalign_byte_copy:
+ lbi.bi $r3, [$r1], #1
+ addi $r4, $r4, #-1
+ sbi.bi $r3, [$r0], #1
+ bnez $r4, unalign_byte_copy
+ beqz $r2, quit_memcpy
+
+unalign_word_copy_entry:
+ andi $r3, $r0, 0x1f ! check cache-line unaligncount
+ beqz $r3, cache_copy
+
+ addi $r3, $r3, #-32
+ abs $r3, $r3
+ sub $r2, $r2, $r3 ! update $R2
+
+unalign_word_copy:
+ lmw.bim $r4, [$r1], $r4
+ addi $r3, $r3, #-4
+ smw.bim $r4, [$r0], $r4
+ bnez $r3, unalign_word_copy
+ beqz $r2, quit_memcpy
+
+ addi $r3, $r2, #-32 ! to check $r2< cache_line , than go to word_copy
+ bltz $r3, word_copy_entry
+cache_copy:
+ srli $r3, $r2, #5
+ beqz $r3, word_copy_entry
+ pushm $r6, $r13
+3:
+ lmw.bim $r6, [$r1], $r13
+ addi $r3, $r3, #-1
+ smw.bim $r6, [$r0], $r13
+ bnez $r3, 3b
+ popm $r6, $r13
+
+word_copy_entry:
+ andi $r2, $r2, #31
+
+ beqz $r2, quit_memcpy
+5:
+ srli $r3, $r2, #2
+ beqz $r3, byte_copy
+word_copy:
+ lmw.bim $r4, [$r1], $r4
+ addi $r3, $r3, #-1
+ smw.bim $r4, [$r0], $r4
+ bnez $r3, word_copy
+ andi $r2, $r2, #3
+ beqz $r2, quit_memcpy
+byte_copy:
+ lbi.bi $r3, [$r1], #1
+ addi $r2, $r2, #-1
+
+ sbi.bi $r3, [$r0], #1
+ bnez $r2, byte_copy
+quit_memcpy:
+ move $r0, $r5
+ ret
+
+ .end
diff -Nur linux-3.4.113.orig/arch/nds32/lib/memmove.S linux-3.4.113/arch/nds32/lib/memmove.S
--- linux-3.4.113.orig/arch/nds32/lib/memmove.S 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/lib/memmove.S 2016-12-01 20:59:24.360613059 +0100
@@ -0,0 +1,80 @@
+/*
+ * linux/arch/nds32/lib/memmove.S -- Memory move function.
+ *
+ * This file is subject to the terms and conditions of the GNU General Public
+ * License. See the file "COPYING" in the main directory of this archive
+ * for more details.
+ *
+ * Copyright (C) 2001 Hiroyuki Kondo, and Hirokazu Takata
+ * Copyright (C) 2004 Hirokazu Takata
+ * Copyright (C) 2006 Andes Technology Corporation
+ *
+ */
+
+#include <linux/linkage.h>
+
+/*
+ void *memmove(void *dst, const void *src, int n);
+
+ dst: $r0
+ src: $r1
+ n : $r2
+ ret: $r0 - pointer to the memory area dst.
+*/
+ .text
+
+ENTRY(memmove)
+ move $r5, $r0 ! Set return value = det
+ beq $r0, $r1, exit_memcpy ! Exit when det = src
+ beqz $r2, exit_memcpy ! Exit when n = 0
+ pushm $t0, $t1 ! Save reg
+ srli $p1, $r2, #2 ! $p1 is how many words to copy
+
+ ! Avoid data lost when memory overlap
+ ! Copy data reversely when src < dst
+ slt $p0, $r0, $r1 ! check if $r0 < $r1
+ beqz $p0, do_reverse ! branch if dst > src
+
+ ! No reverse, dst < src
+ andi $r2, $r2, #3 ! How many bytes are less than a word
+ li $t0, #1 ! Determining copy direction in byte_cpy
+ beqz $p1, byte_cpy ! When n is less than a word
+
+word_cpy:
+ lmw.bim $p0, [$r1], $p0 ! Read a word from src
+ addi $p1, $p1, #-1 ! How many words left to copy
+ smw.bim $p0, [$r0], $p0 ! Copy the word to det
+ bnez $p1, word_cpy ! If remained words > 0
+ beqz $r2, end_memcpy ! No left bytes to copy
+ b byte_cpy
+
+do_reverse:
+ add $r0, $r0, $r2 ! Start with the end of $r0
+ add $r1, $r1, $r2 ! Start with the end of $r1
+ andi $r2, $r2, #3 ! How many bytes are less than a word
+ li $t0, #-1 ! Determining copy direction in byte_cpy
+ beqz $p1, reverse_byte_cpy ! When n is less than a word
+
+reverse_word_cpy:
+ lmw.adm $p0, [$r1], $p0 ! Read a word from src
+ addi $p1, $p1, #-1 ! How many words left to copy
+ smw.adm $p0, [$r0], $p0 ! Copy the word to det
+ bnez $p1, reverse_word_cpy ! If remained words > 0
+ beqz $r2, end_memcpy ! No left bytes to copy
+
+reverse_byte_cpy:
+ addi $r0, $r0, #-1
+ addi $r1, $r1, #-1
+byte_cpy: ! Less than 4 bytes to copy now
+ lb.bi $p0, [$r1], $t0 ! Read a byte from src
+ addi $r2, $r2, #-1 ! How many bytes left to copy
+ sb.bi $p0, [$r0], $t0 ! copy the byte to det
+ bnez $r2, byte_cpy ! If remained bytes > 0
+
+end_memcpy:
+ popm $t0, $t1
+exit_memcpy:
+ move $r0, $r5
+ ret
+
+ .end
diff -Nur linux-3.4.113.orig/arch/nds32/lib/memset.S linux-3.4.113/arch/nds32/lib/memset.S
--- linux-3.4.113.orig/arch/nds32/lib/memset.S 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/lib/memset.S 2016-12-01 20:59:24.360613059 +0100
@@ -0,0 +1,51 @@
+
+/*
+ * linux/arch/nds32/lib/memset.S -- memset function.
+ *
+ * This file is subject to the terms and conditions of the GNU General Public
+ * License. See the file "COPYING" in the main directory of this archive
+ * for more details.
+ *
+ * Copyright (C) 2001,2002 Hiroyuki Kondo, and Hirokazu Takata
+ * Copyright (C) 2004 Hirokazu Takata
+ * Copyright (C) 2006 Andes Technology Corporation
+ *
+ */
+#include <linux/linkage.h>
+#include <asm/assembler.h>
+
+/*
+ void *memset(void *dst, int val, int len);
+
+ dst: $r0
+ val: $r1
+ len: $r2
+ ret: $r0 - pointer to the memory area dst.
+*/
+ .text
+ENTRY(memset)
+ move $r5, $r0 ! Return value
+ beqz $r2, end_memset ! Exit when len = 0
+ srli $p1, $r2, 2 ! $p1 is how many words to copy
+ andi $r2, $r2, 3 ! How many bytes are less than a word
+ beqz $p1, byte_set ! When n is less than a word
+
+ ! set $r1 from ??????ab to abababab
+ andi $r1, $r1, #0x00ff ! $r1 = 000000ab
+ slli $p0, $r1, #8 ! $p0 = 0000ab00
+ or $r1, $r1, $p0 ! $r1 = 0000abab
+ slli $p0, $r1, #16 ! $p0 = abab0000
+ or $r1, $r1, $p0 ! $r1 = abababab
+word_set:
+ addi $p1, $p1, #-1 ! How many words left to copy
+ smw.bim $r1, [$r0], $r1 ! Copy the word to det
+ bnez $p1, word_set ! Still words to set, continue looping
+ beqz $r2, end_memset ! No left byte to set
+byte_set: ! Less than 4 bytes left to set
+ addi $r2, $r2, #-1 ! Decrease len by 1
+ sbi.bi $r1, [$r0], #1 ! Set data of the next byte to $r1
+ bnez $r2, byte_set ! Still bytes left to set
+end_memset:
+ move $r0, $r5
+ ret
+
diff -Nur linux-3.4.113.orig/arch/nds32/lib/memzero.S linux-3.4.113/arch/nds32/lib/memzero.S
--- linux-3.4.113.orig/arch/nds32/lib/memzero.S 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/lib/memzero.S 2016-12-01 20:59:24.360613059 +0100
@@ -0,0 +1,36 @@
+/*
+ * linux/arch/nds32/lib/memzero.S
+ *
+ * Copyright (C) 1995-2000 Russell King
+ * Copyright (C) 2009 Andes Technology Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+#include <linux/linkage.h>
+#include <asm/assembler.h>
+
+ .text
+/*
+ * void *__memzero(void *dst, int len);
+ *
+ * dst: $r0
+ * len: $r1
+ * ret: $r0 - pointer to the memory area dst.
+ *
+ * Call memset(dst, 0, len) to perform memzero.
+ * Currently no optimization because only being referenced in 31 files
+ * (For comparison, memset being referenced in 2527 files)
+ */
+ENTRY(__memzero)
+ beqz $r1, 1f
+ push $lp
+ move $r2, $r1
+ move $r1, #0
+ push $r0
+ bal memset
+ pop $r0
+ pop $lp
+1:
+ ret
diff -Nur linux-3.4.113.orig/arch/nds32/lib/putuser.S linux-3.4.113/arch/nds32/lib/putuser.S
--- linux-3.4.113.orig/arch/nds32/lib/putuser.S 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/lib/putuser.S 2016-12-01 20:59:24.360613059 +0100
@@ -0,0 +1,68 @@
+/*
+ * linux/arch/nds32/lib/putuser.S
+ *
+ * Copyright (C) 2001 Russell King
+ * Copyright (C) 2009 Andes Technology Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Idea from x86 version, (C) Copyright 1998 Linus Torvalds
+ *
+ * These functions have a non-standard call interface to make
+ * them more efficient, especially as they return an error
+ * value in addition to the "real" return value.
+ *
+ * __put_user_X
+ *
+ * Inputs: $r0 contains the address
+ * $r2, $r3 contains the value
+ * Outputs: $r0 is the error code
+ * lr corrupted
+ *
+ * No other registers must be altered. (see include/asm-arm/uaccess.h
+ * for specific ASM register usage).
+ *
+ * Note that ADDR_LIMIT is either 0 or 0xc0000000
+ * Note also that it is intended that __put_user_bad is not global.
+ */
+#include <asm/asm-offsets.h>
+#include <asm/thread_info.h>
+#include <asm/errno.h>
+#include <linux/linkage.h>
+
+ .text
+
+ENTRY(__put_user_1)
+1: sb $r2, [$r0]
+ move $r0, #0
+ ret
+
+ENTRY(__put_user_2)
+2: shi $r2, [$r0] ! Store input halfword
+ move $r0, #0
+ ret
+
+ENTRY(__put_user_4)
+3: sw $r2, [$r0]
+ move $r0, #0
+ ret
+
+ENTRY(__put_user_8)
+5: swi.bi $r2, [$r0], #4
+6: sw $r3, [$r0]
+ move $r0, #0
+ ret
+
+__put_user_bad:
+ move $r0, #-EFAULT
+ ret
+
+.section __ex_table, "a"
+ .long 1b, __put_user_bad
+ .long 2b, __put_user_bad
+ .long 3b, __put_user_bad
+ .long 5b, __put_user_bad
+ .long 6b, __put_user_bad
+.previous
diff -Nur linux-3.4.113.orig/arch/nds32/lib/strchr.S linux-3.4.113/arch/nds32/lib/strchr.S
--- linux-3.4.113.orig/arch/nds32/lib/strchr.S 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/lib/strchr.S 2016-12-01 20:59:24.360613059 +0100
@@ -0,0 +1,37 @@
+/*
+ * linux/arch/nds32/lib/strchr.S
+ *
+ * Copyright (C) 1995-2000 Russell King
+ * Copyright (C) 2009 Andes Technology Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * ASM optimised string functions
+ */
+#include <linux/linkage.h>
+#include <asm/assembler.h>
+
+/*
+ * Prototype: char *strrchr(const char *s, int c);
+ * Purpose : Returns a pointer to the first occurrence of the character c
+ * in the string s. Here "character" means "byte" - these functions
+ * do not work with wide or multi-byte characters.
+ */
+
+ .text
+
+ENTRY(strchr)
+ move $r5, $r0 ! Setup return value
+ andi $r1, $r1, #0xff ! Wipe out useless bits
+loop:
+ lbi.bi $p0, [$r5], #1 ! Load the next byte
+ beqz $p0, exit ! Reach EOS (NULL), return NULL
+ bne $p0, $r1, loop ! Continue if != c
+ addi $r5, $r5, #-1 ! Found
+exit:
+ cmovz $r5, $p0, $p0 ! Return NULL if EOS (NULL)
+ move $r0, $r5
+ ret
+
diff -Nur linux-3.4.113.orig/arch/nds32/lib/strncpy_from_user.S linux-3.4.113/arch/nds32/lib/strncpy_from_user.S
--- linux-3.4.113.orig/arch/nds32/lib/strncpy_from_user.S 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/lib/strncpy_from_user.S 2016-12-01 20:59:24.360613059 +0100
@@ -0,0 +1,45 @@
+/*
+ * linux/arch/nds32/lib/strncpy_from_user.S
+ *
+ * Copyright (C) 1995-2000 Russell King
+ * Copyright (C) 2009 Andes Technology Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+#include <linux/linkage.h>
+#include <asm/assembler.h>
+#include <asm/errno.h>
+
+
+/*
+ * Copy a string from user space to kernel space.
+ * $r0 = dst, $r1 = src, $r2 = n (byte length)
+ * returns the number of characters copied (strlen of copied string),
+ * -EFAULT on exception, or "len" if we fill the whole buffer
+ */
+
+ .text
+ .align 4
+ENTRY(__arch_strncpy_from_user)
+ move $p1, $r1 ! Record the start src addr
+loop:
+ addi $r2, $r2, #-1 ! Decrease n by 1
+ bltz $r2, exit ! Exit if n < 0
+USER( lbi.bi, $p0, [$r1], #1) ! Load the byte from src
+ sbi.bi $p0, [$r0], #1 ! Store the byte to dst
+ bnez $p0, loop ! Continue looping if terminator is not reached
+ addi $r1, $r1, #-1 ! Don't count the terminator
+exit:
+ sub $r0, $r1, $p1 ! Get copied count
+ ret
+
+ .section .fixup,"ax"
+ .align 0
+9001: xor $p0, $p0, $p0
+ sb $p0, [$r0] ! Zero the buffer
+ move $r0, -EFAULT ! Return -EFAULT
+ ret
+ .previous
+
diff -Nur linux-3.4.113.orig/arch/nds32/lib/strnlen_user.S linux-3.4.113/arch/nds32/lib/strnlen_user.S
--- linux-3.4.113.orig/arch/nds32/lib/strnlen_user.S 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/lib/strnlen_user.S 2016-12-01 20:59:24.360613059 +0100
@@ -0,0 +1,43 @@
+/*
+ * linux/arch/nds32/lib/strnlen_user.S
+ *
+ * Copyright (C) 1995-2000 Russell King
+ * Copyright (C) 2009 Andes Technology Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+#include <linux/linkage.h>
+#include <asm/assembler.h>
+#include <asm/errno.h>
+
+ .text
+
+/* Prototype: unsigned long ___arch_strnlen_user(const char *str, long n)
+ * Purpose : get length of a string in user memory
+ * Params : str - address of string in user memory
+ * Returns : length of string *including terminator*
+ * or zero on exception, or n + 1 if too long
+ */
+ .align 4
+ENTRY(__arch_strnlen_user)
+ move $p0, $r0 ! Record the start addr
+ ! beqz $r0, exit ! Exit when Null address
+ beqz $r1, exit ! Exit when n = 0
+loop:
+USER( lbi.bi, $p1, [$r0], #1) ! Load the next byte
+ beqz $p1, exit ! Exit when terminator is reached
+ addi $r1, $r1, #-1 ! Decrease n by 1
+ bnez $r1, loop ! Continue looping if n != 0
+ addi $r0, $r0, #1 ! Return n+1 if too long
+exit:
+ sub $r0, $r0, $p0 ! Get the counted length
+ ret
+
+ .section .fixup,"ax"
+ .align 0
+9001: move $r0, #0 ! Return 0 on exception
+ ret
+ .previous
+
diff -Nur linux-3.4.113.orig/arch/nds32/lib/strrchr.S linux-3.4.113/arch/nds32/lib/strrchr.S
--- linux-3.4.113.orig/arch/nds32/lib/strrchr.S 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/lib/strrchr.S 2016-12-01 20:59:24.360613059 +0100
@@ -0,0 +1,37 @@
+/*
+ * linux/arch/nds32/lib/strrchr.S
+ *
+ * Copyright (C) 1995-2000 Russell King
+ * Copyright (C) 2009 Andes Technology Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * ASM optimised string functions
+ */
+#include <linux/linkage.h>
+#include <asm/assembler.h>
+
+ .text
+/*
+ * Prototype: char *strrchr(const char *s, int c);
+ * Purpose : Returns a pointer to the last occurrence of the character c
+ * in the string s. Here "character" means "byte" - these functions
+ * do not work with wide or multi-byte characters.
+ */
+ .align 4
+ENTRY(strrchr)
+ move $r5, #0
+ beqz $r0, exit
+ andi $r1, $r1, #0xff ! Wipe out useless bits
+loop:
+ lbi $p0, [$r0] ! Load the next byte
+ xor $p1, $p0, $r1 ! Test if the byte == c
+ cmovz $r5, $r0, $p1 ! Save the current position
+ addi $r0, $r0, #1 ! Move on to the next byte
+ bnez $p0, loop ! Continue if not NULL (EOS)
+exit:
+ move $r0, $r5
+ ret
+
diff -Nur linux-3.4.113.orig/arch/nds32/lib/uaccess.S linux-3.4.113/arch/nds32/lib/uaccess.S
--- linux-3.4.113.orig/arch/nds32/lib/uaccess.S 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/lib/uaccess.S 2016-12-01 20:59:24.360613059 +0100
@@ -0,0 +1,159 @@
+/*
+ * linux/arch/nds32/lib/uaccess.S
+ *
+ * Copyright (C) 1995, 1996,1997,1998 Russell King
+ * Copyright (C) 2009 Andes Technology Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Routines to block copy data to/from user memory
+ * These are highly optimised both for the 4k page size
+ * and for various alignments.
+ */
+#include <linux/linkage.h>
+#include <asm/assembler.h>
+#include <asm/errno.h>
+
+ .text
+
+//#define PAGE_SHIFT 12
+
+/* Prototype: int __arch_copy_to_user(void *to, const char *from, size_t n)
+ * Purpose : copy a block to user memory from kernel memory
+ * Params : to - user memory
+ * : from - kernel memory
+ * : n - number of bytes to copy
+ * Returns : Number of bytes NOT copied.
+ */
+
+ENTRY(__arch_copy_to_user)
+ push $r0
+ push $r2
+ beqz $r2, ctu_exit
+ srli $p0, $r2, #2 ! $p0 = number of word to clear
+ andi $r2, $r2, #3 ! Bytes less than a word to copy
+ beqz $p0, byte_ctu ! Only less than a word to copy
+word_ctu:
+ lmw.bim $p1, [$r1], $p1 ! Load the next word
+USER( smw.bim,$p1, [$r0], $p1) ! Store the next word
+ addi $p0, $p0, #-1 ! Decrease word count
+ bnez $p0, word_ctu ! Continue looping to copy all words
+ beqz $r2, ctu_exit ! No left bytes to copy
+byte_ctu:
+ lbi.bi $p1, [$r1], #1 ! Load the next byte
+USER( sbi.bi, $p1, [$r0], #1) ! Store the next byte
+ addi $r2, $r2, #-1 ! Decrease byte count
+ bnez $r2, byte_ctu ! Continue looping to clear all left bytes
+ctu_exit:
+ move $r0, $r2 ! Set return value
+ pop $r2
+ pop $r2 ! Pop saved $r0 to $r2 to not corrupt return value
+ ret
+
+ .section .fixup,"ax"
+ .align 0
+9001:
+ pop $p1 ! Original $r2, n
+ pop $p0 ! Original $r0, void *to
+ sub $r1, $r0, $p0 ! Bytes copied
+ sub $r2, $p1, $r1 ! Bytes left to copy
+ push $lp
+ move $r0, $p0
+ bal __memzero ! Clean up the memory
+ pop $lp
+ move $r0, $r2
+ ret
+
+ .previous
+
+/* Prototype: unsigned long __arch_copy_from_user(void *to,const void *from,unsigned long n);
+ * Purpose : copy a block from user memory to kernel memory
+ * Params : to - kernel memory
+ * : from - user memory
+ * : n - number of bytes to copy
+ * Returns : Number of bytes NOT copied.
+ */
+
+
+ENTRY(__arch_copy_from_user)
+ push $r1
+ push $r2
+ beqz $r2, cfu_exit
+ srli $p0, $r2, #2 ! $p0 = number of word to clear
+ andi $r2, $r2, #3 ! Bytes less than a word to copy
+ beqz $p0, byte_cfu ! Only less than a word to copy
+word_cfu:
+USER( lmw.bim,$p1, [$r1], $p1) ! Load the next word
+ smw.bim $p1, [$r0], $p1 ! Store the next word
+ addi $p0, $p0, #-1 ! Decrease word count
+ bnez $p0, word_cfu ! Continue looping to copy all words
+ beqz $r2, cfu_exit ! No left bytes to copy
+byte_cfu:
+USER( lbi.bi, $p1, [$r1], #1) ! Load the next byte
+ sbi.bi $p1, [$r0], #1 ! Store the next byte
+ addi $r2, $r2, #-1 ! Decrease byte count
+ bnez $r2, byte_cfu ! Continue looping to clear all left bytes
+cfu_exit:
+ move $r0, $r2 ! Set return value
+ pop $r2
+ pop $r1
+ ret
+
+ .section .fixup,"ax"
+ .align 0
+ /*
+ * We took an exception. $r0 contains a pointer to
+ * the byte not copied.
+ */
+9001:
+ pop $p1 ! Original $r2, n
+ pop $p0 ! Original $r0, void *to
+ sub $r1, $r1, $p0 ! Bytes copied
+ sub $r2, $p1, $r1 ! Bytes left to copy
+ push $lp
+ bal __memzero ! Clean up the memory
+ pop $lp
+ move $r0, $r2
+ ret
+ .previous
+
+/* Prototype: int __arch_clear_user(void *addr, size_t sz)
+ * Purpose : clear some user memory
+ * Params : addr - user memory address to clear
+ * : sz - number of bytes to clear
+ * Returns : number of bytes NOT cleared
+ */
+ .align 5
+ENTRY(__arch_clear_user)
+ pushm $r0, $r1
+ beqz $r1, clear_exit
+ xor $p1, $p1, $p1 ! Use $p1=0 to clear mem
+ srli $p0, $r1, #2 ! $p0 = number of word to clear
+ andi $r1, $r1, #3 ! Bytes less than a word to copy
+ beqz $p0, byte_clear ! Only less than a word to clear
+word_clear:
+USER( smw.bim,$p1, [$r0], $p1) ! Clear the word
+ addi $p0, $p0, #-1 ! Decrease word count
+ bnez $p0, word_clear ! Continue looping to clear all words
+ beqz $r1, clear_exit ! No left bytes to copy
+byte_clear:
+USER( sbi.bi, $p1, [$r0], #1) ! Clear the byte
+ addi $r1, $r1, #-1 ! Decrease byte count
+ bnez $r1, byte_clear ! Continue looping to clear all left bytes
+clear_exit:
+ move $r0, $r1 ! Set return value
+ pop $r1
+ pop $r1 ! Pop saved $r0 to $r1 to not corrupt return value
+ ret
+
+ .section .fixup,"ax"
+ .align 0
+9001:
+ popm $p0, $p1 ! $p0 = original $r0, *addr, $p1 = original $r1, n
+ sub $p0, $r0, $p0 ! Bytes copied
+ sub $r0, $p1, $p0 ! Bytes left to copy
+ ret
+ .previous
+
diff -Nur linux-3.4.113.orig/arch/nds32/lib/udivmod.c linux-3.4.113/arch/nds32/lib/udivmod.c
--- linux-3.4.113.orig/arch/nds32/lib/udivmod.c 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/lib/udivmod.c 2016-12-01 20:59:24.360613059 +0100
@@ -0,0 +1,12 @@
+extern unsigned long udivmodsi4(unsigned long num, unsigned long den,
+ int modwanted);
+
+long __udivsi3(long a, long b)
+{
+ return udivmodsi4(a, b, 0);
+}
+
+long __umodsi3(long a, long b)
+{
+ return udivmodsi4(a, b, 1);
+}
diff -Nur linux-3.4.113.orig/arch/nds32/lib/udivmodsi4.c linux-3.4.113/arch/nds32/lib/udivmodsi4.c
--- linux-3.4.113.orig/arch/nds32/lib/udivmodsi4.c 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/lib/udivmodsi4.c 2016-12-01 20:59:24.360613059 +0100
@@ -0,0 +1,21 @@
+unsigned long udivmodsi4(unsigned long num, unsigned long den, int modwanted)
+{
+ unsigned long bit = 1;
+ unsigned long res = 0;
+
+ while (den < num && bit && !(den & (1L << 31))) {
+ den <<= 1;
+ bit <<= 1;
+ }
+ while (bit) {
+ if (num >= den) {
+ num -= den;
+ res |= bit;
+ }
+ bit >>= 1;
+ den >>= 1;
+ }
+ if (modwanted)
+ return num;
+ return res;
+}
diff -Nur linux-3.4.113.orig/arch/nds32/Makefile linux-3.4.113/arch/nds32/Makefile
--- linux-3.4.113.orig/arch/nds32/Makefile 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/Makefile 2016-12-01 20:59:24.360613059 +0100
@@ -0,0 +1,100 @@
+#
+# arch/nds32/Makefile
+#
+# This file is subject to the terms and conditions of the GNU General Public
+# License. See the file "COPYING" in the main directory of this archive
+# for more details.
+#
+# Copyright (C) 1995-2001 by Russell King
+
+LDFLAGS_vmlinux :=-nostdlib --no-undefined -X
+OBJCOPYFLAGS :=-O binary -R .note -R .note.gnu.build-id -R .comment -S
+GZFLAGS :=-9
+KBUILD_CFLAGS +=-pipe -mno-sched-prolog-epilog
+
+# Do not use arch/nds32/defconfig - it's always outdated.
+# Select a platform tht is kept up-to-date
+KBUILD_DEFCONFIG := orca_defconfig
+
+ifeq ($(CONFIG_FRAME_POINTER),y)
+KBUILD_CFLAGS +=-fno-omit-frame-pointer
+endif
+
+comma = ,
+
+# This selects which instruction set is used.
+# Note that GCC does not numerically define an architecture version
+# macro, but instead defines a whole series of macros which makes
+# testing for a specific architecture or later rather impossible.
+arch-y +=-D__nds32__
+gcc_ver :=$(shell $(CC) -E -dM -xc /dev/null | grep __VERSION__ | sed 's/\#define __VERSION__ //')
+ifeq ($(shell expr `echo $(gcc_ver)` \>= 4.9.2 ), 1)
+arch-y += \
+ $(shell $(CC) -E -dM -xc /dev/null | \
+ grep -o -m1 NDS32_EXT_FPU_SP | \
+ sed -e 's/NDS32_EXT_FPU_SP/-mno-ext-fpu-sp -mfloat-abi=soft/') \
+ $(shell $(CC) -E -dM -xc /dev/null | \
+ grep -o -m1 NDS32_EXT_FPU_DP | \
+ sed -e 's/NDS32_EXT_FPU_DP/-mno-ext-fpu-dp -mfloat-abi=soft/')
+tune-y =-D__OPTIMIZE__ -mcmodel=large -D__ARCH_WANT_SYS_WAITPID
+else
+$(shell echo $(__VERSION__))
+arch-y += $(shell $(CC) -E -dM -xc /dev/null | grep -o -m1 NDS32_EXT_FPU_SP | \
+ sed -e 's/NDS32_EXT_FPU_SP/-mno-ext-fpu-sp/') \
+ $(shell $(CC) -E -dM -xc /dev/null | grep -o -m1 NDS32_EXT_FPU_DP | \
+ sed -e 's/NDS32_EXT_FPU_DP/-mno-ext-fpu-dp/') \
+ $(shell $(CC) -E -dM -xc /dev/null | grep -o -m1 NDS32_ABI | \
+ sed -e 's/NDS32_ABI/-mabi=2/')
+tune-y =-D__OPTIMIZE__ -G0 -D__ARCH_WANT_SYS_WAITPID -D_GCC444
+endif
+
+# This is a workaround for FUNCTION_TRACER because v3push will push $fp, $gp and $lp.
+ifdef CONFIG_FUNCTION_TRACER
+arch-y += -mno-v3push
+endif
+# This selects how we optimise for the processor.
+# Need -Unds32 for gcc < 3.x
+CHECKFLAGS += -D__nds32__
+
+KBUILD_CFLAGS +=$(CFLAGS_ABI) $(arch-y) $(tune-y) -Unds32 -DSTRICT_MM_TYPECHECKS # for c-style checking for page.h
+KBUILD_AFLAGS +=$(AFLAGS_ABI) $(arch-y) $(tune-y)
+
+#Default value
+head-y := arch/nds32/kernel/head.o arch/nds32/kernel/init_task.o
+textaddr-y := 0xC000C000
+
+TEXTADDR := $(textaddr-y)
+
+export TEXTADDR DATAADDR GZFLAGS
+
+
+# If we have a machine-specific directory, then include it in the build.
+core-y += arch/nds32/kernel/ arch/nds32/mm/
+core-y += arch/nds32/platforms/
+core-$(CONFIG_FPU) += arch/nds32/math-emu/
+
+drivers-$(CONFIG_OPROFILE) += arch/nds32/oprofile/
+
+libs-y += arch/nds32/lib/
+
+boot := arch/nds32/boot
+
+.PHONY: FORCE
+
+Image: vmlinux
+ $(Q)$(MAKE) $(build)=$(boot) $(boot)/$@
+
+CLEAN_FILES += include/asm-nds32/constants.h*
+
+# We use MRPROPER_FILES and CLEAN_FILES now
+archclean:
+ $(Q)$(MAKE) $(clean)=$(boot)
+
+.PHONY: arch/nds32/kernel/asm-offsets.s
+arch/nds32/kernel/asm-offsets.s: arch/nds32/kernel/asm-offsets.c
+ $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
+
+
+define archhelp
+ echo ' Image - kernel image (arch/$(ARCH)/boot/Image)'
+endef
diff -Nur linux-3.4.113.orig/arch/nds32/math-emu/dp_add.c linux-3.4.113/arch/nds32/math-emu/dp_add.c
--- linux-3.4.113.orig/arch/nds32/math-emu/dp_add.c 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/math-emu/dp_add.c 2016-12-01 20:59:24.360613059 +0100
@@ -0,0 +1,179 @@
+/* IEEE754 floating point arithmetic
+ * double precision: common utilities
+ */
+/*
+ * MIPS floating point support
+ * Copyright (C) 1994-2000 Algorithmics Ltd.
+ * http://www.algor.co.uk
+ *
+ * ########################################################################
+ *
+ * This program is free software; you can distribute it and/or modify it
+ * under the terms of the GNU General Public License (Version 2) as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
+ *
+ * ########################################################################
+ *
+ */
+
+#include "ieee754dp.h"
+
+ieee754dp ieee754dp_add(ieee754dp x, ieee754dp y)
+{
+ COMPXDP;
+ COMPYDP;
+
+ EXPLODEXDP;
+ EXPLODEYDP;
+
+ CLEARCX;
+
+ FLUSHXDP;
+ FLUSHYDP;
+
+ switch (CLPAIR(xc, yc)) {
+ case CLPAIR(IEEE754_CLASS_SNAN, IEEE754_CLASS_QNAN):
+ case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_SNAN):
+ case CLPAIR(IEEE754_CLASS_SNAN, IEEE754_CLASS_SNAN):
+ case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_SNAN):
+ case CLPAIR(IEEE754_CLASS_NORM, IEEE754_CLASS_SNAN):
+ case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_SNAN):
+ case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_SNAN):
+ case CLPAIR(IEEE754_CLASS_SNAN, IEEE754_CLASS_ZERO):
+ case CLPAIR(IEEE754_CLASS_SNAN, IEEE754_CLASS_NORM):
+ case CLPAIR(IEEE754_CLASS_SNAN, IEEE754_CLASS_DNORM):
+ case CLPAIR(IEEE754_CLASS_SNAN, IEEE754_CLASS_INF):
+ SETCX(IEEE754_INVALID_OPERATION);
+ return ieee754dp_nanxcpt(ieee754dp_indef(), "add", x, y);
+
+ case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_QNAN):
+ case CLPAIR(IEEE754_CLASS_NORM, IEEE754_CLASS_QNAN):
+ case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_QNAN):
+ case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_QNAN):
+ return y;
+
+ case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_QNAN):
+ case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_ZERO):
+ case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_NORM):
+ case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_DNORM):
+ case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_INF):
+ return x;
+
+ /* Infinity handling
+ */
+
+ case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_INF):
+ if (xs == ys)
+ return x;
+ SETCX(IEEE754_INVALID_OPERATION);
+ return ieee754dp_xcpt(ieee754dp_indef(), "add", x, y);
+
+ case CLPAIR(IEEE754_CLASS_NORM, IEEE754_CLASS_INF):
+ case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_INF):
+ case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_INF):
+ return y;
+
+ case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_ZERO):
+ case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_NORM):
+ case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_DNORM):
+ return x;
+
+ /* Zero handling
+ */
+
+ case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_ZERO):
+ if (xs == ys)
+ return x;
+ else
+ return ieee754dp_zero(ieee754_csr.rm == IEEE754_RD);
+
+ case CLPAIR(IEEE754_CLASS_NORM, IEEE754_CLASS_ZERO):
+ case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_ZERO):
+ return x;
+
+ case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_NORM):
+ case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_DNORM):
+ return y;
+
+ case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_DNORM):
+ DPDNORMX;
+
+ /* FALL THROUGH */
+
+ case CLPAIR(IEEE754_CLASS_NORM, IEEE754_CLASS_DNORM):
+ DPDNORMY;
+ break;
+
+ case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_NORM):
+ DPDNORMX;
+ break;
+
+ case CLPAIR(IEEE754_CLASS_NORM, IEEE754_CLASS_NORM):
+ break;
+ }
+ assert(xm & DP_HIDDEN_BIT);
+ assert(ym & DP_HIDDEN_BIT);
+
+ /* provide guard,round and stick bit space */
+ xm <<= 3;
+ ym <<= 3;
+
+ if (xe > ye) {
+ /* have to shift y fraction right to align
+ */
+ int s = xe - ye;
+ ym = XDPSRS(ym, s);
+ ye += s;
+ } else if (ye > xe) {
+ /* have to shift x fraction right to align
+ */
+ int s = ye - xe;
+ xm = XDPSRS(xm, s);
+ xe += s;
+ }
+ assert(xe == ye);
+ assert(xe <= DP_EMAX);
+
+ if (xs == ys) {
+ /* generate 28 bit result of adding two 27 bit numbers
+ * leaving result in xm,xs,xe
+ */
+ xm = xm + ym;
+ xe = xe;
+ xs = xs;
+
+ if (xm >> (DP_MBITS + 1 + 3)) { /* carry out */
+ xm = XDPSRS1(xm);
+ xe++;
+ }
+ } else {
+ if (xm >= ym) {
+ xm = xm - ym;
+ xe = xe;
+ xs = xs;
+ } else {
+ xm = ym - xm;
+ xe = xe;
+ xs = ys;
+ }
+ if (xm == 0)
+ return ieee754dp_zero(ieee754_csr.rm == IEEE754_RD);
+
+ /* normalize to rounding precision */
+ while ((xm >> (DP_MBITS + 3)) == 0) {
+ xm <<= 1;
+ xe--;
+ }
+
+ }
+ DPNORMRET2(xs, xe, xm, "add", x, y);
+}
diff -Nur linux-3.4.113.orig/arch/nds32/math-emu/dp_cmp.c linux-3.4.113/arch/nds32/math-emu/dp_cmp.c
--- linux-3.4.113.orig/arch/nds32/math-emu/dp_cmp.c 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/math-emu/dp_cmp.c 2016-12-01 20:59:24.360613059 +0100
@@ -0,0 +1,66 @@
+/* IEEE754 floating point arithmetic
+ * double precision: common utilities
+ */
+/*
+ * MIPS floating point support
+ * Copyright (C) 1994-2000 Algorithmics Ltd.
+ * http://www.algor.co.uk
+ *
+ * ########################################################################
+ *
+ * This program is free software; you can distribute it and/or modify it
+ * under the terms of the GNU General Public License (Version 2) as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
+ *
+ * ########################################################################
+ */
+
+#include "ieee754dp.h"
+
+int ieee754dp_cmp(ieee754dp x, ieee754dp y, int cmp, int sig)
+{
+ COMPXDP;
+ COMPYDP;
+
+ EXPLODEXDP;
+ EXPLODEYDP;
+ FLUSHXDP;
+ FLUSHYDP;
+ CLEARCX; /* Even clear inexact flag here */
+
+ if (ieee754dp_isnan(x) || ieee754dp_isnan(y)) {
+ if (sig || xc == IEEE754_CLASS_SNAN || yc == IEEE754_CLASS_SNAN)
+ SETCX(IEEE754_INVALID_OPERATION);
+ if (cmp & IEEE754_CUN)
+ return 1;
+ if (cmp & (IEEE754_CLT | IEEE754_CGT)) {
+ if (sig && SETANDTESTCX(IEEE754_INVALID_OPERATION))
+ return ieee754si_xcpt(0, "fcmpf", x);
+ }
+ return 0;
+ } else {
+ s64 vx = x.bits;
+ s64 vy = y.bits;
+
+ if (vx < 0)
+ vx = -vx ^ DP_SIGN_BIT;
+ if (vy < 0)
+ vy = -vy ^ DP_SIGN_BIT;
+
+ if (vx < vy)
+ return (cmp & IEEE754_CLT) != 0;
+ else if (vx == vy)
+ return (cmp & IEEE754_CEQ) != 0;
+ else
+ return (cmp & IEEE754_CGT) != 0;
+ }
+}
diff -Nur linux-3.4.113.orig/arch/nds32/math-emu/dp_div.c linux-3.4.113/arch/nds32/math-emu/dp_div.c
--- linux-3.4.113.orig/arch/nds32/math-emu/dp_div.c 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/math-emu/dp_div.c 2016-12-01 20:59:24.360613059 +0100
@@ -0,0 +1,155 @@
+/* IEEE754 floating point arithmetic
+ * double precision: common utilities
+ */
+/*
+ * MIPS floating point support
+ * Copyright (C) 1994-2000 Algorithmics Ltd.
+ * http://www.algor.co.uk
+ *
+ * ########################################################################
+ *
+ * This program is free software; you can distribute it and/or modify it
+ * under the terms of the GNU General Public License (Version 2) as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
+ *
+ * ########################################################################
+ */
+
+#include "ieee754dp.h"
+
+ieee754dp ieee754dp_div(ieee754dp x, ieee754dp y)
+{
+ COMPXDP;
+ COMPYDP;
+
+ EXPLODEXDP;
+ EXPLODEYDP;
+
+ CLEARCX;
+
+ FLUSHXDP;
+ FLUSHYDP;
+
+ switch (CLPAIR(xc, yc)) {
+ case CLPAIR(IEEE754_CLASS_SNAN, IEEE754_CLASS_QNAN):
+ case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_SNAN):
+ case CLPAIR(IEEE754_CLASS_SNAN, IEEE754_CLASS_SNAN):
+ case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_SNAN):
+ case CLPAIR(IEEE754_CLASS_NORM, IEEE754_CLASS_SNAN):
+ case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_SNAN):
+ case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_SNAN):
+ case CLPAIR(IEEE754_CLASS_SNAN, IEEE754_CLASS_ZERO):
+ case CLPAIR(IEEE754_CLASS_SNAN, IEEE754_CLASS_NORM):
+ case CLPAIR(IEEE754_CLASS_SNAN, IEEE754_CLASS_DNORM):
+ case CLPAIR(IEEE754_CLASS_SNAN, IEEE754_CLASS_INF):
+ SETCX(IEEE754_INVALID_OPERATION);
+ return ieee754dp_nanxcpt(ieee754dp_indef(), "div", x, y);
+
+ case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_QNAN):
+ case CLPAIR(IEEE754_CLASS_NORM, IEEE754_CLASS_QNAN):
+ case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_QNAN):
+ case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_QNAN):
+ return y;
+
+ case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_QNAN):
+ case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_ZERO):
+ case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_NORM):
+ case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_DNORM):
+ case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_INF):
+ return x;
+
+ /* Infinity handling
+ */
+
+ case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_INF):
+ SETCX(IEEE754_INVALID_OPERATION);
+ return ieee754dp_xcpt(ieee754dp_indef(), "div", x, y);
+
+ case CLPAIR(IEEE754_CLASS_NORM, IEEE754_CLASS_INF):
+ case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_INF):
+ case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_INF):
+ return ieee754dp_zero(xs ^ ys);
+
+ case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_ZERO):
+ case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_NORM):
+ case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_DNORM):
+ return ieee754dp_inf(xs ^ ys);
+
+ /* Zero handling
+ */
+
+ case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_ZERO):
+ SETCX(IEEE754_INVALID_OPERATION);
+ return ieee754dp_xcpt(ieee754dp_indef(), "div", x, y);
+
+ case CLPAIR(IEEE754_CLASS_NORM, IEEE754_CLASS_ZERO):
+ case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_ZERO):
+ SETCX(IEEE754_ZERO_DIVIDE);
+ return ieee754dp_xcpt(ieee754dp_inf(xs ^ ys), "div", x, y);
+
+ case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_NORM):
+ case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_DNORM):
+ return ieee754dp_zero(xs == ys ? 0 : 1);
+
+ case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_DNORM):
+ DPDNORMX;
+
+ case CLPAIR(IEEE754_CLASS_NORM, IEEE754_CLASS_DNORM):
+ DPDNORMY;
+ break;
+
+ case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_NORM):
+ DPDNORMX;
+ break;
+
+ case CLPAIR(IEEE754_CLASS_NORM, IEEE754_CLASS_NORM):
+ break;
+ }
+ assert(xm & DP_HIDDEN_BIT);
+ assert(ym & DP_HIDDEN_BIT);
+
+ /* provide rounding space */
+ xm <<= 3;
+ ym <<= 3;
+
+ {
+ /* now the dirty work */
+
+ u64 rm = 0;
+ int re = xe - ye;
+ u64 bm;
+
+ for (bm = DP_MBIT(DP_MBITS + 2); bm; bm >>= 1) {
+ if (xm >= ym) {
+ xm -= ym;
+ rm |= bm;
+ if (xm == 0)
+ break;
+ }
+ xm <<= 1;
+ }
+ rm <<= 1;
+ if (xm)
+ rm |= 1; /* have remainder, set sticky */
+
+ assert(rm);
+
+ /* normalise rm to rounding precision ?
+ */
+ while ((rm >> (DP_MBITS + 3)) == 0) {
+ rm <<= 1;
+ re--;
+ }
+
+ DPNORMRET2(xs == ys ? 0 : 1, re, rm, "div", x, y);
+ }
+}
diff -Nur linux-3.4.113.orig/arch/nds32/math-emu/dp_fint.c linux-3.4.113/arch/nds32/math-emu/dp_fint.c
--- linux-3.4.113.orig/arch/nds32/math-emu/dp_fint.c 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/math-emu/dp_fint.c 2016-12-01 20:59:24.360613059 +0100
@@ -0,0 +1,79 @@
+/* IEEE754 floating point arithmetic
+ * double precision: common utilities
+ */
+/*
+ * MIPS floating point support
+ * Copyright (C) 1994-2000 Algorithmics Ltd.
+ * http://www.algor.co.uk
+ *
+ * ########################################################################
+ *
+ * This program is free software; you can distribute it and/or modify it
+ * under the terms of the GNU General Public License (Version 2) as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
+ *
+ * ########################################################################
+ */
+
+#include "ieee754dp.h"
+
+ieee754dp ieee754dp_fint(int x)
+{
+ u64 xm;
+ int xe;
+ int xs;
+
+ CLEARCX;
+
+ if (x == 0)
+ return ieee754dp_zero(0);
+ if (x == 1 || x == -1)
+ return ieee754dp_one(x < 0);
+ if (x == 10 || x == -10)
+ return ieee754dp_ten(x < 0);
+
+ xs = (x < 0);
+ if (xs) {
+ if (x == (1 << 31))
+ xm = ((unsigned)1 << 31); /* max neg can't be safely negated */
+ else
+ xm = -x;
+ } else {
+ xm = x;
+ }
+
+#if 1
+ /* normalize - result can never be inexact or overflow */
+ xe = DP_MBITS;
+ while ((xm >> DP_MBITS) == 0) {
+ xm <<= 1;
+ xe--;
+ }
+ return builddp(xs, xe + DP_EBIAS, xm & ~DP_HIDDEN_BIT);
+#else
+ /* normalize */
+ xe = DP_MBITS + 3;
+ while ((xm >> (DP_MBITS + 3)) == 0) {
+ xm <<= 1;
+ xe--;
+ }
+ DPNORMRET1(xs, xe, xm, "fint", x);
+#endif
+}
+
+ieee754dp ieee754dp_funs(unsigned int u)
+{
+ if ((int)u < 0)
+ return ieee754dp_add(ieee754dp_1e31(),
+ ieee754dp_fint(u & ~(1 << 31)));
+ return ieee754dp_fint(u);
+}
diff -Nur linux-3.4.113.orig/arch/nds32/math-emu/dp_flong.c linux-3.4.113/arch/nds32/math-emu/dp_flong.c
--- linux-3.4.113.orig/arch/nds32/math-emu/dp_flong.c 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/math-emu/dp_flong.c 2016-12-01 20:59:24.360613059 +0100
@@ -0,0 +1,77 @@
+/* IEEE754 floating point arithmetic
+ * double precision: common utilities
+ */
+/*
+ * MIPS floating point support
+ * Copyright (C) 1994-2000 Algorithmics Ltd.
+ * http://www.algor.co.uk
+ *
+ * ########################################################################
+ *
+ * This program is free software; you can distribute it and/or modify it
+ * under the terms of the GNU General Public License (Version 2) as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
+ *
+ * ########################################################################
+ */
+
+#include "ieee754dp.h"
+
+ieee754dp ieee754dp_flong(s64 x)
+{
+ u64 xm;
+ int xe;
+ int xs;
+
+ CLEARCX;
+
+ if (x == 0)
+ return ieee754dp_zero(0);
+ if (x == 1 || x == -1)
+ return ieee754dp_one(x < 0);
+ if (x == 10 || x == -10)
+ return ieee754dp_ten(x < 0);
+
+ xs = (x < 0);
+ if (xs) {
+ if (x == (1ULL << 63))
+ xm = (1ULL << 63); /* max neg can't be safely negated */
+ else
+ xm = -x;
+ } else {
+ xm = x;
+ }
+
+ /* normalize */
+ xe = DP_MBITS + 3;
+ if (xm >> (DP_MBITS + 1 + 3)) {
+ /* shunt out overflow bits */
+ while (xm >> (DP_MBITS + 1 + 3)) {
+ XDPSRSX1();
+ }
+ } else {
+ /* normalize in grs extended double precision */
+ while ((xm >> (DP_MBITS + 3)) == 0) {
+ xm <<= 1;
+ xe--;
+ }
+ }
+ DPNORMRET1(xs, xe, xm, "dp_flong", x);
+}
+
+ieee754dp ieee754dp_fulong(u64 u)
+{
+ if ((s64) u < 0)
+ return ieee754dp_add(ieee754dp_1e63(),
+ ieee754dp_flong(u & ~(1ULL << 63)));
+ return ieee754dp_flong(u);
+}
diff -Nur linux-3.4.113.orig/arch/nds32/math-emu/dp_frexp.c linux-3.4.113/arch/nds32/math-emu/dp_frexp.c
--- linux-3.4.113.orig/arch/nds32/math-emu/dp_frexp.c 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/math-emu/dp_frexp.c 2016-12-01 20:59:24.360613059 +0100
@@ -0,0 +1,52 @@
+/* IEEE754 floating point arithmetic
+ * double precision: common utilities
+ */
+/*
+ * MIPS floating point support
+ * Copyright (C) 1994-2000 Algorithmics Ltd.
+ * http://www.algor.co.uk
+ *
+ * ########################################################################
+ *
+ * This program is free software; you can distribute it and/or modify it
+ * under the terms of the GNU General Public License (Version 2) as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
+ *
+ * ########################################################################
+ */
+
+#include "ieee754dp.h"
+
+/* close to ieeep754dp_logb
+*/
+ieee754dp ieee754dp_frexp(ieee754dp x, int *eptr)
+{
+ COMPXDP;
+ CLEARCX;
+ EXPLODEXDP;
+
+ switch (xc) {
+ case IEEE754_CLASS_SNAN:
+ case IEEE754_CLASS_QNAN:
+ case IEEE754_CLASS_INF:
+ case IEEE754_CLASS_ZERO:
+ *eptr = 0;
+ return x;
+ case IEEE754_CLASS_DNORM:
+ DPDNORMX;
+ break;
+ case IEEE754_CLASS_NORM:
+ break;
+ }
+ *eptr = xe + 1;
+ return builddp(xs, -1 + DP_EBIAS, xm & ~DP_HIDDEN_BIT);
+}
diff -Nur linux-3.4.113.orig/arch/nds32/math-emu/dp_fsp.c linux-3.4.113/arch/nds32/math-emu/dp_fsp.c
--- linux-3.4.113.orig/arch/nds32/math-emu/dp_fsp.c 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/math-emu/dp_fsp.c 2016-12-01 20:59:24.364613214 +0100
@@ -0,0 +1,71 @@
+/* IEEE754 floating point arithmetic
+ * double precision: common utilities
+ */
+/*
+ * MIPS floating point support
+ * Copyright (C) 1994-2000 Algorithmics Ltd.
+ * http://www.algor.co.uk
+ *
+ * ########################################################################
+ *
+ * This program is free software; you can distribute it and/or modify it
+ * under the terms of the GNU General Public License (Version 2) as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
+ *
+ * ########################################################################
+ */
+
+#include "ieee754dp.h"
+
+ieee754dp ieee754dp_fsp(ieee754sp x)
+{
+ COMPXSP;
+
+ EXPLODEXSP;
+
+ CLEARCX;
+
+ FLUSHXSP;
+
+ switch (xc) {
+ case IEEE754_CLASS_SNAN:
+ SETCX(IEEE754_INVALID_OPERATION);
+ return ieee754dp_nanxcpt(ieee754dp_indef(), "fsp");
+ case IEEE754_CLASS_QNAN:
+ return ieee754dp_nanxcpt(builddp(xs,
+ DP_EMAX + 1 + DP_EBIAS,
+ ((u64) xm
+ << (DP_MBITS -
+ SP_MBITS))), "fsp", x);
+ case IEEE754_CLASS_INF:
+ return ieee754dp_inf(xs);
+ case IEEE754_CLASS_ZERO:
+ return ieee754dp_zero(xs);
+ case IEEE754_CLASS_DNORM:
+ /* normalize */
+ while ((xm >> SP_MBITS) == 0) {
+ xm <<= 1;
+ xe--;
+ }
+ break;
+ case IEEE754_CLASS_NORM:
+ break;
+ }
+
+ /* CANT possibly overflow,underflow, or need rounding
+ */
+
+ /* drop the hidden bit */
+ xm &= ~SP_HIDDEN_BIT;
+
+ return builddp(xs, xe + DP_EBIAS, (u64) xm << (DP_MBITS - SP_MBITS));
+}
diff -Nur linux-3.4.113.orig/arch/nds32/math-emu/dp_logb.c linux-3.4.113/arch/nds32/math-emu/dp_logb.c
--- linux-3.4.113.orig/arch/nds32/math-emu/dp_logb.c 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/math-emu/dp_logb.c 2016-12-01 20:59:24.364613214 +0100
@@ -0,0 +1,53 @@
+/* IEEE754 floating point arithmetic
+ * double precision: common utilities
+ */
+/*
+ * MIPS floating point support
+ * Copyright (C) 1994-2000 Algorithmics Ltd.
+ * http://www.algor.co.uk
+ *
+ * ########################################################################
+ *
+ * This program is free software; you can distribute it and/or modify it
+ * under the terms of the GNU General Public License (Version 2) as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
+ *
+ * ########################################################################
+ */
+
+#include "ieee754dp.h"
+
+ieee754dp ieee754dp_logb(ieee754dp x)
+{
+ COMPXDP;
+
+ CLEARCX;
+
+ EXPLODEXDP;
+
+ switch (xc) {
+ case IEEE754_CLASS_SNAN:
+ return ieee754dp_nanxcpt(x, "logb", x);
+ case IEEE754_CLASS_QNAN:
+ return x;
+ case IEEE754_CLASS_INF:
+ return ieee754dp_inf(0);
+ case IEEE754_CLASS_ZERO:
+ return ieee754dp_inf(1);
+ case IEEE754_CLASS_DNORM:
+ DPDNORMX;
+ break;
+ case IEEE754_CLASS_NORM:
+ break;
+ }
+ return ieee754dp_fint(xe);
+}
diff -Nur linux-3.4.113.orig/arch/nds32/math-emu/dp_modf.c linux-3.4.113/arch/nds32/math-emu/dp_modf.c
--- linux-3.4.113.orig/arch/nds32/math-emu/dp_modf.c 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/math-emu/dp_modf.c 2016-12-01 20:59:24.364613214 +0100
@@ -0,0 +1,79 @@
+/* IEEE754 floating point arithmetic
+ * double precision: common utilities
+ */
+/*
+ * MIPS floating point support
+ * Copyright (C) 1994-2000 Algorithmics Ltd.
+ * http://www.algor.co.uk
+ *
+ * ########################################################################
+ *
+ * This program is free software; you can distribute it and/or modify it
+ * under the terms of the GNU General Public License (Version 2) as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
+ *
+ * ########################################################################
+ */
+
+#include "ieee754dp.h"
+
+/* modf function is always exact for a finite number
+*/
+ieee754dp ieee754dp_modf(ieee754dp x, ieee754dp * ip)
+{
+ COMPXDP;
+
+ CLEARCX;
+
+ EXPLODEXDP;
+
+ switch (xc) {
+ case IEEE754_CLASS_SNAN:
+ case IEEE754_CLASS_QNAN:
+ case IEEE754_CLASS_INF:
+ case IEEE754_CLASS_ZERO:
+ *ip = x;
+ return x;
+ case IEEE754_CLASS_DNORM:
+ /* far to small */
+ *ip = ieee754dp_zero(xs);
+ return x;
+ case IEEE754_CLASS_NORM:
+ break;
+ }
+ if (xe < 0) {
+ *ip = ieee754dp_zero(xs);
+ return x;
+ }
+ if (xe >= DP_MBITS) {
+ *ip = x;
+ return ieee754dp_zero(xs);
+ }
+ /* generate ipart mantissa by clearing bottom bits
+ */
+ *ip = builddp(xs, xe + DP_EBIAS,
+ ((xm >> (DP_MBITS - xe)) << (DP_MBITS - xe)) &
+ ~DP_HIDDEN_BIT);
+
+ /* generate fpart mantissa by clearing top bits
+ * and normalizing (must be able to normalize)
+ */
+ xm = (xm << (64 - (DP_MBITS - xe))) >> (64 - (DP_MBITS - xe));
+ if (xm == 0)
+ return ieee754dp_zero(xs);
+
+ while ((xm >> DP_MBITS) == 0) {
+ xm <<= 1;
+ xe--;
+ }
+ return builddp(xs, xe + DP_EBIAS, xm & ~DP_HIDDEN_BIT);
+}
diff -Nur linux-3.4.113.orig/arch/nds32/math-emu/dp_mul.c linux-3.4.113/arch/nds32/math-emu/dp_mul.c
--- linux-3.4.113.orig/arch/nds32/math-emu/dp_mul.c 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/math-emu/dp_mul.c 2016-12-01 20:59:24.364613214 +0100
@@ -0,0 +1,170 @@
+/* IEEE754 floating point arithmetic
+ * double precision: common utilities
+ */
+/*
+ * MIPS floating point support
+ * Copyright (C) 1994-2000 Algorithmics Ltd.
+ * http://www.algor.co.uk
+ *
+ * ########################################################################
+ *
+ * This program is free software; you can distribute it and/or modify it
+ * under the terms of the GNU General Public License (Version 2) as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
+ *
+ * ########################################################################
+ */
+
+#include "ieee754dp.h"
+
+ieee754dp ieee754dp_mul(ieee754dp x, ieee754dp y)
+{
+ COMPXDP;
+ COMPYDP;
+
+ EXPLODEXDP;
+ EXPLODEYDP;
+
+ CLEARCX;
+
+ FLUSHXDP;
+ FLUSHYDP;
+
+ switch (CLPAIR(xc, yc)) {
+ case CLPAIR(IEEE754_CLASS_SNAN, IEEE754_CLASS_QNAN):
+ case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_SNAN):
+ case CLPAIR(IEEE754_CLASS_SNAN, IEEE754_CLASS_SNAN):
+ case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_SNAN):
+ case CLPAIR(IEEE754_CLASS_NORM, IEEE754_CLASS_SNAN):
+ case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_SNAN):
+ case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_SNAN):
+ case CLPAIR(IEEE754_CLASS_SNAN, IEEE754_CLASS_ZERO):
+ case CLPAIR(IEEE754_CLASS_SNAN, IEEE754_CLASS_NORM):
+ case CLPAIR(IEEE754_CLASS_SNAN, IEEE754_CLASS_DNORM):
+ case CLPAIR(IEEE754_CLASS_SNAN, IEEE754_CLASS_INF):
+ SETCX(IEEE754_INVALID_OPERATION);
+ return ieee754dp_nanxcpt(ieee754dp_indef(), "mul", x, y);
+
+ case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_QNAN):
+ case CLPAIR(IEEE754_CLASS_NORM, IEEE754_CLASS_QNAN):
+ case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_QNAN):
+ case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_QNAN):
+ return y;
+
+ case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_QNAN):
+ case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_ZERO):
+ case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_NORM):
+ case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_DNORM):
+ case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_INF):
+ return x;
+
+ /* Infinity handling */
+
+ case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_ZERO):
+ case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_INF):
+ SETCX(IEEE754_INVALID_OPERATION);
+ return ieee754dp_xcpt(ieee754dp_indef(), "mul", x, y);
+
+ case CLPAIR(IEEE754_CLASS_NORM, IEEE754_CLASS_INF):
+ case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_INF):
+ case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_NORM):
+ case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_DNORM):
+ case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_INF):
+ return ieee754dp_inf(xs ^ ys);
+
+ case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_ZERO):
+ case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_NORM):
+ case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_DNORM):
+ case CLPAIR(IEEE754_CLASS_NORM, IEEE754_CLASS_ZERO):
+ case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_ZERO):
+ return ieee754dp_zero(xs ^ ys);
+
+ case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_DNORM):
+ DPDNORMX;
+
+ case CLPAIR(IEEE754_CLASS_NORM, IEEE754_CLASS_DNORM):
+ DPDNORMY;
+ break;
+
+ case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_NORM):
+ DPDNORMX;
+ break;
+
+ case CLPAIR(IEEE754_CLASS_NORM, IEEE754_CLASS_NORM):
+ break;
+ }
+ /* rm = xm * ym, re = xe+ye basicly */
+ assert(xm & DP_HIDDEN_BIT);
+ assert(ym & DP_HIDDEN_BIT);
+ {
+ int re = xe + ye;
+ int rs = xs ^ ys;
+ u64 rm;
+
+ /* shunt to top of word */
+ xm <<= 64 - (DP_MBITS + 1);
+ ym <<= 64 - (DP_MBITS + 1);
+
+ /* multiply 32bits xm,ym to give high 32bits rm with stickness
+ */
+
+ /* 32 * 32 => 64 */
+#define DPXMULT(x, y) ((u64)(x) * (u64)y)
+
+ {
+ unsigned lxm = xm;
+ unsigned hxm = xm >> 32;
+ unsigned lym = ym;
+ unsigned hym = ym >> 32;
+ u64 lrm;
+ u64 hrm;
+
+ lrm = DPXMULT(lxm, lym);
+ hrm = DPXMULT(hxm, hym);
+
+ {
+ u64 t = DPXMULT(lxm, hym);
+ {
+ u64 at = lrm + (t << 32);
+ hrm += at < lrm;
+ lrm = at;
+ }
+ hrm = hrm + (t >> 32);
+ }
+
+ {
+ u64 t = DPXMULT(hxm, lym);
+ {
+ u64 at = lrm + (t << 32);
+ hrm += at < lrm;
+ lrm = at;
+ }
+ hrm = hrm + (t >> 32);
+ }
+ rm = hrm | (lrm != 0);
+ }
+
+ /*
+ * sticky shift down to normal rounding precision
+ */
+ if ((s64) rm < 0) {
+ rm = (rm >> (64 - (DP_MBITS + 1 + 3))) |
+ ((rm << (DP_MBITS + 1 + 3)) != 0);
+ re++;
+ } else {
+ rm = (rm >> (64 - (DP_MBITS + 1 + 3 + 1))) |
+ ((rm << (DP_MBITS + 1 + 3 + 1)) != 0);
+ }
+ assert(rm & (DP_HIDDEN_BIT << 3));
+ DPNORMRET2(rs, re, rm, "mul", x, y);
+ }
+}
diff -Nur linux-3.4.113.orig/arch/nds32/math-emu/dp_scalb.c linux-3.4.113/arch/nds32/math-emu/dp_scalb.c
--- linux-3.4.113.orig/arch/nds32/math-emu/dp_scalb.c 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/math-emu/dp_scalb.c 2016-12-01 20:59:24.364613214 +0100
@@ -0,0 +1,56 @@
+/* IEEE754 floating point arithmetic
+ * double precision: common utilities
+ */
+/*
+ * MIPS floating point support
+ * Copyright (C) 1994-2000 Algorithmics Ltd.
+ * http://www.algor.co.uk
+ *
+ * ########################################################################
+ *
+ * This program is free software; you can distribute it and/or modify it
+ * under the terms of the GNU General Public License (Version 2) as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
+ *
+ * ########################################################################
+ */
+
+#include "ieee754dp.h"
+
+ieee754dp ieee754dp_scalb(ieee754dp x, int n)
+{
+ COMPXDP;
+
+ CLEARCX;
+
+ EXPLODEXDP;
+
+ switch (xc) {
+ case IEEE754_CLASS_SNAN:
+ return ieee754dp_nanxcpt(x, "scalb", x, n);
+ case IEEE754_CLASS_QNAN:
+ case IEEE754_CLASS_INF:
+ case IEEE754_CLASS_ZERO:
+ return x;
+ case IEEE754_CLASS_DNORM:
+ DPDNORMX;
+ break;
+ case IEEE754_CLASS_NORM:
+ break;
+ }
+ DPNORMRET2(xs, xe + n, xm << 3, "scalb", x, n);
+}
+
+ieee754dp ieee754dp_ldexp(ieee754dp x, int n)
+{
+ return ieee754dp_scalb(x, n);
+}
diff -Nur linux-3.4.113.orig/arch/nds32/math-emu/dp_simple.c linux-3.4.113/arch/nds32/math-emu/dp_simple.c
--- linux-3.4.113.orig/arch/nds32/math-emu/dp_simple.c 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/math-emu/dp_simple.c 2016-12-01 20:59:24.364613214 +0100
@@ -0,0 +1,87 @@
+/* IEEE754 floating point arithmetic
+ * double precision: common utilities
+ */
+/*
+ * MIPS floating point support
+ * Copyright (C) 1994-2000 Algorithmics Ltd.
+ * http://www.algor.co.uk
+ *
+ * ########################################################################
+ *
+ * This program is free software; you can distribute it and/or modify it
+ * under the terms of the GNU General Public License (Version 2) as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
+ *
+ * ########################################################################
+ */
+
+#include "ieee754dp.h"
+
+int ieee754dp_finite(ieee754dp x)
+{
+ return DPBEXP(x) != DP_EMAX + 1 + DP_EBIAS;
+}
+
+ieee754dp ieee754dp_copysign(ieee754dp x, ieee754dp y)
+{
+ CLEARCX;
+ DPSIGN(x) = DPSIGN(y);
+ return x;
+}
+
+ieee754dp ieee754dp_neg(ieee754dp x)
+{
+ COMPXDP;
+
+ EXPLODEXDP;
+ CLEARCX;
+ FLUSHXDP;
+
+ /*
+ * Invert the sign ALWAYS to prevent an endless recursion on
+ * pow() in libc.
+ */
+ /* quick fix up */
+ DPSIGN(x) ^= 1;
+
+ if (xc == IEEE754_CLASS_SNAN) {
+ ieee754dp y = ieee754dp_indef();
+ SETCX(IEEE754_INVALID_OPERATION);
+ DPSIGN(y) = DPSIGN(x);
+ return ieee754dp_nanxcpt(y, "neg");
+ }
+
+ if (ieee754dp_isnan(x)) /* but not infinity */
+ return ieee754dp_nanxcpt(x, "neg", x);
+ return x;
+}
+
+ieee754dp ieee754dp_abs(ieee754dp x)
+{
+ COMPXDP;
+
+ EXPLODEXDP;
+ CLEARCX;
+ FLUSHXDP;
+
+ if (xc == IEEE754_CLASS_SNAN) {
+ SETCX(IEEE754_INVALID_OPERATION);
+ return ieee754dp_nanxcpt(ieee754dp_indef(), "neg");
+ }
+
+ if (ieee754dp_isnan(x)) /* but not infinity */
+ return ieee754dp_nanxcpt(x, "abs", x);
+
+ /* quick fix up */
+ DPSIGN(x) = 0;
+ return x;
+}
diff -Nur linux-3.4.113.orig/arch/nds32/math-emu/dp_sqrt.c linux-3.4.113/arch/nds32/math-emu/dp_sqrt.c
--- linux-3.4.113.orig/arch/nds32/math-emu/dp_sqrt.c 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/math-emu/dp_sqrt.c 2016-12-01 20:59:24.364613214 +0100
@@ -0,0 +1,164 @@
+/* IEEE754 floating point arithmetic
+ * double precision square root
+ */
+/*
+ * MIPS floating point support
+ * Copyright (C) 1994-2000 Algorithmics Ltd.
+ * http://www.algor.co.uk
+ *
+ * ########################################################################
+ *
+ * This program is free software; you can distribute it and/or modify it
+ * under the terms of the GNU General Public License (Version 2) as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
+ *
+ * ########################################################################
+ */
+
+#include "ieee754dp.h"
+
+static const unsigned table[] = {
+ 0, 1204, 3062, 5746, 9193, 13348, 18162, 23592,
+ 29598, 36145, 43202, 50740, 58733, 67158, 75992,
+ 85215, 83599, 71378, 60428, 50647, 41945, 34246,
+ 27478, 21581, 16499, 12183, 8588, 5674, 3403,
+ 1742, 661, 130
+};
+
+ieee754dp ieee754dp_sqrt(ieee754dp x)
+{
+ struct _ieee754_csr oldcsr;
+ ieee754dp y, z, t;
+ unsigned scalx, yh;
+ COMPXDP;
+
+ EXPLODEXDP;
+ CLEARCX;
+ FLUSHXDP;
+
+ /* x == INF or NAN? */
+ switch (xc) {
+ case IEEE754_CLASS_QNAN:
+ /* sqrt(Nan) = Nan */
+ return ieee754dp_nanxcpt(x, "sqrt");
+ case IEEE754_CLASS_SNAN:
+ SETCX(IEEE754_INVALID_OPERATION);
+ return ieee754dp_nanxcpt(ieee754dp_indef(), "sqrt");
+ case IEEE754_CLASS_ZERO:
+ /* sqrt(0) = 0 */
+ return x;
+ case IEEE754_CLASS_INF:
+ if (xs) {
+ /* sqrt(-Inf) = Nan */
+ SETCX(IEEE754_INVALID_OPERATION);
+ return ieee754dp_nanxcpt(ieee754dp_indef(), "sqrt");
+ }
+ /* sqrt(+Inf) = Inf */
+ return x;
+ case IEEE754_CLASS_DNORM:
+ DPDNORMX;
+ /* fall through */
+ case IEEE754_CLASS_NORM:
+ if (xs) {
+ /* sqrt(-x) = Nan */
+ SETCX(IEEE754_INVALID_OPERATION);
+ return ieee754dp_nanxcpt(ieee754dp_indef(), "sqrt");
+ }
+ break;
+ }
+
+ /* save old csr; switch off INX enable & flag; set RN rounding */
+ oldcsr = ieee754_csr;
+ ieee754_csr.mx &= ~IEEE754_INEXACT;
+ ieee754_csr.sx &= ~IEEE754_INEXACT;
+ ieee754_csr.rm = IEEE754_RN;
+
+ /* adjust exponent to prevent overflow */
+ scalx = 0;
+ if (xe > 512) { /* x > 2**-512? */
+ xe -= 512; /* x = x / 2**512 */
+ scalx += 256;
+ } else if (xe < -512) { /* x < 2**-512? */
+ xe += 512; /* x = x * 2**512 */
+ scalx -= 256;
+ }
+
+ y = x = builddp(0, xe + DP_EBIAS, xm & ~DP_HIDDEN_BIT);
+
+ /* magic initial approximation to almost 8 sig. bits */
+ yh = y.bits >> 32;
+ yh = (yh >> 1) + 0x1ff80000;
+ yh = yh - table[(yh >> 15) & 31];
+ y.bits = ((u64) yh << 32) | (y.bits & 0xffffffff);
+
+ /* Heron's rule once with correction to improve to ~18 sig. bits */
+ /* t=x/y; y=y+t; py[n0]=py[n0]-0x00100006; py[n1]=0; */
+ t = ieee754dp_div(x, y);
+ y = ieee754dp_add(y, t);
+ y.bits -= 0x0010000600000000LL;
+ y.bits &= 0xffffffff00000000LL;
+
+ /* triple to almost 56 sig. bits: y ~= sqrt(x) to within 1 ulp */
+ /* t=y*y; z=t; pt[n0]+=0x00100000; t+=z; z=(x-z)*y; */
+ z = t = ieee754dp_mul(y, y);
+ t.parts.bexp += 0x001;
+ t = ieee754dp_add(t, z);
+ z = ieee754dp_mul(ieee754dp_sub(x, z), y);
+
+ /* t=z/(t+x) ; pt[n0]+=0x00100000; y+=t; */
+ t = ieee754dp_div(z, ieee754dp_add(t, x));
+ t.parts.bexp += 0x001;
+ y = ieee754dp_add(y, t);
+
+ /* twiddle last bit to force y correctly rounded */
+
+ /* set RZ, clear INEX flag */
+ ieee754_csr.rm = IEEE754_RZ;
+ ieee754_csr.sx &= ~IEEE754_INEXACT;
+
+ /* t=x/y; ...chopped quotient, possibly inexact */
+ t = ieee754dp_div(x, y);
+
+ if (ieee754_csr.sx & IEEE754_INEXACT || t.bits != y.bits) {
+
+ if (!(ieee754_csr.sx & IEEE754_INEXACT))
+ /* t = t-ulp */
+ t.bits -= 1;
+
+ /* add inexact to result status */
+ oldcsr.cx |= IEEE754_INEXACT;
+ oldcsr.sx |= IEEE754_INEXACT;
+
+ switch (oldcsr.rm) {
+ case IEEE754_RP:
+ y.bits += 1;
+ /* drop through */
+ case IEEE754_RN:
+ t.bits += 1;
+ break;
+ }
+
+ /* y=y+t; ...chopped sum */
+ y = ieee754dp_add(y, t);
+
+ /* adjust scalx for correctly rounded sqrt(x) */
+ scalx -= 1;
+ }
+
+ /* py[n0]=py[n0]+scalx; ...scale back y */
+ y.parts.bexp += scalx;
+
+ /* restore rounding mode, possibly set inexact */
+ ieee754_csr = oldcsr;
+
+ return y;
+}
diff -Nur linux-3.4.113.orig/arch/nds32/math-emu/dp_sub.c linux-3.4.113/arch/nds32/math-emu/dp_sub.c
--- linux-3.4.113.orig/arch/nds32/math-emu/dp_sub.c 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/math-emu/dp_sub.c 2016-12-01 20:59:24.364613214 +0100
@@ -0,0 +1,187 @@
+/* IEEE754 floating point arithmetic
+ * double precision: common utilities
+ */
+/*
+ * MIPS floating point support
+ * Copyright (C) 1994-2000 Algorithmics Ltd.
+ * http://www.algor.co.uk
+ *
+ * ########################################################################
+ *
+ * This program is free software; you can distribute it and/or modify it
+ * under the terms of the GNU General Public License (Version 2) as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
+ *
+ * ########################################################################
+ */
+
+#include "ieee754dp.h"
+
+ieee754dp ieee754dp_sub(ieee754dp x, ieee754dp y)
+{
+ COMPXDP;
+ COMPYDP;
+
+ EXPLODEXDP;
+ EXPLODEYDP;
+
+ CLEARCX;
+
+ FLUSHXDP;
+ FLUSHYDP;
+
+ switch (CLPAIR(xc, yc)) {
+ case CLPAIR(IEEE754_CLASS_SNAN, IEEE754_CLASS_QNAN):
+ case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_SNAN):
+ case CLPAIR(IEEE754_CLASS_SNAN, IEEE754_CLASS_SNAN):
+ case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_SNAN):
+ case CLPAIR(IEEE754_CLASS_NORM, IEEE754_CLASS_SNAN):
+ case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_SNAN):
+ case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_SNAN):
+ case CLPAIR(IEEE754_CLASS_SNAN, IEEE754_CLASS_ZERO):
+ case CLPAIR(IEEE754_CLASS_SNAN, IEEE754_CLASS_NORM):
+ case CLPAIR(IEEE754_CLASS_SNAN, IEEE754_CLASS_DNORM):
+ case CLPAIR(IEEE754_CLASS_SNAN, IEEE754_CLASS_INF):
+ SETCX(IEEE754_INVALID_OPERATION);
+ return ieee754dp_nanxcpt(ieee754dp_indef(), "sub", x, y);
+
+ case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_QNAN):
+ case CLPAIR(IEEE754_CLASS_NORM, IEEE754_CLASS_QNAN):
+ case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_QNAN):
+ case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_QNAN):
+ return y;
+
+ case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_QNAN):
+ case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_ZERO):
+ case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_NORM):
+ case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_DNORM):
+ case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_INF):
+ return x;
+
+ /* Infinity handling
+ */
+
+ case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_INF):
+ if (xs != ys)
+ return x;
+ SETCX(IEEE754_INVALID_OPERATION);
+ return ieee754dp_xcpt(ieee754dp_indef(), "sub", x, y);
+
+ case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_INF):
+ case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_INF):
+ case CLPAIR(IEEE754_CLASS_NORM, IEEE754_CLASS_INF):
+ return ieee754dp_inf(ys ^ 1);
+
+ case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_ZERO):
+ case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_NORM):
+ case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_DNORM):
+ return x;
+
+ /* Zero handling
+ */
+
+ case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_ZERO):
+ if (xs != ys)
+ return x;
+ else
+ return ieee754dp_zero(ieee754_csr.rm == IEEE754_RD);
+
+ case CLPAIR(IEEE754_CLASS_NORM, IEEE754_CLASS_ZERO):
+ case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_ZERO):
+ return x;
+
+ case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_NORM):
+ case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_DNORM):
+ /* quick fix up */
+ DPSIGN(y) ^= 1;
+ return y;
+
+ case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_DNORM):
+ DPDNORMX;
+ /* FAAL THOROUGH */
+
+ case CLPAIR(IEEE754_CLASS_NORM, IEEE754_CLASS_DNORM):
+ /* normalize ym,ye */
+ DPDNORMY;
+ break;
+
+ case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_NORM):
+ /* normalize xm,xe */
+ DPDNORMX;
+ break;
+
+ case CLPAIR(IEEE754_CLASS_NORM, IEEE754_CLASS_NORM):
+ break;
+ }
+ /* flip sign of y and handle as add */
+ ys ^= 1;
+
+ assert(xm & DP_HIDDEN_BIT);
+ assert(ym & DP_HIDDEN_BIT);
+
+ /* provide guard,round and stick bit dpace */
+ xm <<= 3;
+ ym <<= 3;
+
+ if (xe > ye) {
+ /* have to shift y fraction right to align
+ */
+ int s = xe - ye;
+ ym = XDPSRS(ym, s);
+ ye += s;
+ } else if (ye > xe) {
+ /* have to shift x fraction right to align
+ */
+ int s = ye - xe;
+ xm = XDPSRS(xm, s);
+ xe += s;
+ }
+ assert(xe == ye);
+ assert(xe <= DP_EMAX);
+
+ if (xs == ys) {
+ /* generate 28 bit result of adding two 27 bit numbers
+ */
+ xm = xm + ym;
+ xe = xe;
+ xs = xs;
+
+ if (xm >> (DP_MBITS + 1 + 3)) { /* carry out */
+ xm = XDPSRS1(xm); /* shift preserving sticky */
+ xe++;
+ }
+ } else {
+ if (xm >= ym) {
+ xm = xm - ym;
+ xe = xe;
+ xs = xs;
+ } else {
+ xm = ym - xm;
+ xe = xe;
+ xs = ys;
+ }
+ if (xm == 0) {
+ if (ieee754_csr.rm == IEEE754_RD)
+ return ieee754dp_zero(1); /* round negative inf. => sign = -1 */
+ else
+ return ieee754dp_zero(0); /* other round modes => sign = 1 */
+ }
+
+ /* normalize to rounding precision
+ */
+ while ((xm >> (DP_MBITS + 3)) == 0) {
+ xm <<= 1;
+ xe--;
+ }
+ }
+ DPNORMRET2(xs, xe, xm, "sub", x, y);
+}
diff -Nur linux-3.4.113.orig/arch/nds32/math-emu/dp_tint.c linux-3.4.113/arch/nds32/math-emu/dp_tint.c
--- linux-3.4.113.orig/arch/nds32/math-emu/dp_tint.c 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/math-emu/dp_tint.c 2016-12-01 20:59:24.364613214 +0100
@@ -0,0 +1,121 @@
+/* IEEE754 floating point arithmetic
+ * double precision: common utilities
+ */
+/*
+ * MIPS floating point support
+ * Copyright (C) 1994-2000 Algorithmics Ltd.
+ * http://www.algor.co.uk
+ *
+ * ########################################################################
+ *
+ * This program is free software; you can distribute it and/or modify it
+ * under the terms of the GNU General Public License (Version 2) as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
+ *
+ * ########################################################################
+ */
+
+#include <linux/kernel.h>
+#include "ieee754dp.h"
+
+int ieee754dp_tint(ieee754dp x)
+{
+ COMPXDP;
+
+ CLEARCX;
+
+ EXPLODEXDP;
+ FLUSHXDP;
+
+ switch (xc) {
+ case IEEE754_CLASS_SNAN:
+ case IEEE754_CLASS_QNAN:
+ case IEEE754_CLASS_INF:
+ SETCX(IEEE754_INVALID_OPERATION);
+ return ieee754si_xcpt(ieee754si_indef(), "dp_tint", x);
+ case IEEE754_CLASS_ZERO:
+ return 0;
+ case IEEE754_CLASS_DNORM:
+ case IEEE754_CLASS_NORM:
+ break;
+ }
+ if (xe > 31) {
+ /* Set invalid. We will only use overflow for floating
+ point overflow */
+ SETCX(IEEE754_INVALID_OPERATION);
+ return ieee754si_xcpt(ieee754si_indef(), "dp_tint", x);
+ }
+ /* oh gawd */
+ if (xe > DP_MBITS) {
+ xm <<= xe - DP_MBITS;
+ } else if (xe < DP_MBITS) {
+ u64 residue;
+ int round;
+ int sticky;
+ int odd;
+
+ if (xe < -1) {
+ residue = xm;
+ round = 0;
+ sticky = residue != 0;
+ xm = 0;
+ } else {
+ residue = xm << (64 - DP_MBITS + xe);
+ round = (residue >> 63) != 0;
+ sticky = (residue << 1) != 0;
+ xm >>= DP_MBITS - xe;
+ }
+ /* Note: At this point upper 32 bits of xm are guaranteed
+ to be zero */
+ odd = (xm & 0x1) != 0x0;
+ switch (ieee754_csr.rm) {
+ case IEEE754_RN:
+ if (round && (sticky || odd))
+ xm++;
+ break;
+ case IEEE754_RZ:
+ break;
+ case IEEE754_RU: /* toward +Infinity */
+ if ((round || sticky) && !xs)
+ xm++;
+ break;
+ case IEEE754_RD: /* toward -Infinity */
+ if ((round || sticky) && xs)
+ xm++;
+ break;
+ }
+ /* look for valid corner case 0x80000000 */
+ if ((xm >> 31) != 0 && (xs == 0 || xm != 0x80000000)) {
+ /* This can happen after rounding */
+ SETCX(IEEE754_INVALID_OPERATION);
+ return ieee754si_xcpt(ieee754si_indef(), "dp_tint", x);
+ }
+ if (round || sticky)
+ SETCX(IEEE754_INEXACT);
+ }
+ if (xs)
+ return -xm;
+ else
+ return xm;
+}
+
+unsigned int ieee754dp_tuns(ieee754dp x)
+{
+ ieee754dp hb = ieee754dp_1e31();
+
+ /* what if x < 0 ?? */
+ if (ieee754dp_lt(x, hb))
+ return (unsigned)ieee754dp_tint(x);
+
+ return (unsigned)ieee754dp_tint(ieee754dp_sub(x, hb)) |
+ ((unsigned)1 << 31);
+}
diff -Nur linux-3.4.113.orig/arch/nds32/math-emu/dp_tlong.c linux-3.4.113/arch/nds32/math-emu/dp_tlong.c
--- linux-3.4.113.orig/arch/nds32/math-emu/dp_tlong.c 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/math-emu/dp_tlong.c 2016-12-01 20:59:24.364613214 +0100
@@ -0,0 +1,123 @@
+/* IEEE754 floating point arithmetic
+ * double precision: common utilities
+ */
+/*
+ * MIPS floating point support
+ * Copyright (C) 1994-2000 Algorithmics Ltd.
+ * http://www.algor.co.uk
+ *
+ * ########################################################################
+ *
+ * This program is free software; you can distribute it and/or modify it
+ * under the terms of the GNU General Public License (Version 2) as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
+ *
+ * ########################################################################
+ */
+
+#include "ieee754dp.h"
+
+s64 ieee754dp_tlong(ieee754dp x)
+{
+ COMPXDP;
+
+ CLEARCX;
+
+ EXPLODEXDP;
+ FLUSHXDP;
+
+ switch (xc) {
+ case IEEE754_CLASS_SNAN:
+ case IEEE754_CLASS_QNAN:
+ case IEEE754_CLASS_INF:
+ SETCX(IEEE754_INVALID_OPERATION);
+ return ieee754di_xcpt(ieee754di_indef(), "dp_tlong", x);
+ case IEEE754_CLASS_ZERO:
+ return 0;
+ case IEEE754_CLASS_DNORM:
+ case IEEE754_CLASS_NORM:
+ break;
+ }
+ if (xe >= 63) {
+ /* look for valid corner case */
+ if (xe == 63 && xs && xm == DP_HIDDEN_BIT)
+ return -0x8000000000000000LL;
+ /* Set invalid. We will only use overflow for floating
+ point overflow */
+ SETCX(IEEE754_INVALID_OPERATION);
+ return ieee754di_xcpt(ieee754di_indef(), "dp_tlong", x);
+ }
+ /* oh gawd */
+ if (xe > DP_MBITS) {
+ xm <<= xe - DP_MBITS;
+ } else if (xe < DP_MBITS) {
+ u64 residue;
+ int round;
+ int sticky;
+ int odd;
+
+ if (xe < -1) {
+ residue = xm;
+ round = 0;
+ sticky = residue != 0;
+ xm = 0;
+ } else {
+ /* Shifting a u64 64 times does not work,
+ * so we do it in two steps. Be aware that xe
+ * may be -1 */
+ residue = xm << (xe + 1);
+ residue <<= 63 - DP_MBITS;
+ round = (residue >> 63) != 0;
+ sticky = (residue << 1) != 0;
+ xm >>= DP_MBITS - xe;
+ }
+ odd = (xm & 0x1) != 0x0;
+ switch (ieee754_csr.rm) {
+ case IEEE754_RN:
+ if (round && (sticky || odd))
+ xm++;
+ break;
+ case IEEE754_RZ:
+ break;
+ case IEEE754_RU: /* toward +Infinity */
+ if ((round || sticky) && !xs)
+ xm++;
+ break;
+ case IEEE754_RD: /* toward -Infinity */
+ if ((round || sticky) && xs)
+ xm++;
+ break;
+ }
+ if ((xm >> 63) != 0) {
+ /* This can happen after rounding */
+ SETCX(IEEE754_INVALID_OPERATION);
+ return ieee754di_xcpt(ieee754di_indef(), "dp_tlong", x);
+ }
+ if (round || sticky)
+ SETCX(IEEE754_INEXACT);
+ }
+ if (xs)
+ return -xm;
+ else
+ return xm;
+}
+
+u64 ieee754dp_tulong(ieee754dp x)
+{
+ ieee754dp hb = ieee754dp_1e63();
+
+ /* what if x < 0 ?? */
+ if (ieee754dp_lt(x, hb))
+ return (u64) ieee754dp_tlong(x);
+
+ return (u64) ieee754dp_tlong(ieee754dp_sub(x, hb)) | (1ULL << 63);
+}
diff -Nur linux-3.4.113.orig/arch/nds32/math-emu/fpuemu.c linux-3.4.113/arch/nds32/math-emu/fpuemu.c
--- linux-3.4.113.orig/arch/nds32/math-emu/fpuemu.c 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/math-emu/fpuemu.c 2016-12-01 20:59:24.364613214 +0100
@@ -0,0 +1,565 @@
+/*
+ * linux/arch/nds32/math-emu/fpuemu.c: a nds32 coprocessor (fpu) instruction emulator
+ *
+ * MIPS floating point support
+ * Copyright (C) 1994-2000 Algorithmics Ltd.
+ * http://www.algor.co.uk
+ *
+ * Kevin D. Kissell, kevink@mips.com and Carsten Langgaard, carstenl@mips.com
+ * Copyright (C) 2000 MIPS Technologies, Inc.
+ * Copyright (C) 2009 Andes Technology Corporation
+ *
+ * This program is free software; you can distribute it and/or modify it
+ * under the terms of the GNU General Public License (Version 2) as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
+ *
+ * A complete emulator for MIPS coprocessor 1 instructions. This is
+ * required for #float(switch) or #float(trap), where it catches all
+ * COP1 instructions via the "CoProcessor Unusable" exception.
+ *
+ * More surprisingly it is also required for #float(ieee), to help out
+ * the hardware fpu at the boundaries of the IEEE-754 representation
+ * (denormalised values, infinities, underflow, etc). It is made
+ * quite nasty because emulation of some non-COP1 instructions is
+ * required, e.g. in branch delay slots.
+ *
+ * Note if you know that you won't have an fpu, then you'll get much
+ * better performance by compiling with -msoft-float!
+ */
+#include <linux/sched.h>
+#include <linux/debugfs.h>
+
+#include <asm/processor.h>
+#include <asm/ptrace.h>
+#include <asm/bitfield.h>
+#include <asm/uaccess.h>
+
+#include "ieee754.h"
+#include "insn.h"
+#include "fpu_emulator.h"
+
+/* Function which emulates a floating point instruction. */
+
+static int fpu_emu(struct pt_regs *, struct fpu_struct *, unsigned long);
+
+/* Further private data for which no space exists in fpu_struct */
+
+struct fpu_emulator_stats fpuemustats;
+
+/* rounding mode */
+#define FPU_FPCSR_RN 0x0 /* nearest */
+#define FPU_FPCSR_RU 0x1 /* towards +Infinity */
+#define FPU_FPCSR_RD 0x2 /* towards -Infinity */
+#define FPU_FPCSR_RZ 0x3 /* towards zero */
+
+/* Convert Mips rounding mode (0..3) to IEEE library modes. */
+static const unsigned char ieee_rm[4] = {
+ [FPU_FPCSR_RN] = IEEE754_RN,
+ [FPU_FPCSR_RU] = IEEE754_RU,
+ [FPU_FPCSR_RD] = IEEE754_RD,
+ [FPU_FPCSR_RZ] = IEEE754_RZ,
+};
+
+/* Convert IEEE library modes to NDS32 rounding mode (0..3). */
+static const unsigned char nds32_rm[4] = {
+ [IEEE754_RN] = FPU_FPCSR_RN,
+ [IEEE754_RZ] = FPU_FPCSR_RZ,
+ [IEEE754_RD] = FPU_FPCSR_RD,
+ [IEEE754_RU] = FPU_FPCSR_RU,
+};
+
+/*
+ * In the Linux kernel, we support selection of FPR format on the
+ * basis of the Status.FR bit. This does imply that, if a full 32
+ * FPRs are desired, there needs to be a flip-flop that can be written
+ * to one at that bit position. In any case, O32 MIPS ABI uses
+ * only the even FPRs (Status.FR = 0).
+ */
+
+#define CP0_STATUS_FR_SUPPORT
+
+#ifdef CP0_STATUS_FR_SUPPORT
+#define FR_BIT ST0_FR
+#else
+#define FR_BIT 0
+#endif
+
+#define SIFROMREG(si, x) ((si) = *((unsigned long *)ctx + x))
+#define SITOREG(si, x) (*((unsigned long *)ctx + x)= (si))
+
+#ifdef __NDS32_EL__
+#define DIFROMREG(di, x) ((di) = (unsigned long long)ptr[2*x] << 32 | (unsigned long long)ptr[2*x+1])
+#define DITOREG(di, x) ptr[2*x] = (di) >> 32; ptr[2*x+1] = (unsigned long)(di)
+#else
+#define DIFROMREG(di, x) ((di) = (unsigned long long)ptr[2*x+1] << 32 | (unsigned long long)ptr[2*x])
+#define DITOREG(di, x) ptr[2*x+1] = (di) >> 32; ptr[2*x] = (unsigned long)(di)
+#endif
+
+#define SPFROMREG(sp, x) SIFROMREG((sp).bits, x)
+#define SPTOREG(sp, x) SITOREG((sp).bits, x)
+#define DPFROMREG(dp, x) DIFROMREG((dp).bits, x)
+#define DPTOREG(dp, x) DITOREG((dp).bits, x)
+
+#define DEF3OP(name, p, f1, f2, f3) \
+static ieee754##p fpemu_##p##_##name(ieee754##p r, ieee754##p s, \
+ ieee754##p t) \
+{ \
+ struct _ieee754_csr ieee754_csr_save; \
+ s = f1(s, t); \
+ ieee754_csr_save = ieee754_csr; \
+ s = f2(s, r); \
+ ieee754_csr_save.cx |= ieee754_csr.cx; \
+ ieee754_csr_save.sx |= ieee754_csr.sx; \
+ s = f3(s); \
+ ieee754_csr.cx |= ieee754_csr_save.cx; \
+ ieee754_csr.sx |= ieee754_csr_save.sx; \
+ return s; \
+}
+
+DEF3OP(madd, sp, ieee754sp_mul, ieee754sp_add,);
+DEF3OP(msub, sp, ieee754sp_mul, ieee754sp_sub,);
+DEF3OP(nmadd, sp, ieee754sp_mul, ieee754sp_add, ieee754sp_neg);
+DEF3OP(nmsub, sp, ieee754sp_mul, ieee754sp_sub, ieee754sp_neg);
+DEF3OP(madd, dp, ieee754dp_mul, ieee754dp_add,);
+DEF3OP(msub, dp, ieee754dp_mul, ieee754dp_sub,);
+DEF3OP(nmadd, dp, ieee754dp_mul, ieee754dp_add, ieee754dp_neg);
+DEF3OP(nmsub, dp, ieee754dp_mul, ieee754dp_sub, ieee754dp_neg);
+
+/*
+ * Emulate the floating point instruction w/ denorm input pointed at by IPC.
+ * According to spec, only FPU arithmetic, data format conversion, and compare instructions.
+ */
+
+static int fpuEmulate(struct pt_regs *regs, struct fpu_struct *fpu)
+{
+ unsigned long insn = 0, addr = regs->NDS32_ipc;
+ unsigned long emulpc, contpc;
+ unsigned char *pc = (void *)&insn;
+ char c;
+ int i = 0;
+
+ for (i = 0; i < 4; i++) {
+ if (__get_user(c, (unsigned char *)addr++))
+ return SIGBUS;
+ *pc++ = c;
+ }
+
+ insn = be32_to_cpu(insn);
+
+ emulpc = regs->NDS32_ipc;
+ contpc = regs->NDS32_ipc + 4;
+
+ fpuemustats.emulated++;
+ switch (NDS32Insn_OPCODE(insn)) {
+ case cop0_op:
+ switch (NDS32Insn_OPCODE_COP0(insn)) {
+
+ case fs1_op:
+ case fs2_op:
+ case fd1_op:
+ case fd2_op:
+ {
+ int sig;
+
+ /* a real fpu computation instruction */
+ if ((sig = fpu_emu(regs, fpu, insn)))
+ return sig;
+ }
+ break;
+
+ default:
+ return SIGILL;
+ }
+ break;
+ default:
+ return SIGILL;
+ }
+
+ /* we did it !! */
+ regs->NDS32_ipc = contpc;
+
+ return 0;
+}
+
+/*
+ * Conversion table from NDS32 fcmp TYP
+ * cond = ieee754dp_cmp(x,y,IEEE754_UN,sig);
+ */
+static const unsigned char cmptab[8] = {
+ IEEE754_CEQ,
+ IEEE754_CLT,
+ IEEE754_CLT | IEEE754_CEQ,
+ IEEE754_CUN,
+ 0,
+ 0,
+ 0,
+ 0,
+};
+
+/*
+ * Emulate a single FPU arithmetic instruction.
+ */
+static int fpu_emu(struct pt_regs *xcp, struct fpu_struct *ctx,
+ unsigned long insn)
+{
+ int rfmt; /* resulting format */
+ unsigned rfpcsr = 0; /* resulting csr */
+ unsigned long *ptr = (unsigned long *)ctx;
+ union {
+ ieee754dp d;
+ ieee754sp s;
+ int w;
+ } rv; /* resulting value */
+
+ fpuemustats.fpuops++;
+ switch (rfmt = NDS32Insn_OPCODE_COP0(insn)) {
+ case fs1_op:{
+ union {
+ ieee754sp(*t) (ieee754sp, ieee754sp, ieee754sp);
+ ieee754sp(*b) (ieee754sp, ieee754sp);
+ ieee754sp(*u) (ieee754sp);
+ } handler;
+
+ switch (NDS32Insn_OPCODE_BIT69(insn)) {
+ case fadds_op:
+ handler.b = ieee754sp_add;
+ goto scopbop;
+ case fsubs_op:
+ handler.b = ieee754sp_sub;
+ goto scopbop;
+ case fmadds_op:
+ handler.t = fpemu_sp_madd;
+ goto scoptop;
+ case fmsubs_op:
+ handler.t = fpemu_sp_msub;
+ goto scoptop;
+ case fnmadds_op:
+ handler.t = fpemu_sp_nmadd;
+ goto scoptop;
+ case fnmsubs_op:
+ handler.t = fpemu_sp_nmsub;
+ goto scoptop;
+ case fmuls_op:
+ handler.b = ieee754sp_mul;
+ goto scopbop;
+ case fdivs_op:
+ handler.b = ieee754sp_div;
+ goto scopbop;
+
+ /* binary op on handler */
+scoptop:
+ {
+ ieee754sp fd, fr, fs, ft;
+
+ SPFROMREG(fr,
+ NDS32Insn_OPCODE_Rt(insn));
+ SPFROMREG(fs,
+ NDS32Insn_OPCODE_Ra(insn));
+ SPFROMREG(ft,
+ NDS32Insn_OPCODE_Rb(insn));
+ fd = (*handler.t) (fr, fs, ft);
+ SPTOREG(fd, NDS32Insn_OPCODE_Rt(insn));
+ }
+scopbop:
+ {
+ ieee754sp fs, ft;
+
+ SPFROMREG(fs,
+ NDS32Insn_OPCODE_Ra(insn));
+ SPFROMREG(ft,
+ NDS32Insn_OPCODE_Rb(insn));
+
+ rv.s = (*handler.b) (fs, ft);
+ goto copcsr;
+ }
+scopuop:
+ {
+ ieee754sp fs;
+
+ SPFROMREG(fs,
+ NDS32Insn_OPCODE_Ra(insn));
+ rv.s = (*handler.u) (fs);
+ goto copcsr;
+ }
+copcsr:
+ if (ieee754_cxtest(IEEE754_INEXACT))
+ rfpcsr |= FPCSR_mskIEX;
+ if (ieee754_cxtest(IEEE754_UNDERFLOW))
+ rfpcsr |= FPCSR_mskUDF;
+ if (ieee754_cxtest(IEEE754_OVERFLOW))
+ rfpcsr |= FPCSR_mskOVF;
+ if (ieee754_cxtest(IEEE754_ZERO_DIVIDE))
+ rfpcsr |= FPCSR_mskDBZ;
+ if (ieee754_cxtest(IEEE754_INVALID_OPERATION))
+ rfpcsr |= FPCSR_mskIVO;
+ break;
+
+ case fs1_f2op_op:
+ switch (NDS32Insn_OPCODE_BIT1014(insn)) {
+ case fs2d_op:{
+ ieee754sp fs;
+ SPFROMREG(fs,
+ NDS32Insn_OPCODE_Ra
+ (insn));
+ rv.d = ieee754dp_fsp(fs);
+ rfmt = fd1_op;
+ goto copcsr;
+ }
+ case fsqrts_op:
+ handler.u = ieee754sp_sqrt;
+ goto scopuop;
+ case fabss_op:
+ handler.u = ieee754sp_abs;
+ goto scopuop;
+ default:
+ return SIGILL;
+ }
+ default:
+ return SIGILL;
+ }
+ break;
+ }
+
+ case fs2_op:
+ switch (NDS32Insn_OPCODE_BIT69(insn)) {
+ case fcmpeqs_op:
+ case fcmpeqs_e_op:
+ case fcmplts_op:
+ case fcmplts_e_op:
+ case fcmples_op:
+ case fcmples_e_op:
+ case fcmpuns_op:
+ case fcmpuns_e_op:
+ {
+ unsigned int cmpop =
+ NDS32Insn_OPCODE_BIT69(insn);
+ if (cmpop < 0x8) {
+ ieee754sp fs, ft;
+
+ SPFROMREG(fs,
+ NDS32Insn_OPCODE_Ra(insn));
+ SPFROMREG(ft,
+ NDS32Insn_OPCODE_Rb(insn));
+ rv.w =
+ ieee754sp_cmp(fs, ft,
+ cmptab[(cmpop >> 1) &
+ 0x7],
+ cmpop & 0x1);
+ if ((cmpop & 0x1)
+ &&
+ ieee754_cxtest
+ (IEEE754_INVALID_OPERATION))
+ rfpcsr = FPCSR_mskIVO;
+ else
+ goto copcsr;
+ } else
+ return SIGILL;
+ }
+ break;
+
+ default:
+ return SIGILL;
+ }
+ break;
+
+ case fd1_op:
+ {
+ union {
+ ieee754dp(*t) (ieee754dp, ieee754dp, ieee754dp);
+ ieee754dp(*b) (ieee754dp, ieee754dp);
+ ieee754dp(*u) (ieee754dp);
+ } handler;
+
+ switch (NDS32Insn_OPCODE_BIT69(insn)) {
+ case faddd_op:
+ handler.b = ieee754dp_add;
+ goto dcopbop;
+ case fsubd_op:
+ handler.b = ieee754dp_sub;
+ goto dcopbop;
+ case fmaddd_op:
+ handler.t = fpemu_dp_madd;
+ goto tdcoptop;
+ case fmsubd_op:
+ handler.t = fpemu_dp_msub;
+ goto tdcoptop;
+ case fnmaddd_op:
+ handler.t = fpemu_dp_nmadd;
+ goto tdcoptop;
+ case fnmsubd_op:
+ handler.t = fpemu_dp_nmsub;
+ goto tdcoptop;
+
+tdcoptop:
+ {
+ ieee754dp fd, fr, fs, ft;
+
+ DPFROMREG(fr,
+ NDS32Insn_OPCODE_Rt(insn));
+ DPFROMREG(fs,
+ NDS32Insn_OPCODE_Ra(insn));
+ DPFROMREG(ft,
+ NDS32Insn_OPCODE_Rb(insn));
+ fd = (*handler.t) (fr, fs, ft);
+ DPTOREG(fd, NDS32Insn_OPCODE_Rt(insn));
+ goto copcsr;
+ }
+
+ case fmuld_op:
+ handler.b = ieee754dp_mul;
+ goto dcopbop;
+ case fdivd_op:
+ handler.b = ieee754dp_div;
+ goto dcopbop;
+
+ /* binary op on handler */
+dcopbop: {
+ ieee754dp fs, ft;
+
+ DPFROMREG(fs,
+ NDS32Insn_OPCODE_Ra(insn));
+ DPFROMREG(ft,
+ NDS32Insn_OPCODE_Rb(insn));
+
+ rv.d = (*handler.b) (fs, ft);
+ goto copcsr;
+ }
+dcopuop: {
+ ieee754dp fs;
+
+ DPFROMREG(fs,
+ NDS32Insn_OPCODE_Ra(insn));
+ rv.d = (*handler.u) (fs);
+ goto copcsr;
+ }
+
+ case fd1_f2op_op:
+ switch (NDS32Insn_OPCODE_BIT1014(insn)) {
+ case fd2s_op:{
+ ieee754dp fs;
+
+ DPFROMREG(fs,
+ NDS32Insn_OPCODE_Ra
+ (insn));
+ rv.s = ieee754sp_fdp(fs);
+ rfmt = fd1_op;
+ goto copcsr;
+ }
+ case fsqrtd_op:
+ handler.u = ieee754dp_sqrt;
+ goto dcopuop;
+ case fabsd_op:
+ handler.u = ieee754dp_abs;
+ goto dcopuop;
+ default:
+ return SIGILL;
+ }
+ default:
+ return SIGILL;
+ }
+ break;
+ }
+
+ case fd2_op:
+ switch (NDS32Insn_OPCODE_BIT69(insn)) {
+ case fcmpeqd_op:
+ case fcmpeqd_e_op:
+ case fcmpltd_op:
+ case fcmpltd_e_op:
+ case fcmpled_op:
+ case fcmpled_e_op:
+ case fcmpund_op:
+ case fcmpund_e_op:
+ {
+ unsigned cmpop = NDS32Insn_OPCODE_BIT69(insn);
+ if (cmpop < 0x8) {
+ ieee754dp fs, ft;
+
+ DPFROMREG(fs,
+ NDS32Insn_OPCODE_Ra(insn));
+ DPFROMREG(ft,
+ NDS32Insn_OPCODE_Rb(insn));
+ rv.w =
+ ieee754dp_cmp(fs, ft,
+ cmptab[(cmpop >> 1) &
+ 0x7],
+ cmpop & 0x1);
+ rfmt = fs2_op;
+ if ((cmpop & 0x1)
+ &&
+ ieee754_cxtest
+ (IEEE754_INVALID_OPERATION))
+ rfpcsr = FPCSR_mskIVO;
+ else
+ goto copcsr;
+ } else
+ return SIGILL;
+ }
+ break;
+ default:
+ return SIGILL;
+ }
+ break;
+
+ default:
+ return SIGILL;
+ }
+
+ /*
+ * Now we can safely write the result back to the register file.
+ */
+ switch (rfmt) {
+ case fd1_op:
+ case fd2_op:
+ DPTOREG(rv.d, NDS32Insn_OPCODE_Rt(insn));
+ break;
+ case fs1_op:
+ case fs2_op:
+ SPTOREG(rv.s, NDS32Insn_OPCODE_Rt(insn));
+ break;
+ default:
+ return SIGILL;
+ }
+
+ /*
+ * Update the fpu CSR register for this operation.
+ * If an exception is required, generate a tidy SIGFPE exception,
+ * without updating the result register.
+ * Note: cause exception bits do not accumulate, they are rewritten
+ * for each op; only the flag/sticky bits accumulate.
+ */
+ ctx->fpcsr = (ctx->fpcsr & ~FPCSR_mskALL) | rfpcsr;
+ if ((ctx->fpcsr << 5) & ctx->fpcsr & FPCSR_mskALLE) {
+ return SIGFPE;
+ }
+
+ return 0;
+}
+
+int do_fpu_denorm(struct pt_regs *regs, struct fpu_struct *fpu)
+{
+ int sig = 0;
+
+ /*
+ * The 'ieee754_csr' is an alias of
+ * fpcsr->RM. No need to copy fpcsr->RM to
+ * ieee754_csr. But ieee754_csr.rm is ieee
+ * library modes. (not NDS32 rounding mode)
+ */
+ /* convert to ieee library modes */
+ ieee754_csr.rm = ieee_rm[ieee754_csr.rm];
+ sig = fpuEmulate(regs, fpu);
+ /* revert to NDS32 rounding mode */
+ ieee754_csr.rm = nds32_rm[ieee754_csr.rm];
+
+ return sig;
+}
diff -Nur linux-3.4.113.orig/arch/nds32/math-emu/fpu_emulator.h linux-3.4.113/arch/nds32/math-emu/fpu_emulator.h
--- linux-3.4.113.orig/arch/nds32/math-emu/fpu_emulator.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/math-emu/fpu_emulator.h 2016-12-01 20:59:24.364613214 +0100
@@ -0,0 +1,36 @@
+/*
+ * This program is free software; you can distribute it and/or modify it
+ * under the terms of the GNU General Public License (Version 2) as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
+ *
+ * Further private data for which no space exists in mips_fpu_struct.
+ * This should be subsumed into the mips_fpu_struct structure as
+ * defined in processor.h as soon as the absurd wired absolute assembler
+ * offsets become dynamic at compile time.
+ *
+ * Kevin D. Kissell, kevink@mips.com and Carsten Langgaard, carstenl@mips.com
+ * Copyright (C) 2000 MIPS Technologies, Inc. All rights reserved.
+ */
+#ifndef _ASM_FPU_EMULATOR_H
+#define _ASM_FPU_EMULATOR_H
+
+struct fpu_emulator_stats {
+ unsigned int emulated;
+ unsigned int loads;
+ unsigned int stores;
+ unsigned int fpuops;
+ unsigned int errors;
+};
+
+extern struct fpu_emulator_stats fpuemustats;
+
+#endif /* _ASM_FPU_EMULATOR_H */
diff -Nur linux-3.4.113.orig/arch/nds32/math-emu/ieee754.c linux-3.4.113/arch/nds32/math-emu/ieee754.c
--- linux-3.4.113.orig/arch/nds32/math-emu/ieee754.c 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/math-emu/ieee754.c 2016-12-01 20:59:24.364613214 +0100
@@ -0,0 +1,125 @@
+/* ieee754 floating point arithmetic
+ * single and double precision
+ *
+ * BUGS
+ * not much dp done
+ * doesn't generate IEEE754_INEXACT
+ *
+ */
+/*
+ * MIPS floating point support
+ * Copyright (C) 1994-2000 Algorithmics Ltd.
+ * http://www.algor.co.uk
+ *
+ * ########################################################################
+ *
+ * This program is free software; you can distribute it and/or modify it
+ * under the terms of the GNU General Public License (Version 2) as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
+ *
+ * ########################################################################
+ */
+
+#include "ieee754int.h"
+#include "ieee754sp.h"
+#include "ieee754dp.h"
+
+#define DP_EBIAS 1023
+#define DP_EMIN (-1022)
+#define DP_EMAX 1023
+
+#define SP_EBIAS 127
+#define SP_EMIN (-126)
+#define SP_EMAX 127
+
+/* special constants
+*/
+
+#if (defined(BYTE_ORDER) && BYTE_ORDER == LITTLE_ENDIAN) || defined(__NDS32_EL__)
+#define SPSTR(s, b, m) {m, b, s}
+#define DPSTR(s, b, mh, ml) {ml, mh, b, s}
+#endif
+
+#ifdef __NDS32_EB__
+#define SPSTR(s, b, m) {s, b, m}
+#define DPSTR(s, b, mh, ml) {s, b, mh, ml}
+#endif
+
+const struct ieee754dp_konst __ieee754dp_spcvals[] = {
+ DPSTR(0, DP_EMIN - 1 + DP_EBIAS, 0, 0), /* + zero */
+ DPSTR(1, DP_EMIN - 1 + DP_EBIAS, 0, 0), /* - zero */
+ DPSTR(0, DP_EBIAS, 0, 0), /* + 1.0 */
+ DPSTR(1, DP_EBIAS, 0, 0), /* - 1.0 */
+ DPSTR(0, 3 + DP_EBIAS, 0x40000, 0), /* + 10.0 */
+ DPSTR(1, 3 + DP_EBIAS, 0x40000, 0), /* - 10.0 */
+ DPSTR(0, DP_EMAX + 1 + DP_EBIAS, 0, 0), /* + infinity */
+ DPSTR(1, DP_EMAX + 1 + DP_EBIAS, 0, 0), /* - infinity */
+ DPSTR(0, DP_EMAX + 1 + DP_EBIAS, 0x7FFFF, 0xFFFFFFFF), /* + indef quiet Nan */
+ DPSTR(0, DP_EMAX + DP_EBIAS, 0xFFFFF, 0xFFFFFFFF), /* + max */
+ DPSTR(1, DP_EMAX + DP_EBIAS, 0xFFFFF, 0xFFFFFFFF), /* - max */
+ DPSTR(0, DP_EMIN + DP_EBIAS, 0, 0), /* + min normal */
+ DPSTR(1, DP_EMIN + DP_EBIAS, 0, 0), /* - min normal */
+ DPSTR(0, DP_EMIN - 1 + DP_EBIAS, 0, 1), /* + min denormal */
+ DPSTR(1, DP_EMIN - 1 + DP_EBIAS, 0, 1), /* - min denormal */
+ DPSTR(0, 31 + DP_EBIAS, 0, 0), /* + 1.0e31 */
+ DPSTR(0, 63 + DP_EBIAS, 0, 0), /* + 1.0e63 */
+};
+
+const struct ieee754sp_konst __ieee754sp_spcvals[] = {
+ SPSTR(0, SP_EMIN - 1 + SP_EBIAS, 0), /* + zero */
+ SPSTR(1, SP_EMIN - 1 + SP_EBIAS, 0), /* - zero */
+ SPSTR(0, SP_EBIAS, 0), /* + 1.0 */
+ SPSTR(1, SP_EBIAS, 0), /* - 1.0 */
+ SPSTR(0, 3 + SP_EBIAS, 0x200000), /* + 10.0 */
+ SPSTR(1, 3 + SP_EBIAS, 0x200000), /* - 10.0 */
+ SPSTR(0, SP_EMAX + 1 + SP_EBIAS, 0), /* + infinity */
+ SPSTR(1, SP_EMAX + 1 + SP_EBIAS, 0), /* - infinity */
+ SPSTR(0, SP_EMAX + 1 + SP_EBIAS, 0x3FFFFF), /* + indef quiet Nan */
+ SPSTR(0, SP_EMAX + SP_EBIAS, 0x7FFFFF), /* + max normal */
+ SPSTR(1, SP_EMAX + SP_EBIAS, 0x7FFFFF), /* - max normal */
+ SPSTR(0, SP_EMIN + SP_EBIAS, 0), /* + min normal */
+ SPSTR(1, SP_EMIN + SP_EBIAS, 0), /* - min normal */
+ SPSTR(0, SP_EMIN - 1 + SP_EBIAS, 1), /* + min denormal */
+ SPSTR(1, SP_EMIN - 1 + SP_EBIAS, 1), /* - min denormal */
+ SPSTR(0, 31 + SP_EBIAS, 0), /* + 1.0e31 */
+ SPSTR(0, 63 + SP_EBIAS, 0), /* + 1.0e63 */
+};
+
+int ieee754si_xcpt(int r, const char *op, ...)
+{
+ struct ieee754xctx ax;
+
+ if (!TSTX())
+ return r;
+ ax.op = op;
+ ax.rt = IEEE754_RT_SI;
+ ax.rv.si = r;
+ va_start(ax.ap, op);
+ ieee754_xcpt(&ax);
+ va_end(ax.ap);
+ return ax.rv.si;
+}
+
+s64 ieee754di_xcpt(s64 r, const char *op, ...)
+{
+ struct ieee754xctx ax;
+
+ if (!TSTX())
+ return r;
+ ax.op = op;
+ ax.rt = IEEE754_RT_DI;
+ ax.rv.di = r;
+ va_start(ax.ap, op);
+ ieee754_xcpt(&ax);
+ va_end(ax.ap);
+ return ax.rv.di;
+}
diff -Nur linux-3.4.113.orig/arch/nds32/math-emu/ieee754d.c linux-3.4.113/arch/nds32/math-emu/ieee754d.c
--- linux-3.4.113.orig/arch/nds32/math-emu/ieee754d.c 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/math-emu/ieee754d.c 2016-12-01 20:59:24.364613214 +0100
@@ -0,0 +1,134 @@
+/*
+ * Some debug functions
+ *
+ * MIPS floating point support
+ *
+ * Copyright (C) 1994-2000 Algorithmics Ltd.
+ * http://www.algor.co.uk
+ *
+ * This program is free software; you can distribute it and/or modify it
+ * under the terms of the GNU General Public License (Version 2) as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
+ *
+ * Nov 7, 2000
+ * Modified to build and operate in Linux kernel environment.
+ *
+ * Kevin D. Kissell, kevink@mips.com and Carsten Langgaard, carstenl@mips.com
+ * Copyright (C) 2000 MIPS Technologies, Inc. All rights reserved.
+ */
+
+#include <linux/kernel.h>
+#include "ieee754.h"
+
+#define DP_EBIAS 1023
+#define DP_EMIN (-1022)
+#define DP_EMAX 1023
+#define DP_FBITS 52
+
+#define SP_EBIAS 127
+#define SP_EMIN (-126)
+#define SP_EMAX 127
+#define SP_FBITS 23
+
+#define DP_MBIT(x) ((u64)1 << (x))
+#define DP_HIDDEN_BIT DP_MBIT(DP_FBITS)
+#define DP_SIGN_BIT DP_MBIT(63)
+
+#define SP_MBIT(x) ((u32)1 << (x))
+#define SP_HIDDEN_BIT SP_MBIT(SP_FBITS)
+#define SP_SIGN_BIT SP_MBIT(31)
+
+#define SPSIGN(sp) (sp.parts.sign)
+#define SPBEXP(sp) (sp.parts.bexp)
+#define SPMANT(sp) (sp.parts.mant)
+
+#define DPSIGN(dp) (dp.parts.sign)
+#define DPBEXP(dp) (dp.parts.bexp)
+#define DPMANT(dp) (dp.parts.mant)
+
+ieee754dp ieee754dp_dump(char *m, ieee754dp x)
+{
+ int i;
+
+ printk("%s", m);
+ printk("<%08x,%08x>\n", (unsigned)(x.bits >> 32), (unsigned)x.bits);
+ printk("\t=");
+ switch (ieee754dp_class(x)) {
+ case IEEE754_CLASS_QNAN:
+ case IEEE754_CLASS_SNAN:
+ printk("Nan %c", DPSIGN(x) ? '-' : '+');
+ for (i = DP_FBITS - 1; i >= 0; i--)
+ printk("%c", DPMANT(x) & DP_MBIT(i) ? '1' : '0');
+ break;
+ case IEEE754_CLASS_INF:
+ printk("%cInfinity", DPSIGN(x) ? '-' : '+');
+ break;
+ case IEEE754_CLASS_ZERO:
+ printk("%cZero", DPSIGN(x) ? '-' : '+');
+ break;
+ case IEEE754_CLASS_DNORM:
+ printk("%c0.", DPSIGN(x) ? '-' : '+');
+ for (i = DP_FBITS - 1; i >= 0; i--)
+ printk("%c", DPMANT(x) & DP_MBIT(i) ? '1' : '0');
+ printk("e%d", DPBEXP(x) - DP_EBIAS);
+ break;
+ case IEEE754_CLASS_NORM:
+ printk("%c1.", DPSIGN(x) ? '-' : '+');
+ for (i = DP_FBITS - 1; i >= 0; i--)
+ printk("%c", DPMANT(x) & DP_MBIT(i) ? '1' : '0');
+ printk("e%d", DPBEXP(x) - DP_EBIAS);
+ break;
+ default:
+ printk("Illegal/Unknown IEEE754 value class");
+ }
+ printk("\n");
+ return x;
+}
+
+ieee754sp ieee754sp_dump(char *m, ieee754sp x)
+{
+ int i;
+
+ printk("%s=", m);
+ printk("<%08x>\n", (unsigned)x.bits);
+ printk("\t=");
+ switch (ieee754sp_class(x)) {
+ case IEEE754_CLASS_QNAN:
+ case IEEE754_CLASS_SNAN:
+ printk("Nan %c", SPSIGN(x) ? '-' : '+');
+ for (i = SP_FBITS - 1; i >= 0; i--)
+ printk("%c", SPMANT(x) & SP_MBIT(i) ? '1' : '0');
+ break;
+ case IEEE754_CLASS_INF:
+ printk("%cInfinity", SPSIGN(x) ? '-' : '+');
+ break;
+ case IEEE754_CLASS_ZERO:
+ printk("%cZero", SPSIGN(x) ? '-' : '+');
+ break;
+ case IEEE754_CLASS_DNORM:
+ printk("%c0.", SPSIGN(x) ? '-' : '+');
+ for (i = SP_FBITS - 1; i >= 0; i--)
+ printk("%c", SPMANT(x) & SP_MBIT(i) ? '1' : '0');
+ printk("e%d", SPBEXP(x) - SP_EBIAS);
+ break;
+ case IEEE754_CLASS_NORM:
+ printk("%c1.", SPSIGN(x) ? '-' : '+');
+ for (i = SP_FBITS - 1; i >= 0; i--)
+ printk("%c", SPMANT(x) & SP_MBIT(i) ? '1' : '0');
+ printk("e%d", SPBEXP(x) - SP_EBIAS);
+ break;
+ default:
+ printk("Illegal/Unknown IEEE754 value class");
+ }
+ printk("\n");
+ return x;
+}
diff -Nur linux-3.4.113.orig/arch/nds32/math-emu/ieee754dp.c linux-3.4.113/arch/nds32/math-emu/ieee754dp.c
--- linux-3.4.113.orig/arch/nds32/math-emu/ieee754dp.c 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/math-emu/ieee754dp.c 2016-12-01 20:59:24.364613214 +0100
@@ -0,0 +1,239 @@
+/* IEEE754 floating point arithmetic
+ * double precision: common utilities
+ */
+/*
+ * MIPS floating point support
+ * Copyright (C) 1994-2000 Algorithmics Ltd.
+ * http://www.algor.co.uk
+ *
+ * ########################################################################
+ *
+ * This program is free software; you can distribute it and/or modify it
+ * under the terms of the GNU General Public License (Version 2) as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
+ *
+ * ########################################################################
+ */
+
+#include "ieee754dp.h"
+
+int ieee754dp_class(ieee754dp x)
+{
+ COMPXDP;
+ EXPLODEXDP;
+ return xc;
+}
+
+int ieee754dp_isnan(ieee754dp x)
+{
+ return ieee754dp_class(x) >= IEEE754_CLASS_SNAN;
+}
+
+int ieee754dp_issnan(ieee754dp x)
+{
+ assert(ieee754dp_isnan(x));
+ return ((DPMANT(x) & DP_MBIT(DP_MBITS - 1)) == DP_MBIT(DP_MBITS - 1));
+}
+
+ieee754dp ieee754dp_xcpt(ieee754dp r, const char *op, ...)
+{
+ struct ieee754xctx ax;
+ if (!TSTX())
+ return r;
+
+ ax.op = op;
+ ax.rt = IEEE754_RT_DP;
+ ax.rv.dp = r;
+ va_start(ax.ap, op);
+ ieee754_xcpt(&ax);
+ va_end(ax.ap);
+ return ax.rv.dp;
+}
+
+ieee754dp ieee754dp_nanxcpt(ieee754dp r, const char *op, ...)
+{
+ struct ieee754xctx ax;
+
+ assert(ieee754dp_isnan(r));
+
+ if (!ieee754dp_issnan(r)) /* QNAN does not cause invalid op !! */
+ return r;
+
+ if (!SETANDTESTCX(IEEE754_INVALID_OPERATION)) {
+ /* not enabled convert to a quiet NaN */
+ DPMANT(r) &= (~DP_MBIT(DP_MBITS - 1));
+ if (ieee754dp_isnan(r))
+ return r;
+ else
+ return ieee754dp_indef();
+ }
+
+ ax.op = op;
+ ax.rt = 0;
+ ax.rv.dp = r;
+ va_start(ax.ap, op);
+ ieee754_xcpt(&ax);
+ va_end(ax.ap);
+ return ax.rv.dp;
+}
+
+ieee754dp ieee754dp_bestnan(ieee754dp x, ieee754dp y)
+{
+ assert(ieee754dp_isnan(x));
+ assert(ieee754dp_isnan(y));
+
+ if (DPMANT(x) > DPMANT(y))
+ return x;
+ else
+ return y;
+}
+
+static u64 get_rounding(int sn, u64 xm)
+{
+ /* inexact must round of 3 bits
+ */
+ if (xm & (DP_MBIT(3) - 1)) {
+ switch (ieee754_csr.rm) {
+ case IEEE754_RZ:
+ break;
+ case IEEE754_RN:
+ xm += 0x3 + ((xm >> 3) & 1);
+ /* xm += (xm&0x8)?0x4:0x3 */
+ break;
+ case IEEE754_RU: /* toward +Infinity */
+ if (!sn) /* ?? */
+ xm += 0x8;
+ break;
+ case IEEE754_RD: /* toward -Infinity */
+ if (sn) /* ?? */
+ xm += 0x8;
+ break;
+ }
+ }
+ return xm;
+}
+
+/* generate a normal/denormal number with over,under handling
+ * sn is sign
+ * xe is an unbiased exponent
+ * xm is 3bit extended precision value.
+ */
+ieee754dp ieee754dp_format(int sn, int xe, u64 xm)
+{
+ assert(xm); /* we don't gen exact zeros (probably should) */
+
+ assert((xm >> (DP_MBITS + 1 + 3)) == 0); /* no execess */
+ assert(xm & (DP_HIDDEN_BIT << 3));
+
+ if (xe < DP_EMIN) {
+ /* strip lower bits */
+ int es = DP_EMIN - xe;
+
+ if (ieee754_csr.nod) {
+ SETCX(IEEE754_UNDERFLOW);
+ SETCX(IEEE754_INEXACT);
+
+ switch (ieee754_csr.rm) {
+ case IEEE754_RN:
+ return ieee754dp_zero(sn);
+ case IEEE754_RZ:
+ return ieee754dp_zero(sn);
+ case IEEE754_RU: /* toward +Infinity */
+ if (sn == 0)
+ return ieee754dp_min(0);
+ else
+ return ieee754dp_zero(1);
+ case IEEE754_RD: /* toward -Infinity */
+ if (sn == 0)
+ return ieee754dp_zero(0);
+ else
+ return ieee754dp_min(1);
+ }
+ }
+
+ if (xe == DP_EMIN - 1
+ && get_rounding(sn, xm) >> (DP_MBITS + 1 + 3)) {
+ /* Not tiny after rounding */
+ SETCX(IEEE754_INEXACT);
+ xm = get_rounding(sn, xm);
+ xm >>= 1;
+ /* Clear grs bits */
+ xm &= ~(DP_MBIT(3) - 1);
+ xe++;
+ } else {
+ /* sticky right shift es bits
+ */
+ xm = XDPSRS(xm, es);
+ xe += es;
+ assert((xm & (DP_HIDDEN_BIT << 3)) == 0);
+ assert(xe == DP_EMIN);
+ }
+ }
+ if (xm & (DP_MBIT(3) - 1)) {
+ SETCX(IEEE754_INEXACT);
+ if ((xm & (DP_HIDDEN_BIT << 3)) == 0) {
+ SETCX(IEEE754_UNDERFLOW);
+ }
+
+ /* inexact must round of 3 bits
+ */
+ xm = get_rounding(sn, xm);
+ /* adjust exponent for rounding add overflowing
+ */
+ if (xm >> (DP_MBITS + 3 + 1)) {
+ /* add causes mantissa overflow */
+ xm >>= 1;
+ xe++;
+ }
+ }
+ /* strip grs bits */
+ xm >>= 3;
+
+ assert((xm >> (DP_MBITS + 1)) == 0); /* no execess */
+ assert(xe >= DP_EMIN);
+
+ if (xe > DP_EMAX) {
+ SETCX(IEEE754_OVERFLOW);
+ SETCX(IEEE754_INEXACT);
+ /* -O can be table indexed by (rm,sn) */
+ switch (ieee754_csr.rm) {
+ case IEEE754_RN:
+ return ieee754dp_inf(sn);
+ case IEEE754_RZ:
+ return ieee754dp_max(sn);
+ case IEEE754_RU: /* toward +Infinity */
+ if (sn == 0)
+ return ieee754dp_inf(0);
+ else
+ return ieee754dp_max(1);
+ case IEEE754_RD: /* toward -Infinity */
+ if (sn == 0)
+ return ieee754dp_max(0);
+ else
+ return ieee754dp_inf(1);
+ }
+ }
+ /* gen norm/denorm/zero */
+
+ if ((xm & DP_HIDDEN_BIT) == 0) {
+ /* we underflow (tiny/zero) */
+ assert(xe == DP_EMIN);
+ if (ieee754_csr.mx & IEEE754_UNDERFLOW)
+ SETCX(IEEE754_UNDERFLOW);
+ return builddp(sn, DP_EMIN - 1 + DP_EBIAS, xm);
+ } else {
+ assert((xm >> (DP_MBITS + 1)) == 0); /* no execess */
+ assert(xm & DP_HIDDEN_BIT);
+
+ return builddp(sn, xe + DP_EBIAS, xm & ~DP_HIDDEN_BIT);
+ }
+}
diff -Nur linux-3.4.113.orig/arch/nds32/math-emu/ieee754dp.h linux-3.4.113/arch/nds32/math-emu/ieee754dp.h
--- linux-3.4.113.orig/arch/nds32/math-emu/ieee754dp.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/math-emu/ieee754dp.h 2016-12-01 20:59:24.364613214 +0100
@@ -0,0 +1,83 @@
+/*
+ * IEEE754 floating point
+ * double precision internal header file
+ */
+/*
+ * MIPS floating point support
+ * Copyright (C) 1994-2000 Algorithmics Ltd.
+ * http://www.algor.co.uk
+ *
+ * ########################################################################
+ *
+ * This program is free software; you can distribute it and/or modify it
+ * under the terms of the GNU General Public License (Version 2) as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
+ *
+ * ########################################################################
+ */
+
+
+#include "ieee754int.h"
+
+#define assert(expr) ((void)0)
+
+/* 3bit extended double precision sticky right shift */
+#define XDPSRS(v,rs) \
+ ((rs > (DP_MBITS+3))?1:((v) >> (rs)) | ((v) << (64-(rs)) != 0))
+
+#define XDPSRSX1() \
+ (xe++, (xm = (xm >> 1) | (xm & 1)))
+
+#define XDPSRS1(v) \
+ (((v) >> 1) | ((v) & 1))
+
+/* convert denormal to normalized with extended exponent */
+#define DPDNORMx(m,e) \
+ while( (m >> DP_MBITS) == 0) { m <<= 1; e--; }
+#define DPDNORMX DPDNORMx(xm, xe)
+#define DPDNORMY DPDNORMx(ym, ye)
+
+static inline ieee754dp builddp(int s, int bx, u64 m)
+{
+ ieee754dp r;
+
+ assert((s) == 0 || (s) == 1);
+ assert((bx) >= DP_EMIN - 1 + DP_EBIAS
+ && (bx) <= DP_EMAX + 1 + DP_EBIAS);
+ assert(((m) >> DP_MBITS) == 0);
+
+ r.parts.sign = s;
+ r.parts.bexp = bx;
+ r.parts.mant = m;
+ return r;
+}
+
+extern int ieee754dp_isnan(ieee754dp);
+extern int ieee754dp_issnan(ieee754dp);
+extern int ieee754si_xcpt(int, const char *, ...);
+extern s64 ieee754di_xcpt(s64, const char *, ...);
+extern ieee754dp ieee754dp_xcpt(ieee754dp, const char *, ...);
+extern ieee754dp ieee754dp_nanxcpt(ieee754dp, const char *, ...);
+extern ieee754dp ieee754dp_bestnan(ieee754dp, ieee754dp);
+extern ieee754dp ieee754dp_format(int, int, u64);
+
+
+#define DPNORMRET2(s, e, m, name, a0, a1) \
+{ \
+ ieee754dp V = ieee754dp_format(s, e, m); \
+ if(TSTX()) \
+ return ieee754dp_xcpt(V, name, a0, a1); \
+ else \
+ return V; \
+}
+
+#define DPNORMRET1(s, e, m, name, a0) DPNORMRET2(s, e, m, name, a0, a0)
diff -Nur linux-3.4.113.orig/arch/nds32/math-emu/ieee754.h linux-3.4.113/arch/nds32/math-emu/ieee754.h
--- linux-3.4.113.orig/arch/nds32/math-emu/ieee754.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/math-emu/ieee754.h 2016-12-01 20:59:24.364613214 +0100
@@ -0,0 +1,467 @@
+/*
+ * MIPS floating point support
+ * Copyright (C) 1994-2000 Algorithmics Ltd.
+ * http://www.algor.co.uk
+ *
+ * This program is free software; you can distribute it and/or modify it
+ * under the terms of the GNU General Public License (Version 2) as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
+ *
+ * Nov 7, 2000
+ * Modification to allow integration with Linux kernel
+ *
+ * Kevin D. Kissell, kevink@mips.com and Carsten Langgard, carstenl@mips.com
+ * Copyright (C) 2000 MIPS Technologies, Inc. All rights reserved.
+ */
+#ifndef __ARCH_MIPS_MATH_EMU_IEEE754_H
+#define __ARCH_MIPS_MATH_EMU_IEEE754_H
+
+#include <asm/byteorder.h>
+#include <linux/types.h>
+#include <linux/sched.h>
+
+/*
+ * Not very pretty, but the Linux kernel's normal va_list definition
+ * does not allow it to be used as a structure element, as it is here.
+ */
+#ifndef _STDARG_H
+#include <stdarg.h>
+#endif
+
+#ifdef __LITTLE_ENDIAN
+struct ieee754dp_konst {
+ unsigned mantlo:32;
+ unsigned manthi:20;
+ unsigned bexp:11;
+ unsigned sign:1;
+};
+struct ieee754sp_konst {
+ unsigned mant:23;
+ unsigned bexp:8;
+ unsigned sign:1;
+};
+
+typedef union _ieee754dp {
+ struct ieee754dp_konst oparts;
+ struct {
+ u64 mant:52;
+ unsigned int bexp:11;
+ unsigned int sign:1;
+ } parts;
+ u64 bits;
+ double d;
+} ieee754dp;
+
+typedef union _ieee754sp {
+ struct ieee754sp_konst parts;
+ float f;
+ u32 bits;
+} ieee754sp;
+#endif
+
+#ifdef __BIG_ENDIAN
+struct ieee754dp_konst {
+ unsigned sign:1;
+ unsigned bexp:11;
+ unsigned manthi:20;
+ unsigned mantlo:32;
+};
+
+typedef union _ieee754dp {
+ struct ieee754dp_konst oparts;
+ struct {
+ unsigned int sign:1;
+ unsigned int bexp:11;
+ u64 mant:52;
+ } parts;
+ double d;
+ u64 bits;
+} ieee754dp;
+
+struct ieee754sp_konst {
+ unsigned sign:1;
+ unsigned bexp:8;
+ unsigned mant:23;
+};
+
+typedef union _ieee754sp {
+ struct ieee754sp_konst parts;
+ float f;
+ u32 bits;
+} ieee754sp;
+#endif
+
+/*
+ * single precision (often aka float)
+*/
+int ieee754sp_finite(ieee754sp x);
+int ieee754sp_class(ieee754sp x);
+
+ieee754sp ieee754sp_abs(ieee754sp x);
+ieee754sp ieee754sp_neg(ieee754sp x);
+ieee754sp ieee754sp_scalb(ieee754sp x, int);
+ieee754sp ieee754sp_logb(ieee754sp x);
+
+/* x with sign of y */
+ieee754sp ieee754sp_copysign(ieee754sp x, ieee754sp y);
+
+ieee754sp ieee754sp_add(ieee754sp x, ieee754sp y);
+ieee754sp ieee754sp_sub(ieee754sp x, ieee754sp y);
+ieee754sp ieee754sp_mul(ieee754sp x, ieee754sp y);
+ieee754sp ieee754sp_div(ieee754sp x, ieee754sp y);
+
+ieee754sp ieee754sp_fint(int x);
+ieee754sp ieee754sp_funs(unsigned x);
+ieee754sp ieee754sp_flong(s64 x);
+ieee754sp ieee754sp_fulong(u64 x);
+ieee754sp ieee754sp_fdp(ieee754dp x);
+
+int ieee754sp_tint(ieee754sp x);
+unsigned int ieee754sp_tuns(ieee754sp x);
+s64 ieee754sp_tlong(ieee754sp x);
+u64 ieee754sp_tulong(ieee754sp x);
+
+int ieee754sp_cmp(ieee754sp x, ieee754sp y, int cop, int sig);
+/*
+ * basic sp math
+ */
+ieee754sp ieee754sp_modf(ieee754sp x, ieee754sp * ip);
+ieee754sp ieee754sp_frexp(ieee754sp x, int *exp);
+ieee754sp ieee754sp_ldexp(ieee754sp x, int exp);
+
+ieee754sp ieee754sp_ceil(ieee754sp x);
+ieee754sp ieee754sp_floor(ieee754sp x);
+ieee754sp ieee754sp_trunc(ieee754sp x);
+
+ieee754sp ieee754sp_sqrt(ieee754sp x);
+
+/*
+ * double precision (often aka double)
+*/
+int ieee754dp_finite(ieee754dp x);
+int ieee754dp_class(ieee754dp x);
+
+/* x with sign of y */
+ieee754dp ieee754dp_copysign(ieee754dp x, ieee754dp y);
+
+ieee754dp ieee754dp_add(ieee754dp x, ieee754dp y);
+ieee754dp ieee754dp_sub(ieee754dp x, ieee754dp y);
+ieee754dp ieee754dp_mul(ieee754dp x, ieee754dp y);
+ieee754dp ieee754dp_div(ieee754dp x, ieee754dp y);
+
+ieee754dp ieee754dp_abs(ieee754dp x);
+ieee754dp ieee754dp_neg(ieee754dp x);
+ieee754dp ieee754dp_scalb(ieee754dp x, int);
+
+/* return exponent as integer in floating point format
+ */
+ieee754dp ieee754dp_logb(ieee754dp x);
+
+ieee754dp ieee754dp_fint(int x);
+ieee754dp ieee754dp_funs(unsigned x);
+ieee754dp ieee754dp_flong(s64 x);
+ieee754dp ieee754dp_fulong(u64 x);
+ieee754dp ieee754dp_fsp(ieee754sp x);
+
+ieee754dp ieee754dp_ceil(ieee754dp x);
+ieee754dp ieee754dp_floor(ieee754dp x);
+ieee754dp ieee754dp_trunc(ieee754dp x);
+
+int ieee754dp_tint(ieee754dp x);
+unsigned int ieee754dp_tuns(ieee754dp x);
+s64 ieee754dp_tlong(ieee754dp x);
+u64 ieee754dp_tulong(ieee754dp x);
+
+int ieee754dp_cmp(ieee754dp x, ieee754dp y, int cop, int sig);
+/*
+ * basic sp math
+ */
+ieee754dp ieee754dp_modf(ieee754dp x, ieee754dp * ip);
+ieee754dp ieee754dp_frexp(ieee754dp x, int *exp);
+ieee754dp ieee754dp_ldexp(ieee754dp x, int exp);
+
+ieee754dp ieee754dp_ceil(ieee754dp x);
+ieee754dp ieee754dp_floor(ieee754dp x);
+ieee754dp ieee754dp_trunc(ieee754dp x);
+
+ieee754dp ieee754dp_sqrt(ieee754dp x);
+
+
+
+/* 5 types of floating point number
+*/
+#define IEEE754_CLASS_NORM 0x00
+#define IEEE754_CLASS_ZERO 0x01
+#define IEEE754_CLASS_DNORM 0x02
+#define IEEE754_CLASS_INF 0x03
+#define IEEE754_CLASS_SNAN 0x04
+#define IEEE754_CLASS_QNAN 0x05
+
+/* exception numbers */
+#define IEEE754_INVALID_OPERATION 0x01
+#define IEEE754_ZERO_DIVIDE 0x02
+#define IEEE754_OVERFLOW 0x04
+#define IEEE754_UNDERFLOW 0x08
+#define IEEE754_INEXACT 0x10
+
+/* cmp operators
+*/
+#define IEEE754_CLT 0x01
+#define IEEE754_CEQ 0x02
+#define IEEE754_CGT 0x04
+#define IEEE754_CUN 0x08
+
+/* rounding mode
+*/
+#define IEEE754_RN 0 /* round to nearest */
+#define IEEE754_RZ 1 /* round toward zero */
+#define IEEE754_RD 2 /* round toward -Infinity */
+#define IEEE754_RU 3 /* round toward +Infinity */
+
+/* other naming */
+#define IEEE754_RM IEEE754_RD
+#define IEEE754_RP IEEE754_RU
+
+/* "normal" comparisons
+*/
+static inline int ieee754sp_eq(ieee754sp x, ieee754sp y)
+{
+ return ieee754sp_cmp(x, y, IEEE754_CEQ, 0);
+}
+
+static inline int ieee754sp_ne(ieee754sp x, ieee754sp y)
+{
+ return ieee754sp_cmp(x, y,
+ IEEE754_CLT | IEEE754_CGT | IEEE754_CUN, 0);
+}
+
+static inline int ieee754sp_lt(ieee754sp x, ieee754sp y)
+{
+ return ieee754sp_cmp(x, y, IEEE754_CLT, 0);
+}
+
+static inline int ieee754sp_le(ieee754sp x, ieee754sp y)
+{
+ return ieee754sp_cmp(x, y, IEEE754_CLT | IEEE754_CEQ, 0);
+}
+
+static inline int ieee754sp_gt(ieee754sp x, ieee754sp y)
+{
+ return ieee754sp_cmp(x, y, IEEE754_CGT, 0);
+}
+
+
+static inline int ieee754sp_ge(ieee754sp x, ieee754sp y)
+{
+ return ieee754sp_cmp(x, y, IEEE754_CGT | IEEE754_CEQ, 0);
+}
+
+static inline int ieee754dp_eq(ieee754dp x, ieee754dp y)
+{
+ return ieee754dp_cmp(x, y, IEEE754_CEQ, 0);
+}
+
+static inline int ieee754dp_ne(ieee754dp x, ieee754dp y)
+{
+ return ieee754dp_cmp(x, y,
+ IEEE754_CLT | IEEE754_CGT | IEEE754_CUN, 0);
+}
+
+static inline int ieee754dp_lt(ieee754dp x, ieee754dp y)
+{
+ return ieee754dp_cmp(x, y, IEEE754_CLT, 0);
+}
+
+static inline int ieee754dp_le(ieee754dp x, ieee754dp y)
+{
+ return ieee754dp_cmp(x, y, IEEE754_CLT | IEEE754_CEQ, 0);
+}
+
+static inline int ieee754dp_gt(ieee754dp x, ieee754dp y)
+{
+ return ieee754dp_cmp(x, y, IEEE754_CGT, 0);
+}
+
+static inline int ieee754dp_ge(ieee754dp x, ieee754dp y)
+{
+ return ieee754dp_cmp(x, y, IEEE754_CGT | IEEE754_CEQ, 0);
+}
+
+
+/*
+ * Like strtod
+ */
+ieee754dp ieee754dp_fstr(const char *s, char **endp);
+char *ieee754dp_tstr(ieee754dp x, int prec, int fmt, int af);
+
+
+/*
+ * The control status register
+ */
+struct _ieee754_csr {
+#ifdef __BIG_ENDIAN
+ unsigned pad0:12;
+ unsigned cx:7; /* exceptions this operation */
+ unsigned nod:1; /* set 1 for no denormalised numbers */
+ unsigned mx:5; /* exception enable mask */
+ unsigned sx:5; /* exceptions total */
+ unsigned rm:2; /* current rounding mode */
+#endif
+#ifdef __LITTLE_ENDIAN
+ unsigned rm:2; /* current rounding mode */
+ unsigned sx:5; /* exceptions total */
+ unsigned mx:5; /* exception enable mask */
+ unsigned nod:1; /* set 1 for no denormalised numbers */
+ unsigned cx:7; /* exceptions this operation */
+ unsigned pad0:12;
+#endif
+};
+#define ieee754_csr (*(struct _ieee754_csr *)(¤t->thread.fpu.fpcsr))
+
+static inline unsigned ieee754_getrm(void)
+{
+ return (ieee754_csr.rm);
+}
+static inline unsigned ieee754_setrm(unsigned rm)
+{
+ return (ieee754_csr.rm = rm);
+}
+
+/*
+ * get current exceptions
+ */
+static inline unsigned ieee754_getcx(void)
+{
+ return (ieee754_csr.cx);
+}
+
+/* test for current exception condition
+ */
+static inline int ieee754_cxtest(unsigned n)
+{
+ return (ieee754_csr.cx & n);
+}
+
+/*
+ * get sticky exceptions
+ */
+static inline unsigned ieee754_getsx(void)
+{
+ return (ieee754_csr.sx);
+}
+
+/* clear sticky conditions
+*/
+static inline unsigned ieee754_clrsx(void)
+{
+ return (ieee754_csr.sx = 0);
+}
+
+/* test for sticky exception condition
+ */
+static inline int ieee754_sxtest(unsigned n)
+{
+ return (ieee754_csr.sx & n);
+}
+
+/* debugging */
+ieee754sp ieee754sp_dump(char *s, ieee754sp x);
+ieee754dp ieee754dp_dump(char *s, ieee754dp x);
+
+#define IEEE754_SPCVAL_PZERO 0
+#define IEEE754_SPCVAL_NZERO 1
+#define IEEE754_SPCVAL_PONE 2
+#define IEEE754_SPCVAL_NONE 3
+#define IEEE754_SPCVAL_PTEN 4
+#define IEEE754_SPCVAL_NTEN 5
+#define IEEE754_SPCVAL_PINFINITY 6
+#define IEEE754_SPCVAL_NINFINITY 7
+#define IEEE754_SPCVAL_INDEF 8
+#define IEEE754_SPCVAL_PMAX 9 /* +max norm */
+#define IEEE754_SPCVAL_NMAX 10 /* -max norm */
+#define IEEE754_SPCVAL_PMIN 11 /* +min norm */
+#define IEEE754_SPCVAL_NMIN 12 /* +min norm */
+#define IEEE754_SPCVAL_PMIND 13 /* +min denorm */
+#define IEEE754_SPCVAL_NMIND 14 /* +min denorm */
+#define IEEE754_SPCVAL_P1E31 15 /* + 1.0e31 */
+#define IEEE754_SPCVAL_P1E63 16 /* + 1.0e63 */
+
+extern const struct ieee754dp_konst __ieee754dp_spcvals[];
+extern const struct ieee754sp_konst __ieee754sp_spcvals[];
+#define ieee754dp_spcvals ((const ieee754dp *)__ieee754dp_spcvals)
+#define ieee754sp_spcvals ((const ieee754sp *)__ieee754sp_spcvals)
+
+/*
+ * Return infinity with given sign
+ */
+#define ieee754dp_inf(sn) (ieee754dp_spcvals[IEEE754_SPCVAL_PINFINITY+(sn)])
+#define ieee754dp_zero(sn) (ieee754dp_spcvals[IEEE754_SPCVAL_PZERO+(sn)])
+#define ieee754dp_one(sn) (ieee754dp_spcvals[IEEE754_SPCVAL_PONE+(sn)])
+#define ieee754dp_ten(sn) (ieee754dp_spcvals[IEEE754_SPCVAL_PTEN+(sn)])
+#define ieee754dp_indef() (ieee754dp_spcvals[IEEE754_SPCVAL_INDEF])
+#define ieee754dp_max(sn) (ieee754dp_spcvals[IEEE754_SPCVAL_PMAX+(sn)])
+#define ieee754dp_min(sn) (ieee754dp_spcvals[IEEE754_SPCVAL_PMIN+(sn)])
+#define ieee754dp_mind(sn) (ieee754dp_spcvals[IEEE754_SPCVAL_PMIND+(sn)])
+#define ieee754dp_1e31() (ieee754dp_spcvals[IEEE754_SPCVAL_P1E31])
+#define ieee754dp_1e63() (ieee754dp_spcvals[IEEE754_SPCVAL_P1E63])
+
+#define ieee754sp_inf(sn) (ieee754sp_spcvals[IEEE754_SPCVAL_PINFINITY+(sn)])
+#define ieee754sp_zero(sn) (ieee754sp_spcvals[IEEE754_SPCVAL_PZERO+(sn)])
+#define ieee754sp_one(sn) (ieee754sp_spcvals[IEEE754_SPCVAL_PONE+(sn)])
+#define ieee754sp_ten(sn) (ieee754sp_spcvals[IEEE754_SPCVAL_PTEN+(sn)])
+#define ieee754sp_indef() (ieee754sp_spcvals[IEEE754_SPCVAL_INDEF])
+#define ieee754sp_max(sn) (ieee754sp_spcvals[IEEE754_SPCVAL_PMAX+(sn)])
+#define ieee754sp_min(sn) (ieee754sp_spcvals[IEEE754_SPCVAL_PMIN+(sn)])
+#define ieee754sp_mind(sn) (ieee754sp_spcvals[IEEE754_SPCVAL_PMIND+(sn)])
+#define ieee754sp_1e31() (ieee754sp_spcvals[IEEE754_SPCVAL_P1E31])
+#define ieee754sp_1e63() (ieee754sp_spcvals[IEEE754_SPCVAL_P1E63])
+
+/*
+ * Indefinite integer value
+ */
+#define ieee754si_indef() INT_MAX
+#ifdef LONG_LONG_MAX
+#define ieee754di_indef() LONG_LONG_MAX
+#else
+#define ieee754di_indef() ((s64)(~0ULL>>1))
+#endif
+
+/* IEEE exception context, passed to handler */
+struct ieee754xctx {
+ const char *op; /* operation name */
+ int rt; /* result type */
+ union {
+ ieee754sp sp; /* single precision */
+ ieee754dp dp; /* double precision */
+#ifdef IEEE854_XP
+ ieee754xp xp; /* extended precision */
+#endif
+ int si; /* standard signed integer (32bits) */
+ s64 di; /* extended signed integer (64bits) */
+ } rv; /* default result format implied by op */
+ va_list ap;
+};
+
+/* result types for xctx.rt */
+#define IEEE754_RT_SP 0
+#define IEEE754_RT_DP 1
+#define IEEE754_RT_XP 2
+#define IEEE754_RT_SI 3
+#define IEEE754_RT_DI 4
+
+extern void ieee754_xcpt(struct ieee754xctx *xcp);
+
+/* compat */
+#define ieee754dp_fix(x) ieee754dp_tint(x)
+#define ieee754sp_fix(x) ieee754sp_tint(x)
+
+#endif /* __ARCH_MIPS_MATH_EMU_IEEE754_H */
diff -Nur linux-3.4.113.orig/arch/nds32/math-emu/ieee754int.h linux-3.4.113/arch/nds32/math-emu/ieee754int.h
--- linux-3.4.113.orig/arch/nds32/math-emu/ieee754int.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/math-emu/ieee754int.h 2016-12-01 20:59:24.364613214 +0100
@@ -0,0 +1,165 @@
+/*
+ * IEEE754 floating point
+ * common internal header file
+ */
+/*
+ * MIPS floating point support
+ * Copyright (C) 1994-2000 Algorithmics Ltd.
+ * http://www.algor.co.uk
+ *
+ * ########################################################################
+ *
+ * This program is free software; you can distribute it and/or modify it
+ * under the terms of the GNU General Public License (Version 2) as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
+ *
+ * ########################################################################
+ */
+
+
+#include "ieee754.h"
+
+#define DP_EBIAS 1023
+#define DP_EMIN (-1022)
+#define DP_EMAX 1023
+#define DP_MBITS 52
+
+#define SP_EBIAS 127
+#define SP_EMIN (-126)
+#define SP_EMAX 127
+#define SP_MBITS 23
+
+#define DP_MBIT(x) ((u64)1 << (x))
+#define DP_HIDDEN_BIT DP_MBIT(DP_MBITS)
+#define DP_SIGN_BIT DP_MBIT(63)
+
+#define SP_MBIT(x) ((u32)1 << (x))
+#define SP_HIDDEN_BIT SP_MBIT(SP_MBITS)
+#define SP_SIGN_BIT SP_MBIT(31)
+
+
+#define SPSIGN(sp) (sp.parts.sign)
+#define SPBEXP(sp) (sp.parts.bexp)
+#define SPMANT(sp) (sp.parts.mant)
+
+#define DPSIGN(dp) (dp.parts.sign)
+#define DPBEXP(dp) (dp.parts.bexp)
+#define DPMANT(dp) (dp.parts.mant)
+
+#define CLPAIR(x, y) ((x)*6+(y))
+
+#define CLEARCX \
+ (ieee754_csr.cx = 0)
+
+#define SETCX(x) \
+ (ieee754_csr.cx |= (x), ieee754_csr.sx |= (x))
+
+#define SETANDTESTCX(x) \
+ (SETCX(x), ieee754_csr.mx & (x))
+
+#define TSTX() \
+ (ieee754_csr.cx & ieee754_csr.mx)
+
+
+#define COMPXSP \
+ unsigned xm; int xe; int xs; int xc
+
+#define COMPYSP \
+ unsigned ym; int ye; int ys; int yc
+
+#define EXPLODESP(v, vc, vs, ve, vm) \
+{\
+ vs = SPSIGN(v);\
+ ve = SPBEXP(v);\
+ vm = SPMANT(v);\
+ if(ve == SP_EMAX+1+SP_EBIAS){\
+ if(vm == 0)\
+ vc = IEEE754_CLASS_INF;\
+ else if(vm & SP_MBIT(SP_MBITS-1)) \
+ vc = IEEE754_CLASS_SNAN;\
+ else \
+ vc = IEEE754_CLASS_QNAN;\
+ } else if(ve == SP_EMIN-1+SP_EBIAS) {\
+ if(vm) {\
+ ve = SP_EMIN;\
+ vc = IEEE754_CLASS_DNORM;\
+ } else\
+ vc = IEEE754_CLASS_ZERO;\
+ } else {\
+ ve -= SP_EBIAS;\
+ vm |= SP_HIDDEN_BIT;\
+ vc = IEEE754_CLASS_NORM;\
+ }\
+}
+#define EXPLODEXSP EXPLODESP(x, xc, xs, xe, xm)
+#define EXPLODEYSP EXPLODESP(y, yc, ys, ye, ym)
+
+
+#define COMPXDP \
+u64 xm; int xe; int xs; int xc
+
+#define COMPYDP \
+u64 ym; int ye; int ys; int yc
+
+#define EXPLODEDP(v, vc, vs, ve, vm) \
+{\
+ vm = DPMANT(v);\
+ vs = DPSIGN(v);\
+ ve = DPBEXP(v);\
+ if(ve == DP_EMAX+1+DP_EBIAS){\
+ if(vm == 0)\
+ vc = IEEE754_CLASS_INF;\
+ else if(vm & DP_MBIT(DP_MBITS-1)) \
+ vc = IEEE754_CLASS_SNAN;\
+ else \
+ vc = IEEE754_CLASS_QNAN;\
+ } else if(ve == DP_EMIN-1+DP_EBIAS) {\
+ if(vm) {\
+ ve = DP_EMIN;\
+ vc = IEEE754_CLASS_DNORM;\
+ } else\
+ vc = IEEE754_CLASS_ZERO;\
+ } else {\
+ ve -= DP_EBIAS;\
+ vm |= DP_HIDDEN_BIT;\
+ vc = IEEE754_CLASS_NORM;\
+ }\
+}
+#define EXPLODEXDP EXPLODEDP(x, xc, xs, xe, xm)
+#define EXPLODEYDP EXPLODEDP(y, yc, ys, ye, ym)
+
+#define FLUSHDP(v, vc, vs, ve, vm) \
+ if(vc==IEEE754_CLASS_DNORM) {\
+ if(ieee754_csr.nod) {\
+ SETCX(IEEE754_INEXACT);\
+ vc = IEEE754_CLASS_ZERO;\
+ ve = DP_EMIN-1+DP_EBIAS;\
+ vm = 0;\
+ v = ieee754dp_zero(vs);\
+ }\
+ }
+
+#define FLUSHSP(v, vc, vs, ve, vm) \
+ if(vc==IEEE754_CLASS_DNORM) {\
+ if(ieee754_csr.nod) {\
+ SETCX(IEEE754_INEXACT);\
+ vc = IEEE754_CLASS_ZERO;\
+ ve = SP_EMIN-1+SP_EBIAS;\
+ vm = 0;\
+ v = ieee754sp_zero(vs);\
+ }\
+ }
+
+#define FLUSHXDP FLUSHDP(x, xc, xs, xe, xm)
+#define FLUSHYDP FLUSHDP(y, yc, ys, ye, ym)
+#define FLUSHXSP FLUSHSP(x, xc, xs, xe, xm)
+#define FLUSHYSP FLUSHSP(y, yc, ys, ye, ym)
diff -Nur linux-3.4.113.orig/arch/nds32/math-emu/ieee754m.c linux-3.4.113/arch/nds32/math-emu/ieee754m.c
--- linux-3.4.113.orig/arch/nds32/math-emu/ieee754m.c 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/math-emu/ieee754m.c 2016-12-01 20:59:24.364613214 +0100
@@ -0,0 +1,55 @@
+/*
+ * floor, trunc, ceil
+ */
+/*
+ * MIPS floating point support
+ * Copyright (C) 1994-2000 Algorithmics Ltd.
+ * http://www.algor.co.uk
+ *
+ * ########################################################################
+ *
+ * This program is free software; you can distribute it and/or modify it
+ * under the terms of the GNU General Public License (Version 2) as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
+ *
+ * ########################################################################
+ */
+
+#include "ieee754.h"
+
+ieee754dp ieee754dp_floor(ieee754dp x)
+{
+ ieee754dp i;
+
+ if (ieee754dp_lt(ieee754dp_modf(x, &i), ieee754dp_zero(0)))
+ return ieee754dp_sub(i, ieee754dp_one(0));
+ else
+ return i;
+}
+
+ieee754dp ieee754dp_ceil(ieee754dp x)
+{
+ ieee754dp i;
+
+ if (ieee754dp_gt(ieee754dp_modf(x, &i), ieee754dp_zero(0)))
+ return ieee754dp_add(i, ieee754dp_one(0));
+ else
+ return i;
+}
+
+ieee754dp ieee754dp_trunc(ieee754dp x)
+{
+ ieee754dp i;
+
+ (void)ieee754dp_modf(x, &i);
+ return i;
+}
diff -Nur linux-3.4.113.orig/arch/nds32/math-emu/ieee754sp.c linux-3.4.113/arch/nds32/math-emu/ieee754sp.c
--- linux-3.4.113.orig/arch/nds32/math-emu/ieee754sp.c 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/math-emu/ieee754sp.c 2016-12-01 20:59:24.364613214 +0100
@@ -0,0 +1,239 @@
+/* IEEE754 floating point arithmetic
+ * single precision
+ */
+/*
+ * MIPS floating point support
+ * Copyright (C) 1994-2000 Algorithmics Ltd.
+ * http://www.algor.co.uk
+ *
+ * ########################################################################
+ *
+ * This program is free software; you can distribute it and/or modify it
+ * under the terms of the GNU General Public License (Version 2) as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
+ *
+ * ########################################################################
+ */
+
+#include "ieee754sp.h"
+
+int ieee754sp_class(ieee754sp x)
+{
+ COMPXSP;
+ EXPLODEXSP;
+ return xc;
+}
+
+int ieee754sp_isnan(ieee754sp x)
+{
+ return ieee754sp_class(x) >= IEEE754_CLASS_SNAN;
+}
+
+int ieee754sp_issnan(ieee754sp x)
+{
+ assert(ieee754sp_isnan(x));
+ return (SPMANT(x) & SP_MBIT(SP_MBITS - 1));
+}
+
+ieee754sp ieee754sp_xcpt(ieee754sp r, const char *op, ...)
+{
+ struct ieee754xctx ax;
+
+ if (!TSTX())
+ return r;
+
+ ax.op = op;
+ ax.rt = IEEE754_RT_SP;
+ ax.rv.sp = r;
+ va_start(ax.ap, op);
+ ieee754_xcpt(&ax);
+ va_end(ax.ap);
+ return ax.rv.sp;
+}
+
+ieee754sp ieee754sp_nanxcpt(ieee754sp r, const char *op, ...)
+{
+ struct ieee754xctx ax;
+
+ assert(ieee754sp_isnan(r));
+
+ if (!ieee754sp_issnan(r)) /* QNAN does not cause invalid op !! */
+ return r;
+
+ if (!SETANDTESTCX(IEEE754_INVALID_OPERATION)) {
+ /* not enabled convert to a quiet NaN */
+ SPMANT(r) &= (~SP_MBIT(SP_MBITS - 1));
+ if (ieee754sp_isnan(r))
+ return r;
+ else
+ return ieee754sp_indef();
+ }
+
+ ax.op = op;
+ ax.rt = 0;
+ ax.rv.sp = r;
+ va_start(ax.ap, op);
+ ieee754_xcpt(&ax);
+ va_end(ax.ap);
+ return ax.rv.sp;
+}
+
+ieee754sp ieee754sp_bestnan(ieee754sp x, ieee754sp y)
+{
+ assert(ieee754sp_isnan(x));
+ assert(ieee754sp_isnan(y));
+
+ if (SPMANT(x) > SPMANT(y))
+ return x;
+ else
+ return y;
+}
+
+static unsigned get_rounding(int sn, unsigned xm)
+{
+ /* inexact must round of 3 bits
+ */
+ if (xm & (SP_MBIT(3) - 1)) {
+ switch (ieee754_csr.rm) {
+ case IEEE754_RZ:
+ break;
+ case IEEE754_RN:
+ xm += 0x3 + ((xm >> 3) & 1);
+ /* xm += (xm&0x8)?0x4:0x3 */
+ break;
+ case IEEE754_RU: /* toward +Infinity */
+ if (!sn) /* ?? */
+ xm += 0x8;
+ break;
+ case IEEE754_RD: /* toward -Infinity */
+ if (sn) /* ?? */
+ xm += 0x8;
+ break;
+ }
+ }
+ return xm;
+}
+
+/* generate a normal/denormal number with over,under handling
+ * sn is sign
+ * xe is an unbiased exponent
+ * xm is 3bit extended precision value.
+ */
+ieee754sp ieee754sp_format(int sn, int xe, unsigned xm)
+{
+ assert(xm); /* we don't gen exact zeros (probably should) */
+
+ assert((xm >> (SP_MBITS + 1 + 3)) == 0); /* no execess */
+ assert(xm & (SP_HIDDEN_BIT << 3));
+
+ if (xe < SP_EMIN) {
+ /* strip lower bits */
+ int es = SP_EMIN - xe;
+
+ if (ieee754_csr.nod) {
+ SETCX(IEEE754_UNDERFLOW);
+ SETCX(IEEE754_INEXACT);
+
+ switch (ieee754_csr.rm) {
+ case IEEE754_RN:
+ return ieee754sp_zero(sn);
+ case IEEE754_RZ:
+ return ieee754sp_zero(sn);
+ case IEEE754_RU: /* toward +Infinity */
+ if (sn == 0)
+ return ieee754sp_min(0);
+ else
+ return ieee754sp_zero(1);
+ case IEEE754_RD: /* toward -Infinity */
+ if (sn == 0)
+ return ieee754sp_zero(0);
+ else
+ return ieee754sp_min(1);
+ }
+ }
+
+ if (xe == SP_EMIN - 1
+ && get_rounding(sn, xm) >> (SP_MBITS + 1 + 3)) {
+ /* Not tiny after rounding */
+ SETCX(IEEE754_INEXACT);
+ xm = get_rounding(sn, xm);
+ xm >>= 1;
+ /* Clear grs bits */
+ xm &= ~(SP_MBIT(3) - 1);
+ xe++;
+ } else {
+ /* sticky right shift es bits
+ */
+ SPXSRSXn(es);
+ assert((xm & (SP_HIDDEN_BIT << 3)) == 0);
+ assert(xe == SP_EMIN);
+ }
+ }
+ if (xm & (SP_MBIT(3) - 1)) {
+ SETCX(IEEE754_INEXACT);
+ if ((xm & (SP_HIDDEN_BIT << 3)) == 0) {
+ SETCX(IEEE754_UNDERFLOW);
+ }
+
+ /* inexact must round of 3 bits
+ */
+ xm = get_rounding(sn, xm);
+ /* adjust exponent for rounding add overflowing
+ */
+ if (xm >> (SP_MBITS + 1 + 3)) {
+ /* add causes mantissa overflow */
+ xm >>= 1;
+ xe++;
+ }
+ }
+ /* strip grs bits */
+ xm >>= 3;
+
+ assert((xm >> (SP_MBITS + 1)) == 0); /* no execess */
+ assert(xe >= SP_EMIN);
+
+ if (xe > SP_EMAX) {
+ SETCX(IEEE754_OVERFLOW);
+ SETCX(IEEE754_INEXACT);
+ /* -O can be table indexed by (rm,sn) */
+ switch (ieee754_csr.rm) {
+ case IEEE754_RN:
+ return ieee754sp_inf(sn);
+ case IEEE754_RZ:
+ return ieee754sp_max(sn);
+ case IEEE754_RU: /* toward +Infinity */
+ if (sn == 0)
+ return ieee754sp_inf(0);
+ else
+ return ieee754sp_max(1);
+ case IEEE754_RD: /* toward -Infinity */
+ if (sn == 0)
+ return ieee754sp_max(0);
+ else
+ return ieee754sp_inf(1);
+ }
+ }
+ /* gen norm/denorm/zero */
+
+ if ((xm & SP_HIDDEN_BIT) == 0) {
+ /* we underflow (tiny/zero) */
+ assert(xe == SP_EMIN);
+ if (ieee754_csr.mx & IEEE754_UNDERFLOW)
+ SETCX(IEEE754_UNDERFLOW);
+ return buildsp(sn, SP_EMIN - 1 + SP_EBIAS, xm);
+ } else {
+ assert((xm >> (SP_MBITS + 1)) == 0); /* no execess */
+ assert(xm & SP_HIDDEN_BIT);
+
+ return buildsp(sn, xe + SP_EBIAS, xm & ~SP_HIDDEN_BIT);
+ }
+}
diff -Nur linux-3.4.113.orig/arch/nds32/math-emu/ieee754sp.h linux-3.4.113/arch/nds32/math-emu/ieee754sp.h
--- linux-3.4.113.orig/arch/nds32/math-emu/ieee754sp.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/math-emu/ieee754sp.h 2016-12-01 20:59:24.364613214 +0100
@@ -0,0 +1,89 @@
+/*
+ * IEEE754 floating point
+ * double precision internal header file
+ */
+/*
+ * MIPS floating point support
+ * Copyright (C) 1994-2000 Algorithmics Ltd.
+ * http://www.algor.co.uk
+ *
+ * ########################################################################
+ *
+ * This program is free software; you can distribute it and/or modify it
+ * under the terms of the GNU General Public License (Version 2) as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
+ *
+ * ########################################################################
+ */
+
+
+#include "ieee754int.h"
+
+#define assert(expr) ((void)0)
+
+/* 3bit extended single precision sticky right shift */
+#define SPXSRSXn(rs) \
+ (xe += rs, \
+ xm = (rs > (SP_MBITS+3))?1:((xm) >> (rs)) | ((xm) << (32-(rs)) != 0))
+
+#define SPXSRSX1() \
+ (xe++, (xm = (xm >> 1) | (xm & 1)))
+
+#define SPXSRSYn(rs) \
+ (ye+=rs, \
+ ym = (rs > (SP_MBITS+3))?1:((ym) >> (rs)) | ((ym) << (32-(rs)) != 0))
+
+#define SPXSRSY1() \
+ (ye++, (ym = (ym >> 1) | (ym & 1)))
+
+/* convert denormal to normalized with extended exponent */
+#define SPDNORMx(m,e) \
+ while( (m >> SP_MBITS) == 0) { m <<= 1; e--; }
+#define SPDNORMX SPDNORMx(xm, xe)
+#define SPDNORMY SPDNORMx(ym, ye)
+
+static inline ieee754sp buildsp(int s, int bx, unsigned m)
+{
+ ieee754sp r;
+
+ assert((s) == 0 || (s) == 1);
+ assert((bx) >= SP_EMIN - 1 + SP_EBIAS
+ && (bx) <= SP_EMAX + 1 + SP_EBIAS);
+ assert(((m) >> SP_MBITS) == 0);
+
+ r.parts.sign = s;
+ r.parts.bexp = bx;
+ r.parts.mant = m;
+
+ return r;
+}
+
+extern int ieee754sp_isnan(ieee754sp);
+extern int ieee754sp_issnan(ieee754sp);
+extern int ieee754si_xcpt(int, const char *, ...);
+extern s64 ieee754di_xcpt(s64, const char *, ...);
+extern ieee754sp ieee754sp_xcpt(ieee754sp, const char *, ...);
+extern ieee754sp ieee754sp_nanxcpt(ieee754sp, const char *, ...);
+extern ieee754sp ieee754sp_bestnan(ieee754sp, ieee754sp);
+extern ieee754sp ieee754sp_format(int, int, unsigned);
+
+
+#define SPNORMRET2(s, e, m, name, a0, a1) \
+{ \
+ ieee754sp V = ieee754sp_format(s, e, m); \
+ if(TSTX()) \
+ return ieee754sp_xcpt(V, name, a0, a1); \
+ else \
+ return V; \
+}
+
+#define SPNORMRET1(s, e, m, name, a0) SPNORMRET2(s, e, m, name, a0, a0)
diff -Nur linux-3.4.113.orig/arch/nds32/math-emu/ieee754xcpt.c linux-3.4.113/arch/nds32/math-emu/ieee754xcpt.c
--- linux-3.4.113.orig/arch/nds32/math-emu/ieee754xcpt.c 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/math-emu/ieee754xcpt.c 2016-12-01 20:59:24.364613214 +0100
@@ -0,0 +1,48 @@
+/*
+ * MIPS floating point support
+ * Copyright (C) 1994-2000 Algorithmics Ltd.
+ * http://www.algor.co.uk
+ *
+ * ########################################################################
+ *
+ * This program is free software; you can distribute it and/or modify it
+ * under the terms of the GNU General Public License (Version 2) as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
+ *
+ * ########################################################################
+ */
+
+/**************************************************************************
+ * Nov 7, 2000
+ * Added preprocessor hacks to map to Linux kernel diagnostics.
+ *
+ * Kevin D. Kissell, kevink@mips.com and Carsten Langgaard, carstenl@mips.com
+ * Copyright (C) 2000 MIPS Technologies, Inc. All rights reserved.
+ *************************************************************************/
+
+#include <linux/kernel.h>
+#include "ieee754.h"
+
+/*
+ * Very naff exception handler (you can plug in your own and
+ * override this).
+ */
+
+static const char *const rtnames[] = {
+ "sp", "dp", "xp", "si", "di"
+};
+
+void ieee754_xcpt(struct ieee754xctx *xcp)
+{
+ printk(KERN_DEBUG "floating point exception in \"%s\", type=%s\n",
+ xcp->op, rtnames[xcp->rt]);
+}
diff -Nur linux-3.4.113.orig/arch/nds32/math-emu/insn.h linux-3.4.113/arch/nds32/math-emu/insn.h
--- linux-3.4.113.orig/arch/nds32/math-emu/insn.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/math-emu/insn.h 2016-12-01 20:59:24.364613214 +0100
@@ -0,0 +1,101 @@
+#ifndef _ASM_INST_H
+#define _ASM_INST_H
+
+#define cop0_op 0x35
+
+/*
+ * COP0 field of opcodes.
+ */
+#define fs1_op 0x0
+#define fs2_op 0x4
+#define fd1_op 0x8
+#define fd2_op 0xc
+
+/*
+ * FS1 opcode.
+ */
+enum fs1 {
+ fadds_op, fsubs_op, fcpynss_op, fcpyss_op,
+ fmadds_op, fmsubs_op, fcmovns_op, fcmovzs_op,
+ fnmadds_op, fnmsubs_op,
+ fmuls_op = 0xc, fdivs_op,
+ fs1_f2op_op = 0xf
+};
+
+/*
+ * FS1/F2OP opcode.
+ */
+enum fs1_f2 {
+ fs2d_op, fsqrts_op, fabss_op = 0x5,
+ fui2s_op = 0x8, fsi2s_op = 0xc,
+ fs2ui_op = 0x10, fs2ui_z_op = 0x14,
+ fs2si_op = 0x18, fs2si_z_op = 0x1c
+};
+
+/*
+ * FS2 opcode.
+ */
+enum fs2 {
+ fcmpeqs_op, fcmpeqs_e_op, fcmplts_op, fcmplts_e_op,
+ fcmples_op, fcmples_e_op, fcmpuns_op, fcmpuns_e_op
+};
+
+/*
+ * FD1 opcode.
+ */
+enum fd1 {
+ faddd_op, fsubd_op, fcpynsd_op, fcpysd_op,
+ fmaddd_op, fmsubd_op, fcmovnd_op, fcmovzd_op,
+ fnmaddd_op, fnmsubd_op,
+ fmuld_op = 0xc, fdivd_op, fd1_f2op_op = 0xf
+};
+
+/*
+ * FD1/F2OP opcode.
+ */
+enum fd1_f2 {
+ fd2s_op, fsqrtd_op, fabsd_op = 0x5,
+ fui2d_op = 0x8, fsi2d_op = 0xc,
+ fd2ui_op = 0x10, fd2ui_z_op = 0x14,
+ fd2si_op = 0x18, fd2si_z_op = 0x1c
+};
+
+/*
+ * FD2 opcode.
+ */
+enum fd2 {
+ fcmpeqd_op, fcmpeqd_e_op, fcmpltd_op, fcmpltd_e_op,
+ fcmpled_op, fcmpled_e_op, fcmpund_op, fcmpund_e_op
+};
+
+
+#define NDS32Insn(x) x
+
+#define I_OPCODE_off 25
+#define NDS32Insn_OPCODE(x) (NDS32Insn(x) >> I_OPCODE_off)
+
+#define I_OPCODE_offRt 20
+#define I_OPCODE_mskRt (0x1fUL << I_OPCODE_offRt)
+#define NDS32Insn_OPCODE_Rt(x) ((NDS32Insn(x) & I_OPCODE_mskRt) >> I_OPCODE_offRt)
+
+#define I_OPCODE_offRa 15
+#define I_OPCODE_mskRa (0x1fUL << I_OPCODE_offRa)
+#define NDS32Insn_OPCODE_Ra(x) ((NDS32Insn(x) & I_OPCODE_mskRa) >> I_OPCODE_offRa)
+
+#define I_OPCODE_offRb 10
+#define I_OPCODE_mskRb (0x1fUL << I_OPCODE_offRb)
+#define NDS32Insn_OPCODE_Rb(x) ((NDS32Insn(x) & I_OPCODE_mskRb) >> I_OPCODE_offRb)
+
+#define I_OPCODE_offbit1014 10
+#define I_OPCODE_mskbit1014 (0x1fUL << I_OPCODE_offbit1014)
+#define NDS32Insn_OPCODE_BIT1014(x) ((NDS32Insn(x) & I_OPCODE_mskbit1014) >> I_OPCODE_offbit1014)
+
+#define I_OPCODE_offbit69 6
+#define I_OPCODE_mskbit69 (0xfUL << I_OPCODE_offbit69)
+#define NDS32Insn_OPCODE_BIT69(x) ((NDS32Insn(x) & I_OPCODE_mskbit69) >> I_OPCODE_offbit69)
+
+#define I_OPCODE_offCOP0 0
+#define I_OPCODE_mskCOP0 (0x3fUL << I_OPCODE_offCOP0)
+#define NDS32Insn_OPCODE_COP0(x) ((NDS32Insn(x) & I_OPCODE_mskCOP0) >> I_OPCODE_offCOP0)
+
+#endif
diff -Nur linux-3.4.113.orig/arch/nds32/math-emu/Makefile linux-3.4.113/arch/nds32/math-emu/Makefile
--- linux-3.4.113.orig/arch/nds32/math-emu/Makefile 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/math-emu/Makefile 2016-12-01 20:59:24.364613214 +0100
@@ -0,0 +1,13 @@
+#
+# Makefile for the Linux/nds32 kernel FPU emulation.
+#
+
+obj-y := fpuemu.o ieee754m.o ieee754d.o ieee754dp.o ieee754sp.o ieee754.o \
+ ieee754xcpt.o dp_frexp.o dp_modf.o dp_div.o dp_mul.o dp_sub.o \
+ dp_add.o dp_fsp.o dp_cmp.o dp_logb.o dp_scalb.o dp_simple.o \
+ dp_tint.o dp_fint.o dp_tlong.o dp_flong.o sp_frexp.o sp_modf.o \
+ sp_div.o sp_mul.o sp_sub.o sp_add.o sp_fdp.o sp_cmp.o sp_logb.o \
+ sp_scalb.o sp_simple.o sp_tint.o sp_fint.o sp_tlong.o sp_flong.o \
+ dp_sqrt.o sp_sqrt.o
+
+EXTRA_CFLAGS += -Werror
diff -Nur linux-3.4.113.orig/arch/nds32/math-emu/sp_add.c linux-3.4.113/arch/nds32/math-emu/sp_add.c
--- linux-3.4.113.orig/arch/nds32/math-emu/sp_add.c 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/math-emu/sp_add.c 2016-12-01 20:59:24.364613214 +0100
@@ -0,0 +1,173 @@
+/* IEEE754 floating point arithmetic
+ * single precision
+ */
+/*
+ * MIPS floating point support
+ * Copyright (C) 1994-2000 Algorithmics Ltd.
+ * http://www.algor.co.uk
+ *
+ * ########################################################################
+ *
+ * This program is free software; you can distribute it and/or modify it
+ * under the terms of the GNU General Public License (Version 2) as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
+ *
+ * ########################################################################
+ */
+
+#include "ieee754sp.h"
+
+ieee754sp ieee754sp_add(ieee754sp x, ieee754sp y)
+{
+ COMPXSP;
+ COMPYSP;
+
+ EXPLODEXSP;
+ EXPLODEYSP;
+
+ CLEARCX;
+
+ FLUSHXSP;
+ FLUSHYSP;
+
+ switch (CLPAIR(xc, yc)) {
+ case CLPAIR(IEEE754_CLASS_SNAN, IEEE754_CLASS_QNAN):
+ case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_SNAN):
+ case CLPAIR(IEEE754_CLASS_SNAN, IEEE754_CLASS_SNAN):
+ case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_SNAN):
+ case CLPAIR(IEEE754_CLASS_NORM, IEEE754_CLASS_SNAN):
+ case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_SNAN):
+ case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_SNAN):
+ case CLPAIR(IEEE754_CLASS_SNAN, IEEE754_CLASS_ZERO):
+ case CLPAIR(IEEE754_CLASS_SNAN, IEEE754_CLASS_NORM):
+ case CLPAIR(IEEE754_CLASS_SNAN, IEEE754_CLASS_DNORM):
+ case CLPAIR(IEEE754_CLASS_SNAN, IEEE754_CLASS_INF):
+ SETCX(IEEE754_INVALID_OPERATION);
+ return ieee754sp_nanxcpt(ieee754sp_indef(), "add", x, y);
+
+ case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_QNAN):
+ case CLPAIR(IEEE754_CLASS_NORM, IEEE754_CLASS_QNAN):
+ case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_QNAN):
+ case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_QNAN):
+ return y;
+
+ case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_QNAN):
+ case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_ZERO):
+ case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_NORM):
+ case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_DNORM):
+ case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_INF):
+ return x;
+
+ /* Infinity handling
+ */
+
+ case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_INF):
+ if (xs == ys)
+ return x;
+ SETCX(IEEE754_INVALID_OPERATION);
+ return ieee754sp_xcpt(ieee754sp_indef(), "add", x, y);
+
+ case CLPAIR(IEEE754_CLASS_NORM, IEEE754_CLASS_INF):
+ case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_INF):
+ case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_INF):
+ return y;
+
+ case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_ZERO):
+ case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_NORM):
+ case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_DNORM):
+ return x;
+
+ /* Zero handling
+ */
+
+ case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_ZERO):
+ if (xs == ys)
+ return x;
+ else
+ return ieee754sp_zero(ieee754_csr.rm == IEEE754_RD);
+
+ case CLPAIR(IEEE754_CLASS_NORM, IEEE754_CLASS_ZERO):
+ case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_ZERO):
+ return x;
+
+ case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_NORM):
+ case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_DNORM):
+ return y;
+
+ case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_DNORM):
+ SPDNORMX;
+
+ case CLPAIR(IEEE754_CLASS_NORM, IEEE754_CLASS_DNORM):
+ SPDNORMY;
+ break;
+
+ case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_NORM):
+ SPDNORMX;
+ break;
+
+ case CLPAIR(IEEE754_CLASS_NORM, IEEE754_CLASS_NORM):
+ break;
+ }
+ assert(xm & SP_HIDDEN_BIT);
+ assert(ym & SP_HIDDEN_BIT);
+
+ /* provide guard,round and stick bit space */
+ xm <<= 3;
+ ym <<= 3;
+
+ if (xe > ye) {
+ /* have to shift y fraction right to align
+ */
+ int s = xe - ye;
+ SPXSRSYn(s);
+ } else if (ye > xe) {
+ /* have to shift x fraction right to align
+ */
+ int s = ye - xe;
+ SPXSRSXn(s);
+ }
+ assert(xe == ye);
+ assert(xe <= SP_EMAX);
+
+ if (xs == ys) {
+ /* generate 28 bit result of adding two 27 bit numbers
+ * leaving result in xm,xs,xe
+ */
+ xm = xm + ym;
+ xe = xe;
+ xs = xs;
+
+ if (xm >> (SP_MBITS + 1 + 3)) { /* carry out */
+ SPXSRSX1();
+ }
+ } else {
+ if (xm >= ym) {
+ xm = xm - ym;
+ xe = xe;
+ xs = xs;
+ } else {
+ xm = ym - xm;
+ xe = xe;
+ xs = ys;
+ }
+ if (xm == 0)
+ return ieee754sp_zero(ieee754_csr.rm == IEEE754_RD);
+
+ /* normalize in extended single precision */
+ while ((xm >> (SP_MBITS + 3)) == 0) {
+ xm <<= 1;
+ xe--;
+ }
+
+ }
+ SPNORMRET2(xs, xe, xm, "add", x, y);
+}
diff -Nur linux-3.4.113.orig/arch/nds32/math-emu/sp_cmp.c linux-3.4.113/arch/nds32/math-emu/sp_cmp.c
--- linux-3.4.113.orig/arch/nds32/math-emu/sp_cmp.c 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/math-emu/sp_cmp.c 2016-12-01 20:59:24.364613214 +0100
@@ -0,0 +1,66 @@
+/* IEEE754 floating point arithmetic
+ * single precision
+ */
+/*
+ * MIPS floating point support
+ * Copyright (C) 1994-2000 Algorithmics Ltd.
+ * http://www.algor.co.uk
+ *
+ * ########################################################################
+ *
+ * This program is free software; you can distribute it and/or modify it
+ * under the terms of the GNU General Public License (Version 2) as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
+ *
+ * ########################################################################
+ */
+
+#include "ieee754sp.h"
+
+int ieee754sp_cmp(ieee754sp x, ieee754sp y, int cmp, int sig)
+{
+ COMPXSP;
+ COMPYSP;
+
+ EXPLODEXSP;
+ EXPLODEYSP;
+ FLUSHXSP;
+ FLUSHYSP;
+ CLEARCX; /* Even clear inexact flag here */
+
+ if (ieee754sp_isnan(x) || ieee754sp_isnan(y)) {
+ if (sig || xc == IEEE754_CLASS_SNAN || yc == IEEE754_CLASS_SNAN)
+ SETCX(IEEE754_INVALID_OPERATION);
+ if (cmp & IEEE754_CUN)
+ return 1;
+ if (cmp & (IEEE754_CLT | IEEE754_CGT)) {
+ if (sig && SETANDTESTCX(IEEE754_INVALID_OPERATION))
+ return ieee754si_xcpt(0, "fcmpf", x);
+ }
+ return 0;
+ } else {
+ int vx = x.bits;
+ int vy = y.bits;
+
+ if (vx < 0)
+ vx = -vx ^ SP_SIGN_BIT;
+ if (vy < 0)
+ vy = -vy ^ SP_SIGN_BIT;
+
+ if (vx < vy)
+ return (cmp & IEEE754_CLT) != 0;
+ else if (vx == vy)
+ return (cmp & IEEE754_CEQ) != 0;
+ else
+ return (cmp & IEEE754_CGT) != 0;
+ }
+}
diff -Nur linux-3.4.113.orig/arch/nds32/math-emu/sp_div.c linux-3.4.113/arch/nds32/math-emu/sp_div.c
--- linux-3.4.113.orig/arch/nds32/math-emu/sp_div.c 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/math-emu/sp_div.c 2016-12-01 20:59:24.364613214 +0100
@@ -0,0 +1,155 @@
+/* IEEE754 floating point arithmetic
+ * single precision
+ */
+/*
+ * MIPS floating point support
+ * Copyright (C) 1994-2000 Algorithmics Ltd.
+ * http://www.algor.co.uk
+ *
+ * ########################################################################
+ *
+ * This program is free software; you can distribute it and/or modify it
+ * under the terms of the GNU General Public License (Version 2) as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
+ *
+ * ########################################################################
+ */
+
+#include "ieee754sp.h"
+
+ieee754sp ieee754sp_div(ieee754sp x, ieee754sp y)
+{
+ COMPXSP;
+ COMPYSP;
+
+ EXPLODEXSP;
+ EXPLODEYSP;
+
+ CLEARCX;
+
+ FLUSHXSP;
+ FLUSHYSP;
+
+ switch (CLPAIR(xc, yc)) {
+ case CLPAIR(IEEE754_CLASS_SNAN, IEEE754_CLASS_QNAN):
+ case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_SNAN):
+ case CLPAIR(IEEE754_CLASS_SNAN, IEEE754_CLASS_SNAN):
+ case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_SNAN):
+ case CLPAIR(IEEE754_CLASS_NORM, IEEE754_CLASS_SNAN):
+ case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_SNAN):
+ case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_SNAN):
+ case CLPAIR(IEEE754_CLASS_SNAN, IEEE754_CLASS_ZERO):
+ case CLPAIR(IEEE754_CLASS_SNAN, IEEE754_CLASS_NORM):
+ case CLPAIR(IEEE754_CLASS_SNAN, IEEE754_CLASS_DNORM):
+ case CLPAIR(IEEE754_CLASS_SNAN, IEEE754_CLASS_INF):
+ SETCX(IEEE754_INVALID_OPERATION);
+ return ieee754sp_nanxcpt(ieee754sp_indef(), "div", x, y);
+
+ case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_QNAN):
+ case CLPAIR(IEEE754_CLASS_NORM, IEEE754_CLASS_QNAN):
+ case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_QNAN):
+ case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_QNAN):
+ return y;
+
+ case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_QNAN):
+ case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_ZERO):
+ case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_NORM):
+ case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_DNORM):
+ case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_INF):
+ return x;
+
+ /* Infinity handling
+ */
+
+ case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_INF):
+ SETCX(IEEE754_INVALID_OPERATION);
+ return ieee754sp_xcpt(ieee754sp_indef(), "div", x, y);
+
+ case CLPAIR(IEEE754_CLASS_NORM, IEEE754_CLASS_INF):
+ case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_INF):
+ case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_INF):
+ return ieee754sp_zero(xs ^ ys);
+
+ case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_ZERO):
+ case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_NORM):
+ case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_DNORM):
+ return ieee754sp_inf(xs ^ ys);
+
+ /* Zero handling
+ */
+
+ case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_ZERO):
+ SETCX(IEEE754_INVALID_OPERATION);
+ return ieee754sp_xcpt(ieee754sp_indef(), "div", x, y);
+
+ case CLPAIR(IEEE754_CLASS_NORM, IEEE754_CLASS_ZERO):
+ case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_ZERO):
+ SETCX(IEEE754_ZERO_DIVIDE);
+ return ieee754sp_xcpt(ieee754sp_inf(xs ^ ys), "div", x, y);
+
+ case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_NORM):
+ case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_DNORM):
+ return ieee754sp_zero(xs == ys ? 0 : 1);
+
+ case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_DNORM):
+ SPDNORMX;
+
+ case CLPAIR(IEEE754_CLASS_NORM, IEEE754_CLASS_DNORM):
+ SPDNORMY;
+ break;
+
+ case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_NORM):
+ SPDNORMX;
+ break;
+
+ case CLPAIR(IEEE754_CLASS_NORM, IEEE754_CLASS_NORM):
+ break;
+ }
+ assert(xm & SP_HIDDEN_BIT);
+ assert(ym & SP_HIDDEN_BIT);
+
+ /* provide rounding space */
+ xm <<= 3;
+ ym <<= 3;
+
+ {
+ /* now the dirty work */
+
+ unsigned rm = 0;
+ int re = xe - ye;
+ unsigned bm;
+
+ for (bm = SP_MBIT(SP_MBITS + 2); bm; bm >>= 1) {
+ if (xm >= ym) {
+ xm -= ym;
+ rm |= bm;
+ if (xm == 0)
+ break;
+ }
+ xm <<= 1;
+ }
+ rm <<= 1;
+ if (xm)
+ rm |= 1; /* have remainder, set sticky */
+
+ assert(rm);
+
+ /* normalise rm to rounding precision ?
+ */
+ while ((rm >> (SP_MBITS + 3)) == 0) {
+ rm <<= 1;
+ re--;
+ }
+
+ SPNORMRET2(xs == ys ? 0 : 1, re, rm, "div", x, y);
+ }
+}
diff -Nur linux-3.4.113.orig/arch/nds32/math-emu/sp_fdp.c linux-3.4.113/arch/nds32/math-emu/sp_fdp.c
--- linux-3.4.113.orig/arch/nds32/math-emu/sp_fdp.c 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/math-emu/sp_fdp.c 2016-12-01 20:59:24.368613368 +0100
@@ -0,0 +1,76 @@
+/* IEEE754 floating point arithmetic
+ * single precision
+ */
+/*
+ * MIPS floating point support
+ * Copyright (C) 1994-2000 Algorithmics Ltd.
+ * http://www.algor.co.uk
+ *
+ * ########################################################################
+ *
+ * This program is free software; you can distribute it and/or modify it
+ * under the terms of the GNU General Public License (Version 2) as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
+ *
+ * ########################################################################
+ */
+
+#include "ieee754sp.h"
+
+ieee754sp ieee754sp_fdp(ieee754dp x)
+{
+ COMPXDP;
+ ieee754sp nan;
+
+ EXPLODEXDP;
+
+ CLEARCX;
+
+ FLUSHXDP;
+
+ switch (xc) {
+ case IEEE754_CLASS_SNAN:
+ SETCX(IEEE754_INVALID_OPERATION);
+ return ieee754sp_nanxcpt(ieee754sp_indef(), "fdp");
+ case IEEE754_CLASS_QNAN:
+ nan = buildsp(xs, SP_EMAX + 1 + SP_EBIAS, (u32)
+ (xm >> (DP_MBITS - SP_MBITS)));
+ if (!ieee754sp_isnan(nan))
+ nan = ieee754sp_indef();
+ return ieee754sp_nanxcpt(nan, "fdp", x);
+ case IEEE754_CLASS_INF:
+ return ieee754sp_inf(xs);
+ case IEEE754_CLASS_ZERO:
+ return ieee754sp_zero(xs);
+ case IEEE754_CLASS_DNORM:
+ /* can't possibly be sp representable */
+ SETCX(IEEE754_UNDERFLOW);
+ SETCX(IEEE754_INEXACT);
+ if ((ieee754_csr.rm == IEEE754_RU && !xs) ||
+ (ieee754_csr.rm == IEEE754_RD && xs))
+ return ieee754sp_xcpt(ieee754sp_mind(xs), "fdp", x);
+ return ieee754sp_xcpt(ieee754sp_zero(xs), "fdp", x);
+ case IEEE754_CLASS_NORM:
+ break;
+ }
+
+ {
+ u32 rm;
+
+ /* convert from DP_MBITS to SP_MBITS+3 with sticky right shift
+ */
+ rm = (xm >> (DP_MBITS - (SP_MBITS + 3))) |
+ ((xm << (64 - (DP_MBITS - (SP_MBITS + 3)))) != 0);
+
+ SPNORMRET1(xs, xe, rm, "fdp", x);
+ }
+}
diff -Nur linux-3.4.113.orig/arch/nds32/math-emu/sp_fint.c linux-3.4.113/arch/nds32/math-emu/sp_fint.c
--- linux-3.4.113.orig/arch/nds32/math-emu/sp_fint.c 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/math-emu/sp_fint.c 2016-12-01 20:59:24.368613368 +0100
@@ -0,0 +1,78 @@
+/* IEEE754 floating point arithmetic
+ * single precision
+ */
+/*
+ * MIPS floating point support
+ * Copyright (C) 1994-2000 Algorithmics Ltd.
+ * http://www.algor.co.uk
+ *
+ * ########################################################################
+ *
+ * This program is free software; you can distribute it and/or modify it
+ * under the terms of the GNU General Public License (Version 2) as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
+ *
+ * ########################################################################
+ */
+
+#include "ieee754sp.h"
+
+ieee754sp ieee754sp_fint(int x)
+{
+ unsigned xm;
+ int xe;
+ int xs;
+
+ CLEARCX;
+
+ if (x == 0)
+ return ieee754sp_zero(0);
+ if (x == 1 || x == -1)
+ return ieee754sp_one(x < 0);
+ if (x == 10 || x == -10)
+ return ieee754sp_ten(x < 0);
+
+ xs = (x < 0);
+ if (xs) {
+ if (x == (1 << 31))
+ xm = ((unsigned)1 << 31); /* max neg can't be safely negated */
+ else
+ xm = -x;
+ } else {
+ xm = x;
+ }
+ xe = SP_MBITS + 3;
+
+ if (xm >> (SP_MBITS + 1 + 3)) {
+ /* shunt out overflow bits
+ */
+ while (xm >> (SP_MBITS + 1 + 3)) {
+ SPXSRSX1();
+ }
+ } else {
+ /* normalize in grs extended single precision
+ */
+ while ((xm >> (SP_MBITS + 3)) == 0) {
+ xm <<= 1;
+ xe--;
+ }
+ }
+ SPNORMRET1(xs, xe, xm, "fint", x);
+}
+
+ieee754sp ieee754sp_funs(unsigned int u)
+{
+ if ((int)u < 0)
+ return ieee754sp_add(ieee754sp_1e31(),
+ ieee754sp_fint(u & ~(1 << 31)));
+ return ieee754sp_fint(u);
+}
diff -Nur linux-3.4.113.orig/arch/nds32/math-emu/sp_flong.c linux-3.4.113/arch/nds32/math-emu/sp_flong.c
--- linux-3.4.113.orig/arch/nds32/math-emu/sp_flong.c 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/math-emu/sp_flong.c 2016-12-01 20:59:24.368613368 +0100
@@ -0,0 +1,77 @@
+/* IEEE754 floating point arithmetic
+ * single precision
+ */
+/*
+ * MIPS floating point support
+ * Copyright (C) 1994-2000 Algorithmics Ltd.
+ * http://www.algor.co.uk
+ *
+ * ########################################################################
+ *
+ * This program is free software; you can distribute it and/or modify it
+ * under the terms of the GNU General Public License (Version 2) as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
+ *
+ * ########################################################################
+ */
+
+#include "ieee754sp.h"
+
+ieee754sp ieee754sp_flong(s64 x)
+{
+ u64 xm; /* <--- need 64-bit mantissa temp */
+ int xe;
+ int xs;
+
+ CLEARCX;
+
+ if (x == 0)
+ return ieee754sp_zero(0);
+ if (x == 1 || x == -1)
+ return ieee754sp_one(x < 0);
+ if (x == 10 || x == -10)
+ return ieee754sp_ten(x < 0);
+
+ xs = (x < 0);
+ if (xs) {
+ if (x == (1ULL << 63))
+ xm = (1ULL << 63); /* max neg can't be safely negated */
+ else
+ xm = -x;
+ } else {
+ xm = x;
+ }
+ xe = SP_MBITS + 3;
+
+ if (xm >> (SP_MBITS + 1 + 3)) {
+ /* shunt out overflow bits
+ */
+ while (xm >> (SP_MBITS + 1 + 3)) {
+ SPXSRSX1();
+ }
+ } else {
+ /* normalize in grs extended single precision */
+ while ((xm >> (SP_MBITS + 3)) == 0) {
+ xm <<= 1;
+ xe--;
+ }
+ }
+ SPNORMRET1(xs, xe, xm, "sp_flong", x);
+}
+
+ieee754sp ieee754sp_fulong(u64 u)
+{
+ if ((s64) u < 0)
+ return ieee754sp_add(ieee754sp_1e63(),
+ ieee754sp_flong(u & ~(1ULL << 63)));
+ return ieee754sp_flong(u);
+}
diff -Nur linux-3.4.113.orig/arch/nds32/math-emu/sp_frexp.c linux-3.4.113/arch/nds32/math-emu/sp_frexp.c
--- linux-3.4.113.orig/arch/nds32/math-emu/sp_frexp.c 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/math-emu/sp_frexp.c 2016-12-01 20:59:24.368613368 +0100
@@ -0,0 +1,52 @@
+/* IEEE754 floating point arithmetic
+ * single precision
+ */
+/*
+ * MIPS floating point support
+ * Copyright (C) 1994-2000 Algorithmics Ltd.
+ * http://www.algor.co.uk
+ *
+ * ########################################################################
+ *
+ * This program is free software; you can distribute it and/or modify it
+ * under the terms of the GNU General Public License (Version 2) as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
+ *
+ * ########################################################################
+ */
+
+#include "ieee754sp.h"
+
+/* close to ieeep754sp_logb
+*/
+ieee754sp ieee754sp_frexp(ieee754sp x, int *eptr)
+{
+ COMPXSP;
+ CLEARCX;
+ EXPLODEXSP;
+
+ switch (xc) {
+ case IEEE754_CLASS_SNAN:
+ case IEEE754_CLASS_QNAN:
+ case IEEE754_CLASS_INF:
+ case IEEE754_CLASS_ZERO:
+ *eptr = 0;
+ return x;
+ case IEEE754_CLASS_DNORM:
+ SPDNORMX;
+ break;
+ case IEEE754_CLASS_NORM:
+ break;
+ }
+ *eptr = xe + 1;
+ return buildsp(xs, -1 + SP_EBIAS, xm & ~SP_HIDDEN_BIT);
+}
diff -Nur linux-3.4.113.orig/arch/nds32/math-emu/sp_logb.c linux-3.4.113/arch/nds32/math-emu/sp_logb.c
--- linux-3.4.113.orig/arch/nds32/math-emu/sp_logb.c 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/math-emu/sp_logb.c 2016-12-01 20:59:24.368613368 +0100
@@ -0,0 +1,53 @@
+/* IEEE754 floating point arithmetic
+ * single precision
+ */
+/*
+ * MIPS floating point support
+ * Copyright (C) 1994-2000 Algorithmics Ltd.
+ * http://www.algor.co.uk
+ *
+ * ########################################################################
+ *
+ * This program is free software; you can distribute it and/or modify it
+ * under the terms of the GNU General Public License (Version 2) as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
+ *
+ * ########################################################################
+ */
+
+#include "ieee754sp.h"
+
+ieee754sp ieee754sp_logb(ieee754sp x)
+{
+ COMPXSP;
+
+ CLEARCX;
+
+ EXPLODEXSP;
+
+ switch (xc) {
+ case IEEE754_CLASS_SNAN:
+ return ieee754sp_nanxcpt(x, "logb", x);
+ case IEEE754_CLASS_QNAN:
+ return x;
+ case IEEE754_CLASS_INF:
+ return ieee754sp_inf(0);
+ case IEEE754_CLASS_ZERO:
+ return ieee754sp_inf(1);
+ case IEEE754_CLASS_DNORM:
+ SPDNORMX;
+ break;
+ case IEEE754_CLASS_NORM:
+ break;
+ }
+ return ieee754sp_fint(xe);
+}
diff -Nur linux-3.4.113.orig/arch/nds32/math-emu/sp_modf.c linux-3.4.113/arch/nds32/math-emu/sp_modf.c
--- linux-3.4.113.orig/arch/nds32/math-emu/sp_modf.c 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/math-emu/sp_modf.c 2016-12-01 20:59:24.368613368 +0100
@@ -0,0 +1,79 @@
+/* IEEE754 floating point arithmetic
+ * single precision
+ */
+/*
+ * MIPS floating point support
+ * Copyright (C) 1994-2000 Algorithmics Ltd.
+ * http://www.algor.co.uk
+ *
+ * ########################################################################
+ *
+ * This program is free software; you can distribute it and/or modify it
+ * under the terms of the GNU General Public License (Version 2) as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
+ *
+ * ########################################################################
+ */
+
+#include "ieee754sp.h"
+
+/* modf function is always exact for a finite number
+*/
+ieee754sp ieee754sp_modf(ieee754sp x, ieee754sp * ip)
+{
+ COMPXSP;
+
+ CLEARCX;
+
+ EXPLODEXSP;
+
+ switch (xc) {
+ case IEEE754_CLASS_SNAN:
+ case IEEE754_CLASS_QNAN:
+ case IEEE754_CLASS_INF:
+ case IEEE754_CLASS_ZERO:
+ *ip = x;
+ return x;
+ case IEEE754_CLASS_DNORM:
+ /* far to small */
+ *ip = ieee754sp_zero(xs);
+ return x;
+ case IEEE754_CLASS_NORM:
+ break;
+ }
+ if (xe < 0) {
+ *ip = ieee754sp_zero(xs);
+ return x;
+ }
+ if (xe >= SP_MBITS) {
+ *ip = x;
+ return ieee754sp_zero(xs);
+ }
+ /* generate ipart mantissa by clearing bottom bits
+ */
+ *ip = buildsp(xs, xe + SP_EBIAS,
+ ((xm >> (SP_MBITS - xe)) << (SP_MBITS - xe)) &
+ ~SP_HIDDEN_BIT);
+
+ /* generate fpart mantissa by clearing top bits
+ * and normalizing (must be able to normalize)
+ */
+ xm = (xm << (32 - (SP_MBITS - xe))) >> (32 - (SP_MBITS - xe));
+ if (xm == 0)
+ return ieee754sp_zero(xs);
+
+ while ((xm >> SP_MBITS) == 0) {
+ xm <<= 1;
+ xe--;
+ }
+ return buildsp(xs, xe + SP_EBIAS, xm & ~SP_HIDDEN_BIT);
+}
diff -Nur linux-3.4.113.orig/arch/nds32/math-emu/sp_mul.c linux-3.4.113/arch/nds32/math-emu/sp_mul.c
--- linux-3.4.113.orig/arch/nds32/math-emu/sp_mul.c 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/math-emu/sp_mul.c 2016-12-01 20:59:24.368613368 +0100
@@ -0,0 +1,168 @@
+/* IEEE754 floating point arithmetic
+ * single precision
+ */
+/*
+ * MIPS floating point support
+ * Copyright (C) 1994-2000 Algorithmics Ltd.
+ * http://www.algor.co.uk
+ *
+ * ########################################################################
+ *
+ * This program is free software; you can distribute it and/or modify it
+ * under the terms of the GNU General Public License (Version 2) as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
+ *
+ * ########################################################################
+ */
+
+#include "ieee754sp.h"
+
+ieee754sp ieee754sp_mul(ieee754sp x, ieee754sp y)
+{
+ COMPXSP;
+ COMPYSP;
+
+ EXPLODEXSP;
+ EXPLODEYSP;
+
+ CLEARCX;
+
+ FLUSHXSP;
+ FLUSHYSP;
+
+ switch (CLPAIR(xc, yc)) {
+ case CLPAIR(IEEE754_CLASS_SNAN, IEEE754_CLASS_QNAN):
+ case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_SNAN):
+ case CLPAIR(IEEE754_CLASS_SNAN, IEEE754_CLASS_SNAN):
+ case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_SNAN):
+ case CLPAIR(IEEE754_CLASS_NORM, IEEE754_CLASS_SNAN):
+ case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_SNAN):
+ case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_SNAN):
+ case CLPAIR(IEEE754_CLASS_SNAN, IEEE754_CLASS_ZERO):
+ case CLPAIR(IEEE754_CLASS_SNAN, IEEE754_CLASS_NORM):
+ case CLPAIR(IEEE754_CLASS_SNAN, IEEE754_CLASS_DNORM):
+ case CLPAIR(IEEE754_CLASS_SNAN, IEEE754_CLASS_INF):
+ SETCX(IEEE754_INVALID_OPERATION);
+ return ieee754sp_nanxcpt(ieee754sp_indef(), "mul", x, y);
+
+ case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_QNAN):
+ case CLPAIR(IEEE754_CLASS_NORM, IEEE754_CLASS_QNAN):
+ case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_QNAN):
+ case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_QNAN):
+ return y;
+
+ case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_QNAN):
+ case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_ZERO):
+ case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_NORM):
+ case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_DNORM):
+ case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_INF):
+ return x;
+
+ /* Infinity handling */
+
+ case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_ZERO):
+ case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_INF):
+ SETCX(IEEE754_INVALID_OPERATION);
+ return ieee754sp_xcpt(ieee754sp_indef(), "mul", x, y);
+
+ case CLPAIR(IEEE754_CLASS_NORM, IEEE754_CLASS_INF):
+ case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_INF):
+ case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_NORM):
+ case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_DNORM):
+ case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_INF):
+ return ieee754sp_inf(xs ^ ys);
+
+ case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_ZERO):
+ case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_NORM):
+ case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_DNORM):
+ case CLPAIR(IEEE754_CLASS_NORM, IEEE754_CLASS_ZERO):
+ case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_ZERO):
+ return ieee754sp_zero(xs ^ ys);
+
+ case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_DNORM):
+ SPDNORMX;
+
+ case CLPAIR(IEEE754_CLASS_NORM, IEEE754_CLASS_DNORM):
+ SPDNORMY;
+ break;
+
+ case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_NORM):
+ SPDNORMX;
+ break;
+
+ case CLPAIR(IEEE754_CLASS_NORM, IEEE754_CLASS_NORM):
+ break;
+ }
+ /* rm = xm * ym, re = xe+ye basicly */
+ assert(xm & SP_HIDDEN_BIT);
+ assert(ym & SP_HIDDEN_BIT);
+
+ {
+ int re = xe + ye;
+ int rs = xs ^ ys;
+ unsigned rm;
+
+ /* shunt to top of word */
+ xm <<= 32 - (SP_MBITS + 1);
+ ym <<= 32 - (SP_MBITS + 1);
+
+ /* multiply 32bits xm,ym to give high 32bits rm with stickness
+ */
+ {
+ unsigned short lxm = xm & 0xffff;
+ unsigned short hxm = xm >> 16;
+ unsigned short lym = ym & 0xffff;
+ unsigned short hym = ym >> 16;
+ unsigned lrm;
+ unsigned hrm;
+
+ lrm = lxm * lym; /* 16 * 16 => 32 */
+ hrm = hxm * hym; /* 16 * 16 => 32 */
+
+ {
+ unsigned t = lxm * hym; /* 16 * 16 => 32 */
+ {
+ unsigned at = lrm + (t << 16);
+ hrm += at < lrm;
+ lrm = at;
+ }
+ hrm = hrm + (t >> 16);
+ }
+
+ {
+ unsigned t = hxm * lym; /* 16 * 16 => 32 */
+ {
+ unsigned at = lrm + (t << 16);
+ hrm += at < lrm;
+ lrm = at;
+ }
+ hrm = hrm + (t >> 16);
+ }
+ rm = hrm | (lrm != 0);
+ }
+
+ /*
+ * sticky shift down to normal rounding precision
+ */
+ if ((int)rm < 0) {
+ rm = (rm >> (32 - (SP_MBITS + 1 + 3))) |
+ ((rm << (SP_MBITS + 1 + 3)) != 0);
+ re++;
+ } else {
+ rm = (rm >> (32 - (SP_MBITS + 1 + 3 + 1))) |
+ ((rm << (SP_MBITS + 1 + 3 + 1)) != 0);
+ }
+ assert(rm & (SP_HIDDEN_BIT << 3));
+
+ SPNORMRET2(rs, re, rm, "mul", x, y);
+ }
+}
diff -Nur linux-3.4.113.orig/arch/nds32/math-emu/sp_scalb.c linux-3.4.113/arch/nds32/math-emu/sp_scalb.c
--- linux-3.4.113.orig/arch/nds32/math-emu/sp_scalb.c 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/math-emu/sp_scalb.c 2016-12-01 20:59:24.368613368 +0100
@@ -0,0 +1,56 @@
+/* IEEE754 floating point arithmetic
+ * single precision
+ */
+/*
+ * MIPS floating point support
+ * Copyright (C) 1994-2000 Algorithmics Ltd.
+ * http://www.algor.co.uk
+ *
+ * ########################################################################
+ *
+ * This program is free software; you can distribute it and/or modify it
+ * under the terms of the GNU General Public License (Version 2) as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
+ *
+ * ########################################################################
+ */
+
+#include "ieee754sp.h"
+
+ieee754sp ieee754sp_scalb(ieee754sp x, int n)
+{
+ COMPXSP;
+
+ CLEARCX;
+
+ EXPLODEXSP;
+
+ switch (xc) {
+ case IEEE754_CLASS_SNAN:
+ return ieee754sp_nanxcpt(x, "scalb", x, n);
+ case IEEE754_CLASS_QNAN:
+ case IEEE754_CLASS_INF:
+ case IEEE754_CLASS_ZERO:
+ return x;
+ case IEEE754_CLASS_DNORM:
+ SPDNORMX;
+ break;
+ case IEEE754_CLASS_NORM:
+ break;
+ }
+ SPNORMRET2(xs, xe + n, xm << 3, "scalb", x, n);
+}
+
+ieee754sp ieee754sp_ldexp(ieee754sp x, int n)
+{
+ return ieee754sp_scalb(x, n);
+}
diff -Nur linux-3.4.113.orig/arch/nds32/math-emu/sp_simple.c linux-3.4.113/arch/nds32/math-emu/sp_simple.c
--- linux-3.4.113.orig/arch/nds32/math-emu/sp_simple.c 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/math-emu/sp_simple.c 2016-12-01 20:59:24.368613368 +0100
@@ -0,0 +1,87 @@
+/* IEEE754 floating point arithmetic
+ * single precision
+ */
+/*
+ * MIPS floating point support
+ * Copyright (C) 1994-2000 Algorithmics Ltd.
+ * http://www.algor.co.uk
+ *
+ * ########################################################################
+ *
+ * This program is free software; you can distribute it and/or modify it
+ * under the terms of the GNU General Public License (Version 2) as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
+ *
+ * ########################################################################
+ */
+
+#include "ieee754sp.h"
+
+int ieee754sp_finite(ieee754sp x)
+{
+ return SPBEXP(x) != SP_EMAX + 1 + SP_EBIAS;
+}
+
+ieee754sp ieee754sp_copysign(ieee754sp x, ieee754sp y)
+{
+ CLEARCX;
+ SPSIGN(x) = SPSIGN(y);
+ return x;
+}
+
+ieee754sp ieee754sp_neg(ieee754sp x)
+{
+ COMPXSP;
+
+ EXPLODEXSP;
+ CLEARCX;
+ FLUSHXSP;
+
+ /*
+ * Invert the sign ALWAYS to prevent an endless recursion on
+ * pow() in libc.
+ */
+ /* quick fix up */
+ SPSIGN(x) ^= 1;
+
+ if (xc == IEEE754_CLASS_SNAN) {
+ ieee754sp y = ieee754sp_indef();
+ SETCX(IEEE754_INVALID_OPERATION);
+ SPSIGN(y) = SPSIGN(x);
+ return ieee754sp_nanxcpt(y, "neg");
+ }
+
+ if (ieee754sp_isnan(x)) /* but not infinity */
+ return ieee754sp_nanxcpt(x, "neg", x);
+ return x;
+}
+
+ieee754sp ieee754sp_abs(ieee754sp x)
+{
+ COMPXSP;
+
+ EXPLODEXSP;
+ CLEARCX;
+ FLUSHXSP;
+
+ if (xc == IEEE754_CLASS_SNAN) {
+ SETCX(IEEE754_INVALID_OPERATION);
+ return ieee754sp_nanxcpt(ieee754sp_indef(), "abs");
+ }
+
+ if (ieee754sp_isnan(x)) /* but not infinity */
+ return ieee754sp_nanxcpt(x, "abs", x);
+
+ /* quick fix up */
+ SPSIGN(x) = 0;
+ return x;
+}
diff -Nur linux-3.4.113.orig/arch/nds32/math-emu/sp_sqrt.c linux-3.4.113/arch/nds32/math-emu/sp_sqrt.c
--- linux-3.4.113.orig/arch/nds32/math-emu/sp_sqrt.c 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/math-emu/sp_sqrt.c 2016-12-01 20:59:24.368613368 +0100
@@ -0,0 +1,116 @@
+/* IEEE754 floating point arithmetic
+ * single precision square root
+ */
+/*
+ * MIPS floating point support
+ * Copyright (C) 1994-2000 Algorithmics Ltd.
+ * http://www.algor.co.uk
+ *
+ * ########################################################################
+ *
+ * This program is free software; you can distribute it and/or modify it
+ * under the terms of the GNU General Public License (Version 2) as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
+ *
+ * ########################################################################
+ */
+
+#include "ieee754sp.h"
+
+ieee754sp ieee754sp_sqrt(ieee754sp x)
+{
+ int ix, s, q, m, t, i;
+ unsigned int r;
+ COMPXSP;
+
+ /* take care of Inf and NaN */
+
+ EXPLODEXSP;
+ CLEARCX;
+ FLUSHXSP;
+
+ /* x == INF or NAN? */
+ switch (xc) {
+ case IEEE754_CLASS_QNAN:
+ /* sqrt(Nan) = Nan */
+ return ieee754sp_nanxcpt(x, "sqrt");
+ case IEEE754_CLASS_SNAN:
+ SETCX(IEEE754_INVALID_OPERATION);
+ return ieee754sp_nanxcpt(ieee754sp_indef(), "sqrt");
+ case IEEE754_CLASS_ZERO:
+ /* sqrt(0) = 0 */
+ return x;
+ case IEEE754_CLASS_INF:
+ if (xs) {
+ /* sqrt(-Inf) = Nan */
+ SETCX(IEEE754_INVALID_OPERATION);
+ return ieee754sp_nanxcpt(ieee754sp_indef(), "sqrt");
+ }
+ /* sqrt(+Inf) = Inf */
+ return x;
+ case IEEE754_CLASS_DNORM:
+ case IEEE754_CLASS_NORM:
+ if (xs) {
+ /* sqrt(-x) = Nan */
+ SETCX(IEEE754_INVALID_OPERATION);
+ return ieee754sp_nanxcpt(ieee754sp_indef(), "sqrt");
+ }
+ break;
+ }
+
+ ix = x.bits;
+
+ /* normalize x */
+ m = (ix >> 23);
+ if (m == 0) { /* subnormal x */
+ for (i = 0; (ix & 0x00800000) == 0; i++)
+ ix <<= 1;
+ m -= i - 1;
+ }
+ m -= 127; /* unbias exponent */
+ ix = (ix & 0x007fffff) | 0x00800000;
+ if (m & 1) /* odd m, double x to make it even */
+ ix += ix;
+ m >>= 1; /* m = [m/2] */
+
+ /* generate sqrt(x) bit by bit */
+ ix += ix;
+ q = s = 0; /* q = sqrt(x) */
+ r = 0x01000000; /* r = moving bit from right to left */
+
+ while (r != 0) {
+ t = s + r;
+ if (t <= ix) {
+ s = t + r;
+ ix -= t;
+ q += r;
+ }
+ ix += ix;
+ r >>= 1;
+ }
+
+ if (ix != 0) {
+ SETCX(IEEE754_INEXACT);
+ switch (ieee754_csr.rm) {
+ case IEEE754_RP:
+ q += 2;
+ break;
+ case IEEE754_RN:
+ q += (q & 1);
+ break;
+ }
+ }
+ ix = (q >> 1) + 0x3f000000;
+ ix += (m << 23);
+ x.bits = ix;
+ return x;
+}
diff -Nur linux-3.4.113.orig/arch/nds32/math-emu/sp_sub.c linux-3.4.113/arch/nds32/math-emu/sp_sub.c
--- linux-3.4.113.orig/arch/nds32/math-emu/sp_sub.c 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/math-emu/sp_sub.c 2016-12-01 20:59:24.368613368 +0100
@@ -0,0 +1,180 @@
+/* IEEE754 floating point arithmetic
+ * single precision
+ */
+/*
+ * MIPS floating point support
+ * Copyright (C) 1994-2000 Algorithmics Ltd.
+ * http://www.algor.co.uk
+ *
+ * ########################################################################
+ *
+ * This program is free software; you can distribute it and/or modify it
+ * under the terms of the GNU General Public License (Version 2) as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
+ *
+ * ########################################################################
+ */
+
+#include "ieee754sp.h"
+
+ieee754sp ieee754sp_sub(ieee754sp x, ieee754sp y)
+{
+ COMPXSP;
+ COMPYSP;
+
+ EXPLODEXSP;
+ EXPLODEYSP;
+
+ CLEARCX;
+
+ FLUSHXSP;
+ FLUSHYSP;
+
+ switch (CLPAIR(xc, yc)) {
+ case CLPAIR(IEEE754_CLASS_SNAN, IEEE754_CLASS_QNAN):
+ case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_SNAN):
+ case CLPAIR(IEEE754_CLASS_SNAN, IEEE754_CLASS_SNAN):
+ case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_SNAN):
+ case CLPAIR(IEEE754_CLASS_NORM, IEEE754_CLASS_SNAN):
+ case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_SNAN):
+ case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_SNAN):
+ case CLPAIR(IEEE754_CLASS_SNAN, IEEE754_CLASS_ZERO):
+ case CLPAIR(IEEE754_CLASS_SNAN, IEEE754_CLASS_NORM):
+ case CLPAIR(IEEE754_CLASS_SNAN, IEEE754_CLASS_DNORM):
+ case CLPAIR(IEEE754_CLASS_SNAN, IEEE754_CLASS_INF):
+ SETCX(IEEE754_INVALID_OPERATION);
+ return ieee754sp_nanxcpt(ieee754sp_indef(), "sub", x, y);
+
+ case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_QNAN):
+ case CLPAIR(IEEE754_CLASS_NORM, IEEE754_CLASS_QNAN):
+ case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_QNAN):
+ case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_QNAN):
+ return y;
+
+ case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_QNAN):
+ case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_ZERO):
+ case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_NORM):
+ case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_DNORM):
+ case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_INF):
+ return x;
+
+ /* Infinity handling
+ */
+
+ case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_INF):
+ if (xs != ys)
+ return x;
+ SETCX(IEEE754_INVALID_OPERATION);
+ return ieee754sp_xcpt(ieee754sp_indef(), "sub", x, y);
+
+ case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_INF):
+ case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_INF):
+ case CLPAIR(IEEE754_CLASS_NORM, IEEE754_CLASS_INF):
+ return ieee754sp_inf(ys ^ 1);
+
+ case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_ZERO):
+ case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_NORM):
+ case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_DNORM):
+ return x;
+
+ /* Zero handling
+ */
+
+ case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_ZERO):
+ if (xs != ys)
+ return x;
+ else
+ return ieee754sp_zero(ieee754_csr.rm == IEEE754_RD);
+
+ case CLPAIR(IEEE754_CLASS_NORM, IEEE754_CLASS_ZERO):
+ case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_ZERO):
+ return x;
+
+ case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_NORM):
+ case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_DNORM):
+ /* quick fix up */
+ DPSIGN(y) ^= 1;
+ return y;
+
+ case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_DNORM):
+ SPDNORMX;
+
+ case CLPAIR(IEEE754_CLASS_NORM, IEEE754_CLASS_DNORM):
+ SPDNORMY;
+ break;
+
+ case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_NORM):
+ SPDNORMX;
+ break;
+
+ case CLPAIR(IEEE754_CLASS_NORM, IEEE754_CLASS_NORM):
+ break;
+ }
+ /* flip sign of y and handle as add */
+ ys ^= 1;
+
+ assert(xm & SP_HIDDEN_BIT);
+ assert(ym & SP_HIDDEN_BIT);
+
+ /* provide guard,round and stick bit space */
+ xm <<= 3;
+ ym <<= 3;
+
+ if (xe > ye) {
+ /* have to shift y fraction right to align
+ */
+ int s = xe - ye;
+ SPXSRSYn(s);
+ } else if (ye > xe) {
+ /* have to shift x fraction right to align
+ */
+ int s = ye - xe;
+ SPXSRSXn(s);
+ }
+ assert(xe == ye);
+ assert(xe <= SP_EMAX);
+
+ if (xs == ys) {
+ /* generate 28 bit result of adding two 27 bit numbers
+ */
+ xm = xm + ym;
+ xe = xe;
+ xs = xs;
+
+ if (xm >> (SP_MBITS + 1 + 3)) { /* carry out */
+ SPXSRSX1(); /* shift preserving sticky */
+ }
+ } else {
+ if (xm >= ym) {
+ xm = xm - ym;
+ xe = xe;
+ xs = xs;
+ } else {
+ xm = ym - xm;
+ xe = xe;
+ xs = ys;
+ }
+ if (xm == 0) {
+ if (ieee754_csr.rm == IEEE754_RD)
+ return ieee754sp_zero(1); /* round negative inf. => sign = -1 */
+ else
+ return ieee754sp_zero(0); /* other round modes => sign = 1 */
+ }
+ /* normalize to rounding precision
+ */
+ while ((xm >> (SP_MBITS + 3)) == 0) {
+ xm <<= 1;
+ xe--;
+ }
+ }
+ SPNORMRET2(xs, xe, xm, "sub", x, y);
+}
diff -Nur linux-3.4.113.orig/arch/nds32/math-emu/sp_tint.c linux-3.4.113/arch/nds32/math-emu/sp_tint.c
--- linux-3.4.113.orig/arch/nds32/math-emu/sp_tint.c 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/math-emu/sp_tint.c 2016-12-01 20:59:24.368613368 +0100
@@ -0,0 +1,125 @@
+/* IEEE754 floating point arithmetic
+ * single precision
+ */
+/*
+ * MIPS floating point support
+ * Copyright (C) 1994-2000 Algorithmics Ltd.
+ * http://www.algor.co.uk
+ *
+ * ########################################################################
+ *
+ * This program is free software; you can distribute it and/or modify it
+ * under the terms of the GNU General Public License (Version 2) as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
+ *
+ * ########################################################################
+ */
+
+#include <linux/kernel.h>
+#include "ieee754sp.h"
+
+int ieee754sp_tint(ieee754sp x)
+{
+ COMPXSP;
+
+ CLEARCX;
+
+ EXPLODEXSP;
+ FLUSHXSP;
+
+ switch (xc) {
+ case IEEE754_CLASS_SNAN:
+ case IEEE754_CLASS_QNAN:
+ case IEEE754_CLASS_INF:
+ SETCX(IEEE754_INVALID_OPERATION);
+ return ieee754si_xcpt(ieee754si_indef(), "sp_tint", x);
+ case IEEE754_CLASS_ZERO:
+ return 0;
+ case IEEE754_CLASS_DNORM:
+ case IEEE754_CLASS_NORM:
+ break;
+ }
+ if (xe >= 31) {
+ /* look for valid corner case */
+ if (xe == 31 && xs && xm == SP_HIDDEN_BIT)
+ return -0x80000000;
+ /* Set invalid. We will only use overflow for floating
+ point overflow */
+ SETCX(IEEE754_INVALID_OPERATION);
+ return ieee754si_xcpt(ieee754si_indef(), "sp_tint", x);
+ }
+ /* oh gawd */
+ if (xe > SP_MBITS) {
+ xm <<= xe - SP_MBITS;
+ } else {
+ u32 residue;
+ int round;
+ int sticky;
+ int odd;
+
+ if (xe < -1) {
+ residue = xm;
+ round = 0;
+ sticky = residue != 0;
+ xm = 0;
+ } else {
+ /* Shifting a u32 32 times does not work,
+ * so we do it in two steps. Be aware that xe
+ * may be -1 */
+ residue = xm << (xe + 1);
+ residue <<= 31 - SP_MBITS;
+ round = (residue >> 31) != 0;
+ sticky = (residue << 1) != 0;
+ xm >>= SP_MBITS - xe;
+ }
+ odd = (xm & 0x1) != 0x0;
+ switch (ieee754_csr.rm) {
+ case IEEE754_RN:
+ if (round && (sticky || odd))
+ xm++;
+ break;
+ case IEEE754_RZ:
+ break;
+ case IEEE754_RU: /* toward +Infinity */
+ if ((round || sticky) && !xs)
+ xm++;
+ break;
+ case IEEE754_RD: /* toward -Infinity */
+ if ((round || sticky) && xs)
+ xm++;
+ break;
+ }
+ if ((xm >> 31) != 0) {
+ /* This can happen after rounding */
+ SETCX(IEEE754_INVALID_OPERATION);
+ return ieee754si_xcpt(ieee754si_indef(), "sp_tint", x);
+ }
+ if (round || sticky)
+ SETCX(IEEE754_INEXACT);
+ }
+ if (xs)
+ return -xm;
+ else
+ return xm;
+}
+
+unsigned int ieee754sp_tuns(ieee754sp x)
+{
+ ieee754sp hb = ieee754sp_1e31();
+
+ /* what if x < 0 ?? */
+ if (ieee754sp_lt(x, hb))
+ return (unsigned)ieee754sp_tint(x);
+
+ return (unsigned)ieee754sp_tint(ieee754sp_sub(x, hb)) |
+ ((unsigned)1 << 31);
+}
diff -Nur linux-3.4.113.orig/arch/nds32/math-emu/sp_tlong.c linux-3.4.113/arch/nds32/math-emu/sp_tlong.c
--- linux-3.4.113.orig/arch/nds32/math-emu/sp_tlong.c 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/math-emu/sp_tlong.c 2016-12-01 20:59:24.368613368 +0100
@@ -0,0 +1,119 @@
+/* IEEE754 floating point arithmetic
+ * single precision
+ */
+/*
+ * MIPS floating point support
+ * Copyright (C) 1994-2000 Algorithmics Ltd.
+ * http://www.algor.co.uk
+ *
+ * ########################################################################
+ *
+ * This program is free software; you can distribute it and/or modify it
+ * under the terms of the GNU General Public License (Version 2) as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
+ *
+ * ########################################################################
+ */
+
+#include "ieee754sp.h"
+
+s64 ieee754sp_tlong(ieee754sp x)
+{
+ COMPXDP; /* <-- need 64-bit mantissa tmp */
+
+ CLEARCX;
+
+ EXPLODEXSP;
+ FLUSHXSP;
+
+ switch (xc) {
+ case IEEE754_CLASS_SNAN:
+ case IEEE754_CLASS_QNAN:
+ case IEEE754_CLASS_INF:
+ SETCX(IEEE754_INVALID_OPERATION);
+ return ieee754di_xcpt(ieee754di_indef(), "sp_tlong", x);
+ case IEEE754_CLASS_ZERO:
+ return 0;
+ case IEEE754_CLASS_DNORM:
+ case IEEE754_CLASS_NORM:
+ break;
+ }
+ if (xe >= 63) {
+ /* look for valid corner case */
+ if (xe == 63 && xs && xm == SP_HIDDEN_BIT)
+ return -0x8000000000000000LL;
+ /* Set invalid. We will only use overflow for floating
+ point overflow */
+ SETCX(IEEE754_INVALID_OPERATION);
+ return ieee754di_xcpt(ieee754di_indef(), "sp_tlong", x);
+ }
+ /* oh gawd */
+ if (xe > SP_MBITS) {
+ xm <<= xe - SP_MBITS;
+ } else if (xe < SP_MBITS) {
+ u32 residue;
+ int round;
+ int sticky;
+ int odd;
+
+ if (xe < -1) {
+ residue = xm;
+ round = 0;
+ sticky = residue != 0;
+ xm = 0;
+ } else {
+ residue = xm << (32 - SP_MBITS + xe);
+ round = (residue >> 31) != 0;
+ sticky = (residue << 1) != 0;
+ xm >>= SP_MBITS - xe;
+ }
+ odd = (xm & 0x1) != 0x0;
+ switch (ieee754_csr.rm) {
+ case IEEE754_RN:
+ if (round && (sticky || odd))
+ xm++;
+ break;
+ case IEEE754_RZ:
+ break;
+ case IEEE754_RU: /* toward +Infinity */
+ if ((round || sticky) && !xs)
+ xm++;
+ break;
+ case IEEE754_RD: /* toward -Infinity */
+ if ((round || sticky) && xs)
+ xm++;
+ break;
+ }
+ if ((xm >> 63) != 0) {
+ /* This can happen after rounding */
+ SETCX(IEEE754_INVALID_OPERATION);
+ return ieee754di_xcpt(ieee754di_indef(), "sp_tlong", x);
+ }
+ if (round || sticky)
+ SETCX(IEEE754_INEXACT);
+ }
+ if (xs)
+ return -xm;
+ else
+ return xm;
+}
+
+u64 ieee754sp_tulong(ieee754sp x)
+{
+ ieee754sp hb = ieee754sp_1e63();
+
+ /* what if x < 0 ?? */
+ if (ieee754sp_lt(x, hb))
+ return (u64) ieee754sp_tlong(x);
+
+ return (u64) ieee754sp_tlong(ieee754sp_sub(x, hb)) | (1ULL << 63);
+}
diff -Nur linux-3.4.113.orig/arch/nds32/mm/alignment.c linux-3.4.113/arch/nds32/mm/alignment.c
--- linux-3.4.113.orig/arch/nds32/mm/alignment.c 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/mm/alignment.c 2016-12-01 20:59:24.368613368 +0100
@@ -0,0 +1,560 @@
+/*
+ * linux/arch/nds32/mm/alignment.c
+ *
+ * Copyright (C) 2008 Andes Technology Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include <linux/module.h>
+#include <linux/proc_fs.h>
+#include <linux/uaccess.h>
+
+#include <asm/unaligned.h>
+
+#ifdef CONFIG_PROC_FS
+extern struct proc_dir_entry *proc_dir_cpu;
+#endif
+
+#define DEBUG(enable, tagged, ...) \
+ do{ \
+ if (enable) { \
+ if (tagged) \
+ printk(KERN_WARNING "[ %30s() ] ", __func__); \
+ printk(KERN_WARNING __VA_ARGS__); \
+ } \
+ } while (0)
+
+#define RT(inst) (((inst) >> 20) & 0x1FUL)
+#define RA(inst) (((inst) >> 15) & 0x1FUL)
+#define RB(inst) (((inst) >> 10) & 0x1FUL)
+#define SV(inst) (((inst) >> 8) & 0x3UL)
+#define IMM(inst) (((inst) >> 0) & 0x3FFFUL)
+
+#define RA3(inst) (((inst) >> 3) & 0x7UL)
+#define RT3(inst) (((inst) >> 6) & 0x7UL)
+#define IMM3U(inst) (((inst) >> 0) & 0x7UL)
+
+#define RA5(inst) (((inst) >> 0) & 0x1FUL)
+#define RT4(inst) (((inst) >> 5) & 0xFUL)
+
+extern int (*do_unaligned_access)
+ (unsigned long entry, unsigned long addr,
+ unsigned long type, struct pt_regs * regs);
+extern int va_present(struct mm_struct *mm, unsigned long addr);
+extern int va_kernel_present(unsigned long addr);
+extern int va_readable(struct pt_regs *regs, unsigned long addr);
+extern int va_writable(struct pt_regs *regs, unsigned long addr);
+
+static int mode = 0x3;
+module_param(mode, int, 1);
+
+static inline unsigned long *idx_to_addr(struct pt_regs *regs, int idx)
+{
+ /* this should be consistent with ptrace.h */
+ if (idx >= 0 && idx <= 25) /* R0-R25 */
+ return ®s->NDS32_r0 + idx;
+ else if (idx >= 28 && idx <= 30) /* FP, GP, LP */
+ return ®s->NDS32_fp + (idx - 28);
+ else if (idx == 31) /* SP */
+ return ®s->NDS32_sp;
+ else
+ return NULL; /* cause a segfault */
+}
+
+static inline unsigned long get_inst(unsigned long addr)
+{
+ /* FIXME: consider 16-bit inst. */
+ return be32_to_cpu(get_unaligned((u32 *) addr));
+}
+
+static inline unsigned long get_data(unsigned long addr, int len)
+{
+ if (len == 4)
+ return get_unaligned((u32 *) addr);
+ else
+ return get_unaligned((u16 *) addr);
+}
+
+static inline void set_data(unsigned long addr, unsigned long val, int len)
+{
+ if (len == 4)
+ put_unaligned(val, (u32 *) addr);
+ else
+ put_unaligned(val, (u16 *) addr);
+}
+
+static inline unsigned long sign_extend(unsigned long val, int len)
+{
+ unsigned long ret = 0;
+ unsigned char *s, *t;
+ int i = 0;
+
+ val = cpu_to_le32(val);
+
+ s = (void *)&val;
+ t = (void *)&ret;
+
+ while (i++ < len)
+ *t++ = *s++;
+
+ if (((*(t - 1)) & 0x80) && (i < 4)) {
+
+ while (i++ <= 4)
+ *t++ = 0xff;
+ }
+
+ return le32_to_cpu(ret);
+}
+
+static inline int do_16(unsigned long inst, struct pt_regs *regs)
+{
+ int imm, regular, load, len, addr_mode, idx_mode;
+ unsigned long unaligned_addr, target_val, source_idx, target_idx,
+ shift = 0;
+ switch ((inst >> 9) & 0x3F) {
+
+ case 0x12: /* LHI333 */
+ imm = 1;
+ regular = 1;
+ load = 1;
+ len = 2;
+ addr_mode = 3;
+ idx_mode = 3;
+ break;
+ case 0x10: /* LWI333 */
+ imm = 1;
+ regular = 1;
+ load = 1;
+ len = 4;
+ addr_mode = 3;
+ idx_mode = 3;
+ break;
+ case 0x11: /* LWI333.bi */
+ imm = 1;
+ regular = 0;
+ load = 1;
+ len = 4;
+ addr_mode = 3;
+ idx_mode = 3;
+ break;
+ case 0x1A: /* LWI450 */
+ imm = 0;
+ regular = 1;
+ load = 1;
+ len = 4;
+ addr_mode = 5;
+ idx_mode = 4;
+ break;
+ case 0x16: /* SHI333 */
+ imm = 1;
+ regular = 1;
+ load = 0;
+ len = 2;
+ addr_mode = 3;
+ idx_mode = 3;
+ break;
+ case 0x14: /* SWI333 */
+ imm = 1;
+ regular = 1;
+ load = 0;
+ len = 4;
+ addr_mode = 3;
+ idx_mode = 3;
+ break;
+ case 0x15: /* SWI333.bi */
+ imm = 1;
+ regular = 0;
+ load = 0;
+ len = 4;
+ addr_mode = 3;
+ idx_mode = 3;
+ break;
+ case 0x1B: /* SWI450 */
+ imm = 0;
+ regular = 1;
+ load = 0;
+ len = 4;
+ addr_mode = 5;
+ idx_mode = 4;
+ break;
+
+ default:
+ return -EFAULT;
+ }
+
+ if (addr_mode == 3) {
+ unaligned_addr = *idx_to_addr(regs, RA3(inst));
+ source_idx = RA3(inst);
+ } else {
+ unaligned_addr = *idx_to_addr(regs, RA5(inst));
+ source_idx = RA5(inst);
+ }
+
+ if (idx_mode == 3)
+ target_idx = RT3(inst);
+ else
+ target_idx = RT4(inst);
+
+ if (imm)
+ shift = IMM3U(inst) * len;
+
+ if (regular)
+ unaligned_addr += shift;
+ else
+ *idx_to_addr(regs, source_idx) = unaligned_addr + shift;
+
+ if (load) {
+
+ if (!va_readable(regs, unaligned_addr))
+ return -EACCES;
+
+ if (!access_ok(VERIFY_READ, (void *)unaligned_addr, len))
+ return -EACCES;
+
+ *idx_to_addr(regs, target_idx) = get_data(unaligned_addr, len);
+ } else {
+
+ if (!va_writable(regs, unaligned_addr))
+ return -EACCES;
+
+ if (!access_ok(VERIFY_WRITE, (void *)unaligned_addr, len))
+ return -EACCES;
+
+ target_val = *idx_to_addr(regs, target_idx);
+ set_data(unaligned_addr, target_val, len);
+ }
+
+ regs->NDS32_ipc += 2;
+
+ return 0;
+}
+
+static inline int do_32(unsigned long inst, struct pt_regs *regs)
+{
+ int imm, regular, load, len, sign_ext;
+ unsigned long unsligned_addr, target_val, shift;
+
+ unsligned_addr = *idx_to_addr(regs, RA(inst));
+
+ switch ((inst >> 25) << 1) {
+
+ case 0x02: /* LHI */
+ imm = 1;
+ regular = 1;
+ load = 1;
+ len = 2;
+ sign_ext = 0;
+ break;
+ case 0x0A: /* LHI.bi */
+ imm = 1;
+ regular = 0;
+ load = 1;
+ len = 2;
+ sign_ext = 0;
+ break;
+ case 0x22: /* LHSI */
+ imm = 1;
+ regular = 1;
+ load = 1;
+ len = 2;
+ sign_ext = 1;
+ break;
+ case 0x2A: /* LHSI.bi */
+ imm = 1;
+ regular = 0;
+ load = 1;
+ len = 2;
+ sign_ext = 1;
+ break;
+ case 0x04: /* LWI */
+ imm = 1;
+ regular = 1;
+ load = 1;
+ len = 4;
+ sign_ext = 0;
+ break;
+ case 0x0C: /* LWI.bi */
+ imm = 1;
+ regular = 0;
+ load = 1;
+ len = 4;
+ sign_ext = 0;
+ break;
+ case 0x12: /* SHI */
+ imm = 1;
+ regular = 1;
+ load = 0;
+ len = 2;
+ sign_ext = 0;
+ break;
+ case 0x1A: /* SHI.bi */
+ imm = 1;
+ regular = 0;
+ load = 0;
+ len = 2;
+ sign_ext = 0;
+ break;
+ case 0x14: /* SWI */
+ imm = 1;
+ regular = 1;
+ load = 0;
+ len = 4;
+ sign_ext = 0;
+ break;
+ case 0x1C: /* SWI.bi */
+ imm = 1;
+ regular = 0;
+ load = 0;
+ len = 4;
+ sign_ext = 0;
+ break;
+
+ default:
+ switch (inst & 0xff) {
+
+ case 0x01: /* LH */
+ imm = 0;
+ regular = 1;
+ load = 1;
+ len = 2;
+ sign_ext = 0;
+ break;
+ case 0x05: /* LH.bi */
+ imm = 0;
+ regular = 0;
+ load = 1;
+ len = 2;
+ sign_ext = 0;
+ break;
+ case 0x11: /* LHS */
+ imm = 0;
+ regular = 1;
+ load = 1;
+ len = 2;
+ sign_ext = 1;
+ break;
+ case 0x15: /* LHS.bi */
+ imm = 0;
+ regular = 0;
+ load = 1;
+ len = 2;
+ sign_ext = 1;
+ break;
+ case 0x02: /* LW */
+ imm = 0;
+ regular = 1;
+ load = 1;
+ len = 4;
+ sign_ext = 0;
+ break;
+ case 0x06: /* LW.bi */
+ imm = 0;
+ regular = 0;
+ load = 1;
+ len = 4;
+ sign_ext = 0;
+ break;
+ case 0x09: /* SH */
+ imm = 0;
+ regular = 1;
+ load = 0;
+ len = 2;
+ sign_ext = 0;
+ break;
+ case 0x0D: /* SH.bi */
+ imm = 0;
+ regular = 0;
+ load = 0;
+ len = 2;
+ sign_ext = 0;
+ break;
+ case 0x0A: /* SW */
+ imm = 0;
+ regular = 1;
+ load = 0;
+ len = 4;
+ sign_ext = 0;
+ break;
+ case 0x0E: /* SW.bi */
+ imm = 0;
+ regular = 0;
+ load = 0;
+ len = 4;
+ sign_ext = 0;
+ break;
+
+ default:
+ return -EFAULT;
+ }
+ }
+
+ if (imm)
+ shift = IMM(inst) * len;
+ else
+ shift = *idx_to_addr(regs, RB(inst)) << SV(inst);
+
+ if (regular)
+ unsligned_addr += shift;
+ else
+ *idx_to_addr(regs, RA(inst)) = unsligned_addr + shift;
+
+ if (load) {
+
+ if (!va_readable(regs, unsligned_addr))
+ return -EACCES;
+
+ if (!access_ok(VERIFY_READ, (void *)unsligned_addr, len))
+ return -EACCES;
+
+ if (sign_ext)
+ *idx_to_addr(regs, RT(inst)) =
+ sign_extend(get_data(unsligned_addr, len), len);
+ else
+ *idx_to_addr(regs, RT(inst)) =
+ get_data(unsligned_addr, len);
+ } else {
+
+ if (!va_writable(regs, unsligned_addr))
+ return -EACCES;
+
+ if (!access_ok(VERIFY_WRITE, (void *)unsligned_addr, len))
+ return -EACCES;
+
+ target_val = *idx_to_addr(regs, RT(inst));
+ set_data(unsligned_addr, target_val, len);
+ }
+
+ regs->NDS32_ipc += 4;
+
+ return 0;
+}
+
+static int _do_unaligned_access(unsigned long entry, unsigned long addr,
+ unsigned long type, struct pt_regs *regs)
+{
+ unsigned long inst;
+ int ret = -EFAULT;
+
+ if (user_mode(regs)) {
+ /* user mode */
+ if (!va_present(current->mm, addr))
+ return ret;
+ } else {
+ /* kernel mode */
+ if (!va_kernel_present(addr))
+ return ret;
+ }
+
+ inst = get_inst(regs->NDS32_ipc);
+
+ DEBUG(mode & 0x04, 1,
+ "Faulting Addr: 0x%08lx, PC: 0x%08lx [ 0x%08lx ]\n", addr,
+ regs->NDS32_ipc, inst);
+
+ if ((user_mode(regs) && (mode & 0x01))
+ || (!user_mode(regs) && (mode & 0x02))) {
+
+ mm_segment_t seg = get_fs();
+
+ set_fs(KERNEL_DS);
+
+ if (inst & 0x80000000)
+ ret = do_16((inst >> 16) & 0xffff, regs);
+ else
+ ret = do_32(inst, regs);
+
+ set_fs(seg);
+ }
+
+ return ret;
+}
+
+#ifdef CONFIG_PROC_FS
+
+static int proc_alignment_read(char *page, char **start, off_t off, int count,
+ int *eof, void *data)
+{
+ char *p = page;
+ int len;
+
+ p += sprintf(p, "(0x01) User Mode: %s\n", mode & 0x01 ? "on" : "off");
+ p += sprintf(p, "(0x02) Kernel Mode: %s\n", mode & 0x02 ? "on" : "off");
+ p += sprintf(p, "(0x04) Warning: %s\n", mode & 0x04 ? "on" : "off");
+
+ len = (p - page) - off;
+ if (len < 0)
+ len = 0;
+
+ *eof = (len <= count) ? 1 : 0;
+ *start = page + off;
+
+ return len;
+}
+
+#define INPUTLEN 12 /* '0' + 'x' + 8digit + '\n' + '\0' */
+
+static int proc_alignment_write(struct file *file, const char __user * buffer,
+ unsigned long count, void *data)
+{
+ unsigned long en;
+ char *endp;
+ char inbuf[INPUTLEN];
+
+ if (count > INPUTLEN - 1)
+ return -EFAULT;
+
+ if (copy_from_user(inbuf, buffer, count))
+ return -EFAULT;
+
+ inbuf[count - 1] = '\0';
+
+ en = simple_strtoul(inbuf, &endp, 0);
+ if (en > 0x07)
+ return -EFAULT;
+
+ mode = en & 0x7;
+
+ return count;
+}
+
+#endif /* CONFIG_PROC_FS */
+
+static int __init unaligned_access_init(void)
+{
+#ifdef CONFIG_PROC_FS
+ static struct proc_dir_entry *res_alignment;
+
+ if (!proc_dir_cpu)
+ if (!(proc_dir_cpu = proc_mkdir("cpu", NULL)))
+ return -ENOMEM;
+
+ if (!
+ (res_alignment =
+ create_proc_entry("alignment", S_IWUSR | S_IRUGO, proc_dir_cpu)))
+ return -ENOMEM;
+
+ res_alignment->read_proc = proc_alignment_read;
+ res_alignment->write_proc = proc_alignment_write;
+#endif
+ do_unaligned_access = _do_unaligned_access;
+
+ return 0;
+}
+
+static void __exit unaligned_access_exit(void)
+{
+#ifdef CONFIG_PROC_FS
+ remove_proc_entry("alignment", proc_dir_cpu);
+#endif
+ do_unaligned_access = NULL;
+}
+
+MODULE_AUTHOR("Roy Lee");
+MODULE_DESCRIPTION("Unaligned Access Handler");
+MODULE_LICENSE("GPL");
+
+module_init(unaligned_access_init);
+module_exit(unaligned_access_exit);
diff -Nur linux-3.4.113.orig/arch/nds32/mm/cacheflush.c linux-3.4.113/arch/nds32/mm/cacheflush.c
--- linux-3.4.113.orig/arch/nds32/mm/cacheflush.c 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/mm/cacheflush.c 2016-12-01 20:59:24.368613368 +0100
@@ -0,0 +1,355 @@
+#include <linux/mm.h>
+#include <linux/sched.h>
+#include <linux/fs.h>
+#include <linux/pagemap.h>
+#include <linux/module.h>
+#include <asm/cacheflush.h>
+#include <asm/proc-fns.h>
+#include <asm/shmparam.h>
+#include <asm/cache_info.h>
+
+extern struct cache_info L1_cache_info[2];
+
+#ifdef CONFIG_CPU_CACHE_NONALIASING
+void flush_cache_mm(struct mm_struct *mm)
+{
+}
+
+void flush_cache_dup_mm(struct mm_struct *mm)
+{
+}
+
+void flush_cache_range(struct vm_area_struct *vma,
+ unsigned long start, unsigned long end)
+{
+}
+
+void flush_cache_page(struct vm_area_struct *vma,
+ unsigned long addr, unsigned long pfn)
+{
+}
+
+void flush_cache_vmap(unsigned long start, unsigned long end)
+{
+}
+
+void flush_cache_vunmap(unsigned long start, unsigned long end)
+{
+}
+
+void flush_dcache_page(struct page *page)
+{
+ struct address_space *mapping;
+
+ if (!PageHighMem(page)) {
+ mapping = page_mapping(page);
+ if (mapping && !mapping_mapped(mapping))
+ set_bit(PG_dcache_dirty, &page->flags);
+ else
+ cpu_dcache_wbinval_page((unsigned long)
+ page_address(page));
+ } else {
+ unsigned long kaddr = (unsigned long)kmap_atomic(page);
+ cpu_dcache_wbinval_page(kaddr);
+ kunmap_atomic((void *)kaddr);
+ }
+}
+
+void copy_to_user_page(struct vm_area_struct *vma, struct page *page,
+ unsigned long vaddr, void *dst, void *src, int len)
+{
+ unsigned long line_size, start, end;
+
+ memcpy(dst, src, len);
+ if (vma->vm_flags & VM_EXEC) {
+ line_size = L1_cache_info[DCACHE].line_size;
+ start = (unsigned long)dst & ~(line_size - 1);
+ end =
+ ((unsigned long)dst + len + line_size - 1) & ~(line_size -
+ 1);
+ cpu_cache_wbinval_range(start, end, 1);
+ }
+}
+
+void copy_from_user_page(struct vm_area_struct *vma, struct page *page,
+ unsigned long vaddr, void *dst, void *src, int len)
+{
+ memcpy(dst, src, len);
+}
+
+void flush_icache_range(unsigned long start, unsigned long end)
+{
+ cpu_cache_wbinval_range(start, end, 1);
+}
+
+void flush_icache_page(struct vm_area_struct *vma, struct page *page)
+{
+}
+
+void update_mmu_cache(struct vm_area_struct *vma, unsigned long addr,
+ pte_t * pte)
+{
+ struct page *page;
+ unsigned long pfn = pte_pfn(*pte);
+
+ if (!pfn_valid(pfn))
+ return;
+
+ if (vma->vm_mm == current->active_mm)
+ asm("mtsr %1, $mr2\ndsb\n"
+ "tlbop %0, RWR\nisb\n"
+ ::"r"(*pte), "r"(addr));
+
+ page = pfn_to_page(pfn);
+
+ if ((test_and_clear_bit(PG_dcache_dirty, &page->flags)) ||
+ (vma->vm_flags & VM_EXEC)) {
+
+ if (!PageHighMem(page)) {
+ cpu_cache_wbinval_page((unsigned long)
+ page_address(page),
+ vma->vm_flags & VM_EXEC);
+ } else {
+ unsigned long kaddr = (unsigned long)kmap_atomic(page);
+ cpu_cache_wbinval_page(kaddr, vma->vm_flags & VM_EXEC);
+ kunmap_atomic((void *)kaddr);
+ }
+ }
+}
+#else
+int va_present(struct mm_struct *mm, unsigned long addr);
+
+static inline unsigned long aliasing(unsigned long addr, unsigned long page)
+{
+ return ((addr & PAGE_MASK) ^ page) & (REALSHMLBA - 1);
+}
+
+static inline unsigned long kremap0(unsigned long uaddr, unsigned long pa)
+{
+ unsigned long kaddr, pte;
+
+#define BASE_ADDR0 0xffffc000
+ kaddr = BASE_ADDR0 | (uaddr & L1_cache_info[DCACHE].aliasing_mask);
+ pte = (pa | PAGE_KERNEL);
+ asm("mtsr %1, $mr2\ndsb\n"
+ "tlbop %0, RWLK\nisb\n"
+ ::"r"(pte), "r"(kaddr));
+ return kaddr;
+}
+
+static inline void kunmap01(unsigned long kaddr)
+{
+ asm volatile ("tlbop %0, UNLK\n\t"
+ "tlbop %0, INV\n\t"
+ ::"r" (kaddr));
+}
+
+static inline unsigned long kremap1(unsigned long uaddr, unsigned long pa)
+{
+ unsigned long kaddr, pte;
+
+#define BASE_ADDR1 0xffff8000
+ kaddr = BASE_ADDR1 | (uaddr & L1_cache_info[DCACHE].aliasing_mask);
+ pte = (pa | PAGE_KERNEL);
+ asm("mtsr %1, $mr2\ndsb\n"
+ "tlbop %0, RWLK\nisb\n"
+ ::"r"(pte), "r"(kaddr));
+ return kaddr;
+}
+
+void flush_cache_mm(struct mm_struct *mm)
+{
+ cpu_dcache_wbinval_all();
+ cpu_icache_inval_all();
+}
+
+void flush_cache_dup_mm(struct mm_struct *mm)
+{
+}
+
+void flush_cache_range(struct vm_area_struct *vma,
+ unsigned long start, unsigned long end)
+{
+ if ((end - start) > 8 * PAGE_SIZE) {
+ cpu_dcache_wbinval_all();
+ if (vma->vm_flags & VM_EXEC)
+ cpu_icache_inval_all();
+ return;
+ }
+
+ while (start < end) {
+ if (va_present(vma->vm_mm, start))
+ cpu_cache_wbinval_page(start, vma->vm_flags & VM_EXEC);
+ start += PAGE_SIZE;
+ }
+}
+
+void flush_cache_page(struct vm_area_struct *vma,
+ unsigned long addr, unsigned long pfn)
+{
+ unsigned long vto, flags;
+
+ local_irq_save(flags);
+ vto = kremap0(addr, pfn << PAGE_SHIFT);
+ cpu_cache_wbinval_page(vto, vma->vm_flags & VM_EXEC);
+ kunmap01(vto);
+ local_irq_restore(flags);
+}
+
+void flush_cache_vmap(unsigned long start, unsigned long end)
+{
+ cpu_dcache_wbinval_all();
+}
+
+void flush_cache_vunmap(unsigned long start, unsigned long end)
+{
+ cpu_dcache_wbinval_all();
+}
+
+void copy_user_highpage(struct page *to, struct page *from,
+ unsigned long vaddr, struct vm_area_struct *vma)
+{
+ unsigned long vto, vfrom, flags, kto, kfrom, pfrom, pto;
+ kto = ((unsigned long)page_address(to) & PAGE_MASK);
+ kfrom = ((unsigned long)page_address(from) & PAGE_MASK);
+ pto = page_to_phys(to);
+ pfrom = page_to_phys(from);
+
+ if (aliasing(vaddr, (unsigned long)kfrom))
+ cpu_dcache_wb_page((unsigned long)kfrom);
+ if (aliasing(vaddr, (unsigned long)kto))
+ cpu_dcache_inval_page((unsigned long)kto);
+ local_irq_save(flags);
+ vto = kremap0(vaddr, pto);
+ vfrom = kremap1(vaddr, pfrom);
+ copy_page((void *)vto, (void *)vfrom);
+ kunmap01(vfrom);
+ kunmap01(vto);
+ local_irq_restore(flags);
+}
+
+EXPORT_SYMBOL(copy_user_highpage);
+
+void clear_user_highpage(struct page *page, unsigned long vaddr)
+{
+ unsigned long vto, flags, kto;
+
+ kto = ((unsigned long)page_address(page) & PAGE_MASK);
+
+ local_irq_save(flags);
+ if (aliasing(kto, vaddr) && kto != 0) {
+ cpu_dcache_inval_page(kto);
+ cpu_icache_inval_page(kto);
+ }
+ vto = kremap0(vaddr, page_to_phys(page));
+ clear_page((void *)vto);
+ kunmap01(vto);
+ local_irq_restore(flags);
+}
+
+EXPORT_SYMBOL(clear_user_highpage);
+
+void flush_dcache_page(struct page *page)
+{
+ struct address_space *mapping;
+
+ mapping = page_mapping(page);
+ if (mapping && !mapping_mapped(mapping))
+ set_bit(PG_dcache_dirty, &page->flags);
+ else {
+ int i, pc;
+ unsigned long vto, kaddr, flags;
+ cpu_dcache_wbinval_page((unsigned long)page_address(page));
+ kaddr = (unsigned long)page_address(page);
+ pc = CACHE_SET(DCACHE) * CACHE_LINE_SIZE(DCACHE) / PAGE_SIZE;
+ for (i = 0; i < pc; i++) {
+ local_irq_save(flags);
+ vto = kremap0(kaddr + i * PAGE_SIZE, __pa(kaddr));
+ cpu_dcache_wbinval_page(vto);
+ kunmap01(vto);
+ local_irq_restore(flags);
+ }
+ }
+}
+
+void copy_to_user_page(struct vm_area_struct *vma, struct page *page,
+ unsigned long vaddr, void *dst, void *src, int len)
+{
+ unsigned long line_size, start, end, vto, flags;
+
+ local_irq_save(flags);
+ vto = kremap0(vaddr, page_to_phys(page));
+ dst = (void *)(vto | (vaddr & (PAGE_SIZE - 1)));
+ memcpy(dst, src, len);
+ if (vma->vm_flags & VM_EXEC) {
+ line_size = L1_cache_info[DCACHE].line_size;
+ start = (unsigned long)dst & ~(line_size - 1);
+ end =
+ ((unsigned long)dst + len + line_size - 1) & ~(line_size -
+ 1);
+ cpu_cache_wbinval_range(start, end, 1);
+ }
+ kunmap01(vto);
+ local_irq_restore(flags);
+}
+
+void copy_from_user_page(struct vm_area_struct *vma, struct page *page,
+ unsigned long vaddr, void *dst, void *src, int len)
+{
+ unsigned long vto, flags;
+
+ local_irq_save(flags);
+ vto = kremap0(vaddr, page_to_phys(page));
+ src = (void *)(vto | (vaddr & (PAGE_SIZE - 1)));
+ memcpy(dst, src, len);
+ kunmap01(vto);
+ local_irq_restore(flags);
+}
+
+void flush_anon_page(struct vm_area_struct *vma,
+ struct page *page, unsigned long vaddr)
+{
+ if (!PageAnon(page))
+ return;
+
+ if (vma->vm_mm != current->active_mm)
+ return;
+
+ cpu_cache_wbinval_page(vaddr & PAGE_MASK, vma->vm_flags & VM_EXEC);
+}
+
+void flush_kernel_dcache_page(struct page *page)
+{
+ cpu_dcache_wbinval_page((unsigned long)page_address(page));
+}
+
+void flush_icache_range(unsigned long start, unsigned long end)
+{
+ cpu_cache_wbinval_range(start, end, 1);
+}
+
+void flush_icache_page(struct vm_area_struct *vma, struct page *page)
+{
+}
+
+void update_mmu_cache(struct vm_area_struct *vma, unsigned long addr,
+ pte_t * pte)
+{
+ struct page *page;
+ unsigned long pfn = pte_pfn(*pte);
+
+ if (!pfn_valid(pfn))
+ return;
+
+ if (vma->vm_mm == current->active_mm) {
+ asm("mtsr %1, $mr2\ndsb\n"
+ "tlbop %0, RWR\nisb\n"
+ ::"r"(*pte), "r"(addr));
+ }
+
+ page = pfn_to_page(pfn);
+ if (test_and_clear_bit(PG_dcache_dirty, &page->flags) ||
+ (vma->vm_flags & VM_EXEC))
+ cpu_dcache_wbinval_page((unsigned long)page_address(page));
+}
+#endif
diff -Nur linux-3.4.113.orig/arch/nds32/mm/cctl.c linux-3.4.113/arch/nds32/mm/cctl.c
--- linux-3.4.113.orig/arch/nds32/mm/cctl.c 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/mm/cctl.c 2016-12-01 20:59:24.368613368 +0100
@@ -0,0 +1,284 @@
+/*
+ * linux/arch/nds32/mm/cctl.c
+ *
+ * Copyright (C) 2009 Andes Technology Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include "cctl.h"
+
+#define DEBUG( enable, tagged, ...) \
+ do{ \
+ if( enable){ \
+ if( tagged) \
+ printk( "[ %30s() ] ", __func__); \
+ printk( __VA_ARGS__); \
+ } \
+ } while( 0)
+
+static int debug = 1;
+module_param(debug, int, 0);
+
+static int proc_read_cache_en(char *page, char **start, off_t off,
+ int count, int *eof, void *data)
+{
+
+ if (!strncmp(data, "ic_en", 7))
+ return sprintf(page, "I-cache: %s\n",
+ (GET_CACHE_CTL() & CACHE_CTL_mskIC_EN) ?
+ "Enabled" : "Disabled");
+ else
+ return sprintf(page, "D-cache: %s\n",
+ (GET_CACHE_CTL() & CACHE_CTL_mskDC_EN) ?
+ "Enabled" : "Disabled");
+}
+
+static int proc_write_cache_en(struct file *file, const char *buffer,
+ unsigned long count, void *data)
+{
+
+ unsigned long en, saved_gie;
+ char inbuf[INPUTLEN];
+
+ if (count > INPUTLEN - 1)
+ count = INPUTLEN - 1;
+
+ if (copy_from_user(inbuf, buffer, count))
+ return -EFAULT;
+
+ inbuf[count] = '\0';
+
+ if (!sscanf(inbuf, "%lu", &en) || en > 1)
+ return -EFAULT;
+
+ GIE_SAVE(&saved_gie);
+
+ if (!strncmp(data, "ic_en", 7)) {
+
+ if (en && !(GET_CACHE_CTL() & CACHE_CTL_mskIC_EN)) {
+
+ SET_CACHE_CTL(GET_CACHE_CTL() | CACHE_CTL_mskIC_EN);
+ DEBUG(debug, 1, "I-cache: Enabled\n");
+ } else if (!en && (GET_CACHE_CTL() & CACHE_CTL_mskIC_EN)) {
+
+ SET_CACHE_CTL(GET_CACHE_CTL() & ~CACHE_CTL_mskIC_EN);
+ cpu_icache_inval_all();
+ DEBUG(debug, 1, "I-cache: Disabled\n");
+ }
+ } else {
+ if (en && !(GET_CACHE_CTL() & CACHE_CTL_mskDC_EN)) {
+
+ SET_CACHE_CTL(GET_CACHE_CTL() | CACHE_CTL_mskDC_EN);
+ DEBUG(debug, 1, "D-cache: Enabled\n");
+ } else if (!en && (GET_CACHE_CTL() & CACHE_CTL_mskDC_EN)) {
+
+ SET_CACHE_CTL(GET_CACHE_CTL() & ~CACHE_CTL_mskDC_EN);
+ cpu_dcache_wbinval_all();
+ DEBUG(debug, 1, "D-cache: Disabled\n");
+ }
+ }
+
+ GIE_RESTORE(saved_gie);
+
+ return count;
+}
+
+struct entry_struct proc_table_cache_en[] = {
+
+ {"ic_en", 0644, proc_read_cache_en, proc_write_cache_en},
+ {"dc_en", 0644, proc_read_cache_en, proc_write_cache_en},
+ {NULL, 0, NULL, NULL}
+};
+
+static int sprint_cache_sdz(char *buf, unsigned long size, unsigned long way,
+ unsigned sdz)
+{
+
+ return sprintf(buf, "[%c] %luK x %lu\n[%c] %luK x %lu\n"
+ "[%c] %luK x %lu\n[%c] %luK x %lu\n",
+ (sdz == 0) ? '*' : ' ', (size / 1024), way,
+ (sdz == 1) ? '*' : ' ', (size / 1024), way / 2,
+ (sdz == 2) ? '*' : ' ', (size / 1024) / 2, way,
+ (sdz == 3) ? '*' : ' ', (size / 1024) / 2, way / 2);
+}
+
+static int proc_read_cache_sdz(char *page, char **start, off_t off,
+ int count, int *eof, void *data)
+{
+
+ if (!strncmp(data, "ic_sdz", 7)) {
+
+ return sprint_cache_sdz(page,
+ CACHE_LINE_SIZE(ICACHE) *
+ CACHE_SET(ICACHE), CACHE_WAY(ICACHE),
+ (GET_SDZ_CTL() & SDZ_CTL_mskICDZ) >>
+ SDZ_CTL_offICDZ);
+ } else {
+ return sprint_cache_sdz(page,
+ CACHE_LINE_SIZE(DCACHE) *
+ CACHE_SET(DCACHE), CACHE_WAY(DCACHE),
+ (GET_SDZ_CTL() & SDZ_CTL_mskDCDZ) >>
+ SDZ_CTL_offDCDZ);
+ }
+}
+
+static int proc_write_cache_sdz(struct file *file, const char *buffer,
+ unsigned long count, void *data)
+{
+
+ unsigned long mode, saved_gie, saved_cctl;
+ char inbuf[INPUTLEN];
+
+ if (count > INPUTLEN - 1)
+ count = INPUTLEN - 1;
+
+ if (copy_from_user(inbuf, buffer, count))
+ return -EFAULT;
+
+ inbuf[count] = '\0';
+
+ if (!sscanf(inbuf, "%lu", &mode) || mode > 3)
+ return -EFAULT;
+
+ GIE_SAVE(&saved_gie);
+
+ saved_cctl = GET_CACHE_CTL();
+ DEBUG(debug, 1, "saved_gie: %ld, saved_cctl: 0x%08lx\n", saved_gie,
+ saved_cctl);
+
+ if (!strncmp(data, "ic_sdz", 7)) {
+
+ DEBUG(debug, 1, "IC_SDZ: mode %ld\n", mode);
+
+ if (mode == 2 || mode == 3) {
+
+ if (CACHE_LINE_SIZE(ICACHE) * CACHE_SET(ICACHE) / 2 <
+ 4096) {
+
+ GIE_RESTORE(saved_gie);
+ DEBUG(debug, 1, "Error: way size < 4096\n");
+ return -1;
+ }
+ }
+
+ /* turn off and flush cache */
+ DEBUG(debug, 1, "turning off cache\n");
+ SET_CACHE_CTL(saved_cctl & ~CACHE_CTL_mskIC_EN);
+ DEBUG(debug, 1, "flushing cache\n");
+ cpu_icache_inval_all();
+
+ /* perform down size operation */
+ DEBUG(debug, 1, "downsizing cache\n");
+ SET_SDZ_CTL((GET_SDZ_CTL() & ~SDZ_CTL_mskICDZ) |
+ (mode << SDZ_CTL_offICDZ));
+ } else {
+
+ DEBUG(debug, 1, "DC_SDZ: mode %ld\n", mode);
+
+ if (mode == 2 || mode == 3) {
+
+ if (CACHE_LINE_SIZE(DCACHE) * CACHE_SET(DCACHE) / 2 <
+ 4096) {
+
+ GIE_RESTORE(saved_gie);
+ DEBUG(debug, 1, "Error: way size < 4096\n");
+ return -1;
+ }
+ }
+
+ /* turn off and flush cache */
+ DEBUG(debug, 1, "turning off cache\n");
+ SET_CACHE_CTL(saved_cctl & ~CACHE_CTL_mskDC_EN);
+ DEBUG(debug, 1, "flushing cache\n");
+ cpu_dcache_wbinval_all();
+
+ /* perform down size operation */
+ DEBUG(debug, 1, "downsizing cache\n");
+ SET_SDZ_CTL((GET_SDZ_CTL() & ~SDZ_CTL_mskDCDZ) |
+ (mode << SDZ_CTL_offDCDZ));
+ }
+
+ /* turn on cache ( if it was enabled) */
+ DEBUG(debug, 1, "restoring saved_cctl : 0x%08lx\n", saved_cctl);
+ SET_CACHE_CTL(saved_cctl);
+
+ DEBUG(debug, 1, "restoring saved_git: %ld\n", saved_gie);
+ GIE_RESTORE(saved_gie);
+
+ return count;
+}
+
+struct entry_struct proc_table_cache_sdz[] = {
+
+ {"ic_sdz", 0644, proc_read_cache_sdz, proc_write_cache_sdz},
+ {"dc_sdz", 0644, proc_read_cache_sdz, proc_write_cache_sdz},
+ {NULL, 0, NULL, NULL}
+};
+
+static struct proc_dir_entry *proc_cctl;
+
+static void create_seq_entry(struct entry_struct *e, mode_t mode,
+ struct proc_dir_entry *parent)
+{
+
+ struct proc_dir_entry *entry = create_proc_entry(e->name, mode, parent);
+
+ if (entry) {
+
+ entry->read_proc = e->readop;
+ entry->write_proc = e->writeop;
+ entry->data = e->name;
+ }
+}
+
+static void install_proc_table(struct entry_struct *table)
+{
+
+ while (table->name) {
+
+ create_seq_entry(table, table->perm, proc_cctl);
+ table++;
+ }
+}
+
+static void remove_proc_table(struct entry_struct *table)
+{
+
+ while (table->name) {
+
+ remove_proc_entry(table->name, proc_cctl);
+ table++;
+ }
+}
+
+static int __init init_cctl(void)
+{
+
+ DEBUG(debug, 1, "CCTL module registered\n");
+
+ proc_cctl = proc_mkdir("cctl", NULL);
+
+ install_proc_table(proc_table_cache_en);
+ install_proc_table(proc_table_cache_sdz);
+
+ return 0;
+}
+
+static void __exit cleanup_cctl(void)
+{
+
+ remove_proc_table(proc_table_cache_sdz);
+ remove_proc_table(proc_table_cache_en);
+ remove_proc_entry("cctl", NULL);
+
+ DEBUG(debug, 1, "CCTL module unregistered\n");
+}
+
+module_init(init_cctl);
+module_exit(cleanup_cctl);
+
+MODULE_LICENSE("GPL");
+MODULE_DESCRIPTION("Userspace Cache Control Module");
diff -Nur linux-3.4.113.orig/arch/nds32/mm/cctl.h linux-3.4.113/arch/nds32/mm/cctl.h
--- linux-3.4.113.orig/arch/nds32/mm/cctl.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/mm/cctl.h 2016-12-01 20:59:24.368613368 +0100
@@ -0,0 +1,22 @@
+#ifndef CCTL_H
+#define CCTL_H
+
+#include <linux/module.h>
+#include <linux/blkdev.h>
+#include <linux/proc_fs.h>
+#include <asm/nds32.h>
+
+#define INPUTLEN 32
+
+extern void cpu_icache_flush(void);
+extern void cpu_dcache_flush(void);
+
+struct entry_struct{
+
+ char *name;
+ int perm;
+ read_proc_t *readop;
+ write_proc_t *writeop;
+};
+
+#endif /* CCTL_H */
diff -Nur linux-3.4.113.orig/arch/nds32/mm/consistent.c linux-3.4.113/arch/nds32/mm/consistent.c
--- linux-3.4.113.orig/arch/nds32/mm/consistent.c 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/mm/consistent.c 2016-12-01 20:59:24.368613368 +0100
@@ -0,0 +1,448 @@
+/*
+ * linux/arch/nds32/mm/consistent.c
+ *
+ * Copyright (C) 2000-2004 Russell King
+ * Copyright (C) 2009 Andes Technology Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * DMA uncached mapping support.
+ */
+#include <linux/dma-mapping.h>
+#include <linux/sched.h>
+#include <linux/slab.h>
+#include <asm/cacheflush.h>
+#include <asm/tlbflush.h>
+#include <asm/pgtable.h>
+#include <linux/module.h>
+
+/*
+ * This is the page table (2MB) covering uncached, DMA consistent allocations
+ */
+static pte_t *consistent_pte;
+static DEFINE_RAW_SPINLOCK(consistent_lock);
+
+/*
+ * VM region handling support.
+ *
+ * This should become something generic, handling VM region allocations for
+ * vmalloc and similar (ioremap, module space, etc).
+ *
+ * I envisage vmalloc()'s supporting vm_struct becoming:
+ *
+ * struct vm_struct {
+ * struct vm_region region;
+ * unsigned long flags;
+ * struct page **pages;
+ * unsigned int nr_pages;
+ * unsigned long phys_addr;
+ * };
+ *
+ * get_vm_area() would then call vm_region_alloc with an appropriate
+ * struct vm_region head (eg):
+ *
+ * struct vm_region vmalloc_head = {
+ * .vm_list = LIST_HEAD_INIT(vmalloc_head.vm_list),
+ * .vm_start = VMALLOC_START,
+ * .vm_end = VMALLOC_END,
+ * };
+ *
+ * However, vmalloc_head.vm_start is variable (typically, it is dependent on
+ * the amount of RAM found at boot time.) I would imagine that get_vm_area()
+ * would have to initialise this each time prior to calling vm_region_alloc().
+ */
+struct arch_vm_region {
+ struct list_head vm_list;
+ unsigned long vm_start;
+ unsigned long vm_end;
+ struct page *vm_pages;
+};
+
+static struct arch_vm_region consistent_head = {
+ .vm_list = LIST_HEAD_INIT(consistent_head.vm_list),
+ .vm_start = CONSISTENT_BASE,
+ .vm_end = CONSISTENT_END,
+};
+
+static struct arch_vm_region *vm_region_alloc(struct arch_vm_region *head,
+ size_t size, int gfp)
+{
+ unsigned long addr = head->vm_start, end = head->vm_end - size;
+ unsigned long flags;
+ struct arch_vm_region *c, *new;
+
+ new = kmalloc(sizeof(struct arch_vm_region), gfp);
+ if (!new)
+ goto out;
+
+ raw_spin_lock_irqsave(&consistent_lock, flags);
+
+ list_for_each_entry(c, &head->vm_list, vm_list) {
+ if ((addr + size) < addr)
+ goto nospc;
+ if ((addr + size) <= c->vm_start)
+ goto found;
+ addr = c->vm_end;
+ if (addr > end)
+ goto nospc;
+ }
+
+found:
+ /*
+ * Insert this entry _before_ the one we found.
+ */
+ list_add_tail(&new->vm_list, &c->vm_list);
+ new->vm_start = addr;
+ new->vm_end = addr + size;
+
+ raw_spin_unlock_irqrestore(&consistent_lock, flags);
+ return new;
+
+nospc:
+ raw_spin_unlock_irqrestore(&consistent_lock, flags);
+ kfree(new);
+out:
+ return NULL;
+}
+
+static struct arch_vm_region *vm_region_find(struct arch_vm_region *head,
+ unsigned long addr)
+{
+ struct arch_vm_region *c;
+
+ list_for_each_entry(c, &head->vm_list, vm_list) {
+ if (c->vm_start == addr)
+ goto out;
+ }
+ c = NULL;
+out:
+ return c;
+}
+
+#ifdef CONFIG_HUGETLB_PAGE
+#error ARM Coherent DMA allocator does not (yet) support huge TLB
+#endif
+
+static void *__dma_alloc(struct device *dev, size_t size, dma_addr_t * handle,
+ int gfp, pgprot_t prot)
+{
+ struct page *page;
+ struct arch_vm_region *c;
+ unsigned long order;
+ unsigned int i;
+ u64 mask = ISA_DMA_THRESHOLD, limit;
+
+ if (!consistent_pte) {
+ printk(KERN_ERR "%s: not initialised\n", __func__);
+ dump_stack();
+ return NULL;
+ }
+
+ if (dev) {
+ mask = dev->coherent_dma_mask;
+
+ /*
+ * Sanity check the DMA mask - it must be non-zero, and
+ * must be able to be satisfied by a DMA allocation.
+ */
+ if (mask == 0) {
+ dev_warn(dev, "coherent DMA mask is unset\n");
+ goto no_page;
+ }
+
+ if ((~mask) & ISA_DMA_THRESHOLD) {
+ dev_warn(dev, "coherent DMA mask %#llx is smaller "
+ "than system GFP_DMA mask %#llx\n",
+ mask, (unsigned long long)ISA_DMA_THRESHOLD);
+ goto no_page;
+ }
+ }
+
+ /*
+ * Sanity check the allocation size.
+ */
+ size = PAGE_ALIGN(size);
+ limit = (mask + 1) & ~mask;
+ if ((limit && size >= limit) ||
+ size >= (CONSISTENT_END - CONSISTENT_BASE)) {
+ printk(KERN_WARNING "coherent allocation too big "
+ "(requested %#x mask %#llx)\n", size, mask);
+ goto no_page;
+ }
+
+ order = get_order(size);
+
+ if (mask != 0xffffffff)
+ gfp |= GFP_DMA;
+
+ page = alloc_pages(gfp, order);
+ if (!page)
+ goto no_page;
+
+ for (i = 1; i < (1 << order); i++)
+ atomic_set(&(page + i)->_count, 1);
+
+ /*
+ * Invalidate any data that might be lurking in the
+ * kernel direct-mapped region for device DMA.
+ */
+ {
+ unsigned long kaddr = (unsigned long)page_address(page);
+ memset(page_address(page), 0, size);
+ cpu_dma_wbinval_range(kaddr, kaddr + size);
+ }
+
+ /*
+ * Allocate a virtual address in the consistent mapping region.
+ */
+ c = vm_region_alloc(&consistent_head, size,
+ gfp & ~(__GFP_DMA | __GFP_HIGHMEM));
+ if (c) {
+ pte_t *pte = consistent_pte + CONSISTENT_OFFSET(c->vm_start);
+ struct page *end = page + (1 << order);
+
+ c->vm_pages = page;
+
+ /*
+ * Set the "dma handle"
+ */
+ *handle = page_to_dma(dev, page);
+
+ do {
+ BUG_ON(!pte_none(*pte));
+
+ /*
+ * x86 does not mark the pages reserved...
+ */
+ SetPageReserved(page);
+ set_pte(pte, mk_pte(page, prot));
+ page++;
+ pte++;
+ } while (size -= PAGE_SIZE);
+
+ /*
+ * Free the otherwise unused pages.
+ */
+ while (page < end) {
+ __free_page(page);
+ page++;
+ }
+
+ return (void *)c->vm_start;
+ }
+
+ if (page)
+ __free_pages(page, order);
+no_page:
+ *handle = ~0;
+ return NULL;
+}
+
+/*
+ * Allocate DMA-coherent memory space and return both the kernel remapped
+ * virtual and bus address for that space.
+ */
+void *dma_alloc_coherent(struct device *dev, size_t size, dma_addr_t * handle,
+ gfp_t gfp)
+{
+ return __dma_alloc(dev, size, handle, gfp,
+ pgprot_noncached(PAGE_KERNEL));
+}
+
+EXPORT_SYMBOL(dma_alloc_coherent);
+
+/*
+ * Allocate a writecombining region, in much the same way as
+ * dma_alloc_coherent above.
+ */
+void *dma_alloc_writecombine(struct device *dev, size_t size,
+ dma_addr_t * handle, gfp_t gfp)
+{
+ return __dma_alloc(dev, size, handle, gfp,
+ pgprot_writecombine(PAGE_KERNEL));
+}
+
+EXPORT_SYMBOL(dma_alloc_writecombine);
+
+static int dma_mmap(struct device *dev, struct vm_area_struct *vma,
+ void *cpu_addr, dma_addr_t dma_addr, size_t size)
+{
+ unsigned long flags, user_size, kern_size;
+ struct arch_vm_region *c;
+ int ret = -ENXIO;
+
+ user_size = (vma->vm_end - vma->vm_start) >> PAGE_SHIFT;
+
+ raw_spin_lock_irqsave(&consistent_lock, flags);
+ c = vm_region_find(&consistent_head, (unsigned long)cpu_addr);
+ raw_spin_unlock_irqrestore(&consistent_lock, flags);
+
+ if (c) {
+ unsigned long off = vma->vm_pgoff;
+
+ kern_size = (c->vm_end - c->vm_start) >> PAGE_SHIFT;
+
+ if (off < kern_size && user_size <= (kern_size - off)) {
+ vma->vm_flags |= VM_RESERVED;
+ ret = remap_pfn_range(vma, vma->vm_start,
+ page_to_pfn(c->vm_pages) + off,
+ user_size << PAGE_SHIFT,
+ vma->vm_page_prot);
+ }
+ }
+
+ return ret;
+}
+
+int dma_mmap_coherent(struct device *dev, struct vm_area_struct *vma,
+ void *cpu_addr, dma_addr_t dma_addr, size_t size)
+{
+ vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
+ return dma_mmap(dev, vma, cpu_addr, dma_addr, size);
+}
+
+EXPORT_SYMBOL(dma_mmap_coherent);
+
+int dma_mmap_writecombine(struct device *dev, struct vm_area_struct *vma,
+ void *cpu_addr, dma_addr_t dma_addr, size_t size)
+{
+ vma->vm_page_prot = pgprot_writecombine(vma->vm_page_prot);
+ return dma_mmap(dev, vma, cpu_addr, dma_addr, size);
+}
+
+EXPORT_SYMBOL(dma_mmap_writecombine);
+
+/*
+ * free a page as defined by the above mapping.
+ */
+void dma_free_coherent(struct device *dev, size_t size, void *cpu_addr,
+ dma_addr_t handle)
+{
+ struct arch_vm_region *c;
+ unsigned long flags, addr;
+ pte_t *ptep;
+
+ size = PAGE_ALIGN(size);
+
+ raw_spin_lock_irqsave(&consistent_lock, flags);
+
+ c = vm_region_find(&consistent_head, (unsigned long)cpu_addr);
+ if (!c)
+ goto no_area;
+
+ if ((c->vm_end - c->vm_start) != size) {
+ printk(KERN_ERR "%s: freeing wrong coherent size (%ld != %d)\n",
+ __func__, c->vm_end - c->vm_start, size);
+ dump_stack();
+ size = c->vm_end - c->vm_start;
+ }
+
+ ptep = consistent_pte + CONSISTENT_OFFSET(c->vm_start);
+ addr = c->vm_start;
+ do {
+ pte_t pte = ptep_get_and_clear(&init_mm, addr, ptep);
+ unsigned long pfn;
+
+ ptep++;
+ addr += PAGE_SIZE;
+
+ if (!pte_none(pte) && pte_present(pte)) {
+ pfn = pte_pfn(pte);
+
+ if (pfn_valid(pfn)) {
+ struct page *page = pfn_to_page(pfn);
+
+ /*
+ * x86 does not mark the pages reserved...
+ */
+ ClearPageReserved(page);
+
+ __free_page(page);
+ continue;
+ }
+ }
+
+ printk(KERN_CRIT "%s: bad page in kernel page table\n",
+ __func__);
+ } while (size -= PAGE_SIZE);
+
+ flush_tlb_kernel_range(c->vm_start, c->vm_end);
+
+ list_del(&c->vm_list);
+
+ raw_spin_unlock_irqrestore(&consistent_lock, flags);
+
+ kfree(c);
+ return;
+
+no_area:
+ raw_spin_unlock_irqrestore(&consistent_lock, flags);
+ printk(KERN_ERR "%s: trying to free invalid coherent area: %p\n",
+ __func__, cpu_addr);
+ dump_stack();
+}
+
+EXPORT_SYMBOL(dma_free_coherent);
+
+/*
+ * Initialise the consistent memory allocation.
+ */
+static int __init consistent_init(void)
+{
+ pgd_t *pgd;
+ pmd_t *pmd;
+ pte_t *pte;
+ int ret = 0;
+
+ do {
+ pgd = pgd_offset(&init_mm, CONSISTENT_BASE);
+ pmd = pmd_alloc(&init_mm, pgd, CONSISTENT_BASE);
+ if (!pmd) {
+ printk(KERN_ERR "%s: no pmd tables\n", __func__);
+ ret = -ENOMEM;
+ break;
+ }
+ /* The first level mapping may be created in somewhere.
+ * It's not necessary to warn here. */
+ /* WARN_ON(!pmd_none(*pmd)); */
+
+ pte = pte_alloc_kernel(pmd, CONSISTENT_BASE);
+ if (!pte) {
+ ret = -ENOMEM;
+ break;
+ }
+
+ consistent_pte = pte;
+ } while (0);
+
+ return ret;
+}
+
+core_initcall(consistent_init);
+
+/*
+ * Make an area consistent for devices.
+ */
+void consistent_sync(void *vaddr, size_t size, int direction)
+{
+ unsigned long start = (unsigned long)vaddr;
+ unsigned long end = start + size;
+
+ switch (direction) {
+ case DMA_FROM_DEVICE: /* invalidate only */
+ cpu_dma_inval_range(start, end);
+ break;
+ case DMA_TO_DEVICE: /* writeback only */
+ cpu_dma_wb_range(start, end);
+ break;
+ case DMA_BIDIRECTIONAL: /* writeback and invalidate */
+ cpu_dma_wbinval_range(start, end);
+ break;
+ default:
+ BUG();
+ }
+}
+
+EXPORT_SYMBOL(consistent_sync);
diff -Nur linux-3.4.113.orig/arch/nds32/mm/extable.c linux-3.4.113/arch/nds32/mm/extable.c
--- linux-3.4.113.orig/arch/nds32/mm/extable.c 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/mm/extable.c 2016-12-01 20:59:24.368613368 +0100
@@ -0,0 +1,18 @@
+/*
+ * linux/arch/nds32/mm/extable.c
+ *
+ * Copyright (C) 2009 Andes Technology Corporation
+ */
+#include <linux/module.h>
+#include <asm/uaccess.h>
+
+int fixup_exception(struct pt_regs *regs)
+{
+ const struct exception_table_entry *fixup;
+
+ fixup = search_exception_tables(instruction_pointer(regs));
+ if (fixup)
+ regs->NDS32_ipc = fixup->fixup;
+
+ return fixup != NULL;
+}
diff -Nur linux-3.4.113.orig/arch/nds32/mm/fault.c linux-3.4.113/arch/nds32/mm/fault.c
--- linux-3.4.113.orig/arch/nds32/mm/fault.c 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/mm/fault.c 2016-12-01 20:59:24.368613368 +0100
@@ -0,0 +1,507 @@
+/*
+ * linux/arch/arm/mm/fault.c
+ *
+ * Copyright (C) 1995 Linus Torvalds
+ * Modifications for ARM processor (c) 1995-2004 Russell King
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+/* ============================================================================
+ *
+ * linux/arch/nds32/mm/fault.c
+ *
+ * Copyright (C) 2007 Andes Technology Corporation
+ * This file is part of Linux and should be licensed under the GPL.
+ * See the file COPYING for conditions for redistribution.
+ *
+ * Abstract:
+ *
+ * This program is for NDS32 architecture, referred from ARM's
+ * implementation.
+ *
+ * Revision History:
+ *
+ * Nov.26.2007 Initial ported by Tom, Shawn, and Steven,
+ * patched for KGDB and refined code by Harry.
+ *
+ * Note:
+ *
+ * ============================================================================
+ */
+#include <linux/module.h>
+#include <linux/signal.h>
+#include <linux/ptrace.h>
+#include <linux/mm.h>
+#include <linux/init.h>
+#include <linux/hardirq.h>
+
+#include <asm/system.h>
+#include <asm/pgtable.h>
+#include <asm/tlbflush.h>
+#include <asm/uaccess.h>
+
+#include "fault.h"
+
+/*
+ * This is useful to dump out the page tables associated with
+ * 'addr' in mm 'mm'.
+ */
+void show_pte(struct mm_struct *mm, unsigned long addr)
+{
+ pgd_t *pgd;
+ if (!mm)
+ mm = &init_mm;
+
+ printk(KERN_ALERT "pgd = %p\n", mm->pgd);
+ pgd = pgd_offset(mm, addr);
+ printk(KERN_ALERT "[%08lx] *pgd=%08lx", addr, pgd_val(*pgd));
+
+ do {
+ pmd_t *pmd;
+
+ if (pgd_none(*pgd))
+ break;
+
+ if (pgd_bad(*pgd)) {
+ printk("(bad)");
+ break;
+ }
+
+ pmd = pmd_offset(pgd, addr);
+#if PTRS_PER_PMD != 1
+ printk(", *pmd=%08lx", pmd_val(*pmd));
+#endif
+
+ if (pmd_none(*pmd))
+ break;
+
+ if (pmd_bad(*pmd)) {
+ printk("(bad)");
+ break;
+ }
+#ifndef CONFIG_HIGHMEM
+ {
+ pte_t *pte;
+ /* We must not map this if we have highmem enabled */
+ pte = pte_offset_map(pmd, addr);
+ printk(", *pte=%08lx", pte_val(*pte));
+ pte_unmap(pte);
+ }
+#endif
+ } while (0);
+
+ printk("\n");
+}
+
+/*
+ * Oops. The kernel tried to access some page that wasn't present.
+ */
+static void
+__do_kernel_fault(struct mm_struct *mm, unsigned long addr, unsigned int fsr,
+ struct pt_regs *regs)
+{
+ /*
+ * Are we prepared to handle this kernel fault?
+ */
+ if (fixup_exception(regs))
+ return;
+
+ /*
+ * No handler, we'll have to terminate things with extreme prejudice.
+ */
+ bust_spinlocks(1);
+ printk(KERN_ALERT
+ "__do_kernel_fault: Unable to handle kernel %s at virtual address %08lx\n",
+ (addr < PAGE_SIZE) ? "NULL pointer dereference" :
+ "paging request", addr);
+
+ show_pte(mm, addr);
+ die("Oops", regs, fsr);
+ bust_spinlocks(0);
+ do_exit(SIGKILL);
+}
+
+/*
+ * Something tried to access memory that isn't in our memory map..
+ * User mode accesses just cause a SIGSEGV
+ */
+static void
+__do_user_fault(struct task_struct *tsk, unsigned long addr,
+ unsigned int fsr, int code, struct pt_regs *regs)
+{
+ struct siginfo si;
+
+#ifdef CONFIG_DEBUG_USER
+ if (user_debug & UDBG_SEGV) {
+ printk(KERN_DEBUG
+ "%s: unhandled page fault at 0x%08lx, code 0x%03x\n",
+ tsk->comm, addr, fsr);
+ show_pte(tsk->mm, addr);
+ show_regs(regs);
+ }
+#endif
+
+ tsk->thread.address = addr;
+ tsk->thread.error_code = fsr;
+ tsk->thread.trap_no = 14;
+ si.si_signo = SIGSEGV;
+ si.si_errno = 0;
+ si.si_code = code;
+ si.si_addr = (void __user *)addr;
+ force_sig_info(SIGSEGV, &si, tsk);
+}
+
+void do_bad_area(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
+{
+ struct task_struct *tsk = current;
+ struct mm_struct *mm = tsk->active_mm;
+
+ /*
+ * If we are in kernel mode at this point, we
+ * have no context to handle this fault with.
+ */
+ if (user_mode(regs)) {
+ __do_user_fault(tsk, addr, fsr, SEGV_MAPERR, regs);
+ } else {
+ __do_kernel_fault(mm, addr, fsr, regs);
+ }
+}
+
+#define VM_FAULT_BADMAP 0x010000
+#define VM_FAULT_BADACCESS 0x020000
+
+void do_page_fault(unsigned long entry, unsigned long addr,
+ unsigned int error_code, struct pt_regs *regs)
+{
+ struct task_struct *tsk;
+ struct mm_struct *mm;
+ struct vm_area_struct *vma;
+ siginfo_t info;
+ int fault;
+ unsigned int mask = VM_READ | VM_WRITE | VM_EXEC;
+ unsigned int flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE;
+
+ error_code = error_code & (ITYPE_mskINST | ITYPE_mskETYPE);
+ tsk = current;
+ mm = tsk->mm;
+ info.si_code = SEGV_MAPERR;
+ /*
+ * We fault-in kernel-space virtual memory on-demand. The
+ * 'reference' page table is init_mm.pgd.
+ *
+ * NOTE! We MUST NOT take any locks for this case. We may
+ * be in an interrupt or a critical region, and should
+ * only copy the information from the master page table,
+ * nothing more.
+ */
+ if (addr >= TASK_SIZE) {
+ if (user_mode(regs))
+ goto bad_area_nosemaphore;
+
+ if (addr >= TASK_SIZE && addr < VMALLOC_END && (entry == 2))
+ goto vmalloc_fault;
+ else
+ goto no_context;
+ }
+
+ /*
+ * If we're in an interrupt or have no user
+ * context, we must not take the fault..
+ */
+ if (unlikely(in_atomic() || !mm))
+ goto no_context;
+
+ /*
+ * As per x86, we may deadlock here. However, since the kernel only
+ * validly references user space from well defined areas of the code,
+ * we can bug out early if this is from code which shouldn't.
+ */
+ if (unlikely(!down_read_trylock(&mm->mmap_sem))) {
+ if (!user_mode(regs) &&
+ !search_exception_tables(instruction_pointer(regs)))
+ goto no_context;
+retry:
+ down_read(&mm->mmap_sem);
+ } else {
+ /*
+ * The above down_read_trylock() might have succeeded in which
+ * case, we'll have missed the might_sleep() from down_read().
+ */
+ might_sleep();
+#ifdef CONFIG_DEBUG_VM
+ if (!user_mode(regs) &&
+ !search_exception_tables(instruction_pointer(regs)))
+ goto no_context;
+#endif
+ }
+
+ vma = find_vma(mm, addr);
+
+ if (unlikely(!vma))
+ goto bad_area;
+
+ if (vma->vm_start <= addr)
+ goto good_area;
+
+ if (unlikely(!(vma->vm_flags & VM_GROWSDOWN)))
+ goto bad_area;
+
+ if (unlikely(expand_stack(vma, addr)))
+ goto bad_area;
+
+ /*
+ * Ok, we have a good vm_area for this memory access, so
+ * we can handle it..
+ */
+
+good_area:
+ info.si_code = SEGV_ACCERR;
+
+ /* first do some preliminary protection checks */
+ if (entry == 2) {
+ if (error_code & ITYPE_mskINST)
+ mask = VM_EXEC;
+ else {
+ mask = VM_READ | VM_WRITE;
+ if (vma->vm_flags & VM_WRITE)
+ flags |= FAULT_FLAG_WRITE;
+ }
+ } else if (entry == 3) {
+ switch (error_code & ITYPE_mskETYPE) {
+ case RD_PROT:
+ mask = VM_READ;
+ break;
+ case WRT_PROT:
+ mask = VM_WRITE;
+ flags |= FAULT_FLAG_WRITE;
+ break;
+ case NOEXEC:
+ mask = VM_EXEC;
+ break;
+ case PAGE_MODIFY:
+ mask = VM_WRITE;
+ flags |= FAULT_FLAG_WRITE;
+ break;
+ case ACC_BIT:
+ BUG();
+ default:
+ break;
+ }
+
+ }
+ if (!(vma->vm_flags & mask))
+ goto bad_area;
+
+ /*
+ * If for any reason at all we couldn't handle the fault,
+ * make sure we exit gracefully rather than endlessly redo
+ * the fault.
+ */
+
+ fault = handle_mm_fault(mm, vma, addr, flags);
+
+ /*
+ * If we need to retry but a fatal signal is pending, handle the
+ * signal first. We do not need to release the mmap_sem because it
+ * would already be released in __lock_page_or_retry in mm/filemap.c.
+ */
+ if ((fault & VM_FAULT_RETRY) && fatal_signal_pending(current))
+ return;
+
+ if (unlikely(fault & VM_FAULT_ERROR)) {
+ if (fault & VM_FAULT_OOM)
+ goto out_of_memory;
+ else if (fault & VM_FAULT_SIGBUS)
+ goto do_sigbus;
+ BUG();
+ }
+
+ /*
+ * Major/minor page fault accounting is only done on the initial
+ * attempt. If we go through a retry, it is extremely likely that the
+ * page will be found in page cache at that point.
+ */
+ if (flags & FAULT_FLAG_ALLOW_RETRY) {
+ if (fault & VM_FAULT_MAJOR)
+ tsk->maj_flt++;
+ else
+ tsk->min_flt++;
+ if (fault & VM_FAULT_RETRY) {
+ flags &= ~FAULT_FLAG_ALLOW_RETRY;
+ flags |= FAULT_FLAG_TRIED;
+
+ /* No need to up_read(&mm->mmap_sem) as we would
+ * have already released it in __lock_page_or_retry
+ * in mm/filemap.c.
+ */
+ goto retry;
+ }
+ }
+
+ up_read(&mm->mmap_sem);
+ return;
+
+ /*
+ * Something tried to access memory that isn't in our memory map..
+ * Fix it, but check if it's kernel or user first..
+ */
+bad_area:
+ up_read(&mm->mmap_sem);
+
+bad_area_nosemaphore:
+
+ /* User mode accesses just cause a SIGSEGV */
+
+ if (user_mode(regs)) {
+ tsk->thread.address = addr;
+ tsk->thread.error_code = error_code;
+ tsk->thread.trap_no = 14;
+ info.si_signo = SIGSEGV;
+ info.si_errno = 0;
+ /* info.si_code has been set above */
+ info.si_addr = (void *)addr;
+ force_sig_info(SIGSEGV, &info, tsk);
+ return;
+ }
+
+no_context:
+
+ /* Are we prepared to handle this kernel fault?
+ *
+ * (The kernel has valid exception-points in the source
+ * when it acesses user-memory. When it fails in one
+ * of those points, we find it in a table and do a jump
+ * to some fixup code that loads an appropriate error
+ * code)
+ */
+
+ {
+ const struct exception_table_entry *entry;
+
+ if ((entry =
+ search_exception_tables(instruction_pointer(regs))) !=
+ NULL) {
+ /* Adjust the instruction pointer in the stackframe */
+ instruction_pointer(regs) = entry->fixup;
+ return;
+ }
+ }
+
+ /*
+ * Oops. The kernel tried to access some bad page. We'll have to
+ * terminate things with extreme prejudice.
+ */
+
+ bust_spinlocks(1);
+ printk(KERN_ALERT
+ "Unable to handle kernel %s at virtual address %08lx\n",
+ (addr < PAGE_SIZE) ? "NULL pointer dereference" :
+ "paging request", addr);
+
+ show_pte(mm, addr);
+ die("Oops", regs, error_code);
+ bust_spinlocks(0);
+ do_exit(SIGKILL);
+
+ /* TODO: verify this necessity */
+ return;
+
+ /*
+ * We ran out of memory, or some other thing happened to us that made
+ * us unable to handle the page fault gracefully.
+ */
+
+out_of_memory:
+ up_read(&mm->mmap_sem);
+ if (!user_mode(regs))
+ goto no_context;
+ pagefault_out_of_memory();
+ return;
+
+do_sigbus:
+ up_read(&mm->mmap_sem);
+
+ /* Kernel mode? Handle exceptions or die */
+ if (!user_mode(regs))
+ goto no_context;
+
+ /*
+ * Send a sigbus
+ */
+ tsk->thread.address = addr;
+ tsk->thread.error_code = error_code;
+ tsk->thread.trap_no = 14;
+ info.si_signo = SIGBUS;
+ info.si_errno = 0;
+ info.si_code = BUS_ADRERR;
+ info.si_addr = (void *)addr;
+ force_sig_info(SIGBUS, &info, tsk);
+
+ return;
+
+vmalloc_fault:
+ {
+ /*
+ * Synchronize this task's top level page-table
+ * with the 'reference' page table.
+ *
+ * Use current_pgd instead of tsk->active_mm->pgd
+ * since the latter might be unavailable if this
+ * code is executed in a misfortunately run irq
+ * (like inside schedule() between switch_mm and
+ * switch_to...).
+ */
+
+ unsigned int index = pgd_index(addr);
+ pgd_t *pgd, *pgd_k;
+ pud_t *pud, *pud_k;
+ pmd_t *pmd, *pmd_k;
+ pte_t *pte_k;
+
+ pgd = (pgd_t *) __va(GET_L1_PPTB()) + index;
+ pgd_k = init_mm.pgd + index;
+
+ if (!pgd_present(*pgd_k))
+ goto no_context;
+
+ pud = pud_offset(pgd, addr);
+ pud_k = pud_offset(pgd_k, addr);
+ if (!pud_present(*pud_k))
+ goto no_context;
+
+ pmd = pmd_offset(pud, addr);
+ pmd_k = pmd_offset(pud_k, addr);
+ if (!pmd_present(*pmd_k))
+ goto no_context;
+
+ if (!pmd_present(*pmd)) {
+ set_pmd(pmd, *pmd_k);
+ /* TODO: need to do a cache flush like arm,
+ * maybe add at header file */
+ } else
+
+ BUG_ON(pmd_page(*pmd) != pmd_page(*pmd_k));
+
+ /*
+ * Since the vmalloc area is global, we don't
+ * need to copy individual PTE's, it is enough to
+ * copy the pgd pointer into the pte page of the
+ * root task. If that is there, we'll find our pte if
+ * it exists.
+ */
+
+ /* Make sure the actual PTE exists as well to
+ * catch kernel vmalloc-area accesses to non-mapped
+ * addres. If we don't do this, this will just
+ * silently loop forever.
+ */
+
+ pte_k = pte_offset_kernel(pmd_k, addr);
+ if (!pte_present(*pte_k))
+ goto no_context;
+
+ return;
+ }
+}
diff -Nur linux-3.4.113.orig/arch/nds32/mm/fault.h linux-3.4.113/arch/nds32/mm/fault.h
--- linux-3.4.113.orig/arch/nds32/mm/fault.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/mm/fault.h 2016-12-01 20:59:24.368613368 +0100
@@ -0,0 +1,5 @@
+void do_bad_area(unsigned long addr, unsigned int fsr, struct pt_regs *regs);
+
+void show_pte(struct mm_struct *mm, unsigned long addr);
+
+unsigned long search_exception_table(unsigned long addr);
diff -Nur linux-3.4.113.orig/arch/nds32/mm/highmem.c linux-3.4.113/arch/nds32/mm/highmem.c
--- linux-3.4.113.orig/arch/nds32/mm/highmem.c 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/mm/highmem.c 2016-12-01 20:59:24.368613368 +0100
@@ -0,0 +1,76 @@
+#include <linux/export.h>
+#include <linux/highmem.h>
+#include <linux/sched.h>
+#include <linux/smp.h>
+#include <linux/interrupt.h>
+#include <linux/bootmem.h>
+#include <asm/fixmap.h>
+#include <asm/tlbflush.h>
+
+void *kmap(struct page *page)
+{
+ unsigned long vaddr;
+ might_sleep();
+ if (!PageHighMem(page))
+ return page_address(page);
+ vaddr = (unsigned long)kmap_high(page);
+ return (void *)vaddr;
+}
+
+EXPORT_SYMBOL(kmap);
+
+void kunmap(struct page *page)
+{
+ BUG_ON(in_interrupt());
+ if (!PageHighMem(page))
+ return;
+ kunmap_high(page);
+}
+
+EXPORT_SYMBOL(kunmap);
+
+/*
+ * kmap_atomic/kunmap_atomic is significantly faster than kmap/kunmap because
+ * no global lock is needed and because the kmap code must perform a global TLB
+ * invalidation when the kmap pool wraps.
+ *
+ * However when holding an atomic kmap is is not legal to sleep, so atomic
+ * kmaps are appropriate for short, tight code paths only.
+ */
+void *kmap_atomic(struct page *page)
+{
+ unsigned int idx;
+ unsigned long vaddr, pte;
+ int type;
+
+ pagefault_disable();
+ if (!PageHighMem(page))
+ return page_address(page);
+
+ type = kmap_atomic_idx_push();
+
+ idx = type + KM_TYPE_NR * smp_processor_id();
+ vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
+ pte = (page_to_pfn(page) << PAGE_SHIFT) | (PAGE_KERNEL);
+ asm volatile ("mtsr %0, $TLB_VPN\n\t"
+ "dsb\n\t"
+ "tlbop %1, RWLK\n\t"
+ "isb\n\t"
+ ::"r" (vaddr), "r"(pte));
+ return (void *)vaddr;
+}
+
+EXPORT_SYMBOL(kmap_atomic);
+
+void __kunmap_atomic(void *kvaddr)
+{
+ if (kvaddr >= (void *)FIXADDR_START) {
+ kmap_atomic_idx_pop();
+ asm volatile ("tlbop %0, UNLK\n\t"
+ "tlbop %0, INV\n\t"
+ ::"r" (kvaddr));
+ }
+ pagefault_enable();
+}
+
+EXPORT_SYMBOL(__kunmap_atomic);
diff -Nur linux-3.4.113.orig/arch/nds32/mm/init.c linux-3.4.113/arch/nds32/mm/init.c
--- linux-3.4.113.orig/arch/nds32/mm/init.c 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/mm/init.c 2016-12-01 20:59:24.368613368 +0100
@@ -0,0 +1,438 @@
+/*
+ * linux/arch/nds32/mm/init.c
+ *
+ * Copyright (C) 1995-2002 Russell King
+ * Copyright (C) 2008 Andes Technology Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+#include <linux/kernel.h>
+#include <linux/errno.h>
+#include <linux/swap.h>
+#include <linux/init.h>
+#include <linux/bootmem.h>
+#include <linux/mman.h>
+#include <linux/nodemask.h>
+#include <linux/initrd.h>
+#include <linux/highmem.h>
+#include <linux/memblock.h>
+
+#include <asm/sections.h>
+#include <asm/mach-types.h>
+#include <asm/hardware.h>
+#include <asm/setup.h>
+#include <asm/tlb.h>
+#include <asm/page.h>
+
+#include <asm/mach/arch.h>
+#include <asm/mach/map.h>
+
+#include "mm.h"
+#include "../../kernel/signal.h"
+
+#define TABLE_SIZE (PTRS_PER_PTE * sizeof(pte_t))
+
+DEFINE_PER_CPU(struct mmu_gather, mmu_gathers);
+DEFINE_SPINLOCK(anon_alias_lock);
+extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
+extern unsigned long phys_initrd_start;
+extern unsigned long phys_initrd_size;
+
+/*
+ * empty_zero_page is a special page that is used for
+ * zero-initialized data and COW.
+ */
+struct page *empty_zero_page;
+
+void show_mem(unsigned int flags)
+{
+ int free = 0, total = 0, reserved = 0;
+ int shared = 0, cached = 0, slab = 0, node;
+
+ printk("Mem-info:\n");
+ show_free_areas(flags);
+ printk("Free swap: %6ldkB\n", nr_swap_pages << (PAGE_SHIFT - 10));
+
+ for_each_online_node(node) {
+ struct page *page, *end;
+
+ page = NODE_MEM_MAP(node);
+ end = page + NODE_DATA(node)->node_spanned_pages;
+
+ do {
+ total++;
+ if (PageReserved(page))
+ reserved++;
+ else if (PageSwapCache(page))
+ cached++;
+ else if (PageSlab(page))
+ slab++;
+ else if (!page_count(page))
+ free++;
+ else
+ shared += page_count(page) - 1;
+ page++;
+ } while (page < end);
+ }
+
+ printk("%d pages of RAM\n", total);
+ printk("%d free pages\n", free);
+ printk("%d reserved pages\n", reserved);
+ printk("%d slab pages\n", slab);
+ printk("%d pages shared\n", shared);
+ printk("%d pages swap cached\n", cached);
+}
+
+struct node_info {
+ unsigned int start;
+ unsigned int end;
+ int bootmap_pages;
+};
+
+#define O_PFN_DOWN(x) ((x) >> PAGE_SHIFT)
+#define V_PFN_DOWN(x) O_PFN_DOWN(__pa(x))
+
+#define O_PFN_UP(x) (PAGE_ALIGN(x) >> PAGE_SHIFT)
+#define V_PFN_UP(x) O_PFN_UP(__pa(x))
+
+#define PFN_SIZE(x) ((x) >> PAGE_SHIFT)
+#define PFN_RANGE(s,e) PFN_SIZE(PAGE_ALIGN((unsigned long)(e)) - \
+ (((unsigned long)(s)) & PAGE_MASK))
+#ifdef CONFIG_EARLY_PRINTK
+#include <asm/fixmap.h>
+
+/*
+ * Using tlbop to create an early I/O mapping
+ */
+void __iomem *__init early_io_map(phys_addr_t pa)
+{
+ unsigned long va;
+ pa &= PAGE_MASK;
+ pa += pgprot_val(PAGE_DEVICE);
+ va = fix_to_virt(FIX_EARLY_DEBUG);
+ /* insert and lock this page to tlb entry directly */
+ asm volatile ("mtsr %0, $TLB_VPN\n\t"
+ "dsb\n\t"
+ "tlbop %1, RWLK\n\t" "isb\n\t"::"r" (va), "r"(pa));
+ return (void __iomem *)va;
+}
+
+int __init early_io_unmap(void)
+{
+ unsigned long va;
+ va = fix_to_virt(FIX_EARLY_DEBUG);
+ asm volatile ("tlbop %0, UNLK\n\t"
+ "tlbop %0, INV\n\t" "isb\n\t"::"r" (va));
+ return 0;
+}
+
+late_initcall(early_io_unmap);
+#endif
+
+static void __init zone_sizes_init(void)
+{
+ unsigned long zones_size[MAX_NR_ZONES];
+
+ /* Clear the zone sizes */
+ memset(zones_size, 0, sizeof(zones_size));
+
+ zones_size[ZONE_NORMAL] = max_low_pfn;
+#ifdef CONFIG_HIGHMEM
+ zones_size[ZONE_HIGHMEM] = max_pfn;
+#endif
+ free_area_init_nodes(zones_size);
+
+}
+
+/*
+ * Map all physical memory under high_memory into kernel's address space.
+ *
+ * This is explicitly coded for two-level page tables, so if you need
+ * something else then this needs to change.
+ */
+static void __init map_ram(void)
+{
+ unsigned long v, p, e;
+ pgd_t *pge;
+ pud_t *pue;
+ pmd_t *pme;
+ pte_t *pte;
+ /* These mark extents of read-only kernel pages...
+ * ...from vmlinux.lds.S
+ */
+
+ p = (u32) memblock_start_of_DRAM() & PAGE_MASK;
+ e = min((u32) memblock_end_of_DRAM(), (u32) __pa(high_memory));
+
+ v = (u32) __va(p);
+ pge = pgd_offset_k(v);
+
+ while (p < e) {
+ int j;
+ pue = pud_offset(pge, v);
+ pme = pmd_offset(pue, v);
+
+ if ((u32) pue != (u32) pge || (u32) pme != (u32) pge) {
+ panic("%s: Kernel hardcoded for "
+ "two-level page tables", __func__);
+ }
+
+ /* Alloc one page for holding PTE's... */
+ pte = (pte_t *) alloc_bootmem_low_pages(PAGE_SIZE);
+ set_pmd(pme, __pmd(__pa(pte) + _PAGE_KERNEL_TABLE));
+
+ /* Fill the newly allocated page with PTE'S */
+ for (j = 0; p < e && j < PTRS_PER_PTE;
+ v += PAGE_SIZE, p += PAGE_SIZE, j++, pte++) {
+ /* Create mapping between p and v. */
+ /* TODO: more fine grant for page access permission */
+ set_pte(pte, __pte(p + pgprot_val(PAGE_KERNEL)));
+ }
+
+ pge++;
+ }
+}
+
+static void __init fixedrange_init(void)
+{
+ unsigned long vaddr, phys, prot;
+ pgd_t *pgd;
+ pud_t *pud;
+ pmd_t *pmd;
+ pte_t *pte;
+
+ /*
+ * Fixed mappings:
+ */
+ vaddr = __fix_to_virt(__end_of_fixed_addresses - 1);
+ pgd = swapper_pg_dir + pgd_index(vaddr);
+ pud = pud_offset(pgd, vaddr);
+ pmd = pmd_offset(pud, vaddr);
+ pte = (pte_t *) alloc_bootmem_low_pages(PAGE_SIZE);
+ set_pmd(pmd, __pmd(__pa(pte) + _PAGE_KERNEL_TABLE));
+
+ /* create return_syscall mapping. */
+ vaddr = __fix_to_virt(FIX_RETURN_SYSCALL);
+ phys = RETURN_SYSCALL_PA_BASE;
+ prot = PAGE_UXKRWX_V2;
+ pte = pte_offset_kernel(pmd, vaddr);
+ set_pte(pte, pfn_pte(phys >> PAGE_SHIFT, prot));
+
+#ifdef CONFIG_HIGHMEM
+ /*
+ * Permanent kmaps:
+ */
+ vaddr = PKMAP_BASE;
+
+ pgd = swapper_pg_dir + pgd_index(vaddr);
+ pud = pud_offset(pgd, vaddr);
+ pmd = pmd_offset(pud, vaddr);
+ pte = (pte_t *) alloc_bootmem_low_pages(PAGE_SIZE);
+ set_pmd(pmd, __pmd(__pa(pte) + _PAGE_KERNEL_TABLE));
+ pkmap_page_table = pte;
+#endif /* CONFIG_HIGHMEM */
+}
+
+/*
+ * paging_init() sets up the page tables, initialises the zone memory
+ * maps, and sets up the zero page, bad page and bad page tables.
+ */
+void __init paging_init(struct machine_desc *mdesc)
+{
+ void *zero_page;
+ int i;
+
+ printk(KERN_INFO "Setting up paging and PTEs.\n");
+
+#ifdef CONFIG_BLK_DEV_INITRD
+ if (phys_initrd_size) {
+ /* assume initrd is put on node 0 */
+ reserve_bootmem_node(NODE_DATA(0), phys_initrd_start,
+ phys_initrd_size, BOOTMEM_DEFAULT);
+ initrd_start = __phys_to_virt(phys_initrd_start);
+ initrd_end = initrd_start + phys_initrd_size;
+ printk(KERN_INFO
+ "initrd_start at 0x%08lx, initrd_end at 0x%08lx\n",
+ initrd_start, initrd_end);
+ }
+#endif
+
+ /* clear out the init_mm.pgd that will contain the kernel's mappings */
+ for (i = 0; i < PTRS_PER_PGD; i++)
+ swapper_pg_dir[i] = __pgd(1);
+
+ map_ram();
+
+ if (mdesc->map_io)
+ mdesc->map_io();
+
+ fixedrange_init();
+
+ /* allocate space for empty_zero_page */
+ zero_page = alloc_bootmem_low_pages(PAGE_SIZE);
+ memset(zero_page, 0, PAGE_SIZE);
+
+ zone_sizes_init();
+
+ empty_zero_page = virt_to_page(zero_page);
+#ifdef CONFIG_NO_KERNEL_LARGE_PAGE
+ SET_MMU_CTL(GET_MMU_CTL() & ~0x400);
+#endif
+#ifdef CONFIG_SMP
+ cpu_dcache_wbinval_all();
+#endif
+ flush_dcache_page(empty_zero_page);
+}
+
+static inline int free_area(unsigned long addr, unsigned long end, char *s)
+{
+ unsigned int size = (end - addr) >> 10;
+ int pages = 0;
+
+ for (; addr < end; addr += PAGE_SIZE) {
+ struct page *page = virt_to_page(addr);
+ ClearPageReserved(page);
+ init_page_count(page);
+ free_page(addr);
+ totalram_pages++;
+ pages++;
+ }
+
+ if (size && s)
+ printk(KERN_INFO "free_area: Freeing %s memory: %dK\n", s,
+ size);
+
+ return pages;
+}
+
+/* Free the reserved page into the buddy system, so it gets managed. */
+static inline void __free_reserved_page(struct page *page)
+{
+ ClearPageReserved(page);
+ init_page_count(page);
+ __free_page(page);
+}
+
+#ifdef CONFIG_HIGHMEM
+void free_highmem_page(struct page *page)
+{
+ __free_reserved_page(page);
+ totalram_pages++;
+ totalhigh_pages++;
+}
+#endif
+
+static inline void __init free_highmem(void)
+{
+#ifdef CONFIG_HIGHMEM
+ unsigned long pfn;
+ for (pfn = PFN_UP(__pa(high_memory)); pfn < max_pfn; pfn++) {
+ phys_addr_t paddr = (phys_addr_t) pfn << PAGE_SHIFT;
+ if (!memblock_is_reserved(paddr))
+ free_highmem_page(pfn_to_page(pfn));
+ }
+#endif
+}
+
+static void __init set_max_mapnr_init(void)
+{
+ max_mapnr = max_pfn;
+}
+
+/*
+ * mem_init() marks the free areas in the mem_map and tells us how much
+ * memory is free. This is done after various parts of the system have
+ * claimed their memory after the kernel image.
+ */
+void __init mem_init(void)
+{
+ phys_addr_t memory_start = memblock_start_of_DRAM();
+ BUG_ON(!mem_map);
+ set_max_mapnr_init();
+
+ free_highmem();
+
+ /* this will put all low memory onto the freelists */
+ totalram_pages += free_all_bootmem();
+
+ printk(KERN_INFO "virtual kernel memory layout:\n"
+ " fixmap : 0x%08lx - 0x%08lx (%4ld kB)\n"
+#ifdef CONFIG_HIGHMEM
+ " pkmap : 0x%08lx - 0x%08lx (%4ld kB)\n"
+#endif
+ " consist : 0x%08lx - 0x%08lx (%4ld MB)\n"
+ " vmalloc : 0x%08lx - 0x%08lx (%4ld MB)\n"
+ " lowmem : 0x%08lx - 0x%08lx (%4ld MB)\n"
+ " .init : 0x%08lx - 0x%08lx (%4ld kB)\n"
+ " .data : 0x%08lx - 0x%08lx (%4ld kB)\n"
+ " .text : 0x%08lx - 0x%08lx (%4ld kB)\n",
+ FIXADDR_START, FIXADDR_TOP, (FIXADDR_TOP - FIXADDR_START) >> 10,
+#ifdef CONFIG_HIGHMEM
+ PKMAP_BASE, PKMAP_BASE + LAST_PKMAP * PAGE_SIZE,
+ (LAST_PKMAP * PAGE_SIZE) >> 10,
+#endif
+ CONSISTENT_BASE, CONSISTENT_END,
+ ((CONSISTENT_END) - (CONSISTENT_BASE)) >> 20, VMALLOC_START,
+ (unsigned long)VMALLOC_END, (VMALLOC_END - VMALLOC_START) >> 20,
+ (unsigned long)__va(memory_start), (unsigned long)high_memory,
+ ((unsigned long)high_memory -
+ (unsigned long)__va(memory_start)) >> 20,
+ (unsigned long)&__init_begin, (unsigned long)&__init_end,
+ ((unsigned long)&__init_end -
+ (unsigned long)&__init_begin) >> 10, (unsigned long)&_etext,
+ (unsigned long)&_edata,
+ ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
+ (unsigned long)&_text, (unsigned long)&_etext,
+ ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
+
+ /*
+ * Check boundaries twice: Some fundamental inconsistencies can
+ * be detected at build time already.
+ */
+#define __FIXADDR_TOP (-PAGE_SIZE)
+#ifdef CONFIG_HIGHMEM
+ BUILD_BUG_ON(PKMAP_BASE + LAST_PKMAP * PAGE_SIZE > FIXADDR_START);
+ BUILD_BUG_ON((CONSISTENT_END) > PKMAP_BASE);
+#endif
+ BUILD_BUG_ON(VMALLOC_END > CONSISTENT_BASE);
+#define high_memory (-128UL << 20)
+ BUILD_BUG_ON(VMALLOC_START >= VMALLOC_END);
+#undef high_memory
+#undef __FIXADDR_TOP
+
+#ifdef CONFIG_HIGHMEM
+ BUG_ON(PKMAP_BASE + LAST_PKMAP * PAGE_SIZE > FIXADDR_START);
+ BUG_ON(CONSISTENT_END > PKMAP_BASE);
+#endif
+ BUG_ON(VMALLOC_END > CONSISTENT_BASE);
+ BUG_ON(VMALLOC_START >= VMALLOC_END);
+ BUG_ON((unsigned long)high_memory > VMALLOC_START);
+
+ return;
+}
+
+void free_initmem(void)
+{
+ free_area((unsigned long)(&__init_begin),
+ (unsigned long)(&__init_end), "init");
+}
+
+#ifdef CONFIG_BLK_DEV_INITRD
+static int keep_initrd;
+
+void free_initrd_mem(unsigned long start, unsigned long end)
+{
+ if (!keep_initrd)
+ free_area(start, end, "initrd");
+}
+
+static int __init keepinitrd_setup(char *__unused)
+{
+ keep_initrd = 1;
+ return 1;
+}
+
+__setup("keepinitrd", keepinitrd_setup);
+#endif
diff -Nur linux-3.4.113.orig/arch/nds32/mm/ioremap.c linux-3.4.113/arch/nds32/mm/ioremap.c
--- linux-3.4.113.orig/arch/nds32/mm/ioremap.c 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/mm/ioremap.c 2016-12-01 20:59:24.368613368 +0100
@@ -0,0 +1,89 @@
+/*
+ * linux/arch/nds32/mm/ioremap.c
+ *
+ * Re-map IO memory to kernel address space so that we can access it.
+ *
+ * (C) Copyright 1995 1996 Linus Torvalds
+ * Copyright (C) 2009 Andes Technology Corporation
+ *
+ * Hacked for ARM by Phil Blundell <philb@gnu.org>
+ * Hacked to allow all architectures to build, and various cleanups
+ * by Russell King
+ *
+ * This allows a driver to remap an arbitrary region of bus memory into
+ * virtual space. One should *only* use readl, writel, memcpy_toio and
+ * so on with such remapped areas.
+ *
+ * Because the ARM only has a 32-bit address space we can't address the
+ * whole of the (physical) PCI space at once. PCI huge-mode addressing
+ * allows us to circumvent this restriction by splitting PCI space into
+ * two 2GB chunks and mapping only one at a time into processor memory.
+ * We use MMU protection domains to trap any attempt to access the bank
+ * that is not currently mapped. (This isn't fully implemented yet.)
+ */
+#include <linux/module.h>
+#include <linux/vmalloc.h>
+#include <linux/io.h>
+#include <asm/cacheflush.h>
+
+/*
+ * Remap an arbitrary physical address space into the kernel virtual
+ * address space. Needed when the kernel wants to access high addresses
+ * directly.
+ *
+ * NOTE! We need to allow non-page-aligned mappings too: we will obviously
+ * have to convert them into an offset in a page-aligned mapping, but the
+ * caller shouldn't need to know that small detail.
+ *
+ * 'flags' are the extra L_PTE_ flags that you want to specify for this
+ * mapping. See include/asm-arm/proc-armv/pgtable.h for more information.
+ */
+void __iomem *__ioremap(unsigned long phys_addr, size_t size,
+ unsigned long flags, unsigned long align)
+{
+ struct vm_struct *area;
+ unsigned long addr, offset, last_addr;
+ pgprot_t prot;
+
+ /* Don't allow wraparound or zero size */
+ last_addr = phys_addr + size - 1;
+ if (!size || last_addr < phys_addr)
+ return NULL;
+
+ /*
+ * Mappings have to be page-aligned
+ */
+ offset = phys_addr & ~PAGE_MASK;
+ phys_addr &= PAGE_MASK;
+ size = PAGE_ALIGN(last_addr + 1) - phys_addr;
+
+ /*
+ * Ok, go for it..
+ */
+ area = get_vm_area(size, VM_IOREMAP);
+ if (!area)
+ return NULL;
+
+ area->phys_addr = phys_addr;
+ addr = (unsigned long)area->addr;
+ /* TODO: verify this value for ioremap */
+ prot = __pgprot(_PAGE_V | _PAGE_M_KRW | _PAGE_D |
+ _PAGE_G | _PAGE_C_DEV | flags);
+ /* TODO: verify this use generic ioremap_page_range instead of
+ * self's remap_area_pages */
+ if (ioremap_page_range(addr, addr + size, phys_addr, prot)) {
+ vunmap((void *)addr);
+ return NULL;
+ }
+ return (__force void __iomem *)(offset + (char *)addr);
+
+}
+
+EXPORT_SYMBOL(__ioremap);
+
+void __iounmap(void __iomem * addr)
+{
+ vunmap((void *)(PAGE_MASK & (unsigned long)addr));
+}
+
+EXPORT_SYMBOL(__iounmap);
diff -Nur linux-3.4.113.orig/arch/nds32/mm/Makefile linux-3.4.113/arch/nds32/mm/Makefile
--- linux-3.4.113.orig/arch/nds32/mm/Makefile 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/mm/Makefile 2016-12-01 20:59:24.368613368 +0100
@@ -0,0 +1,24 @@
+#
+# Makefile for the linux arm-specific parts of the memory manager.
+#
+
+obj-y := consistent.o extable.o \
+ fault.o init.o ioremap.o mmap.o \
+ mm-nds32.o cacheflush.o
+
+obj-y += proc-n12.o
+obj-$(CONFIG_CCTL) += cctl.o
+obj-$(CONFIG_ALIGNMENT_TRAP) += alignment.o
+ifneq ($(CONFIG_CPU_NO_CONTEXT_ID), y)
+obj-y += tlb.o
+endif
+gcc_ver :=$(shell $(CC) -E -dM -xc /dev/null | grep __VERSION__ | sed 's/\#define __VERSION__ //')
+ifeq ($(shell expr `echo $(gcc_ver)` \>= 4.9.2 ), 1)
+CFLAGS_proc-n12.o += -fomit-frame-pointer
+else
+CFLAGS_proc-n12.o += -fomit-frame-pointer -mno-16bit
+endif
+obj-$(CONFIG_HIGHMEM) += highmem.o
+ifdef CONFIG_FUNCTION_TRACER
+CFLAGS_REMOVE_proc-n12.o = -pg
+endif
diff -Nur linux-3.4.113.orig/arch/nds32/mm/mmap.c linux-3.4.113/arch/nds32/mm/mmap.c
--- linux-3.4.113.orig/arch/nds32/mm/mmap.c 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/mm/mmap.c 2016-12-01 20:59:24.368613368 +0100
@@ -0,0 +1,101 @@
+/*
+ * linux/arch/nds32/mm/mmap.c
+ *
+ * Copyright (C) 2009 Andes Technology Corporation
+ */
+#include <linux/sched.h>
+#include <linux/mman.h>
+#include <linux/shm.h>
+
+#define COLOUR_ALIGN(addr,pgoff) \
+ ((((addr)+REALSHMLBA-1)&~(REALSHMLBA-1)) + \
+ (((pgoff)<<PAGE_SHIFT) & (REALSHMLBA-1)))
+
+/*
+ * We need to ensure that shared mappings are correctly aligned to
+ * avoid aliasing issues with VIPT caches. We need to ensure that
+ * a specific page of an object is always mapped at a multiple of
+ * SHMLBA bytes.
+ *
+ * We unconditionally provide this function for all cases, however
+ * in the VIVT case, we optimise out the alignment rules.
+ */
+unsigned long
+arch_get_unmapped_area(struct file *filp, unsigned long addr,
+ unsigned long len, unsigned long pgoff,
+ unsigned long flags)
+{
+ struct mm_struct *mm = current->mm;
+ struct vm_area_struct *vma;
+ unsigned long start_addr;
+ int do_align = 0;
+#ifdef CONFIG_CPU_CACHE_NONALIASING
+ int aliasing = 0;
+#else
+ int aliasing = 1;
+#endif
+
+ /*
+ * We only need to do colour alignment if either the I or D
+ * caches alias.
+ */
+ if (aliasing)
+ do_align = filp || (flags & MAP_SHARED);
+
+ /*
+ * We should enforce the MAP_FIXED case. However, currently
+ * the generic kernel code doesn't allow us to handle this.
+ */
+ if (flags & MAP_FIXED) {
+ if (aliasing && flags & MAP_SHARED && addr & (REALSHMLBA - 1))
+ return -EINVAL;
+ return addr;
+ }
+
+ if (len > TASK_SIZE)
+ return -ENOMEM;
+
+ if (addr) {
+ if (do_align)
+ addr = COLOUR_ALIGN(addr, pgoff);
+ else
+ addr = PAGE_ALIGN(addr);
+
+ vma = find_vma(mm, addr);
+ if (TASK_SIZE - len >= addr &&
+ (!vma || addr + len <= vma->vm_start))
+ return addr;
+ }
+ start_addr = addr = mm->free_area_cache;
+
+full_search:
+ if (do_align)
+ addr = COLOUR_ALIGN(addr, pgoff);
+ else
+ addr = PAGE_ALIGN(addr);
+
+ for (vma = find_vma(mm, addr);; vma = vma->vm_next) {
+ /* At this point: (!vma || addr < vma->vm_end). */
+ if (TASK_SIZE - len < addr) {
+ /*
+ * Start a new search - just in case we missed
+ * some holes.
+ */
+ if (start_addr != TASK_UNMAPPED_BASE) {
+ start_addr = addr = TASK_UNMAPPED_BASE;
+ goto full_search;
+ }
+ return -ENOMEM;
+ }
+ if (!vma || addr + len <= vma->vm_start) {
+ /*
+ * Remember the place where we stopped the search:
+ */
+ mm->free_area_cache = addr + len;
+ return addr;
+ }
+ addr = vma->vm_end;
+ if (do_align)
+ addr = COLOUR_ALIGN(addr, pgoff);
+ }
+}
diff -Nur linux-3.4.113.orig/arch/nds32/mm/mm.h linux-3.4.113/arch/nds32/mm/mm.h
--- linux-3.4.113.orig/arch/nds32/mm/mm.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/mm/mm.h 2016-12-01 20:59:24.372613522 +0100
@@ -0,0 +1,19 @@
+/* the upper-most page table pointer */
+
+#ifdef CONFIG_MMU
+
+extern pmd_t *top_pmd;
+
+#define TOP_PTE(x) pte_offset_kernel(top_pmd, x)
+
+static inline pmd_t *pmd_off(pgd_t *pgd, unsigned long virt)
+{
+ return pmd_offset(pgd, virt);
+}
+
+static inline pmd_t *pmd_off_k(unsigned long virt)
+{
+ return pmd_off(pgd_offset_k(virt), virt);
+}
+
+#endif
diff -Nur linux-3.4.113.orig/arch/nds32/mm/mm-nds32.c linux-3.4.113/arch/nds32/mm/mm-nds32.c
--- linux-3.4.113.orig/arch/nds32/mm/mm-nds32.c 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/mm/mm-nds32.c 2016-12-01 20:59:24.372613522 +0100
@@ -0,0 +1,267 @@
+/*
+ * linux/arch/nds32/mm/mm-nds32.c
+ *
+ * Copyright (C) 1998-2002 Russell King
+ * Copyright (C) 2009 Andes Technology Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Page table sludge for Andes N10/N12 processor architectures.
+ */
+#include <linux/module.h>
+#include <linux/mm.h>
+#include <linux/bootmem.h>
+#include <linux/init_task.h>
+
+#include <asm/pgalloc.h>
+#include <asm/pgtable.h>
+#include <asm/setup.h>
+#include <asm/fixmap.h>
+
+#include <asm/mach/map.h>
+#include "./../kernel/signal.h"
+
+extern void _text, _stext, _etext;
+extern void *high_memory;
+
+#define FIRST_KERNEL_PGD_NR (USER_PTRS_PER_PGD)
+
+/*
+ * need to get a 4k page for level 1
+ */
+
+pgd_t *get_pgd_slow(struct mm_struct *mm)
+{
+ pgd_t *new_pgd, *init_pgd;
+ int i;
+
+ new_pgd = (pgd_t *) __get_free_pages(GFP_KERNEL, 0); //M order 0: one page
+ if (!new_pgd)
+ return NULL;
+ for (i = 0; i < PTRS_PER_PGD; i++) {
+ (*new_pgd) = 1;
+ new_pgd++;
+ }
+ new_pgd -= PTRS_PER_PGD;
+
+ init_pgd = pgd_offset_k(0);
+
+ memcpy(new_pgd + FIRST_KERNEL_PGD_NR, init_pgd + FIRST_KERNEL_PGD_NR,
+ (PTRS_PER_PGD - FIRST_KERNEL_PGD_NR) * sizeof(pgd_t));
+
+ cpu_dcache_wb_range((unsigned long)new_pgd,
+ (unsigned long)new_pgd +
+ PTRS_PER_PGD * sizeof(pgd_t));
+ inc_zone_page_state(virt_to_page((unsigned long *)new_pgd),
+ NR_PAGETABLE);
+
+ return new_pgd;
+}
+
+void free_pgd_slow(struct mm_struct *mm, pgd_t * pgd)
+{
+ pmd_t *pmd;
+ struct page *pte;
+
+ if (!pgd)
+ return;
+
+ pmd = (pmd_t *) pgd;
+ if (pmd_none(*pmd))
+ goto free;
+ if (pmd_bad(*pmd)) {
+ pmd_ERROR(*pmd);
+ pmd_clear(pmd);
+ goto free;
+ }
+
+ pte = pmd_page(*pmd);
+ pmd_clear(pmd);
+ dec_zone_page_state(virt_to_page((unsigned long *)pgd), NR_PAGETABLE);
+ pte_free(mm, pte);
+ pmd_free(mm, pmd);
+free:
+ free_pages((unsigned long)pgd, 0);
+}
+
+/*
+ * Add a PAGE mapping between VIRT and PHYS in domain
+ * DOMAIN with protection PROT. Note that due to the
+ * way we map the PTEs, we must allocate two PTE_SIZE'd
+ * blocks - one for the Linux pte table, and one for
+ * the hardware pte table.
+ */
+static inline void
+alloc_init_page(unsigned long virt, unsigned long phys, unsigned int prot_l1,
+ pgprot_t prot)
+{
+ pmd_t *pmdp;
+ pte_t *ptep;
+
+ pmdp = pmd_offset(pgd_offset_k(virt), virt); //L1PTE
+ if (pmd_none(*pmdp)) { //must not or 0xc0000000
+ ptep = alloc_bootmem_low_pages(PTRS_PER_PTE * sizeof(pte_t));
+ set_pmd(pmdp, __mk_pmd(ptep, 0));
+ }
+ ptep = pte_offset_kernel(pmdp, virt); //L2PTE
+ set_pte(ptep, pfn_pte(phys >> PAGE_SHIFT, prot));
+}
+
+/*
+ * Clear any PGD mapping. On a two-level page table system,
+ * the clearance is done by the middle-level functions (pmd)
+ * rather than the top-level (pgd) functions.
+ */
+static inline void clear_mapping(unsigned long virt)
+{
+ pmd_clear(pmd_offset(pgd_offset_k(virt), virt));
+}
+
+struct mem_types {
+ unsigned int prot_pte;
+ unsigned int prot_l1;
+};
+
+static struct mem_types mem_types[] __initdata = {
+ [MT_DEVICE] = {
+ .prot_pte = 0x9f, //_KERNPG_TABLE,
+ .prot_l1 = PMD_TYPE_TABLE,
+ },
+ [MT_CACHECLEAN] = {
+ .prot_l1 = PMD_TYPE_TABLE,
+ .prot_pte = 0x0, //_KERNPG_TABLE,
+ },
+ [MT_MINICLEAN] = {
+ .prot_l1 = PMD_TYPE_TABLE,
+ .prot_pte = 0x0, // _KERNPG_TABLE,
+ },
+ [MT_CACHE_L1] = {
+ .prot_pte = PAGE_CACHE_L1,
+ .prot_l1 = PMD_TYPE_TABLE,
+ },
+ [MT_UXKRWX_V1] = {
+ .prot_pte = PAGE_UXKRWX_V1,
+ .prot_l1 = PMD_TYPE_TABLE,
+ },
+ [MT_UXKRWX_V2] = {
+ .prot_pte = PAGE_UXKRWX_V2,
+ .prot_l1 = PMD_TYPE_TABLE,
+ },
+ [MT_MEMORY] = {
+ .prot_pte = PAGE_MEMORY,
+ .prot_l1 = PMD_TYPE_TABLE,
+ },
+ [MT_ROM] = {
+ .prot_l1 = PMD_TYPE_TABLE,
+ .prot_pte = 0x2bb, // _KERNPG_TABLE,
+ },
+ [MT_ILM] = {
+ .prot_l1 = PMD_TYPE_TABLE,
+ .prot_pte = 0x2b7, // _KERNPG_TABLE,
+ },
+ [MT_DLM] = {
+ .prot_l1 = PMD_TYPE_TABLE,
+ .prot_pte = 0x297, // _KERNPG_TABLE,
+ }
+};
+
+/*
+ * Create the page directory entries and any necessary
+ * page tables for the mapping specified by `md'. We
+ * are able to cope here with varying sizes and address
+ * offsets, and we take full advantage of sections.
+ */
+static void __init create_mapping(struct map_desc *md)
+{
+ unsigned long virt, length;
+ int prot_l1;
+ pgprot_t prot_pte;
+ long off;
+
+ printk("virt:0x%08lx,phys:%08lx,size:%08lx,pte:%08x\n",
+ md->virtual, md->physical, md->length,
+ __pgprot(mem_types[md->type].prot_pte));
+
+ if (md->virtual < TASK_SIZE) {
+ printk(KERN_WARNING "BUG: not creating mapping area for "
+ "0x%08lx at 0x%08lx in user region, next frame\n",
+ md->physical, md->virtual);
+ panic("In :%s, line:%d", __func__, __LINE__);
+ return;
+ }
+
+ if ((md->type == MT_DEVICE || md->type == MT_ROM) &&
+ md->virtual >= PAGE_OFFSET && md->virtual < VMALLOC_END) {
+ printk(KERN_WARNING "BUG: mapping area for 0x%08lx at 0x%08lx "
+ "overlaps vmalloc space, next frame\n",
+ md->physical, md->virtual);
+ panic("In :%s, line:%d", __func__, __LINE__);
+ }
+
+ prot_pte = __pgprot(mem_types[md->type].prot_pte);
+ prot_l1 = mem_types[md->type].prot_l1;
+ virt = md->virtual;
+ off = md->physical - virt;
+
+ length = md->length;
+ if (mem_types[md->type].prot_l1 == 1 &&
+ (virt & 0xfffff || (virt + off) & 0xfffff
+ || (virt + length) & 0xfffff)) {
+ printk(KERN_WARNING
+ "BUG: map area for 0x%08lx at 0x%08lx can not "
+ "be mapped using pages, ignoring. next frame\n",
+ md->physical, md->virtual);
+ panic("In :%s, line:%d", __func__, __LINE__);
+ return;
+ }
+
+ while (length >= PAGE_SIZE) {
+#ifdef CONFIG_SMP
+ if (((virt >= (unsigned long)&_text)
+ && (virt < (unsigned long)&_etext))
+ || ((virt >= 0xc0000000) && (virt < 0xc0008000)))
+ prot_pte = __pgprot(mem_types[MT_CACHE_L1].prot_pte);
+#endif
+ alloc_init_page(virt, virt + off, prot_l1, prot_pte);
+ virt += PAGE_SIZE;
+ length -= PAGE_SIZE;
+ }
+}
+
+/*
+ * In order to soft-boot, we need to insert a 1:1 mapping in place of
+ * the user-mode pages. This will then ensure that we have predictable
+ * results when turning the mmu off
+ */
+void setup_mm_for_reboot(char mode)
+{
+ unsigned long pmdval;
+ pgd_t *pgd;
+ pmd_t *pmd;
+ int i;
+
+ if (current->mm && current->mm->pgd)
+ pgd = current->mm->pgd;
+ else
+ pgd = init_mm.pgd;
+
+ for (i = 0; i < USER_PTRS_PER_PGD; i++) {
+ pmdval = (i << PGDIR_SHIFT);
+ pmd = pmd_offset(pgd + i, i << PGDIR_SHIFT);
+ set_pmd(pmd, __pmd(pmdval));
+ }
+}
+
+/*
+ * Create the architecture specific mappings
+ */
+void __init iotable_init(struct map_desc *io_desc, int nr)
+{
+ int i;
+
+ for (i = 0; i < nr; i++) {
+ create_mapping(io_desc + i);
+ }
+}
diff -Nur linux-3.4.113.orig/arch/nds32/mm/proc-n12.c linux-3.4.113/arch/nds32/mm/proc-n12.c
--- linux-3.4.113.orig/arch/nds32/mm/proc-n12.c 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/mm/proc-n12.c 2016-12-01 20:59:24.372613522 +0100
@@ -0,0 +1,845 @@
+/*
+ * linux/arch/nds32/mm/proc-nds32.c
+ *
+ * Copyright (C) 2006 Andes Technology Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ *
+ * These are the low level assembler for performing cache and TLB
+ * functions on the nds32.
+ *
+ */
+#include <linux/module.h>
+#include <linux/sched.h>
+#include <linux/mm.h>
+#include <asm/nds32.h>
+#include <asm/pgtable.h>
+#include <asm/tlbflush.h>
+#include <asm/cacheflush.h>
+#ifdef CONFIG_CACHE_L2
+#include <asm/l2_cache.h>
+#endif
+#include <nds32_intrinsic.h>
+
+#include <asm/cache_info.h>
+extern struct cache_info L1_cache_info[2];
+
+#ifdef CONFIG_CACHE_L2
+void n12_L2cache_inval(void)
+{
+ unsigned long cmd = CCTL_CMD_L2_IX_INVAL | CCTL_ALL_CMD;
+
+ L2_CMD_RDY();
+ L2C_W_REG(L2_CCTL_CMD_OFF, cmd);
+ L2_CMD_RDY();
+ L2C_W_REG(L2_CCTL_CMD_OFF, CCTL_CMD_L2_SYNC);
+ L2_CMD_RDY();
+}
+
+void n12_L2cache_wb(void)
+{
+ unsigned long cmd = CCTL_CMD_L2_IX_WB | CCTL_ALL_CMD;
+
+ L2_CMD_RDY();
+ L2C_W_REG(L2_CCTL_CMD_OFF, cmd);
+ L2_CMD_RDY();
+ L2C_W_REG(L2_CCTL_CMD_OFF, CCTL_CMD_L2_SYNC);
+ L2_CMD_RDY();
+}
+#endif
+
+int va_kernel_present(unsigned long addr)
+{
+ pmd_t *pmd;
+ pte_t *ptep, pte;
+ int ret = 0;
+
+ pmd = pmd_offset(pgd_offset_k(addr), addr);
+ if (!pmd_none(*pmd)) {
+ ptep = pte_offset_map(pmd, addr);
+ pte = *ptep;
+ if (pte_present(pte))
+ ret = 1;
+ }
+ return ret;
+}
+
+int va_present(struct mm_struct *mm, unsigned long addr)
+{
+ pgd_t *pgd;
+ pud_t *pud;
+ pmd_t *pmd;
+ pte_t *ptep, pte;
+ int ret = 0;
+
+ pgd = pgd_offset(mm, addr);
+ if (!pgd_none(*pgd)) {
+ pud = pud_offset(pgd, addr);
+ if (!pud_none(*pud)) {
+ pmd = pmd_offset(pud, addr);
+ if (!pmd_none(*pmd)) {
+ ptep = pte_offset_map(pmd, addr);
+ pte = *ptep;
+ if (pte_present(pte))
+ ret = 1;
+ }
+ }
+ }
+ return ret;
+
+}
+
+int va_readable(struct pt_regs *regs, unsigned long addr)
+{
+ struct mm_struct *mm = current->mm;
+ pgd_t *pgd;
+ pud_t *pud;
+ pmd_t *pmd;
+ pte_t *ptep, pte;
+ int ret = 0;
+
+ if (user_mode(regs)) {
+ /* user mode */
+ pgd = pgd_offset(mm, addr);
+ if (!pgd_none(*pgd)) {
+ pud = pud_offset(pgd, addr);
+ if (!pud_none(*pud)) {
+ pmd = pmd_offset(pud, addr);
+ if (!pmd_none(*pmd)) {
+ ptep = pte_offset_map(pmd, addr);
+ pte = *ptep;
+ if (pte_present(pte) && pte_read(pte))
+ ret = 1;
+ }
+ }
+ }
+ } else {
+ /* superuser mode is always readable, so we can only
+ * check it is present or not*/
+ pmd = pmd_offset(pgd_offset_k(addr), addr);
+ if (!pmd_none(*pmd)) {
+ ptep = pte_offset_map(pmd, addr);
+ pte = *ptep;
+ if (pte_present(pte))
+ ret = 1;
+ }
+ }
+ return ret;
+}
+
+int va_writable(struct pt_regs *regs, unsigned long addr)
+{
+ struct mm_struct *mm = current->mm;
+ pgd_t *pgd;
+ pud_t *pud;
+ pmd_t *pmd;
+ pte_t *ptep, pte;
+ int ret = 0;
+
+ if (user_mode(regs)) {
+ /* user mode */
+ pgd = pgd_offset(mm, addr);
+ if (!pgd_none(*pgd)) {
+ pud = pud_offset(pgd, addr);
+ if (!pud_none(*pud)) {
+ pmd = pmd_offset(pud, addr);
+ if (!pmd_none(*pmd)) {
+ ptep = pte_offset_map(pmd, addr);
+ pte = *ptep;
+ if (pte_present(pte) && pte_write(pte))
+ ret = 1;
+ }
+ }
+ }
+ } else {
+ /* superuser mode */
+ pmd = pmd_offset(pgd_offset_k(addr), addr);
+ if (!pmd_none(*pmd)) {
+ ptep = pte_offset_map(pmd, addr);
+ pte = *ptep;
+ if (pte_present(pte) && pte_kernel_write(pte))
+ ret = 1;
+ }
+ }
+ return ret;
+}
+
+#if 0
+static inline void flush_fill_buffer(void)
+{
+ unsigned long kaddr, pte, flags;
+
+ local_irq_save(flags);
+#define BASE_ADDR2 0xffff4000
+ kaddr = BASE_ADDR2;
+ pte = (0x6000 | _PAGE_V | _PAGE_M_KRW | _PAGE_G | _PAGE_C_DEV);
+ asm("tlbop %0, INV\nisb\n"::"r"(kaddr));
+ asm("mtsr %1, $mr2\ndsb\n"
+ "tlbop %0, RWR\nisb\n"::"r"(pte), "r"(kaddr));
+asm("lmw.bi $r0, [%0], $r1\n"::"r"(kaddr):"$r0", "$r1");
+ local_irq_restore(flags);
+}
+#else
+static inline void flush_fill_buffer(void)
+{
+}
+#endif
+
+/*
+ * All
+ */
+void n12_icache_inval_all(void)
+{
+ unsigned long end, line_size;
+
+ line_size = L1_cache_info[ICACHE].line_size;
+ end =
+ line_size * L1_cache_info[ICACHE].ways * L1_cache_info[ICACHE].sets;
+
+ do {
+ end -= line_size;
+ __asm__ volatile ("\n\tcctl %0, L1I_IX_INVAL"::"r" (end));
+ end -= line_size;
+ __asm__ volatile ("\n\tcctl %0, L1I_IX_INVAL"::"r" (end));
+ end -= line_size;
+ __asm__ volatile ("\n\tcctl %0, L1I_IX_INVAL"::"r" (end));
+ end -= line_size;
+ __asm__ volatile ("\n\tcctl %0, L1I_IX_INVAL"::"r" (end));
+ } while (end > 0);
+}
+
+void n12_dcache_inval_all(void)
+{
+#ifdef CONFIG_PLAT_AG102
+ __asm__ volatile ("\n\tcctl L1D_INVALALL");
+#else
+ unsigned long end, line_size;
+
+ line_size = L1_cache_info[DCACHE].line_size;
+ end =
+ line_size * L1_cache_info[DCACHE].ways * L1_cache_info[DCACHE].sets;
+
+ do {
+ end -= line_size;
+ __asm__ volatile ("\n\tcctl %0, L1D_IX_INVAL"::"r" (end));
+ end -= line_size;
+ __asm__ volatile ("\n\tcctl %0, L1D_IX_INVAL"::"r" (end));
+ end -= line_size;
+ __asm__ volatile ("\n\tcctl %0, L1D_IX_INVAL"::"r" (end));
+ end -= line_size;
+ __asm__ volatile ("\n\tcctl %0, L1D_IX_INVAL"::"r" (end));
+ } while (end > 0);
+#endif
+}
+
+void n12_dcache_wb_all(void)
+{
+#ifdef __NDS32_BASELINE_V3
+#ifdef CONFIG_CACHE_L2
+ __nds32__cctl_l1d_wball_alvl();
+#else
+ __nds32__cctl_l1d_wball_one_lvl();
+#endif
+#else
+#ifndef CONFIG_CPU_DCACHE_WRITETHROUGH
+ unsigned long end, line_size;
+
+ line_size = L1_cache_info[DCACHE].line_size;
+ end =
+ line_size * L1_cache_info[DCACHE].ways * L1_cache_info[DCACHE].sets;
+
+ do {
+ end -= line_size;
+ __asm__ volatile ("\n\tcctl %0, L1D_IX_WB"::"r" (end));
+ end -= line_size;
+ __asm__ volatile ("\n\tcctl %0, L1D_IX_WB"::"r" (end));
+ end -= line_size;
+ __asm__ volatile ("\n\tcctl %0, L1D_IX_WB"::"r" (end));
+ end -= line_size;
+ __asm__ volatile ("\n\tcctl %0, L1D_IX_WB"::"r" (end));
+ } while (end > 0);
+#endif
+#endif
+}
+
+void n12_dcache_wbinval_all(void)
+{
+ unsigned long end, line_size;
+#ifndef CONFIG_CPU_DCACHE_WRITETHROUGH
+ unsigned long saved_gie;
+#endif
+
+ line_size = L1_cache_info[DCACHE].line_size;
+ end =
+ line_size * L1_cache_info[DCACHE].ways * L1_cache_info[DCACHE].sets;
+
+#ifndef CONFIG_CPU_DCACHE_WRITETHROUGH
+ GIE_SAVE(&saved_gie);
+#endif
+#ifdef __NDS32_BASELINE_V3
+#ifdef CONFIG_CACHE_L2
+ __nds32__cctl_l1d_wball_alvl();
+#else
+ __nds32__cctl_l1d_wball_one_lvl();
+#endif
+ __nds32__cctl_l1d_invalall();
+#else
+ do {
+ end -= line_size;
+#ifndef CONFIG_CPU_DCACHE_WRITETHROUGH
+ __asm__ volatile ("\n\tcctl %0, L1D_IX_WB"::"r" (end));
+#endif
+#ifndef CONFIG_PLAT_AG102
+ __asm__ volatile ("\n\tcctl %0, L1D_IX_INVAL"::"r" (end));
+#endif
+ end -= line_size;
+#ifndef CONFIG_CPU_DCACHE_WRITETHROUGH
+ __asm__ volatile ("\n\tcctl %0, L1D_IX_WB"::"r" (end));
+#endif
+#ifndef CONFIG_PLAT_AG102
+ __asm__ volatile ("\n\tcctl %0, L1D_IX_INVAL"::"r" (end));
+#endif
+ end -= line_size;
+#ifndef CONFIG_CPU_DCACHE_WRITETHROUGH
+ __asm__ volatile ("\n\tcctl %0, L1D_IX_WB"::"r" (end));
+#endif
+#ifndef CONFIG_PLAT_AG102
+ __asm__ volatile ("\n\tcctl %0, L1D_IX_INVAL"::"r" (end));
+#endif
+ end -= line_size;
+#ifndef CONFIG_CPU_DCACHE_WRITETHROUGH
+ __asm__ volatile ("\n\tcctl %0, L1D_IX_WB"::"r" (end));
+#endif
+#ifndef CONFIG_PLAT_AG102
+ __asm__ volatile ("\n\tcctl %0, L1D_IX_INVAL"::"r" (end));
+#endif
+ } while (end > 0);
+#ifdef CONFIG_PLAT_AG102
+ __asm__ volatile ("\n\tcctl L1D_INVALALL");
+#endif
+#endif
+#ifndef CONFIG_CPU_DCACHE_WRITETHROUGH
+ GIE_RESTORE(saved_gie);
+#endif
+}
+
+/*
+ * Page
+ */
+void n12_icache_inval_page(unsigned long start)
+{
+ unsigned long line_size, end;
+
+ line_size = L1_cache_info[ICACHE].line_size;
+ end = start + PAGE_SIZE;
+
+ do {
+ end -= line_size;
+ __asm__ volatile ("\n\tcctl %0, L1I_VA_INVAL"::"r" (end));
+ end -= line_size;
+ __asm__ volatile ("\n\tcctl %0, L1I_VA_INVAL"::"r" (end));
+ end -= line_size;
+ __asm__ volatile ("\n\tcctl %0, L1I_VA_INVAL"::"r" (end));
+ end -= line_size;
+ __asm__ volatile ("\n\tcctl %0, L1I_VA_INVAL"::"r" (end));
+ } while (end != start);
+}
+
+void n12_dcache_inval_page(unsigned long start)
+{
+ unsigned long line_size, end;
+
+ line_size = L1_cache_info[DCACHE].line_size;
+ end = start + PAGE_SIZE;
+
+ flush_fill_buffer();
+ do {
+ end -= line_size;
+ __asm__ volatile ("\n\tcctl %0, L1D_VA_INVAL"::"r" (end));
+ end -= line_size;
+ __asm__ volatile ("\n\tcctl %0, L1D_VA_INVAL"::"r" (end));
+ end -= line_size;
+ __asm__ volatile ("\n\tcctl %0, L1D_VA_INVAL"::"r" (end));
+ end -= line_size;
+ __asm__ volatile ("\n\tcctl %0, L1D_VA_INVAL"::"r" (end));
+ } while (end != start);
+}
+
+void n12_dcache_wb_page(unsigned long start)
+{
+#ifndef CONFIG_CPU_DCACHE_WRITETHROUGH
+ unsigned long line_size, end;
+
+ line_size = L1_cache_info[DCACHE].line_size;
+ end = start + PAGE_SIZE;
+
+ flush_fill_buffer();
+ do {
+ end -= line_size;
+ __asm__ volatile ("\n\tcctl %0, L1D_VA_WB"::"r" (end));
+ end -= line_size;
+ __asm__ volatile ("\n\tcctl %0, L1D_VA_WB"::"r" (end));
+ end -= line_size;
+ __asm__ volatile ("\n\tcctl %0, L1D_VA_WB"::"r" (end));
+ end -= line_size;
+ __asm__ volatile ("\n\tcctl %0, L1D_VA_WB"::"r" (end));
+ } while (end != start);
+#endif
+}
+
+void n12_dcache_wbinval_page(unsigned long start)
+{
+ unsigned long line_size, end;
+
+ line_size = L1_cache_info[DCACHE].line_size;
+ end = start + PAGE_SIZE;
+
+ flush_fill_buffer();
+ do {
+ end -= line_size;
+#ifndef CONFIG_CPU_DCACHE_WRITETHROUGH
+ __asm__ volatile ("\n\tcctl %0, L1D_VA_WB"::"r" (end));
+#endif
+ __asm__ volatile ("\n\tcctl %0, L1D_VA_INVAL"::"r" (end));
+ end -= line_size;
+#ifndef CONFIG_CPU_DCACHE_WRITETHROUGH
+ __asm__ volatile ("\n\tcctl %0, L1D_VA_WB"::"r" (end));
+#endif
+ __asm__ volatile ("\n\tcctl %0, L1D_VA_INVAL"::"r" (end));
+ end -= line_size;
+#ifndef CONFIG_CPU_DCACHE_WRITETHROUGH
+ __asm__ volatile ("\n\tcctl %0, L1D_VA_WB"::"r" (end));
+#endif
+ __asm__ volatile ("\n\tcctl %0, L1D_VA_INVAL"::"r" (end));
+ end -= line_size;
+#ifndef CONFIG_CPU_DCACHE_WRITETHROUGH
+ __asm__ volatile ("\n\tcctl %0, L1D_VA_WB"::"r" (end));
+#endif
+ __asm__ volatile ("\n\tcctl %0, L1D_VA_INVAL"::"r" (end));
+ } while (end != start);
+}
+
+void n12_cache_wbinval_page(unsigned long page, int flushi)
+{
+ n12_dcache_wbinval_page(page);
+ if (flushi)
+ n12_icache_inval_page(page);
+}
+
+/* These functions are used to invalidate cache by idx instead of
+ * virtual address. User can use virtual address to do this purpose.
+ * It supports 4way and 32KB cache size with 32bytes cacheline size. */
+#include <nds32_intrinsic.h>
+//#define WB_WITH_IDX
+inline unsigned long va2idx(unsigned long va, unsigned int cache_type,
+ unsigned long *way_offset)
+{
+ unsigned char set_bits, way_bits, line_bits;
+ unsigned int idx;
+ set_bits = L1_cache_info[cache_type].set_bits;
+ way_bits = L1_cache_info[cache_type].way_bits;
+ line_bits = L1_cache_info[cache_type].line_bits;
+ *way_offset = set_bits + line_bits;
+
+ idx = (va & (((1 << set_bits) - 1) << line_bits));
+ return idx;
+}
+
+static inline void n12_dcache_inval_idx(unsigned long p)
+{
+ unsigned long idx, i, way_offset;
+ unsigned char ways;
+ ways = L1_cache_info[DCACHE].ways;
+
+ /* Unroll loop. Not support 2 ways invalidate. */
+ if (ways == 2)
+ panic("This way size is not supported. ways:%u, %s\n", ways,
+ __func__);
+ idx = va2idx(p, DCACHE, &way_offset);
+ for (i = 0; i < ways / 4; i++) {
+ __nds32__cctlidx_wbinval(NDS32_CCTL_L1D_IX_INVAL,
+ (idx | i << way_offset));
+ __nds32__cctlidx_wbinval(NDS32_CCTL_L1D_IX_INVAL,
+ (idx | (i + 1) << way_offset));
+ __nds32__cctlidx_wbinval(NDS32_CCTL_L1D_IX_INVAL,
+ (idx | (i + 2) << way_offset));
+ __nds32__cctlidx_wbinval(NDS32_CCTL_L1D_IX_INVAL,
+ (idx | (i + 3) << way_offset));
+ }
+}
+
+static inline void n12_dcache_wb_idx(unsigned long p)
+{
+ unsigned long idx, i, way_offset;
+ unsigned char ways;
+ ways = L1_cache_info[DCACHE].ways;
+
+ /* Unroll the loop. Not support 2 ways invalidate. */
+ if (ways == 2)
+ panic("This way size is not supported. ways:%d, %s\n", ways,
+ __func__);
+ idx = va2idx(p, DCACHE, &way_offset);
+ for (i = 0; i < ways / 4; i++) {
+ __nds32__cctlidx_wbinval(NDS32_CCTL_L1D_IX_WB,
+ (idx | i << way_offset));
+ __nds32__cctlidx_wbinval(NDS32_CCTL_L1D_IX_INVAL,
+ (idx | i << way_offset));
+ __nds32__cctlidx_wbinval(NDS32_CCTL_L1D_IX_WB,
+ (idx | (i + 1) << way_offset));
+ __nds32__cctlidx_wbinval(NDS32_CCTL_L1D_IX_INVAL,
+ (idx | (i + 1) << way_offset));
+ __nds32__cctlidx_wbinval(NDS32_CCTL_L1D_IX_WB,
+ (idx | (i + 2) << way_offset));
+ __nds32__cctlidx_wbinval(NDS32_CCTL_L1D_IX_INVAL,
+ (idx | (i + 2) << way_offset));
+ __nds32__cctlidx_wbinval(NDS32_CCTL_L1D_IX_WB,
+ (idx | (i + 3) << way_offset));
+ __nds32__cctlidx_wbinval(NDS32_CCTL_L1D_IX_INVAL,
+ (idx | (i + 3) << way_offset));
+ }
+}
+
+static inline void n12_dcache_wbinval_idx(unsigned long p)
+{
+ unsigned long idx, i, way_offset;
+ unsigned char ways;
+ ways = L1_cache_info[DCACHE].ways;
+
+ /* Unroll the loop. Not support 2 ways invalidate. */
+ if (ways == 2)
+ panic("This way size is not supported. ways:%d, %s\n", ways,
+ __func__);
+ idx = va2idx(p, DCACHE, &way_offset);
+ for (i = 0; i < ways / 4; i++) {
+ __nds32__cctlidx_wbinval(NDS32_CCTL_L1D_IX_WB,
+ (idx | i << way_offset));
+ __nds32__cctlidx_wbinval(NDS32_CCTL_L1D_IX_WB,
+ (idx | (i + 1) << way_offset));
+ __nds32__cctlidx_wbinval(NDS32_CCTL_L1D_IX_WB,
+ (idx | (i + 2) << way_offset));
+ __nds32__cctlidx_wbinval(NDS32_CCTL_L1D_IX_WB,
+ (idx | (i + 3) << way_offset));
+ }
+}
+
+/*
+ * Range
+ */
+void n12_icache_inval_range(unsigned long start, unsigned long end)
+{
+ unsigned long line_size;
+
+ line_size = L1_cache_info[ICACHE].line_size;
+
+ while (end > start) {
+ __asm__ volatile ("\n\tcctl %0, L1I_VA_INVAL"::"r" (start));
+ start += line_size;
+ }
+}
+
+void n12_dcache_inval_range(unsigned long start, unsigned long end)
+{
+ unsigned long line_size;
+
+ line_size = L1_cache_info[DCACHE].line_size;
+
+ flush_fill_buffer();
+ while (end > start) {
+#ifdef WB_WITH_IDX
+ n12_dcache_inval_idx(start);
+#else
+ __asm__ volatile ("\n\tcctl %0, L1D_VA_INVAL"::"r" (start));
+#endif
+ start += line_size;
+ }
+}
+
+void n12_dcache_wb_range(unsigned long start, unsigned long end)
+{
+#ifndef CONFIG_CPU_DCACHE_WRITETHROUGH
+ unsigned long line_size;
+
+ line_size = L1_cache_info[DCACHE].line_size;
+
+ flush_fill_buffer();
+ while (end > start) {
+#ifdef WB_WITH_IDX
+ n12_dcache_wb_idx(start);
+#else
+ __asm__ volatile ("\n\tcctl %0, L1D_VA_WB"::"r" (start));
+#endif
+ start += line_size;
+ }
+#endif
+}
+
+void n12_dcache_wbinval_range(unsigned long start, unsigned long end)
+{
+ unsigned long line_size;
+
+ line_size = L1_cache_info[DCACHE].line_size;
+
+ flush_fill_buffer();
+ while (end > start) {
+#ifndef CONFIG_CPU_DCACHE_WRITETHROUGH
+#ifdef WB_WITH_IDX
+ n12_dcache_wbinval_idx(start);
+#else
+ __asm__ volatile ("\n\tcctl %0, L1D_VA_WB"::"r" (start));
+#endif
+#endif
+ __asm__ volatile ("\n\tcctl %0, L1D_VA_INVAL"::"r" (start));
+ start += line_size;
+ }
+}
+
+void n12_cache_wbinval_range(unsigned long start, unsigned long end, int flushi)
+{
+ n12_dcache_wbinval_range(start, end);
+ if (flushi)
+ n12_icache_inval_range(start, end);
+}
+
+void n12_cache_wbinval_range_check(struct vm_area_struct *vma,
+ unsigned long start, unsigned long end)
+{
+ unsigned long line_size, t_start, t_end;
+ int flushi;
+
+ flushi = vma->vm_flags & VM_EXEC;
+ line_size = L1_cache_info[DCACHE].line_size;
+ start = start & ~(line_size - 1);
+ end = (end + line_size - 1) & ~(line_size - 1);
+
+ if ((end - start) > (8 * PAGE_SIZE)) {
+ n12_dcache_wbinval_all();
+ if (flushi)
+ n12_icache_inval_all();
+ return;
+ }
+
+ t_start = (start + PAGE_SIZE) & PAGE_MASK;
+ t_end = ((end - 1) & PAGE_MASK);
+
+ if ((start & PAGE_MASK) == t_end) {
+ if (va_present(vma->vm_mm, start))
+ n12_cache_wbinval_range(start, end, flushi);
+ return;
+ }
+
+ if (va_present(vma->vm_mm, start))
+ n12_cache_wbinval_range(start, t_start, flushi);
+
+ if (va_present(vma->vm_mm, end - 1))
+ n12_cache_wbinval_range(t_end, end, flushi);
+
+ while (t_start < t_end) {
+ if (va_present(vma->vm_mm, t_start))
+ n12_cache_wbinval_page(t_start, flushi);
+ t_start += PAGE_SIZE;
+ }
+}
+
+/*
+ * DMA
+ */
+void n12_dma_wb_range(unsigned long start, unsigned long end)
+{
+ unsigned long line_size;
+ line_size = L1_cache_info[DCACHE].line_size;
+ start = start & (~(line_size - 1));
+ end = (end + line_size - 1) & (~(line_size - 1));
+ if (unlikely(start == end))
+ return;
+
+ n12_dcache_wb_range(start, end);
+
+#ifdef CONFIG_CACHE_L2
+ {
+ unsigned long p_start = __pa(start);
+ unsigned long p_end = __pa(end);
+ unsigned long cmd;
+ //TODO Can Use PAGE Mode to optimize if range large than PAGE_SIZE
+ line_size = L2_CACHE_LINE_SIZE();
+ cmd =
+ (p_start & ~(line_size - 1)) | CCTL_CMD_L2_PA_WB |
+ CCTL_SINGLE_CMD;
+ do {
+ L2_CMD_RDY();
+ L2C_W_REG(L2_CCTL_CMD_OFF, cmd);
+ cmd += line_size;
+ p_start += line_size;
+ } while (p_end > p_start);
+ cmd = CCTL_CMD_L2_SYNC;
+ L2_CMD_RDY();
+ L2C_W_REG(L2_CCTL_CMD_OFF, cmd);
+ L2_CMD_RDY();
+
+ }
+#endif
+}
+
+#ifdef CONFIG_CACHE_L2
+void n12_l2dcache_wbinval_range(unsigned long start, unsigned long end)
+{
+ unsigned long p_start;
+ unsigned long p_end;
+ unsigned long cmd;
+ unsigned long line_size;
+
+ p_start = __pa(start);
+ p_end = __pa(end);
+ //TODO Can Use PAGE Mode to optimize if range large than PAGE_SIZE
+ line_size = L2_CACHE_LINE_SIZE();
+ cmd =
+ (p_start & ~(line_size - 1)) | CCTL_CMD_L2_PA_WBINVAL |
+ CCTL_SINGLE_CMD;
+ do {
+ L2_CMD_RDY();
+ L2C_W_REG(L2_CCTL_CMD_OFF, cmd);
+ cmd += line_size;
+ p_start += line_size;
+ } while (p_end > p_start);
+ cmd = CCTL_CMD_L2_SYNC;
+ L2_CMD_RDY();
+ L2C_W_REG(L2_CCTL_CMD_OFF, cmd);
+ L2_CMD_RDY();
+
+}
+#endif
+
+void n12_dma_inval_range(unsigned long start, unsigned long end)
+{
+ unsigned long line_size;
+ unsigned long old_start = start;
+ unsigned long old_end = end;
+ line_size = L1_cache_info[DCACHE].line_size;
+ start = start & (~(line_size - 1));
+ end = (end + line_size - 1) & (~(line_size - 1));
+ if (unlikely(start == end))
+ return;
+ if (start != old_start) {
+ n12_dcache_wbinval_range(start, start + line_size);
+#ifdef CONFIG_CACHE_L2
+ n12_l2dcache_wbinval_range(start, start + line_size);
+#endif
+ }
+ if (end != old_end) {
+ n12_dcache_wbinval_range(end - line_size, end);
+#ifdef CONFIG_CACHE_L2
+ n12_l2dcache_wbinval_range(end - line_size, end);
+#endif
+ }
+ n12_dcache_inval_range(start, end);
+#ifdef CONFIG_CACHE_L2
+ unsigned long p_start = __pa(start);
+ unsigned long p_end = __pa(end);
+ unsigned long cmd;
+ //TODO Can Use PAGE Mode to optimize if range large than PAGE_SIZE
+ line_size = L2_CACHE_LINE_SIZE();
+ cmd =
+ (p_start & ~(line_size - 1)) | CCTL_CMD_L2_PA_INVAL |
+ CCTL_SINGLE_CMD;
+ do {
+ L2_CMD_RDY();
+ L2C_W_REG(L2_CCTL_CMD_OFF, cmd);
+ cmd += line_size;
+ p_start += line_size;
+ } while (p_end > p_start);
+ cmd = CCTL_CMD_L2_SYNC;
+ L2_CMD_RDY();
+ L2C_W_REG(L2_CCTL_CMD_OFF, cmd);
+ L2_CMD_RDY();
+#endif
+
+}
+
+void n12_dma_wbinval_range(unsigned long start, unsigned long end)
+{
+ unsigned long line_size;
+ line_size = L1_cache_info[DCACHE].line_size;
+ start = start & (~(line_size - 1));
+ end = (end + line_size - 1) & (~(line_size - 1));
+ if (unlikely(start == end))
+ return;
+
+ n12_dcache_wbinval_range(start, end);
+#ifdef CONFIG_CACHE_L2
+ {
+ unsigned long p_start = __pa(start);
+ unsigned long p_end = __pa(end);
+ unsigned long cmd;
+ //TODO Can Use PAGE Mode to optimize if range large than PAGE_SIZE
+ line_size = L2_CACHE_LINE_SIZE();
+ cmd =
+ (p_start & ~(line_size - 1)) | CCTL_CMD_L2_PA_WBINVAL |
+ CCTL_SINGLE_CMD;
+ do {
+ L2_CMD_RDY();
+ L2C_W_REG(L2_CCTL_CMD_OFF, cmd);
+ cmd += line_size;
+ p_start += line_size;
+ } while (p_end > p_start);
+ cmd = CCTL_CMD_L2_SYNC;
+ L2_CMD_RDY();
+ L2C_W_REG(L2_CCTL_CMD_OFF, cmd);
+ L2_CMD_RDY();
+
+ }
+#endif
+}
+
+void n12_proc_init(void)
+{
+}
+
+void n12_proc_fin(void)
+{
+}
+
+void n12_do_idle(void)
+{
+ STANDBY(no_wake_grant);
+}
+
+void n12_reset(unsigned long reset)
+{
+ GIE_DISABLE();
+ SET_CACHE_CTL(GET_CACHE_CTL() &
+ ~(CACHE_CTL_mskIC_EN | CACHE_CTL_mskDC_EN));
+ n12_dcache_wbinval_all();
+ n12_icache_inval_all();
+
+ __asm__ __volatile__("jr.toff %0\n\t"::"r"(reset));
+}
+
+void n12_switch_mm(struct mm_struct *mm)
+{
+ unsigned long cid;
+#ifndef CONFIG_CPU_NO_CONTEXT_ID
+ cid = GET_TLB_MISC();
+ cid = (cid & ~TLB_MISC_mskCID) | mm->context.id;
+ SET_TLB_MISC(cid);
+#endif
+ SET_L1_PPTB(__pa(mm->pgd));
+ //workaround N10 single-entry cache flush issue
+ //the following line can be removed once the issue is fixed.
+ __asm__ __volatile__("tlbop %0, INV"::"r"(cid));
+ __nds32__isb();
+#ifdef CONFIG_CPU_NO_CONTEXT_ID
+ local_flush_tlb_mm(mm);
+#endif
+}
diff -Nur linux-3.4.113.orig/arch/nds32/mm/tlb.c linux-3.4.113/arch/nds32/mm/tlb.c
--- linux-3.4.113.orig/arch/nds32/mm/tlb.c 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/mm/tlb.c 2016-12-01 20:59:24.372613522 +0100
@@ -0,0 +1,47 @@
+#include <linux/spinlock_types.h>
+#include <linux/mm.h>
+#include <linux/sched.h>
+#include <asm/nds32.h>
+#include <nds32_intrinsic.h>
+
+unsigned int cpu_last_cid = { TLB_MISC_mskCID + (2 << TLB_MISC_offCID) };
+
+DEFINE_SPINLOCK(cid_lock);
+
+void local_flush_tlb_range(struct vm_area_struct *vma,
+ unsigned long start, unsigned long end)
+{
+ unsigned long flags, ocid, ncid;
+
+ if ((end - start) > 0x400000) {
+ asm("tlbop FLUA");
+ __nds32__isb();
+ return;
+ }
+
+ spin_lock_irqsave(&cid_lock, flags);
+ ocid = GET_TLB_MISC();
+ ncid = (ocid & ~TLB_MISC_mskCID) | vma->vm_mm->context.id;
+ SET_TLB_MISC(ncid);
+ while (start < end) {
+ asm("tlbop %0, INV"::"r"(start));
+ __nds32__isb();
+ start += PAGE_SIZE;
+ }
+ SET_TLB_MISC(ocid);
+ spin_unlock_irqrestore(&cid_lock, flags);
+}
+
+void local_flush_tlb_page(struct vm_area_struct *vma, unsigned long addr)
+{
+ unsigned long flags, ocid, ncid;
+
+ spin_lock_irqsave(&cid_lock, flags);
+ ocid = GET_TLB_MISC();
+ ncid = (ocid & ~TLB_MISC_mskCID) | vma->vm_mm->context.id;
+ SET_TLB_MISC(ncid);
+ asm("tlbop %0, INV"::"r"(addr));
+ __nds32__isb();
+ SET_TLB_MISC(ocid);
+ spin_unlock_irqrestore(&cid_lock, flags);
+}
diff -Nur linux-3.4.113.orig/arch/nds32/oprofile/common.c linux-3.4.113/arch/nds32/oprofile/common.c
--- linux-3.4.113.orig/arch/nds32/oprofile/common.c 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/oprofile/common.c 2016-12-01 20:59:24.372613522 +0100
@@ -0,0 +1,104 @@
+/*
+ * This file is subject to the terms and conditions of the GNU General Public
+ * License. See the file "COPYING" in the main directory of this archive
+ * for more details.
+ *
+ * Copyright (C) 2004, 2005 Ralf Baechle
+ * Copyright (C) 2005 MIPS Technologies, Inc.
+ * Copyright (C) 2008 Andes Technology Corporation
+ */
+#include <linux/errno.h>
+#include <linux/init.h>
+#include <linux/oprofile.h>
+#include <linux/smp.h>
+
+#include "op_impl.h"
+
+extern struct op_nds32_model op_model_nds32_ops __attribute__ ((weak));
+
+static struct op_nds32_model *model;
+
+static struct op_counter_config ctr[20];
+
+static int op_nds32_setup(void)
+{
+ /* Pre-compute the values to stuff in the hardware registers. */
+ model->reg_setup(ctr);
+
+ /* Configure the registers on all cpus. */
+ on_each_cpu(model->cpu_setup, NULL, 1);
+
+ return 0;
+}
+
+static int op_nds32_create_files(struct super_block *sb, struct dentry *root)
+{
+ int i;
+
+ for (i = 0; i < model->num_counters; ++i) {
+ struct dentry *dir;
+ char buf[4];
+
+ snprintf(buf, sizeof buf, "%d", i);
+ dir = oprofilefs_mkdir(sb, root, buf);
+
+ oprofilefs_create_ulong(sb, dir, "enabled", &ctr[i].enabled);
+ oprofilefs_create_ulong(sb, dir, "event", &ctr[i].event);
+ oprofilefs_create_ulong(sb, dir, "count", &ctr[i].count);
+ oprofilefs_create_ulong(sb, dir, "kernel", &ctr[i].kernel);
+ oprofilefs_create_ulong(sb, dir, "user", &ctr[i].user);
+ oprofilefs_create_ulong(sb, dir, "exl", &ctr[i].exl);
+ /* Dummy. */
+ oprofilefs_create_ulong(sb, dir, "unit_mask",
+ &ctr[i].unit_mask);
+ }
+
+ return 0;
+}
+
+static int op_nds32_start(void)
+{
+ on_each_cpu(model->cpu_start, NULL, 1);
+
+ return 0;
+}
+
+static void op_nds32_stop(void)
+{
+ /* Disable performance monitoring for all counters. */
+ on_each_cpu(model->cpu_stop, NULL, 1);
+}
+
+int __init oprofile_arch_init(struct oprofile_operations *ops)
+{
+ struct op_nds32_model *lmodel = NULL;
+ int res;
+
+ lmodel = &op_model_nds32_ops;
+
+ if (!lmodel)
+ return -ENODEV;
+
+ res = lmodel->init();
+ if (res)
+ return res;
+
+ model = lmodel;
+
+ ops->create_files = op_nds32_create_files;
+ ops->setup = op_nds32_setup;
+ ops->start = op_nds32_start;
+ ops->stop = op_nds32_stop;
+ ops->cpu_type = lmodel->cpu_type;
+
+ printk(KERN_INFO "oprofile: using %s performance monitoring.\n",
+ lmodel->cpu_type);
+
+ return 0;
+}
+
+void oprofile_arch_exit(void)
+{
+ if (model)
+ model->exit();
+}
diff -Nur linux-3.4.113.orig/arch/nds32/oprofile/Makefile linux-3.4.113/arch/nds32/oprofile/Makefile
--- linux-3.4.113.orig/arch/nds32/oprofile/Makefile 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/oprofile/Makefile 2016-12-01 20:59:24.372613522 +0100
@@ -0,0 +1,11 @@
+EXTRA_CFLAGS :=
+
+obj-$(CONFIG_OPROFILE) += oprofile.o
+
+DRIVER_OBJS = $(addprefix ../../../drivers/oprofile/, \
+ oprof.o cpu_buffer.o buffer_sync.o \
+ event_buffer.o oprofile_files.o \
+ oprofilefs.o oprofile_stats.o \
+ timer_int.o )
+
+oprofile-y := $(DRIVER_OBJS) common.o op_model_nds32.o
diff -Nur linux-3.4.113.orig/arch/nds32/oprofile/op_impl.h linux-3.4.113/arch/nds32/oprofile/op_impl.h
--- linux-3.4.113.orig/arch/nds32/oprofile/op_impl.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/oprofile/op_impl.h 2016-12-01 20:59:24.372613522 +0100
@@ -0,0 +1,42 @@
+/**
+ * @file arch/alpha/oprofile/op_impl.h
+ *
+ * @remark Copyright 2002 OProfile authors
+ * @remark Read the file COPYING
+ *
+ * @author Richard Henderson <rth@twiddle.net>
+ */
+
+#ifndef OP_IMPL_H
+#define OP_IMPL_H 1
+
+struct pt_regs;
+
+extern int null_perf_irq(struct pt_regs *regs);
+extern int (*perf_irq)(struct pt_regs *regs);
+
+/* Per-counter configuration as set via oprofilefs. */
+struct op_counter_config {
+ unsigned long enabled;
+ unsigned long event;
+ unsigned long count;
+ /* Dummies because I am too lazy to hack the userspace tools. */
+ unsigned long kernel;
+ unsigned long user;
+ unsigned long exl;
+ unsigned long unit_mask;
+};
+
+/* Per-architecture configury and hooks. */
+struct op_nds32_model {
+ void (*reg_setup) (struct op_counter_config *);
+ void (*cpu_setup) (void * dummy);
+ int (*init)(void);
+ void (*exit)(void);
+ void (*cpu_start)(void *args);
+ void (*cpu_stop)(void *args);
+ char *cpu_type;
+ unsigned char num_counters;
+};
+
+#endif
diff -Nur linux-3.4.113.orig/arch/nds32/oprofile/op_model_nds32.c linux-3.4.113/arch/nds32/oprofile/op_model_nds32.c
--- linux-3.4.113.orig/arch/nds32/oprofile/op_model_nds32.c 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/oprofile/op_model_nds32.c 2016-12-01 20:59:24.372613522 +0100
@@ -0,0 +1,400 @@
+/*
+ * This file is subject to the terms and conditions of the GNU General Public
+ * License. See the file "COPYING" in the main directory of this archive
+ * for more details.
+ *
+ * Copyright (C) 2004, 2005 by Ralf Baechle
+ * Copyright (C) 2005 by MIPS Technologies, Inc.
+ * Copyright (C) 2007 Andes Technology Corporation
+ */
+#include <linux/oprofile.h>
+#include <linux/interrupt.h>
+#include <linux/smp.h>
+#include <asm/irq_regs.h>
+#include <asm/nds32.h>
+#include <asm/uaccess.h>
+#include <asm/pfm.h>
+
+#include "op_impl.h"
+
+#ifdef CONFIG_PLAT_AG102
+#include <asm/amic.h>
+#define NDS32_PERFCNTR_IRQA 23
+#define NDS32_PERFCNTR_IRQB 22
+#else
+#define NDS32_PERFCNTR_IRQA 10
+#endif
+#define NDS32_PERFCTL_EN(num) (1 << num)
+#define NDS32_PERFCTL_INTEN (1UL << 3)
+#define NDS32_PERFCTL_OVERFLOW (1UL << 6)
+#define NDS32_PERFCTL_NOKERNEL (1UL << 9)
+#define NDS32_PERFCTL_NOUSER (1UL << 12)
+#define NDS32_PERFCTL_EVENT_0(event) (event << 15)
+#define NDS32_PERFCTL_EVENT_1(event) (event << 16)
+#define NDS32_PERFCTL_EVENT_2(event) (event << 22)
+
+static unsigned long long ov0, ov1, ov2;
+static int syscall = 0;
+
+struct pmu_counter {
+ volatile unsigned long ovf;
+ unsigned long reset_counter;
+};
+
+enum { PFMC0, PFMC1, PFMC2, MAX_COUNTERS };
+
+static struct pmu_counter results[MAX_COUNTERS];
+
+static inline unsigned int read_perfcntr(int counter)
+{
+ switch (counter) {
+ case PFMC0:
+ return GET_PFMC0();
+ break;
+ case PFMC1:
+ return GET_PFMC1();
+ break;
+ case PFMC2:
+ return GET_PFMC2();
+ break;
+ default:
+ printk(KERN_ERR
+ "Oprofile read_perfcntr: CPU has no %d performance counters\n",
+ counter);
+ }
+
+ return 0;
+}
+
+static inline unsigned int read_perfctrl(void)
+{
+ return GET_PFM_CTL();
+}
+
+static inline void write_perfcntr(int counter, unsigned int value)
+{
+ switch (counter) {
+ case PFMC0:
+ SET_PFMC0(value);
+ break;
+ case PFMC1:
+ SET_PFMC1(value);
+ break;
+ case PFMC2:
+ SET_PFMC2(value);
+ break;
+ default:
+ printk(KERN_ERR
+ "Oprofile write_perfcntr: CPU has no %d performance counters\n",
+ counter);
+ }
+}
+
+static inline void write_perfctrl(unsigned int value)
+{
+ SET_PFM_CTL(value);
+}
+
+struct op_nds32_model op_model_nds32_ops;
+
+static struct nds32_register_config {
+ unsigned int control[3];
+ unsigned int counter[3];
+} reg;
+
+/* Compute all of the registers in preparation for enabling profiling. */
+
+static void nds32_reg_setup(struct op_counter_config *ctr)
+{
+ unsigned int counters = op_model_nds32_ops.num_counters;
+ int i;
+
+ /* Compute the performance counter control word. */
+ /* For now count kernel and user mode */
+ for (i = 0; i < counters; i++) {
+ reg.control[i] = 0;
+ reg.counter[i] = 0;
+
+ if (!ctr[i].enabled)
+ continue;
+
+ switch (i) {
+ case 0:
+ reg.control[i] = NDS32_PERFCTL_EVENT_0(ctr[i].event) |
+ (NDS32_PERFCTL_INTEN << i);
+ break;
+ case 1:
+ reg.control[i] = NDS32_PERFCTL_EVENT_1(ctr[i].event) |
+ (NDS32_PERFCTL_INTEN << i);
+ break;
+ case 2:
+ reg.control[i] = NDS32_PERFCTL_EVENT_2(ctr[i].event) |
+ (NDS32_PERFCTL_INTEN << i);
+ break;
+ default:
+ printk(KERN_ERR
+ "Oprofile nds32_reg_setup: CPU has no %d performance counters\n",
+ i);
+ }
+ if (!(ctr[i].kernel))
+ reg.control[i] |= (NDS32_PERFCTL_NOKERNEL << i);
+ if (!(ctr[i].user))
+ reg.control[i] |= (NDS32_PERFCTL_NOUSER << i);
+ reg.counter[i] = -ctr[i].count;
+ }
+}
+
+/* Program all of the registers in preparation for enabling profiling. */
+
+static void nds32_cpu_setup(void *args)
+{
+ unsigned int counters = op_model_nds32_ops.num_counters;
+
+ switch (counters) {
+ case 3:
+ write_perfcntr(2, reg.counter[2]);
+ case 2:
+ write_perfcntr(1, reg.counter[1]);
+ case 1:
+ write_perfcntr(0, reg.counter[0]);
+ }
+ write_perfctrl(0);
+}
+
+/* Start all counters on current CPU */
+static void nds32_cpu_start(void *args)
+{
+ unsigned int counters = op_model_nds32_ops.num_counters;
+ unsigned int value = 0;
+
+ switch (counters) {
+ case 3:
+ if (reg.control[2])
+ value |= (NDS32_PERFCTL_EN(2) | reg.control[2]);
+ case 2:
+ if (reg.control[1])
+ value |= (NDS32_PERFCTL_EN(1) | reg.control[1]);
+ case 1:
+ if (reg.control[0])
+ value |= (NDS32_PERFCTL_EN(0) | reg.control[0]);
+ }
+ write_perfctrl(value);
+}
+
+/* Stop all counters on current CPU */
+static void nds32_cpu_stop(void *args)
+{
+ write_perfctrl(0);
+}
+
+static irqreturn_t nds32_perfcount_handler(int irq, void *dev_id)
+{
+ unsigned int control, i;
+
+ control = read_perfctrl();
+ write_perfctrl(0);
+
+ if (syscall) {
+ if (control & PFM_CTL_mskOVF0)
+ ov0++;
+ if (control & PFM_CTL_mskOVF1)
+ ov1++;
+ if (control & PFM_CTL_mskOVF2)
+ ov2++;
+ } else {
+ for (i = 0; i < MAX_COUNTERS; i++) {
+ if ((control & (NDS32_PERFCTL_INTEN << i))
+ && (control & (NDS32_PERFCTL_OVERFLOW << i))) {
+ oprofile_add_sample(get_irq_regs(), i);
+ write_perfcntr(i, reg.counter[i]);
+ break;
+ }
+ }
+ }
+ write_perfctrl(control);
+
+ return IRQ_HANDLED;
+}
+
+static inline int n_counters(void)
+{
+ return 3;
+}
+
+static inline void reset_counters(int counters)
+{
+ switch (counters) {
+ case 3:
+ write_perfcntr(2, 0);
+ case 2:
+ write_perfcntr(1, 0);
+ case 1:
+ write_perfcntr(0, 0);
+ }
+ write_perfctrl(0);
+}
+
+static int __init nds32_init(void)
+{
+ int counters, ret;
+
+ counters = n_counters();
+ if (counters == 0) {
+ printk(KERN_ERR "Oprofile: CPU has no performance counters\n");
+ return -ENODEV;
+ }
+
+ reset_counters(counters);
+
+ op_model_nds32_ops.num_counters = counters;
+ op_model_nds32_ops.cpu_type = "nds32";
+
+ ret =
+ request_irq(NDS32_PERFCNTR_IRQA, nds32_perfcount_handler,
+ IRQF_SHARED, "NDS32 PERFCNTR", (void *)results);
+ if (ret < 0) {
+ printk(KERN_ERR "oprofile: unable to request IRQ%d\n",
+ NDS32_PERFCNTR_IRQA);
+ return ret;
+ }
+#ifdef CONFIG_PLAT_AG102
+ unsigned int tmp;
+ /* Set NDS32_PERFCNTR_IRQA to bind on core A */
+ tmp =
+ *(volatile unsigned long *)(AMIC_VA_BASE + CPUID0 +
+ ((NDS32_PERFCNTR_IRQA >> 4) << 2));
+ tmp &= ~(0x11 << ((NDS32_PERFCNTR_IRQA & ~0x10) * 2));
+ *(volatile unsigned long *)(AMIC_VA_BASE + CPUID0 +
+ ((NDS32_PERFCNTR_IRQA >> 4) << 2)) = tmp;
+ tmp =
+ (*(volatile unsigned long *)(AMIC_VA_BASE + CPUDC)) & ~(1 <<
+ NDS32_PERFCNTR_IRQA);
+ *(volatile unsigned long *)(AMIC_VA_BASE + CPUDC) = tmp;
+
+ ret =
+ request_irq(NDS32_PERFCNTR_IRQB, nds32_perfcount_handler,
+ IRQF_SHARED, "NDS32 PERFCNTR", (void *)results);
+ if (ret < 0) {
+ printk(KERN_ERR "oprofile: unable to request IRQ%d\n",
+ NDS32_PERFCNTR_IRQB);
+ return ret;
+ }
+ /* Set NDS32_PERFCNTR_IRQB to bind on core B */
+ tmp =
+ *(volatile unsigned long *)(AMIC_VA_BASE + CPUID0 +
+ ((NDS32_PERFCNTR_IRQB >> 4) << 2));
+ tmp &= ~(0x11 << ((NDS32_PERFCNTR_IRQB & ~0x10) * 2));
+ tmp |= 1 << ((NDS32_PERFCNTR_IRQB & ~0x10) * 2);
+ *(volatile unsigned long *)(AMIC_VA_BASE + CPUID0 +
+ ((NDS32_PERFCNTR_IRQB >> 4) << 2)) = tmp;
+ tmp =
+ (*(volatile unsigned long *)(AMIC_VA_BASE + CPUDC)) & ~(1 <<
+ NDS32_PERFCNTR_IRQB);
+ *(volatile unsigned long *)(AMIC_VA_BASE + CPUDC) = tmp;
+#endif
+
+ return 0;
+}
+
+static void nds32_exit(void)
+{
+ reset_counters(op_model_nds32_ops.num_counters);
+
+ free_irq(NDS32_PERFCNTR_IRQA, results);
+#ifdef CONFIG_PLAT_AG102
+ free_irq(NDS32_PERFCNTR_IRQB, results);
+#endif
+}
+
+void sys_pfmctl(int event0, int event1, int event2, int start)
+{
+ unsigned int ctl = 0;
+
+ if (start) {
+ syscall = 1;
+ if (event0 >= 0)
+ ctl |=
+ (NDS32_PERFCTL_EVENT_0(event0) |
+ (NDS32_PERFCTL_INTEN << 0) | NDS32_PERFCTL_EN(0));
+ if (event1 >= 0)
+ ctl |=
+ (NDS32_PERFCTL_EVENT_1(event1) |
+ (NDS32_PERFCTL_INTEN << 1) | NDS32_PERFCTL_EN(1));
+ if (event2 >= 0)
+ ctl |=
+ (NDS32_PERFCTL_EVENT_2(event2) |
+ (NDS32_PERFCTL_INTEN << 2) | NDS32_PERFCTL_EN(2));
+ } else {
+ syscall = 0;
+ if (event0 >= 0)
+ ctl &=
+ ~((NDS32_PERFCTL_INTEN << 0) | NDS32_PERFCTL_EN(0));
+ if (event1 >= 0)
+ ctl &=
+ ~((NDS32_PERFCTL_INTEN << 1) | NDS32_PERFCTL_EN(1));
+ if (event2 >= 0)
+ ctl &=
+ ~((NDS32_PERFCTL_INTEN << 2) | NDS32_PERFCTL_EN(2));
+ }
+
+ write_perfctrl(ctl);
+
+}
+
+int sys_getpfm(struct pcounter __user * p)
+{
+ struct pcounter pfm;
+ unsigned int control;
+
+ control = read_perfctrl();
+ write_perfctrl(0);
+
+ pfm.pfm0 = ov0 << 32 | GET_PFMC0();
+ pfm.pfm1 = ov1 << 32 | GET_PFMC1();
+ pfm.pfm2 = ov2 << 32 | GET_PFMC2();
+
+ if (copy_to_user(p, &pfm, sizeof(pfm)))
+ return -EFAULT;
+
+ write_perfctrl(control);
+
+ return 0;
+}
+
+int sys_setpfm(int pfm0, int pfm1, int pfm2, struct pcounter __user * p)
+{
+ struct pcounter pfm;
+ unsigned int control;
+
+ control = read_perfctrl();
+ write_perfctrl(0);
+
+ if (copy_from_user(&pfm, p, sizeof(pfm)))
+ return -EFAULT;
+
+ if (pfm0) {
+ SET_PFMC0((unsigned int)(pfm.pfm0 & 0xffffffff));
+ ov0 = pfm.pfm0 >> 32;
+ }
+ if (pfm1) {
+ SET_PFMC1((unsigned int)(pfm.pfm1 & 0xffffffff));
+ ov1 = pfm.pfm1 >> 32;
+ }
+ if (pfm2) {
+ SET_PFMC2((unsigned int)(pfm.pfm2 & 0xffffffff));
+ ov2 = pfm.pfm2 >> 32;
+ }
+
+ write_perfctrl(control);
+
+ return 0;
+}
+
+struct op_nds32_model op_model_nds32_ops = {
+ .reg_setup = nds32_reg_setup,
+ .cpu_setup = nds32_cpu_setup,
+ .init = nds32_init,
+ .exit = nds32_exit,
+ .cpu_start = nds32_cpu_start,
+ .cpu_stop = nds32_cpu_stop,
+};
diff -Nur linux-3.4.113.orig/arch/nds32/platforms/ag101/cpu-fcs.c linux-3.4.113/arch/nds32/platforms/ag101/cpu-fcs.c
--- linux-3.4.113.orig/arch/nds32/platforms/ag101/cpu-fcs.c 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/platforms/ag101/cpu-fcs.c 2016-12-01 20:59:24.372613522 +0100
@@ -0,0 +1,401 @@
+/*
+ * linux/arch/nds32/platforms/ag101/cpu-fcs.c
+ *
+ * Copyright (C) 2002,2003 Intrinsyc Software
+ * Copyright (C) 2009 Andes Technology Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * History:
+ * 31-Jul-2002 : Initial version [FB]
+ * 29-Jan-2003 : added PXA255 support [FB]
+ * 20-Apr-2003 : ported to v2.5 (Dustin McIntire, Sensoria Corp.)
+ * 18-Jun-2008 : ported to NDS32 architecture ( Roy Lee, Andestech Corp.)
+ *
+ * Note:
+ * This driver may change the memory bus clock rate, but will not do any
+ * platform specific access timing changes... for example if you have flash
+ * memory connected to CS0, you will need to register a platform specific
+ * notifier which will adjust the memory access strobes to maintain a
+ * minimum strobe width.
+ *
+ */
+#include <linux/module.h>
+#include <linux/cpufreq.h>
+#include <linux/interrupt.h>
+
+#include <asm/hardware.h>
+#include <asm/localmem.h>
+#include <asm/system.h>
+#include <asm/nds32.h>
+#include <asm/irq_regs.h>
+
+#define NDS32_FCS_IRQ 8
+#define AG101_MIN_FREQ 100000
+#define AG101_MAX_FREQ 400000
+#define OSC_KHZ 10000 /* 10 MHz AG101 */
+
+#define USE_CACHE 0
+struct ag101_freq_struct {
+
+ unsigned int khz; /* cpu_clk in khz */
+ unsigned int pll; /* pll mul */
+ unsigned int div; /* ahb div */
+ unsigned int frange; /* pll1 freq range */
+};
+
+struct ag101_freq_struct ag101_run_freqs[] = {
+
+ /* khz , pll, div, frange pll/cpu/ahb/apb */
+ {100000, 10, 2, 0}, /* 400/400/050/025 */
+ {200000, 20, 4, 1}, /* 400/400/050/025 */
+ {300000, 30, 6, 2}, /* 400/400/050/025 */
+ {400000, 40, 8, 2}, /* 400/400/050/025 */
+ {500000, 50, 10, 3}, /* 500/500/050/025 */
+ {0,}
+};
+
+#define NUM_RUN_FREQS ARRAY_SIZE( ag101_run_freqs)
+static struct cpufreq_frequency_table ag101_run_freq_table[NUM_RUN_FREQS + 1];
+
+/* Use the turbo mode frequencies for the CPUFREQ_POLICY_POWERSAVE policy */
+static struct ag101_freq_struct ag101_turbo_freqs[] = {
+
+ /* khz , pll, div, frange pll/cpu/ahb/apb */
+ {100000, 10, 2, 0}, /* 400/400/050/025 */
+ {200000, 20, 4, 1}, /* 400/400/050/025 */
+ {300000, 30, 6, 2}, /* 400/400/050/025 */
+ {400000, 40, 8, 2}, /* 400/400/050/025 */
+ {500000, 50, 10, 3}, /* 500/500/050/025 */
+ {0,}
+};
+
+#define NUM_TURBO_FREQS ARRAY_SIZE( ag101_turbo_freqs)
+static struct cpufreq_frequency_table ag101_turbo_freq_table[NUM_TURBO_FREQS +
+ 1];
+
+/* Generic helper function get CPU clocks in kHz */
+unsigned int ag101_cpufreq_get(unsigned int dummy)
+{
+
+ unsigned int mul = (REG32(PMU_FTPMU010_VA_BASE + 0x30) >> 3UL) & 0x01ff; /* pll1 mul */
+ return OSC_KHZ * mul;
+}
+
+/* find a valid frequency point */
+static int ag101_verify_policy(struct cpufreq_policy *policy)
+{
+
+ struct cpufreq_frequency_table *ag101_freqs_table;
+
+ if (policy->policy == CPUFREQ_POLICY_PERFORMANCE) {
+
+ ag101_freqs_table = ag101_run_freq_table;
+ } else if (policy->policy == CPUFREQ_POLICY_POWERSAVE) {
+
+ ag101_freqs_table = ag101_turbo_freq_table;
+ } else {
+ printk
+ ("CPU PXA: Unknown policy found. Using CPUFREQ_POLICY_PERFORMANCE\n");
+ ag101_freqs_table = ag101_run_freq_table;
+ }
+
+ printk("Verified CPU policy: %dKhz min to %dKhz max\n", policy->min,
+ policy->max);
+
+ return cpufreq_frequency_table_verify(policy, ag101_freqs_table);
+}
+
+static int cal_edivahbclk(int div)
+{
+
+ switch (div) {
+
+ case 1:
+ case 2:
+ case 3:
+ case 4:
+ case 5:
+ case 6:
+ return --div;
+ case 8:
+ return 8;
+ case 10:
+ return 9;
+ case 12:
+ return 10;
+ case 14:
+ return 11;
+ case 15:
+ return 12;
+ case 18:
+ return 13;
+ case 20:
+ return 14;
+ default:
+ printk("Error: No such CPU/AHB frequency ratio %d", div);
+ }
+
+ return 9;
+}
+
+void start_fcs(unsigned int pll, unsigned int frange, unsigned int div)
+{
+
+ /* PDLLCR0 */
+ REG32(PMU_FTPMU010_VA_BASE + 0x30) &= ~0x00003ff8; /* clear PLL1NS and PLL1FRANG fields */
+ REG32(PMU_FTPMU010_VA_BASE + 0x30) |= (pll << 3); /* set PLL1NS */
+ REG32(PMU_FTPMU010_VA_BASE + 0x30) |= (frange << 12); /* set PLL1FRANG */
+
+ /* PMODE */
+ REG32(PMU_FTPMU010_VA_BASE + 0x0c) &= ~0x000000ff; /* clear EDIVAHBCLK field */
+ REG32(PMU_FTPMU010_VA_BASE + 0x0c) |= (div << 4); /* set EDIVAHBCLK [7:4] */
+ REG32(PMU_FTPMU010_VA_BASE + 0x0c) |= (1UL << 2); /* [2]: FCS */
+
+ __asm__ __volatile__("msync all");
+ __asm__ __volatile__("isb");
+ __asm__ __volatile__("standby wake_grant");
+ REG32(PMU_FTPMU010_VA_BASE + 0x30) |= (1UL << 16); /* PDLLCR0 bit[16]==1:disable dll */
+}
+
+void end_fcs(void)
+{
+
+ /* Leave this function as a place marker. */
+}
+
+static int nds32_fcs_handler(int irq, void *dev_id)
+{
+
+ REG32(PMU_FTPMU010_VA_BASE + 0x20) = (1UL << 17); /* Clear IntFCS PMSR[17] */
+ REG32(PMU_FTPMU010_VA_BASE + 0x0c) &= ~(1UL << 2); /* Power Mode Register */
+
+ return 1;
+}
+
+static int ag101_speedstep(int idx)
+{
+
+ unsigned int pll, frange, div;
+ unsigned long flags = 0;
+ int irq, saved_irq_mask;
+ void (*do_fcs) (unsigned int pll, unsigned int frange,
+ unsigned int div);
+
+#if USE_CACHE
+
+ int i;
+ int line_size = CACHE_LINE_SIZE(ICACHE);
+ unsigned long start = ((unsigned long)start_fcs) & ~(line_size - 1);
+ unsigned long end =
+ (((unsigned long)end_fcs) + line_size) & ~(line_size - 1);
+
+ printk("&start_fcs(): 0x%08lx, aligned to: 0x%08lx\n",
+ (unsigned long)start_fcs, start);
+ printk("&end_fcs(): 0x%08lx, aligned to: 0x%08lx\n",
+ (unsigned long)end_fcs, end);
+
+ for (i = start; i <= end; i += CACHE_LINE_SIZE(ICACHE))
+ __asm__ volatile ("\n\tcctl %0, L1I_VA_FILLCK"::
+ "r" (i):"memory");
+
+ do_fcs = start_fcs;
+#else
+ unsigned long buf, aligned_buf, len = PAGE_SIZE;
+
+ buf = (unsigned long)kmalloc(0x100000 + 1000, GFP_KERNEL);
+ if (!buf)
+ printk("Error: kmalloc( base) failed\n");
+
+ aligned_buf = (buf + 0x100000 - 1) & 0xFFF00000;
+
+ if (sys_lmmap(LM_ILM, aligned_buf, aligned_buf + 0x1000, 0, NULL)) {
+ printk("Error: lmmap failed, can't scale frequency.\n");
+#ifdef CONFIG_CPU_FREQ_DEBUG
+ WARN_ON(1);
+#endif
+ return 0;
+ }
+
+ if (((GET_ILMB() & ILMB_mskILMSZ) >> ILMB_offILMSZ) == 9)
+ len = 0x400;
+ else if (((GET_ILMB() & ILMB_mskILMSZ) >> ILMB_offILMSZ) == 10)
+ len = 0x800;
+ memcpy((unsigned char *)aligned_buf, (unsigned char *)start_fcs, len);
+
+ do_fcs = (void *)aligned_buf;
+#endif
+ pll = ag101_run_freqs[idx].pll;
+ div = cal_edivahbclk(ag101_run_freqs[idx].div);
+ frange = ag101_run_freqs[idx].frange;
+
+ irq =
+ request_irq(NDS32_FCS_IRQ, nds32_fcs_handler,
+ IRQF_DISABLED | IRQF_TRIGGER_FALLING,
+ "NDS32 Frequency Change Sequence",
+ (void *)ag101_run_freqs);
+ if (irq < 0)
+ printk(KERN_ERR "Error: unable to request FCS IRQ%d\n",
+ NDS32_FCS_IRQ);
+
+ local_irq_save(flags);
+
+ saved_irq_mask = REG32(INTC_FTINTC010_VA_BASE + 0x04);
+ REG32(INTC_FTINTC010_VA_BASE + 0x04) = (1UL << NDS32_FCS_IRQ);
+
+ do_fcs(pll, frange, div);
+
+ REG32(INTC_FTINTC010_VA_BASE + 0x04) = saved_irq_mask;
+
+ local_irq_restore(flags);
+ free_irq(NDS32_FCS_IRQ, ag101_run_freqs);
+
+#if USE_CACHE
+ for (i = start; i <= end; i += CACHE_LINE_SIZE(ICACHE))
+ __asm__ volatile ("\n\tcctl %0, L1I_VA_ULCK"::"r" (i):"memory");
+#else
+ if (sys_lmunmap(aligned_buf, 0))
+ printk("Error: lmunmap failed\n");
+
+ kfree((void *)buf);
+#endif
+ return 1;
+}
+
+static int ag101_set_target(struct cpufreq_policy *policy,
+ unsigned int target_freq, unsigned int relation)
+{
+
+ unsigned int idx;
+ struct cpufreq_frequency_table *ag101_freqs_table;
+ struct ag101_freq_struct *ag101_freq_settings;
+ struct cpufreq_freqs freqs;
+
+ /* Get the current policy */
+ if (policy->policy == CPUFREQ_POLICY_PERFORMANCE) {
+
+ ag101_freq_settings = ag101_run_freqs;
+ ag101_freqs_table = ag101_run_freq_table;
+ } else if (policy->policy == CPUFREQ_POLICY_POWERSAVE) {
+
+ ag101_freq_settings = ag101_turbo_freqs;
+ ag101_freqs_table = ag101_turbo_freq_table;
+ } else {
+ printk
+ ("Unknown FCS policy found. Using CPUFREQ_POLICY_PERFORMANCE\n");
+ ag101_freq_settings = ag101_run_freqs;
+ ag101_freqs_table = ag101_run_freq_table;
+ }
+
+ /* Lookup the next frequency */
+ if (cpufreq_frequency_table_target
+ (policy, ag101_freqs_table, target_freq, relation, &idx))
+ return -EINVAL;
+
+ freqs.old = policy->cur;
+ freqs.new = ag101_freq_settings[idx].khz;
+ freqs.cpu = policy->cpu;
+
+ /*
+ * Tell everyone what we're about to do...
+ * you should add a notify client with any platform specific
+ * Vcc changing capability
+ */
+ cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE);
+
+ if (freqs.new != freqs.old) {
+ if (!ag101_speedstep(idx))
+ return -ENODEV;
+ }
+
+ /*
+ * Tell everyone what we've just done...
+ * you should add a notify client with any platform specific
+ * SDRAM refresh timer adjustments
+ */
+ cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE);
+
+ return 0;
+}
+
+static int ag101_cpufreq_init(struct cpufreq_policy *policy)
+{
+
+ int i;
+ /* set default policy and cpuinfo */
+ policy->governor = CPUFREQ_DEFAULT_GOVERNOR;
+ policy->policy = CPUFREQ_POLICY_PERFORMANCE;
+ policy->cpuinfo.max_freq = AG101_MAX_FREQ;
+ policy->cpuinfo.min_freq = AG101_MIN_FREQ;
+ policy->cpuinfo.transition_latency = 1000; /* FIXME: 1 ms, assumed */
+ policy->cur = ag101_cpufreq_get(0); /* current freq */
+ policy->min = policy->max = policy->cur;
+
+ /* Generate the run cpufreq_frequency_table struct */
+ for (i = 0; i < NUM_RUN_FREQS; i++) {
+
+ ag101_run_freq_table[i].frequency = ag101_run_freqs[i].khz;
+ ag101_run_freq_table[i].index = i;
+ }
+
+ ag101_run_freq_table[i].frequency = CPUFREQ_TABLE_END;
+
+ /* Generate the turbo cpufreq_frequency_table struct */
+ for (i = 0; i < NUM_TURBO_FREQS; i++) {
+
+ ag101_turbo_freq_table[i].frequency = ag101_turbo_freqs[i].khz;
+ ag101_turbo_freq_table[i].index = i;
+ }
+
+ ag101_turbo_freq_table[i].frequency = CPUFREQ_TABLE_END;
+
+ printk("CPU frequency change support initialized\n");
+
+ return 0;
+}
+
+static struct cpufreq_driver ag101_cpufreq_driver = {
+
+ .verify = ag101_verify_policy,
+ .target = ag101_set_target,
+ .init = ag101_cpufreq_init,
+ .get = ag101_cpufreq_get,
+ .name = "AG101",
+};
+
+static int __init ag101_cpu_init(void)
+{
+
+ if (CPU_IS_N1213_43U1HA0() || CPU_IS_N1213_43U1HB0()) {
+
+ /* Clear IntFS, IntFCS and irq8 */
+ REG32(PMU_FTPMU010_VA_BASE + 0x20) = (1UL << 16);
+ return cpufreq_register_driver(&ag101_cpufreq_driver);
+ } else
+ return -ENODEV;
+}
+
+static void __exit ag101_cpu_exit(void)
+{
+
+ if (CPU_IS_N1213_43U1HA0() || CPU_IS_N1213_43U1HB0())
+ cpufreq_unregister_driver(&ag101_cpufreq_driver);
+}
+
+MODULE_AUTHOR("Andes Technology Corporation");
+MODULE_DESCRIPTION("CPU frequency changing driver for the AG101 architecture");
+MODULE_LICENSE("GPL");
+module_init(ag101_cpu_init);
+module_exit(ag101_cpu_exit);
diff -Nur linux-3.4.113.orig/arch/nds32/platforms/ag101/devices.c linux-3.4.113/arch/nds32/platforms/ag101/devices.c
--- linux-3.4.113.orig/arch/nds32/platforms/ag101/devices.c 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/platforms/ag101/devices.c 2016-12-01 20:59:24.372613522 +0100
@@ -0,0 +1,94 @@
+#include <linux/serial_8250.h>
+#include <asm/mach-types.h>
+#include <asm/sizes.h>
+#include <asm/mach/arch.h>
+#include <asm/mach/map.h>
+#include <asm/spec.h>
+#include <asm/intc.h>
+#include <asm/timer.h>
+
+const struct map_desc platform_io_desc[] __initdata = {
+ {UART0_VA_BASE, UART0_PA_BASE, PAGE_SIZE, MT_DEVICE_NCB},
+ {UART1_VA_BASE, UART1_PA_BASE, PAGE_SIZE, MT_DEVICE_NCB},
+ {INTC_FTINTC010_0_VA_BASE, INTC_FTINTC010_0_PA_BASE, PAGE_SIZE,
+ MT_DEVICE_NCB},
+ {TIMER_FTTMR010_0_VA_BASE, TIMER_FTTMR010_0_PA_BASE, PAGE_SIZE,
+ MT_DEVICE_NCB},
+ {SSP_FTSSP010_0_VA_BASE, SSP_FTSSP010_0_PA_BASE, PAGE_SIZE,
+ MT_DEVICE_NCB},
+ {PMU_FTPMU010_0_VA_BASE, PMU_FTPMU010_0_PA_BASE, PAGE_SIZE,
+ MT_DEVICE_NCB},
+ {MAC_FTMAC100_0_VA_BASE, MAC_FTMAC100_0_PA_BASE, PAGE_SIZE,
+ MT_DEVICE_NCB},
+ {SDC_FTSDC010_0_VA_BASE, SDC_FTSDC010_0_PA_BASE, PAGE_SIZE,
+ MT_DEVICE_NCB},
+ {RTC_FTRTC010_0_VA_BASE, RTC_FTRTC010_0_PA_BASE, PAGE_SIZE,
+ MT_DEVICE_NCB},
+ {WDT_FTWDT010_0_VA_BASE, WDT_FTWDT010_0_PA_BASE, PAGE_SIZE,
+ MT_DEVICE_NCB},
+ {GPIO_FTGPIO010_0_VA_BASE, GPIO_FTGPIO010_0_PA_BASE, PAGE_SIZE,
+ MT_DEVICE_NCB},
+ {CFC_FTCFC010_0_VA_BASE, CFC_FTCFC010_0_PA_BASE, PAGE_SIZE,
+ MT_DEVICE_NCB},
+ {LCD_FTLCDC100_0_VA_BASE, LCD_FTLCDC100_0_PA_BASE, PAGE_SIZE,
+ MT_DEVICE_NCB},
+ {I2C_FTI2C010_0_VA_BASE, I2C_FTI2C010_0_PA_BASE, PAGE_SIZE,
+ MT_DEVICE_NCB},
+ {DMAC_FTDMAC020_0_VA_BASE, DMAC_FTDMAC020_0_PA_BASE, PAGE_SIZE,
+ MT_DEVICE_NCB},
+ {APBBRG_FTAPBBRG020S_0_VA_BASE, APBBRG_FTAPBBRG020S_0_PA_BASE,
+ PAGE_SIZE, MT_DEVICE_NCB},
+ {KMI_FTKBC010_0_VA_BASE, KMI_FTKBC010_0_PA_BASE, PAGE_SIZE,
+ MT_DEVICE_NCNB},
+ {KMI_FTKBC010_1_VA_BASE, KMI_FTKBC010_1_PA_BASE, PAGE_SIZE,
+ MT_DEVICE_NCNB},
+ {USB_FUSB220_0_VA_BASE, USB_FUSB220_0_PA_BASE, PAGE_SIZE,
+ MT_DEVICE_NCNB},
+ {PCIIO_0_VA_BASE, PCIIO_0_PA_BASE, 0x000FF000, MT_DEVICE_NCB},
+ {PCIC_FTPCI100_0_VA_BASE, PCIC_FTPCI100_0_PA_BASE, PAGE_SIZE,
+ MT_DEVICE_NCB},
+ {LED_VA_BASE, LED_PA_BASE, PAGE_SIZE, MT_DEVICE_NCB},
+ {SDMC_FTSDMC021_VA_BASE, SDMC_FTSDMC021_PA_BASE, PAGE_SIZE,
+ MT_DEVICE_NCB},
+ {L2CC_VA_BASE, L2CC_PA_BASE, PAGE_SIZE, MT_DEVICE_NCB}
+};
+
+static void __init platform_map_io(void)
+{
+ iotable_init((struct map_desc *)platform_io_desc,
+ ARRAY_SIZE(platform_io_desc));
+}
+
+static struct uart_port uart0 = {
+ .membase = (void __iomem *)UART0_VA_BASE,
+ .irq = UART0_IRQ,
+ .uartclk = CONFIG_UART_CLK,
+ .regshift = 2,
+ .iotype = UPIO_MEM,
+ .flags = UPF_SKIP_TEST | UPF_BOOT_AUTOCONF,
+ .line = 0,
+ .mapbase = UART0_PA_BASE,
+};
+
+static struct uart_port uart1 = {
+ .membase = (void __iomem *)UART1_VA_BASE,
+ .irq = UART1_IRQ,
+ .uartclk = CONFIG_UART_CLK,
+ .regshift = 2,
+ .iotype = UPIO_MEM,
+ .flags = UPF_SKIP_TEST | UPF_BOOT_AUTOCONF,
+ .line = 1,
+ .mapbase = UART1_PA_BASE,
+};
+
+void ag101_calc_ahb_clk(void);
+static void __init soc_init(void)
+{
+ ag101_calc_ahb_clk();
+ early_serial_setup(&uart0);
+ early_serial_setup(&uart1);
+}
+
+MACHINE_START(FARADAY, PLATFORM_NAME)
+ .param_offset = BOOT_PARAMETER_PA_BASE,.map_io = platform_map_io,.init_irq = platform_init_irq,.timer = &platform_timer, /* defined in timer.c */
+ .init_machine = soc_init, MACHINE_END
diff -Nur linux-3.4.113.orig/arch/nds32/platforms/ag101/fia320.c linux-3.4.113/arch/nds32/platforms/ag101/fia320.c
--- linux-3.4.113.orig/arch/nds32/platforms/ag101/fia320.c 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/platforms/ag101/fia320.c 2016-12-01 20:59:24.372613522 +0100
@@ -0,0 +1,103 @@
+/*
+ * linux/arch/nds32/platforms/ag101/fia320.c
+ *
+ * Faraday A320D Platform Dependent Functions
+ *
+ * Copyright (C) 2005 Faraday Corp. (http://www.faraday-tech.com)
+ * Copyright (C) 2009 Andes Technology Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * ChangeLog
+ *
+ * Luke Lee 09/26/2005 Created
+ * Peter Liao 09/29/2005 Port dynamically getting AHB clock
+ */
+
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/pm.h>
+#include <linux/sched.h>
+#include <linux/irq.h>
+
+#include <asm/hardware.h>
+#include <asm/spec.h>
+
+#ifdef CONFIG_AUTO_SYS_CLK
+#include <nds32_intrinsic.h>
+#define AG101B0 (0x0c020003)
+
+/*
+ * Table for ahb divisor, PMODE[07:04]
+ */
+static const int ahb_div[16] = {
+ 1, 2, 3, 4, 5, 6, 3, 5,
+ 8, 10, 12, 14, 15, 18, 20, -1
+};
+
+/* ag101_get_ahb_clk()
+ *
+ * return AHB clock in Hz.
+ */
+static int ahbclk;
+void ag101_calc_ahb_clk(void)
+{
+ /*
+ * FIXME: We should not put AG101 term in here, Harry@Oct.23.2007
+ */
+ const unsigned int osc = 10; // OSC in MHz
+ unsigned int mul, div, cpu, pll;
+ unsigned int ahb = 0; // ahb clk in Hz
+ unsigned int cpu_ver;
+
+ mul = (REG32(PMU_FTPMU010_0_VA_BASE + 0x30) >> 3) & 0x01ff; // pll1 mul
+ div = (REG32(PMU_FTPMU010_0_VA_BASE + 0x4) >> 8) & 0x000f; // pll1 div
+ ahb = (REG32(PMU_FTPMU010_0_VA_BASE + 0x4) >> 4) & 0x000f; // ahb div
+ div += 1;
+
+ pll = (osc * mul / div); // depend on OSC.
+
+ //AG101B0 PLL divider fix
+ cpu_ver = __nds32__mfsr(NDS32_SR_CPU_VER);
+ if (AG101B0 == cpu_ver)
+ pll >>= 1;
+
+ if (-1 != ahb_div[ahb]) {
+ if ((ahb == 6) || (ahb == 7)) // special cases for 3:2 & 5:2
+ cpu = pll >> 1; // divide by 2
+ else
+ cpu = pll;
+
+ ahb = pll / ahb_div[ahb]; // become ahb clk in MHz.
+
+ printk("AG101 auto-detected AHB clock: CPU/AHB=%uMHz/%uMHz\n",
+ cpu, ahb);
+ ahb *= 1000000; // become ahb clk in Hz.
+ ahbclk = (int)ahb;
+ } else {
+ printk("Unknown AHB divisor:0x%x\n", ahb);
+ ahbclk = 0;
+ }
+
+ ahbclk = (int)ahb;
+}
+
+int ag101_get_ahb_clk(void)
+{
+ return ahbclk;
+}
+
+EXPORT_SYMBOL(ag101_get_ahb_clk);
+#endif
diff -Nur linux-3.4.113.orig/arch/nds32/platforms/ag101/freq-scaling.c linux-3.4.113/arch/nds32/platforms/ag101/freq-scaling.c
--- linux-3.4.113.orig/arch/nds32/platforms/ag101/freq-scaling.c 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/platforms/ag101/freq-scaling.c 2016-12-01 20:59:24.372613522 +0100
@@ -0,0 +1,367 @@
+/*
+ * linux/arch/nds32/platforms/ag101/cpu-fcs.c
+ *
+ * Copyright (C) 2002,2003 Intrinsyc Software
+ * Copyright (C) 2009 Andes Technology Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * History:
+ * 31-Jul-2002 : Initial version [FB]
+ * 29-Jan-2003 : added PXA255 support [FB]
+ * 20-Apr-2003 : ported to v2.5 (Dustin McIntire, Sensoria Corp.)
+ * 18-Jun-2008 : ported to NDS32 architecture ( Roy Lee, Andestech Corp.)
+ *
+ * Note:
+ * This driver may change the memory bus clock rate, but will not do any
+ * platform specific access timing changes... for example if you have flash
+ * memory connected to CS0, you will need to register a platform specific
+ * notifier which will adjust the memory access strobes to maintain a
+ * minimum strobe width.
+ *
+ */
+#include <linux/module.h>
+#include <linux/cpufreq.h>
+#include <linux/interrupt.h>
+
+#include <asm/hardware.h>
+#include <asm/localmem.h>
+#include <asm/system.h>
+#include <asm/nds32.h>
+#include <asm/irq_regs.h>
+
+#define NDS32_FCS_IRQ 8
+#define AG101_MIN_FREQ 70000
+#define AG101_MAX_FREQ 420000
+#define OSC_KHZ 10000 /* 10 MHz AG101 */
+
+#define USE_CACHE 0
+struct ag101_freq_struct {
+
+ unsigned int khz; /* cpu_clk in khz */
+ unsigned int sf; /* scaling factor */
+ unsigned int cr; /* clock ratio */
+};
+
+struct ag101_freq_struct ag101_run_freqs[] = {
+
+ /* khz , sf, cr pll/cpu/ahb/apb */
+ {AG101_MAX_FREQ / 6, 6, 1}, /* 420/070/070/035 */
+ {AG101_MAX_FREQ / 1, 1, 6}, /* 420/420/070/035 */
+ {0}
+};
+
+#define NUM_RUN_FREQS ARRAY_SIZE( ag101_run_freqs)
+static struct cpufreq_frequency_table ag101_run_freq_table[NUM_RUN_FREQS + 1];
+
+/* Use the turbo mode frequencies for the CPUFREQ_POLICY_POWERSAVE policy */
+static struct ag101_freq_struct ag101_turbo_freqs[] = {
+
+ /* khz , sf, cr pll/cpu/ahb/apb */
+ {AG101_MAX_FREQ / 6, 6, 1}, /* 420/070/070/035 */
+ {AG101_MAX_FREQ / 1, 1, 6}, /* 420/420/070/035 */
+ {0}
+};
+
+#define NUM_TURBO_FREQS ARRAY_SIZE( ag101_turbo_freqs)
+static struct cpufreq_frequency_table ag101_turbo_freq_table[NUM_TURBO_FREQS +
+ 1];
+
+/* Generic helper function get CPU clocks in kHz */
+unsigned int ag101_cpufreq_get(unsigned int dummy)
+{
+
+ unsigned int pll = (REG32(PMU_FTPMU010_VA_BASE + 0x30) >> 3UL) & 0x01ff; /* pll */
+ unsigned int sf = (REG32(PMU_FTPMU010_VA_BASE + 0x0c) >> 8UL) & 0x0f; /* scaling factor */
+
+ return OSC_KHZ * pll / (sf + 1);
+}
+
+/* find a valid frequency point */
+static int ag101_verify_policy(struct cpufreq_policy *policy)
+{
+
+ struct cpufreq_frequency_table *ag101_freqs_table;
+
+ if (policy->policy == CPUFREQ_POLICY_PERFORMANCE) {
+
+ ag101_freqs_table = ag101_run_freq_table;
+ } else if (policy->policy == CPUFREQ_POLICY_POWERSAVE) {
+
+ ag101_freqs_table = ag101_turbo_freq_table;
+ } else {
+ printk
+ ("CPU PXA: Unknown policy found. Using CPUFREQ_POLICY_PERFORMANCE\n");
+ ag101_freqs_table = ag101_run_freq_table;
+ }
+
+ printk("Verified CPU policy: %dKhz min to %dKhz max\n", policy->min,
+ policy->max);
+
+ return cpufreq_frequency_table_verify(policy, ag101_freqs_table);
+}
+
+void start_fcs(unsigned int sf, unsigned cr)
+{
+
+ /* set EFSF in PMODE [11:8] */
+ REG32(PMU_FTPMU010_VA_BASE + 0x0c) &= ~(0xfUL << 8);
+ REG32(PMU_FTPMU010_VA_BASE + 0x0c) |= (sf << 8);
+
+ /* set EDIVAHBCLK [7:4] */
+ REG32(PMU_FTPMU010_VA_BASE + 0x0c) &= ~(0xffUL << 0);
+ REG32(PMU_FTPMU010_VA_BASE + 0x0c) |= (cr << 4);
+
+ /* PMR[1]: scaling mode */
+ REG32(PMU_FTPMU010_VA_BASE + 0x0c) |= (1UL << 1);
+
+ __asm__ __volatile__("msync all");
+ __asm__ __volatile__("isb");
+ __asm__ __volatile__("standby wake_grant");
+ // REG32( PMU_FTPMU010_VA_BASE + 0x30) |= ( 1UL << 16); /* PDLLCR0 bit[16]==1:disable dll */
+ REG32(PMU_FTPMU010_VA_BASE + 0x0c) &= ~(1UL << 1); /* Power Mode Register */
+}
+
+void end_fcs(void)
+{
+
+ /* Leave this function as a place marker. */
+}
+
+static int cal_edivahbclk(int div)
+{
+
+ switch (div) {
+
+ case 1:
+ case 2:
+ case 3:
+ case 4:
+ case 5:
+ case 6:
+ return --div;
+ case 8:
+ return 8;
+ case 10:
+ return 9;
+ case 12:
+ return 10;
+ case 14:
+ return 11;
+ case 15:
+ return 12;
+ case 18:
+ return 13;
+ case 20:
+ return 14;
+ default:
+ printk("Error: No such CPU/AHB frequency ratio %d", div);
+ }
+
+ return 9;
+}
+
+static int ag101_speedstep(int idx)
+{
+
+ unsigned int sf, cr;
+ unsigned long flags = 0;
+ void (*do_fcs) (unsigned int efsf, unsigned int edivhbaclk);
+
+#if USE_CACHE
+
+ int i;
+ int line_size = CACHE_LINE_SIZE(ICACHE);
+ unsigned long start = ((unsigned long)start_fcs) & ~(line_size - 1);
+ unsigned long end =
+ (((unsigned long)end_fcs) + line_size) & ~(line_size - 1);
+
+ printk("&start_fcs(): 0x%08lx, aligned to: 0x%08lx\n",
+ (unsigned long)start_fcs, start);
+ printk("&end_fcs(): 0x%08lx, aligned to: 0x%08lx\n",
+ (unsigned long)end_fcs, end);
+
+ for (i = start; i <= end; i += CACHE_LINE_SIZE(ICACHE))
+ __asm__ volatile ("\n\tcctl %0, L1I_VA_FILLCK"::
+ "r" (i):"memory");
+
+ do_fcs = start_fcs;
+#else
+ unsigned long buf, aligned_buf, len = PAGE_SIZE;
+
+ buf = (unsigned long)kmalloc(0x100000 + 1000, GFP_KERNEL);
+ if (!buf)
+ printk("Error: kmalloc( base) failed\n");
+
+ aligned_buf = (buf + 0x100000 - 1) & 0xFFF00000;
+
+ if (sys_lmmap(LM_ILM, aligned_buf, aligned_buf + 0x1000, 0, NULL)) {
+ printk("Error: lmmap failed, can't scale frequency.\n");
+#ifdef CONFIG_CPU_FREQ_DEBUG
+ WARN_ON(1);
+#endif
+ return 0;
+ }
+
+ if (((GET_ILMB() & ILMB_mskILMSZ) >> ILMB_offILMSZ) == 9)
+ len = 0x400;
+ else if (((GET_ILMB() & ILMB_mskILMSZ) >> ILMB_offILMSZ) == 10)
+ len = 0x800;
+ memcpy((unsigned char *)aligned_buf, (unsigned char *)start_fcs, len);
+
+ do_fcs = (void *)aligned_buf;
+#endif
+ sf = ag101_run_freqs[idx].sf - 1;
+ cr = cal_edivahbclk(ag101_run_freqs[idx].cr);
+
+ local_irq_save(flags);
+ do_fcs(sf, cr);
+ local_irq_restore(flags);
+
+#if USE_CACHE
+ for (i = start; i <= end; i += CACHE_LINE_SIZE(ICACHE))
+ __asm__ volatile ("\n\tcctl %0, L1I_VA_ULCK"::"r" (i):"memory");
+#else
+ if (sys_lmunmap(aligned_buf, 0))
+ printk("Error: lmunmap failed\n");
+
+ kfree((void *)buf);
+#endif
+ return 1;
+}
+
+static int ag101_set_target(struct cpufreq_policy *policy,
+ unsigned int target_freq, unsigned int relation)
+{
+
+ unsigned int idx;
+ struct cpufreq_frequency_table *ag101_freqs_table;
+ struct ag101_freq_struct *ag101_freq_settings;
+ struct cpufreq_freqs freqs;
+
+ /* Get the current policy */
+ if (policy->policy == CPUFREQ_POLICY_PERFORMANCE) {
+
+ ag101_freq_settings = ag101_run_freqs;
+ ag101_freqs_table = ag101_run_freq_table;
+ } else if (policy->policy == CPUFREQ_POLICY_POWERSAVE) {
+
+ ag101_freq_settings = ag101_turbo_freqs;
+ ag101_freqs_table = ag101_turbo_freq_table;
+ } else {
+ printk
+ ("Unknown FCS policy found. Using CPUFREQ_POLICY_PERFORMANCE\n");
+ ag101_freq_settings = ag101_run_freqs;
+ ag101_freqs_table = ag101_run_freq_table;
+ }
+
+ /* Lookup the next frequency */
+ if (cpufreq_frequency_table_target
+ (policy, ag101_freqs_table, target_freq, relation, &idx))
+ return -EINVAL;
+
+ freqs.old = policy->cur;
+ freqs.new = ag101_freq_settings[idx].khz;
+ freqs.cpu = policy->cpu;
+
+ /*
+ * Tell everyone what we're about to do...
+ * you should add a notify client with any platform specific
+ * Vcc changing capability
+ */
+ cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE);
+
+ if (freqs.new != freqs.old) {
+
+ if (!ag101_speedstep(idx))
+ return -ENODEV;
+ }
+
+ /*
+ * Tell everyone what we've just done...
+ * you should add a notify client with any platform specific
+ * SDRAM refresh timer adjustments
+ */
+ cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE);
+
+ return 0;
+}
+
+static int ag101_cpufreq_init(struct cpufreq_policy *policy)
+{
+
+ int i;
+ /* set default policy and cpuinfo */
+ policy->governor = CPUFREQ_DEFAULT_GOVERNOR;
+ policy->policy = CPUFREQ_POLICY_PERFORMANCE;
+ policy->cpuinfo.max_freq = AG101_MAX_FREQ;
+ policy->cpuinfo.min_freq = AG101_MIN_FREQ;
+ policy->cpuinfo.transition_latency = 1000; /* FIXME: 1 ms, assumed */
+ policy->cur = ag101_cpufreq_get(0); /* current freq */
+ policy->min = policy->max = policy->cur;
+
+ /* Generate the run cpufreq_frequency_table struct */
+ for (i = 0; i < NUM_RUN_FREQS; i++) {
+
+ ag101_run_freq_table[i].frequency = ag101_run_freqs[i].khz;
+ ag101_run_freq_table[i].index = i;
+ }
+
+ ag101_run_freq_table[i].frequency = CPUFREQ_TABLE_END;
+
+ /* Generate the turbo cpufreq_frequency_table struct */
+ for (i = 0; i < NUM_TURBO_FREQS; i++) {
+
+ ag101_turbo_freq_table[i].frequency = ag101_turbo_freqs[i].khz;
+ ag101_turbo_freq_table[i].index = i;
+ }
+
+ ag101_turbo_freq_table[i].frequency = CPUFREQ_TABLE_END;
+
+ printk("CPU frequency change support initialized\n");
+
+ return 0;
+}
+
+static struct cpufreq_driver ag101_cpufreq_driver = {
+
+ .verify = ag101_verify_policy,
+ .target = ag101_set_target,
+ .init = ag101_cpufreq_init,
+ .get = ag101_cpufreq_get,
+ .name = "AG101",
+};
+
+static int __init ag101_cpu_init(void)
+{
+
+ if (CPU_IS_N1213_43U1HA0() || CPU_IS_N1213_43U1HB0())
+ return cpufreq_register_driver(&ag101_cpufreq_driver);
+ else
+ return -ENODEV;
+}
+
+static void __exit ag101_cpu_exit(void)
+{
+
+ if (CPU_IS_N1213_43U1HA0() || CPU_IS_N1213_43U1HB0())
+ cpufreq_unregister_driver(&ag101_cpufreq_driver);
+}
+
+MODULE_AUTHOR("Andes Technology Corporation");
+MODULE_DESCRIPTION("CPU frequency changing driver for the AG101 architecture");
+MODULE_LICENSE("GPL");
+module_init(ag101_cpu_init);
+module_exit(ag101_cpu_exit);
diff -Nur linux-3.4.113.orig/arch/nds32/platforms/ag101/Kconfig linux-3.4.113/arch/nds32/platforms/ag101/Kconfig
--- linux-3.4.113.orig/arch/nds32/platforms/ag101/Kconfig 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/platforms/ag101/Kconfig 2016-12-01 20:59:24.372613522 +0100
@@ -0,0 +1,9 @@
+menu "AG101 Platform Options"
+
+config AUTO_SYS_CLK
+ bool "Automatic AHB Clock Detection"
+ default y
+ help
+ Automatic detection of AHB clock
+
+endmenu
diff -Nur linux-3.4.113.orig/arch/nds32/platforms/ag101/Makefile linux-3.4.113/arch/nds32/platforms/ag101/Makefile
--- linux-3.4.113.orig/arch/nds32/platforms/ag101/Makefile 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/platforms/ag101/Makefile 2016-12-01 20:59:24.372613522 +0100
@@ -0,0 +1,5 @@
+obj-y = devices.o
+obj-$(CONFIG_AUTO_SYS_CLK) += fia320.o
+obj-$(CONFIG_PM) += pm.o sleep.o
+obj-$(CONFIG_AG101_CPU_FREQ_FCS) += cpu-fcs.o
+obj-$(CONFIG_AG101_CPU_FREQ_SCALING_MODE) += freq-scaling.o
diff -Nur linux-3.4.113.orig/arch/nds32/platforms/ag101/pm.c linux-3.4.113/arch/nds32/platforms/ag101/pm.c
--- linux-3.4.113.orig/arch/nds32/platforms/ag101/pm.c 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/platforms/ag101/pm.c 2016-12-01 20:59:24.372613522 +0100
@@ -0,0 +1,190 @@
+/*
+ * AG101 Power Management Routines
+ *
+ * Copyright (c) 2007 Harry Pan <harry@andestech.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License.
+ *
+ * Abstract:
+ *
+ * This program is for AG101 power management routines.
+ * It is initail referred from 2.6.11 SA1100 PM driver.
+ *
+ * Revision History:
+ *
+ * Jul.13.2007 Initial code by Harry.
+ */
+#include <linux/init.h>
+#include <linux/suspend.h>
+#include <linux/errno.h>
+#include <linux/time.h>
+#include <linux/delay.h>
+
+#include <asm/hardware.h>
+#include <asm/memory.h>
+#include <asm/system.h>
+#include <asm/mach/time.h>
+#include <asm/cacheflush.h>
+
+extern void ag101_cpu_sleep(void);
+extern void ag101_cpu_resume(void);
+extern void ag101_cpu_resume2(void);
+
+#include <asm/timer.h>
+/*
+ * AG101 PMU sleep mode handler.
+ */
+void ag101_pmu_sleep(void)
+{
+ int i;
+ static int irq_saves[3];
+
+ irq_saves[0] = REG32(INTC_FTINTC010_VA_BASE + 0x4);
+ irq_saves[1] = REG32(INTC_FTINTC010_VA_BASE + 0xc);
+ irq_saves[2] = REG32(INTC_FTINTC010_VA_BASE + 0x10);
+
+ /* save SDRAM settings */
+ for (i = 0; i < 0x30; i += 4)
+ REG32(PMU_FTPMU010_VA_BASE + 0x50 + i) = REG32(SDMC_FTSDMC021_VA_BASE + i); //SDRAMC
+
+ /* set resume return address */
+ REG32(PMU_FTPMU010_VA_BASE + 0x88) =
+ virt_to_phys(ag101_cpu_resume) | 0x10000000;
+ REG32(PMU_FTPMU010_VA_BASE + 0x8c) = (u32) ag101_cpu_resume2;
+ REG32(PMU_FTPMU010_VA_BASE + 0x80) = GET_L1_PPTB();
+
+ /* setup wakeup sources */
+ REG32(PMU_FTPMU010_VA_BASE + 0x14) |= -1;
+ REG32(PMU_FTPMU010_VA_BASE + 0x10) |= 0x1fff;
+
+ cpu_dcache_wbinval_all();
+ cpu_icache_inval_all();
+ SET_CACHE_CTL(GET_CACHE_CTL() & ~CACHE_CTL_mskDC_EN);
+ ag101_cpu_sleep();
+
+#ifndef CONFIG_ANDES_PAGE_SIZE_8KB
+
+ if (CPU_IS_N1213_43U1HA0()) {
+ int tmp = 0;
+ /* Downsize cache to bypass cache aliasing issue */
+
+ if ((CACHE_SET(ICACHE) * CACHE_LINE_SIZE(ICACHE)) > 4096)
+ tmp = 0x02 << SDZ_CTL_offICDZ;
+
+ if ((CACHE_SET(DCACHE) * CACHE_LINE_SIZE(DCACHE)) > 4096)
+ tmp |= 0x02 << SDZ_CTL_offDCDZ;
+
+ SET_SDZ_CTL(tmp);
+ ISB();
+ }
+#endif
+
+ SET_CACHE_CTL(GET_CACHE_CTL() | CACHE_CTL_mskDC_EN);
+ REG32(INTC_FTINTC010_VA_BASE + 0x4) = irq_saves[0];
+ REG32(INTC_FTINTC010_VA_BASE + 0xc) = irq_saves[1];
+ REG32(INTC_FTINTC010_VA_BASE + 0x10) = irq_saves[2];
+}
+
+static int ag101_pm_valid(suspend_state_t state)
+{
+ switch (state) {
+ case PM_SUSPEND_ON:
+ case PM_SUSPEND_STANDBY:
+ case PM_SUSPEND_MEM:
+ return 1;
+
+ default:
+ return 0;
+ }
+}
+
+static int ag101_pm_begin(suspend_state_t state)
+{
+ /* TBD if we need it */
+ return 0;
+}
+
+static unsigned long irq_save;
+static inline void setup_wakeup_event(void)
+{
+ REG32(GPIO_FTGPIO010_VA_BASE + 0x20) = 1;
+ irq_save = REG32(INTC_FTINTC010_VA_BASE + 0x4);
+ REG32(INTC_FTINTC010_VA_BASE + 0x4) &= ~(1 << 19);
+ REG32(INTC_FTINTC010_VA_BASE + 0x4) |= 1 << 13;
+}
+
+static inline void remove_wakeup_event(void)
+{
+ REG32(GPIO_FTGPIO010_VA_BASE + 0x30) = 1;
+ REG32(GPIO_FTGPIO010_VA_BASE + 0x20) = 0;
+ REG32(INTC_FTINTC010_VA_BASE + 0x4) = irq_save;
+}
+
+static inline void cpu_standby(void)
+{
+ asm __volatile__("standby no_wake_grant");
+}
+
+static int ag101_pm_enter(suspend_state_t state)
+{
+ switch (state) {
+ case PM_SUSPEND_STANDBY:
+ setup_wakeup_event();
+ cpu_standby();
+ remove_wakeup_event();
+ return 0;
+ case PM_SUSPEND_MEM:
+ ag101_pmu_sleep();
+ return 0;
+ default:
+ return -EINVAL;
+ }
+}
+
+/*
+ * Called after processes are frozen, but before we shutdown devices.
+ */
+static int ag101_pm_prepare(void)
+{
+ /* TBD if we need it */
+ return 0;
+}
+
+/*
+ * Called after devices are wakeuped, but before processes are thawed.
+ */
+static void ag101_pm_finish(void)
+{
+ /* TBD if we need it */
+}
+
+static void ag101_pm_end(void)
+{
+ /* TBD if we need it */
+}
+
+/*
+ * Set to PM_DISK_FIRMWARE so we can quickly veto suspend-to-disk.
+ */
+static struct platform_suspend_ops ag101_pm_ops = {
+ .valid = ag101_pm_valid,
+ .begin = ag101_pm_begin,
+ .prepare = ag101_pm_prepare,
+ .enter = ag101_pm_enter,
+ .finish = ag101_pm_finish,
+ .end = ag101_pm_end,
+};
+
+static int __init ag101_pm_init(void)
+{
+ printk("PM driver init\n");
+ suspend_set_ops(&ag101_pm_ops);
+ REG32(GPIO_FTGPIO010_VA_BASE + 0x30) = 1;
+ REG32(INTC_FTINTC010_VA_BASE + 0x0c) &= ~(1 << 13);
+ REG32(INTC_FTINTC010_VA_BASE + 0x10) &= ~(1 << 13);
+
+ return 0;
+}
+
+late_initcall(ag101_pm_init);
diff -Nur linux-3.4.113.orig/arch/nds32/platforms/ag101/sleep.S linux-3.4.113/arch/nds32/platforms/ag101/sleep.S
--- linux-3.4.113.orig/arch/nds32/platforms/ag101/sleep.S 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/platforms/ag101/sleep.S 2016-12-01 20:59:24.372613522 +0100
@@ -0,0 +1,118 @@
+/*
+ * AG101 Assembler Sleep/WakeUp Management Routines
+ *
+ * Copyright (c) 2007 Harry Pan <harry@andestech.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License.
+ *
+ * Abstract:
+ *
+ * This program is for AG101 suspend/wakeup.
+ *
+ * Revision History:
+ *
+ * Jul.13.2007 Initial code by Harry.
+ */
+#include <linux/linkage.h>
+#include <asm/assembler.h>
+#include <asm/hardware.h>
+#include <asm/spec.h>
+
+ .text
+
+/* ag101_cpu_suspend()
+ *
+ * Causes AG101 to enter sleep state
+ */
+
+ENTRY(ag101_cpu_sleep)
+ pushm $r0, $r30
+ mfusr $r0, $d0.lo ! $d0 lo byte
+ mfusr $r1, $d0.hi ! $d0 hi byte
+ mfusr $r2, $d1.lo ! $d1 lo byte
+ mfusr $r3, $d1.hi ! $d1 hi byte
+ mfsr $r4, $mr0
+ mfsr $r5, $mr1
+ mfsr $r6, $mr4
+ mfsr $r7, $mr6
+ mfsr $r8, $mr7
+ mfsr $r9, $mr8
+ mfsr $r10, $ir0
+ mfsr $r11, $ir1
+ mfsr $r12, $ir2
+ mfsr $r13, $ir3
+ mfsr $r14, $ir9
+ mfsr $r15, $ir10
+ mfsr $r16, $ir12
+ mfsr $r17, $ir13
+ mfsr $r18, $ir14
+ mfsr $r19, $ir15
+ pushm $r0, $r19
+
+ sethi $r0, hi20(PMU_FTPMU010_0_VA_BASE + 0x84)
+ ori $r2, $r0, lo12(PMU_FTPMU010_0_VA_BASE + 0x84)
+ swi $r31, [$r2]
+
+ lwi $r2, [$r0+#0x0c] ! sleep mode
+ ori $r2, $r2, #1
+ swi $r2, [$r0+#0x0c] ! sleep mode
+ standby wake_grant
+1:
+ b 1b ! loop waiting for sleep
+
+/* ag101_cpu_resume()
+ *
+ * Entry point from boot code back to kernel.
+ *
+ */
+
+ENTRY(ag101_cpu_resume)
+ mfsr $r2, $mr0
+ ori $r2, $r2, #0x6
+#ifdef CONFIG_ANDES_PAGE_SIZE_8KB
+ ori $r2, $r2, #0x1
+#endif
+ mtsr $r2, $mr0
+
+ sethi $r2, hi20(PMU_FTPMU010_0_PA_BASE + 0x80)
+ ori $r2, $r2, lo12(PMU_FTPMU010_0_PA_BASE + 0x80)
+ lwi $r3, [$r2]
+ lwi $r4, [$r2 + 0xc]
+ mtsr $r3, $mr1
+
+ mfsr $r0, $mr8
+ ori $r0, $r0, #0x1
+ mtsr $r0, $mr8
+
+ sethi $r2, hi20(AHB_ATFAHBC020S_0_PA_BASE + 0x88)
+ ori $r2, $r2, lo12(AHB_ATFAHBC020S_0_PA_BASE + 0x88)
+ movi $r3, #0x1
+ swi $r3, [$r2]
+
+ jral.ton $r4, $r4
+
+ENTRY(ag101_cpu_resume2)
+ popm $r0, $r19
+ mtusr $r0, $d0.lo ! $d0 lo byte
+ mtusr $r1, $d0.hi ! $d0 hi byte
+ mtusr $r2, $d1.lo ! $d1 lo byte
+ mtusr $r3, $d1.hi ! $d1 hi byte
+ mtsr $r4, $mr0
+ mtsr $r5, $mr1
+ mtsr $r6, $mr4
+ mtsr $r7, $mr6
+ mtsr $r8, $mr7
+ mtsr $r9, $mr8
+ mtsr $r10, $ir0
+ mtsr $r11, $ir1
+ mtsr $r12, $ir2
+ mtsr $r13, $ir3
+ mtsr $r14, $ir9
+ mtsr $r15, $ir10
+ mtsr $r16, $ir12
+ mtsr $r17, $ir13
+ mtsr $r18, $ir14
+ mtsr $r19, $ir15
+ popm $r0, $r30
+ ret
diff -Nur linux-3.4.113.orig/arch/nds32/platforms/ag101p/devices.c linux-3.4.113/arch/nds32/platforms/ag101p/devices.c
--- linux-3.4.113.orig/arch/nds32/platforms/ag101p/devices.c 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/platforms/ag101p/devices.c 2016-12-01 20:59:24.372613522 +0100
@@ -0,0 +1,104 @@
+#include <linux/serial_8250.h>
+#include <asm/mach-types.h>
+#include <asm/sizes.h>
+#include <asm/mach/arch.h>
+#include <asm/mach/map.h>
+#include <asm/spec.h>
+#include <asm/timer.h>
+
+const struct map_desc platform_io_desc[] __initdata = {
+ {UART0_VA_BASE, UART0_PA_BASE, PAGE_SIZE, MT_DEVICE_NCB},
+ {UART1_VA_BASE, UART1_PA_BASE, PAGE_SIZE, MT_DEVICE_NCB},
+ {INTC_FTINTC010_0_VA_BASE, INTC_FTINTC010_0_PA_BASE, PAGE_SIZE,
+ MT_DEVICE_NCB},
+ {TIMER_FTTMR010_0_VA_BASE, TIMER_FTTMR010_0_PA_BASE, PAGE_SIZE,
+ MT_DEVICE_NCB},
+ {SSP_FTSSP010_0_VA_BASE, SSP_FTSSP010_0_PA_BASE, PAGE_SIZE,
+ MT_DEVICE_NCB},
+ {PMU_FTPMU010_0_VA_BASE, PMU_FTPMU010_0_PA_BASE, PAGE_SIZE,
+ MT_DEVICE_NCB},
+ {MAC_FTMAC100_0_VA_BASE, MAC_FTMAC100_0_PA_BASE, PAGE_SIZE,
+ MT_DEVICE_NCB},
+ {SDC_FTSDC010_0_VA_BASE, SDC_FTSDC010_0_PA_BASE, PAGE_SIZE,
+ MT_DEVICE_NCB},
+ {RTC_FTRTC010_0_VA_BASE, RTC_FTRTC010_0_PA_BASE, PAGE_SIZE,
+ MT_DEVICE_NCB},
+ {WDT_FTWDT010_0_VA_BASE, WDT_FTWDT010_0_PA_BASE, PAGE_SIZE,
+ MT_DEVICE_NCB},
+ {GPIO_FTGPIO010_0_VA_BASE, GPIO_FTGPIO010_0_PA_BASE, PAGE_SIZE,
+ MT_DEVICE_NCB},
+ {CFC_FTCFC010_0_VA_BASE, CFC_FTCFC010_0_PA_BASE, PAGE_SIZE,
+ MT_DEVICE_NCB},
+ {LCD_FTLCDC100_0_VA_BASE, LCD_FTLCDC100_0_PA_BASE, PAGE_SIZE,
+ MT_DEVICE_NCB},
+ {I2C_FTI2C010_0_VA_BASE, I2C_FTI2C010_0_PA_BASE, PAGE_SIZE,
+ MT_DEVICE_NCB},
+ {DMAC_FTDMAC020_0_VA_BASE, DMAC_FTDMAC020_0_PA_BASE, PAGE_SIZE,
+ MT_DEVICE_NCB},
+ {APBBRG_FTAPBBRG020S_0_VA_BASE, APBBRG_FTAPBBRG020S_0_PA_BASE,
+ PAGE_SIZE, MT_DEVICE_NCB},
+ {USB_FOTG2XX_0_VA_BASE, USB_FOTG2XX_0_PA_BASE, PAGE_SIZE,
+ MT_DEVICE_NCB},
+ {PCIIO_0_VA_BASE, PCIIO_0_PA_BASE, (0x000FF000 & PAGE_MASK),
+ MT_DEVICE_NCB},
+ {PCIC_FTPCI100_0_VA_BASE, PCIC_FTPCI100_0_PA_BASE, PAGE_SIZE,
+ MT_DEVICE_NCB},
+ {AHB_ATFAHBC020S_0_VA_BASE, AHB_ATFAHBC020S_0_PA_BASE, PAGE_SIZE,
+ MT_DEVICE_NCB},
+ {LED_VA_BASE, LED_PA_BASE, PAGE_SIZE, MT_DEVICE_NCB},
+ {SDMC_FTSDMC021_VA_BASE, SDMC_FTSDMC021_PA_BASE, PAGE_SIZE,
+ MT_DEVICE_NCB},
+ {L2CC_VA_BASE, L2CC_PA_BASE, PAGE_SIZE, MT_DEVICE_NCB}
+};
+
+static void __init platform_map_io(void)
+{
+ iotable_init((struct map_desc *)platform_io_desc,
+ ARRAY_SIZE(platform_io_desc));
+}
+
+static struct uart_port uart0 = {
+ .membase = (void __iomem *)UART0_VA_BASE,
+ .irq = UART0_IRQ,
+ .uartclk = CONFIG_UART_CLK,
+ .regshift = 2,
+ .iotype = UPIO_MEM,
+ .flags = UPF_SKIP_TEST | UPF_BOOT_AUTOCONF,
+ .line = 0,
+ .mapbase = UART0_PA_BASE,
+};
+
+static struct uart_port uart1 = {
+ .membase = (void __iomem *)UART1_VA_BASE,
+ .irq = UART1_IRQ,
+ .uartclk = CONFIG_UART_CLK,
+ .regshift = 2,
+ .iotype = UPIO_MEM,
+ .flags = UPF_SKIP_TEST | UPF_BOOT_AUTOCONF,
+ .line = 1,
+ .mapbase = UART1_PA_BASE,
+};
+
+static void __init soc_init(void)
+{
+ early_serial_setup(&uart0);
+ early_serial_setup(&uart1);
+}
+
+MACHINE_START(FARADAY, PLATFORM_NAME)
+ .param_offset = BOOT_PARAMETER_PA_BASE,
+ .map_io = platform_map_io,
+ .init_irq = platform_init_irq,
+ .timer = &platform_timer, /* defined in timer.c */
+ .init_machine = soc_init,
+MACHINE_END static struct platform_device usb_dev_otg_host = {
+ .name = "fotg-ehci",
+};
+
+static int __init fotg_init(void)
+{
+ platform_device_register(&usb_dev_otg_host);
+ return 0;
+}
+
+device_initcall(fotg_init);
diff -Nur linux-3.4.113.orig/arch/nds32/platforms/ag101p/interrupt-latency.c linux-3.4.113/arch/nds32/platforms/ag101p/interrupt-latency.c
--- linux-3.4.113.orig/arch/nds32/platforms/ag101p/interrupt-latency.c 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/platforms/ag101p/interrupt-latency.c 2016-12-01 20:59:24.372613522 +0100
@@ -0,0 +1,197 @@
+/*
+ * interrupt_latency v1.0 11/25/01
+ * www.embeddedlinuxinterfacing.com
+ *
+ * The original location of this code is
+ * http://www.embeddedlinuxinterfacing.com/chapters/11/
+ *
+ * Copyright (C) 2001 by Craig Hollabaugh
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Library General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+/*
+ * interrupt_latency.c is based on procfs_example.c by Erik Mouw.
+ * For more information, please see, The Linux Kernel Procfs Guide, Erik Mouw
+ * http://kernelnewbies.org/documents/kdoc/procfs-guide/lkprocfsguide.html
+ */
+
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/proc_fs.h>
+#include <linux/irq.h>
+#include <linux/interrupt.h>
+#include <nds32_intrinsic.h>
+
+#define ILT_MODULE_VERSION "1.0"
+#define MODULE_NAME "interrupt_latency"
+
+#define USE_PFM
+static int interruptcount = 0;
+#ifdef USE_PFM
+static unsigned int start_cycle = 0, finish_cycle = 0;
+static unsigned int start_inst = 0, finish_inst = 0;
+static unsigned int start_int = 0, finish_int = 0;
+#else
+static struct timeval tv1, tv2; /* do_gettimeofday fills these */
+#endif
+
+#define INTERRUPT 9
+
+static struct proc_dir_entry *interrupt_latency_file;
+
+/*
+ * function interrupt_interrupt_latency
+ * This function is the interrupt handler for interrupt 7. It sets the tv2
+ * structure using do_gettimeofday. It then deasserts D7.
+ */
+static irqreturn_t interrupt_interrupt_latency(int irq, void *dev_id)
+{
+ unsigned int ir15, pfm_ctl;
+#ifdef USE_PFM
+ /* disable counter */
+ pfm_ctl = 0x4410000; //cycles, instructions and icache misses
+ //pfm_ctl = 0x4c0000; //instructions and interrupts
+ //pfm_ctl = 0x4510000; //icache accesses and misses
+ __nds32__mtsr(pfm_ctl, NDS32_SR_PFM_CTL); //instructions and interrupts
+ finish_cycle = __nds32__mfsr(NDS32_SR_PFMC0);
+ finish_inst = __nds32__mfsr(NDS32_SR_PFMC2);
+ finish_int = __nds32__mfsr(NDS32_SR_PFMC1);
+#else
+ do_gettimeofday(&tv2);
+#endif
+ /* deassert the interrupt signal */
+ ir15 = __nds32__mfsr(NDS32_SR_INT_PEND);
+ __nds32__mtsr((~0x10000) & ir15, NDS32_SR_INT_PEND);
+ __nds32__dsb();
+
+ interruptcount++;
+ return IRQ_HANDLED;
+}
+
+/*
+ * function proc_read_interrupt_latency
+ * The kernel executes this function when a read operation occurs on
+ * /proc/interrupt_latency. This function sets the tv1 structure. It asserts
+ * D7 which should immediately cause interrupt 7 to occur. The handler
+ * records tv2 and deasserts D7. This function returns the time differential
+ * between tv2 and tv1.
+ */
+static int proc_read_interrupt_latency(char *page, char **start, off_t off,
+ int count, int *eof, void *data)
+{
+ int len;
+ unsigned int ir15, pfm_ctl;
+#ifdef USE_PFM
+ //pfm_ctl = 0x4c0007;
+ //pfm_ctl = 0x4510007;
+ pfm_ctl = 0x4410007;
+ start_cycle = __nds32__mfsr(NDS32_SR_PFMC0);
+ start_inst = __nds32__mfsr(NDS32_SR_PFMC2);
+ start_int = __nds32__mfsr(NDS32_SR_PFMC1);
+ __nds32__mtsr(pfm_ctl, NDS32_SR_PFM_CTL);
+#else
+ do_gettimeofday(&tv1);
+#endif
+ /* assert the interrupt signal */
+ ir15 = __nds32__mfsr(NDS32_SR_INT_PEND);
+ __nds32__mtsr(0x10000 | ir15, NDS32_SR_INT_PEND);
+ __nds32__dsb();
+
+#ifdef USE_PFM
+ len =
+ sprintf(page,
+ "Cnt0 %11u Start %11u Finish %11u Cycles %11u\n"
+ "Cnt2 %11u Start %11u Finish %11u icache miss %11u\n"
+ "Cnt1 %11u Start %11u Finish %11u Instructions %11u\n"
+ "Count %11i\n", ((pfm_ctl & 0x8000) >> 15), start_cycle,
+ finish_cycle, (finish_cycle - start_cycle),
+ ((pfm_ctl & 0xfc00000) >> 22), start_inst, finish_inst,
+ (finish_inst - start_inst), ((pfm_ctl & 0x3f0000) >> 16),
+ start_int, finish_int, (finish_int - start_int),
+ interruptcount);
+#else
+ len = sprintf(page, "Start %9i.%06i\nFinish %9i.%06i\nLatency %17i\n\
+Count %19i\n", (int)tv1.tv_sec, (int)tv1.tv_usec, (int)tv2.tv_sec, (int)tv2.tv_usec, (int)(tv2.tv_usec - tv1.tv_usec), interruptcount);
+#endif
+ *eof = 1;
+ return len;
+}
+
+/*
+ * function init_interrupt_latency
+ * This function creates the /proc directory entry interrupt_latency. It
+ * also configures the parallel port then requests interrupt 7 from Linux.
+ */
+static int __init init_interrupt_latency(void)
+{
+ int rv = 0;
+ unsigned int ir14;
+
+ interrupt_latency_file =
+ create_proc_entry("interrupt_latency", 0444, NULL);
+ if (interrupt_latency_file == NULL) {
+ return -ENOMEM;
+ }
+
+ interrupt_latency_file->data = NULL;
+ interrupt_latency_file->read_proc = &proc_read_interrupt_latency;
+ interrupt_latency_file->write_proc = NULL;
+
+ /* request interrupt from linux */
+ rv = request_irq(INTERRUPT, interrupt_interrupt_latency, IRQF_DISABLED,
+ "interrupt_latency", (void *)NULL);
+ if (rv) {
+ printk("Can't get interrupt %d\n", INTERRUPT);
+ goto no_interrupt_latency;
+ }
+
+ /* unmask SWI */
+ ir14 = __nds32__mfsr(NDS32_SR_INT_MASK);
+ __nds32__mtsr((0x10000 | ir14), NDS32_SR_INT_MASK);
+ __nds32__dsb();
+
+ /* everything initialized */
+ printk(KERN_INFO "%s %s initialized\n", MODULE_NAME,
+ ILT_MODULE_VERSION);
+ return 0;
+
+ /* remove the proc entry on error */
+no_interrupt_latency:
+ remove_proc_entry("interrupt_latency", NULL);
+ return 0;
+}
+
+/*
+ * function cleanup_interrupt_latency
+ * This function frees interrupt then removes the /proc directory entry
+ * interrupt_latency.
+ */
+static void __exit cleanup_interrupt_latency(void)
+{
+ /* free the interrupt */
+ free_irq(INTERRUPT, (void *)NULL);
+
+ remove_proc_entry("interrupt_latency", NULL);
+
+ printk(KERN_INFO "%s %s removed\n", MODULE_NAME, ILT_MODULE_VERSION);
+}
+
+module_init(init_interrupt_latency);
+module_exit(cleanup_interrupt_latency);
+
+MODULE_DESCRIPTION("interrupt_latency proc module");
diff -Nur linux-3.4.113.orig/arch/nds32/platforms/ag101p/Kconfig linux-3.4.113/arch/nds32/platforms/ag101p/Kconfig
--- linux-3.4.113.orig/arch/nds32/platforms/ag101p/Kconfig 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/platforms/ag101p/Kconfig 2016-12-01 20:59:24.372613522 +0100
@@ -0,0 +1,11 @@
+menu "AG101P Platform Options"
+config CACHE_L2
+bool "Support L2 cache"
+ default n
+
+config MEASURE_INTERRUPT_LATENCY
+ bool "Measure interrupt latency"
+ default n
+ help
+ Enable measuring interrupt latency with software interrupt
+endmenu
diff -Nur linux-3.4.113.orig/arch/nds32/platforms/ag101p/Makefile linux-3.4.113/arch/nds32/platforms/ag101p/Makefile
--- linux-3.4.113.orig/arch/nds32/platforms/ag101p/Makefile 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/platforms/ag101p/Makefile 2016-12-01 20:59:24.372613522 +0100
@@ -0,0 +1,2 @@
+obj-y = devices.o
+obj-$(CONFIG_MEASURE_INTERRUPT_LATENCY) += interrupt-latency.o
diff -Nur linux-3.4.113.orig/arch/nds32/platforms/ag102/ahbclkcal.c linux-3.4.113/arch/nds32/platforms/ag102/ahbclkcal.c
--- linux-3.4.113.orig/arch/nds32/platforms/ag102/ahbclkcal.c 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/platforms/ag102/ahbclkcal.c 2016-12-01 20:59:24.372613522 +0100
@@ -0,0 +1,216 @@
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/pm.h>
+#include <linux/sched.h>
+#include <linux/irq.h>
+
+#include <asm/hardware.h>
+#include <asm/spec.h>
+#ifdef CONFIG_AUTO_SYS_CLK
+
+#define OSCH3_CLK 33000000
+#define OSCH_CLK 25000000
+#define MHZ 1000000
+/*
+ * Table for ahb divisor, PMODE[07:04]
+ */
+static const int ahb_div[16] = {
+ 1, 2, 3, 4, 5, 6, 3, 5,
+ 8, 10, 12, 14, 15, 18, 20, -1
+};
+
+/* ag102_get_ahb_clk()
+ *
+ * return AHB clock in Hz.
+ */
+static int ahbclk;
+void ag102_calc_ahb_clk(void)
+{
+ unsigned int pcs1_param;
+ unsigned int pcs4_param;
+ unsigned int pcs5_param;
+ unsigned int main_PLL_div;
+ unsigned int main_PLL_out;
+ unsigned int ratio;
+ unsigned int main_PLL_N;
+ unsigned int main_PLL_M = 1;
+ unsigned int F_core0;
+ unsigned int F_core1;
+ unsigned int F_l2cc;
+ unsigned int F_ddr2;
+ unsigned int F_ahb;
+ unsigned int F_apb;
+ unsigned int F_pci;
+
+ pcs1_param = REG32(PCU_VA_BASE + 0xa4); //pcs1 parameter register, for core/ahb/apb clk ratio setting
+ main_PLL_div = (pcs1_param >> 4) & 0x3;
+ ratio = pcs1_param & 0xf;
+
+ pcs4_param = REG32(PCU_VA_BASE + 0x104); //pcs4 parameter register, for main PLL setting
+ main_PLL_N = pcs4_param & 0xff;
+ main_PLL_out = (OSCH3_CLK * main_PLL_N / main_PLL_M) >> main_PLL_div;
+
+ pcs5_param = REG32(PCU_VA_BASE + 0x124); //pcs5 parameter register, for PCI PLL/DLL setting
+
+ switch (ratio) {
+ case 0:
+ F_core0 = main_PLL_out;
+ F_core1 = F_core0;
+ F_l2cc = F_core0 >> 1;
+ F_ddr2 = F_core0 >> 1;
+ F_ahb = F_core0 >> 2;
+ F_apb = F_ahb >> 1;
+ break;
+
+ case 1:
+ F_core0 = main_PLL_out;
+ F_core1 = F_core0;
+ F_l2cc = F_core0 >> 1;
+ F_ddr2 = F_core0 >> 1;
+ F_ahb = F_core0 >> 3;
+ F_apb = F_ahb >> 1;
+ break;
+
+ case 2:
+ F_core0 = main_PLL_out;
+ F_core1 = F_core0 >> 1;
+ F_l2cc = F_core0 >> 1;
+ F_ddr2 = F_core0 >> 1;
+ F_ahb = F_core0 >> 2;
+ F_apb = F_ahb >> 1;
+ break;
+
+ case 3:
+ F_core0 = main_PLL_out;
+ F_core1 = F_core0 >> 1;
+ F_l2cc = F_core0 >> 1;
+ F_ddr2 = F_core0 >> 1;
+ F_ahb = F_core0 >> 3;
+ F_apb = F_ahb >> 1;
+ break;
+
+ case 4:
+ F_core0 = main_PLL_out;
+ F_core1 = F_core0 >> 2;
+ F_l2cc = F_core0 >> 2;
+ F_ddr2 = F_core0 >> 1;
+ F_ahb = F_core0 >> 2;
+ F_apb = F_ahb >> 1;
+ break;
+ case 5:
+ F_core0 = main_PLL_out;
+ F_core1 = F_core0 >> 2;
+ F_l2cc = F_core0 >> 2;
+ F_ddr2 = F_core0 >> 1;
+ F_ahb = F_core0 >> 3;
+ F_apb = F_ahb >> 1;
+ break;
+
+ case 6:
+ F_core0 = main_PLL_out;
+ F_core1 = F_core0;
+ F_l2cc = F_core0;
+ F_ddr2 = F_core0 >> 1;
+ F_ahb = F_core0 >> 2;
+ F_apb = F_ahb >> 1;
+ break;
+
+ case 7:
+ F_core0 = main_PLL_out;
+ F_core1 = F_core0;
+ F_l2cc = F_core0;
+ F_ddr2 = F_core0 >> 1;
+ F_ahb = F_core0 >> 3;
+ F_apb = F_ahb >> 1;
+ break;
+
+ case 8:
+ F_core0 = main_PLL_out;
+ F_core1 = F_core0;
+ F_l2cc = F_core0 >> 1;
+ F_ddr2 = OSCH_CLK * 24 / 2;
+ F_ahb = F_core0 >> 2;
+ F_apb = F_ahb >> 1;
+ break;
+
+ case 9:
+ F_core0 = main_PLL_out;
+ F_core1 = F_core0;
+ F_l2cc = F_core0 >> 1;
+ F_ddr2 = OSCH_CLK * 24 / 2;
+ F_ahb = F_core0 >> 3;
+ F_apb = F_ahb >> 1;
+ break;
+ case 10:
+ F_core0 = main_PLL_out;
+ F_core1 = F_core0 >> 1;
+ F_l2cc = F_core0 >> 1;
+ F_ddr2 = OSCH_CLK * 24 / 2;
+ F_ahb = F_core0 >> 2;
+ F_apb = F_ahb >> 1;
+ break;
+
+ case 11:
+ F_core0 = main_PLL_out;
+ F_core1 = F_core0 >> 1;
+ F_l2cc = F_core0 >> 1;
+ F_ddr2 = OSCH_CLK * 24 / 2;
+ F_ahb = F_core0 >> 3;
+ F_apb = F_ahb >> 1;
+ break;
+
+ case 12:
+ F_core0 = main_PLL_out;
+ F_core1 = F_core0 >> 2;
+ F_l2cc = F_core0 >> 2;
+ F_ddr2 = OSCH_CLK * 24 / 2;
+ F_ahb = F_core0 >> 2;
+ F_apb = F_ahb >> 1;
+ break;
+
+ case 13:
+ F_core0 = main_PLL_out;
+ F_core1 = F_core0 >> 2;
+ F_l2cc = F_core0 >> 2;
+ F_ddr2 = OSCH_CLK * 24 / 2;
+ F_ahb = F_core0 >> 3;
+ F_apb = F_ahb >> 1;
+ break;
+
+ case 14:
+ F_core0 = main_PLL_out;
+ F_core1 = F_core0;
+ F_l2cc = F_core0;
+ F_ddr2 = F_core0;
+ F_ahb = F_core0;
+ F_apb = F_ahb;
+ break;
+ default: // 15
+ F_core0 = OSCH3_CLK;
+ F_core1 = F_core0;
+ F_l2cc = F_core0;
+ F_ddr2 = F_core0;
+ F_ahb = F_core0;
+ F_apb = F_ahb;
+ break;
+ }
+
+ F_pci = OSCH_CLK * 24 / 9;
+ if ((pcs5_param & 0x800) == 0)
+ F_pci = F_pci >> 1;
+
+ ahbclk = (int)F_ahb;
+}
+
+int ag102_get_ahb_clk(void)
+{
+ //return ahbclk+MHZ;
+ return ahbclk;
+}
+
+EXPORT_SYMBOL(ag102_get_ahb_clk);
+#else
+void ag102_calc_ahb_clk(void)
+{
+}
+#endif
diff -Nur linux-3.4.113.orig/arch/nds32/platforms/ag102/devices.c linux-3.4.113/arch/nds32/platforms/ag102/devices.c
--- linux-3.4.113.orig/arch/nds32/platforms/ag102/devices.c 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/platforms/ag102/devices.c 2016-12-01 20:59:24.372613522 +0100
@@ -0,0 +1,181 @@
+#include <linux/serial_8250.h>
+#include <asm/mach-types.h>
+#include <asm/sizes.h>
+#include <asm/mach/arch.h>
+#include <asm/mach/map.h>
+#include <asm/timer.h>
+#include <linux/platform_device.h>
+#include <linux/usb/g_hid.h>
+
+extern void amic_init(void);
+
+const struct map_desc platform_io_desc[] __initdata = {
+ {UART0_VA_BASE, UART0_PA_BASE, PAGE_SIZE, MT_DEVICE_NCB},
+ {UART1_VA_BASE, UART1_PA_BASE, PAGE_SIZE, MT_DEVICE_NCB},
+ {AMIC_VA_BASE, AMIC_PA_BASE, PAGE_SIZE, MT_DEVICE_NCB},
+ {GMAC_VA_BASE, GMAC_PA_BASE, PAGE_SIZE, MT_DEVICE_NCB},
+ {APBBR_VA_BASE, APBBR_PA_BASE, PAGE_SIZE, MT_DEVICE_NCB},
+ {TIMER_VA_BASE, TIMER_PA_BASE, PAGE_SIZE, MT_DEVICE_NCB},
+ {L2CC_VA_BASE, L2CC_PA_BASE, PAGE_SIZE, MT_DEVICE_NCB},
+ {PCIIO_0_VA_BASE, PCIIO_0_PA_BASE, 0x0000F000, MT_DEVICE_NCB},
+ {PCIC_FTPCI100_0_VA_BASE, PCIC_FTPCI100_0_PA_BASE, PAGE_SIZE,
+ MT_DEVICE_NCB},
+ {SDC_FTSDC010_0_VA_BASE, SDC_FTSDC010_0_PA_BASE, PAGE_SIZE,
+ MT_DEVICE_NCB},
+ {RTC_FTRTC010_0_VA_BASE, RTC_FTRTC010_0_PA_BASE, PAGE_SIZE,
+ MT_DEVICE_NCB},
+ {WDT_FTWDT010_0_VA_BASE, WDT_FTWDT010_0_PA_BASE, PAGE_SIZE,
+ MT_DEVICE_NCB},
+ {I2C_FTI2C010_0_VA_BASE, I2C_FTI2C010_0_PA_BASE, PAGE_SIZE,
+ MT_DEVICE_NCB},
+ {GPIO_FTGPIO010_0_VA_BASE, GPIO_FTGPIO010_0_PA_BASE, PAGE_SIZE,
+ MT_DEVICE_NCB},
+ {PCU_VA_BASE, PCU_PA_BASE, PAGE_SIZE, MT_DEVICE_NCB},
+ {LPC_IO_VA_BASE, LPC_IO_PA_BASE, PAGE_SIZE, MT_DEVICE_NCB},
+ {LPC_REG_VA_BASE, LPC_REG_PA_BASE, PAGE_SIZE, MT_DEVICE_NCB},
+ {DMAC_FTDMAC020_0_VA_BASE, DMAC_FTDMAC020_0_PA_BASE, PAGE_SIZE,
+ MT_DEVICE_NCB},
+ {GPU_VA_BASE, GPU_PA_BASE, SZ_64K, MT_DEVICE_NCB},
+ {IDE_FTIDE020_VA_BASE, IDE_FTIDE020_PA_BASE, PAGE_SIZE, MT_DEVICE_NCB},
+ {USB_FOTG2XX_0_VA_BASE, USB_FOTG2XX_0_PA_BASE, PAGE_SIZE,
+ MT_DEVICE_NCB},
+ {CFC_FTCFC010_0_VA_BASE, CFC_FTCFC010_0_PA_BASE, PAGE_SIZE,
+ MT_DEVICE_NCB},
+ {SSP_FTSSP010_0_VA_BASE, SSP_FTSSP010_0_PA_BASE, PAGE_SIZE,
+ MT_DEVICE_NCB},
+ {SPI_FTSSP010_0_VA_BASE, SPI_FTSSP010_0_PA_BASE, PAGE_SIZE,
+ MT_DEVICE_NCB},
+ {DDR2C_VA_BASE, DDR2C_PA_BASE, PAGE_SIZE, MT_DEVICE_NCB},
+ {AHB_ATFAHBC020S_0_VA_BASE, AHB_ATFAHBC020S_0_PA_BASE, PAGE_SIZE,
+ MT_DEVICE_NCB}
+ //{ GPIO_VA_BASE, GPIO_PA_BASE, PAGE_SIZE, MT_DEVICE_NCB }
+};
+
+/* hid descriptor for a keyboard */
+static struct hidg_func_descriptor my_hid_data = {
+ .subclass = 0, /* No subclass */
+ .protocol = 1, /* Keyboard */
+ .report_length = 8,
+ .report_desc_length = 63,
+ .report_desc = {
+ 0x05, 0x01, /* USAGE_PAGE (Generic Desktop) */
+ 0x09, 0x06, /* USAGE (Keyboard) */
+ 0xa1, 0x01, /* COLLECTION (Application) */
+ 0x05, 0x07, /* USAGE_PAGE (Keyboard) */
+ 0x19, 0xe0, /* USAGE_MINIMUM (Keyboard LeftControl) */
+ 0x29, 0xe7, /* USAGE_MAXIMUM (Keyboard Right GUI) */
+ 0x15, 0x00, /* LOGICAL_MINIMUM (0) */
+ 0x25, 0x01, /* LOGICAL_MAXIMUM (1) */
+ 0x75, 0x01, /* REPORT_SIZE (1) */
+ 0x95, 0x08, /* REPORT_COUNT (8) */
+ 0x81, 0x02, /* INPUT (Data,Var,Abs) */
+ 0x95, 0x01, /* REPORT_COUNT (1) */
+ 0x75, 0x08, /* REPORT_SIZE (8) */
+ 0x81, 0x03, /* INPUT (Cnst,Var,Abs) */
+ 0x95, 0x05, /* REPORT_COUNT (5) */
+ 0x75, 0x01, /* REPORT_SIZE (1) */
+ 0x05, 0x08, /* USAGE_PAGE (LEDs) */
+ 0x19, 0x01, /* USAGE_MINIMUM (Num Lock) */
+ 0x29, 0x05, /* USAGE_MAXIMUM (Kana) */
+ 0x91, 0x02, /* OUTPUT (Data,Var,Abs) */
+ 0x95, 0x01, /* REPORT_COUNT (1) */
+ 0x75, 0x03, /* REPORT_SIZE (3) */
+ 0x91, 0x03, /* OUTPUT (Cnst,Var,Abs) */
+ 0x95, 0x06, /* REPORT_COUNT (6) */
+ 0x75, 0x08, /* REPORT_SIZE (8) */
+ 0x15, 0x00, /* LOGICAL_MINIMUM (0) */
+ 0x25, 0x65, /* LOGICAL_MAXIMUM (101) */
+ 0x05, 0x07, /* USAGE_PAGE (Keyboard) */
+ 0x19, 0x00, /* USAGE_MINIMUM (Reserved) */
+ 0x29, 0x65, /* USAGE_MAXIMUM (Keyboard Application) */
+ 0x81, 0x00, /* INPUT (Data,Ary,Abs) */
+ 0xc0 /* END_COLLECTION */
+ }
+};
+
+static struct platform_device my_hid = {
+ .name = "hidg",
+ .id = 0,
+ .num_resources = 0,
+ .resource = 0,
+ .dev.platform_data = &my_hid_data,
+};
+
+static void __init platform_map_io(void)
+{
+ iotable_init((struct map_desc *)platform_io_desc,
+ ARRAY_SIZE(platform_io_desc));
+}
+
+static struct resource ftgmac100_resources[] = {
+ [0] = {
+ .start = GMAC_PA_BASE,
+ .end = GMAC_PA_BASE + SZ_4K - 1,
+ .flags = IORESOURCE_MEM,
+ },
+ [1] = {
+ .start = GMAC_IRQ,
+ .flags = IORESOURCE_IRQ,
+ },
+};
+
+static struct platform_device ftgmac100_device = {
+ .name = "ftgmac100",
+ .id = 0,
+ .num_resources = ARRAY_SIZE(ftgmac100_resources),
+ .resource = ftgmac100_resources,
+};
+
+static int __init devices_init(void)
+{
+ platform_device_register(&ftgmac100_device);
+ platform_device_register(&my_hid);
+ return 0;
+}
+
+arch_initcall(devices_init);
+
+static struct uart_port uart0 = {
+ .membase = (void __iomem *)UART0_VA_BASE,
+ .irq = UART0_IRQ,
+ .uartclk = CONFIG_UART_CLK,
+ .regshift = 2,
+ .iotype = UPIO_MEM,
+ .flags = UPF_SKIP_TEST | UPF_BOOT_AUTOCONF,
+ .line = 0,
+ .mapbase = UART0_PA_BASE,
+};
+
+static struct uart_port uart1 = {
+ .membase = (void __iomem *)UART1_VA_BASE,
+ .irq = UART1_IRQ,
+ .uartclk = CONFIG_UART_CLK,
+ .regshift = 2,
+ .iotype = UPIO_MEM,
+ .flags = UPF_SKIP_TEST | UPF_BOOT_AUTOCONF,
+ .line = 1,
+ .mapbase = UART1_PA_BASE,
+};
+
+void ag102_calc_ahb_clk(void);
+static void __init soc_init(void)
+{
+ ag102_calc_ahb_clk();
+ early_serial_setup(&uart0);
+ early_serial_setup(&uart1);
+}
+
+MACHINE_START(FARADAY, PLATFORM_NAME)
+ .param_offset = BOOT_PARAMETER_PA_BASE,.map_io = platform_map_io,.init_irq = amic_init,.timer = &platform_timer, /* defined in timer.c */
+.init_machine = soc_init,
+ MACHINE_END static struct platform_device usb_dev_otg_host = {
+ .name = "fotg-ehci",
+};
+
+static int __init fotg_init(void)
+{
+ platform_device_register(&usb_dev_otg_host);
+ return 0;
+}
+
+device_initcall(fotg_init);
diff -Nur linux-3.4.113.orig/arch/nds32/platforms/ag102/freq-scaling.c linux-3.4.113/arch/nds32/platforms/ag102/freq-scaling.c
--- linux-3.4.113.orig/arch/nds32/platforms/ag102/freq-scaling.c 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/platforms/ag102/freq-scaling.c 2016-12-01 20:59:24.372613522 +0100
@@ -0,0 +1,512 @@
+/*
+ * linux/arch/nds32/platforms/ag102/cpu-fcs.c
+ *
+ * Copyright (C) 2002,2003 Intrinsyc Software
+ * Copyright (C) 2009 Andes Technology Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * History:
+ * 31-Jul-2002 : Initial version [FB]
+ * 29-Jan-2003 : added PXA255 support [FB]
+ * 20-Apr-2003 : ported to v2.5 (Dustin McIntire, Sensoria Corp.)
+ * 18-Jun-2008 : ported to NDS32 architecture ( Roy Lee, Andestech Corp.)
+ * 13-Oct-2010 : ported to NDS32 AG102 architecture(Gavin Guo, Andestech Corp.)
+ *
+ * Note:
+ * This driver may change the memory bus clock rate, but will not do any
+ * platform specific access timing changes... for example if you have flash
+ * memory connected to CS0, you will need to register a platform specific
+ * notifier which will adjust the memory access strobes to maintain a
+ * minimum strobe width.
+ *
+ */
+#include <linux/module.h>
+#include <linux/cpufreq.h>
+#include <linux/interrupt.h>
+
+#include <linux/delay.h>
+#include <asm/hardware.h>
+#include <asm/localmem.h>
+#include <asm/system.h>
+#include <asm/nds32.h>
+#include <asm/irq_regs.h>
+#include "pcu.h"
+
+void __ddr_fsc_lock_start();
+void __ddr_fsc_lock_end();
+#define AG102_MIN_FREQ 200000000
+#define AG102_MAX_FREQ 1000000000
+#define OSCH3_CLK 33000000 /* 33MHz AG102 */
+
+struct ag102_freq_struct {
+ unsigned int khz; /* cpu_clk in khz */
+ unsigned int sf; /* scaling factor */
+ unsigned int cr; /* clock ratio */
+};
+
+struct ag102_freq_struct ag102_run_freqs[] = {
+ /* khz sf, cr */
+ {OSCH3_CLK * 7, 7, 0}, /* CPUA 231MHz */
+ {OSCH3_CLK * 8, 8, 0}, /* CPUA 264MHz */
+ {OSCH3_CLK * 9, 9, 0},
+ {OSCH3_CLK * 10, 10, 0},
+ {OSCH3_CLK * 11, 11, 0},
+ {OSCH3_CLK * 12, 12, 0},
+ {OSCH3_CLK * 13, 13, 0},
+ {OSCH3_CLK * 14, 14, 0},
+ {OSCH3_CLK * 15, 15, 0},
+ {OSCH3_CLK * 16, 16, 0},
+ /*
+ * {OSCH3_CLK * 17, 17, 0},
+ * {OSCH3_CLK * 18, 18, 0},
+ * {OSCH3_CLK * 19, 19, 0},
+ * {OSCH3_CLK * 20, 20, 0},
+ * {OSCH3_CLK * 21, 21, 0},
+ * {OSCH3_CLK * 22, 22, 0},
+ * {OSCH3_CLK * 23, 23, 0},
+ * {OSCH3_CLK * 24, 24, 0},
+ * {OSCH3_CLK * 25, 25, 0},
+ * {OSCH3_CLK * 26, 26, 0},
+ * {OSCH3_CLK * 27, 27, 0},
+ * {OSCH3_CLK * 28, 28, 0},
+ * {OSCH3_CLK * 29, 29, 0},
+ * {OSCH3_CLK * 30, 30, 0},
+ */
+ {0} /* The last 30 is CPUA 1000MHz */
+};
+
+#define NUM_RUN_FREQS ARRAY_SIZE(ag102_run_freqs)
+static struct cpufreq_frequency_table ag102_run_freq_table[NUM_RUN_FREQS + 1];
+
+/* Generic helper function get CPU clocks in kHz */
+unsigned int ag102_cpufreq_get(unsigned int dummy)
+{
+ unsigned int main_PLL_M = 1;
+ unsigned int main_PLL_out;
+ unsigned int main_PLL_div;
+ unsigned int ratio;
+ unsigned int main_PLL_N;
+ unsigned int pcs1_param;
+ unsigned int pcs4_param;
+
+ pcs1_param = PCU_GET_REG(PCS1_ST2);
+ main_PLL_div = PCU_EXTRACT(PCS1_ST2, DIV, pcs1_param);
+ ratio = PCU_EXTRACT(PCS1_ST2, RATIO, pcs1_param);
+
+ pcs4_param = PCU_GET_REG(PCS4_ST2);
+ main_PLL_N = PCU_EXTRACT(PCS4_ST2, N_FACTOR, pcs4_param);
+ main_PLL_out = (OSCH3_CLK * main_PLL_N / main_PLL_M) >> main_PLL_div;
+
+ printk("CPU frequency is %d\n", main_PLL_out);
+ return main_PLL_out;
+}
+
+/* find a valid frequency point */
+static int ag102_verify_policy(struct cpufreq_policy *policy)
+{
+ printk("Verified CPU policy: %dKhz min to %dKhz max\n", policy->min,
+ policy->max);
+ return cpufreq_frequency_table_verify(policy, ag102_run_freq_table);
+}
+
+void wakeup_and_ddr_train(void)
+{
+ unsigned int csr_reg;
+ unsigned long ddr2_va_base = DDR2C_VA_BASE;
+ /* issue standby */
+ /*standby(PCU_STBY_WAIT_DONE); */
+ __asm__ __volatile__("__fcs_stby:");
+ __asm__ __volatile__("standby wait_done");
+ /* Fill the inline assembly codes into Cache to avoid SDRAM access before the data training is done */
+ __asm__ __volatile__("__ddr_fsc_lock_start:\n"
+ "li $p0, %0 \n"
+ "lwi $p1, [$p0 + 0x1f0] \n"
+ "ori $p1, $p1, 0x100 \n"
+ "swi $p1, [$p0 + 0x1f0] ! DLL Reset \n"
+ "msync \n"
+ "isb \n"
+ "1: \n"
+ "lwi $p1, [$p0 + 0x1f0] \n"
+ "andi $p1, $p1, 0x100 \n"
+ "bnez $p1, 1b ! Wait until DLL reset is done\n"
+ "__trigger_dt:\n"
+ "li $p0, %1 \n"
+ "lwi $p1, [$p0] \n"
+ "li $p0, 0x40000000 \n"
+ "or $p1, $p1, $p0 \n"
+ "li $p0, %2 \n"
+ "swi $p1, [$p0] ! Trigger data training\n"
+ "msync \n"
+ "isb \n"
+ "li $p0, %3 \n"
+ "__wait_init_0:\n"
+ "lwi $p1, [$p0 + 0xc] \n"
+ "srli $p1, $p1, 23 \n"
+ "andi $p1, $p1, 0x1 \n"
+ "bnez $p1, __wait_init_0 ! Wait until init bit in CSR == 0\n"
+ "lwi $p1, [$p0 + 0xc] \n"
+ "srli $p1, $p1, 20 \n"
+ "andi $p1, $p1, 0x1 \n"
+ "beqz $p1, __dt_pass ! Monitor data training result\n"
+ "li $p0, 0xff942000 \n"
+ "li $p1, 0x45 \n"
+ "swi $p1, [$p0] ! put 'E' to UART\n"
+ "li $p1, 0x52 \n"
+ "swi $p1, [$p0] ! put 'R' to UART\n"
+ "li $p1, 0x52 \n"
+ "swi $p1, [$p0] ! put 'R' to UART\n"
+ "li $p1, 0x4f \n"
+ "swi $p1, [$p0] ! put 'O' to UART\n"
+ "li $p1, 0x52 \n"
+ "swi $p1, [$p0] ! put 'R' to UART\n"
+ "li $p1, 0xd \n"
+ "swi $p1, [$p0] ! put '\\r' to UART\n"
+ "li $p1, 0xa \n"
+ "swi $p1, [$p0] ! put '\\n' to UART\n"
+ "j __ddr_fsc_lock_end \n"
+ "__dt_pass:\n"
+ "li $p0, 0xff942000 \n"
+ "li $p1, 0x50 \n"
+ "swi $p1, [$p0] ! put 'P' to UART\n"
+ "li $p1, 'A \n"
+ "swi $p1, [$p0] ! put 'A' to UART\n"
+ "li $p1, 0x53 \n"
+ "swi $p1, [$p0] ! put 'S' to UART\n"
+ "li $p1, 0x53 \n"
+ "swi $p1, [$p0] ! put 'S' to UART\n"
+ "li $p1, '\\r \n"
+ "swi $p1, [$p0] ! put '\\r' to UART\n"
+ "li $p1, '\\n \n"
+ "swi $p1, [$p0] ! put '\\n' to UART\n"
+ "__ddr_fsc_lock_end: \n"::
+ "r"
+ (ddr2_va_base),
+ "r"
+ (ddr2_va_base),
+ "r"(ddr2_va_base), "r"(ddr2_va_base));
+
+ csr_reg = GET_REG(DDR2C_VA_BASE + 0xc);
+ if (csr_reg & 0x100000) {
+ printk("\n###### Data training error ######\nCSR = 0x%x\n\n",
+ csr_reg);
+ }
+}
+
+void check_status()
+{
+ unsigned int reg_value_tmp;
+
+ /*
+ * CPU will continue if it is waked up
+ * => check status
+ */
+ reg_value_tmp = PCU_GET_REG(BSM_STATUS);
+ if (PCU_EXTRACT(BSM_STATUS, STS, reg_value_tmp) != PCS_BSM_DONE) {
+ printk("ERROR: BSM status is not expected:0x%x\n",
+ reg_value_tmp);
+ }
+ PCU_SET_REG(BSM_STATUS, 0x0); // write to clear the status
+
+ /*
+ * Maybe we will need the following code in the future
+ * if (pcs1_used) {
+ * reg_value_tmp = PCU_GET_REG(PCS1_ST1);
+ * if (PCU_EXTRACT(PCS1_ST1, STS, reg_value_tmp) != PCS_STS_DONE) {
+ * printk("ERROR: PCS1 status is not expected:0x%x\n", reg_value_tmp);
+ * printk("DEBUG: PCS1 status 2 is 0x%x\n", PCU_GET_REG(PCS1_ST2));
+ * }
+ * PCU_SET_REG(PCS1_ST1, 0x0); // write to clear the status
+ * pcs1_used = 0;
+ * }
+ */
+
+ /* if (pcs4_used) { */
+ reg_value_tmp = PCU_GET_REG(PCS4_ST1);
+ if (PCU_EXTRACT(PCS4_ST1, STS, reg_value_tmp) != PCS_STS_DONE) {
+ printk("ERROR: PCS4 status is not expected:0x%x\n",
+ reg_value_tmp);
+ printk("DEBUG: PCS4 status 2 is 0x%x\n", PCU_GET_REG(PCS4_ST2));
+ }
+ PCU_SET_REG(PCS4_ST1, 0x0); /* write to clear the status */
+ /* pcs4_used = 0; */
+ /* } */
+
+}
+
+void start_fcs(unsigned int pll_n_factor, unsigned org_div_param)
+{
+ unsigned int pll_range;
+ unsigned int pcs4_prmtr;
+
+ /*
+ * We must keep the frequency between 266~533.
+ * because this is the frequency having been tested.
+ */
+ if (org_div_param == 0) {
+ if ((pll_n_factor < 7) || (pll_n_factor > 16)) { /* 266~533 */
+ printk("\npll_n_factor:%d, org_div_param:%d\n",
+ pll_n_factor, org_div_param);
+ printk
+ ("The input is not accepted! Please input the other value\n");
+ return;
+ }
+ } else { /* div = 1(the divsior is 2), (pll_n_factor*33MHz/2) */
+ if (pll_n_factor < 16) { /* (533/2~1000/2) */
+ printk("\npll_n_factor:%d, org_div_param:%d\n",
+ pll_n_factor, org_div_param);
+ printk
+ ("The input is not accepted! Please input the other value\n");
+ return;
+ }
+
+ }
+ /* Setup the pll_range, pcu need to know the frequency which we setup */
+ if (org_div_param == 0) {
+ if (pll_n_factor <= 15) {
+ pll_range = 2;
+ } else
+ pll_range = 3;
+ } else if (org_div_param == 1) {
+ if (pll_n_factor >= 16 && pll_n_factor <= 30) {
+ pll_range = 2;
+ } else
+ pll_range = 3;
+ }
+
+ printk("\npll_n_factor:%d, org_div_param:%d, pll_range:%d\n",
+ pll_n_factor, org_div_param, pll_range);
+ /* PCS4 */
+ PCU_SET_REG(PCS4_CFG, 0); /* stop */
+ pcs4_prmtr = PCU_PREPARE(PCS4_PARA, IE, 1) | PCU_PREPARE(PCS4_PARA, CMD, PCS_CMD_NOP) | PCU_PREPARE(PCS4_PARA, SYNC, 1) | PCU_PREPARE(PCS4_PARA, PWDN, 0) | PCU_PREPARE(PCS4_PARA, RANGE, pll_range) | /* PLL range */
+ pll_n_factor; /* PLL N factor */
+ PCU_SET_REG(PCS4_PARA, pcs4_prmtr);
+
+ /* BSM */
+ PCU_SET_REG(BSM_CTRL, PCU_PREPARE(BSM_CTRL, IE, 1) | PCU_PREPARE(BSM_CTRL, CMD, PCS_CMD_SCALING | PCS_CMD_DRAM_SF) | PCU_PREPARE(BSM_CTRL, SYNC, 1) | PCU_PREPARE(BSM_CTRL, LINK0, 4) | /* scaling link start */
+ PCU_PREPARE(BSM_CTRL, LINK1, 0x0)); /* wakeup link start */
+ wakeup_and_ddr_train();
+ check_status();
+}
+
+void end_fcs(void)
+{
+ /* Leave this function as a place marker. */
+}
+
+#define LPS_PREC 8
+void calibration()
+{
+ unsigned long ticks, loopbit, lpj;
+ int lps_precision = LPS_PREC;
+
+ lpj = (1 << 12);
+
+ printk(KERN_INFO "Calibrating delay loop... ");
+ while ((lpj <<= 1) != 0) {
+ /* wait for "start of" clock tick */
+ ticks = jiffies;
+ while (ticks == jiffies)
+ /* nothing */ ;
+ /* Go .. */
+ ticks = jiffies;
+ __delay(lpj);
+ ticks = jiffies - ticks;
+ if (ticks)
+ break;
+ }
+
+ /*
+ * Do a binary approximation to get lpj set to
+ * equal one clock (up to lps_precision bits)
+ */
+ lpj >>= 1;
+ loopbit = lpj;
+ while (lps_precision-- && (loopbit >>= 1)) {
+ lpj |= loopbit;
+ ticks = jiffies;
+ while (ticks == jiffies)
+ /* nothing */ ;
+ ticks = jiffies;
+ __delay(lpj);
+ if (jiffies != ticks) /* longer than 1 tick */
+ lpj &= ~loopbit;
+ }
+
+ printk(KERN_CONT "%lu.%02lu BogoMIPS modified(lpj=%lu)\n",
+ lpj / (500000 / HZ), (lpj / (5000 / HZ)) % 100, lpj);
+}
+
+static int ag102_speedstep(int idx)
+{
+ unsigned int j;
+ char ch = 'a';
+ unsigned int sf, cr;
+ unsigned long flags = 0;
+ unsigned long org_div_param;
+ void (*do_fcs) (unsigned int efsf, unsigned int edivhbaclk);
+ int i;
+ int line_size = CACHE_LINE_SIZE(ICACHE);
+ unsigned long start =
+ ((unsigned long)__ddr_fsc_lock_start) & ~(line_size - 1);
+ unsigned long end =
+ (((unsigned long)__ddr_fsc_lock_end) + line_size) & ~(line_size -
+ 1);
+
+ printk("&__ddr_fsc_lock_start(): 0x%08lx, aligned to: 0x%08lx\n",
+ (unsigned long)__ddr_fsc_lock_start, start);
+ printk("&__ddr_fsc_lock_end(): 0x%08lx, aligned to: 0x%08lx\n",
+ (unsigned long)__ddr_fsc_lock_end, end);
+
+ for (i = start; i <= end; i += CACHE_LINE_SIZE(ICACHE))
+ __asm__ volatile ("\n\tcctl %0, L1I_VA_FILLCK"::
+ "r" (i):"memory");
+
+ do_fcs = start_fcs;
+ org_div_param = (PCU_GET_REG(PCS1_ST2) >> 4) & 0x3;
+ sf = ag102_run_freqs[idx].sf;
+ if (org_div_param == 1)
+ sf *= 2;
+#if 0
+ calibration();
+ printk("pcu read value,before frequency scaling:");
+ ag102_cpufreq_get(0);
+#endif
+ local_irq_save(flags);
+ do_fcs(sf, org_div_param);
+ local_irq_restore(flags);
+#if 0
+ printk("\npcu read value,after frequency scaling:");
+ ag102_cpufreq_get(0);
+#endif
+
+ for (i = start; i <= end; i += CACHE_LINE_SIZE(ICACHE))
+ __asm__ volatile ("\n\tcctl %0, L1I_VA_ULCK"::"r" (i):"memory");
+
+ return 1;
+}
+
+static int ag102_set_target(struct cpufreq_policy *policy,
+ unsigned int target_freq, unsigned int relation)
+{
+ unsigned int idx, i, j;
+ char ch = 'a';
+ struct cpufreq_frequency_table *ag102_freqs_table;
+ struct ag102_freq_struct *ag102_freq_settings;
+ struct cpufreq_freqs freqs;
+
+ ag102_freq_settings = ag102_run_freqs;
+ ag102_freqs_table = ag102_run_freq_table;
+
+ if (target_freq > AG102_MAX_FREQ || target_freq < AG102_MIN_FREQ) {
+ printk
+ ("\nThe frequency you input is illegal!!Please enter the frequency between %d ~ %d\n",
+ AG102_MIN_FREQ, AG102_MAX_FREQ);
+ return -EINVAL;
+ }
+
+ /* Lookup the next frequency */
+ if (cpufreq_frequency_table_target
+ (policy, ag102_freqs_table, target_freq, relation, &idx))
+ return -EINVAL;
+
+ freqs.old = policy->cur;
+ freqs.new = ag102_freq_settings[idx].khz;
+ freqs.cpu = policy->cpu;
+
+ /*
+ * Tell everyone what we're about to do...
+ * you should add a notify client with any platform specific
+ * Vcc changing capability
+ */
+ cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE);
+
+ if (freqs.new != freqs.old) {
+
+ if (!ag102_speedstep(idx))
+ return -ENODEV;
+ }
+
+ /*
+ * Tell everyone what we've just done...
+ * you should add a notify client with any platform specific
+ * SDRAM refresh timer adjustments
+ */
+ cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE);
+#if 0
+ printk("After CPUFREQ_POSTCHANGE, scaling:\n");
+ calibration();
+ printk("Speed test...");
+ for (i = 0; i < 26; i++) {
+ for (j = 0; j < 500000000; j++) ;
+ printk("%c", ch);
+ ch += 1;
+ }
+ printk("\n");
+#endif
+ return 0;
+}
+
+static int ag102_cpufreq_init(struct cpufreq_policy *policy)
+{
+ int i;
+ /* set default policy and cpuinfo */
+ policy->governor = CPUFREQ_DEFAULT_GOVERNOR;
+ policy->policy = CPUFREQ_POLICY_PERFORMANCE;
+ policy->cpuinfo.max_freq = AG102_MAX_FREQ;
+ policy->cpuinfo.min_freq = AG102_MIN_FREQ;
+ policy->cpuinfo.transition_latency = 1000; /* FIXME: 1 ms, assumed */
+ policy->cur = ag102_cpufreq_get(0); /* current freq */
+ policy->min = AG102_MIN_FREQ;
+ policy->max = AG102_MAX_FREQ;
+
+ /* Generate the run cpufreq_frequency_table struct */
+ for (i = 0; i < NUM_RUN_FREQS; i++) {
+
+ ag102_run_freq_table[i].frequency = ag102_run_freqs[i].khz;
+ ag102_run_freq_table[i].index = i;
+ }
+
+ ag102_run_freq_table[i].frequency = CPUFREQ_TABLE_END;
+
+ printk("CPU frequency change support initialized\n");
+
+ return 0;
+}
+
+static struct cpufreq_driver ag102_cpufreq_driver = {
+
+ .verify = ag102_verify_policy,
+ .target = ag102_set_target,
+ .init = ag102_cpufreq_init,
+ .get = ag102_cpufreq_get,
+ .name = "AG102",
+};
+
+static int __init ag102_cpu_init(void)
+{
+ return cpufreq_register_driver(&ag102_cpufreq_driver);
+}
+
+static void __exit ag102_cpu_exit(void)
+{
+ cpufreq_unregister_driver(&ag102_cpufreq_driver);
+}
+
+MODULE_AUTHOR("Andes Technology Corporation");
+MODULE_DESCRIPTION("CPU frequency changing driver for the AG102 architecture");
+MODULE_LICENSE("GPL");
+module_init(ag102_cpu_init);
+module_exit(ag102_cpu_exit);
diff -Nur linux-3.4.113.orig/arch/nds32/platforms/ag102/gmac.h linux-3.4.113/arch/nds32/platforms/ag102/gmac.h
--- linux-3.4.113.orig/arch/nds32/platforms/ag102/gmac.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/platforms/ag102/gmac.h 2016-12-01 20:59:24.376613676 +0100
@@ -0,0 +1,354 @@
+#ifdef CONFIG_PLAT_AG102
+#include <asm/spec-ag102.h>
+#else
+#include <asm/spec-ag101.h>
+#endif
+
+#ifndef __GMAC_H
+#define __GMAC_H
+
+// ======================================================
+// GMAC register definition
+// ======================================================
+// GMAC register
+//
+//#define CPE_GMAC_BASE 0xFF90B000 //VA Base
+#define CPE_DDR2_MEM_BASE 0x00000000
+
+#define BIT_MASK(bit_h, bit_l) ((((UINT32)0x1<<(1+bit_h-bit_l))-(UINT32)0x1)<<bit_l)
+
+#define GMAC_REG_ISR (GMAC_VA_BASE+0x0) // interrupt sataus register
+#define GMAC_REG_IME (GMAC_VA_BASE+0x4) // interrupt enable register
+#define GMAC_REG_MAC_MADR (GMAC_VA_BASE+0x8) // mac most signification address
+#define GMAC_REG_MAC_LADR (GMAC_VA_BASE+0xc) // mac least signification address
+#define GMAC_REG_NPTXPD (GMAC_VA_BASE+0x18) // normal priority poll demand
+#define GMAC_REG_RXPD (GMAC_VA_BASE+0x1c) // receive poll demand
+#define GMAC_REG_HPTXPD (GMAC_VA_BASE+0x28) // high priority poll demand
+#define GMAC_REG_NPTXR_BADR (GMAC_VA_BASE+0x20) // normal proprity tx ring base
+#define GMAC_REG_RXR_BADR (GMAC_VA_BASE+0x24) // rx ring base
+#define GMAC_REG_HPTXR_BADR (GMAC_VA_BASE+0x28) // high priority tx ring base
+#define GMAC_REG_DBLAC (GMAC_VA_BASE+0x38) // DMA burst lenght and arbitration control
+#define GMAC_REG_DMAFIFOS (GMAC_VA_BASE+0x3c) // DMA FIFO status
+#define GMAC_REG_REVR (GMAC_VA_BASE+0x40) // revision
+#define GMAC_REG_FEAR (GMAC_VA_BASE+0x44) // feature register
+#define GMAC_REG_TPAFCR (GMAC_VA_BASE+0x48) // Tramsmit Prority Arbitration and FIFO control
+#define GMAC_REG_MACCR (GMAC_VA_BASE+0x50) // mac control register
+#define GMAC_REG_MACSR (GMAC_VA_BASE+0x54) // mac status register
+#define GMAC_REG_PHYCR (GMAC_VA_BASE+0x60) // phy control register
+#define GMAC_REG_PHYDATA (GMAC_VA_BASE+0x64) // phy data register
+#define GMAC_REG_WOLCR (GMAC_VA_BASE+0x70) // wake-on-lan control register
+#define GMAC_REG_WOLSR (GMAC_VA_BASE+0x74) // wake-on-lan status register
+#define GMAC_REG_WFCRC (GMAC_VA_BASE+0x78) // wake-up frame CRC register
+#define GMAC_REG_WFBM1 (GMAC_VA_BASE+0x80) // wake-up frame byte mask 1st
+#define GMAC_REG_WFBM2 (GMAC_VA_BASE+0x84) // wake-up frame byte mask 2nd
+#define GMAC_REG_WFBM3 (GMAC_VA_BASE+0x88) // wake-up frame byte mask 3rd
+#define GMAC_REG_WFBM4 (GMAC_VA_BASE+0x8c) // wake-up frame byte mask 4th
+#define GMAC_REG_RXR_PTR (GMAC_VA_BASE+0x98) //
+#define GMAC_REG_TPKT_CNT (GMAC_VA_BASE+0xa0) // tx packet count
+#define GMAC_REG_TMCOL_SCOL (GMAC_VA_BASE+0xa4) // tx mcol and scol count
+#define GMAC_REG_TECOL_FAIL (GMAC_VA_BASE+0xa8) // tx ecol and fail count
+#define GMAC_REG_TLCOL_URUN (GMAC_VA_BASE+0xac) // tx lcol and urun count
+#define GMAC_REG_RPKT_CNT (GMAC_VA_BASE+0xb0) // rx packet count
+#define GMAC_REG_BROPKT_CNT (GMAC_VA_BASE+0xb4) // broad cast packet count
+#define GMAC_REG_MULPKT_CNT (GMAC_VA_BASE+0xb8) // multicast packet count
+#define GMAC_REG_RPF_AEP (GMAC_VA_BASE+0xbc) //
+#define GMAC_REG_RUNT_CNT (GMAC_VA_BASE+0xc0) // rx runt packet
+#define GMAC_REG_CRCER_FLT (GMAC_VA_BASE+0xc4) // crc error and FLT
+#define GMAC_REG_RCOL_LOST (GMAC_VA_BASE+0xc8) // rx lost and collision count
+
+// interrupt enable
+#define GMAC_IME_PHY_STS_CHG_MASK (BIT_MASK(9, 9)) //
+#define GMAC_IME_PHY_STS_CHG_OFFSET (9)
+#define GMAC_IME_AHB_ERR_MASK (BIT_MASK(8, 8)) //
+#define GMAC_IME_AHB_ERR_OFFSET (8)
+#define GMAC_IME_TPKT_LOST_MASK (BIT_MASK(7, 7)) //
+#define GMAC_IME_TPKT_LOST_OFFSET (7)
+#define GMAC_IME_TXBUF_UNAVA_MASK (BIT_MASK(6, 6)) //
+#define GMAC_IME_TXBUF_UNAVA_OFFSET (6)
+#define GMAC_IME_TPKT2F_MASK (BIT_MASK(5, 5)) //
+#define GMAC_IME_TPKT2F_OFFSET (5)
+#define GMAC_IME_TPKT2B_MASK (BIT_MASK(4, 4)) //
+#define GMAC_IME_TPKT2B_OFFSET (4)
+#define GMAC_IME_RPKT_LOST_MASK (BIT_MASK(3, 3)) //
+#define GMAC_IME_RPKT_LOST_OFFSET (3)
+#define GMAC_IME_RXBUF_UNAVA_MASK (BIT_MASK(2, 2)) //
+#define GMAC_IME_RXBUF_UNAVA_OFFSET (2)
+#define GMAC_IME_RPKT2F_MASK (BIT_MASK(1, 1)) //
+#define GMAC_IME_RPKT2F_OFFSET (1)
+#define GMAC_IME_RPKT2B_MASK (BIT_MASK(0, 0)) //
+#define GMAC_IME_RPKT2B_OFFSET (0)
+
+
+// interrupt status
+#define GMAC_ISR_PHY_STS_CHG_MASK (BIT_MASK(9, 9)) //
+#define GMAC_ISR_PHY_STS_CHG_OFFSET (9)
+#define GMAC_ISR_AHB_ERR_MASK (BIT_MASK(8, 8)) //
+#define GMAC_ISR_AHB_ERR_OFFSET (8)
+#define GMAC_ISR_TPKT_LOST_MASK (BIT_MASK(7, 7)) //
+#define GMAC_ISR_TPKT_LOST_OFFSET (7)
+#define GMAC_ISR_TXBUF_UNAVA_MASK (BIT_MASK(6, 6)) //
+#define GMAC_ISR_TXBUF_UNAVA_OFFSET (6)
+#define GMAC_ISR_TPKT2F_MASK (BIT_MASK(5, 5)) //
+#define GMAC_ISR_TPKT2F_OFFSET (5)
+#define GMAC_ISR_TPKT2B_MASK (BIT_MASK(4, 4)) //
+#define GMAC_ISR_TPKT2B_OFFSET (4)
+#define GMAC_ISR_RPKT_LOST_MASK (BIT_MASK(3, 3)) //
+#define GMAC_ISR_RPKT_LOST_OFFSET (3)
+#define GMAC_ISR_RXBUF_UNAVA_MASK (BIT_MASK(2, 2)) //
+#define GMAC_ISR_RXBUF_UNAVA_OFFSET (2)
+#define GMAC_ISR_RPKT2F_MASK (BIT_MASK(1, 1)) //
+#define GMAC_ISR_RPKT2F_OFFSET (1)
+#define GMAC_ISR_RPKT2B_MASK (BIT_MASK(0, 0)) //
+#define GMAC_ISR_RPKT2B_OFFSET (0)
+
+//bit field for TPAFCR control
+#define GMAC_TPAFCR_TFIFO_SIZE_MASK (BIT_MASK(29, 27)) //
+#define GMAC_TPAFCR_TFIFO_SIZE_OFFSET (27)
+#define GMAC_TPAFCR_RFIFO_SIZE_MASK (BIT_MASK(26, 24)) //
+#define GMAC_TPAFCR_RFIFO_SIZE_OFFSET (24)
+#define GMAC_TPAFCR_EARLY_TXTHR_MASK (BIT_MASK(23, 16)) //
+#define GMAC_TPAFCR_EARLY_TXTHR_OFFSET (16)
+#define GMAC_TPAFCR_EARLY_RXTHR_MASK (BIT_MASK(15, 8)) //
+#define GMAC_TPAFCR_EARLY_RXTHR_OFFSET (8)
+#define GMAC_TPAFCR_HPKT_THR_MASK (BIT_MASK(7, 4)) //
+#define GMAC_TPAFCR_HPKT_THR_OFFSET (4)
+#define GMAC_TPAFCR_NPKT_THR_MASK (BIT_MASK(3, 0)) //
+#define GMAC_TPAFCR_NPKT_THR_OFFSET (0)
+
+//bit field for MAC control
+#define GMAC_MACCR_SW_RST_MASK (BIT_MASK(31, 31)) //
+#define GMAC_MACCR_SW_RST_OFFSET (31)
+#define GMAC_MACCR_DIRECT_PATH_MASK (BIT_MASK(21, 21)) //
+#define GMAC_MACCR_DIRECT_PATH_OFFSET (21)
+#define GMAC_MACCR_SPEED_MASK (BIT_MASK(19, 19)) //
+#define GMAC_MACCR_SPEED_OFFSET (19)
+#define GMAC_MACCR_DISCARD_CRCERR_MASK (BIT_MASK(18, 18)) //
+#define GMAC_MACCR_DISCARD_CRCERR_OFFSET (18)
+#define GMAC_MACCR_BROADPKT_EN_MASK (BIT_MASK(17, 17)) //
+#define GMAC_MACCR_BROADPKT_EN_OFFSET (17)
+#define GMAC_MACCR_RX_MULTIPKT_EN_MASK (BIT_MASK(16, 16)) //
+#define GMAC_MACCR_RX_MULTIPKT_EN_OFFSET (16)
+#define GMAC_MACCR_RX_HT_EN_MASK (BIT_MASK(15, 15)) //
+#define GMAC_MACCR_RX_HT_EN_OFFSET (15)
+#define GMAC_MACCR_RX_ALLADR_MASK (BIT_MASK(14, 14)) //
+#define GMAC_MACCR_RX_ALLADR_OFFSET (14)
+#define GMAC_MACCR_JUMBO_LF_MASK (BIT_MASK(13, 13)) //
+#define GMAC_MACCR_JUMBO_LF_OFFSET (13)
+#define GMAC_MACCR_RX_RUNT_MASK (BIT_MASK(12, 12)) //
+#define GMAC_MACCR_RX_RUNT_OFFSET (12)
+#define GMAC_MACCR_CRC_APD_MASK (BIT_MASK(10, 10)) //
+#define GMAC_MACCR_CRC_APD_OFFSET (10)
+#define GMAC_MACCR_GMAC_MODE_MASK (BIT_MASK(9, 9)) //
+#define GMAC_MACCR_GMAC_MODE_OFFSET (9)
+#define GMAC_MACCR_FULLDUP_MASK (BIT_MASK(8, 8)) //
+#define GMAC_MACCR_FULLDUP_OFFSET (8)
+#define GMAC_MACCR_ENRX_IN_HALFTX_MASK (BIT_MASK(7, 7)) //
+#define GMAC_MACCR_ENRX_IN_HALFTX_OFFSET (7)
+#define GMAC_MACCR_LOOP_EN_MASK (BIT_MASK(6, 6)) //
+#define GMAC_MACCR_LOOP_EN_OFFSET (6)
+#define GMAC_MACCR_HPTXR_EN_MASK (BIT_MASK(5, 5)) //
+#define GMAC_MACCR_HPTXR_EN_OFFSET (5)
+#define GMAC_MACCR_REMOVE_VLAN_MASK (BIT_MASK(4, 4)) //
+#define GMAC_MACCR_REMOVE_VLAN_OFFSET (4)
+#define GMAC_MACCR_RXMAC_EN_MASK (BIT_MASK(3, 3)) //
+#define GMAC_MACCR_RXMAC_EN_OFFSET (3)
+#define GMAC_MACCR_TXMAC_EN_MASK (BIT_MASK(2, 2)) //
+#define GMAC_MACCR_TXMAC_EN_OFFSET (2)
+#define GMAC_MACCR_RXDMA_EN_MASK (BIT_MASK(1, 1)) //
+#define GMAC_MACCR_RXDMA_EN_OFFSET (1)
+#define GMAC_MACCR_TXDMA_EN_MASK (BIT_MASK(0, 0)) //
+#define GMAC_MACCR_TXDMA_EN_OFFSET (0)
+
+//bit field for PHY control
+#define GMAC_PHYCR_MIIWR_MASK (BIT_MASK(27, 27)) //
+#define GMAC_PHYCR_MIIWR_OFFSET (27)
+#define GMAC_PHYCR_MIIRD_MASK (BIT_MASK(26, 26)) //
+#define GMAC_PHYCR_MIIRD_OFFSET (26)
+#define GMAC_PHYCR_REGAD_MASK (BIT_MASK(25, 21)) // register address
+#define GMAC_PHYCR_REGAD_OFFSET (21)
+#define GMAC_PHYCR_PHYAD_MASK (BIT_MASK(20, 16)) // phy address
+#define GMAC_PHYCR_PHYAD_OFFSET (16)
+#define GMAC_PHYCR_MDC_CYCTHR_MASK (BIT_MASK(5, 0)) // cycle threshold
+#define GMAC_PHYCR_MDC_CYCTHR_OFFSET (0)
+
+//bit field for PHY data
+#define GMAC_PHYDATA_MIIRDATA_MASK (BIT_MASK(31, 16)) // read data
+#define GMAC_PHYDATA_MIIRDATA_OFFSET (16)
+#define GMAC_PHYDATA_MIIWDATA_MASK (BIT_MASK(15, 0)) // write data
+#define GMAC_PHYDATA_MIIWDATA_OFFSET (0)
+
+//bit field for WOLCR
+#define GMAC_WOLCR_WOL_TYPE_MASK (BIT_MASK(258, 24)) //
+#define GMAC_WOLCR_WOL_TYPE_OFFSET (24)
+#define GMAC_WOLCR_SW_PDNPHY_MASK (BIT_MASK(18, 18)) //
+#define GMAC_WOLCR_SW_PDNPHY_OFFSET (18)
+#define GMAC_WOLCR_WAKEUP_SEL_MASK (BIT_MASK(17, 16)) //
+#define GMAC_WOLCR_WAKEUP_SEL_OFFSET (16)
+#define GMAC_WOLCR_PWRSAV_MASK (BIT_MASK(15, 15)) //
+#define GMAC_WOLCR_PWRSAV_OFFSET (15)
+#define GMAC_WOLCR_WAKEUP4_EN_MASK (BIT_MASK(6, 6)) //
+#define GMAC_WOLCR_WAKEUP4_EN_OFFSET (6)
+#define GMAC_WOLCR_WAKEUP3_EN_MASK (BIT_MASK(5, 5)) //
+#define GMAC_WOLCR_WAKEUP3_EN_OFFSET (5)
+#define GMAC_WOLCR_WAKEUP2_EN_MASK (BIT_MASK(4, 4)) //
+#define GMAC_WOLCR_WAKEUP2_EN_OFFSET (4)
+#define GMAC_WOLCR_WAKEUP1_EN_MASK (BIT_MASK(3, 3)) //
+#define GMAC_WOLCR_WAKEUP1_EN_OFFSET (3)
+#define GMAC_WOLCR_MAGICPKT_EN_MASK (BIT_MASK(2, 2)) //
+#define GMAC_WOLCR_MAGICPKT_EN_OFFSET (2)
+#define GMAC_WOLCR_LINKCHG1_EN_MASK (BIT_MASK(1, 1)) // read data
+#define GMAC_WOLCR_LINKCHG1_EN_OFFSET (1)
+#define GMAC_WOLCR_LINKCHG0_EN_MASK (BIT_MASK(0, 0)) // write data
+#define GMAC_WOLCR_LINKCHG0_EN_OFFSET (0)
+
+//bit field for WOLSR
+#define GMAC_WOLSR_WAKEUP4_STS_MASK (BIT_MASK(6, 6)) //
+#define GMAC_WOLSR_WAKEUP4_STS_OFFSET (6)
+#define GMAC_WOLSR_WAKEUP3_STS_MASK (BIT_MASK(5, 5)) //
+#define GMAC_WOLSR_WAKEUP3_STS_OFFSET (5)
+#define GMAC_WOLSR_WAKEUP2_STS_MASK (BIT_MASK(4, 4)) //
+#define GMAC_WOLSR_WAKEUP2_STS_OFFSET (4)
+#define GMAC_WOLSR_WAKEUP1_STS_MASK (BIT_MASK(3, 3)) //
+#define GMAC_WOLSR_WAKEUP1_STS_OFFSET (3)
+#define GMAC_WOLSR_MAGICPKT_STS_MASK (BIT_MASK(2, 2)) //
+#define GMAC_WOLSR_MAGICPKT_STS_OFFSET (2)
+#define GMAC_WOLSR_LINKCHG1_STS_MASK (BIT_MASK(1, 1)) // read data
+#define GMAC_WOLSR_LINKCHG1_STS_OFFSET (1)
+#define GMAC_WOLSR_LINKCHG0_STS_MASK (BIT_MASK(0, 0)) // write data
+#define GMAC_WOLSR_LINKCHG0_STS_OFFSET (0)
+
+// feature
+#define GMAC_FEAR_TFIFO_RSIZE_MASK (BIT_MASK(5, 3)) // tx fifo size
+#define GMAC_FEAR_TFIFO_RSIZE_OFFSET (3)
+#define GMAC_FEAR_RFIFO_RSIZE_MASK (BIT_MASK(2, 0)) // rx fufo size
+#define GMAC_FEAR_RFIFO_RSIZE_OFFSET (0)
+
+// ======================================================
+// GMAC access macro
+// ======================================================
+#define GMAC_SET_FIELD(reg, field, value) SET_FIELD(GMAC_REG_##reg, GMAC_##reg##_##field##_##MASK, GMAC_##reg##_##field##_##OFFSET, value)
+#define GMAC_GET_FIELD(reg, field) GET_FIELD(GMAC_REG_##reg, GMAC_##reg##_##field##_##MASK, GMAC_##reg##_##field##_##OFFSET)
+#define GMAC_TEST_FIELD(reg, field) TEST_FIELD(GMAC_REG_##reg, GMAC_##reg##_##field##_##MASK)
+
+#define GMAC_SET_REG(reg, value) SET_REG(GMAC_REG_##reg, value)
+#define GMAC_GET_REG(reg) GET_REG(GMAC_REG_##reg)
+#define GMAC_TEST_BIT(reg, field, value) VAR_TEST_BIT(value, GMAC_##reg##_##field##_##MASK)
+
+#define GMAC_EXTRACT(reg, field, value) EXTRACT_FIELD(value, GMAC_##reg##_##field##_##MASK, GMAC_##reg##_##field##_##OFFSET )
+#define GMAC_PREPARE(reg, field, value) PREPARE_FIELD(value, GMAC_##reg##_##field##_##MASK, GMAC_##reg##_##field##_##OFFSET )
+
+#define GMAC_DEFAULT(reg, field) PREPARE_FIELD(GMAC_##reg##_##field##_##DEFAULT, GMAC_##reg##_##field##_##MASK, GMAC_##reg##_##field##_##OFFSET )
+
+#define GMAC_TEST_SIG(var, sig) VAR_TEST_BIT(var, GMAC_ISR_SIG_##sig)
+#define GMAC_SET_SIG(var, sig) VAR_SET_BIT(var, GMAC_ISR_SIG_##sig)
+#define GMAC_CLR_SIG(var, sig) VAR_CLR_BIT(var, GMAC_ISR_SIG_##sig)
+
+#define FTGMAC100_MEM_BASE (CPE_DDR2_MEM_BASE + 0x00700000) //new: higher space of RAM
+#define FTGMAC100_TXR_BASE (FTGMAC100_MEM_BASE) // 2048 des., 4 byte, 4 DWs
+#define FTGMAC100_RXR_BASE (FTGMAC100_MEM_BASE+ 4096*4*4*2) // offset 2 BASE ADDRESS
+#define FTGMAC100_TXBUF_BASE (FTGMAC100_MEM_BASE+ 0x100000) // offset 2 SIZE ADDRESS
+#define FTGMAC100_RXBUF_BASE (FTGMAC100_MEM_BASE+ 0x400000) // offset 3 SIZE ADDRESS
+
+#define FTGMAC100_DESCRIPTOR_BYTE 16
+#define FTGMAC100_RXBUF_SIZE 1024
+
+//#define GMAC_DAH (0xef12)
+//#define GMAC_DAL (0x3456789a)
+#define GMAC_DAH (0x5555)
+#define GMAC_DAL (0x55555555)
+
+// ======================================================
+// DAVICOM DM9161A PHY register definition
+// ======================================================
+#define DVC_PHY_ID (0x0181b8a0)
+#define DVC_PHY_ADDR (0x0)
+#define DVC_PHY_REG_CTL (0)
+#define DVC_PHY_REG_STS (1)
+#define DVC_PHY_REG_CFG (17)
+#define DVC_PHY_REG_CTL_SW_RST (0x1<<15)
+#define DVC_PHY_REG_CTL_AN_EN (0x1<<12)
+#define DVC_PHY_REG_CTL_AN_RST (0x1<<9)
+#define DVC_PHY_REG_CTL_LOOPBACK (0x1<<14)
+
+// ======================================================
+// Marvell 88E1119R GPHY register definition
+// ======================================================
+#define MAR_GPHY_ID (0x01410e80)
+#define MAR_GPHY_ADDR (0x1f)
+#define MAR_GPHY_REG_CTL (0)
+#define MAR_GPHY_REG_STS (1)
+#define MAR_GPHY_REG_ID0 (2)
+#define MAR_GPHY_REG_ID1 (3)
+#define MAR_GPHY_REG_LPA (5)
+#define MAR_GPHY_REG_COP_CTL (16) // page 0
+#define MAR_GPHY_REG_MAC1 (16) // page 2
+#define MAR_GPHY_REG_LED_CTL (16) // page 3
+#define MAR_GPHY_REG_PKT_GEN (16) // page 6
+#define MAR_GPHY_REG_COP_STS1 (17) // page 0
+#define MAR_GPHY_REG_LED_POLAR (17) // page 3
+#define MAR_GPHY_REG_COP_STS2 (19) // page 0
+#define MAR_GPHY_REG_MAC2 (21) // page 2
+#define MAR_GPHY_REG_MAC_INT_EN (18) // page 0
+#define MAR_GPHY_REG_MAC_STS (19) // page 2
+#define MAR_GPHY_REG_PAGE (22)
+
+#define MAR_GPHY_REG_CTL_SW_RST (0x1<<15)
+#define MAR_GPHY_REG_CTL_AN_EN (0x1<<12)
+#define MAR_GPHY_REG_CTL_START_AN (0x1<<9)
+#define MAR_GPHY_REG_CTL_FULL_DUP (0x1<<8)
+#define MAR_GPHY_REG_CTL_LOOPBACK (0x1<<14)
+#define MAR_GPHY_REG_CTL_SPEED ((0x1<<13)|(0x1<<6))
+#define MAR_GPHY_REG_CTL_SPEED_1000M (0x1<<6)
+#define MAR_GPHY_REG_CTL_SPEED_100M (0x1<<13)
+#define MAR_GPHY_REG_CTL_SPEED_10M (0x0)
+#define MAR_GPHY_REG_STS_AN_COMPLETE (0x1<<5)
+#define MAR_GPHY_REG_MAC1_CLK125_DIS (0x1<<2)
+#define MAR_GPHY_REG_MAC2_SPEED (0x7)
+#define MAR_GPHY_REG_MAC2_SPEED_1000M (0x6)
+#define MAR_GPHY_REG_MAC2_SPEED_100M (0x1) //(0x5)
+#define MAR_GPHY_REG_MAC2_SPEED_10M (0x4)
+#define MAR_GPHY_REG_MAC2_LINE_LOOPBACK (0x1<<14)
+#define MAR_GPHY_REG_EN_STUB (0x1<<5)
+
+typedef struct {
+ UINT8 speed; // 0=10Mbps, 1=100Mbps, 2=1000Mbps
+ UINT8 duplex; // 0=half, 1=full
+} ETH_PHY_STAT;
+
+
+INT32 gmac_test_main();
+INT32 gmac_stress_main(UINT32 test_item, UINT32 test_cnt);
+INT32 gmac_phy_check();
+INT32 gmac_phy_pwr_ctl(UINT32 pwr);
+
+void eth_mac_init(ETH_PHY_STAT *phy_stat);
+void eth_mac_config(UINT32 type);
+void eth_mac_register_dump();
+INT32 eth_mac_interrupt_setup();
+
+INT32 eth_phy_detect(UINT32* phy_addr, UINT32* phy_id);
+INT32 eth_phy_hook_driver (UINT32 phy_id);
+
+void eth_phy_init_mar(UINT32 phy_addr);
+void eth_phy_init_dvc(UINT32 phy_addr);
+//typedef void (*FP_ETH_PHY_INIT)(UINT32 phy_addr);
+
+void eth_phy_config_dvc(UINT32 type, UINT32 phy_addr);
+void eth_phy_config_mar(UINT32 type, UINT32 phy_addr);
+//typedef void (*FP_ETH_PHY_CONFIG)(UINT32 type, UINT32 phy_addr);
+
+UINT32 eth_phy_stat_dvc(UINT32 phy_addr, ETH_PHY_STAT *phy_stat);
+UINT32 eth_phy_stat_mar(UINT32 phy_addr, ETH_PHY_STAT *phy_stat);
+//typedef UINT32 (*FP_ETH_PHY_STAT)(UINT32 phy_addr, ETH_PHY_STAT *phy_stat);
+
+//typedef UINT32 (*FP_ETH_PHY_REG_READ)(UINT32 phy_addr, UINT32 phy_page, UINT32 phy_reg, UINT32 *phy_data);
+//typedef UINT32 (*FP_ETH_PHY_REG_WRITE)(UINT32 phy_addr, UINT32 phy_page, UINT32 phy_reg, UINT32 phy_data);
+
+//extern FP_ETH_PHY_CONFIG eth_phy_config;
+//extern FP_ETH_PHY_INIT eth_phy_init;
+//extern FP_ETH_PHY_STAT eth_phy_stat;
+//extern FP_ETH_PHY_REG_WRITE eth_phy_reg_write;
+//extern FP_ETH_PHY_REG_READ eth_phy_reg_read;
+
+
+#endif // __GMAC_H
\ No newline at end of file
diff -Nur linux-3.4.113.orig/arch/nds32/platforms/ag102/Kconfig linux-3.4.113/arch/nds32/platforms/ag102/Kconfig
--- linux-3.4.113.orig/arch/nds32/platforms/ag102/Kconfig 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/platforms/ag102/Kconfig 2016-12-01 20:59:24.376613676 +0100
@@ -0,0 +1,16 @@
+menu "AG102 Platform Options"
+
+config CACHE_L2
+ bool "Support L2 cache"
+ default y
+
+config LPC
+ bool "LPC support"
+
+config AUTO_SYS_CLK
+ bool "Automatic AHB Clock Detection"
+ default y
+ help
+ Automatic detection of AHB clock
+
+endmenu
diff -Nur linux-3.4.113.orig/arch/nds32/platforms/ag102/lpc.c linux-3.4.113/arch/nds32/platforms/ag102/lpc.c
--- linux-3.4.113.orig/arch/nds32/platforms/ag102/lpc.c 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/platforms/ag102/lpc.c 2016-12-01 20:59:24.376613676 +0100
@@ -0,0 +1,230 @@
+#include <linux/irq.h>
+#include <linux/interrupt.h>
+#include <linux/delay.h>
+
+#include <asm/spec.h>
+
+#define LPC_REG_SCR 0x10
+#define LPC_REG_SIR 0x14
+#define LPC_REG_SIMR 0x18
+
+/*
+ * Level trigger IRQ chip methods
+ */
+
+static void lpc_level_unmask_irq(unsigned int irq)
+{
+ unsigned int val;
+// *(volatile unsigned int *) (LPC_REG_BASE + LPC_REG_SIR) =
+// 1 << (irq - PLATFORM_LPC_IRQ_BASE);
+ val = *(volatile unsigned int *)(LPC_REG_VA_BASE + LPC_REG_SIMR);
+ val &= ~(1 << (irq - PLATFORM_LPC_IRQ_BASE));
+ *(volatile unsigned int *)(LPC_REG_VA_BASE + LPC_REG_SIMR) = val;
+}
+
+static void lpc_level_mask_irq(unsigned int irq)
+{
+ unsigned int val;
+ val = *(volatile unsigned int *)(LPC_REG_VA_BASE + LPC_REG_SIMR);
+ val |= 1 << (irq - PLATFORM_LPC_IRQ_BASE);
+ *(volatile unsigned int *)(LPC_REG_VA_BASE + LPC_REG_SIMR) = val;
+}
+
+static void lpc_level_ack_irq(unsigned int irq)
+{
+ *(volatile unsigned int *)(LPC_REG_VA_BASE + LPC_REG_SIR) =
+ 1 << (irq - PLATFORM_LPC_IRQ_BASE);
+}
+
+static struct irq_chip lpc_simple_chip = {
+ .ack = lpc_level_ack_irq,
+ .mask = lpc_level_mask_irq,
+ .unmask = lpc_level_unmask_irq,
+};
+
+void lpc_irq_rounter(unsigned int irq, struct irq_desc *desc)
+{
+ unsigned int lpc_status;
+ unsigned int lpc_mask;
+ unsigned int lpc_irq;
+ int i;
+ struct irq_desc *lpc_desc;
+
+ desc->chip->mask(irq);
+ desc->chip->ack(irq);
+
+ lpc_status = *(volatile unsigned int *)(LPC_REG_VA_BASE + LPC_REG_SIR);
+ lpc_mask = *(volatile unsigned int *)(LPC_REG_VA_BASE + LPC_REG_SIMR);
+ *(volatile unsigned int *)(LPC_REG_VA_BASE + LPC_REG_SIMR) = 0xffffffff;
+ for (i = 0; i < PLATFORM_LPC_IRQ_TOTALCOUNT; i++) {
+ if (!(~lpc_mask & (1 << i) & lpc_status))
+ continue;
+ lpc_irq = PLATFORM_LPC_IRQ_BASE + i;
+ lpc_desc = irq_desc + lpc_irq;
+ lpc_desc->handle_irq(lpc_irq, lpc_desc);
+ *(volatile unsigned int *)(LPC_REG_VA_BASE + LPC_REG_SIR) =
+ 1 << i;
+ }
+ *(volatile unsigned int *)(LPC_REG_VA_BASE + LPC_REG_SIMR) = lpc_mask;
+
+ desc->chip->unmask(irq);
+}
+
+int __init lpc_init_irq(void)
+{
+ int i;
+
+ *(volatile unsigned int *)(LPC_REG_VA_BASE + LPC_REG_SCR) = 0x1f3;
+ /* Register all IRQ */
+ for (i = PLATFORM_LPC_IRQ_BASE;
+ i < PLATFORM_LPC_IRQ_BASE + PLATFORM_LPC_IRQ_TOTALCOUNT; i++) {
+ // level trigger
+ set_irq_chip(i, &lpc_simple_chip);
+ set_irq_handler(i, handle_simple_irq);
+
+ }
+ set_irq_chained_handler(LPC_IRQ, lpc_irq_rounter);
+
+ return 0;
+}
+
+device_initcall(lpc_init_irq);
+
+#define ITE_ADDR 0x2e
+#define ITE_DATA 0x2f
+void outlpc(unsigned int addr, unsigned int data)
+{
+ *(volatile unsigned int *)(LPC_IO_VA_BASE + 4 * addr) = data;
+}
+
+unsigned int inlpc(unsigned int addr)
+{
+ return *(volatile unsigned int *)(LPC_IO_VA_BASE + 4 * addr);
+}
+
+int __init ite8717_init(void)
+{
+ unsigned char data1, data2;
+ unsigned int count;
+ /* enter configure mode */
+ outlpc(ITE_ADDR, 0x87);
+ outlpc(ITE_ADDR, 0x01);
+ outlpc(ITE_ADDR, 0x55);
+ outlpc(ITE_ADDR, 0x55);
+ /* check chip */
+ outlpc(ITE_ADDR, 0x20);
+ data1 = inlpc(ITE_DATA);
+ outlpc(ITE_ADDR, 0x21);
+ data2 = inlpc(ITE_DATA);
+ if ((data1 != 0x87) && (data2 != 0x17))
+ goto not_found;
+ /* earlyio program */
+ outlpc(ITE_ADDR, 0x07); // LDN=0 -> FDC
+ outlpc(ITE_DATA, 0x00);
+ outlpc(ITE_ADDR, 0x30); // Enable FDC
+ outlpc(ITE_DATA, 0x01);
+ outlpc(ITE_ADDR, 0xf1); // Set (Index 0F1h) = 90h
+ outlpc(ITE_DATA, 0x80);
+
+ outlpc(0x64, 0xaa); // Send KBC self-test command
+ count = 0;
+ do {
+ if (count++ > 0x10000)
+ break;
+ data1 = ~inlpc(0x64);
+ } while (data1 & 0x01);
+ data2 = inlpc(0x60);
+ outlpc(0x64, 0xcb); // Set PS2 mode
+ count = 0;
+ do {
+ if (count++ > 0x10000)
+ break;
+ data1 = inlpc(0x64);
+ } while (data1 & 0x02);
+ outlpc(0x60, 0x01);
+ count = 0;
+ do {
+ if (count++ > 0x10000)
+ break;
+ data1 = inlpc(0x64);
+ } while (data1 & 0x02);
+ outlpc(0x64, 0x60); // 60h = write 8042 command byte
+ count = 0;
+ do {
+ if (count++ > 0x10000)
+ break;
+ data1 = inlpc(0x64);
+ } while (data1 & 0x02);
+ outlpc(0x60, 0x45); // AT interface, keyboard enabled, system flag
+ count = 0;
+ do {
+ if (count++ > 0x10000)
+ break;
+ data1 = inlpc(0x64);
+ } while (data1 & 0x02);
+ outlpc(0x64, 0xae);
+ count = 0;
+ do {
+ if (count++ > 0x10000)
+ break;
+ data1 = ~inlpc(0x64);
+ } while (data1 & 0x01);
+ outlpc(ITE_ADDR, 0x23);
+ outlpc(ITE_DATA, 0x00);
+
+ outlpc(ITE_ADDR, 0x07);
+ outlpc(ITE_DATA, 0x04);
+ outlpc(ITE_ADDR, 0xf0);
+ data1 = inlpc(ITE_DATA);
+ data1 &= 0x18;
+ data1 |= 0x0;
+ outlpc(ITE_DATA, data1);
+ outlpc(ITE_ADDR, 0xf2);
+ data1 = inlpc(ITE_DATA);
+ data1 &= 0x2e;
+ data1 |= 0xa;
+ outlpc(ITE_DATA, data1);
+ outlpc(ITE_ADDR, 0xf4);
+ data1 = inlpc(ITE_DATA);
+ data1 &= 0xaf;
+ data1 |= 0x80;
+ outlpc(ITE_DATA, data1);
+ outlpc(ITE_ADDR, 0xf5);
+ data1 = inlpc(ITE_DATA);
+ data1 &= 0x3f;
+ data1 |= 0x0;
+ outlpc(ITE_DATA, data1);
+ /* initialize all device */
+ outlpc(ITE_ADDR, 0x07);
+ outlpc(ITE_DATA, 0x04);
+ outlpc(ITE_ADDR, 0x30);
+ outlpc(ITE_DATA, 0x01);
+#if 1
+ outlpc(ITE_ADDR, 0x07);
+ outlpc(ITE_DATA, 0x05);
+ outlpc(ITE_ADDR, 0xf0);
+ outlpc(ITE_DATA, 0x4e);
+ outlpc(ITE_ADDR, 0x71);
+ outlpc(ITE_DATA, 0x01);
+#endif
+ outlpc(ITE_ADDR, 0x07);
+ outlpc(ITE_DATA, 0x06);
+ outlpc(ITE_ADDR, 0x30);
+ outlpc(ITE_DATA, 0x01);
+#if 1
+ outlpc(ITE_ADDR, 0xf0);
+ outlpc(ITE_DATA, 0x01);
+ outlpc(ITE_ADDR, 0x71);
+ outlpc(ITE_DATA, 0x01);
+#endif
+
+ /* exit configure mode */
+ outlpc(ITE_ADDR, 0x02);
+ outlpc(ITE_DATA, 0x02);
+ return 0;
+not_found:
+ printk("ITE8717 not found\n");
+ return -1;
+}
+
+subsys_initcall(ite8717_init);
diff -Nur linux-3.4.113.orig/arch/nds32/platforms/ag102/Makefile linux-3.4.113/arch/nds32/platforms/ag102/Makefile
--- linux-3.4.113.orig/arch/nds32/platforms/ag102/Makefile 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/platforms/ag102/Makefile 2016-12-01 20:59:24.376613676 +0100
@@ -0,0 +1,5 @@
+obj-y += devices.o ahbclkcal.o
+obj-$(CONFIG_LPC) += lpc.o
+obj-$(CONFIG_PM) += pm.o sleep.o
+obj-$(CONFIG_AG102_CPU_FREQ_FCS) += cpu-fcs.o
+obj-$(CONFIG_AG102_CPU_FREQ_SCALING_MODE) += freq-scaling.o
diff -Nur linux-3.4.113.orig/arch/nds32/platforms/ag102/pcu.h linux-3.4.113/arch/nds32/platforms/ag102/pcu.h
--- linux-3.4.113.orig/arch/nds32/platforms/ag102/pcu.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/platforms/ag102/pcu.h 2016-12-01 20:59:24.376613676 +0100
@@ -0,0 +1,1887 @@
+#ifndef __PCU_H
+#define __PCU_H
+#include <asm/spec.h>
+#define CPE_PCU_BASE PCU_VA_BASE
+//Data type
+typedef enum Bool {
+ FALSE,
+ TRUE
+} BOOL;
+
+typedef enum {
+ SUCCESS=0,
+ FAIL
+} STATUS;
+
+typedef unsigned char UINT8;
+typedef char INT8;
+typedef unsigned short UINT16;
+typedef short INT16;
+typedef unsigned int UINT32;
+typedef int INT32;
+typedef unsigned long long UINT64;
+typedef long long INT64;
+
+//Registion IO operation macro
+#define REG32(a) (*(volatile UINT32 *)(a))
+#define REG16(a) (*(volatile UINT16 *)(a))
+#define REG8(a) (*(volatile UINT8 *)(a))
+
+#define inb(a) REG8(a)
+#define inhw(a) REG16(a)
+#define inw(a) REG32(a)
+
+#define outb(a, v) (REG8(a) = (UINT8)(v))
+#define outhw(a, v) (REG16(a) = (UINT16)(v))
+#define outw(a, v) (REG32(a) = (UINT32)(v))
+
+
+// Register bit operation macro
+#define ANDES_BIT_MASK(bit_h, bit_l) ((((UINT32)0x1<<(1+bit_h-bit_l))-(UINT32)0x1)<<bit_l)
+
+
+#define SET_BIT(addr, bit) do { outw(addr, (inw(addr) | (0x1<<(bit)))); } while(0)
+#define CLR_BIT(addr, bit) do { outw(addr, (inw(addr) & (~(0x1<<(bit))))); } while(0)
+
+#define SET_FIELD(addr, mask, offset, value) do {\
+ outw(addr, ((inw(addr) & (~mask)) | (((value) << (offset)) &(mask)))); \
+ } while (0)
+#define GET_FIELD(addr, mask, offset) ((inw(addr)&(mask))>> (offset))
+
+#define TEST_FIELD(addr, mask) (inw(addr)&(mask))
+
+#define SET_REG(addr, value) do { outw(addr, value); } while (0)
+#define GET_REG(addr) (inw(addr))
+
+#define CHECK_FIELD(value, mask) ( (value)&(mask) )
+#define EXTRACT_FIELD(value, mask, offset) ( ((value)&(mask))>>(offset) )
+#define PREPARE_FIELD(value, mask, offset) ( ((value)<<(offset))&(mask) )
+
+
+// Variable bit operation macro
+#define VAR_TEST_BIT(var, sig) ((var)&(sig))
+#define VAR_SET_BIT(var, sig) ((var) = (var)|(sig))
+#define VAR_CLR_BIT(var, sig) ((var) = (var)&(~(sig)))
+// ============================
+// PCU register definition
+// ============================
+#define PCU_REG_VER (CPE_PCU_BASE+0x000) //version
+#define PCU_REG_SPINFO (CPE_PCU_BASE+0x004) //scartch pad information
+#define PCU_REG_SOCID (CPE_PCU_BASE+0x010) //SoC ID
+#define PCU_REG_AHB_CFG (CPE_PCU_BASE+0x014) //AHB device configuration
+#define PCU_REG_APB_CFG (CPE_PCU_BASE+0x018) //APB device configuration
+#define PCU_REG_DCSR0 (CPE_PCU_BASE+0x020) //driving capability and slew rate control 0
+#define PCU_REG_DCSR1 (CPE_PCU_BASE+0x024) //driving capability and slew rate control 1
+#define PCU_REG_DCSR2 (CPE_PCU_BASE+0x028) //driving capability and slew rate control 2
+#define PCU_REG_MFPS0 (CPE_PCU_BASE+0x030) //multi-function port setting 0
+#define PCU_REG_MFPS1 (CPE_PCU_BASE+0x034) //multi-function port setting 1
+#define PCU_REG_DMA_SEL (CPE_PCU_BASE+0x038) //dma engin selection
+#define PCU_REG_OSC_CTRL (CPE_PCU_BASE+0x040) //OSC control register
+#define PCU_REG_PWM_DIV (CPE_PCU_BASE+0x044) //PWM clock divider value
+#define PCU_REG_MISC (CPE_PCU_BASE+0x048) //misc register
+#define PCU_REG_BSM_CTRL (CPE_PCU_BASE+0x080) //BSM control register
+#define PCU_REG_BSM_STATUS (CPE_PCU_BASE+0x084) //BSM status
+#define PCU_REG_WAKEUP_SEN (CPE_PCU_BASE+0x088) //wakeup event signal sensitivity
+#define PCU_REG_WAKEUP_STATUS (CPE_PCU_BASE+0x08c) //wakeup event status
+#define PCU_REG_RESET_TIMER (CPE_PCU_BASE+0x090) //reset timer register
+#define PCU_REG_INTR (CPE_PCU_BASE+0x094) //interrup register
+#define PCU_REG_PCS1_CFG (CPE_PCU_BASE+0x0a0)
+#define PCU_REG_PCS1_PARA (CPE_PCU_BASE+0x0a4)
+#define PCU_REG_PCS1_ST1 (CPE_PCU_BASE+0x0a8)
+#define PCU_REG_PCS1_ST2 (CPE_PCU_BASE+0x0ac)
+#define PCU_REG_PCS1_PDD (CPE_PCU_BASE+0x0b0)
+#define PCU_REG_PCS2_CFG (CPE_PCU_BASE+0x0c0)
+#define PCU_REG_PCS2_PARA (CPE_PCU_BASE+0x0c4)
+#define PCU_REG_PCS2_ST1 (CPE_PCU_BASE+0x0c8)
+#define PCU_REG_PCS2_ST2 (CPE_PCU_BASE+0x0cc)
+#define PCU_REG_PCS2_PDD (CPE_PCU_BASE+0x0d0)
+#define PCU_REG_PCS3_CFG (CPE_PCU_BASE+0x0e0)
+#define PCU_REG_PCS3_PARA (CPE_PCU_BASE+0x0e4)
+#define PCU_REG_PCS3_ST1 (CPE_PCU_BASE+0x0e8)
+#define PCU_REG_PCS3_ST2 (CPE_PCU_BASE+0x0ec)
+#define PCU_REG_PCS3_PDD (CPE_PCU_BASE+0x0f0)
+#define PCU_REG_PCS4_CFG (CPE_PCU_BASE+0x100)
+#define PCU_REG_PCS4_PARA (CPE_PCU_BASE+0x104)
+#define PCU_REG_PCS4_ST1 (CPE_PCU_BASE+0x108)
+#define PCU_REG_PCS4_ST2 (CPE_PCU_BASE+0x10c)
+#define PCU_REG_PCS4_PDD (CPE_PCU_BASE+0x110)
+#define PCU_REG_PCS5_CFG (CPE_PCU_BASE+0x120)
+#define PCU_REG_PCS5_PARA (CPE_PCU_BASE+0x124)
+#define PCU_REG_PCS5_ST1 (CPE_PCU_BASE+0x128)
+#define PCU_REG_PCS5_ST2 (CPE_PCU_BASE+0x12c)
+#define PCU_REG_PCS5_PDD (CPE_PCU_BASE+0x130)
+#define PCU_REG_PCS6_CFG (CPE_PCU_BASE+0x140)
+#define PCU_REG_PCS6_PARA (CPE_PCU_BASE+0x144)
+#define PCU_REG_PCS6_ST1 (CPE_PCU_BASE+0x148)
+#define PCU_REG_PCS6_ST2 (CPE_PCU_BASE+0x14c)
+#define PCU_REG_PCS6_PDD (CPE_PCU_BASE+0x150)
+#define PCU_REG_PCS7_CFG (CPE_PCU_BASE+0x160)
+#define PCU_REG_PCS7_PARA (CPE_PCU_BASE+0x164)
+#define PCU_REG_PCS7_ST1 (CPE_PCU_BASE+0x168)
+#define PCU_REG_PCS7_ST2 (CPE_PCU_BASE+0x16c)
+#define PCU_REG_PCS7_PDD (CPE_PCU_BASE+0x170)
+#define PCU_REG_PCS8_CFG (CPE_PCU_BASE+0x180)
+#define PCU_REG_PCS8_PARA (CPE_PCU_BASE+0x184)
+#define PCU_REG_PCS8_ST1 (CPE_PCU_BASE+0x188)
+#define PCU_REG_PCS8_ST2 (CPE_PCU_BASE+0x18c)
+#define PCU_REG_PCS8_PDD (CPE_PCU_BASE+0x190)
+#define PCU_REG_PCS9_CFG (CPE_PCU_BASE+0x1a0)
+#define PCU_REG_PCS9_PARA (CPE_PCU_BASE+0x1a4)
+#define PCU_REG_PCS9_ST1 (CPE_PCU_BASE+0x1a8)
+#define PCU_REG_PCS9_ST2 (CPE_PCU_BASE+0x1ac)
+#define PCU_REG_PCS9_PDD (CPE_PCU_BASE+0x1b0)
+
+#define PCU_SCRATCH_OFFSET_SHIFT (8)
+#define PCU_SCRATCH_SIZE_SHIFT (2) // in byte, 2 means (1<<2) = 4 bytes
+#define PCU_REG_SCRATCH_MEM (CPE_PCU_BASE+ (PCU_SPINFO_OFFSET_DEFAULT<<PCU_SCRATCH_OFFSET_SHIFT) )
+
+// revision register
+#define PCU_VER_VER_MASK (ANDES_BIT_MASK(31, 16))
+#define PCU_VER_VER_OFFSET (16)
+#define PCU_VER_VER_DEFAULT (0x1)
+#define PCU_VER_PCSNO_MASK (ANDES_BIT_MASK(7, 0))
+#define PCU_VER_PCSNO_OFFSET (0)
+#define PCU_VER_PCSNO_DEFAULT (0x9)
+#define PCU_VER_DEFAULT ((PCU_VER_VER_DEFAULT << PCU_VER_VER_OFFSET ) |\
+ (PCU_VER_PCSNO_DEFAULT << PCU_VER_PCSNO_OFFSET))
+
+//scratch pad info
+#define PCU_SPINFO_OFFSET_MASK (ANDES_BIT_MASK(11, 8))
+#define PCU_SPINFO_OFFSET_OFFSET (8)
+#define PCU_SPINFO_OFFSET_DEFAULT (0x4)
+#define PCU_SPINFO_SIZE_MASK (ANDES_BIT_MASK(7, 0))
+#define PCU_SPINFO_SIZE_OFFSET (0)
+#define PCU_SPINFO_SIZE_DEFAULT (0x40)
+#define PCU_SPINFO_DEFAULT ((PCU_SPINFO_OFFSET_DEFAULT << PCU_SPINFO_OFFSET_OFFSET) |\
+ (PCU_SPINFO_SIZE_DEFAULT << PCU_SPINFO_SIZE_OFFSET ))
+
+// revision register
+#define PCU_SOCID_DEV_MASK (ANDES_BIT_MASK(31, 16))
+#define PCU_SOCID_DEV_OFFSET (16)
+#define PCU_SOCID_DEV_DEFAULT (0x102)
+#define PCU_SOCID_MAJ_MASK (ANDES_BIT_MASK(15, 4))
+#define PCU_SOCID_MAJ_OFFSET (4)
+#define PCU_SOCID_MAJ_DEFAULT (0x1)
+#define PCU_SOCID_MIN_MASK (ANDES_BIT_MASK(3, 0))
+#define PCU_SOCID_MIN_OFFSET (0)
+#define PCU_SOCID_MIN_DEFAULT (0x0)
+#define PCU_SOCID_DEFAULT ((PCU_SOCID_DEV_DEFAULT << PCU_SOCID_DEV_OFFSET) |\
+ (PCU_SOCID_MAJ_DEFAULT << PCU_SOCID_MAJ_OFFSET) |\
+ (PCU_SOCID_MIN_DEFAULT << PCU_SOCID_MIN_OFFSET))
+
+// AHB configuration
+#define PCU_AHB_CFG_AHB2AHB_MEM3_MASK (ANDES_BIT_MASK(31, 31))
+#define PCU_AHB_CFG_AHB2AHB_MEM3_OFFSET (31)
+#define PCU_AHB_CFG_AHB2AHB_MEM3_DEFAULT (0x1)
+#define PCU_AHB_CFG_AHB2AHB_MEM2_MASK (ANDES_BIT_MASK(30, 30))
+#define PCU_AHB_CFG_AHB2AHB_MEM2_OFFSET (30)
+#define PCU_AHB_CFG_AHB2AHB_MEM2_DEFAULT (0x1)
+#define PCU_AHB_CFG_AHB2AHB_MEM1_MASK (ANDES_BIT_MASK(29, 29))
+#define PCU_AHB_CFG_AHB2AHB_MEM1_OFFSET (29)
+#define PCU_AHB_CFG_AHB2AHB_MEM1_DEFAULT (0x1)
+#define PCU_AHB_CFG_AHB2AHB_MEM0_MASK (ANDES_BIT_MASK(28, 28))
+#define PCU_AHB_CFG_AHB2AHB_MEM0_OFFSET (28)
+#define PCU_AHB_CFG_AHB2AHB_MEM0_DEFAULT (0x1)
+#define PCU_AHB_CFG_AHB2AHB_REG_MASK (ANDES_BIT_MASK(27, 27))
+#define PCU_AHB_CFG_AHB2AHB_REG_OFFSET (27)
+#define PCU_AHB_CFG_AHB2AHB_REG_DEFAULT (0x1)
+#define PCU_AHB_CFG_L2CC_MASK (ANDES_BIT_MASK(20, 20))
+#define PCU_AHB_CFG_L2CC_OFFSET (20)
+#define PCU_AHB_CFG_L2CC_DEFAULT (0x1)
+#define PCU_AHB_CFG_PCI_MEM_MASK (ANDES_BIT_MASK(19, 19))
+#define PCU_AHB_CFG_PCI_MEM_OFFSET (19)
+#define PCU_AHB_CFG_PCI_MEM_DEFAULT (0x1)
+#define PCU_AHB_CFG_PCI_IO_MASK (ANDES_BIT_MASK(18, 18))
+#define PCU_AHB_CFG_PCI_IO_OFFSET (18)
+#define PCU_AHB_CFG_PCI_IO_DEFAULT (0x1)
+#define PCU_AHB_CFG_LPC_REG_MASK (ANDES_BIT_MASK(17, 17))
+#define PCU_AHB_CFG_LPC_REG_OFFSET (17)
+#define PCU_AHB_CFG_LPC_REG_DEFAULT (0x1)
+#define PCU_AHB_CFG_LPC_IO_MASK (ANDES_BIT_MASK(16, 16))
+#define PCU_AHB_CFG_LPC_IO_OFFSET (16)
+#define PCU_AHB_CFG_LPC_IO_DEFAULT (0x1)
+#define PCU_AHB_CFG_INTC_MASK (ANDES_BIT_MASK(15, 15))
+#define PCU_AHB_CFG_INTC_OFFSET (15)
+#define PCU_AHB_CFG_INTC_DEFAULT (0x1)
+#define PCU_AHB_CFG_USB_MASK (ANDES_BIT_MASK(14, 14))
+#define PCU_AHB_CFG_USB_OFFSET (14)
+#define PCU_AHB_CFG_USB_DEFAULT (0x1)
+#define PCU_AHB_CFG_IDE_MASK (ANDES_BIT_MASK(13, 13))
+#define PCU_AHB_CFG_IDE_OFFSET (13)
+#define PCU_AHB_CFG_IDE_DEFAULT (0x1)
+#define PCU_AHB_CFG_GMAC_MASK (ANDES_BIT_MASK(12, 12))
+#define PCU_AHB_CFG_GMAC_OFFSET (12)
+#define PCU_AHB_CFG_GMAC_DEFAULT (0x1)
+#define PCU_AHB_CFG_GPU_MASK (ANDES_BIT_MASK(9, 9))
+#define PCU_AHB_CFG_GPU_OFFSET (9)
+#define PCU_AHB_CFG_GPU_DEFAULT (0x1)
+#define PCU_AHB_CFG_DLM2_MASK (ANDES_BIT_MASK(8, 8))
+#define PCU_AHB_CFG_DLM2_OFFSET (8)
+#define PCU_AHB_CFG_DLM2_DEFAULT (0x1)
+#define PCU_AHB_CFG_DMAC_MASK (ANDES_BIT_MASK(7, 7))
+#define PCU_AHB_CFG_DMAC_OFFSET (7)
+#define PCU_AHB_CFG_DMAC_DEFAULT (0x1)
+#define PCU_AHB_CFG_DDR2_MEM_MASK (ANDES_BIT_MASK(6, 6))
+#define PCU_AHB_CFG_DDR2_MEM_OFFSET (6)
+#define PCU_AHB_CFG_DDR2_MEM_DEFAULT (0x1)
+#define PCU_AHB_CFG_DDR2C_MASK (ANDES_BIT_MASK(5, 5))
+#define PCU_AHB_CFG_DDR2C_OFFSET (5)
+#define PCU_AHB_CFG_DDR2C_DEFAULT (0x1)
+#define PCU_AHB_CFG_SPI_MASK (ANDES_BIT_MASK(4, 4))
+#define PCU_AHB_CFG_SPI_OFFSET (4)
+#define PCU_AHB_CFG_SPI_DEFAULT (0x1)
+#define PCU_AHB_CFG_DLM1_MASK (ANDES_BIT_MASK(3, 3))
+#define PCU_AHB_CFG_DLM1_OFFSET (3)
+#define PCU_AHB_CFG_DLM1_DEFAULT (0x1)
+#define PCU_AHB_CFG_APB_MASK (ANDES_BIT_MASK(2, 2))
+#define PCU_AHB_CFG_APB_OFFSET (2)
+#define PCU_AHB_CFG_APB_DEFAULT (0x1)
+#define PCU_AHB_CFG_APBREG_MASK (ANDES_BIT_MASK(1, 1))
+#define PCU_AHB_CFG_APBREG_OFFSET (1)
+#define PCU_AHB_CFG_APBREG_DEFAULT (0x1)
+#define PCU_AHB_CFG_AHBC_MASK (ANDES_BIT_MASK(0, 0))
+#define PCU_AHB_CFG_AHBC_OFFSET (0)
+#define PCU_AHB_CFG_AHBC_DEFAULT (0x1)
+#define PCU_AHB_CFG_DEFAULT ((PCU_AHB_CFG_AHB2AHB_MEM3_DEFAULT << PCU_AHB_CFG_AHB2AHB_MEM3_OFFSET) |\
+ (PCU_AHB_CFG_AHB2AHB_MEM2_DEFAULT << PCU_AHB_CFG_AHB2AHB_MEM2_OFFSET) |\
+ (PCU_AHB_CFG_AHB2AHB_MEM1_DEFAULT << PCU_AHB_CFG_AHB2AHB_MEM1_OFFSET) |\
+ (PCU_AHB_CFG_AHB2AHB_MEM0_DEFAULT << PCU_AHB_CFG_AHB2AHB_MEM0_OFFSET) |\
+ (PCU_AHB_CFG_AHB2AHB_REG_DEFAULT << PCU_AHB_CFG_AHB2AHB_REG_OFFSET ) |\
+ (PCU_AHB_CFG_L2CC_DEFAULT << PCU_AHB_CFG_L2CC_OFFSET ) |\
+ (PCU_AHB_CFG_PCI_MEM_DEFAULT << PCU_AHB_CFG_PCI_MEM_OFFSET ) |\
+ (PCU_AHB_CFG_PCI_IO_DEFAULT << PCU_AHB_CFG_PCI_IO_OFFSET ) |\
+ (PCU_AHB_CFG_LPC_REG_DEFAULT << PCU_AHB_CFG_LPC_REG_OFFSET ) |\
+ (PCU_AHB_CFG_LPC_IO_DEFAULT << PCU_AHB_CFG_LPC_IO_OFFSET ) |\
+ (PCU_AHB_CFG_INTC_DEFAULT << PCU_AHB_CFG_INTC_OFFSET ) |\
+ (PCU_AHB_CFG_USB_DEFAULT << PCU_AHB_CFG_USB_OFFSET ) |\
+ (PCU_AHB_CFG_IDE_DEFAULT << PCU_AHB_CFG_IDE_OFFSET ) |\
+ (PCU_AHB_CFG_GMAC_DEFAULT << PCU_AHB_CFG_GMAC_OFFSET ) |\
+ (PCU_AHB_CFG_GPU_DEFAULT << PCU_AHB_CFG_GPU_OFFSET ) |\
+ (PCU_AHB_CFG_DLM2_DEFAULT << PCU_AHB_CFG_DLM2_OFFSET ) |\
+ (PCU_AHB_CFG_DMAC_DEFAULT << PCU_AHB_CFG_DMAC_OFFSET ) |\
+ (PCU_AHB_CFG_DDR2_MEM_DEFAULT << PCU_AHB_CFG_DDR2_MEM_OFFSET ) |\
+ (PCU_AHB_CFG_DDR2C_DEFAULT << PCU_AHB_CFG_DDR2C_OFFSET ) |\
+ (PCU_AHB_CFG_SPI_DEFAULT << PCU_AHB_CFG_SPI_OFFSET ) |\
+ (PCU_AHB_CFG_DLM1_DEFAULT << PCU_AHB_CFG_DLM1_OFFSET ) |\
+ (PCU_AHB_CFG_APB_DEFAULT << PCU_AHB_CFG_APB_OFFSET ) |\
+ (PCU_AHB_CFG_APBREG_DEFAULT << PCU_AHB_CFG_APBREG_OFFSET ) |\
+ (PCU_AHB_CFG_AHBC_DEFAULT << PCU_AHB_CFG_AHBC_OFFSET ))
+
+// APB configuration
+#define PCU_APB_CFG_PWM_MASK (ANDES_BIT_MASK(23, 23))
+#define PCU_APB_CFG_PWM_OFFSET (23)
+#define PCU_APB_CFG_PWM_DEFAULT (0x1)
+#define PCU_APB_CFG_I2C_MASK (ANDES_BIT_MASK(22, 22))
+#define PCU_APB_CFG_I2C_OFFSET (22)
+#define PCU_APB_CFG_I2C_DEFAULT (0x1)
+#define PCU_APB_CFG_GPIO_MASK (ANDES_BIT_MASK(20, 20))
+#define PCU_APB_CFG_GPIO_OFFSET (20)
+#define PCU_APB_CFG_GPIO_DEFAULT (0x1)
+#define PCU_APB_CFG_RTC_MASK (ANDES_BIT_MASK(19, 19))
+#define PCU_APB_CFG_RTC_OFFSET (19)
+#define PCU_APB_CFG_RTC_DEFAULT (0x1)
+#define PCU_APB_CFG_WDT_MASK (ANDES_BIT_MASK(18, 18))
+#define PCU_APB_CFG_WDT_OFFSET (18)
+#define PCU_APB_CFG_WDT_DEFAULT (0x1)
+#define PCU_APB_CFG_TMR_MASK (ANDES_BIT_MASK(17, 17))
+#define PCU_APB_CFG_TMR_OFFSET (17)
+#define PCU_APB_CFG_TMR_DEFAULT (0x1)
+#define PCU_APB_CFG_PCU_MASK (ANDES_BIT_MASK(16, 16))
+#define PCU_APB_CFG_PCU_OFFSET (16)
+#define PCU_APB_CFG_PCU_DEFAULT (0x1)
+#define PCU_APB_CFG_UART2_MASK (ANDES_BIT_MASK(8, 8))
+#define PCU_APB_CFG_UART2_OFFSET (8)
+#define PCU_APB_CFG_UART2_DEFAULT (0x1)
+#define PCU_APB_CFG_AC97I2C_MASK (ANDES_BIT_MASK(6, 6))
+#define PCU_APB_CFG_AC97I2C_OFFSET (6)
+#define PCU_APB_CFG_AC97I2C_DEFAULT (0x1)
+#define PCU_APB_CFG_SDC_MASK (ANDES_BIT_MASK(5, 5))
+#define PCU_APB_CFG_SDC_OFFSET (5)
+#define PCU_APB_CFG_SDC_DEFAULT (0x1)
+#define PCU_APB_CFG_UART1_MASK (ANDES_BIT_MASK(3, 3))
+#define PCU_APB_CFG_UART1_OFFSET (3)
+#define PCU_APB_CFG_UART1_DEFAULT (0x1)
+#define PCU_APB_CFG_SSP_MASK (ANDES_BIT_MASK(2, 2))
+#define PCU_APB_CFG_SSP_OFFSET (2)
+#define PCU_APB_CFG_SSP_DEFAULT (0x1)
+#define PCU_APB_CFG_CFC_MASK (ANDES_BIT_MASK(1, 1))
+#define PCU_APB_CFG_CFC_OFFSET (1)
+#define PCU_APB_CFG_CFC_DEFAULT (0x1)
+#define PCU_APB_CFG_DEFAULT ((PCU_APB_CFG_PWM_DEFAULT << PCU_APB_CFG_PWM_OFFSET ) |\
+ (PCU_APB_CFG_I2C_DEFAULT << PCU_APB_CFG_I2C_OFFSET ) |\
+ (PCU_APB_CFG_GPIO_DEFAULT << PCU_APB_CFG_GPIO_OFFSET ) |\
+ (PCU_APB_CFG_RTC_DEFAULT << PCU_APB_CFG_RTC_OFFSET ) |\
+ (PCU_APB_CFG_WDT_DEFAULT << PCU_APB_CFG_WDT_OFFSET ) |\
+ (PCU_APB_CFG_TMR_DEFAULT << PCU_APB_CFG_TMR_OFFSET ) |\
+ (PCU_APB_CFG_PCU_DEFAULT << PCU_APB_CFG_PCU_OFFSET ) |\
+ (PCU_APB_CFG_UART2_DEFAULT << PCU_APB_CFG_UART2_OFFSET ) |\
+ (PCU_APB_CFG_AC97I2C_DEFAULT << PCU_APB_CFG_AC97I2C_OFFSET) |\
+ (PCU_APB_CFG_SDC_DEFAULT << PCU_APB_CFG_SDC_OFFSET ) |\
+ (PCU_APB_CFG_UART1_DEFAULT << PCU_APB_CFG_UART1_OFFSET ) |\
+ (PCU_APB_CFG_SSP_DEFAULT << PCU_APB_CFG_SSP_OFFSET ) |\
+ (PCU_APB_CFG_CFC_DEFAULT << PCU_APB_CFG_CFC_OFFSET ))
+
+// Driving Capability and Slew Rate
+#define PCU_DCSR0_GPU_MASK (ANDES_BIT_MASK(22, 20))
+#define PCU_DCSR0_GPU_OFFSET (20)
+#define PCU_DCSR0_GPU_DEFAULT (0xb)
+#define PCU_DCSR0_GMAC_MASK (ANDES_BIT_MASK(19, 16))
+#define PCU_DCSR0_GMAC_OFFSET (16)
+#define PCU_DCSR0_GMAC_DEFAULT (0x3)
+#define PCU_DCSR0_ULPI_MASK (ANDES_BIT_MASK(15, 12))
+#define PCU_DCSR0_ULPI_OFFSET (12)
+#define PCU_DCSR0_ULPI_DEFAULT (0xb)
+#define PCU_DCSR0_LPC_MASK (ANDES_BIT_MASK(11, 8))
+#define PCU_DCSR0_LPC_OFFSET (8)
+#define PCU_DCSR0_LPC_DEFAULT (0xb)
+#define PCU_DCSR0_PCIAHB_MASK (ANDES_BIT_MASK(4, 0))
+#define PCU_DCSR0_PCIAHB_OFFSET (0)
+#define PCU_DCSR0_PCIAHB_DEFAULT (0xb)
+#define PCU_DCSR1_I2C_MASK (ANDES_BIT_MASK(3, 0))
+#define PCU_DCSR1_I2C_OFFSET (0)
+#define PCU_DCSR1_I2C_DEFAULT (0x9)
+#define PCU_DCSR2_PCU_MASK (ANDES_BIT_MASK(31, 28))
+#define PCU_DCSR2_PCU_OFFSET (28)
+#define PCU_DCSR2_PCU_DEFAULT (0x3)
+#define PCU_DCSR2_GPIO_MASK (ANDES_BIT_MASK(27, 24))
+#define PCU_DCSR2_GPIO_OFFSET (24)
+#define PCU_DCSR2_GPIO_DEFAULT (0x9)
+#define PCU_DCSR2_CFC_MASK (ANDES_BIT_MASK(23, 20))
+#define PCU_DCSR2_CFC_OFFSET (20)
+#define PCU_DCSR2_CFC_DEFAULT (0xb)
+#define PCU_DCSR2_SD_MASK (ANDES_BIT_MASK(19, 16))
+#define PCU_DCSR2_SD_OFFSET (16)
+#define PCU_DCSR2_SD_DEFAULT (0xb)
+#define PCU_DCSR2_SPI_MASK (ANDES_BIT_MASK(15, 12))
+#define PCU_DCSR2_SPI_OFFSET (12)
+#define PCU_DCSR2_SPI_DEFAULT (0x9)
+#define PCU_DCSR2_AC97_MASK (ANDES_BIT_MASK(11, 8))
+#define PCU_DCSR2_AC97_OFFSET (8)
+#define PCU_DCSR2_AC97_DEFAULT (0xb)
+#define PCU_DCSR2_UART2_MASK (ANDES_BIT_MASK(7, 4))
+#define PCU_DCSR2_UART2_OFFSET (4)
+#define PCU_DCSR2_UART2_DEFAULT (0x9)
+#define PCU_DCSR2_UART1_MASK (ANDES_BIT_MASK(3, 0))
+#define PCU_DCSR2_UART1_OFFSET (0)
+#define PCU_DCSR2_UART1_DEFAULT (0x9)
+#define PCU_DCSR0_DEFAULT ((PCU_DCSR0_GPU_DEFAULT << PCU_DCSR0_GPU_OFFSET ) |\
+ (PCU_DCSR0_GMAC_DEFAULT << PCU_DCSR0_GMAC_OFFSET ) |\
+ (PCU_DCSR0_ULPI_DEFAULT << PCU_DCSR0_ULPI_OFFSET ) |\
+ (PCU_DCSR0_LPC_DEFAULT << PCU_DCSR0_LPC_OFFSET ) |\
+ (PCU_DCSR0_PCIAHB_DEFAULT << PCU_DCSR0_PCIAHB_OFFSET))
+#define PCU_DCSR0_DFT_MASK ((PCU_DCSR0_GPU_MASK ) |\
+ (PCU_DCSR0_GMAC_MASK ) |\
+ (PCU_DCSR0_ULPI_MASK ) |\
+ (PCU_DCSR0_LPC_MASK ) |\
+ (PCU_DCSR0_PCIAHB_MASK))
+
+#define PCU_DCSR1_DEFAULT (PCU_DCSR1_I2C_DEFAULT << PCU_DCSR1_I2C_OFFSET )
+#define PCU_DCSR1_DFT_MASK (PCU_DCSR1_I2C_MASK)
+
+#define PCU_DCSR2_DEFAULT ((PCU_DCSR2_PCU_DEFAULT << PCU_DCSR2_PCU_OFFSET ) |\
+ (PCU_DCSR2_GPIO_DEFAULT << PCU_DCSR2_GPIO_OFFSET ) |\
+ (PCU_DCSR2_CFC_DEFAULT << PCU_DCSR2_CFC_OFFSET ) |\
+ (PCU_DCSR2_SD_DEFAULT << PCU_DCSR2_SD_OFFSET ) |\
+ (PCU_DCSR2_SPI_DEFAULT << PCU_DCSR2_SPI_OFFSET ) |\
+ (PCU_DCSR2_AC97_DEFAULT << PCU_DCSR2_AC97_OFFSET ) |\
+ (PCU_DCSR2_UART2_DEFAULT << PCU_DCSR2_UART2_OFFSET ) |\
+ (PCU_DCSR2_UART1_DEFAULT << PCU_DCSR2_UART1_OFFSET ))
+#define PCU_DCSR2_DFT_MASK ((PCU_DCSR2_PCU_MASK ) |\
+ (PCU_DCSR2_GPIO_MASK ) |\
+ (PCU_DCSR2_CFC_MASK ) |\
+ (PCU_DCSR2_SD_MASK ) |\
+ (PCU_DCSR2_SPI_MASK ) |\
+ (PCU_DCSR2_AC97_MASK ) |\
+ (PCU_DCSR2_UART2_MASK) |\
+ (PCU_DCSR2_UART1_MASK))
+
+//multi function port setting
+#define PCU_MFPS0_ENDIAN_MASK (ANDES_BIT_MASK(31, 31))
+#define PCU_MFPS0_ENDIAN_OFFSET (31)
+//#define PCU_MFPS0_ENDIAN_DEFAULT (0x)
+#define PCU_MFPS0_IVB_MASK (ANDES_BIT_MASK(30, 28))
+#define PCU_MFPS0_IVB_OFFSET (28)
+//#define PCU_MFPS0_IVB_DEFAULT (0x)
+#define PCU_MFPS0_AHBTARGET_MASK (ANDES_BIT_MASK(4, 4))
+#define PCU_MFPS0_AHBTARGET_OFFSET (4)
+//#define PCU_MFPS0_AHBTARGET_DEFAULT (0x)
+#define PCU_MFPS0_AHBDBG_MASK (ANDES_BIT_MASK(3, 3))
+#define PCU_MFPS0_AHBDBG_OFFSET (3)
+//#define PCU_MFPS0_AHBDBG_DEFAULT (0x)
+#define PCU_MFPS0_MINI_MASK (ANDES_BIT_MASK(2, 2))
+#define PCU_MFPS0_MINI_OFFSET (2)
+//#define PCU_MFPS0_MINI_DEFAULT (0x)
+#define PCU_MFPS0_IDE_MASK (ANDES_BIT_MASK(1, 1))
+#define PCU_MFPS0_IDE_OFFSET (1)
+//#define PCU_MFPS0_IDE_DEFAULT (0x)
+#define PCU_MFPS0_PCI_MASK (ANDES_BIT_MASK(0, 0))
+#define PCU_MFPS0_PCI_OFFSET (0)
+//#define PCU_MFPS0_PCI_DEFAULT (0x)
+
+#define PCU_MFPS1_EXT_INT_MASK (ANDES_BIT_MASK(31, 31))
+#define PCU_MFPS1_EXT_INT_OFFSET (31)
+#define PCU_MFPS1_EXT_INT_DEFAULT (0x0)
+#define PCU_MFPS1_AHB_FAST_REQ_MASK (ANDES_BIT_MASK(30, 30))
+#define PCU_MFPS1_AHB_FAST_REQ_OFFSET (30)
+#define PCU_MFPS1_AHB_FAST_REQ_DEFAULT (0x1)
+#define PCU_MFPS1_HSMP_FAST_REQ_MASK (ANDES_BIT_MASK(29, 29))
+#define PCU_MFPS1_HSMP_FAST_REQ_OFFSET (29)
+#define PCU_MFPS1_HSMP_FAST_REQ_DEFAULT (0x1)
+#define PCU_MFPS1_DVO_MASK (ANDES_BIT_MASK(28, 28))
+#define PCU_MFPS1_DVO_OFFSET (28)
+#define PCU_MFPS1_DVO_DEFAULT (0x0)
+#define PCU_MFPS1_SD_GPIO_MASK (ANDES_BIT_MASK(10, 10))
+#define PCU_MFPS1_SD_GPIO_OFFSET (10)
+#define PCU_MFPS1_SD_GPIO_DEFAULT (0x1)
+#define PCU_MFPS1_SPI_GPIO_MASK (ANDES_BIT_MASK(9, 9))
+#define PCU_MFPS1_SPI_GPIO_OFFSET (9)
+#define PCU_MFPS1_SPI_GPIO_DEFAULT (0x1)
+#define PCU_MFPS1_UART2_GPIO_MASK (ANDES_BIT_MASK(8, 8))
+#define PCU_MFPS1_UART2_GPIO_OFFSET (8)
+#define PCU_MFPS1_UART2_GPIO_DEFAULT (0x1)
+#define PCU_MFPS1_UART1_GPIO_MASK (ANDES_BIT_MASK(7, 7))
+#define PCU_MFPS1_UART1_GPIO_OFFSET (7)
+#define PCU_MFPS1_UART1_GPIO_DEFAULT (0x1)
+#define PCU_MFPS1_I2C_GPIO_MASK (ANDES_BIT_MASK(6, 6))
+#define PCU_MFPS1_I2C_GPIO_OFFSET (6)
+#define PCU_MFPS1_I2C_GPIO_DEFAULT (0x1)
+#define PCU_MFPS1_PME_GPIO_MASK (ANDES_BIT_MASK(5, 5))
+#define PCU_MFPS1_PME_GPIO_OFFSET (5)
+#define PCU_MFPS1_PME_GPIO_DEFAULT (0x1)
+#define PCU_MFPS1_PWEN_GPIO_MASK (ANDES_BIT_MASK(4, 4))
+#define PCU_MFPS1_PWEN_GPIO_OFFSET (4)
+#define PCU_MFPS1_PWEN_GPIO_DEFAULT (0x1)
+#define PCU_MFPS1_AC97_GPIO_MASK (ANDES_BIT_MASK(3, 3))
+#define PCU_MFPS1_AC97_GPIO_OFFSET (3)
+#define PCU_MFPS1_AC97_GPIO_DEFAULT (0x0)
+#define PCU_MFPS1_PWM1_GPIO_MASK (ANDES_BIT_MASK(2, 2))
+#define PCU_MFPS1_PWM1_GPIO_OFFSET (2)
+#define PCU_MFPS1_PWM1_GPIO_DEFAULT (0x0)
+#define PCU_MFPS1_PWM0_GPIO_MASK (ANDES_BIT_MASK(1, 1))
+#define PCU_MFPS1_PWM0_GPIO_OFFSET (1)
+#define PCU_MFPS1_PWM0_GPIO_DEFAULT (0x0)
+#define PCU_MFPS1_SUSPEND_GPIO_MASK (ANDES_BIT_MASK(0, 0))
+#define PCU_MFPS1_SUSPEND_GPIO_OFFSET (0)
+#define PCU_MFPS1_SUSPEND_GPIO_DEFAULT (0x0)
+#define PCU_MFPS1_DEFAULT ((PCU_MFPS1_EXT_INT_DEFAULT << PCU_MFPS1_EXT_INT_OFFSET )|\
+ (PCU_MFPS1_AHB_FAST_REQ_DEFAULT << PCU_MFPS1_AHB_FAST_REQ_OFFSET )|\
+ (PCU_MFPS1_HSMP_FAST_REQ_DEFAULT << PCU_MFPS1_HSMP_FAST_REQ_OFFSET)|\
+ (PCU_MFPS1_DVO_DEFAULT << PCU_MFPS1_DVO_OFFSET )|\
+ (PCU_MFPS1_SD_GPIO_DEFAULT << PCU_MFPS1_SD_GPIO_OFFSET )|\
+ (PCU_MFPS1_SPI_GPIO_DEFAULT << PCU_MFPS1_SPI_GPIO_OFFSET )|\
+ (PCU_MFPS1_UART2_GPIO_DEFAULT << PCU_MFPS1_UART2_GPIO_OFFSET )|\
+ (PCU_MFPS1_UART1_GPIO_DEFAULT << PCU_MFPS1_UART1_GPIO_OFFSET )|\
+ (PCU_MFPS1_I2C_GPIO_DEFAULT << PCU_MFPS1_I2C_GPIO_OFFSET )|\
+ (PCU_MFPS1_PME_GPIO_DEFAULT << PCU_MFPS1_PME_GPIO_OFFSET )|\
+ (PCU_MFPS1_PWEN_GPIO_DEFAULT << PCU_MFPS1_PWEN_GPIO_OFFSET )|\
+ (PCU_MFPS1_AC97_GPIO_DEFAULT << PCU_MFPS1_AC97_GPIO_OFFSET )|\
+ (PCU_MFPS1_PWM1_GPIO_DEFAULT << PCU_MFPS1_PWM1_GPIO_OFFSET )|\
+ (PCU_MFPS1_PWM0_GPIO_DEFAULT << PCU_MFPS1_PWM0_GPIO_OFFSET )|\
+ (PCU_MFPS1_SUSPEND_GPIO_DEFAULT << PCU_MFPS1_SUSPEND_GPIO_OFFSET ))
+#define PCU_MFPS1_DFT_MASK ((PCU_MFPS1_EXT_INT_MASK )|\
+ (PCU_MFPS1_AHB_FAST_REQ_MASK )|\
+ (PCU_MFPS1_HSMP_FAST_REQ_MASK)|\
+ (PCU_MFPS1_DVO_MASK )|\
+ (PCU_MFPS1_SD_GPIO_MASK )|\
+ (PCU_MFPS1_SPI_GPIO_MASK )|\
+ (PCU_MFPS1_UART2_GPIO_MASK )|\
+ (PCU_MFPS1_UART1_GPIO_MASK )|\
+ (PCU_MFPS1_I2C_GPIO_MASK )|\
+ (PCU_MFPS1_PME_GPIO_MASK )|\
+ (PCU_MFPS1_PWEN_GPIO_MASK )|\
+ (PCU_MFPS1_AC97_GPIO_MASK )|\
+ (PCU_MFPS1_PWM1_GPIO_MASK )|\
+ (PCU_MFPS1_PWM0_GPIO_MASK )|\
+ (PCU_MFPS1_SUSPEND_GPIO_MASK ))
+
+//DMA engine selection
+#define PCU_DMA_SEL_CFC_MASK (ANDES_BIT_MASK(9, 9))
+#define PCU_DMA_SEL_CFC_OFFSET (9)
+#define PCU_DMA_SEL_CFC_DEFAULT (0x0)
+#define PCU_DMA_SEL_SD_MASK (ANDES_BIT_MASK(9, 9))
+#define PCU_DMA_SEL_SD_OFFSET (9)
+#define PCU_DMA_SEL_SD_DEFAULT (0x0)
+#define PCU_DMA_SEL_UART2_TX_MASK (ANDES_BIT_MASK(9, 9))
+#define PCU_DMA_SEL_UART2_TX_OFFSET (9)
+#define PCU_DMA_SEL_UART2_TX_DEFAULT (0x0)
+#define PCU_DMA_SEL_UART2_RX_MASK (ANDES_BIT_MASK(9, 9))
+#define PCU_DMA_SEL_UART2_RX_OFFSET (9)
+#define PCU_DMA_SEL_UART2_RX_DEFAULT (0x0)
+#define PCU_DMA_SEL_UART1_TX_MASK (ANDES_BIT_MASK(9, 9))
+#define PCU_DMA_SEL_UART1_TX_OFFSET (9)
+#define PCU_DMA_SEL_UART1_TX_DEFAULT (0x0)
+#define PCU_DMA_SEL_UART1_RX_MASK (ANDES_BIT_MASK(9, 9))
+#define PCU_DMA_SEL_UART1_RX_OFFSET (9)
+#define PCU_DMA_SEL_UART1_RX_DEFAULT (0x0)
+#define PCU_DMA_SEL_AC97_TX_MASK (ANDES_BIT_MASK(9, 9))
+#define PCU_DMA_SEL_AC97_TX_OFFSET (9)
+#define PCU_DMA_SEL_AC97_TX_DEFAULT (0x0)
+#define PCU_DMA_SEL_AC97_RX_MASK (ANDES_BIT_MASK(9, 9))
+#define PCU_DMA_SEL_AC97_RX_OFFSET (9)
+#define PCU_DMA_SEL_AC97_RX_DEFAULT (0x0)
+#define PCU_DMA_SEL_DEFAULT ((PCU_DMA_SEL_CFC_DEFAULT << PCU_DMA_SEL_CFC_OFFSET ) |\
+ (PCU_DMA_SEL_SD_DEFAULT << PCU_DMA_SEL_SD_OFFSET ) |\
+ (PCU_DMA_SEL_UART2_TX_DEFAULT << PCU_DMA_SEL_UART2_TX_OFFSET) |\
+ (PCU_DMA_SEL_UART2_RX_DEFAULT << PCU_DMA_SEL_UART2_RX_OFFSET) |\
+ (PCU_DMA_SEL_UART1_TX_DEFAULT << PCU_DMA_SEL_UART1_TX_OFFSET) |\
+ (PCU_DMA_SEL_UART1_RX_DEFAULT << PCU_DMA_SEL_UART1_RX_OFFSET) |\
+ (PCU_DMA_SEL_AC97_TX_DEFAULT << PCU_DMA_SEL_AC97_TX_OFFSET ) |\
+ (PCU_DMA_SEL_AC97_RX_DEFAULT << PCU_DMA_SEL_AC97_RX_OFFSET ) )
+#define PCU_DMA_SEL_DFT_MASK ((PCU_DMA_SEL_CFC_MASK ) |\
+ (PCU_DMA_SEL_SD_MASK ) |\
+ (PCU_DMA_SEL_UART2_TX_MASK) |\
+ (PCU_DMA_SEL_UART2_RX_MASK) |\
+ (PCU_DMA_SEL_UART1_TX_MASK) |\
+ (PCU_DMA_SEL_UART1_RX_MASK) |\
+ (PCU_DMA_SEL_AC97_TX_MASK ) |\
+ (PCU_DMA_SEL_AC97_RX_MASK ) )
+
+// OSC control
+#define PCU_OSC_CTRL_OSCH3RAN_MASK (ANDES_BIT_MASK(9, 8))
+#define PCU_OSC_CTRL_OSCH3RAN_OFFSET (8)
+//#define PCU_OSC_CTRL_OSCH3RAN_DEFAULT (0x0)
+#define PCU_OSC_CTRL_OSCH2RAN_MASK (ANDES_BIT_MASK(7, 6))
+#define PCU_OSC_CTRL_OSCH2RAN_OFFSET (6)
+#define PCU_OSC_CTRL_OSCH2RAN_DEFAULT (0x2)
+#define PCU_OSC_CTRL_OSCH1RAN_MASK (ANDES_BIT_MASK(5, 4))
+#define PCU_OSC_CTRL_OSCH1RAN_OFFSET (4)
+//#define PCU_OSC_CTRL_OSCH1RAN_DEFAULT (0x0)
+#define PCU_OSC_CTRL_OSCHTRI_MASK (ANDES_BIT_MASK(2, 2))
+#define PCU_OSC_CTRL_OSCHTRI_OFFSET (2)
+#define PCU_OSC_CTRL_OSCHTRI_DEFAULT (0x0)
+#define PCU_OSC_CTRL_OSCHSTABLE_MASK (ANDES_BIT_MASK(1, 1))
+#define PCU_OSC_CTRL_OSCHSTABLE_OFFSET (1)
+//#define PCU_OSC_CTRL_OSCHSTABLE_DEFAULT (0x0)
+#define PCU_OSC_CTRL_OSCHOFF_MASK (ANDES_BIT_MASK(0, 0))
+#define PCU_OSC_CTRL_OSCHOFF_OFFSET (0)
+//#define PCU_OSC_CTRL_OSCHOFF_DEFAULT (0x0)
+#define PCU_OSC_CTRL_DEFAULT (PCU_OSC_CTRL_OSCH2RAN_DEFAULT << PCU_OSC_CTRL_OSCH2RAN_OFFSET )
+#define PCU_OSC_CTRL_DFT_MASK (PCU_OSC_CTRL_OSCH2RAN_MASK )
+
+// PWM divider
+#define PCU_PWM_DIV_DIV_MASK (ANDES_BIT_MASK(3, 0))
+#define PCU_PWM_DIV_DIV_OFFSET (0)
+#define PCU_PWM_DIV_DIV_DEFAULT (0x0)
+#define PCU_PWM_DIV_DEFAULT (PCU_PWM_DIV_DIV_DEFAULT<<PCU_PWM_DIV_DIV_OFFSET)
+#define PCU_PWM_DIV_DFT_MASK (PCU_PWM_DIV_DIV_MASK)
+
+// MISC
+#define PCU_MISC_HW_RST_MASK (ANDES_BIT_MASK(31, 31))
+#define PCU_MISC_HW_RST_OFFSET (31)
+#define PCU_MISC_HW_RST_DEFAULT (0x0)
+#define PCU_MISC_WD_RST_MASK (ANDES_BIT_MASK(30, 30))
+#define PCU_MISC_WD_RST_OFFSET (30)
+#define PCU_MISC_WD_RST_DEFAULT (0x0)
+#define PCU_MISC_CPUB_SRST_MASK (ANDES_BIT_MASK(29, 29))
+#define PCU_MISC_CPUB_SRST_OFFSET (29)
+#define PCU_MISC_CPUB_SRST_DEFAULT (0x0)
+#define PCU_MISC_CPUA_SRST_MASK (ANDES_BIT_MASK(28, 28))
+#define PCU_MISC_CPUA_SRST_OFFSET (28)
+#define PCU_MISC_CPUA_SRST_DEFAULT (0x0)
+#define PCU_MISC_PW_FAIL_MASK (ANDES_BIT_MASK(27, 27))
+#define PCU_MISC_PW_FAIL_OFFSET (27)
+#define PCU_MISC_PW_FAIL_DEFAULT (0x0)
+#define PCU_MISC_PW_DAILY_MASK (ANDES_BIT_MASK(26, 26))
+#define PCU_MISC_PW_DAILY_OFFSET (26)
+#define PCU_MISC_PW_DAILY_DEFAULT (0x0)
+#define PCU_MISC_PW_LPC_MASK (ANDES_BIT_MASK(25, 25))
+#define PCU_MISC_PW_LPC_OFFSET (25)
+#define PCU_MISC_PW_LPC_DEFAULT (0x0)
+#define PCU_MISC_PW_PCI_MASK (ANDES_BIT_MASK(24, 24))
+#define PCU_MISC_PW_PCI_OFFSET (24)
+#define PCU_MISC_PW_PCI_DEFAULT (0x0)
+#define PCU_MISC_PW_RTC_MASK (ANDES_BIT_MASK(23, 23))
+#define PCU_MISC_PW_RTC_OFFSET (23)
+#define PCU_MISC_PW_RTC_DEFAULT (0x0)
+#define PCU_MISC_PW_WOL_MASK (ANDES_BIT_MASK(22, 22))
+#define PCU_MISC_PW_WOL_OFFSET (2)
+#define PCU_MISC_PW_WOL_DEFAULT (0x0)
+#define PCU_MISC_PW_GPIO5_MASK (ANDES_BIT_MASK(21, 21))
+#define PCU_MISC_PW_GPIO5_OFFSET (21)
+#define PCU_MISC_PW_GPIO5_DEFAULT (0x0)
+#define PCU_MISC_PW_GPIO4_MASK (ANDES_BIT_MASK(20, 20))
+#define PCU_MISC_PW_GPIO4_OFFSET (20)
+#define PCU_MISC_PW_GPIO4_DEFAULT (0x0)
+#define PCU_MISC_PW_GPIO3_MASK (ANDES_BIT_MASK(19, 19))
+#define PCU_MISC_PW_GPIO3_OFFSET (19)
+#define PCU_MISC_PW_GPIO3_DEFAULT (0x0)
+#define PCU_MISC_PW_GPIO2_MASK (ANDES_BIT_MASK(18, 18))
+#define PCU_MISC_PW_GPIO2_OFFSET (18)
+#define PCU_MISC_PW_GPIO2_DEFAULT (0x0)
+#define PCU_MISC_PW_GPIO1_MASK (ANDES_BIT_MASK(17, 17))
+#define PCU_MISC_PW_GPIO1_OFFSET (17)
+#define PCU_MISC_PW_GPIO1_DEFAULT (0x0)
+#define PCU_MISC_PW_GPIO0_MASK (ANDES_BIT_MASK(16, 16))
+#define PCU_MISC_PW_GPIO0_OFFSET (16)
+#define PCU_MISC_PW_GPIO0_DEFAULT (0x0)
+#define PCU_MISC_EN_CPUB_MASK (ANDES_BIT_MASK(15, 15))
+#define PCU_MISC_EN_CPUB_OFFSET (15)
+#define PCU_MISC_EN_CPUB_DEFAULT (0x0)
+#define PCU_MISC_EN_CPUA_MASK (ANDES_BIT_MASK(14, 14))
+#define PCU_MISC_EN_CPUA_OFFSET (14)
+#define PCU_MISC_EN_CPUA_DEFAULT (0x1)
+#define PCU_MISC_DDR_DLL_TEST_MASK (ANDES_BIT_MASK(12, 12))
+#define PCU_MISC_DDR_DLL_TEST_OFFSET (12)
+#define PCU_MISC_DDR_DLL_TEST_DEFAULT (0x0)
+#define PCU_MISC_DDR_DDQ_TEST_MASK (ANDES_BIT_MASK(11, 11))
+#define PCU_MISC_DDR_DDQ_TEST_OFFSET (11)
+#define PCU_MISC_DDR_DDQ_TEST_DEFAULT (0x0)
+#define PCU_MISC_DDR_DLL_SRST_MASK (ANDES_BIT_MASK(10, 10))
+#define PCU_MISC_DDR_DLL_SRST_OFFSET (10)
+#define PCU_MISC_DDR_DLL_SRST_DEFAULT (0x0)
+#define PCU_MISC_DDR_PLL_BYPASS_MASK (ANDES_BIT_MASK(9, 9))
+#define PCU_MISC_DDR_PLL_BYPASS_OFFSET (9)
+#define PCU_MISC_DDR_PLL_BYPASS_DEFAULT (0x0)
+#define PCU_MISC_400MHZ_SEL_MASK (ANDES_BIT_MASK(8, 8))
+#define PCU_MISC_400MHZ_SEL_OFFSET (8)
+#define PCU_MISC_400MHZ_SEL_DEFAULT (0x0)
+#define PCU_MISC_EXLM_WAIT_B_MASK (ANDES_BIT_MASK(7, 6))
+#define PCU_MISC_EXLM_WAIT_B_OFFSET (6)
+#define PCU_MISC_EXLM_WAIT_B_DEFAULT (0x0)
+#define PCU_MISC_EXLM_WAIT_A_MASK (ANDES_BIT_MASK(5, 4))
+#define PCU_MISC_EXLM_WAIT_A_OFFSET (4)
+#define PCU_MISC_EXLM_WAIT_A_DEFAULT (0x0)
+#define PCU_MISC_USB_WAKE_MASK (ANDES_BIT_MASK(3, 3))
+#define PCU_MISC_USB_WAKE_OFFSET (3)
+#define PCU_MISC_USB_WAKE_DEFAULT (0x0)
+#define PCU_MISC_RST_PCI_MASK (ANDES_BIT_MASK(2, 2))
+#define PCU_MISC_RST_PCI_OFFSET (2)
+#define PCU_MISC_RST_PCI_DEFAULT (0x0)
+#define PCU_MISC_RST_CPUB_MASK (ANDES_BIT_MASK(1, 1))
+#define PCU_MISC_RST_CPUB_OFFSET (1)
+#define PCU_MISC_RST_CPUB_DEFAULT (0x0)
+#define PCU_MISC_RST_CPUA_MASK (ANDES_BIT_MASK(0, 0))
+#define PCU_MISC_RST_CPUA_OFFSET (0)
+#define PCU_MISC_RST_CPUA_DEFAULT (0x0)
+#define PCU_MISC_DEFAULT (/*(PCU_MISC_EN_CPUB_DEFAULT << PCU_MISC_EN_CPUB_OFFSET )|*/\
+ (PCU_MISC_EN_CPUA_DEFAULT << PCU_MISC_EN_CPUA_OFFSET )|\
+ (PCU_MISC_DDR_DLL_TEST_DEFAULT << PCU_MISC_DDR_DLL_TEST_OFFSET )|\
+ (PCU_MISC_DDR_DDQ_TEST_DEFAULT << PCU_MISC_DDR_DDQ_TEST_OFFSET )|\
+ (PCU_MISC_DDR_DLL_SRST_DEFAULT << PCU_MISC_DDR_DLL_SRST_OFFSET )|\
+ (PCU_MISC_DDR_PLL_BYPASS_DEFAULT << PCU_MISC_DDR_PLL_BYPASS_OFFSET )|\
+ (PCU_MISC_400MHZ_SEL_DEFAULT << PCU_MISC_400MHZ_SEL_OFFSET )|\
+ (PCU_MISC_EXLM_WAIT_B_DEFAULT << PCU_MISC_EXLM_WAIT_B_OFFSET )|\
+ (PCU_MISC_EXLM_WAIT_A_DEFAULT << PCU_MISC_EXLM_WAIT_A_OFFSET )|\
+ (PCU_MISC_USB_WAKE_DEFAULT << PCU_MISC_USB_WAKE_OFFSET )|\
+ (PCU_MISC_RST_PCI_DEFAULT << PCU_MISC_RST_PCI_OFFSET )|\
+ (PCU_MISC_RST_CPUB_DEFAULT << PCU_MISC_RST_CPUB_OFFSET )|\
+ (PCU_MISC_RST_CPUA_DEFAULT << PCU_MISC_RST_CPUA_OFFSET ))
+#define PCU_MISC_DFT_MASK (/*(PCU_MISC_EN_CPUB_MASK )|*/\
+ (PCU_MISC_EN_CPUA_MASK )|\
+ (PCU_MISC_DDR_DLL_TEST_MASK )|\
+ (PCU_MISC_DDR_DDQ_TEST_MASK )|\
+ (PCU_MISC_DDR_DLL_SRST_MASK )|\
+ (PCU_MISC_DDR_PLL_BYPASS_MASK)|\
+ (PCU_MISC_400MHZ_SEL_MASK )|\
+ (PCU_MISC_EXLM_WAIT_B_MASK )|\
+ (PCU_MISC_EXLM_WAIT_A_MASK )|\
+ (PCU_MISC_USB_WAKE_MASK )|\
+ (PCU_MISC_RST_PCI_MASK )|\
+ (PCU_MISC_RST_CPUB_MASK )|\
+ (PCU_MISC_RST_CPUA_MASK ))
+#define PCU_MISC_W1C_MASK ((PCU_MISC_HW_RST_MASK )|\
+ (PCU_MISC_WD_RST_MASK )|\
+ (PCU_MISC_CPUB_SRST_MASK)|\
+ (PCU_MISC_CPUA_SRST_MASK))
+
+// BSM control and status
+#define PCU_BSM_CTRL_IE_MASK (ANDES_BIT_MASK(31, 31))
+#define PCU_BSM_CTRL_IE_OFFSET (31)
+#define PCU_BSM_CTRL_IE_DEFAULT (0x0)
+#define PCU_BSM_CTRL_CMD_MASK (ANDES_BIT_MASK(30, 28))
+#define PCU_BSM_CTRL_CMD_OFFSET (28)
+#define PCU_BSM_CTRL_CMD_DEFAULT (0x0)
+#define PCU_BSM_CTRL_SYNC_MASK (ANDES_BIT_MASK(27, 24))
+#define PCU_BSM_CTRL_SYNC_OFFSET (24)
+#define PCU_BSM_CTRL_SYNC_DEFAULT (0x3)
+#define PCU_BSM_CTRL_LINK1_MASK (ANDES_BIT_MASK(7, 4))
+#define PCU_BSM_CTRL_LINK1_OFFSET (4)
+#define PCU_BSM_CTRL_LINK1_DEFAULT (0x0)
+#define PCU_BSM_CTRL_LINK0_MASK (ANDES_BIT_MASK(3, 0))
+#define PCU_BSM_CTRL_LINK0_OFFSET (0)
+#define PCU_BSM_CTRL_LINK0_DEFAULT (0x0)
+#define PCU_BSM_CTRL_DEFAULT ((PCU_BSM_CTRL_IE_DEFAULT << PCU_BSM_CTRL_IE_OFFSET ) |\
+ (PCU_BSM_CTRL_CMD_DEFAULT << PCU_BSM_CTRL_CMD_OFFSET ) |\
+ (PCU_BSM_CTRL_SYNC_DEFAULT << PCU_BSM_CTRL_SYNC_OFFSET ) |\
+ (PCU_BSM_CTRL_LINK1_DEFAULT << PCU_BSM_CTRL_LINK1_OFFSET) |\
+ (PCU_BSM_CTRL_LINK0_DEFAULT << PCU_BSM_CTRL_LINK0_OFFSET))
+
+#define PCU_BSM_STATUS_STS_MASK (ANDES_BIT_MASK(31, 28))
+#define PCU_BSM_STATUS_STS_OFFSET (28)
+#define PCU_BSM_STATUS_STS_DEFAULT (0x0)
+#define PCU_BSM_STATUS_SYNC_MASK (ANDES_BIT_MASK(27, 24))
+#define PCU_BSM_STATUS_SYNC_OFFSET (24)
+#define PCU_BSM_STATUS_SYNC_DEFAULT (0x0)
+#define PCU_BSM_STATUS_CI1_MASK (ANDES_BIT_MASK(7, 4))
+#define PCU_BSM_STATUS_CI1_OFFSET (4)
+#define PCU_BSM_STATUS_CI1_DEFAULT (0x0)
+#define PCU_BSM_STATUS_CI0_MASK (ANDES_BIT_MASK(3, 0))
+#define PCU_BSM_STATUS_CI0_OFFSET (0)
+#define PCU_BSM_STATUS_CI0_DEFAULT (0x0)
+#define PCU_BSM_STATUS_DEFAULT ((PCU_BSM_STATUS_STS_DEFAULT << PCU_BSM_STATUS_STS_OFFSET) |\
+ (PCU_BSM_STATUS_CI1_DEFAULT << PCU_BSM_STATUS_CI1_OFFSET) |\
+ (PCU_BSM_STATUS_CI0_DEFAULT << PCU_BSM_STATUS_CI0_OFFSET))
+
+//wakeup event sensitivity
+#define PCU_WAKEUP_SEN_POL15_MASK (ANDES_BIT_MASK(15, 15))
+#define PCU_WAKEUP_SEN_POL15_OFFSET (15)
+#define PCU_WAKEUP_SEN_POL15_DEFAULT (0x0)
+#define PCU_WAKEUP_SEN_POL14_MASK (ANDES_BIT_MASK(14, 14))
+#define PCU_WAKEUP_SEN_POL14_OFFSET (14)
+#define PCU_WAKEUP_SEN_POL14_DEFAULT (0x0)
+#define PCU_WAKEUP_SEN_POL13_MASK (ANDES_BIT_MASK(13, 13))
+#define PCU_WAKEUP_SEN_POL13_OFFSET (13)
+#define PCU_WAKEUP_SEN_POL13_DEFAULT (0x0)
+#define PCU_WAKEUP_SEN_POL12_MASK (ANDES_BIT_MASK(12, 12))
+#define PCU_WAKEUP_SEN_POL12_OFFSET (12)
+#define PCU_WAKEUP_SEN_POL12_DEFAULT (0x0)
+#define PCU_WAKEUP_SEN_POL11_MASK (ANDES_BIT_MASK(11, 11))
+#define PCU_WAKEUP_SEN_POL11_OFFSET (11)
+#define PCU_WAKEUP_SEN_POL11_DEFAULT (0x0)
+#define PCU_WAKEUP_SEN_POL10_MASK (ANDES_BIT_MASK(10, 10))
+#define PCU_WAKEUP_SEN_POL10_OFFSET (10)
+#define PCU_WAKEUP_SEN_POL10_DEFAULT (0x0)
+#define PCU_WAKEUP_SEN_POL9_MASK (ANDES_BIT_MASK(9, 9))
+#define PCU_WAKEUP_SEN_POL9_OFFSET (9)
+#define PCU_WAKEUP_SEN_POL9_DEFAULT (0x0)
+#define PCU_WAKEUP_SEN_POL8_MASK (ANDES_BIT_MASK(8, 8))
+#define PCU_WAKEUP_SEN_POL8_OFFSET (8)
+#define PCU_WAKEUP_SEN_POL8_DEFAULT (0x1)
+#define PCU_WAKEUP_SEN_POL7_MASK (ANDES_BIT_MASK(7, 7))
+#define PCU_WAKEUP_SEN_POL7_OFFSET (7)
+#define PCU_WAKEUP_SEN_POL7_DEFAULT (0x1)
+#define PCU_WAKEUP_SEN_POL6_MASK (ANDES_BIT_MASK(6, 6))
+#define PCU_WAKEUP_SEN_POL6_OFFSET (6)
+#define PCU_WAKEUP_SEN_POL6_DEFAULT (0x1)
+#define PCU_WAKEUP_SEN_POL5_MASK (ANDES_BIT_MASK(5, 5))
+#define PCU_WAKEUP_SEN_POL5_OFFSET (5)
+#define PCU_WAKEUP_SEN_POL5_DEFAULT (0x0)
+#define PCU_WAKEUP_SEN_POL4_MASK (ANDES_BIT_MASK(4, 4))
+#define PCU_WAKEUP_SEN_POL4_OFFSET (4)
+#define PCU_WAKEUP_SEN_POL4_DEFAULT (0x0)
+#define PCU_WAKEUP_SEN_POL3_MASK (ANDES_BIT_MASK(3, 3))
+#define PCU_WAKEUP_SEN_POL3_OFFSET (3)
+#define PCU_WAKEUP_SEN_POL3_DEFAULT (0x0)
+#define PCU_WAKEUP_SEN_POL2_MASK (ANDES_BIT_MASK(2, 2))
+#define PCU_WAKEUP_SEN_POL2_OFFSET (2)
+#define PCU_WAKEUP_SEN_POL2_DEFAULT (0x0)
+#define PCU_WAKEUP_SEN_POL1_MASK (ANDES_BIT_MASK(1, 1))
+#define PCU_WAKEUP_SEN_POL1_OFFSET (1)
+#define PCU_WAKEUP_SEN_POL1_DEFAULT (0x0)
+#define PCU_WAKEUP_SEN_POL0_MASK (ANDES_BIT_MASK(0, 0))
+#define PCU_WAKEUP_SEN_POL0_OFFSET (0)
+#define PCU_WAKEUP_SEN_POL0_DEFAULT (0x0)
+#define PCU_WAKEUP_SEN_POL_MASK (ANDES_BIT_MASK(15, 0))
+#define PCU_WAKEUP_SEN_POL_OFFSET (0)
+#define PCU_WAKEUP_SEN_POL_DEFAULT ((PCU_WAKEUP_SEN_POL15_DEFAULT << PCU_WAKEUP_SEN_POL15_OFFSET) |\
+ (PCU_WAKEUP_SEN_POL14_DEFAULT << PCU_WAKEUP_SEN_POL14_OFFSET) |\
+ (PCU_WAKEUP_SEN_POL13_DEFAULT << PCU_WAKEUP_SEN_POL13_OFFSET) |\
+ (PCU_WAKEUP_SEN_POL12_DEFAULT << PCU_WAKEUP_SEN_POL12_OFFSET) |\
+ (PCU_WAKEUP_SEN_POL11_DEFAULT << PCU_WAKEUP_SEN_POL11_OFFSET) |\
+ (PCU_WAKEUP_SEN_POL10_DEFAULT << PCU_WAKEUP_SEN_POL10_OFFSET) |\
+ (PCU_WAKEUP_SEN_POL9_DEFAULT << PCU_WAKEUP_SEN_POL9_OFFSET ) |\
+ (PCU_WAKEUP_SEN_POL8_DEFAULT << PCU_WAKEUP_SEN_POL8_OFFSET ) |\
+ (PCU_WAKEUP_SEN_POL7_DEFAULT << PCU_WAKEUP_SEN_POL7_OFFSET ) |\
+ (PCU_WAKEUP_SEN_POL6_DEFAULT << PCU_WAKEUP_SEN_POL6_OFFSET ) |\
+ (PCU_WAKEUP_SEN_POL5_DEFAULT << PCU_WAKEUP_SEN_POL5_OFFSET ) |\
+ (PCU_WAKEUP_SEN_POL4_DEFAULT << PCU_WAKEUP_SEN_POL4_OFFSET ) |\
+ (PCU_WAKEUP_SEN_POL3_DEFAULT << PCU_WAKEUP_SEN_POL3_OFFSET ) |\
+ (PCU_WAKEUP_SEN_POL2_DEFAULT << PCU_WAKEUP_SEN_POL3_OFFSET ) |\
+ (PCU_WAKEUP_SEN_POL1_DEFAULT << PCU_WAKEUP_SEN_POL2_OFFSET ) |\
+ (PCU_WAKEUP_SEN_POL0_DEFAULT << PCU_WAKEUP_SEN_POL0_OFFSET ) )
+#define PCU_WAKEUP_SEN_DEFAULT (PCU_WAKEUP_SEN_POL_DEFAULT)
+#define PCU_WAKEUP_SEN_DFT_MASK (PCU_WAKEUP_SEN_POL_MASK)
+
+#define PCU_WAKEUP_SEN_GPIO0_POL_MASK PCU_WAKEUP_SEN_POL0_MASK
+#define PCU_WAKEUP_SEN_GPIO0_POL_OFFSET PCU_WAKEUP_SEN_POL0_OFFSET
+#define PCU_WAKEUP_SEN_GPIO0_POL_DEFAULT PCU_WAKEUP_SEN_POL0_DEFAULT
+#define PCU_WAKEUP_SEN_GPIO1_POL_MASK PCU_WAKEUP_SEN_POL1_MASK
+#define PCU_WAKEUP_SEN_GPIO1_POL_OFFSET PCU_WAKEUP_SEN_POL1_OFFSET
+#define PCU_WAKEUP_SEN_GPIO1_POL_DEFAULT PCU_WAKEUP_SEN_POL1_DEFAULT
+#define PCU_WAKEUP_SEN_GPIO2_POL_MASK PCU_WAKEUP_SEN_POL2_MASK
+#define PCU_WAKEUP_SEN_GPIO2_POL_OFFSET PCU_WAKEUP_SEN_POL2_OFFSET
+#define PCU_WAKEUP_SEN_GPIO2_POL_DEFAULT PCU_WAKEUP_SEN_POL2_DEFAULT
+#define PCU_WAKEUP_SEN_GPIO3_POL_MASK PCU_WAKEUP_SEN_POL3_MASK
+#define PCU_WAKEUP_SEN_GPIO3_POL_OFFSET PCU_WAKEUP_SEN_POL3_OFFSET
+#define PCU_WAKEUP_SEN_GPIO3_POL_DEFAULT PCU_WAKEUP_SEN_POL3_DEFAULT
+#define PCU_WAKEUP_SEN_GPIO4_POL_MASK PCU_WAKEUP_SEN_POL4_MASK
+#define PCU_WAKEUP_SEN_GPIO4_POL_OFFSET PCU_WAKEUP_SEN_POL4_OFFSET
+#define PCU_WAKEUP_SEN_GPIO4_POL_DEFAULT PCU_WAKEUP_SEN_POL4_DEFAULT
+#define PCU_WAKEUP_SEN_GPIO5_POL_MASK PCU_WAKEUP_SEN_POL5_MASK
+#define PCU_WAKEUP_SEN_GPIO5_POL_OFFSET PCU_WAKEUP_SEN_POL5_OFFSET
+#define PCU_WAKEUP_SEN_GPIO5_POL_DEFAULT PCU_WAKEUP_SEN_POL5_DEFAULT
+#define PCU_WAKEUP_SEN_WOL_POL_MASK PCU_WAKEUP_SEN_POL6_MASK
+#define PCU_WAKEUP_SEN_WOL_POL_OFFSET PCU_WAKEUP_SEN_POL6_OFFSET
+#define PCU_WAKEUP_SEN_WOL_POL_DEFAULT PCU_WAKEUP_SEN_POL6_DEFAULT
+#define PCU_WAKEUP_SEN_RTC_POL_MASK PCU_WAKEUP_SEN_POL7_MASK
+#define PCU_WAKEUP_SEN_RTC_POL_OFFSET PCU_WAKEUP_SEN_POL7_OFFSET
+#define PCU_WAKEUP_SEN_RTC_POL_DEFAULT PCU_WAKEUP_SEN_POL7_DEFAULT
+#define PCU_WAKEUP_SEN_DAY_POL_OFFSET PCU_WAKEUP_SEN_POL8_OFFSET
+#define PCU_WAKEUP_SEN_DAY_POL_DEFAULT PCU_WAKEUP_SEN_POL8_DEFAULT
+#define PCU_WAKEUP_SEN_DBG_POL_MASK PCU_WAKEUP_SEN_POL9_MASK
+#define PCU_WAKEUP_SEN_DBG_POL_OFFSET PCU_WAKEUP_SEN_POL9_OFFSET
+#define PCU_WAKEUP_SEN_DBG_POL_DEFAULT PCU_WAKEUP_SEN_POL9_DEFAULT
+#define PCU_WAKEUP_SEN_PCI_POL_MASK PCU_WAKEUP_SEN_POL10_MASK
+#define PCU_WAKEUP_SEN_PCI_POL_OFFSET PCU_WAKEUP_SEN_POL10_OFFSET
+#define PCU_WAKEUP_SEN_PCI_POL_DEFAULT PCU_WAKEUP_SEN_POL10_DEFAULT
+#define PCU_WAKEUP_SEN_LPC_POL_MASK PCU_WAKEUP_SEN_POL11_MASK
+#define PCU_WAKEUP_SEN_LPC_POL_OFFSET PCU_WAKEUP_SEN_POL11_OFFSET
+#define PCU_WAKEUP_SEN_LPC_POL_DEFAULT PCU_WAKEUP_SEN_POL11_DEFAULT
+
+// wakeup event status register
+#define PCU_WAKEUP_STATUS_SIG_MASK (ANDES_BIT_MASK(15, 0))
+#define PCU_WAKEUP_STATUS_SIG_OFFSET (0)
+#define PCU_WAKEUP_STATUS_SIG_DEFAULT (0x0)
+#define PCU_WAKEUP_STATUS_DEFAULT (PCU_WAKEUP_STATUS_SIG_DEFAULT << PCU_WAKEUP_STATUS_SIG_OFFSET)
+#define PCU_WAKEUP_STATUS_DFT_MASK (PCU_WAKEUP_STATUS_SIG_MASK)
+
+//reset timing
+#define PCU_RESET_TIMER_RG3_MASK (ANDES_BIT_MASK(31, 24))
+#define PCU_RESET_TIMER_RG3_OFFSET (24)
+#define PCU_RESET_TIMER_RG3_DEFAULT PCU_RESET_TIMER_RG3_CNT_DEFAULT // in rtl fast reset, this will be 0x2
+#define PCU_RESET_TIMER_RG3_SRC_MASK (ANDES_BIT_MASK(31, 31))
+#define PCU_RESET_TIMER_RG3_SRC_OFFSET (31)
+#define PCU_RESET_TIMER_RG3_SRC_DEFAULT (0x0)
+#define PCU_RESET_TIMER_RG3_CNT_MASK (ANDES_BIT_MASK(30, 24))
+#define PCU_RESET_TIMER_RG3_CNT_OFFSET (24)
+#define PCU_RESET_TIMER_RG3_CNT_DEFAULT (0x4)
+#define PCU_RESET_TIMER_RG2_MASK (ANDES_BIT_MASK(23, 16))
+#define PCU_RESET_TIMER_RG2_OFFSET (16)
+#define PCU_RESET_TIMER_RG2_DEFAULT PCU_RESET_TIMER_RG2_CNT_DEFAULT // in rtl fast reset, this will be 0x2
+#define PCU_RESET_TIMER_RG2_SRC_MASK (ANDES_BIT_MASK(23, 23))
+#define PCU_RESET_TIMER_RG2_SRC_OFFSET (23)
+#define PCU_RESET_TIMER_RG2_SRC_DEFAULT (0x0)
+#define PCU_RESET_TIMER_RG2_CNT_MASK (ANDES_BIT_MASK(22, 16))
+#define PCU_RESET_TIMER_RG2_CNT_OFFSET (16)
+#define PCU_RESET_TIMER_RG2_CNT_DEFAULT (0x4)
+#define PCU_RESET_TIMER_RG1_MASK (ANDES_BIT_MASK(15, 8))
+#define PCU_RESET_TIMER_RG1_OFFSET (8)
+#define PCU_RESET_TIMER_RG1_DEFAULT PCU_RESET_TIMER_RG1_CNT_DEFAULT // in rtl fast reset, this will be 0x2
+#define PCU_RESET_TIMER_RG1_SRC_MASK (ANDES_BIT_MASK(15, 15))
+#define PCU_RESET_TIMER_RG1_SRC_OFFSET (15)
+#define PCU_RESET_TIMER_RG1_SRC_DEFAULT (0x0)
+#define PCU_RESET_TIMER_RG1_CNT_MASK (ANDES_BIT_MASK(14, 8))
+#define PCU_RESET_TIMER_RG1_CNT_OFFSET (8)
+#define PCU_RESET_TIMER_RG1_CNT_DEFAULT (0x4)
+#define PCU_RESET_TIMER_RG0_MASK (ANDES_BIT_MASK(7, 0))
+#define PCU_RESET_TIMER_RG0_OFFSET (0)
+#define PCU_RESET_TIMER_RG0_DEFAULT PCU_RESET_TIMER_RG0_CNT_DEFAULT // in rtl fast reset, this will be 0x2
+#define PCU_RESET_TIMER_RG0_SRC_MASK (ANDES_BIT_MASK(7, 7))
+#define PCU_RESET_TIMER_RG0_SRC_OFFSET (7)
+#define PCU_RESET_TIMER_RG0_SRC_DEFAULT (0x0)
+#define PCU_RESET_TIMER_RG0_CNT_MASK (ANDES_BIT_MASK(6, 0))
+#define PCU_RESET_TIMER_RG0_CNT_OFFSET (0)
+#define PCU_RESET_TIMER_RG0_CNT_DEFAULT (0x4)
+
+#define PCU_RESET_TIMER_DEFAULT 0x0 /*((PCU_RESET_TIMER_RG3_DEFAULT << PCU_RESET_TIMER_RG3_OFFSET)|\
+ (PCU_RESET_TIMER_RG2_DEFAULT << PCU_RESET_TIMER_RG2_OFFSET)|\
+ (PCU_RESET_TIMER_RG1_DEFAULT << PCU_RESET_TIMER_RG1_OFFSET)|\
+ (PCU_RESET_TIMER_RG0_DEFAULT << PCU_RESET_TIMER_RG0_OFFSET))*/
+#define PCU_RESET_TIMER_DFT_MASK 0x0 /*((PCU_RESET_TIMER_RG3_MASK)|\
+ (PCU_RESET_TIMER_RG2_MASK)|\
+ (PCU_RESET_TIMER_RG1_MASK)|\
+ (PCU_RESET_TIMER_RG0_MASK))*/
+#define PCU_RST_TIMER_SRC_500US (0x1)
+#define PCU_RST_TIMER_SRC_30US (0x0)
+
+// interrupt
+#define PCU_INTR_GPIOSEC_MASK (ANDES_BIT_MASK(11, 11))
+#define PCU_INTR_PWRLOW_MASK (ANDES_BIT_MASK(10, 10))
+#define PCU_INTR_PCS9_MASK (ANDES_BIT_MASK(9, 9))
+#define PCU_INTR_PCS9_OFFSET (9)
+#define PCU_INTR_PCS9_DEFAULT (0x0)
+#define PCU_INTR_PCS8_MASK (ANDES_BIT_MASK(8, 8))
+#define PCU_INTR_PCS8_OFFSET (8)
+#define PCU_INTR_PCS8_DEFAULT (0x0)
+#define PCU_INTR_PCS7_MASK (ANDES_BIT_MASK(7, 7))
+#define PCU_INTR_PCS7_OFFSET (7)
+#define PCU_INTR_PCS7_DEFAULT (0x0)
+#define PCU_INTR_PCS6_MASK (ANDES_BIT_MASK(6, 6))
+#define PCU_INTR_PCS6_OFFSET (6)
+#define PCU_INTR_PCS6_DEFAULT (0x0)
+#define PCU_INTR_PCS5_MASK (ANDES_BIT_MASK(5, 5))
+#define PCU_INTR_PCS5_OFFSET (5)
+#define PCU_INTR_PCS5_DEFAULT (0x0)
+#define PCU_INTR_PCS4_MASK (ANDES_BIT_MASK(4, 4))
+#define PCU_INTR_PCS4_OFFSET (4)
+#define PCU_INTR_PCS4_DEFAULT (0x0)
+#define PCU_INTR_PCS3_MASK (ANDES_BIT_MASK(3, 3))
+#define PCU_INTR_PCS3_OFFSET (3)
+#define PCU_INTR_PCS3_DEFAULT (0x0)
+#define PCU_INTR_PCS2_MASK (ANDES_BIT_MASK(2, 2))
+#define PCU_INTR_PCS2_OFFSET (2)
+#define PCU_INTR_PCS2_DEFAULT (0x0)
+#define PCU_INTR_PCS1_MASK (ANDES_BIT_MASK(1, 1))
+#define PCU_INTR_PCS1_OFFSET (1)
+#define PCU_INTR_PCS1_DEFAULT (0x0)
+#define PCU_INTR_BSM_MASK (ANDES_BIT_MASK(0, 0))
+#define PCU_INTR_BSM_OFFSET (0)
+#define PCU_INTR_BSM_DEFAULT (0x0)
+#define PCU_INTR_DEFAULT (0x0)
+
+// bits field for PCS1 registers
+#define PCU_PCS1_CFG_TYPE_MASK (ANDES_BIT_MASK(30, 28))
+#define PCU_PCS1_CFG_TYPE_OFFSET (28)
+#define PCU_PCS1_CFG_TYPE_DEFAULT (0x1)
+#define PCU_PCS1_CFG_WR_MASK (ANDES_BIT_MASK(27, 27))
+#define PCU_PCS1_CFG_WR_OFFSET (27)
+#define PCU_PCS1_CFG_WR_DEFAULT (0x0)
+#define PCU_PCS1_CFG_SR_MASK (ANDES_BIT_MASK(26, 26))
+#define PCU_PCS1_CFG_SR_OFFSET (0)
+#define PCU_PCS1_CFG_SR_DEFAULT (0x0)
+#define PCU_PCS1_CFG_LS_MASK (ANDES_BIT_MASK(23, 20))
+#define PCU_PCS1_CFG_LS_OFFSET (20)
+#define PCU_PCS1_CFG_LS_DEFAULT (0x0)
+#define PCU_PCS1_CFG_LW_MASK (ANDES_BIT_MASK(19, 16))
+#define PCU_PCS1_CFG_LW_OFFSET (16)
+#define PCU_PCS1_CFG_LW_DEFAULT (0x0)
+#define PCU_PCS1_CFG_WKEN_MASK (ANDES_BIT_MASK(15, 0))
+#define PCU_PCS1_CFG_WKEN_OFFSET (0)
+#define PCU_PCS1_CFG_WKEN_DEFAULT (0x0)
+#define PCU_PCS1_CFG_DEFAULT ((PCU_PCS1_CFG_TYPE_DEFAULT << PCU_PCS1_CFG_TYPE_OFFSET)|\
+ (PCU_PCS1_CFG_WR_DEFAULT << PCU_PCS1_CFG_WR_OFFSET )|\
+ (PCU_PCS1_CFG_SR_DEFAULT << PCU_PCS1_CFG_SR_OFFSET )|\
+ (PCU_PCS1_CFG_LS_DEFAULT << PCU_PCS1_CFG_LS_OFFSET )|\
+ (PCU_PCS1_CFG_LW_DEFAULT << PCU_PCS1_CFG_LW_OFFSET )|\
+ (PCU_PCS1_CFG_WKEN_DEFAULT << PCU_PCS1_CFG_WKEN_OFFSET))
+
+#define PCU_PCS1_PARA_IE_MASK (ANDES_BIT_MASK(31, 31))
+#define PCU_PCS1_PARA_IE_OFFSET (31)
+#define PCU_PCS1_PARA_IE_DEFAULT (0x0)
+#define PCU_PCS1_PARA_CMD_MASK (ANDES_BIT_MASK(30, 28))
+#define PCU_PCS1_PARA_CMD_OFFSET (28)
+#define PCU_PCS1_PARA_CMD_DEFAULT (0x0)
+#define PCU_PCS1_PARA_SYNC_MASK (ANDES_BIT_MASK(27, 24))
+#define PCU_PCS1_PARA_SYNC_OFFSET (24)
+#define PCU_PCS1_PARA_SYNC_DEFAULT (0x3)
+#define PCU_PCS1_PARA_NXTPAR_MASK (ANDES_BIT_MASK(23, 0))
+#define PCU_PCS1_PARA_NXTPAR_OFFSET (0)
+#define PCU_PCS1_PARA_NXTPAR_DEFAULT (0x1)
+#define PCU_PCS1_PARA_DIV_MASK (ANDES_BIT_MASK(5, 4))
+#define PCU_PCS1_PARA_DIV_OFFSET (4)
+//#define PCU_PCS1_PARA_DIV_DEFAULT (0x0) //jumper setting
+#define PCU_PCS1_PARA_RATIO_MASK (ANDES_BIT_MASK(3, 0))
+#define PCU_PCS1_PARA_RATIO_OFFSET (0)
+//#define PCU_PCS1_PARA_RATIO_DEFAULT (0x0) //jumper setting
+#define PCU_PCS1_PARA_DEFAULT ((PCU_PCS1_PARA_IE_DEFAULT << PCU_PCS1_PARA_IE_OFFSET )|\
+ (PCU_PCS1_PARA_CMD_DEFAULT << PCU_PCS1_PARA_CMD_OFFSET )|\
+ (PCU_PCS1_PARA_SYNC_DEFAULT << PCU_PCS1_PARA_SYNC_OFFSET))
+#define PCU_PCS1_PARA_DFT_MASK ((PCU_PCS1_PARA_IE_MASK )|\
+ (PCU_PCS1_PARA_CMD_MASK )|\
+ (PCU_PCS1_PARA_SYNC_MASK))
+
+#define PCU_PCS1_ST1_STS_MASK (ANDES_BIT_MASK(30, 28))
+#define PCU_PCS1_ST1_STS_OFFSET (28)
+#define PCU_PCS1_ST1_STS_DEFAULT (0x0)
+#define PCU_PCS1_ST1_ERR_MASK (ANDES_BIT_MASK(3, 0))
+#define PCU_PCS1_ST1_ERR_OFFSET (0)
+#define PCU_PCS1_ST1_ERR_DEFAULT (0x0)
+#define PCU_PCS1_ST1_DEFAULT ((PCU_PCS1_ST1_STS_DEFAULT << PCU_PCS1_ST1_STS_OFFSET )|\
+ (PCU_PCS1_ST1_ERR_DEFAULT << PCU_PCS1_ST1_ERR_OFFSET ))
+
+#define PCU_PCS1_ST2_SYNC_MASK (ANDES_BIT_MASK(27, 24))
+#define PCU_PCS1_ST2_SYNC_OFFSET (24)
+#define PCU_PCS1_ST2_SYNC_DEFAULT (0x0)
+#define PCU_PCS1_ST2_CURPAR_MASK (ANDES_BIT_MASK(23, 0))
+#define PCU_PCS1_ST2_CURPAR_OFFSET (0)
+//#define PCU_PCS1_ST2_CURPAR_DEFAULT (0x0)
+#define PCU_PCS1_ST2_DIV_MASK (ANDES_BIT_MASK(5, 4))
+#define PCU_PCS1_ST2_DIV_OFFSET (4)
+//#define PCU_PCS1_ST2_DIV_DEFAULT (0x0) //jumper setting
+#define PCU_PCS1_ST2_RATIO_MASK (ANDES_BIT_MASK(3, 0))
+#define PCU_PCS1_ST2_RATIO_OFFSET (0)
+//#define PCU_PCS1_ST2_RATIO_DEFAULT (0x0) //jumper setting
+#define PCU_PCS1_ST2_DEFAULT (PCU_PCS1_ST2_SYNC_DEFAULT << PCU_PCS1_ST2_SYNC_OFFSET)
+#define PCU_PCS1_ST2_DFT_MASK (PCU_PCS1_ST2_SYNC_MASK)
+
+
+// bits field for PCS2 registers
+#define PCU_PCS2_CFG_TYPE_MASK (ANDES_BIT_MASK(30, 28))
+#define PCU_PCS2_CFG_TYPE_OFFSET (28)
+#define PCU_PCS2_CFG_TYPE_DEFAULT (0x2)
+#define PCU_PCS2_CFG_WR_MASK (ANDES_BIT_MASK(27, 27))
+#define PCU_PCS2_CFG_WR_OFFSET (27)
+#define PCU_PCS2_CFG_WR_DEFAULT (0x0)
+#define PCU_PCS2_CFG_SR_MASK (ANDES_BIT_MASK(26, 26))
+#define PCU_PCS2_CFG_SR_OFFSET (0)
+#define PCU_PCS2_CFG_SR_DEFAULT (0x0)
+#define PCU_PCS2_CFG_LS_MASK (ANDES_BIT_MASK(23, 20))
+#define PCU_PCS2_CFG_LS_OFFSET (20)
+#define PCU_PCS2_CFG_LS_DEFAULT (0x0)
+#define PCU_PCS2_CFG_LW_MASK (ANDES_BIT_MASK(19, 16))
+#define PCU_PCS2_CFG_LW_OFFSET (16)
+#define PCU_PCS2_CFG_LW_DEFAULT (0x0)
+#define PCU_PCS2_CFG_WKEN_MASK (ANDES_BIT_MASK(15, 0))
+#define PCU_PCS2_CFG_WKEN_OFFSET (0)
+#define PCU_PCS2_CFG_WKEN_DEFAULT (0x0)
+#define PCU_PCS2_CFG_DEFAULT ((PCU_PCS2_CFG_TYPE_DEFAULT << PCU_PCS2_CFG_TYPE_OFFSET)|\
+ (PCU_PCS2_CFG_WR_DEFAULT << PCU_PCS2_CFG_WR_OFFSET )|\
+ (PCU_PCS2_CFG_SR_DEFAULT << PCU_PCS2_CFG_SR_OFFSET )|\
+ (PCU_PCS2_CFG_LS_DEFAULT << PCU_PCS2_CFG_LS_OFFSET )|\
+ (PCU_PCS2_CFG_LW_DEFAULT << PCU_PCS2_CFG_LW_OFFSET )|\
+ (PCU_PCS2_CFG_WKEN_DEFAULT << PCU_PCS2_CFG_WKEN_OFFSET))
+
+#define PCU_PCS2_PARA_IE_MASK (ANDES_BIT_MASK(31, 31))
+#define PCU_PCS2_PARA_IE_OFFSET (31)
+#define PCU_PCS2_PARA_IE_DEFAULT (0x0)
+#define PCU_PCS2_PARA_CMD_MASK (ANDES_BIT_MASK(30, 28))
+#define PCU_PCS2_PARA_CMD_OFFSET (28)
+#define PCU_PCS2_PARA_CMD_DEFAULT (0x0)
+#define PCU_PCS2_PARA_SYNC_MASK (ANDES_BIT_MASK(27, 24))
+#define PCU_PCS2_PARA_SYNC_OFFSET (24)
+#define PCU_PCS2_PARA_SYNC_DEFAULT (0x3)
+#define PCU_PCS2_PARA_NXTPAR_MASK (ANDES_BIT_MASK(23, 0))
+#define PCU_PCS2_PARA_NXTPAR_OFFSET (0)
+#define PCU_PCS2_PARA_NXTPAR_DEFAULT (0x0)
+#define PCU_PCS2_PARA_DEFAULT ((PCU_PCS2_PARA_IE_DEFAULT << PCU_PCS2_PARA_IE_OFFSET )|\
+ (PCU_PCS2_PARA_CMD_DEFAULT << PCU_PCS2_PARA_CMD_OFFSET )|\
+ (PCU_PCS2_PARA_SYNC_DEFAULT << PCU_PCS2_PARA_SYNC_OFFSET )|\
+ (PCU_PCS2_PARA_NXTPAR_DEFAULT << PCU_PCS2_PARA_NXTPAR_OFFSET))
+#define PCU_PCS2_PARA_DFT_MASK ((PCU_PCS2_PARA_IE_MASK )|\
+ (PCU_PCS2_PARA_CMD_MASK )|\
+ (PCU_PCS2_PARA_SYNC_MASK )|\
+ (PCU_PCS2_PARA_NXTPAR_MASK))
+
+#define PCU_PCS2_ST1_STS_MASK (ANDES_BIT_MASK(30, 28))
+#define PCU_PCS2_ST1_STS_OFFSET (28)
+#define PCU_PCS2_ST1_STS_DEFAULT (0x0)
+#define PCU_PCS2_ST1_ERR_MASK (ANDES_BIT_MASK(3, 0))
+#define PCU_PCS2_ST1_ERR_OFFSET (0)
+#define PCU_PCS2_ST1_ERR_DEFAULT (0x0)
+#define PCU_PCS2_ST1_DEFAULT ((PCU_PCS2_ST1_STS_DEFAULT << PCU_PCS2_ST1_STS_OFFSET )|\
+ (PCU_PCS2_ST1_ERR_DEFAULT << PCU_PCS2_ST1_ERR_OFFSET ))
+
+#define PCU_PCS2_ST2_SYNC_MASK (ANDES_BIT_MASK(27, 24))
+#define PCU_PCS2_ST2_SYNC_OFFSET (24)
+#define PCU_PCS2_ST2_SYNC_DEFAULT (0x0)
+#define PCU_PCS2_ST2_CURPAR_MASK (ANDES_BIT_MASK(23, 0))
+#define PCU_PCS2_ST2_CURPAR_OFFSET (0)
+#define PCU_PCS2_ST2_CURPAR_DEFAULT (0x0)
+#define PCU_PCS2_ST2_DEFAULT ((PCU_PCS2_ST2_SYNC_DEFAULT << PCU_PCS2_ST2_SYNC_OFFSET )|\
+ (PCU_PCS2_ST2_CURPAR_DEFAULT << PCU_PCS2_ST2_CURPAR_OFFSET))
+#define PCU_PCS2_ST2_DFT_MASK ((PCU_PCS2_ST2_SYNC_MASK )|\
+ (PCU_PCS2_ST2_CURPAR_MASK))
+
+// bits field for PCS3 registers
+#define PCU_PCS3_CFG_TYPE_MASK (ANDES_BIT_MASK(30, 28))
+#define PCU_PCS3_CFG_TYPE_OFFSET (28)
+#define PCU_PCS3_CFG_TYPE_DEFAULT (0x2)
+#define PCU_PCS3_CFG_WR_MASK (ANDES_BIT_MASK(27, 27))
+#define PCU_PCS3_CFG_WR_OFFSET (27)
+#define PCU_PCS3_CFG_WR_DEFAULT (0x0)
+#define PCU_PCS3_CFG_SR_MASK (ANDES_BIT_MASK(26, 26))
+#define PCU_PCS3_CFG_SR_OFFSET (0)
+#define PCU_PCS3_CFG_SR_DEFAULT (0x0)
+#define PCU_PCS3_CFG_LS_MASK (ANDES_BIT_MASK(23, 20))
+#define PCU_PCS3_CFG_LS_OFFSET (20)
+#define PCU_PCS3_CFG_LS_DEFAULT (0x0)
+#define PCU_PCS3_CFG_LW_MASK (ANDES_BIT_MASK(19, 16))
+#define PCU_PCS3_CFG_LW_OFFSET (16)
+#define PCU_PCS3_CFG_LW_DEFAULT (0x0)
+#define PCU_PCS3_CFG_WKEN_MASK (ANDES_BIT_MASK(15, 0))
+#define PCU_PCS3_CFG_WKEN_OFFSET (0)
+#define PCU_PCS3_CFG_WKEN_DEFAULT (0x0)
+#define PCU_PCS3_CFG_DEFAULT ((PCU_PCS3_CFG_TYPE_DEFAULT << PCU_PCS3_CFG_TYPE_OFFSET)|\
+ (PCU_PCS3_CFG_WR_DEFAULT << PCU_PCS3_CFG_WR_OFFSET )|\
+ (PCU_PCS3_CFG_SR_DEFAULT << PCU_PCS3_CFG_SR_OFFSET )|\
+ (PCU_PCS3_CFG_LS_DEFAULT << PCU_PCS3_CFG_LS_OFFSET )|\
+ (PCU_PCS3_CFG_LW_DEFAULT << PCU_PCS3_CFG_LW_OFFSET )|\
+ (PCU_PCS3_CFG_WKEN_DEFAULT << PCU_PCS3_CFG_WKEN_OFFSET))
+
+#define PCU_PCS3_PARA_IE_MASK (ANDES_BIT_MASK(31, 31))
+#define PCU_PCS3_PARA_IE_OFFSET (31)
+#define PCU_PCS3_PARA_IE_DEFAULT (0x0)
+#define PCU_PCS3_PARA_CMD_MASK (ANDES_BIT_MASK(30, 28))
+#define PCU_PCS3_PARA_CMD_OFFSET (28)
+#define PCU_PCS3_PARA_CMD_DEFAULT (0x0)
+#define PCU_PCS3_PARA_SYNC_MASK (ANDES_BIT_MASK(27, 24))
+#define PCU_PCS3_PARA_SYNC_OFFSET (24)
+#define PCU_PCS3_PARA_SYNC_DEFAULT (0x3)
+#define PCU_PCS3_PARA_NXTPAR_MASK (ANDES_BIT_MASK(23, 0))
+#define PCU_PCS3_PARA_NXTPAR_OFFSET (0)
+#define PCU_PCS3_PARA_NXTPAR_DEFAULT (0x0)
+#define PCU_PCS3_PARA_DEFAULT ((PCU_PCS3_PARA_IE_DEFAULT << PCU_PCS3_PARA_IE_OFFSET )|\
+ (PCU_PCS3_PARA_CMD_DEFAULT << PCU_PCS3_PARA_CMD_OFFSET )|\
+ (PCU_PCS3_PARA_SYNC_DEFAULT << PCU_PCS3_PARA_SYNC_OFFSET )|\
+ (PCU_PCS3_PARA_NXTPAR_DEFAULT << PCU_PCS3_PARA_NXTPAR_OFFSET))
+#define PCU_PCS3_PARA_DFT_MASK ((PCU_PCS3_PARA_IE_MASK )|\
+ (PCU_PCS3_PARA_CMD_MASK )|\
+ (PCU_PCS3_PARA_SYNC_MASK )|\
+ (PCU_PCS3_PARA_NXTPAR_MASK))
+
+#define PCU_PCS3_ST1_STS_MASK (ANDES_BIT_MASK(30, 28))
+#define PCU_PCS3_ST1_STS_OFFSET (28)
+#define PCU_PCS3_ST1_STS_DEFAULT (0x0)
+#define PCU_PCS3_ST1_ERR_MASK (ANDES_BIT_MASK(3, 0))
+#define PCU_PCS3_ST1_ERR_OFFSET (0)
+#define PCU_PCS3_ST1_ERR_DEFAULT (0x0)
+#define PCU_PCS3_ST1_DEFAULT ((PCU_PCS3_ST1_STS_DEFAULT << PCU_PCS3_ST1_STS_OFFSET )|\
+ (PCU_PCS3_ST1_ERR_DEFAULT << PCU_PCS3_ST1_ERR_OFFSET ))
+
+#define PCU_PCS3_ST2_SYNC_MASK (ANDES_BIT_MASK(27, 24))
+#define PCU_PCS3_ST2_SYNC_OFFSET (24)
+#define PCU_PCS3_ST2_SYNC_DEFAULT (0x0)
+#define PCU_PCS3_ST2_CURPAR_MASK (ANDES_BIT_MASK(23, 0))
+#define PCU_PCS3_ST2_CURPAR_OFFSET (0)
+#define PCU_PCS3_ST2_CURPAR_DEFAULT (0x0)
+#define PCU_PCS3_ST2_DEFAULT ((PCU_PCS3_ST2_SYNC_DEFAULT << PCU_PCS3_ST2_SYNC_OFFSET )|\
+ (PCU_PCS3_ST2_CURPAR_DEFAULT << PCU_PCS3_ST2_CURPAR_OFFSET))
+#define PCU_PCS3_ST2_DFT_MASK ((PCU_PCS3_ST2_SYNC_MASK )|\
+ (PCU_PCS3_ST2_CURPAR_MASK))
+
+// bits field for PCS4 registers
+#define PCU_PCS4_CFG_TYPE_MASK (ANDES_BIT_MASK(30, 28))
+#define PCU_PCS4_CFG_TYPE_OFFSET (28)
+#define PCU_PCS4_CFG_TYPE_DEFAULT (0x0)
+#define PCU_PCS4_CFG_WR_MASK (ANDES_BIT_MASK(27, 27))
+#define PCU_PCS4_CFG_WR_OFFSET (27)
+#define PCU_PCS4_CFG_WR_DEFAULT (0x0)
+#define PCU_PCS4_CFG_SR_MASK (ANDES_BIT_MASK(26, 26))
+#define PCU_PCS4_CFG_SR_OFFSET (0)
+#define PCU_PCS4_CFG_SR_DEFAULT (0x0)
+#define PCU_PCS4_CFG_LS_MASK (ANDES_BIT_MASK(23, 20))
+#define PCU_PCS4_CFG_LS_OFFSET (20)
+#define PCU_PCS4_CFG_LS_DEFAULT (0x0)
+#define PCU_PCS4_CFG_LW_MASK (ANDES_BIT_MASK(19, 16))
+#define PCU_PCS4_CFG_LW_OFFSET (16)
+#define PCU_PCS4_CFG_LW_DEFAULT (0x0)
+#define PCU_PCS4_CFG_WKEN_MASK (ANDES_BIT_MASK(15, 0))
+#define PCU_PCS4_CFG_WKEN_OFFSET (0)
+#define PCU_PCS4_CFG_WKEN_DEFAULT (0x0)
+#define PCU_PCS4_CFG_DEFAULT ((PCU_PCS4_CFG_TYPE_DEFAULT << PCU_PCS4_CFG_TYPE_OFFSET)|\
+ (PCU_PCS4_CFG_WR_DEFAULT << PCU_PCS4_CFG_WR_OFFSET )|\
+ (PCU_PCS4_CFG_SR_DEFAULT << PCU_PCS4_CFG_SR_OFFSET )|\
+ (PCU_PCS4_CFG_LS_DEFAULT << PCU_PCS4_CFG_LS_OFFSET )|\
+ (PCU_PCS4_CFG_LW_DEFAULT << PCU_PCS4_CFG_LW_OFFSET )|\
+ (PCU_PCS4_CFG_WKEN_DEFAULT << PCU_PCS4_CFG_WKEN_OFFSET))
+
+#define PCU_PCS4_PARA_IE_MASK (ANDES_BIT_MASK(31, 31))
+#define PCU_PCS4_PARA_IE_OFFSET (31)
+#define PCU_PCS4_PARA_IE_DEFAULT (0x0)
+#define PCU_PCS4_PARA_CMD_MASK (ANDES_BIT_MASK(30, 28))
+#define PCU_PCS4_PARA_CMD_OFFSET (28)
+#define PCU_PCS4_PARA_CMD_DEFAULT (0x0)
+#define PCU_PCS4_PARA_SYNC_MASK (ANDES_BIT_MASK(27, 24))
+#define PCU_PCS4_PARA_SYNC_OFFSET (24)
+#define PCU_PCS4_PARA_SYNC_DEFAULT (0x3)
+#define PCU_PCS4_PARA_NXTPAR_MASK (ANDES_BIT_MASK(23, 0))
+#define PCU_PCS4_PARA_NXTPAR_OFFSET (0)
+#define PCU_PCS4_PARA_NXTPAR_DEFAULT (0x4)
+#define PCU_PCS4_PARA_PWDN_MASK (ANDES_BIT_MASK(23, 23))
+#define PCU_PCS4_PARA_PWDN_OFFSET (23)
+#define PCU_PCS4_PARA_PWDN_DEFAULT (0x0)
+#define PCU_PCS4_PARA_RANGE_MASK (ANDES_BIT_MASK(17, 16))
+#define PCU_PCS4_PARA_RANGE_OFFSET (16)
+#define PCU_PCS4_PARA_RANGE_DEFAULT (0x0)
+#define PCU_PCS4_PARA_N_FACTOR_MASK (ANDES_BIT_MASK(7, 0))
+#define PCU_PCS4_PARA_N_FACTOR_OFFSET (0)
+#define PCU_PCS4_PARA_N_FACTOR_DEFAULT (0x4)
+#define PCU_PCS4_PARA_DEFAULT ((PCU_PCS4_PARA_IE_DEFAULT << PCU_PCS4_PARA_IE_OFFSET )|\
+ (PCU_PCS4_PARA_CMD_DEFAULT << PCU_PCS4_PARA_CMD_OFFSET )|\
+ (PCU_PCS4_PARA_SYNC_DEFAULT << PCU_PCS4_PARA_SYNC_OFFSET)|\
+ (PCU_PCS4_PARA_PWDN_DEFAULT << PCU_PCS4_PARA_PWDN_OFFSET))
+#define PCU_PCS4_PARA_DFT_MASK ((PCU_PCS4_PARA_IE_MASK )|\
+ (PCU_PCS4_PARA_CMD_MASK )|\
+ (PCU_PCS4_PARA_SYNC_MASK)|\
+ (PCU_PCS4_PARA_PWDN_MASK))
+
+#define PCU_PCS4_ST1_STS_MASK (ANDES_BIT_MASK(30, 28))
+#define PCU_PCS4_ST1_STS_OFFSET (28)
+#define PCU_PCS4_ST1_STS_DEFAULT (0x0)
+#define PCU_PCS4_ST1_ERR_MASK (ANDES_BIT_MASK(3, 0))
+#define PCU_PCS4_ST1_ERR_OFFSET (0)
+#define PCU_PCS4_ST1_ERR_DEFAULT (0x0)
+#define PCU_PCS4_ST1_DEFAULT ((PCU_PCS4_ST1_STS_DEFAULT << PCU_PCS4_ST1_STS_OFFSET )|\
+ (PCU_PCS4_ST1_ERR_DEFAULT << PCU_PCS4_ST1_ERR_OFFSET ))
+
+#define PCU_PCS4_ST2_SYNC_MASK (ANDES_BIT_MASK(27, 24))
+#define PCU_PCS4_ST2_SYNC_OFFSET (24)
+#define PCU_PCS4_ST2_SYNC_DEFAULT (0x0)
+#define PCU_PCS4_ST2_CURPAR_MASK (ANDES_BIT_MASK(23, 0))
+#define PCU_PCS4_ST2_CURPAR_OFFSET (0)
+//#define PCU_PCS4_ST2_CURPAR_DEFAULT (0x0)
+#define PCU_PCS4_ST2_PWDN_MASK PCU_PCS4_PARA_PWDN_MASK
+#define PCU_PCS4_ST2_PWDN_OFFSET PCU_PCS4_PARA_PWDN_OFFSET
+#define PCU_PCS4_ST2_PWDN_DEFAULT PCU_PCS4_PARA_PWDN_DEFAULT
+#define PCU_PCS4_ST2_RANGE_MASK PCU_PCS4_PARA_RANGE_MASK
+#define PCU_PCS4_ST2_RANGE_OFFSET PCU_PCS4_PARA_RANGE_OFFSET
+//#define PCU_PCS4_ST2_RANGE_DEFAULT PCU_PCS4_PARA_RANGE_DEFAULT
+#define PCU_PCS4_ST2_N_FACTOR_MASK PCU_PCS4_PARA_N_FACTOR_MASK
+#define PCU_PCS4_ST2_N_FACTOR_OFFSET PCU_PCS4_PARA_N_FACTOR_OFFSET
+//#define PCU_PCS4_ST2_N_FACTOR_DEFAULT PCU_PCS4_PARA_N_FACTOR_DEFAULT
+#define PCU_PCS4_ST2_DEFAULT ((PCU_PCS4_ST2_SYNC_DEFAULT << PCU_PCS4_ST2_SYNC_OFFSET)|\
+ (PCU_PCS4_ST2_PWDN_DEFAULT << PCU_PCS4_ST2_PWDN_OFFSET))
+#define PCU_PCS4_ST2_DFT_MASK ((PCU_PCS4_ST2_SYNC_MASK)|\
+ (PCU_PCS4_ST2_PWDN_MASK))
+
+// bits field for PCS5 registers
+#define PCU_PCS5_CFG_TYPE_MASK (ANDES_BIT_MASK(30, 28))
+#define PCU_PCS5_CFG_TYPE_OFFSET (28)
+#define PCU_PCS5_CFG_TYPE_DEFAULT (0x0)
+#define PCU_PCS5_CFG_WR_MASK (ANDES_BIT_MASK(27, 27))
+#define PCU_PCS5_CFG_WR_OFFSET (27)
+#define PCU_PCS5_CFG_WR_DEFAULT (0x0)
+#define PCU_PCS5_CFG_SR_MASK (ANDES_BIT_MASK(26, 26))
+#define PCU_PCS5_CFG_SR_OFFSET (0)
+#define PCU_PCS5_CFG_SR_DEFAULT (0x0)
+#define PCU_PCS5_CFG_LS_MASK (ANDES_BIT_MASK(23, 20))
+#define PCU_PCS5_CFG_LS_OFFSET (20)
+#define PCU_PCS5_CFG_LS_DEFAULT (0x0)
+#define PCU_PCS5_CFG_LW_MASK (ANDES_BIT_MASK(19, 16))
+#define PCU_PCS5_CFG_LW_OFFSET (16)
+#define PCU_PCS5_CFG_LW_DEFAULT (0x0)
+#define PCU_PCS5_CFG_WKEN_MASK (ANDES_BIT_MASK(15, 0))
+#define PCU_PCS5_CFG_WKEN_OFFSET (0)
+#define PCU_PCS5_CFG_WKEN_DEFAULT (0x0)
+#define PCU_PCS5_CFG_DEFAULT ((PCU_PCS5_CFG_TYPE_DEFAULT << PCU_PCS5_CFG_TYPE_OFFSET)|\
+ (PCU_PCS5_CFG_WR_DEFAULT << PCU_PCS5_CFG_WR_OFFSET )|\
+ (PCU_PCS5_CFG_SR_DEFAULT << PCU_PCS5_CFG_SR_OFFSET )|\
+ (PCU_PCS5_CFG_LS_DEFAULT << PCU_PCS5_CFG_LS_OFFSET )|\
+ (PCU_PCS5_CFG_LW_DEFAULT << PCU_PCS5_CFG_LW_OFFSET )|\
+ (PCU_PCS5_CFG_WKEN_DEFAULT << PCU_PCS5_CFG_WKEN_OFFSET))
+
+#define PCU_PCS5_PARA_IE_MASK (ANDES_BIT_MASK(31, 31))
+#define PCU_PCS5_PARA_IE_OFFSET (31)
+#define PCU_PCS5_PARA_IE_DEFAULT (0x0)
+#define PCU_PCS5_PARA_CMD_MASK (ANDES_BIT_MASK(30, 28))
+#define PCU_PCS5_PARA_CMD_OFFSET (28)
+#define PCU_PCS5_PARA_CMD_DEFAULT (0x0)
+#define PCU_PCS5_PARA_SYNC_MASK (ANDES_BIT_MASK(27, 24))
+#define PCU_PCS5_PARA_SYNC_OFFSET (24)
+#define PCU_PCS5_PARA_SYNC_DEFAULT (0x3)
+#define PCU_PCS5_PARA_NXTPAR_MASK (ANDES_BIT_MASK(23, 0))
+#define PCU_PCS5_PARA_NXTPAR_OFFSET (0)
+#define PCU_PCS5_PARA_NXTPAR_DEFAULT (0x0)
+#define PCU_PCS5_PARA_DLL_PWDN_MASK (ANDES_BIT_MASK(23, 23))
+#define PCU_PCS5_PARA_DLL_PWDN_OFFSET (23)
+#define PCU_PCS5_PARA_DLL_PWDN_DEFAULT (0x0)
+#define PCU_PCS5_PARA_PLL_PWDN_MASK (ANDES_BIT_MASK(22, 22))
+#define PCU_PCS5_PARA_PLL_PWDN_OFFSET (22)
+#define PCU_PCS5_PARA_PLL_PWDN_DEFAULT (0x0)
+#define PCU_PCS5_PARA_DLL_BYPASS_MASK (ANDES_BIT_MASK(16, 16))
+#define PCU_PCS5_PARA_DLL_BYPASS_OFFSET (16)
+#define PCU_PCS5_PARA_DLL_BYPASS_DEFAULT (0x0)
+#define PCU_PCS5_PARA_DLL_DELAY_MASK (ANDES_BIT_MASK(15, 12))
+#define PCU_PCS5_PARA_DLL_DELAY_OFFSET (12)
+#define PCU_PCS5_PARA_DLL_DELAY_DEFAULT (0x0)
+#define PCU_PCS5_PARA_66MHZ_MASK (ANDES_BIT_MASK(11, 11))
+#define PCU_PCS5_PARA_66MHZ_OFFSET (11)
+//#define PCU_PCS5_PARA_66MHZ_DEFAULT (0x0) /dumper setting
+#define PCU_PCS5_PARA_DEFAULT ((PCU_PCS5_PARA_IE_DEFAULT << PCU_PCS5_PARA_IE_OFFSET )|\
+ (PCU_PCS5_PARA_CMD_DEFAULT << PCU_PCS5_PARA_CMD_OFFSET )|\
+ (PCU_PCS5_PARA_SYNC_DEFAULT << PCU_PCS5_PARA_SYNC_OFFSET )|\
+ (PCU_PCS5_PARA_PLL_PWDN_DEFAULT << PCU_PCS5_PARA_PLL_PWDN_OFFSET )|\
+ (PCU_PCS5_PARA_DLL_DELAY_DEFAULT << PCU_PCS5_PARA_DLL_DELAY_OFFSET ))
+#define PCU_PCS5_PARA_DFT_MASK ((PCU_PCS5_PARA_IE_MASK )|\
+ (PCU_PCS5_PARA_CMD_MASK )|\
+ (PCU_PCS5_PARA_SYNC_MASK )|\
+ (PCU_PCS5_PARA_PLL_PWDN_MASK )|\
+ (PCU_PCS5_PARA_DLL_DELAY_MASK ))
+
+#define PCU_PCS5_ST1_STS_MASK (ANDES_BIT_MASK(30, 28))
+#define PCU_PCS5_ST1_STS_OFFSET (28)
+#define PCU_PCS5_ST1_STS_DEFAULT (0x0)
+#define PCU_PCS5_ST1_ERR_MASK (ANDES_BIT_MASK(3, 0))
+#define PCU_PCS5_ST1_ERR_OFFSET (0)
+#define PCU_PCS5_ST1_ERR_DEFAULT (0x0)
+#define PCU_PCS5_ST1_DEFAULT ((PCU_PCS5_ST1_STS_DEFAULT << PCU_PCS5_ST1_STS_OFFSET )|\
+ (PCU_PCS5_ST1_ERR_DEFAULT << PCU_PCS5_ST1_ERR_OFFSET ))
+
+#define PCU_PCS5_ST2_SYNC_MASK (ANDES_BIT_MASK(27, 24))
+#define PCU_PCS5_ST2_SYNC_OFFSET (24)
+#define PCU_PCS5_ST2_SYNC_DEFAULT (0x0)
+#define PCU_PCS5_ST2_CURPAR_MASK (ANDES_BIT_MASK(23, 0))
+#define PCU_PCS5_ST2_CURPAR_OFFSET (0)
+//#define PCU_PCS5_ST2_CURPAR_DEFAULT (0x0) //no default
+#define PCU_PCS5_ST2_DLL_PWDN_MASK PCU_PCS5_PARA_DLL_PWDN_MASK
+#define PCU_PCS5_ST2_DLL_PWDN_OFFSET PCU_PCS5_PARA_DLL_PWDN_OFFSET
+#define PCU_PCS5_ST2_DLL_PWDN_DEFAULT PCU_PCS5_PARA_DLL_PWDN_DEFAULT
+#define PCU_PCS5_ST2_PLL_PWDN_MASK PCU_PCS5_PARA_PLL_PWDN_MASK
+#define PCU_PCS5_ST2_PLL_PWDN_OFFSET PCU_PCS5_PARA_PLL_PWDN_OFFSET
+#define PCU_PCS5_ST2_PLL_PWDN_DEFAULT PCU_PCS5_PARA_PLL_PWDN_DEFAULT
+#define PCU_PCS5_ST2_DLL_BYPASS_MASK PCU_PCS5_PARA_DLL_BYPASS_MASK
+#define PCU_PCS5_ST2_DLL_BYPASS_OFFSET PCU_PCS5_PARA_DLL_BYPASS_OFFSET
+#define PCU_PCS5_ST2_DLL_BYPASS_DEFAULT PCU_PCS5_PARA_DLL_BYPASS_DEFAULT
+#define PCU_PCS5_ST2_DLL_DELAY_MASK PCU_PCS5_PARA_DLL_DELAY_MASK
+#define PCU_PCS5_ST2_DLL_DELAY_OFFSET PCU_PCS5_PARA_DLL_DELAY_OFFSET
+#define PCU_PCS5_ST2_DLL_DELAY_DEFAULT PCU_PCS5_PARA_DLL_DELAY_DEFAULT
+#define PCU_PCS5_ST2_DEFAULT ((PCU_PCS5_ST2_SYNC_DEFAULT << PCU_PCS5_ST2_SYNC_OFFSET )|\
+ (PCU_PCS5_ST2_PLL_PWDN_DEFAULT << PCU_PCS5_ST2_PLL_PWDN_OFFSET )|\
+ (PCU_PCS5_ST2_DLL_DELAY_DEFAULT << PCU_PCS5_ST2_DLL_DELAY_OFFSET ))
+#define PCU_PCS5_ST2_DFT_MASK ((PCU_PCS5_ST2_SYNC_MASK )|\
+ (PCU_PCS5_ST2_PLL_PWDN_MASK )|\
+ (PCU_PCS5_ST2_DLL_DELAY_MASK ))
+
+// bits field for PCS6 registers
+#define PCU_PCS6_CFG_TYPE_MASK (ANDES_BIT_MASK(30, 28))
+#define PCU_PCS6_CFG_TYPE_OFFSET (28)
+#define PCU_PCS6_CFG_TYPE_DEFAULT (0x0)
+#define PCU_PCS6_CFG_WR_MASK (ANDES_BIT_MASK(27, 27))
+#define PCU_PCS6_CFG_WR_OFFSET (27)
+#define PCU_PCS6_CFG_WR_DEFAULT (0x0)
+#define PCU_PCS6_CFG_SR_MASK (ANDES_BIT_MASK(26, 26))
+#define PCU_PCS6_CFG_SR_OFFSET (0)
+#define PCU_PCS6_CFG_SR_DEFAULT (0x0)
+#define PCU_PCS6_CFG_LS_MASK (ANDES_BIT_MASK(23, 20))
+#define PCU_PCS6_CFG_LS_OFFSET (20)
+#define PCU_PCS6_CFG_LS_DEFAULT (0x0)
+#define PCU_PCS6_CFG_LW_MASK (ANDES_BIT_MASK(19, 16))
+#define PCU_PCS6_CFG_LW_OFFSET (16)
+#define PCU_PCS6_CFG_LW_DEFAULT (0x0)
+#define PCU_PCS6_CFG_WKEN_MASK (ANDES_BIT_MASK(15, 0))
+#define PCU_PCS6_CFG_WKEN_OFFSET (0)
+#define PCU_PCS6_CFG_WKEN_DEFAULT (0x0)
+#define PCU_PCS6_CFG_DEFAULT ((PCU_PCS6_CFG_TYPE_DEFAULT << PCU_PCS6_CFG_TYPE_OFFSET)|\
+ (PCU_PCS6_CFG_WR_DEFAULT << PCU_PCS6_CFG_WR_OFFSET )|\
+ (PCU_PCS6_CFG_SR_DEFAULT << PCU_PCS6_CFG_SR_OFFSET )|\
+ (PCU_PCS6_CFG_LS_DEFAULT << PCU_PCS6_CFG_LS_OFFSET )|\
+ (PCU_PCS6_CFG_LW_DEFAULT << PCU_PCS6_CFG_LW_OFFSET )|\
+ (PCU_PCS6_CFG_WKEN_DEFAULT << PCU_PCS6_CFG_WKEN_OFFSET))
+
+#define PCU_PCS6_PARA_IE_MASK (ANDES_BIT_MASK(31, 31))
+#define PCU_PCS6_PARA_IE_OFFSET (31)
+#define PCU_PCS6_PARA_IE_DEFAULT (0x0)
+#define PCU_PCS6_PARA_CMD_MASK (ANDES_BIT_MASK(30, 28))
+#define PCU_PCS6_PARA_CMD_OFFSET (28)
+#define PCU_PCS6_PARA_CMD_DEFAULT (0x0)
+#define PCU_PCS6_PARA_SYNC_MASK (ANDES_BIT_MASK(27, 24))
+#define PCU_PCS6_PARA_SYNC_OFFSET (24)
+#define PCU_PCS6_PARA_SYNC_DEFAULT (0x3)
+#define PCU_PCS6_PARA_NXTPAR_MASK (ANDES_BIT_MASK(23, 0))
+#define PCU_PCS6_PARA_NXTPAR_OFFSET (0)
+#define PCU_PCS6_PARA_NXTPAR_DEFAULT (0x0)
+#define PCU_PCS6_PARA_PWDN_MASK (ANDES_BIT_MASK(23, 23))
+#define PCU_PCS6_PARA_PWDN_OFFSET (23)
+#define PCU_PCS6_PARA_PWDN_DEFAULT (0x0)
+#define PCU_PCS6_PARA_DEFAULT ((PCU_PCS6_PARA_IE_DEFAULT << PCU_PCS6_PARA_IE_OFFSET )|\
+ (PCU_PCS6_PARA_CMD_DEFAULT << PCU_PCS6_PARA_CMD_OFFSET )|\
+ (PCU_PCS6_PARA_SYNC_DEFAULT << PCU_PCS6_PARA_SYNC_OFFSET)|\
+ (PCU_PCS6_PARA_PWDN_DEFAULT << PCU_PCS6_PARA_PWDN_OFFSET))
+#define PCU_PCS6_PARA_DFT_MASK ((PCU_PCS6_PARA_IE_MASK )|\
+ (PCU_PCS6_PARA_CMD_MASK )|\
+ (PCU_PCS6_PARA_SYNC_MASK)|\
+ (PCU_PCS6_PARA_PWDN_MASK))
+
+#define PCU_PCS6_ST1_STS_MASK (ANDES_BIT_MASK(30, 28))
+#define PCU_PCS6_ST1_STS_OFFSET (28)
+#define PCU_PCS6_ST1_STS_DEFAULT (0x0)
+#define PCU_PCS6_ST1_ERR_MASK (ANDES_BIT_MASK(3, 0))
+#define PCU_PCS6_ST1_ERR_OFFSET (0)
+#define PCU_PCS6_ST1_ERR_DEFAULT (0x0)
+#define PCU_PCS6_ST1_DEFAULT ((PCU_PCS6_ST1_STS_DEFAULT << PCU_PCS6_ST1_STS_OFFSET )|\
+ (PCU_PCS6_ST1_ERR_DEFAULT << PCU_PCS6_ST1_ERR_OFFSET ))
+
+#define PCU_PCS6_ST2_SYNC_MASK (ANDES_BIT_MASK(27, 24))
+#define PCU_PCS6_ST2_SYNC_OFFSET (24)
+#define PCU_PCS6_ST2_SYNC_DEFAULT (0x0)
+#define PCU_PCS6_ST2_CURPAR_MASK (ANDES_BIT_MASK(23, 0))
+#define PCU_PCS6_ST2_CURPAR_OFFSET (0)
+//#define PCU_PCS6_ST2_CURPAR_DEFAULT (0x0) //no default
+#define PCU_PCS6_ST2_PWDN_MASK PCU_PCS6_PARA_PWDN_MASK
+#define PCU_PCS6_ST2_PWDN_OFFSET PCU_PCS6_PARA_PWDN_OFFSET
+#define PCU_PCS6_ST2_PWDN_DEFAULT PCU_PCS6_PARA_PWDN_DEFAULT
+#define PCU_PCS6_ST2_DEFAULT ((PCU_PCS6_ST2_SYNC_DEFAULT << PCU_PCS6_ST2_SYNC_OFFSET)|\
+ (PCU_PCS6_ST2_PWDN_DEFAULT << PCU_PCS6_ST2_PWDN_OFFSET))
+#define PCU_PCS6_ST2_DFT_MASK ((PCU_PCS6_ST2_SYNC_MASK)|\
+ (PCU_PCS6_ST2_PWDN_MASK))
+
+// bits field for PCS7 registers
+#define PCU_PCS7_CFG_TYPE_MASK (ANDES_BIT_MASK(30, 28))
+#define PCU_PCS7_CFG_TYPE_OFFSET (28)
+#define PCU_PCS7_CFG_TYPE_DEFAULT (0x0)
+#define PCU_PCS7_CFG_WR_MASK (ANDES_BIT_MASK(27, 27))
+#define PCU_PCS7_CFG_WR_OFFSET (27)
+#define PCU_PCS7_CFG_WR_DEFAULT (0x0)
+#define PCU_PCS7_CFG_SR_MASK (ANDES_BIT_MASK(26, 26))
+#define PCU_PCS7_CFG_SR_OFFSET (0)
+#define PCU_PCS7_CFG_SR_DEFAULT (0x0)
+#define PCU_PCS7_CFG_LS_MASK (ANDES_BIT_MASK(23, 20))
+#define PCU_PCS7_CFG_LS_OFFSET (20)
+#define PCU_PCS7_CFG_LS_DEFAULT (0x0)
+#define PCU_PCS7_CFG_LW_MASK (ANDES_BIT_MASK(19, 16))
+#define PCU_PCS7_CFG_LW_OFFSET (16)
+#define PCU_PCS7_CFG_LW_DEFAULT (0x0)
+#define PCU_PCS7_CFG_WKEN_MASK (ANDES_BIT_MASK(15, 0))
+#define PCU_PCS7_CFG_WKEN_OFFSET (0)
+#define PCU_PCS7_CFG_WKEN_DEFAULT (0x0)
+#define PCU_PCS7_CFG_DEFAULT ((PCU_PCS7_CFG_TYPE_DEFAULT << PCU_PCS7_CFG_TYPE_OFFSET)|\
+ (PCU_PCS7_CFG_WR_DEFAULT << PCU_PCS7_CFG_WR_OFFSET )|\
+ (PCU_PCS7_CFG_SR_DEFAULT << PCU_PCS7_CFG_SR_OFFSET )|\
+ (PCU_PCS7_CFG_LS_DEFAULT << PCU_PCS7_CFG_LS_OFFSET )|\
+ (PCU_PCS7_CFG_LW_DEFAULT << PCU_PCS7_CFG_LW_OFFSET )|\
+ (PCU_PCS7_CFG_WKEN_DEFAULT << PCU_PCS7_CFG_WKEN_OFFSET))
+
+#define PCU_PCS7_PARA_IE_MASK (ANDES_BIT_MASK(31, 31))
+#define PCU_PCS7_PARA_IE_OFFSET (31)
+#define PCU_PCS7_PARA_IE_DEFAULT (0x0)
+#define PCU_PCS7_PARA_CMD_MASK (ANDES_BIT_MASK(30, 28))
+#define PCU_PCS7_PARA_CMD_OFFSET (28)
+#define PCU_PCS7_PARA_CMD_DEFAULT (0x0)
+#define PCU_PCS7_PARA_SYNC_MASK (ANDES_BIT_MASK(27, 24))
+#define PCU_PCS7_PARA_SYNC_OFFSET (24)
+#define PCU_PCS7_PARA_SYNC_DEFAULT (0x3)
+#define PCU_PCS7_PARA_NXTPAR_MASK (ANDES_BIT_MASK(23, 0))
+#define PCU_PCS7_PARA_NXTPAR_OFFSET (0)
+#define PCU_PCS7_PARA_NXTPAR_DEFAULT (0x0)
+#define PCU_PCS7_PARA_PWDN_MASK (ANDES_BIT_MASK(23, 23))
+#define PCU_PCS7_PARA_PWDN_OFFSET (23)
+#define PCU_PCS7_PARA_PWDN_DEFAULT (0x0)
+#define PCU_PCS7_PARA_DEFAULT ((PCU_PCS7_PARA_IE_DEFAULT << PCU_PCS7_PARA_IE_OFFSET )|\
+ (PCU_PCS7_PARA_CMD_DEFAULT << PCU_PCS7_PARA_CMD_OFFSET )|\
+ (PCU_PCS7_PARA_SYNC_DEFAULT << PCU_PCS7_PARA_SYNC_OFFSET)|\
+ (PCU_PCS7_PARA_PWDN_DEFAULT << PCU_PCS7_PARA_PWDN_OFFSET))
+#define PCU_PCS7_PARA_DFT_MASK ((PCU_PCS7_PARA_IE_MASK )|\
+ (PCU_PCS7_PARA_CMD_MASK )|\
+ (PCU_PCS7_PARA_SYNC_MASK)|\
+ (PCU_PCS7_PARA_PWDN_MASK))
+
+#define PCU_PCS7_ST1_STS_MASK (ANDES_BIT_MASK(30, 28))
+#define PCU_PCS7_ST1_STS_OFFSET (28)
+#define PCU_PCS7_ST1_STS_DEFAULT (0x0)
+#define PCU_PCS7_ST1_ERR_MASK (ANDES_BIT_MASK(3, 0))
+#define PCU_PCS7_ST1_ERR_OFFSET (0)
+#define PCU_PCS7_ST1_ERR_DEFAULT (0x0)
+#define PCU_PCS7_ST1_DEFAULT ((PCU_PCS7_ST1_STS_DEFAULT << PCU_PCS7_ST1_STS_OFFSET )|\
+ (PCU_PCS7_ST1_ERR_DEFAULT << PCU_PCS7_ST1_ERR_OFFSET ))
+
+#define PCU_PCS7_ST2_SYNC_MASK (ANDES_BIT_MASK(27, 24))
+#define PCU_PCS7_ST2_SYNC_OFFSET (24)
+#define PCU_PCS7_ST2_SYNC_DEFAULT (0x0)
+#define PCU_PCS7_ST2_CURPAR_MASK (ANDES_BIT_MASK(23, 0))
+#define PCU_PCS7_ST2_CURPAR_OFFSET (0)
+//#define PCU_PCS7_ST2_CURPAR_DEFAULT (0x0) //no default
+#define PCU_PCS7_ST2_PWDN_MASK PCU_PCS7_PARA_PWDN_MASK
+#define PCU_PCS7_ST2_PWDN_OFFSET PCU_PCS7_PARA_PWDN_OFFSET
+#define PCU_PCS7_ST2_PWDN_DEFAULT PCU_PCS7_PARA_PWDN_DEFAULT
+#define PCU_PCS7_ST2_DEFAULT ((PCU_PCS7_ST2_SYNC_DEFAULT << PCU_PCS7_ST2_SYNC_OFFSET)|\
+ (PCU_PCS7_ST2_PWDN_DEFAULT << PCU_PCS7_ST2_PWDN_OFFSET))
+#define PCU_PCS7_ST2_DFT_MASK ((PCU_PCS7_ST2_SYNC_MASK)|\
+ (PCU_PCS7_ST2_PWDN_MASK))
+
+// bits field for PCS8 registers
+#define PCU_PCS8_CFG_TYPE_MASK (ANDES_BIT_MASK(30, 28))
+#define PCU_PCS8_CFG_TYPE_OFFSET (28)
+#define PCU_PCS8_CFG_TYPE_DEFAULT (0x4)
+#define PCU_PCS8_CFG_WR_MASK (ANDES_BIT_MASK(27, 27))
+#define PCU_PCS8_CFG_WR_OFFSET (27)
+#define PCU_PCS8_CFG_WR_DEFAULT (0x0)
+#define PCU_PCS8_CFG_SR_MASK (ANDES_BIT_MASK(26, 26))
+#define PCU_PCS8_CFG_SR_OFFSET (0)
+#define PCU_PCS8_CFG_SR_DEFAULT (0x0)
+#define PCU_PCS8_CFG_LS_MASK (ANDES_BIT_MASK(23, 20))
+#define PCU_PCS8_CFG_LS_OFFSET (20)
+#define PCU_PCS8_CFG_LS_DEFAULT (0x0)
+#define PCU_PCS8_CFG_LW_MASK (ANDES_BIT_MASK(19, 16))
+#define PCU_PCS8_CFG_LW_OFFSET (16)
+#define PCU_PCS8_CFG_LW_DEFAULT (0x0)
+#define PCU_PCS8_CFG_WKEN_MASK (ANDES_BIT_MASK(15, 0))
+#define PCU_PCS8_CFG_WKEN_OFFSET (0)
+#define PCU_PCS8_CFG_WKEN_DEFAULT (0x0)
+#define PCU_PCS8_CFG_DEFAULT ((PCU_PCS8_CFG_TYPE_DEFAULT << PCU_PCS8_CFG_TYPE_OFFSET)|\
+ (PCU_PCS8_CFG_WR_DEFAULT << PCU_PCS8_CFG_WR_OFFSET )|\
+ (PCU_PCS8_CFG_SR_DEFAULT << PCU_PCS8_CFG_SR_OFFSET )|\
+ (PCU_PCS8_CFG_LS_DEFAULT << PCU_PCS8_CFG_LS_OFFSET )|\
+ (PCU_PCS8_CFG_LW_DEFAULT << PCU_PCS8_CFG_LW_OFFSET )|\
+ (PCU_PCS8_CFG_WKEN_DEFAULT << PCU_PCS8_CFG_WKEN_OFFSET))
+
+#define PCU_PCS8_PARA_IE_MASK (ANDES_BIT_MASK(31, 31))
+#define PCU_PCS8_PARA_IE_OFFSET (31)
+#define PCU_PCS8_PARA_IE_DEFAULT (0x0)
+#define PCU_PCS8_PARA_CMD_MASK (ANDES_BIT_MASK(30, 28))
+#define PCU_PCS8_PARA_CMD_OFFSET (28)
+#define PCU_PCS8_PARA_CMD_DEFAULT (0x0)
+#define PCU_PCS8_PARA_SYNC_MASK (ANDES_BIT_MASK(27, 24))
+#define PCU_PCS8_PARA_SYNC_OFFSET (24)
+#define PCU_PCS8_PARA_SYNC_DEFAULT (0x3)
+#define PCU_PCS8_PARA_NXTPAR_MASK (ANDES_BIT_MASK(23, 0))
+#define PCU_PCS8_PARA_NXTPAR_OFFSET (0)
+#define PCU_PCS8_PARA_NXTPAR_DEFAULT (0x0)
+#define PCU_PCS8_PARA_STOP_MASK (ANDES_BIT_MASK(13, 13))
+#define PCU_PCS8_PARA_STOP_OFFSET (13)
+#define PCU_PCS8_PARA_STOP_DEFAULT (0x0)
+#define PCU_PCS8_PARA_START_MASK (ANDES_BIT_MASK(12, 12))
+#define PCU_PCS8_PARA_START_OFFSET (12)
+#define PCU_PCS8_PARA_START_DEFAULT (0x0)
+#define PCU_PCS8_PARA_BYTES_MASK (ANDES_BIT_MASK(10, 8))
+#define PCU_PCS8_PARA_BYTES_OFFSET (8)
+#define PCU_PCS8_PARA_BYTES_DEFAULT (0x0)
+#define PCU_PCS8_PARA_ADDR_MASK (ANDES_BIT_MASK(7, 1))
+#define PCU_PCS8_PARA_ADDR_OFFSET (1)
+#define PCU_PCS8_PARA_ADDR_DEFAULT (0x0)
+#define PCU_PCS8_PARA_READ_MASK (ANDES_BIT_MASK(0, 0))
+#define PCU_PCS8_PARA_READ_OFFSET (0)
+#define PCU_PCS8_PARA_READ_DEFAULT (0x0)
+#define PCU_PCS8_PARA_DEFAULT ((PCU_PCS8_PARA_IE_DEFAULT << PCU_PCS8_PARA_IE_OFFSET )|\
+ (PCU_PCS8_PARA_CMD_DEFAULT << PCU_PCS8_PARA_CMD_OFFSET )|\
+ (PCU_PCS8_PARA_SYNC_DEFAULT << PCU_PCS8_PARA_SYNC_OFFSET )|\
+ (PCU_PCS8_PARA_NXTPAR_DEFAULT << PCU_PCS8_PARA_NXTPAR_OFFSET))
+
+
+#define PCU_PCS8_ST1_STS_MASK (ANDES_BIT_MASK(30, 28))
+#define PCU_PCS8_ST1_STS_OFFSET (28)
+#define PCU_PCS8_ST1_STS_DEFAULT (0x0)
+#define PCU_PCS8_ST1_ERR_MASK (ANDES_BIT_MASK(3, 0))
+#define PCU_PCS8_ST1_ERR_OFFSET (0)
+#define PCU_PCS8_ST1_ERR_DEFAULT (0x0)
+#define PCU_PCS8_ST1_DEFAULT ((PCU_PCS8_ST1_STS_DEFAULT << PCU_PCS8_ST1_STS_OFFSET )|\
+ (PCU_PCS8_ST1_ERR_DEFAULT << PCU_PCS8_ST1_ERR_OFFSET ))
+
+#define PCU_PCS8_ST2_SYNC_MASK (ANDES_BIT_MASK(27, 24))
+#define PCU_PCS8_ST2_SYNC_OFFSET (24)
+#define PCU_PCS8_ST2_SYNC_DEFAULT (0x0)
+#define PCU_PCS8_ST2_CURPAR_MASK PCU_PCS8_PARA_NXTPAR_MASK
+#define PCU_PCS8_ST2_CURPAR_OFFSET PCU_PCS8_PARA_NXTPAR_OFFSET
+#define PCU_PCS8_ST2_CURPAR_DEFAULT PCU_PCS8_PARA_NXTPAR_DEFAULT
+#define PCU_PCS8_ST2_DEFAULT ((PCU_PCS8_ST2_SYNC_DEFAULT << PCU_PCS8_ST2_SYNC_OFFSET )|\
+ (PCU_PCS8_ST2_CURPAR_DEFAULT << PCU_PCS8_ST2_CURPAR_OFFSET))
+
+
+#define PCU_PCS8_PDD_4TH_BYTE_MASK (ANDES_BIT_MASK(31, 24))
+#define PCU_PCS8_PDD_4TH_BYTE_OFFSET (24)
+#define PCU_PCS8_PDD_4TH_BYTE_DEFAULT (0x0)
+#define PCU_PCS8_PDD_3RD_BYTE_MASK (ANDES_BIT_MASK(23, 16))
+#define PCU_PCS8_PDD_3RD_BYTE_OFFSET (16)
+#define PCU_PCS8_PDD_3RD_BYTE_DEFAULT (0x0)
+#define PCU_PCS8_PDD_2ND_BYTE_MASK (ANDES_BIT_MASK(15, 8))
+#define PCU_PCS8_PDD_2ND_BYTE_OFFSET (8)
+#define PCU_PCS8_PDD_2ND_BYTE_DEFAULT (0x0)
+#define PCU_PCS8_PDD_1ST_BYTE_MASK (ANDES_BIT_MASK(7, 0))
+#define PCU_PCS8_PDD_1ST_BYTE_OFFSET (0)
+#define PCU_PCS8_PDD_1ST_BYTE_DEFAULT (0x0)
+#define PCU_PCS8_PDD_DEFAULT ((PCU_PCS8_PDD_4TH_BYTE_DEFAULT << PCU_PCS8_PDD_4TH_BYTE_OFFSET)|\
+ (PCU_PCS8_PDD_3RD_BYTE_DEFAULT << PCU_PCS8_PDD_3RD_BYTE_OFFSET)|\
+ (PCU_PCS8_PDD_2ND_BYTE_DEFAULT << PCU_PCS8_PDD_2ND_BYTE_OFFSET)|\
+ (PCU_PCS8_PDD_1ST_BYTE_DEFAULT << PCU_PCS8_PDD_1ST_BYTE_OFFSET))
+
+// bits field for PCS9 registers
+#define PCU_PCS9_CFG_TYPE_MASK (ANDES_BIT_MASK(30, 28))
+#define PCU_PCS9_CFG_TYPE_OFFSET (28)
+#define PCU_PCS9_CFG_TYPE_DEFAULT (0x6)
+#define PCU_PCS9_CFG_WR_MASK (ANDES_BIT_MASK(27, 27))
+#define PCU_PCS9_CFG_WR_OFFSET (27)
+#define PCU_PCS9_CFG_WR_DEFAULT (0x0)
+#define PCU_PCS9_CFG_SR_MASK (ANDES_BIT_MASK(26, 26))
+#define PCU_PCS9_CFG_SR_OFFSET (0)
+#define PCU_PCS9_CFG_SR_DEFAULT (0x0)
+#define PCU_PCS9_CFG_LS_MASK (ANDES_BIT_MASK(23, 20))
+#define PCU_PCS9_CFG_LS_OFFSET (20)
+#define PCU_PCS9_CFG_LS_DEFAULT (0x0)
+#define PCU_PCS9_CFG_LW_MASK (ANDES_BIT_MASK(19, 16))
+#define PCU_PCS9_CFG_LW_OFFSET (16)
+#define PCU_PCS9_CFG_LW_DEFAULT (0x0)
+#define PCU_PCS9_CFG_WKEN_MASK (ANDES_BIT_MASK(15, 0))
+#define PCU_PCS9_CFG_WKEN_OFFSET (0)
+#define PCU_PCS9_CFG_WKEN_DEFAULT (0x0)
+#define PCU_PCS9_CFG_DEFAULT ((PCU_PCS9_CFG_TYPE_DEFAULT << PCU_PCS9_CFG_TYPE_OFFSET)|\
+ (PCU_PCS9_CFG_WR_DEFAULT << PCU_PCS9_CFG_WR_OFFSET )|\
+ (PCU_PCS9_CFG_SR_DEFAULT << PCU_PCS9_CFG_SR_OFFSET )|\
+ (PCU_PCS9_CFG_LS_DEFAULT << PCU_PCS9_CFG_LS_OFFSET )|\
+ (PCU_PCS9_CFG_LW_DEFAULT << PCU_PCS9_CFG_LW_OFFSET )|\
+ (PCU_PCS9_CFG_WKEN_DEFAULT << PCU_PCS9_CFG_WKEN_OFFSET))
+
+#define PCU_PCS9_PARA_IE_MASK (ANDES_BIT_MASK(31, 31))
+#define PCU_PCS9_PARA_IE_OFFSET (31)
+#define PCU_PCS9_PARA_IE_DEFAULT (0x0)
+#define PCU_PCS9_PARA_CMD_MASK (ANDES_BIT_MASK(30, 28))
+#define PCU_PCS9_PARA_CMD_OFFSET (28)
+#define PCU_PCS9_PARA_CMD_DEFAULT (0x0)
+#define PCU_PCS9_PARA_SYNC_MASK (ANDES_BIT_MASK(27, 24))
+#define PCU_PCS9_PARA_SYNC_OFFSET (24)
+#define PCU_PCS9_PARA_SYNC_DEFAULT (0x3)
+#define PCU_PCS9_PARA_NXTPAR_MASK (ANDES_BIT_MASK(23, 0))
+#define PCU_PCS9_PARA_NXTPAR_OFFSET (0)
+#define PCU_PCS9_PARA_NXTPAR_DEFAULT (0x0)
+#define PCU_PCS9_PARA_TEST_MASK (PCS_POWER_GPU_AND_DAC |\
+ PCS_POWER_CPUB )
+
+#define PCU_PCS9_PARA_TEST PCU_PCS9_PARA_TEST_MASK
+
+#define PCU_PCS9_PARA_DEFAULT ((PCU_PCS9_PARA_IE_DEFAULT << PCU_PCS9_PARA_IE_OFFSET )|\
+ (PCU_PCS9_PARA_CMD_DEFAULT << PCU_PCS9_PARA_CMD_OFFSET )|\
+ (PCU_PCS9_PARA_SYNC_DEFAULT << PCU_PCS9_PARA_SYNC_OFFSET )|\
+ (PCU_PCS9_PARA_NXTPAR_DEFAULT << PCU_PCS9_PARA_NXTPAR_OFFSET))
+
+#define PCU_PCS9_ST1_STS_MASK (ANDES_BIT_MASK(30, 28))
+#define PCU_PCS9_ST1_STS_OFFSET (28)
+#define PCU_PCS9_ST1_STS_DEFAULT (0x0)
+#define PCU_PCS9_ST1_ERR_MASK (ANDES_BIT_MASK(3, 0))
+#define PCU_PCS9_ST1_ERR_OFFSET (0)
+#define PCU_PCS9_ST1_ERR_DEFAULT (0x0)
+#define PCU_PCS9_ST1_DEFAULT ((PCU_PCS9_ST1_STS_DEFAULT << PCU_PCS9_ST1_STS_OFFSET )|\
+ (PCU_PCS9_ST1_ERR_DEFAULT << PCU_PCS9_ST1_ERR_OFFSET ))
+
+#define PCU_PCS9_ST2_SYNC_MASK (ANDES_BIT_MASK(27, 24))
+#define PCU_PCS9_ST2_SYNC_OFFSET (24)
+#define PCU_PCS9_ST2_SYNC_DEFAULT (0x0)
+#define PCU_PCS9_ST2_CURPAR_MASK PCU_PCS9_PARA_NXTPAR_MASK
+#define PCU_PCS9_ST2_CURPAR_OFFSET PCU_PCS9_PARA_NXTPAR_OFFSET
+#define PCU_PCS9_ST2_CURPAR_DEFAULT (0x1f)
+#define PCU_PCS9_ST2_DEFAULT ((PCU_PCS9_ST2_SYNC_DEFAULT << PCU_PCS9_ST2_SYNC_OFFSET )|\
+ (PCU_PCS9_ST2_CURPAR_DEFAULT << PCU_PCS9_ST2_CURPAR_OFFSET))
+
+#define PCU_PCS9_PDD_CLR_PWOFF_FLAG_MASK (ANDES_BIT_MASK(31, 31))
+#define PCU_PCS9_PDD_CLR_PWOFF_FLAG_OFFSET (31)
+#define PCU_PCS9_PDD_CLR_PWOFF_FLAG_DEFAULT (0x0)
+#define PCU_PCS9_PDD_SUSP2RAM_MASK (ANDES_BIT_MASK(30, 30))
+#define PCU_PCS9_PDD_SUSP2RAM_OFFSET (30)
+#define PCU_PCS9_PDD_SUSP2RAM_DEFAULT (0x0)
+#define PCU_PCS9_PDD_PWR_OFF_TIME_MASK (ANDES_BIT_MASK(29, 28))
+#define PCU_PCS9_PDD_PWR_OFF_TIME_OFFSET (28)
+#define PCU_PCS9_PDD_PWR_OFF_TIME_DEFAULT (0x3)
+#define PCU_PCS9_PDD_TICK_MASK (ANDES_BIT_MASK(24, 24))
+#define PCU_PCS9_PDD_TICK_OFFSET (24)
+#define PCU_PCS9_PDD_TICK_DEFAULT (0x1)
+#define PCU_PCS9_PDD_TIMER4_MASK (ANDES_BIT_MASK(23, 18))
+#define PCU_PCS9_PDD_TIMER4_OFFSET (18)
+#define PCU_PCS9_PDD_TIMER4_DEFAULT (0x20)
+#define PCU_PCS9_PDD_TIMER3_MASK (ANDES_BIT_MASK(17, 12))
+#define PCU_PCS9_PDD_TIMER3_OFFSET (12)
+#define PCU_PCS9_PDD_TIMER3_DEFAULT (0x20)
+#define PCU_PCS9_PDD_TIMER2_MASK (ANDES_BIT_MASK(11, 6))
+#define PCU_PCS9_PDD_TIMER2_OFFSET (6)
+#define PCU_PCS9_PDD_TIMER2_DEFAULT (0x20)
+#define PCU_PCS9_PDD_TIMER1_MASK (ANDES_BIT_MASK(5, 0))
+#define PCU_PCS9_PDD_TIMER1_OFFSET (0)
+#define PCU_PCS9_PDD_TIMER1_DEFAULT (0x20)
+
+#define PCU_PCS9_PDD_DEFAULT ((PCU_PCS9_PDD_CLR_PWOFF_FLAG_DEFAULT << PCU_PCS9_PDD_CLR_PWOFF_FLAG_OFFSET)|\
+ (PCU_PCS9_PDD_SUSP2RAM_DEFAULT << PCU_PCS9_PDD_SUSP2RAM_OFFSET )|\
+ (PCU_PCS9_PDD_PWR_OFF_TIME_DEFAULT << PCU_PCS9_PDD_PWR_OFF_TIME_OFFSET )|\
+ (PCU_PCS9_PDD_TICK_DEFAULT << PCU_PCS9_PDD_TICK_OFFSET )|\
+ (PCU_PCS9_PDD_TIMER4_DEFAULT << PCU_PCS9_PDD_TIMER4_OFFSET )|\
+ (PCU_PCS9_PDD_TIMER3_DEFAULT << PCU_PCS9_PDD_TIMER3_OFFSET )|\
+ (PCU_PCS9_PDD_TIMER2_DEFAULT << PCU_PCS9_PDD_TIMER2_OFFSET )|\
+ (PCU_PCS9_PDD_TIMER1_DEFAULT << PCU_PCS9_PDD_TIMER1_OFFSET ))
+
+// ======================================================
+// PCU definitaion macro
+// ======================================================
+#define PCS_TYPE_PLL 0
+#define PCS_TYPE_DIVIDER 1
+#define PCS_TYPE_CLK_GATING 2
+#define PCS_TYPE_I2C 4
+#define PCS_TYPE_PMBUS 5
+
+#define PCS_WKEN0 (0x1<<0)
+#define PCS_WKEN1 (0x1<<1)
+#define PCS_WKEN2 (0x1<<2)
+#define PCS_WKEN3 (0x1<<3)
+#define PCS_WKEN4 (0x1<<4)
+#define PCS_WKEN5 (0x1<<5)
+#define PCS_WKEN6 (0x1<<6)
+#define PCS_WKEN7 (0x1<<7)
+#define PCS_WKEN8 (0x1<<8)
+#define PCS_WKEN9 (0x1<<9)
+#define PCS_WKEN10 (0x1<<10)
+#define PCS_WKEN11 (0x1<<11)
+#define PCS_WKEN12 (0x1<<12)
+#define PCS_WKEN13 (0x1<<13)
+#define PCS_WKEN14 (0x1<<14)
+#define PCS_WKEN15 (0x1<<15)
+
+#define PCS_WKEN_GPIO0 PCS_WKEN0
+#define PCS_WKEN_GPIO1 PCS_WKEN1
+#define PCS_WKEN_GPIO2 PCS_WKEN2
+#define PCS_WKEN_GPIO3 PCS_WKEN3
+#define PCS_WKEN_GPIO4 PCS_WKEN4
+#define PCS_WKEN_GPIO5 PCS_WKEN5
+#define PCS_WKEN_WOL PCS_WKEN6
+#define PCS_WKEN_RTC PCS_WKEN7
+#define PCS_WKEN_DAY PCS_WKEN8
+#define PCS_WKEN_DBG PCS_WKEN9
+#define PCS_WKEN_PCI PCS_WKEN10
+#define PCS_WKEN_LPC PCS_WKEN11
+#define PCS_WKEN_SRC_CNT 12 // wakeup source number
+#define PCS_WKEN_SRC_MASK ((1<<PCS_WKEN_SRC_CNT)-1)
+
+#define PCS_CMD_NOP 0x0
+#define PCS_CMD_SCALING 0x1
+#define PCS_CMD_PW_DOWN 0x2
+#define PCS_CMD_DRAM_SF 0x4 // DRAM self-refresh
+
+#define PCS_SYNC_CPUA_STBY 0x1
+#define PCS_SYNC_CPUB_STBY 0x2
+
+#if ((!defined(CORE0_IDLE)) && (!defined(CORE1_IDLE)))
+ #define PCS_SYNC_SRC PCS_SYNC_CPUA_STBY
+#elif (!defined(CORE0_IDLE))
+ #define PCS_SYNC_SRC PCS_SYNC_CPUA_STBY
+#else //(!defined(CORE1_IDLE))
+ #define PCS_SYNC_SRC PCS_SYNC_CPUB_STBY
+#endif
+
+#define PCS_PLL_DIVIDE1 0
+#define PCS_PLL_DIVIDE2 1
+#define PCS_PLL_DIVIDE4 2
+#define PCS_PLL_DIVIDE8 3
+
+#define PCS_RATIO_44221H 0 // h(alf): stands for 0.5,
+#define PCS_RATIO_4422HQ 1 // q(uarter) stands for 0.25,
+#define PCS_RATIO_42221H 2 // f(ixed) stands for fixed 400Mhz
+#define PCS_RATIO_4222HQ 3
+#define PCS_RATIO_41121H 4
+#define PCS_RATIO_4112HQ 5
+#define PCS_RATIO_44421H 6
+#define PCS_RATIO_4442HQ 7
+#define PCS_RATIO_442F1H 8
+#define PCS_RATIO_442FHQ 9
+#define PCS_RATIO_422F1H 10
+#define PCS_RATIO_422FHQ 11
+#define PCS_RATIO_411F1H 12
+#define PCS_RATIO_411FHQ 13
+#define PCS_RATIO_111111e 14 // enable pll
+#define PCS_RATIO_111111d 15 // disable pll
+#define PCS_RATIO_MAX PCS_RATIO_111111d
+#define PCS_RATIO_CNT (PCS_RATIO_MAX+1)
+
+#define PCS_GATING_DDR2_HCLK (0x1<<2 )
+#define PCS_GATING_AHB2AHB_HCLK (0x1<<3 )
+#define PCS_GATING_DMAC_HCLK (0x1<<4 )
+#define PCS_GATING_L2CC_HCLK (0x1<<5 )
+#define PCS_GATING_LPC_HCLK (0x1<<6 )
+#define PCS_GATING_I2C_HCLK (0x1<<7 )
+#define PCS_GATING_IDE_HCLK (0x1<<8 )
+#define PCS_GATING_GPU_HCLK (0x1<<9)
+#define PCS_GATING_GMAC_HCLK (0x1<<10)
+#define PCS_GATING_USB_HCLK (0x1<<11)
+#define PCS_GATING_PCI_HCLK (0x1<<12)
+#define PCS_GATING_HCLK_CNT (16)
+#define PCS_GATING_HCLK_VALID (PCS_GATING_DDR2_HCLK |\
+ PCS_GATING_AHB2AHB_HCLK|\
+ PCS_GATING_DMAC_HCLK |\
+ PCS_GATING_L2CC_HCLK |\
+ PCS_GATING_LPC_HCLK |\
+ PCS_GATING_I2C_HCLK |\
+ PCS_GATING_IDE_HCLK |\
+ PCS_GATING_GPU_HCLK |\
+ PCS_GATING_GMAC_HCLK |\
+ PCS_GATING_USB_HCLK |\
+ PCS_GATING_PCI_HCLK )
+
+#define PCS_GATING_NO_PCLK (0x0)
+#define PCS_GATING_SPI_PCLK (0x1<<0 )
+#define PCS_GATING_CFC_PCLK (0x1<<1 )
+#define PCS_GATING_SDC_PCLK (0x1<<2 )
+#define PCS_GATING_WDT_PCLK (0x1<<3 )
+#define PCS_GATING_TMR_PCLK (0x1<<4 )
+#define PCS_GATING_GPIO_PCLK (0x1<<5 )
+#define PCS_GATING_PWM_PCLK (0x1<<6 )
+#define PCS_GATING_I2C_PCLK (0x1<<7 )
+#define PCS_GATING_AC97I2S_PCLK (0x1<<8)
+#define PCS_GATING_UART1_PCLK (0x1<<9)
+#define PCS_GATING_UART2_PCLK (0x1<<10)
+#define PCS_GATING_PCLK_CNT (16)
+
+#define PCS_MAIN_PLL_FREF (33) // reference frequency in MHz
+#define PCS_MAIN_PLL_M_FACTOR (1) // fixed M factor of Main PLL
+#define PCS_MAIN_PLL_50MHZ_H (66)
+#define PCS_MAIN_PLL_125MHZ_L (99)
+#define PCS_MAIN_PLL_125MHZ_H (132)
+#define PCS_MAIN_PLL_250MHZ_L (231)
+#define PCS_MAIN_PLL_250MHZ_H (264)
+#define PCS_MAIN_PLL_500MHZ_L (495)
+#define PCS_MAIN_PLL_500MHZ_H (528)
+#define PCS_MAIN_PLL_830MHZ_L (825)
+//#define PCS_MAIN_PLL_800MHZ_H ()
+//#define PCS_MAIN_PLL_1000MHZ_L ()
+//#define PCS_MAIN_PLL_1000MHZ_H ()
+#define PCS_MAIN_PLL_CNT (4)
+#define PCS_PLL_50to125MHZ (0x0)
+#define PCS_PLL_125to250MHZ (0x1)
+#define PCS_PLL_250to500MHZ (0x2)
+#define PCS_PLL_500to1000MHZ (0x3)
+
+#define PCU_PLL_N_FACTOR(seed, F_ref, M_factor, F_low, F_high) \
+ (((seed)%( 1+ (F_high)*(M_factor)/(F_ref) - (F_low)*(M_factor)/(F_ref))) + ((F_low)*(M_factor)/(F_ref)))
+#define PCS_MAIN_PLL_N_FACTOR(seed, F_low, F_high) \
+ PCU_PLL_N_FACTOR(seed, PCS_MAIN_PLL_FREF, PCS_MAIN_PLL_M_FACTOR, F_low, F_high)
+#define PCS_MAIN_PLL_CLOCK(n_factor) ((n_factor/PCS_MAIN_PLL_M_FACTOR)*PCS_MAIN_PLL_FREF)
+
+#define PCS_POWER_GPU_AND_DAC (0x1<<1)
+#define PCS_POWER_CPUB (0x1<<2)
+#define PCS_POWER_CNT (5)
+
+#define PCS_TICK_OSCH 0x0
+#define PCS_TICK_OSCL 0x1
+
+//
+#define PCS_STS_NORMAL 0x0
+#define PCS_STS_READY 0x1
+#define PCS_STS_SEQUENCE 0x2
+#define PCS_STS_DONE 0x4
+#define PCS_STS_WAKEN 0x6
+
+#define PCS_ERR_NONE 0x0
+#define PCS_ERR_ILLEGAL 0x1
+#define PCS_ERR_SYNC_TIMEOUT 0x2
+#define PCS_ERR_UPDATE_TIMEOUT 0x3
+
+//
+#define PCS_BSM_IDLE 0x0
+#define PCS_BSM_SCALING 0x1
+#define PCS_BSM_DONE 0x3
+#define PCS_BSM_PWDN 0x4
+#define PCS_BSM_ERROR 0x7
+#define PCS_BSM_WAKEN 0x8
+
+#define PCS_BSM_VALID_NO_MAX 9
+
+//
+#define PCS_SCALING_WITH_WAIT_DOWN 0
+#define PCS_SCALING_WITH_WAKE_GRANT 1
+#define PCS_PW_DOWN_WITH_WAIT_DOWN 2
+#define PCS_PW_DOWN_WAKE_GRANT 3
+
+#define PCS_WAKE_WITH_SCALING_CNT (PCS_SCALING_WITH_WAKE_GRANT+1)
+#define PCS_WAKE_WITH_PWDnSCL_CNT (PCS_PW_DOWN_WAKE_GRANT+1)
+
+// standby mode define macro
+#define PCU_STBY_NO_WAKE_GRANT 0
+#define PCU_STBY_WAKE_GRANT 1
+#define PCU_STBY_WAIT_DONE 2
+
+
+// PCU interrupt service routine signal
+#define PCU_ISR_SIG_NONE 0x0
+#define PCU_ISR_SIG_BSM PCU_INTR_BSM_MASK
+#define PCU_ISR_SIG_PCS1 PCU_INTR_PCS1_MASK
+#define PCU_ISR_SIG_PCS2 PCU_INTR_PCS2_MASK
+#define PCU_ISR_SIG_PCS3 PCU_INTR_PCS3_MASK
+#define PCU_ISR_SIG_PCS4 PCU_INTR_PCS4_MASK
+#define PCU_ISR_SIG_PCS5 PCU_INTR_PCS5_MASK
+#define PCU_ISR_SIG_PCS6 PCU_INTR_PCS6_MASK
+#define PCU_ISR_SIG_PCS7 PCU_INTR_PCS7_MASK
+#define PCU_ISR_SIG_PCS8 PCU_INTR_PCS8_MASK
+#define PCU_ISR_SIG_PCS9 PCU_INTR_PCS9_MASK
+
+// ======================================================
+// PCU access macro
+// ======================================================
+#define PCU_SET_FIELD(reg, field, value) SET_FIELD(PCU_REG_##reg, PCU_##reg##_##field##_##MASK, PCU_##reg##_##field##_##OFFSET, value)
+#define PCU_GET_FIELD(reg, field) GET_FIELD(PCU_REG_##reg, PCU_##reg##_##field##_##MASK, PCU_##reg##_##field##_##OFFSET)
+#define PCU_TEST_FIELD(reg, field) TEST_FIELD(PCU_REG_##reg, PCU_##reg##_##field##_##MASK)
+
+#define PCU_SET_REG(reg, value) SET_REG(PCU_REG_##reg, value)
+#define PCU_GET_REG(reg) GET_REG(PCU_REG_##reg)
+#define PCU_TEST_BIT(reg, field, value) VAR_TEST_BIT(value, PCU_##reg##_##field##_##MASK)
+
+#define PCU_CHECK(reg, field, value) CHECK_FIELD (value, PCU_##reg##_##field##_##MASK)
+#define PCU_EXTRACT(reg, field, value) EXTRACT_FIELD(value, PCU_##reg##_##field##_##MASK, PCU_##reg##_##field##_##OFFSET )
+#define PCU_PREPARE(reg, field, value) PREPARE_FIELD(value, PCU_##reg##_##field##_##MASK, PCU_##reg##_##field##_##OFFSET )
+
+#define PCU_DEFAULT(reg, field) ( PCU_##reg##_##field##_##DEFAULT )
+
+#define PCU_TEST_SIG(var, sig) VAR_TEST_BIT(var, PCU_ISR_SIG_##sig)
+#define PCU_SET_SIG(var, sig) VAR_SET_BIT(var, PCU_ISR_SIG_##sig)
+#define PCU_CLR_SIG(var, sig) VAR_CLR_BIT(var, PCU_ISR_SIG_##sig)
+
+// ======================================================
+// PCU access function prototype
+// ======================================================
+#if __STDC__ || defined(__cplusplus)
+#define PROTO_PARAMS(s) s
+#else
+#define PROTO_PARAMS(s) ()
+#endif
+
+#endif //__PCU_H
diff -Nur linux-3.4.113.orig/arch/nds32/platforms/ag102/pm.c linux-3.4.113/arch/nds32/platforms/ag102/pm.c
--- linux-3.4.113.orig/arch/nds32/platforms/ag102/pm.c 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/platforms/ag102/pm.c 2016-12-01 20:59:24.376613676 +0100
@@ -0,0 +1,1614 @@
+/*
+ * AG101 Power Management Routines
+ *
+ * Copyright (c) 2010 Gavin Guo <gavinguo@andestech.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License.
+ *
+ * Abstract:
+ *
+ * This program is for AG102 power management routines.
+ *
+ * Revision History:
+ *
+ * Jul.19.2010 Initial code by Gavin.
+ */
+#include <linux/init.h>
+#include <linux/suspend.h>
+#include <linux/errno.h>
+#include <linux/time.h>
+#include <linux/delay.h>
+/*
+ * the following include file is for testing device node
+ */
+#include <linux/device.h>
+#include <linux/fs.h>
+#include <asm/uaccess.h>
+/*************************/
+#include <asm/hardware.h>
+#include <asm/memory.h>
+#include <asm/system.h>
+#include <asm/mach/time.h>
+#include <asm/cacheflush.h>
+#include <asm/timer.h>
+#include <asm/io.h>
+#include <asm/amic.h>
+
+#include "pcu.h"
+#include "gmac.h"
+
+#ifdef CONFIG_PLAT_AG102
+#include <asm/spec-ag102.h>
+#endif
+
+#define ANDES_PCU_STRING "andes_pcu"
+static int andes_pcu_major;
+static struct class *andes_pcu_class;
+extern void ag102_cpu_sleep(void);
+extern void ag102_cpu_resume(void);
+extern void ag102_cpu_resume2(void);
+extern void __SELF_REFRESH_LOCK_START();
+extern void __SELF_REFRESH_LOCK_END();
+extern void ftpci_postinit(void /**sysdata*/ );
+UINT32 mac_dah, mac_dal;
+
+// ADD by river 2010.12.07 for WOL
+
+UINT32 eth_phy_reg_read(UINT32 phy_addr, UINT32 phy_page, UINT32 phy_reg,
+ UINT32 * phy_data)
+{
+ UINT32 cycthr = GMAC_GET_FIELD(PHYCR, MDC_CYCTHR);
+ UINT32 wdata;
+ UINT32 rdata;
+ //TIMER_P timer;
+
+ printk(">>>>> GMAC : Calling eth_phy_reg_read()...\n");
+
+ wdata = GMAC_PREPARE(PHYCR, MIIRD, 0x1) |
+ GMAC_PREPARE(PHYCR, PHYAD, phy_addr) |
+ GMAC_PREPARE(PHYCR, REGAD, phy_reg) | cycthr;
+
+ printk(">>>>> GMAC : wdata = [0x%08x]\n", wdata);
+
+ GMAC_SET_REG(PHYCR, wdata);
+
+ // wait phy data read
+ //TIMER_INIT(timer, 10000); // trigger timer & wait until finish of data read
+ //while ( (!TIMER_IS_TIMEOUT(timer)) && (GMAC_GET_FIELD(PHYCR, MIIRD))) {
+ // TIMER_TICK(timer);
+ //}
+
+ while (GMAC_GET_FIELD(PHYCR, MIIRD)) {
+ mdelay(50);
+ }
+
+ if (GMAC_GET_FIELD(PHYCR, MIIRD)) {
+ printk("ERR: GPHY read reg[%x] timeout!\n", phy_reg);
+ return 1;
+ } else {
+ rdata = GMAC_GET_FIELD(PHYDATA, MIIRDATA);
+ *phy_data = rdata;
+ printk("GPHY read [%x] \n", rdata);
+ return 0;
+ }
+}
+
+UINT32 eth_phy_reg_write(UINT32 phy_addr, UINT32 phy_page, UINT32 phy_reg,
+ UINT32 phy_data)
+{
+ UINT32 wdata;
+ //TIMER_P timer;
+
+ printk(">>>>> GMAC : Calling eth_phy_reg_write()...\n");
+
+ GMAC_SET_FIELD(PHYDATA, MIIWDATA, phy_data);
+ wdata = GMAC_PREPARE(PHYCR, MIIWR, 0x1) | GMAC_PREPARE(PHYCR, PHYAD, phy_addr) | GMAC_PREPARE(PHYCR, REGAD, phy_reg) | 0x34; //cycthr;
+ GMAC_SET_REG(PHYCR, wdata);
+
+ // wait phy data write
+ //TIMER_INIT(timer, 10000); // trigger timer & wait until finish of data write
+ //while ( (!TIMER_IS_TIMEOUT(timer)) && (GMAC_GET_FIELD(PHYCR, MIIWR))) {
+ // TIMER_TICK(timer);
+ //}
+
+ while (GMAC_GET_FIELD(PHYCR, MIIWR)) {
+ mdelay(50);
+ }
+
+ if (GMAC_GET_FIELD(PHYCR, MIIWR)) {
+ printk("ERR: GPHY write reg[%x] = %x timeout!\n", phy_reg,
+ phy_data);
+ return 1;
+ } else {
+ return 0;
+ }
+}
+
+INT32 eth_phy_detect(UINT32 * phy_addr, UINT32 * phy_id)
+{
+ UINT32 i, find, data1, data2;
+
+ printk(">>>>> GMAC : Calling eth_phy_detect()...\n");
+
+ for (i = 0, find = 0; i <= 0x1f; i++) {
+ eth_phy_reg_read(i, 0, 2, &data1);
+ if ((data1 != 0) && (data1 != 0xffff)) {
+ find = 1;
+ break;
+ }
+ }
+
+ if (find == 0) {
+ printk("Err: no valid phy found!\n");
+ *phy_id = 0;
+ return (-1);
+ }
+
+ eth_phy_reg_read(i, 0, 2, &data1);
+ eth_phy_reg_read(i, 0, 3, &data2);
+ *phy_id = (data1 << 16) | (data2 & 0xffff);
+ *phy_addr = i;
+ printk("Info: phy id = 0x%08x!\n", *phy_id);
+ return 0;
+}
+
+void eth_phy_init(UINT32 phy_addr)
+{
+ UINT32 data, i;
+ //TIMER_P timer;
+ //phy_addr = DVC_PHY_ADDR;
+
+ printk(">>>>> GMAC : Calling eth_phy_init()...\n");
+ // GPHY SW reset
+ eth_phy_reg_read(phy_addr, 0, DVC_PHY_REG_CTL, &data);
+ data |=
+ DVC_PHY_REG_CTL_SW_RST | DVC_PHY_REG_CTL_AN_EN |
+ DVC_PHY_REG_CTL_AN_RST;
+ eth_phy_reg_write(phy_addr, 0, DVC_PHY_REG_CTL, data);
+ for (i = 0; i < 10000; i++) { // must delay enough for phy to get ready
+ //eth_mdelay(2000);
+ mdelay(2);
+ eth_phy_reg_read(phy_addr, 0, DVC_PHY_REG_CTL, &data);
+ if ((data & 0x8000) == 0)
+ break;
+ }
+ if ((data & 0x8000) != 0) {
+ printk("Err: phy sw reset timeout!!!\n");
+ }
+ eth_phy_reg_read(phy_addr, 0, DVC_PHY_REG_CTL, &data);
+ printk("phy control = 0x%x\n", data);
+ eth_phy_reg_read(phy_addr, 0, DVC_PHY_REG_STS, &data);
+ printk("phy status = 0x%x\n", data);
+
+ return;
+}
+
+// initialize MAC setting
+void eth_mac_init(ETH_PHY_STAT * phy_stat)
+{
+ UINT32 i, wdata, rdata;
+ UINT32 duplex, speed, gmac;
+ //UINT32 mac_dah, mac_dal;
+ printk(">>>>> GMAC : Calling eth_mac_init()...\n");
+
+ wdata = GMAC_PREPARE(MACCR, SW_RST, 0x1);
+ GMAC_SET_REG(MACCR, wdata);
+ for (i = 0; i < 1000; i++) { // must delay enough for phy to get ready
+ //eth_mdelay(8000); // delay should be enough
+ mdelay(8);
+ rdata = GMAC_GET_REG(FEAR);
+ if ((rdata >> 31) == 0)
+ break;
+ }
+ if ((rdata >> 31) != 0) {
+ printk("Err: mac sw reset timeout!!!\n");
+ }
+ if (phy_stat->speed == 2) { //giga
+ gmac = 0x1;
+ speed = 0x1;
+ } else if (phy_stat->speed == 1) { //100 Mbps
+ gmac = 0x0;
+ speed = 0x1;
+ } else { //10 Mbps
+ gmac = 0x0;
+ speed = 0x0;
+ }
+ duplex = phy_stat->duplex;
+ GMAC_SET_REG(ISR, 0xffff); // Interrupt Status, write 1 to clear
+ GMAC_SET_REG(IME, 0xffff); // Interrupt Enable, enabling all interrupts
+ GMAC_SET_REG(MAC_MADR, mac_dah);
+ GMAC_SET_REG(MAC_LADR, mac_dal);
+ rdata = GMAC_GET_REG(FEAR);
+ GMAC_SET_FIELD(TPAFCR, TFIFO_SIZE,
+ GMAC_EXTRACT(FEAR, TFIFO_RSIZE, rdata));
+ GMAC_SET_FIELD(TPAFCR, RFIFO_SIZE,
+ GMAC_EXTRACT(FEAR, RFIFO_RSIZE, rdata));
+
+ wdata = GMAC_PREPARE(MACCR, RX_MULTIPKT_EN, 0x1) |
+ GMAC_PREPARE(MACCR, BROADPKT_EN, 0x1) |
+ GMAC_PREPARE(MACCR, RX_ALLADR, 0x1) |
+ GMAC_PREPARE(MACCR, CRC_APD, 0x1) |
+ GMAC_PREPARE(MACCR, FULLDUP, duplex) |
+ GMAC_PREPARE(MACCR, RX_RUNT, 0x1) |
+ GMAC_PREPARE(MACCR, SPEED, speed) |
+ GMAC_PREPARE(MACCR, GMAC_MODE, gmac) |
+ GMAC_PREPARE(MACCR, RXMAC_EN, 0x1) |
+ GMAC_PREPARE(MACCR, TXMAC_EN, 0x1) |
+ GMAC_PREPARE(MACCR, RXDMA_EN, 0x1) |
+ GMAC_PREPARE(MACCR, TXDMA_EN, 0x1);
+ GMAC_SET_REG(MACCR, wdata);
+
+#ifdef AHBC_NO_REMAP
+ GMAC_SET_REG(NPTXR_BADR, FTGMAC100_TXR_BASE | 0x40000000);
+ GMAC_SET_REG(RXR_BADR, FTGMAC100_RXR_BASE | 0x40000000);
+#else
+ GMAC_SET_REG(NPTXR_BADR, FTGMAC100_TXR_BASE);
+ GMAC_SET_REG(RXR_BADR, FTGMAC100_RXR_BASE);
+#endif
+ return;
+}
+
+UINT32 eth_phy_stat(UINT32 phy_addr, ETH_PHY_STAT * phy_stat)
+{
+
+ phy_stat->speed = 0x1;
+ phy_stat->duplex = 0x1;
+
+ return 0;
+}
+
+void gmac_set_wol()
+{
+ UINT32 wdata;
+
+ // Set Rx Wake-up Frame
+ // write 1 clear register before enable power saving mode
+ GMAC_SET_REG(WOLSR, 0xffffffff); // clear wol status
+
+ // set wakeup_sel and power saving mode enable
+ wdata = GMAC_PREPARE(WOLCR, MAGICPKT_EN, 0x1) |
+ GMAC_PREPARE(WOLCR, PWRSAV, 0x1);
+
+ GMAC_SET_REG(WOLCR, wdata);
+
+ return;
+}
+
+// End ADD by river 2010.12.07 for WOL
+
+//////////////////////////////// LPC wake up ///////////////////////////////////////////////////
+#define CPE_LPCIO_BASE LPC_IO_VA_BASE //VA Base
+#define CPE_LPCREG_BASE LPC_REG_VA_BASE //VA Base
+#define CPE_IC_BASE AMIC_VA_BASE
+
+#define ITE_ADDR 0x2e
+#define ITE_DATA 0x2f
+
+#define KBC_CMD 0x64
+#define KBC_STATUS KBC_CMD
+#define KBC_DATA 0x60
+
+#define BIT_OBF 0x01
+#define BIT_IBF 0x02
+
+#define LPC_REG_SCR 0x10
+#define LPC_REG_SIR 0x14
+#define LPC_REG_SIMR 0x18
+
+#define SIRQ_KB 1
+#define SIRQ_MS 12
+
+//#define outlpc(addr, data) outb(data, CPE_LPCIO_BASE + 4 * addr)
+//#define inlpc(addr) inb(CPE_LPCIO_BASE + 4 * addr)
+#define inlpc(addr) REG32(CPE_LPCIO_BASE + 4 * addr)
+
+#define IRQ_LPC 29
+#define LEVEL 0
+#define H_ACTIVE 0
+#define L_ACTIVE 1
+#define IRQ_MASK 0x80
+#define IRQ_MODE 0x20
+#define IRQ_LEVEL 0x24
+
+UINT32 IRQSources = 0; //define the current irq source for debug
+
+static inline void outlpc(unsigned long addr, unsigned long data)
+{
+ REG32(CPE_LPCIO_BASE + 4 * addr) = data;
+}
+
+static void kbc_cmd(UINT8 cmd)
+{
+ int loop_limit = 1000;
+ int i;
+ UINT8 tmpc;
+
+ // wait until the input buffer is empty
+ for (i = 0; i < loop_limit; i++) {
+ tmpc = inlpc(KBC_STATUS);
+ if ((tmpc & BIT_IBF) == 0)
+ break;
+ }
+
+ outlpc(KBC_CMD, cmd);
+}
+
+static void kbc_wdata(UINT8 wdata)
+{
+ int loop_limit = 1000;
+ int i;
+ UINT8 tmpc;
+
+ // wait until the input buffer is empty
+ for (i = 0; i < loop_limit; i++) {
+ tmpc = inlpc(KBC_STATUS);
+ if ((tmpc & BIT_IBF) == 0)
+ break;
+ }
+
+ outlpc(KBC_DATA, wdata);
+}
+
+static UINT8 kbc_rdata(void)
+{
+ int loop_limit = 1000;
+ int i;
+ UINT8 rdata;
+ UINT8 tmpc;
+
+ // wait until the output buffer is not empty
+ for (i = 0; i < loop_limit; i++) {
+ tmpc = inlpc(KBC_STATUS);
+ if (tmpc & BIT_OBF)
+ break;
+ }
+
+ rdata = inlpc(KBC_DATA);
+ return (rdata);
+}
+
+static void delay_loop(int max_no)
+{
+ int i;
+
+ for (i = 0; i < max_no; i++) ;
+}
+
+static UINT8 get_response(void)
+{
+ UINT8 tmpc;
+
+ delay_loop(200000);
+ tmpc = kbc_rdata();
+ return (tmpc);
+}
+
+int it8718f_init(void)
+{
+ static int initialized = 0;
+ UINT8 tmpc;
+ unsigned int chip_id;
+
+ if (initialized == 1)
+ return (0);
+
+ // Enter the configuration mode
+ outlpc(ITE_ADDR, 0x87);
+ outlpc(ITE_ADDR, 0x01);
+ outlpc(ITE_ADDR, 0x55);
+ outlpc(ITE_ADDR, 0x55);
+
+ // Check the chip ID
+ printk("Check IT8718F chip ID => ");
+ outlpc(ITE_ADDR, 0x20);
+ tmpc = inlpc(ITE_DATA);
+ chip_id = (tmpc & 0xff) << 8;
+ outlpc(ITE_ADDR, 0x21);
+ tmpc = inlpc(ITE_DATA);
+ chip_id |= tmpc & 0xff;
+
+ if (chip_id != 0x8718) {
+ printk("FAILED with chip ID = 0x%C%C.\n", (chip_id >> 8) & 0xff,
+ chip_id & 0xff);
+ return (1);
+ } else
+ printk("PASSED\n");
+
+ // KBC Self Test
+ printk("KBC self-test => ");
+ kbc_cmd(0xaa);
+ tmpc = kbc_rdata();
+ if (tmpc != 0x55) {
+ printk("FAILED with code = 0x%C\n", tmpc & 0xff);
+ return (2);
+ } else
+ printk("PASSED\n");
+
+ // KBC Interface Test
+ printk("KBC interface test => ");
+ kbc_cmd(0xab);
+ tmpc = kbc_rdata();
+ switch (tmpc) {
+ case 0:
+ printk("PASSED\n");
+ break;
+
+ case 1:
+ printk("FAILED as the clock is stuck low\n");
+ return (3);
+
+ case 2:
+ printk("FAILED as the clock is stuck high\n");
+ return (3);
+
+ case 3:
+ printk("FAILED as the data is stuck low\n");
+ return (3);
+
+ case 4:
+ printk("FAILED as the data is stuck high\n");
+ return (3);
+
+ default:
+ printk("FAILED with unknown error\n");
+ return (3);
+ break;
+ }
+
+ // Read the KBC mode
+ kbc_cmd(0xca);
+ tmpc = kbc_rdata();
+
+ // Set KBC to the PS/2 mode
+ tmpc |= 0x01;
+ kbc_cmd(0xcb);
+ kbc_wdata(tmpc);
+
+ // Enable keyboard
+ kbc_wdata(0xf4);
+ tmpc = get_response();
+ printk("@@@@@ : Response of enabling keyboard = 0x%x\n", tmpc & 0xff);
+
+ // Enable mouse
+ kbc_cmd(0xd4);
+ kbc_wdata(0xf4);
+ tmpc = get_response();
+ //outmsg("Response of enabling mouse = 0x%C\n", tmpc & 0xff);
+
+ // bit 6: translate
+ // bit 5: mouse enable
+ // bit 4: keyboard enable
+ // bit 3: ignore keyboard lock
+ // bit 2: system flag
+ // bit 1: mouse interrupt enable
+ // bit 0: Keyboard interrupt enable
+ kbc_cmd(0x60);
+ kbc_wdata(0x47);
+
+ // Set repeat rate and delay
+ kbc_wdata(0xf3);
+ kbc_wdata(0x00);
+ tmpc = get_response();
+
+ // Set LDN = 5 (Keyboard)
+ outlpc(ITE_ADDR, 0x07);
+ outlpc(ITE_DATA, 0x05);
+
+ // KBC clock = 8MHz, Key lock enabled, interrupt type can be changed
+ outlpc(ITE_ADDR, 0xf0);
+ outlpc(ITE_DATA, 0x4e);
+
+ // Low-level triggered interrupt
+ outlpc(ITE_ADDR, 0x71);
+ outlpc(ITE_DATA, 0x01);
+
+ // Set LDN = 6 (Mouse)
+ outlpc(ITE_ADDR, 0x07);
+ outlpc(ITE_DATA, 0x06);
+
+ // Enable mouse
+ outlpc(ITE_ADDR, 0x30);
+ outlpc(ITE_DATA, 0x01);
+
+ // Interrupt type can be changed
+ outlpc(ITE_ADDR, 0xf0);
+ outlpc(ITE_DATA, 0x01);
+
+ // Low-level triggered interrupt
+ outlpc(ITE_ADDR, 0x71);
+ outlpc(ITE_DATA, 0x01);
+
+ // Exit the configuration mode
+ outlpc(ITE_ADDR, 0x02);
+ outlpc(ITE_DATA, 0x02);
+
+ initialized = 1;
+ return (0);
+}
+
+//INT for lpc
+/* Turn the interrupt source on. */
+void UnmaskIRQ(UINT32 IRQ)
+{
+ volatile UINT32 *IRQBase;
+
+ IRQBase = (UINT32 *) CPE_IC_BASE;
+
+ IRQBase[(IRQ_MASK / sizeof(UINT32))] |= (1 << IRQ);
+}
+
+void EnableIRQ()
+{
+
+ __asm__ volatile ("setgie.d\n\t"
+ "isb\n\t"
+ "mfsr $r1, $INT_MASK\n\t"
+ "ori $r1, $r1, #0x3f\n\t"
+ "mtsr $r1, $INT_MASK\n\t"
+ "setgie.e\n\t" "isb\n\t");
+
+}
+
+void SetIRQmode(UINT32 IRQ, UINT32 edge)
+{
+ volatile UINT32 *IRQBase;
+
+ IRQBase = (UINT32 *) CPE_IC_BASE;
+
+ if (edge)
+ IRQBase[(IRQ_MODE / sizeof(UINT32))] |= (1 << IRQ);
+ else
+ IRQBase[(IRQ_MODE / sizeof(UINT32))] &= ~(1 << IRQ);
+}
+
+void SetIRQlevel(UINT32 IRQ, UINT32 low)
+{
+ volatile UINT32 *IRQBase;
+
+ IRQBase = (UINT32 *) CPE_IC_BASE;
+
+ if (low)
+ IRQBase[(IRQ_LEVEL / sizeof(UINT32))] |= (1 << IRQ);
+ else
+ IRQBase[(IRQ_LEVEL / sizeof(UINT32))] &= ~(1 << IRQ);
+}
+
+BOOL SetIntTrig(UINT32 intNum, int intMode, int intLevel)
+{
+ if (intNum >= 32) {
+ printk("ERROR: The interrupt number %d is incorrect\n", intNum);
+ return FALSE;
+ } else {
+ SetIRQmode(intNum, intMode);
+ SetIRQlevel(intNum, intLevel);
+ return TRUE;
+ }
+}
+
+BOOL EnableInt(UINT32 intNum)
+{
+
+ if (intNum >= 32) {
+ printk("ERROR: The interrupt number %d is incorrect\n", intNum);
+ return FALSE;
+ } else {
+ IRQSources |= 1 << intNum;
+ UnmaskIRQ(intNum);
+ EnableIRQ();
+ return TRUE;
+ }
+}
+
+//End INT for lpc
+
+void enable_sirq(void)
+{
+ UINT32 data;
+
+ // Unmask SERIRQs of Keyboard and Mouse
+ data = inw(CPE_LPCREG_BASE + LPC_REG_SIMR);
+ data &= ~((1 << SIRQ_KB) | (1 << SIRQ_MS));
+ outw(CPE_LPCREG_BASE + LPC_REG_SIMR, data);
+
+ // Enable SERIRQ
+ data = inw(CPE_LPCREG_BASE + LPC_REG_SCR);
+ data |= 0x1;
+ outw(CPE_LPCREG_BASE + LPC_REG_SCR, data);
+}
+
+void ite_set_pme()
+{
+
+ UINT8 tmpc;
+ unsigned int chip_id;
+ // Enter the configuration mode
+ outlpc(ITE_ADDR, 0x87);
+ outlpc(ITE_ADDR, 0x01);
+ outlpc(ITE_ADDR, 0x55);
+ outlpc(ITE_ADDR, 0x55);
+
+ // Check the chip ID
+ printk("@@@@@ : Check IT8718F chip ID in get_lpc_value => \n");
+ outlpc(ITE_ADDR, 0x20);
+ tmpc = inlpc(ITE_DATA);
+ chip_id = (tmpc & 0xff) << 8;
+ outlpc(ITE_ADDR, 0x21);
+ tmpc = inlpc(ITE_DATA);
+ chip_id |= tmpc & 0xff;
+
+ printk("@@@@@ : chip_id = 0x%08x\n", chip_id);
+ if (chip_id != 0x8718) {
+ printk("FAILED with chip ID = 0x%C%C.\n", (chip_id >> 8) & 0xff,
+ chip_id & 0xff);
+ return (1);
+ } else
+ printk("@@@@@ : PASSED\n");
+
+ // Set LDN = 5
+ outlpc(ITE_ADDR, 0x07);
+ outlpc(ITE_DATA, 0x05);
+
+ //Read index 30
+ outlpc(ITE_ADDR, 0x30);
+ tmpc = inlpc(ITE_DATA);
+ printk("[0x30] = 0x%x\n", tmpc);
+ //Set index 30 bit0 = 0;
+ outlpc(ITE_ADDR, 0x30);
+ outlpc(ITE_DATA, tmpc & 0xFE);
+
+ // Set LDN = 6
+ outlpc(ITE_ADDR, 0x07);
+ outlpc(ITE_DATA, 0x06);
+
+ //Read index 30
+ outlpc(ITE_ADDR, 0x30);
+ tmpc = inlpc(ITE_DATA);
+ printk("[0x30] = 0x%x\n", tmpc);
+ //Set index 30 bit0 = 0;
+ outlpc(ITE_ADDR, 0x30);
+ outlpc(ITE_DATA, tmpc & 0xFE);
+
+ // Set LDN = 4 for PME
+ outlpc(ITE_ADDR, 0x07);
+ outlpc(ITE_DATA, 0x04);
+
+ //Read index F0
+ outlpc(ITE_ADDR, 0xF0);
+ tmpc = inlpc(ITE_DATA);
+ printk("[0xF0] = 0x%x\n", tmpc);
+ //Set index F0 BIT[4:3]=1;
+ outlpc(ITE_ADDR, 0xF0);
+ outlpc(ITE_DATA, tmpc | 0x18);
+
+ //PME output enable
+ //Read index F2
+ outlpc(ITE_ADDR, 0xF2);
+ tmpc = inlpc(ITE_DATA);
+ printk("[0xF2] = 0x%x\n", tmpc);
+ //Set index F2 bit6=0;
+ outlpc(ITE_ADDR, 0xF2);
+ outlpc(ITE_DATA, tmpc & 0xBF);
+
+ // Exit the configuration mode
+ outlpc(ITE_ADDR, 0x02);
+ outlpc(ITE_DATA, 0x02);
+}
+
+void get_keyboard_status()
+{
+
+ printk("Getting keyboard status....\n");
+
+ UINT8 tmpc;
+ unsigned int chip_id;
+
+ // Enter the configuration mode
+ outlpc(ITE_ADDR, 0x87);
+ outlpc(ITE_ADDR, 0x01);
+ outlpc(ITE_ADDR, 0x55);
+ outlpc(ITE_ADDR, 0x55);
+
+ // Check the chip ID
+ //printk("@@@@@ : Check IT8718F chip ID in get_lpc_value => \n");
+ outlpc(ITE_ADDR, 0x20);
+ tmpc = inlpc(ITE_DATA);
+ chip_id = (tmpc & 0xff) << 8;
+ outlpc(ITE_ADDR, 0x21);
+ tmpc = inlpc(ITE_DATA);
+ chip_id |= tmpc & 0xff;
+
+ //printk("@@@@@ : chip_id = 0x%08x\n", chip_id);
+ if (chip_id != 0x8718) {
+ printk("FAILED with chip ID = 0x%C%C.\n", (chip_id >> 8) & 0xff,
+ chip_id & 0xff);
+ return (1);
+ }
+ // Set LDN = 4 for PME
+ outlpc(ITE_ADDR, 0x07);
+ outlpc(ITE_DATA, 0x04);
+
+ ///////// Dump configuration register
+ outlpc(ITE_ADDR, 0xf1);
+ tmpc = inlpc(ITE_DATA);
+ printk("[0xf1] = 0x%x\n", tmpc);
+
+ ///////// Dump configuration register
+ outlpc(ITE_ADDR, 0xf0);
+ tmpc = inlpc(ITE_DATA);
+ printk("[0xf0] = 0x%x\n", tmpc);
+
+}
+
+void get_lpc_value()
+{
+ UINT8 tmpc;
+ unsigned int chip_id;
+
+ // Enter the configuration mode
+ outlpc(ITE_ADDR, 0x87);
+ outlpc(ITE_ADDR, 0x01);
+ outlpc(ITE_ADDR, 0x55);
+ outlpc(ITE_ADDR, 0x55);
+
+ // Check the chip ID
+ printk("@@@@@ : Check IT8718F chip ID in get_lpc_value => \n");
+ outlpc(ITE_ADDR, 0x20);
+ tmpc = inlpc(ITE_DATA);
+ chip_id = (tmpc & 0xff) << 8;
+ outlpc(ITE_ADDR, 0x21);
+ tmpc = inlpc(ITE_DATA);
+ chip_id |= tmpc & 0xff;
+
+ printk("@@@@@ : chip_id = 0x%08x\n", chip_id);
+ if (chip_id != 0x8718) {
+ printk("FAILED with chip ID = 0x%C%C.\n", (chip_id >> 8) & 0xff,
+ chip_id & 0xff);
+ return (1);
+ } else
+ printk("@@@@@ : PASSED\n");
+
+ printk("=================== Get Values ==================\n");
+ //////////// Environment Controller configuration register
+ printk("@@@@@ : Environment Controller configuration register\n");
+ // Set LDN = 4 for PME
+ outlpc(ITE_ADDR, 0x07);
+ outlpc(ITE_DATA, 0x04);
+
+ printk("@@@@@ : LDN = 4\n");
+
+ ///////// Dump configuration register
+ outlpc(ITE_ADDR, 0x30);
+ tmpc = inlpc(ITE_DATA);
+ printk("[0x30] = 0x%x\n", tmpc);
+
+ outlpc(ITE_ADDR, 0x60);
+ tmpc = inlpc(ITE_DATA);
+ printk("[0x60] = 0x%x\n", tmpc);
+
+ outlpc(ITE_ADDR, 0x61);
+ tmpc = inlpc(ITE_DATA);
+ printk("[0x61] = 0x%x\n", tmpc);
+
+ outlpc(ITE_ADDR, 0x62);
+ tmpc = inlpc(ITE_DATA);
+ printk("[0x62] = 0x%x\n", tmpc);
+
+ outlpc(ITE_ADDR, 0x63);
+ tmpc = inlpc(ITE_DATA);
+ printk("[0x63] = 0x%x\n", tmpc);
+
+ outlpc(ITE_ADDR, 0x70);
+ tmpc = inlpc(ITE_DATA);
+ printk("[0x70] = 0x%x\n", tmpc);
+
+ outlpc(ITE_ADDR, 0xf0);
+ tmpc = inlpc(ITE_DATA);
+ printk("[0xf0] = 0x%x\n", tmpc);
+
+ outlpc(ITE_ADDR, 0xf1);
+ tmpc = inlpc(ITE_DATA);
+ printk("[0xf1] = 0x%x\n", tmpc);
+
+ outlpc(ITE_ADDR, 0xf2);
+ tmpc = inlpc(ITE_DATA);
+ printk("[0xf2] = 0x%x\n", tmpc);
+
+ outlpc(ITE_ADDR, 0xf3);
+ tmpc = inlpc(ITE_DATA);
+ printk("[0xf3] = 0x%x\n", tmpc);
+
+ outlpc(ITE_ADDR, 0xf4);
+ tmpc = inlpc(ITE_DATA);
+ printk("[0xf4] = 0x%x\n", tmpc);
+
+ outlpc(ITE_ADDR, 0xf5);
+ tmpc = inlpc(ITE_DATA);
+ printk("[0xf5] = 0x%x\n", tmpc);
+
+ outlpc(ITE_ADDR, 0xf6);
+ tmpc = inlpc(ITE_DATA);
+ printk("[0xf6] = 0x%x\n", tmpc);
+
+ //////////// Keyboard configuration register
+ printk("@@@@@ : Keyboard configuration register\n");
+ // Set LDN = 5
+ outlpc(ITE_ADDR, 0x07);
+ outlpc(ITE_DATA, 0x05);
+
+ printk("@@@@@ : LDN = 5\n");
+
+ outlpc(ITE_ADDR, 0x30);
+ tmpc = inlpc(ITE_DATA);
+ printk("[0x30] = 0x%x\n", tmpc);
+
+ outlpc(ITE_ADDR, 0x60);
+ tmpc = inlpc(ITE_DATA);
+ printk("[0x60] = 0x%x\n", tmpc);
+
+ outlpc(ITE_ADDR, 0x61);
+ tmpc = inlpc(ITE_DATA);
+ printk("[0x61] = 0x%x\n", tmpc);
+
+ outlpc(ITE_ADDR, 0x62);
+ tmpc = inlpc(ITE_DATA);
+ printk("[0x62] = 0x%x\n", tmpc);
+
+ outlpc(ITE_ADDR, 0x63);
+ tmpc = inlpc(ITE_DATA);
+ printk("[0x63] = 0x%x\n", tmpc);
+
+ outlpc(ITE_ADDR, 0x70);
+ tmpc = inlpc(ITE_DATA);
+ printk("[0x70] = 0x%x\n", tmpc);
+
+ outlpc(ITE_ADDR, 0x71);
+ tmpc = inlpc(ITE_DATA);
+ printk("[0x71] = 0x%x\n", tmpc);
+
+ outlpc(ITE_ADDR, 0xf0);
+ tmpc = inlpc(ITE_DATA);
+ printk("[0xf0] = 0x%x\n", tmpc);
+
+ //////////// GPIO configuration register
+ printk("@@@@@ : GPIO configuration register\n");
+ // Set LDN = 7 for GPIO
+ outlpc(ITE_ADDR, 0x07);
+ outlpc(ITE_DATA, 0x07);
+
+ printk("@@@@@ : LDN = 7\n");
+
+ outlpc(ITE_ADDR, 0x60);
+ tmpc = inlpc(ITE_DATA);
+ printk("[0x60] = 0x%x\n", tmpc);
+
+ outlpc(ITE_ADDR, 0x62);
+ tmpc = inlpc(ITE_DATA);
+ printk("[0x62] = 0x%x\n", tmpc);
+
+ outlpc(ITE_ADDR, 0x63);
+ tmpc = inlpc(ITE_DATA);
+ printk("[0x63] = 0x%x\n", tmpc);
+
+ outlpc(ITE_ADDR, 0x64);
+ tmpc = inlpc(ITE_DATA);
+ printk("[0x64] = 0x%x\n", tmpc);
+
+ outlpc(ITE_ADDR, 0x65);
+ tmpc = inlpc(ITE_DATA);
+ printk("[0x65] = 0x%x\n", tmpc);
+
+ outlpc(ITE_ADDR, 0x70);
+ tmpc = inlpc(ITE_DATA);
+ printk("[0x70] = 0x%x\n", tmpc);
+
+ outlpc(ITE_ADDR, 0x71);
+ tmpc = inlpc(ITE_DATA);
+ printk("[0x71] = 0x%x\n", tmpc);
+
+ outlpc(ITE_ADDR, 0x72);
+ tmpc = inlpc(ITE_DATA);
+ printk("[0x72] = 0x%x\n", tmpc);
+
+ outlpc(ITE_ADDR, 0x73);
+ tmpc = inlpc(ITE_DATA);
+ printk("[0x73] = 0x%x\n", tmpc);
+
+ outlpc(ITE_ADDR, 0x74);
+ tmpc = inlpc(ITE_DATA);
+ printk("[0x74] = 0x%x\n", tmpc);
+
+ outlpc(ITE_ADDR, 0xB0);
+ tmpc = inlpc(ITE_DATA);
+ printk("[0xB0] = 0x%x\n", tmpc);
+
+ outlpc(ITE_ADDR, 0xB1);
+ tmpc = inlpc(ITE_DATA);
+ printk("[0xB1] = 0x%x\n", tmpc);
+
+ outlpc(ITE_ADDR, 0xB2);
+ tmpc = inlpc(ITE_DATA);
+ printk("[0xB2] = 0x%x\n", tmpc);
+
+ outlpc(ITE_ADDR, 0xB3);
+ tmpc = inlpc(ITE_DATA);
+ printk("[0xB3] = 0x%x\n", tmpc);
+
+ outlpc(ITE_ADDR, 0xB4);
+ tmpc = inlpc(ITE_DATA);
+ printk("[0xB4] = 0x%x\n", tmpc);
+
+ outlpc(ITE_ADDR, 0xB5);
+ tmpc = inlpc(ITE_DATA);
+ printk("[0xB5] = 0x%x\n", tmpc);
+
+ outlpc(ITE_ADDR, 0xB8);
+ tmpc = inlpc(ITE_DATA);
+ printk("[0xB8] = 0x%x\n", tmpc);
+
+ outlpc(ITE_ADDR, 0xBA);
+ tmpc = inlpc(ITE_DATA);
+ printk("[0xBA] = 0x%x\n", tmpc);
+
+ outlpc(ITE_ADDR, 0xBB);
+ tmpc = inlpc(ITE_DATA);
+ printk("[0xBB] = 0x%x\n", tmpc);
+
+ outlpc(ITE_ADDR, 0xBC);
+ tmpc = inlpc(ITE_DATA);
+ printk("[0xBC] = 0x%x\n", tmpc);
+
+ outlpc(ITE_ADDR, 0xBD);
+ tmpc = inlpc(ITE_DATA);
+ printk("[0xBD] = 0x%x\n", tmpc);
+
+ outlpc(ITE_ADDR, 0xC0);
+ tmpc = inlpc(ITE_DATA);
+ printk("[0xC0] = 0x%x\n", tmpc);
+
+ outlpc(ITE_ADDR, 0xC1);
+ tmpc = inlpc(ITE_DATA);
+ printk("[0xC1] = 0x%x\n", tmpc);
+
+ outlpc(ITE_ADDR, 0xC2);
+ tmpc = inlpc(ITE_DATA);
+ printk("[0xC2] = 0x%x\n", tmpc);
+
+ outlpc(ITE_ADDR, 0xC3);
+ tmpc = inlpc(ITE_DATA);
+ printk("[0xC3] = 0x%x\n", tmpc);
+
+ outlpc(ITE_ADDR, 0xC4);
+ tmpc = inlpc(ITE_DATA);
+ printk("[0xC4] = 0x%x\n", tmpc);
+
+ outlpc(ITE_ADDR, 0xC5);
+ tmpc = inlpc(ITE_DATA);
+ printk("[0xC5] = 0x%x\n", tmpc);
+
+ outlpc(ITE_ADDR, 0xC8);
+ tmpc = inlpc(ITE_DATA);
+ printk("[0xC8] = 0x%x\n", tmpc);
+
+ outlpc(ITE_ADDR, 0xC9);
+ tmpc = inlpc(ITE_DATA);
+ printk("[0xC9] = 0x%x\n", tmpc);
+
+ outlpc(ITE_ADDR, 0xCA);
+ tmpc = inlpc(ITE_DATA);
+ printk("[0xCA] = 0x%x\n", tmpc);
+
+ outlpc(ITE_ADDR, 0xCB);
+ tmpc = inlpc(ITE_DATA);
+ printk("[0xCB] = 0x%x\n", tmpc);
+
+ outlpc(ITE_ADDR, 0xCC);
+ tmpc = inlpc(ITE_DATA);
+ printk("[0xCC] = 0x%x\n", tmpc);
+
+ outlpc(ITE_ADDR, 0xCD);
+ tmpc = inlpc(ITE_DATA);
+ printk("[0xCD] = 0x%x\n", tmpc);
+
+ outlpc(ITE_ADDR, 0xE0);
+ tmpc = inlpc(ITE_DATA);
+ printk("[0xE0] = 0x%x\n", tmpc);
+
+ outlpc(ITE_ADDR, 0xE1);
+ tmpc = inlpc(ITE_DATA);
+ printk("[0xE1] = 0x%x\n", tmpc);
+
+ outlpc(ITE_ADDR, 0xE2);
+ tmpc = inlpc(ITE_DATA);
+ printk("[0xE2] = 0x%x\n", tmpc);
+
+ outlpc(ITE_ADDR, 0xE3);
+ tmpc = inlpc(ITE_DATA);
+ printk("[0xE3] = 0x%x\n", tmpc);
+
+ outlpc(ITE_ADDR, 0xE4);
+ tmpc = inlpc(ITE_DATA);
+ printk("[0xE4] = 0x%x\n", tmpc);
+
+ outlpc(ITE_ADDR, 0xE5);
+ tmpc = inlpc(ITE_DATA);
+ printk("[0xE5] = 0x%x\n", tmpc);
+
+ outlpc(ITE_ADDR, 0xE6);
+ tmpc = inlpc(ITE_DATA);
+ printk("[0xE6] = 0x%x\n", tmpc);
+
+ outlpc(ITE_ADDR, 0xF0);
+ tmpc = inlpc(ITE_DATA);
+ printk("[0xF0] = 0x%x\n", tmpc);
+
+ outlpc(ITE_ADDR, 0xF1);
+ tmpc = inlpc(ITE_DATA);
+ printk("[0xF1] = 0x%x\n", tmpc);
+
+ outlpc(ITE_ADDR, 0xF2);
+ tmpc = inlpc(ITE_DATA);
+ printk("[0xF2] = 0x%x\n", tmpc);
+
+ outlpc(ITE_ADDR, 0xF3);
+ tmpc = inlpc(ITE_DATA);
+ printk("[0xF3] = 0x%x\n", tmpc);
+
+ outlpc(ITE_ADDR, 0xF4);
+ tmpc = inlpc(ITE_DATA);
+ printk("[0xF4] = 0x%x\n", tmpc);
+
+ outlpc(ITE_ADDR, 0xF5);
+ tmpc = inlpc(ITE_DATA);
+ printk("[0xF5] = 0x%x\n", tmpc);
+
+ outlpc(ITE_ADDR, 0xF6);
+ tmpc = inlpc(ITE_DATA);
+ printk("[0xF6] = 0x%x\n", tmpc);
+
+ outlpc(ITE_ADDR, 0xF7);
+ tmpc = inlpc(ITE_DATA);
+ printk("[0xF7] = 0x%x\n", tmpc);
+
+ outlpc(ITE_ADDR, 0xF8);
+ tmpc = inlpc(ITE_DATA);
+ printk("[0xF8] = 0x%x\n", tmpc);
+
+ outlpc(ITE_ADDR, 0xF9);
+ tmpc = inlpc(ITE_DATA);
+ printk("[0xF9] = 0x%x\n", tmpc);
+
+ outlpc(ITE_ADDR, 0xFA);
+ tmpc = inlpc(ITE_DATA);
+ printk("[0xFA] = 0x%x\n", tmpc);
+
+ outlpc(ITE_ADDR, 0xFB);
+ tmpc = inlpc(ITE_DATA);
+ printk("[0xFB] = 0x%x\n", tmpc);
+
+ outlpc(ITE_ADDR, 0xFC);
+ tmpc = inlpc(ITE_DATA);
+ printk("[0xFC] = 0x%x\n", tmpc);
+
+ outlpc(ITE_ADDR, 0xFD);
+ tmpc = inlpc(ITE_DATA);
+ printk("[0xFD] = 0x%x\n", tmpc);
+
+ outlpc(ITE_ADDR, 0xFE);
+ tmpc = inlpc(ITE_DATA);
+ printk("[0xFE] = 0x%x\n", tmpc);
+
+ outlpc(ITE_ADDR, 0xFF);
+ tmpc = inlpc(ITE_DATA);
+ printk("[0xFF] = 0x%x\n", tmpc);
+
+ printk("=================== End Get Values ==================\n");
+
+}
+
+/////////////////////////////// End LPC wake up ///////////////////////////////////////////////
+
+/*
+ * AG102 PMU sleep mode handler.
+ */
+void andes_suspend_to_ram()
+{
+ int i, k, l, checksum, checksuma;
+ unsigned int addr, reg;
+ static int irq_saves[3];
+ unsigned int tmp;
+ pgd_t *pgdv;
+ pud_t *pudv;
+ pmd_t *pmdv;
+ pte_t *ptev;
+ unsigned int resume_addr /*, resume_temp */ ;
+ //unsigned int *resume_tempaddr;
+ __asm__ volatile ("mfsr %0, $ir14\n\t":"=&r" (tmp));
+ //printk("\nag102_cpu_resume:0x%x\n", ag102_cpu_resume);
+ //printk( KERN_WARNING "\nag102_cpu_resume2:0x%x\n", ag102_cpu_resume2);
+ pgdv =
+ (pgd_t *) __va((GET_L1_PPTB() & L1_PPTB_mskBASE)) +
+ pgd_index((unsigned int)ag102_cpu_resume);
+ pudv = pud_offset(pgdv, (unsigned int)ag102_cpu_resume);
+ pmdv = pmd_offset(pudv, (unsigned int)ag102_cpu_resume);
+ ptev = pte_offset_map(pmdv, (unsigned int)ag102_cpu_resume);
+ //printk("ag102_cpu_resume pte:0x%x\n", ptev);
+ resume_addr =
+ ((*ptev) & TLB_DATA_mskPPN) | ((unsigned int)ag102_cpu_resume &
+ 0x00000fff);
+ printk("resume_addr using Page Table :0x%08x\n", resume_addr);
+
+ //ADD by river 2010.09.23
+ printk("@@@@@ resume_addr(VA):0x%08x\n", ag102_cpu_resume);
+ printk("@@@@@ resume_addr2(VA):0x%08x\n", ag102_cpu_resume2);
+ printk("@@@@@ resume_addr(PA) using virt_to_phys :0x%08x\n",
+ virt_to_phys(ag102_cpu_resume));
+ printk("@@@@@ resume_addr2(PA):0x%08x\n",
+ virt_to_phys(ag102_cpu_resume2));
+ printk("@@@@@ AHB Controller for ROM :0x%08x\n",
+ REG32(AHB_ATFAHBC020S_0_VA_BASE + 0x10));
+ printk("@@@@@ AHB Controller for RAM :0x%08x\n",
+ REG32(AHB_ATFAHBC020S_0_VA_BASE + 0x18));
+ //End ADD by river 2010.09.23
+
+ /* trigger mode regs */
+ irq_saves[0] = REG32(AMIC_VA_BASE + 0x20);
+ /* trigger level regs */
+ irq_saves[1] = REG32(AMIC_VA_BASE + 0x24);
+ /* interrupt enable regs */
+ irq_saves[2] = REG32(AMIC_VA_BASE + 0x80);
+ /* save SDRAM settings */
+
+ /* set resume return address */
+ //REG32(PCU_VA_BASE + 0x400) = (resume_addr);
+ REG32(PCU_VA_BASE + 0x400) = (resume_addr) | 0x80000000;
+ REG32(PCU_VA_BASE + 0x404) = (u32) ag102_cpu_resume2;
+ REG32(PCU_VA_BASE + 0x410) = GET_L1_PPTB();
+ //ADD by river 2010.12.02 for reserve kernel remap
+ REG32(PCU_VA_BASE + 0x418) = REG32(AHB_ATFAHBC020S_0_VA_BASE + 0x10);
+ REG32(PCU_VA_BASE + 0x41C) = REG32(AHB_ATFAHBC020S_0_VA_BASE + 0x18);
+ //End ADD by river 2010.12.02 for reserve kernel remap
+ printk("L1_PPTB (PA) =0x%08x\n", GET_L1_PPTB());
+ printk("L1_PPTB (VA) in virtual address =0x%08x\n",
+ phys_to_virt(GET_L1_PPTB()));
+
+ //ADD by river 2010.12.07
+ UINT32 phy_id, phy_addr;
+ ETH_PHY_STAT phy_stat;
+
+ if (eth_phy_detect(&phy_addr, &phy_id) != 0) {
+ printk("ERR: fail to detect known PHY!!!\n");
+ return;
+ }
+ //TEST by river 2010.12.10
+ eth_phy_init(phy_addr);
+ eth_phy_stat(phy_addr, &phy_stat);
+ eth_mac_init(&phy_stat);
+ //End TEST by river 2010.12.10
+ gmac_set_wol();
+ //End ADD by river 2010.12.07
+
+ /////////// ADD by river 2010.12.20 for LPC wakeup /////////////////////////////
+ if (it8718f_init() != 0)
+ return;
+
+ //INTC setup
+ SetIntTrig(IRQ_LPC, LEVEL, H_ACTIVE);
+ EnableInt(IRQ_LPC); // including INT_MASK and GIE in Core
+
+ enable_sirq();
+
+ //__asm__ volatile ("1:\n\t");
+ //__asm__ volatile ("b 1b\n\t");
+
+ printk("Calling ite_set_pme() YAYAYA....\n");
+ ite_set_pme();
+
+ printk("Get Value..... YAYAYA....1\n");
+ get_lpc_value();
+
+ /////////// End ADD by river 2010.12.20 for LPC wakeup /////////////////////////////
+
+ //set GPIO[2] as suspend2dram power control pin
+ PCU_SET_FIELD(MFPS1, SUSPEND_GPIO, 0x1);
+ PCU_SET_FIELD(PCS9_PDD, SUSP2RAM, 0x1);
+ //ADD by river 2010.12.07
+ PCU_SET_REG(PCS9_CFG, PCU_PREPARE(PCS9_CFG, WKEN, PCS_WKEN_WOL | PCS_WKEN_LPC | PCS_WKEN_RTC)); // use only gpio0 and wol
+ //PCU_SET_REG(PCS9_CFG, PCU_PREPARE(PCS9_CFG, WKEN, PCS_WKEN_LPC)); // use lpc
+
+ //End ADD by river 2010.12.07
+
+ /* set pwoer status */
+ //int par = PCS_POWER_GPU_AND_DAC|PCS_POWER_CPUB;
+ int reg_tmp = PCU_PREPARE(PCS9_PARA, IE, 0x1) |
+ PCU_PREPARE(PCS9_PARA, CMD,
+ PCS_CMD_PW_DOWN /*PCS_CMD_SCALING|PCS_CMD_DRAM_SF */ ) |
+ PCU_PREPARE(PCS9_PARA, SYNC, PCS_SYNC_SRC) | PCU_PREPARE(PCS9_PARA, NXTPAR, 0 /*par */ ); // change power status
+ PCU_SET_REG(PCS9_PARA, reg_tmp);
+
+ //PCU_SET_FIELD(MFPS1, SUSPEND_GPIO, 0x1);
+ /* setup wakeup sources */
+ /*
+ k = PCU_PREPARE(WAKEUP_SEN, GPIO0_POL, 0x1) |
+ PCU_PREPARE(WAKEUP_SEN, GPIO1_POL, 0x1) |
+ PCU_PREPARE(WAKEUP_SEN, GPIO2_POL, 0x1) |
+ PCU_PREPARE(WAKEUP_SEN, GPIO3_POL, 0x1) |
+ PCU_PREPARE(WAKEUP_SEN, GPIO4_POL, 0x1) |
+ PCU_PREPARE(WAKEUP_SEN, GPIO5_POL, 0x1) |
+ PCU_PREPARE(WAKEUP_SEN, WOL_POL, 0x1) |
+ PCU_PREPARE(WAKEUP_SEN, LPC_POL, 0x1);
+ l = ~k; //set polarity
+ //l = 0x1c0;
+ PCU_SET_REG(WAKEUP_SEN, l);
+ PCU_SET_REG(PCS9_CFG, PCU_PREPARE(PCS9_CFG, WKEN, k));
+ */
+ /* Set PDD register and set suspend_to_ram */
+ //PCU_SET_FIELD(PCS9_PDD, SUSP2RAM, 0x1);
+
+ cpu_dcache_wbinval_all();
+ cpu_icache_inval_all();
+ SET_CACHE_CTL(GET_CACHE_CTL() & ~CACHE_CTL_mskDC_EN);
+
+ /* lock self-refresh code to L1 cache */
+
+ addr = (unsigned int)__SELF_REFRESH_LOCK_START;
+ reg = (((unsigned int)__SELF_REFRESH_LOCK_END - (unsigned int)__SELF_REFRESH_LOCK_START) >> 5) + 1; //
+
+ for (i = 0; i < reg; i++) {
+ __asm__ volatile ("li $p0, 0x0\n\t"
+ "add $p0, $p0, %0\n\t"
+ "cctl $p0, L1I_VA_FILLCK\n\t"
+ "isb\n\t"::"r" (addr));
+
+ addr += 32;
+ }
+
+ unsigned char *ptr;
+ //ADD by river 2010.11.19
+ printk("The resume address's content is :\n");
+ ptr = (unsigned char *)ag102_cpu_resume;
+ for (i = 0; i < 20; i++) {
+ printk("0x%02x - ", *ptr++);
+ }
+
+ printk("Get Value..... YAYAYA....2\n");
+ get_lpc_value();
+
+ //End ADD by river 2010.11.19
+ ag102_cpu_sleep();
+ printk("return success-1..........\n");
+ /* wakeup and ckeck */
+ /*
+ reg_tmp = PCU_GET_REG(PCS9_ST2);// check Status-2
+ if (PCU_EXTRACT(PCS9_ST2, CURPAR, reg_tmp) != par)
+ printk("Parameter setup is not the same!\n");
+
+ reg_tmp = PCU_GET_REG(PCS9_ST1); // check Status-1
+ if (PCU_EXTRACT(PCS9_ST1, STS, reg_tmp) != PCS_STS_DONE)
+ printk("The work is not done?!\n");
+ if (PCU_EXTRACT(PCS9_ST1, ERR, reg_tmp) != PCS_ERR_NONE)
+ printk("Some error happened!!\n");
+ PCU_SET_REG(PCS9_ST1, 0x0); //clear status
+
+ */
+ ftpci_postinit();
+ SET_CACHE_CTL(GET_CACHE_CTL() | CACHE_CTL_mskDC_EN);
+ /* trigger mode regs */
+ REG32(AMIC_VA_BASE + 0x20) = irq_saves[0];
+ /* trigger level regs */
+ REG32(AMIC_VA_BASE + 0x24) = irq_saves[1];
+ /* interrupt enable regs */
+ REG32(AMIC_VA_BASE + 0x80) = irq_saves[2];
+ __asm__ volatile ("mtsr %0, $ir14\n\t"::"r" (tmp));
+
+ printk("return success-2..........\n");
+ dump_stack();
+
+}
+
+static int ag102_pm_valid(suspend_state_t state)
+{
+ switch (state) {
+ case PM_SUSPEND_ON:
+ case PM_SUSPEND_STANDBY:
+ case PM_SUSPEND_MEM:
+ return 1;
+
+ default:
+ return 0;
+ }
+}
+
+static int ag102_pm_begin(suspend_state_t state)
+{
+ /* TBD if we need it */
+ return 0;
+}
+
+static void andes_suspend_cpu(void)
+{
+ unsigned int irq_save;
+ /* setup GPIO interrupt enable regs to enable GPIO0 */
+ REG32(GPIO_VA_BASE + 0x20) = 1;
+ /* save interrupt enable regs */
+ irq_save = REG32(AMIC_VA_BASE + 0x80);
+ /* accept all interrupts to wake up except timer interrupt */
+ REG32(AMIC_VA_BASE + 0x80) &= ~(1 << 19);
+ /* enable UART0 interrupt */
+ REG32(AMIC_VA_BASE + 0x80) |= 1 << 13;
+
+ /*
+ * for more IRQ info, please refer to
+ * arch/nds32/include/asm/spec.h&spec-ag102.h
+ */
+
+ __asm__ volatile ("standby no_wake_grant\n\t");
+ /* clear GPIO interrupt */
+ REG32(GPIO_VA_BASE + 0x30) = 1;
+ /* disable GPIO interrupt */
+ REG32(GPIO_VA_BASE + 0x20) = 0;
+ /* restore GPIO enable regs */
+ REG32(AMIC_VA_BASE + 0x80) = irq_save;
+}
+
+static int ag102_pm_enter(suspend_state_t state)
+{
+ switch (state) {
+ case PM_SUSPEND_STANDBY:
+ andes_suspend_cpu();
+ return 0;
+ case PM_SUSPEND_MEM:
+ printk("@@@@@@@@@@ : ag102_pm_enter()... from gavin.......\n");
+ andes_suspend_to_ram();
+ return 0;
+ default:
+ return -EINVAL;
+ }
+}
+
+/*
+ * Called after processes are frozen, but before we shutdown devices.
+ */
+static int ag102_pm_prepare(void)
+{
+ /* TBD if we need it */
+ return 0;
+}
+
+/*
+ * Called after devices are wakeuped, but before processes are thawed.
+ */
+static void ag102_pm_finish(void)
+{
+ /* TBD if we need it */
+}
+
+static void ag102_pm_end(void)
+{
+ /* TBD if we need it */
+#if 0
+ class_destroy(andes_pcu_class);
+ unregister_chrdev(andes_pcu_major, ANDES_PCU_STRING);
+#endif
+ printk("pm_exit\n");
+}
+
+static int andes_pcu_ioctl(struct inode *inode, struct file *file,
+ unsigned int cmd, unsigned long arg)
+{
+ return 0;
+}
+
+static int andes_pcu_open(struct inode *inode, struct file *file)
+{
+ return 0;
+}
+
+static ssize_t andes_pcu_write(struct file *filp, const char *buff,
+ size_t count, loff_t * ppos)
+{
+ char data;
+ get_user(data, buff);
+ switch (data) {
+ case 's':
+ printk("Just suspend cpu\n");
+ andes_suspend_cpu();
+ break;
+ case 'm':
+ printk("Suspend to ram\n");
+ andes_suspend_to_ram();
+ break;
+ }
+ return 0;
+}
+
+static int andes_pcu_release(struct inode *inode, struct file *file)
+{
+ return 0;
+}
+
+static struct file_operations andes_pcu_fops = {
+ .owner = THIS_MODULE,
+ .ioctl = andes_pcu_ioctl,
+ .open = andes_pcu_open,
+ .write = andes_pcu_write,
+ .release = andes_pcu_release,
+};
+
+static struct platform_suspend_ops ag102_pm_ops = {
+ .valid = ag102_pm_valid,
+ .begin = ag102_pm_begin,
+ .prepare = ag102_pm_prepare,
+ .enter = ag102_pm_enter,
+ .finish = ag102_pm_finish,
+ .end = ag102_pm_end,
+};
+
+//PCU power-off workaround {
+#undef IRQ_LEVEL
+#include <linux/interrupt.h>
+#include <linux/irq.h>
+
+//#define PM_DEBUG
+#ifdef PM_DEBUG
+#define PRINTK printk
+#else
+#define PRINTK(...)
+#endif
+
+static volatile int pcuirq = 0;
+
+static inline void poweroff_pcu(void)
+{
+ PRINTK(KERN_INFO "[kernel] poweroff_pcu()");
+ REG32(PCU_VA_BASE + 0x1a4) = (2 << 28) | (1 << 24) | (6 << 0); //power-down, sync CPUA, domain GPU+CPUB
+ __asm__ volatile ("standby wait_done\n");
+ REG32(PCU_VA_BASE + 0x1a8) = 0x0; //PCS9 status normal, no error
+}
+
+static inline void clear_pcu_status(void)
+{
+ PRINTK(KERN_INFO "[kernel] clear_pcu_status()");
+ REG32(PCU_VA_BASE + 0x1b0) |= (1 << 31); //clear poweroff flag
+ asm("msync store\nisb");
+}
+
+static irqreturn_t gpio0_isr(int irq, void *dev_id)
+{
+ PRINTK(KERN_INFO "[kernel] gpio0_isr(irq=%d)\n", irq);
+
+ // is GPIO0 IRQ
+ if (REG32(GPIO_VA_BASE + 0x28) & (1 << 0)) {
+ PRINTK(KERN_INFO "GPIO#0 ASSERT!\n");
+
+ pcuirq = 0;
+
+ //disable GPIO0 IRQ
+ REG32(GPIO_VA_BASE + 0x2c) |= (1 << 0); //GPIO0 IRQ mask, level mode AMIC.GPIO#0 also cleared
+
+// REG32(AMIC_VA_BASE + 0x84) = (1<<13); //AMIC clear GPIO interrupt
+
+ return IRQ_HANDLED;
+ }
+
+ return IRQ_NONE;
+}
+
+#define GPIO_SEC (1<<11)
+static irqreturn_t pcu_isr(int irq, void *dev_id)
+{
+ UINT32 status = REG32(PCU_VA_BASE + 0x94);
+ PRINTK(KERN_INFO "[kernel] pcu_isr(irq=%d) status=0x%08x\n", irq,
+ status);
+ if (0 == (GPIO_SEC & status))
+ return IRQ_NONE;
+
+ PRINTK(KERN_INFO "[kernel] GPIO_SEC\n");
+ clear_pcu_status(); //clear PCS9 IRQ (level mode => AMIC.PCU also cleared)
+ pcuirq++;
+ if (1 == pcuirq) {
+ //enable GPIO0 IRQ
+ REG32(GPIO_VA_BASE + 0x30) = (1 << 0); //GPIO0 IRQ cleared
+// REG32(AMIC_VA_BASE + 0x84) = (1 << 13); //AMIC clear GPIO interrupt
+// enable_irq(GPIO_FTGPIO010_IRQ);
+ REG32(AMIC_VA_BASE + 0x80) |= (1 << 13); //AMIC enable GPIO IRQ
+ REG32(GPIO_VA_BASE + 0x2c) &= ~(1 << 0); //GPIO0 IRQ unmask
+ } else if (5 == pcuirq) {
+ poweroff_pcu();
+ }
+// REG32(AMIC_VA_BASE + 0x84) = (1 << 8); //PCU IRQ clear
+
+ return IRQ_HANDLED;
+}
+
+//PCU power-off workaround }
+
+static int __init ag102_pm_init(void)
+{
+ int ret = 0;
+ struct device *temp_class;
+ printk("PM driver init\n");
+ suspend_set_ops(&ag102_pm_ops);
+
+ andes_pcu_major = register_chrdev(0, ANDES_PCU_STRING, &andes_pcu_fops);
+
+ printk("@@@@@ : andes_pcu_major = 0x%08x\n", andes_pcu_major);
+ if (andes_pcu_major < 0) {
+ printk("Unable to get a major for andes pcu driver!\n");
+ return andes_pcu_major;
+ }
+
+ andes_pcu_class = class_create(THIS_MODULE, ANDES_PCU_STRING);
+
+ if (IS_ERR(andes_pcu_class)) {
+ printk(KERN_ERR "Error creating andes pcu class.\n");
+ ret = PTR_ERR(andes_pcu_class);
+ goto err_out1;
+ }
+
+ temp_class = device_create(andes_pcu_class, NULL,
+ MKDEV(andes_pcu_major, 0),
+ NULL, ANDES_PCU_STRING);
+
+ if (IS_ERR(temp_class)) {
+ printk(KERN_ERR "Error creating andes pcu class device.\n");
+ ret = PTR_ERR(temp_class);
+ goto err_out2;
+ }
+
+ mac_dah = GMAC_GET_REG(MAC_MADR);
+ mac_dal = GMAC_GET_REG(MAC_LADR);
+
+ //poweroff workaround
+ {
+ if (request_irq
+ (PCU_IRQ, pcu_isr, IRQF_SHARED, "PCU_POWEROFF", pcu_isr)) {
+ printk("Failed to request PCU interrupt.\n");
+ }
+
+ if (request_irq
+ (GPIO_FTGPIO010_IRQ, gpio0_isr, IRQF_SHARED,
+ "GPIO0_FOR_PCU", gpio0_isr)) {
+ printk("Failed to request GPIO0 interrupt.\n");
+ }
+
+ REG32(PCU_VA_BASE + 0x1b0) |= (3 << 28); //poweroff in 5s
+
+ //AMIC setup
+ // PCU IRQ default edge trigger, rising edge
+ // GPIO_FTGPIO010_IRQ default edge trigger, rising edge
+// REG32(AMIC_VA_BASE + 0x20) &= ~(1 << 8); //PCU IRQ level trigger
+// REG32(AMIC_VA_BASE + 0x24) &= ~(1 << 8); //PCU IRQ active-high
+// REG32(AMIC_VA_BASE + 0x20) &= ~(1 << 13); //GPIO IRQ level trigger
+
+ //GPIO #0 setup
+ REG32(GPIO_VA_BASE + 0x08) &= ~(1 << 0); //GPIO0 input
+ REG32(GPIO_VA_BASE + 0x18) &= ~(1 << 0); //GPIO0 not pulled (external pull-high)
+ REG32(GPIO_VA_BASE + 0x2c) |= (1 << 0); //GPIO0 IRQ masked
+ REG32(GPIO_VA_BASE + 0x34) |= (1 << 0); //GPIO0 IRQ level trigger
+// REG32(GPIO_VA_BASE + 0x38) &= ~(1<<0); //GPIO0 IRQ single edge
+ REG32(GPIO_VA_BASE + 0x3c) &= ~(1 << 0); //GPIO0 IRQ high-active
+ REG32(GPIO_VA_BASE + 0x40) |= (1 << 0); //GPIO0 enable bounce
+ REG32(GPIO_VA_BASE + 0x40) = 0xffff; //GPIO bounce time = x/PCLK
+// REG32(GPIO_VA_BASE + 0x30) = (1<<0); //GPIO0 IRQ cleared
+ REG32(GPIO_VA_BASE + 0x20) |= (1 << 0); //GPIO0 IRQ enable
+
+// enable_irq(PCU_IRQ);
+ REG32(AMIC_VA_BASE + 0x80) |= (1 << 8); //IRQ enabled
+ }
+
+ printk("pm_init\n");
+ return 0;
+err_out2:
+ class_destroy(andes_pcu_class);
+err_out1:
+ unregister_chrdev(andes_pcu_major, ANDES_PCU_STRING);
+ return 1;
+}
+
+//static void resume_to_ccode(void)
+//{
+// printk("Resume to C code successfully....\n");
+//}
+
+late_initcall(ag102_pm_init);
diff -Nur linux-3.4.113.orig/arch/nds32/platforms/ag102/sleep.S linux-3.4.113/arch/nds32/platforms/ag102/sleep.S
--- linux-3.4.113.orig/arch/nds32/platforms/ag102/sleep.S 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/platforms/ag102/sleep.S 2016-12-01 20:59:24.376613676 +0100
@@ -0,0 +1,465 @@
+#include <asm/spec-ag102.h>
+.text
+
+.globl ag102_cpu_sleep
+.globl ag102_cpu_resume
+.globl ag102_cpu_resume2
+.globl __SELF_REFRESH_LOCK_START
+.globl __SELF_REFRESH_LOCK_END
+
+#! 0x94200000; keep r0, r1, r2
+ .macro putch ch
+ li $r0, #0x94200000
+ move $r2, \ch
+88:
+ lwi $r1, [$r0+#0x14]
+ srli $r1, $r1, #5
+ andi $r1, $r1, #0x1
+ beqz $r1, 88b
+ swi $r2, [$r0]
+ .endm
+#! 0x94200000; keep r3, r4
+ .macro hex2asc val
+ addi \val, \val, -10
+ bltz \val, 1f
+ addi \val, \val, 0x41
+ j 2f
+1:
+ addi \val, \val, 0x3a
+2:
+ .endm
+
+ .macro print_hex mhex
+ move $r3, \mhex
+
+ srli $r4, $r3, #28
+ andi $r4, $r4, 0xf
+ hex2asc $r4
+ putch $r4
+ srli $r4, $r3, #24
+ andi $r4, $r4, 0xf
+ hex2asc $r4
+ putch $r4
+ srli $r4, $r3, #20
+ andi $r4, $r4, 0xf
+ hex2asc $r4
+ putch $r4
+ srli $r4, $r3, #16
+ andi $r4, $r4, 0xf
+ hex2asc $r4
+ putch $r4
+ srli $r4, $r3, #12
+ andi $r4, $r4, 0xf
+ hex2asc $r4
+ putch $r4
+ srli $r4, $r3, #8
+ andi $r4, $r4, 0xf
+ hex2asc $r4
+ putch $r4
+ srli $r4, $r3, #4
+ andi $r4, $r4, 0xf
+ hex2asc $r4
+ putch $r4
+ move $r4, $r3
+ andi $r4, $r4, 0xf
+ hex2asc $r4
+ putch $r4
+ .endm
+
+ag102_cpu_resume2:
+/*1:
+b 1b*/
+ //MOD by river 2010.10.13
+ popm $r0, $r19
+ mtusr $r0, $d0.lo ! $d0 lo byte
+ mtusr $r1, $d0.hi ! $d0 hi byte
+ mtusr $r2, $d1.lo ! $d1 lo byte
+ mtusr $r3, $d1.hi ! $d1 hi byte
+ mtsr $r4, $mr0
+ mtsr $r5, $mr1
+ mtsr $r6, $mr4
+ mtsr $r7, $mr6
+ mtsr $r8, $mr7
+ mtsr $r9, $mr8
+ mtsr $r10, $ir0
+ mtsr $r11, $ir1
+ mtsr $r12, $ir2
+ mtsr $r13, $ir3
+ mtsr $r14, $ir9
+ mtsr $r15, $ir10
+ mtsr $r16, $ir12
+ mtsr $r17, $ir13
+ mtsr $r18, $ir14
+ mtsr $r19, $ir15
+ //End MOD by river 2010.10.13
+ popm $r0, $r30
+ ret
+
+ag102_cpu_sleep:
+
+ pushm $r0, $r30
+ //MOD by river 2010.10.13
+ mfusr $r0, $d0.lo ! $d0 lo byte
+ mfusr $r1, $d0.hi ! $d0 hi byte
+ mfusr $r2, $d1.lo ! $d1 lo byte
+ mfusr $r3, $d1.hi ! $d1 hi byte
+ mfsr $r4, $mr0
+ mfsr $r5, $mr1
+ mfsr $r6, $mr4
+ mfsr $r7, $mr6
+ mfsr $r8, $mr7
+ mfsr $r9, $mr8
+ mfsr $r10, $ir0
+ mfsr $r11, $ir1
+ mfsr $r12, $ir2
+ mfsr $r13, $ir3
+ mfsr $r14, $ir9
+ mfsr $r15, $ir10
+ mfsr $r16, $ir12
+ mfsr $r17, $ir13
+ mfsr $r18, $ir14
+ mfsr $r19, $ir15
+ pushm $r0, $r19
+ //End MOD by river 2010.10.13
+
+ /* store $sp to 0x408 scratch pad */
+ sethi $r0, hi20(PCU_VA_BASE + 0x408)
+ ori $r2, $r0, lo12(PCU_VA_BASE + 0x408)
+ swi $r31, [$r2]
+
+ /* set signaure "SUSP" to 0x40c */
+ li $r0, (PCU_VA_BASE + 0x40c)
+ li $r1, 0x53555350 ! set signature "SUSP" to scratch pad register offset 0x40c
+ swi $r1, [$r0]
+
+ /*
+ * store 8 bytes from 16mb to pcu scratch pad resgister
+ * due to data training process will destroy it
+ */
+ li $r0, 0x10000
+ li $r2, (PCU_VA_BASE + 0x414)
+ lwi $r1, [$r0]
+ swi $r1, [$r2]
+ lwi $r1, [$r0 + 0x4]
+ swi $r1, [$r2 + 0x4]
+
+ /* ADD by river 2010.09.23 */
+ /* Save PSW in PCU_VA_BASE + 0x420 */
+ li $r0, (PCU_VA_BASE + 0x420)
+ mfsr $r1, $ir0
+ swi $r1, [$r0]
+ /* Save $mr0 in PCU_VA_BASE + 0x424 */
+ li $r0, (PCU_VA_BASE + 0x424)
+ mfsr $r1, $mr0
+ swi $r1, [$r0]
+ /* Save $mr1 in PCU_VA_BASE + 0x428 */
+ li $r0, (PCU_VA_BASE + 0x428)
+ mfsr $r1, $mr1
+ swi $r1, [$r0]
+ /* Save $mr2 in PCU_VA_BASE + 0x42c */
+ li $r0, (PCU_VA_BASE + 0x42c)
+ mfsr $r1, $mr2
+ swi $r1, [$r0]
+ /* Save $mr3 in PCU_VA_BASE + 0x430 */
+ li $r0, (PCU_VA_BASE + 0x430)
+ mfsr $r1, $mr3
+ swi $r1, [$r0]
+ /* Save $mr4 in PCU_VA_BASE + 0x434 */
+ li $r0, (PCU_VA_BASE + 0x434)
+ mfsr $r1, $mr4
+ swi $r1, [$r0]
+ /* Save $mr5 in PCU_VA_BASE + 0x438 */
+ //li $r0, (PCU_VA_BASE + 0x438)
+ //mfsr $r1, $mr5
+ //swi $r1, [$r0]
+ /* Save $mr6 in PCU_VA_BASE + 0x43c */
+ li $r0, (PCU_VA_BASE + 0x43c)
+ mfsr $r1, $mr6
+ swi $r1, [$r0]
+ /* Save $mr7 in PCU_VA_BASE + 0x440 */
+ li $r0, (PCU_VA_BASE + 0x440)
+ mfsr $r1, $mr7
+ swi $r1, [$r0]
+ /* Save $mr8 in PCU_VA_BASE + 0x444 */
+ li $r0, (PCU_VA_BASE + 0x444)
+ mfsr $r1, $mr8
+ swi $r1, [$r0]
+
+ /* Save $ir3 in PCU_VA_BASE + 0x450 */
+ li $r0, (PCU_VA_BASE + 0x450)
+ mfsr $r1, $ir3
+ swi $r1, [$r0]
+
+ /* Save $ir14 in PCU_VA_BASE + 0x454 */
+ li $r0, (PCU_VA_BASE + 0x454)
+ mfsr $r1, $ir14
+ swi $r1, [$r0]
+
+ /* Save $ir15 in PCU_VA_BASE + 0x458 */
+ li $r0, (PCU_VA_BASE + 0x458)
+ mfsr $r1, $ir15
+ swi $r1, [$r0]
+
+ tlbop FlushAll
+ isb
+ /* End ADD by river 2010.09.23 */
+
+ //Trace by river 2010.12.01
+ /*1:
+ b 1b*/
+ //End Trace by river 2010.12.01
+.p2align 5
+__SELF_REFRESH_LOCK_START:
+ /*sethi $r0, hi20(0x900005cc)
+ ori $r0, $r0, lo12(0x900005cc)
+ sethi $r1, hi20(DDR2C_VA_BASE)
+ swi $r0, [$r1+0x4]
+
+ msync
+ isb
+
+ standby wake_grant
+ .p2align 5*/
+ sethi $r0, hi20(DDR2C_VA_BASE)
+ lwi $r1, [$r0+0x4]
+ li $r2, 0x07ffefff
+ and $r1, $r2, $r1
+ li $r2, 0x90001000
+ or $r1, $r2, $r1
+ swi $r1, [$r0+0x4]
+
+ msync
+ isb
+
+ standby wake_grant
+ .p2align
+
+__SELF_REFRESH_LOCK_END:
+
+ag102_cpu_resume:
+ /* TRACE by river 2010.12.02 */
+ /*1:
+ b 1b*/
+ /* End TRACE by river 2010.12.02 */
+ mfsr $r2, $mr0
+ ori $r2, $r2, #0x6
+#ifdef CONFIG_ANDES_PAGE_SIZE_8KB
+ ori $r2, $r2, #0x1
+#endif
+ mtsr $r2, $mr0
+
+ /* ADD by river 2010.09.23 */
+ li $r3, 'C
+ putch $r3
+ li $r3, '\r
+ putch $r3
+ li $r3, '\n
+ putch $r3
+ li $r3, 'P
+ putch $r3
+ li $r3, '\r
+ putch $r3
+ li $r3, '\n
+ putch $r3
+ li $r3, 'U
+ putch $r3
+ li $r3, '\r
+ putch $r3
+ li $r3, '\n
+ putch $r3
+ li $r3, 'R
+ putch $r3
+ li $r3, '\r
+ putch $r3
+ li $r3, '\n
+ putch $r3
+ li $r3, 'E
+ putch $r3
+ li $r3, '\r
+ putch $r3
+ li $r3, '\n
+ putch $r3
+ li $r3, 'S
+ putch $r3
+ li $r3, '\r
+ putch $r3
+ li $r3, '\n
+ putch $r3
+ li $r3, 'U
+ putch $r3
+ li $r3, '\r
+ putch $r3
+ li $r3, '\n
+ putch $r3
+ li $r3, 'M
+ putch $r3
+ li $r3, '\r
+ putch $r3
+ li $r3, '\n
+ putch $r3
+ li $r3, 'E
+ putch $r3
+ li $r3, '\r
+ putch $r3
+ li $r3, '\n
+ putch $r3
+ /* ADD by river 2010.09.23 */
+
+ /*tlbop FlushAll*/ ! invalidate TLB\n"
+
+ /* ADD by river 2010.09.23 */
+ /* restore PSW */
+ //sethi $r2, hi20(PCU_PA_BASE + 0x420)
+ //ori $r2, $r2, lo12(PCU_PA_BASE + 0x420)
+ //lwi $r3, [$r2]
+ //mtsr $r3, $ir0
+ //move $p1, $r3
+ /* restore $mr0 */
+ sethi $r2, hi20(PCU_PA_BASE + 0x424)
+ ori $r2, $r2, lo12(PCU_PA_BASE + 0x424)
+ lwi $r3, [$r2]
+ mtsr $r3, $mr0
+ /* restore $mr1 */
+ sethi $r2, hi20(PCU_PA_BASE + 0x428)
+ ori $r2, $r2, lo12(PCU_PA_BASE + 0x428)
+ lwi $r3, [$r2]
+ mtsr $r3, $mr1
+
+ /* restore $mr2 */
+ //sethi $r2, hi20(PCU_PA_BASE + 0x42c)
+ //ori $r2, $r2, lo12(PCU_PA_BASE + 0x42c)
+ //lwi $r3, [$r2]
+ //mtsr $r3, $mr2
+ /* restore $mr3 */
+ //sethi $r2, hi20(PCU_PA_BASE + 0x430)
+ //ori $r2, $r2, lo12(PCU_PA_BASE + 0x430)
+ //lwi $r3, [$r2]
+ //mtsr $r3, $mr3
+ /* restore $mr4 */
+ sethi $r2, hi20(PCU_PA_BASE + 0x434)
+ ori $r2, $r2, lo12(PCU_PA_BASE + 0x434)
+ lwi $r3, [$r2]
+ mtsr $r3, $mr4
+ /* restore $mr5 */
+ //sethi $r2, hi20(PCU_PA_BASE + 0x438)
+ //ori $r2, $r2, lo12(PCU_PA_BASE + 0x438)
+ //lwi $r3, [$r2]
+ //mtsr $r3, $mr5
+ /* restore $mr6 */
+ sethi $r2, hi20(PCU_PA_BASE + 0x43c)
+ ori $r2, $r2, lo12(PCU_PA_BASE + 0x43c)
+ lwi $r3, [$r2]
+ mtsr $r3, $mr6
+ /* restore $mr7 */
+ sethi $r2, hi20(PCU_PA_BASE + 0x440)
+ ori $r2, $r2, lo12(PCU_PA_BASE + 0x440)
+ lwi $r3, [$r2]
+ mtsr $r3, $mr7
+ /* restore $mr8 */
+ sethi $r2, hi20(PCU_PA_BASE + 0x444)
+ ori $r2, $r2, lo12(PCU_PA_BASE + 0x444)
+ lwi $r3, [$r2]
+ /* ADD by river 2010.12.02 for ICache Enable */
+ ori $r3, $r3, #0x1
+ /* End ADD by river 2010.12.02 for ICache Enable */
+ mtsr $r3, $mr8
+
+ /* restore $ir3 */
+ sethi $r2, hi20(PCU_PA_BASE + 0x450)
+ ori $r2, $r2, lo12(PCU_PA_BASE + 0x450)
+ lwi $r3, [$r2]
+ mtsr $r3, $ir3
+
+ move $p1, $r3
+ li $r3, '\r
+ putch $r3
+ li $r3, '\n
+ putch $r3
+ print_hex $p1
+ li $r3, '\r
+ putch $r3
+ li $r3, '\n
+ putch $r3
+
+
+ /* restore $ir14 */
+ sethi $r2, hi20(PCU_PA_BASE + 0x454)
+ ori $r2, $r2, lo12(PCU_PA_BASE + 0x454)
+ lwi $r3, [$r2]
+ mtsr $r3, $ir14
+
+ /* restore $ir15 */
+ sethi $r2, hi20(PCU_PA_BASE + 0x458)
+ ori $r2, $r2, lo12(PCU_PA_BASE + 0x458)
+ lwi $r3, [$r2]
+ mtsr $r3, $ir15
+
+ li $r3, '\r
+ putch $r3
+ li $r3, '\n
+ putch $r3
+ move $p1, $r3
+ print_hex $p1
+
+ /* End ADD by river 2010.09.23 */
+
+ /* in this buggy version(ram locate at 1G) TC01 we don't need to do remap.
+ * ebios set memory locate at 1G & size = 1G, for more detail info, please
+ * refer to ebios boot.S.
+ *
+ * sethi $r2, hi20(0x90c00000 + 0x88)
+ * ori $r2, $r2, lo12(0x90c00000 + 0x88)
+ * movi $r3, #0x1
+ * swi $r3, [$r2]
+ **/
+
+ /* restore 8 bytes from pcu scratch pad resgister to 16mb */
+ li $r0, 0x10000
+ li $r2, (PCU_PA_BASE + 0x414)
+ lwi $r1, [$r2]
+ swi $r1, [$r0]
+ lwi $r1, [$r2 + 0x4]
+ swi $r1, [$r0 + 0x4]
+
+ .p2align 5
+ resume_lock_start:
+ /* ADD by river 2010.12.02 for ag102_cpu_resume2 for jral.ton $r4, $r4 */
+ sethi $r2, hi20(PCU_PA_BASE + 0x404)
+ ori $r2, $r2, lo12(PCU_PA_BASE + 0x404)
+ lwi $r4, [$r2]
+ /* End ADD by river 2010.12.02 for ag102_cpu_resume2 */
+
+ /* ADD by river 2010.12.02 for restore kernel ROM map */
+ sethi $r0, hi20(0x40080000)
+ ori $r0, $r0, lo12(0x40080000)
+ sethi $r1, hi20(AHB_ATFAHBC020S_0_PA_BASE + 0x10)
+ ori $r1, $r1, lo12(AHB_ATFAHBC020S_0_PA_BASE + 0x10)
+ swi $r0, [$r1]
+
+ /* ADD by river 2010.12.02 for restore kernel RAM map */
+ sethi $r0, hi20(0x000A0000)
+ ori $r0, $r0, lo12(0x000A0000)
+ sethi $r1, hi20(AHB_ATFAHBC020S_0_PA_BASE + 0x18)
+ ori $r1, $r1, lo12(AHB_ATFAHBC020S_0_PA_BASE + 0x18)
+ swi $r0, [$r1]
+
+ /******************* Gavin version ***************************/
+ //MOD by river 2010.10.13
+ /*sethi $r2, hi20(PCU_PA_BASE + 0x404)
+ ori $r2, $r2, lo12(PCU_PA_BASE + 0x404)
+ lwi $r4, [$r2]
+ mtsr $r4, $IPC
+ li $r1, 0xcb
+ mtsr $r1, $IPSW
+ iret*/
+ //End MOD by river 2010.10.13
+ //End Gavin version////////////////////////////////////////////////////////////
+
+ /* End ADD by river 2010.09.23 */
+ //MOD by river 2010.10.13
+ //////// jral.ton version ////////////////////////////////////////////////////
+
+ jral.ton $r4, $r4
+ .p2align
+ resume_lock_end:
+ //End MOD by river 2010.10.13
diff -Nur linux-3.4.113.orig/arch/nds32/platforms/amic.c linux-3.4.113/arch/nds32/platforms/amic.c
--- linux-3.4.113.orig/arch/nds32/platforms/amic.c 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/platforms/amic.c 2016-12-01 20:59:24.376613676 +0100
@@ -0,0 +1,203 @@
+#include <linux/irq.h>
+#include <linux/interrupt.h>
+#include <linux/ioport.h>
+#include <linux/delay.h>
+
+#include <asm/io.h>
+#include <asm/amic.h>
+
+#define DEBUG(enabled, tagged, ...) \
+ do { \
+ if (enabled) { \
+ if (tagged) \
+ printk("[ %30s() ] ", __func__); \
+ printk(__VA_ARGS__); \
+ } \
+ } while (0)
+
+static DEFINE_SPINLOCK(amic_irq_lock);
+
+static void amic_ack_irq(unsigned int irq)
+{
+ unsigned int data;
+
+ spin_lock(&amic_irq_lock);
+ writel(1 << irq, AMIC_BASE + INTSTA);
+ data = readl(AMIC_BASE + INTSTA);
+ spin_unlock(&amic_irq_lock);
+}
+
+static void amic_mask_irq(unsigned int irq)
+{
+ unsigned int data;
+
+ spin_lock(&amic_irq_lock);
+ data = readl(AMIC_BASE + INTEN);
+ data &= ~(1 << irq);
+ writel(data, AMIC_BASE + INTEN);
+ data = readl(AMIC_BASE + INTEN);
+ spin_unlock(&amic_irq_lock);
+}
+
+static int amic_set_type(unsigned int irq, unsigned int flow_type)
+{
+ unsigned int data;
+
+ spin_lock(&amic_irq_lock);
+ if (flow_type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING)) {
+ data = readl(AMIC_BASE + INTTRG);
+ data |= 1 << irq;
+ writel(data, AMIC_BASE + INTTRG);
+ }
+
+ if (flow_type & (IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW)) {
+ data = readl(AMIC_BASE + INTTRG);
+ data &= ~(1 << irq);
+ writel(data, AMIC_BASE + INTTRG);
+ }
+
+ if (flow_type & (IRQ_TYPE_LEVEL_LOW | IRQ_TYPE_EDGE_FALLING)) {
+ data = readl(AMIC_BASE + INTLVL);
+ data |= 1 << irq;
+ writel(data, AMIC_BASE + INTLVL);
+ }
+
+ if (flow_type & (IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_EDGE_RISING)) {
+ data = readl(AMIC_BASE + INTLVL);
+ data &= ~(1 << irq);
+ writel(data, AMIC_BASE + INTLVL);
+ }
+ spin_unlock(&amic_irq_lock);
+ return 0;
+}
+
+static void amic_unmask_irq(unsigned int irq)
+{
+ unsigned int data;
+
+ spin_lock(&amic_irq_lock);
+ data = readl(AMIC_BASE + INTEN);
+ data |= 1 << irq;
+ writel(data, AMIC_BASE + INTEN);
+ data = readl(AMIC_BASE + INTEN);
+ spin_unlock(&amic_irq_lock);
+}
+
+static int amic_set_affinity(unsigned int irq, const struct cpumask *dest)
+{
+ int cnt = 0;
+ int cpu;
+ volatile unsigned int data;
+ volatile unsigned int dc, amic_irq;
+
+ if (num_online_cpus() > 2)
+ return 0;
+
+ spin_lock(&amic_irq_lock);
+ /* remap irq number for real controller */
+ /* this may be needed in future */
+ /* amic_irq = irq_remap(irq); */
+ amic_irq = irq;
+
+ /* change owner */
+ data = readl(AMIC_BASE + CPUID0 + ((amic_irq >> 4) << 2));
+ for_each_online_cpu(cpu) {
+ if (cpumask_test_cpu(cpu, dest)) {
+ data &= ~(0x3 << ((amic_irq & ~0x10) * 2));
+ data |= cpu << ((amic_irq & ~0x10) * 2);
+ cnt++;
+ }
+ }
+ writel(data, AMIC_BASE + CPUID0 + ((amic_irq >> 4) << 2));
+
+ dc = readl(AMIC_BASE + CPUDC);
+ if (cnt == 2) /* set bit */
+ writel((dc | (1 << amic_irq)), (AMIC_BASE + CPUDC));
+ else /* clear bit */
+ writel((dc & ~(1 << amic_irq)), (AMIC_BASE + CPUDC));
+
+ spin_unlock(&amic_irq_lock);
+
+ DEBUG(0, 1, "en=%08x,status=%08x\n", readl(AMIC_BASE + INTEN),
+ readl(AMIC_BASE + INTSTA));
+
+ return 0;
+}
+
+static struct irq_chip amic_chip = {
+ .name = "AMIC",
+ .ack = amic_ack_irq,
+ .mask = amic_mask_irq,
+ .unmask = amic_unmask_irq,
+ .set_affinity = amic_set_affinity,
+ .set_type = amic_set_type,
+};
+
+void __init amic_init(void)
+{
+ int i, edge;
+ unsigned int temp = smp_processor_id();
+ temp |= temp << 2;
+ temp |= temp << 4;
+ temp |= temp << 8;
+ temp |= temp << 16;
+
+ writel(0x0, AMIC_BASE + INTEN);
+ writel(0x0, AMIC_BASE + CPUDC);
+ writel(temp, AMIC_BASE + CPUID0);
+ writel(temp, AMIC_BASE + CPUID1);
+ writel(0xffff, AMIC_BASE + IPISTA);
+ writel(0xffffffff, AMIC_BASE + INTSTA);
+ writel(0x11111111, AMIC_BASE + PRITY0);
+ writel(0x11111111, AMIC_BASE + PRITY1);
+ writel(0x11111111, AMIC_BASE + PRITY2);
+ writel(0x11111111, AMIC_BASE + PRITY3);
+ writel(DEFAULT_MODE, AMIC_BASE + INTTRG);
+ writel(~DEFAULT_LEVEL, AMIC_BASE + INTLVL);
+ printk("AMIC config %x %x\n", temp, readl(AMIC_BASE + CONFIG));
+
+ for (i = IRQ_BASE, edge = 1; i < IRQ_BASE + IRQ_TOTAL; i++, edge <<= 1) {
+ set_irq_chip(i, &amic_chip);
+ if (DEFAULT_MODE & edge)
+ set_irq_handler(i, handle_edge_irq);
+ else
+ set_irq_handler(i, handle_level_irq);
+ }
+
+}
+
+unsigned int get_IntSrc(void)
+{
+ unsigned int irqsta, irq = 31;
+
+ spin_lock(&amic_irq_lock);
+ irqsta = readl(AMIC_BASE + IPISTA);
+ if (irqsta != 0)
+ irqsta = 0;
+ else
+ irqsta = readl(AMIC_BASE + INTSTA);
+ spin_unlock(&amic_irq_lock);
+
+ if (irqsta == 0)
+ return 32;
+ if (irqsta & 0x0000ffff) {
+ irq -= 16;
+ irqsta <<= 16;
+ }
+ if (irqsta & 0x00ff0000) {
+ irq -= 8;
+ irqsta <<= 8;
+ }
+ if (irqsta & 0x0f000000) {
+ irq -= 4;
+ irqsta <<= 4;
+ }
+ if (irqsta & 0x30000000) {
+ irq -= 2;
+ irqsta <<= 2;
+ }
+ if (irqsta & 0x40000000) {
+ irq -= 1;
+ }
+ return irq;
+}
diff -Nur linux-3.4.113.orig/arch/nds32/platforms/dmad.c linux-3.4.113/arch/nds32/platforms/dmad.c
--- linux-3.4.113.orig/arch/nds32/platforms/dmad.c 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/platforms/dmad.c 2016-12-01 20:59:24.380613830 +0100
@@ -0,0 +1,3601 @@
+/*****************************************************************************
+ *
+ * Copyright Andes Technology Corporation 2007-2008
+ * All Rights Reserved.
+ *
+ * Revision History:
+ *
+ * Aug.21.2007 Created.
+ * Feb.23.2009 Porting to Linux 2.6.
+*****************************************************************************/
+
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/mm.h>
+#include <linux/slab.h>
+#include <linux/spinlock.h>
+#include <linux/completion.h>
+#include <linux/errno.h>
+#include <linux/interrupt.h>
+#include <linux/ioport.h>
+#include <asm/sizes.h>
+#include <asm/types.h>
+#include <asm/io.h>
+#include <asm/dmad.h>
+#include <linux/irq.h>
+
+#if (defined(CONFIG_PLATFORM_AHBDMA) || defined(CONFIG_PLATFORM_APBDMA))
+
+#ifdef CONFIG_PLATFORM_AHBDMA
+#define DMAD_AHB_MAX_CHANNELS DMAC_MAX_CHANNELS
+#else
+#define DMAD_AHB_MAX_CHANNELS 0
+#endif /* CONFIG_PLATFORM_AHBDMA */
+
+#ifdef CONFIG_PLATFORM_APBDMA
+#define DMAD_APB_MAX_CHANNELS APBBR_DMA_MAX_CHANNELS
+#else
+#define DMAD_APB_MAX_CHANNELS 0
+#endif /* CONFIG_PLATFORM_APBDMA */
+
+#define DMAD_DRB_POOL_SIZE 32 /* 128 */
+
+/* reg/io supplementals */
+static inline void setbl(addr_t bit, addr_t reg)
+{
+ outl(inl(reg) | (addr_t) ((addr_t) 1 << bit), reg);
+}
+
+static inline void clrbl(addr_t bit, addr_t reg)
+{
+ outl(inl(reg) & (~((addr_t) ((addr_t) 1 << bit))), reg);
+}
+
+static inline addr_t getbl(addr_t bit, addr_t reg)
+{
+ return inl(reg) & (addr_t) ((addr_t) 1 << bit);
+}
+
+/******************************************************************************/
+
+enum DMAD_DRQ_FLAGS {
+ DMAD_DRQ_STATE_READY = 0x00000001, /* channel allocation status */
+ DMAD_DRQ_STATE_ABORT = 0x00000002, /* abort drb alloc block-wait */
+ DMAD_DRQ_DIR_A1_TO_A0 = 0x00000004, /* Transfer direction */
+};
+
+#define DMAD_DRQ_DIR_MASK DMAD_DRQ_DIR_A1_TO_A0
+
+/* DMA request queue, one instance per channel */
+typedef struct dmad_drq {
+ u32 state; /* enum DMAD_DRQ_STATE */
+
+ addr_t channel_base; /* register base address */
+ addr_t enable_port; /* enable register */
+ addr_t src_port; /* source address register */
+ addr_t dst_port; /* dest address register */
+ addr_t cyc_port; /* size(cycle) register */
+
+ u32 flags; /* enum DMAD_CHREQ_FLAGS */
+
+ spinlock_t drb_pool_lock;
+ dmad_drb *drb_pool; /* drb pool */
+
+ u32 fre_head; /* free list head */
+ u32 fre_tail; /* free list tail */
+
+ u32 rdy_head; /* ready list head */
+ u32 rdy_tail; /* ready list tail */
+
+ u32 sbt_head; /* submitted list head */
+ u32 sbt_tail; /* submitted list tail */
+
+ u32 data_width; /* dma transfer data width */
+
+ struct completion drb_alloc_sync;
+
+ /* client supplied callback function, executed in interrupt context
+ * client private data to be passed to data argument of completion_cb().
+ */
+ void (*completion_cb) (int channel, u16 status, void *data);
+ void *completion_data;
+
+ /* ring-mode fields are valid for DMAD_FLAGS_RING_MODE */
+ dma_addr_t ring_base; /* ring buffer base address */
+ dma_addr_t ring_size; /* size (of data width) */
+ addr_t ring_port; /* for setup/fetch hw_ptr */
+ dmad_drb *ring_drb;
+
+ addr_t dev_addr; /* device data port */
+
+ int periods; /* interrupts periods */
+ dma_addr_t period_size; /* of dma data with */
+ dma_addr_t period_bytes; /* Period size, in bytes */
+
+ /* ring_size - period_size * periods */
+ dma_addr_t remnant_size;
+
+ dma_addr_t sw_ptr; /* sw pointer */
+ int sw_p_idx; /* current ring_ptr */
+ dma_addr_t sw_p_off; /* offset to period base */
+
+} dmad_drq;
+
+/* To shrink code size and improve performance, common channel registers
+ * are preload in drq struct at channel allocation time. One of the key
+ * dependency is the enable bit of both DMAC and APBDMA channel command
+ * registers. Please make sure hw design them at bit 0 of the command register
+ * in future evolvement.
+ */
+#if (DMAC_CSR_CH_EN_BIT != APBBR_DMA_CHEN_BIT)
+#error "DMAC_CSR_CH_EN_BIT != APBBR_DMA_CHEN_BIT"
+#endif
+
+#define DMAD_PORT_ENABLE_BIT APBBR_DMA_CHEN_BIT
+
+static inline void dmad_enable_channel(dmad_drq * drq)
+{
+ setbl(DMAD_PORT_ENABLE_BIT, drq->enable_port);
+}
+
+static inline void dmad_disable_channel(dmad_drq * drq)
+{
+ clrbl(DMAD_PORT_ENABLE_BIT, drq->enable_port);
+}
+
+static inline addr_t dmad_is_channel_enabled(dmad_drq * drq)
+{
+ return (addr_t) getbl(DMAD_PORT_ENABLE_BIT, drq->enable_port);
+}
+
+/* AHB DMAC channel re-route table structure */
+typedef struct _DMAD_AHB_CH_ROUTE {
+ u32 dev_reqn; /* device req/gnt number */
+ addr_t clear_cr; /* routing control register address */
+ addr_t route_cr; /* routing control register address */
+} DMAD_AHB_CH_ROUTE;
+
+#ifdef CONFIG_PLAT_AG102
+#if 0
+/* AHB DMAC channel re-route table. Indexed by AHB DMAC req/ack number. */
+static DMAD_AHB_CH_ROUTE ahb_ch_route_table[] __attribute__ ((__unused__)) = {
+ /* all todo ... */
+
+ {
+ 0x00, DMAC_REQN_IDERX, DMAC_REQN_IDERX}, {
+ 0x01, DMAC_REQN_IDETX, DMAC_REQN_IDETX}, {
+ 0x02, DMAC_REQN_I2SAC97RX, DMAC_REQN_I2SAC97RX}, {
+ 0x03, DMAC_REQN_I2SAC97TX, DMAC_REQN_I2SAC97TX}, {
+ 0x04, DMAC_REQN_UART2RX, DMAC_REQN_UART2RX}, {
+ 0x05, DMAC_REQN_UART2TX, DMAC_REQN_UART2TX}, {
+ 0x06, DMAC_REQN_UART1RX, DMAC_REQN_UART1RX}, {
+ 0x07, DMAC_REQN_UART1TX, DMAC_REQN_UART1TX}, {
+ 0x08, DMAC_REQN_SDC, DMAC_REQN_SDC}, {
+ 0x09, DMAC_REQN_CFC, DMAC_REQN_CFC}, {
+ 0x0a, DMAC_REQN_LPCREQ0, DMAC_REQN_LPCREQ0}, {
+ 0x0b, DMAC_REQN_LPCREQ1, DMAC_REQN_LPCREQ1}, {
+ 0x0c, DMAC_REQN_LPCREQ2, DMAC_REQN_LPCREQ2}, {
+ 0x0d, DMAC_REQN_LPCREQ3, DMAC_REQN_LPCREQ3}, {
+ 0x0e, 0, 0}, {
+0x0f, DMAC_REQN_LPCREQ5, DMAC_REQN_LPCREQ5},};
+#endif
+#else /* CONFIG_PLAT_AG102 */
+
+/* AHB DMAC channel re-route table. Indexed by AHB DMAC req/ack number. */
+static DMAD_AHB_CH_ROUTE ahb_ch_route_table[] = {
+ {0x00, 0, 0},
+ {0x01, PMU_CFC_REQACK_CFG, PMU_CFC_REQACK_CFG},
+ {0x02, PMU_SSP1_REQACK_CFG, PMU_SSP1_REQACK_CFG},
+ {0x03, PMU_UART1RX_REQACK_CFG, PMU_UART1TX_REQACK_CFG},
+ {0x04, PMU_UART1TX_REQACK_CFG, PMU_UART1RX_REQACK_CFG},
+ {0x05, PMU_UART2RX_REQACK_CFG, PMU_UART2TX_REQACK_CFG},
+ {0x06, PMU_UART2TX_REQACK_CFG, PMU_UART2RX_REQACK_CFG},
+ {0x07, PMU_SDC_REQACK_CFG, PMU_SDC_REQACK_CFG},
+ {0x08, PMU_I2SAC97RX_REQACK_CFG, PMU_I2SAC97TX_REQACK_CFG},
+ {0x09, 0, 0},
+ {0x0a, PMU_I2SAC97TX_REQACK_CFG, PMU_I2SAC97RX_REQACK_CFG},
+ {0x0b, PMU_USB_REQACK_CFG, PMU_USB_REQACK_CFG},
+ {0x0c, 0, 0},
+ {0x0d, 0, 0},
+ {0x0e, PMU_EXT0_REQACK_CFG, PMU_EXT0_REQACK_CFG},
+ {0x0f, PMU_EXT1_REQACK_CFG, PMU_EXT1_REQACK_CFG},
+};
+
+#endif /* CONFIG_PLAT_AG102 */
+
+#ifdef CONFIG_PLATFORM_AHBDMA
+
+/* system irq number (per channel, ahb) */
+static const unsigned int ahb_irqs[DMAD_AHB_MAX_CHANNELS] = {
+ DMAC_FTDMAC020_0_IRQ0,
+ DMAC_FTDMAC020_0_IRQ1,
+ DMAC_FTDMAC020_0_IRQ2,
+ DMAC_FTDMAC020_0_IRQ3,
+ DMAC_FTDMAC020_0_IRQ4,
+ DMAC_FTDMAC020_0_IRQ5,
+ DMAC_FTDMAC020_0_IRQ6,
+ DMAC_FTDMAC020_0_IRQ7,
+};
+
+#endif /* CONFIG_PLATFORM_AHBDMA */
+
+#ifdef CONFIG_PLATFORM_APBDMA
+
+/* APB Bridge DMA request number re-route table */
+typedef struct _DMAD_APB_REQN_ROUTE {
+ u32 apb_reqn; /* APB device req/gnt number */
+ u32 ahb_reqn_tx; /* AHB DMAC req/ack number (tx) */
+ u32 ahb_reqn_rx; /* AHB DMAC req/ack number (rx) */
+ u32 bus_sel; /* APBBR_ADDRSEL_APB(0) or APBBR_ADDRSEL_AHB(1) */
+} DMAD_APB_REQN_ROUTE;
+
+#ifdef CONFIG_PLAT_AG102
+
+/* APB Bridge DMA request number re-route table. Indexed by APB DMA req/gnt
+ * number. */
+static DMAD_APB_REQN_ROUTE apb_reqn_route_table[] = {
+ {0x00, 0x00, 0x00, APBBR_ADDRSEL_AHB},
+ {0x01, DMAC_REQN_CFC, DMAC_REQN_CFC, APBBR_ADDRSEL_APB},
+ {0x02, 0x00, 0x00, APBBR_ADDRSEL_APB},
+ {0x03, 0x00, 0x00, APBBR_ADDRSEL_AHB},
+ {0x04, 0x00, 0x00, APBBR_ADDRSEL_AHB},
+ //MOD by river 2010.10.20
+ {0x05, 0x00, 0x00, APBBR_ADDRSEL_AHB},
+ //End MOD by river 2010.10.20
+ {0x06, DMAC_REQN_I2SAC97TX, DMAC_REQN_I2SAC97RX, APBBR_ADDRSEL_APB},
+ {0x07, 0x00, 0x00, APBBR_ADDRSEL_AHB},
+ //MOD by river 2010.10.20
+ {0x08, DMAC_REQN_SDC, DMAC_REQN_SDC, APBBR_ADDRSEL_APB},
+ //End MOD by river 2010.10.20
+ {0x09, 0x00, 0x00, APBBR_ADDRSEL_AHB},
+ {0x0a, DMAC_REQN_UART2TX, DMAC_REQN_UART2RX, APBBR_ADDRSEL_APB},
+ {0x0b, 0x00, 0x00, APBBR_ADDRSEL_AHB},
+ {0x0c, 0x00, 0x00, APBBR_ADDRSEL_AHB},
+ {0x0d, DMAC_REQN_I2SAC97TX, DMAC_REQN_I2SAC97RX, APBBR_ADDRSEL_APB},
+ {0x0e, 0x00, 0x00, APBBR_ADDRSEL_AHB},
+ {0x0f, 0x00, 0x00, APBBR_ADDRSEL_AHB},
+};
+
+#else /* CONFIG_PLAT_AG102 */
+
+/* APB Bridge DMA request number re-route table. Indexed by APB DMA req/gnt
+ * number. */
+static DMAD_APB_REQN_ROUTE apb_reqn_route_table[] = {
+ {0x00, 0x00, 0x00, APBBR_ADDRSEL_AHB},
+ {0x01, DMAC_REQN_CFC, DMAC_REQN_CFC, APBBR_ADDRSEL_APB},
+ {0x02, DMAC_REQN_SSP, DMAC_REQN_SSP, APBBR_ADDRSEL_APB},
+ {0x03, 0x00, 0x00, APBBR_ADDRSEL_AHB},
+ {0x04, 0x00, 0x00, APBBR_ADDRSEL_AHB},
+ {0x05, DMAC_REQN_SDC, DMAC_REQN_SDC, APBBR_ADDRSEL_APB},
+ {0x06, DMAC_REQN_I2SAC97TX, DMAC_REQN_I2SAC97RX, APBBR_ADDRSEL_APB},
+/* for amerald
+ { 0x07, 0x00, 0x00, APBBR_ADDRSEL_AHB },*/
+ {0x07, APBBR_REQN_SDC_AMERALD, APBBR_REQN_SDC_AMERALD,
+ APBBR_ADDRSEL_AHB},
+/* for amerald ac97
+ { 0x08, 0x00, 0x00, APBBR_ADDRSEL_AHB }, */
+ {0x08, APBBR_REQN_I2SAC97TX_AMERALD, APBBR_REQN_I2SAC97TX_AMERALD,
+ APBBR_ADDRSEL_APB},
+ {0x09, 0x00, 0x00, APBBR_ADDRSEL_AHB},
+ {0x0a, DMAC_REQN_UART2TX, DMAC_REQN_UART2RX, APBBR_ADDRSEL_APB},
+ {0x0b, 0x00, 0x00, APBBR_ADDRSEL_AHB},
+ {0x0c, 0x00, 0x00, APBBR_ADDRSEL_AHB},
+ {0x0d, DMAC_REQN_I2SAC97TX, DMAC_REQN_I2SAC97RX, APBBR_ADDRSEL_APB},
+ {0x0e, 0x00, 0x00, APBBR_ADDRSEL_AHB},
+ {0x0f, 0x00, 0x00, APBBR_ADDRSEL_AHB},
+};
+
+#endif /* CONFIG_PLAT_AG102 */
+
+/* system irq number (per channel, apb) */
+static const unsigned int apb_irqs[DMAD_APB_MAX_CHANNELS] = {
+ APBBRG_FTAPBBRG020S_0_IRQ0,
+ APBBRG_FTAPBBRG020S_0_IRQ1,
+ APBBRG_FTAPBBRG020S_0_IRQ2,
+ APBBRG_FTAPBBRG020S_0_IRQ3,
+};
+
+#endif
+
+/* Driver data structure, one instance per system */
+typedef struct DMAD_DATA_STRUCT {
+ /* Driver data initialization flag */
+
+ /* DMA queue pool access control object */
+ spinlock_t drq_pool_lock;
+
+ /* DMA queue base address, to ease alloc/free flow */
+ dmad_drq *drq_pool;
+
+#ifdef CONFIG_PLATFORM_AHBDMA
+ /* DMA queue for AHB DMA channels */
+ dmad_drq *ahb_drq_pool;
+#endif
+
+#ifdef CONFIG_PLATFORM_APBDMA
+ /* DMA queue for APB DMA channels */
+ dmad_drq *apb_drq_pool;
+#endif
+
+} DMAD_DATA;
+
+/* Driver data structure instance, one instance per system */
+static DMAD_DATA dmad __attribute__ ((aligned(4))) = {
+ .drq_pool_lock = __SPIN_LOCK_UNLOCKED(dmad.drq_pool_lock),
+// .drq_pool_lock = SPIN_LOCK_UNLOCKED,
+ .drq_pool = 0,
+#ifdef CONFIG_PLATFORM_AHBDMA
+ .ahb_drq_pool = 0,
+#endif
+#ifdef CONFIG_PLATFORM_APBDMA
+ .apb_drq_pool = 0,
+#endif
+};
+
+/**
+ * dmad_next_drb - static function
+ * @drb_pool : [in] The raw DRB pool of a DMA channel
+ * @node : [in] The node number to lookup its next node
+ * @drb : [out] The drb next to the "node" node number
+ *
+ * Lookup next DRB of the specified node number. "drb" is null if reaches end
+ * of the list.
+ */
+static inline void dmad_next_drb(dmad_drb * drb_pool, u32 node, dmad_drb ** drb)
+{
+ if (likely(drb_pool[node].next != 0))
+ *drb = &drb_pool[drb_pool[node].next];
+ else
+ *drb = 0;
+}
+
+/**
+ * dmad_prev_drb - static function
+ * @drb_pool : [in] The raw DRB pool of a DMA channel
+ * @node : [in] The node number to lookup its previous node
+ * @drb : [out] The drb previous to the "node" node number
+ *
+ * Lookup previous DRB of the specified node number. "drb" is null if reaches
+ * head-end of the list.
+ */
+static inline void dmad_prev_drb(dmad_drb * drb_pool, u32 node, dmad_drb ** drb)
+{
+ if (unlikely(drb_pool[node].prev != 0))
+ *drb = &drb_pool[drb_pool[node].prev];
+ else
+ *drb = 0;
+}
+
+/**
+ * dmad_detach_node - static function
+ * @drb_pool : [in] The raw DRB pool of a DMA channel
+ * @head : [in/out] Reference to the head node number
+ * @tail : [in/out] Reference to the tail node number
+ * @node : [in] The node to be dettached from the queue
+ *
+ * Detached a DRB specified by the node number from the queue. The head and
+ * tail records will be updated accordingly.
+ */
+static inline void dmad_detach_node(dmad_drb * drb_pool,
+ u32 * head, u32 * tail, u32 node)
+{
+ if (likely(drb_pool[node].prev != 0)) {
+ /* prev->next = this->next (= 0, if this is a tail) */
+ drb_pool[drb_pool[node].prev].next = drb_pool[node].next;
+ } else {
+ /* this node is head, move head to next node
+ * (= 0, if this is the only one node) */
+ *head = drb_pool[node].next;
+ }
+
+ if (unlikely(drb_pool[node].next != 0)) {
+ /* next->prev = this->prev (= 0, if this is a head) */
+ drb_pool[drb_pool[node].next].prev = drb_pool[node].prev;
+ } else {
+ /* this node is tail, move tail to previous node
+ * (= 0, if this is the only one node) */
+ *tail = drb_pool[node].prev;
+ }
+
+ drb_pool[node].prev = drb_pool[node].next = 0;
+}
+
+/**
+ * dmad_detach_head - static function
+ * @drb_pool : [in] The raw DRB pool of a DMA channel
+ * @head : [in/out] Reference to the head node number
+ * @tail : [in/out] Reference to the tail node number
+ * @drb : [out] The detached head node; null if the queue is empty
+ *
+ * Detached a DRB from the head of the queue. The head and tail records will
+ * be updated accordingly.
+ */
+static inline void dmad_detach_head(dmad_drb * drb_pool,
+ u32 * head, u32 * tail, dmad_drb ** drb)
+{
+ if (unlikely(*head == 0)) {
+ *drb = NULL;
+ return;
+ }
+
+ *drb = &drb_pool[*head];
+
+ if (likely((*drb)->next != 0)) {
+ /* next->prev = this->prev (= 0, if this is a head) */
+ drb_pool[(*drb)->next].prev = 0;
+
+ /* prev->next = this->next (do nothing, if this is a head) */
+
+ /* head = this->next */
+ *head = (*drb)->next;
+ } else {
+ /* head = tail = 0 */
+ *head = 0;
+ *tail = 0;
+ }
+
+ /* this->prev = this->next = 0 (do nothing, if save code size) */
+ (*drb)->prev = (*drb)->next = 0;
+}
+
+/**
+ * dmad_get_head - static function
+ * @drb_pool : [in] The raw DRB pool of a DMA channel
+ * @head : [in/out] Reference to the head node number
+ * @tail : [in/out] Reference to the tail node number
+ * @drb : [out] The head node; null if the queue is empty
+ *
+ * Get a DRB from the head of the queue. The head and tail records remain
+ * unchanged.
+ */
+static inline void dmad_get_head(dmad_drb * drb_pool, const u32 * head,
+ const u32 * tail, dmad_drb ** drb)
+{
+ if (unlikely(*head == 0)) {
+ *drb = NULL;
+ return;
+ }
+
+ *drb = &drb_pool[*head];
+}
+
+/**
+ * dmad_detach_tail - static function
+ * @drb_pool : [in] The raw DRB pool of a DMA channel
+ * @head : [in/out] Reference to the head node number
+ * @tail : [in/out] Reference to the tail node number
+ * @drb : [out] The tail node; null if the queue is empty
+ *
+ * Detached a DRB from the head of the queue. The head and tail records will
+ * be updated accordingly.
+ */
+static inline void dmad_detach_tail(dmad_drb * drb_pool,
+ u32 * head, u32 * tail, dmad_drb ** drb)
+{
+ if (unlikely(*tail == 0)) {
+ *drb = NULL;
+ return;
+ }
+
+ *drb = &drb_pool[*tail];
+
+ if (likely((*drb)->prev != 0)) {
+ /* prev->next = this->next (= 0, if this is a tail) */
+ drb_pool[(*drb)->prev].next = 0;
+
+ /* next->prev = this->prev (do nothing, if this is a tail) */
+
+ /* tail = this->prev */
+ *tail = (*drb)->prev;
+ } else {
+ /* head = tail = 0 */
+ *head = 0;
+ *tail = 0;
+ }
+
+ /* this->next = this->prev = 0 (do nothing, if save code size) */
+ (*drb)->prev = (*drb)->next = 0;
+}
+
+/**
+ * dmad_get_tail - static function
+ * @drb_pool : [in] The raw DRB pool of a DMA channel
+ * @head : [in/out] Reference to the head node number
+ * @tail : [in/out] Reference to the tail node number
+ * @drb : [out] The tail node; null if the queue is empty
+ *
+ * Get a DRB from the tail of the queue. The head and tail records remain
+ * unchanged.
+ */
+static inline void dmad_get_tail(dmad_drb * drb_pool,
+ u32 * head, u32 * tail, dmad_drb ** drb)
+{
+ if (unlikely(*tail == 0)) {
+ *drb = NULL;
+ return;
+ }
+
+ *drb = &drb_pool[*tail];
+}
+
+/**
+ * dmad_attach_head - static function
+ * @drb_pool : [in] The raw DRB pool of a DMA channel
+ * @head : [in/out] Reference to the head node number
+ * @tail : [in/out] Reference to the tail node number
+ * @node : [in] The node to be attached
+ *
+ * Attach a DRB node to the head of the queue. The head and tail records will
+ * be updated accordingly.
+ */
+static inline void dmad_attach_head(dmad_drb * drb_pool,
+ u32 * head, u32 * tail, u32 node)
+{
+ if (likely(*head != 0)) {
+ /* head->prev = this */
+ drb_pool[*head].prev = node;
+
+ /* this->next = head */
+ drb_pool[node].next = *head;
+ /* this->prev = 0 */
+ drb_pool[node].prev = 0;
+
+ /* head = node */
+ *head = node;
+ } else {
+ /* head = tail = node */
+ *head = *tail = node;
+ drb_pool[node].prev = drb_pool[node].next = 0;
+ }
+}
+
+/**
+ * dmad_attach_head - static function
+ * @drb_pool : [in] The raw DRB pool of a DMA channel
+ * @head : [in/out] Reference to the head node number
+ * @tail : [in/out] Reference to the tail node number
+ * @node : [in] The node to be attached
+ *
+ * Attach a DRB node to the tail of the queue. The head and tail records will
+ * be updated accordingly.
+ */
+static inline void dmad_attach_tail(dmad_drb * drb_pool,
+ u32 * head, u32 * tail, u32 node)
+{
+ if (likely(*tail != 0)) {
+ /* tail->next = this */
+ drb_pool[*tail].next = node;
+
+ /* this->prev = tail */
+ drb_pool[node].prev = *tail;
+ /* this->next = 0 */
+ drb_pool[node].next = 0;
+
+ /* tail = node */
+ *tail = node;
+ } else {
+ /* head = tail = node */
+ *head = *tail = node;
+ drb_pool[node].prev = drb_pool[node].next = 0;
+ }
+}
+
+#ifdef CONFIG_PLATFORM_AHBDMA
+
+/**
+ * dmad_ahb_isr - AHB DMA interrupt service routine
+ *
+ * @irq : [in] The irq number
+ * @dev_id : [in] The identifier to identify the asserted channel
+ *
+ * This is the ISR that services all AHB DMA channels.
+ */
+static irqreturn_t dmad_ahb_isr(int irq, void *dev_id)
+{
+ dmad_drq *drq;
+ dmad_drb *drb, *drb_iter;
+ u32 channel = ((u32) dev_id) - 1;
+ u8 tc_int = 0;
+ u8 err_int = 0;
+ u8 abt_int = 0;
+ u8 cpl_events = 1;
+
+ dmad_dbg("%s() >> channel(%d)\n", __func__, channel);
+
+ if (channel >= DMAD_AHB_MAX_CHANNELS) {
+ dmad_err("%s() invlaid channel number: %d!\n",
+ __func__, channel);
+ return IRQ_HANDLED;
+ }
+
+ /* Fetch channel's DRQ struct (DMA Request Queue) */
+ drq = (dmad_drq *) & dmad.ahb_drq_pool[channel];
+
+ /* Check DMA status register to get channel number */
+ if (likely(getbl(channel, DMAC_INT_TC))) {
+
+ /* Mark as TC int */
+ tc_int = 1;
+
+ /* DMAC INT TC status clear */
+ setbl(channel, DMAC_INT_TC_CLR);
+
+ } else if (getbl(channel + DMAC_INT_ERR_SHIFT, DMAC_INT_ERRABT)) {
+
+ /* Mark as ERR int */
+ err_int = 1;
+
+ /* DMAC INT ERR status clear */
+ setbl(channel + DMAC_INT_ERR_CLR_SHIFT, DMAC_INT_ERRABT_CLR);
+
+ } else if (getbl(channel + DMAC_INT_ABT_SHIFT, DMAC_INT_ERRABT)) {
+
+ /* Mark as ABT int */
+ abt_int = 1;
+
+ /* DMAC INT ABT status clear */
+ setbl(channel + DMAC_INT_ABT_CLR_SHIFT, DMAC_INT_ERRABT_CLR);
+
+ } else {
+
+ dmad_err("%s() possible false-fired ahb dma int,"
+ "channel %d status-reg: tc(0x%08x) arrabt(0x%08x)\n",
+ __func__, channel,
+ inl(DMAC_INT_TC), inl(DMAC_INT_ERRABT_CLR));
+
+ /* Stop DMA channel (make sure the channel will be stopped) */
+ clrbl(DMAC_CSR_CH_EN_BIT, drq->channel_base + DMAC_CSR_OFFSET);
+
+ return IRQ_HANDLED;
+ }
+
+ /* DMAC
+ * Stop DMA channel temporarily */
+ dmad_disable_channel(drq);
+
+ spin_lock(&drq->drb_pool_lock);
+
+ /* Lookup/detach latest submitted DRB (DMA Request Block) from
+ * the DRQ (DMA Request Queue), so ISR could kick off next DRB */
+ dmad_detach_head(drq->drb_pool, &drq->sbt_head, &drq->sbt_tail, &drb);
+ if (drb == NULL) {
+ spin_unlock(&drq->drb_pool_lock);
+ /* submitted list could be empty if client cancel all requests
+ * of the channel. */
+ return IRQ_HANDLED;
+ }
+
+ /* release blocking of drb-allocation, if any ... */
+ if (unlikely((drq->fre_head == 0) &&
+ (drq->flags & DMAD_FLAGS_SLEEP_BLOCK))) {
+ complete_all(&drq->drb_alloc_sync);
+ }
+
+ /* Process DRBs according to interrupt reason */
+ if (tc_int) {
+
+ dmad_dbg("dma finish\n");
+
+ dmad_dbg("finish drb(%d 0x%08x) addr0(0x%08x) "
+ "addr1(0x%08x) size(0x%08x)\n",
+ drb->node, (u32) drb, drb->src_addr,
+ drb->dst_addr, drb->req_cycle);
+
+ if (drb->req_cycle == 0)
+ cpl_events = 0;
+
+ // Mark DRB state as completed
+ drb->state = DMAD_DRB_STATE_COMPLETED;
+ if (cpl_events && drb->sync)
+ complete_all(drb->sync);
+
+ dmad_attach_tail(drq->drb_pool, &drq->fre_head,
+ &drq->fre_tail, drb->node);
+
+ // Check whether there are pending requests in the DRQ
+ if (drq->sbt_head != 0) {
+
+ // Lookup next DRB (DMA Request Block)
+ drb_iter = &drq->drb_pool[drq->sbt_head];
+
+ dmad_dbg("exec drb(%d 0x%08x) addr0(0x%08x) "
+ "addr1(0x%08x) size(0x%08x)\n",
+ drb_iter->node, (u32) drb_iter,
+ drb_iter->src_addr, drb_iter->dst_addr,
+ drb_iter->req_cycle);
+
+ // Kick-off DMA for next DRB
+ // - Source and destination address
+ if (drq->flags & DMAD_DRQ_DIR_A1_TO_A0) {
+ outl(drb_iter->addr1, drq->src_port);
+ outl(drb_iter->addr0, drq->dst_port);
+ } else {
+ outl(drb_iter->addr0, drq->src_port);
+ outl(drb_iter->addr1, drq->dst_port);
+ }
+
+ /* - Transfer size (in units of source width) */
+ outl(drb_iter->req_cycle, drq->cyc_port);
+
+ /* Kick off next request */
+ dmad_enable_channel(drq);
+
+ drb_iter->state = DMAD_DRB_STATE_EXECUTED;
+
+ } else {
+ /* No pending requests, keep the DMA channel stopped */
+ }
+
+ } else {
+
+ dmad_err("%s() ahb dma channel %d error!\n", __func__, channel);
+
+ /* Zero out src, dst, and size */
+ outl(0, drq->src_port);
+ outl(0, drq->dst_port);
+ outl(0, drq->cyc_port);
+
+ /* Remove all pending requests in the queue */
+ drb_iter = drb;
+ while (drb_iter) {
+
+ dmad_err("abort drb(%d 0x%08x) addr0(0x%08x) "
+ "addr1(0x%08x) size(0x%08x)\n",
+ drb_iter->node, (u32) drb_iter,
+ drb_iter->src_addr, drb_iter->dst_addr,
+ drb_iter->req_cycle);
+
+ if (drb_iter->req_cycle == 0)
+ cpl_events = 0;
+
+ /* Mark DRB state as abort */
+ drb_iter->state = DMAD_DRB_STATE_ABORT;
+
+ if (cpl_events && drb_iter->sync)
+ complete_all(drb_iter->sync);
+
+ dmad_attach_tail(drq->drb_pool, &drq->fre_head,
+ &drq->fre_tail, drb_iter->node);
+
+ /* Detach next submitted DRB (DMA Request Block)
+ * from the DRQ (DMA Request Queue) */
+ dmad_detach_head(drq->drb_pool, &drq->sbt_head,
+ &drq->sbt_tail, &drb_iter);
+ }
+ }
+
+ spin_unlock(&drq->drb_pool_lock);
+
+ /* dispatch interrupt-context level callbacks */
+ if (cpl_events && drq->completion_cb) {
+ /* signal DMA driver that new node is available */
+ drq->completion_cb(channel, tc_int, drq->completion_data);
+ }
+
+ dmad_dbg("%s() <<\n", __func__);
+
+ return IRQ_HANDLED;
+}
+
+/**
+ * dmad_ahb_config_dir - prepare command reg according to tx direction
+ * @ch_req : [in] Reference to the DMA request descriptor structure
+ * @channel_cmds : [out] Reference to array of command words to be prepared with
+ * @return : none
+ *
+ * Prepare command registers according to transfer direction ...
+ * channel_cmd[0] DMAC_CSR
+ * channel_cmd[1] DMAC_CFG
+ *
+ * This function only serves as local helper. No protection wrappers.
+ */
+static void dmad_ahb_config_dir(dmad_chreq * ch_req, addr_t * channel_cmds)
+{
+ dmad_drq *drq = (dmad_drq *) ch_req->drq;
+ dmad_ahb_chreq *ahb_req = (dmad_ahb_chreq *) (&ch_req->ahb_req);
+/* for amerald */
+ u32 reqn0, reqn1;
+ dmad_dbg("%s() channel_cmds(0x%08x, 0x%08x)\n",
+ __func__, channel_cmds[0], channel_cmds[1]);
+/* for amerald */
+ if ((inl(PMU_BASE) & AMERALD_MASK) == AMERALD_PRODUCT_ID) {
+ reqn0 = ahb_req->addr0_reqn;
+ reqn1 = ahb_req->addr1_reqn;
+ } else {
+ reqn0 = ch_req->channel;
+ reqn1 = ch_req->channel;
+ }
+ channel_cmds[0] &= ~(addr_t)
+ (DMAC_CSR_SRC_WIDTH_MASK | DMAC_CSR_SRCAD_CTL_MASK |
+ DMAC_CSR_DST_WIDTH_MASK | DMAC_CSR_DSTAD_CTL_MASK |
+ DMAC_CSR_MODE_MASK);
+ channel_cmds[1] &= ~(addr_t)
+ (DMAC_CFG_INT_SRC_RS_MASK | DMAC_CFG_INT_SRC_HE_MASK |
+ DMAC_CFG_INT_DST_RS_MASK | DMAC_CFG_INT_DST_HE_MASK);
+
+ /* 0 - addr0 to addr1; 1 - addr1 to addr0 */
+ if (ahb_req->tx_dir == 0) {
+
+ dmad_dbg("%s() addr0 --> addr1\n", __func__);
+
+ /* - Channel CSR
+ * DST_SEL : 0 (Master 0)
+ * SRC_SEL : 0 (Master 0)
+ * DSTAD_CTL : ahb_req->dst_ctrl
+ * SRCAD_CTL : ahb_req->src_ctrl
+ * MODE : 0 (normal)
+ * DST_WIDTH : ahb_req->dst_width
+ * SRC_WIDTH : ahb_req->src_width
+ * SRC_SIZE : 0 (burst size = 1 byte)
+ */
+ channel_cmds[0] |=
+ (((ahb_req->addr0_width << DMAC_CSR_SRC_WIDTH_SHIFT) &
+ DMAC_CSR_SRC_WIDTH_MASK) |
+ ((ahb_req->addr0_ctrl << DMAC_CSR_SRCAD_CTL_SHIFT) &
+ DMAC_CSR_SRCAD_CTL_MASK) |
+ ((ahb_req->addr1_width << DMAC_CSR_DST_WIDTH_SHIFT) &
+ DMAC_CSR_DST_WIDTH_MASK) |
+ ((ahb_req->addr1_ctrl << DMAC_CSR_DSTAD_CTL_SHIFT) &
+ DMAC_CSR_DSTAD_CTL_MASK));
+
+ /* - Channel CFG
+ * SRC_RS : channel number (not reqn)
+ * SRC_HE : 0 if memory, 1 if device
+ * DST_RS : channel number (not reqn)
+ * DST_HE : 0 if memory, 1 if device
+ */
+ if (likely(ahb_req->hw_handshake != 0)) {
+ /* Channel CSR - Enable HW-handshake mode */
+ channel_cmds[0] |= DMAC_CSR_MODE_MASK;
+
+ /* Channel CFG - Device REQN and HW-handshake mode */
+#ifdef CONFIG_PLAT_AG102
+ /* AG102 fixes this bug */
+ if (ahb_req->addr0_reqn != DMAC_REQN_NONE) {
+ channel_cmds[1] |= (DMAC_CFG_INT_SRC_HE_MASK |
+ ((ahb_req->addr0_reqn <<
+ DMAC_CFG_INT_SRC_RS_SHIFT)
+ &
+ DMAC_CFG_INT_SRC_RS_MASK));
+ }
+
+ if (ahb_req->addr1_reqn != DMAC_REQN_NONE) {
+ channel_cmds[1] |= (DMAC_CFG_INT_DST_HE_MASK |
+ ((ahb_req->addr1_reqn <<
+ DMAC_CFG_INT_DST_RS_SHIFT)
+ &
+ DMAC_CFG_INT_DST_RS_MASK));
+ }
+#else
+ /* AG101/XC5 bug */
+/* for amerald */
+ if (ahb_req->addr0_reqn != DMAC_REQN_NONE) {
+ channel_cmds[1] |= (DMAC_CFG_INT_SRC_HE_MASK |
+ ((reqn0 <<
+ DMAC_CFG_INT_SRC_RS_SHIFT)
+ &
+ DMAC_CFG_INT_SRC_RS_MASK));
+ }
+
+ if (ahb_req->addr1_reqn != DMAC_REQN_NONE) {
+ channel_cmds[1] |= (DMAC_CFG_INT_DST_HE_MASK |
+ ((reqn1 <<
+ DMAC_CFG_INT_DST_RS_SHIFT)
+ &
+ DMAC_CFG_INT_DST_RS_MASK));
+ }
+#endif
+ }
+
+ /* update source data width for faster cycle/byte size conversion */
+ drq->data_width = ahb_req->addr0_width;
+
+ /* remember channel transfer direction */
+ drq->flags &= ~(addr_t) DMAD_DRQ_DIR_A1_TO_A0;
+
+ } else {
+
+ dmad_dbg("%s() addr0 <-- addr1\n", __func__);
+
+ /* - Channel CSR
+ * DST_SEL : 0 (Master 0)
+ * SRC_SEL : 0 (Master 0)
+ * DSTAD_CTL : ahb_req->dst_ctrl
+ * SRCAD_CTL : ahb_req->src_ctrl
+ * MODE : 0 (normal)
+ * DST_WIDTH : ahb_req->dst_width
+ * SRC_WIDTH : ahb_req->src_width
+ * SRC_SIZE : 0 (burst size = 1 byte)
+ */
+ channel_cmds[0] |=
+ (((ahb_req->addr1_width << DMAC_CSR_SRC_WIDTH_SHIFT) &
+ DMAC_CSR_SRC_WIDTH_MASK) |
+ ((ahb_req->addr1_ctrl << DMAC_CSR_SRCAD_CTL_SHIFT) &
+ DMAC_CSR_SRCAD_CTL_MASK) |
+ ((ahb_req->addr0_width << DMAC_CSR_DST_WIDTH_SHIFT) &
+ DMAC_CSR_DST_WIDTH_MASK) |
+ ((ahb_req->addr0_ctrl << DMAC_CSR_DSTAD_CTL_SHIFT) &
+ DMAC_CSR_DSTAD_CTL_MASK));
+
+ /* - Channel CFG
+ * SRC_RS : channel number (not reqn)
+ * SRC_HE : 0 if memory, 1 if device
+ * DST_RS : channel number (not reqn)
+ * DST_HE : 0 if memory, 1 if device
+ */
+ if (likely(ahb_req->hw_handshake != 0)) {
+ /* Channel CSR - Enable HW-handshake mode */
+ channel_cmds[0] |= DMAC_CSR_MODE_MASK;
+
+ /* Channel CFG - Device REQN and HW-handshake mode */
+#ifdef CONFIG_PLAT_AG102
+ /* AG102 fixes this bug */
+ if (ahb_req->addr1_reqn != DMAC_REQN_NONE) {
+ channel_cmds[1] |= (DMAC_CFG_INT_SRC_HE_MASK |
+ ((ahb_req->addr1_reqn <<
+ DMAC_CFG_INT_SRC_RS_SHIFT)
+ &
+ DMAC_CFG_INT_SRC_RS_MASK));
+ }
+
+ if (ahb_req->addr0_reqn != DMAC_REQN_NONE) {
+ channel_cmds[1] |= (DMAC_CFG_INT_DST_HE_MASK |
+ ((ahb_req->addr0_reqn <<
+ DMAC_CFG_INT_DST_RS_SHIFT)
+ &
+ DMAC_CFG_INT_DST_RS_MASK));
+ }
+#else
+ /* AG101/XC5 bug */
+/* for amerald */
+ if (ahb_req->addr1_reqn != DMAC_REQN_NONE) {
+ channel_cmds[1] |= (DMAC_CFG_INT_SRC_HE_MASK |
+ ((reqn1 <<
+ DMAC_CFG_INT_SRC_RS_SHIFT)
+ &
+ DMAC_CFG_INT_SRC_RS_MASK));
+ }
+
+ if (ahb_req->addr0_reqn != DMAC_REQN_NONE) {
+ channel_cmds[1] |= (DMAC_CFG_INT_DST_HE_MASK |
+ ((reqn0 <<
+ DMAC_CFG_INT_DST_RS_SHIFT)
+ &
+ DMAC_CFG_INT_DST_RS_MASK));
+ }
+#endif
+ }
+
+ /* source data width */
+ drq->data_width = ahb_req->addr1_width;
+
+ /* remember channel transfer direction */
+ drq->flags |= (addr_t) DMAD_DRQ_DIR_A1_TO_A0;
+ }
+
+ dmad_dbg("%s() channel_cmds(0x%08x, 0x%08x)\n",
+ __func__, channel_cmds[0], channel_cmds[1]);
+}
+
+/**
+ * dmad_ahb_init - initialize a ahb dma channel
+ * @ch_req : [in] Reference to the DMA request descriptor structure
+ * @return : 0 if success, non-zero if any error
+ *
+ * Register AHB DMA ISR and performs hw initialization for the given DMA
+ * channel.
+ */
+static int dmad_ahb_init(dmad_chreq * ch_req)
+{
+ int err = 0;
+ dmad_drq *drq = (dmad_drq *) ch_req->drq;
+ dmad_ahb_chreq *ahb_req = (dmad_ahb_chreq *) (&ch_req->ahb_req);
+ u32 channel = (u32) ch_req->channel;
+ addr_t channel_base = drq->channel_base;
+ addr_t channel_cmds[2]; // [0] DMAC_CSR; [1] DMAC_CFG
+ unsigned long lock_flags;
+
+ dmad_dbg("%s()\n", __func__);
+
+ /* register interrupt handler */
+ err = request_irq(ahb_irqs[channel], dmad_ahb_isr, 0,
+ "AHB_DMA", (void *)(channel + 1));
+ if (unlikely(err != 0)) {
+ dmad_err("unable to request IRQ %d for AHB DMA "
+ "(error %d)\n", ahb_irqs[channel], err);
+ free_irq(ahb_irqs[channel], (void *)(channel + 1));
+ return err;
+ }
+
+ spin_lock_irqsave(&dmad.drq_pool_lock, lock_flags);
+
+ /**********************************************************
+ * Following code require _safe_exit return path
+ */
+
+#ifdef CONFIG_PLAT_AG102
+ /* PCU
+ *
+ * Add by Dennis 2011.03.09
+ * set 0 to dma selection register to using AHB
+ * DMA.
+ */
+ if (ahb_req->dst_reqn == ahb_req->src_reqn) {
+ dmad_err
+ ("[dmad] invalid source reqn(%d) or destination reqn(%d)\n",
+ ahb_req->src_reqn, ahb_req->dst_reqn);
+ err = -EBADR;
+ goto _safe_exit;
+ }
+ outl(0, PCU_DMA_SEL);
+#else /* CONFIG_PLAT_AG102 */
+
+ /* PMU
+ *
+ * Route APB device DMA to an AHB DMAC channel and specify the channel
+ * number. (connection status could be read back from PMU_AHBDMA_REQACK
+ * register)
+ *
+ * Note: Only one device is routed per AHB DMA channel, the other target
+ * should be either (1) the same device (same reqn), or (2) the AHB
+ * device (reqn = 0).
+ */
+
+ if (ahb_req->dst_reqn != DMAC_REQN_NONE) {
+ // DMA transfer to device
+ if ((ahb_req->dst_reqn > DMAC_REQN_MAX) ||
+ (ahb_ch_route_table[ahb_req->dst_reqn].route_cr == 0)) {
+ dmad_err("Invalid destination reqn(%d) "
+ "or route_cr(0x%08x)\n", ahb_req->dst_reqn,
+ (u32) ahb_ch_route_table[ahb_req->dst_reqn].
+ route_cr);
+ err = -EBADR;
+ goto _safe_exit;
+ }
+
+ outl(0, ahb_ch_route_table[ahb_req->dst_reqn].clear_cr);
+ outl(PMU_DMACUSED_MASK | ((channel << PMU_CHANNEL_SHIFT) &
+ PMU_CHANNEL_MASK),
+ ahb_ch_route_table[ahb_req->dst_reqn].route_cr);
+
+ } else if (ahb_req->src_reqn != DMAC_REQN_NONE) {
+
+ // DMA transfer from device
+ if ((ahb_req->src_reqn > DMAC_REQN_MAX) ||
+ (ahb_ch_route_table[ahb_req->src_reqn].route_cr == 0)) {
+ dmad_err("Invalid source reqn(%d) or "
+ "route_cr(0x%08x)\n", ahb_req->src_reqn,
+ (u32) ahb_ch_route_table[ahb_req->src_reqn].
+ route_cr);
+ err = -EBADR;
+ goto _safe_exit;
+ }
+
+ outl(0, ahb_ch_route_table[ahb_req->src_reqn].clear_cr);
+ outl(PMU_DMACUSED_MASK | ((channel << PMU_CHANNEL_SHIFT) &
+ PMU_CHANNEL_MASK),
+ ahb_ch_route_table[ahb_req->src_reqn].route_cr);
+ }
+#endif /* CONFIG_PLAT_AG102 */
+
+ /* DMAC (Controller Setting) */
+
+ /* - INT TC/ERR/ABT status clear */
+ setbl(channel, DMAC_INT_TC_CLR);
+ setbl(channel + DMAC_INT_ERR_CLR_SHIFT, DMAC_INT_ERRABT_CLR);
+ setbl(channel + DMAC_INT_ABT_CLR_SHIFT, DMAC_INT_ERRABT_CLR);
+
+ // - CSR (enable DMAC, set M0 & M1 default to little endian)
+ outl(DMAC_DMACEN_MASK |
+ ((DMAC_ENDIAN_LITTLE << DMAC_M0ENDIAN_BIT) & DMAC_M0ENDIAN_MASK) |
+ ((DMAC_ENDIAN_LITTLE << DMAC_M1ENDIAN_BIT) & DMAC_M1ENDIAN_MASK),
+ DMAC_CSR);
+
+ /* DMAC (Channel-Specific Setting) */
+ /* - SYNC */
+ if (ahb_req->sync)
+ setbl(channel, DMAC_SYNC);
+ else
+ clrbl(channel, DMAC_SYNC);
+
+ /* - Channel CSR
+ * CH_EN : 0 (disable)
+ * DST_SEL : 0 (Master 0)
+ * SRC_SEL : 0 (Master 0)
+ * DSTAD_CTL : ahb_req->dst_ctrl
+ * SRCAD_CTL : ahb_req->src_ctrl
+ * MODE : 0 (normal)
+ * DST_WIDTH : ahb_req->dst_width
+ * SRC_WIDTH : ahb_req->src_width
+ * ABT : 0 (not abort)
+ * SRC_SIZE : 0 (burst size = 1 byte)
+ * PROT1 : 0 (user mode)
+ * PROT2 : 0 (bot bufferable)
+ * PROT3 : 0 (not cacheable)
+ * CHPRI : ahb_req->priority
+ * DMA_FF_TH : 0 (FIA320 only, threshold = 1)
+ * TC_MSK : 0 (TC counter status enable)
+ */
+ channel_cmds[0] = (ahb_req->priority << DMAC_CSR_CHPRI_SHIFT) &
+ DMAC_CSR_CHPRI_MASK;
+ channel_cmds[0] |= (ahb_req->burst_size << DMAC_CSR_SRC_SIZE_SHIFT) &
+ DMAC_CSR_SRC_SIZE_MASK;
+
+ // - Channel CFG
+ // INT_TC_MSK : 0 (enable TC int)
+ // INT_ERR_MSK : 0 (enable ERR int)
+ // INT_ABT_MSK : 0 (enable ABT int)
+ // SRC_RS : 0
+ // SRC_HE : 0
+ // BUSY : r/o
+ // DST_RS : 0
+ // DST_HE : 0
+ // LLP_CNT : r/o
+ channel_cmds[1] = 0;
+
+ if (0 ==
+ (ch_req->flags & (DMAD_FLAGS_RING_MODE | DMAD_FLAGS_BIDIRECTION)))
+ ahb_req->tx_dir = 0;
+
+ dmad_ahb_config_dir(ch_req, channel_cmds);
+
+ outl(channel_cmds[0], channel_base + DMAC_CSR_OFFSET);
+ outl(channel_cmds[1], channel_base + DMAC_CFG_OFFSET);
+
+ /* SRCADR and DESADR */
+ outl(0, (addr_t) drq->src_port);
+ outl(0, (addr_t) drq->dst_port);
+
+ /* CYC (transfer size) */
+ outl(0, (addr_t) drq->cyc_port);
+
+ /* LLP */
+ outl(0, channel_base + DMAC_LLP_OFFSET);
+
+ /* TOT_SIZE - not now */
+
+_safe_exit:
+
+ spin_unlock_irqrestore(&dmad.drq_pool_lock, lock_flags);
+
+ return err;
+}
+
+#endif /* CONFIG_PLATFORM_AHBDMA */
+
+#ifdef CONFIG_PLATFORM_APBDMA
+
+/**
+ * dmad_apb_isr - APB DMA interrupt service routine
+ *
+ * @irq : [in] The irq number
+ * @dev_id : [in] The identifier to identify the asserted channel
+ *
+ * This is the ISR that services all APB DMA channels.
+ */
+static irqreturn_t dmad_apb_isr(int irq, void *dev_id)
+{
+ dmad_drq *drq;
+ dmad_drb *drb, *drb_iter;
+ u32 channel = ((u32) dev_id) - 1;
+ u32 status;
+ u8 finish_int = 0;
+ u8 err_int = 0;
+ u8 cpl_events = 1;
+
+ dmad_dbg("%s() >> channel(%d)\n", __func__, channel);
+
+ if (channel >= DMAD_APB_MAX_CHANNELS) {
+ dmad_err("%s() invlaid channel number: %d!\n",
+ __func__, channel);
+ return IRQ_HANDLED;
+ }
+
+ /* Lookup channel's DRQ (DMA Request Queue) */
+ drq = (dmad_drq *) & dmad.apb_drq_pool[channel];
+
+ /* - Check DMA status register to get channel number */
+ status = inl((addr_t) drq->channel_base + APBBR_DMA_CMD_OFFSET);
+
+ if (likely(status & APBBR_DMA_FINTST_MASK)) {
+
+ /*dmad_dbg("apb dma int status: finish (0x%08x)\n", status); */
+ finish_int = 1;
+
+ /* APB DMA finish int status clear */
+ clrbl(APBBR_DMA_FINTST_BIT,
+ (addr_t) drq->channel_base + APBBR_DMA_CMD_OFFSET);
+
+ } else if (status & APBBR_DMA_ERRINTST_MASK) {
+
+ /* Perform DMA error checking if no valid channel was found
+ * who assert the finish signal. */
+ dmad_err("apb dma int status: err (0x%08x)\n", status);
+
+ /* Mark as error int */
+ err_int = 1;
+
+ /* APB DMA error int status clear */
+ clrbl(APBBR_DMA_ERRINTST_BIT,
+ (addr_t) drq->channel_base + APBBR_DMA_CMD_OFFSET);
+
+ } else {
+
+ dmad_err("%s() possible false-fired apb dma int,"
+ " channel %d status-reg: 0x%08x\n",
+ __func__, channel, status);
+
+ /* Stop DMA channel (make sure the channel will be stopped) */
+ clrbl(APBBR_DMA_CHEN_BIT,
+ (addr_t) drq->channel_base + APBBR_DMA_CMD_OFFSET);
+
+ return IRQ_HANDLED;
+ }
+
+ /* Stop DMA channel (make sure the channel will be stopped) */
+ dmad_disable_channel(drq);
+
+ spin_lock(&drq->drb_pool_lock);
+
+ /* Lookup/detach latest submitted DRB (DMA Request Block) from */
+ /* the DRQ (DMA Request Queue), so ISR could kick off next DRB */
+ dmad_detach_head(drq->drb_pool, &drq->sbt_head, &drq->sbt_tail, &drb);
+
+ if (unlikely(drb == NULL)) {
+ spin_unlock(&drq->drb_pool_lock);
+ return IRQ_HANDLED;
+ }
+
+ /* release blocking of drb-allocation, if any ... */
+ if (unlikely((drq->fre_head == 0) &&
+ (drq->flags & DMAD_FLAGS_SLEEP_BLOCK))) {
+ complete_all(&drq->drb_alloc_sync);
+ }
+
+ /* Process DRBs according to the cause of this interrupt */
+ if (likely(finish_int)) {
+
+ if (drb->req_cycle == 0)
+ cpl_events = 0;
+
+ /* Mark DRB state as completed */
+ drb->state = DMAD_DRB_STATE_COMPLETED;
+ if (cpl_events && drb->sync)
+ complete_all(drb->sync);
+
+ dmad_attach_tail(drq->drb_pool, &drq->fre_head,
+ &drq->fre_tail, drb->node);
+
+ /* Check whether there are pending requests in the DRQ */
+ if (drq->sbt_head != 0) {
+
+ /* Lookup next DRB (DMA Request Block) */
+ drb_iter = &drq->drb_pool[drq->sbt_head];
+
+ dmad_dbg("exec drb(%d 0x%08x) addr0(0x%08x) "
+ "addr1(0x%08x) size(0x%08x)\n",
+ drb_iter->node, (u32) drb_iter,
+ drb_iter->src_addr, drb_iter->dst_addr,
+ drb_iter->req_cycle);
+
+ /* Kick-off DMA for next DRB */
+ /* - Source and destination address */
+ if (drq->flags & DMAD_DRQ_DIR_A1_TO_A0) {
+ outl(drb_iter->addr1, drq->src_port);
+ outl(drb_iter->addr0, drq->dst_port);
+ } else {
+ outl(drb_iter->addr0, drq->src_port);
+ outl(drb_iter->addr1, drq->dst_port);
+ }
+
+ /* - Transfer size (in units of source width) */
+ outl(drb_iter->req_cycle, drq->cyc_port);
+
+ /* Kick off next request */
+ dmad_enable_channel(drq);
+
+ drb_iter->state = DMAD_DRB_STATE_EXECUTED;
+
+ } else {
+ /* No pending requests, keep the DMA channel stopped */
+ }
+
+ } else if (err_int) {
+
+ dmad_err("%s() apb dma channel %d error!\n", __func__, channel);
+
+ /* Zero out src, dst, and size */
+ outl(0, drq->src_port);
+ outl(0, drq->dst_port);
+ outl(0, drq->cyc_port);
+
+ /* Remove all pending requests in the queue */
+ drb_iter = drb;
+ while (drb_iter) {
+
+ dmad_err("abort drb(%d 0x%08x) addr0(0x%08x) "
+ "addr1(0x%08x) size(0x%08x)\n",
+ drb_iter->node, (u32) drb_iter,
+ drb_iter->src_addr, drb_iter->dst_addr,
+ drb_iter->req_cycle);
+
+ if (drb_iter->req_cycle == 0)
+ cpl_events = 0;
+
+ /* Mark DRB state as abort */
+ drb_iter->state = DMAD_DRB_STATE_ABORT;
+
+ if (cpl_events && drb_iter->sync)
+ complete_all(drb_iter->sync);
+
+ dmad_attach_tail(drq->drb_pool, &drq->fre_head,
+ &drq->fre_tail, drb_iter->node);
+
+ dmad_detach_head(drq->drb_pool, &drq->sbt_head,
+ &drq->sbt_tail, &drb_iter);
+ }
+ }
+
+ spin_unlock(&drq->drb_pool_lock);
+
+ /* dispatch interrupt-context level callbacks */
+ if (cpl_events && drq->completion_cb) {
+ /* signal DMA driver that new node is available */
+ drq->completion_cb(channel, status, drq->completion_data);
+ }
+
+ dmad_dbg("%s() <<\n", __func__);
+
+ return IRQ_HANDLED;
+}
+
+/**
+ * dmad_apb_config_dir - prepare command reg according to tx direction
+ * @ch_req : [in] Reference to the DMA request descriptor structure
+ * @channel_cmds : [out] Reference to array of command words to be prepared with
+ * @return : none
+ *
+ * Prepare command registers according to transfer direction ...
+ * channel_cmd[0] APBBR_DMA_CMD
+ *
+ * This function only serves as local helper. No protection wrappers.
+ */
+static void dmad_apb_config_dir(dmad_chreq * ch_req, addr_t * channel_cmds)
+{
+ dmad_drq *drq = (dmad_drq *) ch_req->drq;
+ dmad_apb_chreq *apb_req = (dmad_apb_chreq *) (&ch_req->apb_req);
+
+ dmad_dbg("%s() channel_cmd(0x%08x)\n", __func__, channel_cmds[0]);
+
+ *channel_cmds &= ~(addr_t)
+ (APBBR_DMA_SRCADDRINC_MASK | APBBR_DMA_DSTADDRINC_MASK |
+ APBBR_DMA_DSTADDRSEL_MASK | APBBR_DMA_DREQSEL_MASK |
+ APBBR_DMA_SRCADDRSEL_MASK | APBBR_DMA_SREQSEL_MASK);
+
+ /* 0 - addr0 to addr1; 1 - addr1 to addr0 */
+ if (apb_req->tx_dir == 0) {
+
+ dmad_dbg("%s() addr0 --> addr1\n", __func__);
+
+ /* APB Bridge DMA (Channel Setting)
+ * - CMD
+ * SRCADR : apb_req->src_ctrl
+ * DESADR : apb_req->dst_ctrl
+ */
+ *channel_cmds |=
+ (((apb_req->addr0_ctrl << APBBR_DMA_SRCADDRINC_SHIFT) &
+ APBBR_DMA_SRCADDRINC_MASK) |
+ ((apb_req->addr1_ctrl << APBBR_DMA_DSTADDRINC_SHIFT) &
+ APBBR_DMA_DSTADDRINC_MASK));
+
+ /* - CMD
+ * DESADRSEL : AHB/APB, driver auto-conf
+ * DREQSEL
+ */
+ *channel_cmds |=
+ ((addr_t) (APBBR_DMA_DSTADDRSEL_MASK &
+ (apb_reqn_route_table[apb_req->addr1_reqn].
+ bus_sel << APBBR_DMA_DSTADDRSEL_BIT)) |
+ (((addr_t) apb_req->
+ addr1_reqn << APBBR_DMA_DREQSEL_SHIFT) &
+ APBBR_DMA_DREQSEL_MASK));
+
+ /* - CMD
+ * SRCADRSEL : AHB/APB, driver auto-conf
+ * SREQSEL
+ */
+ *channel_cmds |=
+ ((addr_t) (APBBR_DMA_SRCADDRSEL_MASK &
+ (apb_reqn_route_table[apb_req->addr0_reqn].
+ bus_sel << APBBR_DMA_SRCADDRSEL_BIT)) |
+ (((addr_t) apb_req->
+ addr0_reqn << APBBR_DMA_SREQSEL_SHIFT) &
+ APBBR_DMA_SREQSEL_MASK));
+
+ drq->flags &= ~(addr_t) DMAD_DRQ_DIR_A1_TO_A0;
+
+ } else {
+
+ dmad_dbg("%s() addr0 <-- addr1\n", __func__);
+
+ /* APB Bridge DMA (Channel Setting)
+ * - CMD
+ * SRCADR : apb_req->src_ctrl
+ * DESADR : apb_req->dst_ctrl
+ */
+ *channel_cmds |=
+ (((apb_req->addr1_ctrl << APBBR_DMA_SRCADDRINC_SHIFT) &
+ APBBR_DMA_SRCADDRINC_MASK) |
+ ((apb_req->addr0_ctrl << APBBR_DMA_DSTADDRINC_SHIFT) &
+ APBBR_DMA_DSTADDRINC_MASK));
+
+ /* - CMD
+ * DESADRSEL : AHB/APB, driver auto-conf
+ * DREQSEL
+ */
+ *channel_cmds |= ((addr_t) (APBBR_DMA_DSTADDRSEL_MASK &
+ (apb_reqn_route_table
+ [apb_req->addr0_reqn].
+ bus_sel <<
+ APBBR_DMA_DSTADDRSEL_BIT)) |
+ (((addr_t) apb_req->
+ addr0_reqn << APBBR_DMA_DREQSEL_SHIFT) &
+ APBBR_DMA_DREQSEL_MASK));
+
+ /* - CMD
+ * SRCADRSEL : AHB/APB, driver auto-conf
+ * SREQSEL
+ */
+ *channel_cmds |= ((addr_t) (APBBR_DMA_SRCADDRSEL_MASK &
+ (apb_reqn_route_table
+ [apb_req->addr1_reqn].
+ bus_sel <<
+ APBBR_DMA_SRCADDRSEL_BIT)) |
+ (((addr_t) apb_req->
+ addr1_reqn << APBBR_DMA_SREQSEL_SHIFT) &
+ APBBR_DMA_SREQSEL_MASK));
+
+ drq->flags |= (addr_t) DMAD_DRQ_DIR_A1_TO_A0;
+ }
+
+ dmad_dbg("%s() channel_cmd(0x%08x)\n", __func__, channel_cmds[0]);
+}
+
+/**
+ * dmad_apb_init - initialize a apb dma channel
+ * @ch_req : [in] Reference to the DMA request descriptor structure
+ * @return : 0 if success, non-zero if any error
+ *
+ * Register APB DMA ISR and performs hw initialization for the given DMA
+ * channel.
+ */
+static int dmad_apb_init(dmad_chreq * ch_req)
+{
+ int err = 0;
+ dmad_drq *drq = (dmad_drq *) ch_req->drq;
+ dmad_apb_chreq *apb_req = (dmad_apb_chreq *) (&ch_req->apb_req);
+ u32 channel = (u32) ch_req->channel;
+ addr_t channel_cmd = 0;
+ unsigned long lock_flags;
+
+ dmad_dbg("%s()\n", __func__);
+
+ /* register interrupt handler */
+ err = request_irq(apb_irqs[channel], dmad_apb_isr, 0,
+ "APB_DMA", (void *)(channel + 1));
+ if (unlikely(err != 0)) {
+ dmad_err("unable to request IRQ %d for APB DMA (error %d)\n",
+ apb_irqs[channel], err);
+ free_irq(apb_irqs[channel], (void *)(channel + 1));
+ return err;
+ }
+
+ spin_lock_irqsave(&dmad.drq_pool_lock, lock_flags);
+
+ /**********************************************************
+ * Following code require _safe_exit return path
+ */
+
+#ifdef CONFIG_PLAT_AG102
+
+ /* PCU
+ *
+ */
+ //ADD by river 2010.10.20
+ if (unlikely((apb_req->src_reqn > APBBR_REQN_MAX) ||
+ (apb_req->dst_reqn > APBBR_REQN_MAX))) {
+ dmad_err("Invalid source reqn(%d) or destination reqn(%d)\n",
+ apb_req->src_reqn, apb_req->dst_reqn);
+ err = -EBADR;
+ goto _safe_exit;
+ }
+
+ if (apb_req->src_reqn != APBBR_REQN_NONE) {
+ u32 ahb_reqn;
+
+ if (apb_req->tx_dir == DMAD_DIR_A0_TO_A1)
+ ahb_reqn =
+ apb_reqn_route_table[apb_req->src_reqn].ahb_reqn_tx;
+ else
+ ahb_reqn =
+ apb_reqn_route_table[apb_req->src_reqn].ahb_reqn_rx;
+
+ }
+
+ if (apb_req->dst_reqn != APBBR_REQN_NONE) {
+ u32 ahb_reqn;
+
+ if (apb_req->tx_dir == DMAD_DIR_A0_TO_A1)
+ ahb_reqn =
+ apb_reqn_route_table[apb_req->dst_reqn].ahb_reqn_tx;
+ else
+ ahb_reqn =
+ apb_reqn_route_table[apb_req->dst_reqn].ahb_reqn_rx;
+
+ }
+ //End ADD by river 2010.10.20
+
+#else /* CONFIG_PLAT_AG102 */
+
+ /* PMU
+ * - Undo APB device DMA to AHB DMAC channel routing. (connection status
+ * is obtained from reading back the PMU_AHBDMA_REQACK register)
+ */
+ if (unlikely((apb_req->src_reqn > APBBR_REQN_MAX) ||
+ (apb_req->dst_reqn > APBBR_REQN_MAX))) {
+ dmad_err("Invalid source reqn(%d) or destination reqn(%d)\n",
+ apb_req->src_reqn, apb_req->dst_reqn);
+ err = -EBADR;
+ goto _safe_exit;
+ }
+
+ if (apb_req->src_reqn != APBBR_REQN_NONE) {
+ u32 ahb_reqn;
+
+ if (apb_req->tx_dir == DMAD_DIR_A0_TO_A1)
+ ahb_reqn =
+ apb_reqn_route_table[apb_req->src_reqn].ahb_reqn_tx;
+ else
+ ahb_reqn =
+ apb_reqn_route_table[apb_req->src_reqn].ahb_reqn_rx;
+
+ outl(0, ahb_ch_route_table[ahb_reqn].clear_cr);
+ outl(0, ahb_ch_route_table[ahb_reqn].route_cr);
+ outl(0, ahb_ch_route_table[ahb_reqn].clear_cr);
+ outl(0, ahb_ch_route_table[ahb_reqn].route_cr);
+ }
+
+ if (apb_req->dst_reqn != APBBR_REQN_NONE) {
+ u32 ahb_reqn;
+
+ if (apb_req->tx_dir == DMAD_DIR_A0_TO_A1)
+ ahb_reqn =
+ apb_reqn_route_table[apb_req->dst_reqn].ahb_reqn_tx;
+ else
+ ahb_reqn =
+ apb_reqn_route_table[apb_req->dst_reqn].ahb_reqn_rx;
+
+ outl(0, ahb_ch_route_table[ahb_reqn].clear_cr);
+ outl(0, ahb_ch_route_table[ahb_reqn].route_cr);
+ outl(0, ahb_ch_route_table[ahb_reqn].clear_cr);
+ outl(0, ahb_ch_route_table[ahb_reqn].route_cr);
+ }
+#endif /* CONFIG_PLAT_AG102 */
+
+ /* APB Bridge DMA (Channel Setting)
+ * - CMD
+ * ENBDIS : 0 (disable for now)
+ * FININTSTS : 0 (clear finishing interrupt status)
+ * FININTENB : 1 (enable finishing interrupt)
+ * BURMOD : apb_req->burst_mode
+ * ERRINTSTS : 0 (clear error interrupt status)
+ * ERRINTENB : 1 (enable error interrupt)
+ * SRCADRSEL : AHB/APB, driver auto-conf
+ * DESADRSEL : AHB/APB, driver auto-conf
+ * SRCADR : apb_req->src_ctrl
+ * DESADR : apb_req->dst_ctrl
+ * REQSEL : apb_req->src_reqn
+ * DATAWIDTH : apb_req->data_width
+ */
+
+ /* - CMD
+ * ENBDIS
+ * FININTSTS
+ * FININTENB
+ * BURMOD
+ * ERRINTSTS
+ * ERRINTENB
+ * DATAWIDTH
+ */
+ channel_cmd =
+ ((addr_t) APBBR_DMA_FINTEN_MASK | APBBR_DMA_ERRINTEN_MASK |
+ ((apb_req->
+ burst_mode << APBBR_DMA_BURST_BIT) & APBBR_DMA_BURST_MASK) |
+ ((apb_req->
+ data_width << APBBR_DMA_DATAWIDTH_SHIFT) &
+ APBBR_DMA_DATAWIDTH_MASK));
+
+ /* - CMD
+ * SRCADRSEL
+ * DESADRSEL
+ * SRCADR
+ * DESADR
+ * REQSEL
+ */
+ if (0 ==
+ (ch_req->flags & (DMAD_FLAGS_RING_MODE | DMAD_FLAGS_BIDIRECTION)))
+ apb_req->tx_dir = 0;
+ dmad_apb_config_dir(ch_req, &channel_cmd);
+
+ /* - CMD outport */
+ outl(channel_cmd, (addr_t) drq->channel_base + APBBR_DMA_CMD_OFFSET);
+
+ /* SRCADR and DESADR */
+ outl(0, (addr_t) drq->src_port);
+ outl(0, (addr_t) drq->dst_port);
+
+ /* CYC (transfer size) */
+ outl(0, (addr_t) drq->cyc_port);
+
+ /* keep channel data width for faster cycle/byte size conversion */
+ drq->data_width = apb_req->data_width;
+
+_safe_exit:
+
+ spin_unlock_irqrestore(&dmad.drq_pool_lock, lock_flags);
+
+ return err;
+}
+
+#endif /* CONFIG_PLATFORM_APBDMA */
+
+/**
+ * dmad_channel_init - initialize given dma channel
+ * @ch_req : [in] Reference to the DMA request descriptor structure
+ * @return : 0 if success, non-zero if any error
+ *
+ * This function serves as the abstraction layer of dmad_ahb_init()
+ * and dmad_apb_init() functions.
+ */
+static int dmad_channel_init(dmad_chreq * ch_req)
+{
+ int err = 0;
+
+ dmad_dbg("%s()\n", __func__);
+
+ if (unlikely(ch_req == NULL))
+ return -EFAULT;
+
+ if (unlikely(ch_req->drq == NULL))
+ return -EBADR;
+
+ /* Initialize DMA controller */
+#ifdef CONFIG_PLATFORM_AHBDMA
+ if (ch_req->controller == DMAD_DMAC_AHB_CORE)
+ err = dmad_ahb_init(ch_req);
+#endif
+#ifdef CONFIG_PLATFORM_APBDMA
+ if (ch_req->controller == DMAD_DMAC_APB_CORE)
+ err = dmad_apb_init(ch_req);
+#endif
+
+ return err;
+}
+
+static inline void dmad_reset_channel(dmad_drq * drq)
+{
+ /* disable dma controller */
+ dmad_disable_channel(drq);
+
+ /* Source and destination address */
+ outl(0, drq->src_port);
+ outl(0, drq->dst_port);
+
+ /* Transfer size (in units of source width) */
+ outl(0, drq->cyc_port);
+}
+
+/**
+ * dmad_channel_reset - reset given dma channel
+ * @ch_req : [in] Reference to the DMA request descriptor structure
+ * @return : 0 if success, non-zero if any error
+ *
+ * This function serves as the abstraction layer of dmad_ahb_reset()
+ * and dmad_apb_reset() functions.
+ */
+static int dmad_channel_reset(dmad_chreq * ch_req)
+{
+ u32 channel = (u32) ch_req->channel;
+ unsigned long lock_flags;
+ int err = 0;
+
+ dmad_dbg("%s()\n", __func__);
+
+ if (unlikely(ch_req == NULL))
+ return -EFAULT;
+
+ if (unlikely(ch_req->drq == NULL))
+ return -EBADR;
+
+ spin_lock_irqsave(&((dmad_drq *) ch_req->drq)->drb_pool_lock,
+ lock_flags);
+
+ /* stop DMA channel */
+ dmad_reset_channel((dmad_drq *) ch_req->drq);
+
+ spin_unlock_irqrestore(&((dmad_drq *) ch_req->drq)->drb_pool_lock,
+ lock_flags);
+
+ /* unregister interrupt handler */
+#ifdef CONFIG_PLATFORM_AHBDMA
+ if (ch_req->controller == DMAD_DMAC_AHB_CORE)
+ free_irq(ahb_irqs[channel], (void *)(channel + 1));
+#endif
+#ifdef CONFIG_PLATFORM_APBDMA
+ if (ch_req->controller == DMAD_DMAC_APB_CORE)
+ free_irq(apb_irqs[channel], (void *)(channel + 1));
+#endif
+
+ return err;
+}
+
+/**
+ * dmad_channel_alloc - allocates and initialize a dma channel
+ * @ch_req : [in/out] Reference to the DMA request descriptor structure
+ * @return : 0 if success, non-zero if any error
+ *
+ * This function allocates a DMA channel according to client's request
+ * parameters. ISR and HW state will also be initialized accordingly.
+ */
+int dmad_channel_alloc(dmad_chreq * ch_req)
+{
+ dmad_drq *drq_iter = NULL;
+ dmad_drb *drb_iter;
+ int err = 0;
+ u32 i = 0;
+
+ dmad_dbg("%s()\n", __func__);
+
+ if (ch_req == NULL) {
+ printk(KERN_ERR "%s() invalid argument!\n", __func__);
+ return -EFAULT;
+ }
+
+ spin_lock(&dmad.drq_pool_lock);
+
+ /* locate an available DMA channel */
+#ifdef CONFIG_PLATFORM_AHBDMA
+ if (ch_req->controller == DMAD_DMAC_AHB_CORE) {
+
+ drq_iter = dmad.ahb_drq_pool;
+
+ if ((ch_req->ahb_req.src_reqn != DMAC_REQN_NONE) ||
+ (ch_req->ahb_req.dst_reqn != DMAC_REQN_NONE)) {
+ /* [2007-12-03] It looks current board have problem to
+ * do dma traffic for APB devices on DMAC channel 0/1.
+ * Redirect all APB devices to start from channel 2.
+ */
+
+ /* [todo] include USB controller ? */
+ drq_iter = &dmad.ahb_drq_pool[2];
+ for (i = 2; i < DMAD_AHB_MAX_CHANNELS; ++i, ++drq_iter) {
+ if (!(drq_iter->state & DMAD_DRQ_STATE_READY))
+ break;
+ }
+ } else {
+ /* channel for other devices is free to allocate */
+ for (i = 0; i < DMAD_AHB_MAX_CHANNELS; ++i, ++drq_iter) {
+ if (!(drq_iter->state & DMAD_DRQ_STATE_READY))
+ break;
+ }
+ }
+
+ if (unlikely(i == DMAD_AHB_MAX_CHANNELS)) {
+ spin_unlock(&dmad.drq_pool_lock);
+ dmad_err("out of available channels (AHB DMAC)!\n");
+ return -ENOSPC;
+ }
+
+ dmad_dbg("allocated channel: %d (AHB DMAC)\n", i);
+
+ }
+#endif
+#ifdef CONFIG_PLATFORM_APBDMA
+ if (ch_req->controller == DMAD_DMAC_APB_CORE) {
+
+ drq_iter = dmad.apb_drq_pool;
+
+ for (i = 0; i < DMAD_APB_MAX_CHANNELS; ++i, ++drq_iter) {
+ if ((drq_iter->state & DMAD_DRQ_STATE_READY) == 0)
+ break;
+ }
+
+ if (unlikely(i == DMAD_APB_MAX_CHANNELS)) {
+ spin_unlock(&dmad.drq_pool_lock);
+ dmad_err("out of available channels (APB DMAC)!\n");
+ return -ENOSPC;
+ }
+
+ dmad_dbg("allocated channel: %d (APB DMAC)\n", i);
+ }
+#endif
+ if (drq_iter == NULL) {
+ spin_unlock(&dmad.drq_pool_lock);
+ printk(KERN_ERR "%s() invalid argument!\n", __func__);
+ return -EFAULT;
+ }
+
+ spin_unlock(&dmad.drq_pool_lock);
+ memset(drq_iter, 0, sizeof(dmad_drq));
+
+ /* Initialize DMA channel's DRB pool as list of free DRBs */
+ drq_iter->drb_pool =
+ kmalloc(DMAD_DRB_POOL_SIZE * sizeof(dmad_drb), GFP_ATOMIC);
+
+ if (drq_iter->drb_pool == NULL) {
+ printk(KERN_ERR "%s() failed to allocate drb pool!\n",
+ __func__);
+ return -ENOMEM;
+ }
+
+ /* Allocate the DMA channel */
+ drq_iter->state = DMAD_DRQ_STATE_READY;
+ drq_iter->flags = ch_req->flags;
+
+ /* Initialize synchronization object for DMA queue access control */
+ spin_lock_init(&drq_iter->drb_pool_lock);
+
+ /* Initialize synchronization object for free drb notification */
+ init_completion(&drq_iter->drb_alloc_sync);
+
+ /* Record the channel number in client's struct */
+ ch_req->channel = i;
+
+ /* Record the channel's queue handle in client's struct */
+ ch_req->drq = drq_iter;
+
+#ifdef CONFIG_PLATFORM_AHBDMA
+ if (ch_req->controller == DMAD_DMAC_AHB_CORE) {
+ drq_iter->channel_base = (addr_t) DMAC_BASE_CH(i);
+ drq_iter->enable_port =
+ (addr_t) drq_iter->channel_base + DMAC_CSR_OFFSET;
+ drq_iter->src_port =
+ (addr_t) drq_iter->channel_base + DMAC_SRC_ADDR_OFFSET;
+ drq_iter->dst_port =
+ (addr_t) drq_iter->channel_base + DMAC_DST_ADDR_OFFSET;
+ drq_iter->cyc_port =
+ (addr_t) drq_iter->channel_base + DMAC_SIZE_OFFSET;
+ }
+#endif
+#ifdef CONFIG_PLATFORM_APBDMA
+ if (ch_req->controller == DMAD_DMAC_APB_CORE) {
+ drq_iter->channel_base = (addr_t) APBBR_DMA_BASE_CH(i);
+ drq_iter->enable_port =
+ (addr_t) drq_iter->channel_base + APBBR_DMA_CMD_OFFSET;
+ drq_iter->src_port =
+ (addr_t) drq_iter->channel_base + APBBR_DMA_SAD_OFFSET;
+ drq_iter->dst_port =
+ (addr_t) drq_iter->channel_base + APBBR_DMA_DAD_OFFSET;
+ drq_iter->cyc_port =
+ (addr_t) drq_iter->channel_base + APBBR_DMA_CYC_OFFSET;
+ }
+#endif
+ /* drb-0 is an invalid node - for node validation */
+ drb_iter = &drq_iter->drb_pool[0];
+ drb_iter->prev = 0;
+ drb_iter->next = 0;
+ drb_iter->node = 0;
+ ++drb_iter;
+
+ /* init other drbs - link in order */
+ for (i = 1; i < DMAD_DRB_POOL_SIZE; ++i, ++drb_iter) {
+ drb_iter->prev = i - 1;
+ drb_iter->next = i + 1;
+ drb_iter->node = i;
+ }
+ drq_iter->drb_pool[DMAD_DRB_POOL_SIZE - 1].next = 0;
+
+ /* Initialize channel's DRB free-list, ready-list, and submitted-list */
+ drq_iter->fre_head = 1;
+ drq_iter->fre_tail = DMAD_DRB_POOL_SIZE - 1;
+ drq_iter->rdy_head = drq_iter->rdy_tail = 0;
+ drq_iter->sbt_head = drq_iter->sbt_tail = 0;
+
+ /* initialize ring buffer mode resources */
+ if (ch_req->flags & DMAD_FLAGS_RING_MODE) {
+
+ int remnant = (int)ch_req->ring_size -
+ (int)ch_req->periods * (int)ch_req->period_size;
+ if (remnant == 0) {
+ drq_iter->periods = ch_req->periods;
+ } else if (remnant > 0) {
+ drq_iter->periods = ch_req->periods; // + 1;
+ } else {
+ dmad_err("%s() Error - buffer_size < "
+ "periods * period_size!\n", __func__);
+ err = -EFAULT;
+ goto _err_exit;
+ }
+
+ drq_iter->ring_size = ch_req->ring_size;
+ drq_iter->period_size = ch_req->period_size;
+ drq_iter->remnant_size = (dma_addr_t) remnant;
+
+ drq_iter->ring_base = (dma_addr_t) ch_req->ring_base;
+ drq_iter->dev_addr = (dma_addr_t) ch_req->dev_addr;
+
+#ifdef CONFIG_PLATFORM_AHBDMA
+ if (ch_req->controller == DMAD_DMAC_AHB_CORE) {
+ if ((ch_req->ahb_req.ring_ctrl == DMAC_CSR_AD_DEC) ||
+ (ch_req->ahb_req.dev_ctrl == DMAC_CSR_AD_DEC)) {
+ dmad_err("%s() Error - decremental"
+ " addressing DMA is not supported in"
+ " ring mode currently!\n", __func__);
+ err = -EFAULT;
+ goto _err_exit;
+ }
+
+ if (ch_req->ahb_req.ring_ctrl == DMAC_CSR_AD_FIX) {
+ dmad_err("%s() Error - ring address control is "
+ "fixed in ring DMA mode!\n", __func__);
+ err = -EFAULT;
+ goto _err_exit;
+ }
+
+ drq_iter->period_bytes =
+ DMAC_CYCLE_TO_BYTES(ch_req->period_size,
+ ch_req->ahb_req.ring_width);
+
+ /* 0 - addr0 to addr1; 1 - addr1 to addr0 */
+ if (ch_req->ahb_req.tx_dir == 0)
+ drq_iter->ring_port =
+ (addr_t) drq_iter->src_port;
+ else
+ drq_iter->ring_port =
+ (addr_t) drq_iter->dst_port;
+
+ }
+#endif
+#ifdef CONFIG_PLATFORM_APBDMA
+ if (ch_req->controller == DMAD_DMAC_APB_CORE) {
+
+ if ((ch_req->apb_req.ring_ctrl >= APBBR_ADDRINC_D1) ||
+ (ch_req->apb_req.dev_ctrl >= APBBR_ADDRINC_D1)) {
+ dmad_err("%s() Error - decremental"
+ " addressing DMA is not supported in"
+ " ring mode currently!\n", __func__);
+ err = -EFAULT;
+ goto _err_exit;
+ }
+
+ if (ch_req->apb_req.ring_ctrl == APBBR_ADDRINC_FIXED) {
+ dmad_err("%s() Error - ring address control is "
+ "fixed in ring DMA mode!\n", __func__);
+ err = -EFAULT;
+ goto _err_exit;
+ }
+
+ drq_iter->period_bytes =
+ APBBR_DMA_CYCLE_TO_BYTES(ch_req->period_size,
+ ch_req->apb_req.
+ data_width);
+
+ /* 0 - addr0 to addr1; 1 - addr1 to addr0 */
+ if (ch_req->apb_req.tx_dir == 0)
+ drq_iter->ring_port =
+ (addr_t) drq_iter->src_port;
+ else
+ drq_iter->ring_port =
+ (addr_t) drq_iter->dst_port;
+ }
+#endif
+ dmad_dbg("%s() ring: base(0x%08x) port(0x%08x) periods(0x%08x)"
+ " period_size(0x%08x) period_bytes(0x%08x)"
+ " remnant_size(0x%08x)\n",
+ __func__, drq_iter->ring_base, drq_iter->ring_port,
+ drq_iter->periods, drq_iter->period_size,
+ drq_iter->period_bytes, drq_iter->remnant_size);
+ }
+
+ drq_iter->completion_cb = ch_req->completion_cb;
+ drq_iter->completion_data = ch_req->completion_data;
+
+ /* Initialize the channel && register isr */
+ err = dmad_channel_init(ch_req);
+
+_err_exit:
+
+ if (err != 0) {
+ spin_lock(&dmad.drq_pool_lock);
+
+ kfree(drq_iter->drb_pool);
+ memset(drq_iter, 0, sizeof(dmad_drq));
+
+ ch_req->channel = -1;
+ ch_req->drq = (void *)0;
+
+ spin_unlock(&dmad.drq_pool_lock);
+
+ dmad_err("Failed to initialize APB DMA! "
+ "Channel allocation aborted!\n");
+ }
+
+ return err;
+}
+
+EXPORT_SYMBOL_GPL(dmad_channel_alloc);
+
+/**
+ * dmad_channel_free - release a dma channel
+ * @ch_req : [in] Reference to the DMA request descriptor structure
+ * @return : 0 if success, non-zero if any error
+ *
+ * This function releases a DMA channel. The channel is available for future
+ * allocation after the invokation.
+ */
+int dmad_channel_free(dmad_chreq * ch_req)
+{
+ dmad_drq *drq;
+
+ dmad_dbg("%s()\n", __func__);
+
+ if (unlikely(ch_req == NULL)) {
+ dmad_err("null ch_req!\n");
+ return -EFAULT;
+ }
+
+ drq = (dmad_drq *) ch_req->drq;
+
+ if (unlikely(drq == NULL)) {
+ dmad_err("null ch_req->drq!\n");
+ return -EBADR;
+ }
+ if (unlikely((ch_req->channel < 0) ||
+ ((drq->state & DMAD_DRQ_STATE_READY) == 0))) {
+ dmad_err("try to free a free channel!\n");
+ return -EBADR;
+ }
+
+ /* Stop/abort channel I/O
+ * (forced to shutdown and should be protected against isr)
+ */
+ dmad_drain_requests(ch_req, 1);
+ dmad_channel_reset(ch_req);
+
+ dmad_dbg("freed channel: %d\n", ch_req->channel);
+
+ spin_lock(&dmad.drq_pool_lock);
+
+ kfree(drq->drb_pool);
+ memset(drq, 0, sizeof(dmad_drq));
+
+ ch_req->drq = 0;
+ ch_req->channel = (u32) - 1;
+
+ spin_unlock(&dmad.drq_pool_lock);
+
+ return 0;
+}
+
+EXPORT_SYMBOL_GPL(dmad_channel_free);
+
+/**
+ * dmad_channel_enable - enable/disable a dma channel
+ * @ch_req : [in] Reference to the DMA request descriptor structure
+ * @enable : [in] 1 to enable the channel, 0 to disable
+ * @return : 0 if success, non-zero if any error
+ *
+ * Enable or disable the given DMA channel.
+ */
+int dmad_channel_enable(const dmad_chreq * ch_req, u8 enable)
+{
+ dmad_drq *drq;
+ unsigned long lock_flags;
+
+ dmad_dbg("%s()\n", __func__);
+
+ if (unlikely(ch_req == NULL))
+ return -EFAULT;
+
+ drq = (dmad_drq *) ch_req->drq;
+
+ if (unlikely(drq == NULL))
+ return -EBADR;
+
+ spin_lock_irqsave(&drq->drb_pool_lock, lock_flags);
+
+ /* Enable/disable DMA channel */
+ if (enable)
+ dmad_enable_channel(drq);
+ else
+ dmad_disable_channel(drq);
+
+ spin_unlock_irqrestore(&drq->drb_pool_lock, lock_flags);
+
+ return 0;
+}
+
+EXPORT_SYMBOL_GPL(dmad_channel_enable);
+
+/**
+ * dmad_config_channel_dir - config dma channel transfer direction
+ * @ch_req : [in] Reference to the DMA request descriptor structure
+ * @dir : [in] DMAD_DRQ_DIR_A0_TO_A1 or DMAD_DRQ_DIR_A1_TO_A0
+ * @return : 0 if success, non-zero if any error
+ *
+ * Reconfigure the channel transfer direction. This function works only if
+ * the channel was allocated with the DMAD_FLAGS_BIDIRECTION flags. Note
+ * that bi-direction mode and ring mode are mutual-exclusive from user's
+ * perspective.
+ */
+int dmad_config_channel_dir(dmad_chreq * ch_req, u8 dir)
+{
+ dmad_drq *drq;
+ addr_t channel_cmds[2];
+ unsigned long lock_flags;
+ u8 cur_dir;
+
+ if (unlikely(ch_req == NULL))
+ return -EFAULT;
+
+ drq = (dmad_drq *) ch_req->drq;
+
+ if (unlikely(drq == NULL))
+ return -EBADR;
+
+ if (unlikely(!(ch_req->flags & DMAD_FLAGS_BIDIRECTION))) {
+ dmad_err("%s() Channel is not configured as"
+ " bidirectional!\n", __func__);
+ return -EFAULT;
+ }
+
+ cur_dir = drq->flags & DMAD_DRQ_DIR_MASK;
+ if (dir == cur_dir) {
+ dmad_dbg("%s() cur_dir(%d) == dir(%d) skip reprogramming hw.\n",
+ __func__, cur_dir, dir);
+ return 0;
+ }
+
+ spin_lock_irqsave(&drq->drb_pool_lock, lock_flags);
+
+ if (unlikely((drq->sbt_head != 0) /*||dmad_is_channel_enabled(drq) */ )) {
+ spin_unlock_irqrestore(&drq->drb_pool_lock, lock_flags);
+ dmad_err("%s() Cannot change direction while the "
+ "channel has pending requests!\n", __func__);
+ return -EFAULT;
+ }
+#ifdef CONFIG_PLATFORM_AHBDMA
+ if (ch_req->controller == DMAD_DMAC_AHB_CORE) {
+
+ channel_cmds[0] =
+ inl((addr_t) drq->channel_base + DMAC_CSR_OFFSET);
+ channel_cmds[1] =
+ inl((addr_t) drq->channel_base + DMAC_CFG_OFFSET);
+
+ ch_req->ahb_req.tx_dir = dir;
+ dmad_ahb_config_dir(ch_req, channel_cmds);
+
+ outl(channel_cmds[1],
+ (addr_t) drq->channel_base + DMAC_CFG_OFFSET);
+ outl(channel_cmds[0],
+ (addr_t) drq->channel_base + DMAC_CSR_OFFSET);
+
+ }
+#endif
+#ifdef CONFIG_PLATFORM_APBDMA
+ if (ch_req->controller == DMAD_DMAC_APB_CORE) {
+
+ channel_cmds[0] =
+ inl((addr_t) drq->channel_base + APBBR_DMA_CMD_OFFSET);
+
+ ch_req->apb_req.tx_dir = dir;
+ dmad_apb_config_dir(ch_req, channel_cmds);
+
+ outl(channel_cmds[0],
+ (addr_t) drq->channel_base + APBBR_DMA_CMD_OFFSET);
+ }
+#endif
+ spin_unlock_irqrestore(&drq->drb_pool_lock, lock_flags);
+
+ return 0;
+}
+
+EXPORT_SYMBOL_GPL(dmad_config_channel_dir);
+
+/**
+ * dmad_max_size_per_drb - return maximum transfer size per drb
+ * @ch_req : [in] Reference to the DMA request descriptor structure
+ * @return : The maximum transfer size per drb, in bytes.
+ *
+ * Calculate the maximum transfer size per drb according to the setting of
+ * data width during channel initialization.
+ *
+ * Return size is aligned to 4-byte boundary; this ensures the alignment
+ * requirement of dma starting address if the function was used in a loop to
+ * separate a large size dma transfer.
+ */
+u32 dmad_max_size_per_drb(dmad_chreq * ch_req)
+{
+ addr_t size = 0;
+ addr_t data_width = (addr_t) ((dmad_drq *) ch_req->drq)->data_width;
+
+#ifdef CONFIG_PLATFORM_AHBDMA
+ if (ch_req->controller == DMAD_DMAC_AHB_CORE) {
+ size = DMAC_CYCLE_TO_BYTES(DMAC_TOT_SIZE_MASK & ((addr_t) ~ 3),
+ data_width);
+ }
+#endif
+#ifdef CONFIG_PLATFORM_APBDMA
+ if (ch_req->controller == DMAD_DMAC_APB_CORE) {
+ size =
+ APBBR_DMA_CYCLE_TO_BYTES(APBBR_DMA_CYC_MASK &
+ ((addr_t) ~ 3), data_width);
+ }
+#endif
+ dmad_dbg("%s() - 0x%08x bytes\n", __func__, size);
+
+ return size;
+}
+
+EXPORT_SYMBOL_GPL(dmad_max_size_per_drb);
+
+/**
+ * dmad_bytes_to_cycles - calculate drb transfer size, in cycles
+ * @ch_req : [in] Reference to the DMA request descriptor structure
+ * @byte_size : [in] The DMA transfer size to be converted, in bytes
+ * @return : The drb transfer size, in cycles.
+ *
+ * Calculate the drb transfer cycle according to the setting of channel data
+ * width and burst setting.
+ *
+ * AHB DMA : unit is number of "data width".
+ * APB DMA : unit is number of "data width * burst size"
+ *
+ * APB Note: According to specification, decrement addressing seems to regard
+ * the burst size setting. For code efficiency,
+ * dmad_make_req_cycles() does not take care of this case and might
+ * produce wrong result.
+ */
+u32 dmad_bytes_to_cycles(dmad_chreq * ch_req, u32 byte_size)
+{
+ addr_t cycle = 0;
+ addr_t data_width = (addr_t) ((dmad_drq *) ch_req->drq)->data_width;
+
+#ifdef CONFIG_PLATFORM_AHBDMA
+ if (ch_req->controller == DMAD_DMAC_AHB_CORE) {
+ cycle = DMAC_BYTES_TO_CYCLE(byte_size, data_width);
+ }
+#endif
+#ifdef CONFIG_PLATFORM_APBDMA
+ if (ch_req->controller == DMAD_DMAC_APB_CORE) {
+ cycle = APBBR_DMA_BYTES_TO_CYCLE(byte_size, data_width);
+ if (ch_req->apb_req.burst_mode)
+ cycle = cycle >> 2;
+ }
+#endif
+
+ dmad_dbg("%s() - 0x%08x bytes --> 0x%08x cycles\n",
+ __func__, byte_size, cycle);
+
+ return cycle;
+}
+
+EXPORT_SYMBOL_GPL(dmad_bytes_to_cycles);
+
+/**
+ * dmad_alloc_drb_internal - allocate a dma-request-block of a dma channel
+ * @ch_req : [in] Reference to the DMA request descriptor structure
+ * @drb : [out] Reference to a drb pointer to receive the allocated drb
+ * @return : 0 if success, non-zero if any error
+ *
+ * Allocates a DRB (DMA request block) of the given DMA channel. DRB is a
+ * single dma request which will be pushed into the submission queue of the
+ * given DMA channel. This is a lightweight internal version of
+ * dmad_alloc_drb() majorly for use in ring mode. Critical access to the
+ * drb pool should be protected before entering this function.
+ */
+static inline int dmad_alloc_drb_internal(dmad_drq * drq, dmad_drb ** drb)
+{
+ /* Initialize drb ptr in case of fail allocation */
+ *drb = NULL;
+
+ if (unlikely(drq->fre_head == 0)) {
+ return -EAGAIN;
+ }
+
+ dmad_detach_head(drq->drb_pool, &drq->fre_head, &drq->fre_tail, drb);
+
+ dmad_attach_tail(drq->drb_pool,
+ &drq->rdy_head, &drq->rdy_tail, (*drb)->node);
+
+ (*drb)->state = DMAD_DRB_STATE_READY;
+ (*drb)->sync = 0;
+
+ dmad_dbg("%s() drb(%d 0x%08x)\n", __func__, (*drb)->node, (u32) (*drb));
+
+ return 0;
+}
+
+/**
+ * dmad_alloc_drb - allocate a dma-request-block of a dma channel
+ * @ch_req : [in] Reference to the DMA request descriptor structure
+ * @drb : [out] Reference to a drb pointer to receive the allocated drb
+ * @return : 0 if success, non-zero if any error
+ *
+ * Allocates a DRB (DMA request block) of the given DMA channel. DRB is a
+ * single dma request which will be pushed into the submission queue of the
+ * given DMA channel.
+ */
+int dmad_alloc_drb(dmad_chreq * ch_req, dmad_drb ** drb)
+{
+ dmad_drq *drq;
+ unsigned long lock_flags;
+
+ dmad_dbg("%s()\n", __func__);
+
+ if (unlikely(ch_req == NULL)) {
+ dmad_err("null ch_req!\n");
+ return -EFAULT;
+ }
+
+ drq = (dmad_drq *) ch_req->drq;
+
+ if (likely(drq == NULL)) {
+ dmad_err("null ch_req->drq!\n");
+ return -EBADR;
+ }
+
+ spin_lock_irqsave(&drq->drb_pool_lock, lock_flags);
+
+ /* Initialize drb ptr in case of fail allocation */
+ *drb = NULL;
+
+ if (unlikely(drq->fre_head == 0)) {
+
+ drq->state &= (u32) ~ DMAD_DRQ_STATE_ABORT;
+
+ spin_unlock_irqrestore(&drq->drb_pool_lock, lock_flags);
+
+_wait_for_free_drbs:
+
+ /* Wait for free urbs */
+ if (drq->flags & DMAD_FLAGS_SLEEP_BLOCK) {
+
+ int timeout =
+ wait_for_completion_interruptible_timeout(&drq->
+ drb_alloc_sync,
+ msecs_to_jiffies
+ (6000));
+
+ /* reset sync object */
+ INIT_COMPLETION(drq->drb_alloc_sync);
+
+ if (timeout < 0) {
+ dmad_err("%s() wait for"
+ " completion error! (%d)\n",
+ __func__, timeout);
+ return timeout;
+ }
+
+ } else if (drq->flags & DMAD_FLAGS_SPIN_BLOCK) {
+
+ u32 timeout = 0x00ffffff;
+
+ while ((drq->fre_head == 0) && (--timeout != 0)) {
+ }
+ if (timeout == 0) {
+ dmad_err("%s() polling wait for "
+ "completion timeout!\n", __func__);
+ return -EAGAIN;
+ }
+
+ } else {
+ return -EAGAIN;
+ }
+
+ spin_lock_irqsave(&drq->drb_pool_lock, lock_flags);
+
+ /* check whether all the requests of the channel has been
+ * abandoned or not */
+ if (unlikely(drq->state & DMAD_DRQ_STATE_ABORT)) {
+ dmad_dbg("%s() drb-allocation aborted due"
+ " to cancel-request ...\n", __func__);
+ drq->state &= (u32) ~ DMAD_DRQ_STATE_ABORT;
+ spin_unlock_irqrestore(&drq->drb_pool_lock, lock_flags);
+ return -ECANCELED;
+ }
+
+ /* check again to avoid non-atomic operation between above
+ * two calls */
+ if (unlikely(drq->fre_head == 0)) {
+ dmad_dbg("%s() lost free drbs ... "
+ "continue waiting ...\n", __func__);
+ spin_unlock_irqrestore(&drq->drb_pool_lock, lock_flags);
+ goto _wait_for_free_drbs;
+ }
+ }
+
+ dmad_detach_head(drq->drb_pool, &drq->fre_head, &drq->fre_tail, drb);
+
+ dmad_attach_tail(drq->drb_pool,
+ &drq->rdy_head, &drq->rdy_tail, (*drb)->node);
+
+ (*drb)->state = DMAD_DRB_STATE_READY;
+ (*drb)->sync = 0;
+
+ dmad_dbg("%s() drb(%d 0x%08x)\n", __func__, (*drb)->node, (u32) (*drb));
+
+ drq->state &= (u32) ~ DMAD_DRQ_STATE_ABORT;
+
+ spin_unlock_irqrestore(&drq->drb_pool_lock, lock_flags);
+
+ return 0;
+}
+
+EXPORT_SYMBOL_GPL(dmad_alloc_drb);
+
+/**
+ * dmad_free_drb - free a dma-request-block of a dma channel
+ * @ch_req : [in] Reference to the DMA request descriptor structure
+ * @drb : [in] Reference to a drb to be freed
+ * @return : 0 if success, non-zero if any error
+ *
+ * Frees a DRB (DMA request block) of the given DMA channel. DRB is a
+ * single dma request which will be pushed into the submission queue of the
+ * given DMA channel.
+ */
+int dmad_free_drb(dmad_chreq * ch_req, dmad_drb * drb)
+{
+ dmad_drq *drq;
+ unsigned long lock_flags;
+
+ dmad_dbg("%s()\n", __func__);
+
+ if (unlikely(ch_req == NULL)) {
+ dmad_err("null ch_req!\n");
+ return -EFAULT;
+ }
+
+ drq = (dmad_drq *) ch_req->drq;
+
+ if (unlikely(drq == NULL)) {
+ dmad_err("null ch_req->drq!\n");
+ return -EBADR;
+ }
+
+ spin_lock_irqsave(&drq->drb_pool_lock, lock_flags);
+
+ /****************************************************
+ * Following code requires _safe_exit return path
+ */
+
+ if (unlikely((drq->rdy_head == 0) || (drb->node == 0) ||
+ (drb->state != DMAD_DRB_STATE_READY) ||
+ (drb->node >= DMAD_DRB_POOL_SIZE))) {
+ dmad_err("Ready-queue is empty or invalid node!\n");
+
+ spin_unlock_irqrestore(&drq->drb_pool_lock, lock_flags);
+ return -EBADR;
+ }
+
+ dmad_detach_node(drq->drb_pool,
+ &drq->rdy_head, &drq->rdy_tail, drb->node);
+ dmad_attach_tail(drq->drb_pool,
+ &drq->fre_head, &drq->fre_tail, drb->node);
+
+ drb->state = DMAD_DRB_STATE_FREE;
+ drb->sync = 0;
+
+ spin_unlock_irqrestore(&drq->drb_pool_lock, lock_flags);
+
+ return 0;
+}
+
+EXPORT_SYMBOL_GPL(dmad_free_drb);
+
+/**
+ * dmad_submit_request_internal - submit a dma-request-block to the dma channel
+ * @ch_req : [in] Reference to the DMA request descriptor structure
+ * @drb : [in] Reference to a drb to be submitted
+ * @keep_fired : [in] non-zero to kickoff dma even the channel has stopped due
+ * to finishing its previous request
+ * @return : 0 if success, non-zero if any error
+ *
+ * Submit a DRB (DMA request block) of the given DMA channel to submission
+ * queue. DRB is a single dma request which will be pushed into the
+ * submission queue of the given DMA channel. This is a lightweight internal
+ * version of dmad_alloc_drb() majorly for use in ring mode. Critical access to
+ * the drb pool should be protected before entering this function.
+ */
+static inline int dmad_submit_request_internal(dmad_drq * drq, dmad_drb * drb)
+{
+ if (drb->state == DMAD_DRB_STATE_READY) {
+ /* Detach user node from ready list */
+ dmad_detach_node(drq->drb_pool,
+ &drq->rdy_head, &drq->rdy_tail, drb->node);
+
+ dmad_attach_tail(drq->drb_pool,
+ &drq->sbt_head, &drq->sbt_tail, drb->node);
+
+ drb->state = DMAD_DRB_STATE_SUBMITTED;
+
+ dmad_dbg("%s() submit drb(%d 0x%08x) addr0(0x%08x) "
+ "addr1(0x%08x) size(0x%08x) state(%d)\n", __func__,
+ drb->node, (u32) drb, drb->src_addr, drb->dst_addr,
+ drb->req_cycle, drb->state);
+ } else {
+ dmad_dbg("%s() skip drb(%d 0x%08x) addr0(0x%08x) addr1(0x%08x)"
+ " size(0x%08x) state(%d)\n", __func__,
+ drb->node, (u32) drb, drb->src_addr, drb->dst_addr,
+ drb->req_cycle, drb->state);
+ }
+
+ return 0;
+}
+
+/**
+ * dmad_submit_request - submit a dma-request-block to the dma channel
+ * @ch_req : [in] Reference to the DMA request descriptor structure
+ * @drb : [in] Reference to a drb to be submitted
+ * @keep_fired : [in] non-zero to kickoff dma even the channel has stopped due
+ * to finishing its previous request
+ * @return : 0 if success, non-zero if any error
+ *
+ * Submit a DRB (DMA request block) of the given DMA channel to submission
+ * queue. DRB is a single dma request which will be pushed into the
+ * submission queue of the given DMA channel.
+ */
+int dmad_submit_request(dmad_chreq * ch_req, dmad_drb * drb, u8 keep_fired)
+{
+ dmad_drq *drq;
+ unsigned long lock_flags;
+
+ dmad_dbg("%s()\n", __func__);
+
+ if (unlikely(ch_req == NULL)) {
+ dmad_err("null ch_req!\n");
+ return -EFAULT;
+ }
+
+ drq = (dmad_drq *) ch_req->drq;
+
+ if (unlikely(drq == NULL)) {
+ dmad_err("null ch_req->drq!\n");
+ return -EBADR;
+ }
+
+ spin_lock_irqsave(&drq->drb_pool_lock, lock_flags);
+
+ /******************************************************
+ * Following code require _safe_exit return path
+ */
+
+ if (unlikely((drq->rdy_head == 0) || (drb->node == 0) ||
+ (drb->node >= DMAD_DRB_POOL_SIZE))) {
+ spin_unlock_irqrestore(&drq->drb_pool_lock, lock_flags);
+ return -EBADR;
+ }
+
+ /* Detach user node from ready list */
+ dmad_detach_node(drq->drb_pool, &drq->rdy_head, &drq->rdy_tail,
+ drb->node);
+
+ /* Queue DRB to the end of the submitted list */
+ dmad_dbg("submit drb(%d 0x%08x) addr0(0x%08x) addr1(0x%08x) "
+ "size(0x%08x) sync(0x%08x) fire(%d)\n",
+ drb->node, (u32) drb, drb->src_addr, drb->dst_addr,
+ drb->req_cycle, (u32) drb->sync, keep_fired);
+
+ /* Check if submission is performed to an empty queue */
+ if (unlikely(keep_fired && (drq->sbt_head == 0))) {
+ /* DMA is not running, so kick off transmission */
+ dmad_dbg("kickoff dma engine.\n");
+
+ dmad_attach_tail(drq->drb_pool,
+ &drq->sbt_head, &drq->sbt_tail, drb->node);
+
+ /* Source and destination address */
+ if (drq->flags & DMAD_DRQ_DIR_A1_TO_A0) {
+ outl(drb->addr1, (addr_t) drq->src_port);
+ outl(drb->addr0, (addr_t) drq->dst_port);
+ } else {
+ outl(drb->addr0, (addr_t) drq->src_port);
+ outl(drb->addr1, (addr_t) drq->dst_port);
+ }
+
+ /* Transfer size (in units of source width) */
+ outl(drb->req_cycle, (addr_t) drq->cyc_port);
+
+ /* Enable DMA channel (Kick off transmission when client
+ * enable it's transfer state) */
+ dmad_enable_channel(drq);
+
+ drb->state = DMAD_DRB_STATE_EXECUTED;
+
+ } else {
+ /* DMA is already running, so only queue DRB to the end of the
+ * list */
+ dmad_attach_tail(drq->drb_pool,
+ &drq->sbt_head, &drq->sbt_tail, drb->node);
+ drb->state = DMAD_DRB_STATE_SUBMITTED;
+ }
+
+ spin_unlock_irqrestore(&drq->drb_pool_lock, lock_flags);
+
+ return 0;
+}
+
+EXPORT_SYMBOL_GPL(dmad_submit_request);
+
+/**
+ * dmad_withdraw_request - cancel a submitted dma-request-block
+ * @ch_req : [in] Reference to the DMA request descriptor structure
+ * @drb : [in] Reference to a drb to be submitted
+ * @keep_fired : [in] non-zero to kickoff dma even the channel has stopped due
+ * to finishing its previous request
+ * @return : 0 if success, non-zero if any error
+ *
+ * Cancel a submitted DRB (DMA request block) of the given DMA channel in its
+ * submission queue. DRB is a single dma request which will be pushed into the
+ * submission queue of the given DMA channel. Cancellation fails if the DRB has
+ * already been kicked off.
+ */
+int dmad_withdraw_request(dmad_chreq * ch_req, dmad_drb * drb)
+{
+ dmad_drq *drq = 0;
+ unsigned long lock_flags;
+
+ dmad_dbg("%s()\n", __func__);
+
+ if (unlikely(ch_req == NULL)) {
+ dmad_err("null ch_req!\n");
+ return -EFAULT;
+ }
+
+ drq = (dmad_drq *) ch_req->drq;
+
+ if (unlikely(drq == NULL)) {
+ dmad_err("null ch_req->drq!\n");
+ return -EBADR;
+ }
+
+ if (unlikely(drq->sbt_head == 0))
+ return -EBADR;
+
+ if (unlikely((drb->node == 0) || (drb->node >= DMAD_DRB_POOL_SIZE)))
+ return -EBADR;
+
+ spin_lock_irqsave(&drq->drb_pool_lock, lock_flags);
+
+ if (unlikely((drq->sbt_head == 0) || (drb->node == 0) ||
+ (drb->state != DMAD_DRB_STATE_SUBMITTED) ||
+ (drb->node >= DMAD_DRB_POOL_SIZE))) {
+ dmad_err("Submitted-queue is empty or invalid node!\n");
+
+ spin_unlock_irqrestore(&drq->drb_pool_lock, lock_flags);
+ return -EBADR;
+ }
+
+ dmad_dbg("cancel drb(%d 0x%08x) addr0(0x%08x) addr1(0x%08x) "
+ "size(0x%08x) state(%d)\n",
+ drb->node, (u32) drb, drb->src_addr, drb->dst_addr,
+ drb->req_cycle, drb->state);
+
+ if (unlikely(drb->state == DMAD_DRB_STATE_EXECUTED)) {
+ dmad_dbg("Already running drb cannot be stopped currently!\n");
+
+ spin_unlock_irqrestore(&drq->drb_pool_lock, lock_flags);
+ return 0;/*-EBADR; */
+ }
+
+ dmad_detach_node(drq->drb_pool,
+ &drq->rdy_head, &drq->rdy_tail, drb->node);
+ dmad_attach_tail(drq->drb_pool,
+ &drq->fre_head, &drq->fre_tail, drb->node);
+
+ drb->state = DMAD_DRB_STATE_FREE;
+
+ if (drb->sync)
+ complete_all(drb->sync);
+ drb->sync = 0;
+
+ spin_unlock_irqrestore(&drq->drb_pool_lock, lock_flags);
+
+ return 0;
+}
+
+EXPORT_SYMBOL_GPL(dmad_withdraw_request);
+
+/**
+ * dmad_kickoff_requests_internal - kickoff hw DMA transmission
+ * @ch_req : [in] Reference to the DMA request descriptor structure
+ * @return : 0 if success, non-zero if any error
+ *
+ * Kickoff hw DMA transmission of the given DMA channel. This function is
+ * valid for both ring & non-ring mode. This is a lightweight internal version
+ * of dmad_kickoff_requests() majorly for use in ring mode. Critical access to
+ * the drb pool should be protected before entering this function.
+ */
+static inline int dmad_kickoff_requests_internal(dmad_drq * drq)
+{
+ dmad_drb *drb;
+
+ dmad_get_head(drq->drb_pool, &drq->sbt_head, &drq->sbt_tail, &drb);
+
+ if (!drb) {
+ dmad_err("%s() null drb!\n", __func__);
+ return -EBADR;
+ }
+
+ dmad_dbg("%s() drb(%d 0x%08x) addr0(0x%08x) addr1(0x%08x) "
+ "size(0x%08x) state(%d)\n", __func__,
+ drb->node, (u32) drb, drb->src_addr, drb->dst_addr,
+ drb->req_cycle, drb->state);
+
+ if (drb->state == DMAD_DRB_STATE_SUBMITTED) {
+ /* Transfer size (in units of source width) */
+ outl(drb->req_cycle, (addr_t) drq->cyc_port);
+
+ /* Source and destination address */
+ if (drq->flags & DMAD_DRQ_DIR_A1_TO_A0) {
+ outl(drb->addr1, (addr_t) drq->src_port);
+ outl(drb->addr0, (addr_t) drq->dst_port);
+ } else {
+ outl(drb->addr0, (addr_t) drq->src_port);
+ outl(drb->addr1, (addr_t) drq->dst_port);
+ }
+
+ drb->state = DMAD_DRB_STATE_EXECUTED;
+ }
+
+ /* Enable DMA channel */
+ if (!dmad_is_channel_enabled(drq)) {
+ dmad_enable_channel(drq);
+ }
+
+ return 0;
+}
+
+/**
+ * dmad_kickoff_requests - kickoff hw DMA transmission of the given DMA channel
+ * @ch_req : [in] Reference to the DMA request descriptor structure
+ * @return : 0 if success, non-zero if any error
+ *
+ * Kickoff hw DMA transmission of the given DMA channel. This function is
+ * valid for both ring & non-ring mode.
+ */
+int dmad_kickoff_requests(dmad_chreq * ch_req)
+{
+ dmad_drq *drq = 0;
+ dmad_drb *drb = 0;
+ unsigned long lock_flags;
+ dma_addr_t req_cycle;
+
+ dmad_dbg("%s()\n", __func__);
+
+ if (unlikely(ch_req == NULL)) {
+ dmad_err("null ch_req!\n");
+ return -EFAULT;
+ }
+
+ drq = (dmad_drq *) ch_req->drq;
+
+ if (unlikely(drq == NULL)) {
+ dmad_err("null ch_req->drq!\n");
+ return -EBADR;
+ }
+
+ spin_lock_irqsave(&drq->drb_pool_lock, lock_flags);
+
+ dmad_get_head(drq->drb_pool, &drq->sbt_head, &drq->sbt_tail, &drb);
+
+ dmad_dbg("drq(0x%08x) channel_base(0x%08x)\n",
+ (u32) drq, drq->channel_base);
+ dmad_dbg("kick off drb(%d 0x%08x) addr0(0x%08x) addr1(0x%08x) "
+ "size(0x%08x) state(%d) a1_to_a0(%d)\n",
+ (u32) drb->node, (u32) drb, drb->addr0, drb->addr1,
+ drb->req_cycle, drb->state,
+ drq->flags & DMAD_DRQ_DIR_A1_TO_A0);
+
+ /* do nothing if no drbs are in the submission queue */
+ if (unlikely((drb == 0) || (drb->state != DMAD_DRB_STATE_SUBMITTED))) {
+ dmad_dbg("%s() invalid drb(%d 0x%08x) or drb-state(%d)!\n",
+ __func__,
+ drb->node, (u32) drb, drb ? drb->state : 0xffffffff);
+ spin_unlock_irqrestore(&drq->drb_pool_lock, lock_flags);
+ return 0;
+ }
+
+ req_cycle = drb->req_cycle;
+
+ if (unlikely(req_cycle == 0)) {
+ dmad_dbg("%s() zero transfer size!\n", __func__);
+ goto _safe_exit;
+ }
+
+ /* Transfer size (in units of source width) */
+ outl(req_cycle, (addr_t) drq->cyc_port);
+
+ /* Source and destination address */
+ if (drq->flags & DMAD_DRQ_DIR_A1_TO_A0) {
+ outl(drb->addr1, (addr_t) drq->src_port);
+ outl(drb->addr0, (addr_t) drq->dst_port);
+ } else {
+ outl(drb->addr0, (addr_t) drq->src_port);
+ outl(drb->addr1, (addr_t) drq->dst_port);
+ }
+
+ drb->state = DMAD_DRB_STATE_EXECUTED;
+
+ /* Enable DMA channel */
+ dmad_enable_channel(drq);
+
+_safe_exit:
+ spin_unlock_irqrestore(&drq->drb_pool_lock, lock_flags);
+
+ return 0;
+}
+
+EXPORT_SYMBOL_GPL(dmad_kickoff_requests);
+
+/**
+ * dmad_probe_hw_ptr_src - probe DMA source hw-address of the given channel
+ * @ch_req : [in] Reference to the DMA request descriptor structure
+ * @return : physical address of current HW source pointer
+ *
+ * Probe DMA source hw-address of the given channel.
+ */
+dma_addr_t dmad_probe_hw_ptr_src(dmad_chreq * ch_req)
+{
+ return (dma_addr_t) inl(((dmad_drq *) ch_req->drq)->src_port);
+}
+
+EXPORT_SYMBOL_GPL(dmad_probe_hw_ptr_src);
+
+/**
+ * dmad_probe_hw_ptr_dst - probe DMA destination hw-address of the given channel
+ * @ch_req : [in] Reference to the DMA request descriptor structure
+ * @return : physical address of current HW destination pointer
+ *
+ * Probe DMA destination hw-address of the given channel.
+ */
+dma_addr_t dmad_probe_hw_ptr_dst(dmad_chreq * ch_req)
+{
+ return (dma_addr_t) inl(((dmad_drq *) ch_req->drq)->dst_port);
+}
+
+EXPORT_SYMBOL_GPL(dmad_probe_hw_ptr_dst);
+
+/**
+ * dmad_update_ring - update DMA ring buffer base && size of the given channel
+ * @ch_req : [in] Reference to the DMA request descriptor structure
+ * @size : [in] The new ring buffer size, in unit of data width (cycles)
+ * @return : 0 if success, non-zero if any error
+ *
+ * Update DMA ring buffer size of the given channel. This function is valid
+ * only if the channel is initialized as ring buffer mode.
+ */
+int dmad_update_ring(dmad_chreq * ch_req)
+{
+ unsigned long lock_flags;
+ dmad_drq *drq = (dmad_drq *) ch_req->drq;
+ int remnant;
+
+ if (unlikely(dmad_is_channel_enabled(drq))) {
+ dmad_err("%s() Error - dma channel should be "
+ "disabled before updating ring size!\n", __func__);
+ return -EFAULT;
+ }
+
+ spin_lock_irqsave(&drq->drb_pool_lock, lock_flags);
+
+ /* todo: range checking */
+
+ remnant = (int)ch_req->ring_size -
+ (int)ch_req->periods * (int)ch_req->period_size;
+ if (remnant == 0) {
+ drq->periods = ch_req->periods;
+ } else if (remnant > 0) {
+ drq->periods = ch_req->periods; // + 1;
+ } else {
+ dmad_err("%s() Error - buffer_size < "
+ "periods * period_size!\n", __func__);
+ spin_unlock_irqrestore(&drq->drb_pool_lock, lock_flags);
+ return -EFAULT;
+ }
+
+ drq->ring_base = ch_req->ring_base;
+ drq->ring_size = ch_req->ring_size;
+ drq->period_size = ch_req->period_size;
+ drq->remnant_size = (dma_addr_t) remnant;
+
+#ifdef CONFIG_PLATFORM_AHBDMA
+ if (ch_req->controller == DMAD_DMAC_AHB_CORE) {
+ drq->period_bytes =
+ DMAC_CYCLE_TO_BYTES(drq->period_size, drq->data_width);
+ }
+#endif
+#ifdef CONFIG_PLATFORM_APBDMA
+ if (ch_req->controller == DMAD_DMAC_APB_CORE) {
+ drq->period_bytes =
+ APBBR_DMA_CYCLE_TO_BYTES(drq->period_size, drq->data_width);
+ }
+#endif
+ spin_unlock_irqrestore(&drq->drb_pool_lock, lock_flags);
+
+ dmad_dbg("%s() ring: base(0x%08x) port(0x%08x) periods(0x%08x) "
+ "period_size(0x%08x) period_bytes(0x%08x) "
+ "remnant_size(0x%08x)\n",
+ __func__, drq->ring_base, drq->ring_port,
+ drq->periods, drq->period_size, drq->period_bytes,
+ drq->remnant_size);
+
+ return 0;
+}
+
+EXPORT_SYMBOL_GPL(dmad_update_ring);
+
+/**
+ * dmad_update_ring_sw_ptr - update DMA ring buffer sw-pointer
+ * @ch_req : [in] Reference to the DMA request descriptor structure
+ * @sw_ptr : [in] The new sw-pointer for the hw-pointer to chase of
+ * @keep_fired : [in] non-zero to kickoff dma even the channel has stopped due
+ * to finishing its previous request
+ * @return : 0 if success, non-zero if any error
+ *
+ * Update DMA ring buffer sw-pointer of the given channel on the fly. This
+ * function is valid only if the channel is initialized as ring buffer mode.
+ * Uint of sw_ptr is in number of dma data width.
+ */
+int dmad_update_ring_sw_ptr(dmad_chreq * ch_req,
+ dma_addr_t sw_ptr, u8 keep_fired)
+{
+ dmad_drq *drq;
+ unsigned long lock_flags;
+ dma_addr_t hw_off = 0, ring_ptr;
+ dma_addr_t sw_p_off, ring_p_off, period_size, period_bytes;
+ dma_addr_t remnant_size;
+ int sw_p_idx, ring_p_idx, period, periods;
+ dmad_drb *drb = NULL;
+
+ /*if (ch_req == NULL) { */
+ /* dmad_dbg("%s() null ch_req!\n", __func__); */
+ /* return -EFAULT; */
+ /*} */
+
+ drq = (dmad_drq *) ch_req->drq;
+
+ /*if (drq == NULL) { */
+ /* dmad_dbg("%s() null ch_req->drq!\n", __func__); */
+ /* return -EBADR; */
+ /*} */
+
+ if (unlikely(sw_ptr > drq->ring_size)) {
+ dmad_err("%s() Invalid ring buffer sw-pointer "
+ "range (0x%08x)! ring_size(0x%08x)\n",
+ __func__, sw_ptr, drq->ring_size);
+ return -EBADR;
+ }
+
+ spin_lock_irqsave(&drq->drb_pool_lock, lock_flags);
+
+ periods = drq->periods;
+ period_size = drq->period_size;
+ period_bytes = drq->period_bytes;
+ remnant_size = drq->remnant_size;
+
+ ring_ptr = drq->sw_ptr;
+ ring_p_idx = drq->sw_p_idx;
+ ring_p_off = drq->sw_p_off;
+
+ sw_p_idx = (int)(sw_ptr / period_size);
+ sw_p_off = sw_ptr % period_size;
+
+ if (remnant_size && (sw_p_idx == periods)) {
+ --sw_p_idx;
+ sw_p_off += period_size;
+ }
+
+ dmad_dbg("%s() ring_ptr(0x%08x) ring_p_idx(0x%08x) "
+ "ring_p_off(0x%08x)\n",
+ __func__, ring_ptr, ring_p_idx, ring_p_off);
+ dmad_dbg("%s() sw_ptr(0x%08x) sw_p_idx(0x%08x) sw_p_off(0x%08x)\n",
+ __func__, sw_ptr, sw_p_idx, sw_p_off);
+
+ if (drq->ring_drb &&
+ (drq->ring_drb->state & (DMAD_DRB_STATE_READY |
+ DMAD_DRB_STATE_SUBMITTED |
+ DMAD_DRB_STATE_EXECUTED))) {
+ drb = drq->ring_drb;
+ } else {
+ /* alloc new drb if there is none yet at ring_ptr */
+ if (0 != dmad_alloc_drb_internal(drq, &drb)) {
+ dmad_err("%s() drb allocation failed!\n", __func__);
+ spin_unlock_irqrestore(&drq->drb_pool_lock, lock_flags);
+ return -ENOSPC;
+ }
+ drb->addr0 = ((dma_addr_t) ring_p_idx * period_bytes) +
+ drq->ring_base;
+ drb->addr1 = drq->dev_addr;
+ drb->req_cycle = 0; // redundent, though, no harm to performance
+
+ dmad_dbg("init_drb(%d 0x%08x) addr0(0x%08x) addr1(0x%08x) "
+ "size(0x%08x) state(%d)\n",
+ (u32) drb->node, (u32) drb, drb->src_addr,
+ drb->dst_addr, drb->req_cycle, drb->state);
+
+ drq->ring_drb = drb;
+ }
+
+ /* Following code-path has been optimized. The design flow is expanded
+ * below for reference.
+ *
+ * if (sw_ptr >= ring_ptr)
+ * if (sw_p_idx == ring_p_idx)
+ * ring_drb::req_cycle <- sw_p_off
+ * if (ring_drb::state == executed)
+ * hw_cycle <- sw_p_idx
+ * fi
+ * else
+ * ring_drb::req_cycle <- period_size
+ * if (ring_drb::state == executed)
+ * hw_cycle <- period_size
+ * fi
+ * for (i = ring_p_idx+1 ~ sw_p_idx-1)
+ * new_drb::ring_addr <- i * period_bytes + ring_base
+ * new_drb::req_cycle <- period_size
+ * rof
+ * sw_drb::ring_addr <- sw_p_idx * period_bytes + ring_base
+ * sw_drb::req_cycle <- sw_p_off
+ * else
+ * // sw_ptr < ring_ptr
+ * ring_drb::req_cycle <- period_size
+ * if (ring_drb::state == executed)
+ * hw_cycle <- period_size
+ * fi
+ * for (i = ring_p_idx+1 ~ idx_max)
+ * new_drb::ring_addr <- i * period_bytes + ring_base
+ * new_drb::req_cycle <- period_size
+ * rof
+ * for (i = 0 ~ sw_p_idx-1)
+ * new_drb::ring_addr <- i * period_bytes + ring_base
+ * new_drb::req_cycle <- period_size
+ * rof
+ * sw_drb::ring_addr <- sw_p_idx * period_bytes + ring_base
+ * sw_drb::req_cycle <- sw_p_off
+ * fi
+ */
+ if ((sw_ptr >= ring_ptr) && (sw_p_idx == ring_p_idx) && (sw_p_off != 0)) {
+
+ dmad_dbg("update ring drb\n");
+
+ /* update drb size at ring_ptr */
+ drb->req_cycle = sw_p_off;
+
+ dmad_dbg("ring_drb(%d 0x%08x) addr0(0x%08x) addr1(0x%08x) "
+ "size(0x%08x) state(%d)\n",
+ (u32) drb->node, (u32) drb, drb->addr0, drb->addr1,
+ drb->req_cycle, drb->state);
+
+ /* update hw dma size of this drb if it has been sent to the
+ * controller */
+ if (drb->state == DMAD_DRB_STATE_EXECUTED) {
+ dmad_disable_channel(drq);
+
+#ifdef CONFIG_PLATFORM_AHBDMA
+ if (ch_req->controller == DMAD_DMAC_AHB_CORE)
+ hw_off = DMAC_BYTES_TO_CYCLE((addr_t)
+ inl((addr_t) drq->
+ ring_port) -
+ (addr_t) drb->
+ addr0,
+ drq->data_width);
+#endif
+#ifdef CONFIG_PLATFORM_APBDMA
+ if (ch_req->controller == DMAD_DMAC_APB_CORE)
+ hw_off = APBBR_DMA_BYTES_TO_CYCLE((addr_t)
+ inl((addr_t)
+ drq->
+ ring_port)
+ -
+ (addr_t) drb->
+ addr0,
+ drq->
+ data_width);
+#endif
+ dmad_dbg("hw_off(0x%08x) sw_p_off(0x%08x)\n",
+ (u32) hw_off, (u32) sw_p_off);
+
+ if (sw_p_off < hw_off)
+ dmad_err("%s() underrun! sw_p_off(0x%08x) <"
+ " hw_off(0x%08x)\n", __func__,
+ (u32) sw_p_off, (u32) hw_off);
+ else
+ outl(sw_p_off - hw_off, drq->cyc_port);
+
+ dmad_enable_channel(drq);
+
+ } else {
+ dmad_submit_request_internal(drq, drb);
+ }
+
+ } else {
+
+ dmad_dbg("fulfill ring drb - sw_ptr(0x%08x) ring_ptr(0x%08x)\n",
+ (u32) sw_ptr, (u32) ring_ptr);
+
+ /* fulfill last drb at ring_ptr */
+ if (ring_p_idx == (periods - 1))
+ drb->req_cycle = period_size + remnant_size;
+ else
+ drb->req_cycle = period_size;
+
+ dmad_dbg("ring_drb(%d 0x%08x) addr0(0x%08x) addr1(0x%08x) "
+ "size(0x%08x) state(%d)\n",
+ (u32) drb->node, (u32) drb, drb->addr0, drb->addr1,
+ drb->req_cycle, drb->state);
+
+ if (drb->state == DMAD_DRB_STATE_EXECUTED) {
+ dmad_disable_channel(drq);
+
+#ifdef CONFIG_PLATFORM_AHBDMA
+ if (ch_req->controller == DMAD_DMAC_AHB_CORE)
+ hw_off = DMAC_BYTES_TO_CYCLE((addr_t)
+ inl((addr_t) drq->
+ ring_port) -
+ (addr_t) drb->
+ addr0,
+ drq->data_width);
+#endif
+#ifdef CONFIG_PLATFORM_APBDMA
+ if (ch_req->controller == DMAD_DMAC_APB_CORE)
+ hw_off = APBBR_DMA_BYTES_TO_CYCLE((addr_t)
+ inl((addr_t)
+ drq->
+ ring_port)
+ -
+ (addr_t) drb->
+ addr0,
+ drq->
+ data_width);
+#endif
+ dmad_dbg("hw_off(0x%08x) period_size(0x%08x)\n",
+ (u32) hw_off, (u32) period_size);
+
+ if (ring_p_idx == (periods - 1)) {
+ if (period_size < hw_off)
+ dmad_err("%s() illegal! "
+ "period_size(0x%08x) + "
+ "remnant_size(0x%08x) < "
+ "hw_off(0x%08x)\n", __func__,
+ (u32) period_size,
+ (u32) remnant_size,
+ (u32) hw_off);
+ else
+ outl(period_size + remnant_size -
+ hw_off, drq->cyc_port);
+ } else {
+ if (period_size < hw_off)
+ dmad_err("%s() illegal! "
+ "period_size(0x%08x) < "
+ "hw_off(0x%08x)\n", __func__,
+ (u32) period_size,
+ (u32) hw_off);
+ else
+ outl(period_size - hw_off,
+ drq->cyc_port);
+ }
+
+ dmad_enable_channel(drq);
+
+ } else {
+ dmad_submit_request_internal(drq, drb);
+ }
+
+ ++ring_p_idx;
+
+ /* adjust sw_ptr period index ahead by one ring cycle */
+ //if (sw_ptr < ring_ptr) {
+ if (sw_p_idx < ring_p_idx) {
+ sw_p_idx += periods;
+ }
+
+ /* allocate in-between (ring_ptr+1 to sw_ptr-1)
+ * full-cycle drbs */
+ for (period = ring_p_idx; period < sw_p_idx; ++period) {
+ if (0 != dmad_alloc_drb_internal(drq, &drb)) {
+ dmad_err("%s() drb allocation failed!\n",
+ __func__);
+ spin_unlock_irqrestore(&drq->drb_pool_lock,
+ lock_flags);
+ return -ENOSPC;
+ }
+
+ drb->addr0 = (dma_addr_t) (period % periods) *
+ period_bytes + drq->ring_base;
+ drb->addr1 = drq->dev_addr;
+
+ if (period == (periods - 1)) {
+ drb->req_cycle = period_size + remnant_size;
+ } else {
+ drb->req_cycle = period_size;
+ }
+
+ dmad_dbg("inbtw_drb(%d 0x%08x) addr0(0x%08x) "
+ "addr1(0x%08x) size(0x%08x) state(%d)\n",
+ (u32) drb->node, (u32) drb, drb->addr0,
+ drb->addr1, drb->req_cycle, drb->state);
+
+ dmad_submit_request_internal(drq, drb);
+ }
+
+ /* allocate drb right at sw_ptr */
+ if (0 != dmad_alloc_drb_internal(drq, &drb)) {
+ dmad_err("%s() drb allocation failed!\n", __func__);
+ spin_unlock_irqrestore(&drq->drb_pool_lock, lock_flags);
+ return -ENOSPC;
+ }
+ drb->addr0 = (dma_addr_t) (sw_p_idx % periods) *
+ period_bytes + drq->ring_base;
+ drb->addr1 = drq->dev_addr;
+ drb->req_cycle = sw_p_off;
+
+ dmad_dbg("swptr_drb(%d 0x%08x) addr0(0x%08x) addr1(0x%08x) "
+ "size(0x%08x) state(%d)\n",
+ (u32) drb->node, (u32) drb, drb->addr0, drb->addr1,
+ drb->req_cycle, drb->state);
+
+ drq->ring_drb = drb;
+
+ if (sw_p_off > 0)
+ dmad_submit_request_internal(drq, drb);
+ }
+
+ drq->sw_ptr = sw_ptr % drq->ring_size;
+ drq->sw_p_idx = sw_p_idx % periods;
+ drq->sw_p_off = sw_p_off;
+
+ if (likely(keep_fired)) {
+ dmad_kickoff_requests_internal(drq);
+ }
+
+ spin_unlock_irqrestore(&drq->drb_pool_lock, lock_flags);
+
+ return 0;
+}
+
+EXPORT_SYMBOL_GPL(dmad_update_ring_sw_ptr);
+
+/**
+ * dmad_probe_ring_hw_ptr - probe DMA ring buffer position of the given channel
+ * @ch_req : [in] Reference to the DMA request descriptor structure
+ * @return : Ring buffer position of current HW ring buffer pointer
+ *
+ * Probe DMA ring buffer position of the given channel. The position is
+ * relative to the ring buffer base. This function is valid only if the
+ * channel is initialized as ring buffer mode.
+ */
+dma_addr_t dmad_probe_ring_hw_ptr(dmad_chreq * ch_req)
+{
+ dmad_drq *drq = (dmad_drq *) ch_req->drq;
+ dma_addr_t cycles =
+ (dma_addr_t) inl(drq->ring_port) - (dma_addr_t) drq->ring_base;
+
+#ifdef CONFIG_PLATFORM_AHBDMA
+ if (ch_req->controller == DMAD_DMAC_AHB_CORE)
+ cycles = DMAC_BYTES_TO_CYCLE(cycles, drq->data_width);
+#endif
+#ifdef CONFIG_PLATFORM_APBDMA
+ if (ch_req->controller == DMAD_DMAC_APB_CORE)
+ cycles = APBBR_DMA_BYTES_TO_CYCLE(cycles, drq->data_width);
+#endif
+ return cycles;
+}
+
+EXPORT_SYMBOL_GPL(dmad_probe_ring_hw_ptr);
+
+/**
+ * dmad_channel_drain - cancel DMA transmission of the given DMA channel
+ * @controller : [in] One of the enum value of DMAD_DMAC_CORE
+ * @drq : [in] Reference to the DMA queue structure (dmad_drq)
+ * @shutdown : [in] Non-zero to force a immediate channel shutdown
+ * @return : 0 if success, non-zero if any error
+ *
+ * Stop the DMA transmission and cancel all submitted requests of the given
+ * DMA channel. This function drains a single channel and is the internal
+ * implementation of the interface routine dmad_drain_requests() and the
+ * module_exit function.
+ */
+static int dmad_channel_drain(u32 controller, dmad_drq * drq, u8 shutdown)
+{
+ dmad_drb *drb = 0;
+ unsigned long lock_flags;
+
+ if (unlikely(drq == NULL)) {
+ dmad_err("null ch_req->drq!\n");
+ return -EBADR;
+ }
+
+ spin_lock_irqsave(&drq->drb_pool_lock, lock_flags);
+
+ /* Stop DMA channel if forced to shutdown immediately */
+ if (shutdown) {
+ /* disable dma controller */
+ dmad_reset_channel(drq);
+
+ /* todo: more settings to stop DMA controller ?? */
+
+ /*if (drb->state == DMAD_DRB_STATE_EXECUTED) { */
+ /*} */
+ }
+
+ /* Detach DRBs in submit queue */
+ dmad_detach_head(drq->drb_pool, &drq->sbt_head, &drq->sbt_tail, &drb);
+
+ while (drb) {
+ dmad_dbg("cancel sbt drb(%d 0x%08x) addr0(0x%08x) "
+ "addr1(0x%08x) size(0x%08x) state(%d)\n",
+ drb->node, (u32) drb, drb->src_addr, drb->dst_addr,
+ drb->req_cycle, (u32) drb->state);
+
+ /* Mark DRB state as abort */
+ drb->state = DMAD_DRB_STATE_ABORT;
+
+ if (drb->sync)
+ complete_all(drb->sync);
+
+ dmad_attach_tail(drq->drb_pool, &drq->fre_head, &drq->fre_tail,
+ drb->node);
+
+ dmad_detach_head(drq->drb_pool, &drq->sbt_head, &drq->sbt_tail,
+ &drb);
+ }
+
+ /* Detach DRBs in ready queue */
+ dmad_detach_head(drq->drb_pool, &drq->rdy_head, &drq->rdy_tail, &drb);
+
+ while (drb) {
+ dmad_dbg("cancel rdy drb(%d 0x%08x) addr0(0x%08x) "
+ "addr1(0x%08x) size(0x%08x) state(%d)\n",
+ drb->node, (u32) drb, drb->src_addr, drb->dst_addr,
+ drb->req_cycle, (u32) drb->state);
+
+ /* Mark DRB state as abort */
+ drb->state = DMAD_DRB_STATE_ABORT;
+
+ dmad_attach_tail(drq->drb_pool, &drq->fre_head, &drq->fre_tail,
+ drb->node);
+
+ /* Detach next submitted DRB (DMA Request Block) from the
+ * DRQ (DMA Request Queue) */
+ dmad_detach_head(drq->drb_pool, &drq->rdy_head, &drq->rdy_tail,
+ &drb);
+ }
+
+ drq->state |= DMAD_DRQ_STATE_ABORT;
+
+ drq->ring_drb = NULL;
+ drq->sw_ptr = 0;
+ drq->sw_p_idx = 0;
+ drq->sw_p_off = 0;
+
+ spin_unlock_irqrestore(&drq->drb_pool_lock, lock_flags);
+
+ if ( /*(drq->fre_head == 0) && */ (drq->flags & DMAD_FLAGS_SLEEP_BLOCK)) {
+ complete_all(&drq->drb_alloc_sync);
+ }
+
+ return 0;
+}
+
+/**
+ * dmad_cancel_requests - cancel DMA transmission of the given DMA channel
+ * @ch_req : [in] Reference to the DMA request descriptor structure
+ * @shutdown : [in] Non-zero to force a immediate channel shutdown
+ * @return : 0 if success, non-zero if any error
+ *
+ * Stop the DMA transmission and cancel all submitted requests of the given
+ * DMA channel.
+ */
+int dmad_drain_requests(dmad_chreq * ch_req, u8 shutdown)
+{
+ dmad_dbg("%s()\n", __func__);
+
+ if (ch_req == NULL) {
+ dmad_err("null ch_req!\n");
+ return -EFAULT;
+ }
+
+ return dmad_channel_drain(ch_req->controller, ch_req->drq, shutdown);
+}
+
+EXPORT_SYMBOL_GPL(dmad_drain_requests);
+
+#ifdef CONFIG_PLATFORM_AHBDMA
+
+/**
+ * dmad_probe_irq_source - probe DMA channel who asserts the shared sw-irq line
+ * @return : The channel number which asserts the shared sw-irq line
+ *
+ * Probe DMA channel who asserts the shared sw-irq line.
+ */
+int dmad_probe_irq_source_ahb(void)
+{
+ int channel; /* interrupt channel number */
+
+ /* todo: spin_lock */
+
+ /* - Check DMA status register to get channel number */
+ for (channel = 0; channel < DMAD_AHB_MAX_CHANNELS; ++channel) {
+ if (getbl(channel, DMAC_INT_TC))
+ return channel;
+ }
+
+ /* Perform DMA error checking if no valid channel was found who
+ * assert the finish signal. */
+ for (channel = 0; channel < DMAD_AHB_MAX_CHANNELS; ++channel) {
+ if (getbl(channel, DMAC_INT_ERRABT))
+ return channel;
+ if (getbl(channel << DMAC_INT_ABT_SHIFT, DMAC_INT_ERRABT))
+ return channel;
+ }
+
+ /* todo: spin_unlock */
+
+ return -EFAULT;
+}
+
+EXPORT_SYMBOL_GPL(dmad_probe_irq_source_ahb);
+
+#endif /* CONFIG_PLATFORM_AHBDMA */
+
+#ifdef CONFIG_PLATFORM_APBDMA
+
+int dmad_probe_irq_source_apb(void)
+{
+ int channel; /* interrupt channel number */
+
+ /* todo: spin_lock */
+
+ /* Check DMA status register to get channel number */
+ for (channel = 0; channel < DMAD_APB_MAX_CHANNELS; ++channel) {
+ if (getbl(APBBR_DMA_FINTST_BIT, APBBR_DMA_BASE_CH(channel) +
+ APBBR_DMA_CMD_OFFSET))
+ return channel;
+ }
+
+ /* Perform DMA error checking if no valid channel was found who
+ * assert the finish signal. */
+ for (channel = 0; channel < DMAD_APB_MAX_CHANNELS; ++channel) {
+ if (getbl(APBBR_DMA_ERRINTST_BIT, APBBR_DMA_BASE_CH(channel) +
+ APBBR_DMA_CMD_OFFSET))
+ return channel;
+ }
+
+ /* todo: spin_unlock */
+
+ return -EFAULT;
+}
+
+EXPORT_SYMBOL_GPL(dmad_probe_irq_source_apb);
+
+#endif /* CONFIG_PLATFORM_APBDMA */
+
+/**
+ * dmad_module_init - dma module-init function
+ * @return : 0 if success, non-zero if any error
+ */
+int __init dmad_module_init(void)
+{
+ int err = 0;
+ dmad_dbg("%s() >>\n", __func__);
+
+ /* clear device struct since the module may be load/unload many times */
+ memset(&dmad, 0, sizeof(dmad));
+
+ dmad.drq_pool =
+ kmalloc((DMAD_AHB_MAX_CHANNELS +
+ DMAD_APB_MAX_CHANNELS) * sizeof(dmad_drq), GFP_KERNEL);
+ if (dmad.drq_pool == NULL) {
+ dmad_err("%s() failed to allocate drb pool!\n", __func__);
+ return -ENOMEM;
+ }
+
+ memset(dmad.drq_pool, 0,
+ (DMAD_AHB_MAX_CHANNELS + DMAD_APB_MAX_CHANNELS) *
+ sizeof(dmad_drq));
+
+ spin_lock_init(&dmad.drq_pool_lock);
+
+#ifdef CONFIG_PLATFORM_AHBDMA
+ dmad.ahb_drq_pool = dmad.drq_pool;
+ if (unlikely(!request_region(DMAC_BASE, SZ_1K, "AHB DMAC"))) {
+ dmad_err("Cannot reserve AHB DMAC I/O region\n");
+ err = -EBUSY;
+ }
+#endif
+
+#ifdef CONFIG_PLATFORM_APBDMA
+ dmad.apb_drq_pool = &dmad.drq_pool[DMAD_AHB_MAX_CHANNELS];
+ if (unlikely(!request_region(APBBR_BASE, SZ_1K, "APB DMAC"))) {
+ dmad_err("Cannot reserve APB DMAC I/O region\n");
+ err = -EBUSY;
+ }
+#endif
+
+ dmad_dbg("DMA module init result: (%d)\n", err);
+ dmad_dbg(" AHB channels: %d; APB channels %d; "
+ "DRBs per channel: %d\n",
+ DMAC_MAX_CHANNELS, APBBR_DMA_MAX_CHANNELS, DMAD_DRB_POOL_SIZE);
+
+ dmad_dbg("%s() return code (%d) <<\n", __func__, err);
+ return err;
+}
+
+/**
+ * dmad_module_init - dma module clean up function
+ */
+void __exit dmad_module_exit(void)
+{
+ dmad_drq *drq;
+ u32 channel;
+
+ dmad_dbg("%s() >>\n", __func__);
+
+ spin_lock(&dmad.drq_pool_lock);
+
+#ifdef CONFIG_PLATFORM_AHBDMA
+ /* cancel existing requests and unregister interrupt handler */
+ for (channel = 0; channel < DMAD_AHB_MAX_CHANNELS; ++channel) {
+
+ /* shutdown dma requests */
+ drq = (dmad_drq *) & dmad.ahb_drq_pool[channel];
+
+ if ((drq->state & DMAD_DRQ_STATE_READY) != 0)
+ dmad_channel_drain(DMAD_DMAC_AHB_CORE, drq, 1);
+
+ /* free registered irq handlers */
+ free_irq(ahb_irqs[channel], (void *)(channel + 1));
+ }
+#endif
+
+#ifdef CONFIG_PLATFORM_APBDMA
+ /* cancel existing requests and unregister interrupt handler */
+ for (channel = 0; channel < DMAD_APB_MAX_CHANNELS; ++channel) {
+
+ /* shutdown dma requests */
+ drq = (dmad_drq *) & dmad.apb_drq_pool[channel];
+
+ if ((drq->state & DMAD_DRQ_STATE_READY) != 0)
+ dmad_channel_drain(DMAD_DMAC_APB_CORE, drq, 1);
+
+ /* free registered irq handlers */
+ free_irq(apb_irqs[channel], (void *)(channel + 1));
+ }
+#endif
+ spin_unlock(&dmad.drq_pool_lock);
+
+ if (dmad.drq_pool)
+ kfree(dmad.drq_pool);
+ memset(&dmad, 0, sizeof(dmad));
+
+ /* release I/O space */
+#ifdef CONFIG_PLATFORM_AHBDMA
+ release_region(DMAC_BASE, SZ_1K);
+#endif /*CONFIG_PLATFORM_AHBDMA */
+
+#ifdef CONFIG_PLATFORM_APBDMA
+ release_region(APBBR_BASE, SZ_1K);
+#endif /* CONFIG_PLATFORM_APBDMA */
+
+ dmad_dbg("DMA module unloaded!\n");
+}
+
+#ifndef MODULE
+arch_initcall(dmad_module_init);
+#else
+module_init(dmad_module_init);
+module_exit(dmad_module_exit);
+#endif
+
+#endif /* CONFIG_PLATFORM_AHBDMA || CONFIG_PLATFORM_APBDMA */
diff -Nur linux-3.4.113.orig/arch/nds32/platforms/dmad_intc.c linux-3.4.113/arch/nds32/platforms/dmad_intc.c
--- linux-3.4.113.orig/arch/nds32/platforms/dmad_intc.c 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/platforms/dmad_intc.c 2016-12-01 20:59:24.380613830 +0100
@@ -0,0 +1,124 @@
+/*
+ * linux/arch/armnommu/mach-faraday/platform-a320/apb_intc.c
+ *
+ * Faraday AHB DMA Interrupt Process Driver Implementation
+ *
+ * Copyright (C) 2005 Faraday Corp. (http://www.faraday-tech.com)
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ *
+ * ChangeLog
+ *
+ * Peter Liao 09/28/2005 Created
+ */
+
+#include <linux/irq.h>
+#include <linux/interrupt.h>
+#include <linux/ioport.h>
+#include <asm/io.h>
+
+#include <asm/intc.h>
+#include <asm/spec.h>
+
+#ifdef CONFIG_PLATFORM_AHBDMA
+extern int dmad_probe_irq_source_ahb(void);
+
+void AHBDMA_irq_rounter(unsigned int irq, struct irq_desc *desc)
+{
+ int ahb_irq;
+ struct irq_desc *ahb_desc;
+ struct irq_data data;
+ data.irq = irq;
+
+ raw_spin_lock(&desc->lock);
+ desc->irq_data.chip->irq_mask(&data);
+ desc->irq_data.chip->irq_ack(&data);
+
+ ahb_irq = dmad_probe_irq_source_ahb();
+ if (ahb_irq >= 0) {
+ ahb_irq += DMAC_FTDMAC020_IRQ0;
+ ahb_desc = irq_desc + ahb_irq;
+
+ raw_spin_unlock(&desc->lock);
+ ahb_desc->handle_irq(ahb_irq, ahb_desc);
+ raw_spin_lock(&desc->lock);
+ }
+
+ desc->irq_data.chip->irq_unmask(&data);
+ raw_spin_unlock(&desc->lock);
+}
+
+int __init intc_ftdmac020_init_irq(void)
+{
+ int i;
+
+ /* Register all IRQ */
+ for (i = DMAC_FTDMAC020_IRQ0;
+ i < DMAC_FTDMAC020_IRQ0 + DMAC_FTDMAC020_IRQ_COUNT; i++) {
+ // level trigger
+ irq_set_chip(i, &dummy_irq_chip);
+ irq_set_handler(i, handle_simple_irq);
+ }
+ irq_set_chained_handler(PLATFORM_AHBDMA_IRQ, AHBDMA_irq_rounter);
+
+ return 0;
+}
+
+arch_initcall(intc_ftdmac020_init_irq);
+#endif /* CONFIG_PLATFORM_AHBDMA */
+
+#ifdef CONFIG_PLATFORM_APBDMA
+extern int dmad_probe_irq_source_apb(void);
+
+void APBDMA_irq_rounter(unsigned int irq, struct irq_desc *desc)
+{
+ int apb_irq;
+ struct irq_desc *apb_desc;
+ struct irq_data data;
+ data.irq = irq;
+
+ raw_spin_lock(&desc->lock);
+
+ //mask_ack_irq(desc, irq);
+ desc->irq_data.chip->irq_mask(&data);
+ desc->irq_data.chip->irq_ack(&data);
+
+ apb_irq = dmad_probe_irq_source_apb();
+ //printk(KERN_INFO "irq (%d) ch(%d)\n", irq, apb_irq);
+
+ if (apb_irq >= 0) {
+ apb_irq += APBBRG_FTAPBBRG020S_0_IRQ0;
+ apb_desc = irq_desc + apb_irq;
+
+ raw_spin_unlock(&desc->lock);
+ apb_desc->handle_irq(irq, apb_desc);
+ raw_spin_lock(&desc->lock);
+ }
+
+ desc->irq_data.chip->irq_unmask(&data);
+ raw_spin_unlock(&desc->lock);
+}
+
+int __init intc_ftapbbrg020s_init_irq(void)
+{
+ int i;
+
+ /* Register all IRQ */
+ for (i = APBBRG_FTAPBBRG020S_0_IRQ0;
+ i < APBBRG_FTAPBBRG020S_0_IRQ0 + APBBRG_FTAPBBRG020S_IRQ_COUNT;
+ i++) {
+ // level trigger
+ irq_set_chip(i, &dummy_irq_chip);
+ irq_set_handler(i, handle_simple_irq);
+ }
+
+ irq_set_chained_handler(PLATFORM_APBDMA_IRQ, APBDMA_irq_rounter);
+
+ return 0;
+}
+
+arch_initcall(intc_ftapbbrg020s_init_irq);
+#endif /* CONFIG_PLATFORM_APBDMA */
diff -Nur linux-3.4.113.orig/arch/nds32/platforms/ftpci.c linux-3.4.113/arch/nds32/platforms/ftpci.c
--- linux-3.4.113.orig/arch/nds32/platforms/ftpci.c 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/platforms/ftpci.c 2016-12-01 20:59:24.380613830 +0100
@@ -0,0 +1,497 @@
+/*
+ * linux/arch/nds32/platforms/ftpci.c
+ *
+ * Faraday FTPCI100 PCI Bridge Controller Device Driver Implementation
+ *
+ * Copyright (C) 2005 Faraday Corp. (http://www.faraday-tech.com)
+ * Copyright (C) 2009 Andes Technology Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ *
+ * ChangeLog
+ *
+ * Peter Liao 09/28/2005 Created.
+ */
+
+#include <linux/sched.h>
+#include <linux/kernel.h>
+#include <linux/pci.h>
+#include <linux/ptrace.h>
+#include <linux/slab.h>
+#include <linux/ioport.h>
+#include <linux/interrupt.h>
+#include <linux/spinlock.h>
+#include <linux/init.h>
+#include <asm/hardware.h>
+#include <asm/irq.h>
+#include <asm/system.h>
+#include <asm/mach/pci.h>
+#include <asm/io.h>
+#include <asm/sizes.h>
+#include <asm/ftpci.h>
+#include <asm/spec.h>
+#include <asm/mach-types.h>
+
+#define IPMODULE PCIC
+#define IPNAME FTPCI100
+
+#define DEBUGFPCI
+#undef DEBUGFPCI
+
+#ifdef DEBUGFPCI
+#define DBGFPCI(x...) printk(x)
+#else
+#define DBGFPCI(x...)
+#endif
+#define FPCI_VA_BASE IP_VA_BASE(0)
+#define FTPCI_PCI_BRIDGE_VENID PCI_BRIDGE_VENID
+#define FPCI_IO_VA_BASE PCIIO_VA_BASE
+#define FPCI_IO_PA_BASE PCIIO_PA_BASE
+#define FPCI_IO_VA_END PCIIO_VA_LIMIT
+#define FPCI_MEM_VA_BASE PCIMEM_VA_BASE
+#define FPCI_MEM_PA_BASE PCIMEM_PA_BASE
+#define FPCI_MEM_VA_END PCIMEM_VA_LIMIT
+#define FPCI_MEM_PA_END (PCIMEM_PA_BASE + SZ_256M)
+
+// --------------------------------------------------------------------
+// AHB Control Register
+// --------------------------------------------------------------------
+#define FTPCI_IOSIZE_REG 0x0
+#define FTPCI_PROT_REG 0x4
+#define FTPCI_CTRL_REG 0x8
+#define FTPCI_ERREN_REG 0xc
+#define FTPCI_SOFTRST_REG 0x10
+#define FTPCI_EN64_REG 0x14
+#define FTPCI_ADDRH32_REG 0x18
+#define FTPCI_CFG_ADR_REG 0x28
+#define FTPCI_CFG_DATA_REG 0x2c
+
+// --------------------------------------------------------------------
+// FTPCI_IOSIZE_REG's constant definitions
+// --------------------------------------------------------------------
+#define FTPCI_BASE_IO_SIZE_1M 0x0
+#define FTPCI_BASE_IO_SIZE_2M 0x1
+#define FTPCI_BASE_IO_SIZE_4M 0x2
+#define FTPCI_BASE_IO_SIZE_8M 0x3
+#define FTPCI_BASE_IO_SIZE_16M 0x4
+#define FTPCI_BASE_IO_SIZE_32M 0x5
+#define FTPCI_BASE_IO_SIZE_64M 0x6
+#define FTPCI_BASE_IO_SIZE_128M 0x7
+#define FTPCI_BASE_IO_SIZE_256M 0x8
+#define FTPCI_BASE_IO_SIZE_512M 0x9
+#define FTPCI_BASE_IO_SIZE_1G 0xa
+#define FTPCI_BASE_IO_SIZE_2G 0xb
+
+// --------------------------------------------------------------------
+// PCI Configuration Register
+// --------------------------------------------------------------------
+#define PCI_INT_MASK 0x4c
+#define PCI_MEM_BASE_SIZE1 0x50
+#define PCI_MEM_BASE_SIZE2 0x54
+#define PCI_MEM_BASE_SIZE3 0x58
+
+// --------------------------------------------------------------------
+// PCI_INT_MASK's bit definitions
+// --------------------------------------------------------------------
+#define PCI_INTA_ENABLE (1U<<22)
+#define PCI_INTB_ENABLE (1U<<23)
+#define PCI_INTC_ENABLE (1U<<24)
+#define PCI_INTD_ENABLE (1U<<25)
+
+// --------------------------------------------------------------------
+// PCI_MEM_BASE_SIZE1's constant definitions
+// --------------------------------------------------------------------
+#define FTPCI_BASE_ADR_SIZE_1MB (PHYS_OFFSET | (0x0<<16))
+#define FTPCI_BASE_ADR_SIZE_2MB (PHYS_OFFSET | (0x1<<16))
+#define FTPCI_BASE_ADR_SIZE_4MB (PHYS_OFFSET | (0x2<<16))
+#define FTPCI_BASE_ADR_SIZE_8MB (PHYS_OFFSET | (0x3<<16))
+#define FTPCI_BASE_ADR_SIZE_16MB (PHYS_OFFSET | (0x4<<16))
+#define FTPCI_BASE_ADR_SIZE_32MB (PHYS_OFFSET | (0x5<<16))
+#define FTPCI_BASE_ADR_SIZE_64MB (PHYS_OFFSET | (0x6<<16))
+#define FTPCI_BASE_ADR_SIZE_128MB (PHYS_OFFSET | (0x7<<16))
+#define FTPCI_BASE_ADR_SIZE_256MB (PHYS_OFFSET | (0x8<<16))
+#define FTPCI_BASE_ADR_SIZE_512MB (PHYS_OFFSET | (0x9<<16))
+#define FTPCI_BASE_ADR_SIZE_1GB (PHYS_OFFSET | (0xa<<16))
+#define FTPCI_BASE_ADR_SIZE_2GB (PHYS_OFFSET | (0xb<<16))
+
+#define CONFIG_CMD(bus, device_fn, where) (0x80000000 | (bus << 16) | (device_fn << 8) | (where & ~3) )
+
+struct pci_dev *pci_bridge = NULL;
+static unsigned int pci_config_addr;
+static unsigned int pci_config_data;
+int ftpci_probed = 0;
+
+static struct resource pcic_resource = {
+ .name = "Faradat PCIC",
+ .start = IP_VA_BASE(0),
+ .end = IP_VA_LIMIT(0),
+};
+
+// Luke Lee 03/21/2005 mod begin
+static int ftpci_read_config_byte(struct pci_bus *bus, unsigned int devfn,
+ int where, u8 * val)
+{
+ u32 v;
+ unsigned int shift;
+
+ outl(CONFIG_CMD(bus->number, devfn, where), pci_config_addr);
+ v = inl(pci_config_data);
+ shift = (where & 0x3) * 8;
+ *val = (v >> shift) & 0xff;
+ return PCIBIOS_SUCCESSFUL;
+}
+
+static int ftpci_read_config_word(struct pci_bus *bus, unsigned int devfn,
+ int where, u16 * val)
+{
+ u32 v;
+ unsigned int shift;
+
+ outl(CONFIG_CMD(bus->number, devfn, where), pci_config_addr);
+ v = inl(pci_config_data);
+ shift = (where & 0x3) * 8;
+ *val = (v >> shift) & 0xffff;
+ return PCIBIOS_SUCCESSFUL;
+}
+
+static int ftpci_read_config_dword(struct pci_bus *bus, unsigned int devfn,
+ int where, u32 * val)
+{
+ u32 v;
+
+ outl(CONFIG_CMD(bus->number, devfn, where), pci_config_addr);
+ v = inl(pci_config_data);
+ *val = v;
+ return PCIBIOS_SUCCESSFUL;
+}
+
+static int ftpci_write_config_byte(struct pci_bus *bus, unsigned int devfn,
+ int where, u8 val)
+{
+ u32 org_val;
+ unsigned int shift;
+
+ shift = (where & 0x3) * 8;
+ outl(CONFIG_CMD(bus->number, devfn, where), pci_config_addr);
+ org_val = inl(pci_config_data);
+ org_val = (org_val & ~(0xff << shift)) | ((u32) val << shift);
+ outl(org_val, pci_config_data);
+ return PCIBIOS_SUCCESSFUL;
+}
+
+static int ftpci_write_config_word(struct pci_bus *bus, unsigned int devfn,
+ int where, u16 val)
+{
+ u32 org_val;
+ unsigned int shift;
+
+ shift = (where & 0x3) * 8;
+ outl(CONFIG_CMD(bus->number, devfn, where), pci_config_addr);
+ org_val = inl(pci_config_data);
+ org_val = (org_val & ~(0xffff << shift)) | ((u32) val << shift);
+ outl(org_val, pci_config_data);
+ return PCIBIOS_SUCCESSFUL;
+}
+
+static int ftpci_write_config_dword(struct pci_bus *bus, unsigned int devfn,
+ int where, u32 val)
+{
+ outl(CONFIG_CMD(bus->number, devfn, where), pci_config_addr);
+ outl(val, pci_config_data);
+ return PCIBIOS_SUCCESSFUL;
+}
+
+// Luke Lee 03/21/2005 mod end
+
+// Luke Lee 03/21/2005 ins begin
+static int ftpci_read_config(struct pci_bus *bus, unsigned int devfn, int where,
+ int size, u32 * val)
+{
+ int r;
+ switch (size) {
+ case 1:
+ r = ftpci_read_config_byte(bus, devfn, where, (u8 *) val); // Luke Lee TOFIX 03/22/2005 : convert to (u8*) -- beware of endian !
+ break;
+ case 2:
+ r = ftpci_read_config_word(bus, devfn, where, (u16 *) val); // Luke Lee TOFIX 03/22/2005 : convert to (u16*) -- beware of endian !
+ break;
+
+ default:
+ r = ftpci_read_config_dword(bus, devfn, where, val);
+ break;
+ }
+
+ return r;
+}
+
+static int ftpci_write_config(struct pci_bus *bus, unsigned int devfn,
+ int where, int size, u32 val)
+{
+ int r;
+ switch (size) {
+ case 1:
+ r = ftpci_write_config_byte(bus, devfn, where, val);
+ break;
+ case 2:
+ r = ftpci_write_config_word(bus, devfn, where, val);
+ break;
+
+ case 4:
+ r = ftpci_write_config_dword(bus, devfn, where, val);
+ break;
+ default:
+ printk("Invalid size for ftpci_write()\n");
+ r = PCIBIOS_FUNC_NOT_SUPPORTED; // Luke Lee 03/23/2005 ins 1
+ }
+
+ return r;
+}
+
+// Luke Lee 03/21/2005 ins end
+
+static struct pci_ops ftpci_ops = {
+ // Luke Lee 03/21/2005 mod begin
+ .read = ftpci_read_config,
+ .write = ftpci_write_config,
+ // Luke Lee 03/21/2005 mod end
+};
+
+/* using virtual address for pci_resource_start() function*/
+static struct resource pci_io = {
+ .name = "Faraday PCI I/O Space",
+ .start = FPCI_IO_VA_BASE,
+ .end = FPCI_IO_VA_END,
+ .flags = IORESOURCE_IO,
+};
+
+/* using physical address for memory resource*/
+static struct resource pci_mem = {
+ .name = "Faraday PCI non-prefetchable Memory Space",
+ .start = FPCI_MEM_PA_BASE,
+ .end = FPCI_MEM_PA_END,
+ .flags = IORESOURCE_MEM,
+};
+
+// Luke Lee 03/23/2005 unrem 1 rem 1
+int __init ftpci_setup_resource(struct resource **resource)
+{
+ DBGFPCI("PCI I/O space from %08lX to %08lX\n", pci_io.start,
+ pci_io.end);
+ DBGFPCI("PCI Memory space from %08lX to %08lX\n", pci_mem.start,
+ pci_mem.end);
+ if (request_resource(&ioport_resource, &pci_io)) {
+ printk(KERN_ERR "PCI: unable to allocate io region\n");
+ return -EBUSY; // Luke Lee 03/23/2005 unrem 1
+ }
+ if (request_resource(&iomem_resource, &pci_mem)) {
+ printk(KERN_ERR "PCI: unable to allocate non-prefetchable "
+ "memory region\n");
+ return -EBUSY; // Luke Lee 03/23/2005 unrem 1
+ }
+
+ /*
+ * bus->resource[0] is the IO resource for this bus
+ * bus->resource[1] is the mem resource for this bus
+ * bus->resource[2] is the prefetch mem resource for this bus
+ */
+
+ resource[0] = &pci_io;
+ resource[1] = &pci_mem;
+ resource[2] = NULL;
+
+ return 1; // Luke Lee 03/23/2005 unrem 1
+}
+
+int ftpci_get_irq(void)
+{
+ unsigned int status;
+ ftpci_read_config_dword(pci_bridge->bus, pci_bridge->devfn, 0x4c, &status); // Luke Lee 03/22/2005 mod 1
+ DBGFPCI("ftpci_get_irq,status=0x%x\n", status);
+ status = (status >> 28);
+ if (status & 0x1)
+ return 0;
+ if (status & 0x2)
+ return 1;
+ if (status & 0x4)
+ return 2;
+ if (status & 0x8)
+ return 3;
+ return -1;
+}
+
+void ftpci_clear_irq(unsigned int irq)
+{
+ //int i;
+ unsigned int status;
+ ftpci_read_config_dword(pci_bridge->bus, pci_bridge->devfn, 0x4c, &status); // Luke Lee 03/22/2005 mod 1
+ if (irq == 0)
+ status = (status & 0xfffffff) | ((0x1) << 28);
+ else if (irq == 1)
+ status = (status & 0xfffffff) | ((0x2) << 28);
+ else if (irq == 2)
+ status = (status & 0xfffffff) | ((0x4) << 28);
+ else if (irq == 3)
+ status = (status & 0xfffffff) | ((0x8) << 28);
+ ftpci_write_config_dword(pci_bridge->bus, pci_bridge->devfn, 0x4c, status); // Luke Lee 03/22/2005 mod 1
+}
+
+void ftpci_unmask_irq(unsigned int irq)
+{
+ u32 val;
+ ftpci_read_config_dword(pci_bridge->bus, pci_bridge->devfn,
+ PCI_INT_MASK, &val);
+ val |= (PCI_INTA_ENABLE << irq);
+ ftpci_write_config_dword(pci_bridge->bus, pci_bridge->devfn,
+ PCI_INT_MASK, val);
+}
+
+void ftpci_mask_irq(unsigned int irq)
+{
+ u32 val;
+ ftpci_read_config_dword(pci_bridge->bus, pci_bridge->devfn,
+ PCI_INT_MASK, &val);
+ val &= ~(PCI_INTA_ENABLE << irq);
+ ftpci_write_config_dword(pci_bridge->bus, pci_bridge->devfn,
+ PCI_INT_MASK, val);
+}
+
+static int ftpci_probe(unsigned int addr_p)
+{
+ unsigned int *addr = (unsigned int *)addr_p;
+ *(volatile unsigned int *)addr = 0x80000000;
+ if (*(volatile unsigned int *)addr == 0x80000000) {
+ DBGFPCI("Faraday FPCI bridge probed ok\n");
+ ftpci_probed = 1;
+ } else {
+ ftpci_probed = 0;
+ }
+ *(volatile unsigned int *)addr = 0x0;
+ return ftpci_probed;
+}
+
+void __init ftpci_preinit(void /**sysdata*/ ) // Luke Lee 03/22/2005 mod 1
+{
+ DBGFPCI("ftpci_preinit()\n\r");
+
+#ifdef CONFIG_PLAT_AG101
+ /* Walk around for A321 but remove after leopard pci */
+ *(volatile unsigned long *)(FPCI_VA_BASE + 0x8) = 0x10;
+#endif
+
+ pci_config_addr = FPCI_VA_BASE + FTPCI_CFG_ADR_REG;
+ pci_config_data = FPCI_VA_BASE + FTPCI_CFG_DATA_REG;
+ DBGFPCI("Config addr is %08X, data port is %08X\n",
+ (int)pci_config_addr, (int)pci_config_data);
+
+ if (!ftpci_probe(pci_config_addr))
+ return;
+}
+
+void ftpci_postinit(void /**sysdata*/ )
+{
+ u32 val;
+ DBGFPCI("ftpci_postinit()\n\r");
+ pci_bridge = pci_get_device(PCI_BRIDGE_VENID, PCI_BRIDGE_DEVID, NULL);
+ if (pci_bridge == NULL)
+ return;
+ // Enable the Interrupt Mask (INTA/INTB/INTC/INTD)
+ ftpci_read_config_dword(pci_bridge->bus, pci_bridge->devfn, PCI_INT_MASK, &val); // Luke Lee 03/22/2005 mod 1
+ val |=
+ (PCI_INTA_ENABLE | PCI_INTB_ENABLE | PCI_INTC_ENABLE |
+ PCI_INTD_ENABLE);
+ ftpci_write_config_dword(pci_bridge->bus, pci_bridge->devfn, PCI_INT_MASK, val); // Luke Lee 03/22/2005 mod 1
+
+ // Write DMA Start Address/Size Data to the Bridge configuration space
+ ftpci_write_config_dword(pci_bridge->bus, pci_bridge->devfn, PCI_MEM_BASE_SIZE1, FTPCI_BASE_ADR_SIZE_1GB); // Luke Lee 03/22/2005 mod 1
+ DBGFPCI("%s: Post init ok\n", __func__);
+}
+
+/*
+ * This routine handles multiple bridges.
+ */
+static u8 __init fpci_swizzle(struct pci_dev *dev, u8 * pinp)
+{
+ // If there are one more bridges on our platfrom, we need to implement this function.
+ DBGFPCI("a320_swizzle(%X,%X)\n\r", (unsigned)dev, (unsigned)pinp);
+ return 0;
+}
+
+static int __init fpci_map_irq(struct pci_dev *dev, u8 slot, u8 pin)
+{
+ DBGFPCI("a320_map_irq,slot=%d pin=%d\n", PCI_SLOT(dev->devfn), pin);
+ switch ((PCI_SLOT(dev->devfn) + pin - 8 - 1) % 4) {
+ case 0:
+ return IP_IRQ0(0);
+ case 1:
+ return IP_IRQ1(0);
+ case 2:
+ return IP_IRQ2(0);
+ case 3:
+ return IP_IRQ3(0);
+ default:
+ printk(KERN_ERR "Not Support Slot %d\n", slot);
+ break;
+ }
+ return -1;
+}
+
+int __init ftpci_setup(int nr, struct pci_sys_data *sys)
+{
+ int ret = 0;
+ if (nr == 0) {
+ ret = ftpci_setup_resource(sys->resource);
+// sys->mem_offset = FPCI_MEM_VA_BASE - FPCI_MEM_PA_BASE;
+ sys->mem_offset = 0;
+ sys->io_offset = FPCI_IO_VA_BASE - FPCI_IO_PA_BASE;
+ }
+ return ret;
+}
+
+static struct pci_bus *__devinit ftpci_scan_bus(int nr,
+ struct pci_sys_data *sys)
+{
+ return pci_scan_bus(sys->busnr, &ftpci_ops, sys);
+}
+
+static struct hw_pci a320_pci __initdata = {
+ .swizzle = fpci_swizzle,
+ .map_irq = fpci_map_irq,
+ .setup = ftpci_setup,
+ .nr_controllers = 1,
+ .scan = ftpci_scan_bus,
+ .preinit = ftpci_preinit, /* The first called init function */
+ .postinit = ftpci_postinit, /* It is called after hw init and scanned PCI bus */
+};
+
+static int __init fpci_init(void)
+{
+#ifdef MODULE
+ printk(KERN_INFO "Faraday PCI driver Init");
+#endif
+ printk(KERN_DEBUG "Init A321 PCI bridge controller\n");
+ /* Register I/O address range of this PCI Bridge Controller */
+ DBGFPCI("Name:%s, Base=%lX, End=%lX\n", pcic_resource.name,
+ pcic_resource.start, pcic_resource.end);
+ request_resource(&ioport_resource, &pcic_resource);
+ pci_common_init(&a320_pci);
+ return 0;
+}
+
+subsys_initcall(fpci_init);
+
+EXPORT_SYMBOL(ftpci_probed);
+EXPORT_SYMBOL(ftpci_clear_irq);
+EXPORT_SYMBOL(ftpci_get_irq);
diff -Nur linux-3.4.113.orig/arch/nds32/platforms/intc.c linux-3.4.113/arch/nds32/platforms/intc.c
--- linux-3.4.113.orig/arch/nds32/platforms/intc.c 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/platforms/intc.c 2016-12-01 20:59:24.380613830 +0100
@@ -0,0 +1,257 @@
+/*
+ * linux/arch/nds32/platforms/intc.c
+ *
+ * Faraday FTINTC010 Master Interrupt Controller Device Driver Implementation
+ *
+ * Copyright (C) 2005 Faraday Corp. (http://www.faraday-tech.com)
+ * Copyright (C) 2009 Andes Technology Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Note
+ *
+ * This program implements only the master INTC of the platform. Slave INTCs must
+ * be initialized by themselves.
+ *
+ * ChangeLog
+ *
+ * Luke Lee 09/14/2005 Created.
+ */
+
+#include <linux/irq.h>
+#include <linux/interrupt.h>
+#include <linux/ioport.h>
+#include <asm/io.h>
+
+#include <asm/intc.h>
+#include <asm/spec.h>
+#include <asm/ftpci.h>
+
+#define IPMODULE INTC
+#define IPNAME FTINTC010
+
+/*
+ * Edge trigger IRQ chip methods
+ */
+#if defined(CONFIG_SMP) && defined(CONFIG_IRQ_PER_CPU)
+spinlock_t irq_chip_lock;
+#endif
+
+static void intc_ftintc010_ack_irq(struct irq_data *data)
+{
+ unsigned int tmp;
+
+ // ack and disable
+#if defined(CONFIG_SMP) && defined(CONFIG_IRQ_PER_CPU)
+ spin_lock_irq(&irq_chip_lock);
+#endif
+ *(volatile unsigned *)(IP_VA_BASE(0) + IRQ_CLEAR_REG) = 1 << data->irq;
+ tmp = *(volatile unsigned *)(IP_VA_BASE(0) + IRQ_CLEAR_REG);
+ tmp = *(volatile unsigned *)(IP_VA_BASE(0) + IRQ_MODE_REG);
+
+ if (!(tmp & (1UL << data->irq))) { /* level trigger */
+
+ *(volatile unsigned *)(IP_VA_BASE(0) + IRQ_MASK_REG) &=
+ ~(1 << data->irq);
+ tmp = *(volatile unsigned *)(IP_VA_BASE(0) + IRQ_MASK_REG);
+ }
+#if defined(CONFIG_SMP) && defined(CONFIG_IRQ_PER_CPU)
+ spin_unlock_irq(&irq_chip_lock);
+#endif
+}
+
+static void intc_ftintc010_mask_irq(struct irq_data *data)
+{
+ unsigned int tmp;
+
+ // disable
+#if defined(CONFIG_SMP) && defined(CONFIG_IRQ_PER_CPU)
+ spin_lock_irq(&irq_chip_lock);
+#endif
+ *(volatile unsigned *)(IP_VA_BASE(0) + IRQ_MASK_REG) &=
+ ~(1 << data->irq);
+ tmp = *(volatile unsigned *)(IP_VA_BASE(0) + IRQ_MASK_REG);
+#if defined(CONFIG_SMP) && defined(CONFIG_IRQ_PER_CPU)
+ spin_unlock_irq(&irq_chip_lock);
+#endif
+}
+
+static void intc_ftintc010_mask_ack_irq(struct irq_data *data)
+{
+ unsigned int tmp;
+
+ // disable
+#if defined(CONFIG_SMP) && defined(CONFIG_IRQ_PER_CPU)
+ spin_lock_irq(&irq_chip_lock);
+#endif
+ *(volatile unsigned *)(IP_VA_BASE(0) + IRQ_MASK_REG) &=
+ ~(1 << data->irq);
+ tmp = *(volatile unsigned *)(IP_VA_BASE(0) + IRQ_MASK_REG);
+
+ *(volatile unsigned *)(IP_VA_BASE(0) + IRQ_CLEAR_REG) = 1 << data->irq;
+ tmp = *(volatile unsigned *)(IP_VA_BASE(0) + IRQ_CLEAR_REG);
+
+#if defined(CONFIG_SMP) && defined(CONFIG_IRQ_PER_CPU)
+ spin_unlock_irq(&irq_chip_lock);
+#endif
+}
+
+static void intc_ftintc010_unmask_irq(struct irq_data *data)
+{
+ unsigned int tmp;
+
+ // enable
+#if defined(CONFIG_SMP) && defined(CONFIG_IRQ_PER_CPU)
+ spin_lock_irq(&irq_chip_lock);
+#endif
+ *(volatile unsigned *)(IP_VA_BASE(0) + IRQ_MASK_REG) |= 1 << data->irq;
+ tmp = *(volatile unsigned *)(IP_VA_BASE(0) + IRQ_MASK_REG);
+#if defined(CONFIG_SMP) && defined(CONFIG_IRQ_PER_CPU)
+ spin_unlock_irq(&irq_chip_lock);
+#endif
+}
+
+static int intc_ftintc010_set_type(struct irq_data *data,
+ unsigned int flow_type)
+{
+#if defined(CONFIG_SMP) && defined(CONFIG_IRQ_PER_CPU)
+ spin_lock_irq(&irq_chip_lock);
+#endif
+ /*
+ * IRQ Trigger Mode Register 1: edge
+ * IRQ Trigger Level Register 1: active high
+ */
+
+ int tmp;
+
+ if (flow_type & (IRQF_TRIGGER_FALLING | IRQF_TRIGGER_LOW)) {
+
+ *(volatile unsigned *)(IP_VA_BASE(0) + IRQ_LEVEL_REG) &=
+ ~(1UL << data->irq);
+ tmp = *(volatile unsigned *)(IP_VA_BASE(0) + IRQ_LEVEL_REG);
+ }
+
+ if (flow_type & (IRQF_TRIGGER_RISING | IRQF_TRIGGER_HIGH)) {
+
+ *(volatile unsigned *)(IP_VA_BASE(0) + IRQ_LEVEL_REG) |=
+ (1UL << data->irq);
+ tmp = *(volatile unsigned *)(IP_VA_BASE(0) + IRQ_LEVEL_REG);
+ }
+
+ if (flow_type & (IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING)) {
+
+ *(volatile unsigned *)(IP_VA_BASE(0) + IRQ_MODE_REG) |=
+ (1UL << data->irq);
+ tmp = *(volatile unsigned *)(IP_VA_BASE(0) + IRQ_MODE_REG);
+ (irq_desc + data->irq)->handle_irq = handle_edge_irq;
+ }
+
+ if (flow_type & (IRQF_TRIGGER_HIGH | IRQF_TRIGGER_LOW)) {
+
+ *(volatile unsigned *)(IP_VA_BASE(0) + IRQ_MODE_REG) &=
+ ~(1UL << data->irq);
+ tmp = *(volatile unsigned *)(IP_VA_BASE(0) + IRQ_MODE_REG);
+ (irq_desc + data->irq)->handle_irq = handle_level_irq;
+ }
+#if defined(CONFIG_SMP) && defined(CONFIG_IRQ_PER_CPU)
+ spin_unlock_irq(&irq_chip_lock);
+#endif
+ return 0;
+}
+
+static struct irq_chip intc_ftintc010_chip = {
+
+ .irq_ack = intc_ftintc010_ack_irq,
+ .irq_mask = intc_ftintc010_mask_irq,
+ .irq_mask_ack = intc_ftintc010_mask_ack_irq,
+ .irq_unmask = intc_ftintc010_unmask_irq,
+ .irq_set_type = intc_ftintc010_set_type,
+};
+
+static struct resource intc_resource = {
+
+ .name = "Main interrupt controller",
+ .start = IP_VA_BASE(0),
+ .end = IP_VA_BASE(0) + IP_VA_SIZE(0),
+};
+
+/*
+ * Initialization of master interrupt controller, after this INTC is
+ * enabled, the rest of Linux initialization codes can then be completed.
+ * For example, timer interrupts and UART interrupts must be enabled during
+ * the boot process.
+ */
+void __init intc_ftintc010_init_irq(void)
+{
+ int i, edge;
+
+#if defined(CONFIG_SMP) && defined(CONFIG_IRQ_PER_CPU)
+ spin_lock_init(&irq_chip_lock);
+#endif
+ /* Initialize the INTC */
+ outl(0x00000000, IP_VA_BASE(0) + IRQ_MASK_REG);
+ outl(0x00000000, IP_VA_BASE(0) + FIQ_MASK_REG);
+ outl(0xffffffff, IP_VA_BASE(0) + IRQ_CLEAR_REG);
+ outl(0xffffffff, IP_VA_BASE(0) + FIQ_CLEAR_REG);
+ outl(PLATFORM_IRQ_TRIGGER_MODE, IP_VA_BASE(0) + IRQ_MODE_REG);
+ /* FTINTC010: bit 0=active high or rising edge, 1=active low or falling edge. */
+ outl(PLATFORM_IRQ_TRIGGER_LEVEL, IP_VA_BASE(0) + IRQ_LEVEL_REG);
+
+ /* Register all IRQ */
+ for (i = PLATFORM_IRQ_BASE, edge = 1;
+ i < PLATFORM_IRQ_BASE + PLATFORM_IRQ_TOTALCOUNT; i++, edge <<= 1) {
+
+ irq_set_chip(i, &intc_ftintc010_chip);
+
+ if (PLATFORM_IRQ_TRIGGER_MODE & edge) /* edge trigger */
+ irq_set_handler(i, handle_edge_irq);
+
+ else /* level trigger */
+ irq_set_handler(i, handle_level_irq);
+ }
+
+ /* Register I/O address range of this INTC */
+ request_resource(&ioport_resource, &intc_resource);
+
+}
+
+unsigned int get_IntSrc(void)
+{
+ unsigned int irq_status, irq = 31;
+
+ irq_status = inl(IP_VA_BASE(0) + IRQ_STATUS_REG);
+ if (irq_status == 0)
+ return 32;
+ if (irq_status & 0x0000ffff) {
+ irq -= 16;
+ irq_status <<= 16;
+ }
+ if (irq_status & 0x00ff0000) {
+ irq -= 8;
+ irq_status <<= 8;
+ }
+ if (irq_status & 0x0f000000) {
+ irq -= 4;
+ irq_status <<= 4;
+ }
+ if (irq_status & 0x30000000) {
+ irq -= 2;
+ irq_status <<= 2;
+ }
+ if (irq_status & 0x40000000) {
+ irq -= 1;
+ }
+ return irq;
+}
diff -Nur linux-3.4.113.orig/arch/nds32/platforms/Kconfig linux-3.4.113/arch/nds32/platforms/Kconfig
--- linux-3.4.113.orig/arch/nds32/platforms/Kconfig 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/platforms/Kconfig 2016-12-01 20:59:24.380613830 +0100
@@ -0,0 +1,122 @@
+choice
+ prompt "platform type"
+ default PLAT_AG101P
+
+config PLAT_VEP
+ bool "vep platform"
+ select CPU_CUSTOM
+ select PLATFORM_INTC
+
+config PLAT_AG101
+ bool "ag101 platform"
+ select CPU_N1213
+ select CPU_N1213_43U1HA0
+ select PLATFORM_INTC
+
+config PLAT_AG102
+ bool "ag102 platform"
+ select CPU_N1233F
+ select PLATFORM_AMIC
+
+config PLAT_AG101P
+ bool "ag101p platform"
+ select CPU_CUSTOM
+ select PLATFORM_INTC if !IVIC
+ select PLATFORM_NOINTC if IVIC
+
+config PLAT_QEMU
+ bool "qemu platform"
+ select CPU_CUSTOM
+ select PLATFORM_INTC
+endchoice
+
+config PLATFORM_NOINTC
+ def_bool n
+ depends on PLAT_AG101P
+
+config PLATFORM_INTC
+ def_bool n
+ depends on !PLAT_AG102
+
+config PLATFORM_AMIC
+ def_bool n
+ depends on PLAT_AG102
+
+config ARCH_WANT_OPTIONAL_GPIOLIB
+ bool "Arch Want Optional GPIOLIB"
+ default y
+
+if PLAT_VEP
+source "arch/nds32/platforms/vep/Kconfig"
+endif
+
+if PLAT_AG101
+source "arch/nds32/platforms/ag101/Kconfig"
+endif
+
+if PLAT_AG102
+source "arch/nds32/platforms/ag102/Kconfig"
+endif
+
+if PLAT_AG101P
+source "arch/nds32/platforms/ag101p/Kconfig"
+endif
+
+if PLAT_QEMU
+source "arch/nds32/platforms/qemu/Kconfig"
+endif
+
+menu "Common Platform Options"
+
+config PLATFORM_AHBDMA
+ tristate "AHB DMA Support"
+ help
+ AHB DMA service API support for other device drivers
+
+config PLATFORM_APBDMA
+ tristate "APB DMA Support"
+ help
+ AHB DMA service API support for other device drivers
+
+config SYS_CLK
+ int "AHB System Clock"
+ default 67737600
+ help
+ Manual setting of AHB clock, must match the jumper setting on
+ the board, or the system time won't be correctly calculated.
+ Notice that even when AUTO_SYS_CLK is ON, this value is still
+ required for adjusting minor time offsets. However, the influence
+ should be within micro-second to nano-second scale.
+
+config UART_CLK
+ int "UART Clock"
+ default 18432000
+ help
+ Change the UART clock in case of non-3.6864MHz OSC is used as main
+ clock source, or an external UART clock source is fed from GPIO23.
+ To support external UART clock from GPIO23, set PMU
+ "Multi-Function Port Setting Register" bit #8 (UartClkSel) to 1.
+ This control register can be found at physical address 0x98100028
+ If this options is changed, please also append "38400" to your
+ kernel command line, e.g.:
+ console=uart,shift,2,io,0xF9820000,38400
+ Note: For A320, the default UART clock is obtained by = 5 * OSC =
+ 5 * 3.6864MHz = 18.432MHz.
+
+menu "Memory configuration"
+
+config SDRAM_SIZE
+ hex "SDRAM Size (hex)"
+ default 4000000
+ ---help---
+ RAM size
+
+config MEMORY_START
+ hex "Physical memory start address"
+ default "0x00000000"
+ ---help---
+ Physical memory start address, you may modify it if it is porting to
+ a new SoC with different start address.
+endmenu
+
+endmenu
diff -Nur linux-3.4.113.orig/arch/nds32/platforms/Makefile linux-3.4.113/arch/nds32/platforms/Makefile
--- linux-3.4.113.orig/arch/nds32/platforms/Makefile 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/platforms/Makefile 2016-12-01 20:59:24.380613830 +0100
@@ -0,0 +1,25 @@
+obj-y := timer.o
+
+ifdef CONFIG_FUNCTION_TRACER
+CFLAGS_REMOVE_timer.o = -pg
+endif
+
+obj-$(CONFIG_PLATFORM_NOINTC) += nointc.o
+obj-$(CONFIG_PLATFORM_INTC) += intc.o
+obj-$(CONFIG_PLATFORM_AMIC) += amic.o
+
+ifeq ("$(CONFIG_PLATFORM_AHBDMA)", "y")
+ obj-y += dmad_intc.o dmad.o
+else
+ ifeq ("$(CONFIG_PLATFORM_APBDMA)", "y")
+ obj-y += dmad_intc.o dmad.o
+ endif
+endif
+
+obj-$(CONFIG_PCI) += ftpci.o pci_intc.o
+
+obj-$(CONFIG_PLAT_VEP) += vep/
+obj-$(CONFIG_PLAT_AG101) += ag101/
+obj-$(CONFIG_PLAT_AG102) += ag102/
+obj-$(CONFIG_PLAT_AG101P) += ag101p/
+obj-$(CONFIG_PLAT_QEMU) += qemu/
diff -Nur linux-3.4.113.orig/arch/nds32/platforms/nointc.c linux-3.4.113/arch/nds32/platforms/nointc.c
--- linux-3.4.113.orig/arch/nds32/platforms/nointc.c 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/platforms/nointc.c 2016-12-01 20:59:24.380613830 +0100
@@ -0,0 +1,134 @@
+/*
+ * linux/arch/nds32/platforms/intc.c
+ *
+ * Faraday FTINTC010 Master Interrupt Controller Device Driver Implementation
+ *
+ * Copyright (C) 2005 Faraday Corp. (http://www.faraday-tech.com)
+ * Copyright (C) 2009 Andes Technology Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include <linux/irq.h>
+
+static void nointc_ack_irq(struct irq_data *data)
+{
+ SET_INT_PEND2(1 << data->irq);
+#if 0
+ asm volatile ("mtsr %0, $INT_PEND2\n\t"
+ "dsb\n\t"::"r" (1 << data->irq));
+#endif
+#if 0
+ asm volatile ("mfsr $r6, $INT_MASK2\n\t"
+ "and $r6, $r6,%0\n\t"
+ "mtsr $r6, $INT_MASK2\n\t"
+ "dsb\n\t"::"r" (~(1 << data->irq)):"$r6");
+#endif
+}
+
+static void nointc_mask_irq(struct irq_data *data)
+{
+ unsigned long int_mask2 = GET_INT_MASK2();
+ SET_INT_MASK2(int_mask2 & (~(1 << data->irq)));
+#if 0
+ asm volatile ("mfsr $r6, $INT_MASK2\n\t"
+ "and $r6, $r6,%0\n\t"
+ "mtsr $r6, $INT_MASK2\n\t"
+ "dsb\n\t"::"r" (~(1 << data->irq)):"$r6");
+#endif
+}
+
+static void nointc_mask_ack_irq(struct irq_data *data)
+{
+ unsigned long int_mask2 = GET_INT_MASK2();
+ SET_INT_MASK2(int_mask2 & (~(1 << data->irq)));
+ SET_INT_PEND2(1 << data->irq);
+#if 0
+ asm volatile ("not $r7, %0\n\t"
+ "mfsr $r6, $INT_MASK2\n\t"
+ "and $r6, $r6, $r7\n\t"
+ "mtsr $r6, $INT_MASK2\n\t"
+ "mtsr %0, $INT_PEND2\n\t"
+ "dsb\n\t"::"r" (1 << data->irq):"$r6", "$r7");
+#endif
+
+}
+
+static void nointc_unmask_irq(struct irq_data *data)
+{
+ unsigned long int_mask2 = GET_INT_MASK2();
+ SET_INT_MASK2(int_mask2 | (1 << data->irq));
+#if 0
+ asm volatile ("mfsr $r6, $INT_MASK2\n\t"
+ "or $r6, $r6,%0\n\t"
+ "mtsr $r6, $INT_MASK2\n\t"
+ "dsb\n\t"::"r" (1 << data->irq):"$r6");
+#endif
+}
+
+static int nointc_set_type(struct irq_data *data, unsigned int flow_type)
+{
+ printk(KERN_WARNING "interrupt type is not configurable\n");
+ return 0;
+}
+
+static struct irq_chip nointc_chip = {
+
+ .irq_ack = nointc_ack_irq,
+ .irq_mask = nointc_mask_irq,
+ .irq_mask_ack = nointc_mask_ack_irq,
+ .irq_unmask = nointc_unmask_irq,
+ .irq_set_type = nointc_set_type,
+};
+
+static unsigned int __initdata nivic_map[6] = { 6, 2, 10, 16, 24, 32 };
+
+void __init nointc_init_irq(void)
+{
+ int i;
+ unsigned long int_trigger_type, int_vec_base, nivic;
+
+ int_vec_base = GET_IVB();
+
+#if 0
+ asm volatile ("mfsr %0, $IVB\n":"=r" (int_vec_base));
+#endif
+
+ if (((int_vec_base & IVB_mskIVIC_VER) >> IVB_offIVIC_VER) == 0) {
+ panic("Unable to use NOINTC option to boot on this cpu\n");
+ }
+
+ nivic = (int_vec_base & IVB_mskNIVIC) >> IVB_offNIVIC;
+ if (nivic >= (sizeof nivic_map / sizeof nivic_map[0])) {
+ panic
+ ("The number of input for IVIC Controller is not supported on this cpu\n");
+ }
+ nivic = nivic_map[nivic];
+
+ int_trigger_type = GET_INT_TRIGGER();
+#if 0
+ asm volatile ("mfsr %0, $INT_TRIGGER\n":"=r" (int_trigger_type));
+#endif
+
+ for (i = 0; i < nivic; i++) {
+ irq_set_chip(i, &nointc_chip);
+ if (int_trigger_type & (1 << i))
+ /* edge-triggered */
+ irq_set_handler(i, handle_edge_irq);
+ else
+ /* level-triggered */
+ irq_set_handler(i, handle_level_irq);
+ }
+}
diff -Nur linux-3.4.113.orig/arch/nds32/platforms/pci_intc.c linux-3.4.113/arch/nds32/platforms/pci_intc.c
--- linux-3.4.113.orig/arch/nds32/platforms/pci_intc.c 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/platforms/pci_intc.c 2016-12-01 20:59:24.380613830 +0100
@@ -0,0 +1,93 @@
+/*
+ * linux/arch/nds32/platforms/pci_intc.c
+ *
+ * Faraday PCI Bridge Interrupt Process Driver Implementation
+ *
+ * Copyright (C) 2005 Faraday Corp. (http://www.faraday-tech.com)
+ * Copyright (C) 2008 Andes Technology Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ *
+ * ChangeLog
+ *
+ * Luke Lee 09/15/2005 Created.
+ * Luke Lee 09/27/2005 Fixed for parent chip registration and notification.
+ * Peter Liao 09/28/2005 Port for PCI IP
+ */
+
+#include <linux/irq.h>
+#include <linux/interrupt.h>
+#include <linux/ioport.h>
+#include <asm/io.h>
+
+#include <asm/spec.h>
+#include <asm/ftpci.h>
+
+#define IPMODULE PCIC
+#define IPNAME FPCI010
+
+/*
+ * Level trigger IRQ chip methods
+ */
+
+static void intc_ftpci100_level_ack_irq(unsigned int irq)
+{
+ ftpci_clear_irq(irq - PLATFORM_PCI_IRQ_BASE);
+}
+
+static void intc_ftpci100_level_mask_irq(unsigned int irq)
+{
+ ftpci_mask_irq(irq - PLATFORM_PCI_IRQ_BASE);
+}
+
+static void intc_ftpci100_level_unmask_irq(unsigned int irq)
+{
+ ftpci_unmask_irq(irq - PLATFORM_PCI_IRQ_BASE);
+}
+
+static struct irq_chip intc_ftpci100_level_chip = {
+ .ack = intc_ftpci100_level_ack_irq,
+ .mask = intc_ftpci100_level_mask_irq,
+ .unmask = intc_ftpci100_level_unmask_irq,
+};
+
+void pci_irq_rounter(unsigned int irq, struct irq_desc *desc)
+{
+ int pci_irq;
+ struct irq_desc *pci_desc;
+
+ desc->chip->mask(irq);
+ desc->chip->ack(irq);
+
+ pci_irq = ftpci_get_irq();
+ if (pci_irq >= 0) {
+ pci_irq += PCIC_FTPCI100_IRQ0;
+ pci_desc = irq_desc + pci_irq;
+ pci_desc->handle_irq(pci_irq, pci_desc);
+ }
+
+ desc->chip->unmask(irq);
+}
+
+int __init intc_ftpci100_init_irq(void)
+{
+ int i;
+
+ /* Register all IRQ */
+ for (i = PCIC_FTPCI100_IRQ0;
+ i < PCIC_FTPCI100_IRQ0 + PCIC_FTPCI100_IRQ_COUNT; i++) {
+ // level trigger
+ set_irq_chip(i, &intc_ftpci100_level_chip);
+ set_irq_handler(i, handle_level_irq);
+ }
+#ifndef CONFIG_PLAT_AG101
+ set_irq_chained_handler(PLATFORM_PCI_IRQ, pci_irq_rounter);
+#endif
+
+ return 0;
+}
+
+subsys_initcall(intc_ftpci100_init_irq);
diff -Nur linux-3.4.113.orig/arch/nds32/platforms/qemu/devices.c linux-3.4.113/arch/nds32/platforms/qemu/devices.c
--- linux-3.4.113.orig/arch/nds32/platforms/qemu/devices.c 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/platforms/qemu/devices.c 2016-12-01 20:59:24.380613830 +0100
@@ -0,0 +1,124 @@
+#include <linux/serial_8250.h>
+#include <asm/mach-types.h>
+#include <asm/sizes.h>
+#include <asm/mach/arch.h>
+#include <asm/mach/map.h>
+#include <asm/spec.h>
+#include <asm/intc.h>
+#include <asm/timer.h>
+
+const struct map_desc platform_io_desc[] __initdata = {
+ {UART0_VA_BASE, UART0_PA_BASE, PAGE_SIZE, MT_DEVICE_NCB},
+ {UART1_VA_BASE, UART1_PA_BASE, PAGE_SIZE, MT_DEVICE_NCB},
+ {INTC_FTINTC010_0_VA_BASE, INTC_FTINTC010_0_PA_BASE, PAGE_SIZE,
+ MT_DEVICE_NCB},
+ {TIMER_FTTMR010_0_VA_BASE, TIMER_FTTMR010_0_PA_BASE, PAGE_SIZE,
+ MT_DEVICE_NCB},
+ {SSP_FTSSP010_0_VA_BASE, SSP_FTSSP010_0_PA_BASE, PAGE_SIZE,
+ MT_DEVICE_NCB},
+ {PMU_FTPMU010_0_VA_BASE, PMU_FTPMU010_0_PA_BASE, PAGE_SIZE,
+ MT_DEVICE_NCB},
+ {MAC_FTMAC100_0_VA_BASE, MAC_FTMAC100_0_PA_BASE, PAGE_SIZE,
+ MT_DEVICE_NCB},
+ {SDC_FTSDC010_0_VA_BASE, SDC_FTSDC010_0_PA_BASE, PAGE_SIZE,
+ MT_DEVICE_NCB},
+ {RTC_FTRTC010_0_VA_BASE, RTC_FTRTC010_0_PA_BASE, PAGE_SIZE,
+ MT_DEVICE_NCB},
+ {WDT_FTWDT010_0_VA_BASE, WDT_FTWDT010_0_PA_BASE, PAGE_SIZE,
+ MT_DEVICE_NCB},
+ {GPIO_FTGPIO010_0_VA_BASE, GPIO_FTGPIO010_0_PA_BASE, PAGE_SIZE,
+ MT_DEVICE_NCB},
+ {CFC_FTCFC010_0_VA_BASE, CFC_FTCFC010_0_PA_BASE, PAGE_SIZE,
+ MT_DEVICE_NCB},
+ {LCD_FTLCDC100_0_VA_BASE, LCD_FTLCDC100_0_PA_BASE, PAGE_SIZE,
+ MT_DEVICE_NCB},
+ {I2C_FTI2C010_0_VA_BASE, I2C_FTI2C010_0_PA_BASE, PAGE_SIZE,
+ MT_DEVICE_NCB},
+ {DMAC_FTDMAC020_0_VA_BASE, DMAC_FTDMAC020_0_PA_BASE, PAGE_SIZE,
+ MT_DEVICE_NCB},
+ {APBBRG_FTAPBBRG020S_0_VA_BASE, APBBRG_FTAPBBRG020S_0_PA_BASE,
+ PAGE_SIZE, MT_DEVICE_NCB},
+ {PCIIO_0_VA_BASE, PCIIO_0_PA_BASE, 0x000FF000, MT_DEVICE_NCB},
+ {PCIC_FTPCI100_0_VA_BASE, PCIC_FTPCI100_0_PA_BASE, PAGE_SIZE,
+ MT_DEVICE_NCB},
+ {LED_VA_BASE, LED_PA_BASE, PAGE_SIZE, MT_DEVICE_NCB},
+ {SDMC_FTSDMC021_VA_BASE, SDMC_FTSDMC021_PA_BASE, PAGE_SIZE,
+ MT_DEVICE_NCB},
+ {L2CC_VA_BASE, L2CC_PA_BASE, PAGE_SIZE, MT_DEVICE_NCB}
+};
+
+static void __init platform_map_io(void)
+{
+ iotable_init((struct map_desc *)platform_io_desc,
+ ARRAY_SIZE(platform_io_desc));
+}
+
+static struct uart_port uart0 = {
+ .membase = (void __iomem *)UART0_VA_BASE,
+ .irq = UART0_IRQ,
+ .uartclk = CONFIG_UART_CLK,
+ .regshift = 2,
+ .iotype = UPIO_MEM,
+ .flags = UPF_SKIP_TEST | UPF_BOOT_AUTOCONF,
+ .line = 0,
+ .mapbase = UART0_PA_BASE,
+};
+
+static struct uart_port uart1 = {
+ .membase = (void __iomem *)UART1_VA_BASE,
+ .irq = UART1_IRQ,
+ .uartclk = CONFIG_UART_CLK,
+ .regshift = 2,
+ .iotype = UPIO_MEM,
+ .flags = UPF_SKIP_TEST | UPF_BOOT_AUTOCONF,
+ .line = 1,
+ .mapbase = UART1_PA_BASE,
+};
+
+static void __init soc_init(void)
+{
+ early_serial_setup(&uart0);
+ early_serial_setup(&uart1);
+}
+
+static struct resource smc91x_resources[] = {
+ [0] = {
+ .name = "smc91x",
+ .start = 0x92100000,
+ .end = 0x92110000,
+ .flags = IORESOURCE_MEM,
+ },
+ [1] = {
+ .start = 25,
+ .end = 25,
+ .flags = IORESOURCE_IRQ,
+ },
+};
+
+static struct platform_device smc91x_device = {
+ .name = "smc91x",
+ .id = 0,
+ .num_resources = ARRAY_SIZE(smc91x_resources),
+ .resource = smc91x_resources,
+};
+
+static __init int smc_init(void)
+{
+ int ret;
+ ret = platform_device_register(&smc91x_device);
+ if (ret == 0)
+ printk("smc is installed now.\n");
+ else
+ printk("smc failed.\n");
+ return 0;
+}
+
+module_init(smc_init);
+
+MACHINE_START(FARADAY, PLATFORM_NAME)
+ .param_offset = BOOT_PARAMETER_PA_BASE,
+ .map_io = platform_map_io,
+ .init_irq = platform_init_irq,
+ .timer = &platform_timer, /* defined in timer.c */
+ .init_machine = soc_init,
+MACHINE_END
diff -Nur linux-3.4.113.orig/arch/nds32/platforms/qemu/Kconfig linux-3.4.113/arch/nds32/platforms/qemu/Kconfig
--- linux-3.4.113.orig/arch/nds32/platforms/qemu/Kconfig 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/platforms/qemu/Kconfig 2016-12-01 20:59:24.380613830 +0100
@@ -0,0 +1,3 @@
+menu "QEMU Platform Options"
+
+endmenu
diff -Nur linux-3.4.113.orig/arch/nds32/platforms/qemu/Makefile linux-3.4.113/arch/nds32/platforms/qemu/Makefile
--- linux-3.4.113.orig/arch/nds32/platforms/qemu/Makefile 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/platforms/qemu/Makefile 2016-12-01 20:59:24.380613830 +0100
@@ -0,0 +1 @@
+obj-y = devices.o
diff -Nur linux-3.4.113.orig/arch/nds32/platforms/timer.c linux-3.4.113/arch/nds32/platforms/timer.c
--- linux-3.4.113.orig/arch/nds32/platforms/timer.c 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/platforms/timer.c 2016-12-01 20:59:24.380613830 +0100
@@ -0,0 +1,250 @@
+/*
+ * linux/arch/nds32/platforms/timer.c
+ *
+ * Faraday FTTMR010 Timer Device Driver Implementation
+ *
+ * Copyright (C) 2005 Faraday Corp. (http://www.faraday-tech.com)
+ * Copyright (C) 2009 Andes Technology Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
+#include <linux/irq.h>
+#include <linux/clocksource.h>
+#include <linux/clockchips.h>
+
+#include <linux/interrupt.h>
+#include <linux/ioport.h>
+#include <linux/cpufreq.h>
+
+#include <asm/mach/time.h>
+#include <asm/timer.h>
+#include <asm/spec.h>
+
+#define REG32_TMR(x) *(volatile unsigned long *)(TIMER_FTTMR010_VA_BASE + (x))
+#define APB_CLK_IN (AHB_CLK_IN / 2)
+
+static struct resource timer_resource = {
+ .name = "Timer 1~3",
+ .start = TIMER_FTTMR010_VA_BASE,
+ .end = TIMER_FTTMR010_VA_LIMIT,
+};
+
+static inline cycle_t clocksource_read_cycles(struct clocksource *cs)
+{
+ return (cycle_t) REG32_TMR(TIMER3_COUNT);
+}
+
+static void clksrc_fttmr010_resume(struct clocksource *cs)
+{
+ REG32_TMR(TIMER_INTRMASK) |= TM3MATCH1 | TM3MATCH2 | TM3OVERFLOW;
+ REG32_TMR(TIMER_TMCR) |= TM3UPDOWN | TM3ENABLE;
+}
+
+static struct clocksource clksrc_fttmr010 = {
+ .name = "fttmr010_tm1",
+ .rating = 300,
+ .read = clocksource_read_cycles,
+ .mask = CLOCKSOURCE_MASK(32),
+ .shift = 21,
+ .flags = CLOCK_SOURCE_IS_CONTINUOUS,
+ .resume = clksrc_fttmr010_resume,
+};
+
+static void __init fttmr010_clocksource_init(void)
+{
+ clksrc_fttmr010.mult =
+ clocksource_hz2mult(APB_CLK_IN, clksrc_fttmr010.shift);
+
+ REG32_TMR(TIMER3_LOAD) = 0;
+ REG32_TMR(TIMER_INTRMASK) |= TM3MATCH1 | TM3MATCH2 | TM3OVERFLOW;
+ REG32_TMR(TIMER_TMCR) |= TM3UPDOWN | TM3ENABLE;
+ if (clocksource_register(&clksrc_fttmr010))
+ printk(KERN_ERR "Error: failed to register %s\n",
+ clksrc_fttmr010.name);
+}
+
+static int fttmr010_set_next_event(unsigned long cycles,
+ struct clock_event_device *evt)
+{
+ REG32_TMR(TIMER1_LOAD) = cycles;
+ return 0;
+}
+
+static void fttmr010_set_mode(enum clock_event_mode mode,
+ struct clock_event_device *evt)
+{
+ switch (mode) {
+ case CLOCK_EVT_MODE_ONESHOT:
+ REG32_TMR(TIMER1_LOAD) = 0xffffffff;
+ REG32_TMR(TIMER_TMCR) |= TM1ENABLE;
+ break;
+
+ case CLOCK_EVT_MODE_PERIODIC:
+ REG32_TMR(TIMER1_COUNT) = APB_CLK_IN / HZ - 1;
+ REG32_TMR(TIMER1_LOAD) = APB_CLK_IN / HZ - 1;
+ REG32_TMR(TIMER_TMCR) |= TM1ENABLE;
+ break;
+ case CLOCK_EVT_MODE_UNUSED:
+ break;
+ case CLOCK_EVT_MODE_SHUTDOWN:
+ REG32_TMR(TIMER_TMCR) &= ~TM1ENABLE;
+ break;
+ case CLOCK_EVT_MODE_RESUME:
+ REG32_TMR(TIMER_INTRMASK) |= TM1MATCH1 | TM1MATCH2;
+ REG32_TMR(TIMER_TMCR) |= TM1ENABLE | TM1OFENABLE;
+ break;
+ }
+}
+
+static struct clock_event_device clockevent_fttmr010 = {
+ .name = "fttmr010_tm1",
+ .features = CLOCK_EVT_FEAT_ONESHOT | CLOCK_EVT_FEAT_PERIODIC,
+ .shift = 32,
+ .cpumask = cpu_all_mask,
+ .set_next_event = fttmr010_set_next_event,
+ .set_mode = fttmr010_set_mode,
+};
+
+static irqreturn_t timer1_interrupt(int irq, void *dev_id)
+{
+ struct clock_event_device *evt = dev_id;
+
+ REG32_TMR(TIMER_INTRSTATE) = TM1MATCH1 | TM1MATCH2 | TM1OVERFLOW;
+
+ evt->event_handler(evt);
+
+ return IRQ_HANDLED;
+}
+
+static struct irqaction timer1_irq = {
+ .name = "Timer Tick",
+ .flags = IRQF_DISABLED | IRQF_TIMER | IRQF_IRQPOLL,
+ .handler = timer1_interrupt,
+ .dev_id = &clockevent_fttmr010
+};
+
+static void __init fttmr010_clockevent_init(void)
+{
+ clockevent_fttmr010.mult =
+ div_sc(APB_CLK_IN, NSEC_PER_SEC, clockevent_fttmr010.shift);
+ clockevent_fttmr010.max_delta_ns =
+ clockevent_delta2ns(0xffffffff, &clockevent_fttmr010);
+ clockevent_fttmr010.min_delta_ns =
+ clockevent_delta2ns(3, &clockevent_fttmr010);
+
+ clockevents_register_device(&clockevent_fttmr010);
+ setup_irq(TIMER_FTTMR010_IRQ0, &timer1_irq);
+}
+
+static void fttmr010_resume(void)
+{
+}
+
+#ifdef CONFIG_CPU_FREQ
+void ag102_calc_ahb_clk(void);
+static int fttmr010_cpufreq_notifier(struct notifier_block *nb,
+ unsigned long val, void *data)
+{
+ if (val == CPUFREQ_POSTCHANGE) {
+
+ unsigned long flags;
+#ifdef CONFIG_PLAT_AG102
+ ag102_calc_ahb_clk();
+#endif
+ local_irq_save(flags);
+
+ clocksource_unregister(&clksrc_fttmr010);
+
+ clksrc_fttmr010.mult =
+ clocksource_hz2mult(APB_CLK_IN, clksrc_fttmr010.shift);
+#ifdef CONFIG_PLAT_AG101
+ clksrc_fttmr010.mult_orig =
+ clocksource_hz2mult(APB_CLK_IN, clksrc_fttmr010.shift);
+#endif
+
+ if (clocksource_register(&clksrc_fttmr010))
+ printk(KERN_ERR "Error: failed to re-register %s\n",
+ clksrc_fttmr010.name);
+ else
+ printk("Re-register clock source %s\n",
+ clksrc_fttmr010.name);
+
+ local_irq_restore(flags);
+
+ clockevent_fttmr010.mult =
+ div_sc(APB_CLK_IN, NSEC_PER_SEC, clockevent_fttmr010.shift);
+
+#ifdef CONFIG_PLAT_AG102
+ printk("Add timer clock modifier...\n");
+ fttmr010_set_mode(CLOCK_EVT_MODE_PERIODIC, 0);
+#endif
+ }
+
+ return 0;
+}
+
+static struct notifier_block fttmr010_cpufreq_notifier_block = {
+ .notifier_call = fttmr010_cpufreq_notifier
+};
+
+static int __init fttmr010_init_cpufreq(void)
+{
+ if (cpufreq_register_notifier(&fttmr010_cpufreq_notifier_block,
+ CPUFREQ_TRANSITION_NOTIFIER))
+ printk("fttmr010: Failed to setup cpufreq notifier\n");
+
+ return 0;
+}
+
+core_initcall(fttmr010_init_cpufreq);
+#endif
+
+static int clksrc_init;
+static void __init fttmr010_init(void)
+{
+ request_resource(&ioport_resource, &timer_resource);
+
+ printk
+ ("FTTMR010 timer 1 installed on IRQ %d, with clock %d at %d HZ.\r\n",
+ TIMER_FTTMR010_IRQ0, APB_CLK_IN, HZ);
+
+ REG32_TMR(TIMER_TMCR) &=
+ ~(TM1ENABLE | TM1CLOCK | TM1OFENABLE | TM1UPDOWN);
+ REG32_TMR(TIMER_INTRMASK) |= TM1MATCH1 | TM1MATCH2;
+ REG32_TMR(TIMER_TMCR) |= TM1OFENABLE;
+
+ fttmr010_clocksource_init();
+ fttmr010_clockevent_init();
+ clksrc_init = 1;
+}
+
+struct sys_timer platform_timer = {
+ .init = fttmr010_init,
+ .resume = fttmr010_resume,
+};
+
+unsigned long long sched_clock(void)
+{
+ if (clksrc_init)
+ return
+ clocksource_cyc2ns(clocksource_read_cycles
+ (&clksrc_fttmr010), clksrc_fttmr010.mult,
+ clksrc_fttmr010.shift);
+ else
+ return (unsigned long long)(jiffies - INITIAL_JIFFIES)
+ * (NSEC_PER_SEC / HZ);
+}
diff -Nur linux-3.4.113.orig/arch/nds32/platforms/vep/devices.c linux-3.4.113/arch/nds32/platforms/vep/devices.c
--- linux-3.4.113.orig/arch/nds32/platforms/vep/devices.c 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/platforms/vep/devices.c 2016-12-01 20:59:24.380613830 +0100
@@ -0,0 +1,83 @@
+#include <linux/serial_8250.h>
+#include <asm/mach-types.h>
+#include <asm/sizes.h>
+#include <asm/mach/arch.h>
+#include <asm/mach/map.h>
+#include <asm/spec.h>
+#include <asm/intc.h>
+#include <asm/timer.h>
+
+const struct map_desc platform_io_desc[] __initdata = {
+ {UART0_VA_BASE, UART0_PA_BASE, PAGE_SIZE, MT_DEVICE_NCB},
+ {UART1_VA_BASE, UART1_PA_BASE, PAGE_SIZE, MT_DEVICE_NCB},
+ {INTC_FTINTC010_0_VA_BASE, INTC_FTINTC010_0_PA_BASE, PAGE_SIZE,
+ MT_DEVICE_NCB},
+ {TIMER_FTTMR010_0_VA_BASE, TIMER_FTTMR010_0_PA_BASE, PAGE_SIZE,
+ MT_DEVICE_NCB},
+ {SSP_FTSSP010_0_VA_BASE, SSP_FTSSP010_0_PA_BASE, PAGE_SIZE,
+ MT_DEVICE_NCB},
+ {PMU_FTPMU010_0_VA_BASE, PMU_FTPMU010_0_PA_BASE, PAGE_SIZE,
+ MT_DEVICE_NCB},
+ {MAC_FTMAC100_0_VA_BASE, MAC_FTMAC100_0_PA_BASE, PAGE_SIZE,
+ MT_DEVICE_NCB},
+ {SDC_FTSDC010_0_VA_BASE, SDC_FTSDC010_0_PA_BASE, PAGE_SIZE,
+ MT_DEVICE_NCB},
+ {RTC_FTRTC010_0_VA_BASE, RTC_FTRTC010_0_PA_BASE, PAGE_SIZE,
+ MT_DEVICE_NCB},
+ {WDT_FTWDT010_0_VA_BASE, WDT_FTWDT010_0_PA_BASE, PAGE_SIZE,
+ MT_DEVICE_NCB},
+ {GPIO_FTGPIO010_0_VA_BASE, GPIO_FTGPIO010_0_PA_BASE, PAGE_SIZE,
+ MT_DEVICE_NCB},
+ {CFC_FTCFC010_0_VA_BASE, CFC_FTCFC010_0_PA_BASE, PAGE_SIZE,
+ MT_DEVICE_NCB},
+ {LCD_FTLCDC100_0_VA_BASE, LCD_FTLCDC100_0_PA_BASE, PAGE_SIZE,
+ MT_DEVICE_NCB},
+ {I2C_FTI2C010_0_VA_BASE, I2C_FTI2C010_0_PA_BASE, PAGE_SIZE,
+ MT_DEVICE_NCB},
+ {DMAC_FTDMAC020_0_VA_BASE, DMAC_FTDMAC020_0_PA_BASE, PAGE_SIZE,
+ MT_DEVICE_NCB},
+ {APBBRG_FTAPBBRG020S_0_VA_BASE, APBBRG_FTAPBBRG020S_0_PA_BASE,
+ PAGE_SIZE, MT_DEVICE_NCB},
+ {LED_VA_BASE, LED_PA_BASE, PAGE_SIZE, MT_DEVICE_NCB},
+ {SDMC_FTSDMC021_VA_BASE, SDMC_FTSDMC021_PA_BASE, PAGE_SIZE,
+ MT_DEVICE_NCB},
+ {L2CC_VA_BASE, L2CC_PA_BASE, PAGE_SIZE, MT_DEVICE_NCB}
+};
+
+static void __init platform_map_io(void)
+{
+ iotable_init((struct map_desc *)platform_io_desc,
+ ARRAY_SIZE(platform_io_desc));
+}
+
+static struct uart_port uart0 = {
+ .membase = (void __iomem *)UART0_VA_BASE,
+ .irq = UART0_IRQ,
+ .uartclk = CONFIG_UART_CLK,
+ .regshift = 2,
+ .iotype = UPIO_MEM,
+ .flags = UPF_SKIP_TEST | UPF_BOOT_AUTOCONF,
+ .line = 0,
+ .mapbase = UART0_PA_BASE,
+};
+
+static struct uart_port uart1 = {
+ .membase = (void __iomem *)UART1_VA_BASE,
+ .irq = UART1_IRQ,
+ .uartclk = CONFIG_UART_CLK,
+ .regshift = 2,
+ .iotype = UPIO_MEM,
+ .flags = UPF_SKIP_TEST | UPF_BOOT_AUTOCONF,
+ .line = 1,
+ .mapbase = UART1_PA_BASE,
+};
+
+static void __init soc_init(void)
+{
+ early_serial_setup(&uart0);
+ early_serial_setup(&uart1);
+}
+
+MACHINE_START(FARADAY, PLATFORM_NAME)
+ .param_offset = BOOT_PARAMETER_PA_BASE,.map_io = platform_map_io,.init_irq = platform_init_irq,.timer = &platform_timer, /* defined in timer.c */
+ .init_machine = soc_init, MACHINE_END
diff -Nur linux-3.4.113.orig/arch/nds32/platforms/vep/Kconfig linux-3.4.113/arch/nds32/platforms/vep/Kconfig
--- linux-3.4.113.orig/arch/nds32/platforms/vep/Kconfig 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/platforms/vep/Kconfig 2016-12-01 20:59:24.380613830 +0100
@@ -0,0 +1,7 @@
+menu "VEP Platform Options"
+
+config CACHE_L2
+ bool "Support L2 cache"
+ default n
+
+endmenu
diff -Nur linux-3.4.113.orig/arch/nds32/platforms/vep/Makefile linux-3.4.113/arch/nds32/platforms/vep/Makefile
--- linux-3.4.113.orig/arch/nds32/platforms/vep/Makefile 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/arch/nds32/platforms/vep/Makefile 2016-12-01 20:59:24.380613830 +0100
@@ -0,0 +1 @@
+obj-y = devices.o
diff -Nur linux-3.4.113.orig/build_linux.sh linux-3.4.113/build_linux.sh
--- linux-3.4.113.orig/build_linux.sh 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/build_linux.sh 2016-12-01 20:59:24.380613830 +0100
@@ -0,0 +1,202 @@
+#!/bin/sh
+
+export ARCH=nds32
+
+print_help()
+{
+ echo "Usage: <platform> [platform_defconfig] [--bootm] [--ramdisk=<ramdisk absolute path>]"
+ echo "Stop Building."
+ exit
+}
+
+BUILDBOOTM=0
+BUILDBOOTPIMAGE=0
+BUILDHEADERS=0
+
+case "$1" in
+ qemu)
+ TARGET=qemu_defconfig
+ IMAGE=qemu
+ export CROSS_COMPILE=nds32le-linux-
+ echo "Building $IMAGE kernel."
+ ;;
+ vep-be)
+ TARGET=vep-be_defconfig
+ IMAGE=vep-be
+ export CROSS_COMPILE=nds32be-linux-
+ echo "Building $IMAGE kernel."
+ ;;
+ vep-le)
+ TARGET=vep-le_defconfig
+ IMAGE=vep-le
+ export CROSS_COMPILE=nds32le-linux-
+ echo "Building $IMAGE kernel."
+ ;;
+ xc5)
+ TARGET=xc5_defconfig
+ IMAGE=xc5
+ export CROSS_COMPILE=nds32le-linux-
+ echo "Building $IMAGE kernel."
+ ;;
+ xc5_8k)
+ TARGET=xc5_8k_defconfig
+ IMAGE=xc5_8k
+ export CROSS_COMPILE=nds32le-linux-
+ echo "Building $IMAGE kernel."
+ ;;
+ ag101a0)
+ TARGET=ag101a0_defconfig
+ IMAGE=ag101a0
+ export CROSS_COMPILE=nds32le-linux-
+ echo "Building $IMAGE kernel."
+ ;;
+ ag101b0)
+ TARGET=ag101b0_defconfig
+ IMAGE=ag101b0
+ export CROSS_COMPILE=nds32le-linux-
+ echo "Building $IMAGE kernel."
+ ;;
+ ag102)
+ TARGET=ag102_defconfig
+ IMAGE=ag102
+ export CROSS_COMPILE=nds32le-linux-
+ echo "Building $IMAGE kernel."
+ ;;
+ u200)
+ TARGET=u200_defconfig
+ IMAGE=u200
+ export CROSS_COMPILE=nds32le-linux-
+ echo "Building $IMAGE kernel."
+ ;;
+ xc5-qa)
+ TARGET=xc5-qa_defconfig
+ IMAGE=xc5-qa
+ export CROSS_COMPILE=nds32le-linux-
+ echo "Building $IMAGE kernel."
+ ;;
+ ag101-qa)
+ TARGET=ag101-qa_defconfig
+ IMAGE=ag101-qa
+ export CROSS_COMPILE=nds32le-linux-
+ echo "Building $IMAGE kernel."
+ ;;
+ *)
+ if [ $# = 1 ]; then
+ echo "No defconfig is given."
+ print_help
+ fi
+ if [ ! -e $2 ]; then
+ echo "Given defconfig is not exist."
+ print_help
+ elif [ ! -f $2 ]; then
+ echo "Given defconfig is not a file."
+ print_help
+ elif [ ! -s $2 ]; then
+ echo "Given defconfig is size 0."
+ print_help
+ elif [ ! -r $2 ]; then
+ echo "Given defconfig has no read attribute."
+ print_help
+ fi
+ TARGET=none
+ IMAGE=$1
+ export CROSS_COMPILE=nds32le-linux-
+ echo "Building $IMAGE kernel."
+esac
+
+ZIMAGE="$IMAGE"_zImage
+VMLINUZ="$IMAGE"_vmlinuz
+VMLINUX="$IMAGE"_vmlinux
+BOOTPIMAGE="$IMAGE"_bootpImage
+BOOTP="$IMAGE"_bootp
+BOOTM="$IMAGE"_bootm
+
+for ARG in $@; do
+ if [ $ARG = $1 ]; then
+ continue
+ fi
+
+ if [ $ARG = $2 ]; then
+ if [ $TARGET = "none" ]; then
+ continue
+ fi
+ fi
+
+ case "$ARG" in
+
+ --bootm)
+ BUILDBOOTM=1
+ ;;
+
+ --ramdisk=*)
+ BUILDBOOTPIMAGE=1
+ RAMDISK=${ARG#*=}
+ if [ ! -e $RAMDISK ]; then
+ echo "Given ramdisk is not exist."
+ print_help
+ elif [ ! -f $RAMDISK ]; then
+ echo "Given ramdisk is not a file."
+ print_help
+ elif [ ! -s $RAMDISK ]; then
+ echo "Given ramdisk is size 0."
+ print_help
+ elif [ ! -r $RAMDISK ]; then
+ echo "Given ramdisk has no read attribute."
+ print_help
+ fi
+ ;;
+# --headers)
+# BUILDHEADERS=1
+# git apply ../linux-2.6-patch/headers.patch
+# echo "Exporting kernel headers."
+# ;;
+ *)
+ print_help
+ esac
+done
+
+if [ "$OSTYPE" = "cygwin" ]; then
+ HOST_LOADLIBES=-lintl\ -lcurses
+fi
+export HOST_LOADLIBES
+
+which ${CROSS_COMPILE}gcc &> /dev/null || export CROSS_COMPILE=nds32-elf-
+
+make mrproper | tee $IMAGE.log
+if [ $TARGET != "none" ]; then
+ make $TARGET| tee -a $IMAGE.log
+else
+ cp $2 .config
+fi
+
+if [ $BUILDHEADERS = 1 ]; then
+ make dep | tee -a $IMAGE.log
+ make headers_install | tee -a $IMAGE.log
+else
+ make | tee -a $IMAGE.log
+
+ cp arch/nds32/boot/zImage ./$ZIMAGE | tee -a $IMAGE.log
+ cp arch/nds32/boot/compressed/vmlinux ./$VMLINUZ | tee -a $IMAGE.log
+ cp ./vmlinux ./$VMLINUX | tee -a $IMAGE.log
+
+ if [ $BUILDBOOTPIMAGE = 1 ]; then
+ make bootpImage INITRD=$RAMDISK | tee -a $IMAGE.log
+ cp arch/nds32/boot/bootpImage ./$BOOTPIMAGE | tee -a $IMAGE.log
+ cp arch/nds32/boot/bootp/bootp ./$BOOTP | tee -a $IMAGE.log
+ fi
+
+ if [ $BUILDBOOTM = 1 ]; then
+ if [ -e "../u-boot/tools/mkimage" ]; then
+ ../u-boot/tools/mkimage \
+ -A nds32 \
+ -O linux \
+ -T kernel \
+ -C none \
+ -a 0x500000 \
+ -e 0x500040 \
+ -d ./arch/nds32/boot/zImage $BOOTM | tee -a $IMAGE.log
+ else
+ echo "Error: ../u-boot/tools/mkimage not found" | tee -a $IMAGE.log
+ fi
+ fi
+fi
diff -Nur linux-3.4.113.orig/drivers/block/ftcfc010.c linux-3.4.113/drivers/block/ftcfc010.c
--- linux-3.4.113.orig/drivers/block/ftcfc010.c 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/drivers/block/ftcfc010.c 2016-12-01 20:59:24.380613830 +0100
@@ -0,0 +1,1299 @@
+/* drivers/block/CPESD/ftsdc010.c
+ *******************************************************************************
+ * Faraday FTSDC010 Device Driver
+ *
+ * Copyright (C) 2005 Faraday Corp. (http://www.faraday-tech.com)
+ *
+ * All Rights Reserved
+ *
+ * Porting to Linux 2.6 on 20050815
+ * Author: Chris Lee, I-Jui Sung, Peter Liao (support APB DMA)
+ * Version: 0.2
+ * History:
+ * 0.1 new creation
+ * 0.2 Porting to meet the style of linux dma
+ * 0.3 modify dma usage to virtual irq of dma interrupt
+ * 0.4 (20050701) Improve r/w performance
+ * 0.5 Porting to Linux 2.6 and replace busy_loop checking with timer's timeout
+ * Todo:
+ *******************************************************************************
+ */
+
+#define DEBUG_OFF 0
+
+#define DEBUG( enable, tagged, ...) \
+do{ \
+ if( enable){ \
+ if( tagged) \
+ printk( "[ %30s() ] ", __func__); \
+ printk( __VA_ARGS__); \
+ } \
+} while( 0)
+
+#include <linux/interrupt.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/sched.h>
+#include <linux/delay.h>
+#include <linux/init.h>
+#include <linux/ioport.h>
+#include <linux/hdreg.h> /* HDIO_GETGEO */
+#include <linux/fs.h>
+#include <linux/blkdev.h>
+#include <linux/buffer_head.h> /* invalidate_bdev */
+#include <linux/bio.h>
+#include <linux/pci.h>
+#include <asm/io.h>
+#include <asm/uaccess.h>
+#include <asm/spec.h>
+#include <asm/dmad.h>
+
+#define IPMODULE CFC
+#define IPNAME FTCFC010
+
+#include "ftcfc010.h"
+
+static int hardsect_size = 512;
+module_param( hardsect_size, int, 0);
+
+static int cf_major = 0; /* must be declared before including blk.h */
+#define DEVICE_NAME "Faraday CFC" /* name for messaging */
+
+#define FTCFC_VA_BASE IP_VA_BASE( 0)
+#define FTCFC_PA_BASE IP_PA_BASE( 0)
+#define FTCFC_IRQ CFC_FTCFC010_IRQ1
+
+#undef CF_DEBUG
+#define CF_DEBUG 0
+struct block_device_operations cf_fops;
+
+typedef struct cf_dev {
+
+ int size; /* device size in sectors */
+ int usage; /* # of users currently */
+ int media_change; /* Flag: media changed? */
+ struct gendisk *gd; /* The gendisk structure */
+ spinlock_t lock; /* For mutual exclusion */
+ struct request_queue *queue; /* The device request queue */
+ int card_state;
+ u32 lba_sec_offset;
+ dmad_chreq ch_req;
+
+} cf_dev_t;
+
+static cf_dev_t *cf_devices;
+static cf_card_t cf_card_info;
+
+static dma_addr_t dma_buf;
+struct completion cf_dma_cmpl;
+
+static uint first_run;
+static uint cf_err_code;
+
+static int g_cf_sectors;
+
+static void SetTransferSize( u32 Addr, u32 Type, u32 OP_Type, u32 Inc_Addr, u32 Transize)
+{
+ u32 ctrl_reg, buf_ctrl_reg;
+ DEBUG( CF_DEBUG, 1, "Enter\n");
+
+ /* set read/write command */
+ while( cfc->HostStatus & BUF_ACTIVE_BIT)
+ ;
+
+ /* Set Transfer size mode to default */
+ cfc->TransSzMode2En = 0;
+
+ /* set 8/16 bits mode */
+ ctrl_reg = cfc->ControlReg;
+
+ if( Transize == SIZE_1_BYTE)
+ ctrl_reg = ( ctrl_reg & ~MODE_BIT) | BYTE_MODE;
+ else
+ ctrl_reg = ( ctrl_reg & ~MODE_BIT) | WORD_MODE;
+
+ DEBUG( CF_DEBUG, 1, "ctrl 1: 0x%08lx\n", ( unsigned long)ctrl_reg);
+ cfc->ControlReg = ctrl_reg;
+
+ /* Write command to buffer */
+ buf_ctrl_reg = cfc->BuffCtrlReg;
+ buf_ctrl_reg = ( buf_ctrl_reg & ~ADR_BIT & ~TYPE_BIT & ~RW_BIT & ~INCADR_BIT & ~TRANS_SIZE_CONTROL_BIT)
+ | Addr | Type | OP_Type | Inc_Addr | ( Transize << TRANS_SIZE_LOC);
+
+ cfc->BuffCtrlReg = buf_ctrl_reg;
+ DEBUG( CF_DEBUG, 1, "buf_ctrl 1: 0x%08lx\n", ( unsigned long)buf_ctrl_reg);
+ DEBUG( CF_DEBUG, 1, "Exit\n");
+}
+
+static void SetTransferSizeEx( u32 Addr, u32 Type, u32 OP_Type, u32 Inc_Addr, u32 Transize)
+{
+ u32 ctrl_reg, buf_ctrl_reg;
+
+ DEBUG( CF_DEBUG, 1, "Enter, SetTransferSizeEx: %d\n", Transize);
+
+ /* set read/write command */
+ while( cfc->HostStatus & BUF_ACTIVE_BIT)
+ ;
+
+ /* Set Transfer size mode to default */
+ cfc->TransSzMode2En = 1;
+
+ /* set 8/16 bits mode */
+ ctrl_reg = cfc->ControlReg;
+
+ if( Transize == SIZE_1_BYTE)
+ ctrl_reg = ( ctrl_reg & ~MODE_BIT) | BYTE_MODE;
+ else
+ ctrl_reg = ( ctrl_reg & ~MODE_BIT) | WORD_MODE;
+
+ cfc->ControlReg = ctrl_reg;
+
+ /* Set Transfer size mode2 reg in FTCFC */
+ cfc->TransSzMode2Cnt = Transize - 1;
+
+ /* Write command to buffer */
+ buf_ctrl_reg = cfc->BuffCtrlReg;
+ buf_ctrl_reg = ( buf_ctrl_reg & ~ADR_BIT & ~TYPE_BIT & ~RW_BIT & ~INCADR_BIT & ~TRANS_SIZE_CONTROL_BIT)
+ | Addr | Type | OP_Type | Inc_Addr;
+
+ cfc->BuffCtrlReg = buf_ctrl_reg;
+
+ DEBUG( CF_DEBUG, 1, "Exit\n");
+}
+
+static void WriteCFCardByte( u32 Addr, u8 Value, u32 Type)
+{
+ while( !( cfc->HostStatus & RDY_nIREQ_BIT))
+ ;
+
+ SetTransferSize( Addr, Type, WRITE_OP, NOINCADR, SIZE_1_BYTE);
+
+ cfc->BufferData = Value;
+
+ while( !( cfc->HostStatus & INTA_BIT))
+ ;
+
+ /* clear command complete status */
+ cfc->HostStatus = INTA_BIT;
+}
+
+static u8 ReadCFCardByte( u32 Addr, u32 Type)
+{
+ u8 ret_data;
+
+ DEBUG( CF_DEBUG, 1, "Enter\n");
+
+ /* wait until ready */
+ while( !( cfc->HostStatus & RDY_nIREQ_BIT))
+ ;
+
+ SetTransferSize( Addr, Type, READ_OP, NOINCADR, SIZE_1_BYTE);
+
+ while( !( cfc->HostStatus & INTA_BIT))
+ ;
+
+ ret_data = cfc->BufferData & 0xff;
+ DEBUG( CF_DEBUG, 1, "data: 0x%02x\n", ret_data);
+
+ while( !( cfc->HostStatus & INTA_BIT))
+ ;
+
+ /* clear command complete status */
+ cfc->HostStatus = INTA_BIT;
+
+ DEBUG( CF_DEBUG, 1, "Exit\n");
+ return ret_data;
+}
+
+/* set Head-cylinder-sector on CF */
+static u32 Translate_Config_HCS( u32 LBA, u32 Sec_count)
+{
+ u8 DriveHead = ( u8)( 0xE0 | ( LBA >> 24)); /* 0xE0 set in LBA mode (bit 7&5 must set to 1) */
+ u8 CylHigh = ( u8)( ( LBA >> 16) & 0xFF);
+ u8 CylLow = ( u8)( ( LBA >> 8) & 0xFF);
+ u8 SecNum = ( u8)( LBA & 0xFF);
+
+ DEBUG( CF_DEBUG, 1, "LBA:%d, %d %d %d %d, count: %d\n",
+ LBA, DriveHead, CylHigh, CylLow, SecNum, Sec_count);
+
+ /* Set CF-ATA reg for start sector */
+ WriteCFCardByte( BLKMEM_DRIVE_REG, DriveHead, COMMON_MEM);
+ WriteCFCardByte( BLKMEM_CYLINDER_HIGH_REG, CylHigh, COMMON_MEM);
+ WriteCFCardByte( BLKMEM_CYLINDER_LOW_REG, CylLow, COMMON_MEM);
+ WriteCFCardByte( BLKMEM_SECTOR_NUMBER_REG, SecNum, COMMON_MEM);
+ WriteCFCardByte( BLKMEM_SECTOR_COUNT_REG, Sec_count, COMMON_MEM);
+
+ return 1;
+}
+
+/*
+ * SetCFCardConfiguration(): ATTRIBUTE MEMORY
+ * Set CF storgae card configuration option register
+ * Conf1 Conf0 Disk Card Mode
+ * ---------------------------------------------------------------
+ * 0 0 Memory Mapped
+ * 0 1 I/O Mapped, any 16 byte system decoded
+ * 1 0 I/O Mapped, 1F0h - 1F7h / 3F6h - 3F7h
+ * 1 1 I/O Mapped, 170h - 177h / 376h - 377h
+ */
+static void SetCFCardMode( u8 Mode)
+{
+ u8 Reg;
+
+ DEBUG( CF_DEBUG, 1, "Enter\n");
+
+ Reg = ReadCFCardByte( CONFIG_OPTION_REG, ATTRIBUTE_MEM); /* CONFIG_OPTION_REG = 0x200 */
+ Reg &= ( LEVLREQ_BIT | SRESET_BIT); /* clear bit0-5 */
+
+ WriteCFCardByte( CONFIG_OPTION_REG, Reg | Mode, ATTRIBUTE_MEM);
+
+ DEBUG( CF_DEBUG, 1, "Exit\n");
+}
+
+/* return 0: fail, 1: success */
+static u32 CF_SendCommand( u16 Cmd)
+{
+ u16 Reg;
+ DEBUG( CF_DEBUG, 1, "Enter\n");
+
+ do{
+ WriteCFCardByte( BLKMEM_COMMAND_REG, Cmd, COMMON_MEM);
+
+ /*
+ * Check status register of Task file register is valid for access
+ * No other bits in status register are valid when BUSY bit is
+ * set to a 1
+ */
+ while( ( ReadCFCardByte( BLKMEM_STATUS_REG, COMMON_MEM) & BUSY_BIT))
+ ;
+
+ Reg = ReadCFCardByte( BLKMEM_STATUS_REG, COMMON_MEM);
+
+ if( Reg & ERR_BIT){
+
+ DEBUG( CF_DEBUG, 1, "Exit ( fail)\n");
+ return 0;
+ }
+
+ } while( !( Reg & RDY_BIT));
+
+ DEBUG( CF_DEBUG, 1, "Exit\n");
+ return 1;
+}
+
+static void CardReset( void)
+{
+ u32 ctrl_reg = cfc->ControlReg;
+ u8 data;
+
+ DEBUG( CF_DEBUG, 1, "Enter\n");
+ cfc->ControlReg = ctrl_reg | RESET_BIT | SIGNAL_ON | PWR_ON; /* set reset bit, float control, power on */
+
+ /* Software must manually clear this bit */
+ mdelay( 100);
+
+ /* clear reset bit */
+ cfc->ControlReg = ( ctrl_reg &~ RESET_BIT) | SIGNAL_ON | PWR_ON | DATA_CMP_INT_MASK | IO_INT_MASK;
+
+ do {
+ data = ReadCFCardByte( BLKMEM_STATUS_REG, COMMON_MEM);
+
+ } while( data & BUSY_BIT); /* please be careful that is locked here */
+
+ data = ReadCFCardByte( BLKMEM_STATUS_REG, COMMON_MEM);
+
+ /* Check if Drive Ready & Drive Seek Complete */
+ if( data == ( RDY_BIT | DSC_BIT))
+ DEBUG( CF_DEBUG, 1, "Reset CF OK, data: 0x%02x\n", ( unsigned char)data);
+ else
+ DEBUG( CF_DEBUG, 1, "Reset CF fail, data: 0x%02x\n", ( unsigned char)data);
+
+ DEBUG( CF_DEBUG, 1, "Exit\n");
+}
+
+static u32 CFCardInit( void)
+{
+ u8 buff[CF_SECTOR_SIZE];
+ u32 i;
+ u32 BSA, BSM, BSIO, BSMOW, BSIORW, apb_ns;
+
+ DEBUG( CF_DEBUG, 1, "Enter\n");
+
+ if( !( cfc->HostStatus & CARD_DETECT_BIT)){
+
+ DEBUG( CF_DEBUG, 1, "No CF Card In Socket\n");
+ return -1;
+ }
+
+ CardReset();
+
+ /* set timer */
+
+ apb_ns = 1000000000 / ( AHB_CLK_IN / 2 ); /* the time of APB clock */
+ BSA = ( 50 + ( apb_ns - ( 50 % apb_ns))) / apb_ns; /* Based on the item tc( R) of BSA */
+ BSMOW = 3;
+ BSIORW = 3;
+ BSM = ( 30 + ( apb_ns - ( 30 % apb_ns))) / apb_ns; /* Base on the item tw( WE) of BSM */
+ BSIO = ( 35 + ( apb_ns - ( 35 % apb_ns))) / apb_ns; /* Base on the item tsuA( IORD,IOWR) of BSIO */
+
+ cfc->TimeCfgReg = ( ( BSMOW & 0x03) << 12)
+ | ( ( BSIORW & 0x03) << 14)
+ | ( ( BSA & 0x0f) << 0)
+ | ( ( BSM & 0x0f) << 4)
+ | ( ( BSIO & 0x0f) << 8);
+
+ SetCFCardMode( CF_MEM_MAP_MODE); /* set memory mode read write access */
+
+ cfc->MultiSector = 0x1; /* enable multi sector read/write */
+
+ /* select drive */
+ WriteCFCardByte( BLKMEM_DRIVE_REG, 0, COMMON_MEM);
+
+ /* identify drive device */
+ if( !CF_SendCommand( ATA_IDENTIFY_DRIVE)){
+
+ DEBUG( CF_DEBUG, 1, "Send Identify Drive command fail\n");
+ return -1;
+ }
+
+ SetTransferSize( BLKMEM_DATA_REG, COMMON_MEM, READ_OP, NOINCADR, SIZE_512_BYTE);
+
+ for( i = 0; i < CF_SECTOR_SIZE / 4; i++){
+
+ while( !( cfc->HostStatus & BUF_DATA_RDY_BIT))
+ ;
+
+ *( ( u32*)&buff[ i*4]) = cfc->BufferData;
+ }
+
+ /* clear command complete status */
+ cfc->HostStatus = INTA_BIT;
+
+ g_cf_sectors = ( ( u32)buff[ 15] << 24) | ( ( u32)buff[ 14] << 16) | ( ( u32)buff[ 17] << 8) | ( ( u32)buff[ 16]);
+ DEBUG( CF_DEBUG, 1, "Card identify - capicity: %d sectors, size: %d kbytes \n", g_cf_sectors, g_cf_sectors >> 1);
+ DEBUG( CF_DEBUG, 1, "Exit\n");
+
+ return 0;
+}
+
+static int cfc_read_block( cf_card_t *info, uint size, uint *buf)
+{
+ /*
+ * Please refer SanDisk SD Manual v1.9 Section 5.1.9.2 ( page 5-76) to set the timeout setting
+ */
+ unsigned long timeout = jiffies + CFC_TIMEOUT_BASE *( ( size + 2048 + 511) >> 9);
+ uint count;
+ u8 data;
+ dmad_chreq *ch_req = (dmad_chreq *)info->private;
+ dmad_drb *drb = 0;
+ u32 drb_size = 0;
+ dma_addr_t addr_iter;
+
+ if( info->DMAEnable){
+
+ DEBUG( CF_DEBUG, 1, "DMA Read - size: %d, buf: 0x%08lx, dma_buf: 0x%08lx\n",
+ size, ( unsigned long)buf, ( unsigned long)dma_buf);
+
+ init_completion(&cf_dma_cmpl);
+
+ if (dma_buf)
+ consistent_sync(__va(dma_buf), size, DMA_FROM_DEVICE);
+ else
+ consistent_sync(buf, size, DMA_FROM_DEVICE);
+
+ //prepare parameter for add dma entry
+ dmad_config_channel_dir(ch_req, DMAD_DIR_A0_TO_A1);
+
+ drb_size = dmad_max_size_per_drb(ch_req);
+
+ if (dma_buf)
+ addr_iter = dma_buf; // given dest phy addr
+ else
+ addr_iter = __pa(buf);
+
+ cfc->ControlReg |= ENDMA_BIT;
+
+ while (size > 0) {
+
+ if (unlikely(0 != dmad_alloc_drb(ch_req, &drb) || (drb == 0))) {
+ printk(KERN_ERR "%s() Failed to allocate dma request block!\n", __func__);
+ return FALSE;
+ }
+
+ drb->addr0 = FTCFC_PA_BASE + 0x10;
+ drb->addr1 = addr_iter;
+
+ if (size <= drb_size) {
+ drb->req_cycle = dmad_bytes_to_cycles(ch_req, size);
+ drb->sync = &cf_dma_cmpl;
+ size = 0;
+ } else {
+ drb->req_cycle = dmad_bytes_to_cycles(ch_req, drb_size);
+ drb->sync = 0;
+ size -= drb_size;
+ addr_iter += drb_size;
+ }
+ //printk(KERN_INFO "%s() size_remain 0x%08x.\n", __func__, size);
+
+ if (unlikely(0 != dmad_submit_request(ch_req, drb, 1))) {
+ printk(KERN_ERR "%s() Failed to submit dma request block!\n", __func__);
+ return FALSE;
+ }
+ }
+
+ if (wait_for_completion_timeout(&cf_dma_cmpl, timeout - jiffies) == 0)
+ printk("%s: read timeout\n", __func__);
+
+ DEBUG( CF_DEBUG, 1, "ControlReg: 0x%08x, HostStatus: 0x%08x, BufCtrl: 0x%08x\n",
+ cfc->ControlReg, cfc->HostStatus, cfc->BuffCtrlReg);
+
+ while( !( cfc->HostStatus & INTA_BIT))
+ ;
+
+ cfc->HostStatus = INTA_BIT;
+
+ /* Stop DMA */
+ cfc->ControlReg &= ~ENDMA_BIT;
+ cfc->ControlReg &= ~MODE_BIT;
+
+ do {
+ data = ReadCFCardByte( BLKMEM_STATUS_REG, COMMON_MEM);
+
+ } while( data & BUSY_BIT);
+ }
+ else {
+ while( size > 0){
+
+ /* read data from FIFO */
+ if( size >= ( CFC_READ_FIFO_LEN << 2))
+ count = CFC_READ_FIFO_LEN;
+ else
+ count = size >> 2;
+
+ /* read data from FIFO */
+ DEBUG( CF_DEBUG, 0, "\n");
+ size -= ( count << 2);
+ }
+ }
+
+ data = ReadCFCardByte( BLKMEM_STATUS_REG, COMMON_MEM);
+
+ while( 1){
+
+ if( data & ERR_BIT){
+
+ DEBUG( CF_DEBUG, 1, "ERROR: ( CFReadSector) CF Read sector error.\n");
+ return FALSE;
+ }
+ else if( data & DWF_BIT){
+
+ DEBUG( CF_DEBUG, 1, "ERROR: ( CFReadSector) CF write fault error.\n");
+ return FALSE;
+ }
+ else if( data & ( RDY_BIT | DSC_BIT)){
+
+ break;
+ }
+ data = ReadCFCardByte( BLKMEM_STATUS_REG, COMMON_MEM);
+ }
+
+ return TRUE;
+}
+
+static int cfc_write_block( cf_card_t *info, uint size, uint *buf)
+{
+ unsigned long timeout = jiffies + CFC_TIMEOUT_BASE * 3 *( ( size + 511) >> 9);
+ uint count;
+ u8 data;
+ dmad_chreq *ch_req = (dmad_chreq *)info->private;
+ dmad_drb *drb = 0;
+ u32 drb_size = 0;
+ dma_addr_t addr_iter;
+
+ if( info->DMAEnable){
+
+ DEBUG( CF_DEBUG, 1, "size: %d, buf: %p) - DMA Write\n", size, buf);
+
+ init_completion(&cf_dma_cmpl);
+
+ if (dma_buf)
+ consistent_sync(__va(dma_buf), size, DMA_TO_DEVICE);
+ else
+ consistent_sync(buf, size, DMA_TO_DEVICE);
+
+ //prepare parameter for add dma entry
+ dmad_config_channel_dir(ch_req, DMAD_DIR_A1_TO_A0);
+
+ drb_size = dmad_max_size_per_drb(ch_req);
+
+ if (dma_buf)
+ addr_iter = dma_buf; // given dest phy addr
+ else
+ addr_iter = __pa(buf);
+
+ cfc->ControlReg |= ENDMA_BIT;
+
+ while (size > 0) {
+
+ if (unlikely(0 != dmad_alloc_drb(ch_req, &drb) || (drb == 0))) {
+ printk(KERN_ERR "%s() Failed to allocate dma request block!\n", __func__);
+ return FALSE;
+ }
+
+ drb->addr0 = FTCFC_PA_BASE + 0x10;
+ drb->addr1 = addr_iter;
+
+ if (size <= drb_size) {
+ drb->req_cycle = dmad_bytes_to_cycles(ch_req, size);
+ drb->sync = &cf_dma_cmpl;
+ size = 0;
+ } else {
+ drb->req_cycle = dmad_bytes_to_cycles(ch_req, drb_size);
+ drb->sync = 0;
+ size -= drb_size;
+ addr_iter += drb_size;
+ }
+ //printk(KERN_INFO "%s() size_remain 0x%08x.\n", __func__, size);
+
+ if (unlikely(0 != dmad_submit_request(ch_req, drb, 1))) {
+ printk(KERN_ERR "%s() Failed to submit dma request block!\n", __func__);
+ return FALSE;
+ }
+ }
+
+ if (wait_for_completion_timeout(&cf_dma_cmpl, timeout - jiffies) == 0)
+ printk("write timeout\n");
+
+ while( !( cfc->HostStatus & INTA_BIT))
+ ;
+
+ cfc->HostStatus = INTA_BIT;
+ /* Stop DMA */
+ cfc->ControlReg &= ~ENDMA_BIT;
+ cfc->ControlReg &= ~MODE_BIT;
+
+ do{
+ data = ReadCFCardByte( BLKMEM_STATUS_REG, COMMON_MEM);
+
+ } while( data & BUSY_BIT);
+ }
+ else {
+ while( size > 0){
+
+ /* write data from FIFO */
+ if( size >= ( CFC_WRITE_FIFO_LEN << 2))
+ count = CFC_WRITE_FIFO_LEN;
+ else
+ count = ( size >> 2);
+
+ size -= ( count << 2);
+ }
+ }
+
+ data = ReadCFCardByte( BLKMEM_STATUS_REG, COMMON_MEM);
+
+ while( 1){
+
+ if( data & ERR_BIT){
+
+ DEBUG( CF_DEBUG, 1, "ERROR: ( CFReadSector) CF Read sector error.\n");
+ return FALSE;
+ }
+ else if( data & DWF_BIT){
+
+ DEBUG( CF_DEBUG, 1, "ERROR: ( CFReadSector) CF write fault error.\n");
+ return FALSE;
+ }
+ else if( data & ( RDY_BIT | DSC_BIT))
+ break;
+
+ data = ReadCFCardByte( BLKMEM_STATUS_REG, COMMON_MEM);
+ }
+ return TRUE;
+}
+
+static int cf_card_insert( cf_card_t *info)
+{
+ DEBUG( CF_DEBUG, 1, "Enter\n");
+ CardReset();
+ DEBUG( CF_DEBUG, 1, "Exit\n");
+
+ return TRUE;
+}
+
+/* Free IRQ and DMA resources */
+static void cf_free( cf_dev_t *dev)
+{
+ release_region( FTCFC_VA_BASE, 0x48); /* return ioport */
+ free_irq( FTCFC_IRQ, dev); /* return Hotswapping irq */
+
+ if (cf_card_info.DMAEnable) {
+#if (CF_DEBUG)
+ if (dev->ch_req.controller == DMAD_DMAC_APB_CORE)
+ printk("%s: free APB dma channel (%d)\n", __func__, dev->ch_req.channel);
+ else
+ printk("%s: free AHB dma channel (%d)\n", __func__, dev->ch_req.channel);
+#endif
+ dmad_channel_free(&dev->ch_req);
+ cf_card_info.DMAEnable = FALSE;
+ }
+}
+
+static int cf_card_remove( cf_card_t *info)
+{
+ cf_err_code = ERR_NO_ERROR;
+
+ info->ActiveState = FALSE;
+ info->WriteProtect = FALSE;
+ info->RCA = 0;
+
+ /* reset host interface controller */
+ cfc->ControlReg |= RESET_BIT;
+
+ mdelay( 100);
+ cfc->ControlReg &= ~RESET_BIT; /* must manually clear reset bit */
+ return TRUE;
+}
+
+irqreturn_t cf_hotswap_interrupt_handler( int irq, void *dev_id)
+{
+ cf_dev_t *dev = dev_id;
+
+ DEBUG( CF_DEBUG, 1, "irq: %d\n", irq);
+
+ /*
+ * When the card is inserted or removed, we must delay a short time to make sure
+ * the SDC_STATUS_REG_CARD_INSERT bit of status register is stable
+ */
+
+ if( cfc->HostStatus & INT_CD_BIT ){
+
+ mdelay( 100); /* wait 0.1 sec for card stable */
+
+ DEBUG( CF_DEBUG, 1, "Card %s\n", cfc->HostStatus & CARD_DETECT_BIT ? "Insert" : "Remove");
+ if( cfc->HostStatus & CARD_DETECT_BIT ){
+
+ dev->card_state = CF_CARD_INSERT;
+ cf_card_insert( &cf_card_info);
+ }
+ else {
+ dev->card_state = CF_CARD_REMOVE;
+ cf_card_remove( &cf_card_info);
+ }
+
+ cfc->HostStatus = INT_CD_BIT;
+ }
+ else{
+ DEBUG( CF_DEBUG, 1, "cfc->HostStatus & INT_CD_BIT == 0\n");
+ }
+
+ DEBUG( CF_DEBUG, 1, "Exit: card state = %d\n", dev->card_state);
+ return IRQ_HANDLED;
+}
+
+int cf_read_multiple_block( cf_card_t *info, uint addr, uint count, uint size, uint timeout, unchar *buf)
+{
+ u8 data;
+
+ DEBUG( CF_DEBUG, 1, "read block addr: 0x%x(%d) sectors: %d\n", addr, addr, count);
+
+ cf_err_code = ERR_NO_ERROR;
+ Translate_Config_HCS( addr, count);
+ CF_SendCommand( ATA_READ_SECTOR);
+
+ do{
+ data = ReadCFCardByte( BLKMEM_STATUS_REG, COMMON_MEM);
+
+ } while( data & BUSY_BIT);
+
+ SetTransferSizeEx( BLKMEM_DATA_REG, COMMON_MEM, READ_OP, NOINCADR, CF_SECTOR_SIZE * count);
+
+ if( first_run == 0){
+
+ udelay( 100000);
+
+ first_run = 1;
+ }
+
+ if( !cfc_read_block( info, CF_SECTOR_SIZE * count, ( uint *)buf))
+ return FALSE;
+
+ if( cf_err_code != ERR_NO_ERROR){
+
+ DEBUG( CF_DEBUG, 1, "error = 0x%x\n", cf_err_code);
+ DEBUG( CF_DEBUG, 1, "r addr %d count %d\n", addr, count);
+
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+int cf_write_multiple_block( cf_card_t *info, uint addr, uint count, uint size, uint timeout, unchar *buf)
+{
+ u8 data;
+
+ DEBUG( CF_DEBUG, 1, "write block addr: 0x%08lx, sectors: %x, sector: %x\n", ( unsigned long)addr, count, 512);
+
+ cf_err_code = ERR_NO_ERROR;
+ Translate_Config_HCS( addr, count);
+ CF_SendCommand( ATA_WRITE_SECTOR);
+ do {
+ data = ReadCFCardByte( BLKMEM_STATUS_REG, COMMON_MEM);
+ } while( data & BUSY_BIT);
+
+ SetTransferSizeEx( BLKMEM_DATA_REG, COMMON_MEM, WRITE_OP, NOINCADR, CF_SECTOR_SIZE * count);
+
+ if( !cfc_write_block( info, CF_SECTOR_SIZE*count, ( uint *) buf))
+ return FALSE;
+
+ if( cf_err_code != ERR_NO_ERROR){
+
+ DEBUG( CF_DEBUG, 1, "error: 0x%08lx\n", ( unsigned long)cf_err_code);
+ DEBUG( CF_DEBUG, 1, "w addr: %d, count: %d\n", addr, count);
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+
+/***************************************************************************
+ * SD Card Read/Write/Erase Function
+ ***************************************************************************/
+int cf_read_sector( cf_card_t *info, uint addr, uint count, unchar *buf)
+{
+ DEBUG( CF_DEBUG, 1, "Enter\n");
+
+ if( !cf_read_multiple_block( info, addr + cf_devices->lba_sec_offset, count,
+ info->CSD.ReadBlockLength, info->ReadAccessTimoutCycle, buf)){
+
+ DEBUG( CF_DEBUG, 1, "read failed\n");
+ return FALSE;
+ }
+
+ DEBUG( CF_DEBUG, 1, "read ok\n");
+
+ if( cf_devices->lba_sec_offset == 0){
+
+ if( !cf_read_multiple_block( info, 0, 1, info->CSD.ReadBlockLength, info->ReadAccessTimoutCycle, buf))
+ return FALSE;
+
+ /* lba ( ??) sector offset */
+ cf_devices->lba_sec_offset = ( *( buf + 0x1C6))
+ | ( *( buf + 0x1C7)) << 8
+ | ( *( buf + 0x1C8)) << 16
+ | ( *( buf + 0x1C9)) << 24;
+
+ /* device total sector number */
+ g_cf_sectors = ( *( buf + 0x1CA))
+ | ( *( buf + 0x1CB)) << 8
+ | ( *( buf + 0x1CC)) << 16
+ | ( *( buf + 0x1CD)) << 24;
+
+ /* only for testing , it only to let format command ok */
+ if( ( buf[ 0x1be] != 0x0) && ( buf[ 0x1be] != 0x80)) /* partition identify */
+ cf_devices->lba_sec_offset = 0; /* sector 0 is PBR */
+ else
+ cf_devices->lba_sec_offset = ( buf[ 0x1c6])
+ | ( buf[ 0x1c7] << 8)
+ | ( buf[ 0x1c8] << 16)
+ | ( buf[ 0x1c9] << 24);
+
+ DEBUG( CF_DEBUG, 1, "lba_sec_offet is %d\n", cf_devices->lba_sec_offset);
+ DEBUG( CF_DEBUG, 1, "the device( partition) total sector number is %d\n", g_cf_sectors);
+ }
+
+ DEBUG( CF_DEBUG, 1, "Exit\n");
+ return TRUE;
+}
+
+int cf_write_sector( cf_card_t *info, uint addr, uint count, unchar *buf)
+{
+ if( !cf_write_multiple_block( info, addr+cf_devices->lba_sec_offset, count,
+ info->CSD.ReadBlockLength, info->ReadAccessTimoutCycle, buf)){
+
+ DEBUG( CF_DEBUG, 1, "write failed\n");
+
+ return FALSE;
+ }
+
+ DEBUG( CF_DEBUG, 1, "write ok\n");
+
+ return TRUE;
+}
+
+/*
+ * Perform an actual transfer:
+ * Returns: # of sectors transferred. 0 = error
+ */
+int cf_transfer( cf_dev_t *device, const struct request *req)
+{
+ int status = 0;
+ int count = 0;
+
+ struct bio *bio = req->bio;
+ struct bio_vec *bvec;
+ struct req_iterator iter;
+
+ DEBUG( CF_DEBUG, 1, "req sector: %d, phys_seg: %d, buf: 0x%08lx\n",
+ (int)req->__sector, req->nr_phys_segments,
+ (unsigned long)bio_data(bio));
+
+ spin_unlock_irq( &device->lock);
+
+ rq_for_each_segment( bvec, req, iter){
+
+ unsigned char *buf = page_address( bvec->bv_page) + bvec->bv_offset;
+ int sectors = bio_cur_bytes( bio) >> 9;
+
+ DEBUG( CF_DEBUG, 1, "bvec[%2d]: sector: %d, count: %d, curr: %d, buf: 0x%08lx\n",
+ iter.i, ( int)bio->bi_sector, count, ( int)sectors, ( unsigned long)buf);
+
+ cf_card_info.private = (void *)&device->ch_req;
+
+ if( rq_data_dir( req) == 0) /* Read */
+ status = cf_read_sector( &cf_card_info, bio->bi_sector, sectors, buf);
+ else
+ status = cf_write_sector( &cf_card_info, bio->bi_sector, sectors, buf);
+
+ DEBUG( CF_DEBUG, 1, "status: %d\n", status);
+
+ if (status <= 0) {
+ spin_lock_irq( &device->lock);
+ return count;
+ }
+
+ count += sectors;
+ bio->bi_sector += sectors;
+ }
+
+ spin_lock_irq( &device->lock);
+
+ if( status <= 0)
+ return 0;
+ else
+ return count;
+}
+
+static int cf_card_setup(cf_dev_t *dev)
+{
+ int i;
+
+ DEBUG( CF_DEBUG, 1, "Enter\n");
+ first_run = 0;
+ cf_err_code = ERR_NO_ERROR;
+
+ cf_card_info.ActiveState = FALSE;
+ cf_card_info.WriteProtect = FALSE;
+ cf_card_info.IOAddr = FTCFC_VA_BASE;
+ cf_card_info.DMAEnable = TRUE;
+ cf_card_info.DMAChannel = dev->ch_req.channel;
+ cf_card_info.SysFrequency = AHB_CLK_IN / 2;
+ cf_card_info.RCA = 0;
+
+ DEBUG( CF_DEBUG, 1, "DMA Enable is %d, Sys frequency = %d\n", cf_card_info.DMAEnable, cf_card_info.SysFrequency);
+
+ if( !cf_card_insert( &cf_card_info))
+ return FALSE;
+
+ /* Marketing MB is not 1048576 */
+ DEBUG( CF_DEBUG, 1, "FTCFC010: CF Card Capacity = %d KBytes\n", g_cf_sectors >> 1);
+
+ for( i = 0; i < CF_DEVS; i++)
+ cf_devices[i].size = g_cf_sectors; /* unit is block, not bytes */
+
+ DEBUG( CF_DEBUG, 1, "Exit\n");
+
+ return TRUE;
+}
+
+int cf_ioctl( struct block_device *bdev, fmode_t mode, unsigned int cmd, unsigned long arg)
+{
+ int size;
+ struct hd_geometry geo;
+ cf_dev_t *device = bdev->bd_disk->private_data;
+
+ DEBUG( CF_DEBUG, 1, "ioctl 0x%x 0x%lx\n", cmd, arg);
+
+ switch ( cmd){
+
+ case BLKGETSIZE:
+ /*
+ * Return the device size, expressed in sectors
+ * FIXME: distinguish between kernel sector size and media sector size
+ */
+ size = device->size;
+ __copy_to_user ( ( long *) arg, &size, sizeof ( long));
+ return 0;
+
+ case HDIO_GETGEO:
+ /*
+ * get geometry: we have to fake one... trim the size to a
+ * multiple of 64 ( 32k): tell we have 16 sectors, 4 heads,
+ * whatever cylinders. Tell also that data starts at sector. 4.
+ */
+ geo.cylinders = ( device->size / 4) / 8; /* ?? only for test */
+ geo.heads = 4;
+ geo.sectors = 8;
+ geo.start = 0;
+ __copy_to_user ( ( void *) arg, &geo, sizeof ( geo));
+ return 0;
+
+ default:
+ /* For ioctls we don't understand, let the block layer handle them */
+ return -ENOTTY;
+ }
+
+ return -ENOTTY; /* unknown command */
+}
+
+static void cf_request( struct request_queue *q)
+{
+ cf_dev_t *dev;
+ int ret = 0;
+ struct request *req;
+ static int act = 0;
+
+ if( act)
+ return;
+
+ act = 1;
+
+ while( ( req = blk_fetch_request( q)) != NULL){
+
+ dev = req->rq_disk->private_data;
+
+ if( !dev || dev->card_state == CF_CARD_REMOVE){
+
+ DEBUG( CF_DEBUG, 1, "CF: locating device error\n");
+ __blk_end_request_cur( req, -EIO);
+
+ act = 0;
+ return;
+ }
+
+ ret = cf_transfer( dev, req);
+ __blk_end_request( req, 0, ret << 9);
+ }
+
+ act = 0;
+}
+
+static int cf_dma_ch_alloc(cf_dev_t *dev)
+{
+ dmad_chreq *ch_req = &dev->ch_req;
+
+ memset(ch_req, 0, sizeof(dmad_chreq));
+
+#ifdef CONFIG_PLATFORM_APBDMA
+
+ ch_req->apb_req.addr0_ctrl = APBBR_ADDRINC_FIXED; /* (in) APBBR_ADDRINC_xxx */
+ ch_req->apb_req.addr0_reqn = APBBR_REQN_CFC; /* (in) APBBR_REQN_xxx (also used to help determine bus selection) */
+ ch_req->apb_req.addr1_ctrl = APBBR_ADDRINC_I4X; /* (in) APBBR_ADDRINC_xxx */
+ ch_req->apb_req.addr1_reqn = APBBR_REQN_NONE; /* (in) APBBR_REQN_xxx (also used to help determine bus selection) */
+ ch_req->apb_req.burst_mode = 0; /* (in) Burst mode (0: no burst 1-, 1: burst 4- data cycles per dma cycle) */
+ ch_req->apb_req.data_width = APBBR_DATAWIDTH_4; /* (in) APBBR_DATAWIDTH_4(word), APBBR_DATAWIDTH_2(half-word), APBBR_DATAWIDTH_1(byte) */
+ ch_req->apb_req.tx_dir = DMAD_DIR_A0_TO_A1; /* (in) DMAD_DIR_A0_TO_A1, DMAD_DIR_A1_TO_A0 */
+
+ ch_req->controller = DMAD_DMAC_APB_CORE; /* (in) DMAD_DMAC_AHB_CORE, DMAD_DMAC_APB_CORE */
+ ch_req->flags = DMAD_FLAGS_SLEEP_BLOCK | DMAD_FLAGS_BIDIRECTION;
+
+ if (dmad_channel_alloc(ch_req) != 0) {
+ memset(ch_req, 0, sizeof(dmad_chreq));
+ printk(KERN_INFO "%s: APB dma channel allocation failed\n", __func__);
+ goto _try_ahb;
+ }
+
+#if (CF_DEBUG)
+ printk("%s: APB dma channel allocated (ch: %d)\n", __func__, ch_req->channel);
+#endif
+
+ return 0;
+
+_try_ahb:
+
+#endif /* CONFIG_PLATFORM_APBDMA */
+
+#ifdef CONFIG_PLATFORM_AHBDMA
+
+ ch_req->ahb_req.sync = 1; /* (in) non-zero if src and dst have different clock domain */
+ ch_req->ahb_req.priority = DMAC_CSR_CHPRI_1; /* (in) DMAC_CSR_CHPRI_0 (lowest) ~ DMAC_CSR_CHPRI_3 (highest) */
+ ch_req->ahb_req.hw_handshake = 1; /* (in) non-zero to enable hardware handshake mode */
+ ch_req->ahb_req.burst_size = DMAC_CSR_SIZE_4; /* (in) DMAC_CSR_SIZE_1 ~ DMAC_CSR_SIZE_256 */
+ ch_req->ahb_req.addr0_width = DMAC_CSR_WIDTH_32; /* (in) DMAC_CSR_WIDTH_8, DMAC_CSR_WIDTH_16, or DMAC_CSR_WIDTH_32 */
+ ch_req->ahb_req.addr0_ctrl = DMAC_CSR_AD_FIX; /* (in) DMAC_CSR_AD_INC, DMAC_CSR_AD_DEC, or DMAC_CSR_AD_FIX */
+ ch_req->ahb_req.addr0_reqn = DMAC_REQN_CFC; /* (in) DMAC_REQN_xxx (also used to help determine channel number) */
+ ch_req->ahb_req.addr1_width = DMAC_CSR_WIDTH_32; /* (in) DMAC_CSR_WIDTH_8, DMAC_CSR_WIDTH_16, or DMAC_CSR_WIDTH_32 */
+ ch_req->ahb_req.addr1_ctrl = DMAC_CSR_AD_INC; /* (in) DMAC_CSR_AD_INC, DMAC_CSR_AD_DEC, or DMAC_CSR_AD_FIX */
+ ch_req->ahb_req.addr1_reqn = DMAC_REQN_NONE; /* (in) DMAC_REQN_xxx (also used to help determine channel number) */
+ ch_req->ahb_req.tx_dir = DMAD_DIR_A0_TO_A1; /* (in) DMAD_DIR_A0_TO_A1, DMAD_DIR_A1_TO_A0 */
+
+ ch_req->controller = DMAD_DMAC_AHB_CORE; /* (in) DMAD_DMAC_AHB_CORE, DMAD_DMAC_APB_CORE */
+ ch_req->flags = DMAD_FLAGS_SLEEP_BLOCK | DMAD_FLAGS_BIDIRECTION;
+
+ if (dmad_channel_alloc(ch_req) != 0) {
+ memset(ch_req, 0, sizeof(dmad_chreq));
+ printk(KERN_INFO "%s: AHB dma channel allocation failed\n", __func__);
+ goto _err_exit;
+ }
+
+#if (CF_DEBUG)
+ printk("%s: AHB dma channel allocated (ch: %d)\n", __func__, ch_req->channel);
+#endif
+
+ return 0;
+
+_err_exit:
+
+#endif /* CONFIG_PLATFORM_AHBDMA */
+
+ return -ENODEV;
+}
+
+/*
+ * Note no locks taken out here. In a worst case scenario, we could drop
+ * a chunk of system memory. But that should never happen, since validation
+ * happens at open or mount time, when locks are held.
+ */
+static int cf_revalidate( struct gendisk *gd)
+{
+ cf_dev_t *dev = gd->private_data;
+
+ DEBUG( CF_DEBUG, 1, "Enter\n");
+ dev->card_state = cfc->HostStatus & CARD_DETECT_BIT ? CF_CARD_INSERT : CF_CARD_REMOVE;
+
+ DEBUG( CF_DEBUG, 1, "card state: %s\n",
+ dev->card_state == CF_CARD_INSERT ? "INSERT" :
+ dev->card_state == CF_CARD_WORK ? "WORK" : "REMOVE");
+
+ if( !dev->usage){
+
+ if( cf_card_setup(dev) != TRUE){
+
+ DEBUG( CF_DEBUG, 1, "cf_card_setup failed\n");
+ dev->card_state = CF_CARD_REMOVE;
+
+ return -1;
+ }
+ else {
+ DEBUG( CF_DEBUG, 1, "CFC Driver with DMA Mode\n");
+
+ if (cf_card_info.DMAEnable) {
+ /* acquire dma channel */
+ if (cf_dma_ch_alloc(dev) != 0) {
+ cf_card_info.DMAEnable = FALSE;
+ cf_free( dev);
+ DEBUG( CF_DEBUG, 1, "Request DMA resource failed\n");
+ return -1;
+ }
+ DEBUG( CF_DEBUG, 1, "Request DMA resource success\n");
+ }
+
+ /* SDC interrupt, currently only for HotSwap */
+ DEBUG( CF_DEBUG, 1, "Request CFC IRQ: %d\n", FTCFC_IRQ);
+
+ if( request_irq( FTCFC_IRQ, cf_hotswap_interrupt_handler, IRQF_DISABLED, "CF controller", dev) != 0){
+
+ DEBUG( CF_DEBUG, 1, "Unable to allocate CFC IRQ: 0x%x\n", FTCFC_IRQ);
+ cf_free( dev);
+ return -1;
+ }
+
+ /* require io port address for sd controller */
+ if( request_region( FTCFC_VA_BASE, 0x48, "CF Controller") == NULL){
+
+ DEBUG( CF_DEBUG, 1, "request io port of sd controller fail\n");
+ cf_free( dev);
+ return -1;
+ }
+
+ dev->card_state = CF_CARD_WORK;
+ }
+ }
+
+ DEBUG( CF_DEBUG, 1, "Exit\n");
+
+ return 0;
+}
+
+/* TODO: forbids open for write when WRITE_PROTECT = 1 */
+static int cf_open( struct block_device *bdev, fmode_t mode)
+{
+ cf_dev_t *dev= bdev->bd_disk->private_data; /* device information */
+
+ DEBUG( CF_DEBUG, 1, "Enter\n");
+
+ if( ( cfc->HostStatus & CARD_DETECT_BIT) != CARD_DETECT_BIT){
+
+ DEBUG( CF_DEBUG, 1, "Error: ( ENOMEDIUM)\n");
+ return -ENOMEDIUM;
+ }
+
+ if( CFCardInit()){
+
+ DEBUG( CF_DEBUG, 1, "root initialize failed\n");
+ return FALSE;
+ }
+
+ if( !dev->usage){
+
+ dev->media_change = 1;
+ DEBUG( CF_DEBUG, 1, "forced check_disk_change check\n");
+ check_disk_change( bdev);
+ }
+ else{
+ dev->media_change = 0;
+ }
+
+ DEBUG( CF_DEBUG, 1, "set_capacity() to %d blocks ( %d KBytes)\n", dev->size, dev->size >> 1);
+ set_capacity( dev->gd, dev->size);
+ dev->usage++;
+ cf_devices->lba_sec_offset = 0;
+ DEBUG( CF_DEBUG, 1, "dev: 0x%08lx, cf_devices: 0x%08lx\n", ( unsigned long)dev, ( unsigned long)cf_devices);
+
+ DEBUG( CF_DEBUG, 1, "Exit\n");
+
+ return 0; /* success */
+}
+
+static int cf_release( struct gendisk *gd, fmode_t mode)
+{
+ cf_dev_t *dev = gd->private_data;
+
+ DEBUG( CF_DEBUG, 1, "Enter\n");
+
+ dev->usage--;
+
+ if( !dev->usage)
+ cf_free( dev);
+
+ DEBUG( CF_DEBUG, 1, "Exit\n");
+
+ return 0;
+}
+
+static void setup_device( struct cf_dev *dev, int which)
+{
+ memset ( dev, 0, sizeof ( struct cf_dev));
+ dev->size = 0;
+ spin_lock_init( &dev->lock);
+
+ dev->queue = blk_init_queue( cf_request, &dev->lock);
+
+ if( !dev->queue)
+ goto out_vfree;
+
+ blk_queue_logical_block_size( dev->queue, hardsect_size);
+ dev->queue->queuedata = dev;
+
+ dev->card_state = CF_CARD_REMOVE;
+
+ /* And the gendisk structure. */
+ dev->gd = alloc_disk( CF_MINORS);
+ if( ! dev->gd){
+
+ DEBUG( CF_DEBUG, 1, "alloc_disk failure\n");
+ goto out_vfree;
+ }
+
+ dev->gd->flags = GENHD_FL_REMOVABLE | GENHD_FL_SUPPRESS_PARTITION_INFO;
+ dev->gd->major = cf_major;
+ dev->gd->first_minor = which * CF_MINORS;
+ dev->gd->minors = CF_MINORS;
+ dev->gd->fops = &cf_fops;
+ dev->gd->queue = dev->queue;
+ dev->gd->private_data = dev;
+
+ snprintf ( dev->gd->disk_name, 32, "cpecf%c", which + 'a');
+ set_capacity( dev->gd, 0);
+ add_disk( dev->gd);
+
+ return;
+
+out_vfree:
+
+ return;
+}
+
+static int cf_media_changed( struct gendisk *gd)
+{
+ struct cf_dev *dev = gd->private_data;
+
+ DEBUG( CF_DEBUG, 1, "cf_media_changed = %d\n", dev->media_change);
+
+ return dev->media_change;
+}
+
+struct block_device_operations cf_fops = {
+
+ .owner = THIS_MODULE,
+ .open = cf_open,
+ .release = cf_release,
+ .ioctl = cf_ioctl,
+ .revalidate_disk = cf_revalidate,
+ .media_changed = cf_media_changed,
+};
+
+static int __init cf_module_init( void)
+{
+ int result= -ENOMEM, i;
+
+ DEBUG( 1, 0, "Faraday CF controller Driver (DMA mode)\n");
+
+ cf_major = register_blkdev( cf_major, DEVICE_NAME);
+
+ if( cf_major <= 0){
+
+ DEBUG( CF_DEBUG, 1, ":unable to get major number\n");
+ return -EBUSY;
+ }
+
+ DEBUG( 1, 0, "CF: make node with 'mknod /dev/cpecf b %d 0'\n", cf_major);
+
+ cf_devices = kzalloc( CF_DEVS * sizeof( cf_dev_t), GFP_KERNEL);
+
+ if( !cf_devices)
+ goto fail_malloc;
+
+ for( i = 0; i < CF_DEVS; i++)
+ setup_device( cf_devices + i, i);
+
+ return 0;
+
+fail_malloc:
+
+ if( cf_devices)
+ kfree( cf_devices);
+
+ unregister_blkdev( cf_major, DEVICE_NAME);
+
+ return result;
+}
+
+static void cf_module_cleanup( void)
+{
+ int i;
+
+ if( cf_devices){
+
+ for( i = 0; i < CF_DEVS; i++){
+
+ del_gendisk( cf_devices[i].gd);
+ put_disk( cf_devices[i].gd);
+
+ if( cf_devices[i].queue)
+ blk_cleanup_queue( cf_devices[i].queue);
+ }
+
+ kfree( cf_devices);
+ }
+
+ unregister_blkdev( cf_major, DEVICE_NAME);
+}
+
+module_init( cf_module_init);
+module_exit( cf_module_cleanup);
+
+MODULE_AUTHOR( "Faraday Corp.");
+MODULE_LICENSE( "GPL");
diff -Nur linux-3.4.113.orig/drivers/block/ftcfc010.h linux-3.4.113/drivers/block/ftcfc010.h
--- linux-3.4.113.orig/drivers/block/ftcfc010.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/drivers/block/ftcfc010.h 2016-12-01 20:59:24.380613830 +0100
@@ -0,0 +1,438 @@
+/* drivers/block/CPECF/ftcfc.h
+ *
+ * Faraday FTCFC010 Device Driver
+ *
+ * Copyright (C) 2005 Faraday Corp. (http://www.faraday-tech.com)
+ *
+ * All Rights Reserved
+ */
+
+#ifndef _FTCFC_H_
+#define _FTCFC_H_
+
+#define CF_DEBUG 1
+
+#ifndef TRUE
+#define TRUE 1
+#endif
+
+#ifndef FALSE
+#define FALSE 0
+#endif
+
+#define CF_DEVS 1 /* number of disks */
+#define CF_MINORS 16 /* minors per disk */
+#define CF_SECTOR_SIZE 512 /* sector size */
+
+/* SD Card State */
+#define CF_CARD_REMOVE 0
+#define CF_CARD_INSERT 1
+#define CF_CARD_WORK 2
+
+/* data window register */
+#define CFC_READ_FIFO_LEN 4
+#define CFC_WRITE_FIFO_LEN 4
+
+/* card type, sd or mmc */
+#define MEMORY_CARD_TYPE_SD 0
+#define MEMORY_CARD_TYPE_MMC 1
+
+/*****************************************************************************
+ * SYSTEM ERROR_CODE
+ ****************************************************************************/
+#define ERR_NO_ERROR 0x00000000
+
+/* command error */
+#define ERR_DATA_CRC_ERROR 0x00000100
+#define ERR_RSP_CRC_ERROR 0x00000200
+#define ERR_DATA_TIMEOUT_ERROR 0x00000400
+#define ERR_RSP_TIMEOUT_ERROR 0x00000800
+
+#define ERR_WAIT_OVERRUN_TIMEOUT 0x00001000
+#define ERR_WAIT_UNDERRUN_TIMEOUT 0x00002000
+#define ERR_WAIT_DATA_CRC_TIMEOUT 0x00004000
+#define ERR_WAIT_TRANSFER_END_TIMEOUT 0x00008000
+
+#define ERR_SEND_COMMAND_TIMEOUT 0x00010000
+
+/* using APB DMA error */
+#define ERR_APBDMA_RSP_ERROR 0x02000000
+
+/*
+ * Please refer SanDisk SD Manual v1.9 Section 5.1.9.2 (page 5-76) to set the timeout setting
+ */
+#if CF_DEBUG
+#define CFC_TIMEOUT_BASE (HZ/2) /* Unit is 500 ms */
+#else
+#define CFC_TIMEOUT_BASE (HZ/3) /* Unit is 333 ms */
+#endif
+
+typedef struct _cf_cid_t
+{
+ uint ManufacturerID;
+ uint ApplicationID;
+ unchar ProductName[7];
+ uint ProductRevisionHigh;
+ uint ProductRevisionLow;
+ uint ProductSerialNumber;
+ uint ManufactureMonth;
+ uint ManufactureYear;
+} cf_cid_t;
+
+typedef struct _cf_ccf_t
+{
+ uint CSDStructure;
+ uint MMCSpecVersion;
+ uint TAAC_u;
+ uint NSAC_u;
+ uint TransferSpeed;
+ uint CardCmdClass;
+ uint ReadBlockLength;
+ uint ReadBlockPartial;
+ uint WriteBlockMisalign;
+ uint ReadBlockMisalign;
+ uint DSRImplemant;
+ uint BlockNumber;
+ uint MemorySize;
+ uint VDDReadMin_u;
+ uint VDDReadMax_u;
+ uint VDDWriteMin_u;
+ uint VDDWriteMax_u;
+ uint EraseBlkEnable;
+ uint EraseSectorSize;
+ uint WriteProtectGroupSize;
+ uint WriteProtectGroupEnable;
+ uint WriteSpeedFactor;
+ uint WriteBlockLength;
+ unchar WriteBlockPartial;
+ unchar CopyFlag;
+ unchar PermanentWriteProtect;
+ unchar TemporaryWriteProtect;
+ unchar FileFormat;
+} cf_ccf_t;
+
+/*****************************************************************************
+ * SD SCR register
+ ****************************************************************************/
+typedef struct _cf_scr_t
+{
+ uint Reserved:16;
+ uint SD_BUS_WIDTH:4;
+ uint SD_SECURITY:3;
+ uint DATA_STAT_AFTER_ERASE:1;
+ uint SD_SPEC:4;
+ uint SCR_STRUCTURE:4;
+
+ uint ManufacturerReserved;
+} cf_scr_t;
+
+/*****************************************************************************
+ * sd card structure
+ ****************************************************************************/
+typedef struct _cf_card_t
+{
+ /* host interface configuration */
+ uint IOAddr; /* host controller register base address */
+ uint DMAEnable;
+ uint DMAChannel;
+
+ uint CardType;
+
+ uint CIDWord[4];
+ cf_cid_t CID;
+
+ uint CSDWord[4];
+ cf_ccf_t CSD;
+
+ ushort RCA;
+ cf_scr_t SCR;
+
+ /* access time out */
+ uint ReadAccessTimoutCycle;
+ uint WriteAccessTimoutCycle;
+
+ /* system configurations */
+ uint SysFrequency;
+
+ /* card status */
+ int ActiveState;
+ int WriteProtect;
+
+ void *private;
+} cf_card_t;
+
+typedef struct _CF_Dev
+{
+ u32 dev_size; /* used same as sect_num */
+ u32 sect_num; /* sector num */
+ u8 blksize_bit; /* It's not used */
+ u32 blksize; /* size of block in file system, 1024 */
+
+ u32 phy_blksize; /* Physical size of block on the CF. It's not used */
+ u32 phy_sectorsize; /* the size of erasable sector. It's not used */
+ u32 wp_grp_size; /* the size of write protected group. It's not used */
+
+ spinlock_t lock; /* synchronization */
+ struct semaphore sema; /* synchronization */
+ u32 usage;
+
+ u8 busy;
+
+ wait_queue_head_t select_wait; /* Kernel thread blocked on it. It's not used */
+ u8 cmd; /* What command being executed. */
+ u32 result; /* set by tasklet */
+ u8 *buff;
+
+ u32 lba_sec_offset;
+
+ /*APB_DMA */
+
+ u8 DMATransDir; /* 0: IDLE, 1:READ, 2:WRITE */
+} CF_Dev;
+
+#define CFC_R_IDLE 0x00
+#define CFC_R_START_TRANSFER 0x01
+#define CFC_R_SET_CFCARD_REG 0x02
+#define CFC_R_SET_CFCARD_READ_CMD 0x03
+#define CFC_R_CHK_CFCARD_READY 0x04
+#define CFC_R_SET_DMA_REG 0x05
+#define CFC_R_DMA_START 0x06
+#define CFC_R_DMA_INT 0x07
+#define CFC_R_DMA_FINISH 0x08
+#define CFC_R_PIO_START 0x09
+#define CFC_R_PIO_FINISH 0x0A
+#define CFC_R_CHECK_CFCARD_BUSY 0x0B
+#define CFC_R_CHECK_CFCARD_READY 0x0C
+
+#define CFC_W_IDLE 0x00
+#define CFC_W_START_TRANSFER 0x10
+#define CFC_W_SET_CFCARD_REG 0x20
+#define CFC_W_SET_CFCARD_READ_CMD 0x30
+#define CFC_W_CHK_CFCARD_READY 0x40
+#define CFC_W_SET_DMA_REG 0x50
+#define CFC_W_DMA_START 0x60
+#define CFC_W_DMA_INT 0x70
+#define CFC_W_DMA_FINISH 0x80
+#define CFC_W_PIO_START 0x90
+#define CFC_W_PIO_FINISH 0xA0
+#define CFC_W_CHECK_CFCARD_BUSY 0xB0
+#define CFC_W_CHECK_CFCARD_READY 0xC0
+
+#define DMA_IDLE 0x00
+#define DMA_READ 0x01
+#define DMA_WRITE 0x02
+
+typedef struct CFCTYPE
+{
+ u32 HostStatus; /* 0x00 */
+ u32 ControlReg; /* 0x04 */
+ u32 TimeCfgReg; /* 0x08 */
+ u32 BuffCtrlReg; /* 0x0C */
+ u32 BufferData; /* 0x10 */
+ u32 MultiSector; /* 0x14 */
+
+ /* Enchanced Feature */
+ u32 TransSzMode2En; /* 0x18 */
+ u32 TransSzMode2Cnt; /* 0x1C */
+ u32 Reserved[4]; /* 0x20~0x2F is reserved */
+ u32 Revision; /* 0x30 */
+ u32 Feature; /* 0x34 (define buffer size) */
+
+} CFCTYPE;
+
+#define cfc ((volatile struct CFCTYPE *) (FTCFC_VA_BASE))
+
+typedef struct _tag_CFCardInfo
+{
+ u32 SectTotal;
+ u8 ConfigOptionReg;
+ u8 ConfigAndStatusReg;
+ u8 PinReplaceReg;
+ u8 SocketCopyReg;
+
+} CF_CARD_INFO;
+
+#define CFC_C_Complete 0x00000400
+#define CFC_B_Ready 0x00000200
+#define CFC_8bit 0x00000040
+#define CFC_16bit 0x00000000
+#define CFC_Reset 0x00000020
+#define CFC_T_2048 0x000C0000
+#define CFC_T_1024 0x000B0000
+#define CFC_T_512 0x000A0000
+#define CFC_T_256 0x00090000
+#define CFC_T_128 0x00080000
+#define CFC_T_64 0x00070000
+#define CFC_T_32 0x00060000
+#define CFC_T_16 0x00050000
+#define CFC_T_8 0x00040000
+#define CFC_T_4 0x00030000
+#define CFC_T_2 0x00020000
+#define CFC_T_1 0x00010000
+#define CFC_Read 0x00000000
+#define CFC_Write 0x00008000
+#define CFC_Increment 0x00004000
+#define CFC_Attribute 0x00000000
+#define CFC_Memory 0x00002000
+#define CFC_IO 0x00003000
+
+/* CF status register bit mapping */
+#define RDY_nIREQ_BIT 0x0001
+#define CARD_DETECT_BIT 0x0002
+#define VOL33_SENSE_BIT 0x0004
+#define VOL40_SENSE_BIT 0x0008
+#define STATUS_CHANGE_BIT 0x0010
+#define SPKR_BIT 0x0020
+#define BUF_ACTIVE_BIT 0x0100
+#define BUF_DATA_RDY_BIT 0x0200
+#define INTA_BIT 0x0400
+#define BUF_SIZE_BITS 0xF000
+#define INT_CD_BIT 0x10000
+#define INT_IO_BIT 0x20000
+
+/* CF control register bit mapping */
+#define POWER_CONTROL_BIT 0x000F
+#define FLOW_CONTROL_BIT 0x0010
+#define RESET_BIT 0x0020
+#define MODE_BIT 0x0040
+#define DMA_BIT 0x0100
+
+#define PWR_ON 1
+#define PWR_OFF 0
+
+#define SIGNAL_ON 0x0010
+#define SIGNAL_OFF 0x0000
+
+#define BYTE_MODE 0x0040
+#define WORD_MODE 0x0000
+
+#define ENDMA_BIT 0x0100
+#define DISDMA_BIT 0x0000
+
+#define CARD_DETECT_INT_MASK 0x0200
+#define DATA_CMP_INT_MASK 0x0400
+#define IO_INT_MASK 0x0800
+
+/* active buffer control register bit mapping */
+#define ADR_BIT 0x007FF
+#define TYPE_BIT 0x03000
+#define INCADR_BIT 0x04000
+#define RW_BIT 0x08000
+#define TRANS_SIZE_CONTROL_BIT 0xF0000
+
+#define INCADR 0x04000
+#define NOINCADR 0x00000
+#define TRANS_SIZE_LOC 16
+
+#define SIZE_1_BYTE 0x01
+#define SIZE_2_BYTE 0x02
+#define SIZE_4_BYTE 0x03
+#define SIZE_8_BYTE 0x04
+#define SIZE_16_BYTE 0x05
+#define SIZE_32_BYTE 0x06
+#define SIZE_64_BYTE 0x07
+#define SIZE_128_BYTE 0x08
+#define SIZE_256_BYTE 0x09
+#define SIZE_512_BYTE 0x0a
+#define SIZE_1024_BYTE 0x0b
+#define SIZE_2048_BYTE 0x0c
+
+#define READ_OP 0x00000
+#define WRITE_OP 0x08000
+
+/* type description */
+#define ATTRIBUTE_MEM 0x00000
+#define COMMON_MEM 0x02000
+
+/*
+ * CF card
+ * memory map register
+ * IO block register
+ */
+#define BLKMEM_DATA_REG 0x000
+#define BLKMEM_ERROR_REG ( BLKMEM_DATA_REG + 0x01)
+#define BLKMEM_FEATURE_REG ( BLKMEM_DATA_REG + 0x01)
+#define BLKMEM_SECTOR_COUNT_REG ( BLKMEM_DATA_REG + 0x02)
+#define BLKMEM_SECTOR_NUMBER_REG ( BLKMEM_DATA_REG + 0x03)
+#define BLKMEM_CYLINDER_LOW_REG ( BLKMEM_DATA_REG + 0x04)
+#define BLKMEM_CYLINDER_HIGH_REG ( BLKMEM_DATA_REG + 0x05)
+#define BLKMEM_DRIVE_REG ( BLKMEM_DATA_REG + 0x06)
+#define BLKMEM_STATUS_REG ( BLKMEM_DATA_REG + 0x07)
+#define BLKMEM_COMMAND_REG ( BLKMEM_DATA_REG + 0x07)
+
+#define BLKMEM_EVEN_DATA_REG ( BLKMEM_DATA_REG + 0x08)
+#define BLKMEM_ODD_DATA_REG ( BLKMEM_DATA_REG + 0x09)
+#define BLKMEM_DUP_ERROR_REG ( BLKMEM_DATA_REG + 0x0d)
+#define BLKMEM_DUP_FEATURE_REG ( BLKMEM_DATA_REG + 0x0d)
+#define BLKMEM_DEV_CONTROL_REG ( BLKMEM_DATA_REG + 0x0e)
+#define BLKMEM_DRIVE_ADDR_REG ( BLKMEM_DATA_REG + 0x0f)
+#define BLKMEM_WINDOW_REG ( BLKMEM_DATA_REG + 0x400)
+#define BLKMEM_MAX_WINDOW_REG ( BLKMEM_DATA_REG + 0x7ff)
+
+/* status register */
+#define BUSY_BIT 0x80
+#define RDY_BIT 0x40
+#define DWF_BIT 0x20
+#define DSC_BIT 0x10
+#define DRQ_BIT 0x08
+#define CORR_BIT 0x04
+#define ERR_BIT 0x01
+
+/* CF ATA command */
+#define ATA_CHECK_POWER_MODE 0xe5
+#define ATA_EXECUTE_DRIVE_DIAG 0x90
+#define ATA_ERASE_SECTOR 0xc0
+#define ATA_FORMAT_TRACK 0x50
+#define ATA_IDENTIFY_DRIVE 0xec
+#define ATA_IDLE 0xe3
+#define ATA_IDLE_IMMEDIATE 0xe1
+#define ATA_INIT_DRIVE_PARA 0x91
+#define ATA_READ_BUFFER 0xe4
+#define ATA_READ_LONG_SECTOR 0x22
+#define ATA_READ_MULTIPLE 0xc4
+#define ATA_READ_SECTOR 0x21
+#define ATA_READ_VERIFY_SECTOR 0x40
+#define ATA_RECALIBRATE 0x10
+#define ATA_REQUEST_SENSE 0x03
+#define ATA_SECURITY_DISABLE_PASSWORD 0xf6
+#define ATA_SECURITY_EREASE_PREPARE 0xf3
+#define ATA_SECURITY_ERASE_UNIT 0xf4
+#define ATA_SECURITY_FREEZE_LOCK 0xf5
+#define ATA_SECURITY_SET_PASSWORD 0xf1
+#define ATA_SECURITY_UNLOCK 0xf2
+#define ATA_SEEK 0x70
+#define ATA_SET_FEATURE 0xef
+#define ATA_SET_MULTIPLE_MODE 0xc6
+#define ATA_SET_SLEEP_MODE 0xe6
+#define ATA_STANDBY 0xe2
+#define ATA_STANDBY_IMMEDIATE 0xe0
+#define ATA_TRANSFER_SECTOR 0x87
+#define ATA_WEAR_LEVEL 0xf5
+#define ATA_WRITE_BUFFER 0xe8
+#define ATA_WRITE_LONG_SECTOR 0x32
+#define ATA_WRITE_MULTIPLE 0xc5
+#define ATA_WRITE_MULTIPLE_WO_ERASE 0xcd
+#define ATA_WRITE_SECTOR 0x30
+#define ATA_WRITE_SECTOR_WO_ERASE 0x38
+#define ATA_WRITE_VERIFY 0x3c
+
+#define CF_MEM_MAP_MODE 0x0
+/* attribute memory space register description */
+#define ATTRIBUTE_MEM_BASE 0
+#define ATTRIBUTE_MEM_CONFIG_BASE 0x200
+#define CONFIG_OPTION_REG ( ATTRIBUTE_MEM_CONFIG_BASE + 0x00)
+#define CARD_CONFIG_STATUS_REG ( ATTRIBUTE_MEM_CONFIG_BASE + 0x02)
+#define PIN_REPLACE_REG ( ATTRIBUTE_MEM_CONFIG_BASE + 0x04)
+#define SOCKET_COPY_REG ( ATTRIBUTE_MEM_CONFIG_BASE + 0x06)
+
+/* configuration option register */
+#define CONF0_BIT 0x01
+#define CONF1_BIT 0x02
+#define CONF2_BIT 0x04
+#define CONF3_BIT 0x08
+#define CONF4_BIT 0x10
+#define CONF5_BIT 0x20
+#define LEVLREQ_BIT 0x40
+#define SRESET_BIT 0x80
+
+#endif
diff -Nur linux-3.4.113.orig/drivers/block/ftsdc010.c linux-3.4.113/drivers/block/ftsdc010.c
--- linux-3.4.113.orig/drivers/block/ftsdc010.c 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/drivers/block/ftsdc010.c 2016-12-01 20:59:24.384613985 +0100
@@ -0,0 +1,2206 @@
+/* drivers/block/CPESD/ftsdc010.c
+ *******************************************************************************
+ * Faraday FTSDC010 Device Driver
+ *
+ * Copyright (C) 2005 Faraday Corp. (http://www.faraday-tech.com)
+ *
+ * All Rights Reserved
+ *
+ * Porting to Linux 2.6 on 20050815
+ * Author: Chris Lee, I-Jui Sung, Peter Liao (support APB DMA)
+ * Version: 0.2
+ * History:
+ * 0.1 new creation
+ * 0.2 Porting to meet the style of linux dma
+ * 0.3 modify dma usage to virtual irq of dma interrupt
+ * 0.4 (20050701) Improve r/w performance
+ * 0.5 Porting to Linux 2.6 and replace busy_loop checking with timer's timeout
+ * Todo:
+ *******************************************************************************
+ */
+
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/sched.h>
+#include <linux/delay.h>
+#include <linux/init.h>
+#include <linux/ioport.h>
+#include <linux/hdreg.h> /* HDIO_GETGEO */
+#include <linux/fs.h>
+#include <linux/blkdev.h>
+#include <linux/buffer_head.h> /* invalidate_bdev */
+#include <linux/bio.h>
+#include <linux/pci.h>
+#include <linux/mutex.h>
+#include <asm/io.h>
+#include <asm/uaccess.h>
+#include <asm/spec.h>
+#include <asm/dmad.h>
+
+#define IPMODULE SDC
+#define IPNAME FTSDC010
+
+/* Define CONFIG_FTSDC010_USE_TIMER_DELAY if you want to use software timer instead of busy loop checking */
+#define CONFIG_FTSDC010_USE_TIMER_DELAY
+#undef CONFIG_FTSDC010_USE_TIMER_DELAY
+#include "ftsdc010.h"
+#include <linux/interrupt.h>
+MODULE_AUTHOR("Faraday Corp.");
+MODULE_LICENSE("Faraday License");
+
+/* options */
+#define FORCE_PCI_CONSISTENCY 1 /* define it to 1 if met consistency problems */
+#define KERNEL_SECTOR_SIZE 512 /* Use this when we refer to kernel related sector size */
+
+static int hardsect_size = 512;
+module_param(hardsect_size, int, 0);
+/*------------------------------------------------------------------------------
+ * Predefine for block device
+ */
+#define MAJOR_NR sd_major /* force definitions on in blk.h */
+static int sd_major=0;//SD_MAJOR; /* must be declared before including blk.h */
+#define SD_SHIFT 4 /* max 16 partitions */
+#define DEVICE_NAME "Faraday SDC" /* name for messaging */
+#define DEVICE_REQUEST sd_request
+#define DEVICE_NR(device) (MINOR(device) >> SD_SHIFT)
+//#define DEVICE_INTR sd_intrptr /* pointer to the bottom half */
+#define DEVICE_NO_RANDOM /* no entropy to contribute */
+#define DEVICE_OFF(d) /* do-nothing */
+
+/*#include <linux/blk.h>
+#include <linux/blkpg.h>*/ /* blk_ioctl() */
+
+/*------------------------------------------------------------------------------
+ * Macro definition
+ */
+#define FTSDC_VA_BASE IP_VA_BASE(0)
+#define FTSDC_PA_BASE IP_PA_BASE(0)
+#define FTSDC_IRQ IP_IRQ(0)
+#define SDC_W_REG(offset, value) outl(value, IP_VA_BASE(0) + offset)
+#define SDC_R_REG(offset) inl(IP_VA_BASE(0) + offset)
+
+
+/*------------------------------------------------------------------------------
+ * Global variable
+ */
+
+/* The following items are obtained through kmalloc() in sd_module_init() */
+
+struct block_device_operations sd_fops;
+/* our device structure */
+struct sd_dev {
+ int size; /* device size in sectors */
+ int usage; /* # of users currently */
+ int media_change; /* Flag: media changed? */
+ struct gendisk *gd; /* The gendisk structure */
+ spinlock_t lock; /* For mutual exclusion */
+ struct request_queue *queue; /* The device request queue */
+ int card_state;
+ dmad_chreq ch_req;
+ bool dma_enable;
+};
+static struct sd_dev *sd_devices = NULL;
+
+static sd_card_t sd_card_info;
+static int sector_offset,Do_onetime;
+
+dma_addr_t dma_buf = 0; /* ?? non-zero for for manually debug ?? */
+struct completion sd_dma_cmpl;
+
+static int sync_mode=0;
+
+static uint first_run = 0;
+uint sd_err_code;
+
+#define FILE_FORMAT_HARD_DISK_LIKE 0
+#define FILE_FORMAT_FLOPPY_LIKE 1
+#define FILE_FORMAT_UNIVERSAL 2
+#define FILE_FORMAT_UNKNOW 3
+#define FILE_FORMAT_RESERVED 4
+
+#define K 1000
+
+uint TAAC_TimeUnitTable[] = { // unit is ns
+ 1, 10, 100, 1 * K, 10 * K, 100 * K, 1 * K * K, 10 * K * K
+};
+
+uint TRANS_SPEED_RateUintTable[] = {
+ 100 * K, 1 * K * K, 10 * K * K, 100 * K * K
+};
+
+uint TRANS_SPEED_TimeValueTable_u[] = { // unit=1/10
+ 0, 10, 12, 13, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 70, 80
+};
+
+uint VDD_CURR_MIN_Table_u[] = { // unit=1/10
+ 5, 10, 50, 100, 250, 350, 600, 1000
+};
+
+uint VDD_CURR_MAX_Table_u[] = {
+ 1, 5, 10, 25, 35, 45, 80, 200
+};
+
+uint TAAC_TimeValueTable_u[] = { // unit=1/10
+ 0, 10, 12, 13, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 70, 80
+};
+
+
+unsigned int SDC_READ_FIFO_LEN;
+unsigned int SDC_WRITE_FIFO_LEN;
+
+/*------------------------------------------------------------------------------
+ * Local declaration of function
+ */
+static int sd_revalidate(struct gendisk *gd);
+static int sd_media_changed(struct gendisk *gd);
+static int sd_card_setup(struct sd_dev *dev);
+int sd_check_err(uint status);
+int sd_get_scr(sd_card_t *info, uint *scr);
+int sd_set_transfer_state(sd_card_t *info);
+uint sd_block_size_convert(uint size);
+int sd_read_sector(sd_card_t *info, uint addr, uint count, unchar *buf);
+void sd_reset_host_controller(void);
+/*------------------------------------------------------------------------------
+ * Local function
+ */
+
+/*
+ * SD host controller operation
+ */
+int sdc_send_cmd(uint cmd, uint arg, uint *rsp)
+{
+#ifndef CONFIG_FTSDC010_USE_TIMER_DELAY
+ int count = 0;
+#else
+ unsigned long timeout = jiffies + SDC_GET_STATUS_RETRY_TIMEOUT_COUNT;
+#endif
+ int i;
+ uint status;
+ P_DEBUG("SD Cmd is %d\n",cmd);
+
+ /* clear command relative bits of status register */
+ SDC_W_REG(SDC_CLEAR_REG, SDC_STATUS_REG_RSP_CRC_FAIL | SDC_STATUS_REG_RSP_TIMEOUT | SDC_STATUS_REG_RSP_CRC_OK| SDC_STATUS_REG_CMD_SEND);
+ /* write argument to arugument register if necessary */
+ SDC_W_REG(SDC_ARGU_REG, arg);
+ /* send command */
+ SDC_W_REG(SDC_CMD_REG, cmd | SDC_CMD_REG_CMD_EN);
+
+ /* wait for the CMD_SEND bit of status register is set */
+#ifndef CONFIG_FTSDC010_USE_TIMER_DELAY
+ while (count++ < SDC_GET_STATUS_RETRY_COUNT) {
+#else
+ while (time_before(jiffies, timeout)) {
+#endif
+ status = SDC_R_REG(SDC_STATUS_REG);
+ if (!(cmd & SDC_CMD_REG_NEED_RSP)) {
+ /* if this command does not need response, wait command sent flag */
+ if (status & SDC_STATUS_REG_CMD_SEND) {
+ /* clear command sent bit */
+ SDC_W_REG(SDC_CLEAR_REG, SDC_STATUS_REG_CMD_SEND);
+ sd_err_code = ERR_NO_ERROR;
+ return TRUE;
+ }
+ } else {
+ /* if this command needs response */
+ if (status & SDC_STATUS_REG_RSP_TIMEOUT) {
+ /* clear response timeout bit */
+ SDC_W_REG(SDC_CLEAR_REG, SDC_STATUS_REG_RSP_TIMEOUT);
+ sd_err_code = ERR_RSP_TIMEOUT_ERROR;
+ printk("%s() ERR_RSP_TIMEOUT_ERROR\n", __func__);
+ return FALSE;
+ } else if (status & SDC_STATUS_REG_RSP_CRC_FAIL) {
+ /* clear response fail bit */
+ SDC_W_REG(SDC_CLEAR_REG, SDC_STATUS_REG_RSP_CRC_FAIL);
+ sd_err_code = ERR_RSP_CRC_ERROR;
+ printk("%s() ERR_RSP_CRC_ERROR\n", __func__);
+ return FALSE;
+ } else if (status & SDC_STATUS_REG_RSP_CRC_OK) {
+ /* clear response OK bit */
+ SDC_W_REG(SDC_CLEAR_REG, SDC_STATUS_REG_RSP_CRC_OK);
+ /* if it is long response */
+ if (cmd & SDC_CMD_REG_LONG_RSP)
+ for (i = 0; i < 4; i++, rsp++)
+ *rsp = SDC_R_REG(SDC_RESPONSE0_REG + (i * 4));
+ else
+ *rsp = SDC_R_REG(SDC_RESPONSE0_REG);
+ sd_err_code = ERR_NO_ERROR;
+ return TRUE;
+ }
+ }
+ }
+ sd_err_code = ERR_SEND_COMMAND_TIMEOUT;
+ P_DEBUG("%s() ERR_SEND_COMMAND_TIMEOUT\n", __func__);
+ return FALSE;
+}
+
+int sdc_check_tx_ready(void)
+{
+ uint status;
+#ifndef CONFIG_FTSDC010_USE_TIMER_DELAY
+ int count = 0;
+ while (count++ < SDC_GET_STATUS_RETRY_COUNT) {
+#else
+ unsigned long timeout = jiffies + SDC_GET_STATUS_RETRY_TIMEOUT_COUNT;
+ while (time_before(jiffies, timeout)) {
+#endif
+ status = SDC_R_REG(SDC_STATUS_REG);
+ if (status & SDC_STATUS_REG_FIFO_UNDERRUN) {
+ /* clear FIFO underrun bit */
+ SDC_W_REG(SDC_CLEAR_REG, SDC_STATUS_REG_FIFO_UNDERRUN);
+ return TRUE;
+ } else if (status & SDC_STATUS_REG_DATA_TIMEOUT) {
+ /* clear data timeout bit */
+ printk("Wait Write FIFO TimeOut\n");
+ SDC_W_REG(SDC_CLEAR_REG, SDC_STATUS_REG_DATA_TIMEOUT);
+ sd_err_code = ERR_DATA_TIMEOUT_ERROR;
+ return FALSE;
+ }
+ }
+ sd_err_code = ERR_WAIT_UNDERRUN_TIMEOUT;
+ P_DEBUG("%s() ERR_WAIT_UNDERRUN_TIMEOUT\n", __func__);
+ return FALSE;
+}
+
+int sdc_check_rx_ready(void)
+{
+ uint status;
+#ifndef CONFIG_FTSDC010_USE_TIMER_DELAY
+ int count = 0;
+ while (count++ < SDC_GET_STATUS_RETRY_COUNT) {
+#else
+ unsigned long timeout = jiffies + SDC_GET_STATUS_RETRY_TIMEOUT_COUNT;
+ while (time_before(jiffies, timeout)) {
+#endif
+ status = SDC_R_REG(SDC_STATUS_REG);
+ if (status & SDC_STATUS_REG_FIFO_OVERRUN) {
+ /* clear FIFO overrun bit */
+ SDC_W_REG(SDC_CLEAR_REG, SDC_STATUS_REG_FIFO_OVERRUN);
+ return TRUE;
+ } else if (status & SDC_STATUS_REG_DATA_TIMEOUT) {
+ /* clear data timeout bit */
+ printk("Wait Read FIFO TimeOut\n");
+ SDC_W_REG(SDC_CLEAR_REG, SDC_STATUS_REG_DATA_TIMEOUT);
+ sd_err_code = ERR_DATA_TIMEOUT_ERROR;
+ return FALSE;
+ }
+ }
+ sd_err_code = ERR_WAIT_OVERRUN_TIMEOUT;
+ P_DEBUG("%s() ERR_WAIT_OVERRUN_TIMEOUT\n", __func__);
+ return FALSE;
+}
+
+int sdc_check_data_crc(void)
+{
+ uint status=0;
+#ifndef CONFIG_FTSDC010_USE_TIMER_DELAY
+ int count = 0;
+ while (count++ < SDC_GET_STATUS_RETRY_COUNT) {
+#else
+ unsigned long timeout = jiffies + SDC_GET_STATUS_RETRY_TIMEOUT_COUNT;
+ while (time_before(jiffies, timeout)) {
+#endif
+ status = SDC_R_REG(SDC_STATUS_REG);
+ if (status & SDC_STATUS_REG_DATA_CRC_OK) {
+ P_DEBUGG("%s : receive data ok, status=0x%x\n", __func__, status);
+ /* clear data CRC OK bit */
+ SDC_W_REG(SDC_CLEAR_REG, SDC_STATUS_REG_DATA_CRC_OK);
+ return TRUE;
+ } else if (status & SDC_STATUS_REG_DATA_CRC_FAIL) {
+ /* clear data CRC fail bit */
+ SDC_W_REG(SDC_CLEAR_REG, SDC_STATUS_REG_DATA_CRC_FAIL);
+ sd_err_code = ERR_DATA_CRC_ERROR;
+ printk("%s() ERR_DATA_CRC_ERROR\n", __func__);
+ return FALSE;
+ } else if (status & SDC_STATUS_REG_DATA_TIMEOUT) {
+ /* clear data timeout bit */
+ SDC_W_REG(SDC_CLEAR_REG, SDC_STATUS_REG_DATA_TIMEOUT);
+ sd_err_code = ERR_DATA_TIMEOUT_ERROR;
+ printk("%s() ERR_DATA_TIMEOUT_ERROR\n", __func__);
+ return FALSE;
+ }
+ }
+ P_DEBUG("%s() ERR_WAIT_DATA_CRC_TIMEOUT, status=0x%x\n", __func__, status);
+ sd_err_code = ERR_WAIT_DATA_CRC_TIMEOUT;
+ return FALSE;
+}
+
+static inline int sdc_check_data_end(void)
+{
+ uint status;
+#ifndef CONFIG_FTSDC010_USE_TIMER_DELAY
+ int count = 0;
+ while (count++ < SDC_GET_STATUS_RETRY_COUNT) {
+#else
+ unsigned long timeout = jiffies + SDC_GET_STATUS_RETRY_TIMEOUT_COUNT;
+ while (time_before(jiffies, timeout)) {
+#endif
+ status = SDC_R_REG(SDC_STATUS_REG);
+ if (status & SDC_STATUS_REG_DATA_END) {
+ SDC_W_REG(SDC_CLEAR_REG, SDC_STATUS_REG_DATA_END);
+ return TRUE;
+ } else if (status & SDC_STATUS_REG_DATA_TIMEOUT) {
+ /* clear data timeout bit */
+ SDC_W_REG(SDC_CLEAR_REG, SDC_STATUS_REG_DATA_TIMEOUT);
+ sd_err_code = ERR_DATA_TIMEOUT_ERROR;
+ printk("%s() ERR_DATA_TIMEOUT_ERROR\n", __func__);
+ return FALSE;
+ }
+ }
+ sd_err_code = ERR_WAIT_TRANSFER_END_TIMEOUT;
+ P_DEBUG("%s() ERR_WAIT_TRANSFER_END_TIMEOUT\n", __func__);
+ return FALSE;
+}
+
+int sdc_set_bus_width_cmd(sd_card_t *info, uint width)
+{
+ uint status;
+
+ /* send CMD55 to indicate to the card that the next command is an application specific command */
+ if (!sdc_send_cmd(SD_APP_CMD | SDC_CMD_REG_NEED_RSP, (((uint)info->RCA) << 16), &status))
+ return FALSE;
+ if (!sd_check_err(status))
+ return FALSE;
+ /* send ACMD6 to set bus width */
+ if (!sdc_send_cmd(SD_SET_BUS_WIDTH_CMD | SDC_CMD_REG_APP_CMD | SDC_CMD_REG_NEED_RSP, width, &status))
+ return FALSE;
+ if (!sd_check_err(status))
+ return FALSE;
+
+ return TRUE;
+}
+
+int sdc_set_bus_width(sd_card_t *info)
+{
+ uint width;
+
+ /* if it is not SD card, it does not support wide bus */
+ if (info->CardType != MEMORY_CARD_TYPE_SD)
+ return TRUE;
+ /* get SCR register */
+ if (!sd_get_scr(info, (uint *) &info->SCR))
+ return FALSE;
+ /* if host controller does not support wide bus, return */
+ if ((SDC_R_REG(SDC_BUS_WIDTH_REG) & SDC_WIDE_BUS_SUPPORT) != SDC_WIDE_BUS_SUPPORT)
+ return TRUE;
+ if (!sd_set_transfer_state(info))
+ return FALSE;
+ if (info->SCR.SD_BUS_WIDTH & SD_SCR_4_BIT_BIT)
+ width = SD_BUS_WIDTH_4_BIT;
+ else
+ width = SD_BUS_WIDTH_1_BIT;
+ if (!sdc_set_bus_width_cmd(info, width))
+ return FALSE;
+ if (width == SD_BUS_WIDTH_1_BIT)
+ SDC_W_REG(SDC_BUS_WIDTH_REG, SDC_BUS_WIDTH_REG_SINGLE_BUS);
+ else
+ SDC_W_REG(SDC_BUS_WIDTH_REG, SDC_BUS_WIDTH_REG_WIDE_BUS);
+
+ return TRUE;
+}
+
+static inline int sdc_pre_erase_cmd(uint nr_blocks)
+{
+ uint status;
+ sd_card_t *info=&sd_card_info;
+ /* send CMD55 to indicate to the card that the next command is an application specific command */
+ if (!sdc_send_cmd(SD_APP_CMD | SDC_CMD_REG_NEED_RSP, (((uint)info->RCA) << 16), &status))
+ return FALSE;
+ if (!sd_check_err(status))
+ return FALSE;
+ /* send ACMD6 to set bus width */
+ if (!sdc_send_cmd(23 | SDC_CMD_REG_APP_CMD | SDC_CMD_REG_NEED_RSP, nr_blocks, &status))
+ return FALSE;
+ if (!sd_check_err(status))
+ return FALSE;
+
+ return TRUE;
+}
+
+
+uint sdc_set_bus_clock(sd_card_t *info, uint clock)
+{
+ uint div = 0, reg;
+
+ while (clock < (info->SysFrequency / (2 * (div + 1))))
+ div++;
+ /* write clock divided */
+ reg = SDC_R_REG(SDC_CLOCK_CTRL_REG);
+ reg &= (~SDC_CLOCK_REG_CLK_DIV | 0x80); //ijsung: preserv SD or MMC
+ reg += div & SDC_CLOCK_REG_CLK_DIV;
+ SDC_W_REG(SDC_CLOCK_CTRL_REG, reg);
+ P_DEBUG("%s: SD clock=%d, info->SysFrequency=%d, div=%d\n",__func__,clock, info->SysFrequency, div);
+ return info->SysFrequency / (2 * (div + 1));
+}
+
+static inline int sdc_set_block_size(uint size)
+{
+ uint status;
+ static uint last_size=0;
+ if (size == last_size)
+ return TRUE;
+ else
+ last_size=size;
+
+ if (!sdc_send_cmd(SD_SET_BLOCKLEN_CMD | SDC_CMD_REG_NEED_RSP, size, &status))
+ return FALSE;
+ if (!sd_check_err(status))
+ return FALSE;
+ return TRUE;
+}
+
+void sdc_set_card_type(int type)
+{
+ uint reg;
+
+ reg = SDC_R_REG(SDC_CLOCK_CTRL_REG);
+ reg &= ~SDC_CLOCK_REG_CARD_TYPE;
+
+ if (type == MEMORY_CARD_TYPE_SD) {
+ reg |= SDC_CARD_TYPE_SD;
+ }
+ else {
+ reg |= SDC_CARD_TYPE_MMC;
+ }
+
+ SDC_W_REG(SDC_CLOCK_CTRL_REG, reg);
+}
+
+int sdc_read_block(sd_card_t *info, uint size, uint *buf)
+{
+ /*
+ * Please refer SanDisk SD Manual v1.9 Section 5.1.9.2 (page 5-76) to set the timeout setting
+ */
+ unsigned long timeout = jiffies + SDC_TIMEOUT_BASE*((size+511)>>9);
+ uint count, i;
+ dmad_chreq *ch_req = (dmad_chreq *)info->private;
+ dmad_drb *drb = 0;
+ u32 drb_size = 0;
+ dma_addr_t addr_iter;
+
+ //if (info->DMAEnable) {
+ if ((info->DMAEnable) && ((size & 0xf) == 0)) {
+ P_DEBUG("%s:size=%d, buf=%p) - DMA Read\n", __func__, size,buf );
+ P_DEBUG("dma_buf = %d\n", dma_buf);
+
+ init_completion(&sd_dma_cmpl);
+
+ if (dma_buf)
+ consistent_sync(__va(dma_buf), size, DMA_FROM_DEVICE);
+ else
+ consistent_sync(buf, size, DMA_FROM_DEVICE);
+
+ //prepare parameter for add dma entry
+ dmad_config_channel_dir(ch_req, DMAD_DIR_A0_TO_A1);
+
+ drb_size = dmad_max_size_per_drb(ch_req);
+
+ if (dma_buf)
+ addr_iter = dma_buf; // given dest phy addr
+ else
+ addr_iter = __pa(buf);
+
+ while (size > 0) {
+
+ if (unlikely(0 != dmad_alloc_drb(ch_req, &drb) || (drb == 0))) {
+ printk(KERN_ERR "%s() Failed to allocate dma request block!\n", __func__);
+ return FALSE;
+ }
+
+ drb->addr0 = FTSDC_PA_BASE + SDC_DATA_WINDOW_REG;
+ drb->addr1 = addr_iter;
+
+ if (size <= drb_size) {
+ drb->req_cycle = dmad_bytes_to_cycles(ch_req, size);
+ drb->sync = &sd_dma_cmpl;
+ size = 0;
+ } else {
+ drb->req_cycle = dmad_bytes_to_cycles(ch_req, drb_size);
+ drb->sync = 0;
+ size -= drb_size;
+ addr_iter += drb_size;
+ }
+ //printk(KERN_INFO "%s() size_remain 0x%08x.\n", __func__, size);
+
+ if (unlikely(0 != dmad_submit_request(ch_req, drb, 1))) {
+ printk(KERN_ERR "%s() Failed to submit dma request block!\n", __func__);
+ return FALSE;
+ }
+ }
+
+ if (wait_for_completion_timeout(&sd_dma_cmpl, timeout - jiffies) == 0)
+ printk("%s: read timeout\n", __func__);
+ } else {
+ while (size > 0) {
+ if (!sdc_check_rx_ready()) {
+ printk("error...........\n");
+ return FALSE;
+ }
+ /* read data from FIFO */
+ if (size >= (SDC_READ_FIFO_LEN << 2))
+ count = SDC_READ_FIFO_LEN;
+ else
+ count = size >> 2;
+ /* read data from FIFO */
+ P_DEBUG("\n");
+ for (i = 1; i <= count; i++, buf++)
+ {
+ *buf = SDC_R_REG(SDC_DATA_WINDOW_REG);
+ P_DEBUG("%.8x ",*buf);
+ }
+ size -= (count << 2);
+ }
+ }
+ return sdc_check_data_crc();
+}
+
+int sdc_write_block(sd_card_t *info, uint size, uint *buf)
+{
+ unsigned long timeout = jiffies + SDC_TIMEOUT_BASE*3*((size+511)>>9);
+ uint count, i;
+ dmad_chreq *ch_req = (dmad_chreq *)info->private;
+ dmad_drb *drb = 0;
+ u32 drb_size = 0;
+ dma_addr_t addr_iter;
+
+ //if (info->DMAEnable) {
+ if ((info->DMAEnable) && ((size & 0xf) == 0)) {
+ P_DEBUG("%s:size=%d, buf=%p) - DMA Write\n", __func__, size,buf );
+
+ init_completion(&sd_dma_cmpl);
+
+ if (dma_buf)
+ consistent_sync(__va(dma_buf), size, DMA_TO_DEVICE);
+ else
+ consistent_sync(buf, size, DMA_TO_DEVICE);
+
+ //prepare parameter for add dma entry
+ dmad_config_channel_dir(ch_req, DMAD_DIR_A1_TO_A0);
+
+ drb_size = dmad_max_size_per_drb(ch_req);
+
+ if (dma_buf)
+ addr_iter = dma_buf; // given dest phy addr
+ else
+ addr_iter = __pa(buf);
+
+ while (size > 0) {
+
+ if (unlikely(0 != dmad_alloc_drb(ch_req, &drb) || (drb == 0))) {
+ printk(KERN_ERR "%s() Failed to allocate dma request block!\n", __func__);
+ return FALSE;
+ }
+
+ drb->addr0 = FTSDC_PA_BASE + SDC_DATA_WINDOW_REG;
+ drb->addr1 = addr_iter;
+
+ if (size <= drb_size) {
+ drb->req_cycle = dmad_bytes_to_cycles(ch_req, size);
+ drb->sync = &sd_dma_cmpl;
+ size = 0;
+ } else {
+ drb->req_cycle = dmad_bytes_to_cycles(ch_req, drb_size);
+ drb->sync = 0;
+ size -= drb_size;
+ addr_iter += drb_size;
+ }
+ //printk(KERN_INFO "%s() size_remain 0x%08x.\n", __func__, size);
+
+ if (unlikely(0 != dmad_submit_request(ch_req, drb, 1))) {
+ printk(KERN_ERR "%s() Failed to submit dma request block!\n", __func__);
+ return FALSE;
+ }
+ }
+
+ if (wait_for_completion_timeout(&sd_dma_cmpl, timeout - jiffies) == 0)
+ printk("write timeout\n");
+ } else {
+ while (size > 0) {
+ if (!sdc_check_tx_ready())
+ return FALSE;
+ /* write data from FIFO */
+ if (size >= (SDC_WRITE_FIFO_LEN << 2))
+ count = SDC_WRITE_FIFO_LEN;
+ else
+ count = (size >> 2) ;
+ /* write data from FIFO */
+ for (i = 0; i < count; i++, buf++)
+ SDC_W_REG(SDC_DATA_WINDOW_REG, *buf);
+ size -= (count << 2);
+ }
+ }
+ return sdc_check_data_crc();
+}
+
+void sdc_config_transfer(sd_card_t *SDCard, uint len, uint size, uint rw, uint timeout)
+{
+ u32 con;
+ /* write timeout */
+ SDC_W_REG(SDC_DATA_TIMER_REG, timeout * 2);
+ /* set data length */
+ SDC_W_REG(SDC_DATA_LEN_REG, len);
+
+ /* set data block */
+ if (SDCard->DMAEnable) {
+ con = sd_block_size_convert(size) | SDC_DATA_CTRL_REG_DMA_EN | rw | SDC_DATA_CTRL_REG_DATA_EN;
+ con |= SDC_DMA_TYPE_4;
+ P_DEBUG("%s() transfer DMA mode\n", __func__);
+ SDC_W_REG(SDC_DATA_CTRL_REG, con);
+ } else {
+ P_DEBUG("%s() transfer nonDMA mode\n", __func__);
+ SDC_W_REG(SDC_DATA_CTRL_REG, sd_block_size_convert(size) | rw | SDC_DATA_CTRL_REG_DATA_EN);
+ }
+}
+
+/* Note: This funciton may be called by interrupt handler */
+void sdc_reset(void)
+{
+ uint ret;
+ unsigned long delay = jiffies + (HZ/10)*3; //Delay 300ms
+
+ /* reset host interface */
+ SDC_W_REG(SDC_CMD_REG, SDC_CMD_REG_SDC_RST);
+
+ /* loop, until the reset bit is clear */
+ do {
+ ret = SDC_R_REG(SDC_CMD_REG);
+ } while ((ret & SDC_CMD_REG_SDC_RST) != 0);
+ #if 0
+ udelay(1000);
+ #else
+ while(time_before(jiffies, delay));
+ #endif
+}
+
+/*
+ * SD card operation
+ */
+void sd_endian_change(uint *dt, int len)
+{
+ uint ul;
+
+ for(; len > 0; len--, dt++) {
+ ul = *dt;
+ ((unchar *)dt)[0] = ((unchar *)&ul)[3];
+ ((unchar *)dt)[1] = ((unchar *)&ul)[2];
+ ((unchar *)dt)[2] = ((unchar *)&ul)[1];
+ ((unchar *)dt)[3] = ((unchar *)&ul)[0];
+ }
+}
+
+int sd_get_ocr(sd_card_t *info, uint hocr, uint *cocr)
+{
+ uint status;
+ int count = 0;
+
+ do {
+ if (info->CardType == MEMORY_CARD_TYPE_SD) {
+ /* send CMD55 to indicate to the card that the next command is an application specific command */
+ if (!sdc_send_cmd(SD_APP_CMD | SDC_CMD_REG_NEED_RSP, ((uint) info->RCA) << 16, &status))
+ return FALSE;
+ if (!sd_check_err(status))
+ return FALSE;
+ /* send ACMD41 to get OCR register */
+ if (!sdc_send_cmd(SD_APP_OP_COND | SDC_CMD_REG_APP_CMD | SDC_CMD_REG_NEED_RSP, (uint) hocr, (uint *) cocr))
+ return FALSE;
+ } else {
+ /* send CMD1 to get OCR register */
+ if (!sdc_send_cmd(SD_MMC_OP_COND | SDC_CMD_REG_NEED_RSP, (uint) hocr, (uint *) cocr))
+ return FALSE;
+ }
+ if (count++ > SD_CARD_GET_OCR_RETRY_COUNT) {
+ sd_err_code = ERR_SD_CARD_IS_BUSY;
+ printk("%s : ERR_SD_CARD_IS_BUSY\n", __func__);
+ return FALSE;
+ }
+ udelay(1000); /* According to spec, at most 1 msec or 74 clock cycles */
+ } while ((*cocr & SD_OCR_BUSY_BIT) != SD_OCR_BUSY_BIT);
+
+ return TRUE;
+}
+
+int sd_get_scr(sd_card_t *info, uint *scr)
+{
+ uint status;
+
+ if (!sd_set_transfer_state(info))
+ return FALSE;
+ if (!sdc_set_block_size(8))
+ return FALSE;
+ sdc_config_transfer(info, 8, 8, SDC_DATA_CTRL_REG_DATA_READ, 0xFFFFFFFF);
+ /* send CMD55 to indicate to the card that the next command is an application specific command */
+ if (!sdc_send_cmd(SD_APP_CMD | SDC_CMD_REG_NEED_RSP, ((uint) info->RCA) << 16, &status))
+ return FALSE;
+ if (!sd_check_err(status))
+ return FALSE;
+ /* send ACMD51 to get SCR */
+ if (!sdc_send_cmd(SD_SEND_SCR_CMD | SDC_CMD_REG_APP_CMD | SDC_CMD_REG_NEED_RSP, 0, &status))
+ return FALSE;
+ if (!sd_check_err(status))
+ return FALSE;
+ if (!sdc_read_block(info, 8, (uint *) scr))
+ return FALSE;
+ if (!sdc_check_data_end())
+ return FALSE;
+ sd_endian_change(scr, 2);
+
+ return TRUE;
+}
+
+int sd_check_err(uint status)
+{
+ if (status & SD_STATUS_ERROR_BITS) {
+ sd_err_code = ERR_SD_CARD_STATUS_ERROR;
+ printk("%s() ERR_SD_CARD_STATUS_ERROR %X\n", __func__, status);
+ return FALSE;
+ }
+ sd_err_code = ERR_NO_ERROR;
+ return TRUE;
+}
+
+int sd_get_card_state(sd_card_t *info, uint *ret)
+{
+ uint status;
+
+ /* send CMD13 to get card status */
+ if (!sdc_send_cmd(SD_SEND_STATUS_CMD | SDC_CMD_REG_NEED_RSP, ((uint) info->RCA) << 16, &status))
+ return FALSE;
+ if (!sd_check_err(status))
+ return FALSE;
+ *ret = (status & SD_STATUS_CURRENT_STATE) >> SD_STATUS_CURRENT_STATE_LOC;
+ return TRUE;
+}
+
+int sd_operation_complete(sd_card_t *info, uint finish)
+{
+ uint state;
+ int count = 0;
+ while (count++ < SD_CARD_WAIT_OPERATION_COMPLETE_RETRY_COUNT) {
+ if (!sd_get_card_state(info, &state))
+ return FALSE;
+ if (state == finish)
+ return TRUE;
+ }
+ P_DEBUG("%s() error\n", __func__);
+ return FALSE;
+}
+
+int sd_stop_transmission(void)
+{
+ uint status;
+
+ /* send CMD12 to stop transmission */
+ if (!sdc_send_cmd(SD_STOP_TRANSMISSION_CMD | SDC_CMD_REG_NEED_RSP, 0, &status))
+ return FALSE;
+
+ if (!sd_check_err(status))
+ return FALSE;
+
+ return TRUE;
+}
+
+int sd_set_card_standby(sd_card_t *info)
+{
+ uint state;
+ int count = 0;
+ while (count++ < SD_CARD_STATE_CHANGE_RETRY_COUNT) {
+ if (!sd_get_card_state(info, &state))
+ return FALSE;
+
+ switch (state) {
+ case SD_IDLE_STATE:
+ case SD_READY_STATE:
+ case SD_IDENT_STATE:
+ printk("%s() error\n", __func__);
+ return FALSE;
+ case SD_DIS_STATE:
+ return sd_operation_complete(info, SD_STBY_STATE);
+ case SD_TRAN_STATE:
+ if (!sdc_send_cmd(SD_SELECT_CARD_CMD, 0, NULL))
+ return FALSE;
+ break;
+ case SD_DATA_STATE:
+ if (sd_operation_complete(info, SD_TRAN_STATE))
+ return TRUE;
+ if (sd_err_code != ERR_NO_ERROR)
+ return FALSE;
+ if (!sd_stop_transmission())
+ return FALSE;
+ break;
+ case SD_RCV_STATE:
+ if (sd_operation_complete(info, SD_TRAN_STATE))
+ return TRUE;
+ if (sd_err_code != ERR_NO_ERROR)
+ return FALSE;
+ if (!sd_stop_transmission())
+ return FALSE;
+ break;
+ case SD_PRG_STATE:
+ if (!sd_operation_complete(info, SD_TRAN_STATE))
+ return FALSE;
+ break;
+ case SD_STBY_STATE:
+ return TRUE;
+ }
+ }
+ P_DEBUG("%s() error\n", __func__);
+ return FALSE;
+}
+
+uint two_power(uint n)
+{
+ uint pow = 1;
+
+ for (; n > 0; n--)
+ pow <<= 1;
+ return pow;
+}
+
+int sd_csd_parse(sd_csd_t *csd, uint *csd_word)
+{
+ sd_csd_bit_t *csd_bit;
+ uint mult, blocks, len;
+
+ if ((csd_word[0] & 0x00000001) != 1) {
+ sd_err_code = ERR_CSD_REGISTER_ERROR;
+ printk("%s() ERR_CSD_REGISTER_ERROR\n", __func__);
+ return FALSE;
+ }
+
+ csd_bit = (sd_csd_bit_t *) csd_word;
+ csd->CSDStructure = csd_bit->CSD_STRUCTURE;
+ csd->MMCSpecVersion = csd_bit->MMC_SPEC_VERS;
+ csd->TAAC_u = TAAC_TimeValueTable_u[csd_bit->TAAC_TimeValue] * TAAC_TimeUnitTable[csd_bit->TAAC_TimeUnit] / 10;
+ csd->NSAC_u = csd_bit->NSAC * 100;
+ csd->TransferSpeed = TRANS_SPEED_RateUintTable[csd_bit->TRAN_SPEED_RateUnit] * TRANS_SPEED_TimeValueTable_u[csd_bit->TRAN_SPEED_TimeValue] / 10;
+ csd->CardCmdClass = csd_bit->CCC;
+ csd->ReadBlockLength = two_power(csd_bit->READ_BL_LEN);
+ csd->ReadBlockPartial = csd_bit->READ_BL_PARTIAL;
+ csd->WriteBlockMisalign = csd_bit->WRITE_BLK_MISALIGN;
+ csd->ReadBlockMisalign = csd_bit->READ_BLK_MISALIGN;
+ csd->DSRImplemant = csd_bit->DSR_IMP;
+ mult = 1 << (csd_bit->C_SIZE_MULT + 2);
+ blocks = ((csd_bit->C_SIZE_1 | (csd_bit->C_SIZE_2 << 2)) + 1) * mult;
+ len = 1 << (csd_bit->READ_BL_LEN);
+ csd->BlockNumber = blocks;
+ csd->MemorySize = blocks * len;
+ csd->VDDReadMin_u = VDD_CURR_MIN_Table_u[csd_bit->VDD_R_CURR_MIN];
+ csd->VDDReadMax_u = VDD_CURR_MAX_Table_u[csd_bit->VDD_R_CURR_MAX];
+ csd->VDDWriteMin_u = VDD_CURR_MIN_Table_u[csd_bit->VDD_W_CURR_MIN];
+ csd->VDDWriteMax_u = VDD_CURR_MAX_Table_u[csd_bit->VDD_W_CURR_MAX];
+ csd->EraseBlkEnable = csd_bit->ERASE_BLK_ENABLE;
+ csd->EraseSectorSize = csd_bit->ERASE_SECTOR_SIZE + 1;
+ csd->WriteProtectGroupSize = csd_bit->WP_GRP_SIZE + 1;
+ csd->WriteProtectGroupEnable = csd_bit->WP_GRP_ENABLE;
+ csd->WriteSpeedFactor = two_power(csd_bit->R2W_FACTOR);
+ csd->WriteBlockLength = two_power(csd_bit->WRITE_BL_LEN);
+ csd->WriteBlockPartial = csd_bit->WRITE_BL_PARTIAL;
+ csd->CopyFlag = csd_bit->COPY;
+ csd->PermanentWriteProtect = csd_bit->PERM_WRITE_PROTECT;
+ csd->TemporaryWriteProtect = csd_bit->TMP_WRITE_PROTECT;
+
+ if (csd_bit->FILE_FORMAT_GRP == 0)
+ csd->FileFormat = csd_bit->FILE_FORMAT;
+ else
+ csd->FileFormat = FILE_FORMAT_RESERVED;
+
+ return TRUE;
+}
+
+int sd_cid_parse(sd_cid_t *cid, uint *cid_word)
+{
+ unchar *ptr;
+ int i;
+
+ if ((cid_word[0] & 0x00000001) != 1)
+ {
+ sd_err_code = ERR_CID_REGISTER_ERROR;
+ printk("%s() ERR_CID_REGISTER_ERROR\n", __func__);
+ return FALSE;
+ }
+
+ cid->ManufacturerID = (cid_word[3] & 0xFF000000) >> 24;
+ cid->ApplicationID = (cid_word[3] & 0x00FFFF00) >> 8;
+
+ ptr = (unchar *) cid_word;
+ ptr += 15 - 3;
+ for (i = 0; i < 6; i++, ptr--)
+ cid->ProductName[i] = *ptr;
+ cid->ProductName[6] = '\0' ;
+
+ cid->ProductRevisionLow = (cid_word[1] & 0x00F00000) >> 20;
+ cid->ProductRevisionHigh = (cid_word[1] & 0x000F0000) >> 16;
+ cid->ProductSerialNumber = ((cid_word[1] & 0x0000FFFF) << 16) + ((cid_word[0] & 0xFFFF0000) >> 16);
+ cid->ManufactureMonth = ((cid_word[0] & 0x00000F00) >> 8);
+ cid->ManufactureYear = ((cid_word[0] & 0x0000F000) >> 12) + SD_DEFAULT_YEAR_CODE;
+
+ return TRUE;
+}
+
+uint sd_read_timeout_cycle(uint clock, sd_csd_t *csd)
+{
+#if 1 //ivan for 100ms maximux from document "ProdManualIndGradeSDv1.0[1].pdf" chapter A-2
+ return clock/10; // /10;
+#else
+ uint ret, total, per;
+
+ per = 1000000000 / clock;
+ total = (csd->TAAC_u + (csd->NSAC_u * 100 * per)) * 100;
+
+ if (total > (100 * 1000 * 1000))
+ total = 100 * 1000 * 1000;
+ ret = total / per;
+
+ return ret;
+#endif
+}
+
+uint sd_block_size_convert(uint size)
+{
+ uint ret = 0;
+
+ while (size >= 2) {
+ size >>= 1;
+ ret++;
+ }
+ return ret;
+}
+
+int sd_select_card(sd_card_t *info)
+{
+ uint status;
+
+ /* send CMD7 with valid RCA to select */
+ if (!sdc_send_cmd(SD_SELECT_CARD_CMD | SDC_CMD_REG_NEED_RSP, ((uint)info->RCA) << 16, &status))
+ return FALSE;
+ if (!sd_check_err(status))
+ return FALSE;
+ return TRUE;
+}
+
+int sd_set_transfer_state(sd_card_t *info)
+{
+ uint state;
+ int count = 0;
+ while (count++ < SD_CARD_STATE_CHANGE_RETRY_COUNT) {
+ if (!sd_get_card_state(info, &state))
+ return FALSE;
+
+ switch (state) {
+ case SD_IDLE_STATE:
+ case SD_READY_STATE:
+ case SD_IDENT_STATE:
+ printk("%s() error\n", __func__);
+ return FALSE;
+ case SD_DIS_STATE:
+ if (!sd_operation_complete(info, SD_STBY_STATE))
+ return FALSE;
+ break;
+ case SD_TRAN_STATE:
+ return TRUE;
+ case SD_DATA_STATE:
+ if (sd_operation_complete(info, SD_TRAN_STATE))
+ return TRUE;
+ if (sd_err_code != ERR_NO_ERROR)
+ return FALSE;
+ if (!sd_stop_transmission())
+ return FALSE;
+ break;
+ case SD_RCV_STATE:
+ if (sd_operation_complete(info, SD_TRAN_STATE))
+ return TRUE;
+ if (sd_err_code != ERR_NO_ERROR)
+ return FALSE;
+ if (!sd_stop_transmission())
+ return FALSE;
+ break;
+ case SD_PRG_STATE:
+ if (!sd_operation_complete(info, SD_TRAN_STATE))
+ return FALSE;
+ break;
+ case SD_STBY_STATE:
+ if (!sd_select_card(info))
+ return FALSE;
+ }
+ }
+ P_DEBUG("%s() error\n", __func__);
+ return FALSE;
+}
+
+uint sd_write_timeout_cycle(uint clock, sd_csd_t *CSD)
+{
+#if 1 //ivan for 250ms maximux from document
+ return clock/4; //ijsung hack
+#else
+ uint ret, total, pre;
+
+ pre = 1000000000 / clock;
+ total = CSD->WriteSpeedFactor * 100 * (CSD->TAAC_u + (CSD->NSAC_u * 100 * pre));
+
+ if (total > (100 * 1000 * 1000))
+ total = 100 * 1000 * 1000;
+ ret = total / pre;
+
+ return ret;
+#endif
+}
+
+int sd_card_identify(sd_card_t *info)
+{
+ uint rca, status, cid[4];
+
+ /* reset all cards */
+ if (!sdc_send_cmd(SD_GO_IDLE_STATE_CMD, 0, NULL))
+ return FALSE;
+ udelay(1000);
+ /* Do operating voltage range validation */
+ /* get OCR register */
+ if (!sd_get_ocr(info, SDC_OCR, (uint *) &info->OCR))
+ return FALSE;
+ /* ckeck the operation conditions */
+ if ((info->OCR & SDC_OCR) == 0) {
+ sd_err_code = ERR_OUT_OF_VOLF_RANGE;
+ return FALSE;
+ }
+
+ /* send CMD2 to get CID register */
+ if (!sdc_send_cmd(SD_ALL_SEND_CID_CMD | SDC_CMD_REG_NEED_RSP | SDC_CMD_REG_LONG_RSP, 0, cid))
+ return FALSE;
+ if (info->CardType == MEMORY_CARD_TYPE_SD) {
+ /* send CMD3 to get RCA register */
+ if (!sdc_send_cmd(SD_SEND_RELATIVE_ADDR_CMD | SDC_CMD_REG_NEED_RSP, 0, &rca))
+ return FALSE;
+ info->RCA = (ushort) (rca >> 16);
+ } else {
+ /* so far, we only support one interface, so we can give RCA any value */
+ info->RCA = 0x1;
+ /* send CMD3 to set RCA register */
+ if (!sdc_send_cmd(SD_SEND_RELATIVE_ADDR_CMD | SDC_CMD_REG_NEED_RSP, (info->RCA << 16), &status))
+ return FALSE;
+ if (!sd_check_err(status))
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+int sd_card_init(sd_card_t *info)
+{
+ uint clock;
+
+ P_DEBUG("--> %s\n", __func__);
+ if ((SDC_R_REG(SDC_STATUS_REG) & SDC_STATUS_REG_CARD_INSERT) != SDC_CARD_INSERT)
+ return FALSE;
+ sd_err_code = ERR_NO_ERROR;
+ /* At first, set card type to SD */
+ info->CardType = MEMORY_CARD_TYPE_SD;
+ /* set memory card type */
+ sdc_set_card_type(info->CardType);
+ /* start card idenfication process */
+ if (!sd_card_identify(info)) {
+ printk("this is not SD card\n");
+ sd_err_code = ERR_NO_ERROR;
+ info->CardType = MEMORY_CARD_TYPE_MMC;
+ /* set memory card type */
+ sdc_set_card_type(info->CardType);
+ if (!sd_card_identify(info))
+ return FALSE;
+ }
+
+ /* get CSD */
+ if (!sd_set_card_standby(info))
+ return FALSE;
+ /* send CMD9 to get CSD register */
+ if (!sdc_send_cmd(SD_SEND_CSD_CMD | SDC_CMD_REG_NEED_RSP | SDC_CMD_REG_LONG_RSP, ((uint) info->RCA) << 16, info->CSDWord))
+ return FALSE;
+ sd_csd_parse(&info->CSD, info->CSDWord);
+
+ if (info->CSD.ReadBlockLength != SD_SECTOR_SIZE) {
+ printk("Sector size is mis-matched (SD CSD report=0x%X,SD_SECTOR_SIZE=0x%X)\n", info->CSD.ReadBlockLength, SD_SECTOR_SIZE);
+ info->CSD.ReadBlockLength = SD_SECTOR_SIZE;
+// return FALSE;
+ }
+
+ /* get CID */
+ /* send CMD10 to get CID register */
+ if (!sdc_send_cmd(SD_SEND_CID_CMD | SDC_CMD_REG_NEED_RSP | SDC_CMD_REG_LONG_RSP, ((uint) info->RCA) << 16, info->CIDWord))
+ return FALSE;
+ sd_cid_parse(&info->CID, info->CIDWord);
+
+ /* Set card bus clock. sdc_set_bus_clock() will give the real card bus clock has been set. */
+ clock = sdc_set_bus_clock(info, info->CSD.TransferSpeed);
+ info->ReadAccessTimoutCycle = sd_read_timeout_cycle(clock, &(info->CSD));
+ info->WriteAccessTimoutCycle = sd_write_timeout_cycle(clock, &(info->CSD));
+ /* set bus width */
+ if (!sdc_set_bus_width(info))
+ return FALSE;
+
+ /* check write protect */
+ info->WriteProtect = ((SDC_R_REG(SDC_STATUS_REG) & SDC_STATUS_REG_CARD_LOCK) == SDC_STATUS_REG_CARD_LOCK) ? TRUE : FALSE;
+ if(info->WriteProtect == TRUE)
+ printk("SD/MMC Card is Write Protected\n");
+ info->ActiveState = TRUE;
+ P_DEBUG("<-- %s\n", __func__);
+
+ return TRUE;
+}
+
+int sd_card_insert(sd_card_t *info)
+{
+ P_DEBUG("--> %s\n", __func__);
+ /* reset host interface controller */
+ sdc_reset();
+ /* turn on clock using default clock*/
+ SDC_W_REG(SDC_CLOCK_CTRL_REG, SDC_R_REG(SDC_CLOCK_CTRL_REG)&0xff);
+
+ if (!sd_card_init(info)) {
+ printk("root initialize failed\n");
+ return FALSE;
+ }
+ /* set interrupt mask register */
+ SDC_W_REG(SDC_INT_MASK_REG, SDC_STATUS_REG_CARD_CHANGE | SDC_STATUS_REG_DATA_TIMEOUT);
+ P_DEBUG("<-- %s\n", __func__);
+
+ return TRUE;
+}
+
+int sd_card_remove(sd_card_t *info)
+{
+ sd_err_code = ERR_NO_ERROR;
+
+ info->ActiveState = FALSE;
+ info->WriteProtect = FALSE;
+ info->RCA = 0;
+ /* reset host interface controller */
+ sdc_reset();
+ /* set interrupt mask register */
+ SDC_W_REG(SDC_INT_MASK_REG, SDC_STATUS_REG_CARD_CHANGE | SDC_STATUS_REG_DATA_TIMEOUT);
+ sd_err_code = ERR_CARD_NOT_EXIST;
+ /* turn off clock */
+ SDC_W_REG(SDC_CLOCK_CTRL_REG, SDC_R_REG(SDC_CLOCK_CTRL_REG) | 0x100);
+ return TRUE;
+}
+
+irqreturn_t sd_hotswap_interrupt_handler(int irq, void *dev_id)
+{
+ uint status;
+ struct sd_dev *dev = dev_id;
+
+ P_DEBUG("--> %s, irq=%d\n", __func__, irq);
+ /* When the card is inserted or removed, we must delay a short time to make sure */
+ /* the SDC_STATUS_REG_CARD_INSERT bit of status register is stable */
+ udelay(1000);
+ status = SDC_R_REG(SDC_STATUS_REG);
+ if ((status & SDC_STATUS_REG_CARD_CHANGE) == SDC_STATUS_REG_CARD_CHANGE) {
+ SDC_W_REG(SDC_CLEAR_REG, SDC_STATUS_REG_CARD_CHANGE | SDC_STATUS_REG_DATA_TIMEOUT);
+ if ((status & SDC_STATUS_REG_CARD_INSERT) == SDC_CARD_INSERT) {
+ dev->card_state = SD_CARD_INSERT;
+ printk("Card Insert\n");
+ sd_card_insert(&sd_card_info);
+ } else {
+ dev->card_state = SD_CARD_REMOVE;
+ printk("Card Remove\n");
+ sd_card_remove(&sd_card_info);
+ /* remove all current transfers as I/O error*/
+#if 0 //ASYNC
+ spin_lock_irqsave(&io_request_lock, status);
+ INIT_REQUEST;
+ while(!QUEUE_EMPTY)
+ end_request(0);
+ bh_busy=0;
+ spin_unlock_irqrestore(&io_request_lock, status);
+#endif
+ }
+ } else if ((status & SDC_STATUS_REG_DATA_TIMEOUT) == SDC_STATUS_REG_DATA_TIMEOUT) {
+ SDC_W_REG(SDC_CLEAR_REG, SDC_STATUS_REG_CARD_CHANGE | SDC_STATUS_REG_DATA_TIMEOUT);
+
+#if 0 //ASYNC
+ printk("Data timeout. Retry.\n");
+ sd_clustered_bh(2);
+#else
+ printk("Data timeout. Retry.\n");
+#endif
+ }
+ P_DEBUGG("card state=%d\n", dev->card_state);
+ P_DEBUG("<-- %s\n", __func__);
+ return IRQ_HANDLED;
+}
+
+/*------------------------------------
+ * Block-driver specific functions
+ */
+/*
+ * Find the device for this request.
+ */
+#if 0
+static inline struct sd_dev *sd_locate_device(const struct request *req)
+{
+ int devno;
+ struct sd_dev *dev;
+
+ P_DEBUG("--> %s\n", __func__);
+#if 0
+ /* Check if the minor number is in range */
+ devno = DEVICE_NR(req->rq_dev);
+ P_DEBUGG("minor=%d\n", devno);
+ if (devno >= SD_DEVS) {
+ static int count = 0;
+
+ if (count++ < 5) /* print the message at most five times */
+ P_DEBUG("request for unknown device\n");
+ return NULL;
+ }
+#endif
+ dev = sd_devices + devno;
+ P_DEBUGG("card_state=%d\n", dev->card_state);
+ P_DEBUG("<-- %s\n", __func__);
+ return dev;
+}
+
+int sd_card_check_exist(sd_card_t *info)
+{
+ /* if card is not exist */
+ if ((SDC_R_REG(SDC_STATUS_REG) & SDC_STATUS_REG_CARD_INSERT) != SDC_CARD_INSERT) {
+ sd_card_remove(info);
+ return FALSE;
+ }
+ /* if card is not active */
+ if (!info->ActiveState)
+ {
+ return sd_card_insert(info);
+ }
+ return TRUE;
+}
+#endif
+
+void sd_reset_host_controller(void)
+{
+ uint clock, mask, width;
+
+ /* read register */
+ clock = SDC_R_REG(SDC_CLOCK_CTRL_REG);
+ width = SDC_R_REG(SDC_BUS_WIDTH_REG);
+ mask = SDC_R_REG(SDC_INT_MASK_REG);
+ /* reset host interface */
+ sdc_reset();
+ /* restore register */
+ SDC_W_REG(SDC_CLOCK_CTRL_REG, clock);
+ SDC_W_REG(SDC_BUS_WIDTH_REG, width);
+ SDC_W_REG(SDC_INT_MASK_REG, mask);
+}
+
+int sd_read_single_block(sd_card_t *info, uint addr, uint size, uint timeout, unchar *buf)
+{
+ uint status;
+
+ if (!sdc_set_block_size(size))
+ return FALSE;
+
+ sdc_config_transfer(info, size, size, SDC_DATA_CTRL_REG_DATA_READ, timeout);
+
+ if (!sdc_send_cmd(SD_READ_SINGLE_BLOCK_CMD | SDC_CMD_REG_NEED_RSP, addr, &status))
+ return FALSE;
+ if (!sd_check_err(status))
+ return FALSE;
+
+#ifdef DELAY_FOR_DMA_READ
+ if (first_run==0) {
+ int i=0;
+ for(i=0;i<10;i++)
+ udelay(1000);
+ first_run=1;
+ }
+#endif
+ if (!sdc_read_block(info, size, (uint *) buf))
+ return FALSE;
+
+ if (sd_err_code != ERR_NO_ERROR) {
+ printk("%s() error=0x%X\n", __func__, sd_err_code);
+ sd_reset_host_controller();
+ return FALSE;
+ } else {
+ if (!sdc_check_data_end()) {
+ sd_stop_transmission();
+ printk("%s()2 error=0x%X\n", __func__, sd_err_code);
+ return FALSE;
+ }
+ }
+
+ return TRUE;
+}
+
+int sd_write_single_block(sd_card_t *info, uint addr, uint size, uint timeout, unchar *buf)
+{
+ uint status;
+
+ if (!sdc_set_block_size(size))
+ return FALSE;
+
+ sdc_config_transfer(info, size, size, SDC_DATA_CTRL_REG_DATA_WRITE, timeout);
+
+ if (!sdc_send_cmd(SD_WRITE_SINGLE_BLOCK_CMD | SDC_CMD_REG_NEED_RSP, addr, &status))
+ return FALSE;
+ if (!sd_check_err(status))
+ return FALSE;
+
+ if (!sdc_write_block(info, size, (uint *) buf))
+ return FALSE;
+ if (sd_err_code != ERR_NO_ERROR) {
+ printk("%s() error=0x%X\n", __func__, sd_err_code);
+ sd_reset_host_controller();
+ return FALSE;
+ } else {
+ if (!sdc_check_data_end()) {
+ sd_stop_transmission();
+ printk("%s()2 error=0x%X\n", __func__, sd_err_code);
+ return FALSE;
+ }
+ }
+
+ return TRUE;
+}
+
+int sd_read_multiple_block(sd_card_t *info, uint addr, uint count, uint size, uint timeout, unchar *buf)
+{
+ uint err, status;
+
+ if (!sdc_set_block_size(size))
+ return FALSE;
+
+ sdc_config_transfer(info, count * size, size, SDC_DATA_CTRL_REG_DATA_READ, timeout);
+
+ if (!sdc_send_cmd(SD_READ_MULTIPLE_BLOCK_CMD | SDC_CMD_REG_NEED_RSP, addr, &status))
+ return FALSE;
+ if (!sd_check_err(status))
+ return FALSE;
+
+#ifdef DELAY_FOR_DMA_READ
+ if (first_run==0) {
+ int i=0;
+ for(i=0;i<10;i++)
+ udelay(1000);
+ first_run=1;
+ }
+#endif
+#if 0 //ijsung: Sometimes this will cause IRQ lost, and is slower. Use method below
+ while (count > 0) {
+ if (!sdc_read_block(info, size, (uint *) buf))
+ return FALSE;
+ count--;
+ buf += size;
+ }
+#else //ijsung: DMA at once.
+ if (!sdc_read_block(info, size*count, (uint *) buf))
+ return FALSE;
+#endif
+ if (sd_err_code != ERR_NO_ERROR) {
+ err = sd_err_code;
+ sd_stop_transmission();
+ sd_reset_host_controller();
+ sd_err_code |= err;
+ printk("%s() error=0x%X\n", __func__, sd_err_code);
+ return FALSE;
+ } else {
+ if (!sdc_check_data_end()) {
+ err = sd_err_code;
+ sd_stop_transmission();
+ sd_err_code |= err;
+ printk("%s()2 error=0x%X\n", __func__, sd_err_code);
+ return FALSE;
+ }
+ if (!sd_stop_transmission())
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+int sd_write_multiple_block(sd_card_t *info, uint addr, uint count, uint size, uint timeout, unchar *buf)
+{
+ uint ErrorCode, status;
+
+ if(!sdc_set_block_size(size))
+ return FALSE;
+
+ sdc_config_transfer(info, count * size, size, SDC_DATA_CTRL_REG_DATA_WRITE, timeout);
+ sdc_pre_erase_cmd(count); //ijsung: pre-erase
+ if (!sdc_send_cmd(SD_WRITE_MULTIPLE_BLOCK_CMD | SDC_CMD_REG_NEED_RSP, addr, &status))
+ return FALSE;
+ if (!sd_check_err(status))
+ return FALSE;
+#if 0 //ijsung: Sometimes this will cause IRQ lost, and is slower. Use method below
+ while (count > 0) {
+ if (!sdc_write_block(info, size, (uint *) buf))
+ return FALSE;
+ count--;
+ buf += size;
+ }
+#else //ijsung: DMA at once.
+ if (!sdc_write_block(info, size*count, (uint *) buf))
+ return FALSE;
+#endif
+
+ if (sd_err_code != ERR_NO_ERROR)
+ {
+ ErrorCode = sd_err_code;
+ sd_stop_transmission();
+ sd_reset_host_controller();
+ sd_err_code |= ErrorCode;
+ printk("%s() error=0x%X\n", __func__, sd_err_code);
+ return FALSE;
+ } else {
+ if (!sdc_check_data_end()) {
+ ErrorCode = sd_err_code;
+ sd_stop_transmission();
+ sd_err_code |= ErrorCode;
+ printk("%s()2 error=0x%X\n", __func__, sd_err_code);
+ return FALSE;
+ }
+ if (!sd_stop_transmission())
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+int sd_wait_transfer_state(sd_card_t *info)
+{
+ uint state;
+ int count = 0;
+ while (count++ < SD_CARD_WAIT_TRANSFER_STATE_RETRY_COUNT) {
+ if (!sd_get_card_state(info, &state))
+ return FALSE;
+
+ switch (state) {
+ case SD_IDLE_STATE:
+ case SD_READY_STATE:
+ case SD_IDENT_STATE:
+ case SD_DIS_STATE:
+ case SD_STBY_STATE:
+ printk("%s() error\n", __func__);
+ return FALSE;
+ case SD_TRAN_STATE:
+ return TRUE;
+ case SD_DATA_STATE:
+ case SD_RCV_STATE:
+ case SD_PRG_STATE:
+ break;
+ }
+ }
+ sd_err_code = ERR_SD_CARD_IS_BUSY;
+ P_DEBUG("%s() ERR_SD_CARD_IS_BUSY\n", __func__);
+ return FALSE;
+}
+
+/***************************************************************************
+SD Card Read/Write/Erase Function
+***************************************************************************/
+int sd_read_sector(sd_card_t *info, uint addr, uint count, unchar *buf)
+{
+ int cnt;
+ uint start;
+ sync_mode=1;
+ P_DEBUG("%s : sector = %d,count = %d\n",__func__,addr,count);
+ if (count > MAX_READ_SECTOR_NR) {
+ P_DEBUG("Readable Block Number Per Commands is 0x%X\n",MAX_READ_SECTOR_NR);
+ return FALSE;
+ }
+
+ sd_err_code = ERR_NO_ERROR;
+
+ if (!info->ActiveState) {
+ P_DEBUG("%s : SD card not active!!\n", __func__);
+ return FALSE;
+ }
+
+ if (!sd_set_transfer_state(info))
+ return FALSE;
+
+ start = addr * info->CSD.ReadBlockLength;
+ cnt = (int) count;
+
+ while (cnt > 0) {
+ if (cnt > 1) {
+ if (!sd_read_multiple_block(info, start, (cnt > MAX_MULTI_BLOCK_NUM) ? MAX_MULTI_BLOCK_NUM : cnt,
+ info->CSD.ReadBlockLength, info->ReadAccessTimoutCycle, buf))
+ return FALSE;
+ } else {
+ if (!sd_read_single_block(info, start, info->CSD.ReadBlockLength, info->ReadAccessTimoutCycle, buf))
+ return FALSE;
+ return TRUE;
+ }
+
+ if (!sd_wait_transfer_state(info))
+ return FALSE;
+
+ cnt -= MAX_MULTI_BLOCK_NUM;
+ start += MAX_MULTI_BLOCK_NUM * info->CSD.ReadBlockLength;
+ buf += MAX_MULTI_BLOCK_NUM * info->CSD.ReadBlockLength;
+ }
+
+ return TRUE;
+}
+
+int sd_write_sector(sd_card_t *info, uint addr, uint count, unchar *buf)
+{
+ int cnt;
+ uint start;
+
+ if (count > MAX_WRITE_SECTOR_NR) {
+ P_DEBUG("Writable Block Number Per Commands is 0x%X\n",MAX_WRITE_SECTOR_NR);
+ return FALSE;
+ }
+
+ sd_err_code = ERR_NO_ERROR;
+
+ if (!info->ActiveState) {
+ P_DEBUG("%s : SD card not active!!\n", __func__);
+ return FALSE;
+ }
+
+ if (info->WriteProtect == TRUE) {
+ sd_err_code = ERR_SD_CARD_IS_LOCK;
+ printk("Write Protected!!\n");
+ return FALSE;
+ }
+ if (!sd_set_transfer_state(info))
+ return FALSE;
+
+ start = addr * info->CSD.ReadBlockLength;
+ cnt = (int) count;
+
+ while (cnt > 0) {
+ if (cnt > 1) {
+ if (!sd_write_multiple_block(info, start, (cnt > MAX_MULTI_BLOCK_NUM) ? MAX_MULTI_BLOCK_NUM : cnt,
+ info->CSD.ReadBlockLength, info->WriteAccessTimoutCycle, buf))
+ return FALSE;
+ } else {
+ if (!sd_write_single_block(info, start, info->CSD.ReadBlockLength, info->WriteAccessTimoutCycle, buf))
+ return FALSE;
+ return TRUE;
+ }
+
+ if (!sd_wait_transfer_state(info))
+ return FALSE;
+
+ cnt -= MAX_MULTI_BLOCK_NUM;
+ start += MAX_MULTI_BLOCK_NUM * info->CSD.ReadBlockLength;
+ buf += MAX_MULTI_BLOCK_NUM * info->CSD.ReadBlockLength;
+ }
+
+ return TRUE;
+}
+/*----------------------------------------------
+ * Perform an actual transfer:
+ * Returns: # of sectors transferred. 0 = error
+ */
+static int sd_transfer(struct sd_dev *device, const struct request *req)
+{
+ int status = 0;
+ int count = 0;
+
+ struct bio *bio = req->bio;
+ struct bio_vec *bvec;
+ struct req_iterator iter;
+
+ spin_unlock_irq( &device->lock);
+
+#if 0
+ P_DEBUG("\nreq sector: %d, nr_sectors: %d, hard_cur_sectors: %d phys_seg: %d, buf: 0x%08lx\n",
+ (int)req->sector, (int)req->nr_sectors, (int)req->hard_cur_sectors,
+ (int)req->nr_phys_segments, (ulong)bio_data( bio));
+#endif
+
+ rq_for_each_segment( bvec, req, iter) {
+
+ unsigned char *buf = page_address( bvec->bv_page) + bvec->bv_offset;
+ int sectors = bio_cur_bytes(bio) >> 9;
+
+ P_DEBUG("bvec[%2d]: sector: %d, count: %d, curr: %d, buf: 0x%08lx, ",
+ iter.i, (int)bio->bi_sector, count, (int)sectors, (unsigned long)buf);
+
+ sd_card_info.private = (void *)&device->ch_req;
+
+ if( rq_data_dir(req) == 0) /* Read */
+ status = sd_read_sector( &sd_card_info, sector_offset + bio->bi_sector, sectors, buf);
+ else
+ status = sd_write_sector( &sd_card_info, sector_offset + bio->bi_sector, sectors, buf);
+
+ P_DEBUG("status: %d\n", status);
+
+ if (status <= 0) {
+ spin_lock_irq( &device->lock);
+ return count;
+ }
+
+ count += sectors;
+ bio->bi_sector += sectors;
+ }
+
+ if( ( req->__sector == 0) && !Do_onetime){
+
+ unsigned char *buf = bio_data( bio);
+
+ if( ( buf[ 0x1be] != 0x0) && ( buf[ 0x1be] != 0x80)) /* partition identify */
+ sector_offset = 0; //sector 0 is PBR
+ else
+ sector_offset = ( buf[ 0x1c6]) | ( buf[ 0x1c7] << 8) | ( buf[ 0x1c8] <<16) |( buf[ 0x1c9] << 24);
+
+ P_DEBUG( "sector_offset = %d\n", sector_offset);
+ Do_onetime = 1;
+ }
+
+ spin_lock_irq( &device->lock);
+
+ if( status <= 0)
+ return 0;
+ else
+ return count;
+}
+
+#ifdef SD_DEBUG
+uint sd_dev_info(void)
+{
+ sd_csd_t *CSD;
+ sd_cid_t *CID;
+
+ P_DEBUG("============SDCard=====================================\n");
+#if 0
+ if (!sd_card_check_exist(&sd_card_info))
+ {
+ P_DEBUG("SD Card does not exist!!!");
+ return FALSE;
+ }
+#else
+ if (!sd_card_info.ActiveState) {
+ P_DEBUG("%s : SD card not active!!\n", __func__);
+ return FALSE;
+ }
+#endif
+
+ /* print OCR, RCA register */
+ P_DEBUG("OCR>> 0x%08X RCA>> 0x%04X\n", (uint) sd_card_info.OCR, sd_card_info.RCA);
+ /* print CID register */
+ P_DEBUG("CID>> 0x%08X 0x%08X 0x%08X 0x%08X\n", sd_card_info.CIDWord[0], sd_card_info.CIDWord[1], sd_card_info.CIDWord[2], sd_card_info.CIDWord[3]);
+ CID = &(sd_card_info.CID);
+ P_DEBUG(" MID:0x%02X OID:0x%04X PNM:%s PRV:%d.%d PSN:0x%08X\n", CID->ManufacturerID, CID->ApplicationID, CID->ProductName,
+ CID->ProductRevisionHigh, CID->ProductRevisionLow, CID->ProductSerialNumber);
+ P_DEBUG(" MDT:%d/%d\n", CID->ManufactureMonth, CID->ManufactureYear);
+ /* print CSD register */
+ P_DEBUG("CSD>> 0x%08X 0x%08X 0x%08X 0x%08X\n", sd_card_info.CSDWord[0], sd_card_info.CSDWord[1], sd_card_info.CSDWord[2], sd_card_info.CSDWord[3]);
+ CSD = &(sd_card_info.CSD);
+ P_DEBUG(" CSDStructure:%d Spec.Version:%d\n", CSD->CSDStructure, CSD->MMCSpecVersion);
+ P_DEBUG(" TAAC:%dns NSAC:%d clock cycles\n", CSD->TAAC_u, CSD->NSAC_u);
+ P_DEBUG(" TransferSpeed:%d bit/s CardCommandClass:0x%03X\n", CSD->TransferSpeed, CSD->CardCmdClass);
+ P_DEBUG(" ReadBlLen:%d ReadBlPartial:%X WriteBlkMisalign:%X ReadBlkMisalign:%X\n", CSD->ReadBlockLength, CSD->ReadBlockPartial, CSD->WriteBlockMisalign, CSD->ReadBlockMisalign);
+ P_DEBUG(" DSP:%X BlockNumber:%d MemorySize:%d \n", CSD->DSRImplemant, CSD->BlockNumber, CSD->MemorySize);
+ P_DEBUG(" VDD_R_MIN:%d/10mA VDD_R_MAX:%dmA\n", (uint) CSD->VDDReadMin_u, (uint) CSD->VDDReadMax_u);
+ P_DEBUG(" VDD_W_MIN:%d/10mA VDD_W_MAX:%dmA\n", (uint) CSD->VDDWriteMin_u, (uint) CSD->VDDWriteMax_u);
+ P_DEBUG(" EraseBlkEnable:%d EraseSectorSize:%d WpGrpSize:%d WpGrpEnable:%X\n", CSD->EraseBlkEnable, CSD->EraseSectorSize, CSD->WriteProtectGroupSize, CSD->WriteProtectGroupEnable);
+ P_DEBUG(" WriteSpeedFactor:%d WriteBlLen:%d WriteBlPartial:%X\n", CSD->WriteSpeedFactor, CSD->WriteBlockLength, CSD->WriteBlockPartial);
+ P_DEBUG(" Copy:%X PermWrProtect:%X TmpWrProtect:%X FileFormat:%X\n", CSD->CopyFlag, CSD->PermanentWriteProtect, CSD->TemporaryWriteProtect, CSD->FileFormat);
+ P_DEBUG(" ReadTimoutCycle:0x%08X WriteTimoutCycle:0x%08X\n", sd_card_info.ReadAccessTimoutCycle, sd_card_info.WriteAccessTimoutCycle);
+ /* print SCR register */
+ P_DEBUG("SCR>> 0x%08X 0x%08X \n", *(((uint *) &sd_card_info.SCR)), *(((uint *) &sd_card_info.SCR) + 1));
+ P_DEBUG(" SCR_STRUCTURE:%d, SD_SPEC:%d, Data_status_after_erase:%d\n", sd_card_info.SCR.SCR_STRUCTURE, sd_card_info.SCR.SD_SPEC, sd_card_info.SCR.DATA_STAT_AFTER_ERASE);
+ P_DEBUG(" sd_security:%d, SD_BUS_WIDTH:%X\n", sd_card_info.SCR.SD_SECURITY, sd_card_info.SCR.SD_BUS_WIDTH);
+
+ return TRUE;
+}
+#endif
+
+static int sd_card_setup(struct sd_dev *dev)
+{
+ uint sd_card_size;
+ int i;
+
+ P_DEBUG("--> %s\n", __func__);
+ first_run = 0;
+ sd_err_code = ERR_NO_ERROR;
+
+ sd_card_info.ActiveState = FALSE;
+ sd_card_info.WriteProtect = FALSE;
+ sd_card_info.IOAddr = FTSDC_VA_BASE;
+ sd_card_info.DMAEnable = FALSE;
+
+ sd_card_info.SysFrequency = AHB_CLK_IN/2;
+ P_DEBUG("DMA Enable is %d, Sys frequency = %d\n", sd_card_info.DMAEnable, sd_card_info.SysFrequency);
+ sd_card_info.RCA = 0;
+ sd_card_info.Drive = 'S';
+
+ if (!sd_card_insert(&sd_card_info))
+ return FALSE;
+#ifdef SD_DEBUG
+ if (!sd_dev_info())
+ return FALSE;
+#endif
+ sd_card_size = sd_card_info.CSD.MemorySize;
+ printk(KERN_NOTICE "FTSDC010: SD Card Capacity=%d MB\n", sd_card_size/1000000); /* Marketing MB is not 1048576 */
+
+ for (i = 0; i < SD_DEVS; i++) {
+ sd_devices[i].size = sd_card_size / SD_SECTOR_SIZE; //unit is block, not bytes
+
+#if 0
+ sd_partitions[i << SD_SHIFT].nr_sects =sd_size * (SD_BLKSIZE / SD_SECTOR_SIZE);
+ P_DEBUG ("%s() %d-th device, size=%d blks(blks=%d),nr_sects=%ld\n", __func__, i, sd_size, SD_BLKSIZE, sd_partitions[i << SD_SHIFT].nr_sects);
+#endif
+ //sd_devices[i].card_state = SD_CARD_WORK;
+ //sema_init(&(sd_devices[i].sema), 1); // add by Charles Tsai*/
+ }
+
+ sd_card_info.DMAEnable = dev->dma_enable;
+
+ P_DEBUG("<-- %s\n", __func__);
+ return TRUE;
+}
+
+/*
+ * Driver stuff
+ */
+/*------------------------------------
+ * The ioctl implementation
+ */
+int sd_ioctl(struct block_device *bdev, fmode_t mode, unsigned int cmd, unsigned long arg)
+{
+ int size;
+ struct hd_geometry geo;
+ struct sd_dev *device=bdev->bd_disk->private_data;
+ P_DEBUG ("ioctl 0x%x 0x%lx\n", cmd, arg);
+ switch (cmd) {
+ case BLKGETSIZE:
+ /* Return the device size, expressed in sectors */
+ /* FIXME: distinguish between kernel sector size and media sector size */
+ size = device->size;
+ __copy_to_user ((long *) arg, &size, sizeof (long));
+ return 0;
+#if 0
+ case BLKFLSBUF: /* flush */
+ return blk_ioctl(inode->i_rdev, cmd, arg);
+ case BLKRAGET: /* return the readahead value */
+ return blk_ioctl(inode->i_rdev, cmd, arg);
+ case BLKRASET: /* set the readahead value */
+ if (!capable (CAP_SYS_RAWIO))
+ return -EACCES;
+ if (arg > 0xff)
+ return -EINVAL; /* limit it */
+ return 0;
+// case BLKRRPART: /* re-read partition table */
+// return sd_revalidate (inode->i_rdev);
+#endif
+ case HDIO_GETGEO:
+ /*
+ * get geometry: we have to fake one... trim the size to a
+ * multiple of 64 (32k): tell we have 16 sectors, 4 heads,
+ * whatever cylinders. Tell also that data starts at sector. 4.
+ */
+ geo.cylinders = (device->size/4)/8; /* ?? only for test */
+ geo.heads = 4;
+ geo.sectors = 8;
+ geo.start = 0;
+ __copy_to_user ((void *) arg, &geo, sizeof (geo));
+ return 0;
+ default:
+ /*
+ * For ioctls we don't understand, let the block layer handle them.
+ */
+ return -ENOTTY;//blk_ioctl (inode->i_rdev, cmd, arg);
+ }
+
+ return -ENOTTY; /* unknown command */
+}
+
+static void sd_request(struct request_queue *q)
+{
+ struct sd_dev *dev;
+ static int active;
+#ifndef A320_SD_USE_ASYNC_DMA
+ int ret;
+ struct request *req;
+#else
+ if(bh_busy)
+ return;
+#endif
+ if(active)
+ return;
+ active = 1;
+ P_DEBUG("--> %s\n", __func__);
+repeat:
+ /* Locate the device */
+ if((req=blk_fetch_request(q))==NULL) {
+ active = 0;
+ return;
+ }
+ dev = req->rq_disk->private_data;
+ if (!dev||dev->card_state == SD_CARD_REMOVE) {
+ if(!dev)
+ printk(KERN_NOTICE"SD: locating device error\n");
+ __blk_end_request_cur(req, -EIO);
+ goto repeat;
+ }
+#ifndef A320_SD_USE_ASYNC_DMA
+ sync_mode=1;
+ //spin_unlock_irq(&io_request_lock);
+ ret = sd_transfer(dev, req);
+ __blk_end_request(req, 0, ret << 9);
+ //spin_lock_irq(&io_request_lock);
+ goto repeat;
+
+#else
+ sync_mode=0; //Use new async DMA machanism
+ //printk("%s: set up initial DMA, from sector %d to buffer 0x%X\n", __func__, CURRENT->sector+sector_offset, CURRENT->buffer);
+ //sd_init_async_dma();
+ sd_clustered_bh(1);
+ //bh_busy=1;
+#endif
+ P_DEBUG("<-- %s\n", __func__);
+}
+
+#if 0
+/*-----------------------------------------
+ * Support for removable devices
+ */
+int sd_check_change(kdev_t i_rdev)
+{
+ int minor = DEVICE_NR(i_rdev);
+ struct sd_dev *dev = sd_devices + minor;
+
+ P_DEBUG("--> %s\n", __func__);
+ P_DEBUG("minor=%d\n", minor);
+ if (minor >= SD_DEVS) /* paranoid */
+ return 0;
+ P_DEBUG("check change for dev %d\n", minor);
+ if (dev->usage) {
+ P_DEBUG("disk not change\n");
+ P_DEBUG("<-- %s\n", __func__);
+ return 0; /* still valid */
+ }
+ P_DEBUG("disk changed\n");
+ P_DEBUG("<-- %s\n", __func__);
+ return 1; /* expired */
+}
+#endif
+
+static int sd_dma_ch_alloc(struct sd_dev *dev)
+{
+ dmad_chreq *ch_req = &dev->ch_req;
+
+ memset(ch_req, 0, sizeof(dmad_chreq));
+
+#ifdef CONFIG_PLATFORM_APBDMA
+
+ ch_req->apb_req.addr0_ctrl = APBBR_ADDRINC_FIXED; /* (in) APBBR_ADDRINC_xxx */
+/* for amerald */
+ if((inl(PMU_BASE) & AMERALD_MASK) == AMERALD_PRODUCT_ID){
+ ch_req->apb_req.addr0_reqn = APBBR_REQN_SDC_AMERALD;
+ }else
+ ch_req->apb_req.addr0_reqn = APBBR_REQN_SDC; /* (in) APBBR_REQN_xxx (also used to help determine bus selection) */
+ ch_req->apb_req.addr1_ctrl = APBBR_ADDRINC_I4X; /* (in) APBBR_ADDRINC_xxx */
+ ch_req->apb_req.addr1_reqn = APBBR_REQN_NONE; /* (in) APBBR_REQN_xxx (also used to help determine bus selection) */
+ ch_req->apb_req.burst_mode = 1; /* (in) Burst mode (0: no burst 1-, 1: burst 4- data cycles per dma cycle) */
+ ch_req->apb_req.data_width = APBBR_DATAWIDTH_4; /* (in) APBBR_DATAWIDTH_4(word), APBBR_DATAWIDTH_2(half-word), APBBR_DATAWIDTH_1(byte) */
+ ch_req->apb_req.tx_dir = DMAD_DIR_A0_TO_A1; /* (in) DMAD_DIR_A0_TO_A1, DMAD_DIR_A1_TO_A0 */
+
+ ch_req->controller = DMAD_DMAC_APB_CORE; /* (in) DMAD_DMAC_AHB_CORE, DMAD_DMAC_APB_CORE */
+ ch_req->flags = DMAD_FLAGS_SLEEP_BLOCK | DMAD_FLAGS_BIDIRECTION;
+
+ if (dmad_channel_alloc(ch_req) != 0) {
+ memset(ch_req, 0, sizeof(dmad_chreq));
+ printk(KERN_INFO "%s: APB dma channel allocation failed\n", __func__);
+ goto _try_ahb;
+ }
+
+ P_DEBUG("%s: APB dma channel allocated (ch: %d)\n", __func__, ch_req->channel);
+ //printk("%s: APB dma channel allocated (ch: %d)\n", __func__, ch_req->channel);
+
+ return 0;
+
+_try_ahb:
+
+#endif /* CONFIG_PLATFORM_APBDMA */
+
+#ifdef CONFIG_PLATFORM_AHBDMA
+
+ ch_req->ahb_req.sync = 1; /* (in) non-zero if src and dst have different clock domain */
+ ch_req->ahb_req.priority = DMAC_CSR_CHPRI_1; /* (in) DMAC_CSR_CHPRI_0 (lowest) ~ DMAC_CSR_CHPRI_3 (highest) */
+ ch_req->ahb_req.hw_handshake = 1; /* (in) non-zero to enable hardware handshake mode */
+ ch_req->ahb_req.burst_size = DMAC_CSR_SIZE_4; /* (in) DMAC_CSR_SIZE_1 ~ DMAC_CSR_SIZE_256 */
+ ch_req->ahb_req.addr0_width = DMAC_CSR_WIDTH_32; /* (in) DMAC_CSR_WIDTH_8, DMAC_CSR_WIDTH_16, or DMAC_CSR_WIDTH_32 */
+ ch_req->ahb_req.addr0_ctrl = DMAC_CSR_AD_FIX; /* (in) DMAC_CSR_AD_INC, DMAC_CSR_AD_DEC, or DMAC_CSR_AD_FIX */
+ ch_req->ahb_req.addr0_reqn = DMAC_REQN_SDC; /* (in) DMAC_REQN_xxx (also used to help determine channel number) */
+ ch_req->ahb_req.addr1_width = DMAC_CSR_WIDTH_32; /* (in) DMAC_CSR_WIDTH_8, DMAC_CSR_WIDTH_16, or DMAC_CSR_WIDTH_32 */
+ ch_req->ahb_req.addr1_ctrl = DMAC_CSR_AD_INC; /* (in) DMAC_CSR_AD_INC, DMAC_CSR_AD_DEC, or DMAC_CSR_AD_FIX */
+ ch_req->ahb_req.addr1_reqn = DMAC_REQN_NONE; /* (in) DMAC_REQN_xxx (also used to help determine channel number) */
+ ch_req->ahb_req.tx_dir = DMAD_DIR_A0_TO_A1; /* (in) DMAD_DIR_A0_TO_A1, DMAD_DIR_A1_TO_A0 */
+
+ ch_req->controller = DMAD_DMAC_AHB_CORE; /* (in) DMAD_DMAC_AHB_CORE, DMAD_DMAC_APB_CORE */
+ ch_req->flags = DMAD_FLAGS_SLEEP_BLOCK | DMAD_FLAGS_BIDIRECTION;
+
+ if (dmad_channel_alloc(ch_req) != 0) {
+ memset(ch_req, 0, sizeof(dmad_chreq));
+ printk(KERN_INFO "%s: AHB dma channel allocation failed\n", __func__);
+ goto _err_exit;
+ }
+
+ P_DEBUG("%s: AHB dma channel allocated (ch: %d)\n", __func__, ch_req->channel);
+ //printk("%s: AHB dma channel allocated (ch: %d)\n", __func__, ch_req->channel);
+
+ return 0;
+
+_err_exit:
+
+#endif /* CONFIG_PLATFORM_AHBDMA */
+
+ return -ENODEV;
+}
+
+/*--------------------------------
+ * Note no locks taken out here. In a worst case scenario, we could drop
+ * a chunk of system memory. But that should never happen, since validation
+ * happens at open or mount time, when locks are held.
+ */
+static int sd_revalidate(struct gendisk *gd)
+{
+ struct sd_dev *dev = gd->private_data;
+
+ P_DEBUG("--> %s\n", __func__);
+ P_DEBUG("card state=%s\n", dev->card_state == SD_CARD_INSERT ? "INSERT" : dev->card_state == SD_CARD_WORK ? "WORK" : "REMOVE");
+
+ if (dev->usage == 0) {
+ if (sd_card_setup(dev) != TRUE) {
+ dev->card_state = SD_CARD_REMOVE;
+ return -1;
+ } else {
+ enable_irq(FTSDC_IRQ);
+ dev->card_state = SD_CARD_WORK;
+ }
+ }
+ P_DEBUG("<-- %s\n", __func__);
+
+ return 0;
+}
+
+/*
+ * Device open and close
+ * TODO: forbids open for write when WRITE_PROTECT=1
+ */
+int sd_open(struct block_device *bdev, fmode_t mode)
+{
+ struct sd_dev *dev= bdev->bd_disk->private_data; /* device information */
+ P_DEBUG("--> %s\n", __func__);
+ /* Early return if there's nothing in the card slot */
+ if ((SDC_R_REG(SDC_STATUS_REG) & SDC_STATUS_REG_CARD_INSERT) != SDC_CARD_INSERT) {
+ P_DEBUG("<-- %s (ENOMEDIUM)\n", __func__);
+ return -ENOMEDIUM;
+ }
+ //spin_lock(&dev->lock);
+ if (!dev->usage) {
+ dev->media_change=1;
+ P_DEBUG("%s: forced check_disk_change check\n", __func__);
+ check_disk_change(bdev);
+ sector_offset=0;
+ Do_onetime=0;
+ } else
+ dev->media_change=0;
+
+ /* Set size HERE:
+ * must rely on sd_revalidate to set correct size
+ * (seems on check_disk_change()) */
+ P_DEBUG("%s: set_capacity() to %d blocks (%d bytes)\n",__func__, dev->size, dev->size*SD_SECTOR_SIZE);
+ set_capacity(dev->gd, dev->size);
+ dev->usage++;
+ P_DEBUG("<-- %s\n", __func__);
+
+ return 0; /* success */
+}
+
+int sd_release(struct gendisk *gd, fmode_t mode)
+{
+ struct sd_dev *dev = gd->private_data;
+
+ disable_irq(FTSDC_IRQ);
+ printk(" + sd_release : umount SD\n");
+
+ P_DEBUG("--> %s\n", __func__);
+ dev->usage--;
+ P_DEBUG("<-- %s\n", __func__);
+
+ return 0;
+}
+
+/*--------------------------------------
+ * The file operations
+ */
+struct block_device_operations sd_fops = {
+ owner: THIS_MODULE,
+ open: sd_open,
+ release: sd_release,
+ ioctl: sd_ioctl,
+ revalidate_disk: sd_revalidate,
+ media_changed: sd_media_changed,
+};
+
+void init_sd_pmu(void)
+{
+
+#ifdef CONFIG_FIE8100_PLATFORM
+ unsigned int u32temp;
+ u32temp = *(volatile unsigned int *)(A320_PMU_VA_BASE + 0x14);
+ u32temp &= ~0x3000;
+ u32temp |= 0x2000;
+ *(volatile unsigned int *)(A320_PMU_VA_BASE + 0x14)=u32temp;
+#endif
+
+#ifdef CONFIG_FIE7000_PLATFORM
+ *(volatile unsigned int *)(A320_PMU_VA_BASE + 0x114) = (*(volatile unsigned int *)(A320_PMU_VA_BASE + 0x114) & 0xFFFF0FFF) | 0x00002000;
+#endif
+}
+
+/*
+ * Set up our internal device.
+ */
+static int setup_device(struct sd_dev *dev)
+{
+ /*
+ * Get some memory.
+ */
+ memset (dev, 0, sizeof (struct sd_dev));
+ dev->size = 0;//SD_DUMMY_SIZE/SD_SECTOR_SIZE; /* We'll fill this with correct size later*/
+ spin_lock_init(&dev->lock);
+ /* Request Queue */
+ dev->queue = blk_init_queue(sd_request, &dev->lock);
+ if (dev->queue == NULL)
+ return -EFAULT;
+
+ blk_queue_logical_block_size(dev->queue, hardsect_size);
+ dev->queue->queuedata = dev;
+
+ dev->card_state = SD_CARD_REMOVE;
+
+ /*
+ * And the gendisk structure.
+ */
+ dev->gd = alloc_disk(SD_MINORS);
+ if (! dev->gd) {
+ printk (KERN_NOTICE "alloc_disk failure\n");
+ return -EFAULT;
+ }
+
+ dev->gd->flags = GENHD_FL_REMOVABLE|GENHD_FL_SUPPRESS_PARTITION_INFO;
+ dev->gd->major = sd_major;
+ dev->gd->first_minor = 0;
+ dev->gd->minors = SD_MINORS;
+ dev->gd->fops = &sd_fops;
+ dev->gd->queue = dev->queue;
+ dev->gd->private_data = dev;
+ snprintf (dev->gd->disk_name, 32, "cpesd%c", 'a');
+ set_capacity(dev->gd, 0); //SD_DUMMY_SIZE/SD_SECTOR_SIZE*(hardsect_size/KERNEL_SECTOR_SIZE));
+ add_disk(dev->gd);
+
+ /*
+ * dma alloc
+ */
+ if (sd_dma_ch_alloc(dev) == 0) {
+ printk(KERN_NOTICE "Faraday SD controller Driver (DMA mode)\n");
+ dev->dma_enable = true;
+ } else {
+ printk(KERN_NOTICE "Faraday SD controller Driver (PIO mode)\n");
+ }
+
+ return 0;
+}
+/*
+ * Look for a media change.
+ */
+static int sd_media_changed(struct gendisk *gd)
+{
+ struct sd_dev *dev = gd->private_data;
+ return dev->media_change;
+}
+
+/*
+ * module stuff
+ */
+static int __init sd_module_init(void)
+{
+ int result=-ENOMEM;
+ spinlock_t complete_lock;
+ unsigned long iflags;
+ spin_lock_init(&complete_lock);
+
+#ifdef CONFIG_PLAT_QEMU
+ SDC_READ_FIFO_LEN = SDC_WRITE_FIFO_LEN = SDC_R_REG(0x44) & 0xff;
+#else
+ if(SDC_R_REG(0xa0) == 0x00030101)
+ SDC_READ_FIFO_LEN = SDC_WRITE_FIFO_LEN = SDC_R_REG(0x9c) & 0xff;
+ else
+ SDC_READ_FIFO_LEN = SDC_WRITE_FIFO_LEN = SDC_R_REG(SDC_FEATURE_REG) & 0xff;
+#endif
+ /* Register SD driver */
+ sd_major = register_blkdev(sd_major, DEVICE_NAME);
+ if (sd_major <= 0) {
+ printk(KERN_WARNING DEVICE_NAME ":unable to get major number\n");
+ return -EBUSY;
+ }
+ init_sd_pmu(); /* Power on SDC */
+ P_DEBUG("SD Major Number = %d\n", sd_major);
+ printk(KERN_ALERT "SD: make node with 'mknod /dev/cpesd b %d 0'\n", sd_major);
+
+ sd_devices = kmalloc(sizeof(struct sd_dev), GFP_KERNEL);
+ if (!sd_devices)
+ goto fail_malloc;
+ memset(sd_devices, 0, sizeof(struct sd_dev));
+
+ if (setup_device(sd_devices))
+ goto fail_malloc;
+
+ P_DEBUG("Request SDC IRQ=%d\n", FTSDC_IRQ);
+ spin_lock_irqsave(&complete_lock, iflags);
+ if (request_irq(FTSDC_IRQ, sd_hotswap_interrupt_handler, IRQF_DISABLED, "SD controller", sd_devices) != 0) {
+ printk(KERN_ERR "Unable to allocate SDC IRQ=0x%X\n", FTSDC_IRQ);
+ goto fail_malloc;
+ }
+ disable_irq(FTSDC_IRQ);
+ spin_unlock_irqrestore(&complete_lock, iflags);
+ if (request_region(FTSDC_VA_BASE, 0x48, "SD Controller") == NULL) {
+ printk(KERN_ERR "request io port of sd controller fail\n");
+ goto fail_mem;
+ }
+
+ return 0; /* succeed */
+
+fail_mem:
+ free_irq(FTSDC_IRQ, sd_devices);
+
+fail_malloc:
+ if (sd_devices)
+ kfree(sd_devices);
+ unregister_blkdev(sd_major, DEVICE_NAME);
+ return result;
+}
+
+static void sd_module_cleanup(void)
+{
+ P_DEBUG("--> %s\n", __func__);
+
+ /* unregister the device now to avoid further operations during cleanup */
+
+ if (sd_devices) {
+ del_gendisk(sd_devices->gd);
+ put_disk(sd_devices->gd);
+ if(sd_devices->queue)
+ blk_cleanup_queue(sd_devices->queue);
+
+ if (sd_devices->dma_enable)
+ dmad_channel_free(&sd_devices->ch_req);
+
+ kfree(sd_devices);
+ }
+
+ release_region(FTSDC_VA_BASE, 0x48);
+ free_irq(FTSDC_IRQ, sd_devices);
+
+ unregister_blkdev(sd_major, DEVICE_NAME);
+ P_DEBUG("<-- %s\n", __func__);
+}
+
+module_init(sd_module_init);
+module_exit(sd_module_cleanup);
diff -Nur linux-3.4.113.orig/drivers/block/ftsdc010.h linux-3.4.113/drivers/block/ftsdc010.h
--- linux-3.4.113.orig/drivers/block/ftsdc010.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/drivers/block/ftsdc010.h 2016-12-01 20:59:24.384613985 +0100
@@ -0,0 +1,477 @@
+/* drivers/block/CPESD/ftsdc010.h
+ *
+ * Faraday FTSDC010 Device Driver
+ *
+ * Copyright (C) 2005 Faraday Corp. (http://www.faraday-tech.com)
+ *
+ * All Rights Reserved
+ */
+
+#ifndef _FTSDC010_H_
+#define _FTSDC010_H_
+
+#ifndef TRUE
+#define TRUE 1
+#endif
+
+#ifndef FALSE
+#define FALSE 0
+#endif
+
+//#define SD_DEBUG
+#define DELAY_FOR_DMA_READ
+
+#ifdef SD_DEBUG
+ #define P_DEBUG(fmt, args...) printk(KERN_ALERT "SD: " fmt, ## args)
+#else
+ #define P_DEBUG(a...)
+#endif
+#define P_DEBUGG(a...)
+
+#define MAX_READ_SECTOR_NR 96 //16
+#define MAX_WRITE_SECTOR_NR MAX_READ_SECTOR_NR
+
+#define SD_MAJOR 6 /* default major number, if zero, it means dynamic allocate */
+#define SD_DEVS 1 /* number of disks */
+#define SD_MINORS 16 /* minors per disk */
+#define SD_RAHEAD 2 /* number of sectors */
+#define SD_BLKSIZE 1024 /* block size */
+#define SD_SECTOR_SIZE 512 /* sector size */
+#define SD_DUMMY_SIZE (256*1024*1024) // for sake of hotswap/hotplug
+#if 0
+typedef struct _sd_dev_t {
+ int size;
+ int usage;
+ //struct timer_list timer;
+ spinlock_t lock;
+ struct semaphore sema; // synchronization
+ int card_state;
+} sd_dev_t;
+#endif
+//---------SD Card State
+#define SD_CARD_REMOVE 0
+#define SD_CARD_INSERT 1
+#define SD_CARD_WORK 2
+
+/* so far, SD controller support 3.2-3.3 VDD */
+#define SDC_OCR 0x00FF8000
+
+/* sd controller register */
+#define SDC_CMD_REG 0x00000000
+#define SDC_ARGU_REG 0x00000004
+#define SDC_RESPONSE0_REG 0x00000008
+#define SDC_RESPONSE1_REG 0x0000000C
+#define SDC_RESPONSE2_REG 0x00000010
+#define SDC_RESPONSE3_REG 0x00000014
+#define SDC_RSP_CMD_REG 0x00000018
+#define SDC_DATA_CTRL_REG 0x0000001C
+#define SDC_DATA_TIMER_REG 0x00000020
+#define SDC_DATA_LEN_REG 0x00000024
+#define SDC_STATUS_REG 0x00000028
+#define SDC_CLEAR_REG 0x0000002C
+#define SDC_INT_MASK_REG 0x00000030
+#define SDC_POWER_CTRL_REG 0x00000034
+#define SDC_CLOCK_CTRL_REG 0x00000038
+#define SDC_BUS_WIDTH_REG 0x0000003C
+#define SDC_DATA_WINDOW_REG 0x00000040
+#ifdef A320D_BUILDIN_SDC
+#define SDC_FEATURE_REG 0x00000044
+#define SDC_REVISION_REG 0x00000048
+#else
+#define SDC_MMC_INT_RSP_REG 0x00000044
+#define SDC_GP_OUTPUT_REG 0x00000048
+#define SDC_FEATURE_REG 0x0000009C
+#define SDC_REVISION_REG 0x000000A0
+#endif
+
+/* bit mapping of command register */
+#define SDC_CMD_REG_INDEX 0x0000003F
+#define SDC_CMD_REG_NEED_RSP 0x00000040
+#define SDC_CMD_REG_LONG_RSP 0x00000080
+#define SDC_CMD_REG_APP_CMD 0x00000100
+#define SDC_CMD_REG_CMD_EN 0x00000200
+#define SDC_CMD_REG_SDC_RST 0x00000400
+
+/* bit mapping of response command register */
+#define SDC_RSP_CMD_REG_INDEX 0x0000003F
+#define SDC_RSP_CMD_REG_APP 0x00000040
+
+/* bit mapping of data control register */
+#define SDC_DATA_CTRL_REG_BLK_SIZE 0x0000000F
+#define SDC_DATA_CTRL_REG_DATA_WRITE 0x00000010
+#define SDC_DATA_CTRL_REG_DATA_READ 0x00000000
+#define SDC_DATA_CTRL_REG_DMA_EN 0x00000020
+#define SDC_DATA_CTRL_REG_DATA_EN 0x00000040
+
+#define SDC_DMA_TYPE_1 0x00000000
+#define SDC_DMA_TYPE_4 0x00000100
+#define SDC_DMA_TYPE_8 0x00000200
+
+/* bit mapping of status/clear/mask register */
+#define SDC_STATUS_REG_RSP_CRC_FAIL 0x00000001
+#define SDC_STATUS_REG_DATA_CRC_FAIL 0x00000002
+#define SDC_STATUS_REG_RSP_TIMEOUT 0x00000004
+#define SDC_STATUS_REG_DATA_TIMEOUT 0x00000008
+#define SDC_STATUS_REG_RSP_CRC_OK 0x00000010
+#define SDC_STATUS_REG_DATA_CRC_OK 0x00000020
+#define SDC_STATUS_REG_CMD_SEND 0x00000040
+#define SDC_STATUS_REG_DATA_END 0x00000080
+#define SDC_STATUS_REG_FIFO_UNDERRUN 0x00000100
+#define SDC_STATUS_REG_FIFO_OVERRUN 0x00000200
+#define SDC_STATUS_REG_CARD_CHANGE 0x00000400
+#define SDC_STATUS_REG_CARD_INSERT 0x00000800
+#define SDC_STATUS_REG_CARD_LOCK 0x00001000
+
+#define SDC_CARD_INSERT 0x0
+#define SDC_CARD_REMOVE SDC_STATUS_REG_CARD_INSERT
+
+/* bit mapping of power control register */
+#define SDC_POWER_REG_POWER_ON 0x00000010
+#define SDC_POWER_REG_POWER_BITS 0x0000000F
+
+/* bit mapping of clock control register */
+#define SDC_CLOCK_REG_CARD_TYPE 0x00000080
+#define SDC_CLOCK_REG_CLK_DIV 0x0000007F
+
+/* card type */
+#define SDC_CARD_TYPE_SD SDC_CLOCK_REG_CARD_TYPE
+#define SDC_CARD_TYPE_MMC 0x0
+
+/* bit mapping of bus width register */
+#define SDC_BUS_WIDTH_REG_SINGLE_BUS 0x00000001
+#define SDC_BUS_WIDTH_REG_WIDE_BUS 0x00000004
+#define SDC_WIDE_BUS_SUPPORT 0x00000008
+
+/* data window register */
+//#define SDC_READ_FIFO_LEN 4
+//#define SDC_WRITE_FIFO_LEN 4
+
+/* card type, sd or mmc */
+#define MEMORY_CARD_TYPE_SD 0
+#define MEMORY_CARD_TYPE_MMC 1
+
+/********************************************************************/
+/* SYSTEM ERROR_CODE */
+/********************************************************************/
+#define ERR_NO_ERROR 0x00000000
+
+/* general error */
+#define ERR_CARD_NOT_EXIST 0x00000001
+#define ERR_OUT_OF_VOLF_RANGE 0x00000002
+#define ERR_SD_PARTITIAL_READ_ERROR 0x00000004
+#define ERR_SD_PARTITIAL_WRITE_ERROR 0x00000008
+
+#define ERR_SD_CARD_IS_LOCK 0x00000010
+
+/* command error */
+#define ERR_DATA_CRC_ERROR 0x00000100
+#define ERR_RSP_CRC_ERROR 0x00000200
+#define ERR_DATA_TIMEOUT_ERROR 0x00000400
+#define ERR_RSP_TIMEOUT_ERROR 0x00000800
+
+#define ERR_WAIT_OVERRUN_TIMEOUT 0x00001000
+#define ERR_WAIT_UNDERRUN_TIMEOUT 0x00002000
+#define ERR_WAIT_DATA_CRC_TIMEOUT 0x00004000
+#define ERR_WAIT_TRANSFER_END_TIMEOUT 0x00008000
+
+#define ERR_SEND_COMMAND_TIMEOUT 0x00010000
+
+/* sd error */
+#define ERR_SD_CARD_IS_BUSY 0x00100000
+#define ERR_CID_REGISTER_ERROR 0x00200000
+#define ERR_CSD_REGISTER_ERROR 0x00400000
+
+/* sd card status error */
+#define ERR_SD_CARD_STATUS_ERROR 0x01000000
+/* SDC using APB DMA error */
+#define ERR_DMA_RSP_ERROR 0x02000000
+
+#define SD_SCR_1_BIT_BIT 0x0001
+#define SD_SCR_4_BIT_BIT 0x0004
+
+/********************************************************************/
+/* The bit mapping of SD Status register */
+/********************************************************************/
+#define SD_STATUS_OUT_OF_RANGE 0x80000000
+#define SD_STATUS_ADDRESS_ERROR 0x40000000
+#define SD_STATUS_BLOCK_LEN_ERROR 0x20000000
+#define SD_STATUS_ERASE_SEQ_ERROR 0x10000000
+#define SD_STATUS_ERASE_PARAM 0x08000000
+#define SD_STATUS_WP_VIOLATION 0x04000000
+#define SD_STATUS_CARD_IS_LOCK 0x02000000
+#define SD_STATUS_LOCK_UNLOCK_FILED 0x01000000
+#define SD_STATUS_COM_CRC_ERROR 0x00800000
+#define SD_STATUS_ILLEGAL_COMMAND 0x00400000
+#define SD_STATUS_CARD_ECC_FAILED 0x00200000
+#define SD_STATUS_CC_ERROR 0x00100000
+#define SD_STATUS_ERROR 0x00080000
+#define SD_STATUS_UNDERRUN 0x00040000
+#define SD_STATUS_OVERRUN 0x00020000
+#define SD_STATUS_CID_CSD_OVERWRITE 0x00010000
+#define SD_STATUS_WP_ERASE_SKIP 0x00008000
+#define SD_STATUS_CARD_ECC_DISABLE 0x00004000
+#define SD_STATUS_ERASE_RESET 0x00002000
+#define SD_STATUS_CURRENT_STATE 0x00001E00
+#define SD_STATUS_READY_FOR_DATA 0x00000100
+#define SD_STATUS_APP_CMD 0x00000020
+#define SD_STATUS_AKE_SEQ_ERROR 0x00000008
+#define SD_STATUS_ERROR_BITS (SD_STATUS_ADDRESS_ERROR | SD_STATUS_BLOCK_LEN_ERROR | SD_STATUS_ERASE_SEQ_ERROR | SD_STATUS_ERASE_PARAM | SD_STATUS_WP_VIOLATION | SD_STATUS_LOCK_UNLOCK_FILED | SD_STATUS_CARD_ECC_FAILED | SD_STATUS_CC_ERROR | SD_STATUS_ERROR | SD_STATUS_UNDERRUN | SD_STATUS_OVERRUN | SD_STATUS_CID_CSD_OVERWRITE | SD_STATUS_WP_ERASE_SKIP | SD_STATUS_AKE_SEQ_ERROR)
+#define SD_STATUS_CURRENT_STATE_LOC 9
+
+/********************************************************************/
+/* SD command response type */
+/********************************************************************/
+#define SD_NO_RESPONSE 0
+#define SD_RESPONSE_R1 1
+#define SD_RESPONSE_R1b 2
+#define SD_RESPONSE_R2 3
+#define SD_RESPONSE_R3 4
+#define SD_RESPONSE_R6 5
+
+/********************************************************************/
+/* SD command */
+/********************************************************************/
+#define SD_GO_IDLE_STATE_CMD 0
+#define SD_MMC_OP_COND 1
+#define SD_ALL_SEND_CID_CMD 2
+#define SD_SEND_RELATIVE_ADDR_CMD 3
+#define SD_SET_DSR_CMD 4
+#define SD_SET_BUS_WIDTH_CMD 6
+#define SD_SELECT_CARD_CMD 7
+#define SD_SEND_CSD_CMD 9
+#define SD_SEND_CID_CMD 10
+#define SD_STOP_TRANSMISSION_CMD 12
+#define SD_SEND_STATUS_CMD 13
+#define SD_GO_INACTIVE_STATE_CMD 15
+#define SD_SET_BLOCKLEN_CMD 16
+#define SD_READ_SINGLE_BLOCK_CMD 17
+#define SD_READ_MULTIPLE_BLOCK_CMD 18
+#define SD_WRITE_SINGLE_BLOCK_CMD 24
+#define SD_WRITE_MULTIPLE_BLOCK_CMD 25
+#define SD_PROGRAM_CSD_CMD 27
+#define SD_ERASE_SECTOR_START_CMD 32
+#define SD_ERASE_SECTOR_END_CMD 33
+#define SD_ERASE_CMD 38
+#define SD_APP_OP_COND 41
+#define SD_LOCK_UNLOCK_CMD 42
+#define SD_SEND_SCR_CMD 51
+#define SD_APP_CMD 55
+#define SD_GET_CMD 56
+
+/* retry count */
+#ifndef CONFIG_FTSDC010_USE_TIMER_DELAY
+#define SD_CARD_GET_OCR_RETRY_COUNT 0x1000
+#define SD_CARD_WAIT_OPERATION_COMPLETE_RETRY_COUNT 8000
+#define SD_CARD_STATE_CHANGE_RETRY_COUNT 30000
+#define SD_CARD_WAIT_TRANSFER_STATE_RETRY_COUNT 30000
+#define SDC_GET_STATUS_RETRY_COUNT 0x300000
+#else
+#define SD_CARD_GET_OCR_RETRY_COUNT 0x1000
+#define SD_CARD_WAIT_OPERATION_COMPLETE_RETRY_COUNT 8000
+#define SD_CARD_STATE_CHANGE_RETRY_COUNT 10000
+#define SD_CARD_WAIT_TRANSFER_STATE_RETRY_COUNT 10000
+#endif
+
+/*
+ * Please refer SanDisk SD Manual v1.9 Section 5.1.9.2 (page 5-76) to set the timeout setting
+ */
+#ifdef SD_DEBUG
+#define SDC_TIMEOUT_BASE (HZ/2) // Unit is 500 ms
+#else
+#define SDC_TIMEOUT_BASE (HZ/3) // Unit is 333 ms
+#endif
+#define SDC_GET_STATUS_RETRY_TIMEOUT_COUNT (HZ*4)
+
+/* sd card standby state */
+#define SD_IDLE_STATE 0
+#define SD_READY_STATE 1
+#define SD_IDENT_STATE 2
+#define SD_STBY_STATE 3
+#define SD_TRAN_STATE 4
+#define SD_DATA_STATE 5
+#define SD_RCV_STATE 6
+#define SD_PRG_STATE 7
+#define SD_DIS_STATE 8
+
+#define SD_BUS_WIDTH_1_BIT 0
+#define SD_BUS_WIDTH_4_BIT 2
+
+/********************************************************************/
+/* SD card OCR register */
+/********************************************************************/
+#define SD_OCR_BUSY_BIT 0x80000000
+
+/********************************************************************/
+/* SD CID register */
+/********************************************************************/
+#define SD_DEFAULT_MONTH_CODE 1
+#define SD_DEFAULT_YEAR_CODE 2000
+#define MAX_MULTI_BLOCK_NUM 126
+
+typedef struct _sd_cid_t
+{
+ uint ManufacturerID;
+ uint ApplicationID;
+ unchar ProductName[7];
+ uint ProductRevisionHigh;
+ uint ProductRevisionLow;
+ uint ProductSerialNumber;
+ uint ManufactureMonth;
+ uint ManufactureYear;
+} sd_cid_t;
+
+/********************************************************************/
+/* SD CSD register */
+/********************************************************************/
+#define SD_CSD_STRUCTURE_1_0 0
+#define SD_CSD_STRUCTURE_1_1 1
+
+#define SD_CSD_SPEC_VERS_1_0_1_2 0
+#define SD_CSD_SPEC_VERS_1_4 1
+#define SD_CSD_SPEC_VERS_2_1 2
+
+#define SD_TAAC_TIME_UINT_BITS 0x07
+#define SD_TAAC_TIME_VALUE_BITS 0x78
+
+typedef struct _sd_csd_t
+{
+ uint CSDStructure;
+ uint MMCSpecVersion;
+ uint TAAC_u;
+ uint NSAC_u;
+ uint TransferSpeed;
+ uint CardCmdClass;
+ uint ReadBlockLength;
+ uint ReadBlockPartial;
+ uint WriteBlockMisalign;
+ uint ReadBlockMisalign;
+ uint DSRImplemant;
+ uint BlockNumber;
+ uint MemorySize;
+ uint VDDReadMin_u;
+ uint VDDReadMax_u;
+ uint VDDWriteMin_u;
+ uint VDDWriteMax_u;
+ uint EraseBlkEnable;
+ uint EraseSectorSize;
+ uint WriteProtectGroupSize;
+ uint WriteProtectGroupEnable;
+ uint WriteSpeedFactor;
+ uint WriteBlockLength;
+ unchar WriteBlockPartial;
+ unchar CopyFlag;
+ unchar PermanentWriteProtect;
+ unchar TemporaryWriteProtect;
+ unchar FileFormat;
+} sd_csd_t;
+
+typedef struct _sd_csd_bit_t
+{
+ uint NotUsed:1;
+ uint CRC:7;
+ uint MMCardReserved1:2;
+ uint FILE_FORMAT:2;
+ uint TMP_WRITE_PROTECT:1;
+ uint PERM_WRITE_PROTECT:1;
+ uint COPY:1;
+ uint FILE_FORMAT_GRP:1;
+
+ uint Reserved2:5;
+ uint WRITE_BL_PARTIAL:1;
+ uint WRITE_BL_LEN:4;
+ uint R2W_FACTOR:3;
+ uint MMCardReserved0:2;
+ uint WP_GRP_ENABLE:1;
+
+ uint WP_GRP_SIZE:7;
+ uint ERASE_SECTOR_SIZE:7;
+ uint ERASE_BLK_ENABLE:1;
+ uint C_SIZE_MULT:3;
+ uint VDD_W_CURR_MAX:3;
+ uint VDD_W_CURR_MIN:3;
+ uint VDD_R_CURR_MAX:3;
+ uint VDD_R_CURR_MIN:3;
+
+ uint C_SIZE_1:2;
+ uint C_SIZE_2:10; // divide its into 2, 10bits
+
+ uint Reserved1:2;
+ uint DSR_IMP:1;
+ uint READ_BLK_MISALIGN:1;
+ uint WRITE_BLK_MISALIGN:1;
+ uint READ_BL_PARTIAL:1;
+
+ uint READ_BL_LEN:4;
+ uint CCC:12;
+
+ uint TRAN_SPEED_RateUnit:3;
+ uint TRAN_SPEED_TimeValue:4;
+ uint TRAN_SPEED_Reserved:1;
+
+ uint NSAC:8;
+
+ uint TAAC_TimeUnit:3;
+ uint TAAC_TimeValue:4;
+ uint TAAC_Reserved:1;
+
+ uint Reserved0:2;
+ uint MMC_SPEC_VERS:4;
+ uint CSD_STRUCTURE:2;
+} sd_csd_bit_t;
+
+/********************************************************************/
+/* SD SCR register */
+/********************************************************************/
+typedef struct _sd_scr_t
+{
+ uint Reserved:16;
+ uint SD_BUS_WIDTH:4;
+ uint SD_SECURITY:3;
+ uint DATA_STAT_AFTER_ERASE:1;
+ uint SD_SPEC:4;
+ uint SCR_STRUCTURE:4;
+
+ uint ManufacturerReserved;
+} sd_scr_t;
+
+/********************************************************************/
+/* sd card structure */
+/********************************************************************/
+typedef struct _sd_card_t
+{
+ /* host interface configuration */
+ uint IOAddr; /* host controller register base address */
+ uint DMAEnable;
+
+ uint CardType;
+
+ /* card register */
+ uint OCR;
+
+ uint CIDWord[4];
+ sd_cid_t CID;
+
+ uint CSDWord[4];
+ sd_csd_t CSD;
+
+ ushort RCA;
+ sd_scr_t SCR;
+
+ /* access time out */
+ uint ReadAccessTimoutCycle;
+ uint WriteAccessTimoutCycle;
+
+ /* Drive Name */
+ uint Drive;
+
+ /* system configurations */
+ uint SysFrequency;
+
+ /* card status */
+ int ActiveState;
+ int WriteProtect;
+
+ void *private;
+} sd_card_t;
+
+#endif
diff -Nur linux-3.4.113.orig/drivers/block/Kconfig linux-3.4.113/drivers/block/Kconfig
--- linux-3.4.113.orig/drivers/block/Kconfig 2016-10-26 17:15:47.000000000 +0200
+++ linux-3.4.113/drivers/block/Kconfig 2016-12-01 20:59:24.384613985 +0100
@@ -498,6 +498,14 @@
block device driver. It communicates with a back-end driver
in another domain which drives the actual block device.
+config FTSDC010
+ tristate "Faraday FTSDC010 driver"
+ depends on NDS32
+
+config FTCFC010
+ tristate "Faraday FTCFC010 driver"
+ depends on NDS32
+
config XEN_BLKDEV_BACKEND
tristate "Xen block-device backend driver"
depends on XEN_BACKEND
diff -Nur linux-3.4.113.orig/drivers/block/Makefile linux-3.4.113/drivers/block/Makefile
--- linux-3.4.113.orig/drivers/block/Makefile 2016-10-26 17:15:47.000000000 +0200
+++ linux-3.4.113/drivers/block/Makefile 2016-12-01 20:59:24.384613985 +0100
@@ -43,3 +43,5 @@
obj-$(CONFIG_BLK_DEV_PCIESSD_MTIP32XX) += mtip32xx/
swim_mod-y := swim.o swim_asm.o
+obj-$(CONFIG_FTSDC010) += ftsdc010.o
+obj-$(CONFIG_FTCFC010) += ftcfc010.o
diff -Nur linux-3.4.113.orig/drivers/gpio/gpio-ftgpio010.c linux-3.4.113/drivers/gpio/gpio-ftgpio010.c
--- linux-3.4.113.orig/drivers/gpio/gpio-ftgpio010.c 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/drivers/gpio/gpio-ftgpio010.c 2016-12-01 20:59:24.384613985 +0100
@@ -0,0 +1,218 @@
+#include <linux/module.h>
+#include <linux/irq.h>
+#include <linux/interrupt.h>
+#include <linux/io.h>
+#include <linux/gpio.h>
+
+#define GPIO_DATA_OUT 0x00
+#define GPIO_DATA_IN 0x04
+#define PIN_DIR 0x08
+#define PIN_BYPASS 0x0C
+#define GPIO_DATA_SET 0x10
+#define GPIO_DATA_CLEAR 0x14
+#define PIN_PULL_ENABLE 0x18
+#define PIN_PULL_TYPE 0x1C
+#define INT_ENABLE 0x20
+#define INT_RAW_STATE 0x24
+#define INT_MASKED_STATE 0x28
+#define INT_MASK 0x2C
+#define INT_CLEAR 0x30
+#define INT_TRIGGER 0x34
+#define INT_BOTH 0x38
+#define INT_RISE_NEG 0x3C
+#define BOUNCE_ENABLE 0x40
+#define BOUNCE_PRE_SCALE 0x44
+
+#define GPIO_READL(offset) \
+ readl(GPIO_FTGPIO010_VA_BASE + (offset))
+
+#define GPIO_WRITEL(val, offset) \
+ writel((val), GPIO_FTGPIO010_VA_BASE + (offset))
+
+#define FTGPIO010_VIRTUAL_IRQ_BASE 100
+
+static int irq_to_gpio(unsigned int irq)
+{
+ return irq - FTGPIO010_VIRTUAL_IRQ_BASE;
+}
+
+static int ftgpio_to_irq(struct gpio_chip *gc, unsigned int offset)
+{
+ return FTGPIO010_VIRTUAL_IRQ_BASE + offset;
+}
+
+static int ftgpio_get(struct gpio_chip *gc, unsigned int gpio)
+{
+ return (GPIO_READL(GPIO_DATA_IN) >> gpio & 1);
+}
+
+static void ftgpio_set(struct gpio_chip *gc, unsigned int gpio, int data)
+{
+ unsigned long val;
+
+ if (data)
+ val = GPIO_READL(GPIO_DATA_OUT) | (0x1UL << gpio);
+ else
+ val = GPIO_READL(GPIO_DATA_OUT) & ~(0x1UL << gpio);
+
+ GPIO_WRITEL(val, GPIO_DATA_OUT);
+}
+
+static int ftgpio_dir_in(struct gpio_chip *gc, unsigned int gpio)
+{
+ unsigned long val;
+
+ val = GPIO_READL(PIN_DIR) & ~(0x1UL << gpio);
+ GPIO_WRITEL(val, PIN_DIR);
+
+ return 0;
+}
+
+static int ftgpio_dir_out(struct gpio_chip *gc, unsigned int gpio, int data)
+{
+ unsigned long val;
+
+ val = GPIO_READL(PIN_DIR) | (0x1UL << gpio);
+ GPIO_WRITEL(val, PIN_DIR);
+
+ gc->set(gc, gpio, data);
+
+ return 0;
+}
+
+static struct gpio_chip ftgpio_chip = {
+
+ .label = "FTGPIO010",
+ .base = 0,
+ .ngpio = 16,
+ .direction_input = ftgpio_dir_in,
+ .direction_output = ftgpio_dir_out,
+ .get = ftgpio_get,
+ .set = ftgpio_set,
+ .to_irq = ftgpio_to_irq,
+};
+
+static void ftgpio_irq_ack(struct irq_data *data)
+{
+ GPIO_WRITEL(0x1UL << irq_to_gpio(data->irq), INT_CLEAR);
+}
+
+static void ftgpio_irq_mask(struct irq_data *data)
+{
+ unsigned long val;
+
+ val = GPIO_READL(INT_MASK) | (0x1UL << irq_to_gpio(data->irq));
+ GPIO_WRITEL(val, INT_MASK);
+}
+
+static void ftgpio_irq_unmask(struct irq_data *data)
+{
+ unsigned long val;
+ val = GPIO_READL(INT_MASK) & ~(0x1UL << irq_to_gpio(data->irq));
+ GPIO_WRITEL(val, INT_MASK);
+}
+
+static int ftgpio_irq_set_type(struct irq_data *data, unsigned int flow_type)
+{
+ unsigned long bit = 0x1UL << irq_to_gpio(data->irq);
+ unsigned long val;
+ val = GPIO_READL(INT_BOTH);
+
+ if (flow_type & IRQF_TRIGGER_RISING && flow_type & IRQF_TRIGGER_FALLING)
+ GPIO_WRITEL(val | bit, INT_BOTH);
+ else
+ GPIO_WRITEL(val & ~bit, INT_BOTH);
+
+ val = GPIO_READL(INT_RISE_NEG);
+
+ if (flow_type & IRQF_TRIGGER_FALLING)
+ GPIO_WRITEL(val | bit, INT_RISE_NEG);
+ else if (flow_type & IRQF_TRIGGER_RISING)
+ GPIO_WRITEL(val & ~bit, INT_RISE_NEG);
+
+ return 0;
+}
+
+static struct irq_chip ftgpio_irq_chip = {
+
+ .name = "FTGPIO010_irq",
+ .irq_ack = ftgpio_irq_ack,
+ .irq_mask = ftgpio_irq_mask,
+ .irq_unmask = ftgpio_irq_unmask,
+ .irq_set_type = ftgpio_irq_set_type,
+};
+
+static void gpio_irq_router(unsigned int irq, struct irq_desc *desc)
+{
+ unsigned long status;
+ int i = 0;
+
+ status = GPIO_READL(INT_RAW_STATE);
+ status &= ~((1 << 22) | (1 << 25) | (1 << 26));
+
+ while (status) {
+
+ if (status & 0x1UL)
+ generic_handle_irq(gpio_to_irq(i));
+
+ status >>= 1;
+ i++;
+ }
+}
+
+static int gpio_init(void)
+{
+ int i;
+
+ /* disable interrupt */
+ GPIO_WRITEL(0x00000000UL, INT_ENABLE);
+
+ /* mask interrupt */
+ GPIO_WRITEL(0x0000FFFFUL, INT_MASK);
+
+ /* triggered interrupt on both edge */
+ GPIO_WRITEL(0x0000FFFFUL, INT_BOTH);
+
+ /* clear interrupt */
+ GPIO_WRITEL(0x0000FFFFUL, INT_CLEAR);
+
+ /* enable de-bouncing */
+ GPIO_WRITEL(0x0000FFFFUL, BOUNCE_ENABLE);
+
+ /* enable interrupt */
+ GPIO_WRITEL(0x0000FFFFUL, INT_ENABLE);
+
+ gpiochip_add(&ftgpio_chip);
+
+ for (i = 0; i < ftgpio_chip.ngpio; i++) {
+
+ irq_set_chip(gpio_to_irq(i), &ftgpio_irq_chip);
+ irq_set_handler(gpio_to_irq(i), handle_level_irq);
+ }
+
+ irq_set_chained_handler(GPIO_FTGPIO010_IRQ, gpio_irq_router);
+
+ pr_info("GPIO module inserted\n");
+
+ return 0;
+}
+
+static void __exit gpio_exit(void)
+{
+ int i=0;
+ /* disable interrupt */
+ GPIO_WRITEL(0x00000000UL, INT_ENABLE);
+ while(i<ftgpio_chip.ngpio)
+ gpio_free(i++);
+
+ if (gpiochip_remove(&ftgpio_chip))
+ pr_info("failed to remove gpiochip\n");
+
+ pr_info("GPIO module removed\n");
+}
+
+MODULE_DESCRIPTION("FTGPIO010");
+MODULE_LICENSE("GPL");
+
+module_init(gpio_init);
+module_exit(gpio_exit);
diff -Nur linux-3.4.113.orig/drivers/gpio/Kconfig linux-3.4.113/drivers/gpio/Kconfig
--- linux-3.4.113.orig/drivers/gpio/Kconfig 2016-10-26 17:15:47.000000000 +0200
+++ linux-3.4.113/drivers/gpio/Kconfig 2016-12-01 20:59:24.384613985 +0100
@@ -492,6 +492,10 @@
This enables support for the Philips UCB1400 GPIO pins.
The UCB1400 is an AC97 audio codec.
+config GPIO_FTGPIO010
+ tristate "Farady FTGPIO010 GPIO support"
+ depends on NDS32 && GENERIC_GPIO && ARCH_WANT_OPTIONAL_GPIOLIB
+
comment "MODULbus GPIO expanders:"
config GPIO_JANZ_TTL
diff -Nur linux-3.4.113.orig/drivers/gpio/Makefile linux-3.4.113/drivers/gpio/Makefile
--- linux-3.4.113.orig/drivers/gpio/Makefile 2016-10-26 17:15:47.000000000 +0200
+++ linux-3.4.113/drivers/gpio/Makefile 2016-12-01 20:59:24.384613985 +0100
@@ -64,3 +64,4 @@
obj-$(CONFIG_GPIO_WM8350) += gpio-wm8350.o
obj-$(CONFIG_GPIO_WM8994) += gpio-wm8994.o
obj-$(CONFIG_GPIO_XILINX) += gpio-xilinx.o
+obj-$(CONFIG_GPIO_FTGPIO010) += gpio-ftgpio010.o
\ No newline at end of file
diff -Nur linux-3.4.113.orig/drivers/input/touchscreen/cpe_ts/cpe_ts.c linux-3.4.113/drivers/input/touchscreen/cpe_ts/cpe_ts.c
--- linux-3.4.113.orig/drivers/input/touchscreen/cpe_ts/cpe_ts.c 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/drivers/input/touchscreen/cpe_ts/cpe_ts.c 2016-12-01 20:59:24.384613985 +0100
@@ -0,0 +1,376 @@
+#include <linux/input.h>
+#include <linux/interrupt.h>
+#include <linux/platform_device.h>
+#include <linux/io.h>
+
+#include <asm/irq.h>
+#include "cpe_ts.h"
+
+
+#include <linux/module.h>
+
+#include <linux/irqnr.h>
+#include <linux/irq.h>
+
+#define TOUCHSCREEN_IRQ 28
+
+#define ads_dbg( enabled, tagged, ...) \
+ do{ \
+ if( enabled){ \
+ if( tagged) \
+ printk( "[ %30s() ] ", __func__); \
+ printk( __VA_ARGS__); \
+ } \
+ } while( 0)
+
+#define TS_POLL_DELAY ( 1 * 1000000) /* ns delay before the first sample */
+#define TS_POLL_PERIOD ( delay * 1000000) /* ns delay between samples */
+
+static int debug = 0;
+static int delay = 25;
+
+module_param(debug, int, 0);
+module_param(delay, int, 0);
+
+struct ads7846
+{
+ void __iomem * regs;
+ struct input_dev *input;
+ char phys[32];
+ struct hrtimer timer;
+ int irq;
+ spinlock_t lock;
+ bool disabled;
+};
+
+struct ts_event
+{
+ int x;
+ int y;
+ int z1, z2;
+ int Rt;
+};
+
+struct ads7846 touchscreen;
+
+#define ADS_START ( 0x1UL << 7)
+#define ADS_A2A1A0_d_y ( 0x1UL << 4) /* differential */
+#define ADS_A2A1A0_d_z1 ( 0x3UL << 4) /* differential */
+#define ADS_A2A1A0_d_z2 ( 0x4UL << 4) /* differential */
+#define ADS_A2A1A0_d_x ( 0x5UL << 4) /* differential */
+#define ADS_12_BIT ( 0x0UL << 3)
+#define ADS_SER ( 0x1UL << 2) /* non-differential */
+#define ADS_DFR ( 0x0UL << 2) /* differential */
+#define ADS_PD10_PDOWN ( 0x0UL << 0) /* lowpower mode + penirq */
+#define ADS_PD10_ADC_ON ( 0x1UL << 0) /* ADC on */
+#define ADS_PD10_REF_ON ( 0x2UL << 0) /* vREF on + penirq */
+#define ADS_PD10_ALL_ON ( 0x3UL << 0) /* ADC + vREF on */
+
+#define MAX_12BIT ( ( 0x1UL << 12) - 1)
+
+#define READ_X ( ADS_A2A1A0_d_x | ADS_12_BIT | ADS_DFR)
+#define READ_Y ( ADS_A2A1A0_d_y | ADS_12_BIT | ADS_DFR)
+#define READ_Z1 ( ADS_A2A1A0_d_z1 | ADS_12_BIT | ADS_DFR)
+#define READ_Z2 ( ADS_A2A1A0_d_z2 | ADS_12_BIT | ADS_DFR)
+
+static int
+read_val(struct ads7846 *ts, unsigned long cmd)
+{
+ unsigned long data = 0;
+ int repeat = 5;
+ int i;
+
+ ads_dbg(0, 1, "Queuing data: 0x%08lx\n", cmd << 16);
+
+ for (i = 0; i < repeat; i++)
+ {
+ while (!(REG32(ts->regs + SSP_REG_SR) & SSP_SR_mskTFNF));
+ REG32(ts->regs + SSP_REG_DR) = (ADS_START | cmd | ADS_PD10_ALL_ON) << 16;
+ }
+
+ for (i = 0; i < repeat; i++)
+ {
+ while (!(REG32(ts->regs + SSP_REG_SR) & SSP_SR_mskRFVE));
+ data = (REG32(ts->regs + SSP_REG_DR) >> 3) & 0xFFF;
+ }
+
+ while (!(REG32(ts->regs + SSP_REG_SR) & SSP_SR_mskTFNF));
+ REG32(ts->regs + SSP_REG_DR) = (ADS_START | cmd) << 16;
+
+ while (!(REG32(ts->regs + SSP_REG_SR) & SSP_SR_mskRFVE));
+
+ data = (REG32(ts->regs + SSP_REG_DR) >> 3) & 0xFFF;
+ ads_dbg(0, 1, "CMD <%02lx> data: 0x%08lx( %ld)\n", cmd, data, data);
+
+ return data;
+}
+
+static int pendown(struct ads7846 *ts)
+{
+ return read_val(ts, READ_Z1) > 40;
+}
+
+static void report(struct ads7846 *ts, struct ts_event *e)
+{
+ e->x = read_val(ts, READ_X);
+ e->y = read_val(ts, READ_Y);
+ e->z1 = read_val(ts, READ_Z1);
+ e->z2 = read_val(ts, READ_Z2);
+
+ ads_dbg(debug, 1, "x: %4d, y: %4d, z1: %4d, z2: %4d\n", e->x, e->y, e->z1, e->z2);
+}
+
+#define FILTER_LIMIT 35
+
+static enum hrtimer_restart ads7846_timer(struct hrtimer *handle)
+{
+ struct ads7846 *ts = container_of(handle, struct ads7846, timer);
+ struct ts_event e;
+ struct irq_desc *desc = (struct irq_desc *)irq_get_irq_data((unsigned int)ts->irq);
+ static int xp = 0, yp = 0;
+
+ if (ts->disabled)
+ return HRTIMER_NORESTART;
+
+ if (!pendown(ts))
+ {
+ ads_dbg(debug, 1, "Release\n");
+
+ input_report_key(ts->input, BTN_TOUCH, 0);
+ input_report_abs(ts->input, ABS_PRESSURE, 0);
+ input_sync(ts->input);
+
+ if(desc->irq_data.chip->irq_ack)
+ desc->irq_data.chip->irq_ack(&desc->irq_data);
+ enable_irq(ts->irq);
+ return HRTIMER_NORESTART;
+ }
+ report(ts, &e);
+
+#ifdef CONFIG_TOUCHSCREEN_CPE_TS_DEJITTER
+ if (abs(xp - e.x) > FILTER_LIMIT || abs(yp - e.y) > FILTER_LIMIT)
+ {
+#endif
+ input_report_key(ts->input, BTN_TOUCH, 1);
+ input_report_abs(ts->input, ABS_X, e.x);
+ input_report_abs(ts->input, ABS_Y, e.y);
+ input_report_abs(ts->input, ABS_PRESSURE, 50);
+ xp = e.x;
+ yp = e.y;
+#ifdef CONFIG_TOUCHSCREEN_CPE_TS_DEJITTER
+ }
+#endif
+ input_sync(ts->input);
+ hrtimer_start(&ts->timer, ktime_set(0, TS_POLL_PERIOD), HRTIMER_MODE_REL);
+ ads_dbg(0, 1, "Leave\n");
+ return HRTIMER_NORESTART;
+}
+
+static irqreturn_t ads7846_irq(int irq, void *handle)
+{
+ struct ads7846 *ts = handle;
+
+ if (ts->disabled)
+ return IRQ_HANDLED;
+
+ disable_irq_nosync(irq);
+ hrtimer_start(&ts->timer, ktime_set(0, TS_POLL_DELAY), HRTIMER_MODE_REL);
+
+ return IRQ_HANDLED;
+}
+
+static int xspi_init_hw(void __iomem *regs_base)
+{
+ int rev = REG32(regs_base + SSP_REG_REV);
+ int reva = REG32(regs_base + SSP_REG_REV-0x20);
+
+ if ((((rev & SSP_REV_mskMAJOR_REV) >> SSP_REV_offMAJOR_REV) != 1)&&
+ (((reva & SSP_REV_mskMAJOR_REV) >> SSP_REV_offMAJOR_REV) != 1))
+ {
+ ads_dbg(1, 0, "ADS7846 Touchscreen controller initialized failed:\n"
+ "\tcannot detect Faraday SSP Controller\n");
+ return -ENXIO;
+ }
+ REG32(regs_base + SSP_REG_CR2) |= (1UL << SSP_CR2_offSSPRST);
+
+ REG32(regs_base + SSP_REG_CR1) =
+ (0UL << SSP_CR1_offPDL) | /* Padding Data Length */
+ (23UL << SSP_CR1_offSDL) | /* Serial Data Length */
+ (5UL << SSP_CR1_offSCLKDIV); /* SCLK Divider */
+
+ REG32(regs_base + SSP_REG_CR0) =
+ (1UL << SSP_CR0_offFFMT) | /* Frame Format */
+ (3UL << SSP_CR0_offOPM) | /* Operation Mode */
+ (0UL << SSP_CR0_offSCLKPO) | /* SCLK Polarity */
+ (0UL << SSP_CR0_offSCLKPH); /* SCLK Phase */
+
+ REG32(regs_base + SSP_REG_CR2) |= (1UL << SSP_CR2_offTXFCLR) | (1UL << SSP_CR2_offRXFCLR);
+ REG32(regs_base + SSP_REG_CR2) |= (1UL << SSP_CR2_offSSPEN) | (1UL << SSP_CR2_offTXDOE);
+ return 0;
+}
+
+static int ads7846_probe(struct platform_device *pdev)
+{
+ struct ads7846 *ts = &touchscreen;
+ struct input_dev *input_dev;
+ int err = 0;
+ platform_set_drvdata(pdev, ts);
+
+ ts->regs = ioremap(0x98b00000, 44);
+ err = xspi_init_hw(ts->regs);
+ if (err)
+ goto err_unmap;
+ input_dev = input_allocate_device();
+ if (!input_dev)
+ {
+ err = -ENOMEM;
+ goto err_free_mem;
+ }
+
+ ts->input = input_dev;
+
+ hrtimer_init(&ts->timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
+ ts->timer.function = ads7846_timer;
+
+ input_dev->name = "ADS7846 Touchscreen";
+ input_dev->phys = ts->phys;
+
+ input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
+ input_dev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH);
+ input_set_abs_params(input_dev, ABS_X, 0, MAX_12BIT, 0, 0);
+ input_set_abs_params(input_dev, ABS_Y, 0, MAX_12BIT, 0, 0);
+ input_set_abs_params(input_dev, ABS_PRESSURE, 0, MAX_12BIT, 0, 0);
+
+ ts->irq = TOUCHSCREEN_IRQ;
+
+ if (request_irq(ts->irq, ads7846_irq, IRQF_TRIGGER_RISING, "touch screen", ts))
+ goto err_free_mem;
+
+ err = input_register_device(input_dev);
+ if (err)
+ goto err_free_irq;
+
+ spin_lock_init(&ts->lock);
+ return 0;
+err_free_irq:
+ free_irq(ts->irq, ts);
+err_free_mem:
+ input_free_device(input_dev);
+err_unmap:
+ iounmap(ts->regs);
+
+ return err;
+}
+
+static int __devexit ads7846_remove(struct platform_device *pdev)
+{
+ struct ads7846 *ts = platform_get_drvdata(pdev);
+
+ disable_irq(ts->irq);
+ free_irq(ts->irq, ts);
+ iounmap(ts->regs);
+ input_unregister_device(ts->input);
+
+ return 0;
+}
+
+#ifdef CONFIG_PM
+static int ads7846_suspend( struct platform_device *pdev, pm_message_t message)
+{
+ struct ads7846 *ts = platform_get_drvdata(pdev);
+
+ spin_lock_irq(&ts->lock);
+ ts->disabled = true;
+ disable_irq(ts->irq);
+ spin_unlock_irq(&ts->lock);
+
+ return 0;
+}
+
+static int ads7846_resume( struct platform_device *pdev)
+{
+ struct ads7846 *ts = platform_get_drvdata(pdev);
+
+ spin_lock_irq(&ts->lock);
+
+ enable_irq(ts->irq);
+ ts->disabled = false;
+
+ spin_unlock_irq(&ts->lock);
+
+ return 0;
+}
+#else
+#define ads7846_suspend NULL
+#define ads7846_resume NULL
+#endif
+
+static void platform_device_release(struct device *dev){
+}
+
+static struct resource ads7846_resources[] =
+{
+ [0] = {
+ .start = SSP_FTSSP010_PA_BASE,
+ .end = SSP_FTSSP010_PA_LIMIT,
+ .flags = IORESOURCE_MEM,
+ },
+ [1] = {
+ .start = TOUCHSCREEN_IRQ, //feed me! SSP_FTSSP010_IRQ in spec.h
+ .end = TOUCHSCREEN_IRQ,
+ .flags = IORESOURCE_IRQ,
+ },
+};
+
+static struct platform_device ads7846_device =
+{
+ .name = "ads7846",
+ .id = -1,
+ .resource = ads7846_resources,
+ .num_resources = ARRAY_SIZE(ads7846_resources),
+ .dev = {
+ .release = platform_device_release,
+ },
+};
+
+#if 0
+static struct platform_driver ads7846_driver =
+{
+ .driver = {
+ .name = "ads7846",
+ .owner = THIS_MODULE,
+ },
+ .probe = ads7846_probe,
+ .remove = __devexit_p(ads7846_remove),
+ .suspend = ads7846_suspend,
+ .resume = ads7846_resume,
+};
+#else
+static struct platform_driver ads7846_driver =
+{
+ .driver = {
+ .name = "ads7846",
+ },
+ .probe = ads7846_probe,
+ .remove = __devexit_p(ads7846_remove),
+ .suspend = ads7846_suspend,
+ .resume = ads7846_resume,
+};
+#endif
+
+static int __init ads7846_init(void)
+{
+ platform_device_register(&ads7846_device);
+ return platform_driver_register(&ads7846_driver);
+}
+
+static void __exit ads7846_exit(void)
+{
+ platform_device_unregister(&ads7846_device);
+ platform_driver_unregister(&ads7846_driver);
+}
+
+module_init(ads7846_init);
+module_exit(ads7846_exit);
+MODULE_DESCRIPTION("ADS7846 TouchScreen Driver");
+MODULE_LICENSE("GPL");
diff -Nur linux-3.4.113.orig/drivers/input/touchscreen/cpe_ts/cpe_ts.h linux-3.4.113/drivers/input/touchscreen/cpe_ts/cpe_ts.h
--- linux-3.4.113.orig/drivers/input/touchscreen/cpe_ts/cpe_ts.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/drivers/input/touchscreen/cpe_ts/cpe_ts.h 2016-12-01 20:59:24.384613985 +0100
@@ -0,0 +1,218 @@
+#ifndef SSP_FARADAY_H
+#define SSP_FARADAY_H
+
+#define XILINX_SPI_NAME "faraday-spi"
+
+/*
+ * Register definitions as per "OPB Serial Peripheral Interface ( SPI) ( v1.00e)
+ * Product Specification", DS464
+ */
+#define XSPI_CR_OFFSET 0x62 /* 16-bit Control Register */
+
+#define XSPI_CR_ENABLE 0x02
+#define XSPI_CR_MASTER_MODE 0x04
+#define XSPI_CR_CPOL 0x08
+#define XSPI_CR_CPHA 0x10
+#define XSPI_CR_MODE_MASK ( XSPI_CR_CPHA | XSPI_CR_CPOL)
+#define XSPI_CR_TXFIFO_RESET 0x20
+#define XSPI_CR_RXFIFO_RESET 0x40
+#define XSPI_CR_MANUAL_SSELECT 0x80
+#define XSPI_CR_TRANS_INHIBIT 0x100
+
+#define XSPI_SR_OFFSET 0x67 /* 8-bit Status Register */
+
+#define XSPI_SR_RX_EMPTY_MASK 0x01 /* Receive FIFO is empty */
+#define XSPI_SR_RX_FULL_MASK 0x02 /* Receive FIFO is full */
+#define XSPI_SR_TX_EMPTY_MASK 0x04 /* Transmit FIFO is empty */
+#define XSPI_SR_TX_FULL_MASK 0x08 /* Transmit FIFO is full */
+#define XSPI_SR_MODE_FAULT_MASK 0x10 /* Mode fault error */
+
+#define XSPI_TXD_OFFSET 0x6b /* 8-bit Data Transmit Register */
+#define XSPI_RXD_OFFSET 0x6f /* 8-bit Data Receive Register */
+
+#define XSPI_SSR_OFFSET 0x70 /* 32-bit Slave Select Register */
+
+/* Register definitions as per "OPB IPIF ( v3.01c) Product Specification", DS414
+ * IPIF registers are 32 bit
+ */
+#define XIPIF_V123B_DGIER_OFFSET 0x1c /* IPIF global int enable reg */
+#define XIPIF_V123B_GINTR_ENABLE 0x80000000
+
+#define XIPIF_V123B_IISR_OFFSET 0x20 /* IPIF interrupt status reg */
+#define XIPIF_V123B_IIER_OFFSET 0x28 /* IPIF interrupt enable reg */
+
+#define XSPI_INTR_MODE_FAULT 0x01 /* Mode fault error */
+#define XSPI_INTR_SLAVE_MODE_FAULT 0x02 /* Selected as slave while disabled */
+#define XSPI_INTR_TX_EMPTY 0x04 /* TxFIFO is empty */
+#define XSPI_INTR_TX_UNDERRUN 0x08 /* TxFIFO was underrun */
+#define XSPI_INTR_RX_FULL 0x10 /* RxFIFO is full */
+#define XSPI_INTR_RX_OVERRUN 0x20 /* RxFIFO was overrun */
+
+#define XIPIF_V123B_RESETR_OFFSET 0x40 /* IPIF reset register */
+#define XIPIF_V123B_RESET_MASK 0x0a /* the value to write */
+
+/*************************************************************************/
+#if 0
+#define SSP_REG_CR0 ( SSP_FTSSP010_VA_BASE + 0x00) /* SSP Control Register 0 */
+#define SSP_REG_CR1 ( SSP_FTSSP010_VA_BASE + 0x04) /* SSP Control Register 1 */
+#define SSP_REG_CR2 ( SSP_FTSSP010_VA_BASE + 0x08) /* SSP Control Register 2 */
+#define SSP_REG_SR ( SSP_FTSSP010_VA_BASE + 0x0c) /* SSP Status Register */
+#define SSP_REG_ICR ( SSP_FTSSP010_VA_BASE + 0x10) /* SSP Interrupt Control Register */
+#define SSP_REG_ISR ( SSP_FTSSP010_VA_BASE + 0x14) /* SSP Interrupt Status Register */
+#define SSP_REG_DR ( SSP_FTSSP010_VA_BASE + 0x18) /* SSP Data Register */
+#define SSP_REG_ACL ( SSP_FTSSP010_VA_BASE + 0x20) /* AC-Link Slot Valid Register */
+#define SSP_REG_REV ( SSP_FTSSP010_VA_BASE + 0x40) /* SSP Revision Register */
+#define SSP_REG_FEA ( SSP_FTSSP010_VA_BASE + 0x44) /* SSP Feature Register */
+#endif
+#define SSP_REG_CR0 0x00 /* SSP Control Register 0 */
+#define SSP_REG_CR1 0x04 /* SSP Control Register 1 */
+#define SSP_REG_CR2 0x08 /* SSP Control Register 2 */
+#define SSP_REG_SR 0x0C /* SSP Status Register */
+#define SSP_REG_ICR 0x10 /* SSP Interrupt Control Register */
+#define SSP_REG_ISR 0x14 /* SSP Interrupt Status Register */
+#define SSP_REG_DR 0x18 /* SSP Data Register */
+#define SSP_REG_ACL 0x20 /* AC-Link Slot Valid Register */
+#define SSP_REG_REV 0x60 /* SSP Revision Register */
+#define SSP_REG_FEA 0x64 /* SSP Feature Register */
+
+#define SSP_CR0_offFFMT 12 /* Frame Format */
+#define SSP_CR0_offFSDIST 8 /* Frame/Sync and Data Distance */
+#define SSP_CR0_offLBM 7 /* Loopback Mode */
+#define SSP_CR0_offLSB 6 /* Bit Sequence Indicator */
+#define SSP_CR0_offFSPO 5 /* Frame/Sync Polarity */
+#define SSP_CR0_offFSJSFY 4 /* Data Justify */
+#define SSP_CR0_offOPM 2 /* Operation Mode */
+#define SSP_CR0_offSCLKPO 1 /* SCLK Polarity */
+#define SSP_CR0_offSCLKPH 0 /* SCLK Phase */
+
+#define SSP_CR0_mskFFMT ( 0x07UL << SSP_CR0_offFFMT)
+#define SSP_CR0_mskFSDIST ( 0x03UL << SSP_CR0_offFSDIST)
+#define SSP_CR0_mskLBM ( 0x01UL << SSP_CR0_offLBM)
+#define SSP_CR0_mskLSB ( 0x01UL << SSP_CR0_offLSB)
+#define SSP_CR0_mskFSPO ( 0x01UL << SSP_CR0_offFSPO)
+#define SSP_CR0_mskFSJSFY ( 0x01UL << SSP_CR0_offFSJSFY)
+#define SSP_CR0_mskOPM ( 0x03UL << SSP_CR0_offOPM)
+#define SSP_CR0_mskSCLKPO ( 0x01UL << SSP_CR0_offSCLKPO)
+#define SSP_CR0_mskSCLKPH ( 0x01UL << SSP_CR0_offSCLKPH)
+
+#define SSP_CR1_offPDL 24 /* Padding Data Length */
+#define SSP_CR1_offSDL 16 /* Serial Data Length */
+#define SSP_CR1_offSCLKDIV 0 /* SCLK Divider */
+
+#define SSP_CR1_mskPDL ( 0xFFUL << SSP_CR1_offPDL)
+#define SSP_CR1_mskSDL ( 0x1FUL << SSP_CR1_offSDL)
+#define SSP_CR1_mskSCLKDIV ( 0xFFUL << SSP_CR1_offSCLKDIV)
+
+#define SSP_CR2_offSSPRST 6 /* SSP Reset */
+#define SSP_CR2_offACCRST 5 /* AC-Link Cold Reset Enable */
+#define SSP_CR2_offACWRST 4 /* AC-Link Warm Reset Enable */
+#define SSP_CR2_offTXFCLR 3 /* Transmit FIFO Clear */
+#define SSP_CR2_offRXFCLR 2 /* Recieve FIFO clear */
+#define SSP_CR2_offTXDOE 1 /* Transmit Data Output Enable */
+#define SSP_CR2_offSSPEN 0 /* The SSP Enable */
+
+#define SSP_CR2_mskSSPRST ( 0x01UL << SSP_CR2_offSSPRST)
+#define SSP_CR2_mskACCRST ( 0x01UL << SSP_CR2_offACCRST)
+#define SSP_CR2_mskACWRST ( 0x01UL << SSP_CR2_offACWRST)
+#define SSP_CR2_mskTXFCLR ( 0x01UL << SSP_CR2_offTXFCLR)
+#define SSP_CR2_mskRXFCLR ( 0x01UL << SSP_CR2_offRXFCLR)
+#define SSP_CR2_mskTXDOE ( 0x01UL << SSP_CR2_offTXDOE)
+#define SSP_CR2_mskSSPEN ( 0x01UL << SSP_CR2_offSSPEN)
+
+#define SSP_SR_offTFVE 12 /* Transmit FIFO Valid Entries */
+#define SSP_SR_offRFVE 4 /* Recieve FIFO Valid Entries */
+#define SSP_SR_offBUSY 2 /* Busy Indicator */
+#define SSP_SR_offTFNF 1 /* Transmit FIFO not full */
+#define SSP_SR_offRFF 0 /* Recieve FIFO full */
+
+#define SSP_SR_mskTFVE ( 0x1FUL << SSP_SR_offTFVE)
+#define SSP_SR_mskRFVE ( 0x1FUL << SSP_SR_offRFVE)
+#define SSP_SR_mskBUSY ( 0x01UL << SSP_SR_offBUSY)
+#define SSP_SR_mskTFNF ( 0x01UL << SSP_SR_offTFNF)
+#define SSP_SR_mskRFF ( 0x01UL << SSP_SR_offRFF)
+
+#define SSP_ICR_offTFTHOD 12 /* Transmit FIFO Threshold */
+#define SSP_ICR_offRFTHOD 8 /* Recieve FIFO Threshold */
+#define SSP_ICR_offAC97FCEN 6 /* AC97 Frame Complete */
+#define SSP_ICR_offTFDMAEN 5 /* Transmit DMA Request Enable */
+#define SSP_ICR_offRFDMAEN 4 /* Recieve DMA Request Enable */
+#define SSP_ICR_offTFTHIEN 3 /* Transmit FIFO Threshold Interrupt */
+#define SSP_ICR_offRFTHIEN 2 /* Recieve FIFO Threshold Interrupt */
+#define SSP_ICR_offTFURIEN 1 /* Transmit FIFO Underrun Interrupt Enable */
+#define SSP_ICR_offRFORIEN 0 /* Recieve FIFO Overrun Interrupt Enable */
+
+#define SSP_ICR_mskTFTHOD ( 0x0FUL << SSP_ICR_offTFTHOD)
+#define SSP_ICR_mskRFTHOD ( 0x0FUL << SSP_ICR_offRFTHOD)
+#define SSP_ICR_mskAC97FCEN ( 0x01UL << SSP_ICR_offAC97FCEN)
+#define SSP_ICR_mskTFDMAEN ( 0x01UL << SSP_ICR_offTFDMAEN)
+#define SSP_ICR_mskRFDMAEN ( 0x01UL << SSP_ICR_offRFDMAEN)
+#define SSP_ICR_mskTFTHIEN ( 0x01UL << SSP_ICR_offTFTHIEN)
+#define SSP_ICR_mskRFTHIEN ( 0x01UL << SSP_ICR_offRFTHIEN)
+#define SSP_ICR_mskTFURIEN ( 0x01UL << SSP_ICR_offTFURIEN)
+#define SSP_ICR_mskRFORIEN ( 0x01UL << SSP_ICR_offRFORIEN)
+
+#define SSP_ISR_offAC97FCI 4 /* AC97 Frame Complete Interrupt */
+#define SSP_ISR_offTFTHI 3 /* Transmit FIFO Threshold Interrupt */
+#define SSP_ISR_offRFTHI 2 /* Recieve FIFO Threshold Interrupt */
+#define SSP_ISR_offTFURI 1 /* Transmit FIFO underrun Interrupt */
+#define SSP_ISR_offRFORI 0 /* Recieve FIFO Overun Interrupt */
+
+#define SSP_ISR_mskAC97FCI ( 0x01UL << SSP_ISR_offAC97FCI)
+#define SSP_ISR_mskTFTHI ( 0x01UL << SSP_ISR_offTFTHI)
+#define SSP_ISR_mskRFTHI ( 0x01UL << SSP_ISR_offRFTHI)
+#define SSP_ISR_mskTFURI ( 0x01UL << SSP_ISR_offTFURI)
+#define SSP_ISR_mskRFORI ( 0x01UL << SSP_ISR_offRFORI)
+
+#define SSP_ACL_offSLOT1V 14 /* The 1st Slot is Valid */
+#define SSP_ACL_offSLOT2V 13 /* The 2nd Slot is Valid */
+#define SSP_ACL_offSLOT3V 12 /* The 3th Slot is Valid */
+#define SSP_ACL_offSLOT4V 11 /* The 4th Slot is Valid */
+#define SSP_ACL_offSLOT5V 10 /* The 5th Slot is Valid */
+#define SSP_ACL_offSLOT6V 9 /* The 6th Slot is Valid */
+#define SSP_ACL_offSLOT7V 8 /* The 7th Slot is Valid */
+#define SSP_ACL_offSLOT8V 7 /* The 8th Slot is Valid */
+#define SSP_ACL_offSLOT9V 6 /* The 9th Slot is Valid */
+#define SSP_ACL_offSLOT10V 5 /* The 10th Slot is Valid */
+#define SSP_ACL_offSLOT11V 4 /* The 11th Slot is Valid */
+#define SSP_ACL_offSLOT12V 3 /* The 12th Slot is Valid */
+#define SSP_ACL_offCODECID 0 /* Codec ID, which will be shifted out as tag slot */
+
+#define SSP_ACL_mskSLOT1V ( 0x01UL << SSP_ACL_offSLOT1V)
+#define SSP_ACL_mskSLOT2V ( 0x01UL << SSP_ACL_offSLOT2V)
+#define SSP_ACL_mskSLOT3V ( 0x01UL << SSP_ACL_offSLOT3V)
+#define SSP_ACL_mskSLOT4V ( 0x01UL << SSP_ACL_offSLOT4V)
+#define SSP_ACL_mskSLOT5V ( 0x01UL << SSP_ACL_offSLOT5V)
+#define SSP_ACL_mskSLOT6V ( 0x01UL << SSP_ACL_offSLOT6V)
+#define SSP_ACL_mskSLOT7V ( 0x01UL << SSP_ACL_offSLOT7V)
+#define SSP_ACL_mskSLOT8V ( 0x01UL << SSP_ACL_offSLOT8V)
+#define SSP_ACL_mskSLOT9V ( 0x01UL << SSP_ACL_offSLOT9V)
+#define SSP_ACL_mskSLOT10V ( 0x01UL << SSP_ACL_offSLOT10V)
+#define SSP_ACL_mskSLOT11V ( 0x01UL << SSP_ACL_offSLOT11V)
+#define SSP_ACL_mskSLOT12V ( 0x01UL << SSP_ACL_offSLOT12V)
+#define SSP_ACL_mskCODECID ( 0x03UL << SSP_ACL_offCODECID)
+
+#define SSP_REV_offMAJOR_REV 16 /* Major Revision Number */
+#define SSP_REV_offMINOR_REV 8 /* Minor Revision Number */
+#define SSP_REV_offREL_REV 0 /* Release Number */
+
+#define SSP_REV_mskMAJOR_REV ( 0xFFUL << SSP_REV_offMAJOR_REV)
+#define SSP_REV_mskMINOR_REV ( 0xFFUL << SSP_REV_offMINOR_REV)
+#define SSP_REV_mskREL_REV ( 0xFFUL << SSP_REV_offREL_REV)
+
+#define SSP_FEA_offSSP_FCFG 27 /* The SSP Functional Configurations */
+#define SSP_FEA_offSPIMWR_FCFG 26 /* Motorola's SPI and National Semiconductor's Microwire Configurations */
+#define SSP_FEA_offI2S_FCFG 25 /* Philips's I2S Functional Configurations */
+#define SSP_FEA_offAC97_FCFG 24 /* Intel's AC-Link Functional Configurations */
+#define SSP_FEA_offTXFIFO_WIDTH 16 /* Transmit FIFO Size Configurations */
+#define SSP_FEA_offRXFIFO_WIDTH 8 /* Recieve FIFO Size Configuration */
+#define SSP_FEA_offFIFO_WIDTH 0 /* Transmit/Recieve FIFO Width */
+
+#define SSP_FEA_mskSSP_FCFG ( 0x01UL << SSP_FEA_offSSP_FCFG)
+#define SSP_FEA_mskSPIMWR_FCFG ( 0x01UL << SSP_FEA_offSPIMWR_FCFG)
+#define SSP_FEA_mskI2S_FCFG ( 0x01UL << SSP_FEA_offI2S_FCFG)
+#define SSP_FEA_mskAC97_FCFG ( 0x01UL << SSP_FEA_offAC97_FCFG)
+#define SSP_FEA_mskTXFIFO_WIDTH ( 0xFFUL << SSP_FEA_offTXFIFO_WIDTH)
+#define SSP_FEA_mskRXFIFO_WIDTH ( 0xFFUL << SSP_FEA_offRXFIFO_WIDTH)
+#define SSP_FEA_mskFIFO_WIDTH ( 0xFFUL << SSP_FEA_offFIFO_WIDTH)
+
+#endif /* SSP_FARADAY */
diff -Nur linux-3.4.113.orig/drivers/input/touchscreen/cpe_ts/Makefile linux-3.4.113/drivers/input/touchscreen/cpe_ts/Makefile
--- linux-3.4.113.orig/drivers/input/touchscreen/cpe_ts/Makefile 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/drivers/input/touchscreen/cpe_ts/Makefile 2016-12-01 20:59:24.384613985 +0100
@@ -0,0 +1 @@
+obj-$(CONFIG_TOUCHSCREEN_CPE_TS) += cpe_ts.o
diff -Nur linux-3.4.113.orig/drivers/input/touchscreen/Kconfig linux-3.4.113/drivers/input/touchscreen/Kconfig
--- linux-3.4.113.orig/drivers/input/touchscreen/Kconfig 2016-10-26 17:15:47.000000000 +0200
+++ linux-3.4.113/drivers/input/touchscreen/Kconfig 2016-12-01 20:59:24.384613985 +0100
@@ -86,6 +86,26 @@
To compile this driver as a module, choose M here: the
module will be called ad7879-spi.
+config TOUCHSCREEN_CPE_TS
+ tristate "Touchscreen Driver for AG101/XC5"
+ help
+ This driver directly accesses SPI controller to communicate with
+ the ads7846 chip.
+
+ Once we have a SPI controller driver
+ , we can adopt to the SPI
+ framework that kernel provides.
+
+config TOUCHSCREEN_CPE_TS_DEJITTER
+ bool "Dejitter Detection"
+ depends on TOUCHSCREEN_CPE_TS
+ default y
+ help
+ Say Y here to enable dejitter detection in AG101/Leopard Touchscreen Driver.
+
+ If unsure, say y.
+
+
config TOUCHSCREEN_ATMEL_MXT
tristate "Atmel mXT I2C Touchscreen"
depends on I2C
diff -Nur linux-3.4.113.orig/drivers/input/touchscreen/Makefile linux-3.4.113/drivers/input/touchscreen/Makefile
--- linux-3.4.113.orig/drivers/input/touchscreen/Makefile 2016-10-26 17:15:47.000000000 +0200
+++ linux-3.4.113/drivers/input/touchscreen/Makefile 2016-12-01 20:59:24.384613985 +0100
@@ -69,3 +69,4 @@
obj-$(CONFIG_TOUCHSCREEN_WM97XX_ZYLONITE) += zylonite-wm97xx.o
obj-$(CONFIG_TOUCHSCREEN_W90X900) += w90p910_ts.o
obj-$(CONFIG_TOUCHSCREEN_TPS6507X) += tps6507x-ts.o
+obj-$(CONFIG_TOUCHSCREEN_CPE_TS) += cpe_ts/
diff -Nur linux-3.4.113.orig/drivers/mmc/core/bus.c linux-3.4.113/drivers/mmc/core/bus.c
--- linux-3.4.113.orig/drivers/mmc/core/bus.c 2016-10-26 17:15:47.000000000 +0200
+++ linux-3.4.113/drivers/mmc/core/bus.c 2016-12-01 20:59:24.384613985 +0100
@@ -26,7 +26,9 @@
#include "bus.h"
#define to_mmc_driver(d) container_of(d, struct mmc_driver, drv)
-
+#ifdef CONFIG_MMC_TEST
+static struct mmc_driver *mmc_test_drv;
+#endif
static ssize_t mmc_type_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
@@ -109,6 +111,11 @@
struct mmc_driver *drv = to_mmc_driver(dev->driver);
struct mmc_card *card = mmc_dev_to_card(dev);
+ #ifdef CONFIG_MMC_TEST
+ mmc_test_drv->probe(card);
+ printk("debug mmc_bus_probe\n");
+ #endif
+
return drv->probe(card);
}
@@ -200,6 +207,11 @@
int mmc_register_driver(struct mmc_driver *drv)
{
drv->drv.bus = &mmc_bus_type;
+ #ifdef CONFIG_MMC_TEST
+ printk("debug defined config_mmc_test in mmc_register_driver\n");
+ if(!strcmp(drv->drv.name,"mmc_test"))
+ mmc_test_drv = drv;
+ #endif
return driver_register(&drv->drv);
}
diff -Nur linux-3.4.113.orig/drivers/mmc/host/ftsdc010.c linux-3.4.113/drivers/mmc/host/ftsdc010.c
--- linux-3.4.113.orig/drivers/mmc/host/ftsdc010.c 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/drivers/mmc/host/ftsdc010.c 2016-12-01 20:59:24.388614139 +0100
@@ -0,0 +1,1586 @@
+/* drivers/mmc/host/ftsdc010.c
+ * Copyright (C) 2010 Andestech
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include <linux/module.h>
+#include <linux/dma-mapping.h>
+#include <linux/clk.h>
+#include <linux/mmc/host.h>
+#include <linux/mmc/mmc.h>
+#include <linux/mmc/card.h>
+#include <linux/platform_device.h>
+#include <linux/debugfs.h>
+#include <linux/seq_file.h>
+#include <linux/irq.h>
+#include <linux/interrupt.h>
+#include <linux/delay.h>
+#include <linux/slab.h>
+
+#include <asm/io.h>
+#include <asm/spec.h>
+#include <asm/dmad.h>
+
+#include "ftsdc010.h"
+
+#define DRIVER_NAME "ftsdc010"
+
+#define REG_READ(addr) readl((host->base + addr))
+#define REG_WRITE(data, addr) writel((data), (host->base + addr))
+
+#define APB_CLK_IN (AHB_CLK_IN / 2)
+
+enum dbg_channels {
+ dbg_err = (1 << 0),
+ dbg_debug = (1 << 1),
+ dbg_info = (1 << 2),
+ dbg_irq = (1 << 3),
+ dbg_sg = (1 << 4),
+ dbg_dma = (1 << 5),
+ dbg_pio = (1 << 6),
+ dbg_fail = (1 << 7),
+ dbg_conf = (1 << 8),
+};
+
+static struct workqueue_struct *mywq;
+
+static const int dbgmap_err = dbg_fail;
+static const int dbgmap_info = dbg_info | dbg_conf;
+static const int dbgmap_debug = dbg_err | dbg_debug | dbg_info | dbg_conf;
+#if 1
+#define dbg(host, channels, args...) \
+ do { \
+ if (dbgmap_err & channels) \
+ dev_err(&host->pdev->dev, args); \
+ else if (dbgmap_info & channels) \
+ dev_info(&host->pdev->dev, args); \
+ else if (dbgmap_debug & channels) \
+ dev_dbg(&host->pdev->dev, args); \
+ } while (0)
+#endif
+#if 0
+#define dbg(host, channels, args...) \
+ do { \
+ printk(KERN_INFO "%s: ", "ftsdc");\
+ printk(args); \
+ } while(0)
+#endif
+
+static void finalize_request(struct ftsdc_host *host);
+static void ftsdc_send_request(struct mmc_host *mmc);
+
+#ifdef CONFIG_MMC_DEBUG
+
+static void dbg_dumpregs(struct ftsdc_host *host, char *prefix)
+{
+ u32 con, cmdarg, r0, r1, r2, r3, rcmd, dcon, dtimer,
+ dlen, sta, clr, imask, pcon, ccon, bwidth, scon1,
+ scon2, ssta, fea;
+
+ con = REG_READ(SDC_CMD_REG);
+ cmdarg = REG_READ(SDC_ARGU_REG);
+ r0 = REG_READ(SDC_RESPONSE0_REG);
+ r1 = REG_READ(SDC_RESPONSE1_REG);
+ r2 = REG_READ(SDC_RESPONSE2_REG);
+ r3 = REG_READ(SDC_RESPONSE3_REG);
+ rcmd = REG_READ(SDC_RSP_CMD_REG);
+ dcon = REG_READ(SDC_DATA_CTRL_REG);
+ dtimer = REG_READ(SDC_DATA_TIMER_REG);
+ dlen = REG_READ(SDC_DATA_LEN_REG);
+ sta = REG_READ(SDC_STATUS_REG);
+ clr = REG_READ(SDC_CLEAR_REG);
+ imask = REG_READ(SDC_INT_MASK_REG);
+ pcon = REG_READ(SDC_POWER_CTRL_REG);
+ ccon = REG_READ(SDC_CLOCK_CTRL_REG);
+ bwidth = REG_READ(SDC_BUS_WIDTH_REG);
+ scon1 = REG_READ(SDC_SDIO_CTRL1_REG);
+ scon2 = REG_READ(SDC_SDIO_CTRL2_REG);
+ ssta = REG_READ(SDC_SDIO_STATUS_REG);
+ fea = REG_READ(SDC_FEATURE_REG);
+
+ dbg(host, dbg_debug, "%s CON:[%08x] STA:[%08x] INT:[%08x], PWR:[%08x], CLK:[%08x]\n",
+ prefix, con, sta, imask, pcon, ccon);
+
+ dbg(host, dbg_debug, "%s DCON:[%08x] DTIME:[%08x]"
+ " DLEN:[%08x] DWIDTH:[%08x]\n",
+ prefix, dcon, dtimer, dlen, bwidth);
+
+ dbg(host, dbg_debug, "%s R0:[%08x] R1:[%08x]"
+ " R2:[%08x] R3:[%08x]\n",
+ prefix, r0, r1, r2, r3);
+
+ dbg(host, dbg_debug, "%s SCON1:[%08x] SCON2:[%08x]"
+ " SSTA:[%08x] FEA:[%08x]\n",
+ prefix, scon1, scon2, ssta, fea);
+}
+
+static void prepare_dbgmsg(struct ftsdc_host *host, struct mmc_command *cmd,
+ int stop)
+{
+ snprintf(host->dbgmsg_cmd, 300,
+ "#%u%s op:%i arg:0x%08x flags:0x08%x retries:%u",
+ host->ccnt, (stop ? " (STOP)" : ""),
+ cmd->opcode, cmd->arg, cmd->flags, cmd->retries);
+
+ if (cmd->data) {
+ snprintf(host->dbgmsg_dat, 300,
+ "#%u bsize:%u blocks:%u bytes:%u",
+ host->dcnt, cmd->data->blksz,
+ cmd->data->blocks,
+ cmd->data->blocks * cmd->data->blksz);
+ } else {
+ host->dbgmsg_dat[0] = '\0';
+ }
+}
+
+static void dbg_dumpcmd(struct ftsdc_host *host, struct mmc_command *cmd,
+ int fail)
+{
+ unsigned int dbglvl = fail ? dbg_fail : dbg_debug;
+
+ if (!cmd)
+ return;
+
+ if (cmd->error == 0) {
+ dbg(host, dbglvl, "CMD[OK] %s R0:0x%08x\n",
+ host->dbgmsg_cmd, cmd->resp[0]);
+ } else {
+ dbg(host, dbglvl, "CMD[ERR %i] %s Status:%s\n",
+ cmd->error, host->dbgmsg_cmd, host->status);
+ }
+
+ if (!cmd->data)
+ return;
+
+ if (cmd->data->error == 0) {
+ dbg(host, dbglvl, "DAT[OK] %s\n", host->dbgmsg_dat);
+ } else {
+ dbg(host, dbglvl, "DAT[ERR %i] %s DCNT:0x%08x\n",
+ cmd->data->error, host->dbgmsg_dat,
+ REG_READ(SDC_DATA_LEN_REG));
+ }
+}
+#else
+static void dbg_dumpcmd(struct ftsdc_host *host,
+ struct mmc_command *cmd, int fail) { }
+
+static void prepare_dbgmsg(struct ftsdc_host *host, struct mmc_command *cmd,
+ int stop) { }
+
+static void dbg_dumpregs(struct ftsdc_host *host, char *prefix) { }
+
+#endif /* CONFIG_MMC_DEBUG */
+
+static inline bool ftsdc_dmaexist(struct ftsdc_host *host)
+{
+ return (host->dma_req != NULL);
+}
+
+static inline u32 enable_imask(struct ftsdc_host *host, u32 imask)
+{
+ u32 newmask;
+
+#ifdef CONFIG_MMC_DEBUG
+ if (imask & SDC_STATUS_REG_SDIO_INTR) printk("\n*** E ***\n");
+#endif
+ newmask = REG_READ(SDC_INT_MASK_REG);
+ newmask |= imask;
+
+ REG_WRITE(newmask, SDC_INT_MASK_REG);
+
+ return newmask;
+}
+
+static inline u32 disable_imask(struct ftsdc_host *host, u32 imask)
+{
+ u32 newmask;
+
+#ifdef CONFIG_MMC_DEBUG
+ if (imask & SDC_STATUS_REG_SDIO_INTR) printk("\n*** D ***\n");
+#endif
+ newmask = REG_READ(SDC_INT_MASK_REG);
+ newmask &= ~imask;
+
+ REG_WRITE(newmask, SDC_INT_MASK_REG);
+
+ return newmask;
+}
+
+static inline void clear_imask(struct ftsdc_host *host)
+{
+ u32 mask = REG_READ(SDC_INT_MASK_REG);
+
+ /* preserve the SDIO IRQ mask state */
+ mask &= (SDC_INT_MASK_REG_SDIO_INTR | SDC_INT_MASK_REG_CARD_CHANGE);
+ REG_WRITE(mask, SDC_INT_MASK_REG);
+}
+
+//static void ftsdc_check_sdio_irq(struct ftsdc_host *host)
+//{
+// if (host->sdio_irqen) {
+// u32 con = REG_READ(SDC_STATUS_REG);
+// if (con & SDC_STATUS_REG_SDIO_INTR) {
+// printk(KERN_DEBUG "%s: signalling irq\n", __func__);
+// mmc_signal_sdio_irq(host->mmc);
+// }
+// }
+//}
+
+static inline void get_data_buffer(struct ftsdc_host *host)
+{
+ struct scatterlist *sg;
+
+ BUG_ON(host->buf_sgptr >= host->mrq->data->sg_len);
+
+ sg = &host->mrq->data->sg[host->buf_sgptr];
+
+ host->buf_bytes = sg->length;
+ host->buf_ptr = host->dodma ? (u32 *)sg->dma_address : sg_virt(sg);
+ host->buf_sgptr++;
+}
+
+static inline u32 cal_blksz(unsigned int blksz)
+{
+ u32 blksztwo = 0;
+
+ while (blksz >>= 1)
+ blksztwo++;
+
+ return blksztwo;
+}
+
+/**
+ * ftsdc_enable_irq - enable IRQ, after having disabled it.
+ * @host: The device state.
+ * @more: True if more IRQs are expected from transfer.
+ *
+ * Enable the main IRQ if needed after it has been disabled.
+ *
+ * The IRQ can be one of the following states:
+ * - enable after data read/write
+ * - disable when handle data read/write
+ */
+static void ftsdc_enable_irq(struct ftsdc_host *host, bool enable)
+{
+ unsigned long flags;
+ local_irq_save(flags);
+
+ host->irq_enabled = enable;
+
+ if (enable)
+ enable_irq(host->irq);
+ else
+ disable_irq(host->irq);
+
+ local_irq_restore(flags);
+}
+
+static void do_pio_read(struct ftsdc_host *host)
+{
+ u32 fifo;
+ u32 fifo_words;
+ u32 *ptr;
+ u32 status;
+ u32 retry = 0;
+
+
+ BUG_ON(host->buf_bytes != 0);
+
+ while (host->buf_sgptr < host->mrq->data->sg_len) {
+ get_data_buffer(host);
+
+ dbg(host, dbg_pio,
+ "pio_read(): new target: [%i]@[%p]\n",
+ host->buf_bytes, host->buf_ptr);
+
+ while (host->buf_bytes) {
+ status = REG_READ(SDC_STATUS_REG);
+
+ if (status & SDC_STATUS_REG_FIFO_OVERRUN) {
+ fifo = host->fifo_len > host->buf_bytes ?
+ host->buf_bytes : host->fifo_len;
+
+#if 1
+ dbg(host, dbg_pio,
+ "pio_read(): fifo:[%02i] buffer:[%03i] dcnt:[%08X]\n",
+ fifo, host->buf_bytes,
+ REG_READ(SDC_DATA_LEN_REG));
+#endif
+
+ host->buf_bytes -= fifo;
+ host->buf_count += fifo;
+
+ fifo_words = fifo >> 2;
+ ptr = host->buf_ptr;
+ while (fifo_words--)
+ *ptr++ = REG_READ(SDC_DATA_WINDOW_REG);
+
+ host->buf_ptr = ptr;
+ //ADD by river 2010.10.26 for adding some delays for SD card to put data into FIFO again
+ //mdelay(1);
+ udelay(800);
+ //End ADD by river 2010.10.26 for adding some delays for SD card to put data into FIFO again
+
+ /* sdio allow non-power-of-2 blksz */
+ if (fifo & 3) {
+ u32 n = fifo & 3;
+ u32 data = REG_READ(SDC_DATA_WINDOW_REG);
+ u8 *p = (u8 *)host->buf_ptr;
+
+ while (n--) {
+ *p++ = data;
+ data >>= 8;
+ }
+ }
+ } else {
+ udelay(1);
+ if (++retry >= SDC_PIO_RETRY) {
+ host->mrq->data->error = -EIO;
+ goto err;
+ }
+ }
+ }
+ }
+
+err:
+
+ host->buf_active = XFER_NONE;
+ host->complete_what = COMPLETION_FINALIZE;
+}
+
+static void do_pio_write(struct ftsdc_host *host)
+{
+ u32 fifo;
+ u32 *ptr;
+ u32 status;
+ u32 retry = 0;
+
+ BUG_ON(host->buf_bytes != 0);
+
+ while (host->buf_sgptr < host->mrq->data->sg_len) {
+ get_data_buffer(host);
+
+ dbg(host, dbg_pio,
+ "pio_write(): new source: [%i]@[%p]\n",
+ host->buf_bytes, host->buf_ptr);
+
+ while (host->buf_bytes) {
+ status = REG_READ(SDC_STATUS_REG);
+ if (status & SDC_STATUS_REG_FIFO_UNDERRUN) {
+ fifo = host->fifo_len > host->buf_bytes ?
+ host->buf_bytes : host->fifo_len;
+
+ dbg(host, dbg_pio,
+ "pio_write(): fifo:[%02i] buffer:[%03i] dcnt:[%08X]\n",
+ fifo, host->buf_bytes,
+ REG_READ(SDC_DATA_LEN_REG));
+
+ host->buf_bytes -= fifo;
+ host->buf_count += fifo;
+
+ fifo = (fifo + 3) >> 2;
+ ptr = host->buf_ptr;
+ while (fifo--) {
+ REG_WRITE(*ptr, SDC_DATA_WINDOW_REG);
+ ptr++;
+ }
+ host->buf_ptr = ptr;
+ } else {
+ udelay(1);
+ if (++retry >= SDC_PIO_RETRY) {
+ host->mrq->data->error = -EIO;
+ goto err;
+ }
+ }
+ }
+ }
+
+err:
+ host->buf_active = XFER_NONE;
+ host->complete_what = COMPLETION_FINALIZE;
+}
+
+static void do_dma_access(struct ftsdc_host *host)
+{
+ int res;
+ unsigned long timeout;
+ dmad_chreq *req = host->dma_req;
+ dmad_drb *drb = 0;
+
+ while (host->buf_sgptr < host->mrq->data->sg_len) {
+
+ INIT_COMPLETION(host->dma_complete);
+ get_data_buffer(host);
+
+ dbg(host, dbg_dma,
+ "dma_%s(): new target: [%i]@[%p]\n",
+ host->buf_active == XFER_READ ? "read" : "write",
+ host->buf_bytes, host->buf_ptr);
+
+ res = dmad_alloc_drb(req, &drb);
+ if (res != 0 || (drb == 0)) {
+ dbg(host, dbg_err, "%s() Failed to allocate dma request block!\n", __func__);
+ host->mrq->data->error = -ENODEV;
+ goto err;
+ }
+
+ drb->addr0 = SDC_FTSDC010_0_PA_BASE + SDC_DATA_WINDOW_REG;
+ drb->addr1 = (dma_addr_t)host->buf_ptr;
+ drb->req_cycle = dmad_bytes_to_cycles(req, host->buf_bytes);
+ drb->sync = &host->dma_complete;
+
+ timeout = SDC_TIMEOUT_BASE*((host->buf_bytes+511)>>9);
+
+ res = dmad_submit_request(req, drb, 1);
+ if (res != 0) {
+ dbg(host, dbg_err, "%s() Failed to submit dma request block!\n", __func__);
+ host->mrq->data->error = -ENODEV;
+ goto err;
+ }
+
+ dbg(host, dbg_err, "reach here!\n");
+ if (wait_for_completion_timeout(&host->dma_complete, timeout) == 0) {
+ dbg(host, dbg_err, "%s: read timeout\n", __func__);
+ host->mrq->data->error = -ETIMEDOUT;
+ goto err;
+ }
+ }
+
+ host->dma_finish = true;
+err:
+ host->buf_active = XFER_NONE;
+ host->complete_what = COMPLETION_FINALIZE;
+}
+
+static void ftsdc_work(struct work_struct *work)
+{
+ struct ftsdc_host *host =
+ container_of(work, struct ftsdc_host, work);
+
+ ftsdc_enable_irq(host, false);
+
+ if (host->dodma) {
+ do_dma_access(host);
+ } else {
+ if (host->buf_active == XFER_WRITE)
+ do_pio_write(host);
+
+ if (host->buf_active == XFER_READ)
+ do_pio_read(host);
+ }
+
+ tasklet_schedule(&host->pio_tasklet);
+ ftsdc_enable_irq(host, true);
+}
+
+
+static void pio_tasklet(unsigned long data)
+{
+ struct ftsdc_host *host = (struct ftsdc_host *) data;
+
+ if (host->complete_what == COMPLETION_XFER_PROGRESS) {
+ queue_work(mywq, (struct work_struct *)&host->work);
+ return;
+ }
+
+ if (host->complete_what == COMPLETION_FINALIZE) {
+ clear_imask(host);
+ if (host->buf_active != XFER_NONE) {
+ dbg(host, dbg_err, "unfinished %s "
+ "- buf_count:[%u] buf_bytes:[%u]\n",
+ (host->buf_active == XFER_READ) ? "read" : "write",
+ host->buf_count, host->buf_bytes);
+
+ if (host->mrq->data)
+ host->mrq->data->error = -EINVAL;
+ }
+
+ finalize_request(host);
+ }
+}
+
+
+static void finalize_request(struct ftsdc_host *host)
+{
+ struct mmc_request *mrq = host->mrq;
+ struct mmc_command *cmd;
+ u32 con;
+ int debug_as_failure = 0;
+
+ if (host->complete_what != COMPLETION_FINALIZE)
+ return;
+
+ if (!mrq)
+ return;
+
+ cmd = host->cmd_is_stop ? mrq->stop : mrq->cmd;
+
+ if (cmd->data && (cmd->error == 0) &&
+ (cmd->data->error == 0)) {
+ if (host->dodma && (!host->dma_finish)) {
+ dbg(host, dbg_dma, "DMA Missing (%d)!\n",
+ host->dma_finish);
+ return;
+ }
+ host->dodma = false;
+ }
+
+ /* Read response from controller. */
+ if (cmd->flags & MMC_RSP_136) {
+ cmd->resp[3] = REG_READ(SDC_RESPONSE0_REG);
+ cmd->resp[2] = REG_READ(SDC_RESPONSE1_REG);
+ cmd->resp[1] = REG_READ(SDC_RESPONSE2_REG);
+ cmd->resp[0] = REG_READ(SDC_RESPONSE3_REG);
+ } else if (cmd->flags & MMC_RSP_PRESENT) {
+ cmd->resp[0] = REG_READ(SDC_RESPONSE0_REG);
+ }
+
+ if (cmd->error)
+ debug_as_failure = 1;
+
+ if (cmd->data && cmd->data->error)
+ debug_as_failure = 1;
+
+ dbg_dumpcmd(host, cmd, debug_as_failure);
+
+ clear_imask(host);
+ con = REG_READ(SDC_STATUS_REG);
+ con &= ~SDC_CLEAR_REG_SDIO_INTR;
+ REG_WRITE(con, SDC_CLEAR_REG);
+
+ if (cmd->data && cmd->error)
+ cmd->data->error = cmd->error;
+
+ if (cmd->data && cmd->data->stop && (!host->cmd_is_stop)) {
+ host->cmd_is_stop = 1;
+ ftsdc_send_request(host->mmc);
+ return;
+ }
+
+ /* If we have no data transfer we are finished here */
+ if (!mrq->data)
+ goto request_done;
+
+ /* Calulate the amout of bytes transfer if there was no error */
+ if (mrq->data->error == 0) {
+ mrq->data->bytes_xfered =
+ (mrq->data->blocks * mrq->data->blksz);
+ } else {
+ mrq->data->bytes_xfered = 0;
+ }
+
+request_done:
+ host->complete_what = COMPLETION_NONE;
+ host->mrq = NULL;
+
+ host->last_opcode = mrq->cmd->opcode;
+ mmc_request_done(host->mmc, mrq);
+}
+
+static void ftsdc_send_command(struct ftsdc_host *host,
+ struct mmc_command *cmd)
+{
+ u32 ccon = 0;
+ u32 newmask = 0;
+ u32 scon;
+
+ if (cmd->data) {
+ host->complete_what = COMPLETION_XFER_PROGRESS;
+ newmask |= SDC_INT_MASK_REG_RSP_TIMEOUT;
+ } else if (cmd->flags & MMC_RSP_PRESENT) {
+ host->complete_what = COMPLETION_RSPFIN;
+ newmask |= SDC_INT_MASK_REG_RSP_TIMEOUT;
+ } else {
+ host->complete_what = COMPLETION_CMDSENT;
+ newmask |= SDC_INT_MASK_REG_CMD_SEND;
+ }
+
+ ccon |= cmd->opcode & SDC_CMD_REG_INDEX;
+ ccon |= SDC_CMD_REG_CMD_EN;
+
+ if (cmd->flags & MMC_RSP_PRESENT) {
+ ccon |= SDC_CMD_REG_NEED_RSP;
+ newmask |= SDC_INT_MASK_REG_RSP_CRC_OK |
+ SDC_INT_MASK_REG_RSP_CRC_FAIL;
+ }
+
+ if (cmd->flags & MMC_RSP_136)
+ ccon |= SDC_CMD_REG_LONG_RSP;
+
+ /* applicatiion specific cmd must follow an MMC_APP_CMD. The
+ * value will be updated in finalize_request function */
+ if (host->last_opcode == MMC_APP_CMD)
+ ccon |= SDC_CMD_REG_APP_CMD;
+
+ enable_imask(host, newmask);
+ REG_WRITE(cmd->arg, SDC_ARGU_REG);
+
+ scon = REG_READ(SDC_SDIO_CTRL1_REG);
+ if (host->mmc->card != NULL && mmc_card_sdio(host->mmc->card))
+ scon |= SDC_SDIO_CTRL1_REG_SDIO_ENABLE;
+ else
+ scon &= ~SDC_SDIO_CTRL1_REG_SDIO_ENABLE;
+ REG_WRITE(scon, SDC_SDIO_CTRL1_REG);
+
+ dbg_dumpregs(host, "");
+ dbg(host, dbg_debug, "CON[%x]\n", ccon);
+
+ REG_WRITE(ccon, SDC_CMD_REG);
+}
+
+static int ftsdc_setup_data(struct ftsdc_host *host, struct mmc_data *data)
+{
+ u32 dcon, newmask = 0;
+
+ /* configure data transfer paramter */
+
+ if (!data)
+ return 0;
+ if(host->mmc->card && host->mmc->card->type==(unsigned int)MMC_TYPE_SD){
+ if (((data->blksz - 1) & data->blksz) != 0) {
+ pr_warning("%s: can't do non-power-of 2 sized block transfers (blksz %d)\n", __func__, data->blksz);
+ return -EINVAL;
+ }
+ }
+
+ if (data->blksz <= 2) {
+ /* We cannot deal with unaligned blocks with more than
+ * one block being transfered. */
+
+ if (data->blocks > 1) {
+ pr_warning("%s: can't do non-word sized block transfers (blksz %d)\n", __func__, data->blksz);
+ return -EINVAL;
+ }
+ }
+
+ /* data length */
+ dcon = data->blksz * data->blocks;
+ REG_WRITE(dcon, SDC_DATA_LEN_REG);
+
+ /* write data control */
+ dcon = 0;
+ dcon = cal_blksz(data->blksz);
+
+ /* enable UNDERFUN will trigger interrupt immediatedly
+ * So setup it when rsp is received successfully
+ */
+ if (data->flags & MMC_DATA_WRITE) {
+ dcon |= SDC_DATA_CTRL_REG_DATA_WRITE;
+ } else {
+ dcon &= ~SDC_DATA_CTRL_REG_DATA_WRITE;
+ newmask |= SDC_INT_MASK_REG_FIFO_OVERRUN;
+ }
+
+ /* always reset fifo since last transfer may fail */
+ dcon |= SDC_DATA_CTRL_REG_FIFO_RST;
+
+ /* enable data transfer which will be pended until cmd is send */
+ dcon |= SDC_DATA_CTRL_REG_DATA_EN;
+
+ if (ftsdc_dmaexist(host) &&
+ ((data->blksz * data->blocks) & 0xf) == 0) {
+ newmask &= ~SDC_INT_MASK_REG_FIFO_OVERRUN;
+ dcon |= SDC_DATA_CTRL_REG_DMA_EN;
+ dcon |= SDC_DMA_TYPE_4;
+ host->dodma = true;
+
+ }
+
+ REG_WRITE(dcon, SDC_DATA_CTRL_REG);
+
+ /* add to IMASK register */
+ newmask |= SDC_INT_MASK_REG_DATA_CRC_FAIL |
+ SDC_INT_MASK_REG_DATA_TIMEOUT;
+
+ enable_imask(host, newmask);
+
+ /* handle sdio */
+ dcon = SDC_SDIO_CTRL1_REG_READ_WAIT_ENABLE & REG_READ(SDC_SDIO_CTRL1_REG);
+ dcon |= data->blksz | data->blocks << 15;
+ if (1 < data->blocks)
+ dcon |= SDC_SDIO_CTRL1_REG_SDIO_BLK_MODE;
+ REG_WRITE(dcon, SDC_SDIO_CTRL1_REG);
+
+ return 0;
+}
+
+#define BOTH_DIR (MMC_DATA_WRITE | MMC_DATA_READ)
+
+static int ftsdc_prepare_buffer(struct ftsdc_host *host, struct mmc_data *data)
+{
+ int rw = (data->flags & MMC_DATA_WRITE) ? 1 : 0;
+
+ if ((!host->mrq) || (!host->mrq->data))
+ return -EINVAL;
+
+ BUG_ON((data->flags & BOTH_DIR) == BOTH_DIR);
+
+ host->buf_sgptr = 0;
+ host->buf_bytes = 0;
+ host->buf_count = 0;
+ host->buf_active = rw ? XFER_WRITE : XFER_READ;
+
+ if (host->dodma) {
+ u32 dma_len;
+ u32 drb_size;
+ dma_len = dma_map_sg(mmc_dev(host->mmc), data->sg, data->sg_len,
+ rw ? DMA_TO_DEVICE : DMA_FROM_DEVICE);
+ if (dma_len == 0)
+ return -ENOMEM;
+
+
+ dmad_config_channel_dir(host->dma_req,
+ rw ? DMAD_DIR_A1_TO_A0 : DMAD_DIR_A0_TO_A1);
+
+ drb_size = dmad_max_size_per_drb(host->dma_req);
+ if (drb_size < (data->blksz & data->blocks))
+ return -ENODEV;
+
+ host->dma_finish = false;
+ }
+
+ return 0;
+}
+
+static irqreturn_t ftsdc_irq(int irq, void *dev_id)
+{
+ struct ftsdc_host *host = dev_id;
+ struct mmc_command *cmd;
+ u32 mci_status;
+ u32 mci_clear;
+ u32 mci_imsk;
+ unsigned long iflags;
+
+ mci_status = REG_READ(SDC_STATUS_REG);
+ mci_imsk = REG_READ(SDC_INT_MASK_REG);
+
+ dbg(host, dbg_debug, "irq: status:0x%08x, mask : %08x\n", mci_status, mci_imsk);
+
+ if (mci_status & SDC_STATUS_REG_SDIO_INTR) {
+ if (mci_imsk & SDC_INT_MASK_REG_SDIO_INTR) {
+ mci_clear = SDC_CLEAR_REG_SDIO_INTR;
+ REG_WRITE(mci_clear, SDC_CLEAR_REG);
+
+ mmc_signal_sdio_irq(host->mmc);
+ return IRQ_HANDLED;
+ }
+ }
+
+ spin_lock_irqsave(&host->complete_lock, iflags);
+
+ mci_status = REG_READ(SDC_STATUS_REG);
+ mci_clear = 0;
+
+ if (mci_status & SDC_STATUS_REG_CARD_CHANGE) {
+ if ((mci_status & SDC_STATUS_REG_CARD_DETECT)
+ == SDC_CARD_INSERT) {
+ host->status = "card insert";
+ mmc_detect_change(host->mmc, msecs_to_jiffies(500));
+ } else {
+ host->status = "card remove";
+ }
+
+ mci_clear |= SDC_CLEAR_REG_CARD_CHANGE;
+ dbg(host, dbg_irq, "%s\n", host->status);
+
+ if (host->complete_what != COMPLETION_NONE) {
+ host->mrq->cmd->error = -EIO;
+ goto close_transfer;
+ }
+
+ goto irq_out;
+ }
+
+ if ((host->complete_what == COMPLETION_NONE) ||
+ (host->complete_what == COMPLETION_FINALIZE)) {
+ host->status = "nothing to complete";
+ mci_clear = -1u;
+ goto irq_out;
+ }
+
+ if (!host->mrq) {
+ host->status = "no active mrq";
+ clear_imask(host);
+ goto irq_out;
+ }
+
+ cmd = host->cmd_is_stop ? host->mrq->stop : host->mrq->cmd;
+
+ if (!cmd) {
+ host->status = "no active cmd";
+ clear_imask(host);
+ goto irq_out;
+ }
+
+ if (mci_status & SDC_STATUS_REG_CMD_SEND) {
+ mci_clear |= SDC_CLEAR_REG_CMD_SEND;
+
+ if (host->complete_what == COMPLETION_CMDSENT) {
+ host->status = "ok: command sent";
+ goto close_transfer;
+ } else {
+ host->status = "error: command sent(status not match)";
+ cmd->error = -EINVAL;
+ goto fail_transfer;
+ }
+ }
+
+ /* handle error status */
+ if (mci_status & SDC_STATUS_REG_RSP_TIMEOUT) {
+ dbg(host, dbg_err, "CMDSTAT: error RSP TIMEOUT\n");
+ mci_clear |= SDC_CLEAR_REG_RSP_TIMEOUT;
+ cmd->error = -ETIMEDOUT;
+ host->status = "error: response timeout";
+ goto fail_transfer;
+ }
+
+ if (mci_status & SDC_STATUS_REG_RSP_CRC_FAIL) {
+ mci_clear |= SDC_CLEAR_REG_RSP_CRC_FAIL;
+ /* This is wierd hack */
+ if (cmd->flags & MMC_RSP_CRC) {
+ dbg(host, dbg_err, "CMDSTAT: error RSP CRC\n");
+ cmd->error = -EILSEQ;
+ host->status = "error: RSP CRC failed";
+ goto fail_transfer;
+ } else {
+ host->status = "R3 or R4 type command";
+ goto close_transfer;
+ }
+ }
+
+ if (mci_status & SDC_STATUS_REG_RSP_CRC_OK) {
+ mci_clear |= SDC_CLEAR_REG_RSP_CRC_OK;
+
+ if (host->complete_what == COMPLETION_XFER_PROGRESS) {
+ REG_WRITE(mci_clear, SDC_CLEAR_REG);
+
+ host->status = "RSP recv OK";
+ if (!cmd->data)
+ goto close_transfer;
+
+ if (host->dodma) {
+ tasklet_schedule(&host->pio_tasklet);
+ host->status = "dma access";
+ goto irq_out;
+ }
+
+ if (host->buf_active == XFER_WRITE)
+ enable_imask(host, SDC_INT_MASK_REG_FIFO_UNDERRUN);
+ } else if (host->complete_what == COMPLETION_RSPFIN) {
+ goto close_transfer;
+ }
+ }
+
+ /* handler data transfer */
+ if (mci_status & SDC_STATUS_REG_DATA_TIMEOUT) {
+ dbg(host, dbg_err, "CMDSTAT: error DATA TIMEOUT\n");
+ mci_clear |= SDC_CLEAR_REG_DATA_TIMEOUT;
+ cmd->error = -ETIMEDOUT;
+ host->status = "error: data timeout";
+ goto fail_transfer;
+ }
+
+ if (mci_status & SDC_STATUS_REG_DATA_CRC_FAIL) {
+ dbg(host, dbg_err, "CMDSTAT: error DATA CRC\n");
+ mci_clear |= SDC_CLEAR_REG_DATA_CRC_FAIL;
+ cmd->error = -EILSEQ;
+ host->status = "error: data CRC fail";
+ goto fail_transfer;
+ }
+
+ if ((mci_status & SDC_STATUS_REG_FIFO_UNDERRUN) ||
+ mci_status & SDC_STATUS_REG_FIFO_OVERRUN) {
+
+ disable_imask(host, SDC_INT_MASK_REG_FIFO_OVERRUN |
+ SDC_INT_MASK_REG_FIFO_UNDERRUN);
+
+ if (!host->dodma) {
+ if (host->buf_active == XFER_WRITE) {
+ tasklet_schedule(&host->pio_tasklet);
+ host->status = "pio tx";
+ } else if (host->buf_active == XFER_READ) {
+
+ tasklet_schedule(&host->pio_tasklet);
+ host->status = "pio rx";
+ }
+ }
+ }
+
+ goto irq_out;
+
+fail_transfer:
+ host->buf_active = XFER_NONE;
+
+close_transfer:
+ host->complete_what = COMPLETION_FINALIZE;
+
+ clear_imask(host);
+ tasklet_schedule(&host->pio_tasklet);
+
+irq_out:
+ REG_WRITE(mci_clear, SDC_CLEAR_REG);
+
+ dbg(host, dbg_debug, "irq: %s\n", host->status);
+ spin_unlock_irqrestore(&host->complete_lock, iflags);
+ return IRQ_HANDLED;
+}
+
+static void ftsdc_send_request(struct mmc_host *mmc)
+{
+ struct ftsdc_host *host = mmc_priv(mmc);
+ struct mmc_request *mrq = host->mrq;
+ struct mmc_command *cmd = host->cmd_is_stop ? mrq->stop : mrq->cmd;
+
+ host->ccnt++;
+ prepare_dbgmsg(host, cmd, host->cmd_is_stop);
+ dbg(host, dbg_debug, "%s\n", host->dbgmsg_cmd);
+
+ if (cmd->data) {
+ int res = ftsdc_setup_data(host, cmd->data);
+
+ host->dcnt++;
+
+ if (res) {
+ dbg(host, dbg_err, "setup data error %d\n", res);
+ cmd->error = res;
+ cmd->data->error = res;
+
+ mmc_request_done(mmc, mrq);
+ return;
+ }
+
+ res = ftsdc_prepare_buffer(host, cmd->data);
+
+ if (res) {
+ dbg(host, dbg_err, "data prepare error %d\n", res);
+ cmd->error = res;
+ cmd->data->error = res;
+
+ mmc_request_done(mmc, mrq);
+ return;
+ }
+ }
+
+ /* Send command */
+ ftsdc_send_command(host, cmd);
+}
+
+static int ftsdc_get_cd(struct mmc_host *mmc)
+{
+ struct ftsdc_host *host = mmc_priv(mmc);
+
+ u32 con = REG_READ(SDC_STATUS_REG);
+ dbg(host, dbg_debug, "get_cd status:%.8x\n\n", con);
+
+ return (con & SDC_STATUS_REG_CARD_DETECT) ? 0 : 1;
+}
+
+static void ftsdc_request(struct mmc_host *mmc, struct mmc_request *mrq)
+{
+ struct ftsdc_host *host = mmc_priv(mmc);
+
+/* work_around_for_amerald(mrq);*/
+ host->status = "mmc request";
+ host->cmd_is_stop = 0;
+ host->mrq = mrq;
+ if (ftsdc_get_cd(mmc) == 0) {
+ dbg(host, dbg_err, "%s: no medium present\n", __func__);
+ host->mrq->cmd->error = -ENOMEDIUM;
+ mmc_request_done(mmc, mrq);
+ } else {
+ ftsdc_send_request(mmc);
+ }
+
+ dbg(host, dbg_debug, "send request \n");
+}
+
+static void ftsdc_set_clk(struct ftsdc_host *host, struct mmc_ios *ios)
+{
+ u32 clk_div = 0;
+ u32 con;
+
+ dbg(host, dbg_debug, "request clk : %u \n", ios->clock);
+ con = REG_READ(SDC_CLOCK_CTRL_REG);
+ if (ios->clock == 0) {
+ host->real_rate = 0;
+ con |= SDC_CLOCK_CTRL_REG_CLK_DIS;
+ } else {
+ clk_div = (APB_CLK_IN / (ios->clock << 1)) - 1;
+ host->real_rate = APB_CLK_IN / ((clk_div+1)<<1);
+ if (host->real_rate > ios->clock) {
+ ++clk_div;
+ host->real_rate = APB_CLK_IN / ((clk_div+1)<<1);
+ }
+ if (clk_div > 127)
+ dbg(host, dbg_err, "%s: no match clock rate, %u\n", __func__, ios->clock);
+
+ con = (con & ~SDC_CLOCK_CTRL_REG_CLK_DIV) | (clk_div & SDC_CLOCK_CTRL_REG_CLK_DIV);
+ con &= ~SDC_CLOCK_CTRL_REG_CLK_DIS;
+ }
+
+ REG_WRITE(con, SDC_CLOCK_CTRL_REG);
+}
+
+static void ftsdc_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
+{
+ struct ftsdc_host *host = mmc_priv(mmc);
+ u32 con;
+
+ con = REG_READ(SDC_POWER_CTRL_REG);
+ switch (ios->power_mode) {
+ case MMC_POWER_ON:
+ case MMC_POWER_UP:
+ con |= SDC_POWER_CTRL_REG_POWER_ON;
+ break;
+ case MMC_POWER_OFF:
+ default:
+ con &= ~SDC_POWER_CTRL_REG_POWER_ON;
+ break;
+ }
+
+ REG_WRITE(con, SDC_POWER_CTRL_REG);
+
+ ftsdc_set_clk(host, ios);
+
+ if ((ios->power_mode == MMC_POWER_ON) ||
+ (ios->power_mode == MMC_POWER_UP)) {
+ dbg(host, dbg_debug, "running at %ukHz (requested: %ukHz).\n",
+ host->real_rate/1000, ios->clock/1000);
+ } else {
+ dbg(host, dbg_debug, "powered down.\n");
+ }
+
+ host->bus_width = ios->bus_width;
+ /* write bus configure */
+ con = REG_READ(SDC_BUS_WIDTH_REG);
+
+ con &= ~(SDC_BUS_WIDTH_REG_SINGLE_BUS |
+ SDC_BUS_WIDTH_REG_WIDE_4_BUS |
+ SDC_BUS_WIDTH_REG_WIDE_8_BUS);
+ if (host->bus_width == MMC_BUS_WIDTH_1)
+ con |= SDC_BUS_WIDTH_REG_SINGLE_BUS;
+ else if (host->bus_width == MMC_BUS_WIDTH_4)
+ con |= SDC_BUS_WIDTH_REG_WIDE_4_BUS;
+ else if (host->bus_width == MMC_BUS_WIDTH_8)
+ con |= SDC_BUS_WIDTH_REG_WIDE_8_BUS;
+ else {
+ dbg(host, dbg_err, "set_ios: can't support bus mode");
+ }
+ REG_WRITE(con, SDC_BUS_WIDTH_REG);
+
+ /*set rsp and data timeout */
+ con = -1;
+ REG_WRITE(con, SDC_DATA_TIMER_REG);
+}
+
+static int ftsdc_get_ro(struct mmc_host *mmc)
+{
+ struct ftsdc_host *host = mmc_priv(mmc);
+ u32 con = REG_READ(SDC_STATUS_REG);
+ dbg(host, dbg_debug, "get_ro status:%.8x\n", con);
+
+ return (con & SDC_STATUS_REG_CARD_LOCK) ? 1 : 0;
+}
+
+
+static void ftsdc_enable_sdio_irq(struct mmc_host *mmc, int enable)
+{
+ struct ftsdc_host *host = mmc_priv(mmc);
+ unsigned long flags;
+ u32 con;
+#ifdef CONFIG_MMC_DEBUG
+ u32 ena;
+#endif
+
+ local_irq_save(flags);
+
+ con = REG_READ(SDC_INT_MASK_REG);
+#ifdef CONFIG_MMC_DEBUG
+ ena = (con & SDC_STATUS_REG_SDIO_INTR) ? 1:0;
+ if (ena == enable)
+ printk("\n*** XXX ***\n");
+#endif
+
+ con = enable ? (con | SDC_STATUS_REG_SDIO_INTR) : (con & ~SDC_STATUS_REG_SDIO_INTR);
+ REG_WRITE(con, SDC_INT_MASK_REG);
+
+#ifdef CONFIG_MMC_DEBUG
+ //check and ensure data out to SD host controller
+ ena = (REG_READ(SDC_INT_MASK_REG) & SDC_STATUS_REG_SDIO_INTR) ? 1:0;
+ if (ena != enable) {
+ printk("\n*** YYY ***\n");
+ }
+#endif
+
+ local_irq_restore(flags);
+}
+
+static struct mmc_host_ops ftsdc_ops = {
+ .request = ftsdc_request,
+ .set_ios = ftsdc_set_ios,
+ .get_ro = ftsdc_get_ro,
+ .get_cd = ftsdc_get_cd,
+ .enable_sdio_irq = ftsdc_enable_sdio_irq,
+};
+
+#ifdef CONFIG_DEBUG_FS
+
+static int ftsdc_state_show(struct seq_file *seq, void *v)
+{
+ struct ftsdc_host *host = seq->private;
+
+ seq_printf(seq, "Register base = 0x%08x\n", (u32)host->base);
+ seq_printf(seq, "Clock rate = %u\n", host->real_rate);
+ seq_printf(seq, "host status = %s\n", host->status);
+ seq_printf(seq, "IRQ = %d\n", host->irq);
+ seq_printf(seq, "IRQ enabled = %d\n", host->irq_enabled);
+ seq_printf(seq, "complete what = %d\n", host->complete_what);
+ seq_printf(seq, "dma support = %d\n", ftsdc_dmaexist(host));
+ seq_printf(seq, "use dma = %d\n", host->dodma);
+
+ return 0;
+}
+
+static int ftsdc_state_open(struct inode *inode, struct file *file)
+{
+ return single_open(file, ftsdc_state_show, inode->i_private);
+}
+
+static const struct file_operations ftsdc_fops_state = {
+ .owner = THIS_MODULE,
+ .open = ftsdc_state_open,
+ .read = seq_read,
+ .llseek = seq_lseek,
+ .release = single_release,
+};
+
+#define DBG_REG(_r) { .addr = SDC_## _r ## _REG, .name = #_r }
+
+struct ftsdc_reg {
+ unsigned short addr;
+ unsigned char *name;
+} debug_regs[] = {
+ DBG_REG(CMD),
+ DBG_REG(ARGU),
+ DBG_REG(RESPONSE0),
+ DBG_REG(RESPONSE1),
+ DBG_REG(RESPONSE2),
+ DBG_REG(RESPONSE3),
+ DBG_REG(RSP_CMD),
+ DBG_REG(DATA_CTRL),
+ DBG_REG(DATA_TIMER),
+ DBG_REG(DATA_LEN),
+ DBG_REG(STATUS),
+ DBG_REG(CLEAR),
+ DBG_REG(INT_MASK),
+ DBG_REG(POWER_CTRL),
+ DBG_REG(CLOCK_CTRL),
+ DBG_REG(BUS_WIDTH),
+ DBG_REG(SDIO_CTRL1),
+ DBG_REG(SDIO_CTRL2),
+ DBG_REG(SDIO_STATUS),
+ DBG_REG(FEATURE),
+ DBG_REG(REVISION),
+ {}
+};
+
+static int ftsdc_regs_show(struct seq_file *seq, void *v)
+{
+ struct ftsdc_host *host = seq->private;
+ struct ftsdc_reg *rptr = debug_regs;
+
+ for (; rptr->name; rptr++)
+ seq_printf(seq, "SDI%s\t=0x%08x\n", rptr->name,
+ REG_READ(rptr->addr));
+
+ return 0;
+}
+
+static int ftsdc_regs_open(struct inode *inode, struct file *file)
+{
+ return single_open(file, ftsdc_regs_show, inode->i_private);
+}
+
+static const struct file_operations ftsdc_fops_regs = {
+ .owner = THIS_MODULE,
+ .open = ftsdc_regs_open,
+ .read = seq_read,
+ .llseek = seq_lseek,
+ .release = single_release,
+};
+
+static void ftsdc_debugfs_attach(struct ftsdc_host *host)
+{
+ struct device *dev = &host->pdev->dev;
+
+ host->debug_root = debugfs_create_dir(dev_name(dev), NULL);
+ if (IS_ERR(host->debug_root)) {
+ dev_err(dev, "failed to create debugfs root\n");
+ return;
+ }
+
+ host->debug_state = debugfs_create_file("state", 0444,
+ host->debug_root, host,
+ &ftsdc_fops_state);
+
+ if (IS_ERR(host->debug_state))
+ dev_err(dev, "failed to create debug state file\n");
+
+ host->debug_regs = debugfs_create_file("regs", 0444,
+ host->debug_root, host,
+ &ftsdc_fops_regs);
+
+ if (IS_ERR(host->debug_regs))
+ dev_err(dev, "failed to create debug regs file\n");
+}
+
+static void ftsdc_debugfs_remove(struct ftsdc_host *host)
+{
+ debugfs_remove(host->debug_regs);
+ debugfs_remove(host->debug_state);
+ debugfs_remove(host->debug_root);
+}
+
+#else
+static inline void ftsdc_debugfs_attach(struct ftsdc_host *host) { }
+static inline void ftsdc_debugfs_remove(struct ftsdc_host *host) { }
+
+#endif /* CONFIG_DEBUG_FS */
+
+#if (defined(CONFIG_PLATFORM_AHBDMA) || defined(CONFIG_PLATFORM_APBDMA))
+static int ftsdc_alloc_dma(struct ftsdc_host *host)
+{
+ dmad_chreq *req = host->dma_req;
+
+ req = kzalloc(sizeof(dmad_chreq), GFP_KERNEL);
+#ifdef CONFIG_PLATFORM_APBDMA
+#ifdef CONFIG_PLAT_AG102
+ //ADD by river 2010.10.20
+ outl(inl(PCU_VA_BASE + 0x38) | 0x00000300, PCU_VA_BASE + 0x38);
+ //End ADD by river 2010.10.20
+#endif
+ req->apb_req.addr0_ctrl = APBBR_ADDRINC_FIXED; /* (in) APBBR_ADDRINC_xxx */
+/* for amerald */
+ if((inl(PMU_BASE) & AMERALD_MASK) == AMERALD_PRODUCT_ID){
+ req->apb_req.addr0_reqn = APBBR_REQN_SDC_AMERALD;
+ }else
+ {
+ req->apb_req.addr0_reqn = APBBR_REQN_SDC; /* (in) APBBR_REQN_xxx (also used to help determine bus selection) */
+ }
+ req->apb_req.addr1_ctrl = APBBR_ADDRINC_I4X; /* (in) APBBR_ADDRINC_xxx */
+ req->apb_req.addr1_reqn = APBBR_REQN_NONE; /* (in) APBBR_REQN_xxx (also used to help determine bus selection) */
+ req->apb_req.burst_mode = 1; /* (in) Burst mode (0: no burst 1-, 1: burst 4- data cycles per dma cycle) */
+ req->apb_req.data_width = APBBR_DATAWIDTH_4; /* (in) APBBR_DATAWIDTH_4(word), APBBR_DATAWIDTH_2(half-word), APBBR_DATAWIDTH_1(byte) */
+ req->apb_req.tx_dir = DMAD_DIR_A0_TO_A1; /* (in) DMAD_DIR_A0_TO_A1, DMAD_DIR_A1_TO_A0 */
+ req->controller = DMAD_DMAC_APB_CORE; /* (in) DMAD_DMAC_AHB_CORE, DMAD_DMAC_APB_CORE */
+ req->flags = DMAD_FLAGS_SLEEP_BLOCK | DMAD_FLAGS_BIDIRECTION;
+
+ if (dmad_channel_alloc(req) == 0) {
+ dbg(host, dbg_debug, "%s: APB dma channel allocated (ch: %d)\n", __func__, req->channel);
+ host->dma_req = req;
+ return 0;
+ }
+
+ memset(req, 0, sizeof(dmad_chreq));
+ dbg(host, dbg_info, "%s: APB dma channel allocation failed\n", __func__);
+#endif /* CONFIG_PLATFORM_APBDMA */
+
+#ifdef CONFIG_PLATFORM_AHBDMA
+ req->ahb_req.sync = 1; /* (in) non-zero if src and dst have different clock domain */
+ req->ahb_req.priority = DMAC_CSR_CHPRI_1; /* (in) DMAC_CSR_CHPRI_0 (lowest) ~ DMAC_CSR_CHPRI_3 (highest) */
+ req->ahb_req.hw_handshake = 1; /* (in) non-zero to enable hardware handshake mode */
+ req->ahb_req.burst_size = DMAC_CSR_SIZE_4; /* (in) DMAC_CSR_SIZE_1 ~ DMAC_CSR_SIZE_256 */
+ req->ahb_req.addr0_width = DMAC_CSR_WIDTH_32; /* (in) DMAC_CSR_WIDTH_8, DMAC_CSR_WIDTH_16, or DMAC_CSR_WIDTH_32 */
+ req->ahb_req.addr0_ctrl = DMAC_CSR_AD_FIX; /* (in) DMAC_CSR_AD_INC, DMAC_CSR_AD_DEC, or DMAC_CSR_AD_FIX */
+ req->ahb_req.addr0_reqn = DMAC_REQN_SDC; /* (in) DMAC_REQN_xxx (also used to help determine channel number) */
+ req->ahb_req.addr1_width = DMAC_CSR_WIDTH_32; /* (in) DMAC_CSR_WIDTH_8, DMAC_CSR_WIDTH_16, or DMAC_CSR_WIDTH_32 */
+ req->ahb_req.addr1_ctrl = DMAC_CSR_AD_INC; /* (in) DMAC_CSR_AD_INC, DMAC_CSR_AD_DEC, or DMAC_CSR_AD_FIX */
+ req->ahb_req.addr1_reqn = DMAC_REQN_NONE; /* (in) DMAC_REQN_xxx (also used to help determine channel number) */
+ req->ahb_req.tx_dir = DMAD_DIR_A0_TO_A1; /* (in) DMAD_DIR_A0_TO_A1, DMAD_DIR_A1_TO_A0 */
+
+ req->controller = DMAD_DMAC_AHB_CORE; /* (in) DMAD_DMAC_AHB_CORE, DMAD_DMAC_APB_CORE */
+ req->flags = DMAD_FLAGS_SLEEP_BLOCK | DMAD_FLAGS_BIDIRECTION;
+
+ if (dmad_channel_alloc(req) == 0) {
+ dbg(host, dbg_debug, "%s: AHB dma channel allocated (ch: %d)\n", __func__, req->channel);
+ host->dma_req = req;
+ return 0;
+ }
+
+ dbg(host, dbg_info, "%s: AHB dma channel allocation failed\n", __func__);
+#endif
+
+ kfree(req);
+ return -ENODEV;
+
+}
+#endif
+
+static int __devinit ftsdc_probe(struct platform_device *pdev)
+{
+ struct ftsdc_host *host;
+ struct mmc_host *mmc;
+ int ret = -ENOMEM;
+ u32 con;
+
+ mmc = mmc_alloc_host(sizeof(struct ftsdc_host), &pdev->dev);
+ if (!mmc) {
+// ret = -ENOMEM;
+ goto probe_out;
+ }
+
+ host = mmc_priv(mmc);
+ host->mmc = mmc;
+ host->pdev = pdev;
+
+ mywq = create_workqueue("atcsdc_queue");
+ if (NULL == mywq)
+ goto probe_free_host;
+
+ spin_lock_init(&host->complete_lock);
+ tasklet_init(&host->pio_tasklet, pio_tasklet, (unsigned long) host);
+ init_completion(&host->dma_complete);
+ INIT_WORK(&host->work, ftsdc_work);
+
+ host->complete_what = COMPLETION_NONE;
+ host->buf_active = XFER_NONE;
+
+#if (defined(CONFIG_PLATFORM_AHBDMA) || defined(CONFIG_PLATFORM_APBDMA))
+ ftsdc_alloc_dma(host);
+#endif
+
+ host->mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+ if (!host->mem) {
+ dev_err(&pdev->dev,
+ "failed to get io memory region resouce.\n");
+
+ ret = -ENOENT;
+ goto probe_free_host;
+ }
+
+ host->mem = request_mem_region(host->mem->start,
+ resource_size(host->mem), pdev->name);
+
+ if (!host->mem) {
+ dev_err(&pdev->dev, "failed to request io memory region.\n");
+ ret = -ENOENT;
+ goto probe_free_wq;
+ }
+
+ host->base = (void __iomem *) SDC_FTSDC010_0_VA_BASE;
+ host->irq = SDC_FTSDC010_IRQ;
+ if (request_irq(host->irq, ftsdc_irq, IRQF_DISABLED, DRIVER_NAME, host)) {
+ dev_err(&pdev->dev, "failed to request mci interrupt.\n");
+ ret = -ENOENT;
+ goto probe_free_mem_region;
+ }
+ host->irq_enabled = true;
+
+ /* enable card change interruption */
+ con = REG_READ(SDC_INT_MASK_REG);
+ con |= SDC_INT_MASK_REG_CARD_CHANGE;
+ REG_WRITE(con, SDC_INT_MASK_REG);
+
+ con = REG_READ(SDC_BUS_WIDTH_REG);
+
+ mmc->ops = &ftsdc_ops;
+ mmc->ocr_avail = MMC_VDD_32_33 | MMC_VDD_33_34;
+
+ if (con & SDC_WIDE_4_BUS_SUPPORT)
+ mmc->caps |= MMC_CAP_4_BIT_DATA;
+ else if (con & SDC_WIDE_8_BUS_SUPPORT)
+ mmc->caps |= MMC_CAP_8_BIT_DATA;
+
+#ifndef A320D_BUILDIN_SDC
+ mmc->caps |= MMC_CAP_SDIO_IRQ;
+#endif
+
+ mmc->f_min = APB_CLK_IN / (2 * 128);
+ mmc->f_max = APB_CLK_IN / 2;
+
+ /* limit SDIO mode max size */
+ mmc->max_req_size = 128 * 1024 * 1024 - 1;
+ mmc->max_blk_size = 2047;
+ mmc->max_req_size = (mmc->max_req_size + 1) / (mmc->max_blk_size + 1);
+ mmc->max_seg_size = mmc->max_req_size;
+ mmc->max_blk_count = (1<<17)-1;
+
+ /* kernel default value. see Doc/block/biodocs.txt */
+ /*
+ 'struct mmc_host' has no member named 'max_phys_segs'
+ 'struct mmc_host' has no member named 'max_hw_segs'
+ */
+// mmc->max_phys_segs = 128;
+// mmc->max_hw_segs = 128;
+
+ /* set fifo lenght and default threshold half */
+ con = REG_READ(SDC_FEATURE_REG);
+ host->fifo_len = (con & SDC_FEATURE_REG_FIFO_DEPTH) * sizeof(u32);
+
+ dbg(host, dbg_debug,
+ "probe: mapped mci_base:%p irq:%u.\n",
+ host->base, host->irq);
+
+ dbg_dumpregs(host, "");
+
+ ret = mmc_add_host(mmc);
+ if (ret) {
+ dev_err(&pdev->dev, "failed to add mmc host.\n");
+ goto probe_free_irq;
+ }
+
+ ftsdc_debugfs_attach(host);
+
+ platform_set_drvdata(pdev, mmc);
+ dev_info(&pdev->dev, "%s - using %s SDIO IRQ\n", mmc_hostname(mmc),
+ mmc->caps & MMC_CAP_SDIO_IRQ ? "hw" : "sw");
+
+ return 0;
+
+ probe_free_irq:
+ free_irq(host->irq, host);
+
+ probe_free_mem_region:
+ release_mem_region(host->mem->start, resource_size(host->mem));
+
+probe_free_wq:
+ destroy_workqueue(mywq);
+
+ probe_free_host:
+ mmc_free_host(mmc);
+
+ probe_out:
+ return ret;
+}
+
+static void ftsdc_shutdown(struct platform_device *pdev)
+{
+ struct mmc_host *mmc = platform_get_drvdata(pdev);
+ struct ftsdc_host *host = mmc_priv(mmc);
+
+ flush_workqueue(mywq);
+ destroy_workqueue(mywq);
+
+ ftsdc_debugfs_remove(host);
+ mmc_remove_host(mmc);
+}
+
+static int __devexit ftsdc_remove(struct platform_device *pdev)
+{
+ struct mmc_host *mmc = platform_get_drvdata(pdev);
+ struct ftsdc_host *host = mmc_priv(mmc);
+
+ ftsdc_shutdown(pdev);
+
+ tasklet_disable(&host->pio_tasklet);
+
+ if (ftsdc_dmaexist(host))
+ kfree(host->dma_req);
+
+ free_irq(host->irq, host);
+
+ release_mem_region(host->mem->start, resource_size(host->mem));
+
+ mmc_free_host(mmc);
+ return 0;
+}
+
+
+#ifdef CONFIG_PM
+static int ftsdc_free_dma(struct ftsdc_host *host)
+{
+ dmad_channel_free(host->dma_req);
+ return 0;
+}
+
+static int ftsdc_suspend(struct platform_device *pdev, pm_message_t state)
+{
+ struct mmc_host *mmc = platform_get_drvdata(pdev);
+ struct ftsdc_host *host = mmc_priv(mmc);
+ int ret = 0;
+ if (mmc) {
+ ftsdc_free_dma(host);
+ ret = mmc_suspend_host(mmc);
+ }
+ return ret;
+
+}
+
+static int ftsdc_resume(struct platform_device *pdev)
+{
+ struct mmc_host *mmc = platform_get_drvdata(pdev);
+ int ret = 0;
+ struct ftsdc_host *host = mmc_priv(mmc);
+ if (mmc) {
+#if (defined(CONFIG_PLATFORM_AHBDMA) || defined(CONFIG_PLATFORM_APBDMA))
+ ftsdc_alloc_dma(host);
+#endif
+ ret = mmc_resume_host(mmc);
+ }
+ return ret;
+}
+
+static void platform_device_release(struct device *dev){
+}
+
+
+#else
+#define ftsdc_suspend NULL
+#define ftsdc_resume NULL
+#endif
+
+
+static struct platform_driver ftsdc_driver = {
+ .driver = {
+ .name = "ftsdc010",
+ .owner = THIS_MODULE,
+ },
+ .probe = ftsdc_probe,
+ .remove = __devexit_p(ftsdc_remove),
+ .shutdown = ftsdc_shutdown,
+ .suspend = ftsdc_suspend,
+ .resume = ftsdc_resume,
+};
+
+static struct resource sdc_resource[] = {
+ [0] = {
+ .start = SDC_FTSDC010_0_VA_BASE,
+ .end = SDC_FTSDC010_0_VA_BASE + 0x1000 - 1,
+ .flags = IORESOURCE_MEM,
+ },
+ [1] = {
+ .start = SDC_FTSDC010_0_IRQ,
+ .flags = IORESOURCE_IRQ,
+ }
+
+};
+
+struct platform_device sdc_device = {
+ .name = "ftsdc010",
+ .id = 0,
+ .num_resources = ARRAY_SIZE(sdc_resource),
+ .resource = sdc_resource,
+ .dev = {
+ .release = platform_device_release,
+ },
+};
+
+static int __init ftsdc_init(void)
+{
+ platform_device_register(&sdc_device);
+ return platform_driver_register(&ftsdc_driver);
+}
+
+static void __exit ftsdc_exit(void)
+{
+ platform_driver_unregister(&ftsdc_driver);
+ platform_device_unregister(&sdc_device);
+}
+module_init(ftsdc_init);
+module_exit(ftsdc_exit);
+
+MODULE_DESCRIPTION("Andestech Leopard MMC/SD Card Interface driver");
+MODULE_LICENSE("GPL v2");
diff -Nur linux-3.4.113.orig/drivers/mmc/host/ftsdc010.h linux-3.4.113/drivers/mmc/host/ftsdc010.h
--- linux-3.4.113.orig/drivers/mmc/host/ftsdc010.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/drivers/mmc/host/ftsdc010.h 2016-12-01 20:59:24.388614139 +0100
@@ -0,0 +1,240 @@
+/*
+ * linux/driver/mmc/ftsdc010.h - Andestech MMC/SD driver
+ * Andestech FTSDC010 Device Driver
+ *
+ * Andestech (C) 2005 Faraday Corp. (http://www.Andestech.com)
+ *
+ * All Rights Reserved
+ */
+
+#ifndef _FTSDC010_H_
+#define _FTSDC010_H_
+
+//#define SD_DEBUG
+#define DELAY_FOR_DMA_READ
+
+#ifdef SD_DEBUG
+ #define P_DEBUG(fmt, args...) printk(KERN_ALERT "SD: " fmt, ## args)
+#else
+ #define P_DEBUG(a...)
+#endif
+#define P_DEBUGG(a...)
+
+/* used for dma timeout */
+#define SDC_TIMEOUT_BASE (HZ/2) // Unit is 500 ms
+
+/* used for pio retry times */
+#define SDC_PIO_RETRY 0x300000
+
+/* sd controller register */
+#define SDC_CMD_REG 0x00000000
+#define SDC_ARGU_REG 0x00000004
+#define SDC_RESPONSE0_REG 0x00000008
+#define SDC_RESPONSE1_REG 0x0000000C
+#define SDC_RESPONSE2_REG 0x00000010
+#define SDC_RESPONSE3_REG 0x00000014
+#define SDC_RSP_CMD_REG 0x00000018
+#define SDC_DATA_CTRL_REG 0x0000001C
+#define SDC_DATA_TIMER_REG 0x00000020
+#define SDC_DATA_LEN_REG 0x00000024
+#define SDC_STATUS_REG 0x00000028
+#define SDC_CLEAR_REG 0x0000002C
+#define SDC_INT_MASK_REG 0x00000030
+#define SDC_POWER_CTRL_REG 0x00000034
+#define SDC_CLOCK_CTRL_REG 0x00000038
+#define SDC_BUS_WIDTH_REG 0x0000003C
+#define SDC_DATA_WINDOW_REG 0x00000040
+
+#ifdef A320D_BUILDIN_SDC
+#define SDC_FEATURE_REG 0x00000044
+#define SDC_REVISION_REG 0x00000048
+#else
+#define SDC_MMC_INT_RSP_REG 0x00000044
+#define SDC_GP_OUTPUT_REG 0x00000048
+#define SDC_FEATURE_REG 0x0000009C
+#define SDC_REVISION_REG 0x000000A0
+#endif
+
+#define SDC_SDIO_CTRL1_REG 0x0000006C
+#define SDC_SDIO_CTRL2_REG 0x00000070
+#define SDC_SDIO_STATUS_REG 0x00000074
+
+/* bit mapping of command register */
+#define SDC_CMD_REG_INDEX 0x0000003F
+#define SDC_CMD_REG_NEED_RSP 0x00000040
+#define SDC_CMD_REG_LONG_RSP 0x00000080
+#define SDC_CMD_REG_APP_CMD 0x00000100
+#define SDC_CMD_REG_CMD_EN 0x00000200
+#define SDC_CMD_REG_SDC_RST 0x00000400
+#define SDC_CMD_MMC_INT_STOP 0x00000800
+
+/* bit mapping of response command register */
+#define SDC_RSP_CMD_REG_INDEX 0x0000003F
+#define SDC_RSP_CMD_REG_APP 0x00000040
+
+/* bit mapping of data control register */
+#define SDC_DATA_CTRL_REG_BLK_SIZE 0x0000000F
+#define SDC_DATA_CTRL_REG_DATA_WRITE 0x00000010
+#define SDC_DATA_CTRL_REG_DMA_EN 0x00000020
+#define SDC_DATA_CTRL_REG_DATA_EN 0x00000040
+#define SDC_DATA_CTRL_REG_FIFOTH 0x00000080
+#define SDC_DATA_CTRL_REG_DMA_TYPE 0x00000300
+#define SDC_DATA_CTRL_REG_FIFO_RST 0x00000400
+#define SDC_CPRM_DATA_CHANGE_ENDIAN_EN 0x00000800
+#define SDC_CPRM_DATA_SWAP_HL_EN 0x00001000
+
+#define SDC_DMA_TYPE_1 0x00000000
+#define SDC_DMA_TYPE_4 0x00000100
+#define SDC_DMA_TYPE_8 0x00000200
+
+/* bit mapping of status register */
+#define SDC_STATUS_REG_RSP_CRC_FAIL 0x00000001
+#define SDC_STATUS_REG_DATA_CRC_FAIL 0x00000002
+#define SDC_STATUS_REG_RSP_TIMEOUT 0x00000004
+#define SDC_STATUS_REG_DATA_TIMEOUT 0x00000008
+#define SDC_STATUS_REG_RSP_CRC_OK 0x00000010
+#define SDC_STATUS_REG_DATA_CRC_OK 0x00000020
+#define SDC_STATUS_REG_CMD_SEND 0x00000040
+#define SDC_STATUS_REG_DATA_END 0x00000080
+#define SDC_STATUS_REG_FIFO_UNDERRUN 0x00000100
+#define SDC_STATUS_REG_FIFO_OVERRUN 0x00000200
+#define SDC_STATUS_REG_CARD_CHANGE 0x00000400
+#define SDC_STATUS_REG_CARD_DETECT 0x00000800
+#define SDC_STATUS_REG_CARD_LOCK 0x00001000
+#define SDC_STATUS_REG_CP_READY 0x00002000
+#define SDC_STATUS_REG_CP_BUF_READY 0x00004000
+#define SDC_STATUS_REG_PLAIN_TEXT_READY 0x00008000
+#define SDC_STATUS_REG_SDIO_INTR 0x00010000
+
+/* bit mapping of clear register */
+#define SDC_CLEAR_REG_RSP_CRC_FAIL 0x00000001
+#define SDC_CLEAR_REG_DATA_CRC_FAIL 0x00000002
+#define SDC_CLEAR_REG_RSP_TIMEOUT 0x00000004
+#define SDC_CLEAR_REG_DATA_TIMEOUT 0x00000008
+#define SDC_CLEAR_REG_RSP_CRC_OK 0x00000010
+#define SDC_CLEAR_REG_DATA_CRC_OK 0x00000020
+#define SDC_CLEAR_REG_CMD_SEND 0x00000040
+#define SDC_CLEAR_REG_DATA_END 0x00000080
+#define SDC_CLEAR_REG_CARD_CHANGE 0x00000400
+#define SDC_CLEAR_REG_SDIO_INTR 0x00010000
+
+/* bit mapping of int_mask register */
+#define SDC_INT_MASK_REG_RSP_CRC_FAIL 0x00000001
+#define SDC_INT_MASK_REG_DATA_CRC_FAIL 0x00000002
+#define SDC_INT_MASK_REG_RSP_TIMEOUT 0x00000004
+#define SDC_INT_MASK_REG_DATA_TIMEOUT 0x00000008
+#define SDC_INT_MASK_REG_RSP_CRC_OK 0x00000010
+#define SDC_INT_MASK_REG_DATA_CRC_OK 0x00000020
+#define SDC_INT_MASK_REG_CMD_SEND 0x00000040
+#define SDC_INT_MASK_REG_DATA_END 0x00000080
+#define SDC_INT_MASK_REG_FIFO_UNDERRUN 0x00000100
+#define SDC_INT_MASK_REG_FIFO_OVERRUN 0x00000200
+#define SDC_INT_MASK_REG_CARD_CHANGE 0x00000400
+#define SDC_INT_MASK_REG_CARD_LOCK 0x00001000
+#define SDC_INT_MASK_REG_CP_READY 0x00002000
+#define SDC_INT_MASK_REG_CP_BUF_READY 0x00004000
+#define SDC_INT_MASK_REG_PLAIN_TEXT_READY 0x00008000
+#define SDC_INT_MASK_REG_SDIO_INTR 0x00010000
+
+
+#define SDC_CARD_INSERT 0x0
+#define SDC_CARD_REMOVE SDC_STATUS_REG_CARD_DETECT
+
+/* bit mapping of power control register */
+#define SDC_POWER_CTRL_REG_POWER_ON 0x00000010
+#define SDC_POWER_CTRL_REG_POWER_BITS 0x0000000F
+
+/* bit mapping of clock control register */
+#define SDC_CLOCK_CTRL_REG_CLK_DIV 0x0000007F
+#define SDC_CLOCK_CTRL_REG_CARD_TYPE 0x00000080
+#define SDC_CLOCK_CTRL_REG_CLK_DIS 0x00000100
+
+/* card type */
+#define SDC_CARD_TYPE_SD SDC_CLOCK_REG_CARD_TYPE
+#define SDC_CARD_TYPE_MMC 0x0
+
+/* bit mapping of bus width register */
+#define SDC_BUS_WIDTH_REG_SINGLE_BUS 0x00000001
+#define SDC_BUS_WIDTH_REG_WIDE_8_BUS 0x00000002
+#define SDC_BUS_WIDTH_REG_WIDE_4_BUS 0x00000004
+#define SDC_BUS_WIDTH_REG_WIDE_BUS_SUPPORT 0x00000018
+#define SDC_BUS_WIDTH_REG_CARD_DETECT 0x00000020
+
+#define SDC_WIDE_4_BUS_SUPPORT 0x00000008
+#define SDC_WIDE_8_BUS_SUPPORT 0x00000010
+
+/* bit mapping of feature register */
+#define SDC_FEATURE_REG_FIFO_DEPTH 0x000000FF
+#define SDC_FEATURE_REG_CPRM_FUNCTION 0x00000100
+
+/* bit mapping of sdio control register */
+#define SDC_SDIO_CTRL1_REG_SDIO_BLK_NO 0xFFFF8000
+#define SDC_SDIO_CTRL1_REG_SDIO_ENABLE 0x00004000
+#define SDC_SDIO_CTRL1_REG_READ_WAIT_ENABLE 0x00002000
+#define SDC_SDIO_CTRL1_REG_SDIO_BLK_MODE 0x00001000
+#define SDC_SDIO_CTRL1_REG_SDIO_BLK_SIZE 0x00000FFF
+
+/* bit mapping of sdio status register */
+#define SDC_SDIO_SDIO_STATUS_REG_FIFO_REMAIN_NO 0x00FE0000
+#define SDC_SDIO_SDIO_STATUS_REG_SDIO_BLK_CNT 0x0001FFFF
+
+enum ftsdc_waitfor {
+ COMPLETION_NONE,
+ COMPLETION_FINALIZE,
+ COMPLETION_CMDSENT,
+ COMPLETION_RSPFIN,
+ COMPLETION_XFER_PROGRESS,
+};
+
+struct ftsdc_host {
+ struct platform_device *pdev;
+ struct mmc_host *mmc;
+ struct resource *mem;
+ struct clk *clk;
+ void __iomem *base;
+ int irq;
+
+ unsigned int real_rate;
+ bool irq_enabled;
+ unsigned int fifo_len; /* bytes */
+ unsigned int last_opcode; /* keep last successful cmd to judge application specific command */
+
+ struct mmc_request *mrq;
+ int cmd_is_stop;
+
+ spinlock_t complete_lock;
+ enum ftsdc_waitfor complete_what;
+
+ struct completion dma_complete;
+ dmad_chreq *dma_req;
+ bool dodma;
+ bool dma_finish;
+
+
+ u32 buf_sgptr; /* keep next scallterlist buffer index */
+ u32 buf_bytes; /* keep current total scallterlist buffer length */
+ u32 buf_count; /* keep real data size rw from sd */
+ u32 *buf_ptr; /* keep current scallterlist buffer address */
+#define XFER_NONE 0
+#define XFER_READ 1
+#define XFER_WRITE 2
+ u32 buf_active; /* keep current transfer mode */
+
+ int bus_width;
+
+ char dbgmsg_cmd[301];
+ char dbgmsg_dat[301];
+ char *status;
+
+ unsigned int ccnt, dcnt;
+ struct tasklet_struct pio_tasklet;
+ struct work_struct work;
+
+#ifdef CONFIG_DEBUG_FS
+ struct dentry *debug_root;
+ struct dentry *debug_state;
+ struct dentry *debug_regs;
+#endif
+};
+
+#endif
diff -Nur linux-3.4.113.orig/drivers/mmc/host/Kconfig linux-3.4.113/drivers/mmc/host/Kconfig
--- linux-3.4.113.orig/drivers/mmc/host/Kconfig 2016-10-26 17:15:47.000000000 +0200
+++ linux-3.4.113/drivers/mmc/host/Kconfig 2016-12-01 20:59:24.388614139 +0100
@@ -609,3 +609,8 @@
Note: These controllers only support SDIO cards and do not
support MMC or SD memory cards.
+
+config MMC_FTSDC010
+ tristate "Andestech MMC/SD function support"
+ depends on NDS32 && !FTSDC010
+
diff -Nur linux-3.4.113.orig/drivers/mmc/host/Makefile linux-3.4.113/drivers/mmc/host/Makefile
--- linux-3.4.113.orig/drivers/mmc/host/Makefile 2016-10-26 17:15:47.000000000 +0200
+++ linux-3.4.113/drivers/mmc/host/Makefile 2016-12-01 20:59:24.388614139 +0100
@@ -45,6 +45,7 @@
obj-$(CONFIG_MMC_JZ4740) += jz4740_mmc.o
obj-$(CONFIG_MMC_VUB300) += vub300.o
obj-$(CONFIG_MMC_USHC) += ushc.o
+obj-$(CONFIG_MMC_FTSDC010) += ftsdc010.o
obj-$(CONFIG_MMC_SDHCI_PLTFM) += sdhci-pltfm.o
obj-$(CONFIG_MMC_SDHCI_CNS3XXX) += sdhci-cns3xxx.o
diff -Nur linux-3.4.113.orig/drivers/net/ethernet/faraday/ftmac100.c linux-3.4.113/drivers/net/ethernet/faraday/ftmac100.c
--- linux-3.4.113.orig/drivers/net/ethernet/faraday/ftmac100.c 2016-10-26 17:15:47.000000000 +0200
+++ linux-3.4.113/drivers/net/ethernet/faraday/ftmac100.c 2016-12-01 20:59:24.388614139 +0100
@@ -1,1202 +1,1210 @@
/*
- * Faraday FTMAC100 10/100 Ethernet
+ * drivers/net/ftmac100.c
*
- * (C) Copyright 2009-2011 Faraday Technology
- * Po-Yu Chuang <ratbert@faraday-tech.com>
+ * Faraday FTMAC100 Device Driver
*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
+ * Copyright (C) 2005 Faraday Corp. (http://www.faraday-tech.com)
+ *
+ * All Rights Reserved
*
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
-#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
-
-#include <linux/dma-mapping.h>
-#include <linux/etherdevice.h>
-#include <linux/ethtool.h>
+#include <linux/module.h>
#include <linux/init.h>
+#include <linux/moduleparam.h>
+
+#include <linux/sched.h>
+#include <linux/kernel.h> /* printk() */
+#include <linux/slab.h> /* kmalloc() */
+#include <linux/errno.h> /* error codes */
+#include <linux/types.h> /* size_t */
#include <linux/interrupt.h>
-#include <linux/io.h>
-#include <linux/mii.h>
-#include <linux/module.h>
-#include <linux/netdevice.h>
+
+#include <linux/in.h>
#include <linux/platform_device.h>
+#include <linux/netdevice.h> /* struct device, and other headers */
+#include <linux/etherdevice.h> /* eth_type_trans */
+#include <linux/ip.h> /* struct iphdr */
+#include <linux/tcp.h> /* struct tcphdr */
+#include <linux/skbuff.h>
+
+#include <linux/in6.h>
+#include <asm/checksum.h>
+
+
+#include <linux/version.h>
+#include <linux/kernel.h>
+#include <linux/fcntl.h>
+#include <linux/ptrace.h>
+#include <linux/ioport.h>
+#include <linux/slab.h>
+#include <linux/string.h>
+#include <linux/proc_fs.h>
+#include <asm/bitops.h>
+#include <asm/io.h>
+#include <asm/hardware.h>
+#include <linux/pci.h>
+#include <linux/delay.h>
+#include <linux/netdevice.h>
+#include <linux/etherdevice.h>
+#include <linux/skbuff.h>
+#include <asm/cacheflush.h> // dma_clean_range
+#include <asm/spec.h>
#include "ftmac100.h"
-#define DRV_NAME "ftmac100"
-#define DRV_VERSION "0.2"
-
-#define RX_QUEUE_ENTRIES 128 /* must be power of 2 */
-#define TX_QUEUE_ENTRIES 16 /* must be power of 2 */
+#define IPMODULE MAC
+#define IPNAME FTMAC100
-#define MAX_PKT_SIZE 1518
-#define RX_BUF_SIZE 2044 /* must be smaller than 0x7ff */
+#define ENABLE_BOTTOM_HALF 0
+#define ZERO_COPY 1
-#if MAX_PKT_SIZE > 0x7ff
-#error invalid MAX_PKT_SIZE
-#endif
-
-#if RX_BUF_SIZE > 0x7ff || RX_BUF_SIZE > PAGE_SIZE
-#error invalid RX_BUF_SIZE
-#endif
-
-/******************************************************************************
- * private data
- *****************************************************************************/
-struct ftmac100_descs {
- struct ftmac100_rxdes rxdes[RX_QUEUE_ENTRIES];
- struct ftmac100_txdes txdes[TX_QUEUE_ENTRIES];
-};
-
-struct ftmac100 {
- struct resource *res;
- void __iomem *base;
- int irq;
-
- struct ftmac100_descs *descs;
- dma_addr_t descs_dma_addr;
-
- unsigned int rx_pointer;
- unsigned int tx_clean_pointer;
- unsigned int tx_pointer;
- unsigned int tx_pending;
-
- spinlock_t tx_lock;
-
- struct net_device *netdev;
- struct device *dev;
- struct napi_struct napi;
+#define FTMAC100_DEBUG 0
+#define CARDNAME "FTMAC100"
- struct mii_if_info mii;
-};
-
-static int ftmac100_alloc_rx_page(struct ftmac100 *priv,
- struct ftmac100_rxdes *rxdes, gfp_t gfp);
-
-/******************************************************************************
- * internal functions (hardware register access)
- *****************************************************************************/
-#define INT_MASK_ALL_ENABLED (FTMAC100_INT_RPKT_FINISH | \
- FTMAC100_INT_NORXBUF | \
- FTMAC100_INT_XPKT_OK | \
- FTMAC100_INT_XPKT_LOST | \
- FTMAC100_INT_RPKT_LOST | \
- FTMAC100_INT_AHB_ERR | \
- FTMAC100_INT_PHYSTS_CHG)
+MODULE_AUTHOR("Faraday Corp.");
+MODULE_LICENSE("GPL");
-#define INT_MASK_ALL_DISABLED 0
+static const char version[] = "Faraday FTMAC100 Driver (Linux 2.6) 09/28/05 - (C) 2005 Faraday Corp.\n";
+static volatile int trans_busy = 0;
+static const char mac_string[] = "Faraday MAC";
-static void ftmac100_enable_all_int(struct ftmac100 *priv)
-{
- iowrite32(INT_MASK_ALL_ENABLED, priv->base + FTMAC100_OFFSET_IMR);
-}
+#if FTMAC100_DEBUG > 2
+static void print_packet( unsigned char * buf, int length );
+#endif
-static void ftmac100_disable_all_int(struct ftmac100 *priv)
-{
- iowrite32(INT_MASK_ALL_DISABLED, priv->base + FTMAC100_OFFSET_IMR);
-}
+#if FTMAC100_DEBUG > 0
+#define PRINTK printk
+#else
+#define PRINTK(x...)
+#endif
-static void ftmac100_set_rx_ring_base(struct ftmac100 *priv, dma_addr_t addr)
-{
- iowrite32(addr, priv->base + FTMAC100_OFFSET_RXR_BADR);
+static int ftmac100_open(struct net_device *dev);
+static void ftmac100_timeout (struct net_device *dev);
+static int ftmac100_close(struct net_device *dev);
+static struct net_device_stats * ftmac100_query_statistics( struct net_device *dev);
+#ifdef HAVE_MULTICAST
+static void ftmac100_set_multicast_list(struct net_device *dev);
+#endif
+static void ftmac100_phy_configure(struct net_device* dev) {};
+static irqreturn_t ftmac100_interrupt(int irq, void * dev_id);
+static void ftmac100_rcv(void *dev);
+static int ftmac100_setup(struct net_device *dev);
+static int ftmac100_reset( struct net_device* dev );
+static void ftmac100_enable( struct net_device *dev );
+
+static void put_mac(int base, unsigned char *mac_addr)
+{
+ int val;
+
+ val = ((u32)mac_addr[0])<<8 | (u32)mac_addr[1];
+ outl(val, base);
+ val = ((((u32)mac_addr[2])<<24)&0xff000000) |
+ ((((u32)mac_addr[3])<<16)&0xff0000) |
+ ((((u32)mac_addr[4])<<8)&0xff00) |
+ ((((u32)mac_addr[5])<<0)&0xff);
+ outl(val, base+4);
+}
+
+static void get_mac(int base, unsigned char *mac_addr)
+{
+ int val;
+
+ //printk("+get_mac\n");
+
+ val = inl(base);
+ mac_addr[0] = (val>>8)&0xff;
+ mac_addr[1] = val&0xff;
+ val = inl(base+4); //john add +4
+ mac_addr[2] = (val>>24)&0xff;
+ mac_addr[3] = (val>>16)&0xff;
+ mac_addr[4] = (val>>8)&0xff;
+ mac_addr[5] = val&0xff;
+}
+
+static void auto_get_mac(int id,unsigned char *mac_addr)
+{
+ get_mac(MAC_FTMAC100_0_VA_BASE + MAC_MADR_REG, mac_addr);
+
+ if (memcmp(mac_addr, "\0\0\0\0\0\0", 6) == 0) {
+ mac_addr[0]=0;
+ mac_addr[1]=0x23;
+ mac_addr[2]=0x96;
+ mac_addr[3]=0x00;
+ mac_addr[4]=0xff;
+ mac_addr[5]=0x00;
+ }
}
-static void ftmac100_set_tx_ring_base(struct ftmac100 *priv, dma_addr_t addr)
+/*
+ * Print the Ethernet address
+ */
+static void ft_print_mac(unsigned char *mac_addr)
{
- iowrite32(addr, priv->base + FTMAC100_OFFSET_TXR_BADR);
+ printk("ADDR: %pM\n", mac_addr);
}
-static void ftmac100_txdma_start_polling(struct ftmac100 *priv)
-{
- iowrite32(1, priv->base + FTMAC100_OFFSET_TXPD);
-}
-static int ftmac100_reset(struct ftmac100 *priv)
+#ifdef HAVE_MULTICAST
+/*
+ * Finds the CRC32 of a set of bytes.
+ * Again, from Peter Cammaert's code.
+ */
+static int crc32( char * s, int length )
{
- struct net_device *netdev = priv->netdev;
- int i;
-
- /* NOTE: reset clears all registers */
- iowrite32(FTMAC100_MACCR_SW_RST, priv->base + FTMAC100_OFFSET_MACCR);
-
- for (i = 0; i < 5; i++) {
- unsigned int maccr;
-
- maccr = ioread32(priv->base + FTMAC100_OFFSET_MACCR);
- if (!(maccr & FTMAC100_MACCR_SW_RST)) {
- /*
- * FTMAC100_MACCR_SW_RST cleared does not indicate
- * that hardware reset completed (what the f*ck).
- * We still need to wait for a while.
- */
- udelay(500);
- return 0;
+ /* indices */
+ int perByte;
+ int perBit;
+ /* crc polynomial for Ethernet */
+ const unsigned long poly = 0xedb88320;
+ /* crc value - preinitialized to all 1's */
+ unsigned long crc_value = 0xffffffff;
+
+ //printk("+crc32\n");
+
+ for ( perByte = 0; perByte < length; perByte ++ ) {
+ unsigned char c;
+
+ c = *(s++);
+ for ( perBit = 0; perBit < 8; perBit++ ) {
+ crc_value = (crc_value>>1)^
+ (((crc_value^c)&0x01)?poly:0);
+ c >>= 1;
}
-
- udelay(1000);
}
-
- netdev_err(netdev, "software reset failed\n");
- return -EIO;
-}
-
-static void ftmac100_set_mac(struct ftmac100 *priv, const unsigned char *mac)
-{
- unsigned int maddr = mac[0] << 8 | mac[1];
- unsigned int laddr = mac[2] << 24 | mac[3] << 16 | mac[4] << 8 | mac[5];
-
- iowrite32(maddr, priv->base + FTMAC100_OFFSET_MAC_MADR);
- iowrite32(laddr, priv->base + FTMAC100_OFFSET_MAC_LADR);
+ return crc_value;
}
+#endif
-#define MACCR_ENABLE_ALL (FTMAC100_MACCR_XMT_EN | \
- FTMAC100_MACCR_RCV_EN | \
- FTMAC100_MACCR_XDMA_EN | \
- FTMAC100_MACCR_RDMA_EN | \
- FTMAC100_MACCR_CRC_APD | \
- FTMAC100_MACCR_FULLDUP | \
- FTMAC100_MACCR_RX_RUNT | \
- FTMAC100_MACCR_RX_BROADPKT)
-
-static int ftmac100_start_hw(struct ftmac100 *priv)
+static int ftmac100_reset( struct net_device* dev )
{
- struct net_device *netdev = priv->netdev;
+ unsigned ioaddr = dev->base_addr;
+ int rcount;
- if (ftmac100_reset(priv))
- return -EIO;
+ PRINTK("+ftmac100_reset:I/O addr=%X\n", ioaddr);
- /* setup ring buffer base registers */
- ftmac100_set_rx_ring_base(priv,
- priv->descs_dma_addr +
- offsetof(struct ftmac100_descs, rxdes));
- ftmac100_set_tx_ring_base(priv,
- priv->descs_dma_addr +
- offsetof(struct ftmac100_descs, txdes));
+ outl( SW_RST_bit, ioaddr + MACCR_REG );
- iowrite32(FTMAC100_APTC_RXPOLL_CNT(1), priv->base + FTMAC100_OFFSET_APTC);
+ /* this should pause enough for the chip to be happy */
+ for (rcount = 0; (inl( ioaddr + MACCR_REG ) & SW_RST_bit) != 0; rcount++) {
+ //mdelay(10);
+ msleep_interruptible(10);
+ if (rcount > 5) // Retry 5 times
+ return -ENODEV;
+ }
- ftmac100_set_mac(priv, netdev->dev_addr);
+ outl( 0, ioaddr + IMR_REG ); /* Disable all interrupts */
+ if (inl(ioaddr+IMR_REG)!=0)
+ return -ENODEV;
- iowrite32(MACCR_ENABLE_ALL, priv->base + FTMAC100_OFFSET_MACCR);
- return 0;
+ return 0;
}
-static void ftmac100_stop_hw(struct ftmac100 *priv)
-{
- iowrite32(0, priv->base + FTMAC100_OFFSET_MACCR);
-}
-/******************************************************************************
- * internal functions (receive descriptor)
- *****************************************************************************/
-static bool ftmac100_rxdes_first_segment(struct ftmac100_rxdes *rxdes)
-{
- return rxdes->rxdes0 & cpu_to_le32(FTMAC100_RXDES0_FRS);
-}
-
-static bool ftmac100_rxdes_last_segment(struct ftmac100_rxdes *rxdes)
+/*
+ . Function: ftmac100_enable
+ . Purpose: let the chip talk to the outside work
+ . Method:
+ . 1. Enable the transmitter
+ . 2. Enable the receiver
+ . 3. Enable interrupts
+*/
+static void ftmac100_enable( struct net_device *dev )
{
- return rxdes->rxdes0 & cpu_to_le32(FTMAC100_RXDES0_LRS);
-}
+ unsigned int ioaddr = dev->base_addr;
+ int i;
+ struct ftmac100_local *priv = (struct ftmac100_local *)netdev_priv(dev);
+ char mac_addr[6];
-static bool ftmac100_rxdes_owned_by_dma(struct ftmac100_rxdes *rxdes)
-{
- return rxdes->rxdes0 & cpu_to_le32(FTMAC100_RXDES0_RXDMA_OWN);
-}
+ //printk("+ftmac100_enable\n");
+ PRINTK("%s:ftmac100_enable ioaddr=%X\n", dev->name, ioaddr);
-static void ftmac100_rxdes_set_dma_own(struct ftmac100_rxdes *rxdes)
-{
- /* clear status bits */
- rxdes->rxdes0 = cpu_to_le32(FTMAC100_RXDES0_RXDMA_OWN);
+ for (i=0; i<RXDES_NUM; ++i) {
+ priv->rx_descs[i].RXDMA_OWN = OWNBY_FTMAC100; // owned by FTMAC100
+ }
+ priv->rx_idx = 0;
+
+ for (i=0; i<TXDES_NUM; ++i) {
+ priv->tx_descs[i].TXDMA_OWN = OWNBY_SOFTWARE; // owned by software
+ }
+ priv->tx_idx = 0;
+
+
+ /* set the MAC address */
+ put_mac(ioaddr + MAC_MADR_REG, dev->dev_addr);
+
+ //john add
+ get_mac(ioaddr + MAC_MADR_REG, mac_addr);
+ ft_print_mac(mac_addr);
+
+ outl( priv->rx_descs_dma, ioaddr + RXR_BADR_REG);
+ outl( priv->tx_descs_dma, ioaddr + TXR_BADR_REG);
+ outl( 0x00001010, ioaddr + ITC_REG); // TODO: threshold too small
+ outl( (0UL<<TXPOLL_CNT)|(0x1<<RXPOLL_CNT), ioaddr + APTC_REG); // TODO: bandwidth overhead maybe too big, polling too often ?!
+ outl( 0x1d8, ioaddr + DBLAC_REG ); //Luke Lee: 1 110 010 111 (0x397)
+
+ /* now, enable interrupts */
+ outl( PHYSTS_CHG_bit
+ | AHB_ERR_bit
+ | RPKT_LOST_bit
+ | RPKT_SAV_bit
+ | XPKT_LOST_bit
+ | XPKT_OK_bit
+ | NOTXBUF_bit
+ | XPKT_FINISH_bit
+ | NORXBUF_bit
+ | RPKT_FINISH_bit
+ , ioaddr + IMR_REG);
+
+ /// enable trans/recv,...
+ outl( priv->maccr_val, ioaddr + MACCR_REG );
+ PRINTK("%s:ftmac100_enable DONE\n", dev->name);
}
-static bool ftmac100_rxdes_rx_error(struct ftmac100_rxdes *rxdes)
+/*
+ . Function: ftmac100_shutdown
+ . Purpose: closes down the SMC91xxx chip.
+ . Method:
+ . 1. zero the interrupt mask
+ . 2. clear the enable receive flag
+ . 3. clear the enable xmit flags
+ .
+ . TODO:
+ . (1) maybe utilize power down mode.
+ . Why not yet? Because while the chip will go into power down mode,
+ . the manual says that it will wake up in response to any I/O requests
+ . in the register space. Empirical results do not show this working.
+*/
+static void ftmac100_shutdown( unsigned int ioaddr )
{
- return rxdes->rxdes0 & cpu_to_le32(FTMAC100_RXDES0_RX_ERR);
-}
+ //printk("+ftmac100_shutdown\n");
-static bool ftmac100_rxdes_crc_error(struct ftmac100_rxdes *rxdes)
-{
- return rxdes->rxdes0 & cpu_to_le32(FTMAC100_RXDES0_CRC_ERR);
+ outl( 0, ioaddr + IMR_REG );
+ outl( 0, ioaddr + MACCR_REG );
}
-static bool ftmac100_rxdes_frame_too_long(struct ftmac100_rxdes *rxdes)
+/*
+ * Function: ftmac100_wait_to_send_packet( struct sk_buff * skb, struct device * )
+ * Purpose:
+ * Attempt to allocate memory for a packet, if chip-memory is not
+ * available, then tell the card to generate an interrupt when it
+ * is available*
+ *
+ * Algorithm:
+ *
+ * o if the saved_skb is not currently null, then drop this packet
+ * on the floor. This should never happen, because of TBUSY.
+ * o if the saved_skb is null, then replace it with the current packet,
+ * o See if I can sending it now.
+ * o (NO): Enable interrupts and let the interrupt handler deal with it.
+ * o (YES):Send it now.
+ */
+static int ftmac100_wait_to_send_packet( struct sk_buff * skb, struct net_device * dev )
{
- return rxdes->rxdes0 & cpu_to_le32(FTMAC100_RXDES0_FTL);
-}
+ struct ftmac100_local *priv=(struct ftmac100_local *)netdev_priv(dev);
+ unsigned int ioaddr=dev->base_addr;
+ volatile TX_DESC *cur_desc;
+ int length;
+ unsigned long flags;
+
+ //printk("+ftmac100_wait_to_send_packet\n");
+
+ spin_lock_irqsave(&priv->lock, flags);
+ if (skb==NULL) {
+ printk("%s(%d): NULL skb???\n", __FILE__,__LINE__);
+ spin_unlock_irqrestore(&priv->lock, flags);
+ return 0;
+ }
+
+ cur_desc = &priv->tx_descs[priv->tx_idx];
+#if ZERO_COPY
+ /* Record buffer address to be freed later */
+ priv->tx_skbuff[priv->tx_idx] = skb;
+#endif
+
+#ifdef not_complete_yet
+ if (cur_desc->TXDMA_OWN != TX_OWNBY_SOFTWARE) /// no empty transmit descriptor
+ {
+ DO_PRINT("no empty transmit descriptor\n");
+ DO_PRINT("jiffies = %d\n", jiffies);
+ lp->stats.tx_dropped++;
+ netif_stop_queue(dev); /// waiting to do:
+ spin_unlock_irqrestore(&lp->lock, flags);
+
+ return 1;
+ }
+#endif /* end_of_not */
+
+ for (; cur_desc->TXDMA_OWN != OWNBY_SOFTWARE; ) {
+ PRINTK( KERN_WARNING "NO empty TX\n"); //printk("no empty TX descriptor:0x%x:0x%x\n",(unsigned)cur_desc,(unsigned)cur_desc[0]);
+ udelay(1);
+ }
+ length = ETH_ZLEN < skb->len ? skb->len : ETH_ZLEN;
+ length = min(length, TX_BUF_SIZE); // truncate jumbo packets
+
+#if FTMAC100_DEBUG > 2
+ printk("Transmitting Packet at 0x%x\n",(unsigned int)cur_desc->VIR_TXBUF_BADR);
+ print_packet( skb->data, length );
+#endif
-static bool ftmac100_rxdes_runt(struct ftmac100_rxdes *rxdes)
-{
- return rxdes->rxdes0 & cpu_to_le32(FTMAC100_RXDES0_RUNT);
-}
+#if ZERO_COPY
+ cur_desc->VIR_TXBUF_BADR = (unsigned)skb->data;
+ cur_desc->TXBUF_BADR = virt_to_phys(skb->data);
+ cpu_dma_wb_range((unsigned)skb->data, ((unsigned)(skb->data) + length + CACHE_LINE_SIZE( DCACHE) - 1 )&(~(CACHE_LINE_SIZE( DCACHE)-1)) );
-static bool ftmac100_rxdes_odd_nibble(struct ftmac100_rxdes *rxdes)
-{
- return rxdes->rxdes0 & cpu_to_le32(FTMAC100_RXDES0_RX_ODD_NB);
-}
+#else
+ memcpy((char *)cur_desc->VIR_TXBUF_BADR, skb->data, length);
+#endif
-static unsigned int ftmac100_rxdes_frame_length(struct ftmac100_rxdes *rxdes)
-{
- return le32_to_cpu(rxdes->rxdes0) & FTMAC100_RXDES0_RFL;
+ cur_desc->TXBUF_Size = length;
+ cur_desc->LTS = 1;
+ cur_desc->FTS = 1;
+
+ cur_desc->TX2FIC = 0;
+ cur_desc->TXIC = 0;
+
+ cur_desc->TXDMA_OWN = OWNBY_FTMAC100;
+
+ outl( 0xffffffff, ioaddr + TXPD_REG );
+
+ priv->tx_idx = (priv->tx_idx + 1) & (TXDES_NUM-1);
+ priv->stats.tx_packets++;
+ priv->stats.tx_bytes += skb->len;
+#if !ZERO_COPY
+ dev_kfree_skb_any (skb);
+#endif
+ dev->trans_start = jiffies;
+ spin_unlock_irqrestore(&priv->lock, flags);
+ return 0;
}
-static bool ftmac100_rxdes_multicast(struct ftmac100_rxdes *rxdes)
-{
- return rxdes->rxdes0 & cpu_to_le32(FTMAC100_RXDES0_MULTICAST);
-}
+//#define dma_allocate(x,y,z,w) dma_alloc_coherent((x),(y),(dma_addr_t*)(z),(w))
+#define dma_allocate(x,y,z,w) dma_alloc_writecombine((x),(y),(dma_addr_t*)(z),(w))
-static void ftmac100_rxdes_set_buffer_size(struct ftmac100_rxdes *rxdes,
- unsigned int size)
+static int ftmac100_ringbuf_alloc(struct net_device *dev,struct ftmac100_local *priv)
{
- rxdes->rxdes1 &= cpu_to_le32(FTMAC100_RXDES1_EDORR);
- rxdes->rxdes1 |= cpu_to_le32(FTMAC100_RXDES1_RXBUF_SIZE(size));
-}
+ int i;
-static void ftmac100_rxdes_set_end_of_ring(struct ftmac100_rxdes *rxdes)
-{
- rxdes->rxdes1 |= cpu_to_le32(FTMAC100_RXDES1_EDORR);
-}
+ //printk("+ftmac100_ringbuf_alloc\n");
-static void ftmac100_rxdes_set_dma_addr(struct ftmac100_rxdes *rxdes,
- dma_addr_t addr)
-{
- rxdes->rxdes2 = cpu_to_le32(addr);
-}
+ priv->rx_descs = dma_allocate( NULL, sizeof(RX_DESC)*RXDES_NUM, &(priv->rx_descs_dma), GFP_KERNEL );
+ if (priv->rx_descs == NULL || (( (u32)priv->rx_descs & 0xf)!=0)) {
+ printk("Receive Ring Buffer allocation error\n");
+ return -ENOMEM;
+ }
+#if FTMAC100_DEBUG > 2
+ else
+ printk( KERN_INFO "* Allocated RX descs=%X, bus addr=%X, size=%d*%d=%d\n",
+ (unsigned)priv->rx_descs, (unsigned)priv->rx_descs_dma,
+ sizeof(RX_DESC),RXDES_NUM,sizeof(RX_DESC)*RXDES_NUM );
+#endif
+ memset((unsigned int *)priv->rx_descs, 0, sizeof(RX_DESC)*RXDES_NUM);
-static dma_addr_t ftmac100_rxdes_get_dma_addr(struct ftmac100_rxdes *rxdes)
-{
- return le32_to_cpu(rxdes->rxdes2);
+ priv->rx_buf = dma_allocate( NULL, RX_BUF_SIZE*RXDES_NUM, &(priv->rx_buf_dma), GFP_KERNEL );
+ if (priv->rx_buf == NULL || (( (u32)priv->rx_buf & 3)!=0)) {
+ printk("Receive Ring Buffer allocation error\n");
+ return -ENOMEM;
+ }
+#if FTMAC100_DEBUG > 2
+ else
+ printk( KERN_INFO "* Allocated RX buf=%X, bus addr=%X, size=%d*%d=%d\n",
+ (unsigned)priv->rx_buf, (unsigned)priv->rx_buf_dma,
+ RX_BUF_SIZE, RXDES_NUM, RX_BUF_SIZE*RXDES_NUM );
+#endif
+
+ memset((void *)priv->rx_buf,0,sizeof(RX_BUF_SIZE)*RXDES_NUM);
+
+ for (i=0; i<RXDES_NUM; ++i) {
+ priv->rx_descs[i].RXBUF_Size = RX_BUF_SIZE;
+ priv->rx_descs[i].EDOTR = 0; // not last descriptor
+ priv->rx_descs[i].RXBUF_BADR = priv->rx_buf_dma+RX_BUF_SIZE*i;
+ priv->rx_descs[i].VIR_RXBUF_BADR=(unsigned int)priv->rx_buf+RX_BUF_SIZE*i;
+ }
+ priv->rx_descs[RXDES_NUM-1].EDOTR = 1; // is last descriptor
+
+ priv->tx_descs = dma_allocate( NULL, sizeof(TX_DESC)*TXDES_NUM, &(priv->tx_descs_dma), GFP_KERNEL );
+ if (priv->tx_descs == NULL || (( (u32)priv->tx_descs & 0xf)!=0)) {
+ printk("Transmit Ring Buffer allocation error\n");
+ return -ENOMEM;
+ }
+#if FTMAC100_DEBUG > 2
+ else
+ printk( KERN_INFO "* Allocated TX descs=%X, bus addr=%X, size=%d*%d=%d\n",
+ (unsigned)priv->tx_descs, (unsigned)priv->tx_descs_dma, sizeof(TX_DESC),TXDES_NUM,sizeof(TX_DESC)*TXDES_NUM);
+#endif
+ memset((void *)priv->tx_descs,0,sizeof(TX_DESC)*TXDES_NUM);
+
+ priv->tx_buf = dma_allocate( NULL, TX_BUF_SIZE*TXDES_NUM, &(priv->tx_buf_dma), GFP_KERNEL );
+ if (priv->tx_buf == NULL || (( (u32)priv->tx_buf & 0x3)!=0)) {
+ printk("Transmit Ring Buffer allocation error\n");
+ return -ENOMEM;
+ }
+#if FTMAC100_DEBUG > 2
+ else
+ printk( KERN_INFO "* Allocated TX buf=%X, bus addr=%X, size=%d*%d=%d\n",
+ (unsigned)priv->tx_buf, (unsigned)priv->tx_buf_dma,
+ TX_BUF_SIZE, TXDES_NUM, TX_BUF_SIZE*TXDES_NUM );
+#endif
+
+ memset((void *)priv->tx_buf,0,sizeof(TX_BUF_SIZE)*TXDES_NUM);
+
+ for (i=0; i<TXDES_NUM; ++i) {
+ priv->tx_descs[i].EDOTR = 0; // not last descriptor
+ priv->tx_descs[i].TXBUF_BADR=priv->tx_buf_dma+TX_BUF_SIZE*i;
+ priv->tx_descs[i].VIR_TXBUF_BADR=(unsigned int)priv->tx_buf+TX_BUF_SIZE*i;
+ }
+ priv->tx_descs[TXDES_NUM-1].EDOTR = 1; // is last descriptor
+ return 0;
}
/*
- * rxdes3 is not used by hardware. We use it to keep track of page.
- * Since hardware does not touch it, we can skip cpu_to_le32()/le32_to_cpu().
+ * Function: ftmac100_poll( struct net_device *dev )
+ *
+ * Purpose:
+ * poll interface callback function.
*/
-static void ftmac100_rxdes_set_page(struct ftmac100_rxdes *rxdes, struct page *page)
+void ftmac100_poll(struct net_device *dev)
{
- rxdes->rxdes3 = (unsigned int)page;
+ disable_irq(dev->irq);
+ ftmac100_interrupt(dev->irq, dev);
+ enable_irq(dev->irq);
}
-static struct page *ftmac100_rxdes_get_page(struct ftmac100_rxdes *rxdes)
-{
- return (struct page *)rxdes->rxdes3;
-}
-
-/******************************************************************************
- * internal functions (receive)
- *****************************************************************************/
-static int ftmac100_next_rx_pointer(int pointer)
+/*
+ * Function: ftmac100_setup( struct net_device *dev )
+ *
+ * Purpose:
+ * Tests to see if the device 'dev' points to an ftmac100 chip.
+ * Returns a 0 on success
+ */
+static const struct net_device_ops ftmac100_ops = {
+ .ndo_init = ftmac100_setup,
+ .ndo_open = ftmac100_open,
+ .ndo_stop = ftmac100_close,
+ .ndo_start_xmit = ftmac100_wait_to_send_packet,
+ .ndo_get_stats = ftmac100_query_statistics,
+ .ndo_tx_timeout = ftmac100_timeout,
+#ifdef HAVE_MULTICAST
+ .ndo_set_multicast_list = ftmac100_set_multicast_list,
+#endif
+ .ndo_set_mac_address = eth_mac_addr,
+#ifdef CONFIG_NET_POLL_CONTROLLER
+ .ndo_poll_controller = ftmac100_poll,
+#endif
+};
+static int ftmac100_setup(struct net_device *dev)
{
- return (pointer + 1) & (RX_QUEUE_ENTRIES - 1);
-}
+ int retval;
+ static unsigned version_printed = 0;
+ struct ftmac100_local *priv;
+
+ if (version_printed++ == 0)
+ printk(KERN_INFO "%s", version);
+
+ /* Now, print out the card info, in a short format.. */
+ printk(KERN_INFO "%s: device at %#3x IRQ:%d NOWAIT:%d\n",dev->name,
+ (unsigned)dev->base_addr, dev->irq, dev->dma);
+
+ /* Initialize priviate data */
+ priv = (struct ftmac100_local *)netdev_priv(dev);
+ memset(priv, 0, sizeof(struct ftmac100_local));
+ spin_lock_init(&priv->lock);
+ priv->maccr_val = FULLDUP_bit
+ | CRC_APD_bit
+ | MDC_SEL_bit
+ | RCV_EN_bit
+ | XMT_EN_bit
+ | RDMA_EN_bit
+ | XDMA_EN_bit ;
+ retval = ftmac100_ringbuf_alloc(dev,priv);
+ if (retval)
+ goto err_out;
+
+ /* now, reset the chip, and put it into a known state */
+ retval = ftmac100_reset( dev );
+ if (retval) {
+ printk( "%s: unable to reset.\n", dev->name );
+ goto err_out;
+ }
+
+ /* Fill in the fields of the device structure with ethernet values. */
+ ether_setup(dev);
+
+ /* Grab the IRQ */
+ retval = request_irq(dev->irq, &ftmac100_interrupt, IRQF_DISABLED, dev->name, dev);
+ if (retval) {
+ printk("%s: unable to get IRQ %d (irqval=%d).\n", dev->name, dev->irq, retval);
+ goto err_out;
+ }
+
+#if 0
+ if ((proc_ftmac100 = create_proc_entry( "ftmac100", 0, 0 ))) {
+ proc_ftmac100->read_proc = ftmac100_read_proc;
+ proc_ftmac100->data = dev;
+ proc_ftmac100->owner = THIS_MODULE;
+ }
+#endif
-static void ftmac100_rx_pointer_advance(struct ftmac100 *priv)
-{
- priv->rx_pointer = ftmac100_next_rx_pointer(priv->rx_pointer);
-}
+ return 0;
-static struct ftmac100_rxdes *ftmac100_current_rxdes(struct ftmac100 *priv)
-{
- return &priv->descs->rxdes[priv->rx_pointer];
+err_out:
+ dma_free_coherent( NULL, sizeof(RX_DESC)*RXDES_NUM, (void*)priv->rx_descs, (dma_addr_t)priv->rx_descs_dma );
+ dma_free_coherent( NULL, RX_BUF_SIZE*RXDES_NUM, (void*)priv->rx_buf, (dma_addr_t)priv->rx_buf_dma );
+ dma_free_coherent( NULL, sizeof(TX_DESC)*TXDES_NUM, (void*)priv->tx_descs, (dma_addr_t)priv->tx_descs_dma );
+ dma_free_coherent( NULL, TX_BUF_SIZE*TXDES_NUM, (void*)priv->tx_buf, (dma_addr_t)priv->tx_buf_dma );
+ priv->rx_descs = NULL; priv->rx_descs_dma = 0;
+ priv->rx_buf = NULL; priv->rx_buf_dma = 0;
+ priv->tx_descs = NULL; priv->tx_descs_dma = 0;
+ priv->tx_buf = NULL; priv->tx_buf_dma = 0;
+ return retval;
}
-static struct ftmac100_rxdes *
-ftmac100_rx_locate_first_segment(struct ftmac100 *priv)
-{
- struct ftmac100_rxdes *rxdes = ftmac100_current_rxdes(priv);
- while (!ftmac100_rxdes_owned_by_dma(rxdes)) {
- if (ftmac100_rxdes_first_segment(rxdes))
- return rxdes;
+#if FTMAC100_DEBUG > 2
+static void print_packet( unsigned char * buf, int length )
+{
+#if FTMAC100_DEBUG > 3
+ int i;
+ int remainder;
+ int lines;
+#endif
- ftmac100_rxdes_set_dma_own(rxdes);
- ftmac100_rx_pointer_advance(priv);
- rxdes = ftmac100_current_rxdes(priv);
- }
+// printk("Packet of length %d \n", length );
- return NULL;
+#if FTMAC100_DEBUG > 3
+ lines = length >> 4;
+ remainder = length & 15;
+
+ for ( i = 0; i < lines ; i ++ ) {
+ int cur;
+ for ( cur = 0; cur < 8; cur ++ ) {
+ unsigned char a, b;
+ a = *(buf ++ );
+ b = *(buf ++ );
+ printk("%02x%02x ", a, b );
+ }
+ printk("\n");
+ }
+ for ( i = 0; i < remainder/2 ; i++ ) {
+ unsigned char a, b;
+
+ a = *(buf ++ );
+ b = *(buf ++ );
+ printk("%02x%02x ", a, b );
+ }
+ printk("\n");
+#endif
}
+#endif
-static bool ftmac100_rx_packet_error(struct ftmac100 *priv,
- struct ftmac100_rxdes *rxdes)
-{
- struct net_device *netdev = priv->netdev;
- bool error = false;
-
- if (unlikely(ftmac100_rxdes_rx_error(rxdes))) {
- if (net_ratelimit())
- netdev_info(netdev, "rx err\n");
-
- netdev->stats.rx_errors++;
- error = true;
- }
-
- if (unlikely(ftmac100_rxdes_crc_error(rxdes))) {
- if (net_ratelimit())
- netdev_info(netdev, "rx crc err\n");
-
- netdev->stats.rx_crc_errors++;
- error = true;
- }
-
- if (unlikely(ftmac100_rxdes_frame_too_long(rxdes))) {
- if (net_ratelimit())
- netdev_info(netdev, "rx frame too long\n");
-
- netdev->stats.rx_length_errors++;
- error = true;
- } else if (unlikely(ftmac100_rxdes_runt(rxdes))) {
- if (net_ratelimit())
- netdev_info(netdev, "rx runt\n");
-
- netdev->stats.rx_length_errors++;
- error = true;
- } else if (unlikely(ftmac100_rxdes_odd_nibble(rxdes))) {
- if (net_ratelimit())
- netdev_info(netdev, "rx odd nibble\n");
-
- netdev->stats.rx_length_errors++;
- error = true;
- }
-
- return error;
-}
-static void ftmac100_rx_drop_packet(struct ftmac100 *priv)
+/*
+ * Open and Initialize the board
+ *
+ * Set up everything, reset the card, etc ..
+ *
+ */
+static int ftmac100_open(struct net_device *dev)
{
- struct net_device *netdev = priv->netdev;
- struct ftmac100_rxdes *rxdes = ftmac100_current_rxdes(priv);
- bool done = false;
-
- if (net_ratelimit())
- netdev_dbg(netdev, "drop packet %p\n", rxdes);
+ int retval = 0;
+ PRINTK("+%s:ftmac100_open\n", dev->name);
- do {
- if (ftmac100_rxdes_last_segment(rxdes))
- done = true;
+ //netif_start_queue(dev);
- ftmac100_rxdes_set_dma_own(rxdes);
- ftmac100_rx_pointer_advance(priv);
- rxdes = ftmac100_current_rxdes(priv);
- } while (!done && !ftmac100_rxdes_owned_by_dma(rxdes));
-
- netdev->stats.rx_dropped++;
+ /* reset the hardware */
+ ftmac100_reset( dev );
+ retval = ftmac100_reset( dev );
+ if (retval) {
+ printk( "%s: unable to reset.\n", dev->name );
+ retval = -ENODEV;
+ } else {
+ ftmac100_enable( dev );
+
+ /* Configure the PHY */
+ ftmac100_phy_configure(dev);
+
+ netif_start_queue(dev);
+
+ PRINTK("+%s:ftmac100_open DONE\n", dev->name);
+ }
+
+ return retval;
}
-static bool ftmac100_rx_packet(struct ftmac100 *priv, int *processed)
-{
- struct net_device *netdev = priv->netdev;
- struct ftmac100_rxdes *rxdes;
- struct sk_buff *skb;
- struct page *page;
- dma_addr_t map;
- int length;
- rxdes = ftmac100_rx_locate_first_segment(priv);
- if (!rxdes)
- return false;
-
- if (unlikely(ftmac100_rx_packet_error(priv, rxdes))) {
- ftmac100_rx_drop_packet(priv);
- return true;
- }
-
- /*
- * It is impossible to get multi-segment packets
- * because we always provide big enough receive buffers.
- */
- if (unlikely(!ftmac100_rxdes_last_segment(rxdes)))
- BUG();
-
- /* start processing */
- skb = netdev_alloc_skb_ip_align(netdev, 128);
- if (unlikely(!skb)) {
- if (net_ratelimit())
- netdev_err(netdev, "rx skb alloc failed\n");
-
- ftmac100_rx_drop_packet(priv);
- return true;
- }
-
- if (unlikely(ftmac100_rxdes_multicast(rxdes)))
- netdev->stats.multicast++;
-
- map = ftmac100_rxdes_get_dma_addr(rxdes);
- dma_unmap_page(priv->dev, map, RX_BUF_SIZE, DMA_FROM_DEVICE);
-
- length = ftmac100_rxdes_frame_length(rxdes);
- page = ftmac100_rxdes_get_page(rxdes);
- skb_fill_page_desc(skb, 0, page, 0, length);
- skb->len += length;
- skb->data_len += length;
-
- /* page might be freed in __pskb_pull_tail() */
- if (length > 64)
- skb->truesize += PAGE_SIZE;
- __pskb_pull_tail(skb, min(length, 64));
-
- ftmac100_alloc_rx_page(priv, rxdes, GFP_ATOMIC);
-
- ftmac100_rx_pointer_advance(priv);
-
- skb->protocol = eth_type_trans(skb, netdev);
-
- netdev->stats.rx_packets++;
- netdev->stats.rx_bytes += skb->len;
+/*
+ * Called by the kernel to send a packet out into the void
+ * of the net. This routine is largely based on
+ * skeleton.c, from Becker.
+ *
+ */
+static void ftmac100_timeout (struct net_device *dev)
+{
+ /* If we get here, some higher level has decided we are broken.
+ There should really be a "kick me" function call instead. */
+ printk(KERN_WARNING "%s: transmit timed out?\n",dev->name);
- /* push packet to protocol stack */
- netif_receive_skb(skb);
+ //printk("+ftmac100_timeout\n");
- (*processed)++;
- return true;
+ ftmac100_reset( dev );
+ ftmac100_enable( dev );
+ ftmac100_phy_configure(dev);
+ netif_wake_queue(dev);
+ dev->trans_start = jiffies;
}
-/******************************************************************************
- * internal functions (transmit descriptor)
- *****************************************************************************/
-static void ftmac100_txdes_reset(struct ftmac100_txdes *txdes)
+#if ZERO_COPY
+/*
+ * Free transmitted skb buffer when it's safe.
+ */
+static void ftmac100_free_tx (struct net_device *dev, int irq)
{
- /* clear all except end of ring bit */
- txdes->txdes0 = 0;
- txdes->txdes1 &= cpu_to_le32(FTMAC100_TXDES1_EDOTR);
- txdes->txdes2 = 0;
- txdes->txdes3 = 0;
-}
+ struct ftmac100_local *priv = (struct ftmac100_local *)netdev_priv(dev);
+ //volatile TX_DESC *cur_desc;
+ int entry = priv->old_tx & (TXDES_NUM-1);
+
+ //enter spinlock
+ if (!irq)
+ spin_lock(&priv->lock);
+
+ /* Free used tx skbuffs */
+ while (entry != priv->tx_idx) {
+ struct sk_buff *skb;
+
+ skb = priv->tx_skbuff[entry];
+ if(skb) {
+ dev_kfree_skb_any (skb);
+ priv->tx_skbuff[entry] = 0;
+ }
-static bool ftmac100_txdes_owned_by_dma(struct ftmac100_txdes *txdes)
-{
- return txdes->txdes0 & cpu_to_le32(FTMAC100_TXDES0_TXDMA_OWN);
-}
+ entry = (entry + 1) & (TXDES_NUM-1);
+ }
-static void ftmac100_txdes_set_dma_own(struct ftmac100_txdes *txdes)
-{
- /*
- * Make sure dma own bit will not be set before any other
- * descriptor fields.
- */
- wmb();
- txdes->txdes0 |= cpu_to_le32(FTMAC100_TXDES0_TXDMA_OWN);
-}
+ if (!irq)
+ spin_unlock(&priv->lock);
+ //exit spinloc
-static bool ftmac100_txdes_excessive_collision(struct ftmac100_txdes *txdes)
-{
- return txdes->txdes0 & cpu_to_le32(FTMAC100_TXDES0_TXPKT_EXSCOL);
+ priv->old_tx = entry;
+ netif_wake_queue (dev);
}
+#endif
-static bool ftmac100_txdes_late_collision(struct ftmac100_txdes *txdes)
-{
- return txdes->txdes0 & cpu_to_le32(FTMAC100_TXDES0_TXPKT_LATECOL);
-}
+/*
+ .
+ . This is the main routine of the driver, to handle the net_device when
+ . it needs some attention.
+ .
+ . So:
+ . first, save state of the chipset
+ . branch off into routines to handle each case, and acknowledge
+ . each to the interrupt register
+ . and finally restore state.
+ .
+ */
-static void ftmac100_txdes_set_end_of_ring(struct ftmac100_txdes *txdes)
-{
- txdes->txdes1 |= cpu_to_le32(FTMAC100_TXDES1_EDOTR);
-}
+#if FTMAC100_DEBUG > 2
-static void ftmac100_txdes_set_first_segment(struct ftmac100_txdes *txdes)
+static void dump_intc(void)
{
- txdes->txdes1 |= cpu_to_le32(FTMAC100_TXDES1_FTS);
+ printk( " INTC[0] IRQSRC=%08X,MASK=%08X,MOD=%08X,LEV=%08X,STAT=%08X\n",
+ *((volatile unsigned*)(INTC_FTINTC010_VA_BASE+0)),
+ *((volatile unsigned*)(INTC_FTINTC010_VA_BASE+0x4)),
+ *((volatile unsigned*)(INTC_FTINTC010_VA_BASE+0xc)),
+ *((volatile unsigned*)(INTC_FTINTC010_VA_BASE+0x10)),
+ *((volatile unsigned*)(INTC_FTINTC010_VA_BASE+0x14)) );
+ printk( " INTC[1] IRQSRC=%08X,MASK=%08X,MOD=%08X,LEV=%08X,STAT=%08X\n",
+ *((volatile unsigned*)(INTC_FTINTC010_1_VA_BASE+0)),
+ *((volatile unsigned*)(INTC_FTINTC010_1_VA_BASE+0x4)),
+ *((volatile unsigned*)(INTC_FTINTC010_1_VA_BASE+0xc)),
+ *((volatile unsigned*)(INTC_FTINTC010_1_VA_BASE+0x10)),
+ *((volatile unsigned*)(INTC_FTINTC010_1_VA_BASE+0x14)) );
}
+#else
+#define dump_intc()
+#endif
-static void ftmac100_txdes_set_last_segment(struct ftmac100_txdes *txdes)
+#if FTMAC100_DEBUG > 2
+static void show_intstatus(unsigned char status)
{
- txdes->txdes1 |= cpu_to_le32(FTMAC100_TXDES1_LTS);
+ static int count = 0;
+ if (status & PHYSTS_CHG_bit)
+ printk( "[%d]%s ", count, "PHYSTS_CHG" );
+ if (status & AHB_ERR_bit)
+ printk( "[%d]%s ", count, "AHB_ERR" );
+ if (status & RPKT_LOST_bit)
+ printk( "[%d]%s ", count, "RPKT_LOST" );
+ if (status & RPKT_SAV_bit)
+ printk( "[%d]%s ", count, "RPKT_SAV" );
+ if (status & XPKT_LOST_bit)
+ printk( "[%d]%s ", count, "XPKT_LOST" );
+ if (status & XPKT_OK_bit)
+ printk( "[%d]%s ", count, "XPKT_OK" );
+ if (status & NOTXBUF_bit)
+ printk( "[%d]%s ", count, "NOTXBUF" );
+ if (status & XPKT_FINISH_bit)
+ printk( "[%d]%s ", count, "XPKT_FINISH" );
+ if (status & NORXBUF_bit)
+ printk( "[%d]%s ", count, "NORXBUF" );
+ if (status & RPKT_FINISH_bit)
+ printk( "[%d]%s ", count, "RPKT_FINISH" );
+ if (status & ~(PHYSTS_CHG_bit | AHB_ERR_bit | RPKT_LOST_bit | RPKT_SAV_bit
+ | XPKT_LOST_bit | XPKT_OK_bit | NOTXBUF_bit | XPKT_FINISH_bit
+ | NORXBUF_bit | RPKT_FINISH_bit))
+ printk( "[%d]%s ", count, "<Unknown>" );
+ count++;
}
+#else
+#define show_intstatus(x)
+#endif
+
-static void ftmac100_txdes_set_txint(struct ftmac100_txdes *txdes)
+/*
+ * The interrupt handler
+ */
+static irqreturn_t ftmac100_interrupt(int irq, void * dev_id)
{
- txdes->txdes1 |= cpu_to_le32(FTMAC100_TXDES1_TXIC);
-}
+ struct net_device *dev = dev_id;
+ unsigned int ioaddr = dev->base_addr;
+ unsigned status; // interrupt status
+ unsigned char mask; // interrupt mask
+ struct ftmac100_local *priv = (struct ftmac100_local *)netdev_priv(dev);
+ unsigned long flags;
+
+ spin_lock_irqsave(&priv->lock,flags); // Luke 08/18/2005 ins
+ PRINTK(KERN_INFO "+ftmac100_interrupt\n");
+ dump_intc();
+
+ if (dev == NULL||priv == NULL) {
+ printk(KERN_WARNING "%s: irq %d for unknown device.\n", "ftmac100_interrupt", irq);
+ return IRQ_HANDLED;
+ }
+
+ /* read the interrupt status register */
+ mask = inl( ioaddr + IMR_REG );
+
+ /* read the status flag, and mask it */
+ status = inl( ioaddr + ISR_REG ) & mask;
+
+ show_intstatus(status);
+
+ if ( status & RPKT_FINISH_bit )
+ ftmac100_rcv(dev);
+
+ if (status & NORXBUF_bit) {
+ //printk("<0x%x:NORXBUF>",status);
+ outl( mask & ~NORXBUF_bit, ioaddr + IMR_REG);
+ trans_busy = 1;
+
+#if ENABLE_BOTTOM_HALF
+ priv->rcv_tq.sync = 0;
+ priv->rcv_tq.routine=ftmac100_rcv;
+ priv->rcv_tq.data = dev;
+ queue_task(&priv->rcv_tq, &tq_timer);
+ //queue_task(&priv->rcv_tq, &tq_immediate);
+#else
+ ftmac100_rcv( dev );
+#endif
+ }
+
+ if (status & AHB_ERR_bit)
+ printk("<0x%x:AHB_ERR>",status);
+
+ if (status & XPKT_FINISH_bit)
+ printk( "[XPKT_FINISH]" );
+
+ /*
+ if (status & PHYSTS_CHG_bit) {
+ }
+ */
+ if (status & XPKT_OK_bit) {
+#if ZERO_COPY
+ ftmac100_free_tx(dev,1);
+#endif
+ }
+ /*
+ if (status & NOTXBUF_bit) {
+ }
+ */
+
+ if (status & RPKT_LOST_bit)
+ priv->stats.rx_errors++;
+
+ if (status & XPKT_LOST_bit) {
+#if ZERO_COPY
+ ftmac100_free_tx(dev,1);
+#endif
+ priv->stats.tx_errors++;
+ }
+
+ PRINTK(KERN_INFO "+ftmac100_interrupt DONE\n");
+ dump_intc();
+ PRINTK(KERN_INFO "\n");
+ spin_unlock_irqrestore(&priv->lock,flags); // Luke 08/18/2005 ins
-static void ftmac100_txdes_set_buffer_size(struct ftmac100_txdes *txdes,
- unsigned int len)
-{
- txdes->txdes1 |= cpu_to_le32(FTMAC100_TXDES1_TXBUF_SIZE(len));
+ return IRQ_HANDLED;
}
-static void ftmac100_txdes_set_dma_addr(struct ftmac100_txdes *txdes,
- dma_addr_t addr)
-{
- txdes->txdes2 = cpu_to_le32(addr);
-}
-static dma_addr_t ftmac100_txdes_get_dma_addr(struct ftmac100_txdes *txdes)
-{
- return le32_to_cpu(txdes->txdes2);
-}
/*
- * txdes3 is not used by hardware. We use it to keep track of socket buffer.
- * Since hardware does not touch it, we can skip cpu_to_le32()/le32_to_cpu().
+ . ftmac100_rcv - receive a packet from the card
+ .
+ . There is ( at least ) a packet waiting to be read from
+ . chip-memory.
+ .
+ . o Read the status
+ . o If an error, record it
+ . o otherwise, read in the packet
*/
-static void ftmac100_txdes_set_skb(struct ftmac100_txdes *txdes, struct sk_buff *skb)
-{
- txdes->txdes3 = (unsigned int)skb;
-}
-static struct sk_buff *ftmac100_txdes_get_skb(struct ftmac100_txdes *txdes)
+static void ftmac100_rcv(void *devp)
{
- return (struct sk_buff *)txdes->txdes3;
+ struct net_device *dev=(struct net_device *)devp;
+ struct ftmac100_local *priv = (struct ftmac100_local *)netdev_priv(dev);
+ unsigned int ioaddr=dev->base_addr;
+ int packet_length;
+ int rcv_cnt;
+ volatile RX_DESC *cur_desc;
+ int cpy_length;
+ int cur_idx;
+ int seg_length;
+ int have_package;
+ int have_frs;
+ int start_idx;
+
+ struct sk_buff * skb;
+ unsigned char * data;
+
+ PRINTK("+ ftmac100_rcv\n");
+
+ start_idx = priv->rx_idx;
+
+ for (rcv_cnt=0; rcv_cnt<8 ; ++rcv_cnt) {
+ packet_length = 0;
+ cur_idx = priv->rx_idx;
+
+ have_package = 0;
+ have_frs = 0;
+ for (; (cur_desc = &priv->rx_descs[priv->rx_idx])->RXDMA_OWN==0; ) {
+ have_package = 1;
+ priv->rx_idx = (priv->rx_idx+1) & (RXDES_NUM-1);
+ if (cur_desc->FRS) {
+ have_frs = 1;
+ if (cur_desc->RX_ERR || cur_desc->CRC_ERR || cur_desc->FTL
+ || cur_desc->RUNT || cur_desc->RX_ODD_NB) {
+ priv->stats.rx_errors++; // error frame....
+ break;
+ }
+ if (cur_desc->MULTICAST)
+ priv->stats.multicast++;
+ packet_length = cur_desc->ReceiveFrameLength; // normal frame
+ }
+ if ( cur_desc->LRS ) // packet's last frame
+ break;
+ }
+ if (have_package==0)
+ goto done;
+ if (have_frs == 0)
+ priv->stats.rx_over_errors++;
+
+ if (packet_length>0) {
+ // Allocate enough memory for entire receive frame, to be safe
+ skb = dev_alloc_skb( packet_length + 2 );
+
+ if ( skb == NULL ) {
+ printk(KERN_NOTICE "%s: Low memory, packet dropped.\n", dev->name);
+ priv->stats.rx_dropped++;
+ goto done;
+ }
+
+ skb_reserve( skb, 2 ); /* 16 bit alignment */
+ skb->dev = dev;
+
+ data = skb_put( skb, packet_length );
+ cpy_length = 0;
+ for (; cur_idx!=priv->rx_idx; cur_idx = (cur_idx+1) & (RXDES_NUM-1)) {
+ seg_length = min(packet_length - cpy_length, RX_BUF_SIZE);
+ memcpy(data+cpy_length, (char *)priv->rx_descs[cur_idx].VIR_RXBUF_BADR, seg_length);
+ cpy_length += seg_length;
+ }
+
+ skb->protocol = eth_type_trans(skb, dev);
+ netif_rx(skb);
+ dev->last_rx = jiffies;
+ priv->stats.rx_packets++;
+ priv->stats.rx_bytes += skb->len;
+ }
+ }
+
+done:
+ if (start_idx != priv->rx_idx) {
+ for (cur_idx = (start_idx+1)%RXDES_NUM; cur_idx != priv->rx_idx; cur_idx = (cur_idx+1)%RXDES_NUM) {
+ priv->rx_descs[cur_idx].RXDMA_OWN = 1;
+ }
+ priv->rx_descs[start_idx].RXDMA_OWN = 1;
+ }
+ if (trans_busy == 1) {
+ outl( priv->maccr_val, ioaddr + MACCR_REG );
+ outl( inl(ioaddr + IMR_REG) | NORXBUF_bit, ioaddr + IMR_REG);
+ }
+
+ PRINTK("+ ftmac100_rcv DONE\n");
+
+ return;
}
-/******************************************************************************
- * internal functions (transmit)
- *****************************************************************************/
-static int ftmac100_next_tx_pointer(int pointer)
+/*
+ . ftmac100_close
+ .
+ . this makes the board clean up everything that it can
+ . and not talk to the outside world. Caused by
+ . an 'ifconfig ethX down'
+ .
+ */
+static int ftmac100_close(struct net_device *dev)
{
- return (pointer + 1) & (TX_QUEUE_ENTRIES - 1);
-}
+ //printk("+ftmac100_close\n");
-static void ftmac100_tx_pointer_advance(struct ftmac100 *priv)
-{
- priv->tx_pointer = ftmac100_next_tx_pointer(priv->tx_pointer);
+ netif_stop_queue(dev);
+
+ ftmac100_shutdown( dev->base_addr );
+#if ZERO_COPY
+ ftmac100_free_tx(dev,0);
+#endif
+ return 0;
}
-static void ftmac100_tx_clean_pointer_advance(struct ftmac100 *priv)
+/*
+ . Get the current statistics.
+ . This may be called with the card open or closed.
+ */
+static struct net_device_stats* ftmac100_query_statistics(struct net_device *dev)
{
- priv->tx_clean_pointer = ftmac100_next_tx_pointer(priv->tx_clean_pointer);
-}
+ struct ftmac100_local *priv = (struct ftmac100_local *)netdev_priv(dev);
-static struct ftmac100_txdes *ftmac100_current_txdes(struct ftmac100 *priv)
-{
- return &priv->descs->txdes[priv->tx_pointer];
-}
+ PRINTK("+ftmac100_query_statistics\n");
-static struct ftmac100_txdes *ftmac100_current_clean_txdes(struct ftmac100 *priv)
-{
- return &priv->descs->txdes[priv->tx_clean_pointer];
+ return &priv->stats;
}
-static bool ftmac100_tx_complete_packet(struct ftmac100 *priv)
-{
- struct net_device *netdev = priv->netdev;
- struct ftmac100_txdes *txdes;
- struct sk_buff *skb;
- dma_addr_t map;
-
- if (priv->tx_pending == 0)
- return false;
- txdes = ftmac100_current_clean_txdes(priv);
-
- if (ftmac100_txdes_owned_by_dma(txdes))
- return false;
-
- skb = ftmac100_txdes_get_skb(txdes);
- map = ftmac100_txdes_get_dma_addr(txdes);
-
- if (unlikely(ftmac100_txdes_excessive_collision(txdes) ||
- ftmac100_txdes_late_collision(txdes))) {
- /*
- * packet transmitted to ethernet lost due to late collision
- * or excessive collision
- */
- netdev->stats.tx_aborted_errors++;
- } else {
- netdev->stats.tx_packets++;
- netdev->stats.tx_bytes += skb->len;
- }
+#ifdef HAVE_MULTICAST
- dma_unmap_single(priv->dev, map, skb_headlen(skb), DMA_TO_DEVICE);
- dev_kfree_skb(skb);
-
- ftmac100_txdes_reset(txdes);
-
- ftmac100_tx_clean_pointer_advance(priv);
-
- spin_lock(&priv->tx_lock);
- priv->tx_pending--;
- spin_unlock(&priv->tx_lock);
- netif_wake_queue(netdev);
-
- return true;
-}
+/*
+ . Function: ftmac100_setmulticast( unsigned int ioaddr, int count, dev_mc_list * adds )
+ . Purpose:
+ . This sets the internal hardware table to filter out unwanted multicast
+ . packets before they take up memory.
+ */
-static void ftmac100_tx_complete(struct ftmac100 *priv)
+static void ftmac100_setmulticast( unsigned int ioaddr, int count, struct dev_mc_list * addrs )
{
- while (ftmac100_tx_complete_packet(priv))
- ;
+ struct dev_mc_list * cur_addr;
+ int crc_val;
+
+ //printk("+ftmac100_setmulticast\n");
+
+ for (cur_addr = addrs ; cur_addr!=NULL ; cur_addr = cur_addr->next ) {
+ if ( !( *cur_addr->dmi_addr & 1 ) )
+ continue;
+ crc_val = crc32( cur_addr->dmi_addr, 6 );
+ crc_val = (crc_val>>26)&0x3f; // ¨ú MSB 6 bit
+ if (crc_val >= 32)
+ outl(inl(ioaddr+MAHT1_REG) | (1UL<<(crc_val-32)), ioaddr+MAHT1_REG);
+ else
+ outl(inl(ioaddr+MAHT0_REG) | (1UL<<crc_val), ioaddr+MAHT0_REG);
+ }
}
-static int ftmac100_xmit(struct ftmac100 *priv, struct sk_buff *skb,
- dma_addr_t map)
-{
- struct net_device *netdev = priv->netdev;
- struct ftmac100_txdes *txdes;
- unsigned int len = (skb->len < ETH_ZLEN) ? ETH_ZLEN : skb->len;
-
- txdes = ftmac100_current_txdes(priv);
- ftmac100_tx_pointer_advance(priv);
-
- /* setup TX descriptor */
- ftmac100_txdes_set_skb(txdes, skb);
- ftmac100_txdes_set_dma_addr(txdes, map);
-
- ftmac100_txdes_set_first_segment(txdes);
- ftmac100_txdes_set_last_segment(txdes);
- ftmac100_txdes_set_txint(txdes);
- ftmac100_txdes_set_buffer_size(txdes, len);
- spin_lock(&priv->tx_lock);
- priv->tx_pending++;
- if (priv->tx_pending == TX_QUEUE_ENTRIES)
- netif_stop_queue(netdev);
-
- /* start transmit */
- ftmac100_txdes_set_dma_own(txdes);
- spin_unlock(&priv->tx_lock);
+/*
+ . ftmac100_set_multicast_list
+ .
+ . This routine will, depending on the values passed to it,
+ . either make it accept multicast packets, go into
+ . promiscuous mode ( for TCPDUMP and cousins ) or accept
+ . a select set of multicast packets
+*/
+static void ftmac100_set_multicast_list(struct net_device *dev)
+{
+ unsigned int ioaddr = dev->base_addr;
+ struct ftmac100_local *priv = (struct ftmac100_local *)netdev_priv(dev);
+
+ //printk("+ftmac100_set_multicast_list\n");
+
+ if (dev->flags & IFF_PROMISC)
+ priv->maccr_val |= RCV_ALL_bit;
+ else
+ priv->maccr_val &= ~RCV_ALL_bit;
+
+ if ( !(dev->flags & IFF_ALLMULTI) )
+ priv->maccr_val |= RX_MULTIPKT_bit;
+ else
+ priv->maccr_val &= ~RX_MULTIPKT_bit;
+
+ if (dev->mc_count) {
+ priv->maccr_val |= HT_MULTI_EN_bit;
+ ftmac100_setmulticast( ioaddr, dev->mc_count, dev->mc_list );
+ }
+ else
+ priv->maccr_val &= ~HT_MULTI_EN_bit;
- ftmac100_txdma_start_polling(priv);
- return NETDEV_TX_OK;
+ outl( priv->maccr_val, ioaddr + MACCR_REG );
}
+#endif
-/******************************************************************************
- * internal functions (buffer)
- *****************************************************************************/
-static int ftmac100_alloc_rx_page(struct ftmac100 *priv,
- struct ftmac100_rxdes *rxdes, gfp_t gfp)
-{
- struct net_device *netdev = priv->netdev;
- struct page *page;
- dma_addr_t map;
-
- page = alloc_page(gfp);
- if (!page) {
- if (net_ratelimit())
- netdev_err(netdev, "failed to allocate rx page\n");
- return -ENOMEM;
- }
-
- map = dma_map_page(priv->dev, page, 0, RX_BUF_SIZE, DMA_FROM_DEVICE);
- if (unlikely(dma_mapping_error(priv->dev, map))) {
- if (net_ratelimit())
- netdev_err(netdev, "failed to map rx page\n");
- __free_page(page);
- return -ENOMEM;
- }
-
- ftmac100_rxdes_set_page(rxdes, page);
- ftmac100_rxdes_set_dma_addr(rxdes, map);
- ftmac100_rxdes_set_buffer_size(rxdes, RX_BUF_SIZE);
- ftmac100_rxdes_set_dma_own(rxdes);
- return 0;
-}
+/*
+ * Module initialization function
+ */
-static void ftmac100_free_buffers(struct ftmac100 *priv)
+static int ftmac100_probe(struct platform_device *pdev)
{
- int i;
+ int result,thisresult;
+ struct net_device *dev;
+ struct resource *iores;
- for (i = 0; i < RX_QUEUE_ENTRIES; i++) {
- struct ftmac100_rxdes *rxdes = &priv->descs->rxdes[i];
- struct page *page = ftmac100_rxdes_get_page(rxdes);
- dma_addr_t map = ftmac100_rxdes_get_dma_addr(rxdes);
+ PRINTK("+init_module\n");
- if (!page)
- continue;
+ result = -ENODEV;
- dma_unmap_page(priv->dev, map, RX_BUF_SIZE, DMA_FROM_DEVICE);
- __free_page(page);
+ dev = alloc_etherdev(sizeof(struct ftmac100_local));
+ if (!dev) {
+ printk(KERN_ERR "Fail allocating ethernet device");
+ return -ENODEV;
}
-
- for (i = 0; i < TX_QUEUE_ENTRIES; i++) {
- struct ftmac100_txdes *txdes = &priv->descs->txdes[i];
- struct sk_buff *skb = ftmac100_txdes_get_skb(txdes);
- dma_addr_t map = ftmac100_txdes_get_dma_addr(txdes);
-
- if (!skb)
- continue;
-
- dma_unmap_single(priv->dev, map, skb_headlen(skb), DMA_TO_DEVICE);
- dev_kfree_skb(skb);
+ iores = platform_get_resource(pdev, IORESOURCE_IO, 0);
+ /* Copy the parameters from the platform specification */
+ dev->base_addr = iores->start;
+ dev->irq = platform_get_irq(pdev, 0);
+ dev->netdev_ops = &ftmac100_ops;
+
+ //dev->dma = nowait; // Use DMA field for nowait
+ /* Setup initial mac address */
+ auto_get_mac(pdev->id,dev->dev_addr);
+
+ if ((thisresult = register_netdev(dev)) != 0) {
+ free_irq( dev->irq, dev );
+ free_netdev(dev);
+ } else {
+ platform_set_drvdata(pdev, dev);
}
+ if (thisresult == 0) // any of the devices initialized, run
+ result = 0;
- dma_free_coherent(priv->dev, sizeof(struct ftmac100_descs),
- priv->descs, priv->descs_dma_addr);
+ return result;
}
-static int ftmac100_alloc_buffers(struct ftmac100 *priv)
-{
- int i;
-
- priv->descs = dma_alloc_coherent(priv->dev, sizeof(struct ftmac100_descs),
- &priv->descs_dma_addr, GFP_KERNEL);
- if (!priv->descs)
- return -ENOMEM;
-
- memset(priv->descs, 0, sizeof(struct ftmac100_descs));
-
- /* initialize RX ring */
- ftmac100_rxdes_set_end_of_ring(&priv->descs->rxdes[RX_QUEUE_ENTRIES - 1]);
-
- for (i = 0; i < RX_QUEUE_ENTRIES; i++) {
- struct ftmac100_rxdes *rxdes = &priv->descs->rxdes[i];
-
- if (ftmac100_alloc_rx_page(priv, rxdes, GFP_KERNEL))
- goto err;
- }
-
- /* initialize TX ring */
- ftmac100_txdes_set_end_of_ring(&priv->descs->txdes[TX_QUEUE_ENTRIES - 1]);
- return 0;
-
-err:
- ftmac100_free_buffers(priv);
- return -ENOMEM;
-}
-/******************************************************************************
- * struct mii_if_info functions
- *****************************************************************************/
-static int ftmac100_mdio_read(struct net_device *netdev, int phy_id, int reg)
+/*
+ * Cleanup when module is removed with rmmod
+ */
+
+static int ftmac100_remove(struct platform_device *pdev)
{
- struct ftmac100 *priv = netdev_priv(netdev);
- unsigned int phycr;
- int i;
-
- phycr = FTMAC100_PHYCR_PHYAD(phy_id) |
- FTMAC100_PHYCR_REGAD(reg) |
- FTMAC100_PHYCR_MIIRD;
-
- iowrite32(phycr, priv->base + FTMAC100_OFFSET_PHYCR);
-
- for (i = 0; i < 10; i++) {
- phycr = ioread32(priv->base + FTMAC100_OFFSET_PHYCR);
-
- if ((phycr & FTMAC100_PHYCR_MIIRD) == 0)
- return phycr & FTMAC100_PHYCR_MIIRDATA;
-
- udelay(100);
- }
-
- netdev_err(netdev, "mdio read timed out\n");
+ struct net_device *dev;
+ struct ftmac100_local *priv;
+ PRINTK("+cleanup_module\n");
+
+ dev = platform_get_drvdata(pdev);
+
+ priv = (struct ftmac100_local *)netdev_priv(dev);
+ if (priv->rx_descs)
+ dma_free_coherent( NULL, sizeof(RX_DESC)*RXDES_NUM, (void*)priv->rx_descs, (dma_addr_t)priv->rx_descs_dma );
+ if (priv->rx_buf)
+ dma_free_coherent( NULL, RX_BUF_SIZE*RXDES_NUM, (void*)priv->rx_buf, (dma_addr_t)priv->rx_buf_dma );
+ if (priv->tx_descs)
+ dma_free_coherent( NULL, sizeof(TX_DESC)*TXDES_NUM, (void*)priv->tx_descs, (dma_addr_t)priv->tx_descs_dma );
+ if (priv->tx_buf)
+ dma_free_coherent( NULL, TX_BUF_SIZE*TXDES_NUM, (void*)priv->tx_buf, (dma_addr_t)priv->tx_buf_dma );
+ priv->rx_descs = NULL; priv->rx_descs_dma = 0;
+ priv->rx_buf = NULL; priv->rx_buf_dma = 0;
+ priv->tx_descs = NULL; priv->tx_descs_dma = 0;
+ priv->tx_buf = NULL; priv->tx_buf_dma = 0;
+
+ /* No need to check MOD_IN_USE, as sys_delete_module() checks. */
+ unregister_netdev(dev);
+
+ free_irq(dev->irq, dev);
+ //TODO: where is the request_region ?
+ //release_region(devFMAC.base_addr, SMC_IO_EXTENT);
+ free_netdev(dev);
return 0;
}
-static void ftmac100_mdio_write(struct net_device *netdev, int phy_id, int reg,
- int data)
-{
- struct ftmac100 *priv = netdev_priv(netdev);
- unsigned int phycr;
- int i;
-
- phycr = FTMAC100_PHYCR_PHYAD(phy_id) |
- FTMAC100_PHYCR_REGAD(reg) |
- FTMAC100_PHYCR_MIIWR;
-
- data = FTMAC100_PHYWDATA_MIIWDATA(data);
-
- iowrite32(data, priv->base + FTMAC100_OFFSET_PHYWDATA);
- iowrite32(phycr, priv->base + FTMAC100_OFFSET_PHYCR);
-
- for (i = 0; i < 10; i++) {
- phycr = ioread32(priv->base + FTMAC100_OFFSET_PHYCR);
-
- if ((phycr & FTMAC100_PHYCR_MIIWR) == 0)
- return;
-
- udelay(100);
- }
-
- netdev_err(netdev, "mdio write timed out\n");
-}
-
-/******************************************************************************
- * struct ethtool_ops functions
- *****************************************************************************/
-static void ftmac100_get_drvinfo(struct net_device *netdev,
- struct ethtool_drvinfo *info)
-{
- strcpy(info->driver, DRV_NAME);
- strcpy(info->version, DRV_VERSION);
- strcpy(info->bus_info, dev_name(&netdev->dev));
-}
-
-static int ftmac100_get_settings(struct net_device *netdev, struct ethtool_cmd *cmd)
-{
- struct ftmac100 *priv = netdev_priv(netdev);
- return mii_ethtool_gset(&priv->mii, cmd);
-}
-
-static int ftmac100_set_settings(struct net_device *netdev, struct ethtool_cmd *cmd)
-{
- struct ftmac100 *priv = netdev_priv(netdev);
- return mii_ethtool_sset(&priv->mii, cmd);
-}
-
-static int ftmac100_nway_reset(struct net_device *netdev)
+static int ftmac100_suspend(struct platform_device *pdev, pm_message_t state)
{
- struct ftmac100 *priv = netdev_priv(netdev);
- return mii_nway_restart(&priv->mii);
-}
-
-static u32 ftmac100_get_link(struct net_device *netdev)
-{
- struct ftmac100 *priv = netdev_priv(netdev);
- return mii_link_ok(&priv->mii);
-}
-
-static const struct ethtool_ops ftmac100_ethtool_ops = {
- .set_settings = ftmac100_set_settings,
- .get_settings = ftmac100_get_settings,
- .get_drvinfo = ftmac100_get_drvinfo,
- .nway_reset = ftmac100_nway_reset,
- .get_link = ftmac100_get_link,
-};
-
-/******************************************************************************
- * interrupt handler
- *****************************************************************************/
-static irqreturn_t ftmac100_interrupt(int irq, void *dev_id)
-{
- struct net_device *netdev = dev_id;
- struct ftmac100 *priv = netdev_priv(netdev);
-
- if (likely(netif_running(netdev))) {
- /* Disable interrupts for polling */
- ftmac100_disable_all_int(priv);
- napi_schedule(&priv->napi);
- }
-
- return IRQ_HANDLED;
-}
-
-/******************************************************************************
- * struct napi_struct functions
- *****************************************************************************/
-static int ftmac100_poll(struct napi_struct *napi, int budget)
-{
- struct ftmac100 *priv = container_of(napi, struct ftmac100, napi);
- struct net_device *netdev = priv->netdev;
- unsigned int status;
- bool completed = true;
- int rx = 0;
-
- status = ioread32(priv->base + FTMAC100_OFFSET_ISR);
-
- if (status & (FTMAC100_INT_RPKT_FINISH | FTMAC100_INT_NORXBUF)) {
- /*
- * FTMAC100_INT_RPKT_FINISH:
- * RX DMA has received packets into RX buffer successfully
- *
- * FTMAC100_INT_NORXBUF:
- * RX buffer unavailable
- */
- bool retry;
-
- do {
- retry = ftmac100_rx_packet(priv, &rx);
- } while (retry && rx < budget);
+ struct net_device *ndev = platform_get_drvdata(pdev);
- if (retry && rx == budget)
- completed = false;
- }
-
- if (status & (FTMAC100_INT_XPKT_OK | FTMAC100_INT_XPKT_LOST)) {
- /*
- * FTMAC100_INT_XPKT_OK:
- * packet transmitted to ethernet successfully
- *
- * FTMAC100_INT_XPKT_LOST:
- * packet transmitted to ethernet lost due to late
- * collision or excessive collision
- */
- ftmac100_tx_complete(priv);
- }
-
- if (status & (FTMAC100_INT_NORXBUF | FTMAC100_INT_RPKT_LOST |
- FTMAC100_INT_AHB_ERR | FTMAC100_INT_PHYSTS_CHG)) {
- if (net_ratelimit())
- netdev_info(netdev, "[ISR] = 0x%x: %s%s%s%s\n", status,
- status & FTMAC100_INT_NORXBUF ? "NORXBUF " : "",
- status & FTMAC100_INT_RPKT_LOST ? "RPKT_LOST " : "",
- status & FTMAC100_INT_AHB_ERR ? "AHB_ERR " : "",
- status & FTMAC100_INT_PHYSTS_CHG ? "PHYSTS_CHG" : "");
-
- if (status & FTMAC100_INT_NORXBUF) {
- /* RX buffer unavailable */
- netdev->stats.rx_over_errors++;
- }
-
- if (status & FTMAC100_INT_RPKT_LOST) {
- /* received packet lost due to RX FIFO full */
- netdev->stats.rx_fifo_errors++;
- }
-
- if (status & FTMAC100_INT_PHYSTS_CHG) {
- /* PHY link status change */
- mii_check_link(&priv->mii);
+ if (ndev) {
+ if (netif_running(ndev)) {
+ netif_device_detach(ndev);
+ ftmac100_shutdown(ndev->base_addr);
}
}
-
- if (completed) {
- /* stop polling */
- napi_complete(napi);
- ftmac100_enable_all_int(priv);
- }
-
- return rx;
-}
-
-/******************************************************************************
- * struct net_device_ops functions
- *****************************************************************************/
-static int ftmac100_open(struct net_device *netdev)
-{
- struct ftmac100 *priv = netdev_priv(netdev);
- int err;
-
- err = ftmac100_alloc_buffers(priv);
- if (err) {
- netdev_err(netdev, "failed to allocate buffers\n");
- goto err_alloc;
- }
-
- err = request_irq(priv->irq, ftmac100_interrupt, 0, netdev->name, netdev);
- if (err) {
- netdev_err(netdev, "failed to request irq %d\n", priv->irq);
- goto err_irq;
- }
-
- priv->rx_pointer = 0;
- priv->tx_clean_pointer = 0;
- priv->tx_pointer = 0;
- priv->tx_pending = 0;
-
- err = ftmac100_start_hw(priv);
- if (err)
- goto err_hw;
-
- napi_enable(&priv->napi);
- netif_start_queue(netdev);
-
- ftmac100_enable_all_int(priv);
-
- return 0;
-
-err_hw:
- free_irq(priv->irq, netdev);
-err_irq:
- ftmac100_free_buffers(priv);
-err_alloc:
- return err;
-}
-
-static int ftmac100_stop(struct net_device *netdev)
-{
- struct ftmac100 *priv = netdev_priv(netdev);
-
- ftmac100_disable_all_int(priv);
- netif_stop_queue(netdev);
- napi_disable(&priv->napi);
- ftmac100_stop_hw(priv);
- free_irq(priv->irq, netdev);
- ftmac100_free_buffers(priv);
-
return 0;
}
-static int ftmac100_hard_start_xmit(struct sk_buff *skb, struct net_device *netdev)
+static int ftmac100_resume(struct platform_device *pdev)
{
- struct ftmac100 *priv = netdev_priv(netdev);
- dma_addr_t map;
-
- if (unlikely(skb->len > MAX_PKT_SIZE)) {
- if (net_ratelimit())
- netdev_dbg(netdev, "tx packet too big\n");
-
- netdev->stats.tx_dropped++;
- dev_kfree_skb(skb);
- return NETDEV_TX_OK;
- }
+ struct net_device *ndev = platform_get_drvdata(pdev);
- map = dma_map_single(priv->dev, skb->data, skb_headlen(skb), DMA_TO_DEVICE);
- if (unlikely(dma_mapping_error(priv->dev, map))) {
- /* drop packet */
- if (net_ratelimit())
- netdev_err(netdev, "map socket buffer failed\n");
-
- netdev->stats.tx_dropped++;
- dev_kfree_skb(skb);
- return NETDEV_TX_OK;
+ if (ndev) {
+ if (netif_running(ndev)) {
+ ftmac100_reset(ndev);
+ ftmac100_enable(ndev);
+ netif_device_attach(ndev);
+ }
}
-
- return ftmac100_xmit(priv, skb, map);
+ return 0;
}
-/* optional */
-static int ftmac100_do_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
-{
- struct ftmac100 *priv = netdev_priv(netdev);
- struct mii_ioctl_data *data = if_mii(ifr);
-
- return generic_mii_ioctl(&priv->mii, data, cmd, NULL);
+static void platform_device_release(struct device *dev){
}
-static const struct net_device_ops ftmac100_netdev_ops = {
- .ndo_open = ftmac100_open,
- .ndo_stop = ftmac100_stop,
- .ndo_start_xmit = ftmac100_hard_start_xmit,
- .ndo_set_mac_address = eth_mac_addr,
- .ndo_validate_addr = eth_validate_addr,
- .ndo_do_ioctl = ftmac100_do_ioctl,
+static struct platform_driver ftmac100_driver = {
+ .probe = ftmac100_probe,
+ .remove = ftmac100_remove,
+ .suspend = ftmac100_suspend,
+ .resume = ftmac100_resume,
+ .driver = {
+ .name = "ftmac100",
+ },
};
-/******************************************************************************
- * struct platform_driver functions
- *****************************************************************************/
-static int ftmac100_probe(struct platform_device *pdev)
-{
- struct resource *res;
- int irq;
- struct net_device *netdev;
- struct ftmac100 *priv;
- int err;
-
- if (!pdev)
- return -ENODEV;
-
- res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
- if (!res)
- return -ENXIO;
-
- irq = platform_get_irq(pdev, 0);
- if (irq < 0)
- return irq;
-
- /* setup net_device */
- netdev = alloc_etherdev(sizeof(*priv));
- if (!netdev) {
- err = -ENOMEM;
- goto err_alloc_etherdev;
- }
-
- SET_NETDEV_DEV(netdev, &pdev->dev);
- SET_ETHTOOL_OPS(netdev, &ftmac100_ethtool_ops);
- netdev->netdev_ops = &ftmac100_netdev_ops;
-
- platform_set_drvdata(pdev, netdev);
-
- /* setup private data */
- priv = netdev_priv(netdev);
- priv->netdev = netdev;
- priv->dev = &pdev->dev;
-
- spin_lock_init(&priv->tx_lock);
-
- /* initialize NAPI */
- netif_napi_add(netdev, &priv->napi, ftmac100_poll, 64);
-
- /* map io memory */
- priv->res = request_mem_region(res->start, resource_size(res),
- dev_name(&pdev->dev));
- if (!priv->res) {
- dev_err(&pdev->dev, "Could not reserve memory region\n");
- err = -ENOMEM;
- goto err_req_mem;
- }
-
- priv->base = ioremap(res->start, resource_size(res));
- if (!priv->base) {
- dev_err(&pdev->dev, "Failed to ioremap ethernet registers\n");
- err = -EIO;
- goto err_ioremap;
- }
-
- priv->irq = irq;
-
- /* initialize struct mii_if_info */
- priv->mii.phy_id = 0;
- priv->mii.phy_id_mask = 0x1f;
- priv->mii.reg_num_mask = 0x1f;
- priv->mii.dev = netdev;
- priv->mii.mdio_read = ftmac100_mdio_read;
- priv->mii.mdio_write = ftmac100_mdio_write;
-
- /* register network device */
- err = register_netdev(netdev);
- if (err) {
- dev_err(&pdev->dev, "Failed to register netdev\n");
- goto err_register_netdev;
- }
-
- netdev_info(netdev, "irq %d, mapped at %p\n", priv->irq, priv->base);
-
- if (!is_valid_ether_addr(netdev->dev_addr)) {
- eth_hw_addr_random(netdev);
- netdev_info(netdev, "generated random MAC address %pM\n",
- netdev->dev_addr);
- }
-
- return 0;
-
-err_register_netdev:
- iounmap(priv->base);
-err_ioremap:
- release_resource(priv->res);
-err_req_mem:
- netif_napi_del(&priv->napi);
- platform_set_drvdata(pdev, NULL);
- free_netdev(netdev);
-err_alloc_etherdev:
- return err;
-}
-
-static int __exit ftmac100_remove(struct platform_device *pdev)
-{
- struct net_device *netdev;
- struct ftmac100 *priv;
-
- netdev = platform_get_drvdata(pdev);
- priv = netdev_priv(netdev);
-
- unregister_netdev(netdev);
-
- iounmap(priv->base);
- release_resource(priv->res);
-
- netif_napi_del(&priv->napi);
- platform_set_drvdata(pdev, NULL);
- free_netdev(netdev);
- return 0;
-}
+static struct resource ftmac100_resources_a320[] = {
+ [0] = {
+ .start = MAC_FTMAC100_0_VA_BASE,
+ .end = MAC_FTMAC100_0_VA_LIMIT,
+ .flags = IORESOURCE_IO,
+ },
+ [1] = {
+ .start = MAC_FTMAC100_0_IRQ,
+ .flags = IORESOURCE_IRQ,
+ },
+};
-static struct platform_driver ftmac100_driver = {
- .probe = ftmac100_probe,
- .remove = __exit_p(ftmac100_remove),
- .driver = {
- .name = DRV_NAME,
- .owner = THIS_MODULE,
+static struct platform_device ftmac100_device_a320 = {
+ .name = "ftmac100",
+ .id = 0,
+ .num_resources = ARRAY_SIZE(ftmac100_resources_a320),
+ .resource = ftmac100_resources_a320,
+ .dev = {
+ .release = platform_device_release,
},
};
-/******************************************************************************
- * initialization / finalization
- *****************************************************************************/
+
static int __init ftmac100_init(void)
{
- pr_info("Loading version " DRV_VERSION " ...\n");
+ platform_device_register(&ftmac100_device_a320);
return platform_driver_register(&ftmac100_driver);
}
static void __exit ftmac100_exit(void)
{
platform_driver_unregister(&ftmac100_driver);
+ platform_device_unregister(&ftmac100_device_a320);
}
module_init(ftmac100_init);
module_exit(ftmac100_exit);
-
-MODULE_AUTHOR("Po-Yu Chuang <ratbert@faraday-tech.com>");
-MODULE_DESCRIPTION("FTMAC100 driver");
-MODULE_LICENSE("GPL");
diff -Nur linux-3.4.113.orig/drivers/net/ethernet/faraday/ftmac100.h linux-3.4.113/drivers/net/ethernet/faraday/ftmac100.h
--- linux-3.4.113.orig/drivers/net/ethernet/faraday/ftmac100.h 2016-10-26 17:15:47.000000000 +0200
+++ linux-3.4.113/drivers/net/ethernet/faraday/ftmac100.h 2016-12-01 20:59:24.388614139 +0100
@@ -1,180 +1,267 @@
/*
- * Faraday FTMAC100 10/100 Ethernet
+ * drivers/net/ftmac100.h
*
- * (C) Copyright 2009-2011 Faraday Technology
- * Po-Yu Chuang <ratbert@faraday-tech.com>
+ * Faraday FTMAC100 Device Driver
*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
+ * Copyright (C) 2005 Faraday Corp. (http://www.faraday-tech.com)
+ *
+ * All Rights Reserved
*
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-
-#ifndef __FTMAC100_H
-#define __FTMAC100_H
-
-#define FTMAC100_OFFSET_ISR 0x00
-#define FTMAC100_OFFSET_IMR 0x04
-#define FTMAC100_OFFSET_MAC_MADR 0x08
-#define FTMAC100_OFFSET_MAC_LADR 0x0c
-#define FTMAC100_OFFSET_MAHT0 0x10
-#define FTMAC100_OFFSET_MAHT1 0x14
-#define FTMAC100_OFFSET_TXPD 0x18
-#define FTMAC100_OFFSET_RXPD 0x1c
-#define FTMAC100_OFFSET_TXR_BADR 0x20
-#define FTMAC100_OFFSET_RXR_BADR 0x24
-#define FTMAC100_OFFSET_ITC 0x28
-#define FTMAC100_OFFSET_APTC 0x2c
-#define FTMAC100_OFFSET_DBLAC 0x30
-#define FTMAC100_OFFSET_MACCR 0x88
-#define FTMAC100_OFFSET_MACSR 0x8c
-#define FTMAC100_OFFSET_PHYCR 0x90
-#define FTMAC100_OFFSET_PHYWDATA 0x94
-#define FTMAC100_OFFSET_FCR 0x98
-#define FTMAC100_OFFSET_BPR 0x9c
-#define FTMAC100_OFFSET_TS 0xc4
-#define FTMAC100_OFFSET_DMAFIFOS 0xc8
-#define FTMAC100_OFFSET_TM 0xcc
-#define FTMAC100_OFFSET_TX_MCOL_SCOL 0xd4
-#define FTMAC100_OFFSET_RPF_AEP 0xd8
-#define FTMAC100_OFFSET_XM_PG 0xdc
-#define FTMAC100_OFFSET_RUNT_TLCC 0xe0
-#define FTMAC100_OFFSET_CRCER_FTL 0xe4
-#define FTMAC100_OFFSET_RLC_RCC 0xe8
-#define FTMAC100_OFFSET_BROC 0xec
-#define FTMAC100_OFFSET_MULCA 0xf0
-#define FTMAC100_OFFSET_RP 0xf4
-#define FTMAC100_OFFSET_XP 0xf8
-
-/*
- * Interrupt status register & interrupt mask register
- */
-#define FTMAC100_INT_RPKT_FINISH (1 << 0)
-#define FTMAC100_INT_NORXBUF (1 << 1)
-#define FTMAC100_INT_XPKT_FINISH (1 << 2)
-#define FTMAC100_INT_NOTXBUF (1 << 3)
-#define FTMAC100_INT_XPKT_OK (1 << 4)
-#define FTMAC100_INT_XPKT_LOST (1 << 5)
-#define FTMAC100_INT_RPKT_SAV (1 << 6)
-#define FTMAC100_INT_RPKT_LOST (1 << 7)
-#define FTMAC100_INT_AHB_ERR (1 << 8)
-#define FTMAC100_INT_PHYSTS_CHG (1 << 9)
-
-/*
- * Interrupt timer control register
*/
-#define FTMAC100_ITC_RXINT_CNT(x) (((x) & 0xf) << 0)
-#define FTMAC100_ITC_RXINT_THR(x) (((x) & 0x7) << 4)
-#define FTMAC100_ITC_RXINT_TIME_SEL (1 << 7)
-#define FTMAC100_ITC_TXINT_CNT(x) (((x) & 0xf) << 8)
-#define FTMAC100_ITC_TXINT_THR(x) (((x) & 0x7) << 12)
-#define FTMAC100_ITC_TXINT_TIME_SEL (1 << 15)
-/*
- * Automatic polling timer control register
- */
-#define FTMAC100_APTC_RXPOLL_CNT(x) (((x) & 0xf) << 0)
-#define FTMAC100_APTC_RXPOLL_TIME_SEL (1 << 4)
-#define FTMAC100_APTC_TXPOLL_CNT(x) (((x) & 0xf) << 8)
-#define FTMAC100_APTC_TXPOLL_TIME_SEL (1 << 12)
+#ifndef _FTMAC100_H_
+#define _FTMAC100_H_
-/*
- * DMA burst length and arbitration control register
- */
-#define FTMAC100_DBLAC_INCR4_EN (1 << 0)
-#define FTMAC100_DBLAC_INCR8_EN (1 << 1)
-#define FTMAC100_DBLAC_INCR16_EN (1 << 2)
-#define FTMAC100_DBLAC_RXFIFO_LTHR(x) (((x) & 0x7) << 3)
-#define FTMAC100_DBLAC_RXFIFO_HTHR(x) (((x) & 0x7) << 6)
-#define FTMAC100_DBLAC_RX_THR_EN (1 << 9)
+#define ISR_REG 0x00 // interrups status register
+#define IMR_REG 0x04 // interrupt maks register
+#define MAC_MADR_REG 0x08 // MAC address (Most significant)
+#define MAC_LADR_REG 0x0c // MAC address (Least significant)
+
+#define MAHT0_REG 0x10 // Multicast Address Hash Table 0 register
+#define MAHT1_REG 0x14 // Multicast Address Hash Table 1 register
+#define TXPD_REG 0x18 // Transmit Poll Demand register
+#define RXPD_REG 0x1c // Receive Poll Demand register
+#define TXR_BADR_REG 0x20 // Transmit Ring Base Address register
+#define RXR_BADR_REG 0x24 // Receive Ring Base Address register
+#define ITC_REG 0x28 // interrupt timer control register
+#define APTC_REG 0x2c // Automatic Polling Timer control register
+#define DBLAC_REG 0x30 // DMA Burst Length and Arbitration control register
+
+
+
+#define MACCR_REG 0x88 // MAC control register
+#define MACSR_REG 0x8c // MAC status register
+#define PHYCR_REG 0x90 // PHY control register
+#define PHYWDATA_REG 0x94 // PHY Write Data register
+#define FCR_REG 0x98 // Flow Control register
+#define BPR_REG 0x9c // back pressure register
+#define WOLCR_REG 0xa0 // Wake-On-Lan control register
+#define WOLSR_REG 0xa4 // Wake-On-Lan status register
+#define WFCRC_REG 0xa8 // Wake-up Frame CRC register
+#define WFBM1_REG 0xb0 // wake-up frame byte mask 1st double word register
+#define WFBM2_REG 0xb4 // wake-up frame byte mask 2nd double word register
+#define WFBM3_REG 0xb8 // wake-up frame byte mask 3rd double word register
+#define WFBM4_REG 0xbc // wake-up frame byte mask 4th double word register
+#define TM_REG 0xcc // test mode register
+
+#define PHYSTS_CHG_bit (1UL<<9)
+#define AHB_ERR_bit (1UL<<8)
+#define RPKT_LOST_bit (1UL<<7)
+#define RPKT_SAV_bit (1UL<<6)
+#define XPKT_LOST_bit (1UL<<5)
+#define XPKT_OK_bit (1UL<<4)
+#define NOTXBUF_bit (1UL<<3)
+#define XPKT_FINISH_bit (1UL<<2)
+#define NORXBUF_bit (1UL<<1)
+#define RPKT_FINISH_bit (1UL<<0)
+
+
+#ifdef __NDS32_EB__
+typedef struct
+{
+ unsigned int Reserved2:19;
+ unsigned int TXPOLL_TIME_SEL:1;
+ unsigned int TXPOLL_CNT:4;
+ unsigned int Reserved1:3;
+ unsigned int RXPOLL_TIME_SEL:1;
+ unsigned int RXPOLL_CNT:4;
+}FTMAC100_APTCR_Status;
+#else
+typedef struct
+{
+ unsigned int RXPOLL_CNT:4;
+ unsigned int RXPOLL_TIME_SEL:1;
+ unsigned int Reserved1:3;
+ unsigned int TXPOLL_CNT:4;
+ unsigned int TXPOLL_TIME_SEL:1;
+ unsigned int Reserved2:19;
+} FTMAC100_APTCR_Status;
+#endif
+
+#define RX_BROADPKT_bit (1UL<<17) // Receiving broadcast packet
+#define RX_MULTIPKT_bit (1UL<<16) // receiving multicast packet
+#define FULLDUP_bit (1UL<<15) // full duplex
+#define CRC_APD_bit (1UL<<14) // append crc to transmit packet
+#define MDC_SEL_bit (1UL<<13) // set MDC as TX_CK/10
+#define RCV_ALL_bit (1UL<<12) // not check incoming packet's destination address
+#define RX_FTL_bit (1UL<<11) // Store incoming packet even its length is great than 1518 byte
+#define RX_RUNT_bit (1UL<<10) // Store incoming packet even its length is les than 64 byte
+#define HT_MULTI_EN_bit (1UL<<9)
+#define RCV_EN_bit (1UL<<8) // receiver enable
+#define XMT_EN_bit (1UL<<5) // transmitter enable
+#define CRC_DIS_bit (1UL<<4)
+#define LOOP_EN_bit (1UL<<3) // Internal loop-back
+#define SW_RST_bit (1UL<<2) // software reset/
+#define RDMA_EN_bit (1UL<<1) // enable DMA receiving channel
+#define XDMA_EN_bit (1UL<<0) // enable DMA transmitting channel
+
+
+// --------------------------------------------------------------------
+// Receive Ring descriptor structure
+// --------------------------------------------------------------------
+#ifdef __NDS32_EB__
+typedef struct
+{
+ // RXDES0
+ unsigned int RXDMA_OWN:1; // 1 ==> owned by FTMAC100, 0 ==> owned by software
+ unsigned int Reserved3:1;
+ unsigned int FRS:1;
+ unsigned int LRS:1;
+ unsigned int Reserved2:5;
+ unsigned int RX_ODD_NB:1;
+ unsigned int RUNT:1;
+ unsigned int FTL:1;
+ unsigned int CRC_ERR:1; //19
+ unsigned int RX_ERR:1; //18
+ unsigned int BROARDCAST:1; //17
+ unsigned int MULTICAST:1; //16
+ unsigned int Reserved1:5; //11~15
+ unsigned int ReceiveFrameLength:11;//0~10
+
+ // RXDES1
+ unsigned int EDOTR:1;
+ unsigned int Reserved:20;
+ unsigned int RXBUF_Size:11;
+
+ // RXDES2
+ unsigned int RXBUF_BADR;
+
+ unsigned int VIR_RXBUF_BADR; // not defined, §ÚÌ®³¨Ó©ñ receive buffer ªº virtual address
+
+}RX_DESC;
+
+
+typedef struct
+{
+ // TXDES0
+ unsigned int TXDMA_OWN:1;
+ unsigned int Reserved1:29;
+ unsigned int TXPKT_EXSCOL:1;
+ unsigned int TXPKT_LATECOL:1;
+
+ // TXDES1
+ unsigned int EDOTR:1;
+ unsigned int TXIC:1;
+ unsigned int TX2FIC:1;
+ unsigned int FTS:1;
+ unsigned int LTS:1;
+ unsigned int Reserved2:16;
+ unsigned int TXBUF_Size:11;
+
+ // RXDES2
+ unsigned int TXBUF_BADR;
+ unsigned int VIR_TXBUF_BADR;
+}TX_DESC;
+#else
+typedef struct
+{
+ // RXDES0
+ unsigned int ReceiveFrameLength:11;//0~10
+ unsigned int Reserved1:5; //11~15
+ unsigned int MULTICAST:1; //16
+ unsigned int BROARDCAST:1; //17
+ unsigned int RX_ERR:1; //18
+ unsigned int CRC_ERR:1; //19
+ unsigned int FTL:1;
+ unsigned int RUNT:1;
+ unsigned int RX_ODD_NB:1;
+ unsigned int Reserved2:5;
+ unsigned int LRS:1;
+ unsigned int FRS:1;
+ unsigned int Reserved3:1;
+ unsigned int RXDMA_OWN:1; // 1 ==> owned by FTMAC100, 0 ==> owned by software
+
+ // RXDES1
+ unsigned int RXBUF_Size:11;
+ unsigned int Reserved:20;
+ unsigned int EDOTR:1;
+
+ // RXDES2
+ unsigned int RXBUF_BADR;
+
+ unsigned int VIR_RXBUF_BADR; // not defined, §ÚÌ®³¨Ó©ñ receive buffer ªº virtual address
+
+} RX_DESC;
+
+
+typedef struct
+{
+ // TXDES0
+ unsigned int TXPKT_LATECOL:1;
+ unsigned int TXPKT_EXSCOL:1;
+ unsigned int Reserved1:29;
+ unsigned int TXDMA_OWN:1;
+
+ // TXDES1
+ unsigned int TXBUF_Size:11;
+ unsigned int Reserved2:16;
+ unsigned int LTS:1;
+ unsigned int FTS:1;
+ unsigned int TX2FIC:1;
+ unsigned int TXIC:1;
+ unsigned int EDOTR:1;
+
+ // RXDES2
+ unsigned int TXBUF_BADR;
+ unsigned int VIR_TXBUF_BADR;
+} TX_DESC;
+#endif
+
+// waiting to do:
+#define TXPOLL_CNT 8
+#define RXPOLL_CNT 0
+
+#define OWNBY_SOFTWARE 0
+#define OWNBY_FTMAC100 1
+
+// --------------------------------------------------------------------
+// driver related definition
+// --------------------------------------------------------------------
+#define RXDES_NUM 256 // must be 2's power
+#define RX_BUF_SIZE 1536
+#define TXDES_NUM 64 // must be 2's power
+#define TX_BUF_SIZE 1536 // Luke Lee : Just bigger than 1518
+
+
+struct ftmac100_local
+{
+ // these are things that the kernel wants me to keep, so users
+ // can find out semi-useless statistics of how well the card is
+ // performing
+ struct net_device_stats stats;
+
+ // Set to true during the auto-negotiation sequence
+ int autoneg_active;
+
+ // Address of our PHY port
+ unsigned int phyaddr;
+
+ // Type of PHY
+ unsigned int phytype;
+
+ // Last contents of PHY Register 18
+ unsigned int lastPhy18;
+
+ spinlock_t lock;
+
+ volatile RX_DESC *rx_descs; // receive ring base address
+ unsigned int rx_descs_dma; // receive ring physical base address
+ char *rx_buf; // receive buffer cpu address
+ int rx_buf_dma; // receive buffer physical address
+ int rx_idx; // receive descriptor
+ //struct sk_buff *rx_skbuff[RXDES_NUM];
+
+ volatile TX_DESC *tx_descs;
+ unsigned int tx_descs_dma;
+ char *tx_buf;
+ int tx_buf_dma;
+ int tx_idx;
+ int old_tx;
+ struct sk_buff *tx_skbuff[RXDES_NUM];
+
+ int maccr_val;
+};
-/*
- * MAC control register
- */
-#define FTMAC100_MACCR_XDMA_EN (1 << 0)
-#define FTMAC100_MACCR_RDMA_EN (1 << 1)
-#define FTMAC100_MACCR_SW_RST (1 << 2)
-#define FTMAC100_MACCR_LOOP_EN (1 << 3)
-#define FTMAC100_MACCR_CRC_DIS (1 << 4)
-#define FTMAC100_MACCR_XMT_EN (1 << 5)
-#define FTMAC100_MACCR_ENRX_IN_HALFTX (1 << 6)
-#define FTMAC100_MACCR_RCV_EN (1 << 8)
-#define FTMAC100_MACCR_HT_MULTI_EN (1 << 9)
-#define FTMAC100_MACCR_RX_RUNT (1 << 10)
-#define FTMAC100_MACCR_RX_FTL (1 << 11)
-#define FTMAC100_MACCR_RCV_ALL (1 << 12)
-#define FTMAC100_MACCR_CRC_APD (1 << 14)
-#define FTMAC100_MACCR_FULLDUP (1 << 15)
-#define FTMAC100_MACCR_RX_MULTIPKT (1 << 16)
-#define FTMAC100_MACCR_RX_BROADPKT (1 << 17)
-
-/*
- * PHY control register
- */
-#define FTMAC100_PHYCR_MIIRDATA 0xffff
-#define FTMAC100_PHYCR_PHYAD(x) (((x) & 0x1f) << 16)
-#define FTMAC100_PHYCR_REGAD(x) (((x) & 0x1f) << 21)
-#define FTMAC100_PHYCR_MIIRD (1 << 26)
-#define FTMAC100_PHYCR_MIIWR (1 << 27)
-
-/*
- * PHY write data register
- */
-#define FTMAC100_PHYWDATA_MIIWDATA(x) ((x) & 0xffff)
-
-/*
- * Transmit descriptor, aligned to 16 bytes
- */
-struct ftmac100_txdes {
- unsigned int txdes0;
- unsigned int txdes1;
- unsigned int txdes2; /* TXBUF_BADR */
- unsigned int txdes3; /* not used by HW */
-} __attribute__ ((aligned(16)));
-
-#define FTMAC100_TXDES0_TXPKT_LATECOL (1 << 0)
-#define FTMAC100_TXDES0_TXPKT_EXSCOL (1 << 1)
-#define FTMAC100_TXDES0_TXDMA_OWN (1 << 31)
-
-#define FTMAC100_TXDES1_TXBUF_SIZE(x) ((x) & 0x7ff)
-#define FTMAC100_TXDES1_LTS (1 << 27)
-#define FTMAC100_TXDES1_FTS (1 << 28)
-#define FTMAC100_TXDES1_TX2FIC (1 << 29)
-#define FTMAC100_TXDES1_TXIC (1 << 30)
-#define FTMAC100_TXDES1_EDOTR (1 << 31)
-
-/*
- * Receive descriptor, aligned to 16 bytes
- */
-struct ftmac100_rxdes {
- unsigned int rxdes0;
- unsigned int rxdes1;
- unsigned int rxdes2; /* RXBUF_BADR */
- unsigned int rxdes3; /* not used by HW */
-} __attribute__ ((aligned(16)));
-
-#define FTMAC100_RXDES0_RFL 0x7ff
-#define FTMAC100_RXDES0_MULTICAST (1 << 16)
-#define FTMAC100_RXDES0_BROADCAST (1 << 17)
-#define FTMAC100_RXDES0_RX_ERR (1 << 18)
-#define FTMAC100_RXDES0_CRC_ERR (1 << 19)
-#define FTMAC100_RXDES0_FTL (1 << 20)
-#define FTMAC100_RXDES0_RUNT (1 << 21)
-#define FTMAC100_RXDES0_RX_ODD_NB (1 << 22)
-#define FTMAC100_RXDES0_LRS (1 << 28)
-#define FTMAC100_RXDES0_FRS (1 << 29)
-#define FTMAC100_RXDES0_RXDMA_OWN (1 << 31)
+#endif
-#define FTMAC100_RXDES1_RXBUF_SIZE(x) ((x) & 0x7ff)
-#define FTMAC100_RXDES1_EDORR (1 << 31)
-#endif /* __FTMAC100_H */
diff -Nur linux-3.4.113.orig/drivers/net/ethernet/faraday/Kconfig linux-3.4.113/drivers/net/ethernet/faraday/Kconfig
--- linux-3.4.113.orig/drivers/net/ethernet/faraday/Kconfig 2016-10-26 17:15:47.000000000 +0200
+++ linux-3.4.113/drivers/net/ethernet/faraday/Kconfig 2016-12-01 20:59:24.388614139 +0100
@@ -5,7 +5,7 @@
config NET_VENDOR_FARADAY
bool "Faraday devices"
default y
- depends on ARM
+ depends on ARM || NDS32
---help---
If you have a network (Ethernet) card belonging to this class, say Y
and read the Ethernet-HOWTO, available from
@@ -20,7 +20,7 @@
config FTMAC100
tristate "Faraday FTMAC100 10/100 Ethernet support"
- depends on ARM
+ depends on ARM || NDS32
select NET_CORE
select MII
---help---
diff -Nur linux-3.4.113.orig/drivers/pci/Makefile linux-3.4.113/drivers/pci/Makefile
--- linux-3.4.113.orig/drivers/pci/Makefile 2016-10-26 17:15:47.000000000 +0200
+++ linux-3.4.113/drivers/pci/Makefile 2016-12-01 20:59:24.388614139 +0100
@@ -49,6 +49,7 @@
obj-$(CONFIG_MICROBLAZE) += setup-bus.o
obj-$(CONFIG_TILE) += setup-bus.o setup-irq.o
obj-$(CONFIG_SPARC_LEON) += setup-bus.o setup-irq.o
+obj-$(CONFIG_NDS32) += setup-bus.o setup-irq.o
#
# ACPI Related PCI FW Functions
diff -Nur linux-3.4.113.orig/drivers/rtc/Kconfig linux-3.4.113/drivers/rtc/Kconfig
--- linux-3.4.113.orig/drivers/rtc/Kconfig 2016-10-26 17:15:47.000000000 +0200
+++ linux-3.4.113/drivers/rtc/Kconfig 2016-12-01 20:59:24.388614139 +0100
@@ -779,6 +779,16 @@
This driver can also be built as a module. If so, the module
will be called rtc-ep93xx.
+config RTC_DRV_FTRTC010
+ tristate "Faraday Real Time Clock"
+ depends on NDS32
+ help
+ If you say Y here you will get access to the real time clock
+ built into your AG101 CPU.
+
+ To compile this driver as a module, choose M here: the
+ module will be called rtc-ftrtc010.
+
config RTC_DRV_SA1100
tristate "SA11x0/PXA2xx/PXA910"
depends on ARCH_SA1100 || ARCH_PXA || ARCH_MMP
diff -Nur linux-3.4.113.orig/drivers/rtc/Makefile linux-3.4.113/drivers/rtc/Makefile
--- linux-3.4.113.orig/drivers/rtc/Makefile 2016-10-26 17:15:47.000000000 +0200
+++ linux-3.4.113/drivers/rtc/Makefile 2016-12-01 20:59:24.388614139 +0100
@@ -50,6 +50,7 @@
obj-$(CONFIG_RTC_DRV_FM3130) += rtc-fm3130.o
obj-$(CONFIG_RTC_DRV_GENERIC) += rtc-generic.o
obj-$(CONFIG_RTC_DRV_IMXDI) += rtc-imxdi.o
+obj-$(CONFIG_RTC_DRV_FTRTC010) += rtc-ftrtc010.o
obj-$(CONFIG_RTC_DRV_ISL1208) += rtc-isl1208.o
obj-$(CONFIG_RTC_DRV_ISL12022) += rtc-isl12022.o
obj-$(CONFIG_RTC_DRV_JZ4740) += rtc-jz4740.o
diff -Nur linux-3.4.113.orig/drivers/rtc/rtc-ftrtc010.c linux-3.4.113/drivers/rtc/rtc-ftrtc010.c
--- linux-3.4.113.orig/drivers/rtc/rtc-ftrtc010.c 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/drivers/rtc/rtc-ftrtc010.c 2016-12-01 20:59:24.388614139 +0100
@@ -0,0 +1,371 @@
+/*
+ * Faraday RTC Support
+ *
+ * Copyright (C) 2006, 2007, 2008 Paul Mundt
+ * Copyright (C) 2006 Jamie Lenehan
+ * Copyright (C) 2008 Angelo Castello
+ * Copyright (C) 2008 Roy Lee
+ *
+ * Based on the old arch/sh/kernel/cpu/rtc.c by:
+ *
+ * Copyright (C) 2000 Philipp Rumpf <prumpf@tux.org>
+ * Copyright (C) 1999 Tetsuya Okada & Niibe Yutaka
+ *
+ * This file is subject to the terms and conditions of the GNU General Public
+ * License. See the file "COPYING" in the main directory of this archive
+ * for more details.
+ */
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/rtc.h>
+#include <linux/delay.h>
+#include <linux/init.h>
+#include <linux/platform_device.h>
+#include <linux/seq_file.h>
+#include <linux/interrupt.h>
+#include <linux/io.h>
+
+#define PCLK ( AHB_CLK_IN / 2)
+
+#define DRV_NAME "faraday-rtc"
+
+#define RTC_REG( off) ( *( volatile unsigned long *)( rtc->regbase + ( off)))
+
+#define RTC_CR RTC_REG( 0x20) /* Control */
+#define RTC_CR_IE ( 0x1UL << 0)
+#define RTC_CR_IES ( 0x1UL << 1)
+#define RTC_CR_IEM ( 0x1UL << 2)
+#define RTC_CR_IEH ( 0x1UL << 3)
+#define RTC_CR_IED ( 0x1UL << 4)
+#define RTC_CR_ALRM ( 0x1UL << 5)
+#define RTC_CR_LOAD ( 0x1UL << 6)
+
+#define RTC_RR RTC_REG( 0x1C) /* RTC Record Register */
+#define RTC_DIV RTC_REG( 0x38) /* RTC Divede Register */
+#define RTC_REV RTC_REG( 0x3C) /* RTC Divede Register */
+
+#define RTC_IR RTC_REG( 0x34) /* RTC interrupt state */
+#define RTC_IR_IES ( 0x1UL << 0) /* RTC interrupt state */
+#define RTC_IR_IEM ( 0x1UL << 1) /* RTC interrupt state */
+#define RTC_IR_IEH ( 0x1UL << 2) /* RTC interrupt state */
+#define RTC_IR_IED ( 0x1UL << 3) /* RTC interrupt state */
+#define RTC_IR_ALRM ( 0x1UL << 4) /* RTC interrupt state */
+
+#define RTC_SECOND RTC_REG( 0x00) /* RTC sec */
+#define RTC_MINUTE RTC_REG( 0x04) /* RTC min */
+#define RTC_HOUR RTC_REG( 0x08) /* RTC hour */
+#define RTC_DAYS RTC_REG( 0x0C) /* RTC day */
+
+#define RTC_ALRM_SECOND RTC_REG( 0x10) /* RTC alarm sec */
+#define RTC_ALRM_MINUTE RTC_REG( 0x14) /* RTC alarm min */
+#define RTC_ALRM_HOUR RTC_REG( 0x18) /* RTC alarm hour */
+
+#define RTC_WRITE_SECOND RTC_REG( 0x24) /* RTC write port for sec */
+#define RTC_WRITE_MINUTE RTC_REG( 0x28) /* RTC write port for min */
+#define RTC_WRITE_HOUR RTC_REG( 0x2C) /* RTC write port for hour */
+#define RTC_WRITE_DAYS RTC_REG( 0x30) /* RTC write port for day */
+
+struct ft_rtc{
+
+ void __iomem *regbase;
+ struct resource *res;
+ unsigned int alarm_irq;
+ unsigned int interrupt_irq;
+ struct rtc_device *rtc_dev;
+ spinlock_t lock; /* Protects this structure */
+};
+
+struct ft_rtc rtc_platform_data;
+
+static irqreturn_t ft_rtc_interrupt( int irq, void *dev_id){
+
+ struct ft_rtc *rtc = dev_id;
+ if( RTC_IR & RTC_IR_IES){
+
+ RTC_IR &= ~RTC_IR_IES;
+ rtc_update_irq( rtc->rtc_dev, 1, RTC_UF | RTC_IRQF);
+
+ return IRQ_HANDLED;
+ }
+
+ return IRQ_NONE;
+}
+
+static irqreturn_t ft_rtc_alarm( int irq, void *dev_id){
+
+ struct ft_rtc *rtc = dev_id;
+ if( RTC_IR & RTC_IR_ALRM){
+
+ RTC_CR &= ~RTC_CR_ALRM;
+ RTC_IR &= ~RTC_IR_ALRM;
+ rtc_update_irq( rtc->rtc_dev, 1, RTC_AF | RTC_IRQF);
+
+ return IRQ_HANDLED;
+ }
+
+ return IRQ_NONE;
+}
+
+static void ft_rtc_release( struct device *dev){
+
+ struct ft_rtc *rtc = dev_get_drvdata( dev);
+
+ RTC_CR &= ~RTC_CR_IES;
+ RTC_CR &= ~RTC_CR_ALRM;
+}
+
+/* rick add */
+static int ft_alarm_irq_enable(struct device *dev, unsigned int enabled)
+{
+// printk("\n\nft_alarm_irq_enable\n\n");
+
+ struct ft_rtc *rtc = dev_get_drvdata( dev);
+ spin_lock_irq(&rtc->lock);
+ if (enabled)
+ RTC_CR |= RTC_CR_ALRM;
+ else
+ RTC_CR &= ~RTC_CR_ALRM;
+ spin_unlock_irq(&rtc->lock);
+ return 0;
+}
+
+static int ft_rtc_read_time( struct device *dev, struct rtc_time *tm){
+ struct ft_rtc *rtc = dev_get_drvdata( dev);
+ unsigned long time = RTC_DAYS * 86400 + RTC_HOUR * 3600 + RTC_MINUTE * 60 + RTC_SECOND;
+ rtc_time_to_tm( time, tm);
+ if( rtc_valid_tm( tm) < 0) {
+ dev_err( dev, "invalid date\n");
+ rtc_time_to_tm( 0, tm);
+ }
+ return 0;
+}
+
+static int ft_rtc_set_time( struct device *dev, struct rtc_time *tm){
+
+ struct ft_rtc *rtc = dev_get_drvdata( dev);
+ unsigned long time = 0;
+
+ rtc_tm_to_time( tm, &time);
+
+ RTC_WRITE_DAYS = time / 86400;
+ time %= 86400;
+
+ RTC_WRITE_HOUR = time / 3600;
+ time %= 3600;
+
+ RTC_WRITE_MINUTE = time / 60;
+ time %= 60;
+
+ RTC_WRITE_SECOND = time;
+
+ RTC_CR |= RTC_CR_LOAD;
+
+ return 0;
+}
+
+static int ft_rtc_read_alarm( struct device *dev, struct rtc_wkalrm *wkalrm){
+
+ struct ft_rtc *rtc = dev_get_drvdata( dev);
+ struct rtc_time *tm = &wkalrm->time;
+
+ tm->tm_sec = RTC_ALRM_SECOND;
+ tm->tm_min = RTC_ALRM_MINUTE;
+ tm->tm_hour = RTC_ALRM_HOUR;
+
+ wkalrm->enabled = ( RTC_CR & RTC_CR_ALRM) ? 1 : 0;
+
+ return 0;
+}
+
+static int ft_rtc_set_alarm( struct device *dev, struct rtc_wkalrm *wkalrm){
+
+ struct ft_rtc *rtc = dev_get_drvdata( dev);
+ struct rtc_time *tm = &wkalrm->time;
+ int err = rtc_valid_tm( tm);
+ if( err < 0){
+
+ dev_err( dev, "invalid alarm value\n");
+ return err;
+ }
+
+ /* disable alarm interrupt and clear the alarm flag */
+ RTC_CR &= ~RTC_CR_ALRM;
+
+ /* set alarm time */
+ RTC_ALRM_SECOND = tm->tm_sec;
+ RTC_ALRM_MINUTE = tm->tm_min;
+ RTC_ALRM_HOUR = tm->tm_hour;
+
+ if( wkalrm->enabled)
+ RTC_CR |= RTC_CR_ALRM;
+
+ return 0;
+}
+
+/*
+static int ft_rtc_irq_set_state( struct device *dev, int enabled){
+ struct ft_rtc *rtc = dev_get_drvdata( dev);
+ if( enabled)
+ RTC_CR |= RTC_CR_IES;
+ else
+ RTC_CR &= ~RTC_CR_IES;
+
+ return 0;
+}
+
+*/
+
+static struct rtc_class_ops ft_rtc_ops = {
+
+ .release = ft_rtc_release,
+ .alarm_irq_enable = ft_alarm_irq_enable,
+
+ .read_time = ft_rtc_read_time,
+ .set_time = ft_rtc_set_time,
+ .read_alarm = ft_rtc_read_alarm,
+ .set_alarm = ft_rtc_set_alarm,
+};
+
+static int __devinit ft_rtc_probe( struct platform_device *pdev){
+
+ struct ft_rtc *rtc = &rtc_platform_data;
+ int ret = -ENOENT;
+ spin_lock_init(&rtc->lock);
+
+ if( ( rtc->alarm_irq = platform_get_irq( pdev, 0)) < 0)
+ goto err_exit;
+
+ if( ( rtc->interrupt_irq = platform_get_irq( pdev, 1)) < 0)
+ goto err_exit;
+
+ if( !( rtc->res = platform_get_resource( pdev, IORESOURCE_MEM, 0)))
+ goto err_exit;
+
+ if( ( ret = request_irq( rtc->alarm_irq , ft_rtc_alarm, 0, "RTC Alarm : ftrtc010", rtc)))
+ goto err_exit;
+
+ if( ( ret = request_irq( rtc->interrupt_irq , ft_rtc_interrupt, 0, "RTC Interrupt : ftrtc010", rtc)))
+ goto err_interrupt_irq;
+
+ ret = -EBUSY;
+
+ if( !( rtc->res = request_mem_region( rtc->res->start, rtc->res->end - rtc->res->start + 1, pdev->name)))
+ goto err_request_region;
+
+ ret = -EINVAL;
+
+ if( !( rtc->regbase = ioremap_nocache( rtc->res->start, rtc->res->end - rtc->res->start + 1)))
+ goto err_ioremap1;
+
+
+ //RTC_DIV = ( 0x1UL << 31) | 2; /* AG101 */
+ RTC_CR |= RTC_CR_IE;
+ platform_set_drvdata( pdev, rtc);
+ device_init_wakeup(&pdev->dev, true);
+
+ rtc->rtc_dev = rtc_device_register( DRV_NAME, &pdev->dev, &ft_rtc_ops, THIS_MODULE);
+
+ if( IS_ERR( rtc->rtc_dev)) {
+
+ ret = PTR_ERR( rtc->rtc_dev);
+ goto err_unmap;
+ }
+
+ rtc->rtc_dev->max_user_freq = 256;
+ rtc->rtc_dev->irq_freq = 1;
+ return 0;
+
+err_unmap:
+ iounmap( rtc->regbase);
+err_ioremap1:
+ release_resource( rtc->res);
+err_request_region:
+ free_irq( rtc->interrupt_irq, rtc);
+err_interrupt_irq:
+ free_irq( rtc->alarm_irq, rtc);
+err_exit:
+ return ret;
+}
+
+static int __devexit ft_rtc_remove( struct platform_device *pdev){
+
+ struct ft_rtc *rtc = platform_get_drvdata( pdev);
+
+ rtc_device_unregister( rtc->rtc_dev);
+
+ RTC_CR &= ~RTC_CR_ALRM;
+
+ free_irq( rtc->alarm_irq, rtc);
+ free_irq( rtc->interrupt_irq, rtc);
+
+ iounmap( rtc->regbase);
+
+ platform_set_drvdata( pdev, NULL);
+
+ return 0;
+}
+
+static void platform_device_release(struct device *dev){
+}
+
+static struct resource rtc_resources[] = {
+ {
+ .start = RTC_FTRTC010_PA_BASE,
+ .end = RTC_FTRTC010_PA_LIMIT,
+ .flags = IORESOURCE_MEM,
+ },
+ {
+ .start = RTC_FTRTC010_IRQ0,
+ .end = RTC_FTRTC010_IRQ0,
+ .flags = IORESOURCE_IRQ,
+ },
+ {
+ .start = RTC_FTRTC010_IRQ1,
+ .end = RTC_FTRTC010_IRQ1,
+ .flags = IORESOURCE_IRQ,
+ },
+};
+
+static struct platform_driver ft_rtc_platform_driver = {
+
+ .driver = {
+ .name = DRV_NAME,
+ .owner = THIS_MODULE,
+ },
+ .probe = ft_rtc_probe,
+ .remove = __devexit_p( ft_rtc_remove),
+};
+
+static struct platform_device rtc_device = {
+
+ .name = DRV_NAME,
+ .id = 0,
+ .resource = rtc_resources,
+ .num_resources = ARRAY_SIZE( rtc_resources),
+ .dev = {
+ .platform_data = &rtc_platform_data,
+ .release = platform_device_release,
+ },
+};
+
+static int __init ft_rtc_init( void){
+ platform_device_register( &rtc_device);
+ return platform_driver_register( &ft_rtc_platform_driver);
+}
+
+static void __exit ft_rtc_exit( void){
+
+ platform_driver_unregister( &ft_rtc_platform_driver);
+ platform_device_unregister( &rtc_device);
+}
+
+module_init( ft_rtc_init);
+module_exit( ft_rtc_exit);
+
+MODULE_DESCRIPTION( "SuperH on-chip RTC driver");
+MODULE_AUTHOR( "Paul Mundt <lethal@linux-sh.org>, "
+ "Jamie Lenehan <lenehan@twibble.org>, "
+ "Angelo Castello <angelo.castello@st.com>, "
+ "Roy Lee <roylee@andestech.com>");
+MODULE_LICENSE( "GPL");
+MODULE_ALIAS( "platform:" DRV_NAME);
diff -Nur linux-3.4.113.orig/drivers/tty/serial/8250/8250.c linux-3.4.113/drivers/tty/serial/8250/8250.c
--- linux-3.4.113.orig/drivers/tty/serial/8250/8250.c 2016-10-26 17:15:47.000000000 +0200
+++ linux-3.4.113/drivers/tty/serial/8250/8250.c 2016-12-01 20:59:24.392614293 +0100
@@ -570,6 +570,7 @@
serial_out(up, UART_ICR, value);
}
+#ifndef CONFIG_NDS32
static unsigned int serial_icr_read(struct uart_8250_port *up, int offset)
{
unsigned int value;
@@ -581,6 +582,7 @@
return value;
}
+#endif
/*
* FIFO support.
@@ -722,6 +724,7 @@
return count;
}
+#ifndef CONFIG_NDS32
/*
* Read UART ID using the divisor method - set DLL and DLM to zero
* and the revision will be in DLL and device type in DLM. We
@@ -749,7 +752,9 @@
return id;
}
+#endif
+#ifndef CONFIG_NDS32
/*
* This is a helper routine to autodetect StarTech/Exar/Oxsemi UART's.
* When this function is called we know it is at least a StarTech
@@ -842,6 +847,7 @@
else
up->port.type = PORT_16650V2;
}
+#endif
/*
* We detected a chip without a FIFO. Only two fall into
@@ -865,6 +871,7 @@
up->port.type = PORT_16450;
}
+#ifndef CONFIG_NDS32
static int broken_efr(struct uart_8250_port *up)
{
/*
@@ -877,6 +884,7 @@
return 0;
}
+#endif
static inline int ns16550a_goto_highspeed(struct uart_8250_port *up)
{
@@ -908,7 +916,7 @@
up->port.type = PORT_16550A;
up->capabilities |= UART_CAP_FIFO;
-
+#ifndef CONFIG_NDS32
/*
* Check for presence of the EFR when DLAB is set.
* Only ST16C650V1 UARTs pass this test.
@@ -937,6 +945,7 @@
autoconfig_has_efr(up);
return;
}
+#endif
/*
* Check for a National Semiconductor SuperIO chip.
@@ -1156,10 +1165,11 @@
* We also initialise the EFR (if any) to zero for later. The
* EFR occupies the same register location as the FCR and IIR.
*/
+#ifndef CONFIG_NDS32
serial_out(up, UART_LCR, UART_LCR_CONF_MODE_B);
serial_out(up, UART_EFR, 0);
serial_out(up, UART_LCR, 0);
-
+#endif
serial_out(up, UART_FCR, UART_FCR_ENABLE_FIFO);
scratch = serial_in(up, UART_IIR) >> 6;
diff -Nur linux-3.4.113.orig/drivers/video/FTLCDC100/faradayfb.h linux-3.4.113/drivers/video/FTLCDC100/faradayfb.h
--- linux-3.4.113.orig/drivers/video/FTLCDC100/faradayfb.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/drivers/video/FTLCDC100/faradayfb.h 2016-12-01 20:59:24.392614293 +0100
@@ -0,0 +1,215 @@
+#ifndef __FARADAYFB_H
+#define __FARADAYFB_H
+
+#define FARADAYFB_MODULE_NAME "faradayfb"
+#define DEBUG(enabled, tagged, ...) \
+ do { \
+ if (enabled) { \
+ if (tagged) \
+ printk("[ %30s() ] ", __func__); \
+ printk(__VA_ARGS__); \
+ } \
+ } while (0)
+
+#if defined(CONFIG_FFB_MODE_RGB)
+# define DEFAULT_COLOR FFB_MODE_RGB
+#elif defined(CONFIG_FFB_MODE_YUV422)
+# define DEFAULT_COLOR FFB_MODE_YUV422
+#elif defined(CONFIG_FFB_MODE_YUV420)
+# define DEFAULT_COLOR FFB_MODE_YUV420
+#endif
+
+#if defined(CONFIG_FFB_MODE_8BPP)
+# define DEFAULT_BPP FFB_MODE_8BPP
+#elif defined(CONFIG_FFB_MODE_16BPP)
+# define DEFAULT_BPP FFB_MODE_16BPP
+#elif defined(CONFIG_FFB_MODE_24BPP)
+# define DEFAULT_BPP FFB_MODE_24BPP
+#endif
+
+#define FFB_DEFAULT_MODE (DEFAULT_COLOR | DEFAULT_BPP)
+
+struct lcd_param {
+
+ unsigned long value;
+ unsigned long flags;
+};
+
+inline struct lcd_param* get_lcd_time(struct lcd_param* array, unsigned long num_array, unsigned long type)
+{
+ int i;
+
+ for (i = 0; i < num_array; i++) {
+
+ struct lcd_param *r = &array[i];
+
+ if (r->flags & type & 0xff)
+ return r;
+ }
+
+ return NULL;
+}
+
+inline struct lcd_param* get_lcd_ctrl(struct lcd_param* array, unsigned long num_array, unsigned long type)
+{
+ int i;
+
+ for (i = 0; i < num_array; i++) {
+
+ struct lcd_param *r = &array[i];
+
+ if ((r->flags & type & 0xff) && (r->flags & type & 0xff00))
+ return r;
+ }
+
+ return NULL;
+}
+
+enum { RGB_8, RGB_16, RGB_24, NR_RGB};
+
+struct faradayfb_rgb {
+
+ struct fb_bitfield red;
+ struct fb_bitfield green;
+ struct fb_bitfield blue;
+ struct fb_bitfield transp;
+};
+
+/* This structure describes the machine which we are running on. */
+struct faradayfb_mach_info {
+
+ unsigned long num_time0;
+ struct lcd_param * time0;
+
+ unsigned long num_time1;
+ struct lcd_param * time1;
+
+ unsigned long num_time2;
+ struct lcd_param * time2;
+
+ unsigned long num_control;
+ struct lcd_param * control;
+
+ unsigned long pixclock;
+
+ unsigned long xres;
+ unsigned long yres;
+
+ unsigned int max_bpp;
+ unsigned int sync;
+
+ unsigned int cmap_greyscale:1,
+ cmap_inverse:1,
+ cmap_static:1,
+ unused:29;
+};
+
+struct faradayfb_info {
+
+ struct fb_info *info;
+ struct faradayfb_rgb *rgb[NR_RGB];
+
+ unsigned int xres;
+ unsigned int yres;
+ unsigned int max_bpp;
+
+ /*
+ * These are the addresses we mapped
+ * the framebuffer memory region to.
+ */
+ dma_addr_t map_dma;
+ unsigned char * map_cpu;
+ unsigned int map_size;
+
+ unsigned char * screen_cpu;
+ dma_addr_t screen_dma;
+ u32 * palette_cpu;
+ dma_addr_t palette_dma;
+ unsigned int palette_size;
+
+ unsigned int cmap_inverse:1,
+ cmap_static:1,
+ unused:30;
+
+ unsigned long time0;
+ unsigned long time1;
+ unsigned long time2;
+ unsigned long control;
+ unsigned long int_mask;
+ unsigned long io_base;
+
+ unsigned int state;
+ unsigned int task_state;
+ struct semaphore ctrlr_sem;
+ wait_queue_head_t ctrlr_wait;
+ struct work_struct task;
+
+ unsigned long smode;
+ unsigned long frame420_size;
+};
+
+/*
+ * These are the actions for set_ctrlr_state
+ */
+#define C_DISABLE 0
+#define C_ENABLE 1
+#define C_DISABLE_CLKCHANGE 2
+#define C_ENABLE_CLKCHANGE 3
+#define C_REENABLE 4
+#define C_DISABLE_PM 5
+#define C_ENABLE_PM 6
+#define C_STARTUP 7
+
+#define FARADAY_LCDTIME0_GET_HBP(x) ((((x) >> 24) & 0xFF) + 1)
+#define FARADAY_LCDTIME0_GET_HFP(x) ((((x) >> 16) & 0xFF) + 1)
+#define FARADAY_LCDTIME0_GET_HW(x) ((((x) >> 8) & 0xFF) + 1)
+#define FARADAY_LCDTIME1_GET_VBP(x) ((((x) >> 24) & 0xFF) )
+#define FARADAY_LCDTIME1_GET_VFP(x) ((((x) >> 16) & 0xFF) )
+#define FARADAY_LCDTIME1_GET_VW(x) ((((x) >> 8) & 0xFF) + 1)
+
+#define FARADAY_LCDTIME0_HBP(x) ((((x) - 1) & 0xFF) << 24)
+#define FARADAY_LCDTIME0_HFP(x) ((((x) - 1) & 0xFF) << 16)
+#define FARADAY_LCDTIME0_HW(x) ((((x) - 1) & 0xFF) << 8)
+#define FARADAY_LCDTIME0_PL(x) (((((x) >> 4) - 1) & 0x3F) << 2)
+#define FARADAY_LCDTIME1_VBP(x) ((((x) ) & 0xFF) << 24)
+#define FARADAY_LCDTIME1_VFP(x) ((((x) ) & 0xFF) << 16)
+#define FARADAY_LCDTIME1_VW(x) ((((x) - 1) & 0xFF) << 8)
+#define FARADAY_LCDTIME1_LF(x) ((((x) - 1) & 0x3FF) )
+
+#define FFB_MODE_RGB 0x00000001
+#define FFB_MODE_YUV420 0x00000002
+#define FFB_MODE_YUV422 0x00000004
+
+#define FFB_MODE_8BPP 0x00000100
+#define FFB_MODE_16BPP 0x00000200
+#define FFB_MODE_24BPP 0x00000400
+
+/* Minimum X and Y resolutions */
+#define MIN_XRES 64
+#define MIN_YRES 64
+
+typedef struct LCDTag {
+
+ u32 Timing0; /* 0x00 */
+ u32 Timing1; /* 0x04 */
+ u32 Timing2; /* 0x08 */
+ u32 Timing3; /* 0x0C */
+ u32 UPBase; /* 0x10 */
+ u32 LPBase; /* 0x14 */
+ u32 INTREnable; /* 0x18 */
+ u32 Control; /* 0x1C */
+ u32 Status; /* 0x20 */
+ u32 Interrupt; /* 0x24 */
+ u32 UPCurr; /* 0x28 */
+ u32 LPCurr; /* 0x2C */
+ u32 Reserved1[5]; /* 0x30~0x40 */
+ u32 GPIO; /* 0x44 */
+ u32 Reserved2[0x74 - 6]; /* 0x48~0x1FC */
+
+ u32 Palette[0x80]; /* 0x200~0x3FC */
+ u32 TestReg[0x100]; /* 0x400~0x7FC */
+
+} LCD_Register;
+
+#endif /* __FARADAYFB_H */
+
diff -Nur linux-3.4.113.orig/drivers/video/FTLCDC100/faradayfb-main.c linux-3.4.113/drivers/video/FTLCDC100/faradayfb-main.c
--- linux-3.4.113.orig/drivers/video/FTLCDC100/faradayfb-main.c 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/drivers/video/FTLCDC100/faradayfb-main.c 2016-12-01 20:59:24.392614293 +0100
@@ -0,0 +1,911 @@
+#include <linux/module.h>
+#include <linux/fb.h>
+#include <linux/delay.h>
+#include <linux/device.h>
+#include <linux/dma-mapping.h>
+#include <linux/interrupt.h>
+#include <linux/platform_device.h>
+
+#include <asm/uaccess.h>
+#include <asm/atomic.h>
+#include <asm/mach-types.h>
+
+#include "faradayfb.h"
+#include "lcd-info.c"
+#include "pingpong-module.c"
+
+static u32 faradayfb_pseudo_palette[32];
+static inline void faradayfb_lcd_power(struct fb_info *info, int on)
+{
+ struct faradayfb_info *fbi = info->par;
+ volatile LCD_Register *plcd = (LCD_Register *)fbi->io_base;
+
+ if (on)
+ fbi->control |= (1UL << 11);
+ else
+ fbi->control &= ~(1UL << 11);
+
+ plcd->Control = fbi->control;
+}
+
+static void faradayfb_setup_gpio(struct fb_info *info)
+{
+ struct faradayfb_info *fbi = info->par;
+ volatile LCD_Register *plcd = (LCD_Register *)fbi->io_base;
+
+ plcd->GPIO = 0x010000;
+}
+
+static inline void faradayfb_pmu_on(void)
+{
+ REG32(PMU_FTPMU010_VA_BASE + 0x44) |= 0x00700000;
+}
+
+static inline void faradayfb_pmu_off(void)
+{
+ REG32(PMU_FTPMU010_VA_BASE + 0x44) &= ~0x00700000;
+}
+
+static void faradayfb_enable_controller(struct fb_info *info)
+{
+ struct faradayfb_info *fbi = info->par;
+ volatile LCD_Register *plcd = (LCD_Register *)fbi->io_base;
+
+ plcd->Timing0 = fbi->time0;
+ plcd->Timing1 = fbi->time1;
+ plcd->Timing2 = fbi->time2;
+ plcd->Control = fbi->control & ~0x01;
+
+ plcd->UPBase = fbi->screen_dma | fbi->frame420_size;
+
+ faradayfb_pmu_on();
+ plcd->Control |= 0x01;
+
+ DEBUG(0, 1, "Time0 = 0x%08x\n", plcd->Timing0);
+ DEBUG(0, 1, "Time1 = 0x%08x\n", plcd->Timing1);
+ DEBUG(0, 1, "Time2 = 0x%08x\n", plcd->Timing2);
+ DEBUG(0, 1, "Control = 0x%08x\n", plcd->Control);
+ DEBUG(0, 1, "UPBase = 0x%08x\n", plcd->UPBase);
+}
+
+static void faradayfb_disable_controller(struct fb_info *info)
+{
+ struct faradayfb_info *fbi = info->par;
+ volatile LCD_Register *plcd = (LCD_Register *)fbi->io_base;
+ DECLARE_WAITQUEUE(wait, current);
+
+ set_current_state(TASK_UNINTERRUPTIBLE);
+ add_wait_queue(&fbi->ctrlr_wait, &wait);
+
+ fbi->control &= ~0x0001;
+ plcd->Control = fbi->control;
+ faradayfb_pmu_off();
+
+ schedule_timeout(20 * HZ / 1000);
+ remove_wait_queue(&fbi->ctrlr_wait, &wait);
+}
+
+static void faradayfb_enable_int(struct fb_info *info)
+{
+ struct faradayfb_info *fbi = info->par;
+ volatile LCD_Register *plcd = (LCD_Register *)fbi->io_base;
+
+ plcd->INTREnable = fbi->int_mask;
+}
+
+static void faradayfb_disable_int(struct fb_info *info)
+{
+ struct faradayfb_info *fbi = info->par;
+ volatile LCD_Register *plcd = (LCD_Register *)fbi->io_base;
+
+ fbi->int_mask = plcd->INTREnable;
+ plcd->INTREnable = 0;
+ plcd->Status = 0x1e;
+}
+
+static struct faradayfb_rgb def_rgb_8 = {
+
+ .red = { .offset = 0, .length = 4 },
+ .green = { .offset = 0, .length = 4 },
+ .blue = { .offset = 0, .length = 4 },
+ .transp = { .offset = 0, .length = 0 },
+};
+
+static struct faradayfb_rgb def_rgb_16 = {
+
+ .red = { .offset = 11, .length = 5, .msb_right = 0 },
+ .green = { .offset = 5, .length = 6, .msb_right = 0 },
+ .blue = { .offset = 0, .length = 5, .msb_right = 0 },
+ .transp = { .offset = 15, .length = 0, .msb_right = 0 },
+};
+
+static struct faradayfb_rgb def_rgb_24 = {
+
+ .red = { .offset = 16, .length = 8, .msb_right = 0 },
+ .green = { .offset = 8, .length = 8, .msb_right = 0 },
+ .blue = { .offset = 0, .length = 8, .msb_right = 0 },
+ .transp = { .offset = 0, .length = 0, .msb_right = 0 },
+};
+
+static inline void faradayfb_schedule_work(struct fb_info *info, unsigned int state)
+{
+ struct faradayfb_info *fbi = info->par;
+ unsigned long flags;
+
+ local_irq_save(flags);
+
+ /*
+ * We need to handle two requests being made at the same time.
+ * There are two important cases:
+ * 1. When we are changing VT (C_REENABLE) while unblanking (C_ENABLE)
+ * We must perform the unblanking, which will do our REENABLE for us.
+ * 2. When we are blanking, but immediately unblank before we have
+ * blanked. We do the "REENABLE" thing here as well, just to be sure.
+ */
+ if (fbi->task_state == C_ENABLE && state == C_REENABLE)
+ state = (unsigned int) - 1;
+
+ if (fbi->task_state == C_DISABLE && state == C_ENABLE)
+ state = C_REENABLE;
+
+ if (state != (unsigned int) - 1) {
+
+ fbi->task_state = state;
+ schedule_work(&fbi->task);
+ }
+
+ local_irq_restore(flags);
+}
+
+static int faradayfb_setpalettereg(unsigned int regno, unsigned int red,
+ unsigned int green, unsigned int blue, unsigned int trans,
+ struct fb_info *info)
+{
+ struct faradayfb_info *fbi = info->par;
+
+ if (regno < fbi->palette_size) {
+
+ fbi->palette_cpu[regno] = ((red >> 0) & (0x1fUL << 11)) |
+ ((green >> 5) & (0x3F << 5)) |
+ ((blue >> 11) & (0x1f << 0));
+
+ return 0;
+ }
+
+ return 1;
+}
+
+static int faradayfb_setcolreg(unsigned int regno, unsigned int red, unsigned int green,
+ unsigned int blue, unsigned int trans, struct fb_info *info)
+{
+ struct faradayfb_info *fbi = info->par;
+ int ret = 1;
+ /*
+ * If inverse mode was selected, invert all the colours
+ * rather than the register number. The register number
+ * is what you poke into the framebuffer to produce the
+ * colour you requested.
+ */
+ if (fbi->cmap_inverse) {
+
+ red = 0xffff - red;
+ green = 0xffff - green;
+ blue = 0xffff - blue;
+ }
+
+ /*
+ * If greyscale is true, then we convert the RGB value
+ * to greyscale no mater what visual we are using.
+ */
+ if (info->var.grayscale)
+ red = green = blue = (19595 * red + 38470 * green + 7471 * blue) >> 16;
+
+ switch(info->fix.visual) {
+
+ case FB_VISUAL_TRUECOLOR:
+ /*
+ * 12 or 16-bit True Colour. We encode the RGB value
+ * according to the RGB bitfield information.
+ */
+ if (regno < 16) {
+
+ u32 col;
+ red >>= (16 - info->var.red.length);
+ green >>= (16 - info->var.green.length);
+ blue >>= (16 - info->var.blue.length);
+ col = (red << info->var.red.offset) |
+ (green << info->var.green.offset) |
+ (blue << info->var.blue.offset) ;
+
+ switch(info->var.bits_per_pixel) {
+
+ /* is the following code correct?? */
+ case 16:
+ case 32:
+ ((u32 *)(info->pseudo_palette))[regno] = col;
+ ret=0;
+ break;
+ }
+ }
+ break;
+
+ case FB_VISUAL_STATIC_PSEUDOCOLOR:
+ case FB_VISUAL_PSEUDOCOLOR:
+ if (fbi->smode == FFB_MODE_RGB)
+ ret = faradayfb_setpalettereg(regno, red, green, blue, trans, info);
+ break;
+ }
+
+ return ret;
+}
+
+/*
+ * Round up in the following order: bits_per_pixel, xres,
+ * yres, xres_virtual, yres_virtual, xoffset, yoffset, grayscale,
+ * bitfields, horizontal timing, vertical timing.
+ */
+static int faradayfb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
+{
+ struct faradayfb_info *fbi = info->par;
+ int rgbidx;
+
+ var->xres = min(var->xres, (unsigned int)MIN_XRES);
+ var->yres = min(var->yres, (unsigned int)MIN_YRES);
+ var->xres = max(var->xres, fbi->xres);
+ var->yres = max(var->yres, fbi->yres);
+ var->xres_virtual = max(var->xres_virtual, var->xres);
+ var->yres_virtual = max(var->yres_virtual, var->yres);
+
+ DEBUG(0, 1, "var->bits_per_pixel = %d\n", var->bits_per_pixel);
+
+ switch (var->bits_per_pixel) {
+
+ case 1: case 2: case 4: case 8:
+ rgbidx = RGB_8;
+ break;
+
+ case 16:
+ rgbidx = RGB_16;
+ break;
+
+ case 32:
+ rgbidx = RGB_24;
+ break;
+
+ default:
+ return -EINVAL;
+ }
+
+ /*
+ * Copy the RGB parameters for this display
+ * from the machine specific parameters.
+ */
+ var->red = fbi->rgb[ rgbidx]->red;
+ var->green = fbi->rgb[ rgbidx]->green;
+ var->blue = fbi->rgb[ rgbidx]->blue;
+ var->transp = fbi->rgb[ rgbidx]->transp;
+
+ DEBUG(0, 1, "RGBT length = %d:%d:%d:%d\n",
+ var->red.length, var->green.length, var->blue.length, var->transp.length);
+
+ DEBUG(0, 1, "RGBT offset = %d:%d:%d:%d\n",
+ var->red.offset, var->green.offset, var->blue.offset, var->transp.offset);
+
+ DEBUG(0, 1, "Leave\n");
+
+ return 0;
+}
+
+/*
+ * Configures LCD Controller based on entries in var parameter. Settings are
+ * only written to the controller if changes were made.
+ */
+static int faradayfb_activate_var(struct fb_var_screeninfo *var, struct fb_info *info)
+{
+ struct faradayfb_info *fbi = info->par;
+ volatile LCD_Register *plcd = (LCD_Register *)fbi->io_base;
+
+ DEBUG(0, 1, "var: xres=%d hslen=%d lm=%d rm=%d\n", var->xres, var->hsync_len, var->left_margin, var->right_margin);
+ DEBUG(0, 1, "var: yres=%d vslen=%d um=%d bm=%d\n", var->yres, var->vsync_len, var->upper_margin, var->lower_margin);
+
+ fbi->time0 = FARADAY_LCDTIME0_HFP(var->left_margin)
+ | FARADAY_LCDTIME0_HBP(var->right_margin)
+ | FARADAY_LCDTIME0_HW(var->hsync_len)
+ | FARADAY_LCDTIME0_PL(var->xres);
+
+ fbi->time1 = FARADAY_LCDTIME1_VBP(var->upper_margin)
+ | FARADAY_LCDTIME1_VFP(var->lower_margin)
+ | FARADAY_LCDTIME1_VW(var->vsync_len)
+ | FARADAY_LCDTIME1_LF(var->yres);
+
+ if ((plcd->Timing0 != fbi->time0)
+ || (plcd->Timing1 != fbi->time1)
+ || (plcd->Timing2 != fbi->time2)
+ || (plcd->Control != fbi->control)) {
+
+ faradayfb_schedule_work(info, C_REENABLE);
+ }
+
+ return 0;
+}
+
+/* Set the user defined part of the display for the specified console */
+static int faradayfb_set_par(struct fb_info *info)
+{
+ struct faradayfb_info *fbi = info->par;
+ struct fb_var_screeninfo *var = &info->var;
+ unsigned long palette_mem_size;
+
+ if (var->bits_per_pixel == 16 || var->bits_per_pixel == 32)
+ info->fix.visual = FB_VISUAL_TRUECOLOR;
+ else if (!fbi->cmap_static)
+ info->fix.visual = FB_VISUAL_PSEUDOCOLOR;
+ else {
+ /*
+ * Some people have weird ideas about wanting static
+ * pseudocolor maps. I suspect their user space
+ * applications are broken.
+ */
+ info->fix.visual = FB_VISUAL_STATIC_PSEUDOCOLOR;
+ }
+
+ info->fix.line_length = var->xres_virtual * var->bits_per_pixel / 8;
+
+ fbi->palette_size = var->bits_per_pixel == 8 ? 256 : 16;
+
+ palette_mem_size = fbi->palette_size * sizeof(u32);
+
+ DEBUG(0, 1, "info->fix.line_length = %d\n", info->fix.line_length);
+ DEBUG(0, 1, "palette_mem_size = 0x%08lx\n", (unsigned long) palette_mem_size);
+
+ fbi->palette_cpu = (u32 *)(fbi->map_cpu + PAGE_SIZE - palette_mem_size);
+
+ fbi->palette_dma = fbi->map_dma + PAGE_SIZE - palette_mem_size;
+
+ /* Set (any) board control register to handle new color depth */
+ faradayfb_activate_var(var, info);
+
+ DEBUG(0, 1, "Leave\n");
+
+ return 0;
+}
+
+static irqreturn_t faradayfb_handle_irq(int irq, void *dev_id)
+{
+#if 0
+ struct fb_info *info = (struct fb_info*)dev_id;
+ struct faradayfb_info *fbi = info->par;
+ volatile LCD_Register *plcd = (LCD_Register *)fbi->io_base;
+ u32 status = plcd->Interrupt;
+#endif
+ return IRQ_HANDLED;
+}
+
+/*
+ * This function must be called from task context only, since it will
+ * sleep when disabling the LCD controller, or if we get two contending
+ * processes trying to alter state.
+ */
+static void set_ctrlr_state(struct fb_info *info, unsigned int state)
+{
+ struct faradayfb_info *fbi = info->par;
+ unsigned int old_state;
+
+ down(&fbi->ctrlr_sem);
+
+ old_state = fbi->state;
+
+ /* Hack around fbcon initialisation. */
+ if (old_state == C_STARTUP && state == C_REENABLE)
+ state = C_ENABLE;
+
+ switch (state) {
+ case C_DISABLE_PM:
+ case C_DISABLE:
+
+ /* Disable controller */
+ if (old_state != C_DISABLE) {
+
+ fbi->state = state;
+ faradayfb_disable_int(info);
+ faradayfb_lcd_power(info, 0);
+ // faradayfb_disable_controller(info);
+ }
+ break;
+
+ case C_REENABLE:
+ /*
+ * Re-enable the controller only if it was already
+ * enabled. This is so we reprogram the control
+ * registers.
+ */
+ if (old_state == C_ENABLE) {
+
+ faradayfb_disable_int(info);
+ faradayfb_lcd_power(info, 0);
+ faradayfb_disable_controller(info);
+
+ faradayfb_setup_gpio(info);
+ faradayfb_lcd_power(info, 1);
+ faradayfb_enable_controller(info);
+ faradayfb_enable_int(info);
+ }
+ break;
+
+ case C_ENABLE_PM:
+ /*
+ * Re-enable the controller after PM. This is not
+ * perfect - think about the case where we were doing
+ * a clock change, and we suspended half-way through.
+ */
+ if (old_state != C_DISABLE_PM)
+ break;
+ /* fall through */
+
+ case C_ENABLE:
+ /*
+ * Power up the LCD screen, enable controller, and
+ * turn on the backlight.
+ */
+ if (old_state != C_ENABLE) {
+
+ fbi->state = C_ENABLE;
+ faradayfb_setup_gpio(info);
+ faradayfb_lcd_power(info, 1);
+ faradayfb_enable_controller(info);
+ faradayfb_enable_int(info);
+ }
+ break;
+ }
+ up(&fbi->ctrlr_sem);
+}
+
+/*
+ * Blank the display by setting all palette values to zero. Note, the
+ * 12 and 16 bpp modes don't really use the palette, so this will not
+ * blank the display in all modes.
+ */
+static int faradayfb_blank(int blank, struct fb_info *info)
+{
+ struct faradayfb_info *fbi = info->par;
+ int i;
+
+ switch (blank) {
+ case FB_BLANK_POWERDOWN:
+ case FB_BLANK_VSYNC_SUSPEND:
+ case FB_BLANK_HSYNC_SUSPEND:
+ case FB_BLANK_NORMAL:
+
+ if (info->fix.visual == FB_VISUAL_PSEUDOCOLOR ||
+ info->fix.visual == FB_VISUAL_STATIC_PSEUDOCOLOR) {
+
+ for (i = 0; i < fbi->palette_size; i++)
+ faradayfb_setpalettereg(i, 0, 0, 0, 0, info);
+ }
+
+ faradayfb_schedule_work(info, C_DISABLE);
+
+ break;
+
+ case FB_BLANK_UNBLANK:
+
+ if (info->fix.visual == FB_VISUAL_PSEUDOCOLOR ||
+ info->fix.visual == FB_VISUAL_STATIC_PSEUDOCOLOR)
+ fb_set_cmap(&info->cmap, info);
+
+ faradayfb_schedule_work(info, C_ENABLE);
+
+ break;
+ }
+
+ return 0;
+}
+
+/*
+ * Our LCD controller task (which is called when we blank or unblank)
+ * via keventd.
+ */
+static void faradayfb_task(struct work_struct *dummy)
+{
+ struct faradayfb_info *fbi = container_of(dummy, struct faradayfb_info, task);
+ struct fb_info *info = fbi->info;
+ unsigned int state;
+
+ state = xchg(&fbi->task_state, -1);
+ set_ctrlr_state(info, state);
+}
+
+/* Fake monspecs to fill in fbinfo structure */
+static struct fb_monspecs monspecs = {
+
+ .hfmin = 30000,
+ .hfmax = 70000,
+ .vfmin = 50,
+ .vfmax = 65,
+};
+
+static int ffb_get_mach_param(struct faradayfb_mach_info *inf, struct fb_info *info, unsigned long smode)
+{
+ struct faradayfb_info *fbi = info->par;
+ struct lcd_param *tparam;
+ unsigned long bpp_mode;
+
+ if (!(tparam = get_lcd_time(inf->time0, inf->num_time0, smode)))
+ return -1;
+
+ fbi->time0 = tparam->value;
+
+ if (!(tparam = get_lcd_time(inf->time1, inf->num_time1, smode)))
+ return -1;
+
+ fbi->time1 = tparam->value;
+
+ if (!(tparam = get_lcd_time(inf->time2, inf->num_time2, smode)))
+ return -1;
+
+ fbi->time2 = tparam->value;
+
+ switch(info->var.bits_per_pixel) {
+
+ case 1: case 2: case 4: case 8:
+ bpp_mode = FFB_MODE_8BPP;
+ break;
+
+ case 16:
+ bpp_mode = FFB_MODE_16BPP;
+ break;
+
+ case 32:
+ bpp_mode = FFB_MODE_24BPP;
+ break;
+
+ default:
+ DEBUG(1, 1, "Unsupported BPP, set default BPP to 16\n");
+ bpp_mode = FFB_MODE_16BPP;
+ break;
+ }
+
+ if (!(tparam = get_lcd_ctrl(inf->control, inf->num_control, smode | bpp_mode)))
+ return -1;
+
+ fbi->control = tparam->value;
+
+ fbi->xres = inf->xres;
+ fbi->yres = inf->yres;
+
+ return 0;
+}
+
+static int faradayfb_set_var(struct fb_info *info, struct faradayfb_mach_info *inf, unsigned long type)
+{
+ struct faradayfb_info *fbi = info->par;
+ unsigned long t_smode = 0;
+
+ if (!type)
+ t_smode = fbi->smode;
+ else
+ t_smode = type;
+
+ if (ffb_get_mach_param(inf, info, t_smode)) {
+
+ DEBUG(1, 1, "Not support mode(%lx)\n", t_smode);
+ return -1;
+ }
+
+ info->var.xres = fbi->xres;
+ info->var.xres_virtual = fbi->xres;
+ info->var.yres = fbi->yres;
+ info->var.yres_virtual = fbi->yres;
+
+ info->var.upper_margin = FARADAY_LCDTIME1_GET_VBP(fbi->time1);
+ info->var.lower_margin = FARADAY_LCDTIME1_GET_VFP(fbi->time1);
+ info->var.vsync_len = FARADAY_LCDTIME1_GET_VW(fbi->time1);
+ info->var.left_margin = FARADAY_LCDTIME0_GET_HFP(fbi->time0);
+ info->var.right_margin = FARADAY_LCDTIME0_GET_HBP(fbi->time0);
+ info->var.hsync_len = FARADAY_LCDTIME0_GET_HW(fbi->time0);
+
+ fbi->int_mask = 0;
+
+ if (t_smode & FFB_MODE_YUV420)
+ fbi->frame420_size = (((info->var.xres * info->var.yres + 0xffff) & 0xffff0000) >> 16) << 2;
+ else
+ fbi->frame420_size = 0;
+
+ return 0;
+}
+
+static struct fb_ops faradayfb_ops = {
+
+ .owner = THIS_MODULE,
+ .fb_check_var = faradayfb_check_var,
+ .fb_set_par = faradayfb_set_par,
+ .fb_setcolreg = faradayfb_setcolreg,
+ .fb_fillrect = cfb_fillrect,
+ .fb_copyarea = cfb_copyarea,
+ .fb_imageblit = cfb_imageblit,
+ .fb_blank = faradayfb_blank,
+ .fb_mmap = faradayfb_mmap,
+ .fb_ioctl = faradayfb_ioctl,
+};
+
+static struct fb_info * __init faradayfb_init_fbinfo(struct device *dev)
+{
+ struct faradayfb_mach_info *inf;
+ struct fb_info *info;
+ struct faradayfb_info *fbi;
+
+ if (!(info = framebuffer_alloc(sizeof(struct faradayfb_info), dev)))
+ return NULL;
+
+ fbi = info->par;
+ fbi->info = info;
+
+ fbi->io_base = LCD_FTLCDC100_0_VA_BASE;
+ strcpy(info->fix.id, FARADAYFB_MODULE_NAME);
+
+ info->fix.type = FB_TYPE_PACKED_PIXELS;
+ info->fix.type_aux = 0;
+ info->fix.xpanstep = 0;
+ info->fix.ypanstep = 0;
+ info->fix.ywrapstep = 0;
+ info->fix.accel = FB_ACCEL_NONE;
+
+ info->var.nonstd = 0;
+ info->var.activate = FB_ACTIVATE_NOW;
+ info->var.height = -1;
+ info->var.width = -1;
+ info->var.accel_flags = 0;
+ info->var.vmode = FB_VMODE_NONINTERLACED;
+
+ info->fbops = &faradayfb_ops;
+ info->flags = FBINFO_DEFAULT;
+ info->monspecs = monspecs;
+ info->pseudo_palette = &faradayfb_pseudo_palette;
+
+ fbi->rgb[RGB_8] = &def_rgb_8;
+ fbi->rgb[RGB_16] = &def_rgb_16;
+ fbi->rgb[RGB_24] = &def_rgb_24;
+
+ inf = (struct faradayfb_mach_info*)dev->platform_data;
+
+ /*
+ * People just don't seem to get this. We don't support
+ * anything but correct entries now, so panic if someone
+ * does something stupid.
+ */
+
+ fbi->xres = inf->xres;
+ fbi->yres = inf->yres;
+ fbi->max_bpp = 32;
+#if defined(CONFIG_FFB_MODE_8BPP)
+ info->var.bits_per_pixel = min((u32)8, inf->max_bpp);
+#elif defined(CONFIG_FFB_MODE_16BPP)
+ info->var.bits_per_pixel = min((u32)16, inf->max_bpp);
+#elif defined(CONFIG_FFB_MODE_24BPP)
+ info->var.bits_per_pixel = min((u32)32, inf->max_bpp);
+ info->var.bits_per_pixel = 32;
+#endif
+
+ info->var.pixclock = inf->pixclock;
+ info->var.sync = inf->sync;
+ info->var.grayscale = inf->cmap_greyscale;
+ fbi->cmap_inverse = inf->cmap_inverse;
+ fbi->cmap_static = inf->cmap_static;
+
+ fbi->smode = FFB_DEFAULT_MODE;
+
+ if (faradayfb_set_var(info, inf, 0))
+ goto err;
+
+ fbi->state = C_STARTUP;
+ fbi->task_state = (unsigned char) - 1;
+ info->fix.smem_len = faradayfb_cal_frame_buf_size(fbi);
+
+ init_waitqueue_head(&fbi->ctrlr_wait);
+ INIT_WORK(&fbi->task, faradayfb_task);
+ init_MUTEX(&fbi->ctrlr_sem);
+
+ return info;
+err:
+ kfree(fbi);
+ kfree(info);
+
+ return NULL;
+}
+
+static int faradayfb_probe(struct platform_device *pdev)
+{
+ struct fb_info *info;
+ struct faradayfb_info *fbi;
+ int irq;
+ int ret = 0;
+
+ ret = -ENOMEM;
+
+ if (!(info = faradayfb_init_fbinfo(&pdev->dev))) {
+
+ DEBUG(1, 1, "unable to allocate memory for device info\n");
+ goto err_exit;
+ }
+
+ fbi = info->par;
+
+ /* Initialize video memory */
+ if ((ret = faradayfb_map_video_memory(info)) < 0)
+ goto err_free_mem;
+
+ ret = -EINVAL;
+
+ if ((irq = platform_get_irq(pdev, 0)) <= 0)
+ goto err_free_map;
+
+ if (request_irq(irq, faradayfb_handle_irq, IRQF_DISABLED, "LCD", info)) {
+
+ DEBUG(1, 1, "request_irq failed: %d\n", ret);
+ goto err_free_map;
+ }
+
+ /*
+ * This makes sure that our colour bitfield
+ * descriptors are correctly initialised.
+ */
+ faradayfb_check_var(&info->var, info);
+ faradayfb_set_par(info);
+
+ dev_set_drvdata(&pdev->dev, info);
+
+// <============================================
+ if ((ret = register_framebuffer(info)) < 0) {
+
+ DEBUG(1, 1, "register_framebuffer failed\n");
+ goto err_free_irq;
+ }
+// <============================================
+
+ faradayfb_clean_screen(info);
+
+ return 0;
+
+err_free_irq:
+ dev_set_drvdata(&pdev->dev, NULL);
+ free_irq(irq, info);
+err_free_map:
+ faradayfb_unmap_video_memory(info);
+err_free_mem:
+ kfree(info->par);
+ kfree(info);
+err_exit:
+ return ret;
+}
+
+/* Called when the device is being detached from the driver */
+static int faradayfb_remove(struct platform_device *pdev)
+{
+ struct fb_info *info = platform_get_drvdata(pdev);
+ int irq;
+
+ set_ctrlr_state(info, C_DISABLE);
+
+ irq = platform_get_irq(pdev, 0);
+ free_irq(irq, info);
+
+ unregister_framebuffer(info);
+ faradayfb_unmap_video_memory(info);
+ dev_set_drvdata(&pdev->dev, NULL);
+ kfree(info->par);
+ kfree(info);
+
+ return 0;
+}
+
+#ifdef CONFIG_PM
+
+/* suspend and resume support for the lcd controller */
+static int faradayfb_suspend(struct platform_device *pdev, pm_message_t mesg)
+{
+ struct fb_info *info = platform_get_drvdata(pdev);
+
+ // if (level == SUSPEND_DISABLE || level == SUSPEND_POWER_DOWN)
+ if (mesg.event == PM_EVENT_PRETHAW || mesg.event & PM_EVENT_SLEEP)
+ set_ctrlr_state(info, C_DISABLE_PM);
+
+ return 0;
+}
+
+static int faradayfb_resume(struct platform_device *pdev)
+{
+ struct fb_info *info = platform_get_drvdata(pdev);
+
+ // need modify
+ // if (level == RESUME_ENABLE)
+ set_ctrlr_state(info, C_ENABLE_PM);
+
+ return 0;
+}
+
+#else
+#define faradayfb_suspend NULL
+#define faradayfb_resume NULL
+#endif
+
+static struct resource faradayfb_resource[] = {
+
+ {
+ .start = LCD_FTLCDC100_0_PA_BASE,
+ .end = LCD_FTLCDC100_0_PA_LIMIT,
+ .flags = IORESOURCE_MEM,
+ },
+ {
+ .start = LCD_FTLCDC100_0_IRQ,
+ .end = LCD_FTLCDC100_0_IRQ,
+ .flags = IORESOURCE_IRQ,
+ }
+};
+
+static u64 faradayfb_dmamask = ~(u32)0;
+
+static struct platform_device faradayfb_device = {
+
+ .name = "faraday-lcd",
+ .id = -1,
+ .num_resources = ARRAY_SIZE(faradayfb_resource),
+ .resource = faradayfb_resource,
+ .dev = {
+
+ .platform_data = &ffb_mach_info,
+ .dma_mask = &faradayfb_dmamask,
+ .coherent_dma_mask = 0xffffffff,
+ }
+};
+
+static struct platform_driver faradayfb_driver = {
+ .probe = faradayfb_probe,
+ .remove = faradayfb_remove,
+ .suspend = faradayfb_suspend,
+ .resume = faradayfb_resume,
+ .driver = {
+ .name = "faraday-lcd",
+ },
+};
+
+/*
+rick note faraday driver
+*/
+
+/* Register both the driver and the device */
+int __init faradayfb_init(void)
+{
+ int ret = 0;
+ /* Register the device with LDM */
+
+#if 1
+ if (platform_device_register(&faradayfb_device)) {
+
+ DEBUG(1, 1, "failed to register faradayfb device\n");
+ ret = -ENODEV;
+ goto exit;
+ }
+#endif
+ /* Register the driver with LDM */
+ if (platform_driver_register(&faradayfb_driver)) {
+
+ DEBUG(1, 1, "failed to register faradayfb driver\n");
+ platform_device_unregister(&faradayfb_device);
+ ret = -ENODEV;
+ goto exit;
+ }
+exit:
+ return ret;
+}
+
+static void __exit faradayfb_cleanup(void)
+{
+ platform_driver_unregister(&faradayfb_driver);
+ platform_device_unregister(&faradayfb_device);
+}
+
+module_init(faradayfb_init);
+module_exit(faradayfb_cleanup);
+MODULE_DESCRIPTION("Faraday LCD driver");
+MODULE_AUTHOR("Francis Huang <francish@faraday-tech.com>");
+MODULE_LICENSE("GPL");
diff -Nur linux-3.4.113.orig/drivers/video/FTLCDC100/Kconfig linux-3.4.113/drivers/video/FTLCDC100/Kconfig
--- linux-3.4.113.orig/drivers/video/FTLCDC100/Kconfig 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/drivers/video/FTLCDC100/Kconfig 2016-12-01 20:59:24.392614293 +0100
@@ -0,0 +1,74 @@
+config FB_FTLCDC100
+ tristate "Faraday FTLCDC100 driver"
+ depends on FB && NDS32
+ select FB_CFB_FILLRECT
+ select FB_CFB_COPYAREA
+ select FB_CFB_IMAGEBLIT
+
+ choice
+ prompt "Default LCD Panel"
+ depends on FB_FTLCDC100
+ default PANEL_AUA036QN01
+ help
+ This option select a default panel setting for the LCD controller
+
+ config PANEL_AUA036QN01
+ bool "AU 3.5 inch LCD Panel"
+
+ config PANEL_CH7013A
+ bool "Chrontel Digital PC to TV Encoder"
+ select I2C
+ select I2C_FARADAY
+ select CH7013A
+
+ config PANEL_AUA070VW04
+ bool "AU 7.0 inch LCD Panel"
+
+ config PANEL_LW500AC9601
+ bool "CHIMEI 5.0 inch LCD panel"
+
+ endchoice
+
+ # config FTLCD_OSD
+ # bool "Enable OSD (On Screen Display)"
+ # depends on FB_FTLCDC100
+ # default n
+ # ---help---
+ # This enables access to the OSD (On Screen Display) for Faraday
+ # FTLCDC100 LCD control. Disabling OSD will reduce the size of
+ # the kernel by approximately 6kb.
+ #
+
+ choice
+ prompt "Default Color Mode"
+ depends on FB_FTLCDC100
+ default FFB_MODE_RGB
+ help
+ This option select default color mode
+
+ config FFB_MODE_RGB
+ bool "RGB Mode"
+ config FFB_MODE_YUV422
+ bool "YUV422 Mode"
+ config FFB_MODE_YUV420
+ bool "YUV420 Mode"
+ endchoice
+
+ choice
+ prompt "Default BPP"
+ depends on FB_FTLCDC100
+ default FFB_MODE_16BPP
+ help
+ This option select default BPP (bits-per-pixel)
+
+ config FFB_MODE_8BPP
+ depends on FFB_MODE_RGB || FFB_MODE_YUV420
+ bool "8 bits-per-pixel"
+ config FFB_MODE_16BPP
+ depends on FFB_MODE_RGB || FFB_MODE_YUV422
+ bool "16 bits-per-pixel"
+ config FFB_MODE_24BPP
+ depends on FFB_MODE_RGB
+ bool "24 bits-per-pixel"
+ endchoice
+
diff -Nur linux-3.4.113.orig/drivers/video/FTLCDC100/lcd-info.c linux-3.4.113/drivers/video/FTLCDC100/lcd-info.c
--- linux-3.4.113.orig/drivers/video/FTLCDC100/lcd-info.c 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/drivers/video/FTLCDC100/lcd-info.c 2016-12-01 20:59:24.392614293 +0100
@@ -0,0 +1,264 @@
+/*
+ * HBP : Horizontal Back Porch
+ * HFP : Horizontal Front Porch
+ * HSPW: Horizontal Sync. Pulse Width
+ * PPL : Pixels-per-line = 16(PPL+1)
+ */
+#define ENC_PARAM_TIME0(HBP, HFP, HSPW, PPL) \
+ ((((HBP) - 1) << 24) | \
+ (((HFP) - 1) << 16) | \
+ (((HSPW) - 1) << 8 ) | \
+ ((((PPL) >> 4) - 1) << 2 ))
+
+/*
+ * HBP : Vertical Back Porch
+ * HFP : Vertical Front Porch
+ * HSPW: Vertical Sync. Pulse Width
+ * LPP : Lines-per-panel = LPP + 1
+ */
+#define ENC_PARAM_TIME1(VBP, VFP, VSPW, LPP) \
+ ((((VBP) ) << 24) | \
+ (((VFP) ) << 16) | \
+ (((VSPW) - 1) << 10) | \
+ (((LPP) - 1) ))
+
+/*
+ * PRA : Pixel Rate Adaptive
+ * IOE : Invert Panel Output Enable
+ * IPC : Invert Panel Clock (Test Chip Testing)
+ * IHS : Invert Horisontal Sync.
+ * IVS : Invert Versical Sync.
+ * PCD : Panel Clock Divisor
+ */
+#define ENC_PARAM_TIME2(PRA, IOE, IPC, IHS, IVS, PCD) \
+ (((PRA) << 15) | \
+ ((IOE) << 14) | \
+ ((IPC) << 13) | \
+ ((IHS) << 12) | \
+ ((IVS) << 11) | \
+ (((PCD) - 1) ))
+
+/*
+ * Enable YCbCr
+ * Enable YCbCr420
+ * FIFO threadhold
+ * Panel type, 0-6bit, 1-8bit
+ * LcdVComp, when to generate interrupt, 1: start of back_porch
+ * Power Enable
+ * Big Endian Pixel/Byte Ordering
+ * BGR
+ * TFT
+ * LCD bits per pixel
+ * Controller Enable
+ */
+
+#define ENC_PARAM_CTRL(ENYUV, ENYUV420, FIFOTH, PTYPE, VCOMP, LCD_ON, ENDIAN, BGR, TFT, BPP, LCD_EN) \
+ ((ENYUV << 18) | \
+ (ENYUV420 << 17) | \
+ (FIFOTH << 16) | \
+ (PTYPE << 15) | \
+ (VCOMP << 12) | \
+ (LCD_ON << 11) | \
+ (ENDIAN << 9) | \
+ (BGR << 8) | \
+ (TFT << 5) | \
+ (BPP << 1) | \
+ (LCD_EN))
+
+static struct lcd_param control[] = {
+
+ {
+ .value = ENC_PARAM_CTRL(0, 0, 1, 1, 0x3, 1, 0x0, 1, 1, 0x3, 1),
+ .flags = FFB_MODE_RGB | FFB_MODE_8BPP,
+ },
+ {
+ .value = ENC_PARAM_CTRL(1, 1, 1, 1, 0x3, 1, 0x0, 0, 1, 0x3, 1),
+ .flags = FFB_MODE_YUV420 | FFB_MODE_8BPP,
+ },
+ {
+ .value = ENC_PARAM_CTRL(1, 0, 1, 1, 0x3, 1, 0x0, 0, 1, 0x4, 1),
+ .flags = FFB_MODE_YUV422 | FFB_MODE_16BPP,
+ },
+ {
+ .value = ENC_PARAM_CTRL(0, 0, 1, 1, 0x3, 1, 0x0, 1, 1, 0x4, 1),
+ .flags = FFB_MODE_RGB | FFB_MODE_16BPP,
+ },
+ {
+ .value = ENC_PARAM_CTRL(0, 0, 1, 1, 0x3, 1, 0x0, 1, 1, 0x5, 1),
+ .flags = FFB_MODE_RGB | FFB_MODE_24BPP,
+ },
+};
+
+#ifdef CONFIG_PANEL_AUA036QN01
+
+static struct lcd_param time0[] = {
+
+ {
+ .value = ENC_PARAM_TIME0(7, 6, 1, 320),
+ .flags = FFB_MODE_RGB | FFB_MODE_YUV420 | FFB_MODE_YUV422,
+ },
+};
+
+static struct lcd_param time1[] = {
+
+ {
+ .value = ENC_PARAM_TIME1(1, 1, 1, 240),
+ .flags = FFB_MODE_RGB | FFB_MODE_YUV420 | FFB_MODE_YUV422,
+ },
+};
+
+static struct lcd_param time2[] = {
+
+ {
+ .value = ENC_PARAM_TIME2(0, 0, 1, 1, 1, 0x7),
+ .flags = FFB_MODE_RGB | FFB_MODE_YUV420 | FFB_MODE_YUV422,
+ },
+};
+
+static struct faradayfb_mach_info ffb_mach_info = {
+
+ .pixclock = 171521,
+ .xres = 320,
+ .yres = 240,
+ .max_bpp = 24,
+ .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
+ .num_time0 = ARRAY_SIZE(time0),
+ .time0 = time0,
+ .num_time1 = ARRAY_SIZE(time1),
+ .time1 = time1,
+ .num_time2 = ARRAY_SIZE(time2),
+ .time2 = time2,
+ .num_control = ARRAY_SIZE(control),
+ .control = control,
+};
+#endif
+
+#ifdef CONFIG_PANEL_AUA070VW04
+static struct lcd_param time0[] = {
+
+ {
+ .value = ENC_PARAM_TIME0(88, 40, 128, 800),
+ .flags = FFB_MODE_RGB | FFB_MODE_YUV420 | FFB_MODE_YUV422,
+ },
+};
+
+static struct lcd_param time1[] = {
+
+ {
+ .value = ENC_PARAM_TIME1(21, 1, 3, 480),
+ .flags = FFB_MODE_RGB | FFB_MODE_YUV420 | FFB_MODE_YUV422,
+ },
+};
+
+static struct lcd_param time2[] = {
+
+ {
+ .value = ENC_PARAM_TIME2(0, 1, 1, 1, 1, 0x5),
+ .flags = FFB_MODE_RGB | FFB_MODE_YUV420 | FFB_MODE_YUV422,
+ },
+};
+
+static struct faradayfb_mach_info ffb_mach_info = {
+
+ .pixclock = 171521,
+ .xres = 800,
+ .yres = 480,
+ .max_bpp = 24,
+ .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
+ .num_time0 = ARRAY_SIZE(time0),
+ .time0 = time0,
+ .num_time1 = ARRAY_SIZE(time1),
+ .time1 = time1,
+ .num_time2 = ARRAY_SIZE(time2),
+ .time2 = time2,
+ .num_control = ARRAY_SIZE(control),
+ .control = control,
+};
+
+#endif
+
+#ifdef CONFIG_PANEL_LW500AC9601
+static struct lcd_param time0[] = {
+
+ {
+ .value = ENC_PARAM_TIME0(88, 40, 128, 800),
+ .flags = FFB_MODE_RGB | FFB_MODE_YUV420 | FFB_MODE_YUV422,
+ },
+};
+
+static struct lcd_param time1[] = {
+
+ {
+ .value = ENC_PARAM_TIME1(21, 1, 3, 480),
+ .flags = FFB_MODE_RGB | FFB_MODE_YUV420 | FFB_MODE_YUV422,
+ },
+};
+
+static struct lcd_param time2[] = {
+
+ {
+ .value = ENC_PARAM_TIME2( 0, 0, 1, 1, 1, 0x3),
+ .flags = FFB_MODE_RGB | FFB_MODE_YUV420 | FFB_MODE_YUV422,
+ },
+};
+
+static struct faradayfb_mach_info ffb_mach_info = {
+
+ .pixclock = 171521,
+ .xres = 800,
+ .yres = 480,
+ .max_bpp = 24,
+ .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
+ .num_time0 = ARRAY_SIZE(time0),
+ .time0 = time0,
+ .num_time1 = ARRAY_SIZE(time1),
+ .time1 = time1,
+ .num_time2 = ARRAY_SIZE(time2),
+ .time2 = time2,
+ .num_control = ARRAY_SIZE(control),
+ .control = control,
+};
+#endif
+
+#ifdef CONFIG_CH7013A
+static struct lcd_param time0[] = {
+
+ {
+ .value = ENC_PARAM_TIME0(42, 10, 96, 640),
+ .flags = FFB_MODE_RGB,
+ },
+};
+
+static struct lcd_param time1[] = {
+
+ {
+ .value = ENC_PARAM_TIME1(28, 5, 2, 480),
+ .flags = FFB_MODE_RGB,
+ },
+};
+static struct lcd_param time2[] = {
+
+ {
+ .value = ENC_PARAM_TIME2(0, 1, 1, 0, 0, 0x3),
+ .flags = FFB_MODE_RGB,
+ },
+};
+
+static struct faradayfb_mach_info ffb_mach_info = {
+
+ .pixclock = 37910,
+ .xres = 640,
+ .yres = 480,
+ .max_bpp = 24,
+ .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
+ .num_time0 = ARRAY_SIZE(time0),
+ .time0 = time0,
+ .num_time1 = ARRAY_SIZE(time1),
+ .time1 = time1,
+ .num_time2 = ARRAY_SIZE(time2),
+ .time2 = time2,
+ .num_control = ARRAY_SIZE(control),
+ .control = control,
+};
+
+#endif /* CONFIG_CH7013A */
diff -Nur linux-3.4.113.orig/drivers/video/FTLCDC100/Makefile linux-3.4.113/drivers/video/FTLCDC100/Makefile
--- linux-3.4.113.orig/drivers/video/FTLCDC100/Makefile 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/drivers/video/FTLCDC100/Makefile 2016-12-01 20:59:24.392614293 +0100
@@ -0,0 +1 @@
+obj-$(CONFIG_FB_FTLCDC100) += faradayfb-main.o
diff -Nur linux-3.4.113.orig/drivers/video/FTLCDC100/pingpong-module.c linux-3.4.113/drivers/video/FTLCDC100/pingpong-module.c
--- linux-3.4.113.orig/drivers/video/FTLCDC100/pingpong-module.c 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/drivers/video/FTLCDC100/pingpong-module.c 2016-12-01 20:59:24.392614293 +0100
@@ -0,0 +1,592 @@
+void *fmem_alloc(size_t size, dma_addr_t *dma_handle, unsigned long flags)
+{
+ struct page *page;
+ void *cpu_addr = NULL;
+
+ size = PAGE_ALIGN(size);
+
+ if (!(page = alloc_pages(GFP_DMA, get_order(size)))) {
+
+ DEBUG(1, 1, "alloc_pages fail! (requested %#x)", size);
+ goto no_page;
+ }
+
+ *dma_handle = page_to_phys(page);
+
+ if ((cpu_addr = __ioremap(*dma_handle, size, flags, 1))) {
+
+ do {
+ SetPageReserved(page);
+ page++;
+ } while (size -= PAGE_SIZE);
+ }
+ else {
+ __free_pages(page, get_order(size));
+ DEBUG(1, 1, "__ioremap fail! (phy %#x)", *dma_handle);
+ }
+no_page:
+ return cpu_addr;
+}
+
+void fmem_free(size_t size, void *cpu_addr, dma_addr_t handle)
+{
+ struct page *page = pfn_to_page(handle >> PAGE_SHIFT);
+
+ __iounmap(cpu_addr);
+ size = PAGE_ALIGN(size);
+
+ do {
+ ClearPageReserved(page);
+ __free_page(page);
+ page++;
+
+ } while (size -= PAGE_SIZE);
+}
+
+static int faradayfb_mmap(struct fb_info *info, struct vm_area_struct *vma)
+{
+ struct faradayfb_info *fbi = info->par;
+ unsigned long off = vma->vm_pgoff << PAGE_SHIFT;
+ int ret = -EINVAL;
+
+ DEBUG(0, 1, "Enter\n");
+
+ if (off < info->fix.smem_len) {
+
+ off += fbi->screen_dma & PAGE_MASK;
+ vma->vm_pgoff = off >> PAGE_SHIFT;
+ vma->vm_page_prot = pgprot_writecombine(vma->vm_page_prot);
+ vma->vm_flags |= VM_RESERVED;
+ ret = remap_pfn_range(vma, vma->vm_start, vma->vm_pgoff,
+ vma->vm_end - vma->vm_start, vma->vm_page_prot);
+ }
+ else {
+ DEBUG(1, 1, "buffer mapping error !!\n");
+ }
+
+ DEBUG(0, 1, "Leave\n");
+
+ return ret;
+}
+
+/*
+ * Allocates the DRAM memory for the frame buffer. This buffer is
+ * remapped into a non-cached, non-buffered, memory region to
+ * allow palette and pixel writes to occur without flushing the
+ * cache. Once this area is remapped, all virtual memory
+ * access to the video memory should occur at the new region.
+ */
+static int __init faradayfb_map_video_memory(struct fb_info *info)
+{
+ struct faradayfb_info *fbi = info->par;
+
+ /*
+ * We reserve one page for the palette, plus the size
+ * of the framebuffer.
+ */
+ fbi->map_size = PAGE_ALIGN(info->fix.smem_len + PAGE_SIZE);
+
+ fbi->map_cpu = fmem_alloc(fbi->map_size, &fbi->map_dma, pgprot_writecombine(PAGE_KERNEL));
+ // fbi->map_cpu = dma_alloc_writecombine(fbi->info->dev, fbi->map_size, &fbi->map_dma, GFP_KERNEL);
+
+ if (fbi->map_cpu) {
+
+ memset(fbi->map_cpu, 0x1d, fbi->map_size);
+ info->screen_base = fbi->map_cpu + PAGE_SIZE;
+ fbi->screen_dma = fbi->map_dma + PAGE_SIZE;
+ info->fix.smem_start = fbi->screen_dma;
+ }
+
+ return fbi->map_cpu ? 0 : -ENOMEM;
+}
+
+static inline void faradayfb_clean_screen(struct fb_info *info)
+{
+ struct faradayfb_info *fbi = info->par;
+ int size = info->var.xres * info->var.yres;
+
+ if (fbi->smode & FFB_MODE_YUV422) {
+
+ memset(fbi->map_cpu, 16, size * info->var.bits_per_pixel / 8);
+ }
+ else if (fbi->smode & FFB_MODE_YUV420) {
+
+ memset(fbi->map_cpu, 16, size);
+ memset(fbi->map_cpu + PAGE_SIZE + ((size + 0xffff) & 0xffff0000), 128, size / 4);
+ memset(fbi->map_cpu + PAGE_SIZE + ((size + 0xffff) & 0xffff0000) * 5 / 4, 128, size / 4);
+ }
+}
+
+static inline void faradayfb_unmap_video_memory(struct fb_info *info)
+{
+ struct faradayfb_info *fbi = info->par;
+ fmem_free(fbi->map_size, fbi->map_cpu, fbi->map_dma);
+}
+
+#define FRAME_SIZE_RGB(xres, yres, mbpp) ((xres) * (yres) * (mbpp) / 8)
+#define FRAME_SIZE_YUV422(xres, yres, mbpp) (((xres) * (yres) * (mbpp) / 8) * 2)
+#define FRAME_SIZE_YUV420(xres, yres, mbpp) (((((xres) * (yres) * (mbpp) / 8) + 0xffff) & 0xffff0000) * 3 / 2)
+
+static inline u32 faradayfb_cal_frame_buf_size(struct faradayfb_info *fbi)
+{
+ u32 size_rgb = FRAME_SIZE_RGB(fbi->xres, fbi->yres, fbi->max_bpp);
+ u32 size_yuv422 = FRAME_SIZE_YUV422(fbi->xres, fbi->yres, 8);
+ u32 size_yuv420 = FRAME_SIZE_YUV420(fbi->xres, fbi->yres, 8);
+
+ return max(size_rgb, max(size_yuv422, size_yuv420));
+}
+
+#ifdef CONFIG_FTLCD_OSD
+/************************************
+ * OSD
+ ***********************************/
+#define FOSD_SETPOS 0x46e1
+#define FOSD_SETDIM 0x46e2
+#define FOSD_SETSCAL 0x46e3
+#define FLCD_SET_TRANSPARENT 0x46e4
+#define FLCD_SET_STRING 0x46e5
+#define FOSD_ON 0x46e6
+#define FOSD_OFF 0x46e7
+#define FRREG 0x46e8
+#define FWREG 0x46e9
+
+#define dig_alpha (16 * 10) + (16 * 26) + (16 * 3)
+
+struct fosd_string {
+
+ unsigned int Str_row;
+ unsigned int display_mode;
+ unsigned int fg_color;
+ unsigned int bg_color;
+ unsigned char Str_OSD[30];
+};
+
+struct fosd_data {
+
+ unsigned int HPos;
+ unsigned int VPos;
+ unsigned int HDim;
+ unsigned int VDim;
+ unsigned int transparent_level;
+ unsigned int HScal;
+ unsigned int VScal;
+ struct fosd_string Str_Data[10];
+};
+
+unsigned int OSD_Font[] = {
+
+ /* 0 */
+ 0x00, 0x00, 0x00, 0x3e, 0x63, 0x67, 0x6f, 0x7b,
+ 0x73, 0x63, 0x63, 0x3e, 0x00, 0x00, 0x00, 0x00,
+
+ /* 1 */
+ 0x00, 0x00, 0x00, 0x0c, 0x1c, 0x3c, 0x0c, 0x0c,
+ 0x0c, 0x0c, 0x0c, 0x3f, 0x00, 0x00, 0x00, 0x00,
+
+ /* 2 */
+ 0x00, 0x00, 0x00, 0x3e, 0x63, 0x03, 0x06, 0x0c,
+ 0x18, 0x30, 0x63, 0x7f, 0x00, 0x00, 0x00, 0x00,
+
+ /* 3 */
+ 0x00, 0x00, 0x00, 0x3E, 0x63, 0x03, 0x03, 0x1e,
+ 0x03, 0x03, 0x63, 0x3E, 0x00, 0x00, 0x00, 0x00,
+
+ /* 4 */
+ 0x00, 0x00, 0x00, 0x06, 0x0e, 0x1e, 0x36, 0x66,
+ 0x7f, 0x06, 0x06, 0x0f, 0x00, 0x00, 0x00, 0x00,
+
+ /* 5 */
+ 0x00, 0x00, 0x00, 0x7f, 0x60, 0x60, 0x60, 0x7e,
+ 0x03, 0x03, 0x63, 0x3e, 0x00, 0x00, 0x00, 0x00,
+
+ /* 6 */
+ 0x00, 0x00, 0x00, 0x1c, 0x30, 0x60, 0x60, 0x7e,
+ 0x63, 0x63, 0x63, 0x3e, 0x00, 0x00, 0x00, 0x00,
+
+ /* 7 */
+ 0x00, 0x00, 0x00, 0x7f, 0x63, 0x03, 0x06, 0x0c,
+ 0x18, 0x18, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00,
+
+ /* 8 */
+ 0x00, 0x00, 0x00, 0x3e, 0x63, 0x63, 0x63, 0x3e,
+ 0x63, 0x63, 0x63, 0x3e, 0x00, 0x00, 0x00, 0x00,
+
+ /* 9 */
+ 0x00, 0x00, 0x00, 0x3e, 0x63, 0x63, 0x63, 0x3f,
+ 0x03, 0x03, 0x06, 0x3c, 0x00, 0x00, 0x00, 0x00,
+
+ /* A */
+ 0x00, 0x00, 0x00, 0x08, 0x1c, 0x36, 0x63, 0x63,
+ 0x7f, 0x63, 0x63, 0x63, 0x00, 0x00, 0x00, 0x00,
+
+ /* B */
+ 0x00, 0x00, 0x00, 0x7E, 0x33, 0x33, 0x33, 0x3E,
+ 0x33, 0x33, 0x33, 0x7E, 0x00, 0x00, 0x00, 0x00,
+
+ /* C */
+ 0x00, 0x00, 0x00, 0x1E, 0x33, 0x61, 0x60, 0x60,
+ 0x60, 0x61, 0x33, 0x1E, 0x00, 0x00, 0x00, 0x00,
+
+ /* D */
+ 0x00, 0x00, 0x00, 0x7c, 0x36, 0x33, 0x33, 0x33,
+ 0x33, 0x33, 0x36, 0x7C, 0x00, 0x00, 0x00, 0x00,
+
+ /* E */
+ 0x00, 0x00, 0x00, 0x7f, 0x33, 0x31, 0x34, 0x3c,
+ 0x34, 0x31, 0x33, 0x7f, 0x00, 0x00, 0x00, 0x00,
+
+ /* F */
+ 0x00, 0x00, 0x00, 0x7f, 0x33, 0x31, 0x34, 0x3c,
+ 0x34, 0x30, 0x30, 0x78, 0x00, 0x00, 0x00, 0x00,
+
+ /* G */
+ 0x00, 0x00, 0x00, 0x1E, 0x33, 0x61, 0x60, 0x60,
+ 0x6F, 0x63, 0x36, 0x7C, 0x00, 0x00, 0x00, 0x00,
+
+ /* H */
+ 0x00, 0x00, 0x00, 0x63, 0x63, 0x63, 0x64, 0x7f,
+ 0x63, 0x63, 0x63, 0x63, 0x00, 0x00, 0x00, 0x00,
+
+ /* I */
+ 0x00, 0x00, 0x00, 0x3c, 0x18, 0x18, 0x18, 0x18,
+ 0x18, 0x18, 0x18, 0x3c, 0x00, 0x00, 0x00, 0x00,
+
+ /* J */
+ 0x00, 0x00, 0x00, 0x0f, 0x06, 0x06, 0x06, 0x06,
+ 0x06, 0x66, 0x66, 0x3c, 0x00, 0x00, 0x00, 0x00,
+
+ /* K */
+ 0x00, 0x00, 0x00, 0x73, 0x33, 0x36, 0x36, 0x3c,
+ 0x36, 0x36, 0x33, 0x73, 0x00, 0x00, 0x00, 0x00,
+
+ /* L */
+ 0x00, 0x00, 0x00, 0x78, 0x30, 0x30, 0x30, 0x30,
+ 0x30, 0x31, 0x33, 0x7f, 0x00, 0x00, 0x00, 0x00,
+
+ /* M */
+ 0x00, 0x00, 0x00, 0x63, 0x77, 0x7f, 0x6b, 0x63,
+ 0x63, 0x63, 0x63, 0x63, 0x00, 0x00, 0x00, 0x00,
+
+ /* N */
+ 0x00, 0x00, 0x00, 0x63, 0x73, 0x7b, 0x7f, 0x6f,
+ 0x67, 0x63, 0x63, 0x63, 0x00, 0x00, 0x00, 0x00,
+
+ /* O */
+ 0x00, 0x00, 0x00, 0x1c, 0x36, 0x63, 0x63, 0x63,
+ 0x63, 0x63, 0x36, 0x1c, 0x00, 0x00, 0x00, 0x00,
+
+ /* P */
+ 0x00, 0x00, 0x00, 0x7e, 0x33, 0x33, 0x33, 0x3e,
+ 0x30, 0x30, 0x30, 0x78, 0x00, 0x00, 0x00, 0x00,
+
+ /* Q */
+ 0x00, 0x00, 0x00, 0x3e, 0x63, 0x63, 0x63, 0x63,
+ 0x6b, 0x6f, 0x3e, 0x06, 0x07, 0x00, 0x00, 0x00,
+
+ /* R */
+ 0x00, 0x00, 0x00, 0x7e, 0x33, 0x33, 0x33, 0x3e,
+ 0x36, 0x33, 0x33, 0x73, 0x00, 0x00, 0x00, 0x00,
+
+ /* S */
+ 0x00, 0x00, 0x00, 0x3e, 0x63, 0x63, 0x30, 0x1c,
+ 0x06, 0x63, 0x63, 0x3e, 0x00, 0x00, 0x00, 0x00,
+
+ /* T */
+ 0x00, 0x00, 0x00, 0xFF, 0x99, 0x18, 0x18, 0x18,
+ 0x18, 0x18, 0x18, 0x3c, 0x00, 0x00, 0x00, 0x00,
+
+ /* U */
+ 0x00, 0x00, 0x00, 0x63, 0x63, 0x63, 0x63, 0x63,
+ 0x63, 0x63, 0x63, 0x3e, 0x00, 0x00, 0x00, 0x00,
+
+ /* V */
+ 0x00, 0x00, 0x00, 0x63, 0x63, 0x63, 0x63, 0x63,
+ 0x63, 0x36, 0x1c, 0x08, 0x00, 0x00, 0x00, 0x00,
+
+ /* W */
+ 0x00, 0x00, 0x00, 0x63, 0x63, 0x63, 0x63, 0x63,
+ 0x6b, 0x7f, 0x77, 0x63, 0x00, 0x00, 0x00, 0x00,
+
+ /* X */
+ 0x00, 0x00, 0x00, 0x63, 0x63, 0x63, 0x36, 0x1c,
+ 0x36, 0x63, 0x63, 0x63, 0x00, 0x00, 0x00, 0x00,
+
+ /* Y */
+ 0x00, 0x00, 0x00, 0x63, 0x63, 0x63, 0x36, 0x1c,
+ 0x1c, 0x1c, 0x1c, 0x3e, 0x00, 0x00, 0x00, 0x00,
+
+ /* Z */
+ 0x00, 0x00, 0x00, 0x7f, 0x63, 0x46, 0x0c, 0x18,
+ 0x30, 0x61, 0x63, 0x7f, 0x00, 0x00, 0x00, 0x00,
+
+ /* space */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+
+ /* = */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7E, 0x00,
+ 0x00, 0x7E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+
+ /* , */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x18, 0x18, 0x18, 0x30, 0x00, 0x00, 0x00,
+};
+
+void OSD_On(struct faradayfb_info *fbi)
+{
+ REG32(fbi->io_base + 0x34) &= 0xfffffffe;
+ REG32(fbi->io_base + 0x34) |= 1;
+}
+
+void OSD_Off(struct faradayfb_info *fbi)
+{
+ REG32(fbi->io_base + 0x34) &= 0xfffffffe;
+}
+
+void OSD_Pos(struct faradayfb_info *fbi, int HPos, int VPos)
+{
+ REG32(fbi->io_base + 0x38) = (HPos << 10) | VPos;
+}
+
+void OSD_Dim(struct faradayfb_info *fbi, int HDim, int VDim)
+{
+ REG32(fbi->io_base + 0x34) &= 0x0000001f;
+ REG32(fbi->io_base + 0x34) |= ((HDim << 10) | (VDim << 5));
+}
+
+void OSD_transparent(struct faradayfb_info *fbi, int level)
+{
+ REG32(fbi->io_base + 0x40) &= 0xffffff00;
+ REG32(fbi->io_base + 0x40) |= (level << 6);
+}
+
+void OSD_fg_color(struct faradayfb_info *fbi, int pal0, int pal1, int pal2, int pal3)
+{
+ REG32(fbi->io_base + 0x3c) = (pal0) | (pal1 << 8) | (pal2 << 16) | (pal3<< 24);
+}
+
+void OSD_bg_color(struct faradayfb_info *fbi, int pal1, int pal2, int pal3)
+{
+ REG32(fbi->io_base + 0x40) &= 0x000000ff;
+ REG32(fbi->io_base + 0x40) |= (pal1 << 8) | (pal2 << 16) | (pal3 << 24);
+}
+
+void OSD_Scal(struct faradayfb_info *fbi, int HScal, int VScal)
+{
+ REG32(fbi->io_base + 0x34) &= 0xffffffe1;
+ REG32(fbi->io_base + 0x34) |= (HScal << 3) | (VScal << 1);
+}
+
+void OSD_putc(struct faradayfb_info *fbi, char c, int position, unsigned int value)
+{
+ if (c >= '0' && c <= '9')
+ REG32(fbi->io_base + 0xc000 + position * 4) = ((c -'0') << 4) | value;
+
+ else if (c>= 'A' && c <= 'Z')
+ REG32(fbi->io_base + 0xc000 + position * 4) = ((c - 'A' + 10) << 4) | value;
+
+ if (c == ' ')
+ REG32(fbi->io_base + 0xc000 + position * 4) = (('Z' - 'A' + 10 + 1) << 4) | value;
+
+ if (c == '=')
+ REG32(fbi->io_base + 0xc000 + position * 4) = (('Z' - 'A' + 10 + 2) << 4) | value;
+
+ if (c == ',')
+ REG32(fbi->io_base + 0xc000 + position * 4) = (('Z' - 'A' + 10 + 3) << 4) | value;
+}
+
+void OSD_puts(struct faradayfb_info *fbi, char *str, int position, unsigned int value)
+{
+ int i;
+
+ for (i = 0; i < strlen(str); i++)
+ OSD_putc(fbi, *(str + i), position + i, value);
+}
+
+void OSD_String(struct faradayfb_info *fbi, int row, int mode, char *str, int fg_color, int bg_color)
+{
+ int i, j, x, y;
+ unsigned int value = fg_color | bg_color;
+
+ /* 10 digit & 26 alphabet & ' ' & '=' & ',' */
+ for (i = 0; i < dig_alpha; i++) {
+
+ x = 0;
+ y = OSD_Font[i];
+
+ for (j = 0; j < 12; j ++) { /* reorder */
+ if (y & 1)
+ x |= 1;
+ y >>= 1;
+ x <<= 1;
+ }
+
+ x >>= 1;
+ REG32(fbi->io_base + 0x8000 + i * 4) = x;
+ }
+
+ OSD_puts(fbi, str, row, value);
+
+ if (mode == 2) { /* YCbCr */
+
+ OSD_fg_color(fbi, 0x57, 0x88, 0x3B, 0xFF);
+ OSD_bg_color(fbi, 0x57, 0x88, 0x3B);
+ }
+ else {
+ OSD_fg_color(fbi, 0x07, 0x38, 0xC0, 0xFF);
+ OSD_bg_color(fbi, 0x07, 0x38, 0xc0);
+ }
+}
+#endif /* CONFIG_FTLCD_OSD */
+
+struct andesIO {
+
+ unsigned long Regaddr;
+ unsigned long Regoffset;
+ unsigned long Regvalue;
+};
+
+static int faradayfb_ioctl(struct fb_info *info, unsigned int cmd, unsigned long arg)
+{
+ int ret = 0;
+#ifdef CONFIG_FTLCD_OSD
+ struct faradayfb_info *fbi = info->par;
+ int i;
+ struct fosd_data fosd;
+
+ struct andesIO IOAccess;
+ unsigned long *Regaccess;
+#endif
+
+ DEBUG(0, 1, "Enter\n");
+
+ switch (cmd) {
+#ifdef CONFIG_FTLCD_OSD
+ case FRREG:
+
+ if (copy_from_user(&IOAccess, (struct andesIO *)arg, sizeof(struct andesIO))) {
+
+ ret = -EFAULT;
+ break;
+ }
+
+ Regaccess = (unsigned long *)(((IOAccess.Regaddr >> 4) | (unsigned long)0xF0000000) + IOAccess.Regoffset);
+
+ IOAccess.Regvalue = *(Regaccess);
+
+ if (copy_to_user((struct andesIO *)arg, &IOAccess, sizeof(struct andesIO))) {
+ ret = -EFAULT;
+ break;
+ }
+
+ break;
+
+ case FWREG:
+
+ if (copy_from_user(&IOAccess, (struct andesIO *)arg, sizeof(struct andesIO))) {
+ ret = -EFAULT;
+ break;
+ }
+
+ Regaccess = (unsigned long *)(((IOAccess.Regaddr >> 4) | (unsigned long)0xF0000000) + IOAccess.Regoffset);
+ *(Regaccess) = IOAccess.Regvalue;
+
+ break;
+
+ case FOSD_ON:
+
+ DEBUG(1, 1, "FOSD_ON:\n");
+ OSD_On(fbi);
+ break;
+
+ case FOSD_OFF:
+
+ DEBUG(1, 1, "FOSD_OFF:\n");
+ OSD_Off(fbi);
+ break;
+
+ case FOSD_SETPOS:
+
+ DEBUG(1, 1, "FOSD_SETPOS:\n");
+
+ if (copy_from_user(&fosd, (unsigned int *)arg, 2 * sizeof(unsigned int))) {
+
+ ret = -EFAULT;
+ break;
+ }
+
+ OSD_Pos(fbi, fosd.HPos, fosd.VPos);
+ DEBUG(1, 1, "OSD_Pos = %d %d\n", fosd.HPos, fosd.VPos);
+ break;
+
+ case FOSD_SETDIM:
+
+ DEBUG(1, 1, "FOSD_SETDIM:\n");
+
+ if (copy_from_user(&fosd, (unsigned int *)arg, 4 * sizeof(unsigned int))) {
+
+ ret = -EFAULT;
+ break;
+ }
+
+ OSD_Dim(fbi, fosd.HDim, fosd.VDim);
+ DEBUG(1, 1, "OSD_Dim = %d %d\n", fosd.HDim, fosd.VDim);
+ break;
+
+ case FOSD_SETSCAL:
+
+ DEBUG(1, 1, "FOSD_SETSCAL:\n");
+
+ if (copy_from_user(&fosd, (unsigned int *)arg, 7 * sizeof(unsigned int))) {
+ ret = -EFAULT;
+ break;
+ }
+
+ OSD_Scal(fbi, fosd.HScal, fosd.VScal);
+ break;
+
+ case FLCD_SET_TRANSPARENT:
+
+ DEBUG(1, 1, "FLCD_SET_TRANSPARENT:\n");
+
+ if (copy_from_user(&fosd, (unsigned int *)arg, 5 * sizeof(unsigned int))) {
+
+ ret = -EFAULT;
+ break;
+ }
+
+ OSD_transparent(fbi, fosd.transparent_level);
+ DEBUG(1, 1, "OSD_transparent = %d\n", fosd.transparent_level);
+ break;
+
+ case FLCD_SET_STRING:
+
+ DEBUG(1, 1, "FLCD_SET_STRING:\n");
+
+ if (copy_from_user(&fosd, (unsigned int *)arg, sizeof(struct fosd_data))) {
+
+ ret = -EFAULT;
+ break;
+ }
+
+ for (i = 0; i < fosd.VDim; i++)
+
+ OSD_String(fbi, fosd.Str_Data[i].Str_row,
+ fosd.Str_Data[i].display_mode,
+ fosd.Str_Data[i].Str_OSD,
+ fosd.Str_Data[i].fg_color,
+ fosd.Str_Data[i].bg_color);
+ break;
+#endif /* CONFIG_FTLCD_OSD */
+
+ default:
+
+ DEBUG(1, 1, "IOCTL CMD(0x%08u) no define!\n", cmd);
+ ret = -EFAULT;
+ break;
+ }
+
+ DEBUG(0, 1, "Leave\n");
+ return ret;
+}
+
diff -Nur linux-3.4.113.orig/drivers/video/Kconfig linux-3.4.113/drivers/video/Kconfig
--- linux-3.4.113.orig/drivers/video/Kconfig 2016-10-26 17:15:47.000000000 +0200
+++ linux-3.4.113/drivers/video/Kconfig 2016-12-01 20:59:24.392614293 +0100
@@ -2166,6 +2166,8 @@
---help---
Say Y here to enable support for PNX4008 RGB Framebuffer
+source "drivers/video/FTLCDC100/Kconfig"
+
config FB_IBM_GXT4500
tristate "Framebuffer support for IBM GXT4500P adaptor"
depends on FB && PPC
diff -Nur linux-3.4.113.orig/drivers/video/Makefile linux-3.4.113/drivers/video/Makefile
--- linux-3.4.113.orig/drivers/video/Makefile 2016-10-26 17:15:47.000000000 +0200
+++ linux-3.4.113/drivers/video/Makefile 2016-12-01 20:59:24.392614293 +0100
@@ -143,6 +143,7 @@
obj-$(CONFIG_FB_CARMINE) += carminefb.o
obj-$(CONFIG_FB_MB862XX) += mb862xx/
obj-$(CONFIG_FB_MSM) += msm/
+obj-$(CONFIG_FB_FTLCDC100) += FTLCDC100/
obj-$(CONFIG_FB_NUC900) += nuc900fb.o
obj-$(CONFIG_FB_JZ4740) += jz4740_fb.o
obj-$(CONFIG_FB_PUV3_UNIGFX) += fb-puv3.o
diff -Nur linux-3.4.113.orig/drivers/watchdog/ftwdt010_wdt.c linux-3.4.113/drivers/watchdog/ftwdt010_wdt.c
--- linux-3.4.113.orig/drivers/watchdog/ftwdt010_wdt.c 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/drivers/watchdog/ftwdt010_wdt.c 2016-12-01 20:59:24.392614293 +0100
@@ -0,0 +1,127 @@
+/*
+ * Watchdog driver for the FTWDT010 Watch Dog Driver
+ *
+ * (c) Copyright 2004 Faraday Technology Corp. (www.faraday-tech.com)
+ * Based on sa1100_wdt.c by Oleg Drokin <green@crimea.edu>
+ * Based on SoftDog driver by Alan Cox <alan@redhat.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version
+ * 2 of the License, or (at your option) any later version.
+ *
+ * 27/11/2004 Initial release
+ */
+#include <linux/module.h>
+#include <linux/fs.h>
+#include <linux/miscdevice.h>
+#include <linux/watchdog.h>
+#include <linux/delay.h>
+#include <asm/uaccess.h>
+
+#define DEBUG( str, ...) \
+ do{ \
+ if( debug) \
+ printk( str, ##__VA_ARGS__); \
+ } while(0)
+
+#define wdcounter (*( volatile unsigned long *)( WDT_FTWDT010_VA_BASE + 0x00))
+#define wdload (*( volatile unsigned long *)( WDT_FTWDT010_VA_BASE + 0x04))
+#define wdrestart (*( volatile unsigned long *)( WDT_FTWDT010_VA_BASE + 0x08))
+#define wdcr (*( volatile unsigned long *)( WDT_FTWDT010_VA_BASE + 0x0C))
+#define wdstatus (*( volatile unsigned long *)( WDT_FTWDT010_VA_BASE + 0x10))
+#define wdclear (*( volatile unsigned long *)( WDT_FTWDT010_VA_BASE + 0x14))
+#define wdintrcter (*( volatile unsigned long *)( WDT_FTWDT010_VA_BASE + 0x18))
+
+#define TIMER_MARGIN 60 /* (secs) Default is 1 minute */
+#define RESTART_MAGIC 0x5AB9
+#define PCLK (AHB_CLK_IN / 2)
+
+static int debug = 0;
+static int timeout = TIMER_MARGIN; /* in seconds */
+
+module_param(debug, int, 0);
+module_param(timeout, int, 0);
+
+static int ftwdt010_dog_open(struct inode *inode, struct file *file){
+
+#if 0
+ /* Allow only one person to hold it open */
+ if( test_and_set_bit( 1, &ftwdt010_wdt_users))
+ return -EBUSY;
+
+ ftwdt010_wdt_users = 1;
+#endif
+ DEBUG("Activating WDT..\n");
+
+ wdcr = 0;
+ wdload = PCLK * timeout;
+ wdrestart = RESTART_MAGIC; /* Magic number */
+ wdcr = 0x03; /* Enable WDT */
+
+ return 0;
+}
+
+static int ftwdt010_dog_release(struct inode *inode, struct file *file){
+
+#ifndef CONFIG_WATCHDOG_NOWAYOUT
+ /*
+ * Shut off the timer.
+ * Lock it in if it's a module and we defined ...NOWAYOUT
+ */
+ wdcr = 0;
+ DEBUG( "Deactivating WDT..\n");
+#endif
+ return 0;
+}
+
+static ssize_t ftwdt010_dog_write(struct file *file, const char *data, size_t len, loff_t *ppos){
+
+ if(len){
+
+ wdrestart = RESTART_MAGIC;
+ return 1;
+ }
+
+ return 0;
+}
+
+static struct file_operations ftwdt010_dog_fops = {
+
+ .owner = THIS_MODULE,
+ .llseek = no_llseek,
+ .write = ftwdt010_dog_write,
+ .open = ftwdt010_dog_open,
+ .release = ftwdt010_dog_release,
+};
+
+static struct miscdevice ftwdt010_dog_miscdev = {
+
+ WATCHDOG_MINOR,
+ "FTWDT010 watchdog",
+ &ftwdt010_dog_fops
+};
+
+static int __init ftwdt010_dog_init( void){
+
+ int ret;
+
+ ret = misc_register(&ftwdt010_dog_miscdev);
+
+ if( ret)
+ return ret;
+
+ DEBUG("FTWDT010 watchdog timer: timer timeout %d sec\n", timeout);
+
+ return 0;
+}
+
+static void __exit ftwdt010_dog_exit( void){
+
+ misc_deregister(&ftwdt010_dog_miscdev);
+}
+
+module_init(ftwdt010_dog_init);
+module_exit(ftwdt010_dog_exit);
+MODULE_AUTHOR("Faraday Corp.");
+MODULE_LICENSE("GPL");
diff -Nur linux-3.4.113.orig/drivers/watchdog/Kconfig linux-3.4.113/drivers/watchdog/Kconfig
--- linux-3.4.113.orig/drivers/watchdog/Kconfig 2016-10-26 17:15:47.000000000 +0200
+++ linux-3.4.113/drivers/watchdog/Kconfig 2016-12-01 20:59:24.392614293 +0100
@@ -64,6 +64,12 @@
To compile this driver as a module, choose M here: the
module will be called softdog.
+config FTWDT010_WATCHDOG
+ tristate "FTWDT010_WATCHDOG"
+ help
+ Support for Faraday ftwdt010 watchdog. When the watchdog triigers the
+ system will be reset.
+
config WM831X_WATCHDOG
tristate "WM831x watchdog"
depends on MFD_WM831X
diff -Nur linux-3.4.113.orig/drivers/watchdog/Makefile linux-3.4.113/drivers/watchdog/Makefile
--- linux-3.4.113.orig/drivers/watchdog/Makefile 2016-10-26 17:15:47.000000000 +0200
+++ linux-3.4.113/drivers/watchdog/Makefile 2016-12-01 20:59:24.392614293 +0100
@@ -163,6 +163,7 @@
obj-$(CONFIG_XEN_WDT) += xen_wdt.o
# Architecture Independent
+obj-$(CONFIG_FTWDT010_WATCHDOG) += ftwdt010_wdt.o
obj-$(CONFIG_WM831X_WATCHDOG) += wm831x_wdt.o
obj-$(CONFIG_WM8350_WATCHDOG) += wm8350_wdt.o
obj-$(CONFIG_MAX63XX_WATCHDOG) += max63xx_wdt.o
diff -Nur linux-3.4.113.orig/include/linux/mm.h linux-3.4.113/include/linux/mm.h
--- linux-3.4.113.orig/include/linux/mm.h 2016-10-26 17:15:47.000000000 +0200
+++ linux-3.4.113/include/linux/mm.h 2016-12-01 20:59:24.392614293 +0100
@@ -157,6 +157,7 @@
#define FAULT_FLAG_ALLOW_RETRY 0x08 /* Retry fault if blocking */
#define FAULT_FLAG_RETRY_NOWAIT 0x10 /* Don't drop mmap_sem and wait when retrying */
#define FAULT_FLAG_KILLABLE 0x20 /* The fault task is in SIGKILL killable region */
+#define FAULT_FLAG_TRIED 0x40 /* second try */
/*
* This interface is used by x86 PAT code to identify a pfn mapping that is
diff -Nur linux-3.4.113.orig/include/linux/semaphore.h linux-3.4.113/include/linux/semaphore.h
--- linux-3.4.113.orig/include/linux/semaphore.h 2016-10-26 17:15:47.000000000 +0200
+++ linux-3.4.113/include/linux/semaphore.h 2016-12-01 20:59:24.392614293 +0100
@@ -36,6 +36,9 @@
lockdep_init_map(&sem->lock.dep_map, "semaphore->lock", &__key, 0);
}
+#define init_MUTEX(sem) sema_init(sem, 1)
+#define init_MUTEX_LOCKED(sem) sema_init(sem, 0)
+
extern void down(struct semaphore *sem);
extern int __must_check down_interruptible(struct semaphore *sem);
extern int __must_check down_killable(struct semaphore *sem);
diff -Nur linux-3.4.113.orig/init/Kconfig linux-3.4.113/init/Kconfig
--- linux-3.4.113.orig/init/Kconfig 2016-10-26 17:15:47.000000000 +0200
+++ linux-3.4.113/init/Kconfig 2016-12-01 20:59:24.392614293 +0100
@@ -966,7 +966,7 @@
config UID16
bool "Enable 16-bit UID system calls" if EXPERT
- depends on ARM || BLACKFIN || CRIS || FRV || H8300 || X86_32 || M68K || (S390 && !64BIT) || SUPERH || SPARC32 || (SPARC64 && COMPAT) || UML || (X86_64 && IA32_EMULATION)
+ depends on ARM || BLACKFIN || CRIS || FRV || H8300 || X86_32 || M68K || NDS32 || (S390 && !64BIT) || SUPERH || SPARC32 || (SPARC64 && COMPAT) || UML || (X86_64 && IA32_EMULATION)
default y
help
This enables the legacy 16-bit UID syscall wrappers.
diff -Nur linux-3.4.113.orig/kernel/Makefile linux-3.4.113/kernel/Makefile
--- linux-3.4.113.orig/kernel/Makefile 2016-10-26 17:15:47.000000000 +0200
+++ linux-3.4.113/kernel/Makefile 2016-12-01 20:59:24.396614447 +0100
@@ -20,6 +20,7 @@
CFLAGS_REMOVE_rtmutex-debug.o = -pg
CFLAGS_REMOVE_cgroup-debug.o = -pg
CFLAGS_REMOVE_irq_work.o = -pg
+CFLAGS_REMOVE_kallsyms.o = -pg
endif
obj-y += sched/
diff -Nur linux-3.4.113.orig/kernel/trace/Kconfig linux-3.4.113/kernel/trace/Kconfig
--- linux-3.4.113.orig/kernel/trace/Kconfig 2016-10-26 17:15:47.000000000 +0200
+++ linux-3.4.113/kernel/trace/Kconfig 2016-12-01 20:59:24.396614447 +0100
@@ -141,7 +141,7 @@
config FUNCTION_TRACER
bool "Kernel Function Tracer"
depends on HAVE_FUNCTION_TRACER
- select FRAME_POINTER if !ARM_UNWIND && !PPC && !S390 && !MICROBLAZE
+ select FRAME_POINTER if !ARM_UNWIND && !PPC && !S390 && !MICROBLAZE && !NDS32
select KALLSYMS
select GENERIC_TRACER
select CONTEXT_SWITCH_TRACER
diff -Nur linux-3.4.113.orig/lib/Kconfig.debug linux-3.4.113/lib/Kconfig.debug
--- linux-3.4.113.orig/lib/Kconfig.debug 2016-10-26 17:15:47.000000000 +0200
+++ linux-3.4.113/lib/Kconfig.debug 2016-12-01 20:59:24.396614447 +0100
@@ -615,7 +615,7 @@
bool
depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
select STACKTRACE
- select FRAME_POINTER if !MIPS && !PPC && !ARM_UNWIND && !S390 && !MICROBLAZE
+ select FRAME_POINTER if !MIPS && !PPC && !ARM_UNWIND && !S390 && !MICROBLAZE && !NDS32
select KALLSYMS
select KALLSYMS_ALL
@@ -1122,7 +1122,7 @@
depends on FAULT_INJECTION_DEBUG_FS && STACKTRACE_SUPPORT
depends on !X86_64
select STACKTRACE
- select FRAME_POINTER if !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND
+ select FRAME_POINTER if !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND && !NDS32
help
Provide stacktrace filter for fault-injection capabilities
@@ -1132,7 +1132,7 @@
depends on DEBUG_KERNEL
depends on STACKTRACE_SUPPORT
depends on PROC_FS
- select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND
+ select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND && !NDS32
select KALLSYMS
select KALLSYMS_ALL
select STACKTRACE
diff -Nur linux-3.4.113.orig/sound/Kconfig linux-3.4.113/sound/Kconfig
--- linux-3.4.113.orig/sound/Kconfig 2016-10-26 17:15:47.000000000 +0200
+++ linux-3.4.113/sound/Kconfig 2016-12-01 20:59:24.396614447 +0100
@@ -93,6 +93,8 @@
source "sound/sh/Kconfig"
+source "sound/nds32/Kconfig"
+
# the following will depend on the order of config.
# here assuming USB is defined before ALSA
source "sound/usb/Kconfig"
diff -Nur linux-3.4.113.orig/sound/Makefile linux-3.4.113/sound/Makefile
--- linux-3.4.113.orig/sound/Makefile 2016-10-26 17:15:47.000000000 +0200
+++ linux-3.4.113/sound/Makefile 2016-12-01 20:59:24.396614447 +0100
@@ -6,7 +6,7 @@
obj-$(CONFIG_SOUND_PRIME) += oss/
obj-$(CONFIG_DMASOUND) += oss/
obj-$(CONFIG_SND) += core/ i2c/ drivers/ isa/ pci/ ppc/ arm/ sh/ synth/ usb/ \
- firewire/ sparc/ spi/ parisc/ pcmcia/ mips/ soc/ atmel/
+ firewire/ sparc/ spi/ parisc/ pcmcia/ mips/ soc/ atmel/ nds32/
obj-$(CONFIG_SND_AOA) += aoa/
# This one must be compilable even if sound is configured out
diff -Nur linux-3.4.113.orig/sound/nds32/FTSSP010_ALSA.c linux-3.4.113/sound/nds32/FTSSP010_ALSA.c
--- linux-3.4.113.orig/sound/nds32/FTSSP010_ALSA.c 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/sound/nds32/FTSSP010_ALSA.c 2016-12-01 20:59:24.396614447 +0100
@@ -0,0 +1,2020 @@
+/* FTSSP010 - UDA1345TS module:
+ *
+ * $log$
+ *
+ * 2006/02/23: I-Jui Sung: OSS emulation half-duplex
+ * playback/capture at 48K, 44.1K, 8K
+ * with mono/stereo 16bit/8bit
+ *
+ * 2006/02/22: I-Jui Sung: OSS emulation playback at 44.1KHz
+ * 16-bit mono completed. Relying ALSA to
+ * resample
+ * 2009/02/24: dma upgrade checking list:
+ * - ac97 mode playback ................. ok
+ * - ac97 mode capture .................. ok
+ * - i2s mode playback .................. ok
+ * - i2s mode capture ................... ok
+ * - mixer support (snd_ctl_add, ...) ... todo
+ * - debug /proc entry .................. ok
+ */
+
+
+#include <linux/init.h>
+#include <linux/module.h>
+#include <asm/io.h>
+#include <linux/delay.h>
+//#include <asm/spec.h>
+#include <asm/dmad.h>
+#include <linux/dma-mapping.h>
+#include <sound/core.h>
+#include <sound/pcm.h>
+#include <sound/initval.h>
+#include <sound/asound.h>
+#include <linux/i2c.h>
+#include <sound/control.h>
+#include <linux/interrupt.h>
+
+#include <asm/hardware.h>
+#include <asm/irq.h>
+#include <asm/io.h>
+#include <asm/spec.h>
+
+#include "FTSSP010_UDA1345TS.h"
+
+//ADD by river 2011.06.02
+struct alc5630_data;
+//End ADD by river 2011.06.02
+
+void init_hw(unsigned int cardno,unsigned int ac97, struct i2c_client *client);
+
+#if (!defined(CONFIG_PLATFORM_AHBDMA) && !defined(CONFIG_PLATFORM_APBDMA))
+#warning needs ahb/apb dma to wrok
+#endif
+
+/* ---------------------------------------------------------------------------
+ * Define the debug level of FTSSP_DEBUG
+ */
+#define FTSSP_DEBUG 0
+#define FTSSP_DEBUG_VERBOSE 0
+#define FTSSP_PROC_FS 0
+
+#undef VVDBG
+#if (FTSSP_DEBUG_VERBOSE)
+#define VVDBG(vvar...) (void)0
+//#define VVDBG(vvar...) printk(KERN_INFO vvar)
+#else
+#define VVDBG(vvar...) (void)0
+#endif
+
+#undef ERR
+#define ERR(vvar...) printk(KERN_ERR vvar)
+
+#undef INFO
+#define INFO(vvar...) printk(KERN_INFO vvar)
+
+#if (FTSSP_DEBUG)
+#undef DBG
+#define DBG(vvar...) printk(KERN_INFO vvar)
+#else
+#define DBG(vvar...) (void)0
+#endif
+
+#if (FTSSP_DEBUG_VERBOSE)
+#undef VDBG
+#define VDBG(vvar...) printk(KERN_INFO vvar)
+#else
+#define VDBG(vvar...) (void)0
+#endif
+
+#ifdef CONFIG_SND_FTSSP010_I2S
+//ADD by river 2011.02.11
+static struct i2c_client *g_i2c_client;
+
+////////// ADD by river 2011.01.26
+// Each client has this additional data
+struct alc5630_data {
+ struct i2c_client *client;
+ struct delayed_work work;
+ unsigned long gpio2_value;
+ struct mutex mtx;
+};
+
+static int alc5630_i2c_attach(struct i2c_adapter *adapter);
+static int alc5630_i2c_probe(struct i2c_client *client, const struct i2c_device_id *id);
+static int alc5630_i2c_suspend(struct i2c_client *i2c_client, pm_message_t mesg);
+static int alc5630_i2c_resume(struct i2c_client *i2c_client);
+
+static int alc5630_i2c_remove(struct i2c_client *client);
+static int ftssp_alsa_init(struct i2c_client *client);
+
+
+static int i2s_alc5630_read(unsigned int raddr, char *data, struct i2c_client *client)
+{
+ struct i2c_adapter *adap = client->adapter;
+ struct i2c_msg msg;
+ int ret, i2c_value;
+
+ //Reading ALC5630 register
+ msg.addr = raddr;
+ msg.flags = (client->flags & I2C_M_TEN) | I2C_M_RD;
+ msg.len = 1;
+ msg.buf = (char *)data;
+
+ //ret = i2c_transfer(adap, &msg, 1);
+ #ifndef CONFIG_SND_FTSSP010_AC97
+ ret = i2c_transfer(adap, &msg, 1);
+ #endif
+
+ if (ret != 0) {
+ printk("i2c read failed\n");
+ return -1;
+ }
+ else
+ {
+ i2c_value = (data[0]&0xff) << 8 | (data[1]&0xff);
+ return i2c_value;
+ }
+
+}
+
+static void i2s_alc5630_write(unsigned int addr, unsigned int data, struct i2c_client *client)
+{
+
+ struct i2c_adapter *adap = client->adapter;
+ struct i2c_msg msg;
+ int ret, i2c_value;
+ char buf[3];
+
+ //Writing ALC5630 register
+ i2c_value = 0x0;
+ msg.addr = addr;
+ msg.flags = (client->flags & I2C_M_TEN) | ~I2C_M_RD;
+ msg.len = 1;
+
+ buf[0] = (data >> 8) & 0xff;
+ buf[1] = data & 0xff;
+ msg.buf = (char *)buf;
+
+ //ret = i2c_transfer(adap, &msg, 1);
+ #ifndef CONFIG_SND_FTSSP010_AC97
+ ret = i2c_transfer(adap, &msg, 1);
+ #endif
+
+ if (ret != 0) {
+ printk("i2c write failed\n");
+ }
+
+}
+
+static void i2s_alc5630_read_test(struct i2c_client *client)
+{
+ char data[3];
+ //printk(">>>>> : i2s_alc5630_read_test().....\n");
+ printk("Reg 0x%02x = 0x%08x\n", 0x0, i2s_alc5630_read(0x0, data,client));
+ printk("Reg 0x%02x = 0x%08x\n", 0x02, i2s_alc5630_read(0x02, data,client));
+ printk("Reg 0x%02x = 0x%08x\n", 0x04, i2s_alc5630_read(0x04, data,client));
+ printk("Reg 0x%02x = 0x%08x\n", 0x06, i2s_alc5630_read(0x06, data,client));
+ printk("Reg 0x%02x = 0x%08x\n", 0x08, i2s_alc5630_read(0x08, data,client));
+ printk("Reg 0x%02x = 0x%08x\n", 0x0a, i2s_alc5630_read(0x0a, data,client));
+ printk("Reg 0x%02x = 0x%08x\n", 0x0c, i2s_alc5630_read(0x0c, data,client));
+ printk("Reg 0x%02x = 0x%08x\n", 0x0e, i2s_alc5630_read(0x0e, data,client));
+
+ printk("Reg 0x%02x = 0x%08x\n", 0x10, i2s_alc5630_read(0x10, data,client));
+ printk("Reg 0x%02x = 0x%08x\n", 0x12, i2s_alc5630_read(0x12, data,client));
+ printk("Reg 0x%02x = 0x%08x\n", 0x14, i2s_alc5630_read(0x14, data,client));
+ printk("Reg 0x%02x = 0x%08x\n", 0x16, i2s_alc5630_read(0x16, data,client));
+ printk("Reg 0x%02x = 0x%08x\n", 0x18, i2s_alc5630_read(0x18, data,client));
+ printk("Reg 0x%02x = 0x%08x\n", 0x1a, i2s_alc5630_read(0x1a, data,client));
+ printk("Reg 0x%02x = 0x%08x\n", 0x1c, i2s_alc5630_read(0x1c, data,client));
+ printk("Reg 0x%02x = 0x%08x\n", 0x1e, i2s_alc5630_read(0x1e, data,client));
+
+ printk("Reg 0x%02x = 0x%08x\n", 0x20, i2s_alc5630_read(0x20, data,client));
+ printk("Reg 0x%02x = 0x%08x\n", 0x22, i2s_alc5630_read(0x22, data,client));
+ printk("Reg 0x%02x = 0x%08x\n", 0x24, i2s_alc5630_read(0x24, data,client));
+ printk("Reg 0x%02x = 0x%08x\n", 0x26, i2s_alc5630_read(0x26, data,client));
+ printk("Reg 0x%02x = 0x%08x\n", 0x28, i2s_alc5630_read(0x28, data,client));
+ printk("Reg 0x%02x = 0x%08x\n", 0x2a, i2s_alc5630_read(0x2a, data,client));
+ printk("Reg 0x%02x = 0x%08x\n", 0x2c, i2s_alc5630_read(0x2c, data,client));
+ printk("Reg 0x%02x = 0x%08x\n", 0x2e, i2s_alc5630_read(0x2e, data,client));
+
+ printk("Reg 0x%02x = 0x%08x\n", 0x30, i2s_alc5630_read(0x30, data,client));
+ printk("Reg 0x%02x = 0x%08x\n", 0x32, i2s_alc5630_read(0x32, data,client));
+ printk("Reg 0x%02x = 0x%08x\n", 0x34, i2s_alc5630_read(0x34, data,client));
+ printk("Reg 0x%02x = 0x%08x\n", 0x36, i2s_alc5630_read(0x36, data,client));
+ printk("Reg 0x%02x = 0x%08x\n", 0x38, i2s_alc5630_read(0x38, data,client));
+ printk("Reg 0x%02x = 0x%08x\n", 0x3a, i2s_alc5630_read(0x3a, data,client));
+ printk("Reg 0x%02x = 0x%08x\n", 0x3c, i2s_alc5630_read(0x3c, data,client));
+ printk("Reg 0x%02x = 0x%08x\n", 0x3e, i2s_alc5630_read(0x3e, data,client));
+
+ printk("Reg 0x%02x = 0x%08x\n", 0x40, i2s_alc5630_read(0x40, data,client));
+ printk("Reg 0x%02x = 0x%08x\n", 0x42, i2s_alc5630_read(0x42, data,client));
+ printk("Reg 0x%02x = 0x%08x\n", 0x44, i2s_alc5630_read(0x44, data,client));
+ printk("Reg 0x%02x = 0x%08x\n", 0x46, i2s_alc5630_read(0x46, data,client));
+ printk("Reg 0x%02x = 0x%08x\n", 0x48, i2s_alc5630_read(0x48, data,client));
+ printk("Reg 0x%02x = 0x%08x\n", 0x4a, i2s_alc5630_read(0x4a, data,client));
+ printk("Reg 0x%02x = 0x%08x\n", 0x4c, i2s_alc5630_read(0x4c, data,client));
+ printk("Reg 0x%02x = 0x%08x\n", 0x4e, i2s_alc5630_read(0x4e, data,client));
+
+ printk("Reg 0x%02x = 0x%08x\n", 0x50, i2s_alc5630_read(0x50, data,client));
+ printk("Reg 0x%02x = 0x%08x\n", 0x52, i2s_alc5630_read(0x52, data,client));
+ printk("Reg 0x%02x = 0x%08x\n", 0x54, i2s_alc5630_read(0x54, data,client));
+ printk("Reg 0x%02x = 0x%08x\n", 0x56, i2s_alc5630_read(0x56, data,client));
+ printk("Reg 0x%02x = 0x%08x\n", 0x58, i2s_alc5630_read(0x58, data,client));
+ printk("Reg 0x%02x = 0x%08x\n", 0x5a, i2s_alc5630_read(0x5a, data,client));
+ printk("Reg 0x%02x = 0x%08x\n", 0x5c, i2s_alc5630_read(0x5c, data,client));
+ printk("Reg 0x%02x = 0x%08x\n", 0x5e, i2s_alc5630_read(0x5e, data,client));
+
+ printk("Reg 0x%02x = 0x%08x\n", 0x60, i2s_alc5630_read(0x60, data,client));
+ printk("Reg 0x%02x = 0x%08x\n", 0x62, i2s_alc5630_read(0x62, data,client));
+ printk("Reg 0x%02x = 0x%08x\n", 0x64, i2s_alc5630_read(0x64, data,client));
+ printk("Reg 0x%02x = 0x%08x\n", 0x66, i2s_alc5630_read(0x66, data,client));
+ printk("Reg 0x%02x = 0x%08x\n", 0x68, i2s_alc5630_read(0x68, data,client));
+ printk("Reg 0x%02x = 0x%08x\n", 0x6a, i2s_alc5630_read(0x6a, data,client));
+ printk("Reg 0x%02x = 0x%08x\n", 0x6c, i2s_alc5630_read(0x6c, data,client));
+ printk("Reg 0x%02x = 0x%08x\n", 0x6e, i2s_alc5630_read(0x6e, data,client));
+
+ printk("Reg 0x%02x = 0x%08x\n", 0x70, i2s_alc5630_read(0x70, data,client));
+ printk("Reg 0x%02x = 0x%08x\n", 0x72, i2s_alc5630_read(0x72, data,client));
+ printk("Reg 0x%02x = 0x%08x\n", 0x74, i2s_alc5630_read(0x74, data,client));
+ printk("Reg 0x%02x = 0x%08x\n", 0x76, i2s_alc5630_read(0x76, data,client));
+ printk("Reg 0x%02x = 0x%08x\n", 0x78, i2s_alc5630_read(0x78, data,client));
+ printk("Reg 0x%02x = 0x%08x\n", 0x7a, i2s_alc5630_read(0x7a, data,client));
+ printk("Reg 0x%02x = 0x%08x\n", 0x7c, i2s_alc5630_read(0x7c, data,client));
+ printk("Reg 0x%02x = 0x%08x\n", 0x7e, i2s_alc5630_read(0x7e, data,client));
+
+}
+
+static int alc5630_i2c_attach(struct i2c_adapter *adapter){
+
+ struct i2c_board_info info;
+ struct i2c_client *client;
+
+ int ret=0;
+
+ //i2c_dbg( 1, "alc5630_i2c_attach() is called.\n");
+ //printk(">>>>>>>>>> (2) alc5630_i2c_attach() is called.\n");
+
+ //ret = i2c_probe(adapter, &addr_data, alc5630_detect);
+ memset(&info, 0, sizeof(struct i2c_board_info));
+ strlcpy(info.type, "alc5630_codec", I2C_NAME_SIZE);
+ //info.addr = 0x3e;
+ info.addr = 0x66;
+ //info.platform_data = node;
+
+ //client = i2c_new_device(adapter, &info);
+ #ifndef CONFIG_SND_FTSSP010_AC97
+ client = i2c_new_device(adapter, &info);
+ #endif
+ if (!client) {
+ printk("$$$$$????? : i2c_new_device() failed.....\n");
+ return -ENODEV;
+ }
+ /*
+ * We know the driver is already loaded, so the device should be
+ * already bound. If not it means binding failed, and then there
+ * is no point in keeping the device instantiated.
+ */
+ if (!client->driver) {
+ //i2c_unregister_device(client);
+ #ifndef CONFIG_SND_FTSSP010_AC97
+ i2c_unregister_device(client);
+ #endif
+ return -ENODEV;
+ }
+
+ /*
+ * Let i2c-core delete that device on driver removal.
+ * This is safe because i2c-core holds the core_lock mutex for us.
+ */
+ list_add_tail(&client->detected, &client->driver->clients);
+
+ return ret;
+}
+
+static irqreturn_t gpio2_irq(int irq, void *dev_id)
+{
+
+ struct i2c_client *client = (struct i2c_client *)dev_id;
+ struct alc5630_data *alc5630 = i2c_get_clientdata(client);
+
+ unsigned long org_mask, org_dir;
+ //printk("@@@@@#####$$$$$!!!!! : gpio2_irq is detected ???....\n");
+
+ //Mask GPIO interrupt
+ //REG32(AMIC_VA_BASE + 0x80) = REG32(AMIC_VA_BASE + 0x80) & ~(1 << 13); //GPIO interrupt disable
+
+ //Dump AMIC contents and ir~
+ unsigned long ir0,ir1,ir2, ir3, ir4, ir5;
+ unsigned long ir6, ir7, ir8, ir9, ir10;
+ unsigned long ir11, ir12, ir13, ir14, ir15;
+ unsigned long gpio2_value, value;
+ char data[3];
+
+
+ //__asm__ volatile ("setgie.d\n\t");
+ //REG32(AMIC_VA_BASE + 0x80) = 0;
+
+
+ //Get original gpio direction
+ org_dir = REG32(GPIO_VA_BASE + 0x08);
+
+ //Get original gpio interrupt mask
+ org_mask = REG32(GPIO_VA_BASE + 0x2c);
+
+ //Mask all gpio interrupt
+ REG32(GPIO_VA_BASE + 0x2c) = 0x0000FFFF;
+ //Clear all gpio interrupt
+ REG32(GPIO_VA_BASE + 0x30) = 0x0000FFFF;
+
+ //Get gpio pin value
+ REG32(GPIO_VA_BASE + 0x08) = REG32(GPIO_VA_BASE + 0x08) & ~(0x1UL << 2); //Set gpio2 direction => input
+ gpio2_value = (REG32(GPIO_VA_BASE + 0x04) >> 2 & 1);
+ //printk("The gpio2 value is 0x%08x\n",gpio2_value);
+
+
+ alc5630->gpio2_value = gpio2_value;
+ schedule_delayed_work(&alc5630->work, 1);
+
+ /*if (gpio3_value==0x1) {
+ i2s_alc5630_write(0x02, 0x0000, g_i2c_client);
+ i2s_alc5630_write(0x3A, i2s_alc5630_read(0x3A, data,g_i2c_client)|0x0040 , g_i2c_client);
+ printk("External speaker is plugged in... and Try to mute internal speaker......\n");
+ }
+ else {
+ i2s_alc5630_write(0x02, 0x5F5F, g_i2c_client);
+ i2s_alc5630_write(0x3A, i2s_alc5630_read(0x3A, data,g_i2c_client)|0x0440 , g_i2c_client);
+ printk("External speaker is pulled ... and Try to unmute internal speaker......\n");
+ }*/
+
+
+ //Set gpio3 pin value to 0
+ //REG32(GPIO_VA_BASE + 0x08) = REG32(GPIO_VA_BASE + 0x08) | (0x1UL << 3); //Set gpio3 direction => output
+ //value = REG32(GPIO_VA_BASE + 0x00) & ~(0x1UL << 3);
+ //REG32(GPIO_VA_BASE + 0x00) = value;
+
+ //Get gpio pin value again
+ //REG32(GPIO_VA_BASE + 0x08) = REG32(GPIO_VA_BASE + 0x08) & ~(0x1UL << 3); //Set gpio3 direction => input
+ //gpio3_value = (REG32(GPIO_VA_BASE + 0x04) >> 3 & 1);
+ //printk("The gpio3 value is 0x%08x\n",gpio3_value);
+
+ //restore original gpio interrupt mask
+ REG32(GPIO_VA_BASE + 0x2c) = org_mask;
+
+ //restore original gpio direction
+ REG32(GPIO_VA_BASE + 0x08) = org_dir;
+
+ //unmask GPIO interrupt
+ //REG32(AMIC_VA_BASE + 0x80) = REG32(AMIC_VA_BASE + 0x80) | (1 << 13); //GPIO interrupt enable
+ REG32(AMIC_VA_BASE + 0x84) = REG32(AMIC_VA_BASE + 0x84) | (1 << 13); //Clear GPIO interrupt
+ REG32(GPIO_VA_BASE + 0x30) = 0x0000FFFF; //Clear all gpio interrupt
+
+ //printk("@@@@@#####$$$$$!!!!! : gpio2_irq() is exited....\n");
+
+ return IRQ_HANDLED;
+}
+
+static void iic_work(struct work_struct *work)
+{
+ char data[3];
+ struct alc5630_data *alc5630 =
+ container_of(to_delayed_work(work), struct alc5630_data, work);
+
+
+ if (alc5630->gpio2_value==0x0) {
+ //i2s_alc5630_write(0x02, 0x0000, alc5630->client);
+ i2s_alc5630_write(0x02, 0x5F5F, alc5630->client);
+ i2s_alc5630_write(0x3A, (i2s_alc5630_read(0x3A, data,alc5630->client) & 0xFBFF) | 0x0040 , alc5630->client);
+ //printk("External speaker is plugged in... and Try to mute internal speaker......\n");
+ //i2s_alc5630_read_test(alc5630->client);
+ }
+ else {
+ //i2s_alc5630_write(0x02, 0x5F5F, alc5630->client);
+ i2s_alc5630_write(0x02, 0x0000, alc5630->client);
+ i2s_alc5630_write(0x3A, i2s_alc5630_read(0x3A, data,alc5630->client)|0x0440 , alc5630->client);
+ //printk("External speaker is pulled ... and Try to unmute internal speaker......\n");
+ //i2s_alc5630_read_test(alc5630->client);
+ }
+ //ftsdc_enable_irq(host, false);
+
+
+ //ftsdc_enable_irq(host, true);
+}
+
+static int alc5630_i2c_probe(struct i2c_client *client, const struct i2c_device_id *id)
+{
+
+ struct alc5630_data *alc5630;
+ struct i2c_adapter *adap = client->adapter;
+ //unsigned char ret1, ret2;
+ struct i2c_msg msg;
+ char rbuf[3], wbuf[3];
+ int ret, i2c_rvalue, i2c_wvalue;
+ unsigned int gpio2_value;
+ char data[3];
+
+ //i2c_dbg( 1, "alc5630_i2c_probe() is called.\n");
+ //printk(">>>>>>>>>> (3) alc5630_i2c_probe() is called.\n");
+
+ alc5630 = kzalloc(sizeof(struct alc5630_data), GFP_KERNEL);
+
+ if (!alc5630)
+ return -ENOMEM;
+
+ mutex_init(&alc5630->mtx);
+ client-> flags = 0;
+ alc5630->client = client;
+ i2c_set_clientdata(client, alc5630);
+
+ //ADD by river 2011.05.18 for GPIO2 interrupt => edge trigger and rising edge
+ REG32(GPIO_VA_BASE + 0x20) = 0x00000000;
+ REG32(GPIO_VA_BASE + 0x2c) = 0x00000000;
+ REG32(GPIO_VA_BASE + 0x2c) = 0x00000000;
+ REG32(GPIO_VA_BASE + 0x30) = 0x0000FFFF;
+ REG32(GPIO_VA_BASE + 0x38) = 0x0000FFFF;
+ REG32(GPIO_VA_BASE + 0x40) = 0x0000FFFF;
+
+
+ REG32(GPIO_VA_BASE + 0x08) = REG32(GPIO_VA_BASE + 0x08) & ~(1 << 2); //GPIO2 as input
+ REG32(GPIO_VA_BASE + 0x34) = REG32(GPIO_VA_BASE + 0x34) & ~(1 << 2); //GPIO2 edge trigger
+ //REG32(GPIO_VA_BASE + 0x38) = REG32(GPIO_VA_BASE + 0x38) & ~(1 << 2); //GPIO2 single edge
+ REG32(GPIO_VA_BASE + 0x38) = REG32(GPIO_VA_BASE + 0x38) | (1 << 2); //GPIO2 both edge
+ REG32(GPIO_VA_BASE + 0x3c) = REG32(GPIO_VA_BASE + 0x3c) & ~(1 << 2); //GPIO2 rising edge
+ REG32(GPIO_VA_BASE + 0x20) = REG32(GPIO_VA_BASE + 0x20) | (1 << 2); //GPIO2 pin interrupt enable
+
+ REG32(AMIC_VA_BASE + 0x20) = REG32(AMIC_VA_BASE + 0x20) | (1 << 13); //Interrupt Trigger Mode (edge trigger)
+ REG32(AMIC_VA_BASE + 0x24) = REG32(AMIC_VA_BASE + 0x24) & ~(1 << 13); //Interrupt Trigger edge(rising edge)
+ REG32(AMIC_VA_BASE + 0x80) = REG32(AMIC_VA_BASE + 0x80) | (1 << 13); //GPIO interrupt enabled
+ //REG32(AMIC_VA_BASE + 0x80) = 0; //GPIO interrupt enabled
+
+ if (request_irq(GPIO_FTGPIO010_IRQ, gpio2_irq, IRQF_SHARED, "gpio2", client)) {
+ printk("Failed to request GPIO2 interrupt.\n");
+ goto fail;
+ }
+
+ //ADD by river 2011.07.11
+ //REG32(GPIO_VA_BASE + 0x08) = REG32(GPIO_VA_BASE + 0x08) & ~(0x1UL << 3); //Set gpio3 direction => input
+ gpio2_value = (REG32(GPIO_VA_BASE + 0x04) >> 2 & 1);
+ //printk("The gpio2 value is 0x%08x\n",gpio2_value);
+ alc5630->gpio2_value = gpio2_value;
+
+ if (gpio2_value==0x0) {
+ i2s_alc5630_write(0x02, 0x5F5F, alc5630->client);
+ i2s_alc5630_write(0x3A, (i2s_alc5630_read(0x3A, data,alc5630->client) & 0xFBFF) | 0x0040 , alc5630->client);
+ //printk("@@@@@ alc5630_i2c_probe : External speaker is plugged in... and Try to mute internal speaker......\n");
+ //i2s_alc5630_read_test(alc5630->client);
+ }
+ else {
+ i2s_alc5630_write(0x02, 0x0000, alc5630->client);
+ i2s_alc5630_write(0x3A, i2s_alc5630_read(0x3A, data,alc5630->client)|0x0440 , alc5630->client);
+ //printk("@@@@@ alc5630_i2c_probe : External speaker is pulled ... and Try to unmute internal speaker......\n");
+ //i2s_alc5630_read_test(alc5630->client);
+ }
+
+ //End ADD by river 2011.07.11
+
+ //ADD by river 2011.06.02
+ INIT_DELAYED_WORK(&alc5630->work, iic_work);
+ //End ADD by river 2011.06.02
+ //End ADD by river 2011.05.18
+
+ ftssp_alsa_init(client);
+
+ return 0;
+ fail:
+ mutex_destroy(&alc5630->mtx);
+ kfree(alc5630);
+ return -EINVAL;
+
+}
+
+////////End ADD by river 2011.01.26
+#endif
+
+/* ---------------------------------------------------------------------------
+ * Preserved size of memory space for audio DMA ring
+ */
+#define FTSSP_HW_DMA_SIZE (512 * 1024)
+
+/* Buffer sizes reported to ALSA layer - AC97 mode */
+
+/* ring size, exported to application */
+#define AC97_HW_BUFFER_BYTES_MAX (42 * 1024)
+/* should not exceed AC97_HW_PERIOD_BYTES_MAX */
+#define AC97_HW_PERIOD_BYTES_MIN (2 * 1024)
+/* AC97_HW_PERIOD_BYTES_MAX * AC97_HW_PERIODS_MAX <= AC97_HW_BUFFER_SIZE */
+#define AC97_HW_PERIOD_BYTES_MAX (8 * 1024)
+/* 3 <= AC97_HW_PERIODS_MIN <= AC97_HW_PERIODS_MAX */
+#define AC97_HW_PERIODS_MIN 3
+/* AC97_HW_PERIOD_BYTES_MAX * AC97_HW_PERIODS_MAX <= AC97_HW_BUFFER_SIZE */
+#define AC97_HW_PERIODS_MAX 5
+
+/* Driver internal dma buffer size, x2 for S16_LE(16-bits) to AC97 (20-bits),
+ * x6 for sampling rate converion from minimum 8k to AC97 48k.
+ *
+ * Note that AC97 mode cannot do playback and recording simultaneouly. So we
+ * use up all FTSSP_HW_DMA_SIZE of memory.
+ */
+#define AC97_HW_DMA_SIZE (AC97_HW_BUFFER_BYTES_MAX * 2 * 6)
+
+/* Buffer sizes reported to ALSA layer - I2S mode */
+
+/* ring size, exported to application */
+#define I2S_HW_BUFFER_BYTES_MAX (256 * 1024)
+/* should not exceed I2S_HW_PERIOD_BYTES_MAX */
+#define I2S_HW_PERIOD_BYTES_MIN (2 * 1024)
+/* I2S_HW_PERIOD_BYTES_MAX * I2S_HW_PERIODS_MAX <= I2S_HW_BUFFER_SIZE */
+#define I2S_HW_PERIOD_BYTES_MAX (32 * 1024)
+/* 3 <= I2S_HW_PERIODS_MIN <= I2S_HW_PERIODS_MAX */
+#define I2S_HW_PERIODS_MIN 3
+/* I2S_HW_PERIOD_BYTES_MAX * I2S_HW_PERIODS_MAX <= I2S_HW_BUFFER_SIZE */
+#define I2S_HW_PERIODS_MAX 8
+
+/* Page-in size for playback and capture each. Note that I2S mode can do
+ * playback and recording simultaneouly, so this size should be less than or
+ * equal to FTSSP_HW_DMA_SIZE/2
+ */
+#define I2S_HW_DMA_SIZE (I2S_HW_BUFFER_BYTES_MAX)
+
+/* ---------------------------------------------------------------------------
+ * Audio formats
+ */
+#define AC97_CODEC_FORMATS (SNDRV_PCM_FMTBIT_S16_LE)
+#define AC97_CODEC_SAMPLE_RATES (SNDRV_PCM_RATE_48000 | \
+ SNDRV_PCM_RATE_16000 | \
+ SNDRV_PCM_RATE_8000)
+#define AC97_CODEC_SAMPLE_RATE_MIN (8000)
+#define AC97_CODEC_SAMPLE_RATE_MAX (48000)
+
+#define I2S_CODEC_FORMATS (SNDRV_PCM_FMTBIT_S16_LE)
+#define I2S_CODEC_SAMPLE_RATES (SNDRV_PCM_RATE_48000 | \
+ SNDRV_PCM_RATE_44100 | \
+ SNDRV_PCM_RATE_32000 | \
+ SNDRV_PCM_RATE_22050 | \
+ SNDRV_PCM_RATE_16000 | \
+ SNDRV_PCM_RATE_11025 | \
+ SNDRV_PCM_RATE_8000)
+#define I2S_CODEC_SAMPLE_RATE_MIN (8000)
+#define I2S_CODEC_SAMPLE_RATE_MAX (48000)
+
+
+/* ---------------------------------------------------------------------------
+ * Configuration
+ */
+#if (CONFIG_PROC_FS == 0)
+#undef FTSSP_PROC_FS
+#define FTSSP_PROC_FS 0
+#else
+#if (FTSSP_PROC_FS)
+#include <sound/info.h>
+#endif /* FTSSP_PROC_FS */
+#endif /* CONFIG_PROC_FS */
+
+#define FTSSP_CARD_ID "ftssp010"
+#define FTSSP_DRIVER_NAME "ftssp"
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Faraday Technology Corp.");
+MODULE_DESCRIPTION("FTSSP010 Linux 2.6 Driver");
+
+static int cardno = 0;
+//static const unsigned int SSP_FTSSP010_pa_base[SSP_FTSSP010_IRQ_COUNT] =
+// { SSP_FTSSP010_PA_BASE };
+
+/* Driver mode */
+#ifdef CONFIG_SND_FTSSP010_AC97
+static int ac97 = 1;
+#else
+static int ac97 = 0;
+#endif
+
+// ----------------------------------------------
+module_param(cardno, int, 0);
+MODULE_PARM_DESC(cardno, "FTSSP No.");
+
+module_param(ac97, int, 0);
+MODULE_PARM_DESC(ac97, "AC97 mode");
+// ----------------------------------------------
+
+/* ---------------------------------------------------------------------------
+ * Structures
+ */
+
+/* private data for card */
+typedef struct {
+ struct snd_card *card;
+ struct snd_pcm *pcm;
+ struct snd_pcm_substream *substream_tx;
+ struct snd_pcm_substream *substream_rx;
+#if (FTSSP_PROC_FS)
+ struct snd_info_entry *info_buf_max;
+ struct snd_info_entry *info_period_min;
+ struct snd_info_entry *info_period_max;
+ struct snd_info_entry *info_periods_min;
+ struct snd_info_entry *info_periods_max;
+#endif
+} ftssp_chip;
+
+/* dma request descriptors */
+dmad_chreq dma_chreq_tx = {
+ .channel = -1,
+ .drq = NULL,
+};
+
+dmad_chreq dma_chreq_rx = {
+ .channel = -1,
+ .drq = NULL,
+};
+
+/* Holds ALSA card instance pointers */
+struct snd_card *ftssp_cards[SSP_FTSSP010_COUNT];
+
+/* snd_pcm_hardware */
+static struct snd_pcm_hardware snd_ftssp_pcm_hw =
+{
+ .info = SNDRV_PCM_INFO_INTERLEAVED,
+ .formats = I2S_CODEC_FORMATS,
+ .rates = I2S_CODEC_SAMPLE_RATES,
+ .rate_min = I2S_CODEC_SAMPLE_RATE_MIN,
+ .rate_max = I2S_CODEC_SAMPLE_RATE_MAX,
+ .channels_min = 1,
+ .channels_max = 2,
+ .buffer_bytes_max = I2S_HW_BUFFER_BYTES_MAX,
+ .period_bytes_min = I2S_HW_PERIOD_BYTES_MIN,
+ .period_bytes_max = I2S_HW_PERIOD_BYTES_MAX,
+ .periods_min = I2S_HW_PERIODS_MIN,
+ .periods_max = I2S_HW_PERIODS_MAX,
+};
+
+/* private data for a substream (playback or capture) */
+/* function pointer for set up AHBDMA for this substream */
+typedef void (*start_t)(int cardno, unsigned use_dma);
+typedef void (*pmu_set_clocking_t)(unsigned int);
+typedef void (*ftssp010_config_t)(int cardno, unsigned is_stereo,
+ unsigned speed, int use8bit);
+
+typedef struct {
+ u32 busy;
+ spinlock_t dma_lock;
+ unsigned dma_area_va;
+ int dma_width;
+ unsigned int tx_period;
+ unsigned int rx_period;
+
+ start_t start;
+ pmu_set_clocking_t pmu_set_clocking;
+ ftssp010_config_t hw_config;
+} ftssp_substream;
+
+static ftssp_substream ftssp010_substreams[2] = {
+ /* Playback substream */
+ {
+ busy : 0,
+ start : ftssp010_start_tx,
+ pmu_set_clocking : pmu_set_i2s_clocking,
+ hw_config : ftssp010_config_tx,
+ },
+ /* Capture substream */
+ {
+ busy : 0,
+ start : ftssp010_start_rx,
+ pmu_set_clocking : pmu_set_i2s_clocking,
+ hw_config : ftssp010_config_rx,
+ }
+};
+
+/* (AC97 only) Convert 16 bits PCM data in user buffer to/from 20 bits PCM data
+ * (32 bits actaully in dma buffer) for AC97 codec.
+ */
+static int snd_ftssp_playback_copy(struct snd_pcm_substream *substream,
+ int channel, snd_pcm_uframes_t pos, void *usr_buf,
+ snd_pcm_uframes_t count)
+{
+ struct snd_pcm_runtime *runtime = substream->runtime;
+ ftssp_substream *ftssp010_substream =
+ (ftssp_substream *) runtime->private_data;
+
+
+ //printk("~~~~~ : snd_ftssp_playback_copy() is invoked....\n");
+ u32 *dma_va = NULL;
+ u16 *usr_va = usr_buf;
+ int copy_words;
+ int pcm_data;
+
+ dmad_chreq *dma_chreq;
+
+ /* frames_to_bytes(runtime, pos + count) * 2(bytes/per pcm) /
+ * 4(bytes per dma unit) */
+ u32 sw_ptr = (u32)frames_to_bytes(runtime, pos + count) >> 1;
+
+ switch (runtime->rate) {
+ case 8000:
+ sw_ptr *= 6;
+
+ dma_va = (unsigned *)(ftssp010_substream->dma_area_va +
+ frames_to_bytes(runtime, pos * 6) * 2);
+
+ VVDBG("%s: pos(0x%08x) count(0x%08x) next_pos(0x%08x)\n",
+ __func__, (u32)pos, (u32)count, (u32)(pos + count));
+ VVDBG("%s: va base(0x%08x) range (0x%08x ~ 0x%08x)\n",
+ __func__, (u32)ftssp010_substream->dma_area_va,
+ (u32)dma_va,
+ (u32)dma_va +
+ (u32)2 * frames_to_bytes(runtime, count * 6));
+
+ if (runtime->channels == 1) {
+ while (count--) {
+ dma_va[0] = (u32)(*usr_va++) << 4;
+ dma_va[1] = dma_va[2] = dma_va[3] =
+ dma_va[4] = dma_va[5] = dma_va[0];
+ //memcpy(&dma_va[1], &dma_va[0], 5 * 4 * 1);
+ dma_va += 6;
+ }
+ } else { // assume 2 channels
+ while (count--) {
+ dma_va[0] = (u32)(*usr_va++) << 4;
+ dma_va[1] = (u32)(*usr_va++) << 4;
+ dma_va[2] = dma_va[4] = dma_va[6] =
+ dma_va[8] = dma_va[10] = dma_va[0];
+ dma_va[3] = dma_va[5] = dma_va[7] =
+ dma_va[9] = dma_va[11] = dma_va[0];
+ //memcpy(&dma_va[2], &dma_va[0], 5 * 4 * 2);
+ dma_va += 12;
+ }
+ }
+ break;
+ case 16000:
+ sw_ptr *= 3;
+
+ dma_va = (unsigned *)(ftssp010_substream->dma_area_va +
+ frames_to_bytes(runtime, pos * 3) * 2);
+
+ VVDBG("%s: pos(0x%08x) count(0x%08x) next_pos(0x%08x)\n",
+ __func__, (u32)pos, (u32)count, (u32)(pos + count));
+ VVDBG("%s: va base(0x%08x) range (0x%08x ~ 0x%08x)\n",
+ __func__, (u32)ftssp010_substream->dma_area_va,
+ (u32)dma_va,
+ (u32)dma_va +
+ (u32)2 * frames_to_bytes(runtime, count * 3));
+
+ if (runtime->channels == 1) {
+ while (count--) {
+ dma_va[0] = (u32)(*usr_va++) << 4;
+ dma_va[1] = dma_va[2] = dma_va[0];
+ //memcpy(&dma_va[1], &dma_va[0], 2 * 4 * 1);
+ dma_va += 3;
+ }
+ } else { // assume 2 channels
+ while (count--) {
+ dma_va[0] = (u32)(*usr_va++) << 4;
+ dma_va[1] = (u32)(*usr_va++) << 4;
+ dma_va[2] = dma_va[4] = dma_va[0];
+ dma_va[3] = dma_va[5] = dma_va[1];
+ //memcpy(&dma_va[2], &dma_va[0], 2 * 4 * 2);
+ dma_va += 6;
+ }
+ }
+ break;
+ case 48000:
+ default:
+ dma_va = (unsigned *)(ftssp010_substream->dma_area_va +
+ frames_to_bytes(runtime, pos) * 2);
+ copy_words = 2 * frames_to_bytes(runtime, count) / sizeof(u32);
+
+ VVDBG("%s: pos(0x%08x) count(0x%08x) next_pos(0x%08x)\n",
+ __func__, (u32)pos, (u32)count, (u32)(pos + count));
+ VVDBG("%s: va base(0x%08x) range (0x%08x ~ 0x%08x)\n",
+ __func__, (u32)ftssp010_substream->dma_area_va,
+ (u32)dma_va,
+ (u32)dma_va + (u32)copy_words*4);
+
+ while (copy_words--) {
+ pcm_data = (*usr_va++);
+ *dma_va++= pcm_data << 4;
+ }
+ break;
+ }
+
+ dma_chreq = &dma_chreq_tx;
+
+ if (dmad_update_ring_sw_ptr(dma_chreq, sw_ptr,
+ (runtime->status->state == SNDRV_PCM_STATE_RUNNING) ? 1:0) != 0)
+ {
+ ERR("%s: failed to update sw-pointer!\n", __func__);
+ return -ENODEV;
+ }
+
+ return 0;
+}
+
+static int snd_ftssp_capture_copy(struct snd_pcm_substream *substream,
+ int channel, snd_pcm_uframes_t pos, void *usr_buf,
+ snd_pcm_uframes_t count)
+{
+ struct snd_pcm_runtime *runtime = substream->runtime;
+ ftssp_substream *ftssp010_substream =
+ (ftssp_substream *) runtime->private_data;
+
+ //printk("~~~~~ : snd_ftssp_capture_copy() is invoked....\n");
+ //printk(">>>>>>>>>> : snd_ftssp_capture_copy() for recording....\n");
+ u32 *dma_va = NULL;
+ u16 *usr_va = usr_buf;
+
+ switch (runtime->rate) {
+ case 8000:
+ dma_va = (unsigned *)(ftssp010_substream->dma_area_va +
+ frames_to_bytes(runtime, pos * 6) * 2);
+
+ VVDBG("%s: pos(0x%08x) count(0x%08x) next_pos(0x%08x)\n",
+ __func__, (u32)pos, (u32)count, (u32)(pos + count));
+ VVDBG("%s: va base(0x%08x) range (0x%08x ~ 0x%08x)\n",
+ __func__, (u32)ftssp010_substream->dma_area_va,
+ (u32)dma_va,
+ (u32)dma_va +
+ (u32)2 * frames_to_bytes(runtime, count * 6));
+
+ if (runtime->channels == 1) {
+ while (count--) {
+ *usr_va++ = (u16)(dma_va[0] >> 4);
+ dma_va += 6;
+ }
+ } else {
+ while (count--) {
+ usr_va[0] = (u16)(dma_va[0] >> 4);
+
+ /* [hw-limit] only slot-3 has valid data in
+ * recording mode -- check TAG_DATA_MONO
+ * defined in "FTSSP010_lib.c". Mask out
+ * one channel to avoid hi-freq noise.
+ */
+ usr_va[1] = usr_va[0];
+ usr_va += 2;
+ dma_va += 12;
+ }
+ }
+ break;
+ case 16000:
+ dma_va = (unsigned *)(ftssp010_substream->dma_area_va +
+ frames_to_bytes(runtime, pos * 3) * 2);
+
+ VVDBG("%s: pos(0x%08x) count(0x%08x) next_pos(0x%08x)\n",
+ __func__, (u32)pos, (u32)count, (u32)(pos + count));
+ VVDBG("%s: va base(0x%08x) range (0x%08x ~ 0x%08x)\n",
+ __func__, (u32)ftssp010_substream->dma_area_va,
+ (u32)dma_va,
+ (u32)dma_va +
+ (u32)2 * frames_to_bytes(runtime, count * 3));
+
+ if (runtime->channels == 1) {
+ while (count--) {
+ *usr_va++ = (u16)(dma_va[0] >> 4);
+ dma_va += 3;
+ }
+ } else {
+ while (count--) {
+ usr_va[0] = (u16)(dma_va[0] >> 4);
+
+ /* [hw-limit] only slot-3 has valid data in
+ * recording mode -- check TAG_DATA_MONO
+ * defined in "FTSSP010_lib.c". Mask out
+ * one channel to avoid hi-freq noise.
+ */
+ usr_va[1] = usr_va[0];
+ usr_va += 2;
+ dma_va += 6;
+ }
+ }
+ break;
+ case 48000:
+ default:
+ dma_va = (unsigned *)(ftssp010_substream->dma_area_va +
+ frames_to_bytes(runtime, pos) * 2);
+
+ VVDBG("%s: pos(0x%08x) count(0x%08x) next_pos(0x%08x)\n",
+ __func__, (u32)pos, (u32)count, (u32)(pos + count));
+ VVDBG("%s: va base(0x%08x) range (0x%08x ~ 0x%08x)\n",
+ __func__, (u32)ftssp010_substream->dma_area_va,
+ (u32)dma_va,
+ (u32)dma_va +
+ (u32)2 * frames_to_bytes(runtime, count));
+
+ if (runtime->channels == 1) {
+ while (count--) {
+ *usr_va++ = (u16)(*dma_va++ >> 4);
+ }
+ } else {
+ while (count--) {
+ usr_va[0] = (u16)(dma_va[0] >> 4);
+
+ /* [hw-limit] only slot-3 has valid data in
+ * recording mode -- check TAG_DATA_MONO
+ * defined in "FTSSP010_lib.c". Mask out
+ * one channel to avoid hi-freq noise.
+ */
+ usr_va[1] = usr_va[0];
+ usr_va += 2;
+ dma_va += 2;
+ }
+ }
+ break;
+ }
+
+ return 0;
+}
+
+/**
+ * These dma callbacks are called in interrupt context.
+ * @data: pointer to the chip-wide structure.
+ * TODO: use stream-specifc data
+ */
+__attribute__((__unused__))
+static void ftssp_dma_callback_tx(int ch, u16 int_status, void *data)
+{
+ ftssp_chip *chip = (ftssp_chip *)data;
+
+ //printk("~~~~~ : ftssp_dma_callback_tx() is invoked....\n");
+ if (!ac97) {
+ /* in i2s mode, no indication to driver for user data length.
+ * For simplicity, just go ahead by one period */
+
+ struct snd_pcm_runtime *runtime = chip->substream_tx->runtime;
+ ftssp_substream *ftssp010_substream =
+ (ftssp_substream *)runtime->private_data;
+ u32 sw_ptr;
+ u32 tx_period = ftssp010_substream->tx_period + 1;
+
+ if (tx_period == runtime->periods)
+ sw_ptr = runtime->buffer_size;
+ else
+ sw_ptr = tx_period * runtime->period_size;
+
+ sw_ptr = (u32)frames_to_bytes(runtime, sw_ptr) >> 1;
+
+ if (dmad_update_ring_sw_ptr(&dma_chreq_tx, (u32)sw_ptr, 0)) {
+ ERR("%s: failed to update sw-pointer!\n", __func__);
+ }
+
+ ftssp010_substream->tx_period = tx_period % runtime->periods;
+ }
+
+ snd_pcm_period_elapsed(chip->substream_tx);
+}
+
+__attribute__((__unused__))
+static void ftssp_dma_callback_rx(int ch, u16 int_status, void *data)
+{
+ ftssp_chip *chip = (ftssp_chip *)data;
+ struct snd_pcm_runtime *runtime = chip->substream_rx->runtime;
+ ftssp_substream *ftssp010_substream =
+ (ftssp_substream *)runtime->private_data;
+
+ //printk("~~~~~ : ftssp_dma_callback_rx() is invoked....\n");
+ //printk(">>>>>>>>>> : ftssp_dma_callback_rx() for recording....\n");
+
+ u32 sw_ptr;
+ u32 rx_period = ftssp010_substream->rx_period + 1;
+
+ if (rx_period == runtime->periods)
+ sw_ptr = runtime->buffer_size;
+ else
+ sw_ptr = rx_period * runtime->period_size;
+
+ if (ac97) {
+ switch (runtime->rate) {
+ case 8000:
+ sw_ptr = sw_ptr * 6;
+ break;
+ case 16000:
+ sw_ptr = sw_ptr * 3;
+ break;
+ case 48000:
+ default:
+ break;
+ }
+ }
+ sw_ptr = (u32)frames_to_bytes(runtime, sw_ptr) >> 1;
+
+ if (dmad_update_ring_sw_ptr(&dma_chreq_rx, (u32)sw_ptr, 0) != 0) {
+ ERR("%s: failed to update sw-pointer!\n", __func__);
+ }
+
+ ftssp010_substream->rx_period = rx_period % runtime->periods;
+
+ snd_pcm_period_elapsed(chip->substream_rx);
+}
+
+static inline int snd_ftssp_dma_ch_alloc(struct snd_pcm_substream *substream)
+{
+ dmad_chreq *ch_req __attribute__((__unused__)) = 0;
+
+ //printk("~~~~~ WATCH : snd_ftssp_dma_ch_alloc() is invoked....\n");
+#ifdef CONFIG_PLATFORM_APBDMA
+
+ if (substream->pstr->stream == SNDRV_PCM_STREAM_PLAYBACK) {
+ ch_req = &dma_chreq_tx;
+ ch_req->completion_cb = ftssp_dma_callback_tx;
+ ch_req->apb_req.tx_dir = DMAD_DIR_A0_TO_A1;
+ /*for amerald ac97 ssp2 */
+ if((inl(PMU_BASE) & AMERALD_MASK) == AMERALD_PRODUCT_ID)
+ {
+ ch_req->apb_req.dev_reqn = APBBR_REQN_I2SAC97TX_AMERALD;
+ }
+ else
+ ch_req->apb_req.dev_reqn = APBBR_REQN_I2SAC97TX;
+ } else {
+ ch_req = &dma_chreq_rx;
+ ch_req->completion_cb = ftssp_dma_callback_rx;
+ ch_req->apb_req.tx_dir = DMAD_DIR_A1_TO_A0;
+ /*for amerald ac97 ssp2 */
+ if((inl(PMU_BASE) & AMERALD_MASK) == AMERALD_PRODUCT_ID)
+ {
+ ch_req->apb_req.dev_reqn = APBBR_REQN_I2SAC97RX_AMERALD;
+ }
+ else
+ ch_req->apb_req.dev_reqn = APBBR_REQN_I2SAC97RX;
+ }
+
+ ch_req->controller = DMAD_DMAC_APB_CORE;
+ ch_req->flags = DMAD_FLAGS_RING_MODE;
+ ch_req->ring_base = 0;
+ ch_req->dev_addr = (dma_addr_t)FTSSP010_DATA_PA(cardno);
+ ch_req->periods = 0;
+ ch_req->period_size = 0;
+
+ if (ac97) {
+ ch_req->apb_req.ring_ctrl = APBBR_ADDRINC_I4X;
+ ch_req->apb_req.ring_reqn = APBBR_REQN_NONE;
+ ch_req->apb_req.dev_ctrl = APBBR_ADDRINC_FIXED;
+ ch_req->apb_req.burst_mode = 0;
+ ch_req->apb_req.data_width = APBBR_DATAWIDTH_4;
+ } else {
+ ch_req->apb_req.ring_ctrl = APBBR_ADDRINC_I2X;
+ ch_req->apb_req.ring_reqn = APBBR_REQN_NONE;
+ ch_req->apb_req.dev_ctrl = APBBR_ADDRINC_FIXED;
+ ch_req->apb_req.burst_mode = 0;
+ ch_req->apb_req.data_width = APBBR_DATAWIDTH_2;
+ }
+
+ ch_req->completion_data = (void *)snd_pcm_substream_chip(substream);
+
+ if (dmad_channel_alloc(ch_req) != 0) {
+ ERR("%s: APBDMA channel allocation failed\n",__func__);
+ goto _try_ahb;
+ }
+
+ DBG("%s: APBDMA channel allocated (ch: %d) ring_mode\n",
+ __func__, ch_req->channel);
+
+ return 0;
+
+_try_ahb:
+
+#endif /* CONFIG_PLATFORM_APBDMA */
+
+#ifdef CONFIG_PLATFORM_AHBDMA
+ if (substream->pstr->stream == SNDRV_PCM_STREAM_PLAYBACK) {
+ ch_req = &dma_chreq_tx;
+ ch_req->completion_cb = ftssp_dma_callback_tx;
+ ch_req->ahb_req.tx_dir = DMAD_DIR_A0_TO_A1;
+ if((inl(PMU_BASE) & AMERALD_MASK) == AMERALD_PRODUCT_ID)
+ {
+ ch_req->ahb_req.dev_reqn = DMAC_REQN_I2SAC97TX_AMERALD;
+ }
+ else
+ ch_req->ahb_req.dev_reqn = DMAC_REQN_I2SAC97TX;
+ } else {
+ ch_req = &dma_chreq_rx;
+ ch_req->completion_cb = ftssp_dma_callback_rx;
+ ch_req->ahb_req.tx_dir = DMAD_DIR_A1_TO_A0;
+ if((inl(PMU_BASE) & AMERALD_MASK) == AMERALD_PRODUCT_ID)
+ {
+ ch_req->ahb_req.dev_reqn = DMAC_REQN_I2SAC97RX_AMERALD;
+ }
+ else
+ ch_req->ahb_req.dev_reqn = DMAC_REQN_I2SAC97RX;
+ }
+
+ ch_req->controller = DMAD_DMAC_AHB_CORE;
+ ch_req->flags = DMAD_FLAGS_RING_MODE;
+ ch_req->ring_base = 0;
+ ch_req->dev_addr = (dma_addr_t)FTSSP010_DATA_PA(cardno);
+ ch_req->periods = 0;
+ ch_req->period_size = 0;
+
+ ch_req->ahb_req.sync = 1;
+ ch_req->ahb_req.priority = DMAC_CSR_CHPRI_2;
+ ch_req->ahb_req.hw_handshake = 1;
+ ch_req->ahb_req.burst_size = DMAC_CSR_SIZE_1;
+
+ if (ac97) {
+ ch_req->ahb_req.ring_width = DMAC_CSR_WIDTH_32;
+ ch_req->ahb_req.ring_ctrl = DMAC_CSR_AD_INC;
+ ch_req->ahb_req.ring_reqn = DMAC_REQN_NONE;
+ ch_req->ahb_req.dev_width = DMAC_CSR_WIDTH_32;
+ ch_req->ahb_req.dev_ctrl = DMAC_CSR_AD_FIX;
+ } else {
+ ch_req->ahb_req.ring_width = DMAC_CSR_WIDTH_16;
+ ch_req->ahb_req.ring_ctrl = DMAC_CSR_AD_INC;
+ ch_req->ahb_req.ring_reqn = DMAC_REQN_NONE;
+ ch_req->ahb_req.dev_width = DMAC_CSR_WIDTH_16;
+ ch_req->ahb_req.dev_ctrl = DMAC_CSR_AD_FIX;
+ }
+
+ ch_req->completion_data = (void *)snd_pcm_substream_chip(substream);
+
+ if (dmad_channel_alloc(ch_req) != 0) {
+ ERR("%s: AHBDMA channel allocation failed\n", __func__);
+ goto _err_exit;
+ }
+
+ DBG("%s: AHBDMA channel allocated (ch: %d) ring_mode\n",
+ __func__, ch_req->channel);
+
+ return 0;
+
+_err_exit:
+
+#endif /* CONFIG_PLATFORM_AHBDMA */
+
+ return -ENODEV;
+}
+
+static inline ftssp_substream *ftssp010_substream_new(int stream_id)
+{
+ ftssp_substream *s = NULL;
+
+ //printk("~~~~~ : ftssp010_substream_new() is invoked....\n");
+
+ switch (stream_id) {
+ case SNDRV_PCM_STREAM_PLAYBACK:
+ s = &ftssp010_substreams[0];
+ break;
+ case SNDRV_PCM_STREAM_CAPTURE:
+ s = &ftssp010_substreams[1];
+ break;
+ default:
+ ERR("%s: wrong stream type (%d)\n", __func__, stream_id);
+ return NULL;
+ }
+
+ if (s->busy) {
+ ERR("%s: device busy!\n", __func__);
+ return NULL;
+ }
+ s->busy = 1;
+
+ spin_lock_init(&s->dma_lock);
+
+ return s;
+}
+
+static int snd_ftssp_pcm_open(struct snd_pcm_substream *substream)
+{
+ struct snd_pcm_runtime *runtime = substream->runtime;
+ int stream_id = substream->pstr->stream;
+
+ VDBG("%s, %s\n", __func__,
+ (substream->pstr->stream == SNDRV_PCM_STREAM_PLAYBACK) ?
+ "playback" : "capture");
+
+ //printk("~~~~~ : snd_ftssp_pcm_open() is invoked....\n");
+
+ /* Both playback and capture share a hardware description */
+ runtime->hw = snd_ftssp_pcm_hw;
+
+ /* Allocate & Initialize stream-specific data */
+ runtime->private_data = ftssp010_substream_new(stream_id);
+
+ if (runtime->private_data) {
+ //printk("~~~~~ YAYAYA @@@@@ : Calling snd_ftssp_dma_ch_alloc().\n");
+ return snd_ftssp_dma_ch_alloc(substream);
+ }
+ else
+ return -EBUSY;
+}
+
+static int snd_ftssp_pcm_close(struct snd_pcm_substream *substream)
+{
+ int stream_id = substream->pstr->stream;
+ ftssp_substream *ftssp010_substream =
+ (ftssp_substream *)substream->runtime->private_data;
+
+ VDBG("%s, %s\n", __func__,
+ (substream->pstr->stream == SNDRV_PCM_STREAM_PLAYBACK) ?
+ "playback" : "capture");
+
+ //printk("~~~~~ : snd_ftssp_pcm_close() is invoked....\n");
+
+ if (stream_id == SNDRV_PCM_STREAM_PLAYBACK)
+ dmad_channel_free(&dma_chreq_tx);
+ else
+ dmad_channel_free(&dma_chreq_rx);
+
+ ftssp010_substream->busy = 0;
+ return 0;
+}
+
+static int snd_ftssp_pcm_hw_params(struct snd_pcm_substream *substream,
+ struct snd_pcm_hw_params *hw_params)
+{
+ VDBG("%s, %s\n", __func__,
+ (substream->pstr->stream == SNDRV_PCM_STREAM_PLAYBACK) ?
+ "playback" : "capture");
+
+ //printk("~~~~~ : snd_ftssp_pcm_hw_params() is invoked....\n");
+
+ if (ac97)
+ return snd_pcm_lib_malloc_pages(substream, AC97_HW_DMA_SIZE);
+ else
+ return snd_pcm_lib_malloc_pages(substream, I2S_HW_DMA_SIZE);
+}
+
+static int snd_ftssp_pcm_hw_free(struct snd_pcm_substream *substream)
+{
+ VDBG("%s, %s\n", __func__,
+ (substream->pstr->stream == SNDRV_PCM_STREAM_PLAYBACK) ?
+ "playback" : "capture");
+ //printk("~~~~~ : snd_ftssp_pcm_hw_free() is invoked....\n");
+
+ if (substream->pstr->stream == SNDRV_PCM_STREAM_PLAYBACK)
+ dmad_drain_requests(&dma_chreq_tx, 1);
+ else
+ dmad_drain_requests(&dma_chreq_rx, 1);
+
+ return snd_pcm_lib_free_pages(substream);
+}
+
+/* Prepare FTSSP010 AHBDMA for playback & capture */
+static int snd_ftssp_pcm_prepare(struct snd_pcm_substream *substream)
+{
+ ftssp_chip *chip = snd_pcm_substream_chip(substream);
+ struct snd_pcm_runtime *runtime = substream->runtime;
+
+ //printk("~~~~~ : snd_ftssp_pcm_prepare() is invoked....\n");
+ //printk("@@@@@ >>>>> : snd_ftssp_pcm_prepare() is called.\n");
+
+ ftssp_substream *ftssp010_substream =
+ (ftssp_substream *)runtime->private_data;
+
+ int stream_id = substream->pstr->stream;
+ dmad_chreq *dma_chreq;
+ unsigned period_size, buffer_size;
+
+ if (stream_id == SNDRV_PCM_STREAM_PLAYBACK)
+ dma_chreq = &dma_chreq_tx;
+ else
+ dma_chreq = &dma_chreq_rx;
+
+ period_size = frames_to_bytes(runtime, runtime->period_size);
+ buffer_size = frames_to_bytes(runtime, runtime->buffer_size);
+
+ if (runtime->format != SNDRV_PCM_FORMAT_S16_LE)
+ return -ENODEV;
+
+ if (ac97) {
+ switch (runtime->rate) {
+ case 8000:
+ period_size *= 12;
+ buffer_size *= 12;
+ break;
+ case 16000:
+ period_size *= 6;
+ buffer_size *= 6;
+ break;
+ case 48000:
+ default:
+ period_size *= 2;
+ buffer_size *= 2;
+ break;
+ }
+
+ ftssp010_substream->dma_width = 4;
+ } else {
+ ftssp010_substream->dma_width = 2;
+ }
+
+ dmad_drain_requests(dma_chreq, 1);
+
+ dma_chreq->ring_base = (dma_addr_t)runtime->dma_addr;
+ dma_chreq->periods = (dma_addr_t)runtime->periods;
+ if (ac97) {
+ dma_chreq->period_size = (dma_addr_t)(period_size >> 2);
+ dma_chreq->ring_size = (dma_addr_t)(buffer_size >> 2);
+ } else {
+ dma_chreq->period_size = (dma_addr_t)(period_size >> 1);
+ dma_chreq->ring_size = (dma_addr_t)(buffer_size >> 1);
+ }
+ dmad_update_ring(dma_chreq);
+
+ /* Set PMU, FTSSP010, and DMA */
+ spin_lock(&ftssp010_substream->dma_lock);
+
+ /* keep DMA buffer VA for copy() callback */
+ // todo: support playback/capture simultaneously
+ ftssp010_substream->dma_area_va = (u32)runtime->dma_area;
+
+ if (ac97) {
+ ftssp010_substream->pmu_set_clocking(48000);
+ ftssp010_substream->hw_config(cardno,
+ runtime->channels > 1 ? 1 : 0, /* 1: stereo, 0: mono */
+ 48000, ftssp010_substream->dma_width);
+ } else {
+
+ ftssp010_substream->pmu_set_clocking(runtime->rate);
+ ftssp010_substream->hw_config(cardno,
+ runtime->channels > 1 ? 1 : 0, /* 1: stereo, 0: mono */
+ runtime->rate, ftssp010_substream->dma_width);
+ }
+
+ if (stream_id == SNDRV_PCM_STREAM_PLAYBACK) {
+ ftssp010_substream->tx_period = 0;
+ chip->substream_tx = substream;
+ } else {
+ ftssp010_substream->rx_period = 0;
+ chip->substream_rx = substream;
+ }
+
+ spin_unlock(&ftssp010_substream->dma_lock);
+
+ VVDBG("%s <<\n", __func__);
+
+ return 0;
+}
+
+static inline int snd_ftssp_start_play(ftssp_substream *ftssp010_substream,
+ struct snd_pcm_runtime *runtime)
+{
+ int err = 0;
+
+ //printk("~~~~~ : snd_ftssp_start_play() is invoked....\n");
+
+ if (ac97) {
+ /* in ac97 mode, user data was fed to dma buffer through
+ * driver-provided copy callback */
+ err = dmad_kickoff_requests(&dma_chreq_tx);
+ if (err != 0) {
+ ERR("%s: failed to kickoff dma!\n", __func__);
+ return err;
+ }
+ } else {
+ /* in i2s mode, no indication to driver for user data length
+ * (except start threshold). For simplicity at start, just go
+ * ahead by one cycle */
+
+ u32 sw_ptr =
+ (u32)frames_to_bytes(runtime, runtime->buffer_size) >>1;
+
+ err = dmad_update_ring_sw_ptr(&dma_chreq_tx, sw_ptr, 0);
+ if (err != 0) {
+ ERR("%s: failed to update sw-pointer!\n", __func__);
+ return err;
+ }
+
+ err = dmad_kickoff_requests(&dma_chreq_tx);
+ if (err != 0) {
+ ERR("%s: failed to kickoff dma!\n", __func__);
+ return err;
+ }
+ }
+
+ ftssp010_substream->start(cardno, 1);
+
+ //ADD by river 2011.03.08
+ //i2s_alc5630_write(0x02, 0x0000, g_i2c_client);
+ //i2s_alc5630_write(0x04, 0x0000, g_i2c_client);
+ //i2s_alc5630_write(0x0c, 0x1010, g_i2c_client);
+ //i2s_alc5630_write(0x10, 0xff03, g_i2c_client);
+ //End ADD by river 2011.03.08
+
+ return 0;
+}
+
+static inline int snd_ftssp_start_record(ftssp_substream *ftssp010_substream,
+ struct snd_pcm_runtime *runtime)
+{
+ int err = 0;
+
+ //printk("~~~~~ : snd_ftssp_start_record() is invoked....\n");
+
+ u32 sw_ptr = (u32)frames_to_bytes(runtime, runtime->buffer_size);
+
+ if (ac97) {
+ switch (runtime->rate) {
+ case 8000:
+ sw_ptr = (sw_ptr * 3);
+ break;
+ case 16000:
+ sw_ptr = (sw_ptr * 3) >> 1;
+ break;
+ case 48000:
+ default:
+ sw_ptr = sw_ptr >> 1;
+ break;
+ }
+ } else {
+
+ //printk(">>>>>>>>>> : snd_ftssp_start_record() for recording....\n");
+ sw_ptr = sw_ptr >> 1;
+ }
+
+ err = dmad_update_ring_sw_ptr(&dma_chreq_rx, sw_ptr, 0);
+ if (err != 0) {
+ ERR("%s: failed to update sw-pointer!\n", __func__);
+ return err;
+ }
+
+ err = dmad_kickoff_requests(&dma_chreq_rx);
+ if (err != 0) {
+ ERR("%s: failed to kickoff dma!\n", __func__);
+ return err;
+ }
+
+ ftssp010_substream->start(cardno, 1);
+
+ return 0;
+}
+
+/* Triggers AHBDMA for playback & capture */
+static int snd_ftssp_pcm_trigger(struct snd_pcm_substream * substream, int cmd)
+{
+ ftssp_substream *ftssp010_substream =
+ (ftssp_substream *)substream->runtime->private_data;
+ struct snd_pcm_runtime *runtime = substream->runtime;
+ int err = 0;
+ int stream_id = substream->pstr->stream;
+
+ //printk("~~~~~ : snd_ftssp_pcm_trigger() is invoked....\n");
+
+ /* note local interrupts are already disabled in the midlevel code */
+ spin_lock(&ftssp010_substream->dma_lock);
+
+ switch (cmd) {
+ case SNDRV_PCM_TRIGGER_START:
+
+ VDBG("%s: SNDRV_PCM_TRIGGER_START state(0x%08x)\n",
+ __func__, (u32)runtime->status->state);
+
+ if (stream_id == SNDRV_PCM_STREAM_PLAYBACK) {
+ err = snd_ftssp_start_play(ftssp010_substream, runtime);
+ } else {
+ err = snd_ftssp_start_record(ftssp010_substream,
+ runtime);
+ }
+ break;
+
+ case SNDRV_PCM_TRIGGER_STOP:
+
+ VDBG("%s: SNDRV_PCM_TRIGGER_STOP state(0x%08x)\n",
+ __func__, (u32)substream->runtime->status->state);
+
+ if (stream_id == SNDRV_PCM_STREAM_PLAYBACK) {
+ ftssp010_stop_tx(cardno);
+ dmad_drain_requests(&dma_chreq_tx, 1);
+ } else {
+ ftssp010_stop_rx(cardno);
+ dmad_drain_requests(&dma_chreq_rx, 1);
+ }
+ break;
+ default:
+ err = -EINVAL;
+ break;
+ }
+
+ spin_unlock(&ftssp010_substream->dma_lock);
+ return err;
+}
+
+// pcm middle-layer call this function within irq (snd_pcm_period_elapsed) or
+// with local irq disabled (snd_pcm_lib_write1)
+static snd_pcm_uframes_t snd_ftssp_pcm_pointer(
+ struct snd_pcm_substream *substream)
+{
+ struct snd_pcm_runtime *runtime = substream->runtime;
+ u32 hw_ptr;
+ snd_pcm_uframes_t ret;
+ int stream_id = substream->pstr->stream;
+
+ //printk("~~~~~ : snd_ftssp_pcm_pointer() is invoked....\n");
+
+
+ /* Fetch DMA pointer, with spin lock */
+ //spin_lock_irqsave(&ftssp010_substream->dma_lock, flags);
+
+ if (stream_id == SNDRV_PCM_STREAM_PLAYBACK) {
+ hw_ptr = dmad_probe_ring_hw_ptr(&dma_chreq_tx);
+ } else {
+ hw_ptr = dmad_probe_ring_hw_ptr(&dma_chreq_rx);
+ }
+
+ //spin_unlock_irqrestore(&ftssp010_substream->dma_lock, flags);
+
+ if (ac97) {
+ ret = bytes_to_frames(runtime, hw_ptr << 1);
+
+ switch (runtime->rate) {
+ case 8000:
+ ret = ret / 6;
+ break;
+ case 16000:
+ ret = ret / 3;
+ break;
+ case 48000:
+ default:
+ break;
+ }
+ } else {
+ ret = bytes_to_frames(runtime, hw_ptr << 1);
+ }
+
+
+ VVDBG("%s: hw_ptr(0x%08x) ret(0x%08x)\n",
+ (stream_id == SNDRV_PCM_STREAM_PLAYBACK) ? "p" : "c",
+ (u32)hw_ptr, (u32)ret);
+
+ /* ALSA requires return value 0 <= ret < buffer_size */
+ if (ret >= runtime->buffer_size)
+ return 0;
+ return ret;
+}
+
+/* For FTSSP010 driver, operations are shared among playback & capture */
+static struct snd_pcm_ops snd_ftssp_playback_ops = {
+ .open = snd_ftssp_pcm_open,
+ .close = snd_ftssp_pcm_close,
+ .ioctl = snd_pcm_lib_ioctl,
+ .hw_params = snd_ftssp_pcm_hw_params,
+ .hw_free = snd_ftssp_pcm_hw_free,
+ .prepare = snd_ftssp_pcm_prepare,
+ .trigger = snd_ftssp_pcm_trigger,
+ .pointer = snd_ftssp_pcm_pointer,
+ .copy = NULL,
+};
+
+static struct snd_pcm_ops snd_ftssp_capture_ops = {
+ .open = snd_ftssp_pcm_open,
+ .close = snd_ftssp_pcm_close,
+ .ioctl = snd_pcm_lib_ioctl,
+ .hw_params = snd_ftssp_pcm_hw_params,
+ .hw_free = snd_ftssp_pcm_hw_free,
+ .prepare = snd_ftssp_pcm_prepare,
+ .trigger = snd_ftssp_pcm_trigger,
+ .pointer = snd_ftssp_pcm_pointer,
+ .copy = NULL,
+};
+
+/* ALSA PCM constructor */
+static int snd_ftssp_new_pcm(ftssp_chip *chip)
+{
+ struct snd_pcm *pcm;
+ int err;
+
+ //printk("~~~~~ : snd_ftssp_new_pcm() is invoked....\n");
+
+ /* PCM device #0 with 1 playback and 1 capture */
+ if ((err = snd_pcm_new(chip->card, "ftssp_pcm", 0, 1, 1, &pcm)) < 0)
+ return err;
+
+ pcm->private_data = chip;
+ strcpy(pcm->name, "ftssp_pcm device");
+ chip->pcm = pcm;
+
+ /* set operators for playback and capture*/
+ snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK,
+ &snd_ftssp_playback_ops);
+
+ snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE,
+ &snd_ftssp_capture_ops);
+
+ /* Pre-allocate buffer, as suggested by ALSA driver document */
+ // todo: support playback/capture simultaneously
+ snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
+ NULL, FTSSP_HW_DMA_SIZE, FTSSP_HW_DMA_SIZE);
+
+ /* Force half-duplex (on A320D, or AC97 mode) */
+ if (ac97)
+ pcm->info_flags |= SNDRV_PCM_INFO_HALF_DUPLEX;
+
+ return 0;
+}
+
+#if (FTSSP_PROC_FS)
+static void snd_ftssp_buf_max_read(struct snd_info_entry *entry,
+ struct snd_info_buffer *buffer)
+{
+ snd_iprintf(buffer, "%d\n", snd_ftssp_pcm_hw.buffer_bytes_max);
+}
+
+static void snd_ftssp_buf_max_write(struct snd_info_entry *entry,
+ struct snd_info_buffer *buffer)
+{
+ char tmp[128];
+ char *ptr_e;
+ u32 val;
+
+ if (buffer->size == 0)
+ return;
+
+ memset(tmp, 0, 128);
+ snd_info_get_str(tmp, buffer->buffer, 127);
+
+ val = simple_strtoul(tmp, &ptr_e, 10);
+ if (*ptr_e == 'k')
+ val *= 1024;
+ else if (*ptr_e == 'm')
+ val *= 1024 * 1024;
+
+ if (ac97) {
+ if (val > AC97_HW_BUFFER_BYTES_MAX)
+ val = AC97_HW_BUFFER_BYTES_MAX;
+ } else {
+ if (val > I2S_HW_BUFFER_BYTES_MAX)
+ val = I2S_HW_BUFFER_BYTES_MAX;
+ }
+
+ snd_ftssp_pcm_hw.buffer_bytes_max = (size_t)val;
+}
+
+static void snd_ftssp_period_min_read(struct snd_info_entry *entry,
+ struct snd_info_buffer *buffer)
+{
+ snd_iprintf(buffer, "%d\n", snd_ftssp_pcm_hw.period_bytes_min);
+}
+
+static void snd_ftssp_period_min_write(struct snd_info_entry *entry,
+ struct snd_info_buffer *buffer)
+{
+ char tmp[128];
+ char *ptr_e;
+ u32 val;
+
+ if (buffer->size == 0)
+ return;
+
+ memset(tmp, 0, 128);
+ snd_info_get_str(tmp, buffer->buffer, 127);
+
+ val = simple_strtoul(tmp, &ptr_e, 10);
+ if (*ptr_e == 'k')
+ val *= 1024;
+ else if (*ptr_e == 'm')
+ val *= 1024 * 1024;
+
+ snd_ftssp_pcm_hw.period_bytes_min = (size_t)val;
+
+ if ((val * snd_ftssp_pcm_hw.periods_max) >
+ snd_ftssp_pcm_hw.buffer_bytes_max) {
+ INFO("\nWarning: period_bytes(%d) * periods(%d) exceeds "
+ "hw_buffer_size(%d).\n",
+ snd_ftssp_pcm_hw.period_bytes_min,
+ snd_ftssp_pcm_hw.periods_max,
+ snd_ftssp_pcm_hw.buffer_bytes_max);
+ INFO(" Unexpected access violation may occur!\n");
+ }
+}
+
+static void snd_ftssp_period_max_read(struct snd_info_entry *entry,
+ struct snd_info_buffer *buffer)
+{
+ snd_iprintf(buffer, "%d\n", snd_ftssp_pcm_hw.period_bytes_max);
+}
+
+static void snd_ftssp_period_max_write(struct snd_info_entry *entry,
+ struct snd_info_buffer *buffer)
+{
+ char tmp[128];
+ char *ptr_e;
+ u32 val;
+
+ if (buffer->size == 0)
+ return;
+
+ memset(tmp, 0, 128);
+ snd_info_get_str(tmp, buffer->buffer, 127);
+
+ val = simple_strtoul(tmp, &ptr_e, 10);
+ if (*ptr_e == 'k')
+ val *= 1024;
+ else if (*ptr_e == 'm')
+ val *= 1024 * 1024;
+
+ snd_ftssp_pcm_hw.period_bytes_max = (size_t)val;
+
+ if ((val * snd_ftssp_pcm_hw.periods_max) >
+ snd_ftssp_pcm_hw.buffer_bytes_max) {
+ INFO("\nWarning: period_bytes(%d) * periods(%d) exceeds "
+ "hw_buffer_size(%d).\n",
+ snd_ftssp_pcm_hw.period_bytes_max,
+ snd_ftssp_pcm_hw.periods_max,
+ snd_ftssp_pcm_hw.buffer_bytes_max);
+ INFO(" Unexpected access violation may occur!\n");
+ }
+}
+
+static void snd_ftssp_periods_min_read(struct snd_info_entry *entry,
+ struct snd_info_buffer *buffer)
+{
+ snd_iprintf(buffer, "%d\n", snd_ftssp_pcm_hw.periods_min);
+}
+
+static void snd_ftssp_periods_min_write(struct snd_info_entry *entry,
+ struct snd_info_buffer *buffer)
+{
+ char tmp[128];
+ char *ptr_e;
+ u32 val;
+
+ if (buffer->size == 0)
+ return;
+
+ memset(tmp, 0, 128);
+ snd_info_get_str(tmp, buffer->buffer, 127);
+
+ val = simple_strtoul(tmp, &ptr_e, 10);
+ if (*ptr_e == 'k')
+ val *= 1024;
+ else if (*ptr_e == 'm')
+ val *= 1024 * 1024;
+
+ snd_ftssp_pcm_hw.periods_min = (size_t)val;
+
+ if ((val * snd_ftssp_pcm_hw.period_bytes_max) >
+ snd_ftssp_pcm_hw.buffer_bytes_max) {
+ INFO("\nWarning: period_bytes(%d) * periods(%d) exceeds "
+ "hw_buffer_size(%d).\n",
+ snd_ftssp_pcm_hw.period_bytes_max,
+ snd_ftssp_pcm_hw.periods_min,
+ snd_ftssp_pcm_hw.buffer_bytes_max);
+ INFO(" Unexpected access violation may occur!\n");
+ }
+}
+
+static void snd_ftssp_periods_max_read(struct snd_info_entry *entry,
+ struct snd_info_buffer *buffer)
+{
+ snd_iprintf(buffer, "%d\n", snd_ftssp_pcm_hw.periods_max);
+}
+
+static void snd_ftssp_periods_max_write(struct snd_info_entry *entry,
+ struct snd_info_buffer *buffer)
+{
+ char tmp[128];
+ char *ptr_e;
+ u32 val;
+
+ if (buffer->size == 0)
+ return;
+
+ memset(tmp, 0, 128);
+ snd_info_get_str(tmp, buffer->buffer, 127);
+
+ val = simple_strtoul(tmp, &ptr_e, 10);
+ if (*ptr_e == 'k')
+ val *= 1024;
+ else if (*ptr_e == 'm')
+ val *= 1024 * 1024;
+
+ snd_ftssp_pcm_hw.periods_max = (size_t)val;
+
+ if ((val * snd_ftssp_pcm_hw.period_bytes_max) >
+ snd_ftssp_pcm_hw.buffer_bytes_max) {
+ INFO("\nWarning: period_bytes(%d) * periods(%d) exceeds "
+ "hw_buffer_size(%d).\n",
+ snd_ftssp_pcm_hw.period_bytes_max,
+ snd_ftssp_pcm_hw.periods_max,
+ snd_ftssp_pcm_hw.buffer_bytes_max);
+ INFO(" Unexpected access violation may occur!\n");
+ }
+}
+#endif //FTSSP_PROC_FS
+
+static inline void ftssp_ac97_init(void)
+{
+ //driver_name = AC97_DRIVER_NAME;
+ //codec_info = AC97_CODEC_NAME;
+
+ /* Change codec-dependent callbacks to AC97 */
+ ftssp010_substreams[0].pmu_set_clocking = pmu_set_ac97_clocking;
+ ftssp010_substreams[0].hw_config = ftssp010_config_ac97_play;
+ ftssp010_substreams[1].pmu_set_clocking = pmu_set_ac97_clocking;
+ ftssp010_substreams[1].hw_config = ftssp010_config_ac97_rec;
+
+ snd_ftssp_playback_ops.copy = snd_ftssp_playback_copy;
+ snd_ftssp_capture_ops.copy = snd_ftssp_capture_copy;
+
+ snd_ftssp_pcm_hw.rates = AC97_CODEC_SAMPLE_RATES;
+ snd_ftssp_pcm_hw.rate_min = AC97_CODEC_SAMPLE_RATE_MIN;
+ snd_ftssp_pcm_hw.rate_max = AC97_CODEC_SAMPLE_RATE_MAX;
+ snd_ftssp_pcm_hw.formats = AC97_CODEC_FORMATS;
+ snd_ftssp_pcm_hw.buffer_bytes_max = AC97_HW_BUFFER_BYTES_MAX;
+ snd_ftssp_pcm_hw.period_bytes_min = AC97_HW_PERIOD_BYTES_MIN;
+ snd_ftssp_pcm_hw.period_bytes_max = AC97_HW_PERIOD_BYTES_MAX;
+ snd_ftssp_pcm_hw.periods_min = AC97_HW_PERIODS_MIN;
+ snd_ftssp_pcm_hw.periods_max = AC97_HW_PERIODS_MAX;
+}
+
+static int ftssp_alsa_init(struct i2c_client *client)
+{
+ ftssp_chip *chip;
+ int err;
+
+ //ADD by river 2011.03.08
+ //g_i2c_client = client;
+ //End ADD by river 2011.03.08
+ //printk(">>>>>>>>> (4) ftssp_alsa_init().\n");
+ init_hw(cardno, ac97, client);
+
+ if (ac97)
+ ftssp_ac97_init();
+
+ DBG("%s: FTSSP010 #%d (Physical Addr=0x%08X), mode: %s\n",
+ __func__,
+ cardno, SSP_FTSSP010_pa_base[cardno],
+ ac97 ? "ac97" : "i2s");
+
+ err = snd_card_create(cardno, FTSSP_CARD_ID, THIS_MODULE,
+ sizeof(ftssp_chip), &ftssp_cards[cardno]);
+ if (err < 0)
+ return err;
+
+ if (ac97) {
+ sprintf(ftssp_cards[cardno]->driver, FTSSP_DRIVER_NAME);
+ sprintf(ftssp_cards[cardno]->shortname,
+ FTSSP_DRIVER_NAME "_ac97");
+ sprintf(ftssp_cards[cardno]->longname,
+ FTSSP_DRIVER_NAME "_ac97 controller");
+ } else {
+ sprintf(ftssp_cards[cardno]->driver, FTSSP_DRIVER_NAME);
+ sprintf(ftssp_cards[cardno]->shortname,
+ FTSSP_DRIVER_NAME "_i2s");
+ sprintf(ftssp_cards[cardno]->longname,
+ FTSSP_DRIVER_NAME "_i2s controller");
+ }
+
+ // PCM
+ chip = (ftssp_chip *)(ftssp_cards[cardno]->private_data);
+ chip->card = ftssp_cards[cardno];
+
+ if ((err = snd_ftssp_new_pcm(chip))) {
+ ERR("%s, Can't new PCM devices\n",__func__);
+ return -ENODEV;
+ }
+
+#if (FTSSP_PROC_FS)
+ // new a proc entries subordinate to card->proc_root for debugging
+ // /proc/card#/buf_max
+ snd_card_proc_new(chip->card, "buf_max", &chip->info_buf_max);
+ if (chip->info_buf_max) {
+ chip->info_buf_max->c.text.read = snd_ftssp_buf_max_read;
+ chip->info_buf_max->c.text.write = snd_ftssp_buf_max_write;
+ }
+ // /proc/card#/period_min
+ snd_card_proc_new(chip->card, "period_size_min",
+ &chip->info_period_min);
+ if (chip->info_period_min) {
+ chip->info_period_min->c.text.read = snd_ftssp_period_min_read;
+ chip->info_period_min->c.text.write =
+ snd_ftssp_period_min_write;
+ }
+ // /proc/card#/period_max
+ snd_card_proc_new(chip->card, "period_size_max",
+ &chip->info_period_max);
+ if (chip->info_period_max) {
+ chip->info_period_max->c.text.read = snd_ftssp_period_max_read;
+ chip->info_period_max->c.text.write =
+ snd_ftssp_period_max_write;
+ }
+ // /proc/card#/periods_min
+ snd_card_proc_new(chip->card, "periods_min", &chip->info_periods_min);
+ if (chip->info_periods_min) {
+ chip->info_periods_min->c.text.read =
+ snd_ftssp_periods_min_read;
+ chip->info_periods_min->c.text.write =
+ snd_ftssp_periods_min_write;
+ }
+ // /proc/card#/periods_max
+ snd_card_proc_new(chip->card, "periods_max", &chip->info_periods_max);
+ if (chip->info_periods_max) {
+ chip->info_periods_max->c.text.read =
+ snd_ftssp_periods_max_read;
+ chip->info_periods_max->c.text.write =
+ snd_ftssp_periods_max_write;
+ }
+#endif
+
+ // Register the card to ALSA
+ if ((err = snd_card_register(chip->card)) == 0) {
+ INFO("%s card registered!\n", FTSSP_CARD_ID);
+ }
+
+ return 0;
+}
+
+#ifdef CONFIG_SND_FTSSP010_I2S
+//ADD by river 2011.01.26
+static int alc5630_i2c_remove(struct i2c_client *client)
+{
+ struct alc5630_data *alc5630 = i2c_get_clientdata(client);
+
+ // power down codec chip
+ //tas_write_reg(tas, TAS_REG_ACR, 1, &tmp);
+
+ mutex_destroy(&alc5630->mtx);
+ kfree(alc5630);
+ return 0;
+}
+
+static const struct i2c_device_id alc5630_i2c_id[] = {
+ { "alc5630_codec", 0 },
+ { }
+};
+
+// This is the driver that will be inserted
+static struct i2c_driver alc5630_driver = {
+ .driver = {
+ .name = "alc5630_codec",
+ .owner = THIS_MODULE,
+ },
+ .attach_adapter = alc5630_i2c_attach,
+ .probe = alc5630_i2c_probe,
+ .remove = alc5630_i2c_remove,
+ .suspend = alc5630_i2c_suspend,
+ .resume = alc5630_i2c_resume,
+ .id_table = alc5630_i2c_id,
+};
+
+static int alc5630_i2c_suspend(struct i2c_client *i2c_client, pm_message_t mesg)
+{
+ //printk("@@@@@ TRACE by river 2011.05.10 : alc5630_i2c_suspend() is invoked.\n");
+
+ //i2c_del_driver(&alc5630_driver);
+ //#ifndef CONFIG_SND_FTSSP010_AC97
+ // i2c_del_driver(&alc5630_driver);
+ //#endif
+ //printk("@@@@@ TRACE by river 2011.05.10 : alc5630_i2c_suspend() -2 is invoked.\n");
+ dmad_channel_free(&dma_chreq_tx);
+ dmad_channel_free(&dma_chreq_rx);
+ //printk("@@@@@ TRACE by river 2011.05.10 : alc5630_i2c_suspend() -3 is invoked.\n");
+ //snd_card_free(ftssp_cards[cardno]);
+
+ return 0;
+
+}
+
+static int alc5630_i2c_resume(struct i2c_client *i2c_client)
+{
+
+ //printk("@@@@@ TRACE by river 2011.05.10 : alc5630_i2c_resume() is invoked.\n");
+ //#ifdef CONFIG_SND_FTSSP010_AC97
+ // ftssp_alsa_init(NULL);
+ //#else
+ // return i2c_add_driver(&alc5630_driver);
+ //#endif
+
+ return 0;
+
+}
+#endif
+
+static __init int ftssp_alsa_i2c_i2s_init(void)
+{
+
+ //printk(">>>>>>>>>> (1) ftssp_alsa_i2c_i2s_init().\n");
+ //return i2c_add_driver(&alc5630_driver);
+ #ifdef CONFIG_SND_FTSSP010_AC97
+ return ftssp_alsa_init(NULL);
+ #else
+ return i2c_add_driver(&alc5630_driver);
+ #endif
+}
+//End ADD by river 2011.01.26
+
+static __exit void ftssp_alsa_i2c_i2s_exit(void)
+{
+ DBG("%s, cleaning up\n",__func__);
+
+ //i2c_del_driver(&alc5630_driver);
+ #ifndef CONFIG_SND_FTSSP010_AC97
+ i2c_del_driver(&alc5630_driver);
+ #endif
+
+ dmad_channel_free(&dma_chreq_tx);
+ dmad_channel_free(&dma_chreq_rx);
+
+ snd_card_free(ftssp_cards[cardno]);
+}
+
+/*static __exit void ftssp_alsa_exit(void)
+{
+ DBG("%s, cleaning up\n",__func__);
+
+ dmad_channel_free(&dma_chreq_tx);
+ dmad_channel_free(&dma_chreq_rx);
+
+ snd_card_free(ftssp_cards[cardno]);
+}*/
+
+//MOD by river 2011.01.26
+//module_init(ftssp_alsa_init);
+//module_exit(ftssp_alsa_exit);
+module_init(ftssp_alsa_i2c_i2s_init);
+module_exit(ftssp_alsa_i2c_i2s_exit);
+//End MOD by river 2011.01.26
diff -Nur linux-3.4.113.orig/sound/nds32/FTSSP010_HDA.c linux-3.4.113/sound/nds32/FTSSP010_HDA.c
--- linux-3.4.113.orig/sound/nds32/FTSSP010_HDA.c 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/sound/nds32/FTSSP010_HDA.c 2016-12-01 20:59:24.396614447 +0100
@@ -0,0 +1,745 @@
+/* FTSSP010 - UDA1345TS module:
+ *
+ * $log$
+ *
+ * 2006/02/23: I-Jui Sung: OSS emulation half-duplex
+ * playback/capture at 48K, 44.1K, 8K
+ * with mono/stereo 16bit/8bit
+ *
+ * 2006/02/22: I-Jui Sung: OSS emulation playback at 44.1KHz
+ * 16-bit mono completed. Relying ALSA to
+ * resample
+ * 2009/02/24: dma upgrade checking list:
+ * - ac97 mode playback ................. ok
+ * - ac97 mode capture .................. ok
+ * - i2s mode playback .................. ok
+ * - i2s mode capture ................... ok
+ * - mixer support (snd_ctl_add, ...) ... todo
+ * - debug /proc entry .................. ok
+ */
+
+
+#include <linux/init.h>
+#include <linux/module.h>
+#include <asm/io.h>
+#include <linux/delay.h>
+#include <asm/spec.h>
+#include <asm/dmad.h>
+#include <linux/dma-mapping.h>
+#include <sound/core.h>
+#include <sound/pcm.h>
+#include <sound/initval.h>
+#include <sound/asound.h>
+#include <sound/control.h>
+#include "FTSSP010_HDA.h"
+void init_hw(unsigned int cardno);
+
+#if (!defined(CONFIG_PLATFORM_AHBDMA) && !defined(CONFIG_PLATFORM_APBDMA))
+#warning needs ahb/apb dma to wrok
+#endif
+
+/* ---------------------------------------------------------------------------
+ * Define the debug level of FTSSP_DEBUG
+ */
+#define FTSSP_DEBUG 0
+#define FTSSP_DEBUG_VERBOSE 0
+#define FTSSP_PROC_FS 1
+
+#undef VVDBG
+#if (FTSSP_DEBUG_VERBOSE)
+//#define VVDBG(vvar...) (void)0
+#define VVDBG(vvar...) printk(KERN_INFO vvar)
+#else
+#define VVDBG(vvar...) (void)0
+#endif
+
+#undef ERR
+#define ERR(vvar...) printk(KERN_ERR vvar)
+
+#undef INFO
+#define INFO(vvar...) printk(KERN_INFO vvar)
+
+#if (FTSSP_DEBUG)
+#undef DBG
+#define DBG(vvar...) printk(KERN_INFO vvar)
+#else
+#define DBG(vvar...) (void)0
+#endif
+
+#if (FTSSP_DEBUG_VERBOSE)
+#undef VDBG
+#define VDBG(vvar...) printk(KERN_INFO vvar)
+#else
+#define VDBG(vvar...) (void)0
+#endif
+
+/* ---------------------------------------------------------------------------
+ * Preserved size of memory space for audio DMA ring
+ */
+#define FTSSP_HW_DMA_SIZE (512 * 1024)
+
+
+/* HDA HW configuration*/
+/* ring size, exported to application */
+#define HDA_HW_BUFFER_BYTES_MAX (256 * 1024)
+#define HDA_HW_PERIOD_BYTES_MIN (2 * 1024)
+#define HDA_HW_PERIOD_BYTES_MAX (32 * 1024)
+#define HDA_HW_PERIODS_MIN 3
+#define HDA_HW_PERIODS_MAX 8
+
+#define HDA_HW_DMA_SIZE (HDA_HW_BUFFER_BYTES_MAX)
+
+
+/* ---------------------------------------------------------------------------
+ * Audio formats
+ */
+
+/* HDA formats */
+#define HDA_CODEC_FORMATS (SNDRV_PCM_FMTBIT_S16_LE)
+#define HDA_CODEC_SAMPLE_RATES (SNDRV_PCM_RATE_192000 | \
+ SNDRV_PCM_RATE_176400| \
+ SNDRV_PCM_RATE_96000 | \
+ SNDRV_PCM_RATE_88200 | \
+ SNDRV_PCM_RATE_48000 | \
+ SNDRV_PCM_RATE_44100 | \
+ SNDRV_PCM_RATE_32000 | \
+ SNDRV_PCM_RATE_22050 | \
+ SNDRV_PCM_RATE_16000 | \
+ SNDRV_PCM_RATE_11025 | \
+ SNDRV_PCM_RATE_8000)
+#define HDA_CODEC_SAMPLE_RATE_MIN (8000)
+#define HDA_CODEC_SAMPLE_RATE_MAX (192000)
+
+/* ---------------------------------------------------------------------------
+ * Configuration
+ */
+#if (CONFIG_PROC_FS == 0)
+#undef FTSSP_PROC_FS
+#define FTSSP_PROC_FS 0
+#else
+#if (FTSSP_PROC_FS)
+#include <sound/info.h>
+#endif /* FTSSP_PROC_FS */
+#endif /* CONFIG_PROC_FS */
+
+#define FTSSP_CARD_ID "ftssp010"
+#define FTSSP_DRIVER_NAME "ftssp"
+
+MODULE_LICENSE("Faraday License");
+MODULE_AUTHOR("Faraday Technology Corp.");
+MODULE_DESCRIPTION("FTSSP010 Linux 2.6 Driver");
+
+static int cardno = 0;
+static const unsigned int SSP_FTSSP010_pa_base[SSP_FTSSP010_IRQ_COUNT] =
+ { SSP_FTSSP010_PA_BASE };
+
+/* Driver mode */
+
+// ----------------------------------------------
+module_param(cardno, int, 0);
+MODULE_PARM_DESC(cardno, "FTSSP No.");
+
+// ----------------------------------------------
+
+/* ---------------------------------------------------------------------------
+ * Structures
+ */
+
+/* private data for card */
+typedef struct {
+ struct snd_card *card;
+ struct snd_pcm *pcm;
+ struct snd_pcm_substream *substream_tx;
+ struct snd_pcm_substream *substream_rx;
+} ftssp_chip;
+
+/* dma request descriptors */
+dmad_chreq dma_chreq_tx = {
+ .channel = -1,
+ .drq = NULL,
+};
+
+dmad_chreq dma_chreq_rx = {
+ .channel = -1,
+ .drq = NULL,
+};
+
+/* Holds ALSA card instance pointers */
+struct snd_card *ftssp_cards[SSP_FTSSP010_COUNT];
+
+/* snd_pcm_hardware */
+static struct snd_pcm_hardware snd_ftssp_pcm_hw =
+{
+ .info = SNDRV_PCM_INFO_INTERLEAVED,
+ .formats = HDA_CODEC_FORMATS,
+ .rates = HDA_CODEC_SAMPLE_RATES,
+ .rate_min = HDA_CODEC_SAMPLE_RATE_MIN,
+ .rate_max = HDA_CODEC_SAMPLE_RATE_MAX,
+ .channels_min = 1,
+ .channels_max = 2,
+ .buffer_bytes_max = HDA_HW_BUFFER_BYTES_MAX,
+ .period_bytes_min = HDA_HW_PERIOD_BYTES_MIN,
+ .period_bytes_max = HDA_HW_PERIOD_BYTES_MAX,
+ .periods_min = HDA_HW_PERIODS_MIN,
+ .periods_max = HDA_HW_PERIODS_MAX,
+};
+
+/* private data for a substream (playback or capture) */
+/* function pointer for set up AHBDMA for this substream */
+typedef void (*start_t)(int cardno, unsigned use_dma);
+typedef void (*ftssp010_config_t)(int cardno, unsigned is_stereo,
+ unsigned speed, int use8bit);
+
+typedef struct {
+ u32 busy;
+ spinlock_t dma_lock;
+ unsigned dma_area_va;
+ int dma_width;
+ unsigned int tx_period;
+ unsigned int rx_period;
+
+ start_t start;
+ ftssp010_config_t hw_config;
+} ftssp_substream;
+
+static ftssp_substream ftssp010_substreams[2] = {
+ /* Playback substream */
+ {
+ busy : 0,
+ hw_config : ftssp010_config_hda_play,
+ },
+ /* Capture substream */
+ {
+ busy : 0,
+ hw_config : ftssp010_config_hda_rec,
+ }
+};
+
+
+/**
+ * These dma callbacks are called in interrupt context.
+ * @data: pointer to the chip-wide structure.
+ * TODO: use stream-specifc data
+ */
+__attribute__((__unused__))
+static void ftssp_dma_callback_tx(int ch, u16 int_status, void *data)
+{
+ ftssp_chip *chip = (ftssp_chip *)data;
+ struct snd_pcm_runtime *runtime = chip->substream_tx->runtime;
+ ftssp_substream *ftssp010_substream =
+ (ftssp_substream *)runtime->private_data;
+ u32 sw_ptr;
+ u32 tx_period = ftssp010_substream->tx_period + 1;
+
+ if (tx_period == runtime->periods)
+ sw_ptr = runtime->buffer_size;
+ else
+ sw_ptr = tx_period * runtime->period_size;
+
+ sw_ptr = (u32)frames_to_bytes(runtime, sw_ptr) >> 1;
+
+ if (dmad_update_ring_sw_ptr(&dma_chreq_tx, (u32)sw_ptr, 0)) {
+ ERR("%s: failed to update sw-pointer!\n", __func__);
+ }
+
+ ftssp010_substream->tx_period = tx_period % runtime->periods;
+ snd_pcm_period_elapsed(chip->substream_tx);
+}
+
+__attribute__((__unused__))
+static void ftssp_dma_callback_rx(int ch, u16 int_status, void *data)
+{
+ ftssp_chip *chip = (ftssp_chip *)data;
+ struct snd_pcm_runtime *runtime = chip->substream_rx->runtime;
+ ftssp_substream *ftssp010_substream =
+ (ftssp_substream *)runtime->private_data;
+ u32 sw_ptr;
+ u32 rx_period = ftssp010_substream->rx_period + 1;
+
+ if (rx_period == runtime->periods)
+ sw_ptr = runtime->buffer_size;
+ else
+ sw_ptr = rx_period * runtime->period_size;
+ sw_ptr = (u32)frames_to_bytes(runtime, sw_ptr) >> 1;
+
+ if (dmad_update_ring_sw_ptr(&dma_chreq_rx, (u32)sw_ptr, 0) != 0) {
+ ERR("%s: failed to update sw-pointer!\n", __func__);
+ }
+
+ ftssp010_substream->rx_period = rx_period % runtime->periods;
+
+ snd_pcm_period_elapsed(chip->substream_rx);
+}
+
+static inline int snd_ftssp_dma_ch_alloc(struct snd_pcm_substream *substream)
+{
+ dmad_chreq *ch_req __attribute__((__unused__)) = 0;
+
+#ifdef CONFIG_PLATFORM_APBDMA
+
+ if (substream->pstr->stream == SNDRV_PCM_STREAM_PLAYBACK) {
+ ch_req = &dma_chreq_tx;
+ ch_req->completion_cb = ftssp_dma_callback_tx;
+ ch_req->apb_req.tx_dir = DMAD_DIR_A0_TO_A1;
+ ch_req->apb_req.dev_reqn = APBBR_REQN_I2SAC97TX;
+ } else {
+ ch_req = &dma_chreq_rx;
+ ch_req->completion_cb = ftssp_dma_callback_rx;
+ ch_req->apb_req.tx_dir = DMAD_DIR_A1_TO_A0;
+ ch_req->apb_req.dev_reqn = APBBR_REQN_I2SAC97RX;
+ }
+
+ ch_req->controller = DMAD_DMAC_APB_CORE;
+ ch_req->flags = DMAD_FLAGS_RING_MODE;
+ ch_req->ring_base = 0;
+ ch_req->dev_addr = (dma_addr_t)FTSSP010_DATA_PA(cardno);
+ ch_req->periods = 0;
+ ch_req->period_size = 0;
+
+ ch_req->apb_req.ring_ctrl = APBBR_ADDRINC_I2X;
+ ch_req->apb_req.ring_reqn = APBBR_REQN_NONE;
+ ch_req->apb_req.dev_ctrl = APBBR_ADDRINC_FIXED;
+ ch_req->apb_req.burst_mode = 0;
+ ch_req->apb_req.data_width = APBBR_DATAWIDTH_2;
+ ch_req->completion_data = (void *)snd_pcm_substream_chip(substream);
+
+ ch_req->completion_data = (void *)snd_pcm_substream_chip(substream);
+
+ if (dmad_channel_alloc(ch_req) != 0) {
+ ERR("%s: APBDMA channel allocation failed\n",__func__);
+ goto _try_ahb;
+ }
+
+ DBG("%s: APBDMA channel allocated (ch: %d) ring_mode\n",
+ __func__, ch_req->channel);
+
+ return 0;
+
+_try_ahb:
+
+#endif /* CONFIG_PLATFORM_APBDMA */
+
+#ifdef CONFIG_PLATFORM_AHBDMA
+
+ if (substream->pstr->stream == SNDRV_PCM_STREAM_PLAYBACK) {
+ ch_req = &dma_chreq_tx;
+ ch_req->completion_cb = ftssp_dma_callback_tx;
+ ch_req->ahb_req.tx_dir = DMAD_DIR_A0_TO_A1;
+ ch_req->ahb_req.dev_reqn = DMAC_REQN_I2SAC97TX;
+ } else {
+ ch_req = &dma_chreq_rx;
+ ch_req->completion_cb = ftssp_dma_callback_rx;
+ ch_req->ahb_req.tx_dir = DMAD_DIR_A1_TO_A0;
+ ch_req->ahb_req.dev_reqn = DMAC_REQN_I2SAC97RX;
+ }
+
+ ch_req->controller = DMAD_DMAC_AHB_CORE;
+ ch_req->flags = DMAD_FLAGS_RING_MODE;
+ ch_req->ring_base = 0;
+ ch_req->dev_addr = (dma_addr_t)FTSSP010_DATA_PA(cardno);
+ ch_req->periods = 0;
+ ch_req->period_size = 0;
+
+ ch_req->ahb_req.sync = 1;
+ ch_req->ahb_req.priority = DMAC_CSR_CHPRI_2;
+ ch_req->ahb_req.hw_handshake = 1;
+ ch_req->ahb_req.burst_size = DMAC_CSR_SIZE_1;
+
+ ch_req->ahb_req.ring_width = DMAC_CSR_WIDTH_32;
+ ch_req->ahb_req.ring_ctrl = DMAC_CSR_AD_INC;
+ ch_req->ahb_req.ring_reqn = DMAC_REQN_NONE;
+ ch_req->ahb_req.dev_width = DMAC_CSR_WIDTH_32;
+ ch_req->ahb_req.dev_ctrl = DMAC_CSR_AD_FIX;
+
+ ch_req->completion_data = (void *)snd_pcm_substream_chip(substream);
+
+ if (dmad_channel_alloc(ch_req) != 0) {
+ ERR("%s: AHBDMA channel allocation failed\n", __func__);
+ goto _err_exit;
+ }
+
+ DBG("%s: AHBDMA channel allocated (ch: %d) ring_mode\n",
+ __func__, ch_req->channel);
+
+ return 0;
+
+_err_exit:
+
+#endif /* CONFIG_PLATFORM_AHBDMA */
+
+ return -ENODEV;
+}
+
+static inline ftssp_substream *ftssp010_substream_new(int stream_id)
+{
+ ftssp_substream *s = NULL;
+
+ switch (stream_id) {
+ case SNDRV_PCM_STREAM_PLAYBACK:
+ s = &ftssp010_substreams[0];
+ break;
+ case SNDRV_PCM_STREAM_CAPTURE:
+ s = &ftssp010_substreams[1];
+ break;
+ default:
+ ERR("%s: wrong stream type (%d)\n", __func__, stream_id);
+ return NULL;
+ }
+
+ if (s->busy) {
+ ERR("%s: device busy!\n", __func__);
+ return NULL;
+ }
+ s->busy = 1;
+
+ spin_lock_init(&s->dma_lock);
+
+ return s;
+}
+
+static int snd_ftssp_pcm_open(struct snd_pcm_substream *substream)
+{
+ struct snd_pcm_runtime *runtime = substream->runtime;
+ int stream_id = substream->pstr->stream;
+
+ VDBG("%s, %s\n", __func__,
+ (substream->pstr->stream == SNDRV_PCM_STREAM_PLAYBACK) ?
+ "playback" : "capture");
+
+ /* Both playback and capture share a hardware description */
+ runtime->hw = snd_ftssp_pcm_hw;
+
+ /* Allocate & Initialize stream-specific data */
+ runtime->private_data = ftssp010_substream_new(stream_id);
+
+ if (runtime->private_data)
+ return snd_ftssp_dma_ch_alloc(substream);
+ else
+ return -EBUSY;
+}
+
+static int snd_ftssp_pcm_close(struct snd_pcm_substream *substream)
+{
+ int stream_id = substream->pstr->stream;
+ ftssp_substream *ftssp010_substream =
+ (ftssp_substream *)substream->runtime->private_data;
+
+ VDBG("%s, %s\n", __func__,
+ (substream->pstr->stream == SNDRV_PCM_STREAM_PLAYBACK) ?
+ "playback" : "capture");
+
+ if (stream_id == SNDRV_PCM_STREAM_PLAYBACK)
+ dmad_channel_free(&dma_chreq_tx);
+ else
+ dmad_channel_free(&dma_chreq_rx);
+
+ ftssp010_substream->busy = 0;
+ return 0;
+}
+
+static int snd_ftssp_pcm_hw_params(struct snd_pcm_substream *substream,
+ struct snd_pcm_hw_params *hw_params)
+{
+ VDBG("%s, %s\n", __func__,
+ (substream->pstr->stream == SNDRV_PCM_STREAM_PLAYBACK) ?
+ "playback" : "capture");
+
+ return snd_pcm_lib_malloc_pages(substream, HDA_HW_DMA_SIZE);
+}
+
+static int snd_ftssp_pcm_hw_free(struct snd_pcm_substream *substream)
+{
+ VDBG("%s, %s\n", __func__,
+ (substream->pstr->stream == SNDRV_PCM_STREAM_PLAYBACK) ?
+ "playback" : "capture");
+
+ if (substream->pstr->stream == SNDRV_PCM_STREAM_PLAYBACK)
+ dmad_drain_requests(&dma_chreq_tx, 1);
+ else
+ dmad_drain_requests(&dma_chreq_rx, 1);
+
+ return snd_pcm_lib_free_pages(substream);
+}
+
+/* Prepare FTSSP010 AHBDMA for playback & capture */
+static int snd_ftssp_pcm_prepare(struct snd_pcm_substream *substream)
+{
+ ftssp_chip *chip = snd_pcm_substream_chip(substream);
+ struct snd_pcm_runtime *runtime = substream->runtime;
+
+ ftssp_substream *ftssp010_substream =
+ (ftssp_substream *)runtime->private_data;
+
+ int stream_id = substream->pstr->stream;
+ dmad_chreq *dma_chreq;
+ unsigned period_size, buffer_size;
+ VVDBG("%s before spin_lock<<\n", __func__);
+ if (stream_id == SNDRV_PCM_STREAM_PLAYBACK)
+ dma_chreq = &dma_chreq_tx;
+ else
+ dma_chreq = &dma_chreq_rx;
+
+ period_size = frames_to_bytes(runtime, runtime->period_size);
+ buffer_size = frames_to_bytes(runtime, runtime->buffer_size);
+
+ if (runtime->format != SNDRV_PCM_FORMAT_S16_LE)
+ return -ENODEV;
+
+ ftssp010_substream->dma_width = 4;
+
+ dmad_drain_requests(dma_chreq, 1);
+
+ dma_chreq->ring_base = (dma_addr_t)runtime->dma_addr;
+ dma_chreq->periods = (dma_addr_t)runtime->periods;
+ dma_chreq->period_size = (dma_addr_t)(period_size >> 1);
+ dma_chreq->ring_size = (dma_addr_t)(buffer_size >> 1);
+ dmad_update_ring(dma_chreq);
+
+ /* Set PMU, FTSSP010, and DMA */
+ spin_lock(&ftssp010_substream->dma_lock);
+
+ /* keep DMA buffer VA for copy() callback */
+ // todo: support playback/capture simultaneously
+ ftssp010_substream->dma_area_va = (u32)runtime->dma_area;
+ VVDBG("%s before hw_config<<\n", __func__);
+ ftssp010_substream->hw_config(cardno,
+ runtime->channels > 1 ? 1 : 0, /* 1: stereo, 0: mono */
+ runtime->rate, ftssp010_substream->dma_width);
+ VVDBG("%s after hw_config<<\n", __func__);
+ if (stream_id == SNDRV_PCM_STREAM_PLAYBACK) {
+ ftssp010_substream->tx_period = 0;
+ chip->substream_tx = substream;
+ } else {
+ ftssp010_substream->rx_period = 0;
+ chip->substream_rx = substream;
+ }
+
+ spin_unlock(&ftssp010_substream->dma_lock);
+ VVDBG("%s after spin_unlock <<\n", __func__);
+
+ return 0;
+}
+
+static inline int snd_ftssp_start_play(ftssp_substream *ftssp010_substream,
+ struct snd_pcm_runtime *runtime)
+{
+ int err = 0;
+ u32 sw_ptr =
+ (u32)frames_to_bytes(runtime, runtime->buffer_size) >> 1;
+
+ err = dmad_update_ring_sw_ptr(&dma_chreq_tx, sw_ptr, 0);
+ if (err != 0) {
+ ERR("%s: failed to update sw-pointer!\n", __func__);
+ return err;
+ }
+ err = dmad_kickoff_requests(&dma_chreq_tx);
+ if (err != 0) {
+ ERR("%s: failed to kickoff dma!\n", __func__);
+ return err;
+ }
+
+ return 0;
+}
+
+static inline int snd_ftssp_start_record(ftssp_substream *ftssp010_substream,
+ struct snd_pcm_runtime *runtime)
+{
+ int err = 0;
+ u32 sw_ptr = (u32)frames_to_bytes(runtime, runtime->buffer_size);
+
+ sw_ptr = sw_ptr >> 1;
+ printk(">>>>>>>>>> : snd_ftssp_start_record() for recording....\n");
+ err = dmad_update_ring_sw_ptr(&dma_chreq_rx, sw_ptr, 0);
+ if (err != 0) {
+ ERR("%s: failed to update sw-pointer!\n", __func__);
+ return err;
+ }
+
+ err = dmad_kickoff_requests(&dma_chreq_rx);
+ if (err != 0) {
+ ERR("%s: failed to kickoff dma!\n", __func__);
+ return err;
+ }
+
+
+ return 0;
+}
+
+/* Triggers AHBDMA for playback & capture */
+static int snd_ftssp_pcm_trigger(struct snd_pcm_substream * substream, int cmd)
+{
+ ftssp_substream *ftssp010_substream =
+ (ftssp_substream *)substream->runtime->private_data;
+ struct snd_pcm_runtime *runtime = substream->runtime;
+ int err = 0;
+ int stream_id = substream->pstr->stream;
+
+ /* note local interrupts are already disabled in the midlevel code */
+ spin_lock(&ftssp010_substream->dma_lock);
+
+ switch (cmd) {
+ case SNDRV_PCM_TRIGGER_START:
+
+ VDBG("%s: SNDRV_PCM_TRIGGER_START state(0x%08x)\n",
+ __func__, (u32)runtime->status->state);
+
+ if (stream_id == SNDRV_PCM_STREAM_PLAYBACK) {
+ err = snd_ftssp_start_play(ftssp010_substream, runtime);
+ } else {
+ err = snd_ftssp_start_record(ftssp010_substream,
+ runtime);
+ }
+ break;
+
+ case SNDRV_PCM_TRIGGER_STOP:
+
+ VDBG("%s: SNDRV_PCM_TRIGGER_STOP state(0x%08x)\n",
+ __func__, (u32)substream->runtime->status->state);
+
+ if (stream_id == SNDRV_PCM_STREAM_PLAYBACK) {
+ ftssp010_stop_tx(cardno);
+ dmad_drain_requests(&dma_chreq_tx, 1);
+ } else {
+ ftssp010_stop_rx(cardno);
+ dmad_drain_requests(&dma_chreq_rx, 1);
+ }
+ break;
+ default:
+ err = -EINVAL;
+ break;
+ }
+
+ spin_unlock(&ftssp010_substream->dma_lock);
+ return err;
+}
+
+// pcm middle-layer call this function within irq (snd_pcm_period_elapsed) or
+// with local irq disabled (snd_pcm_lib_write1)
+static snd_pcm_uframes_t snd_ftssp_pcm_pointer(
+ struct snd_pcm_substream *substream)
+{
+ struct snd_pcm_runtime *runtime = substream->runtime;
+ u32 hw_ptr;
+ snd_pcm_uframes_t ret;
+ int stream_id = substream->pstr->stream;
+
+ /* Fetch DMA pointer, with spin lock */
+ //spin_lock_irqsave(&ftssp010_substream->dma_lock, flags);
+
+ if (stream_id == SNDRV_PCM_STREAM_PLAYBACK) {
+ hw_ptr = dmad_probe_ring_hw_ptr(&dma_chreq_tx);
+ } else {
+ hw_ptr = dmad_probe_ring_hw_ptr(&dma_chreq_rx);
+ }
+ ret = bytes_to_frames(runtime, hw_ptr << 1);
+ //spin_unlock_irqrestore(&ftssp010_substream->dma_lock, flags);
+ VVDBG("%s: hw_ptr(0x%08x) ret(0x%08x)\n",
+ (stream_id == SNDRV_PCM_STREAM_PLAYBACK) ? "p" : "c",
+ (u32)hw_ptr, (u32)ret);
+
+ /* ALSA requires return value 0 <= ret < buffer_size */
+ if (ret >= runtime->buffer_size)
+ return 0;
+ return ret;
+}
+
+/* For FTSSP010 driver, operations are shared among playback & capture */
+static struct snd_pcm_ops snd_ftssp_playback_ops = {
+ .open = snd_ftssp_pcm_open,
+ .close = snd_ftssp_pcm_close,
+ .ioctl = snd_pcm_lib_ioctl,
+ .hw_params = snd_ftssp_pcm_hw_params,
+ .hw_free = snd_ftssp_pcm_hw_free,
+ .prepare = snd_ftssp_pcm_prepare,
+ .trigger = snd_ftssp_pcm_trigger,
+ .pointer = snd_ftssp_pcm_pointer,
+ .copy = NULL,
+};
+
+static struct snd_pcm_ops snd_ftssp_capture_ops = {
+ .open = snd_ftssp_pcm_open,
+ .close = snd_ftssp_pcm_close,
+ .ioctl = snd_pcm_lib_ioctl,
+ .hw_params = snd_ftssp_pcm_hw_params,
+ .hw_free = snd_ftssp_pcm_hw_free,
+ .prepare = snd_ftssp_pcm_prepare,
+ .trigger = snd_ftssp_pcm_trigger,
+ .pointer = snd_ftssp_pcm_pointer,
+ .copy = NULL,
+};
+
+/* ALSA PCM constructor */
+static int snd_ftssp_new_pcm(ftssp_chip *chip)
+{
+ struct snd_pcm *pcm;
+ int err;
+
+ /* PCM device #0 with 1 playback and 1 capture */
+ if ((err = snd_pcm_new(chip->card, "ftssp_pcm", 0, 1, 1, &pcm)) < 0)
+ return err;
+
+ pcm->private_data = chip;
+ strcpy(pcm->name, "ftssp_pcm device");
+ chip->pcm = pcm;
+
+ /* set operators for playback and capture*/
+ snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK,
+ &snd_ftssp_playback_ops);
+
+ snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE,
+ &snd_ftssp_capture_ops);
+
+ /* Pre-allocate buffer, as suggested by ALSA driver document */
+ // todo: support playback/capture simultaneously
+ snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
+ NULL, FTSSP_HW_DMA_SIZE, FTSSP_HW_DMA_SIZE);
+
+ return 0;
+}
+
+static __init int ftssp_alsa_init(void)
+{
+ ftssp_chip *chip;
+ int err;
+ init_hw(cardno);
+ INFO("After init_hw!\n");
+ err = snd_card_create(cardno, FTSSP_CARD_ID, THIS_MODULE,
+ sizeof(ftssp_chip), &ftssp_cards[cardno]);
+ INFO("After snd_card_create!\n");
+ if (err < 0)
+ return err;
+ sprintf(ftssp_cards[cardno]->driver, FTSSP_DRIVER_NAME);
+ sprintf(ftssp_cards[cardno]->shortname,
+ FTSSP_DRIVER_NAME "_HDA");
+ sprintf(ftssp_cards[cardno]->longname,
+ FTSSP_DRIVER_NAME "_HDA controller");
+ /* PCM */
+ chip = (ftssp_chip *)(ftssp_cards[cardno]->private_data);
+ chip->card = ftssp_cards[cardno];
+
+ if ((err = snd_ftssp_new_pcm(chip))) {
+ ERR("%s, Can't new PCM devices\n",__func__);
+ return -ENODEV;
+ }
+
+
+ /* Register the card to ALSA */
+ if ((err = snd_card_register(chip->card)) == 0) {
+ INFO("%s card registered!\n", FTSSP_CARD_ID);
+ }
+
+ return 0;
+}
+
+static __exit void ftssp_alsa_exit(void)
+{
+ DBG("%s, cleaning up\n",__func__);
+
+ dmad_channel_free(&dma_chreq_tx);
+ dmad_channel_free(&dma_chreq_rx);
+
+ snd_card_free(ftssp_cards[cardno]);
+}
+
+module_init(ftssp_alsa_init);
+module_exit(ftssp_alsa_exit);
diff -Nur linux-3.4.113.orig/sound/nds32/FTSSP010_HDA.h linux-3.4.113/sound/nds32/FTSSP010_HDA.h
--- linux-3.4.113.orig/sound/nds32/FTSSP010_HDA.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/sound/nds32/FTSSP010_HDA.h 2016-12-01 20:59:24.396614447 +0100
@@ -0,0 +1,34 @@
+/* FTSSP010 - HDA supporting library header */
+/*
+ *
+ * $log$
+ *
+ */
+#include <linux/init.h>
+#include <linux/module.h>
+#include <asm/io.h>
+#include <linux/delay.h>
+#include <asm/spec.h>
+#include <linux/dma-mapping.h>
+
+
+#define FTSSP010_DATA(x) (SSP_FTSSP010_va_base[(x)]+0x18)
+#define FTSSP010_DATA_PA(x) (SSP_FTSSP010_pa_base[(x)]+0x18)
+
+
+/* Returns FTSSP010 status */
+extern void ftssp010_set_int_control(int cardno, unsigned val);
+extern int ftssp010_get_status(int cardno);
+extern unsigned ftssp010_get_int_status(int cardno);
+/* Polls FIFO full register */
+extern int ftssp010_tx_fifo_not_full(int cardno);
+
+/* Configure FTSSP010 to a given sampling rate and channel number */
+extern void ftssp010_config_hda_play(int cardno, unsigned is_stereo, unsigned speed, int use8bit);
+
+extern void ftssp010_config_hda_rec(int cardno, unsigned is_stereo, unsigned speed, int use8bit);
+
+extern void ftssp010_stop_tx(int cardno);
+extern void ftssp010_stop_rx(int cardno);
+
+
diff -Nur linux-3.4.113.orig/sound/nds32/FTSSP010_HDA_lib.c linux-3.4.113/sound/nds32/FTSSP010_HDA_lib.c
--- linux-3.4.113.orig/sound/nds32/FTSSP010_HDA_lib.c 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/sound/nds32/FTSSP010_HDA_lib.c 2016-12-01 20:59:24.396614447 +0100
@@ -0,0 +1,477 @@
+/* FTSSP010 - UDA1345TS module
+ *
+ * $log$
+ */
+
+#include <linux/init.h>
+#include <linux/module.h>
+#include <asm/io.h>
+#include <linux/delay.h>
+#include <asm/spec.h>
+#include <asm/dmad.h>
+#include <linux/dma-mapping.h>
+#include "hda.h"
+
+#if 0
+MODULE_LICENSE("Faraday License");
+MODULE_AUTHOR("Faraday Technology Corp.");
+MODULE_DESCRIPTION("FTSSP010 - UDA1345TS Linux 2.6 Library");
+#endif
+#undef ERR
+#define ERR(vvar...) printk(KERN_ERR vvar)
+#define DBG(vvar...) printk(KERN_INFO vvar)
+
+#define SSP_TXFCLR 0x8
+#define SSP_RXFCLR 0x4
+#define SSP_RFIEN 0x4
+#define SSP_TFIEN 0x8
+#define SSP_SSPEN 0x1
+#define SSP_TXDOE 0x2
+#define SSP_RXDMAEN 0x10
+#define SSP_TXDMAEN 0x20
+#define SSP_RFURIEN 0x1
+#define SSP_TFURIEN 0x2
+#define HDA_STRNUM_RX 1
+#define HDA_STRNUM_TX 2
+#define HDA_CHANUM 0
+#define HDA_CRST_MASK 0x20
+/* Initialize FTSSP010 to output to UDA1345TS via I2S */
+#define FTSSP010_CONTROL0(x) (SSP_FTSSP010_va_base[(x)]+0x0)
+#define FTSSP010_CONTROL0_OPM_STEREO 0xC
+#define FTSSP010_CONTROL0_OPM_MONO 0x8
+
+#define FTSSP010_CONTROL1(x) (SSP_FTSSP010_va_base[(x)]+0x4)
+#define FTSSP010_CONTROL2(x) (SSP_FTSSP010_va_base[(x)]+0x8)
+
+#define FTSSP010_INT_CONTROL(x) (SSP_FTSSP010_va_base[(x)]+0x10)
+#define FTSSP010_STATUS(x) (SSP_FTSSP010_va_base[(x)]+0xC)
+#define FTSSP010_INT_STATUS(x) (SSP_FTSSP010_va_base[(x)]+0x14)
+#define FTSSP010_DATA(x) (SSP_FTSSP010_va_base[(x)]+0x18)
+#define FTSSP010_INFO(x) (SSP_FTSSP010_va_base[(x)]+0x1C)
+#define FTSSP010_AC_COMMAND(x) (SSP_FTSSP010_va_base[(x)]+0x28)
+#define FTSSP010_IRSPR(x) (SSP_FTSSP010_va_base[(x)]+0x2C)
+#define FTSSP010_ICMDST(x) (SSP_FTSSP010_va_base[(x)]+0x30)
+#define HDA_REG_OSDC(x) (SSP_FTSSP010_va_base[(x)]+0x50)
+#define HDA_REG_ISDC(x) (SSP_FTSSP010_va_base[(x)]+0x54)
+
+static const unsigned int SSP_FTSSP010_va_base[SSP_FTSSP010_IRQ_COUNT] = { SSP_FTSSP010_VA_BASE };
+static const unsigned int SSP_FTSSP010_pa_base[SSP_FTSSP010_IRQ_COUNT] = { SSP_FTSSP010_PA_BASE };
+
+void SetSSP_Enable(int cardno, int enable)
+{
+ volatile unsigned int ctrl = 0;
+
+ ctrl = inl(FTSSP010_CONTROL2(cardno));
+ if(enable)
+ ctrl |= SSP_SSPEN + SSP_TXDOE;
+ else
+ ctrl &= ~(SSP_SSPEN + SSP_TXDOE);
+
+ outl(ctrl, FTSSP010_CONTROL2(cardno));
+}
+void SetSSP_Enable_rx(int cardno, int enable)
+{
+ volatile unsigned int ctrl = 0;
+
+ ctrl = inl(FTSSP010_CONTROL2(cardno));
+ if(enable)
+ ctrl |= SSP_SSPEN ;
+ else
+ ctrl &= ~(SSP_SSPEN);
+
+ outl(ctrl, FTSSP010_CONTROL2(cardno));
+}
+
+void SetSSP_FIFO_Threshold(int cardno, unsigned int trans_len,unsigned int rec_len)
+{
+ volatile unsigned int ctrl = 0;
+ ctrl = inl(FTSSP010_INT_CONTROL(cardno));
+
+ ctrl &= ~0x0000FF00;
+ ctrl |= ((trans_len << 12) + (rec_len << 8)) & 0x0000FF00;
+
+ outl(ctrl, FTSSP010_INT_CONTROL(cardno));
+}
+void SetSSP_IntMask(int cardno,int Mask)
+{
+ volatile unsigned int ctrl = 0;
+ ctrl = inl(FTSSP010_INT_CONTROL(cardno));
+ ctrl &= ~0x3F;
+ ctrl |= Mask;
+ outw(ctrl, FTSSP010_INT_CONTROL(cardno));
+}
+void SetSSP_TXFIFO(int cardno, unsigned int threshold,unsigned int underrun)
+{
+ volatile unsigned int data = 0;
+
+ data = inl(FTSSP010_INT_CONTROL(cardno));
+
+ if (threshold)
+ data |= SSP_TFIEN;
+ else
+ data &= ~SSP_TFIEN; //Howard@2007-4-13
+
+ if (underrun)
+ data |= SSP_TFURIEN;
+ else
+ data &= ~SSP_TFURIEN; //Howard@2007-4-13
+
+ outl(data, FTSSP010_INT_CONTROL(cardno));
+}
+void SetSSP_RXFIFO(int cardno,unsigned int threshold,unsigned int underrun)
+{
+ volatile unsigned int data = 0;
+
+ data = inl(FTSSP010_INT_CONTROL(cardno));
+
+ if (threshold)
+ data |= SSP_RFIEN;
+ else
+ data &= ~SSP_RFIEN; //Howard@2007-4-13
+
+ if (underrun)
+ data |= SSP_RFURIEN;
+ else
+ data &= ~SSP_RFURIEN; //Howard@2007-4-13
+
+ outl(data, FTSSP010_INT_CONTROL(cardno));
+}
+void SetSSP_DMA(int cardno, unsigned int trans,unsigned int rec)
+{
+ volatile unsigned int data = 0;
+
+ data = inl(FTSSP010_INT_CONTROL(cardno));
+
+ if (trans)
+ data |= SSP_TXDMAEN;
+ else
+ data &= ~SSP_TXDMAEN;
+
+ if (rec)
+ data |= SSP_RXDMAEN;
+ else
+ data &= ~SSP_RXDMAEN;
+
+ outl(data, FTSSP010_INT_CONTROL(cardno));
+}
+void SSPClearTxFIFO(int cardno)
+{
+ volatile unsigned int data = 0;
+
+ data = inl(FTSSP010_CONTROL2(cardno));
+ data |= SSP_TXFCLR;
+ outl(data, FTSSP010_CONTROL2(cardno));
+}
+
+
+void SSPClearRxFIFO(int cardno)
+{
+ volatile unsigned int data = 0;
+
+ data = inl(FTSSP010_CONTROL2(cardno));
+ data |= SSP_RXFCLR;
+ outl(data, FTSSP010_CONTROL2(cardno));
+}
+
+void ftssp010_set_int_control(int cardno, unsigned val)
+{
+ outl(val, FTSSP010_INT_CONTROL(cardno));
+}
+
+unsigned ftssp010_get_int_status(int cardno)
+{
+ return (inl(FTSSP010_INT_STATUS(cardno)));
+}
+
+int ftssp010_get_status(int cardno)
+{
+ return (inl(FTSSP010_STATUS(cardno)));
+}
+
+int ftssp010_tx_fifo_not_full(int cardno)
+{
+ return (inl(FTSSP010_STATUS(cardno))&0x2)==0x2;
+}
+
+int ftssp010_tx_fifo_vaild_entries(int cardno)
+{
+ return (inl(FTSSP010_STATUS(cardno))>>12) & 0x1f;
+}
+
+/* Configure FTSSP010 to a given sampling rate and channel number
+ * for HDA mode in playback mode
+ */
+void init_hw(unsigned int cardno)
+{
+ /* Step 1: Set HDA Mode & HDA Format */
+ outl(HDA_MODE | 0x4000, FTSSP010_CONTROL0(cardno)); /* set FTSSP010 to HDA mode */
+ mdelay(50);
+ outl(HDA_CRST_CLR | (5 << HDA_RST_FCNT_OFS), FTSSP010_CONTROL2(cardno)); /* Cold Reset AC-Link */
+ mdelay(50);
+ while((inl(FTSSP010_CONTROL2(cardno)) & HDA_CRST_MASK) != HDA_CRST_CLR);
+ SetSSP_IntMask(cardno, 0);
+
+}
+void SSPClearFIFO(int cardno, unsigned int tx, unsigned int rx)
+{
+ unsigned int data;
+
+ if (tx == 1) {
+ //clear TX
+ data = inl(FTSSP010_CONTROL2(cardno));
+ //data = REG32(SSP_REG_CTRL2);
+ data |= SSP_TXFCLR;
+ outl(data, FTSSP010_CONTROL2(cardno));
+ //REG32(SSP_REG_CTRL2) = data;
+ }
+
+ if (rx == 1) {
+ //clear RX
+ data = inl(FTSSP010_CONTROL2(cardno));
+ //data = REG32(SSP_REG_CTRL2);
+ data |= SSP_RXFCLR;
+ //REG32(SSP_REG_CTRL2) = data;
+ outl(data, FTSSP010_CONTROL2(cardno));
+ }
+}
+void hda_cmd_rsp(int cardno, unsigned int node_num, unsigned int verb_num, unsigned int func_num)
+{
+ //unsigned int HDA_REG_ICMDST;
+ volatile unsigned int hda_cmd = HDA_COD_DEVADDR | (node_num << 20) | (verb_num << 8) | func_num;
+ //Wait CMD Bus Not Busy
+ while((inl(FTSSP010_ICMDST(cardno)) & HDA_ICB_MASK) != 0);
+ //Write CMD into ICW
+ outl(hda_cmd, FTSSP010_AC_COMMAND(cardno));
+ mdelay(50);
+ //Wait new resp is latched into IRR
+ while((inl(FTSSP010_ICMDST(cardno)) & HDA_IRV_MASK) == 0);
+ //Get Resp From IRR & Compare with Expected Resp
+ //clear IRV
+ outl(inl(FTSSP010_ICMDST(cardno)) | (1 << HDA_IRV_OFFSET), FTSSP010_ICMDST(cardno));
+ mdelay(50);
+}
+void hda_cmdrsp_proc(int cardno, unsigned int node_num, unsigned int issue_cmd, unsigned int expect_rsp)
+{
+ unsigned int hda_cmd = HDA_COD_DEVADDR | node_num | issue_cmd;
+ unsigned int HDA_REG_ICMDST;
+ //Wait CMD Bus Not Busy
+ while((inl(FTSSP010_ICMDST(cardno)) & HDA_ICB_MASK) != 0);
+
+ //Write CMD into ICW
+ //REG32(HDA_REG_ICMDW) = hda_cmd;
+ outl(hda_cmd, FTSSP010_AC_COMMAND(cardno));
+ mdelay(50);
+ //Wait new resp is latched into IRR
+ while((inl(FTSSP010_ICMDST(cardno)) & HDA_IRV_MASK) == 0);
+ //Get Resp From IRR & Compare with Expected Resp
+ if (inl(FTSSP010_IRSPR(cardno)) != expect_rsp) {
+ ERR("%s: unexpected rsp!",__func__);
+ }
+ else {
+ //clear IRV
+ outl(inl(FTSSP010_ICMDST(cardno)) | (1 << HDA_IRV_OFFSET), FTSSP010_ICMDST(cardno));
+ }
+}
+unsigned int hda_covfmt_setup(unsigned int type, unsigned int base, unsigned int mult, unsigned int div, unsigned int bits, unsigned int chnum)
+{
+ unsigned int hda_fmt = type << HDA_FMT_TYPE_OFS |
+ base << HDA_FMT_BASE_OFS |
+ mult << HDA_FMT_MULT_OFS |
+ div << HDA_FMT_DIV_OFS |
+ bits << HDA_FMT_BITS_OFS |
+ chnum << HDA_FMT_CHNUM_OFS;
+ return hda_fmt;
+}
+unsigned int hda_covstr_setup(unsigned int stream, unsigned int channel)
+{
+ unsigned int hda_str = stream << HDA_STR_STR_OFS |
+ channel << HDA_STR_CHA_OFS ;
+ return hda_str;
+}
+unsigned int hda_converter_setup(int cardno, unsigned int mode, unsigned int type, unsigned int base, unsigned mult, unsigned int div, unsigned int bits, unsigned int chnum, unsigned int stream, unsigned int channel)
+{
+ unsigned int hda_fmt = 0;
+ unsigned int hda_str = 0;
+ unsigned int exp_rsp = 0;
+ unsigned int node_num = 0;
+
+ if (mode == HDA_OUT_STR) {
+ node_num = HDA_OUTCOV_NODE;
+ }
+ else {
+ node_num = HDA_INCOV_NODE;
+ }
+ //a: Set Converter Format to Converter
+ hda_fmt = hda_covfmt_setup(type, base, mult, div, bits, chnum);
+ exp_rsp = HDA_RESP_ZERO_VAL;
+ hda_cmdrsp_proc(cardno, node_num, (HDA_CMD_SETCVTFMT | hda_fmt), exp_rsp);
+ //b: Get Converter Format from Converter
+ exp_rsp = hda_fmt;
+ hda_cmdrsp_proc(cardno, node_num, HDA_CMD_GETCVTFMT, exp_rsp);
+ //c: Set Converter Stream to Converter
+ hda_str = hda_covstr_setup(stream, channel);
+ exp_rsp = HDA_RESP_ZERO_VAL;
+ hda_cmdrsp_proc(cardno, node_num, (HDA_CMD_SETCVTSTR | hda_str), exp_rsp);
+ //d: Get Converter Stream from Converter
+ exp_rsp = hda_str;
+ hda_cmdrsp_proc(cardno, node_num, HDA_CMD_GETCVTSTR, exp_rsp);
+
+ return hda_fmt;
+}
+void hda_iosdc_setup(int cardno, unsigned int io_sel, unsigned int ctrl, unsigned int stream_num, unsigned int hda_fmt)
+{
+ unsigned int hda_reg_base = (io_sel == 1)? HDA_REG_OSDC(cardno) : HDA_REG_ISDC(cardno);
+ if (ctrl == 1) {//run
+ outl((stream_num << HDA_SDC_STNUM_OFFSET) | hda_fmt, hda_reg_base);
+ outl((inl(hda_reg_base) | (1 << HDA_SDC_SRUN_OFFSET)),hda_reg_base);
+ }
+
+}
+static void _ftssp010_config_hda(int cardno, unsigned is_stereo, unsigned speed, int is_rec)
+{
+ unsigned int hda_fmt = 0;
+ unsigned int div = 0,mult = 0, base = 0;
+ switch (speed) {
+ case 44100:
+ base = 1;
+ div = 0;
+ break;
+ case 48000:
+ div = 0;
+ break;
+ case 96000:
+ mult = 1;
+ break;
+ case 192000:
+ mult = 3;
+ break;
+ }
+
+ if (is_rec) { /* Recording */
+ /* ------------------------------------------------ */
+ /* Codec initialization */
+ /* ------------------------------------------------ */
+ /* Step 3: Codec Evaluation */
+ /* root_node -> node 1(Audio Func Group) */
+ /* -> node 2(Output Converter) */
+ /* -> node 3(Input Converter) */
+ /* ------------------------------------------------ */
+ //input
+ hda_cmd_rsp(cardno, 0x1a, 0x707, 0x20); //pin complex => input enable, port-c LINE1
+ hda_cmd_rsp(cardno, 0x08, 0x3f0, 0x3f);//pin amp => max LINE ADC amplifier gain
+ hda_cmd_rsp(cardno, 0x1a, 0x3f0, 0x00);//pin complex => no mute
+ hda_cmd_rsp(cardno, 0x23, 0x3f2, 0x3f);//pin complex => no mute
+ /* ------------------------------ */
+ /* Step 4: Output Converter Setup */
+ /* ------------------------------ */
+ /* Set Converter Format & Stream to Node 2(Output Converter) */
+ /* type = PCM, base = 48K, mult = xN, div = /M, bits = 8~32bits/sample, chnum = 1 */
+ /* stream = 1, lowest channel = 0 */
+
+ hda_fmt = hda_converter_setup(cardno, HDA_IN_STR, //MODE
+ 0, base, mult, div, 1, 1, //FORMAT
+ HDA_STRNUM_RX, HDA_CHANUM); //STREAM
+ /* ---------------------------- */
+ /* Step 5: Enable Output Stream */
+ /* ---------------------------- */
+ hda_iosdc_setup(cardno, HDA_IN_STR, HDA_STR_RUN, HDA_STRNUM_RX, hda_fmt);
+ SetSSP_Enable_rx(cardno, 1);
+ SetSSP_RXFIFO(cardno, 0, 0);
+ SetSSP_TXFIFO(cardno, 0, 0);
+ SetSSP_FIFO_Threshold(cardno,12,12);
+ SetSSP_DMA(cardno, 0, 1);
+
+ SSPClearTxFIFO(cardno);
+ SSPClearRxFIFO(cardno);
+
+ //SetSSP_Enable_rx(cardno, 0);
+
+ } else { /* Playback */
+ /* ------------------------------------------------ */
+ /* Codec initialization */
+ /* ------------------------------------------------ */
+ /* Step 3: Codec Evaluation */
+ /* root_node -> node 1(Audio Func Group) */
+ /* -> node 2(Output Converter) */
+ /* -> node 3(Input Converter) */
+ /* ------------------------------------------------ */
+ //DBG("%s before_cmd_rsp<<",__func__);
+ hda_cmd_rsp(cardno, 0x14, 0x707, 0x40);//pin complex => output
+ //DBG("%s after hda_cmd_rsp<<pin complex => output>>",__func__);
+ hda_cmd_rsp(cardno, 0x0c, 0x3f0, 0x3f);//pin amp => 0x3f
+ hda_cmd_rsp(cardno, 0x14, 0x3f0, 0x00);//pin complex => no mute
+ //DBG("%s after hda_cmd_rsp",__func__);
+ //msleep_interruptible(10);
+ /* ------------------------------ */
+ /* Step 4: Output Converter Setup */
+ /* ------------------------------ */
+ /* Set Converter Format & Stream to Node 2(Output Converter) */
+ /* type = PCM, base = 48K, mult = xN, div = /M, bits = 8~32bits/sample, chnum = 1 */
+ /* stream = 1, lowest channel = 0 */
+ hda_fmt = hda_converter_setup(cardno, HDA_OUT_STR, //MODE
+ 0, base, mult, div, 1, 1, //FORMAT
+ HDA_STRNUM_TX, HDA_CHANUM); //STREAM
+ //DBG("%s after hda_converter_setup",__func__);
+ /* ---------------------------- */
+ /* Step 5: Enable Output Stream */
+ /* ---------------------------- */
+ hda_iosdc_setup(cardno, HDA_OUT_STR, HDA_STR_RUN, HDA_STRNUM_TX, hda_fmt);
+ SetSSP_Enable(cardno, 1);
+ SetSSP_RXFIFO(cardno, 0, 0);
+ SetSSP_TXFIFO(cardno, 0, 0);
+ //outl(0xC, FTSSP010_CONTROL2(cardno)); /* Disable FTSSP010, clear RX/TX Fifo. */
+ SetSSP_FIFO_Threshold(cardno,12,12);
+ SetSSP_DMA(cardno,1,0);
+
+ SSPClearTxFIFO(cardno);
+ SSPClearRxFIFO(cardno);
+ }
+
+ while(inl(FTSSP010_INT_STATUS(cardno))&0x3);
+}
+/* for HDA */
+void ftssp010_config_hda_play(int cardno, unsigned is_stereo, unsigned speed, int use8bit)
+{
+ _ftssp010_config_hda(cardno, is_stereo, speed, 0);
+}
+
+void ftssp010_config_hda_rec(int cardno, unsigned is_stereo, unsigned speed, int use8bit)
+{
+ _ftssp010_config_hda(cardno, is_stereo, speed, 1);
+}
+
+
+
+void ftssp010_stop_tx(int cardno)
+{
+ unsigned int hda_reg_base = HDA_REG_OSDC(cardno);
+ SetSSP_Enable(cardno,0);
+ SetSSP_DMA(cardno,0,0);
+
+ /* turn off output node */
+ hda_cmd_rsp(cardno,0x14, 0x707, 0); //pin complex => input enable, port-c LINE1
+ hda_cmd_rsp(cardno,0x0c, 0x3f0, 0x80); //pin amp => max LINE ADC amplifier gain
+ hda_cmd_rsp(cardno,0x14, 0x3f0, 0x80); //pin complex => no mute
+
+ outl(0, hda_reg_base);
+ SSPClearFIFO(cardno, 1, 0);
+ //outl(inl(FTSSP010_INT_CONTROL(cardno)) & (~0x22), FTSSP010_INT_CONTROL(cardno));
+}
+
+void ftssp010_stop_rx(int cardno)
+{
+ unsigned int hda_reg_base = HDA_REG_ISDC(cardno);
+ SetSSP_Enable_rx(cardno, 0);
+ SetSSP_DMA(cardno, 0, 0);
+
+ /* turn off output node */
+ hda_cmd_rsp(cardno,0x1a, 0x707, 0); //pin complex => input enable, port-c LINE1
+ hda_cmd_rsp(cardno,0x08, 0x3f0, 0x80);//pin amp => LINE ADC amplifier gain
+ hda_cmd_rsp(cardno,0x1a, 0x3f0, 0x80);//pin complex => mute
+ hda_cmd_rsp(cardno,0x23, 0x3f2, 0x80);//pin complex => no mute
+
+ outl(0, hda_reg_base);
+ SSPClearFIFO(cardno, 0, 1);
+ //outl(inl(FTSSP010_INT_CONTROL(cardno)) & (~0x11), FTSSP010_INT_CONTROL(cardno));
+}
+
diff -Nur linux-3.4.113.orig/sound/nds32/FTSSP010_lib.c linux-3.4.113/sound/nds32/FTSSP010_lib.c
--- linux-3.4.113.orig/sound/nds32/FTSSP010_lib.c 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/sound/nds32/FTSSP010_lib.c 2016-12-01 20:59:24.396614447 +0100
@@ -0,0 +1,795 @@
+/* FTSSP010 - UDA1345TS module
+ *
+ * $log$
+ */
+
+#include <linux/init.h>
+#include <linux/module.h>
+#include <asm/io.h>
+#include <linux/delay.h>
+#include <linux/i2c.h>
+#include <asm/spec.h>
+#include <asm/dmad.h>
+#include <linux/dma-mapping.h>
+#include "FTSSP010_UDA1345TS.h"
+
+#if 0
+MODULE_LICENSE("Faraday License");
+MODULE_AUTHOR("Faraday Technology Corp.");
+MODULE_DESCRIPTION("FTSSP010 - UDA1345TS Linux 2.6 Library");
+#endif
+
+#define PMU_PDLLCR1 (PMU_FTPMU010_VA_BASE+0x34)
+#define PMU_MFPSR (PMU_FTPMU010_VA_BASE+0x28)
+#define PMU_I2SAC97_REQACKCFG (PMU_FTPMU010_VA_BASE+0xbc)
+#define PMU_C4 (PMU_FTPMU010_VA_BASE+0xc4)
+
+#define SSPCLK_TO_SCLKDIV(sspclk_div2,bps) ((sspclk_div2)/(bps)-1)
+
+// Each client has this additional data
+struct alc5630_data {
+ struct i2c_client *client;
+ struct delayed_work work;
+ unsigned long gpio2_value;
+ struct mutex mtx;
+};
+
+//ADD by river 2011.01.26
+static int i2s_alc5630_read(unsigned int raddr, char *data, struct i2c_client *client)
+{
+#ifndef CONFIG_SND_FTSSP010_AC97
+ struct i2c_adapter *adap = client->adapter;
+ int ret;
+#endif
+ struct i2c_msg msg;
+ int i2c_value;
+
+ //Reading ALC5630 register
+ msg.addr = raddr;
+ msg.flags = (client->flags & I2C_M_TEN) | I2C_M_RD;
+ msg.len = 1;
+ msg.buf = (char *)data;
+
+ //ret = i2c_transfer(adap, &msg, 1);
+#ifndef CONFIG_SND_FTSSP010_AC97
+ ret = i2c_transfer(adap, &msg, 1);
+ if (ret != 0) {
+ printk("i2c read failed\n");
+ return -1;
+ }
+ else
+#endif
+ {
+ i2c_value = (data[0]&0xff) << 8 | (data[1]&0xff);
+ return i2c_value;
+ }
+}
+
+static void i2s_alc5630_write(unsigned int raddr, unsigned int data, struct i2c_client *client)
+{
+#ifndef CONFIG_SND_FTSSP010_AC97
+ struct i2c_adapter *adap = client->adapter;
+ int ret;
+#endif
+ struct i2c_msg msg;
+ char buf[3];
+
+ //Writing ALC5630 register
+ msg.addr = raddr;
+ msg.flags = (client->flags & I2C_M_TEN) | ~I2C_M_RD;
+ msg.len = 1;
+
+ buf[0] = (data >> 8) & 0xff;
+ buf[1] = data & 0xff;
+ msg.buf = (char *)buf;
+
+ //ret = i2c_transfer(adap, &msg, 1);
+#ifndef CONFIG_SND_FTSSP010_AC97
+ ret = i2c_transfer(adap, &msg, 1);
+ if (ret != 0)
+ {
+ printk("i2c write failed\n");
+ }
+#endif
+}
+
+/*
+static void i2s_alc5630_master_stereo_mode(struct i2c_client *client)
+{
+ //printk(">>>>>>>>> (7) i2s_alc5630_master_stereo_mode() is called.\n");
+ i2s_alc5630_write(0x02, 0x5f5f, client);
+ mdelay(50);
+ i2s_alc5630_write(0x04, 0x5f5f, client);
+ mdelay(50);
+ i2s_alc5630_write(0x26, 0x000f, client);
+ mdelay(50);
+ i2s_alc5630_write(0x34, 0x0000, client); // codec master mode
+ //i2s_alc5630_write(0x34, 0x8000, client); // codec slave mode
+ mdelay(50);
+ i2s_alc5630_write(0x3a, 0x0801, client);
+ mdelay(50);
+ i2s_alc5630_write(0x3c, 0xffff, client);
+ mdelay(50);
+ i2s_alc5630_write(0x3e, 0xffff, client);
+ mdelay(50);
+ i2s_alc5630_write(0x60, 0x3075, client); // codec master mode. divider.
+ mdelay(50);
+ i2s_alc5630_write(0x62, 0x1010, client); // codec master mode. divider.
+
+}
+*/
+
+/*
+static void i2s_alc5630_read_test(struct i2c_client *client)
+{
+ char data[3];
+ printk(">>>>> : i2s_alc5630_read_test().....\n");
+ printk("Reg 0x%02x = 0x%08x\n", 0x0, i2s_alc5630_read(0x0, data,client));
+ printk("Reg 0x%02x = 0x%08x\n", 0x02, i2s_alc5630_read(0x02, data,client));
+ printk("Reg 0x%02x = 0x%08x\n", 0x04, i2s_alc5630_read(0x04, data,client));
+ printk("Reg 0x%02x = 0x%08x\n", 0x06, i2s_alc5630_read(0x06, data,client));
+ printk("Reg 0x%02x = 0x%08x\n", 0x08, i2s_alc5630_read(0x08, data,client));
+ printk("Reg 0x%02x = 0x%08x\n", 0x0a, i2s_alc5630_read(0x0a, data,client));
+ printk("Reg 0x%02x = 0x%08x\n", 0x0c, i2s_alc5630_read(0x0c, data,client));
+ printk("Reg 0x%02x = 0x%08x\n", 0x0e, i2s_alc5630_read(0x0e, data,client));
+
+ printk("Reg 0x%02x = 0x%08x\n", 0x10, i2s_alc5630_read(0x10, data,client));
+ printk("Reg 0x%02x = 0x%08x\n", 0x12, i2s_alc5630_read(0x12, data,client));
+ printk("Reg 0x%02x = 0x%08x\n", 0x14, i2s_alc5630_read(0x14, data,client));
+ printk("Reg 0x%02x = 0x%08x\n", 0x16, i2s_alc5630_read(0x16, data,client));
+ printk("Reg 0x%02x = 0x%08x\n", 0x18, i2s_alc5630_read(0x18, data,client));
+ printk("Reg 0x%02x = 0x%08x\n", 0x1a, i2s_alc5630_read(0x1a, data,client));
+ printk("Reg 0x%02x = 0x%08x\n", 0x1c, i2s_alc5630_read(0x1c, data,client));
+ printk("Reg 0x%02x = 0x%08x\n", 0x1e, i2s_alc5630_read(0x1e, data,client));
+
+ printk("Reg 0x%02x = 0x%08x\n", 0x20, i2s_alc5630_read(0x20, data,client));
+ printk("Reg 0x%02x = 0x%08x\n", 0x22, i2s_alc5630_read(0x22, data,client));
+ printk("Reg 0x%02x = 0x%08x\n", 0x24, i2s_alc5630_read(0x24, data,client));
+ printk("Reg 0x%02x = 0x%08x\n", 0x26, i2s_alc5630_read(0x26, data,client));
+ printk("Reg 0x%02x = 0x%08x\n", 0x28, i2s_alc5630_read(0x28, data,client));
+ printk("Reg 0x%02x = 0x%08x\n", 0x2a, i2s_alc5630_read(0x2a, data,client));
+ printk("Reg 0x%02x = 0x%08x\n", 0x2c, i2s_alc5630_read(0x2c, data,client));
+ printk("Reg 0x%02x = 0x%08x\n", 0x2e, i2s_alc5630_read(0x2e, data,client));
+
+ printk("Reg 0x%02x = 0x%08x\n", 0x30, i2s_alc5630_read(0x30, data,client));
+ printk("Reg 0x%02x = 0x%08x\n", 0x32, i2s_alc5630_read(0x32, data,client));
+ printk("Reg 0x%02x = 0x%08x\n", 0x34, i2s_alc5630_read(0x34, data,client));
+ printk("Reg 0x%02x = 0x%08x\n", 0x36, i2s_alc5630_read(0x36, data,client));
+ printk("Reg 0x%02x = 0x%08x\n", 0x38, i2s_alc5630_read(0x38, data,client));
+ printk("Reg 0x%02x = 0x%08x\n", 0x3a, i2s_alc5630_read(0x3a, data,client));
+ printk("Reg 0x%02x = 0x%08x\n", 0x3c, i2s_alc5630_read(0x3c, data,client));
+ printk("Reg 0x%02x = 0x%08x\n", 0x3e, i2s_alc5630_read(0x3e, data,client));
+
+ printk("Reg 0x%02x = 0x%08x\n", 0x40, i2s_alc5630_read(0x40, data,client));
+ printk("Reg 0x%02x = 0x%08x\n", 0x42, i2s_alc5630_read(0x42, data,client));
+ printk("Reg 0x%02x = 0x%08x\n", 0x44, i2s_alc5630_read(0x44, data,client));
+ printk("Reg 0x%02x = 0x%08x\n", 0x46, i2s_alc5630_read(0x46, data,client));
+ printk("Reg 0x%02x = 0x%08x\n", 0x48, i2s_alc5630_read(0x48, data,client));
+ printk("Reg 0x%02x = 0x%08x\n", 0x4a, i2s_alc5630_read(0x4a, data,client));
+ printk("Reg 0x%02x = 0x%08x\n", 0x4c, i2s_alc5630_read(0x4c, data,client));
+ printk("Reg 0x%02x = 0x%08x\n", 0x4e, i2s_alc5630_read(0x4e, data,client));
+
+ printk("Reg 0x%02x = 0x%08x\n", 0x50, i2s_alc5630_read(0x50, data,client));
+ printk("Reg 0x%02x = 0x%08x\n", 0x52, i2s_alc5630_read(0x52, data,client));
+ printk("Reg 0x%02x = 0x%08x\n", 0x54, i2s_alc5630_read(0x54, data,client));
+ printk("Reg 0x%02x = 0x%08x\n", 0x56, i2s_alc5630_read(0x56, data,client));
+ printk("Reg 0x%02x = 0x%08x\n", 0x58, i2s_alc5630_read(0x58, data,client));
+ printk("Reg 0x%02x = 0x%08x\n", 0x5a, i2s_alc5630_read(0x5a, data,client));
+ printk("Reg 0x%02x = 0x%08x\n", 0x5c, i2s_alc5630_read(0x5c, data,client));
+ printk("Reg 0x%02x = 0x%08x\n", 0x5e, i2s_alc5630_read(0x5e, data,client));
+
+ printk("Reg 0x%02x = 0x%08x\n", 0x60, i2s_alc5630_read(0x60, data,client));
+ printk("Reg 0x%02x = 0x%08x\n", 0x62, i2s_alc5630_read(0x62, data,client));
+ printk("Reg 0x%02x = 0x%08x\n", 0x64, i2s_alc5630_read(0x64, data,client));
+ printk("Reg 0x%02x = 0x%08x\n", 0x66, i2s_alc5630_read(0x66, data,client));
+ printk("Reg 0x%02x = 0x%08x\n", 0x68, i2s_alc5630_read(0x68, data,client));
+ printk("Reg 0x%02x = 0x%08x\n", 0x6a, i2s_alc5630_read(0x6a, data,client));
+ printk("Reg 0x%02x = 0x%08x\n", 0x6c, i2s_alc5630_read(0x6c, data,client));
+ printk("Reg 0x%02x = 0x%08x\n", 0x6e, i2s_alc5630_read(0x6e, data,client));
+
+ printk("Reg 0x%02x = 0x%08x\n", 0x70, i2s_alc5630_read(0x70, data,client));
+ printk("Reg 0x%02x = 0x%08x\n", 0x72, i2s_alc5630_read(0x72, data,client));
+ printk("Reg 0x%02x = 0x%08x\n", 0x74, i2s_alc5630_read(0x74, data,client));
+ printk("Reg 0x%02x = 0x%08x\n", 0x76, i2s_alc5630_read(0x76, data,client));
+ printk("Reg 0x%02x = 0x%08x\n", 0x78, i2s_alc5630_read(0x78, data,client));
+ printk("Reg 0x%02x = 0x%08x\n", 0x7a, i2s_alc5630_read(0x7a, data,client));
+ printk("Reg 0x%02x = 0x%08x\n", 0x7c, i2s_alc5630_read(0x7c, data,client));
+ printk("Reg 0x%02x = 0x%08x\n", 0x7e, i2s_alc5630_read(0x7e, data,client));
+
+}
+*/
+
+static void i2s_al5630_slave_stereo_mode(struct i2c_client *client)
+{
+
+
+ i2s_alc5630_write(0x34, 0x8000, client); // codec slave mode
+ i2s_alc5630_write(0x0c, 0x1010, client);
+ i2s_alc5630_write(0x10, 0xee03, client);
+ i2s_alc5630_write(0x1c, 0x0748, client);
+ //i2s_alc5630_write(0x02, 0x8080, client);
+ //i2s_alc5630_write(0x04, 0x8888, client);
+ i2s_alc5630_write(0x62, 0x0000, client);
+
+}
+
+//End ADD by river 2011.01.26
+
+
+/* Drive PMU to generate I2S main clocking signal. Also configures PMU to set correct DMA REQ/ACK pair */
+void pmu_set_i2s_clocking(unsigned int speed)
+{
+ unsigned int pmu_pdllcr1; /* PLL/DLL Control Register 1 */
+ /* Configure PMU to generate I2S main clock */
+ #ifdef CONFIG_PLAT_AG101
+ pmu_pdllcr1 = inl(PMU_PDLLCR1)&0xfff0ffff; /* Bit 19-16 are relevent */
+ #endif
+
+ switch (speed) {
+ case 8000:
+ pmu_pdllcr1 |= 0x00000000; /* 2.048MHz x2 */
+ break;
+ case 11025:
+ pmu_pdllcr1 |= 0x00010000; /* 2.8224MHz x2 */
+ break;
+ case 16000:
+ pmu_pdllcr1 |= 0x00020000; /* 4.096MHz x2 */
+ break;
+ case 22050:
+ pmu_pdllcr1 |= 0x00030000; /* 5.6448MHz x2 */
+ break;
+ case 32000:
+ pmu_pdllcr1 |= 0x00040000; /* 8.192MHz x2 */
+ break;
+ case 44100:
+ pmu_pdllcr1 |= 0x00050000; /* 11.2896Mhz x2 */
+ break;
+ case 48000:
+ pmu_pdllcr1 |= 0x00060000; /* 12.2880MHz x2 */
+ break;
+ default:
+ printk("%s: Unknown i2s speed %d\n",__func__,speed);
+ };
+
+ #ifdef CONFIG_PLAT_AG101
+ outl(pmu_pdllcr1, PMU_PDLLCR1);
+ /* Configure PMU to select I2S output (instead of AC97) */
+ outl(inl(PMU_MFPSR)&(~(1<<3)), PMU_MFPSR); /* clear bit 3 of MFPSR*/
+ #endif
+}
+
+/* Drive PMU to generate AC97 main clocking signal. Also configures PMU to set correct DMA REQ/ACK pair */
+void pmu_set_ac97_clocking(unsigned int speed)
+{
+ /* Configure PMU to select AC97 output (instead of I2S) */
+ /* Set GPIO[26] to AC97 clock, use 49.152MHz main clock (AC97 CLK1) */
+ //outl(inl(PMU_MFPSR)|((1<<13)|(1<<3)), PMU_MFPSR); /* Set bit 13 & 3 of MFPSR*/
+ #ifndef CONFIG_PLAT_AG102
+ outl(inl(PMU_MFPSR)|((1<<13)|(1<<3)), PMU_MFPSR); /* Set bit 13 & 3 of MFPSR*/
+ #endif
+}
+
+/* Programs PMU to set I2S/AC97 DMA Channel, ch=0-7 */
+void pmu_set_i2s_dma_channel(unsigned ch)
+{
+ #ifdef CONFIG_PLAT_AG101
+ ch&=0x7;
+ //outl((inl(PMU_I2SAC97_REQACKCFG)&(~0x7))|ch, PMU_I2SAC97_REQACKCFG);
+ outl(0xa, PMU_I2SAC97_REQACKCFG);
+ outl(0xb, PMU_C4);
+ #endif
+}
+
+/* Initialize FTSSP010 to output to UDA1345TS via I2S */
+#define FTSSP010_CONTROL0(x) (SSP_FTSSP010_va_base[(x)]+0x0)
+#define FTSSP010_CONTROL0_OPM_STEREO 0xC
+#define FTSSP010_CONTROL0_OPM_MONO 0x8
+
+#define FTSSP010_CONTROL1(x) (SSP_FTSSP010_va_base[(x)]+0x4)
+#define FTSSP010_CONTROL2(x) (SSP_FTSSP010_va_base[(x)]+0x8)
+
+#define FTSSP010_INT_CONTROL(x) (SSP_FTSSP010_va_base[(x)]+0x10)
+#define FTSSP010_STATUS(x) (SSP_FTSSP010_va_base[(x)]+0xC)
+#define FTSSP010_INT_STATUS(x) (SSP_FTSSP010_va_base[(x)]+0x14)
+#define FTSSP010_DATA(x) (SSP_FTSSP010_va_base[(x)]+0x18)
+#define FTSSP010_INFO(x) (SSP_FTSSP010_va_base[(x)]+0x1C)
+
+//static const unsigned int SSP_FTSSP010_va_base[SSP_FTSSP010_IRQ_COUNT] = { SSP_FTSSP010_VA_BASE };
+//static const unsigned int SSP_FTSSP010_pa_base[SSP_FTSSP010_IRQ_COUNT] = { SSP_FTSSP010_PA_BASE };
+
+//ADD by river 2011.02.11
+static struct i2c_client *g_i2c_client;
+
+
+#define FTSSP010_ACLINK_SLOT_VALID(x) (SSP_FTSSP010_va_base[(x)]+0x20)
+
+void ftssp010_set_int_control(int cardno, unsigned val)
+{
+ outl(val, FTSSP010_INT_CONTROL(cardno));
+}
+
+unsigned ftssp010_get_int_status(int cardno)
+{
+ return (inl(FTSSP010_INT_STATUS(cardno)));
+}
+
+int ftssp010_get_status(int cardno)
+{
+ return (inl(FTSSP010_STATUS(cardno)));
+}
+
+int ftssp010_tx_fifo_not_full(int cardno)
+{
+ return (inl(FTSSP010_STATUS(cardno))&0x2)==0x2;
+}
+
+int ftssp010_tx_fifo_vaild_entries(int cardno)
+{
+ return (inl(FTSSP010_STATUS(cardno))>>12) & 0x1f;
+}
+
+#include "FTSSP010_W83972D.h"
+
+// AC97 codec tags
+#define TAG_COMMAND 0xe000
+#define TAG_DATA 0x9800 /* Slot 3/4 */
+#define TAG_DATA_MONO 0x9000 /* Slot 3 */
+//#define TAG_DATA_LINE_IN 0x9000 /* Slot 3 */
+
+void ftssp010_ac97_write_codec_start(unsigned int cardno)
+{
+ outl(0x0, FTSSP010_INT_CONTROL(cardno));/*Disable interrupts & DMA req */
+ outl(0xC, FTSSP010_CONTROL2(cardno)); /* Disable FTSSP010, clear RX/TX Fifo. */
+ outl(TAG_COMMAND, FTSSP010_ACLINK_SLOT_VALID(cardno));
+}
+
+void ftssp010_ac97_write_codec(unsigned int cardno,unsigned int reg,unsigned int data)
+{
+ outl(reg << 12, FTSSP010_DATA(cardno));
+ mdelay(50);
+ outl(data << 4, FTSSP010_DATA(cardno));
+ mdelay(50);
+}
+
+void ftssp010_ac97_write_codec_commit(unsigned int cardno)
+{
+ while((inl(FTSSP010_CONTROL2(cardno))&0x1)==0) {
+ outl(0x3 , FTSSP010_CONTROL2(cardno)); /* SSPEN + TXDOE */
+ }
+ while(ftssp010_tx_fifo_vaild_entries(cardno))
+ ;
+ /* Wait for frame completion */
+ while((inl(FTSSP010_INT_STATUS(cardno))&0x10)==0)
+ ;
+ outl(0x0, FTSSP010_CONTROL2(cardno));
+}
+
+/* Configure FTSSP010 to a given sampling rate and channel number
+ * for AC97 mode in playback mode
+ */
+void init_hw(unsigned int cardno,unsigned int ac97, struct i2c_client *client)
+{
+
+ //printk(">>>>>>>>>> (5) init_hw() is called.\n");
+ g_i2c_client = client;
+
+ if(ac97)
+ {
+ //pmu_set_ac97_clocking(48000);
+ #ifndef CONFIG_PLAT_AG102
+ pmu_set_ac97_clocking(48000);
+ #endif
+ outl(0x400c, FTSSP010_CONTROL0(cardno)); /* set FTSSP010 to AC97 mode */
+ mdelay(50);
+ outl(0xc400, FTSSP010_INT_CONTROL(cardno));
+ mdelay(50);
+ outl(0x20, FTSSP010_CONTROL2(cardno)); /* Cold Reset AC-Link */
+ mdelay(50);
+ while(inl(FTSSP010_CONTROL2(cardno)))
+ mdelay(50);
+ outl(0x40, FTSSP010_CONTROL2(cardno)); /* Reset AC-Link */
+ mdelay(1500);
+ }
+ else
+ {
+
+ //printk(">>>>>>>>> (6) I2S mode selected....YAYAYA......\n");
+ #ifdef CONFIG_PLAT_AG101
+ outl(inl(PMU_MFPSR)&(~(1<<3)), PMU_MFPSR); /* clear bit 3 of MFPSR*/
+ outl(0xa, PMU_I2SAC97_REQACKCFG);
+ outl(0xb, PMU_C4);
+ #endif
+
+ //MOD by river 2011.01.26
+ //i2s_alc5630_master_stereo_mode(client);
+ i2s_al5630_slave_stereo_mode(client);
+ //ssp_slave_stereo_mode();
+ //End MOD by river 2011.01.26
+ outl(0x311c, FTSSP010_CONTROL0(cardno)); /* I2S Master */
+ outl(0, FTSSP010_CONTROL1(cardno)); /* I2S Master */
+ outl(0xc400, FTSSP010_INT_CONTROL(cardno)); /* I2S Master */
+ outl(0x40, FTSSP010_CONTROL2(cardno)); /* Reset AC-Link */
+
+ //i2s_alc5630_read_test(client);
+ }
+}
+static void _ftssp010_config_ac97(int cardno, unsigned is_stereo, unsigned speed, int is_rec)
+{
+ /* Codec initialization */
+ ftssp010_ac97_write_codec_start(cardno);
+ ftssp010_ac97_write_codec(cardno, W83972D_RESET, 0);
+ ftssp010_ac97_write_codec_commit(cardno);
+
+ msleep_interruptible(10);
+ ftssp010_ac97_write_codec_start(cardno);
+
+ if (is_rec) { /* Recording */
+ /* Mute output */
+ //ftssp010_ac97_write_codec(cardno, W83972D_STEREO_OUTPUT_CONTROL, 0x8000);
+ /* Mute PCM */
+ //ftssp010_ac97_write_codec(cardno, W83972D_PCM_OUTPUT_CONTROL, 0x8000);
+
+ /* Register 0x10, Line-In/Mic Gain */
+ ftssp010_ac97_write_codec(cardno, W83972D_LINE_IN_VOLUME, 0x808);
+ //ftssp010_ac97_write_codec(cardno, W83972D_AUX_INPUT_CONTROL, 0x808);
+ ftssp010_ac97_write_codec(cardno, W83972D_MIC_VOLUME, 0x8);
+ /* FIXME: REC from line-in only */
+
+ /* Register 0x1A, Record Select=StereoMix */
+ ftssp010_ac97_write_codec(cardno, W83972D_RECORD_SELECT, 0x505 /*404*/);
+ /* Register 0x1C, Record Gain=0db */
+ ftssp010_ac97_write_codec(cardno, W83972D_RECORD_GAIN, 0x808);
+ ftssp010_ac97_write_codec(cardno, W83972D_RECORD_GAIN_MIC, 0x8);
+ } else { /* Playback */
+ /* Register 0x10, Mute Line-In/Mic Gain */
+ ftssp010_ac97_write_codec(cardno, W83972D_LINE_IN_VOLUME, 0x8000);
+ ftssp010_ac97_write_codec(cardno, W83972D_MIC_VOLUME, 0x8000);
+
+ /* Register 0x1A, Mute Record Gains */
+ ftssp010_ac97_write_codec(cardno, W83972D_RECORD_GAIN, 0x8000);
+ ftssp010_ac97_write_codec(cardno, W83972D_RECORD_GAIN_MIC, 0x8000);
+
+ /* Output */
+ ftssp010_ac97_write_codec(cardno, W83972D_STEREO_OUTPUT_CONTROL, 0);
+ ftssp010_ac97_write_codec(cardno, W83972D_PCM_OUTPUT_CONTROL, 0x808);
+ }
+
+#if 0
+ ftssp010_ac97_write_codec(cardno, W83972D_EXT_AUDIO_CONTROL, 0x1);
+ ftssp010_ac97_write_codec(cardno, W83972D_DAC_SAMPLE_RATE_CONTROL, speed);
+#endif
+
+ ftssp010_ac97_write_codec_commit(cardno);
+ msleep_interruptible(10);
+
+ /* Start data transfer */
+// if(is_rec) {
+// outl(TAG_DATA_LINE_IN, FTSSP010_ACLINK_SLOT_VALID(cardno));
+// } else {
+ if(is_stereo)
+ outl(TAG_DATA, FTSSP010_ACLINK_SLOT_VALID(cardno));
+ else
+ outl(TAG_DATA_MONO, FTSSP010_ACLINK_SLOT_VALID(cardno));
+// }
+ while(inl(FTSSP010_INT_STATUS(cardno))&0x3);
+// msleep_interruptible(10);
+}
+
+void ftssp010_config_ac97_play(int cardno, unsigned is_stereo, unsigned speed, int use8bit)
+{
+ _ftssp010_config_ac97(cardno, is_stereo, speed, 0);
+}
+
+void ftssp010_config_ac97_rec(int cardno, unsigned is_stereo, unsigned speed, int use8bit)
+{
+ _ftssp010_config_ac97(cardno, is_stereo, speed, 1);
+}
+/*
+ * Configure FTSSP010 to a given sampling rate and channel number
+ * for I2S mode
+ */
+void ftssp010_config(int cardno, unsigned is_stereo, unsigned speed, int width, int is_rec)
+{
+ int use8bit = (width == 1 ? 1 : 0);
+ unsigned opm, bps = 2 * (use8bit ? 8 : 16); /* bits per 1 second audio data. */
+ unsigned fpclkdiv = 0;
+
+ //ADD by river 2011.06.02
+ struct alc5630_data *alc5630;
+ char data[3];
+ opm = is_stereo ? FTSSP010_CONTROL0_OPM_STEREO : FTSSP010_CONTROL0_OPM_MONO;
+ //MOD by river 2011.01.27
+ outl(0x3100 | opm, FTSSP010_CONTROL0(cardno)); /* I2S Master */
+ //End MOD by river 2011.01.27
+
+#if 0
+ printk("%s: use %dHz %d-bit %s \n",__func__,
+ speed,
+ use8bit?8:16,
+ is_stereo?"stereo":"mono"
+ );
+#endif
+
+ /* configures CONTROL1 to use suitable clock divider.
+ the I2S clock is generated from PMU. */
+ bps *= speed;
+ switch(speed) {
+ case 8000: /* SCLK : 256KHZ */
+ i2s_alc5630_write(0x44, 0x3ea0, g_i2c_client); //?
+ i2s_alc5630_write(0x60, 0x3174, g_i2c_client);
+ i2s_alc5630_write(0x62, 0x1010, g_i2c_client);
+ //i2s_alc5630_write(0x44, 0x6a0, g_i2c_client); //?
+ //i2s_alc5630_write(0x60, 0x3174, g_i2c_client);
+ //i2s_alc5630_write(0x62, 0x1010, g_i2c_client);
+ fpclkdiv = 0xBB;
+
+ //fpclkdiv=SSPCLK_TO_SCLKDIV(2048000, bps);
+ break;
+ case 11025: /* SCLK : 352.8KHZ */
+ i2s_alc5630_write(0x44, 0x3ea0, g_i2c_client); //?
+ i2s_alc5630_write(0x60, 0x3174, g_i2c_client);
+ i2s_alc5630_write(0x62, 0x1010, g_i2c_client);
+ fpclkdiv = 0x88;
+ //fpclkdiv=SSPCLK_TO_SCLKDIV(2822400, bps);
+ break;
+ case 16000: /* SCLK : 512KHZ */
+ i2s_alc5630_write(0x44, 0x3ea0, g_i2c_client); //?
+ i2s_alc5630_write(0x60, 0x3174, g_i2c_client);
+ i2s_alc5630_write(0x62, 0x1010, g_i2c_client);
+ fpclkdiv = 0x5f;
+ //fpclkdiv=SSPCLK_TO_SCLKDIV(4096000, bps);
+ break;
+ case 22050: /* SCLK : 705.6KHZ */
+ i2s_alc5630_write(0x44, 0x3ea0, g_i2c_client);
+ i2s_alc5630_write(0x60, 0x3174, g_i2c_client);
+ i2s_alc5630_write(0x62, 0x1010, g_i2c_client);
+ fpclkdiv = 0x45;
+ //fpclkdiv=SSPCLK_TO_SCLKDIV(5644800, bps);
+ break;
+ case 24000: /* SCLK : 768KHZ */
+ i2s_alc5630_write(0x44, 0x3ea0, g_i2c_client);
+ i2s_alc5630_write(0x60, 0x3174, g_i2c_client);
+ i2s_alc5630_write(0x62, 0x1010, g_i2c_client);
+ fpclkdiv = 0x3e;
+ //fpclkdiv=SSPCLK_TO_SCLKDIV(5644800, bps);
+ break;
+ case 32000: /* SCLK : 1024KHZ */
+ i2s_alc5630_write(0x44, 0x3ea0, g_i2c_client);
+ i2s_alc5630_write(0x60, 0x3174, g_i2c_client);
+ i2s_alc5630_write(0x62, 0x1010, g_i2c_client);
+ //fpclkdiv = 0x2e;
+ fpclkdiv = 0x2f;
+ //fpclkdiv=SSPCLK_TO_SCLKDIV(8192000, bps);
+ break;
+ case 44100: /* SCLK : 1.4112 MHZ */ /* 96 MHZ */
+ i2s_alc5630_write(0x44, 0x3ea0, g_i2c_client);
+ i2s_alc5630_write(0x60, 0x3174, g_i2c_client);
+ i2s_alc5630_write(0x62, 0x1010, g_i2c_client);
+ fpclkdiv = 0x22;
+ //fpclkdiv=SSPCLK_TO_SCLKDIV(11289600, bps);
+ break;
+ case 48000: /* SCLK : 1.536 MHZ */
+ i2s_alc5630_write(0x44, 0x3ea0, g_i2c_client);
+ i2s_alc5630_write(0x60, 0x3174, g_i2c_client);
+ i2s_alc5630_write(0x62, 0x1010, g_i2c_client);
+ fpclkdiv = 0x1f;
+ //fpclkdiv=SSPCLK_TO_SCLKDIV(12288000, bps);
+
+ break;
+ default:
+ printk("%s: unsupported speed %d\n", __func__,speed);
+ return;
+ };
+
+
+ if(!use8bit) {
+ outl(0xf0000|fpclkdiv, FTSSP010_CONTROL1(cardno)); /* 16bits */
+ //outl(0xf0000|0x10, FTSSP010_CONTROL1(cardno)); /* 16bits */
+ //outl(0xf0000|0x22, FTSSP010_CONTROL1(cardno)); /* 16bits */
+ } else {
+ outl(0x70000|fpclkdiv, FTSSP010_CONTROL1(cardno)); /* 8bits */
+ }
+
+ //printk("#####$$$$$ : bps = %d\n", bps);
+ //printk("#####$$$$$ : speed = %d\n", speed);
+ //printk("#####$$$$$ : fpclkdiv = 0x%08x\n", fpclkdiv);
+ //printk("#####$$$$$ : FTSSP010_CONTROL1(cardno) = 0x%08x\n", inl(FTSSP010_CONTROL1(cardno)));
+
+ if(is_rec)
+ outl(inl(FTSSP010_INT_CONTROL(cardno))&(~0x0f15), FTSSP010_INT_CONTROL(cardno)); /* Disable all interrupts */
+ else
+ outl(inl(FTSSP010_INT_CONTROL(cardno))&(~0xf02a) , FTSSP010_INT_CONTROL(cardno)); /* Disable all interrupts */
+
+ outl(0xc, FTSSP010_CONTROL2(cardno)); /* clear FIFOs */
+
+ //ADD by river 2011.06.02
+ alc5630 = i2c_get_clientdata(g_i2c_client);
+ //End
+
+ if(is_rec) {
+ printk("ftssp010_config() for I2S mode in record.\n");
+ //ADD by river 2011.03.21
+ //TEST by river 2011.03.22 for recording => workable
+ //i2s_alc5630_write(0x0e, 0x8888, g_i2c_client);
+ i2s_alc5630_write(0x0e, 0x0808, g_i2c_client);
+ i2s_alc5630_write(0x10, 0xee03, g_i2c_client);
+ i2s_alc5630_write(0x22, 0x0500, g_i2c_client);
+ i2s_alc5630_write(0x1c, 0x0748, g_i2c_client);
+ i2s_alc5630_write(0x14, 0x1f1f, g_i2c_client);
+ i2s_alc5630_write(0x12, 0xdfdf, g_i2c_client);
+
+ i2s_alc5630_write(0x26, 0x000f, g_i2c_client);
+ i2s_alc5630_write(0x3a, 0xffff, g_i2c_client);
+ i2s_alc5630_write(0x3c, 0xffff, g_i2c_client);
+ //i2s_alc5630_write(0x3e, 0xffff, g_i2c_client);
+ i2s_alc5630_write(0x3e, 0x80cf, g_i2c_client);
+
+ i2s_alc5630_write(0x44, 0x3ea0, g_i2c_client);
+ i2s_alc5630_write(0x42, 0x2000, g_i2c_client);
+ i2s_alc5630_write(0x40, 0x8c0a, g_i2c_client);
+
+ //i2s_alc5630_write(0x02, 0x0000, g_i2c_client);
+ i2s_alc5630_write(0x02, 0x8080, g_i2c_client);
+ i2s_alc5630_write(0x04, 0x0000, g_i2c_client);
+ //End TEST by river 2011.03.22
+
+ //printk("ftssp010_config() for I2S mode (Recording) ===> Dump register.\n");
+ //i2s_alc5630_read_test(g_i2c_client);
+
+ }
+ else {
+ //printk("ftssp010_config() for I2S mode in playback.\n");
+ //ADD by river 2011.03.24 for record and playback case
+ i2s_alc5630_write(0x0e, 0x0808, g_i2c_client);
+ i2s_alc5630_write(0x12, 0xcbcb, g_i2c_client);
+ i2s_alc5630_write(0x14, 0x7f7f, g_i2c_client);
+ i2s_alc5630_write(0x22, 0x0000, g_i2c_client);
+ i2s_alc5630_write(0x3e, 0x8000, g_i2c_client);
+ i2s_alc5630_write(0x40, 0x0c0a, g_i2c_client);
+ i2s_alc5630_write(0x42, 0x0000, g_i2c_client);
+ //End ADD by river 2011.03.24 for record and playback case
+
+ //TEST by river 2011.03.23
+ i2s_alc5630_write(0x26, 0x0000, g_i2c_client);
+ i2s_alc5630_write(0x3c, 0x2000, g_i2c_client);
+ i2s_alc5630_write(0x3a, 0x0002, g_i2c_client);
+ i2s_alc5630_write(0x3c, 0xa330, g_i2c_client);
+ i2s_alc5630_write(0x3a, 0xc843, g_i2c_client);
+ //End TEST by river 2011.03.23
+
+ //ADD by river 2011.03.23 for HP Out De-pop
+ i2s_alc5630_write(0x3A, i2s_alc5630_read(0x3A, data,g_i2c_client)|0x0002 , g_i2c_client);
+ i2s_alc5630_write(0x04, i2s_alc5630_read(0x04, data,g_i2c_client)|0x8080 , g_i2c_client);
+ i2s_alc5630_write(0x3A, i2s_alc5630_read(0x3A, data,g_i2c_client)|0x0040 , g_i2c_client);
+ i2s_alc5630_write(0x3c, i2s_alc5630_read(0x3C, data,g_i2c_client)|0x2000 , g_i2c_client);
+ i2s_alc5630_write(0x3E, i2s_alc5630_read(0x3E, data,g_i2c_client)|0xfC00 , g_i2c_client);
+ i2s_alc5630_write(0x5E, i2s_alc5630_read(0x5E, data,g_i2c_client)|0x0100 , g_i2c_client);
+ mdelay(500);
+ i2s_alc5630_write(0x3A, i2s_alc5630_read(0x3A, data,g_i2c_client)|0x0200 , g_i2c_client);
+ i2s_alc5630_write(0x3A, i2s_alc5630_read(0x3A, data,g_i2c_client)|0x0100 , g_i2c_client);
+ i2s_alc5630_write(0x5E, i2s_alc5630_read(0x5E, data,g_i2c_client)& 0xfeff ,g_i2c_client);
+ //End ADD by river 2011.03.23 for HP Out De-pop
+
+
+ //TEST by river 2011.03.22
+ i2s_alc5630_write(0x1c, 0x0748, g_i2c_client);
+ //End TEST by river 2011.03.22
+
+
+ //TEST by river 2011.03.16
+ //i2s_alc5630_write(0x02, 0x8080, g_i2c_client);
+ i2s_alc5630_write(0x26, 0x000f, g_i2c_client);
+ //End TEST by river 2011.03.16
+
+ //ADD by river 2011.03.23
+ if (alc5630->gpio2_value==0x0)
+ i2s_alc5630_write(0x3A, (i2s_alc5630_read(0x3A, data,g_i2c_client) & 0xFBFF)|0x0040 , g_i2c_client);
+ else
+ i2s_alc5630_write(0x3A, i2s_alc5630_read(0x3A, data,g_i2c_client)|0x0440 , g_i2c_client);
+
+
+ i2s_alc5630_write(0x5E, i2s_alc5630_read(0x5E, data,g_i2c_client)|0x0020 , g_i2c_client);
+ i2s_alc5630_write(0x5E, i2s_alc5630_read(0x5E, data,g_i2c_client)|0x00c0 , g_i2c_client);
+ i2s_alc5630_write(0x04, i2s_alc5630_read(0x04, data,g_i2c_client)& 0x7f7f , g_i2c_client);
+ mdelay(30);
+
+ if (alc5630->gpio2_value==0x0) {
+ //printk(">>>>>>>>>>>> Turn off internal speaker.....\n");
+ i2s_alc5630_write(0x02, 0x5F5F, g_i2c_client);
+ //i2s_alc5630_write(0x02, 0x0000, g_i2c_client);
+ }
+ else {
+ //printk(">>>>>>>>>>>> Turn on internal speaker.....\n");
+ i2s_alc5630_write(0x02, 0x0000, g_i2c_client);
+ //i2s_alc5630_write(0x02, 0x5F5F, g_i2c_client);
+ }
+ //End ADD by river 2011.03.23
+
+
+ //printk("ftssp010_config() for I2S mode (Playback) ===> Dump register.\n");
+ //i2s_alc5630_read_test(g_i2c_client);
+ }
+
+#if 0
+ /* Stuff TX fifo */
+ while(ftssp010_tx_fifo_not_full(cardno)) {
+ outl(0x0, FTSSP010_DATA(cardno));
+ }
+#endif
+}
+
+void ftssp010_config_tx(int cardno, unsigned is_stereo, unsigned speed, int width)
+{
+ return ftssp010_config(cardno, is_stereo, speed, width, 0);
+}
+
+void ftssp010_config_rx(int cardno, unsigned is_stereo, unsigned speed, int width)
+{
+ return ftssp010_config(cardno, is_stereo, speed, width, 1);
+}
+
+/* Configures FTSSP010 to start TX. If use_dma being nonzero,
+ * FTSSP010 will use hardware handshake for DMA */
+void ftssp010_start_tx(int cardno, unsigned use_dma)
+{
+ unsigned bogus=0x800*3;
+ if(use_dma) {
+ /* Enable H/W DMA Request and set TX DMA threshold to 12*/
+// outl(0xC022, FTSSP010_INT_CONTROL(cardno));
+ outl(inl(FTSSP010_INT_CONTROL(cardno)) | 0xc422, FTSSP010_INT_CONTROL(cardno));
+#if 0
+ printk("%s: enable DMA request\n", __func__);
+#endif
+ }
+// outl(0x3, FTSSP010_CONTROL2(cardno));
+ outl(inl(FTSSP010_CONTROL2(cardno)) | 0x3, FTSSP010_CONTROL2(cardno));
+// printk("%s\n",__func__);
+// printk("int_control 0x%x\n",inl(FTSSP010_INT_CONTROL(cardno)));
+// printk("control2 0x%x\n",inl(FTSSP010_CONTROL2(cardno)));
+ if(!use_dma) {
+ while(bogus>0) {
+ while(!ftssp010_tx_fifo_not_full(cardno))
+ udelay(50);
+ outl(0, FTSSP010_DATA(cardno));
+ bogus--;
+ }
+ }
+}
+
+/* Configures FTSSP010 to start RX. If use_dma being nonzero,
+ * FTSSP010 will use hardware handshake for DMA */
+void ftssp010_start_rx(int cardno, unsigned use_dma)
+{
+ if(use_dma) {
+ /* Enable H/W DMA Request and set RX DMA threshold to 2*/
+// outl(0x0111, FTSSP010_INT_CONTROL(cardno));
+ outl(inl(FTSSP010_INT_CONTROL(cardno)) | 0xc411, FTSSP010_INT_CONTROL(cardno));
+#if 0
+ printk("%s: enable DMA request\n", __func__);
+#endif
+ }
+// outl(0x3, FTSSP010_CONTROL2(cardno));
+ outl(inl(FTSSP010_CONTROL2(cardno)) | 0x3, FTSSP010_CONTROL2(cardno));
+// printk("%s\n",__func__);
+// printk("int_control 0x%x\n",inl(FTSSP010_INT_CONTROL(cardno)));
+// printk("control2 0x%x\n",inl(FTSSP010_CONTROL2(cardno)));
+}
+
+void ftssp010_stop_tx(int cardno)
+{
+// outl(0, FTSSP010_CONTROL2(cardno));
+ outl(inl(FTSSP010_INT_CONTROL(cardno)) & (~0x22), FTSSP010_INT_CONTROL(cardno));
+// printk("%s\n",__func__);
+// printk("int_control 0x%x\n",inl(FTSSP010_INT_CONTROL(cardno)));
+// printk("control2 0x%x\n",inl(FTSSP010_CONTROL2(cardno)));
+}
+
+void ftssp010_stop_rx(int cardno)
+{
+ //outl(0, FTSSP010_CONTROL2(cardno));
+ outl(inl(FTSSP010_INT_CONTROL(cardno)) & (~0x11), FTSSP010_INT_CONTROL(cardno));
+ //printk("%s\n",__func__);
+ //printk("int_control 0x%x\n",inl(FTSSP010_INT_CONTROL(cardno)));
+ //printk("control2 0x%x\n",inl(FTSSP010_CONTROL2(cardno)));
+}
+
diff -Nur linux-3.4.113.orig/sound/nds32/FTSSP010_UDA1345TS.h linux-3.4.113/sound/nds32/FTSSP010_UDA1345TS.h
--- linux-3.4.113.orig/sound/nds32/FTSSP010_UDA1345TS.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/sound/nds32/FTSSP010_UDA1345TS.h 2016-12-01 20:59:24.396614447 +0100
@@ -0,0 +1,81 @@
+/* FTSSP010 - UDA1345TS supporting library header */
+/*
+ *
+ * $log$
+ *
+ */
+#include <linux/init.h>
+#include <linux/module.h>
+#include <asm/io.h>
+#include <linux/delay.h>
+#include <asm/spec.h>
+#include <linux/dma-mapping.h>
+
+/* Programming sequence:
+ * Suppose your playback format is 44.1KHz, 16 bit stereo
+ * PIO mode:
+ * pmu_set_i2s_clocking(44100);
+ * ftssp010_config(1, 44100, 0);
+ * ftssp010_start_tx(0);
+ * while(ftssp010_tx_fifo_not_full()) {
+ * Poke_your_PCM_data_to_FTSSP_data_port
+ *
+ * DMA mode:
+ * pmu_set_i2s_clocking(44100);
+ * ftssp010_config(1, 44100);
+ * <setup DMA controller, acquire DMA channel>
+ * pmu_set_i2s_dma_channel(ch);
+ * ftssp010_start_tx(1);
+ * <wait DMA to complete..>
+ * ftssp010_stop_tx();
+ */
+#define FTSSP010_DATA(x) (SSP_FTSSP010_va_base[(x)]+0x18)
+#define FTSSP010_DATA_PA(x) (SSP_FTSSP010_pa_base[(x)]+0x18)
+
+/* Initialize FTSSP010 to output to UDA1345TS via I2S */
+#define FTSSP010_CONTROL0(x) (SSP_FTSSP010_va_base[(x)]+0x0)
+#define FTSSP010_CONTROL0_OPM_STEREO 0xC
+#define FTSSP010_CONTROL0_OPM_MONO 0x8
+
+#define FTSSP010_CONTROL1(x) (SSP_FTSSP010_va_base[(x)]+0x4)
+#define FTSSP010_CONTROL2(x) (SSP_FTSSP010_va_base[(x)]+0x8)
+
+#define FTSSP010_INT_CONTROL(x) (SSP_FTSSP010_va_base[(x)]+0x10)
+#define FTSSP010_STATUS(x) (SSP_FTSSP010_va_base[(x)]+0xC)
+#define FTSSP010_INT_STATUS(x) (SSP_FTSSP010_va_base[(x)]+0x14)
+#define FTSSP010_DATA(x) (SSP_FTSSP010_va_base[(x)]+0x18)
+#define FTSSP010_INFO(x) (SSP_FTSSP010_va_base[(x)]+0x1C)
+
+static const unsigned int SSP_FTSSP010_va_base[SSP_FTSSP010_IRQ_COUNT] = { SSP_FTSSP010_VA_BASE };
+static const unsigned int SSP_FTSSP010_pa_base[SSP_FTSSP010_IRQ_COUNT] = { SSP_FTSSP010_PA_BASE };
+
+/* Drive PMU to generate I2S main clocking signal. Also configures PMU to set correct DMA REQ/ACK pair */
+extern void pmu_set_i2s_clocking(unsigned int speed);
+/* Programs PMU to set I2S/AC97 DMA Channel, ch=0-7 */
+extern void pmu_set_i2s_dma_channel(unsigned ch);
+
+/* Drive PMU to generate AC97 main clocking signal. Also configures PMU to set correct DMA REQ/ACK pair */
+extern void pmu_set_ac97_clocking(unsigned int speed);
+
+/* Returns FTSSP010 status */
+extern void ftssp010_set_int_control(int cardno, unsigned val);
+extern int ftssp010_get_status(int cardno);
+extern unsigned ftssp010_get_int_status(int cardno);
+/* Polls FIFO full register */
+extern int ftssp010_tx_fifo_not_full(int cardno);
+/* Configure FTSSP010 to a given sampling rate and channel number */
+extern void ftssp010_config_tx(int cardno, unsigned is_stereo, unsigned speed, int use8bit);
+extern void ftssp010_config_rx(int cardno, unsigned is_stereo, unsigned speed, int use8bit);
+
+/* Configure FTSSP010 to a given sampling rate and channel number */
+extern void ftssp010_config_ac97_play(int cardno, unsigned is_stereo, unsigned speed, int use8bit);
+
+extern void ftssp010_config_ac97_rec(int cardno, unsigned is_stereo, unsigned speed, int use8bit);
+
+/* Initialize FTSSP010 to output to UDA1345TS via I2S */
+extern void ftssp010_start_tx(int cardno, unsigned use_dma);
+extern void ftssp010_start_rx(int cardno, unsigned use_dma);
+extern void ftssp010_stop_tx(int cardno);
+extern void ftssp010_stop_rx(int cardno);
+
+
diff -Nur linux-3.4.113.orig/sound/nds32/FTSSP010_W83972D.h linux-3.4.113/sound/nds32/FTSSP010_W83972D.h
--- linux-3.4.113.orig/sound/nds32/FTSSP010_W83972D.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/sound/nds32/FTSSP010_W83972D.h 2016-12-01 20:59:24.396614447 +0100
@@ -0,0 +1,17 @@
+/* AC97 Codec related */
+
+
+/* Register Index for Winbond W83972D AC97 Codec */
+#define W83972D_RESET 0x0
+#define W83972D_STEREO_OUTPUT_CONTROL 0x2
+#define W83972D_MIC_VOLUME 0xE
+#define W83972D_LINE_IN_VOLUME 0x10
+#define W83972D_AUX_INPUT_CONTROL 0x16
+#define W83972D_PCM_OUTPUT_CONTROL 0x18
+#define W83972D_RECORD_SELECT 0x1A
+#define W83972D_RECORD_GAIN 0x1C
+#define W83972D_RECORD_GAIN_MIC 0x1E
+#define W83972D_EXT_AUDIO_CONTROL 0x2A
+#define W83972D_DAC_SAMPLE_RATE_CONTROL 0x2C
+#define W83972D_VER1 0x7C
+#define W83972D_VER2 0x7E
diff -Nur linux-3.4.113.orig/sound/nds32/hda.h linux-3.4.113/sound/nds32/hda.h
--- linux-3.4.113.orig/sound/nds32/hda.h 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/sound/nds32/hda.h 2016-12-01 20:59:24.396614447 +0100
@@ -0,0 +1,106 @@
+// HDA Mode definition
+ #define HDA_MODE 0x80000000
+
+ // HDA CTRL definition
+ #define HDA_CRST_SET 0x00
+ #define HDA_CRST_CLR 0x20
+ #define HDA_CRST_MASK 0x20
+ #define HDA_RST_FCNT_OFS 8
+
+ // HDA LNKST definition
+ #define HDA_COD_ALIVE 0x20000000
+
+ // HDA INTC definition
+ #define HDA_INTC_USOLEN 0x40000
+ #define HDA_INTC_SDIWEN 0x20000
+ #define HDA_INTC_CRINTE 0x10000
+
+ // HDA INTST definition
+ #define HDA_INTST_USOLEN 0x80
+ #define HDA_INTST_SDIWEN 0x40
+ #define HDA_INTST_CRINTE 0x20
+
+ // HDA ICMDST mask & offset
+ #define HDA_IRRADD_MASK 0xf0
+ #define HDA_IRRUNSOL_MASK 0x08
+ #define HDA_IRV_MASK 0x02
+ #define HDA_ICB_MASK 0x01
+ #define HDA_IRRADD_OFFSET 4
+ #define HDA_IRRUNSOL_OFFSET 3
+ #define HDA_IRV_OFFSET 1
+ #define HDA_ICB_OFFSET 0
+ //HDA OSDC/ISDC bit offset
+ #define HDA_SDC_STNUM_OFFSET 28
+ #define HDA_SDC_SRUN_OFFSET 15
+ #define HDA_SDC_BASE_OFFSET 14
+ #define HDA_SDC_MULT_OFFSET 11
+ #define HDA_SDC_DIV_OFFSET 8
+ #define HDA_SDC_BITS_OFFSET 4
+ #define HDA_SDC_CHAN_OFFSET 0
+
+ // HDA Codec CMD
+ #define HDA_COD_DEVADDR 0x00000000
+ #define HDA_ROOT_NODE 0x00000000
+ #define HDA_AUDIO_NODE 0x00100000
+ #define HDA_OUTCOV_NODE 0x00200000
+ //#define HDA_INCOV_NODE 0x0FF00000
+ #define HDA_INCOV_NODE 0x00800000 //kane, for real CODEC node mapping
+ #define HDA_CMD_FGRST 0x0007FF00
+ #define HDA_CMD_GETVID 0x000F0000
+ #define HDA_CMD_SUBNCNT 0x000F0004
+ #define HDA_CMD_FGTYPE 0x000F0005
+ #define HDA_CMD_AUDIOWCAP 0x000F0009
+ #define HDA_CMD_SETCVTSTR 0x00070600
+ #define HDA_CMD_GETCVTSTR 0x000F0600
+ #define HDA_CMD_SETCVTFMT 0x00020000
+ #define HDA_CMD_GETCVTFMT 0x000A0000
+ #define HDA_CMD_SETPROCST 0x00070300
+ #define HDA_CMD_TRIGUNSOL 0x00070400
+ //HDA Codec Resp
+ #define HDA_RESP_ZERO_VAL 0x00000000
+ #define HDA_RESP_EXP_VID 0x10ec0888
+ #define HDA_RSP_NODNUM_MSK 0xff0000
+ #define HDA_RSP_NODCNT_MSK 0x0000ff
+ #define HDA_RSP_NODNUM_OFS 16
+ #define HDA_RSP_NODCNT_OFS 0
+ #define HDA_RSP_FGNTYPE_MSK 0xff
+ #define HDA_RSP_FGNUSCAP_MSK 0x100
+ #define HDA_RSP_FGNTYPE_OFS 0
+ #define HDA_RSP_FGNUSCAP_OFS 8
+ #define HDA_RSP_AWCTYPE_MSK 0xf00000
+ #define HDA_RSP_AWCUSCAP_MSK 0x000080
+ #define HDA_RSP_AWCSTE_MSK 0x000001
+ #define HDA_RSP_AWCTYPE_OFS 20
+ #define HDA_RSP_AWCUSCAP_OFS 7
+ #define HDA_RSP_AWCSTE_OFS 0
+ #define HDA_RSP_CVTCHA_MSK 0x00
+ #define HDA_RSP_CVTSTR_MSK 0xf0
+ #define HDA_RSP_FMTTYPE_MSK 0x8000
+ #define HDA_RSP_FMTBASE_MSK 0x4000
+ #define HDA_RSP_FMTMULT_MSK 0x3800
+ #define HDA_RSP_FMTDIV_MSK 0x0700
+ #define HDA_RSP_FMTBITS_MSK 0x0070
+ #define HDA_RSP_FMTCHNUM_MSK 0x000f
+ //HDA Func Group definition
+ #define HDA_FG_AUDIO 0x1
+ // HDA Audio Widiget definition
+ #define HDA_AWC_INPUT 0x1
+ #define HDA_AWC_OUTPUT 0x0
+ #define HDA_AWC_MONO 0x0
+ #define HDA_AWC_STEREO 0x1
+ // HDA Converter Format definition
+ #define HDA_FMT_TYPE_OFS 15
+ #define HDA_FMT_BASE_OFS 14
+ #define HDA_FMT_MULT_OFS 11
+ #define HDA_FMT_DIV_OFS 8
+ #define HDA_FMT_BITS_OFS 4
+ #define HDA_FMT_CHNUM_OFS 0
+ // HDA Coverter Stream definition
+ #define HDA_STR_STR_OFS 4
+ #define HDA_STR_CHA_OFS 0
+ // HDA IOSDC definition
+ #define HDA_IN_STR 0
+ #define HDA_OUT_STR 1
+ #define HDA_STR_STOP 0
+ #define HDA_STR_RUN 1
+
diff -Nur linux-3.4.113.orig/sound/nds32/Kconfig linux-3.4.113/sound/nds32/Kconfig
--- linux-3.4.113.orig/sound/nds32/Kconfig 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/sound/nds32/Kconfig 2016-12-01 20:59:24.396614447 +0100
@@ -0,0 +1,22 @@
+menu "ALSA NDS32 devices"
+ depends on SND!=n && NDS32
+
+config SND_FTSSP010
+ tristate "Faraday FTSSP010 audio Driver"
+ depends on SND && NDS32
+ select SND_PCM
+# select SND_AC97_CODEC
+
+choice
+ prompt "AC97/I2S/HDA selection"
+ depends on SND_FTSSP010
+ default SND_FTSSP010_AC97
+config SND_FTSSP010_AC97
+ bool "AC97"
+config SND_FTSSP010_I2S
+ bool "I2S"
+config SND_FTSSP010_HDA
+ bool "HDA"
+endchoice
+endmenu
+
diff -Nur linux-3.4.113.orig/sound/nds32/Makefile linux-3.4.113/sound/nds32/Makefile
--- linux-3.4.113.orig/sound/nds32/Makefile 1970-01-01 01:00:00.000000000 +0100
+++ linux-3.4.113/sound/nds32/Makefile 2016-12-01 20:59:24.396614447 +0100
@@ -0,0 +1,10 @@
+ifeq ($(CONFIG_SND_FTSSP010_AC97),y)
+snd-ftssp010-objs := FTSSP010_ALSA.o FTSSP010_lib.o
+endif
+ifeq ($(CONFIG_SND_FTSSP010_I2S),y)
+snd-ftssp010-objs := FTSSP010_ALSA.o FTSSP010_lib.o
+endif
+ifeq ($(CONFIG_SND_FTSSP010_HDA),y)
+snd-ftssp010-objs := FTSSP010_HDA.o FTSSP010_HDA_lib.o
+endif
+obj-$(CONFIG_SND_FTSSP010) += snd-ftssp010.o
diff -Nur linux-3.4.113.orig/arch/nds32/include/asm/sigcontext.h linux-3.4.113/arch/nds32/include/asm/sigcontext.h
--- linux-3.4.113.orig/arch/nds32/include/asm/sigcontext.h 2016-12-04 19:56:12.061027027 +0100
+++ linux-3.4.113/arch/nds32/include/asm/sigcontext.h 2016-12-04 19:56:45.122305938 +0100
@@ -59,7 +59,7 @@
unsigned long nds32_r25;
unsigned long nds32_fp; /* $r28 */
unsigned long nds32_gp; /* $r29 */
- unsigned long nds32_lr; /* $r30 */
+ unsigned long nds32_lp; /* $r30 */
unsigned long nds32_sp; /* $r31 */
unsigned long nds32_ipc;
unsigned long fault_address;
|