|
| 1 | +/* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | + |
| 3 | +#include <cpu/power/scom.h> |
| 4 | +#include <cpu/power/occ.h> |
| 5 | +#include <timer.h> |
| 6 | + |
| 7 | + |
| 8 | +static void pm_ocb_setup(const uint32_t i_ocb_bar) |
| 9 | +{ |
| 10 | + write_scom(OCBCSRn_OR[0], PPC_BIT(OCB_PIB_OCBCSR0_OCB_STREAM_MODE)); |
| 11 | + write_scom(OCBCSRn_CLEAR[0], PPC_BIT(OCB_PIB_OCBCSR0_OCB_STREAM_TYPE)); |
| 12 | + write_scom(OCBARn[0], (uint64_t)i_ocb_bar << 32); |
| 13 | +} |
| 14 | + |
| 15 | +static void put_ocb_indirect( |
| 16 | + const uint32_t i_ocb_req_length, |
| 17 | + const uint32_t i_oci_address, |
| 18 | + uint64_t* io_ocb_buffer) |
| 19 | +{ |
| 20 | + write_scom(PU_OCB_PIB_OCBAR0, (uint64_t)i_oci_address << 32); |
| 21 | + uint64_t ocb_pib = read_scom(PU_OCB_PIB_OCBCSR0_RO); |
| 22 | + if((ocb_pib & OCB_PIB_OCBCSR0_OCB_STREAM_MODE) |
| 23 | + && (ocb_pib & OCB_PIB_OCBCSR0_OCB_STREAM_TYPE)) |
| 24 | + { |
| 25 | + uint64_t stream_push_control = read_scom(PU_OCB_OCI_OCBSHCS0_SCOM); |
| 26 | + if (stream_push_control & OCB_OCI_OCBSHCS0_PUSH_ENABLE) |
| 27 | + for(uint8_t l_counter = 0; l_counter < 4; l_counter++) |
| 28 | + { |
| 29 | + if (!(stream_push_control & OCB_OCI_OCBSHCS0_PUSH_FULL)) |
| 30 | + { |
| 31 | + break; |
| 32 | + } |
| 33 | + // Hostboot has delay of 0 here |
| 34 | + wait_us(1, false); |
| 35 | + stream_push_control = read_scom(PU_OCB_OCI_OCBSHCS0_SCOM); |
| 36 | + } |
| 37 | + } |
| 38 | + for(uint32_t l_index = 0; l_index < i_ocb_req_length; l_index++) |
| 39 | + { |
| 40 | + write_scom(PU_OCB_PIB_OCBDR0, io_ocb_buffer[l_index]); |
| 41 | + } |
| 42 | +} |
| 43 | + |
| 44 | +static void get_ocb_indirect( |
| 45 | + const uint32_t i_ocb_req_length, |
| 46 | + const uint32_t i_oci_address, |
| 47 | + uint64_t* io_ocb_buffer) |
| 48 | +{ |
| 49 | + write_scom(PU_OCB_PIB_OCBAR0, (uint64_t)i_oci_address << 32); |
| 50 | + for(uint32_t l_loopCount = 0; l_loopCount < i_ocb_req_length; l_loopCount++) |
| 51 | + { |
| 52 | + io_ocb_buffer[l_loopCount] = read_scom(PU_OCB_PIB_OCBDR0); |
| 53 | + } |
| 54 | +} |
| 55 | + |
| 56 | +void writeOCCSRAM( |
| 57 | + const uint32_t address, |
| 58 | + uint64_t * buffer, |
| 59 | + size_t data_length) |
| 60 | +{ |
| 61 | + pm_ocb_setup(address); |
| 62 | + put_ocb_indirect( |
| 63 | + data_length / 8, |
| 64 | + address, |
| 65 | + buffer); |
| 66 | +} |
| 67 | + |
| 68 | +void readOCCSRAM( |
| 69 | + const uint32_t address, |
| 70 | + uint64_t * buffer, |
| 71 | + size_t data_length) |
| 72 | +{ |
| 73 | + pm_ocb_setup(address); |
| 74 | + get_ocb_indirect( |
| 75 | + data_length / 8, |
| 76 | + address, |
| 77 | + buffer); |
| 78 | +} |
| 79 | + |
| 80 | +uint64_t makeStart405Instruction(void) |
| 81 | +{ |
| 82 | + uint64_t l_epAddr; |
| 83 | + readOCCSRAM( |
| 84 | + OCC_405_SRAM_ADDRESS + OCC_OFFSET_MAIN_EP, |
| 85 | + &l_epAddr, |
| 86 | + 8); |
| 87 | + |
| 88 | + // The branch instruction is of the form 0x4BXXXXX200000000, where X |
| 89 | + // is the address of the 405 main's entry point (alligned as shown). |
| 90 | + // Example: If 405 main's EP is FFF5B570, then the branch instruction |
| 91 | + // will be 0x4bf5b57200000000. The last two bits of the first byte of |
| 92 | + // the branch instruction must be '2' according to the OCC instruction |
| 93 | + // set manual. |
| 94 | + return OCC_BRANCH_INSTR | (((uint64_t)(BRANCH_ADDR_MASK & l_epAddr)) << 32); |
| 95 | +} |
| 96 | + |
| 97 | +void clear_occ_special_wakeups(void) |
| 98 | +{ |
| 99 | + for(size_t chiplet_index = 0; |
| 100 | + chiplet_index < NUMBER_OF_EX_CHIPLETS; |
| 101 | + ++chiplet_index) |
| 102 | + { |
| 103 | + write_scom_for_chiplet( |
| 104 | + EX_CHIPLETS[chiplet_index], |
| 105 | + EX_PPM_SPWKUP_OCC, |
| 106 | + read_scom_for_chiplet(EX_CHIPLETS[chiplet_index], |
| 107 | + EX_PPM_SPWKUP_OCC) & ~PPC_BIT(0)); |
| 108 | + } |
| 109 | +} |
0 commit comments