114a43e69SBenjamin Herrenschmidt/* 214a43e69SBenjamin Herrenschmidt * PowerNV OPAL API wrappers 314a43e69SBenjamin Herrenschmidt * 414a43e69SBenjamin Herrenschmidt * Copyright 2011 IBM Corp. 514a43e69SBenjamin Herrenschmidt * 614a43e69SBenjamin Herrenschmidt * This program is free software; you can redistribute it and/or 714a43e69SBenjamin Herrenschmidt * modify it under the terms of the GNU General Public License 814a43e69SBenjamin Herrenschmidt * as published by the Free Software Foundation; either version 914a43e69SBenjamin Herrenschmidt * 2 of the License, or (at your option) any later version. 1014a43e69SBenjamin Herrenschmidt */ 1114a43e69SBenjamin Herrenschmidt 1214a43e69SBenjamin Herrenschmidt#include <asm/ppc_asm.h> 1314a43e69SBenjamin Herrenschmidt#include <asm/hvcall.h> 1414a43e69SBenjamin Herrenschmidt#include <asm/asm-offsets.h> 1514a43e69SBenjamin Herrenschmidt#include <asm/opal.h> 16c49f6353SAnton Blanchard#include <asm/jump_label.h> 17c49f6353SAnton Blanchard 18c49f6353SAnton Blanchard .section ".text" 19c49f6353SAnton Blanchard 20c49f6353SAnton Blanchard#ifdef CONFIG_TRACEPOINTS 21c49f6353SAnton Blanchard#ifdef CONFIG_JUMP_LABEL 22c49f6353SAnton Blanchard#define OPAL_BRANCH(LABEL) \ 23c49f6353SAnton Blanchard ARCH_STATIC_BRANCH(LABEL, opal_tracepoint_key) 24c49f6353SAnton Blanchard#else 25c49f6353SAnton Blanchard 26c49f6353SAnton Blanchard .section ".toc","aw" 27c49f6353SAnton Blanchard 28c49f6353SAnton Blanchard .globl opal_tracepoint_refcount 29c49f6353SAnton Blanchardopal_tracepoint_refcount: 30c49f6353SAnton Blanchard .llong 0 31c49f6353SAnton Blanchard 32c49f6353SAnton Blanchard .section ".text" 33c49f6353SAnton Blanchard 34c49f6353SAnton Blanchard/* 35c49f6353SAnton Blanchard * We branch around this in early init by using an unconditional cpu 36c49f6353SAnton Blanchard * feature. 37c49f6353SAnton Blanchard */ 38c49f6353SAnton Blanchard#define OPAL_BRANCH(LABEL) \ 39c49f6353SAnton BlanchardBEGIN_FTR_SECTION; \ 40c49f6353SAnton Blanchard b 1f; \ 41c49f6353SAnton BlanchardEND_FTR_SECTION(0, 1); \ 42c49f6353SAnton Blanchard ld r12,opal_tracepoint_refcount@toc(r2); \ 43c49f6353SAnton Blanchard std r12,32(r1); \ 44c49f6353SAnton Blanchard cmpdi r12,0; \ 45c49f6353SAnton Blanchard bne- LABEL; \ 46c49f6353SAnton Blanchard1: 47c49f6353SAnton Blanchard 48c49f6353SAnton Blanchard#endif 49c49f6353SAnton Blanchard 50c49f6353SAnton Blanchard#else 51c49f6353SAnton Blanchard#define OPAL_BRANCH(LABEL) 52c49f6353SAnton Blanchard#endif 5314a43e69SBenjamin Herrenschmidt 5414a43e69SBenjamin Herrenschmidt/* TODO: 5514a43e69SBenjamin Herrenschmidt * 5614a43e69SBenjamin Herrenschmidt * - Trace irqs in/off (needs saving/restoring all args, argh...) 5714a43e69SBenjamin Herrenschmidt * - Get r11 feed up by Dave so I can have better register usage 5814a43e69SBenjamin Herrenschmidt */ 59c49f6353SAnton Blanchard 6014a43e69SBenjamin Herrenschmidt#define OPAL_CALL(name, token) \ 6114a43e69SBenjamin Herrenschmidt _GLOBAL(name); \ 6214a43e69SBenjamin Herrenschmidt mflr r0; \ 6314a43e69SBenjamin Herrenschmidt std r0,16(r1); \ 64c49f6353SAnton Blanchard li r0,token; \ 65c49f6353SAnton Blanchard OPAL_BRANCH(opal_tracepoint_entry) \ 66c49f6353SAnton Blanchard mfcr r12; \ 67bbe30b3bSAnton Blanchard stw r12,8(r1); \ 6814a43e69SBenjamin Herrenschmidt std r1,PACAR1(r13); \ 69c49f6353SAnton Blanchard li r11,0; \ 7014a43e69SBenjamin Herrenschmidt mfmsr r12; \ 71c49f6353SAnton Blanchard ori r11,r11,MSR_EE; \ 7214a43e69SBenjamin Herrenschmidt std r12,PACASAVEDMSR(r13); \ 73c49f6353SAnton Blanchard andc r12,r12,r11; \ 7414a43e69SBenjamin Herrenschmidt mtmsrd r12,1; \ 75c49f6353SAnton Blanchard LOAD_REG_ADDR(r11,opal_return); \ 76c49f6353SAnton Blanchard mtlr r11; \ 77c49f6353SAnton Blanchard li r11,MSR_DR|MSR_IR|MSR_LE;\ 78c49f6353SAnton Blanchard andc r12,r12,r11; \ 7914a43e69SBenjamin Herrenschmidt mtspr SPRN_HSRR1,r12; \ 8014a43e69SBenjamin Herrenschmidt LOAD_REG_ADDR(r11,opal); \ 8114a43e69SBenjamin Herrenschmidt ld r12,8(r11); \ 8214a43e69SBenjamin Herrenschmidt ld r2,0(r11); \ 8314a43e69SBenjamin Herrenschmidt mtspr SPRN_HSRR0,r12; \ 8414a43e69SBenjamin Herrenschmidt hrfid 8514a43e69SBenjamin Herrenschmidt 86ad0289e4SAnton Blanchardopal_return: 87be401b37SBenjamin Herrenschmidt /* 88be401b37SBenjamin Herrenschmidt * Fixup endian on OPAL return... we should be able to simplify 89be401b37SBenjamin Herrenschmidt * this by instead converting the below trampoline to a set of 90be401b37SBenjamin Herrenschmidt * bytes (always BE) since MSR:LE will end up fixed up as a side 91be401b37SBenjamin Herrenschmidt * effect of the rfid. 92be401b37SBenjamin Herrenschmidt */ 93be401b37SBenjamin Herrenschmidt FIXUP_ENDIAN 9414a43e69SBenjamin Herrenschmidt ld r2,PACATOC(r13); 95bbe30b3bSAnton Blanchard lwz r4,8(r1); 9614a43e69SBenjamin Herrenschmidt ld r5,16(r1); 9714a43e69SBenjamin Herrenschmidt ld r6,PACASAVEDMSR(r13); 9814a43e69SBenjamin Herrenschmidt mtspr SPRN_SRR0,r5; 9914a43e69SBenjamin Herrenschmidt mtspr SPRN_SRR1,r6; 10014a43e69SBenjamin Herrenschmidt mtcr r4; 10114a43e69SBenjamin Herrenschmidt rfid 10214a43e69SBenjamin Herrenschmidt 103c49f6353SAnton Blanchard#ifdef CONFIG_TRACEPOINTS 104c49f6353SAnton Blanchardopal_tracepoint_entry: 105c49f6353SAnton Blanchard stdu r1,-STACKFRAMESIZE(r1) 106c49f6353SAnton Blanchard std r0,STK_REG(R23)(r1) 107c49f6353SAnton Blanchard std r3,STK_REG(R24)(r1) 108c49f6353SAnton Blanchard std r4,STK_REG(R25)(r1) 109c49f6353SAnton Blanchard std r5,STK_REG(R26)(r1) 110c49f6353SAnton Blanchard std r6,STK_REG(R27)(r1) 111c49f6353SAnton Blanchard std r7,STK_REG(R28)(r1) 112c49f6353SAnton Blanchard std r8,STK_REG(R29)(r1) 113c49f6353SAnton Blanchard std r9,STK_REG(R30)(r1) 114c49f6353SAnton Blanchard std r10,STK_REG(R31)(r1) 115c49f6353SAnton Blanchard mr r3,r0 116c49f6353SAnton Blanchard addi r4,r1,STK_REG(R24) 117c49f6353SAnton Blanchard bl __trace_opal_entry 118c49f6353SAnton Blanchard ld r0,STK_REG(R23)(r1) 119c49f6353SAnton Blanchard ld r3,STK_REG(R24)(r1) 120c49f6353SAnton Blanchard ld r4,STK_REG(R25)(r1) 121c49f6353SAnton Blanchard ld r5,STK_REG(R26)(r1) 122c49f6353SAnton Blanchard ld r6,STK_REG(R27)(r1) 123c49f6353SAnton Blanchard ld r7,STK_REG(R28)(r1) 124c49f6353SAnton Blanchard ld r8,STK_REG(R29)(r1) 125c49f6353SAnton Blanchard ld r9,STK_REG(R30)(r1) 126c49f6353SAnton Blanchard ld r10,STK_REG(R31)(r1) 127c49f6353SAnton Blanchard LOAD_REG_ADDR(r11,opal_tracepoint_return) 128c49f6353SAnton Blanchard mfcr r12 129c49f6353SAnton Blanchard std r11,16(r1) 130c49f6353SAnton Blanchard stw r12,8(r1) 131c49f6353SAnton Blanchard std r1,PACAR1(r13) 132c49f6353SAnton Blanchard li r11,0 133c49f6353SAnton Blanchard mfmsr r12 134c49f6353SAnton Blanchard ori r11,r11,MSR_EE 135c49f6353SAnton Blanchard std r12,PACASAVEDMSR(r13) 136c49f6353SAnton Blanchard andc r12,r12,r11 137c49f6353SAnton Blanchard mtmsrd r12,1 138c49f6353SAnton Blanchard LOAD_REG_ADDR(r11,opal_return) 139c49f6353SAnton Blanchard mtlr r11 140c49f6353SAnton Blanchard li r11,MSR_DR|MSR_IR|MSR_LE 141c49f6353SAnton Blanchard andc r12,r12,r11 142c49f6353SAnton Blanchard mtspr SPRN_HSRR1,r12 143c49f6353SAnton Blanchard LOAD_REG_ADDR(r11,opal) 144c49f6353SAnton Blanchard ld r12,8(r11) 145c49f6353SAnton Blanchard ld r2,0(r11) 146c49f6353SAnton Blanchard mtspr SPRN_HSRR0,r12 147c49f6353SAnton Blanchard hrfid 148c49f6353SAnton Blanchard 149c49f6353SAnton Blanchardopal_tracepoint_return: 150c49f6353SAnton Blanchard std r3,STK_REG(R31)(r1) 151c49f6353SAnton Blanchard mr r4,r3 152c49f6353SAnton Blanchard ld r0,STK_REG(R23)(r1) 153c49f6353SAnton Blanchard bl __trace_opal_exit 154c49f6353SAnton Blanchard ld r3,STK_REG(R31)(r1) 155c49f6353SAnton Blanchard addi r1,r1,STACKFRAMESIZE 156c49f6353SAnton Blanchard ld r0,16(r1) 157c49f6353SAnton Blanchard mtlr r0 158c49f6353SAnton Blanchard blr 159c49f6353SAnton Blanchard#endif 160c49f6353SAnton Blanchard 161e28b05e7SJoel StanleyOPAL_CALL(opal_invalid_call, OPAL_INVALID_CALL); 16214a43e69SBenjamin HerrenschmidtOPAL_CALL(opal_console_write, OPAL_CONSOLE_WRITE); 16314a43e69SBenjamin HerrenschmidtOPAL_CALL(opal_console_read, OPAL_CONSOLE_READ); 16414a43e69SBenjamin HerrenschmidtOPAL_CALL(opal_console_write_buffer_space, OPAL_CONSOLE_WRITE_BUFFER_SPACE); 16514a43e69SBenjamin HerrenschmidtOPAL_CALL(opal_rtc_read, OPAL_RTC_READ); 16614a43e69SBenjamin HerrenschmidtOPAL_CALL(opal_rtc_write, OPAL_RTC_WRITE); 16714a43e69SBenjamin HerrenschmidtOPAL_CALL(opal_cec_power_down, OPAL_CEC_POWER_DOWN); 16814a43e69SBenjamin HerrenschmidtOPAL_CALL(opal_cec_reboot, OPAL_CEC_REBOOT); 16914a43e69SBenjamin HerrenschmidtOPAL_CALL(opal_read_nvram, OPAL_READ_NVRAM); 17014a43e69SBenjamin HerrenschmidtOPAL_CALL(opal_write_nvram, OPAL_WRITE_NVRAM); 17114a43e69SBenjamin HerrenschmidtOPAL_CALL(opal_handle_interrupt, OPAL_HANDLE_INTERRUPT); 17214a43e69SBenjamin HerrenschmidtOPAL_CALL(opal_poll_events, OPAL_POLL_EVENTS); 17314a43e69SBenjamin HerrenschmidtOPAL_CALL(opal_pci_set_hub_tce_memory, OPAL_PCI_SET_HUB_TCE_MEMORY); 17414a43e69SBenjamin HerrenschmidtOPAL_CALL(opal_pci_set_phb_tce_memory, OPAL_PCI_SET_PHB_TCE_MEMORY); 17514a43e69SBenjamin HerrenschmidtOPAL_CALL(opal_pci_config_read_byte, OPAL_PCI_CONFIG_READ_BYTE); 17614a43e69SBenjamin HerrenschmidtOPAL_CALL(opal_pci_config_read_half_word, OPAL_PCI_CONFIG_READ_HALF_WORD); 17714a43e69SBenjamin HerrenschmidtOPAL_CALL(opal_pci_config_read_word, OPAL_PCI_CONFIG_READ_WORD); 17814a43e69SBenjamin HerrenschmidtOPAL_CALL(opal_pci_config_write_byte, OPAL_PCI_CONFIG_WRITE_BYTE); 17914a43e69SBenjamin HerrenschmidtOPAL_CALL(opal_pci_config_write_half_word, OPAL_PCI_CONFIG_WRITE_HALF_WORD); 18014a43e69SBenjamin HerrenschmidtOPAL_CALL(opal_pci_config_write_word, OPAL_PCI_CONFIG_WRITE_WORD); 18114a43e69SBenjamin HerrenschmidtOPAL_CALL(opal_set_xive, OPAL_SET_XIVE); 18214a43e69SBenjamin HerrenschmidtOPAL_CALL(opal_get_xive, OPAL_GET_XIVE); 18314a43e69SBenjamin HerrenschmidtOPAL_CALL(opal_register_exception_handler, OPAL_REGISTER_OPAL_EXCEPTION_HANDLER); 18414a43e69SBenjamin HerrenschmidtOPAL_CALL(opal_pci_eeh_freeze_status, OPAL_PCI_EEH_FREEZE_STATUS); 18514a43e69SBenjamin HerrenschmidtOPAL_CALL(opal_pci_eeh_freeze_clear, OPAL_PCI_EEH_FREEZE_CLEAR); 18614a43e69SBenjamin HerrenschmidtOPAL_CALL(opal_pci_shpc, OPAL_PCI_SHPC); 18714a43e69SBenjamin HerrenschmidtOPAL_CALL(opal_pci_phb_mmio_enable, OPAL_PCI_PHB_MMIO_ENABLE); 18814a43e69SBenjamin HerrenschmidtOPAL_CALL(opal_pci_set_phb_mem_window, OPAL_PCI_SET_PHB_MEM_WINDOW); 18914a43e69SBenjamin HerrenschmidtOPAL_CALL(opal_pci_map_pe_mmio_window, OPAL_PCI_MAP_PE_MMIO_WINDOW); 19014a43e69SBenjamin HerrenschmidtOPAL_CALL(opal_pci_set_phb_table_memory, OPAL_PCI_SET_PHB_TABLE_MEMORY); 19114a43e69SBenjamin HerrenschmidtOPAL_CALL(opal_pci_set_pe, OPAL_PCI_SET_PE); 19214a43e69SBenjamin HerrenschmidtOPAL_CALL(opal_pci_set_peltv, OPAL_PCI_SET_PELTV); 19314a43e69SBenjamin HerrenschmidtOPAL_CALL(opal_pci_set_mve, OPAL_PCI_SET_MVE); 19414a43e69SBenjamin HerrenschmidtOPAL_CALL(opal_pci_set_mve_enable, OPAL_PCI_SET_MVE_ENABLE); 19514a43e69SBenjamin HerrenschmidtOPAL_CALL(opal_pci_get_xive_reissue, OPAL_PCI_GET_XIVE_REISSUE); 19614a43e69SBenjamin HerrenschmidtOPAL_CALL(opal_pci_set_xive_reissue, OPAL_PCI_SET_XIVE_REISSUE); 19714a43e69SBenjamin HerrenschmidtOPAL_CALL(opal_pci_set_xive_pe, OPAL_PCI_SET_XIVE_PE); 19814a43e69SBenjamin HerrenschmidtOPAL_CALL(opal_get_xive_source, OPAL_GET_XIVE_SOURCE); 19914a43e69SBenjamin HerrenschmidtOPAL_CALL(opal_get_msi_32, OPAL_GET_MSI_32); 20014a43e69SBenjamin HerrenschmidtOPAL_CALL(opal_get_msi_64, OPAL_GET_MSI_64); 20114a43e69SBenjamin HerrenschmidtOPAL_CALL(opal_start_cpu, OPAL_START_CPU); 20214a43e69SBenjamin HerrenschmidtOPAL_CALL(opal_query_cpu_status, OPAL_QUERY_CPU_STATUS); 20314a43e69SBenjamin HerrenschmidtOPAL_CALL(opal_write_oppanel, OPAL_WRITE_OPPANEL); 20414a43e69SBenjamin HerrenschmidtOPAL_CALL(opal_pci_map_pe_dma_window, OPAL_PCI_MAP_PE_DMA_WINDOW); 20514a43e69SBenjamin HerrenschmidtOPAL_CALL(opal_pci_map_pe_dma_window_real, OPAL_PCI_MAP_PE_DMA_WINDOW_REAL); 20614a43e69SBenjamin HerrenschmidtOPAL_CALL(opal_pci_reset, OPAL_PCI_RESET); 207f11fe552SBenjamin HerrenschmidtOPAL_CALL(opal_pci_get_hub_diag_data, OPAL_PCI_GET_HUB_DIAG_DATA); 208f11fe552SBenjamin HerrenschmidtOPAL_CALL(opal_pci_get_phb_diag_data, OPAL_PCI_GET_PHB_DIAG_DATA); 209f11fe552SBenjamin HerrenschmidtOPAL_CALL(opal_pci_fence_phb, OPAL_PCI_FENCE_PHB); 210f11fe552SBenjamin HerrenschmidtOPAL_CALL(opal_pci_reinit, OPAL_PCI_REINIT); 211f11fe552SBenjamin HerrenschmidtOPAL_CALL(opal_pci_mask_pe_error, OPAL_PCI_MASK_PE_ERROR); 212f11fe552SBenjamin HerrenschmidtOPAL_CALL(opal_set_slot_led_status, OPAL_SET_SLOT_LED_STATUS); 213f11fe552SBenjamin HerrenschmidtOPAL_CALL(opal_get_epow_status, OPAL_GET_EPOW_STATUS); 214f11fe552SBenjamin HerrenschmidtOPAL_CALL(opal_set_system_attention_led, OPAL_SET_SYSTEM_ATTENTION_LED); 21523773230SGavin ShanOPAL_CALL(opal_pci_next_error, OPAL_PCI_NEXT_ERROR); 21623773230SGavin ShanOPAL_CALL(opal_pci_poll, OPAL_PCI_POLL); 217137436c9SGavin ShanOPAL_CALL(opal_pci_msi_eoi, OPAL_PCI_MSI_EOI); 21823773230SGavin ShanOPAL_CALL(opal_pci_get_phb_diag_data2, OPAL_PCI_GET_PHB_DIAG_DATA2); 219cc0efb57SBenjamin HerrenschmidtOPAL_CALL(opal_xscom_read, OPAL_XSCOM_READ); 220cc0efb57SBenjamin HerrenschmidtOPAL_CALL(opal_xscom_write, OPAL_XSCOM_WRITE); 221cc0efb57SBenjamin HerrenschmidtOPAL_CALL(opal_lpc_read, OPAL_LPC_READ); 222cc0efb57SBenjamin HerrenschmidtOPAL_CALL(opal_lpc_write, OPAL_LPC_WRITE); 22313906db6SBenjamin HerrenschmidtOPAL_CALL(opal_return_cpu, OPAL_RETURN_CPU); 2244926616cSBenjamin HerrenschmidtOPAL_CALL(opal_reinit_cpus, OPAL_REINIT_CPUS); 225774fea1aSStewart SmithOPAL_CALL(opal_read_elog, OPAL_ELOG_READ); 226774fea1aSStewart SmithOPAL_CALL(opal_send_ack_elog, OPAL_ELOG_ACK); 227774fea1aSStewart SmithOPAL_CALL(opal_get_elog_size, OPAL_ELOG_SIZE); 228774fea1aSStewart SmithOPAL_CALL(opal_resend_pending_logs, OPAL_ELOG_RESEND); 229774fea1aSStewart SmithOPAL_CALL(opal_write_elog, OPAL_ELOG_WRITE); 23050bd6153SVasant HegdeOPAL_CALL(opal_validate_flash, OPAL_FLASH_VALIDATE); 23150bd6153SVasant HegdeOPAL_CALL(opal_manage_flash, OPAL_FLASH_MANAGE); 23250bd6153SVasant HegdeOPAL_CALL(opal_update_flash, OPAL_FLASH_UPDATE); 23397eb001fSVaidyanathan SrinivasanOPAL_CALL(opal_resync_timebase, OPAL_RESYNC_TIMEBASE); 234c7e64b9cSStewart SmithOPAL_CALL(opal_dump_init, OPAL_DUMP_INIT); 235c7e64b9cSStewart SmithOPAL_CALL(opal_dump_info, OPAL_DUMP_INFO); 236c7e64b9cSStewart SmithOPAL_CALL(opal_dump_info2, OPAL_DUMP_INFO2); 237c7e64b9cSStewart SmithOPAL_CALL(opal_dump_read, OPAL_DUMP_READ); 238c7e64b9cSStewart SmithOPAL_CALL(opal_dump_ack, OPAL_DUMP_ACK); 23924366360SMahesh SalgaonkarOPAL_CALL(opal_get_msg, OPAL_GET_MSG); 24024366360SMahesh SalgaonkarOPAL_CALL(opal_check_completion, OPAL_CHECK_ASYNC_COMPLETION); 241c7e64b9cSStewart SmithOPAL_CALL(opal_dump_resend_notification, OPAL_DUMP_RESEND); 242f7d98d18SVasant HegdeOPAL_CALL(opal_sync_host_reboot, OPAL_SYNC_HOST_REBOOT); 2437224adbbSNeelesh GuptaOPAL_CALL(opal_sensor_read, OPAL_SENSOR_READ); 2444029cd66SNeelesh GuptaOPAL_CALL(opal_get_param, OPAL_GET_PARAM); 2454029cd66SNeelesh GuptaOPAL_CALL(opal_set_param, OPAL_SET_PARAM); 246