Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge tag 'powerpc-3.19-2' of git://git.kernel.org/pub/scm/linux/kernel/git/mpe/linux

Pull second batch of powerpc updates from Michael Ellerman:
"The highlight is the series that reworks the idle management on
powernv, which allows us to use deeper idle states on those machines.

There's the fix from Anton for the "BUG at kernel/smpboot.c:134!"
problem.

An i2c driver for powernv. This is acked by Wolfram Sang, and he
asked that we take it through the powerpc tree.

A fix for audit from rgb at Red Hat, acked by Paul Moore who is one of
the audit maintainers.

A patch from Ben to export the symbol map of our OPAL firmware as a
sysfs file, so that tools can use it.

Also some CXL fixes, a couple of powerpc perf fixes, a fix for
smt-enabled, and the patch to add __force to get_user() so we can use
bitwise types"

* tag 'powerpc-3.19-2' of git://git.kernel.org/pub/scm/linux/kernel/git/mpe/linux:
powerpc/powernv: Ignore smt-enabled on Power8 and later
powerpc/uaccess: Allow get_user() with bitwise types
powerpc/powernv: Expose OPAL firmware symbol map
powernv/powerpc: Add winkle support for offline cpus
powernv/cpuidle: Redesign idle states management
powerpc/powernv: Enable Offline CPUs to enter deep idle states
powerpc/powernv: Switch off MMU before entering nap/sleep/rvwinkle mode
i2c: Driver to expose PowerNV platform i2c busses
powerpc: add little endian flag to syscall_get_arch()
power/perf/hv-24x7: Use kmem_cache_free() instead of kfree
powerpc/perf/hv-24x7: Use per-cpu page buffer
cxl: Unmap MMIO regions when detaching a context
cxl: Add timeout to process element commands
cxl: Change contexts_lock to a mutex to fix sleep while atomic bug
powerpc: Secondary CPUs must set cpu_callin_map after setting active and online

+1157 -109
+37
Documentation/devicetree/bindings/i2c/i2c-opal.txt
··· 1 + Device-tree bindings for I2C OPAL driver 2 + ---------------------------------------- 3 + 4 + Most of the device node and properties layout is specific to the firmware and 5 + used by the firmware itself for configuring the port. From the linux 6 + perspective, the properties of use are "ibm,port-name" and "ibm,opal-id". 7 + 8 + Required properties: 9 + 10 + - reg: Port-id within a given master 11 + - compatible: must be "ibm,opal-i2c" 12 + - ibm,opal-id: Refers to a specific bus and used to identify it when calling 13 + the relevant OPAL functions. 14 + - bus-frequency: Operating frequency of the i2c bus (in HZ). Informational for 15 + linux, used by the FW though. 16 + 17 + Optional properties: 18 + - ibm,port-name: Firmware provides this name that uniquely identifies the i2c 19 + port. 20 + 21 + The node contains a number of other properties that are used by the FW itself 22 + and depend on the specific hardware implementation. The example below depicts 23 + a P8 on-chip bus. 24 + 25 + Example: 26 + 27 + i2c-bus@0 { 28 + reg = <0x0>; 29 + bus-frequency = <0x61a80>; 30 + compatible = "ibm,power8-i2c-port", "ibm,opal-i2c"; 31 + ibm,opal-id = <0x1>; 32 + ibm,port-name = "p8_00000000_e1p0"; 33 + #address-cells = <0x1>; 34 + phandle = <0x10000006>; 35 + #size-cells = <0x0>; 36 + linux,phandle = <0x10000006>; 37 + };
+20
arch/powerpc/include/asm/cpuidle.h
··· 1 + #ifndef _ASM_POWERPC_CPUIDLE_H 2 + #define _ASM_POWERPC_CPUIDLE_H 3 + 4 + #ifdef CONFIG_PPC_POWERNV 5 + /* Used in powernv idle state management */ 6 + #define PNV_THREAD_RUNNING 0 7 + #define PNV_THREAD_NAP 1 8 + #define PNV_THREAD_SLEEP 2 9 + #define PNV_THREAD_WINKLE 3 10 + #define PNV_CORE_IDLE_LOCK_BIT 0x100 11 + #define PNV_CORE_IDLE_THREAD_BITS 0x0FF 12 + 13 + #ifndef __ASSEMBLY__ 14 + extern u32 pnv_fastsleep_workaround_at_entry[]; 15 + extern u32 pnv_fastsleep_workaround_at_exit[]; 16 + #endif 17 + 18 + #endif 19 + 20 + #endif
+42
arch/powerpc/include/asm/opal.h
··· 56 56 #define OPAL_HARDWARE_FROZEN -13 57 57 #define OPAL_WRONG_STATE -14 58 58 #define OPAL_ASYNC_COMPLETION -15 59 + #define OPAL_I2C_TIMEOUT -17 60 + #define OPAL_I2C_INVALID_CMD -18 61 + #define OPAL_I2C_LBUS_PARITY -19 62 + #define OPAL_I2C_BKEND_OVERRUN -20 63 + #define OPAL_I2C_BKEND_ACCESS -21 64 + #define OPAL_I2C_ARBT_LOST -22 65 + #define OPAL_I2C_NACK_RCVD -23 66 + #define OPAL_I2C_STOP_ERR -24 59 67 60 68 /* API Tokens (in r0) */ 61 69 #define OPAL_INVALID_CALL -1 ··· 160 152 #define OPAL_PCI_ERR_INJECT 96 161 153 #define OPAL_PCI_EEH_FREEZE_SET 97 162 154 #define OPAL_HANDLE_HMI 98 155 + #define OPAL_CONFIG_CPU_IDLE_STATE 99 156 + #define OPAL_SLW_SET_REG 100 163 157 #define OPAL_REGISTER_DUMP_REGION 101 164 158 #define OPAL_UNREGISTER_DUMP_REGION 102 165 159 #define OPAL_WRITE_TPO 103 166 160 #define OPAL_READ_TPO 104 167 161 #define OPAL_IPMI_SEND 107 168 162 #define OPAL_IPMI_RECV 108 163 + #define OPAL_I2C_REQUEST 109 164 + 165 + /* Device tree flags */ 166 + 167 + /* Flags set in power-mgmt nodes in device tree if 168 + * respective idle states are supported in the platform. 169 + */ 170 + #define OPAL_PM_NAP_ENABLED 0x00010000 171 + #define OPAL_PM_SLEEP_ENABLED 0x00020000 172 + #define OPAL_PM_WINKLE_ENABLED 0x00040000 173 + #define OPAL_PM_SLEEP_ENABLED_ER1 0x00080000 169 174 170 175 #ifndef __ASSEMBLY__ 171 176 ··· 733 712 uint64_t line_len; 734 713 } oppanel_line_t; 735 714 715 + /* OPAL I2C request */ 716 + struct opal_i2c_request { 717 + uint8_t type; 718 + #define OPAL_I2C_RAW_READ 0 719 + #define OPAL_I2C_RAW_WRITE 1 720 + #define OPAL_I2C_SM_READ 2 721 + #define OPAL_I2C_SM_WRITE 3 722 + uint8_t flags; 723 + #define OPAL_I2C_ADDR_10 0x01 /* Not supported yet */ 724 + uint8_t subaddr_sz; /* Max 4 */ 725 + uint8_t reserved; 726 + __be16 addr; /* 7 or 10 bit address */ 727 + __be16 reserved2; 728 + __be32 subaddr; /* Sub-address if any */ 729 + __be32 size; /* Data size */ 730 + __be64 buffer_ra; /* Buffer real address */ 731 + }; 732 + 736 733 /* /sys/firmware/opal */ 737 734 extern struct kobject *opal_kobj; 738 735 ··· 915 876 int64_t opal_handle_hmi(void); 916 877 int64_t opal_register_dump_region(uint32_t id, uint64_t start, uint64_t end); 917 878 int64_t opal_unregister_dump_region(uint32_t id); 879 + int64_t opal_slw_set_reg(uint64_t cpu_pir, uint64_t sprn, uint64_t val); 918 880 int64_t opal_pci_set_phb_cxl_mode(uint64_t phb_id, uint64_t mode, uint64_t pe_number); 919 881 int64_t opal_ipmi_send(uint64_t interface, struct opal_ipmi_msg *msg, 920 882 uint64_t msg_len); 921 883 int64_t opal_ipmi_recv(uint64_t interface, struct opal_ipmi_msg *msg, 922 884 uint64_t *msg_len); 885 + int64_t opal_i2c_request(uint64_t async_token, uint32_t bus_id, 886 + struct opal_i2c_request *oreq); 923 887 924 888 /* Internal functions */ 925 889 extern int early_init_dt_scan_opal(unsigned long node, const char *uname,
+10
arch/powerpc/include/asm/paca.h
··· 152 152 u64 tm_scratch; /* TM scratch area for reclaim */ 153 153 #endif 154 154 155 + #ifdef CONFIG_PPC_POWERNV 156 + /* Per-core mask tracking idle threads and a lock bit-[L][TTTTTTTT] */ 157 + u32 *core_idle_state_ptr; 158 + u8 thread_idle_state; /* PNV_THREAD_RUNNING/NAP/SLEEP */ 159 + /* Mask to indicate thread id in core */ 160 + u8 thread_mask; 161 + /* Mask to denote subcore sibling threads */ 162 + u8 subcore_sibling_mask; 163 + #endif 164 + 155 165 #ifdef CONFIG_PPC_BOOK3S_64 156 166 /* Exclusive emergency stack pointer for machine check exception. */ 157 167 void *mc_emergency_sp;
+2
arch/powerpc/include/asm/ppc-opcode.h
··· 194 194 195 195 #define PPC_INST_NAP 0x4c000364 196 196 #define PPC_INST_SLEEP 0x4c0003a4 197 + #define PPC_INST_WINKLE 0x4c0003e4 197 198 198 199 /* A2 specific instructions */ 199 200 #define PPC_INST_ERATWE 0x7c0001a6 ··· 376 375 377 376 #define PPC_NAP stringify_in_c(.long PPC_INST_NAP) 378 377 #define PPC_SLEEP stringify_in_c(.long PPC_INST_SLEEP) 378 + #define PPC_WINKLE stringify_in_c(.long PPC_INST_WINKLE) 379 379 380 380 /* BHRB instructions */ 381 381 #define PPC_CLRBHRB stringify_in_c(.long PPC_INST_CLRBHRB)
+2 -1
arch/powerpc/include/asm/processor.h
··· 452 452 453 453 extern int powersave_nap; /* set if nap mode can be used in idle loop */ 454 454 extern unsigned long power7_nap(int check_irq); 455 - extern void power7_sleep(void); 455 + extern unsigned long power7_sleep(void); 456 + extern unsigned long power7_winkle(void); 456 457 extern void flush_instruction_cache(void); 457 458 extern void hard_reset_now(void); 458 459 extern void poweroff_now(void);
+4
arch/powerpc/include/asm/reg.h
··· 118 118 #define __MSR (MSR_ME | MSR_RI | MSR_IR | MSR_DR | MSR_ISF |MSR_HV) 119 119 #ifdef __BIG_ENDIAN__ 120 120 #define MSR_ __MSR 121 + #define MSR_IDLE (MSR_ME | MSR_SF | MSR_HV) 121 122 #else 122 123 #define MSR_ (__MSR | MSR_LE) 124 + #define MSR_IDLE (MSR_ME | MSR_SF | MSR_HV | MSR_LE) 123 125 #endif 124 126 #define MSR_KERNEL (MSR_ | MSR_64BIT) 125 127 #define MSR_USER32 (MSR_ | MSR_PR | MSR_EE) ··· 373 371 #define SPRN_DBAT7L 0x23F /* Data BAT 7 Lower Register */ 374 372 #define SPRN_DBAT7U 0x23E /* Data BAT 7 Upper Register */ 375 373 #define SPRN_PPR 0x380 /* SMT Thread status Register */ 374 + #define SPRN_TSCR 0x399 /* Thread Switch Control Register */ 376 375 377 376 #define SPRN_DEC 0x016 /* Decrement Register */ 378 377 #define SPRN_DER 0x095 /* Debug Enable Regsiter */ ··· 731 728 #define SPRN_BESCR 806 /* Branch event status and control register */ 732 729 #define BESCR_GE 0x8000000000000000ULL /* Global Enable */ 733 730 #define SPRN_WORT 895 /* Workload optimization register - thread */ 731 + #define SPRN_WORC 863 /* Workload optimization register - core */ 734 732 735 733 #define SPRN_PMC1 787 736 734 #define SPRN_PMC2 788
+5 -1
arch/powerpc/include/asm/syscall.h
··· 90 90 91 91 static inline int syscall_get_arch(void) 92 92 { 93 - return is_32bit_task() ? AUDIT_ARCH_PPC : AUDIT_ARCH_PPC64; 93 + int arch = is_32bit_task() ? AUDIT_ARCH_PPC : AUDIT_ARCH_PPC64; 94 + #ifdef __LITTLE_ENDIAN__ 95 + arch |= __AUDIT_ARCH_LE; 96 + #endif 97 + return arch; 94 98 } 95 99 #endif /* _ASM_SYSCALL_H */
+3 -3
arch/powerpc/include/asm/uaccess.h
··· 284 284 if (!is_kernel_addr((unsigned long)__gu_addr)) \ 285 285 might_fault(); \ 286 286 __get_user_size(__gu_val, __gu_addr, (size), __gu_err); \ 287 - (x) = (__typeof__(*(ptr)))__gu_val; \ 287 + (x) = (__force __typeof__(*(ptr)))__gu_val; \ 288 288 __gu_err; \ 289 289 }) 290 290 #endif /* __powerpc64__ */ ··· 297 297 might_fault(); \ 298 298 if (access_ok(VERIFY_READ, __gu_addr, (size))) \ 299 299 __get_user_size(__gu_val, __gu_addr, (size), __gu_err); \ 300 - (x) = (__typeof__(*(ptr)))__gu_val; \ 300 + (x) = (__force __typeof__(*(ptr)))__gu_val; \ 301 301 __gu_err; \ 302 302 }) 303 303 ··· 308 308 const __typeof__(*(ptr)) __user *__gu_addr = (ptr); \ 309 309 __chk_user_ptr(ptr); \ 310 310 __get_user_size(__gu_val, __gu_addr, (size), __gu_err); \ 311 - (x) = (__typeof__(*(ptr)))__gu_val; \ 311 + (x) = (__force __typeof__(*(ptr)))__gu_val; \ 312 312 __gu_err; \ 313 313 }) 314 314
+11
arch/powerpc/kernel/asm-offsets.c
··· 726 726 arch.timing_last_enter.tv32.tbl)); 727 727 #endif 728 728 729 + #ifdef CONFIG_PPC_POWERNV 730 + DEFINE(PACA_CORE_IDLE_STATE_PTR, 731 + offsetof(struct paca_struct, core_idle_state_ptr)); 732 + DEFINE(PACA_THREAD_IDLE_STATE, 733 + offsetof(struct paca_struct, thread_idle_state)); 734 + DEFINE(PACA_THREAD_MASK, 735 + offsetof(struct paca_struct, thread_mask)); 736 + DEFINE(PACA_SUBCORE_SIBLING_MASK, 737 + offsetof(struct paca_struct, subcore_sibling_mask)); 738 + #endif 739 + 729 740 return 0; 730 741 }
+24 -11
arch/powerpc/kernel/exceptions-64s.S
··· 15 15 #include <asm/hw_irq.h> 16 16 #include <asm/exception-64s.h> 17 17 #include <asm/ptrace.h> 18 + #include <asm/cpuidle.h> 18 19 19 20 /* 20 21 * We layout physical memory as follows: ··· 102 101 #ifdef CONFIG_PPC_P7_NAP 103 102 BEGIN_FTR_SECTION 104 103 /* Running native on arch 2.06 or later, check if we are 105 - * waking up from nap. We only handle no state loss and 106 - * supervisor state loss. We do -not- handle hypervisor 107 - * state loss at this time. 104 + * waking up from nap/sleep/winkle. 108 105 */ 109 106 mfspr r13,SPRN_SRR1 110 107 rlwinm. r13,r13,47-31,30,31 111 108 beq 9f 112 109 113 - /* waking up from powersave (nap) state */ 114 - cmpwi cr1,r13,2 115 - /* Total loss of HV state is fatal, we could try to use the 116 - * PIR to locate a PACA, then use an emergency stack etc... 117 - * OPAL v3 based powernv platforms have new idle states 118 - * which fall in this catagory. 110 + cmpwi cr3,r13,2 111 + 112 + /* 113 + * Check if last bit of HSPGR0 is set. This indicates whether we are 114 + * waking up from winkle. 119 115 */ 120 - bgt cr1,8f 121 116 GET_PACA(r13) 117 + clrldi r5,r13,63 118 + clrrdi r13,r13,1 119 + cmpwi cr4,r5,1 120 + mtspr SPRN_HSPRG0,r13 121 + 122 + lbz r0,PACA_THREAD_IDLE_STATE(r13) 123 + cmpwi cr2,r0,PNV_THREAD_NAP 124 + bgt cr2,8f /* Either sleep or Winkle */ 125 + 126 + /* Waking up from nap should not cause hypervisor state loss */ 127 + bgt cr3,. 128 + 129 + /* Waking up from nap */ 130 + li r0,PNV_THREAD_RUNNING 131 + stb r0,PACA_THREAD_IDLE_STATE(r13) /* Clear thread state */ 122 132 123 133 #ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE 124 134 li r0,KVM_HWTHREAD_IN_KERNEL ··· 145 133 146 134 /* Return SRR1 from power7_nap() */ 147 135 mfspr r3,SPRN_SRR1 148 - beq cr1,2f 136 + beq cr3,2f 149 137 b power7_wakeup_noloss 150 138 2: b power7_wakeup_loss 151 139 ··· 1394 1382 MACHINE_CHECK_HANDLER_WINDUP 1395 1383 GET_PACA(r13) 1396 1384 ld r1,PACAR1(r13) 1385 + li r3,PNV_THREAD_NAP 1397 1386 b power7_enter_nap_mode 1398 1387 4: 1399 1388 #endif
+301 -45
arch/powerpc/kernel/idle_power7.S
··· 18 18 #include <asm/hw_irq.h> 19 19 #include <asm/kvm_book3s_asm.h> 20 20 #include <asm/opal.h> 21 + #include <asm/cpuidle.h> 22 + #include <asm/mmu-hash64.h> 21 23 22 24 #undef DEBUG 25 + 26 + /* 27 + * Use unused space in the interrupt stack to save and restore 28 + * registers for winkle support. 29 + */ 30 + #define _SDR1 GPR3 31 + #define _RPR GPR4 32 + #define _SPURR GPR5 33 + #define _PURR GPR6 34 + #define _TSCR GPR7 35 + #define _DSCR GPR8 36 + #define _AMOR GPR9 37 + #define _WORT GPR10 38 + #define _WORC GPR11 23 39 24 40 /* Idle state entry routines */ 25 41 ··· 53 37 54 38 /* 55 39 * Pass requested state in r3: 56 - * 0 - nap 57 - * 1 - sleep 40 + * r3 - PNV_THREAD_NAP/SLEEP/WINKLE 58 41 * 59 42 * To check IRQ_HAPPENED in r4 60 43 * 0 - don't check ··· 116 101 std r9,_MSR(r1) 117 102 std r1,PACAR1(r13) 118 103 119 - _GLOBAL(power7_enter_nap_mode) 104 + /* 105 + * Go to real mode to do the nap, as required by the architecture. 106 + * Also, we need to be in real mode before setting hwthread_state, 107 + * because as soon as we do that, another thread can switch 108 + * the MMU context to the guest. 109 + */ 110 + LOAD_REG_IMMEDIATE(r5, MSR_IDLE) 111 + li r6, MSR_RI 112 + andc r6, r9, r6 113 + LOAD_REG_ADDR(r7, power7_enter_nap_mode) 114 + mtmsrd r6, 1 /* clear RI before setting SRR0/1 */ 115 + mtspr SPRN_SRR0, r7 116 + mtspr SPRN_SRR1, r5 117 + rfid 118 + 119 + .globl power7_enter_nap_mode 120 + power7_enter_nap_mode: 120 121 #ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE 121 122 /* Tell KVM we're napping */ 122 123 li r4,KVM_HWTHREAD_IN_NAP 123 124 stb r4,HSTATE_HWTHREAD_STATE(r13) 124 125 #endif 125 - cmpwi cr0,r3,1 126 - beq 2f 126 + stb r3,PACA_THREAD_IDLE_STATE(r13) 127 + cmpwi cr3,r3,PNV_THREAD_SLEEP 128 + bge cr3,2f 127 129 IDLE_STATE_ENTER_SEQ(PPC_NAP) 128 130 /* No return */ 129 - 2: IDLE_STATE_ENTER_SEQ(PPC_SLEEP) 130 - /* No return */ 131 + 2: 132 + /* Sleep or winkle */ 133 + lbz r7,PACA_THREAD_MASK(r13) 134 + ld r14,PACA_CORE_IDLE_STATE_PTR(r13) 135 + lwarx_loop1: 136 + lwarx r15,0,r14 137 + andc r15,r15,r7 /* Clear thread bit */ 138 + 139 + andi. r15,r15,PNV_CORE_IDLE_THREAD_BITS 140 + 141 + /* 142 + * If cr0 = 0, then current thread is the last thread of the core entering 143 + * sleep. Last thread needs to execute the hardware bug workaround code if 144 + * required by the platform. 145 + * Make the workaround call unconditionally here. The below branch call is 146 + * patched out when the idle states are discovered if the platform does not 147 + * require it. 148 + */ 149 + .global pnv_fastsleep_workaround_at_entry 150 + pnv_fastsleep_workaround_at_entry: 151 + beq fastsleep_workaround_at_entry 152 + 153 + stwcx. r15,0,r14 154 + bne- lwarx_loop1 155 + isync 156 + 157 + common_enter: /* common code for all the threads entering sleep or winkle */ 158 + bgt cr3,enter_winkle 159 + IDLE_STATE_ENTER_SEQ(PPC_SLEEP) 160 + 161 + fastsleep_workaround_at_entry: 162 + ori r15,r15,PNV_CORE_IDLE_LOCK_BIT 163 + stwcx. r15,0,r14 164 + bne- lwarx_loop1 165 + isync 166 + 167 + /* Fast sleep workaround */ 168 + li r3,1 169 + li r4,1 170 + li r0,OPAL_CONFIG_CPU_IDLE_STATE 171 + bl opal_call_realmode 172 + 173 + /* Clear Lock bit */ 174 + li r0,0 175 + lwsync 176 + stw r0,0(r14) 177 + b common_enter 178 + 179 + enter_winkle: 180 + /* 181 + * Note all register i.e per-core, per-subcore or per-thread is saved 182 + * here since any thread in the core might wake up first 183 + */ 184 + mfspr r3,SPRN_SDR1 185 + std r3,_SDR1(r1) 186 + mfspr r3,SPRN_RPR 187 + std r3,_RPR(r1) 188 + mfspr r3,SPRN_SPURR 189 + std r3,_SPURR(r1) 190 + mfspr r3,SPRN_PURR 191 + std r3,_PURR(r1) 192 + mfspr r3,SPRN_TSCR 193 + std r3,_TSCR(r1) 194 + mfspr r3,SPRN_DSCR 195 + std r3,_DSCR(r1) 196 + mfspr r3,SPRN_AMOR 197 + std r3,_AMOR(r1) 198 + mfspr r3,SPRN_WORT 199 + std r3,_WORT(r1) 200 + mfspr r3,SPRN_WORC 201 + std r3,_WORC(r1) 202 + IDLE_STATE_ENTER_SEQ(PPC_WINKLE) 131 203 132 204 _GLOBAL(power7_idle) 133 205 /* Now check if user or arch enabled NAP mode */ ··· 227 125 228 126 _GLOBAL(power7_nap) 229 127 mr r4,r3 230 - li r3,0 128 + li r3,PNV_THREAD_NAP 231 129 b power7_powersave_common 232 130 /* No return */ 233 131 234 132 _GLOBAL(power7_sleep) 235 - li r3,1 133 + li r3,PNV_THREAD_SLEEP 236 134 li r4,1 237 135 b power7_powersave_common 238 136 /* No return */ 239 137 240 - /* 241 - * Make opal call in realmode. This is a generic function to be called 242 - * from realmode from reset vector. It handles endianess. 243 - * 244 - * r13 - paca pointer 245 - * r1 - stack pointer 246 - * r3 - opal token 247 - */ 248 - opal_call_realmode: 249 - mflr r12 250 - std r12,_LINK(r1) 251 - ld r2,PACATOC(r13) 252 - /* Set opal return address */ 253 - LOAD_REG_ADDR(r0,return_from_opal_call) 254 - mtlr r0 255 - /* Handle endian-ness */ 256 - li r0,MSR_LE 257 - mfmsr r12 258 - andc r12,r12,r0 259 - mtspr SPRN_HSRR1,r12 260 - mr r0,r3 /* Move opal token to r0 */ 261 - LOAD_REG_ADDR(r11,opal) 262 - ld r12,8(r11) 263 - ld r2,0(r11) 264 - mtspr SPRN_HSRR0,r12 265 - hrfid 266 - 267 - return_from_opal_call: 268 - FIXUP_ENDIAN 269 - ld r0,_LINK(r1) 270 - mtlr r0 271 - blr 138 + _GLOBAL(power7_winkle) 139 + li r3,3 140 + li r4,1 141 + b power7_powersave_common 142 + /* No return */ 272 143 273 144 #define CHECK_HMI_INTERRUPT \ 274 145 mfspr r0,SPRN_SRR1; \ ··· 256 181 ld r2,PACATOC(r13); \ 257 182 ld r1,PACAR1(r13); \ 258 183 std r3,ORIG_GPR3(r1); /* Save original r3 */ \ 259 - li r3,OPAL_HANDLE_HMI; /* Pass opal token argument*/ \ 184 + li r0,OPAL_HANDLE_HMI; /* Pass opal token argument*/ \ 260 185 bl opal_call_realmode; \ 261 186 ld r3,ORIG_GPR3(r1); /* Restore original r3 */ \ 262 187 20: nop; ··· 265 190 _GLOBAL(power7_wakeup_tb_loss) 266 191 ld r2,PACATOC(r13); 267 192 ld r1,PACAR1(r13) 193 + /* 194 + * Before entering any idle state, the NVGPRs are saved in the stack 195 + * and they are restored before switching to the process context. Hence 196 + * until they are restored, they are free to be used. 197 + * 198 + * Save SRR1 in a NVGPR as it might be clobbered in opal_call_realmode 199 + * (called in CHECK_HMI_INTERRUPT). SRR1 is required to determine the 200 + * wakeup reason if we branch to kvm_start_guest. 201 + */ 268 202 203 + mfspr r16,SPRN_SRR1 269 204 BEGIN_FTR_SECTION 270 205 CHECK_HMI_INTERRUPT 271 206 END_FTR_SECTION_IFSET(CPU_FTR_HVMODE) 272 - /* Time base re-sync */ 273 - li r3,OPAL_RESYNC_TIMEBASE 274 - bl opal_call_realmode; 275 207 208 + lbz r7,PACA_THREAD_MASK(r13) 209 + ld r14,PACA_CORE_IDLE_STATE_PTR(r13) 210 + lwarx_loop2: 211 + lwarx r15,0,r14 212 + andi. r9,r15,PNV_CORE_IDLE_LOCK_BIT 213 + /* 214 + * Lock bit is set in one of the 2 cases- 215 + * a. In the sleep/winkle enter path, the last thread is executing 216 + * fastsleep workaround code. 217 + * b. In the wake up path, another thread is executing fastsleep 218 + * workaround undo code or resyncing timebase or restoring context 219 + * In either case loop until the lock bit is cleared. 220 + */ 221 + bne core_idle_lock_held 222 + 223 + cmpwi cr2,r15,0 224 + lbz r4,PACA_SUBCORE_SIBLING_MASK(r13) 225 + and r4,r4,r15 226 + cmpwi cr1,r4,0 /* Check if first in subcore */ 227 + 228 + /* 229 + * At this stage 230 + * cr1 - 0b0100 if first thread to wakeup in subcore 231 + * cr2 - 0b0100 if first thread to wakeup in core 232 + * cr3- 0b0010 if waking up from sleep or winkle 233 + * cr4 - 0b0100 if waking up from winkle 234 + */ 235 + 236 + or r15,r15,r7 /* Set thread bit */ 237 + 238 + beq cr1,first_thread_in_subcore 239 + 240 + /* Not first thread in subcore to wake up */ 241 + stwcx. r15,0,r14 242 + bne- lwarx_loop2 243 + isync 244 + b common_exit 245 + 246 + core_idle_lock_held: 247 + HMT_LOW 248 + core_idle_lock_loop: 249 + lwz r15,0(14) 250 + andi. r9,r15,PNV_CORE_IDLE_LOCK_BIT 251 + bne core_idle_lock_loop 252 + HMT_MEDIUM 253 + b lwarx_loop2 254 + 255 + first_thread_in_subcore: 256 + /* First thread in subcore to wakeup */ 257 + ori r15,r15,PNV_CORE_IDLE_LOCK_BIT 258 + stwcx. r15,0,r14 259 + bne- lwarx_loop2 260 + isync 261 + 262 + /* 263 + * If waking up from sleep, subcore state is not lost. Hence 264 + * skip subcore state restore 265 + */ 266 + bne cr4,subcore_state_restored 267 + 268 + /* Restore per-subcore state */ 269 + ld r4,_SDR1(r1) 270 + mtspr SPRN_SDR1,r4 271 + ld r4,_RPR(r1) 272 + mtspr SPRN_RPR,r4 273 + ld r4,_AMOR(r1) 274 + mtspr SPRN_AMOR,r4 275 + 276 + subcore_state_restored: 277 + /* 278 + * Check if the thread is also the first thread in the core. If not, 279 + * skip to clear_lock. 280 + */ 281 + bne cr2,clear_lock 282 + 283 + first_thread_in_core: 284 + 285 + /* 286 + * First thread in the core waking up from fastsleep. It needs to 287 + * call the fastsleep workaround code if the platform requires it. 288 + * Call it unconditionally here. The below branch instruction will 289 + * be patched out when the idle states are discovered if platform 290 + * does not require workaround. 291 + */ 292 + .global pnv_fastsleep_workaround_at_exit 293 + pnv_fastsleep_workaround_at_exit: 294 + b fastsleep_workaround_at_exit 295 + 296 + timebase_resync: 297 + /* Do timebase resync if we are waking up from sleep. Use cr3 value 298 + * set in exceptions-64s.S */ 299 + ble cr3,clear_lock 300 + /* Time base re-sync */ 301 + li r0,OPAL_RESYNC_TIMEBASE 302 + bl opal_call_realmode; 276 303 /* TODO: Check r3 for failure */ 304 + 305 + /* 306 + * If waking up from sleep, per core state is not lost, skip to 307 + * clear_lock. 308 + */ 309 + bne cr4,clear_lock 310 + 311 + /* Restore per core state */ 312 + ld r4,_TSCR(r1) 313 + mtspr SPRN_TSCR,r4 314 + ld r4,_WORC(r1) 315 + mtspr SPRN_WORC,r4 316 + 317 + clear_lock: 318 + andi. r15,r15,PNV_CORE_IDLE_THREAD_BITS 319 + lwsync 320 + stw r15,0(r14) 321 + 322 + common_exit: 323 + /* 324 + * Common to all threads. 325 + * 326 + * If waking up from sleep, hypervisor state is not lost. Hence 327 + * skip hypervisor state restore. 328 + */ 329 + bne cr4,hypervisor_state_restored 330 + 331 + /* Waking up from winkle */ 332 + 333 + /* Restore per thread state */ 334 + bl __restore_cpu_power8 335 + 336 + /* Restore SLB from PACA */ 337 + ld r8,PACA_SLBSHADOWPTR(r13) 338 + 339 + .rept SLB_NUM_BOLTED 340 + li r3, SLBSHADOW_SAVEAREA 341 + LDX_BE r5, r8, r3 342 + addi r3, r3, 8 343 + LDX_BE r6, r8, r3 344 + andis. r7,r5,SLB_ESID_V@h 345 + beq 1f 346 + slbmte r6,r5 347 + 1: addi r8,r8,16 348 + .endr 349 + 350 + ld r4,_SPURR(r1) 351 + mtspr SPRN_SPURR,r4 352 + ld r4,_PURR(r1) 353 + mtspr SPRN_PURR,r4 354 + ld r4,_DSCR(r1) 355 + mtspr SPRN_DSCR,r4 356 + ld r4,_WORT(r1) 357 + mtspr SPRN_WORT,r4 358 + 359 + hypervisor_state_restored: 360 + 361 + li r5,PNV_THREAD_RUNNING 362 + stb r5,PACA_THREAD_IDLE_STATE(r13) 363 + 364 + mtspr SPRN_SRR1,r16 365 + #ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE 366 + li r0,KVM_HWTHREAD_IN_KERNEL 367 + stb r0,HSTATE_HWTHREAD_STATE(r13) 368 + /* Order setting hwthread_state vs. testing hwthread_req */ 369 + sync 370 + lbz r0,HSTATE_HWTHREAD_REQ(r13) 371 + cmpwi r0,0 372 + beq 6f 373 + b kvm_start_guest 374 + 6: 375 + #endif 277 376 278 377 REST_NVGPRS(r1) 279 378 REST_GPR(2, r1) ··· 460 211 mtspr SPRN_SRR1,r4 461 212 mtspr SPRN_SRR0,r5 462 213 rfid 214 + 215 + fastsleep_workaround_at_exit: 216 + li r3,1 217 + li r4,0 218 + li r0,OPAL_CONFIG_CPU_IDLE_STATE 219 + bl opal_call_realmode 220 + b timebase_resync 463 221 464 222 /* 465 223 * R3 here contains the value that will be returned to the caller
+8 -1
arch/powerpc/kernel/smp.c
··· 700 700 smp_store_cpu_info(cpu); 701 701 set_dec(tb_ticks_per_jiffy); 702 702 preempt_disable(); 703 - cpu_callin_map[cpu] = 1; 704 703 705 704 if (smp_ops->setup_cpu) 706 705 smp_ops->setup_cpu(cpu); ··· 737 738 smp_wmb(); 738 739 notify_cpu_starting(cpu); 739 740 set_cpu_online(cpu, true); 741 + 742 + /* 743 + * CPU must be marked active and online before we signal back to the 744 + * master, because the scheduler needs to see the cpu_online and 745 + * cpu_active bits set. 746 + */ 747 + smp_wmb(); 748 + cpu_callin_map[cpu] = 1; 740 749 741 750 local_irq_enable(); 742 751
+10 -13
arch/powerpc/perf/hv-24x7.c
··· 177 177 } \ 178 178 ret = sprintf(buf, _fmt, _expr); \ 179 179 e_free: \ 180 - kfree(page); \ 180 + kmem_cache_free(hv_page_cache, page); \ 181 181 return ret; \ 182 182 } \ 183 183 static DEVICE_ATTR_RO(_name) ··· 217 217 domain == HV_24X7_PERF_DOMAIN_PHYSICAL_CORE; 218 218 } 219 219 220 + DEFINE_PER_CPU(char, hv_24x7_reqb[4096]) __aligned(4096); 221 + DEFINE_PER_CPU(char, hv_24x7_resb[4096]) __aligned(4096); 222 + 220 223 static unsigned long single_24x7_request(u8 domain, u32 offset, u16 ix, 221 224 u16 lpar, u64 *res, 222 225 bool success_expected) 223 226 { 224 - unsigned long ret = -ENOMEM; 227 + unsigned long ret; 225 228 226 229 /* 227 230 * request_buffer and result_buffer are not required to be 4k aligned, ··· 246 243 BUILD_BUG_ON(sizeof(*request_buffer) > 4096); 247 244 BUILD_BUG_ON(sizeof(*result_buffer) > 4096); 248 245 249 - request_buffer = kmem_cache_zalloc(hv_page_cache, GFP_USER); 250 - if (!request_buffer) 251 - goto out; 246 + request_buffer = (void *)get_cpu_var(hv_24x7_reqb); 247 + result_buffer = (void *)get_cpu_var(hv_24x7_resb); 252 248 253 - result_buffer = kmem_cache_zalloc(hv_page_cache, GFP_USER); 254 - if (!result_buffer) 255 - goto out_free_request_buffer; 249 + memset(request_buffer, 0, 4096); 250 + memset(result_buffer, 0, 4096); 256 251 257 252 *request_buffer = (struct reqb) { 258 253 .buf = { ··· 279 278 domain, offset, ix, lpar, ret, ret, 280 279 result_buffer->buf.detailed_rc, 281 280 result_buffer->buf.failing_request_ix); 282 - goto out_free_result_buffer; 281 + goto out; 283 282 } 284 283 285 284 *res = be64_to_cpu(result_buffer->result); 286 285 287 - out_free_result_buffer: 288 - kfree(result_buffer); 289 - out_free_request_buffer: 290 - kfree(request_buffer); 291 286 out: 292 287 return ret; 293 288 }
+39
arch/powerpc/platforms/powernv/opal-wrappers.S
··· 158 158 blr 159 159 #endif 160 160 161 + /* 162 + * Make opal call in realmode. This is a generic function to be called 163 + * from realmode. It handles endianness. 164 + * 165 + * r13 - paca pointer 166 + * r1 - stack pointer 167 + * r0 - opal token 168 + */ 169 + _GLOBAL(opal_call_realmode) 170 + mflr r12 171 + std r12,PPC_LR_STKOFF(r1) 172 + ld r2,PACATOC(r13) 173 + /* Set opal return address */ 174 + LOAD_REG_ADDR(r12,return_from_opal_call) 175 + mtlr r12 176 + 177 + mfmsr r12 178 + #ifdef __LITTLE_ENDIAN__ 179 + /* Handle endian-ness */ 180 + li r11,MSR_LE 181 + andc r12,r12,r11 182 + #endif 183 + mtspr SPRN_HSRR1,r12 184 + LOAD_REG_ADDR(r11,opal) 185 + ld r12,8(r11) 186 + ld r2,0(r11) 187 + mtspr SPRN_HSRR0,r12 188 + hrfid 189 + 190 + return_from_opal_call: 191 + #ifdef __LITTLE_ENDIAN__ 192 + FIXUP_ENDIAN 193 + #endif 194 + ld r12,PPC_LR_STKOFF(r1) 195 + mtlr r12 196 + blr 197 + 161 198 OPAL_CALL(opal_invalid_call, OPAL_INVALID_CALL); 162 199 OPAL_CALL(opal_console_write, OPAL_CONSOLE_WRITE); 163 200 OPAL_CALL(opal_console_read, OPAL_CONSOLE_READ); ··· 284 247 OPAL_CALL(opal_get_param, OPAL_GET_PARAM); 285 248 OPAL_CALL(opal_set_param, OPAL_SET_PARAM); 286 249 OPAL_CALL(opal_handle_hmi, OPAL_HANDLE_HMI); 250 + OPAL_CALL(opal_slw_set_reg, OPAL_SLW_SET_REG); 287 251 OPAL_CALL(opal_register_dump_region, OPAL_REGISTER_DUMP_REGION); 288 252 OPAL_CALL(opal_unregister_dump_region, OPAL_UNREGISTER_DUMP_REGION); 289 253 OPAL_CALL(opal_pci_set_phb_cxl_mode, OPAL_PCI_SET_PHB_CXL_MODE); ··· 292 254 OPAL_CALL(opal_tpo_read, OPAL_READ_TPO); 293 255 OPAL_CALL(opal_ipmi_send, OPAL_IPMI_SEND); 294 256 OPAL_CALL(opal_ipmi_recv, OPAL_IPMI_RECV); 257 + OPAL_CALL(opal_i2c_request, OPAL_I2C_REQUEST);
+49 -1
arch/powerpc/platforms/powernv/opal.c
··· 9 9 * 2 of the License, or (at your option) any later version. 10 10 */ 11 11 12 - #undef DEBUG 12 + #define pr_fmt(fmt) "opal: " fmt 13 13 14 + #include <linux/printk.h> 14 15 #include <linux/types.h> 15 16 #include <linux/of.h> 16 17 #include <linux/of_fdt.h> ··· 626 625 return 0; 627 626 } 628 627 628 + static ssize_t symbol_map_read(struct file *fp, struct kobject *kobj, 629 + struct bin_attribute *bin_attr, 630 + char *buf, loff_t off, size_t count) 631 + { 632 + return memory_read_from_buffer(buf, count, &off, bin_attr->private, 633 + bin_attr->size); 634 + } 635 + 636 + static BIN_ATTR_RO(symbol_map, 0); 637 + 638 + static void opal_export_symmap(void) 639 + { 640 + const __be64 *syms; 641 + unsigned int size; 642 + struct device_node *fw; 643 + int rc; 644 + 645 + fw = of_find_node_by_path("/ibm,opal/firmware"); 646 + if (!fw) 647 + return; 648 + syms = of_get_property(fw, "symbol-map", &size); 649 + if (!syms || size != 2 * sizeof(__be64)) 650 + return; 651 + 652 + /* Setup attributes */ 653 + bin_attr_symbol_map.private = __va(be64_to_cpu(syms[0])); 654 + bin_attr_symbol_map.size = be64_to_cpu(syms[1]); 655 + 656 + rc = sysfs_create_bin_file(opal_kobj, &bin_attr_symbol_map); 657 + if (rc) 658 + pr_warn("Error %d creating OPAL symbols file\n", rc); 659 + } 660 + 629 661 static void __init opal_dump_region_init(void) 630 662 { 631 663 void *addr; ··· 687 653 of_platform_device_create(np, NULL, NULL); 688 654 } 689 655 656 + static void opal_i2c_create_devs(void) 657 + { 658 + struct device_node *np; 659 + 660 + for_each_compatible_node(np, NULL, "ibm,opal-i2c") 661 + of_platform_device_create(np, NULL, NULL); 662 + } 663 + 690 664 static int __init opal_init(void) 691 665 { 692 666 struct device_node *np, *consoles; ··· 721 679 of_node_put(consoles); 722 680 } 723 681 682 + /* Create i2c platform devices */ 683 + opal_i2c_create_devs(); 684 + 724 685 /* Find all OPAL interrupts and request them */ 725 686 irqs = of_get_property(opal_node, "opal-interrupts", &irqlen); 726 687 pr_debug("opal: Found %d interrupts reserved for OPAL\n", ··· 747 702 /* Create "opal" kobject under /sys/firmware */ 748 703 rc = opal_sysfs_init(); 749 704 if (rc == 0) { 705 + /* Export symbol map to userspace */ 706 + opal_export_symmap(); 750 707 /* Setup dump region interface */ 751 708 opal_dump_region_init(); 752 709 /* Setup error log interface */ ··· 871 824 EXPORT_SYMBOL_GPL(opal_rtc_write); 872 825 EXPORT_SYMBOL_GPL(opal_tpo_read); 873 826 EXPORT_SYMBOL_GPL(opal_tpo_write); 827 + EXPORT_SYMBOL_GPL(opal_i2c_request);
+2
arch/powerpc/platforms/powernv/powernv.h
··· 29 29 } 30 30 #endif 31 31 32 + extern u32 pnv_get_supported_cpuidle_states(void); 33 + 32 34 extern void pnv_lpc_init(void); 33 35 34 36 bool cpu_core_split_required(void);
+166
arch/powerpc/platforms/powernv/setup.c
··· 36 36 #include <asm/opal.h> 37 37 #include <asm/kexec.h> 38 38 #include <asm/smp.h> 39 + #include <asm/cputhreads.h> 40 + #include <asm/cpuidle.h> 41 + #include <asm/code-patching.h> 39 42 40 43 #include "powernv.h" 44 + #include "subcore.h" 41 45 42 46 static void __init pnv_setup_arch(void) 43 47 { ··· 291 287 ppc_md.halt = rtas_halt; 292 288 } 293 289 #endif /* CONFIG_PPC_POWERNV_RTAS */ 290 + 291 + static u32 supported_cpuidle_states; 292 + 293 + int pnv_save_sprs_for_winkle(void) 294 + { 295 + int cpu; 296 + int rc; 297 + 298 + /* 299 + * hid0, hid1, hid4, hid5, hmeer and lpcr values are symmetric accross 300 + * all cpus at boot. Get these reg values of current cpu and use the 301 + * same accross all cpus. 302 + */ 303 + uint64_t lpcr_val = mfspr(SPRN_LPCR); 304 + uint64_t hid0_val = mfspr(SPRN_HID0); 305 + uint64_t hid1_val = mfspr(SPRN_HID1); 306 + uint64_t hid4_val = mfspr(SPRN_HID4); 307 + uint64_t hid5_val = mfspr(SPRN_HID5); 308 + uint64_t hmeer_val = mfspr(SPRN_HMEER); 309 + 310 + for_each_possible_cpu(cpu) { 311 + uint64_t pir = get_hard_smp_processor_id(cpu); 312 + uint64_t hsprg0_val = (uint64_t)&paca[cpu]; 313 + 314 + /* 315 + * HSPRG0 is used to store the cpu's pointer to paca. Hence last 316 + * 3 bits are guaranteed to be 0. Program slw to restore HSPRG0 317 + * with 63rd bit set, so that when a thread wakes up at 0x100 we 318 + * can use this bit to distinguish between fastsleep and 319 + * deep winkle. 320 + */ 321 + hsprg0_val |= 1; 322 + 323 + rc = opal_slw_set_reg(pir, SPRN_HSPRG0, hsprg0_val); 324 + if (rc != 0) 325 + return rc; 326 + 327 + rc = opal_slw_set_reg(pir, SPRN_LPCR, lpcr_val); 328 + if (rc != 0) 329 + return rc; 330 + 331 + /* HIDs are per core registers */ 332 + if (cpu_thread_in_core(cpu) == 0) { 333 + 334 + rc = opal_slw_set_reg(pir, SPRN_HMEER, hmeer_val); 335 + if (rc != 0) 336 + return rc; 337 + 338 + rc = opal_slw_set_reg(pir, SPRN_HID0, hid0_val); 339 + if (rc != 0) 340 + return rc; 341 + 342 + rc = opal_slw_set_reg(pir, SPRN_HID1, hid1_val); 343 + if (rc != 0) 344 + return rc; 345 + 346 + rc = opal_slw_set_reg(pir, SPRN_HID4, hid4_val); 347 + if (rc != 0) 348 + return rc; 349 + 350 + rc = opal_slw_set_reg(pir, SPRN_HID5, hid5_val); 351 + if (rc != 0) 352 + return rc; 353 + } 354 + } 355 + 356 + return 0; 357 + } 358 + 359 + static void pnv_alloc_idle_core_states(void) 360 + { 361 + int i, j; 362 + int nr_cores = cpu_nr_cores(); 363 + u32 *core_idle_state; 364 + 365 + /* 366 + * core_idle_state - First 8 bits track the idle state of each thread 367 + * of the core. The 8th bit is the lock bit. Initially all thread bits 368 + * are set. They are cleared when the thread enters deep idle state 369 + * like sleep and winkle. Initially the lock bit is cleared. 370 + * The lock bit has 2 purposes 371 + * a. While the first thread is restoring core state, it prevents 372 + * other threads in the core from switching to process context. 373 + * b. While the last thread in the core is saving the core state, it 374 + * prevents a different thread from waking up. 375 + */ 376 + for (i = 0; i < nr_cores; i++) { 377 + int first_cpu = i * threads_per_core; 378 + int node = cpu_to_node(first_cpu); 379 + 380 + core_idle_state = kmalloc_node(sizeof(u32), GFP_KERNEL, node); 381 + *core_idle_state = PNV_CORE_IDLE_THREAD_BITS; 382 + 383 + for (j = 0; j < threads_per_core; j++) { 384 + int cpu = first_cpu + j; 385 + 386 + paca[cpu].core_idle_state_ptr = core_idle_state; 387 + paca[cpu].thread_idle_state = PNV_THREAD_RUNNING; 388 + paca[cpu].thread_mask = 1 << j; 389 + } 390 + } 391 + 392 + update_subcore_sibling_mask(); 393 + 394 + if (supported_cpuidle_states & OPAL_PM_WINKLE_ENABLED) 395 + pnv_save_sprs_for_winkle(); 396 + } 397 + 398 + u32 pnv_get_supported_cpuidle_states(void) 399 + { 400 + return supported_cpuidle_states; 401 + } 402 + EXPORT_SYMBOL_GPL(pnv_get_supported_cpuidle_states); 403 + 404 + static int __init pnv_init_idle_states(void) 405 + { 406 + struct device_node *power_mgt; 407 + int dt_idle_states; 408 + const __be32 *idle_state_flags; 409 + u32 len_flags, flags; 410 + int i; 411 + 412 + supported_cpuidle_states = 0; 413 + 414 + if (cpuidle_disable != IDLE_NO_OVERRIDE) 415 + return 0; 416 + 417 + if (!firmware_has_feature(FW_FEATURE_OPALv3)) 418 + return 0; 419 + 420 + power_mgt = of_find_node_by_path("/ibm,opal/power-mgt"); 421 + if (!power_mgt) { 422 + pr_warn("opal: PowerMgmt Node not found\n"); 423 + return 0; 424 + } 425 + 426 + idle_state_flags = of_get_property(power_mgt, 427 + "ibm,cpu-idle-state-flags", &len_flags); 428 + if (!idle_state_flags) { 429 + pr_warn("DT-PowerMgmt: missing ibm,cpu-idle-state-flags\n"); 430 + return 0; 431 + } 432 + 433 + dt_idle_states = len_flags / sizeof(u32); 434 + 435 + for (i = 0; i < dt_idle_states; i++) { 436 + flags = be32_to_cpu(idle_state_flags[i]); 437 + supported_cpuidle_states |= flags; 438 + } 439 + if (!(supported_cpuidle_states & OPAL_PM_SLEEP_ENABLED_ER1)) { 440 + patch_instruction( 441 + (unsigned int *)pnv_fastsleep_workaround_at_entry, 442 + PPC_INST_NOP); 443 + patch_instruction( 444 + (unsigned int *)pnv_fastsleep_workaround_at_exit, 445 + PPC_INST_NOP); 446 + } 447 + pnv_alloc_idle_core_states(); 448 + return 0; 449 + } 450 + 451 + subsys_initcall(pnv_init_idle_states); 294 452 295 453 static int __init pnv_probe(void) 296 454 {
+27 -2
arch/powerpc/platforms/powernv/smp.c
··· 150 150 { 151 151 unsigned int cpu; 152 152 unsigned long srr1; 153 + u32 idle_states; 153 154 154 155 /* Standard hot unplug procedure */ 155 156 local_irq_disable(); ··· 161 160 generic_set_cpu_dead(cpu); 162 161 smp_wmb(); 163 162 163 + idle_states = pnv_get_supported_cpuidle_states(); 164 164 /* We don't want to take decrementer interrupts while we are offline, 165 165 * so clear LPCR:PECE1. We keep PECE2 enabled. 166 166 */ 167 167 mtspr(SPRN_LPCR, mfspr(SPRN_LPCR) & ~(u64)LPCR_PECE1); 168 168 while (!generic_check_cpu_restart(cpu)) { 169 + 169 170 ppc64_runlatch_off(); 170 - srr1 = power7_nap(1); 171 + 172 + if (idle_states & OPAL_PM_WINKLE_ENABLED) 173 + srr1 = power7_winkle(); 174 + else if ((idle_states & OPAL_PM_SLEEP_ENABLED) || 175 + (idle_states & OPAL_PM_SLEEP_ENABLED_ER1)) 176 + srr1 = power7_sleep(); 177 + else 178 + srr1 = power7_nap(1); 179 + 171 180 ppc64_runlatch_on(); 172 181 173 182 /* ··· 209 198 210 199 #endif /* CONFIG_HOTPLUG_CPU */ 211 200 201 + static int pnv_cpu_bootable(unsigned int nr) 202 + { 203 + /* 204 + * Starting with POWER8, the subcore logic relies on all threads of a 205 + * core being booted so that they can participate in split mode 206 + * switches. So on those machines we ignore the smt_enabled_at_boot 207 + * setting (smt-enabled on the kernel command line). 208 + */ 209 + if (cpu_has_feature(CPU_FTR_ARCH_207S)) 210 + return 1; 211 + 212 + return smp_generic_cpu_bootable(nr); 213 + } 214 + 212 215 static struct smp_ops_t pnv_smp_ops = { 213 216 .message_pass = smp_muxed_ipi_message_pass, 214 217 .cause_ipi = NULL, /* Filled at runtime by xics_smp_probe() */ 215 218 .probe = xics_smp_probe, 216 219 .kick_cpu = pnv_smp_kick_cpu, 217 220 .setup_cpu = pnv_smp_setup_cpu, 218 - .cpu_bootable = smp_generic_cpu_bootable, 221 + .cpu_bootable = pnv_cpu_bootable, 219 222 #ifdef CONFIG_HOTPLUG_CPU 220 223 .cpu_disable = pnv_smp_cpu_disable, 221 224 .cpu_die = generic_cpu_die,
+34
arch/powerpc/platforms/powernv/subcore.c
··· 160 160 mb(); 161 161 } 162 162 163 + static void update_hid_in_slw(u64 hid0) 164 + { 165 + u64 idle_states = pnv_get_supported_cpuidle_states(); 166 + 167 + if (idle_states & OPAL_PM_WINKLE_ENABLED) { 168 + /* OPAL call to patch slw with the new HID0 value */ 169 + u64 cpu_pir = hard_smp_processor_id(); 170 + 171 + opal_slw_set_reg(cpu_pir, SPRN_HID0, hid0); 172 + } 173 + } 174 + 163 175 static void unsplit_core(void) 164 176 { 165 177 u64 hid0, mask; ··· 191 179 hid0 = mfspr(SPRN_HID0); 192 180 hid0 &= ~HID0_POWER8_DYNLPARDIS; 193 181 mtspr(SPRN_HID0, hid0); 182 + update_hid_in_slw(hid0); 194 183 195 184 while (mfspr(SPRN_HID0) & mask) 196 185 cpu_relax(); ··· 228 215 hid0 = mfspr(SPRN_HID0); 229 216 hid0 |= HID0_POWER8_DYNLPARDIS | split_parms[i].value; 230 217 mtspr(SPRN_HID0, hid0); 218 + update_hid_in_slw(hid0); 231 219 232 220 /* Wait for it to happen */ 233 221 while (!(mfspr(SPRN_HID0) & split_parms[i].mask)) ··· 265 251 return true; 266 252 } 267 253 254 + void update_subcore_sibling_mask(void) 255 + { 256 + int cpu; 257 + /* 258 + * sibling mask for the first cpu. Left shift this by required bits 259 + * to get sibling mask for the rest of the cpus. 260 + */ 261 + int sibling_mask_first_cpu = (1 << threads_per_subcore) - 1; 262 + 263 + for_each_possible_cpu(cpu) { 264 + int tid = cpu_thread_in_core(cpu); 265 + int offset = (tid / threads_per_subcore) * threads_per_subcore; 266 + int mask = sibling_mask_first_cpu << offset; 267 + 268 + paca[cpu].subcore_sibling_mask = mask; 269 + 270 + } 271 + } 272 + 268 273 static int cpu_update_split_mode(void *data) 269 274 { 270 275 int cpu, new_mode = *(int *)data; ··· 317 284 /* Make the new mode public */ 318 285 subcores_per_core = new_mode; 319 286 threads_per_subcore = threads_per_core / subcores_per_core; 287 + update_subcore_sibling_mask(); 320 288 321 289 /* Make sure the new mode is written before we exit */ 322 290 mb();
+8 -1
arch/powerpc/platforms/powernv/subcore.h
··· 14 14 #define SYNC_STEP_FINISHED 3 /* Set by secondary when split/unsplit is done */ 15 15 16 16 #ifndef __ASSEMBLY__ 17 + 18 + #ifdef CONFIG_SMP 17 19 void split_core_secondary_loop(u8 *state); 18 - #endif 20 + extern void update_subcore_sibling_mask(void); 21 + #else 22 + static inline void update_subcore_sibling_mask(void) { }; 23 + #endif /* CONFIG_SMP */ 24 + 25 + #endif /* __ASSEMBLY__ */
+4 -6
drivers/cpuidle/cpuidle-powernv.c
··· 16 16 17 17 #include <asm/machdep.h> 18 18 #include <asm/firmware.h> 19 + #include <asm/opal.h> 19 20 #include <asm/runlatch.h> 20 21 21 - /* Flags and constants used in PowerNV platform */ 22 - 23 22 #define MAX_POWERNV_IDLE_STATES 8 24 - #define IDLE_USE_INST_NAP 0x00010000 /* Use nap instruction */ 25 - #define IDLE_USE_INST_SLEEP 0x00020000 /* Use sleep instruction */ 26 23 27 24 struct cpuidle_driver powernv_idle_driver = { 28 25 .name = "powernv_idle", ··· 194 197 * target residency to be 10x exit_latency 195 198 */ 196 199 latency_ns = be32_to_cpu(idle_state_latency[i]); 197 - if (flags & IDLE_USE_INST_NAP) { 200 + if (flags & OPAL_PM_NAP_ENABLED) { 198 201 /* Add NAP state */ 199 202 strcpy(powernv_states[nr_idle_states].name, "Nap"); 200 203 strcpy(powernv_states[nr_idle_states].desc, "Nap"); ··· 207 210 nr_idle_states++; 208 211 } 209 212 210 - if (flags & IDLE_USE_INST_SLEEP) { 213 + if (flags & OPAL_PM_SLEEP_ENABLED || 214 + flags & OPAL_PM_SLEEP_ENABLED_ER1) { 211 215 /* Add FASTSLEEP state */ 212 216 strcpy(powernv_states[nr_idle_states].name, "FastSleep"); 213 217 strcpy(powernv_states[nr_idle_states].desc, "FastSleep");
+11
drivers/i2c/busses/Kconfig
··· 1072 1072 This support is also available as a module. If so, the module 1073 1073 will be called scx200_acb. 1074 1074 1075 + config I2C_OPAL 1076 + tristate "IBM OPAL I2C driver" 1077 + depends on PPC_POWERNV 1078 + default y 1079 + help 1080 + This exposes the PowerNV platform i2c busses to the linux i2c layer, 1081 + the driver is based on the OPAL interfaces. 1082 + 1083 + This driver can also be built as a module. If so, the module will be 1084 + called as i2c-opal. 1085 + 1075 1086 endmenu
+1
drivers/i2c/busses/Makefile
··· 102 102 obj-$(CONFIG_I2C_BCM_KONA) += i2c-bcm-kona.o 103 103 obj-$(CONFIG_I2C_CROS_EC_TUNNEL) += i2c-cros-ec-tunnel.o 104 104 obj-$(CONFIG_I2C_ELEKTOR) += i2c-elektor.o 105 + obj-$(CONFIG_I2C_OPAL) += i2c-opal.o 105 106 obj-$(CONFIG_I2C_PCA_ISA) += i2c-pca-isa.o 106 107 obj-$(CONFIG_I2C_SIBYTE) += i2c-sibyte.o 107 108 obj-$(CONFIG_SCx200_ACB) += scx200_acb.o
+294
drivers/i2c/busses/i2c-opal.c
··· 1 + /* 2 + * IBM OPAL I2C driver 3 + * Copyright (C) 2014 IBM 4 + * 5 + * This program is free software; you can redistribute it and/or modify 6 + * it under the terms of the GNU General Public License as published by 7 + * the Free Software Foundation; either version 2 of the License, or 8 + * (at your option) any later version. 9 + * 10 + * This program is distributed in the hope that it will be useful, 11 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 + * GNU General Public License for more details. 14 + * 15 + * You should have received a copy of the GNU General Public License 16 + * along with this program. 17 + */ 18 + 19 + #include <linux/device.h> 20 + #include <linux/i2c.h> 21 + #include <linux/kernel.h> 22 + #include <linux/mm.h> 23 + #include <linux/module.h> 24 + #include <linux/of.h> 25 + #include <linux/platform_device.h> 26 + #include <linux/slab.h> 27 + 28 + #include <asm/firmware.h> 29 + #include <asm/opal.h> 30 + 31 + static int i2c_opal_translate_error(int rc) 32 + { 33 + switch (rc) { 34 + case OPAL_NO_MEM: 35 + return -ENOMEM; 36 + case OPAL_PARAMETER: 37 + return -EINVAL; 38 + case OPAL_I2C_ARBT_LOST: 39 + return -EAGAIN; 40 + case OPAL_I2C_TIMEOUT: 41 + return -ETIMEDOUT; 42 + case OPAL_I2C_NACK_RCVD: 43 + return -ENXIO; 44 + case OPAL_I2C_STOP_ERR: 45 + return -EBUSY; 46 + default: 47 + return -EIO; 48 + } 49 + } 50 + 51 + static int i2c_opal_send_request(u32 bus_id, struct opal_i2c_request *req) 52 + { 53 + struct opal_msg msg; 54 + int token, rc; 55 + 56 + token = opal_async_get_token_interruptible(); 57 + if (token < 0) { 58 + if (token != -ERESTARTSYS) 59 + pr_err("Failed to get the async token\n"); 60 + 61 + return token; 62 + } 63 + 64 + rc = opal_i2c_request(token, bus_id, req); 65 + if (rc != OPAL_ASYNC_COMPLETION) { 66 + rc = i2c_opal_translate_error(rc); 67 + goto exit; 68 + } 69 + 70 + rc = opal_async_wait_response(token, &msg); 71 + if (rc) 72 + goto exit; 73 + 74 + rc = be64_to_cpu(msg.params[1]); 75 + if (rc != OPAL_SUCCESS) { 76 + rc = i2c_opal_translate_error(rc); 77 + goto exit; 78 + } 79 + 80 + exit: 81 + opal_async_release_token(token); 82 + return rc; 83 + } 84 + 85 + static int i2c_opal_master_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, 86 + int num) 87 + { 88 + unsigned long opal_id = (unsigned long)adap->algo_data; 89 + struct opal_i2c_request req; 90 + int rc, i; 91 + 92 + /* We only support fairly simple combinations here of one 93 + * or two messages 94 + */ 95 + memset(&req, 0, sizeof(req)); 96 + switch(num) { 97 + case 0: 98 + return 0; 99 + case 1: 100 + req.type = (msgs[0].flags & I2C_M_RD) ? 101 + OPAL_I2C_RAW_READ : OPAL_I2C_RAW_WRITE; 102 + req.addr = cpu_to_be16(msgs[0].addr); 103 + req.size = cpu_to_be32(msgs[0].len); 104 + req.buffer_ra = cpu_to_be64(__pa(msgs[0].buf)); 105 + break; 106 + case 2: 107 + /* For two messages, we basically support only simple 108 + * smbus transactions of a write plus a read. We might 109 + * want to allow also two writes but we'd have to bounce 110 + * the data into a single buffer. 111 + */ 112 + if ((msgs[0].flags & I2C_M_RD) || !(msgs[1].flags & I2C_M_RD)) 113 + return -EOPNOTSUPP; 114 + if (msgs[0].len > 4) 115 + return -EOPNOTSUPP; 116 + if (msgs[0].addr != msgs[1].addr) 117 + return -EOPNOTSUPP; 118 + req.type = OPAL_I2C_SM_READ; 119 + req.addr = cpu_to_be16(msgs[0].addr); 120 + req.subaddr_sz = msgs[0].len; 121 + for (i = 0; i < msgs[0].len; i++) 122 + req.subaddr = (req.subaddr << 8) | msgs[0].buf[i]; 123 + req.subaddr = cpu_to_be32(req.subaddr); 124 + req.size = cpu_to_be32(msgs[1].len); 125 + req.buffer_ra = cpu_to_be64(__pa(msgs[1].buf)); 126 + break; 127 + default: 128 + return -EOPNOTSUPP; 129 + } 130 + 131 + rc = i2c_opal_send_request(opal_id, &req); 132 + if (rc) 133 + return rc; 134 + 135 + return num; 136 + } 137 + 138 + static int i2c_opal_smbus_xfer(struct i2c_adapter *adap, u16 addr, 139 + unsigned short flags, char read_write, 140 + u8 command, int size, union i2c_smbus_data *data) 141 + { 142 + unsigned long opal_id = (unsigned long)adap->algo_data; 143 + struct opal_i2c_request req; 144 + u8 local[2]; 145 + int rc; 146 + 147 + memset(&req, 0, sizeof(req)); 148 + 149 + req.addr = cpu_to_be16(addr); 150 + switch (size) { 151 + case I2C_SMBUS_BYTE: 152 + req.buffer_ra = cpu_to_be64(__pa(&data->byte)); 153 + req.size = cpu_to_be32(1); 154 + /* Fall through */ 155 + case I2C_SMBUS_QUICK: 156 + req.type = (read_write == I2C_SMBUS_READ) ? 157 + OPAL_I2C_RAW_READ : OPAL_I2C_RAW_WRITE; 158 + break; 159 + case I2C_SMBUS_BYTE_DATA: 160 + req.buffer_ra = cpu_to_be64(__pa(&data->byte)); 161 + req.size = cpu_to_be32(1); 162 + req.subaddr = cpu_to_be32(command); 163 + req.subaddr_sz = 1; 164 + req.type = (read_write == I2C_SMBUS_READ) ? 165 + OPAL_I2C_SM_READ : OPAL_I2C_SM_WRITE; 166 + break; 167 + case I2C_SMBUS_WORD_DATA: 168 + if (!read_write) { 169 + local[0] = data->word & 0xff; 170 + local[1] = (data->word >> 8) & 0xff; 171 + } 172 + req.buffer_ra = cpu_to_be64(__pa(local)); 173 + req.size = cpu_to_be32(2); 174 + req.subaddr = cpu_to_be32(command); 175 + req.subaddr_sz = 1; 176 + req.type = (read_write == I2C_SMBUS_READ) ? 177 + OPAL_I2C_SM_READ : OPAL_I2C_SM_WRITE; 178 + break; 179 + case I2C_SMBUS_I2C_BLOCK_DATA: 180 + req.buffer_ra = cpu_to_be64(__pa(&data->block[1])); 181 + req.size = cpu_to_be32(data->block[0]); 182 + req.subaddr = cpu_to_be32(command); 183 + req.subaddr_sz = 1; 184 + req.type = (read_write == I2C_SMBUS_READ) ? 185 + OPAL_I2C_SM_READ : OPAL_I2C_SM_WRITE; 186 + break; 187 + default: 188 + return -EINVAL; 189 + } 190 + 191 + rc = i2c_opal_send_request(opal_id, &req); 192 + if (!rc && read_write && size == I2C_SMBUS_WORD_DATA) { 193 + data->word = ((u16)local[1]) << 8; 194 + data->word |= local[0]; 195 + } 196 + 197 + return rc; 198 + } 199 + 200 + static u32 i2c_opal_func(struct i2c_adapter *adapter) 201 + { 202 + return I2C_FUNC_I2C | I2C_FUNC_SMBUS_QUICK | I2C_FUNC_SMBUS_BYTE | 203 + I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA | 204 + I2C_FUNC_SMBUS_I2C_BLOCK; 205 + } 206 + 207 + static const struct i2c_algorithm i2c_opal_algo = { 208 + .master_xfer = i2c_opal_master_xfer, 209 + .smbus_xfer = i2c_opal_smbus_xfer, 210 + .functionality = i2c_opal_func, 211 + }; 212 + 213 + static int i2c_opal_probe(struct platform_device *pdev) 214 + { 215 + struct i2c_adapter *adapter; 216 + const char *pname; 217 + u32 opal_id; 218 + int rc; 219 + 220 + if (!pdev->dev.of_node) 221 + return -ENODEV; 222 + 223 + rc = of_property_read_u32(pdev->dev.of_node, "ibm,opal-id", &opal_id); 224 + if (rc) { 225 + dev_err(&pdev->dev, "Missing ibm,opal-id property !\n"); 226 + return -EIO; 227 + } 228 + 229 + adapter = devm_kzalloc(&pdev->dev, sizeof(*adapter), GFP_KERNEL); 230 + if (!adapter) 231 + return -ENOMEM; 232 + 233 + adapter->algo = &i2c_opal_algo; 234 + adapter->algo_data = (void *)(unsigned long)opal_id; 235 + adapter->dev.parent = &pdev->dev; 236 + adapter->dev.of_node = of_node_get(pdev->dev.of_node); 237 + pname = of_get_property(pdev->dev.of_node, "ibm,port-name", NULL); 238 + if (pname) 239 + strlcpy(adapter->name, pname, sizeof(adapter->name)); 240 + else 241 + strlcpy(adapter->name, "opal", sizeof(adapter->name)); 242 + 243 + platform_set_drvdata(pdev, adapter); 244 + rc = i2c_add_adapter(adapter); 245 + if (rc) 246 + dev_err(&pdev->dev, "Failed to register the i2c adapter\n"); 247 + 248 + return rc; 249 + } 250 + 251 + static int i2c_opal_remove(struct platform_device *pdev) 252 + { 253 + struct i2c_adapter *adapter = platform_get_drvdata(pdev); 254 + 255 + i2c_del_adapter(adapter); 256 + 257 + return 0; 258 + } 259 + 260 + static const struct of_device_id i2c_opal_of_match[] = { 261 + { 262 + .compatible = "ibm,opal-i2c", 263 + }, 264 + { } 265 + }; 266 + MODULE_DEVICE_TABLE(of, i2c_opal_of_match); 267 + 268 + static struct platform_driver i2c_opal_driver = { 269 + .probe = i2c_opal_probe, 270 + .remove = i2c_opal_remove, 271 + .driver = { 272 + .name = "i2c-opal", 273 + .of_match_table = i2c_opal_of_match, 274 + }, 275 + }; 276 + 277 + static int __init i2c_opal_init(void) 278 + { 279 + if (!firmware_has_feature(FW_FEATURE_OPAL)) 280 + return -ENODEV; 281 + 282 + return platform_driver_register(&i2c_opal_driver); 283 + } 284 + module_init(i2c_opal_init); 285 + 286 + static void __exit i2c_opal_exit(void) 287 + { 288 + return platform_driver_unregister(&i2c_opal_driver); 289 + } 290 + module_exit(i2c_opal_exit); 291 + 292 + MODULE_AUTHOR("Neelesh Gupta <neelegup@linux.vnet.ibm.com>"); 293 + MODULE_DESCRIPTION("IBM OPAL I2C driver"); 294 + MODULE_LICENSE("GPL");
+18 -8
drivers/misc/cxl/context.c
··· 34 34 /* 35 35 * Initialises a CXL context. 36 36 */ 37 - int cxl_context_init(struct cxl_context *ctx, struct cxl_afu *afu, bool master) 37 + int cxl_context_init(struct cxl_context *ctx, struct cxl_afu *afu, bool master, 38 + struct address_space *mapping) 38 39 { 39 40 int i; 40 41 ··· 43 42 ctx->afu = afu; 44 43 ctx->master = master; 45 44 ctx->pid = NULL; /* Set in start work ioctl */ 45 + mutex_init(&ctx->mapping_lock); 46 + ctx->mapping = mapping; 46 47 47 48 /* 48 49 * Allocate the segment table before we put it in the IDR so that we ··· 85 82 * Allocating IDR! We better make sure everything's setup that 86 83 * dereferences from it. 87 84 */ 85 + mutex_lock(&afu->contexts_lock); 88 86 idr_preload(GFP_KERNEL); 89 - spin_lock(&afu->contexts_lock); 90 87 i = idr_alloc(&ctx->afu->contexts_idr, ctx, 0, 91 88 ctx->afu->num_procs, GFP_NOWAIT); 92 - spin_unlock(&afu->contexts_lock); 93 89 idr_preload_end(); 90 + mutex_unlock(&afu->contexts_lock); 94 91 if (i < 0) 95 92 return i; 96 93 ··· 150 147 afu_release_irqs(ctx); 151 148 flush_work(&ctx->fault_work); /* Only needed for dedicated process */ 152 149 wake_up_all(&ctx->wq); 150 + 151 + /* Release Problem State Area mapping */ 152 + mutex_lock(&ctx->mapping_lock); 153 + if (ctx->mapping) 154 + unmap_mapping_range(ctx->mapping, 0, 0, 1); 155 + mutex_unlock(&ctx->mapping_lock); 153 156 } 154 157 155 158 /* ··· 177 168 struct cxl_context *ctx; 178 169 int tmp; 179 170 180 - rcu_read_lock(); 181 - idr_for_each_entry(&afu->contexts_idr, ctx, tmp) 171 + mutex_lock(&afu->contexts_lock); 172 + idr_for_each_entry(&afu->contexts_idr, ctx, tmp) { 182 173 /* 183 174 * Anything done in here needs to be setup before the IDR is 184 175 * created and torn down after the IDR removed 185 176 */ 186 177 __detach_context(ctx); 187 - rcu_read_unlock(); 178 + } 179 + mutex_unlock(&afu->contexts_lock); 188 180 } 189 181 190 182 void cxl_context_free(struct cxl_context *ctx) 191 183 { 192 - spin_lock(&ctx->afu->contexts_lock); 184 + mutex_lock(&ctx->afu->contexts_lock); 193 185 idr_remove(&ctx->afu->contexts_idr, ctx->pe); 194 - spin_unlock(&ctx->afu->contexts_lock); 186 + mutex_unlock(&ctx->afu->contexts_lock); 195 187 synchronize_rcu(); 196 188 197 189 free_page((u64)ctx->sstp);
+7 -2
drivers/misc/cxl/cxl.h
··· 351 351 struct device *chardev_s, *chardev_m, *chardev_d; 352 352 struct idr contexts_idr; 353 353 struct dentry *debugfs; 354 - spinlock_t contexts_lock; 354 + struct mutex contexts_lock; 355 355 struct mutex spa_mutex; 356 356 spinlock_t afu_cntl_lock; 357 357 ··· 397 397 /* Problem state MMIO */ 398 398 phys_addr_t psn_phys; 399 399 u64 psn_size; 400 + 401 + /* Used to unmap any mmaps when force detaching */ 402 + struct address_space *mapping; 403 + struct mutex mapping_lock; 400 404 401 405 spinlock_t sste_lock; /* Protects segment table entries */ 402 406 struct cxl_sste *sstp; ··· 603 599 void init_cxl_native(void); 604 600 605 601 struct cxl_context *cxl_context_alloc(void); 606 - int cxl_context_init(struct cxl_context *ctx, struct cxl_afu *afu, bool master); 602 + int cxl_context_init(struct cxl_context *ctx, struct cxl_afu *afu, bool master, 603 + struct address_space *mapping); 607 604 void cxl_context_free(struct cxl_context *ctx); 608 605 int cxl_context_iomap(struct cxl_context *ctx, struct vm_area_struct *vma); 609 606
+5 -1
drivers/misc/cxl/file.c
··· 77 77 goto err_put_afu; 78 78 } 79 79 80 - if ((rc = cxl_context_init(ctx, afu, master))) 80 + if ((rc = cxl_context_init(ctx, afu, master, inode->i_mapping))) 81 81 goto err_put_afu; 82 82 83 83 pr_devel("afu_open pe: %i\n", ctx->pe); ··· 112 112 pr_devel("%s: closing cxl file descriptor. pe: %i\n", 113 113 __func__, ctx->pe); 114 114 cxl_context_detach(ctx); 115 + 116 + mutex_lock(&ctx->mapping_lock); 117 + ctx->mapping = NULL; 118 + mutex_unlock(&ctx->mapping_lock); 115 119 116 120 put_device(&ctx->afu->dev); 117 121
+5 -7
drivers/misc/cxl/native.c
··· 277 277 u64 cmd, u64 pe_state) 278 278 { 279 279 u64 state; 280 + unsigned long timeout = jiffies + (HZ * CXL_TIMEOUT); 280 281 281 282 WARN_ON(!ctx->afu->enabled); 282 283 ··· 287 286 smp_mb(); 288 287 cxl_p1n_write(ctx->afu, CXL_PSL_LLCMD_An, cmd | ctx->pe); 289 288 while (1) { 289 + if (time_after_eq(jiffies, timeout)) { 290 + dev_warn(&ctx->afu->dev, "WARNING: Process Element Command timed out!\n"); 291 + return -EBUSY; 292 + } 290 293 state = be64_to_cpup(ctx->afu->sw_command_status); 291 294 if (state == ~0ULL) { 292 295 pr_err("cxl: Error adding process element to AFU\n"); ··· 615 610 return 0; 616 611 } 617 612 618 - /* 619 - * TODO: handle case when this is called inside a rcu_read_lock() which may 620 - * happen when we unbind the driver (ie. cxl_context_detach_all()) . Terminate 621 - * & remove use a mutex lock and schedule which will not good with lock held. 622 - * May need to write do_process_element_cmd() that handles outstanding page 623 - * faults synchronously. 624 - */ 625 613 static inline int detach_process_native_afu_directed(struct cxl_context *ctx) 626 614 { 627 615 if (!ctx->pe_inserted)
+1 -1
drivers/misc/cxl/pci.c
··· 502 502 afu->dev.release = cxl_release_afu; 503 503 afu->slice = slice; 504 504 idr_init(&afu->contexts_idr); 505 - spin_lock_init(&afu->contexts_lock); 505 + mutex_init(&afu->contexts_lock); 506 506 spin_lock_init(&afu->afu_cntl_lock); 507 507 mutex_init(&afu->spa_mutex); 508 508
+5 -5
drivers/misc/cxl/sysfs.c
··· 121 121 int rc; 122 122 123 123 /* Not safe to reset if it is currently in use */ 124 - spin_lock(&afu->contexts_lock); 124 + mutex_lock(&afu->contexts_lock); 125 125 if (!idr_is_empty(&afu->contexts_idr)) { 126 126 rc = -EBUSY; 127 127 goto err; ··· 132 132 133 133 rc = count; 134 134 err: 135 - spin_unlock(&afu->contexts_lock); 135 + mutex_unlock(&afu->contexts_lock); 136 136 return rc; 137 137 } 138 138 ··· 247 247 int rc = -EBUSY; 248 248 249 249 /* can't change this if we have a user */ 250 - spin_lock(&afu->contexts_lock); 250 + mutex_lock(&afu->contexts_lock); 251 251 if (!idr_is_empty(&afu->contexts_idr)) 252 252 goto err; 253 253 ··· 271 271 afu->current_mode = 0; 272 272 afu->num_procs = 0; 273 273 274 - spin_unlock(&afu->contexts_lock); 274 + mutex_unlock(&afu->contexts_lock); 275 275 276 276 if ((rc = _cxl_afu_deactivate_mode(afu, old_mode))) 277 277 return rc; ··· 280 280 281 281 return count; 282 282 err: 283 - spin_unlock(&afu->contexts_lock); 283 + mutex_unlock(&afu->contexts_lock); 284 284 return rc; 285 285 } 286 286
+2
include/uapi/linux/audit.h
··· 371 371 #define AUDIT_ARCH_PARISC (EM_PARISC) 372 372 #define AUDIT_ARCH_PARISC64 (EM_PARISC|__AUDIT_ARCH_64BIT) 373 373 #define AUDIT_ARCH_PPC (EM_PPC) 374 + /* do not define AUDIT_ARCH_PPCLE since it is not supported by audit */ 374 375 #define AUDIT_ARCH_PPC64 (EM_PPC64|__AUDIT_ARCH_64BIT) 376 + #define AUDIT_ARCH_PPC64LE (EM_PPC64|__AUDIT_ARCH_64BIT|__AUDIT_ARCH_LE) 375 377 #define AUDIT_ARCH_S390 (EM_S390) 376 378 #define AUDIT_ARCH_S390X (EM_S390|__AUDIT_ARCH_64BIT) 377 379 #define AUDIT_ARCH_SH (EM_SH)