| Dean Nelson | 89eb8eb | 2005-03-23 19:50:00 -0700 | [diff] [blame] | 1 | /* | 
|  | 2 | * This file is subject to the terms and conditions of the GNU General Public | 
|  | 3 | * License.  See the file "COPYING" in the main directory of this archive | 
|  | 4 | * for more details. | 
|  | 5 | * | 
| Dean Nelson | 45d9ca4 | 2008-04-22 14:46:56 -0500 | [diff] [blame] | 6 | * Copyright (c) 2004-2008 Silicon Graphics, Inc.  All Rights Reserved. | 
| Dean Nelson | 89eb8eb | 2005-03-23 19:50:00 -0700 | [diff] [blame] | 7 | */ | 
|  | 8 |  | 
| Dean Nelson | 89eb8eb | 2005-03-23 19:50:00 -0700 | [diff] [blame] | 9 | /* | 
|  | 10 | * Cross Partition Communication (XPC) partition support. | 
|  | 11 | * | 
|  | 12 | *	This is the part of XPC that detects the presence/absence of | 
|  | 13 | *	other partitions. It provides a heartbeat and monitors the | 
|  | 14 | *	heartbeats of other partitions. | 
|  | 15 | * | 
|  | 16 | */ | 
|  | 17 |  | 
| Dean Nelson | 261f3b4 | 2008-07-29 22:34:16 -0700 | [diff] [blame] | 18 | #include <linux/device.h> | 
|  | 19 | #include <linux/hardirq.h> | 
| Dean Nelson | 45d9ca4 | 2008-04-22 14:46:56 -0500 | [diff] [blame] | 20 | #include "xpc.h" | 
| Dean Nelson | 89eb8eb | 2005-03-23 19:50:00 -0700 | [diff] [blame] | 21 |  | 
| Dean Nelson | 89eb8eb | 2005-03-23 19:50:00 -0700 | [diff] [blame] | 22 | /* XPC is exiting flag */ | 
|  | 23 | int xpc_exiting; | 
|  | 24 |  | 
| Dean Nelson | 4b38fcd | 2005-10-25 14:09:51 -0500 | [diff] [blame] | 25 | /* this partition's reserved page pointers */ | 
| Dean Nelson | 89eb8eb | 2005-03-23 19:50:00 -0700 | [diff] [blame] | 26 | struct xpc_rsvd_page *xpc_rsvd_page; | 
| Dean Nelson | 04de741 | 2008-07-29 22:34:14 -0700 | [diff] [blame] | 27 | static unsigned long *xpc_part_nasids; | 
|  | 28 | unsigned long *xpc_mach_nasids; | 
| Dean Nelson | 89eb8eb | 2005-03-23 19:50:00 -0700 | [diff] [blame] | 29 |  | 
| Dean Nelson | 04de741 | 2008-07-29 22:34:14 -0700 | [diff] [blame] | 30 | static int xpc_nasid_mask_nbytes;	/* #of bytes in nasid mask */ | 
|  | 31 | int xpc_nasid_mask_nlongs;	/* #of longs in nasid mask */ | 
| Dean Nelson | 4b38fcd | 2005-10-25 14:09:51 -0500 | [diff] [blame] | 32 |  | 
| Dean Nelson | bc63d38 | 2008-07-29 22:34:04 -0700 | [diff] [blame] | 33 | struct xpc_partition *xpc_partitions; | 
| Dean Nelson | 89eb8eb | 2005-03-23 19:50:00 -0700 | [diff] [blame] | 34 |  | 
| Dean Nelson | 89eb8eb | 2005-03-23 19:50:00 -0700 | [diff] [blame] | 35 | /* | 
| Jes Sorensen | 7aa6ba4 | 2006-02-17 05:18:43 -0500 | [diff] [blame] | 36 | * Guarantee that the kmalloc'd memory is cacheline aligned. | 
|  | 37 | */ | 
| Dean Nelson | 7682a4c | 2006-08-08 15:03:29 -0500 | [diff] [blame] | 38 | void * | 
| Jes Sorensen | 7aa6ba4 | 2006-02-17 05:18:43 -0500 | [diff] [blame] | 39 | xpc_kmalloc_cacheline_aligned(size_t size, gfp_t flags, void **base) | 
|  | 40 | { | 
|  | 41 | /* see if kmalloc will give us cachline aligned memory by default */ | 
|  | 42 | *base = kmalloc(size, flags); | 
| Dean Nelson | 2c2b94f | 2008-04-22 14:50:17 -0500 | [diff] [blame] | 43 | if (*base == NULL) | 
| Jes Sorensen | 7aa6ba4 | 2006-02-17 05:18:43 -0500 | [diff] [blame] | 44 | return NULL; | 
| Dean Nelson | 2c2b94f | 2008-04-22 14:50:17 -0500 | [diff] [blame] | 45 |  | 
|  | 46 | if ((u64)*base == L1_CACHE_ALIGN((u64)*base)) | 
| Jes Sorensen | 7aa6ba4 | 2006-02-17 05:18:43 -0500 | [diff] [blame] | 47 | return *base; | 
| Dean Nelson | 2c2b94f | 2008-04-22 14:50:17 -0500 | [diff] [blame] | 48 |  | 
| Jes Sorensen | 7aa6ba4 | 2006-02-17 05:18:43 -0500 | [diff] [blame] | 49 | kfree(*base); | 
|  | 50 |  | 
|  | 51 | /* nope, we'll have to do it ourselves */ | 
|  | 52 | *base = kmalloc(size + L1_CACHE_BYTES, flags); | 
| Dean Nelson | 2c2b94f | 2008-04-22 14:50:17 -0500 | [diff] [blame] | 53 | if (*base == NULL) | 
| Jes Sorensen | 7aa6ba4 | 2006-02-17 05:18:43 -0500 | [diff] [blame] | 54 | return NULL; | 
| Dean Nelson | 2c2b94f | 2008-04-22 14:50:17 -0500 | [diff] [blame] | 55 |  | 
| Dean Nelson | 4a3ad2d | 2008-04-22 14:48:01 -0500 | [diff] [blame] | 56 | return (void *)L1_CACHE_ALIGN((u64)*base); | 
| Jes Sorensen | 7aa6ba4 | 2006-02-17 05:18:43 -0500 | [diff] [blame] | 57 | } | 
|  | 58 |  | 
| Jes Sorensen | 7aa6ba4 | 2006-02-17 05:18:43 -0500 | [diff] [blame] | 59 | /* | 
| Dean Nelson | 89eb8eb | 2005-03-23 19:50:00 -0700 | [diff] [blame] | 60 | * Given a nasid, get the physical address of the  partition's reserved page | 
|  | 61 | * for that nasid. This function returns 0 on any error. | 
|  | 62 | */ | 
| Dean Nelson | a812dcc | 2008-07-29 22:34:16 -0700 | [diff] [blame] | 63 | static unsigned long | 
| Dean Nelson | 2792902 | 2005-10-25 14:11:53 -0500 | [diff] [blame] | 64 | xpc_get_rsvd_page_pa(int nasid) | 
| Dean Nelson | 89eb8eb | 2005-03-23 19:50:00 -0700 | [diff] [blame] | 65 | { | 
| Dean Nelson | 908787d | 2008-07-29 22:34:05 -0700 | [diff] [blame] | 66 | enum xp_retval ret; | 
| Dean Nelson | 89eb8eb | 2005-03-23 19:50:00 -0700 | [diff] [blame] | 67 | u64 cookie = 0; | 
| Dean Nelson | a812dcc | 2008-07-29 22:34:16 -0700 | [diff] [blame] | 68 | unsigned long rp_pa = nasid;	/* seed with nasid */ | 
| Dean Nelson | 261f3b4 | 2008-07-29 22:34:16 -0700 | [diff] [blame] | 69 | size_t len = 0; | 
| Dean Nelson | a812dcc | 2008-07-29 22:34:16 -0700 | [diff] [blame] | 70 | size_t buf_len = 0; | 
|  | 71 | void *buf = buf; | 
| Dean Nelson | 2792902 | 2005-10-25 14:11:53 -0500 | [diff] [blame] | 72 | void *buf_base = NULL; | 
| Robin Holt | a7665b0 | 2009-04-13 14:40:19 -0700 | [diff] [blame] | 73 | enum xp_retval (*get_partition_rsvd_page_pa) | 
|  | 74 | (void *, u64 *, unsigned long *, size_t *) = | 
|  | 75 | xpc_arch_ops.get_partition_rsvd_page_pa; | 
| Dean Nelson | 89eb8eb | 2005-03-23 19:50:00 -0700 | [diff] [blame] | 76 |  | 
| Dean Nelson | 89eb8eb | 2005-03-23 19:50:00 -0700 | [diff] [blame] | 77 | while (1) { | 
|  | 78 |  | 
| Dean Nelson | 5b8669d | 2008-07-29 22:34:18 -0700 | [diff] [blame] | 79 | /* !!! rp_pa will need to be _gpa on UV. | 
|  | 80 | * ??? So do we save it into the architecture specific parts | 
|  | 81 | * ??? of the xpc_partition structure? Do we rename this | 
|  | 82 | * ??? function or have two versions? Rename rp_pa for UV to | 
|  | 83 | * ??? rp_gpa? | 
|  | 84 | */ | 
| Robin Holt | a7665b0 | 2009-04-13 14:40:19 -0700 | [diff] [blame] | 85 | ret = get_partition_rsvd_page_pa(buf, &cookie, &rp_pa, &len); | 
| Dean Nelson | 89eb8eb | 2005-03-23 19:50:00 -0700 | [diff] [blame] | 86 |  | 
| Dean Nelson | 261f3b4 | 2008-07-29 22:34:16 -0700 | [diff] [blame] | 87 | dev_dbg(xpc_part, "SAL returned with ret=%d, cookie=0x%016lx, " | 
|  | 88 | "address=0x%016lx, len=0x%016lx\n", ret, | 
| Dean Nelson | a812dcc | 2008-07-29 22:34:16 -0700 | [diff] [blame] | 89 | (unsigned long)cookie, rp_pa, len); | 
| Dean Nelson | 89eb8eb | 2005-03-23 19:50:00 -0700 | [diff] [blame] | 90 |  | 
| Dean Nelson | 261f3b4 | 2008-07-29 22:34:16 -0700 | [diff] [blame] | 91 | if (ret != xpNeedMoreInfo) | 
| Dean Nelson | 89eb8eb | 2005-03-23 19:50:00 -0700 | [diff] [blame] | 92 | break; | 
| Dean Nelson | 89eb8eb | 2005-03-23 19:50:00 -0700 | [diff] [blame] | 93 |  | 
| Dean Nelson | ea57f80 | 2008-07-29 22:34:14 -0700 | [diff] [blame] | 94 | /* !!! L1_CACHE_ALIGN() is only a sn2-bte_copy requirement */ | 
| Dean Nelson | 2792902 | 2005-10-25 14:11:53 -0500 | [diff] [blame] | 95 | if (L1_CACHE_ALIGN(len) > buf_len) { | 
| Jesper Juhl | cbf283c | 2006-04-20 10:11:09 -0700 | [diff] [blame] | 96 | kfree(buf_base); | 
| Dean Nelson | 2792902 | 2005-10-25 14:11:53 -0500 | [diff] [blame] | 97 | buf_len = L1_CACHE_ALIGN(len); | 
| Dean Nelson | a812dcc | 2008-07-29 22:34:16 -0700 | [diff] [blame] | 98 | buf = xpc_kmalloc_cacheline_aligned(buf_len, GFP_KERNEL, | 
|  | 99 | &buf_base); | 
| Dean Nelson | 2792902 | 2005-10-25 14:11:53 -0500 | [diff] [blame] | 100 | if (buf_base == NULL) { | 
|  | 101 | dev_err(xpc_part, "unable to kmalloc " | 
| Dean Nelson | a812dcc | 2008-07-29 22:34:16 -0700 | [diff] [blame] | 102 | "len=0x%016lx\n", buf_len); | 
| Dean Nelson | 261f3b4 | 2008-07-29 22:34:16 -0700 | [diff] [blame] | 103 | ret = xpNoMemory; | 
| Dean Nelson | 2792902 | 2005-10-25 14:11:53 -0500 | [diff] [blame] | 104 | break; | 
|  | 105 | } | 
| Dean Nelson | 89eb8eb | 2005-03-23 19:50:00 -0700 | [diff] [blame] | 106 | } | 
|  | 107 |  | 
| Dean Nelson | a812dcc | 2008-07-29 22:34:16 -0700 | [diff] [blame] | 108 | ret = xp_remote_memcpy(xp_pa(buf), rp_pa, buf_len); | 
| Dean Nelson | 908787d | 2008-07-29 22:34:05 -0700 | [diff] [blame] | 109 | if (ret != xpSuccess) { | 
|  | 110 | dev_dbg(xpc_part, "xp_remote_memcpy failed %d\n", ret); | 
| Dean Nelson | 89eb8eb | 2005-03-23 19:50:00 -0700 | [diff] [blame] | 111 | break; | 
|  | 112 | } | 
|  | 113 | } | 
|  | 114 |  | 
| Jesper Juhl | cbf283c | 2006-04-20 10:11:09 -0700 | [diff] [blame] | 115 | kfree(buf_base); | 
| Dean Nelson | 2792902 | 2005-10-25 14:11:53 -0500 | [diff] [blame] | 116 |  | 
| Dean Nelson | 261f3b4 | 2008-07-29 22:34:16 -0700 | [diff] [blame] | 117 | if (ret != xpSuccess) | 
| Dean Nelson | 89eb8eb | 2005-03-23 19:50:00 -0700 | [diff] [blame] | 118 | rp_pa = 0; | 
| Dean Nelson | 2c2b94f | 2008-04-22 14:50:17 -0500 | [diff] [blame] | 119 |  | 
| Dean Nelson | a812dcc | 2008-07-29 22:34:16 -0700 | [diff] [blame] | 120 | dev_dbg(xpc_part, "reserved page at phys address 0x%016lx\n", rp_pa); | 
| Dean Nelson | 89eb8eb | 2005-03-23 19:50:00 -0700 | [diff] [blame] | 121 | return rp_pa; | 
|  | 122 | } | 
|  | 123 |  | 
| Dean Nelson | 89eb8eb | 2005-03-23 19:50:00 -0700 | [diff] [blame] | 124 | /* | 
|  | 125 | * Fill the partition reserved page with the information needed by | 
|  | 126 | * other partitions to discover we are alive and establish initial | 
|  | 127 | * communications. | 
|  | 128 | */ | 
| Dean Nelson | 5b8669d | 2008-07-29 22:34:18 -0700 | [diff] [blame] | 129 | int | 
| Dean Nelson | 94bd270 | 2008-07-29 22:34:05 -0700 | [diff] [blame] | 130 | xpc_setup_rsvd_page(void) | 
| Dean Nelson | 89eb8eb | 2005-03-23 19:50:00 -0700 | [diff] [blame] | 131 | { | 
| Dean Nelson | 5b8669d | 2008-07-29 22:34:18 -0700 | [diff] [blame] | 132 | int ret; | 
| Dean Nelson | 89eb8eb | 2005-03-23 19:50:00 -0700 | [diff] [blame] | 133 | struct xpc_rsvd_page *rp; | 
| Dean Nelson | a812dcc | 2008-07-29 22:34:16 -0700 | [diff] [blame] | 134 | unsigned long rp_pa; | 
| Dean Nelson | 81fe788 | 2008-07-29 22:34:15 -0700 | [diff] [blame] | 135 | unsigned long new_ts_jiffies; | 
| Dean Nelson | 89eb8eb | 2005-03-23 19:50:00 -0700 | [diff] [blame] | 136 |  | 
| Dean Nelson | 89eb8eb | 2005-03-23 19:50:00 -0700 | [diff] [blame] | 137 | /* get the local reserved page's address */ | 
|  | 138 |  | 
| Dean Nelson | 2792902 | 2005-10-25 14:11:53 -0500 | [diff] [blame] | 139 | preempt_disable(); | 
| Dean Nelson | 261f3b4 | 2008-07-29 22:34:16 -0700 | [diff] [blame] | 140 | rp_pa = xpc_get_rsvd_page_pa(xp_cpu_to_nasid(smp_processor_id())); | 
| Dean Nelson | 2792902 | 2005-10-25 14:11:53 -0500 | [diff] [blame] | 141 | preempt_enable(); | 
| Dean Nelson | 89eb8eb | 2005-03-23 19:50:00 -0700 | [diff] [blame] | 142 | if (rp_pa == 0) { | 
|  | 143 | dev_err(xpc_part, "SAL failed to locate the reserved page\n"); | 
| Dean Nelson | 5b8669d | 2008-07-29 22:34:18 -0700 | [diff] [blame] | 144 | return -ESRCH; | 
| Dean Nelson | 89eb8eb | 2005-03-23 19:50:00 -0700 | [diff] [blame] | 145 | } | 
| Dean Nelson | 4a3ad2d | 2008-04-22 14:48:01 -0500 | [diff] [blame] | 146 | rp = (struct xpc_rsvd_page *)__va(rp_pa); | 
| Dean Nelson | 89eb8eb | 2005-03-23 19:50:00 -0700 | [diff] [blame] | 147 |  | 
| Dean Nelson | 94bd270 | 2008-07-29 22:34:05 -0700 | [diff] [blame] | 148 | if (rp->SAL_version < 3) { | 
|  | 149 | /* SAL_versions < 3 had a SAL_partid defined as a u8 */ | 
|  | 150 | rp->SAL_partid &= 0xff; | 
|  | 151 | } | 
| Dean Nelson | 261f3b4 | 2008-07-29 22:34:16 -0700 | [diff] [blame] | 152 | BUG_ON(rp->SAL_partid != xp_partition_id); | 
| Dean Nelson | 94bd270 | 2008-07-29 22:34:05 -0700 | [diff] [blame] | 153 |  | 
|  | 154 | if (rp->SAL_partid < 0 || rp->SAL_partid >= xp_max_npartitions) { | 
|  | 155 | dev_err(xpc_part, "the reserved page's partid of %d is outside " | 
|  | 156 | "supported range (< 0 || >= %d)\n", rp->SAL_partid, | 
|  | 157 | xp_max_npartitions); | 
| Dean Nelson | 5b8669d | 2008-07-29 22:34:18 -0700 | [diff] [blame] | 158 | return -EINVAL; | 
| Dean Nelson | 89eb8eb | 2005-03-23 19:50:00 -0700 | [diff] [blame] | 159 | } | 
|  | 160 |  | 
|  | 161 | rp->version = XPC_RP_VERSION; | 
| Dean Nelson | 94bd270 | 2008-07-29 22:34:05 -0700 | [diff] [blame] | 162 | rp->max_npartitions = xp_max_npartitions; | 
| Dean Nelson | 89eb8eb | 2005-03-23 19:50:00 -0700 | [diff] [blame] | 163 |  | 
| Dean Nelson | 4b38fcd | 2005-10-25 14:09:51 -0500 | [diff] [blame] | 164 | /* establish the actual sizes of the nasid masks */ | 
|  | 165 | if (rp->SAL_version == 1) { | 
|  | 166 | /* SAL_version 1 didn't set the nasids_size field */ | 
| Dean Nelson | 94bd270 | 2008-07-29 22:34:05 -0700 | [diff] [blame] | 167 | rp->SAL_nasids_size = 128; | 
| Dean Nelson | 4b38fcd | 2005-10-25 14:09:51 -0500 | [diff] [blame] | 168 | } | 
| Dean Nelson | 04de741 | 2008-07-29 22:34:14 -0700 | [diff] [blame] | 169 | xpc_nasid_mask_nbytes = rp->SAL_nasids_size; | 
|  | 170 | xpc_nasid_mask_nlongs = BITS_TO_LONGS(rp->SAL_nasids_size * | 
|  | 171 | BITS_PER_BYTE); | 
| Dean Nelson | 4b38fcd | 2005-10-25 14:09:51 -0500 | [diff] [blame] | 172 |  | 
|  | 173 | /* setup the pointers to the various items in the reserved page */ | 
|  | 174 | xpc_part_nasids = XPC_RP_PART_NASIDS(rp); | 
|  | 175 | xpc_mach_nasids = XPC_RP_MACH_NASIDS(rp); | 
| Dean Nelson | 94bd270 | 2008-07-29 22:34:05 -0700 | [diff] [blame] | 176 |  | 
| Robin Holt | a7665b0 | 2009-04-13 14:40:19 -0700 | [diff] [blame] | 177 | ret = xpc_arch_ops.setup_rsvd_page(rp); | 
| Dean Nelson | 5b8669d | 2008-07-29 22:34:18 -0700 | [diff] [blame] | 178 | if (ret != 0) | 
|  | 179 | return ret; | 
| Dean Nelson | 89eb8eb | 2005-03-23 19:50:00 -0700 | [diff] [blame] | 180 |  | 
|  | 181 | /* | 
| Dean Nelson | 94bd270 | 2008-07-29 22:34:05 -0700 | [diff] [blame] | 182 | * Set timestamp of when reserved page was setup by XPC. | 
| Dean Nelson | 89eb8eb | 2005-03-23 19:50:00 -0700 | [diff] [blame] | 183 | * This signifies to the remote partition that our reserved | 
|  | 184 | * page is initialized. | 
|  | 185 | */ | 
| Dean Nelson | 81fe788 | 2008-07-29 22:34:15 -0700 | [diff] [blame] | 186 | new_ts_jiffies = jiffies; | 
|  | 187 | if (new_ts_jiffies == 0 || new_ts_jiffies == rp->ts_jiffies) | 
|  | 188 | new_ts_jiffies++; | 
|  | 189 | rp->ts_jiffies = new_ts_jiffies; | 
| Dean Nelson | 89eb8eb | 2005-03-23 19:50:00 -0700 | [diff] [blame] | 190 |  | 
| Dean Nelson | 5b8669d | 2008-07-29 22:34:18 -0700 | [diff] [blame] | 191 | xpc_rsvd_page = rp; | 
|  | 192 | return 0; | 
|  | 193 | } | 
|  | 194 |  | 
|  | 195 | void | 
|  | 196 | xpc_teardown_rsvd_page(void) | 
|  | 197 | { | 
|  | 198 | /* a zero timestamp indicates our rsvd page is not initialized */ | 
|  | 199 | xpc_rsvd_page->ts_jiffies = 0; | 
| Dean Nelson | 89eb8eb | 2005-03-23 19:50:00 -0700 | [diff] [blame] | 200 | } | 
|  | 201 |  | 
| Dean Nelson | 89eb8eb | 2005-03-23 19:50:00 -0700 | [diff] [blame] | 202 | /* | 
| Dean Nelson | 4b38fcd | 2005-10-25 14:09:51 -0500 | [diff] [blame] | 203 | * Get a copy of a portion of the remote partition's rsvd page. | 
| Dean Nelson | 89eb8eb | 2005-03-23 19:50:00 -0700 | [diff] [blame] | 204 | * | 
|  | 205 | * remote_rp points to a buffer that is cacheline aligned for BTE copies and | 
| Dean Nelson | 4b38fcd | 2005-10-25 14:09:51 -0500 | [diff] [blame] | 206 | * is large enough to contain a copy of their reserved page header and | 
|  | 207 | * part_nasids mask. | 
| Dean Nelson | 89eb8eb | 2005-03-23 19:50:00 -0700 | [diff] [blame] | 208 | */ | 
| Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 209 | enum xp_retval | 
| Dean Nelson | 04de741 | 2008-07-29 22:34:14 -0700 | [diff] [blame] | 210 | xpc_get_remote_rp(int nasid, unsigned long *discovered_nasids, | 
| Dean Nelson | a812dcc | 2008-07-29 22:34:16 -0700 | [diff] [blame] | 211 | struct xpc_rsvd_page *remote_rp, unsigned long *remote_rp_pa) | 
| Dean Nelson | 89eb8eb | 2005-03-23 19:50:00 -0700 | [diff] [blame] | 212 | { | 
| Dean Nelson | 04de741 | 2008-07-29 22:34:14 -0700 | [diff] [blame] | 213 | int l; | 
| Dean Nelson | 908787d | 2008-07-29 22:34:05 -0700 | [diff] [blame] | 214 | enum xp_retval ret; | 
| Dean Nelson | 89eb8eb | 2005-03-23 19:50:00 -0700 | [diff] [blame] | 215 |  | 
| Dean Nelson | 89eb8eb | 2005-03-23 19:50:00 -0700 | [diff] [blame] | 216 | /* get the reserved page's physical address */ | 
|  | 217 |  | 
| Dean Nelson | 2792902 | 2005-10-25 14:11:53 -0500 | [diff] [blame] | 218 | *remote_rp_pa = xpc_get_rsvd_page_pa(nasid); | 
| Dean Nelson | 2c2b94f | 2008-04-22 14:50:17 -0500 | [diff] [blame] | 219 | if (*remote_rp_pa == 0) | 
| Dean Nelson | 65c17b8 | 2008-05-12 14:02:02 -0700 | [diff] [blame] | 220 | return xpNoRsvdPageAddr; | 
| Dean Nelson | 89eb8eb | 2005-03-23 19:50:00 -0700 | [diff] [blame] | 221 |  | 
| Dean Nelson | 4b38fcd | 2005-10-25 14:09:51 -0500 | [diff] [blame] | 222 | /* pull over the reserved page header and part_nasids mask */ | 
| Dean Nelson | a812dcc | 2008-07-29 22:34:16 -0700 | [diff] [blame] | 223 | ret = xp_remote_memcpy(xp_pa(remote_rp), *remote_rp_pa, | 
| Dean Nelson | 04de741 | 2008-07-29 22:34:14 -0700 | [diff] [blame] | 224 | XPC_RP_HEADER_SIZE + xpc_nasid_mask_nbytes); | 
| Dean Nelson | 908787d | 2008-07-29 22:34:05 -0700 | [diff] [blame] | 225 | if (ret != xpSuccess) | 
|  | 226 | return ret; | 
| Dean Nelson | 89eb8eb | 2005-03-23 19:50:00 -0700 | [diff] [blame] | 227 |  | 
| Dean Nelson | 89eb8eb | 2005-03-23 19:50:00 -0700 | [diff] [blame] | 228 | if (discovered_nasids != NULL) { | 
| Dean Nelson | 04de741 | 2008-07-29 22:34:14 -0700 | [diff] [blame] | 229 | unsigned long *remote_part_nasids = | 
|  | 230 | XPC_RP_PART_NASIDS(remote_rp); | 
| Dean Nelson | 4b38fcd | 2005-10-25 14:09:51 -0500 | [diff] [blame] | 231 |  | 
| Dean Nelson | 04de741 | 2008-07-29 22:34:14 -0700 | [diff] [blame] | 232 | for (l = 0; l < xpc_nasid_mask_nlongs; l++) | 
|  | 233 | discovered_nasids[l] |= remote_part_nasids[l]; | 
| Dean Nelson | 89eb8eb | 2005-03-23 19:50:00 -0700 | [diff] [blame] | 234 | } | 
|  | 235 |  | 
| Dean Nelson | 81fe788 | 2008-07-29 22:34:15 -0700 | [diff] [blame] | 236 | /* zero timestamp indicates the reserved page has not been setup */ | 
|  | 237 | if (remote_rp->ts_jiffies == 0) | 
| Dean Nelson | 94bd270 | 2008-07-29 22:34:05 -0700 | [diff] [blame] | 238 | return xpRsvdPageNotSet; | 
|  | 239 |  | 
| Dean Nelson | 89eb8eb | 2005-03-23 19:50:00 -0700 | [diff] [blame] | 240 | if (XPC_VERSION_MAJOR(remote_rp->version) != | 
| Dean Nelson | 4a3ad2d | 2008-04-22 14:48:01 -0500 | [diff] [blame] | 241 | XPC_VERSION_MAJOR(XPC_RP_VERSION)) { | 
| Dean Nelson | 65c17b8 | 2008-05-12 14:02:02 -0700 | [diff] [blame] | 242 | return xpBadVersion; | 
| Dean Nelson | 89eb8eb | 2005-03-23 19:50:00 -0700 | [diff] [blame] | 243 | } | 
|  | 244 |  | 
| Dean Nelson | a47d5da | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 245 | /* check that both remote and local partids are valid for each side */ | 
| Dean Nelson | aaa3cd6 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 246 | if (remote_rp->SAL_partid < 0 || | 
|  | 247 | remote_rp->SAL_partid >= xp_max_npartitions || | 
| Dean Nelson | 261f3b4 | 2008-07-29 22:34:16 -0700 | [diff] [blame] | 248 | remote_rp->max_npartitions <= xp_partition_id) { | 
| Dean Nelson | 94bd270 | 2008-07-29 22:34:05 -0700 | [diff] [blame] | 249 | return xpInvalidPartid; | 
| Dean Nelson | aaa3cd6 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 250 | } | 
|  | 251 |  | 
| Dean Nelson | 261f3b4 | 2008-07-29 22:34:16 -0700 | [diff] [blame] | 252 | if (remote_rp->SAL_partid == xp_partition_id) | 
| Dean Nelson | aaa3cd6 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 253 | return xpLocalPartid; | 
| Dean Nelson | 94bd270 | 2008-07-29 22:34:05 -0700 | [diff] [blame] | 254 |  | 
| Dean Nelson | 65c17b8 | 2008-05-12 14:02:02 -0700 | [diff] [blame] | 255 | return xpSuccess; | 
| Dean Nelson | 89eb8eb | 2005-03-23 19:50:00 -0700 | [diff] [blame] | 256 | } | 
|  | 257 |  | 
| Dean Nelson | 89eb8eb | 2005-03-23 19:50:00 -0700 | [diff] [blame] | 258 | /* | 
| Dean Nelson | a47d5da | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 259 | * See if the other side has responded to a partition deactivate request | 
|  | 260 | * from us. Though we requested the remote partition to deactivate with regard | 
|  | 261 | * to us, we really only need to wait for the other side to disengage from us. | 
| Dean Nelson | a607c38 | 2005-09-01 14:01:37 -0500 | [diff] [blame] | 262 | */ | 
|  | 263 | int | 
|  | 264 | xpc_partition_disengaged(struct xpc_partition *part) | 
|  | 265 | { | 
| Dean Nelson | 64d032b | 2008-05-12 14:02:03 -0700 | [diff] [blame] | 266 | short partid = XPC_PARTID(part); | 
| Dean Nelson | a607c38 | 2005-09-01 14:01:37 -0500 | [diff] [blame] | 267 | int disengaged; | 
|  | 268 |  | 
| Robin Holt | a7665b0 | 2009-04-13 14:40:19 -0700 | [diff] [blame] | 269 | disengaged = !xpc_arch_ops.partition_engaged(partid); | 
| Dean Nelson | a47d5da | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 270 | if (part->disengage_timeout) { | 
| Dean Nelson | a607c38 | 2005-09-01 14:01:37 -0500 | [diff] [blame] | 271 | if (!disengaged) { | 
| Dean Nelson | a47d5da | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 272 | if (time_is_after_jiffies(part->disengage_timeout)) { | 
| Dean Nelson | a607c38 | 2005-09-01 14:01:37 -0500 | [diff] [blame] | 273 | /* timelimit hasn't been reached yet */ | 
|  | 274 | return 0; | 
|  | 275 | } | 
|  | 276 |  | 
|  | 277 | /* | 
| Dean Nelson | a47d5da | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 278 | * Other side hasn't responded to our deactivate | 
| Dean Nelson | a607c38 | 2005-09-01 14:01:37 -0500 | [diff] [blame] | 279 | * request in a timely fashion, so assume it's dead. | 
|  | 280 | */ | 
|  | 281 |  | 
| Dean Nelson | a47d5da | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 282 | dev_info(xpc_part, "deactivate request to remote " | 
|  | 283 | "partition %d timed out\n", partid); | 
|  | 284 | xpc_disengage_timedout = 1; | 
| Robin Holt | a7665b0 | 2009-04-13 14:40:19 -0700 | [diff] [blame] | 285 | xpc_arch_ops.assume_partition_disengaged(partid); | 
| Dean Nelson | a607c38 | 2005-09-01 14:01:37 -0500 | [diff] [blame] | 286 | disengaged = 1; | 
|  | 287 | } | 
| Dean Nelson | a47d5da | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 288 | part->disengage_timeout = 0; | 
| Dean Nelson | a607c38 | 2005-09-01 14:01:37 -0500 | [diff] [blame] | 289 |  | 
|  | 290 | /* cancel the timer function, provided it's not us */ | 
| Dean Nelson | a47d5da | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 291 | if (!in_interrupt()) | 
|  | 292 | del_singleshot_timer_sync(&part->disengage_timer); | 
| Dean Nelson | a607c38 | 2005-09-01 14:01:37 -0500 | [diff] [blame] | 293 |  | 
| Dean Nelson | 83469b5 | 2008-07-29 22:34:18 -0700 | [diff] [blame] | 294 | DBUG_ON(part->act_state != XPC_P_AS_DEACTIVATING && | 
|  | 295 | part->act_state != XPC_P_AS_INACTIVE); | 
|  | 296 | if (part->act_state != XPC_P_AS_INACTIVE) | 
| Dean Nelson | a607c38 | 2005-09-01 14:01:37 -0500 | [diff] [blame] | 297 | xpc_wakeup_channel_mgr(part); | 
| Dean Nelson | a607c38 | 2005-09-01 14:01:37 -0500 | [diff] [blame] | 298 |  | 
| Robin Holt | a7665b0 | 2009-04-13 14:40:19 -0700 | [diff] [blame] | 299 | xpc_arch_ops.cancel_partition_deactivation_request(part); | 
| Dean Nelson | a607c38 | 2005-09-01 14:01:37 -0500 | [diff] [blame] | 300 | } | 
|  | 301 | return disengaged; | 
|  | 302 | } | 
|  | 303 |  | 
| Dean Nelson | a607c38 | 2005-09-01 14:01:37 -0500 | [diff] [blame] | 304 | /* | 
| Dean Nelson | 89eb8eb | 2005-03-23 19:50:00 -0700 | [diff] [blame] | 305 | * Mark specified partition as active. | 
|  | 306 | */ | 
| Dean Nelson | 65c17b8 | 2008-05-12 14:02:02 -0700 | [diff] [blame] | 307 | enum xp_retval | 
| Dean Nelson | 89eb8eb | 2005-03-23 19:50:00 -0700 | [diff] [blame] | 308 | xpc_mark_partition_active(struct xpc_partition *part) | 
|  | 309 | { | 
|  | 310 | unsigned long irq_flags; | 
| Dean Nelson | 65c17b8 | 2008-05-12 14:02:02 -0700 | [diff] [blame] | 311 | enum xp_retval ret; | 
| Dean Nelson | 89eb8eb | 2005-03-23 19:50:00 -0700 | [diff] [blame] | 312 |  | 
| Dean Nelson | 89eb8eb | 2005-03-23 19:50:00 -0700 | [diff] [blame] | 313 | dev_dbg(xpc_part, "setting partition %d to ACTIVE\n", XPC_PARTID(part)); | 
|  | 314 |  | 
|  | 315 | spin_lock_irqsave(&part->act_lock, irq_flags); | 
| Dean Nelson | 83469b5 | 2008-07-29 22:34:18 -0700 | [diff] [blame] | 316 | if (part->act_state == XPC_P_AS_ACTIVATING) { | 
|  | 317 | part->act_state = XPC_P_AS_ACTIVE; | 
| Dean Nelson | 65c17b8 | 2008-05-12 14:02:02 -0700 | [diff] [blame] | 318 | ret = xpSuccess; | 
| Dean Nelson | 89eb8eb | 2005-03-23 19:50:00 -0700 | [diff] [blame] | 319 | } else { | 
| Dean Nelson | 65c17b8 | 2008-05-12 14:02:02 -0700 | [diff] [blame] | 320 | DBUG_ON(part->reason == xpSuccess); | 
| Dean Nelson | 89eb8eb | 2005-03-23 19:50:00 -0700 | [diff] [blame] | 321 | ret = part->reason; | 
|  | 322 | } | 
|  | 323 | spin_unlock_irqrestore(&part->act_lock, irq_flags); | 
|  | 324 |  | 
|  | 325 | return ret; | 
|  | 326 | } | 
|  | 327 |  | 
| Dean Nelson | 89eb8eb | 2005-03-23 19:50:00 -0700 | [diff] [blame] | 328 | /* | 
| Dean Nelson | a47d5da | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 329 | * Start the process of deactivating the specified partition. | 
| Dean Nelson | 89eb8eb | 2005-03-23 19:50:00 -0700 | [diff] [blame] | 330 | */ | 
|  | 331 | void | 
|  | 332 | xpc_deactivate_partition(const int line, struct xpc_partition *part, | 
| Dean Nelson | 65c17b8 | 2008-05-12 14:02:02 -0700 | [diff] [blame] | 333 | enum xp_retval reason) | 
| Dean Nelson | 89eb8eb | 2005-03-23 19:50:00 -0700 | [diff] [blame] | 334 | { | 
|  | 335 | unsigned long irq_flags; | 
| Dean Nelson | 89eb8eb | 2005-03-23 19:50:00 -0700 | [diff] [blame] | 336 |  | 
| Dean Nelson | 89eb8eb | 2005-03-23 19:50:00 -0700 | [diff] [blame] | 337 | spin_lock_irqsave(&part->act_lock, irq_flags); | 
|  | 338 |  | 
| Dean Nelson | 83469b5 | 2008-07-29 22:34:18 -0700 | [diff] [blame] | 339 | if (part->act_state == XPC_P_AS_INACTIVE) { | 
| Dean Nelson | 89eb8eb | 2005-03-23 19:50:00 -0700 | [diff] [blame] | 340 | XPC_SET_REASON(part, reason, line); | 
|  | 341 | spin_unlock_irqrestore(&part->act_lock, irq_flags); | 
| Dean Nelson | 65c17b8 | 2008-05-12 14:02:02 -0700 | [diff] [blame] | 342 | if (reason == xpReactivating) { | 
| Dean Nelson | 89eb8eb | 2005-03-23 19:50:00 -0700 | [diff] [blame] | 343 | /* we interrupt ourselves to reactivate partition */ | 
| Robin Holt | a7665b0 | 2009-04-13 14:40:19 -0700 | [diff] [blame] | 344 | xpc_arch_ops.request_partition_reactivation(part); | 
| Dean Nelson | 89eb8eb | 2005-03-23 19:50:00 -0700 | [diff] [blame] | 345 | } | 
|  | 346 | return; | 
|  | 347 | } | 
| Dean Nelson | 83469b5 | 2008-07-29 22:34:18 -0700 | [diff] [blame] | 348 | if (part->act_state == XPC_P_AS_DEACTIVATING) { | 
| Dean Nelson | 65c17b8 | 2008-05-12 14:02:02 -0700 | [diff] [blame] | 349 | if ((part->reason == xpUnloading && reason != xpUnloading) || | 
|  | 350 | reason == xpReactivating) { | 
| Dean Nelson | 89eb8eb | 2005-03-23 19:50:00 -0700 | [diff] [blame] | 351 | XPC_SET_REASON(part, reason, line); | 
|  | 352 | } | 
|  | 353 | spin_unlock_irqrestore(&part->act_lock, irq_flags); | 
|  | 354 | return; | 
|  | 355 | } | 
|  | 356 |  | 
| Dean Nelson | 83469b5 | 2008-07-29 22:34:18 -0700 | [diff] [blame] | 357 | part->act_state = XPC_P_AS_DEACTIVATING; | 
| Dean Nelson | 89eb8eb | 2005-03-23 19:50:00 -0700 | [diff] [blame] | 358 | XPC_SET_REASON(part, reason, line); | 
|  | 359 |  | 
|  | 360 | spin_unlock_irqrestore(&part->act_lock, irq_flags); | 
|  | 361 |  | 
| Dean Nelson | a47d5da | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 362 | /* ask remote partition to deactivate with regard to us */ | 
| Robin Holt | a7665b0 | 2009-04-13 14:40:19 -0700 | [diff] [blame] | 363 | xpc_arch_ops.request_partition_deactivation(part); | 
| Dean Nelson | 89eb8eb | 2005-03-23 19:50:00 -0700 | [diff] [blame] | 364 |  | 
| Dean Nelson | a47d5da | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 365 | /* set a timelimit on the disengage phase of the deactivation request */ | 
|  | 366 | part->disengage_timeout = jiffies + (xpc_disengage_timelimit * HZ); | 
|  | 367 | part->disengage_timer.expires = part->disengage_timeout; | 
|  | 368 | add_timer(&part->disengage_timer); | 
| Dean Nelson | 89eb8eb | 2005-03-23 19:50:00 -0700 | [diff] [blame] | 369 |  | 
| Dean Nelson | e54af72 | 2005-10-25 14:07:43 -0500 | [diff] [blame] | 370 | dev_dbg(xpc_part, "bringing partition %d down, reason = %d\n", | 
|  | 371 | XPC_PARTID(part), reason); | 
| Dean Nelson | 89eb8eb | 2005-03-23 19:50:00 -0700 | [diff] [blame] | 372 |  | 
| Dean Nelson | a607c38 | 2005-09-01 14:01:37 -0500 | [diff] [blame] | 373 | xpc_partition_going_down(part, reason); | 
| Dean Nelson | 89eb8eb | 2005-03-23 19:50:00 -0700 | [diff] [blame] | 374 | } | 
|  | 375 |  | 
| Dean Nelson | 89eb8eb | 2005-03-23 19:50:00 -0700 | [diff] [blame] | 376 | /* | 
| Dean Nelson | a607c38 | 2005-09-01 14:01:37 -0500 | [diff] [blame] | 377 | * Mark specified partition as inactive. | 
| Dean Nelson | 89eb8eb | 2005-03-23 19:50:00 -0700 | [diff] [blame] | 378 | */ | 
|  | 379 | void | 
|  | 380 | xpc_mark_partition_inactive(struct xpc_partition *part) | 
|  | 381 | { | 
|  | 382 | unsigned long irq_flags; | 
|  | 383 |  | 
| Dean Nelson | 89eb8eb | 2005-03-23 19:50:00 -0700 | [diff] [blame] | 384 | dev_dbg(xpc_part, "setting partition %d to INACTIVE\n", | 
|  | 385 | XPC_PARTID(part)); | 
|  | 386 |  | 
|  | 387 | spin_lock_irqsave(&part->act_lock, irq_flags); | 
| Dean Nelson | 83469b5 | 2008-07-29 22:34:18 -0700 | [diff] [blame] | 388 | part->act_state = XPC_P_AS_INACTIVE; | 
| Dean Nelson | 89eb8eb | 2005-03-23 19:50:00 -0700 | [diff] [blame] | 389 | spin_unlock_irqrestore(&part->act_lock, irq_flags); | 
|  | 390 | part->remote_rp_pa = 0; | 
|  | 391 | } | 
|  | 392 |  | 
| Dean Nelson | 89eb8eb | 2005-03-23 19:50:00 -0700 | [diff] [blame] | 393 | /* | 
|  | 394 | * SAL has provided a partition and machine mask.  The partition mask | 
|  | 395 | * contains a bit for each even nasid in our partition.  The machine | 
|  | 396 | * mask contains a bit for each even nasid in the entire machine. | 
|  | 397 | * | 
|  | 398 | * Using those two bit arrays, we can determine which nasids are | 
|  | 399 | * known in the machine.  Each should also have a reserved page | 
|  | 400 | * initialized if they are available for partitioning. | 
|  | 401 | */ | 
|  | 402 | void | 
|  | 403 | xpc_discovery(void) | 
|  | 404 | { | 
|  | 405 | void *remote_rp_base; | 
|  | 406 | struct xpc_rsvd_page *remote_rp; | 
| Dean Nelson | a812dcc | 2008-07-29 22:34:16 -0700 | [diff] [blame] | 407 | unsigned long remote_rp_pa; | 
| Dean Nelson | 89eb8eb | 2005-03-23 19:50:00 -0700 | [diff] [blame] | 408 | int region; | 
| Dean Nelson | 4b38fcd | 2005-10-25 14:09:51 -0500 | [diff] [blame] | 409 | int region_size; | 
| Dean Nelson | 89eb8eb | 2005-03-23 19:50:00 -0700 | [diff] [blame] | 410 | int max_regions; | 
|  | 411 | int nasid; | 
|  | 412 | struct xpc_rsvd_page *rp; | 
| Dean Nelson | 04de741 | 2008-07-29 22:34:14 -0700 | [diff] [blame] | 413 | unsigned long *discovered_nasids; | 
| Dean Nelson | 65c17b8 | 2008-05-12 14:02:02 -0700 | [diff] [blame] | 414 | enum xp_retval ret; | 
| Dean Nelson | 89eb8eb | 2005-03-23 19:50:00 -0700 | [diff] [blame] | 415 |  | 
| Dean Nelson | 4b38fcd | 2005-10-25 14:09:51 -0500 | [diff] [blame] | 416 | remote_rp = xpc_kmalloc_cacheline_aligned(XPC_RP_HEADER_SIZE + | 
| Dean Nelson | 04de741 | 2008-07-29 22:34:14 -0700 | [diff] [blame] | 417 | xpc_nasid_mask_nbytes, | 
| Dean Nelson | 4a3ad2d | 2008-04-22 14:48:01 -0500 | [diff] [blame] | 418 | GFP_KERNEL, &remote_rp_base); | 
| Dean Nelson | 2c2b94f | 2008-04-22 14:50:17 -0500 | [diff] [blame] | 419 | if (remote_rp == NULL) | 
| Dean Nelson | 89eb8eb | 2005-03-23 19:50:00 -0700 | [diff] [blame] | 420 | return; | 
| Dean Nelson | 2c2b94f | 2008-04-22 14:50:17 -0500 | [diff] [blame] | 421 |  | 
| Dean Nelson | 04de741 | 2008-07-29 22:34:14 -0700 | [diff] [blame] | 422 | discovered_nasids = kzalloc(sizeof(long) * xpc_nasid_mask_nlongs, | 
| Dean Nelson | 4a3ad2d | 2008-04-22 14:48:01 -0500 | [diff] [blame] | 423 | GFP_KERNEL); | 
| Dean Nelson | 89eb8eb | 2005-03-23 19:50:00 -0700 | [diff] [blame] | 424 | if (discovered_nasids == NULL) { | 
|  | 425 | kfree(remote_rp_base); | 
|  | 426 | return; | 
|  | 427 | } | 
| Dean Nelson | 89eb8eb | 2005-03-23 19:50:00 -0700 | [diff] [blame] | 428 |  | 
| Dean Nelson | 4a3ad2d | 2008-04-22 14:48:01 -0500 | [diff] [blame] | 429 | rp = (struct xpc_rsvd_page *)xpc_rsvd_page; | 
| Dean Nelson | 89eb8eb | 2005-03-23 19:50:00 -0700 | [diff] [blame] | 430 |  | 
|  | 431 | /* | 
|  | 432 | * The term 'region' in this context refers to the minimum number of | 
|  | 433 | * nodes that can comprise an access protection grouping. The access | 
|  | 434 | * protection is in regards to memory, IOI and IPI. | 
|  | 435 | */ | 
| Dean Nelson | 4b38fcd | 2005-10-25 14:09:51 -0500 | [diff] [blame] | 436 | max_regions = 64; | 
| Dean Nelson | 261f3b4 | 2008-07-29 22:34:16 -0700 | [diff] [blame] | 437 | region_size = xp_region_size; | 
| Dean Nelson | 4b38fcd | 2005-10-25 14:09:51 -0500 | [diff] [blame] | 438 |  | 
|  | 439 | switch (region_size) { | 
|  | 440 | case 128: | 
|  | 441 | max_regions *= 2; | 
|  | 442 | case 64: | 
|  | 443 | max_regions *= 2; | 
|  | 444 | case 32: | 
|  | 445 | max_regions *= 2; | 
|  | 446 | region_size = 16; | 
|  | 447 | DBUG_ON(!is_shub2()); | 
|  | 448 | } | 
| Dean Nelson | 89eb8eb | 2005-03-23 19:50:00 -0700 | [diff] [blame] | 449 |  | 
|  | 450 | for (region = 0; region < max_regions; region++) { | 
|  | 451 |  | 
| Dean Nelson | 2c2b94f | 2008-04-22 14:50:17 -0500 | [diff] [blame] | 452 | if (xpc_exiting) | 
| Dean Nelson | 89eb8eb | 2005-03-23 19:50:00 -0700 | [diff] [blame] | 453 | break; | 
| Dean Nelson | 89eb8eb | 2005-03-23 19:50:00 -0700 | [diff] [blame] | 454 |  | 
|  | 455 | dev_dbg(xpc_part, "searching region %d\n", region); | 
|  | 456 |  | 
| Dean Nelson | 4b38fcd | 2005-10-25 14:09:51 -0500 | [diff] [blame] | 457 | for (nasid = (region * region_size * 2); | 
| Dean Nelson | 4a3ad2d | 2008-04-22 14:48:01 -0500 | [diff] [blame] | 458 | nasid < ((region + 1) * region_size * 2); nasid += 2) { | 
| Dean Nelson | 89eb8eb | 2005-03-23 19:50:00 -0700 | [diff] [blame] | 459 |  | 
| Dean Nelson | 2c2b94f | 2008-04-22 14:50:17 -0500 | [diff] [blame] | 460 | if (xpc_exiting) | 
| Dean Nelson | 89eb8eb | 2005-03-23 19:50:00 -0700 | [diff] [blame] | 461 | break; | 
| Dean Nelson | 89eb8eb | 2005-03-23 19:50:00 -0700 | [diff] [blame] | 462 |  | 
|  | 463 | dev_dbg(xpc_part, "checking nasid %d\n", nasid); | 
|  | 464 |  | 
| Dean Nelson | 04de741 | 2008-07-29 22:34:14 -0700 | [diff] [blame] | 465 | if (test_bit(nasid / 2, xpc_part_nasids)) { | 
| Dean Nelson | 89eb8eb | 2005-03-23 19:50:00 -0700 | [diff] [blame] | 466 | dev_dbg(xpc_part, "PROM indicates Nasid %d is " | 
|  | 467 | "part of the local partition; skipping " | 
|  | 468 | "region\n", nasid); | 
|  | 469 | break; | 
|  | 470 | } | 
|  | 471 |  | 
| Dean Nelson | 04de741 | 2008-07-29 22:34:14 -0700 | [diff] [blame] | 472 | if (!(test_bit(nasid / 2, xpc_mach_nasids))) { | 
| Dean Nelson | 89eb8eb | 2005-03-23 19:50:00 -0700 | [diff] [blame] | 473 | dev_dbg(xpc_part, "PROM indicates Nasid %d was " | 
|  | 474 | "not on Numa-Link network at reset\n", | 
|  | 475 | nasid); | 
|  | 476 | continue; | 
|  | 477 | } | 
|  | 478 |  | 
| Dean Nelson | 04de741 | 2008-07-29 22:34:14 -0700 | [diff] [blame] | 479 | if (test_bit(nasid / 2, discovered_nasids)) { | 
| Dean Nelson | 89eb8eb | 2005-03-23 19:50:00 -0700 | [diff] [blame] | 480 | dev_dbg(xpc_part, "Nasid %d is part of a " | 
|  | 481 | "partition which was previously " | 
|  | 482 | "discovered\n", nasid); | 
|  | 483 | continue; | 
|  | 484 | } | 
|  | 485 |  | 
| Dean Nelson | 33ba3c7 | 2008-07-29 22:34:07 -0700 | [diff] [blame] | 486 | /* pull over the rsvd page header & part_nasids mask */ | 
| Dean Nelson | 89eb8eb | 2005-03-23 19:50:00 -0700 | [diff] [blame] | 487 |  | 
|  | 488 | ret = xpc_get_remote_rp(nasid, discovered_nasids, | 
| Dean Nelson | 4a3ad2d | 2008-04-22 14:48:01 -0500 | [diff] [blame] | 489 | remote_rp, &remote_rp_pa); | 
| Dean Nelson | 65c17b8 | 2008-05-12 14:02:02 -0700 | [diff] [blame] | 490 | if (ret != xpSuccess) { | 
| Dean Nelson | 89eb8eb | 2005-03-23 19:50:00 -0700 | [diff] [blame] | 491 | dev_dbg(xpc_part, "unable to get reserved page " | 
|  | 492 | "from nasid %d, reason=%d\n", nasid, | 
|  | 493 | ret); | 
|  | 494 |  | 
| Dean Nelson | 65c17b8 | 2008-05-12 14:02:02 -0700 | [diff] [blame] | 495 | if (ret == xpLocalPartid) | 
| Dean Nelson | 89eb8eb | 2005-03-23 19:50:00 -0700 | [diff] [blame] | 496 | break; | 
| Dean Nelson | 2c2b94f | 2008-04-22 14:50:17 -0500 | [diff] [blame] | 497 |  | 
| Dean Nelson | 89eb8eb | 2005-03-23 19:50:00 -0700 | [diff] [blame] | 498 | continue; | 
|  | 499 | } | 
|  | 500 |  | 
| Robin Holt | a7665b0 | 2009-04-13 14:40:19 -0700 | [diff] [blame] | 501 | xpc_arch_ops.request_partition_activation(remote_rp, | 
| Dean Nelson | a47d5da | 2008-07-29 22:34:09 -0700 | [diff] [blame] | 502 | remote_rp_pa, nasid); | 
| Dean Nelson | 89eb8eb | 2005-03-23 19:50:00 -0700 | [diff] [blame] | 503 | } | 
|  | 504 | } | 
|  | 505 |  | 
|  | 506 | kfree(discovered_nasids); | 
|  | 507 | kfree(remote_rp_base); | 
|  | 508 | } | 
|  | 509 |  | 
| Dean Nelson | 89eb8eb | 2005-03-23 19:50:00 -0700 | [diff] [blame] | 510 | /* | 
|  | 511 | * Given a partid, get the nasids owned by that partition from the | 
| Dean Nelson | 3a7d555 | 2005-04-04 13:14:00 -0700 | [diff] [blame] | 512 | * remote partition's reserved page. | 
| Dean Nelson | 89eb8eb | 2005-03-23 19:50:00 -0700 | [diff] [blame] | 513 | */ | 
| Dean Nelson | 65c17b8 | 2008-05-12 14:02:02 -0700 | [diff] [blame] | 514 | enum xp_retval | 
| Dean Nelson | 64d032b | 2008-05-12 14:02:03 -0700 | [diff] [blame] | 515 | xpc_initiate_partid_to_nasids(short partid, void *nasid_mask) | 
| Dean Nelson | 89eb8eb | 2005-03-23 19:50:00 -0700 | [diff] [blame] | 516 | { | 
|  | 517 | struct xpc_partition *part; | 
| Dean Nelson | a812dcc | 2008-07-29 22:34:16 -0700 | [diff] [blame] | 518 | unsigned long part_nasid_pa; | 
| Dean Nelson | 89eb8eb | 2005-03-23 19:50:00 -0700 | [diff] [blame] | 519 |  | 
| Dean Nelson | 89eb8eb | 2005-03-23 19:50:00 -0700 | [diff] [blame] | 520 | part = &xpc_partitions[partid]; | 
| Dean Nelson | 2c2b94f | 2008-04-22 14:50:17 -0500 | [diff] [blame] | 521 | if (part->remote_rp_pa == 0) | 
| Dean Nelson | 65c17b8 | 2008-05-12 14:02:02 -0700 | [diff] [blame] | 522 | return xpPartitionDown; | 
| Dean Nelson | 89eb8eb | 2005-03-23 19:50:00 -0700 | [diff] [blame] | 523 |  | 
| Dean Nelson | 04de741 | 2008-07-29 22:34:14 -0700 | [diff] [blame] | 524 | memset(nasid_mask, 0, xpc_nasid_mask_nbytes); | 
| Dean Nelson | 4b38fcd | 2005-10-25 14:09:51 -0500 | [diff] [blame] | 525 |  | 
| Dean Nelson | a812dcc | 2008-07-29 22:34:16 -0700 | [diff] [blame] | 526 | part_nasid_pa = (unsigned long)XPC_RP_PART_NASIDS(part->remote_rp_pa); | 
| Dean Nelson | 89eb8eb | 2005-03-23 19:50:00 -0700 | [diff] [blame] | 527 |  | 
| Dean Nelson | a812dcc | 2008-07-29 22:34:16 -0700 | [diff] [blame] | 528 | return xp_remote_memcpy(xp_pa(nasid_mask), part_nasid_pa, | 
| Dean Nelson | 04de741 | 2008-07-29 22:34:14 -0700 | [diff] [blame] | 529 | xpc_nasid_mask_nbytes); | 
| Dean Nelson | 89eb8eb | 2005-03-23 19:50:00 -0700 | [diff] [blame] | 530 | } |