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-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * Copyright (C) 1992-1997, 2000-2003 Silicon Graphics, Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * Copyright (C) 2004 Christoph Hellwig.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * Support functions for the HUB ASIC - mostly PIO mapping related.
^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/bitops.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/mmzone.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <asm/sn/addrs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <asm/sn/arch.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <asm/sn/agent.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <asm/sn/io.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <asm/xtalk/xtalk.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) static int force_fire_and_forget = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22)  * hub_pio_map	-  establish a HUB PIO mapping
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24)  * @hub:	hub to perform PIO mapping on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25)  * @widget:	widget ID to perform PIO mapping for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26)  * @xtalk_addr: xtalk_address that needs to be mapped
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27)  * @size:	size of the PIO mapping
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) unsigned long hub_pio_map(nasid_t nasid, xwidgetnum_t widget,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 			  unsigned long xtalk_addr, size_t size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	unsigned i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	/* use small-window mapping if possible */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	if ((xtalk_addr % SWIN_SIZE) + size <= SWIN_SIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 		return NODE_SWIN_BASE(nasid, widget) + (xtalk_addr % SWIN_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	if ((xtalk_addr % BWIN_SIZE) + size > BWIN_SIZE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 		printk(KERN_WARNING "PIO mapping at hub %d widget %d addr 0x%lx"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 				" too big (%ld)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 				nasid, widget, xtalk_addr, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	xtalk_addr &= ~(BWIN_SIZE-1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	for (i = 0; i < HUB_NUM_BIG_WINDOW; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 		if (test_and_set_bit(i, hub_data(nasid)->h_bigwin_used))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 		 * The code below does a PIO write to setup an ITTE entry.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 		 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 		 * We need to prevent other CPUs from seeing our updated
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 		 * memory shadow of the ITTE (in the piomap) until the ITTE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 		 * entry is actually set up; otherwise, another CPU might
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 		 * attempt a PIO prematurely.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 		 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 		 * Also, the only way we can know that an entry has been
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 		 * received  by the hub and can be used by future PIO reads/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 		 * writes is by reading back the ITTE entry after writing it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 		 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 		 * For these two reasons, we PIO read back the ITTE entry
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 		 * after we write it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 		IIO_ITTE_PUT(nasid, i, HUB_PIO_MAP_TO_MEM, widget, xtalk_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 		__raw_readq(IIO_ITTE_GET(nasid, i));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 		return NODE_BWIN_BASE(nasid, widget) + (xtalk_addr % BWIN_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	printk(KERN_WARNING "unable to establish PIO mapping for at"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 			" hub %d widget %d addr 0x%lx\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 			nasid, widget, xtalk_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80)  * hub_setup_prb(nasid, prbnum, credits, conveyor)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82)  *	Put a PRB into fire-and-forget mode if conveyor isn't set.  Otherwise,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83)  *	put it into conveyor belt mode with the specified number of credits.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) static void hub_setup_prb(nasid_t nasid, int prbnum, int credits)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	union iprb_u prb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	int prb_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	 * Get the current register value.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	prb_offset = IIO_IOPRB(prbnum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	prb.iprb_regval = REMOTE_HUB_L(nasid, prb_offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	 * Clear out some fields.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	prb.iprb_ovflow = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	prb.iprb_bnakctr = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	prb.iprb_anakctr = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	 * Enable or disable fire-and-forget mode.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	prb.iprb_ff = force_fire_and_forget ? 1 : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	 * Set the appropriate number of PIO credits for the widget.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	prb.iprb_xtalkctr = credits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	 * Store the new value to the register.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	REMOTE_HUB_S(nasid, prb_offset, prb.iprb_regval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120)  * hub_set_piomode  -  set pio mode for a given hub
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)  * @nasid:	physical node ID for the hub in question
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124)  * Put the hub into either "PIO conveyor belt" mode or "fire-and-forget" mode.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125)  * To do this, we have to make absolutely sure that no PIOs are in progress
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)  * so we turn off access to all widgets for the duration of the function.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128)  * XXX - This code should really check what kind of widget we're talking
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129)  * to.	Bridges can only handle three requests, but XG will do more.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130)  * How many can crossbow handle to widget 0?  We're assuming 1.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132)  * XXX - There is a bug in the crossbow that link reset PIOs do not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133)  * return write responses.  The easiest solution to this problem is to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134)  * leave widget 0 (xbow) in fire-and-forget mode at all times.	This
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135)  * only affects pio's to xbow registers, which should be rare.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) static void hub_set_piomode(nasid_t nasid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	u64 ii_iowa;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	union hubii_wcr_u ii_wcr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	unsigned i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	ii_iowa = REMOTE_HUB_L(nasid, IIO_OUTWIDGET_ACCESS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	REMOTE_HUB_S(nasid, IIO_OUTWIDGET_ACCESS, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	ii_wcr.wcr_reg_value = REMOTE_HUB_L(nasid, IIO_WCR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	if (ii_wcr.iwcr_dir_con) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 		 * Assume a bridge here.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 		hub_setup_prb(nasid, 0, 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 		 * Assume a crossbow here.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 		hub_setup_prb(nasid, 0, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	 * XXX - Here's where we should take the widget type into
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	 * when account assigning credits.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	for (i = HUB_WIDGET_ID_MIN; i <= HUB_WIDGET_ID_MAX; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 		hub_setup_prb(nasid, i, 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	REMOTE_HUB_S(nasid, IIO_OUTWIDGET_ACCESS, ii_iowa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171)  * hub_pio_init	 -  PIO-related hub initialization
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173)  * @hub:	hubinfo structure for our hub
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) void hub_pio_init(nasid_t nasid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	unsigned i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	/* initialize big window piomaps for this hub */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	bitmap_zero(hub_data(nasid)->h_bigwin_used, HUB_NUM_BIG_WINDOW);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	for (i = 0; i < HUB_NUM_BIG_WINDOW; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 		IIO_ITTE_DISABLE(nasid, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	hub_set_piomode(nasid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) }