1e9b60476SAmit Daniel Kachhap/* SPDX-License-Identifier: GPL-2.0 */ 2e9b60476SAmit Daniel Kachhap/* Copyright (C) 2020 ARM Limited */ 3e9b60476SAmit Daniel Kachhap 4e9b60476SAmit Daniel Kachhap#include "mte_def.h" 5e9b60476SAmit Daniel Kachhap 6*55c8a987SMark Brown.arch armv8.5-a+memtag 7*55c8a987SMark Brown 8e9b60476SAmit Daniel Kachhap#define ENTRY(name) \ 9e9b60476SAmit Daniel Kachhap .globl name ;\ 10e9b60476SAmit Daniel Kachhap .p2align 2;\ 11e9b60476SAmit Daniel Kachhap .type name, @function ;\ 12e9b60476SAmit Daniel Kachhapname: 13e9b60476SAmit Daniel Kachhap 14e9b60476SAmit Daniel Kachhap#define ENDPROC(name) \ 15e9b60476SAmit Daniel Kachhap .size name, .-name ; 16e9b60476SAmit Daniel Kachhap 17e9b60476SAmit Daniel Kachhap .text 18e9b60476SAmit Daniel Kachhap/* 19e9b60476SAmit Daniel Kachhap * mte_insert_random_tag: Insert random tag and might be same as the source tag if 20e9b60476SAmit Daniel Kachhap * the source pointer has it. 21e9b60476SAmit Daniel Kachhap * Input: 22e9b60476SAmit Daniel Kachhap * x0 - source pointer with a tag/no-tag 23e9b60476SAmit Daniel Kachhap * Return: 24e9b60476SAmit Daniel Kachhap * x0 - pointer with random tag 25e9b60476SAmit Daniel Kachhap */ 26e9b60476SAmit Daniel KachhapENTRY(mte_insert_random_tag) 27e9b60476SAmit Daniel Kachhap irg x0, x0, xzr 28e9b60476SAmit Daniel Kachhap ret 29e9b60476SAmit Daniel KachhapENDPROC(mte_insert_random_tag) 30e9b60476SAmit Daniel Kachhap 31e9b60476SAmit Daniel Kachhap/* 324dafc08dSAmit Daniel Kachhap * mte_insert_new_tag: Insert new tag and different from the source tag if 334dafc08dSAmit Daniel Kachhap * source pointer has it. 344dafc08dSAmit Daniel Kachhap * Input: 354dafc08dSAmit Daniel Kachhap * x0 - source pointer with a tag/no-tag 364dafc08dSAmit Daniel Kachhap * Return: 374dafc08dSAmit Daniel Kachhap * x0 - pointer with random tag 384dafc08dSAmit Daniel Kachhap */ 394dafc08dSAmit Daniel KachhapENTRY(mte_insert_new_tag) 404dafc08dSAmit Daniel Kachhap gmi x1, x0, xzr 414dafc08dSAmit Daniel Kachhap irg x0, x0, x1 424dafc08dSAmit Daniel Kachhap ret 434dafc08dSAmit Daniel KachhapENDPROC(mte_insert_new_tag) 444dafc08dSAmit Daniel Kachhap 454dafc08dSAmit Daniel Kachhap/* 46e9b60476SAmit Daniel Kachhap * mte_get_tag_address: Get the tag from given address. 47e9b60476SAmit Daniel Kachhap * Input: 48e9b60476SAmit Daniel Kachhap * x0 - source pointer 49e9b60476SAmit Daniel Kachhap * Return: 50e9b60476SAmit Daniel Kachhap * x0 - pointer with appended tag 51e9b60476SAmit Daniel Kachhap */ 52e9b60476SAmit Daniel KachhapENTRY(mte_get_tag_address) 53e9b60476SAmit Daniel Kachhap ldg x0, [x0] 54e9b60476SAmit Daniel Kachhap ret 55e9b60476SAmit Daniel KachhapENDPROC(mte_get_tag_address) 56e9b60476SAmit Daniel Kachhap 57e9b60476SAmit Daniel Kachhap/* 58e9b60476SAmit Daniel Kachhap * mte_set_tag_address_range: Set the tag range from the given address 59e9b60476SAmit Daniel Kachhap * Input: 60e9b60476SAmit Daniel Kachhap * x0 - source pointer with tag data 61e9b60476SAmit Daniel Kachhap * x1 - range 62e9b60476SAmit Daniel Kachhap * Return: 63e9b60476SAmit Daniel Kachhap * none 64e9b60476SAmit Daniel Kachhap */ 65e9b60476SAmit Daniel KachhapENTRY(mte_set_tag_address_range) 66e9b60476SAmit Daniel Kachhap cbz x1, 2f 67e9b60476SAmit Daniel Kachhap1: 68e9b60476SAmit Daniel Kachhap stg x0, [x0, #0x0] 69e9b60476SAmit Daniel Kachhap add x0, x0, #MT_GRANULE_SIZE 70e9b60476SAmit Daniel Kachhap sub x1, x1, #MT_GRANULE_SIZE 71e9b60476SAmit Daniel Kachhap cbnz x1, 1b 72e9b60476SAmit Daniel Kachhap2: 73e9b60476SAmit Daniel Kachhap ret 74e9b60476SAmit Daniel KachhapENDPROC(mte_set_tag_address_range) 75e9b60476SAmit Daniel Kachhap 76e9b60476SAmit Daniel Kachhap/* 77e9b60476SAmit Daniel Kachhap * mt_clear_tag_address_range: Clear the tag range from the given address 78e9b60476SAmit Daniel Kachhap * Input: 79e9b60476SAmit Daniel Kachhap * x0 - source pointer with tag data 80e9b60476SAmit Daniel Kachhap * x1 - range 81e9b60476SAmit Daniel Kachhap * Return: 82e9b60476SAmit Daniel Kachhap * none 83e9b60476SAmit Daniel Kachhap */ 84e9b60476SAmit Daniel KachhapENTRY(mte_clear_tag_address_range) 85e9b60476SAmit Daniel Kachhap cbz x1, 2f 86e9b60476SAmit Daniel Kachhap1: 87e9b60476SAmit Daniel Kachhap stzg x0, [x0, #0x0] 88e9b60476SAmit Daniel Kachhap add x0, x0, #MT_GRANULE_SIZE 89e9b60476SAmit Daniel Kachhap sub x1, x1, #MT_GRANULE_SIZE 90e9b60476SAmit Daniel Kachhap cbnz x1, 1b 91e9b60476SAmit Daniel Kachhap2: 92e9b60476SAmit Daniel Kachhap ret 93e9b60476SAmit Daniel KachhapENDPROC(mte_clear_tag_address_range) 94e9b60476SAmit Daniel Kachhap 95e9b60476SAmit Daniel Kachhap/* 96e9b60476SAmit Daniel Kachhap * mte_enable_pstate_tco: Enable PSTATE.TCO (tag check override) field 97e9b60476SAmit Daniel Kachhap * Input: 98e9b60476SAmit Daniel Kachhap * none 99e9b60476SAmit Daniel Kachhap * Return: 100e9b60476SAmit Daniel Kachhap * none 101e9b60476SAmit Daniel Kachhap */ 102e9b60476SAmit Daniel KachhapENTRY(mte_enable_pstate_tco) 103e9b60476SAmit Daniel Kachhap msr tco, #MT_PSTATE_TCO_EN 104e9b60476SAmit Daniel Kachhap ret 105e9b60476SAmit Daniel KachhapENDPROC(mte_enable_pstate_tco) 106e9b60476SAmit Daniel Kachhap 107e9b60476SAmit Daniel Kachhap/* 108e9b60476SAmit Daniel Kachhap * mte_disable_pstate_tco: Disable PSTATE.TCO (tag check override) field 109e9b60476SAmit Daniel Kachhap * Input: 110e9b60476SAmit Daniel Kachhap * none 111e9b60476SAmit Daniel Kachhap * Return: 112e9b60476SAmit Daniel Kachhap * none 113e9b60476SAmit Daniel Kachhap */ 114e9b60476SAmit Daniel KachhapENTRY(mte_disable_pstate_tco) 115e9b60476SAmit Daniel Kachhap msr tco, #MT_PSTATE_TCO_DIS 116e9b60476SAmit Daniel Kachhap ret 117e9b60476SAmit Daniel KachhapENDPROC(mte_disable_pstate_tco) 118e9b60476SAmit Daniel Kachhap 119e9b60476SAmit Daniel Kachhap/* 120e9b60476SAmit Daniel Kachhap * mte_get_pstate_tco: Get PSTATE.TCO (tag check override) field 121e9b60476SAmit Daniel Kachhap * Input: 122e9b60476SAmit Daniel Kachhap * none 123e9b60476SAmit Daniel Kachhap * Return: 124e9b60476SAmit Daniel Kachhap * x0 125e9b60476SAmit Daniel Kachhap */ 126e9b60476SAmit Daniel KachhapENTRY(mte_get_pstate_tco) 127e9b60476SAmit Daniel Kachhap mrs x0, tco 128e9b60476SAmit Daniel Kachhap ubfx x0, x0, #MT_PSTATE_TCO_SHIFT, #1 129e9b60476SAmit Daniel Kachhap ret 130e9b60476SAmit Daniel KachhapENDPROC(mte_get_pstate_tco) 131