Ye Li | 0db17f4 | 2021-08-07 16:00:41 +0800 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
| 2 | /* |
| 3 | * Copyright 2020 NXP |
| 4 | * |
| 5 | */ |
| 6 | |
| 7 | #include <common.h> |
| 8 | #include <hang.h> |
| 9 | #include <malloc.h> |
| 10 | #include <asm/io.h> |
| 11 | #include <dm.h> |
| 12 | #include <asm/arch/s400_api.h> |
| 13 | #include <misc.h> |
| 14 | |
| 15 | DECLARE_GLOBAL_DATA_PTR; |
| 16 | |
Ye Li | a61f267 | 2021-08-07 16:00:52 +0800 | [diff] [blame^] | 17 | int ahab_release_rdc(u8 core_id, u32 *response) |
Ye Li | 0db17f4 | 2021-08-07 16:00:41 +0800 | [diff] [blame] | 18 | { |
| 19 | struct udevice *dev = gd->arch.s400_dev; |
| 20 | int size = sizeof(struct imx8ulp_s400_msg); |
| 21 | struct imx8ulp_s400_msg msg; |
| 22 | int ret; |
| 23 | |
| 24 | if (!dev) { |
| 25 | printf("s400 dev is not initialized\n"); |
| 26 | return -ENODEV; |
| 27 | } |
| 28 | |
| 29 | msg.version = AHAB_VERSION; |
| 30 | msg.tag = AHAB_CMD_TAG; |
| 31 | msg.size = 2; |
| 32 | msg.command = AHAB_RELEASE_RDC_REQ_CID; |
| 33 | msg.data[0] = core_id; |
| 34 | |
| 35 | ret = misc_call(dev, false, &msg, size, &msg, size); |
| 36 | if (ret) |
| 37 | printf("Error: %s: ret %d, core id %u, response 0x%x\n", |
| 38 | __func__, ret, core_id, msg.data[0]); |
| 39 | |
Ye Li | a61f267 | 2021-08-07 16:00:52 +0800 | [diff] [blame^] | 40 | if (response) |
| 41 | *response = msg.data[0]; |
| 42 | |
| 43 | return ret; |
| 44 | } |
| 45 | |
| 46 | int ahab_auth_oem_ctnr(ulong ctnr_addr, u32 *response) |
| 47 | { |
| 48 | struct udevice *dev = gd->arch.s400_dev; |
| 49 | int size = sizeof(struct imx8ulp_s400_msg); |
| 50 | struct imx8ulp_s400_msg msg; |
| 51 | int ret; |
| 52 | |
| 53 | if (!dev) { |
| 54 | printf("s400 dev is not initialized\n"); |
| 55 | return -ENODEV; |
| 56 | } |
| 57 | |
| 58 | msg.version = AHAB_VERSION; |
| 59 | msg.tag = AHAB_CMD_TAG; |
| 60 | msg.size = 3; |
| 61 | msg.command = AHAB_AUTH_OEM_CTNR_CID; |
| 62 | msg.data[0] = upper_32_bits(ctnr_addr); |
| 63 | msg.data[1] = lower_32_bits(ctnr_addr); |
| 64 | |
| 65 | ret = misc_call(dev, false, &msg, size, &msg, size); |
| 66 | if (ret) |
| 67 | printf("Error: %s: ret %d, cntr_addr 0x%lx, response 0x%x\n", |
| 68 | __func__, ret, ctnr_addr, msg.data[0]); |
| 69 | |
| 70 | if (response) |
| 71 | *response = msg.data[0]; |
| 72 | |
| 73 | return ret; |
| 74 | } |
| 75 | |
| 76 | int ahab_release_container(u32 *response) |
| 77 | { |
| 78 | struct udevice *dev = gd->arch.s400_dev; |
| 79 | int size = sizeof(struct imx8ulp_s400_msg); |
| 80 | struct imx8ulp_s400_msg msg; |
| 81 | int ret; |
| 82 | |
| 83 | if (!dev) { |
| 84 | printf("s400 dev is not initialized\n"); |
| 85 | return -ENODEV; |
| 86 | } |
| 87 | |
| 88 | msg.version = AHAB_VERSION; |
| 89 | msg.tag = AHAB_CMD_TAG; |
| 90 | msg.size = 1; |
| 91 | msg.command = AHAB_RELEASE_CTNR_CID; |
| 92 | |
| 93 | ret = misc_call(dev, false, &msg, size, &msg, size); |
| 94 | if (ret) |
| 95 | printf("Error: %s: ret %d, response 0x%x\n", |
| 96 | __func__, ret, msg.data[0]); |
| 97 | |
| 98 | if (response) |
| 99 | *response = msg.data[0]; |
| 100 | |
| 101 | return ret; |
| 102 | } |
| 103 | |
| 104 | int ahab_verify_image(u32 img_id, u32 *response) |
| 105 | { |
| 106 | struct udevice *dev = gd->arch.s400_dev; |
| 107 | int size = sizeof(struct imx8ulp_s400_msg); |
| 108 | struct imx8ulp_s400_msg msg; |
| 109 | int ret; |
| 110 | |
| 111 | if (!dev) { |
| 112 | printf("s400 dev is not initialized\n"); |
| 113 | return -ENODEV; |
| 114 | } |
| 115 | |
| 116 | msg.version = AHAB_VERSION; |
| 117 | msg.tag = AHAB_CMD_TAG; |
| 118 | msg.size = 2; |
| 119 | msg.command = AHAB_VERIFY_IMG_CID; |
| 120 | msg.data[0] = 1 << img_id; |
| 121 | |
| 122 | ret = misc_call(dev, false, &msg, size, &msg, size); |
| 123 | if (ret) |
| 124 | printf("Error: %s: ret %d, img_id %u, response 0x%x\n", |
| 125 | __func__, ret, img_id, msg.data[0]); |
| 126 | |
| 127 | if (response) |
| 128 | *response = msg.data[0]; |
| 129 | |
| 130 | return ret; |
| 131 | } |
| 132 | |
| 133 | int ahab_forward_lifecycle(u16 life_cycle, u32 *response) |
| 134 | { |
| 135 | struct udevice *dev = gd->arch.s400_dev; |
| 136 | int size = sizeof(struct imx8ulp_s400_msg); |
| 137 | struct imx8ulp_s400_msg msg; |
| 138 | int ret; |
| 139 | |
| 140 | if (!dev) { |
| 141 | printf("s400 dev is not initialized\n"); |
| 142 | return -ENODEV; |
| 143 | } |
| 144 | |
| 145 | msg.version = AHAB_VERSION; |
| 146 | msg.tag = AHAB_CMD_TAG; |
| 147 | msg.size = 2; |
| 148 | msg.command = AHAB_FWD_LIFECYCLE_UP_REQ_CID; |
| 149 | msg.data[0] = life_cycle; |
| 150 | |
| 151 | ret = misc_call(dev, false, &msg, size, &msg, size); |
| 152 | if (ret) |
| 153 | printf("Error: %s: ret %d, life_cycle 0x%x, response 0x%x\n", |
| 154 | __func__, ret, life_cycle, msg.data[0]); |
| 155 | |
| 156 | if (response) |
| 157 | *response = msg.data[0]; |
| 158 | |
Ye Li | 0db17f4 | 2021-08-07 16:00:41 +0800 | [diff] [blame] | 159 | return ret; |
| 160 | } |