~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/arch/sparc/kernel/pcic.c

Version: ~ [ linux-5.8-rc4 ] ~ [ linux-5.7.7 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.50 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.131 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.187 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.229 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.229 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.19.8 ] ~ [ linux-3.18.140 ] ~ [ linux-3.17.8 ] ~ [ linux-3.16.85 ] ~ [ linux-3.15.10 ] ~ [ linux-3.14.79 ] ~ [ linux-3.13.11 ] ~ [ linux-3.12.74 ] ~ [ linux-3.11.10 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /arch/sparc/kernel/pcic.c (Version linux-3.12.74) and /arch/m68k/kernel/pcic.c (Version linux-4.5.7)


  1 /*                                                  1 
  2  * pcic.c: MicroSPARC-IIep PCI controller supp    
  3  *                                                
  4  * Copyright (C) 1998 V. Roganov and G. Raiko     
  5  *                                                
  6  * Code is derived from Ultra/PCI PSYCHO contr    
  7  * for author info.                               
  8  *                                                
  9  * Support for diverse IIep based platforms by    
 10  * CP-1200 by Eric Brower.                        
 11  */                                               
 12                                                   
 13 #include <linux/kernel.h>                         
 14 #include <linux/types.h>                          
 15 #include <linux/init.h>                           
 16 #include <linux/mm.h>                             
 17 #include <linux/slab.h>                           
 18 #include <linux/jiffies.h>                        
 19                                                   
 20 #include <asm/swift.h> /* for cache flushing.     
 21 #include <asm/io.h>                               
 22                                                   
 23 #include <linux/ctype.h>                          
 24 #include <linux/pci.h>                            
 25 #include <linux/time.h>                           
 26 #include <linux/timex.h>                          
 27 #include <linux/interrupt.h>                      
 28 #include <linux/export.h>                         
 29                                                   
 30 #include <asm/irq.h>                              
 31 #include <asm/oplib.h>                            
 32 #include <asm/prom.h>                             
 33 #include <asm/pcic.h>                             
 34 #include <asm/timex.h>                            
 35 #include <asm/timer.h>                            
 36 #include <asm/uaccess.h>                          
 37 #include <asm/irq_regs.h>                         
 38                                                   
 39 #include "irq.h"                                  
 40                                                   
 41 /*                                                
 42  * I studied different documents and many live    
 43  * family and 3.xx versions. I came to the ama    
 44  * absolutely no way to route interrupts in II    
 45  * information which PROM presents. We must ha    
 46  * schematics. And this actually sucks.   -- z    
 47  *                                                
 48  * To find irq for a device we determine which    
 49  * is in effect or, in other words, on which m    
 50  * We use PROM name for this although other te    
 51  * in special cases (Gleb reports a PROMless I    
 52  * Once we know the map we take device configu    
 53  * find PCIC pin number where INT line goes. T    
 54  * preferred irq into the PCIC or supply the p    
 55  */                                               
 56 struct pcic_ca2irq {                              
 57         unsigned char busno;            /* PCI    
 58         unsigned char devfn;            /* Con    
 59         unsigned char pin;              /* PCI    
 60         unsigned char irq;              /* Pre    
 61         unsigned int force;             /* Enf    
 62 };                                                
 63                                                   
 64 struct pcic_sn2list {                             
 65         char *sysname;                            
 66         struct pcic_ca2irq *intmap;               
 67         int mapdim;                               
 68 };                                                
 69                                                   
 70 /*                                                
 71  * JavaEngine-1 apparently has different versi    
 72  *                                                
 73  * According to communications with Sun folks,    
 74  * pin 0 - parallel, audio;                       
 75  * pin 1 - Ethernet;                              
 76  * pin 2 - su;                                    
 77  * pin 3 - PS/2 kbd and mouse.                    
 78  *                                                
 79  * OEM manual (805-1486):                         
 80  * pin 0: Ethernet                                
 81  * pin 1: All EBus                                
 82  * pin 2: IGA (unused)                            
 83  * pin 3: Not connected                           
 84  * OEM manual says that 501-4628 & 501-4811 ar    
 85  * only the latter has NAND flash in place.       
 86  *                                                
 87  * So far unofficial Sun wins over the OEM man    
 88  */                                               
 89 static struct pcic_ca2irq pcic_i_je1a[] = {       
 90         { 0, 0x00, 2, 12, 0 },          /* EBu    
 91         { 0, 0x01, 1,  6, 1 },          /* Hap    
 92         { 0, 0x80, 0,  7, 0 },          /* IGA    
 93 };                                                
 94                                                   
 95 /* XXX JS-E entry is incomplete - PCI Slot 2 a    
 96 static struct pcic_ca2irq pcic_i_jse[] = {        
 97         { 0, 0x00, 0, 13, 0 },          /* Ebu    
 98         { 0, 0x01, 1,  6, 0 },          /* hme    
 99         { 0, 0x08, 2,  9, 0 },          /* VGA    
100         { 0, 0x10, 6,  8, 0 },          /* PCI    
101         { 0, 0x18, 7, 12, 0 },          /* PCI    
102         { 0, 0x38, 4,  9, 0 },          /* All    
103         { 0, 0x80, 5, 11, 0 },          /* EID    
104         /* {0,0x88, 0,0,0} - unknown device...    
105         { 0, 0xA0, 4,  9, 0 },          /* USB    
106         /*                                        
107          * Some pins belong to non-PCI devices    
108          * sun4m timers - irq 10, 14              
109          * PC style RTC - pin 7, irq 4 ?          
110          * Smart card, Parallel - pin 4 shared    
111          * audio - pin 3, irq 5 ?                 
112          */                                       
113 };                                                
114                                                   
115 /* SPARCengine-6 was the original release name    
116  * The documentation differs between the two v    
117  */                                               
118 static struct pcic_ca2irq pcic_i_se6[] = {        
119         { 0, 0x08, 0,  2, 0 },          /* SCS    
120         { 0, 0x01, 1,  6, 0 },          /* HME    
121         { 0, 0x00, 3, 13, 0 },          /* EBu    
122 };                                                
123                                                   
124 /*                                                
125  * Krups (courtesy of Varol Kaptan)               
126  * No documentation available, but it was easy    
127  * because it was very similar to Espresso.       
128  *                                                
129  * pin 0 - kbd, mouse, serial;                    
130  * pin 1 - Ethernet;                              
131  * pin 2 - igs (we do not use it);                
132  * pin 3 - audio;                                 
133  * pin 4,5,6 - unused;                            
134  * pin 7 - RTC (from P2 onwards as David B. sa    
135  */                                               
136 static struct pcic_ca2irq pcic_i_jk[] = {         
137         { 0, 0x00, 0, 13, 0 },          /* Ebu    
138         { 0, 0x01, 1,  6, 0 },          /* hme    
139 };                                                
140                                                   
141 /*                                                
142  * Several entries in this list may point to t    
143  * as several PROMs may be installed on the sa    
144  */                                               
145 #define SN2L_INIT(name, map)    \                 
146   { name, map, ARRAY_SIZE(map) }                  
147                                                   
148 static struct pcic_sn2list pcic_known_sysnames    
149         SN2L_INIT("SUNW,JavaEngine1", pcic_i_j    
150         SN2L_INIT("SUNW,JS-E", pcic_i_jse),       
151         SN2L_INIT("SUNW,SPARCengine-6", pcic_i    
152         SN2L_INIT("SUNW,JS-NC", pcic_i_jk),       
153         SN2L_INIT("SUNW,JSIIep", pcic_i_jk),      
154         { NULL, NULL, 0 }                         
155 };                                                
156                                                   
157 /*                                                
158  * Only one PCIC per IIep,                        
159  * and since we have no SMP IIep, only one per    
160  */                                               
161 static int pcic0_up;                              
162 static struct linux_pcic pcic0;                   
163                                                   
164 void __iomem *pcic_regs;                          
165 volatile int pcic_speculative;                    
166 volatile int pcic_trapped;                        
167                                                   
168 /* forward */                                     
169 unsigned int pcic_build_device_irq(struct plat    
170                                    unsigned in    
171                                                   
172 #define CONFIG_CMD(bus, device_fn, where) (0x8    
173                                                   
174 static int pcic_read_config_dword(unsigned int    
175     int where, u32 *value)                        
176 {                                                 
177         struct linux_pcic *pcic;                  
178         unsigned long flags;                      
179                                                   
180         pcic = &pcic0;                            
181                                                   
182         local_irq_save(flags);                    
183 #if 0 /* does not fail here */                    
184         pcic_speculative = 1;                     
185         pcic_trapped = 0;                         
186 #endif                                            
187         writel(CONFIG_CMD(busno, devfn, where)    
188 #if 0 /* does not fail here */                    
189         nop();                                    
190         if (pcic_trapped) {                       
191                 local_irq_restore(flags);         
192                 *value = ~0;                      
193                 return 0;                         
194         }                                         
195 #endif                                            
196         pcic_speculative = 2;                     
197         pcic_trapped = 0;                         
198         *value = readl(pcic->pcic_config_space    
199         nop();                                    
200         if (pcic_trapped) {                       
201                 pcic_speculative = 0;             
202                 local_irq_restore(flags);         
203                 *value = ~0;                      
204                 return 0;                         
205         }                                         
206         pcic_speculative = 0;                     
207         local_irq_restore(flags);                 
208         return 0;                                 
209 }                                                 
210                                                   
211 static int pcic_read_config(struct pci_bus *bu    
212    int where, int size, u32 *val)                 
213 {                                                 
214         unsigned int v;                           
215                                                   
216         if (bus->number != 0) return -EINVAL;     
217         switch (size) {                           
218         case 1:                                   
219                 pcic_read_config_dword(bus->nu    
220                 *val = 0xff & (v >> (8*(where     
221                 return 0;                         
222         case 2:                                   
223                 if (where&1) return -EINVAL;      
224                 pcic_read_config_dword(bus->nu    
225                 *val = 0xffff & (v >> (8*(wher    
226                 return 0;                         
227         case 4:                                   
228                 if (where&3) return -EINVAL;      
229                 pcic_read_config_dword(bus->nu    
230                 return 0;                         
231         }                                         
232         return -EINVAL;                           
233 }                                                 
234                                                   
235 static int pcic_write_config_dword(unsigned in    
236     int where, u32 value)                         
237 {                                                 
238         struct linux_pcic *pcic;                  
239         unsigned long flags;                      
240                                                   
241         pcic = &pcic0;                            
242                                                   
243         local_irq_save(flags);                    
244         writel(CONFIG_CMD(busno, devfn, where)    
245         writel(value, pcic->pcic_config_space_    
246         local_irq_restore(flags);                 
247         return 0;                                 
248 }                                                 
249                                                   
250 static int pcic_write_config(struct pci_bus *b    
251    int where, int size, u32 val)                  
252 {                                                 
253         unsigned int v;                           
254                                                   
255         if (bus->number != 0) return -EINVAL;     
256         switch (size) {                           
257         case 1:                                   
258                 pcic_read_config_dword(bus->nu    
259                 v = (v & ~(0xff << (8*(where&3    
260                     ((0xff&val) << (8*(where&3    
261                 return pcic_write_config_dword    
262         case 2:                                   
263                 if (where&1) return -EINVAL;      
264                 pcic_read_config_dword(bus->nu    
265                 v = (v & ~(0xffff << (8*(where    
266                     ((0xffff&val) << (8*(where    
267                 return pcic_write_config_dword    
268         case 4:                                   
269                 if (where&3) return -EINVAL;      
270                 return pcic_write_config_dword    
271         }                                         
272         return -EINVAL;                           
273 }                                                 
274                                                   
275 static struct pci_ops pcic_ops = {                
276         .read =         pcic_read_config,         
277         .write =        pcic_write_config,        
278 };                                                
279                                                   
280 /*                                                
281  * On sparc64 pcibios_init() calls pci_control    
282  * We want PCIC probed little ahead so that in    
283  * would be operational.                          
284  */                                               
285 int __init pcic_probe(void)                       
286 {                                                 
287         struct linux_pcic *pcic;                  
288         struct linux_prom_registers regs[PROMR    
289         struct linux_pbm_info* pbm;               
290         char namebuf[64];                         
291         phandle node;                             
292         int err;                                  
293                                                   
294         if (pcic0_up) {                           
295                 prom_printf("PCIC: called twic    
296                 prom_halt();                      
297         }                                         
298         pcic = &pcic0;                            
299                                                   
300         node = prom_getchild (prom_root_node);    
301         node = prom_searchsiblings (node, "pci    
302         if (node == 0)                            
303                 return -ENODEV;                   
304         /*                                        
305          * Map in PCIC register set, config sp    
306          */                                       
307         err = prom_getproperty(node, "reg", (c    
308         if (err == 0 || err == -1) {              
309                 prom_printf("PCIC: Error, cann    
310                             "from PROM.\n");      
311                 prom_halt();                      
312         }                                         
313                                                   
314         pcic0_up = 1;                             
315                                                   
316         pcic->pcic_res_regs.name = "pcic_regis    
317         pcic->pcic_regs = ioremap(regs[0].phys    
318         if (!pcic->pcic_regs) {                   
319                 prom_printf("PCIC: Error, cann    
320                 prom_halt();                      
321         }                                         
322                                                   
323         pcic->pcic_res_io.name = "pcic_io";       
324         if ((pcic->pcic_io = (unsigned long)      
325             ioremap(regs[1].phys_addr, 0x10000    
326                 prom_printf("PCIC: Error, cann    
327                 prom_halt();                      
328         }                                         
329                                                   
330         pcic->pcic_res_cfg_addr.name = "pcic_c    
331         if ((pcic->pcic_config_space_addr =       
332             ioremap(regs[2].phys_addr, regs[2]    
333                 prom_printf("PCIC: Error, cann    
334                             "PCI Configuration    
335                 prom_halt();                      
336         }                                         
337                                                   
338         /*                                        
339          * Docs say three least significant bi    
340          * must be the same. Thus, we need adj    
341          */                                       
342         pcic->pcic_res_cfg_data.name = "pcic_c    
343         if ((pcic->pcic_config_space_data =       
344             ioremap(regs[3].phys_addr, regs[3]    
345                 prom_printf("PCIC: Error, cann    
346                             "PCI Configuration    
347                 prom_halt();                      
348         }                                         
349                                                   
350         pbm = &pcic->pbm;                         
351         pbm->prom_node = node;                    
352         prom_getstring(node, "name", namebuf,     
353         strcpy(pbm->prom_name, namebuf);          
354                                                   
355         {                                         
356                 extern volatile int t_nmi[4];     
357                 extern int pcic_nmi_trap_patch    
358                                                   
359                 t_nmi[0] = pcic_nmi_trap_patch    
360                 t_nmi[1] = pcic_nmi_trap_patch    
361                 t_nmi[2] = pcic_nmi_trap_patch    
362                 t_nmi[3] = pcic_nmi_trap_patch    
363                 swift_flush_dcache();             
364                 pcic_regs = pcic->pcic_regs;      
365         }                                         
366                                                   
367         prom_getstring(prom_root_node, "name",    
368         {                                         
369                 struct pcic_sn2list *p;           
370                                                   
371                 for (p = pcic_known_sysnames;     
372                         if (strcmp(namebuf, p-    
373                                 break;            
374                 }                                 
375                 pcic->pcic_imap = p->intmap;      
376                 pcic->pcic_imdim = p->mapdim;     
377         }                                         
378         if (pcic->pcic_imap == NULL) {            
379                 /*                                
380                  * We do not panic here for th    
381                  */                               
382                 printk("PCIC: System %s is unk    
383                     namebuf);                     
384         }                                         
385                                                   
386         return 0;                                 
387 }                                                 
388                                                   
389 static void __init pcic_pbm_scan_bus(struct li    
390 {                                                 
391         struct linux_pbm_info *pbm = &pcic->pb    
392                                                   
393         pbm->pci_bus = pci_scan_bus(pbm->pci_f    
394 #if 0 /* deadwood transplanted from sparc64 */    
395         pci_fill_in_pbm_cookies(pbm->pci_bus,     
396         pci_record_assignments(pbm, pbm->pci_b    
397         pci_assign_unassigned(pbm, pbm->pci_bu    
398         pci_fixup_irq(pbm, pbm->pci_bus);         
399 #endif                                            
400 }                                                 
401                                                   
402 /*                                                
403  * Main entry point from the PCI subsystem.       
404  */                                               
405 static int __init pcic_init(void)                 
406 {                                                 
407         struct linux_pcic *pcic;                  
408                                                   
409         /*                                        
410          * PCIC should be initialized at start    
411          * So, here we report the presence of     
412          */                                       
413         if(!pcic0_up)                             
414                 return 0;                         
415         pcic = &pcic0;                            
416                                                   
417         /*                                        
418          *      Switch off IOTLB translation.     
419          */                                       
420         writeb(PCI_DVMA_CONTROL_IOTLB_DISABLE,    
421                pcic->pcic_regs+PCI_DVMA_CONTRO    
422                                                   
423         /*                                        
424          *      Increase mapped size for PCI m    
425          *      Should be done in that order (    
426          *      Why we couldn't set up 4GB and    
427          */                                       
428         writel(0xF0000000UL, pcic->pcic_regs+P    
429         writel(0+PCI_BASE_ADDRESS_SPACE_MEMORY    
430                pcic->pcic_regs+PCI_BASE_ADDRES    
431                                                   
432         pcic_pbm_scan_bus(pcic);                  
433                                                   
434         return 0;                                 
435 }                                                 
436                                                   
437 int pcic_present(void)                            
438 {                                                 
439         return pcic0_up;                          
440 }                                                 
441                                                   
442 static int pdev_to_pnode(struct linux_pbm_info    
443 {                                                 
444         struct linux_prom_pci_registers regs[P    
445         int err;                                  
446         phandle node = prom_getchild(pbm->prom    
447                                                   
448         while(node) {                             
449                 err = prom_getproperty(node, "    
450                                        (char *    
451                 if(err != 0 && err != -1) {       
452                         unsigned long devfn =     
453                         if(devfn == pdev->devf    
454                                 return node;      
455                 }                                 
456                 node = prom_getsibling(node);     
457         }                                         
458         return 0;                                 
459 }                                                 
460                                                   
461 static inline struct pcidev_cookie *pci_devcoo    
462 {                                                 
463         return kmalloc(sizeof(struct pcidev_co    
464 }                                                 
465                                                   
466 static void pcic_map_pci_device(struct linux_p    
467     struct pci_dev *dev, int node)                
468 {                                                 
469         char namebuf[64];                         
470         unsigned long address;                    
471         unsigned long flags;                      
472         int j;                                    
473                                                   
474         if (node == 0 || node == -1) {            
475                 strcpy(namebuf, "???");           
476         } else {                                  
477                 prom_getstring(node, "name", n    
478         }                                         
479                                                   
480         for (j = 0; j < 6; j++) {                 
481                 address = dev->resource[j].sta    
482                 if (address == 0) break;          
483                 flags = dev->resource[j].flags    
484                 if ((flags & IORESOURCE_IO) !=    
485                         if (address < 0x10000)    
486                                 /*                
487                                  * A device re    
488                                  * We generate    
489                                  * access into    
490                                  *                
491                                  * Since a dev    
492                                  * do ioremap(    
493                                  * we supply v    
494                                  *                
495                                  * Note that r    
496                                  * works for t    
497                                  *                
498                                  * XXX Neat tr    
499                                  * to shit int    
500                                  * What if we     
501                                  * PCI base ad    
502                                  */               
503                                 dev->resource[    
504                                     pcic->pcic    
505                                 dev->resource[    
506                                 dev->resource[    
507                                     (flags & ~    
508                         } else {                  
509                                 /*                
510                                  * OOPS... PCI    
511                                  * not have an    
512                                  * so it must     
513                                  * board in a     
514                                  * under 64K b    
515                                  */               
516                                 printk("PCIC:     
517                                     "this will    
518                                     "device '%    
519                                     namebuf, d    
520                         }                         
521                 }                                 
522         }                                         
523 }                                                 
524                                                   
525 static void                                       
526 pcic_fill_irq(struct linux_pcic *pcic, struct     
527 {                                                 
528         struct pcic_ca2irq *p;                    
529         unsigned int real_irq;                    
530         int i, ivec;                              
531         char namebuf[64];                         
532                                                   
533         if (node == 0 || node == -1) {            
534                 strcpy(namebuf, "???");           
535         } else {                                  
536                 prom_getstring(node, "name", n    
537         }                                         
538                                                   
539         if ((p = pcic->pcic_imap) == 0) {         
540                 dev->irq = 0;                     
541                 return;                           
542         }                                         
543         for (i = 0; i < pcic->pcic_imdim; i++)    
544                 if (p->busno == dev->bus->numb    
545                         break;                    
546                 p++;                              
547         }                                         
548         if (i >= pcic->pcic_imdim) {              
549                 printk("PCIC: device %s devfn     
550                     namebuf, dev->bus->number,    
551                 dev->irq = 0;                     
552                 return;                           
553         }                                         
554                                                   
555         i = p->pin;                               
556         if (i >= 0 && i < 4) {                    
557                 ivec = readw(pcic->pcic_regs+P    
558                 real_irq = ivec >> (i << 2) &     
559         } else if (i >= 4 && i < 8) {             
560                 ivec = readw(pcic->pcic_regs+P    
561                 real_irq = ivec >> ((i-4) << 2    
562         } else {                                  
563                 printk("PCIC: BAD PIN %d\n", i    
564         }                                         
565 /* P3 */ /* printk("PCIC: device %s pin %d ive    
566                                                   
567         /* real_irq means PROM did not bother     
568          * half of PCIC. This happens on JS-E     
569          */                                       
570         if (real_irq == 0 || p->force) {          
571                 if (p->irq == 0 || p->irq >= 1    
572                         printk("PCIC: BAD IRQ     
573                 }                                 
574                 printk("PCIC: setting irq %d a    
575                     p->irq, p->pin, dev->bus->    
576                 real_irq = p->irq;                
577                                                   
578                 i = p->pin;                       
579                 if (i >= 4) {                     
580                         ivec = readw(pcic->pci    
581                         ivec &= ~(0xF << ((i -    
582                         ivec |= p->irq << ((i     
583                         writew(ivec, pcic->pci    
584                 } else {                          
585                         ivec = readw(pcic->pci    
586                         ivec &= ~(0xF << (i <<    
587                         ivec |= p->irq << (i <    
588                         writew(ivec, pcic->pci    
589                 }                                 
590         }                                         
591         dev->irq = pcic_build_device_irq(NULL,    
592 }                                                 
593                                                   
594 /*                                                
595  * Normally called from {do_}pci_scan_bus...      
596  */                                               
597 void pcibios_fixup_bus(struct pci_bus *bus)       
598 {                                                 
599         struct pci_dev *dev;                      
600         int i, has_io, has_mem;                   
601         unsigned int cmd;                         
602         struct linux_pcic *pcic;                  
603         /* struct linux_pbm_info* pbm = &pcic-    
604         int node;                                 
605         struct pcidev_cookie *pcp;                
606                                                   
607         if (!pcic0_up) {                          
608                 printk("pcibios_fixup_bus: no     
609                 return;                           
610         }                                         
611         pcic = &pcic0;                            
612                                                   
613         /*                                        
614          * Next crud is an equivalent of pbm =    
615          */                                       
616         if (bus->number != 0) {                   
617                 printk("pcibios_fixup_bus: non    
618                 return;                           
619         }                                         
620                                                   
621         list_for_each_entry(dev, &bus->devices    
622                                                   
623                 /*                                
624                  * Comment from i386 branch:      
625                  *     There are buggy BIOSes     
626                  *     access to PCI devices.     
627                  *     be sure that the BIOS d    
628                  *     to the device. [mj]        
629                  * OBP is a case of such BIOS     
630                  */                               
631                 has_io = has_mem = 0;             
632                 for(i=0; i<6; i++) {              
633                         unsigned long f = dev-    
634                         if (f & IORESOURCE_IO)    
635                                 has_io = 1;       
636                         } else if (f & IORESOU    
637                                 has_mem = 1;      
638                 }                                 
639                 pcic_read_config(dev->bus, dev    
640                 if (has_io && !(cmd & PCI_COMM    
641                         printk("PCIC: Enabling    
642                                 dev->bus->numb    
643                         cmd |= PCI_COMMAND_IO;    
644                         pcic_write_config(dev-    
645                             PCI_COMMAND, 2, cm    
646                 }                                 
647                 if (has_mem && !(cmd & PCI_COM    
648                         printk("PCIC: Enabling    
649                                 dev->bus->numb    
650                         cmd |= PCI_COMMAND_MEM    
651                         pcic_write_config(dev-    
652                             PCI_COMMAND, 2, cm    
653                 }                                 
654                                                   
655                 node = pdev_to_pnode(&pcic->pb    
656                 if(node == 0)                     
657                         node = -1;                
658                                                   
659                 /* cookies */                     
660                 pcp = pci_devcookie_alloc();      
661                 pcp->pbm = &pcic->pbm;            
662                 pcp->prom_node = of_find_node_    
663                 dev->sysdata = pcp;               
664                                                   
665                 /* fixing I/O to look like mem    
666                 if ((dev->class>>16) != PCI_BA    
667                         pcic_map_pci_device(pc    
668                                                   
669                 pcic_fill_irq(pcic, dev, node)    
670         }                                         
671 }                                                 
672                                                   
673 /*                                                
674  * pcic_pin_to_irq() is exported to bus probin    
675  */                                               
676 unsigned int                                      
677 pcic_pin_to_irq(unsigned int pin, const char *    
678 {                                                 
679         struct linux_pcic *pcic = &pcic0;         
680         unsigned int irq;                         
681         unsigned int ivec;                        
682                                                   
683         if (pin < 4) {                            
684                 ivec = readw(pcic->pcic_regs+P    
685                 irq = ivec >> (pin << 2) & 0xF    
686         } else if (pin < 8) {                     
687                 ivec = readw(pcic->pcic_regs+P    
688                 irq = ivec >> ((pin-4) << 2) &    
689         } else {                                  
690                 printk("PCIC: BAD PIN %d FOR %    
691                 for (;;) {}     /* XXX Cannot     
692         }                                         
693 /* P3 */ /* printk("PCIC: dev %s pin %d ivec 0    
694         return irq;                               
695 }                                                 
696                                                   
697 /* Makes compiler happy */                        
698 static volatile int pcic_timer_dummy;             
699                                                   
700 static void pcic_clear_clock_irq(void)            
701 {                                                 
702         pcic_timer_dummy = readl(pcic0.pcic_re    
703 }                                                 
704                                                   
705 /* CPU frequency is 100 MHz, timer increments     
706 #define USECS_PER_JIFFY  (1000000 / HZ)           
707 #define TICK_TIMER_LIMIT ((100 * 1000000 / 4)     
708                                                   
709 static unsigned int pcic_cycles_offset(void)      
710 {                                                 
711         u32 value, count;                         
712                                                   
713         value = readl(pcic0.pcic_regs + PCI_SY    
714         count = value & ~PCI_SYS_COUNTER_OVERF    
715                                                   
716         if (value & PCI_SYS_COUNTER_OVERFLOW)     
717                 count += TICK_TIMER_LIMIT;        
718         /*                                        
719          * We divide all by HZ                    
720          * to have microsecond resolution and     
721          */                                       
722         count = ((count / HZ) * USECS_PER_JIFF    
723                                                   
724         /* Coordinate with the sparc_config.cl    
725         return count * 2;                         
726 }                                                 
727                                                   
728 void __init pci_time_init(void)                   
729 {                                                 
730         struct linux_pcic *pcic = &pcic0;         
731         unsigned long v;                          
732         int timer_irq, irq;                       
733         int err;                                  
734                                                   
735 #ifndef CONFIG_SMP                                
736         /*                                        
737          * The clock_rate is in SBUS dimension    
738          * We take into account this in pcic_c    
739          */                                       
740         sparc_config.clock_rate = SBUS_CLOCK_R    
741         sparc_config.features |= FEAT_L10_CLOC    
742 #endif                                            
743         sparc_config.features |= FEAT_L10_CLOC    
744         sparc_config.get_cycles_offset = pcic_    
745                                                   
746         writel (TICK_TIMER_LIMIT, pcic->pcic_r    
747         /* PROM should set appropriate irq */     
748         v = readb(pcic->pcic_regs+PCI_COUNTER_    
749         timer_irq = PCI_COUNTER_IRQ_SYS(v);       
750         writel (PCI_COUNTER_IRQ_SET(timer_irq,    
751                 pcic->pcic_regs+PCI_COUNTER_IR    
752         irq = pcic_build_device_irq(NULL, time    
753         err = request_irq(irq, timer_interrupt    
754                           IRQF_TIMER, "timer",    
755         if (err) {                                
756                 prom_printf("time_init: unable    
757                 prom_halt();                      
758         }                                         
759         local_irq_enable();                       
760 }                                                 
761                                                   
762                                                   
763 #if 0                                             
764 static void watchdog_reset() {                    
765         writeb(0, pcic->pcic_regs+PCI_SYS_STAT    
766 }                                                 
767 #endif                                            
768                                                   
769 resource_size_t pcibios_align_resource(void *d    
770                                 resource_size_    
771 {                                                 
772         return res->start;                        
773 }                                                 
774                                                   
775 int pcibios_enable_device(struct pci_dev *pdev    
776 {                                                 
777         return 0;                                 
778 }                                                 
779                                                   
780 /*                                                
781  * NMI                                            
782  */                                               
783 void pcic_nmi(unsigned int pend, struct pt_reg    
784 {                                                 
785                                                   
786         pend = flip_dword(pend);                  
787                                                   
788         if (!pcic_speculative || (pend & PCI_S    
789                 /*                                
790                  * XXX On CP-1200 PCI #SERR ma    
791                  * what to do about it yet.       
792                  */                               
793                 printk("Aiee, NMI pend 0x%x pc    
794                     pend, (int)regs->pc, pcic_    
795                 for (;;) { }                      
796         }                                         
797         pcic_speculative = 0;                     
798         pcic_trapped = 1;                         
799         regs->pc = regs->npc;                     
800         regs->npc += 4;                           
801 }                                                 
802                                                   
803 static inline unsigned long get_irqmask(int ir    
804 {                                                 
805         return 1 << irq_nr;                       
806 }                                                 
807                                                   
808 static void pcic_mask_irq(struct irq_data *dat    
809 {                                                 
810         unsigned long mask, flags;                
811                                                   
812         mask = (unsigned long)data->chip_data;    
813         local_irq_save(flags);                    
814         writel(mask, pcic0.pcic_regs+PCI_SYS_I    
815         local_irq_restore(flags);                 
816 }                                                 
817                                                   
818 static void pcic_unmask_irq(struct irq_data *d    
819 {                                                 
820         unsigned long mask, flags;                
821                                                   
822         mask = (unsigned long)data->chip_data;    
823         local_irq_save(flags);                    
824         writel(mask, pcic0.pcic_regs+PCI_SYS_I    
825         local_irq_restore(flags);                 
826 }                                                 
827                                                   
828 static unsigned int pcic_startup_irq(struct ir    
829 {                                                 
830         irq_link(data->irq);                      
831         pcic_unmask_irq(data);                    
832         return 0;                                 
833 }                                                 
834                                                   
835 static struct irq_chip pcic_irq = {               
836         .name           = "pcic",                 
837         .irq_startup    = pcic_startup_irq,       
838         .irq_mask       = pcic_mask_irq,          
839         .irq_unmask     = pcic_unmask_irq,        
840 };                                                
841                                                   
842 unsigned int pcic_build_device_irq(struct plat    
843                                    unsigned in    
844 {                                                 
845         unsigned int irq;                         
846         unsigned long mask;                       
847                                                   
848         irq = 0;                                  
849         mask = get_irqmask(real_irq);             
850         if (mask == 0)                            
851                 goto out;                         
852                                                   
853         irq = irq_alloc(real_irq, real_irq);      
854         if (irq == 0)                             
855                 goto out;                         
856                                                   
857         irq_set_chip_and_handler_name(irq, &pc    
858                                       handle_l    
859         irq_set_chip_data(irq, (void *)mask);     
860                                                   
861 out:                                              
862         return irq;                               
863 }                                                 
864                                                   
865                                                   
866 static void pcic_load_profile_irq(int cpu, uns    
867 {                                                 
868         printk("PCIC: unimplemented code: FILE    
869 }                                                 
870                                                   
871 void __init sun4m_pci_init_IRQ(void)              
872 {                                                 
873         sparc_config.build_device_irq = pcic_b    
874         sparc_config.clear_clock_irq  = pcic_c    
875         sparc_config.load_profile_irq = pcic_l    
876 }                                                 
877                                                   
878 /*                                                
879  * This probably belongs here rather than iopo    
880  * we do not want this crud linked into SBus k    
881  * Also, think for a moment about likes of flo    
882  * include architecture specific parts. They m    
883  *                                                
884  * We do not use horrible macros here because     
885  * advance pointer by sizeof(size).               
886  */                                               
887 void outsb(unsigned long addr, const void *src    
888 {                                                 
889         while (count) {                           
890                 count -= 1;                       
891                 outb(*(const char *)src, addr)    
892                 src += 1;                         
893                 /* addr += 1; */                  
894         }                                         
895 }                                                 
896 EXPORT_SYMBOL(outsb);                             
897                                                   
898 void outsw(unsigned long addr, const void *src    
899 {                                                 
900         while (count) {                           
901                 count -= 2;                       
902                 outw(*(const short *)src, addr    
903                 src += 2;                         
904                 /* addr += 2; */                  
905         }                                         
906 }                                                 
907 EXPORT_SYMBOL(outsw);                             
908                                                   
909 void outsl(unsigned long addr, const void *src    
910 {                                                 
911         while (count) {                           
912                 count -= 4;                       
913                 outl(*(const long *)src, addr)    
914                 src += 4;                         
915                 /* addr += 4; */                  
916         }                                         
917 }                                                 
918 EXPORT_SYMBOL(outsl);                             
919                                                   
920 void insb(unsigned long addr, void *dst, unsig    
921 {                                                 
922         while (count) {                           
923                 count -= 1;                       
924                 *(unsigned char *)dst = inb(ad    
925                 dst += 1;                         
926                 /* addr += 1; */                  
927         }                                         
928 }                                                 
929 EXPORT_SYMBOL(insb);                              
930                                                   
931 void insw(unsigned long addr, void *dst, unsig    
932 {                                                 
933         while (count) {                           
934                 count -= 2;                       
935                 *(unsigned short *)dst = inw(a    
936                 dst += 2;                         
937                 /* addr += 2; */                  
938         }                                         
939 }                                                 
940 EXPORT_SYMBOL(insw);                              
941                                                   
942 void insl(unsigned long addr, void *dst, unsig    
943 {                                                 
944         while (count) {                           
945                 count -= 4;                       
946                 /*                                
947                  * XXX I am sure we are in for    
948                  */                               
949                 *(unsigned long *)dst = inl(ad    
950                 dst += 4;                         
951                 /* addr += 4; */                  
952         }                                         
953 }                                                 
954 EXPORT_SYMBOL(insl);                              
955                                                   
956 subsys_initcall(pcic_init);                       
957                                                   

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp