Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * starfire.c: Starfire/E10000 support.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Copyright (C) 1998 David S. Miller (davem@redhat.com)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * Copyright (C) 2000 Anton Blanchard (anton@samba.org)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <asm/page.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <asm/oplib.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <asm/smp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <asm/upa.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <asm/starfire.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19)  * A few places around the kernel check this to see if
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20)  * they need to call us to do things in a Starfire specific
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21)  * way.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) int this_is_starfire = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) void check_if_starfire(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 	phandle ssnode = prom_finddevice("/ssp-serial");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 	if (ssnode != 0 && (s32)ssnode != -1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 		this_is_starfire = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33)  * Each Starfire board has 32 registers which perform translation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34)  * and delivery of traditional interrupt packets into the extended
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35)  * Starfire hardware format.  Essentially UPAID's now have 2 more
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36)  * bits than in all previous Sun5 systems.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) struct starfire_irqinfo {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	unsigned long imap_slots[32];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	unsigned long tregs[32];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	struct starfire_irqinfo *next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	int upaid, hwmid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) static struct starfire_irqinfo *sflist = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) /* Beam me up Scott(McNeil)y... */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) void starfire_hookup(int upaid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	struct starfire_irqinfo *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	unsigned long treg_base, hwmid, i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	p = kmalloc(sizeof(*p), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	if (!p) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 		prom_printf("starfire_hookup: No memory, this is insane.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 		prom_halt();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	treg_base = 0x100fc000000UL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	hwmid = ((upaid & 0x3c) << 1) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 		((upaid & 0x40) >> 4) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 		(upaid & 0x3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	p->hwmid = hwmid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	treg_base += (hwmid << 33UL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	treg_base += 0x200UL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	for (i = 0; i < 32; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 		p->imap_slots[i] = 0UL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 		p->tregs[i] = treg_base + (i * 0x10UL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 		/* Lets play it safe and not overwrite existing mappings */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 		if (upa_readl(p->tregs[i]) != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 			p->imap_slots[i] = 0xdeadbeaf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	p->upaid = upaid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	p->next = sflist;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	sflist = p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) unsigned int starfire_translate(unsigned long imap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 				unsigned int upaid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	struct starfire_irqinfo *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	unsigned int bus_hwmid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	unsigned int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	bus_hwmid = (((unsigned long)imap) >> 33) & 0x7f;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	for (p = sflist; p != NULL; p = p->next)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 		if (p->hwmid == bus_hwmid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	if (p == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 		prom_printf("XFIRE: Cannot find irqinfo for imap %016lx\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 			    ((unsigned long)imap));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 		prom_halt();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	for (i = 0; i < 32; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 		if (p->imap_slots[i] == imap ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 		    p->imap_slots[i] == 0UL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	if (i == 32) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 		printk("starfire_translate: Are you kidding me?\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 		panic("Lucy in the sky....");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	p->imap_slots[i] = imap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	/* map to real upaid */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	upaid = (((upaid & 0x3c) << 1) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 		 ((upaid & 0x40) >> 4) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 		 (upaid & 0x3));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	upa_writel(upaid, p->tregs[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	return i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) }