^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * c 2001 PPC 64 Team, IBM Corp
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * /proc/powerpc/rtas/firmware_flash interface
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * This file implements a firmware_flash interface to pump a firmware
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * image into the kernel. At reboot time rtas_restart() will see the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * firmware image and flash it as it reboots (see rtas.c).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/proc_fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/reboot.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <asm/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <asm/rtas.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #define MODULE_VERS "1.0"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #define MODULE_NAME "rtas_flash"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #define FIRMWARE_FLASH_NAME "firmware_flash"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #define FIRMWARE_UPDATE_NAME "firmware_update"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #define MANAGE_FLASH_NAME "manage_flash"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #define VALIDATE_FLASH_NAME "validate_flash"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) /* General RTAS Status Codes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #define RTAS_RC_SUCCESS 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #define RTAS_RC_HW_ERR -1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) #define RTAS_RC_BUSY -2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) /* Flash image status values */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) #define FLASH_AUTH -9002 /* RTAS Not Service Authority Partition */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) #define FLASH_NO_OP -1099 /* No operation initiated by user */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) #define FLASH_IMG_SHORT -1005 /* Flash image shorter than expected */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) #define FLASH_IMG_BAD_LEN -1004 /* Bad length value in flash list block */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) #define FLASH_IMG_NULL_DATA -1003 /* Bad data value in flash list block */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) #define FLASH_IMG_READY 0 /* Firmware img ready for flash on reboot */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) /* Manage image status values */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) #define MANAGE_AUTH -9002 /* RTAS Not Service Authority Partition */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) #define MANAGE_ACTIVE_ERR -9001 /* RTAS Cannot Overwrite Active Img */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) #define MANAGE_NO_OP -1099 /* No operation initiated by user */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) #define MANAGE_PARAM_ERR -3 /* RTAS Parameter Error */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) #define MANAGE_HW_ERR -1 /* RTAS Hardware Error */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) /* Validate image status values */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) #define VALIDATE_AUTH -9002 /* RTAS Not Service Authority Partition */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) #define VALIDATE_NO_OP -1099 /* No operation initiated by the user */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) #define VALIDATE_INCOMPLETE -1002 /* User copied < VALIDATE_BUF_SIZE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) #define VALIDATE_READY -1001 /* Firmware image ready for validation */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) #define VALIDATE_PARAM_ERR -3 /* RTAS Parameter Error */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) #define VALIDATE_HW_ERR -1 /* RTAS Hardware Error */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) /* ibm,validate-flash-image update result tokens */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) #define VALIDATE_TMP_UPDATE 0 /* T side will be updated */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) #define VALIDATE_FLASH_AUTH 1 /* Partition does not have authority */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) #define VALIDATE_INVALID_IMG 2 /* Candidate image is not valid */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) #define VALIDATE_CUR_UNKNOWN 3 /* Current fixpack level is unknown */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) * Current T side will be committed to P side before being replace with new
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) * image, and the new image is downlevel from current image
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) #define VALIDATE_TMP_COMMIT_DL 4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) * Current T side will be committed to P side before being replaced with new
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) * image
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) #define VALIDATE_TMP_COMMIT 5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) * T side will be updated with a downlevel image
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) #define VALIDATE_TMP_UPDATE_DL 6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) * The candidate image's release date is later than the system's firmware
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) * service entitlement date - service warranty period has expired
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) #define VALIDATE_OUT_OF_WRNTY 7
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) /* ibm,manage-flash-image operation tokens */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) #define RTAS_REJECT_TMP_IMG 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) #define RTAS_COMMIT_TMP_IMG 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) /* Array sizes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) #define VALIDATE_BUF_SIZE 4096
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) #define VALIDATE_MSG_LEN 256
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) #define RTAS_MSG_MAXLEN 64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) /* Quirk - RTAS requires 4k list length and block size */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) #define RTAS_BLKLIST_LENGTH 4096
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) #define RTAS_BLK_SIZE 4096
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) struct flash_block {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) char *data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) unsigned long length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) /* This struct is very similar but not identical to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) * that needed by the rtas flash update.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) * All we need to do for rtas is rewrite num_blocks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) * into a version/length and translate the pointers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) * to absolute.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) #define FLASH_BLOCKS_PER_NODE ((RTAS_BLKLIST_LENGTH - 16) / sizeof(struct flash_block))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) struct flash_block_list {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) unsigned long num_blocks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) struct flash_block_list *next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) struct flash_block blocks[FLASH_BLOCKS_PER_NODE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) static struct flash_block_list *rtas_firmware_flash_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) /* Use slab cache to guarantee 4k alignment */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) static struct kmem_cache *flash_block_cache = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) #define FLASH_BLOCK_LIST_VERSION (1UL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) * Local copy of the flash block list.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) * The rtas_firmware_flash_list varable will be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) * set once the data is fully read.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) * For convenience as we build the list we use virtual addrs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) * we do not fill in the version number, and the length field
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) * is treated as the number of entries currently in the block
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) * (i.e. not a byte count). This is all fixed when calling
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) * the flash routine.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) /* Status int must be first member of struct */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) struct rtas_update_flash_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) int status; /* Flash update status */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) struct flash_block_list *flist; /* Local copy of flash block list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) /* Status int must be first member of struct */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) struct rtas_manage_flash_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) int status; /* Returned status */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) /* Status int must be first member of struct */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) struct rtas_validate_flash_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) int status; /* Returned status */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) char *buf; /* Candidate image buffer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) unsigned int buf_size; /* Size of image buf */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) unsigned int update_results; /* Update results token */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) static struct rtas_update_flash_t rtas_update_flash_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) static struct rtas_manage_flash_t rtas_manage_flash_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) static struct rtas_validate_flash_t rtas_validate_flash_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) static DEFINE_MUTEX(rtas_update_flash_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) static DEFINE_MUTEX(rtas_manage_flash_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) static DEFINE_MUTEX(rtas_validate_flash_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) /* Do simple sanity checks on the flash image. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) static int flash_list_valid(struct flash_block_list *flist)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) struct flash_block_list *f;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) unsigned long block_size, image_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) /* Paranoid self test here. We also collect the image size. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) image_size = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) for (f = flist; f; f = f->next) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) for (i = 0; i < f->num_blocks; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) if (f->blocks[i].data == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) return FLASH_IMG_NULL_DATA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) block_size = f->blocks[i].length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) if (block_size <= 0 || block_size > RTAS_BLK_SIZE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) return FLASH_IMG_BAD_LEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) image_size += block_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) if (image_size < (256 << 10)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) if (image_size < 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) return FLASH_NO_OP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) printk(KERN_INFO "FLASH: flash image with %ld bytes stored for hardware flash on reboot\n", image_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) return FLASH_IMG_READY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) static void free_flash_list(struct flash_block_list *f)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) struct flash_block_list *next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) while (f) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) for (i = 0; i < f->num_blocks; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) kmem_cache_free(flash_block_cache, f->blocks[i].data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) next = f->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) kmem_cache_free(flash_block_cache, f);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) f = next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) static int rtas_flash_release(struct inode *inode, struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) struct rtas_update_flash_t *const uf = &rtas_update_flash_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) mutex_lock(&rtas_update_flash_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) if (uf->flist) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) /* File was opened in write mode for a new flash attempt */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) /* Clear saved list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) if (rtas_firmware_flash_list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) free_flash_list(rtas_firmware_flash_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) rtas_firmware_flash_list = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) if (uf->status != FLASH_AUTH)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) uf->status = flash_list_valid(uf->flist);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) if (uf->status == FLASH_IMG_READY)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) rtas_firmware_flash_list = uf->flist;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) free_flash_list(uf->flist);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) uf->flist = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) mutex_unlock(&rtas_update_flash_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) static size_t get_flash_status_msg(int status, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) const char *msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) size_t len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) switch (status) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) case FLASH_AUTH:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) msg = "error: this partition does not have service authority\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) case FLASH_NO_OP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) msg = "info: no firmware image for flash\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) case FLASH_IMG_SHORT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) msg = "error: flash image short\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) case FLASH_IMG_BAD_LEN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) msg = "error: internal error bad length\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) case FLASH_IMG_NULL_DATA:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) msg = "error: internal error null data\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) case FLASH_IMG_READY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) msg = "ready: firmware image ready for flash on reboot\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) return sprintf(buf, "error: unexpected status value %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) len = strlen(msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) memcpy(buf, msg, len + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) return len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) /* Reading the proc file will show status (not the firmware contents) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) static ssize_t rtas_flash_read_msg(struct file *file, char __user *buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) size_t count, loff_t *ppos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) struct rtas_update_flash_t *const uf = &rtas_update_flash_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) char msg[RTAS_MSG_MAXLEN];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) size_t len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) int status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) mutex_lock(&rtas_update_flash_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) status = uf->status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) mutex_unlock(&rtas_update_flash_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) /* Read as text message */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) len = get_flash_status_msg(status, msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) return simple_read_from_buffer(buf, count, ppos, msg, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) static ssize_t rtas_flash_read_num(struct file *file, char __user *buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) size_t count, loff_t *ppos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) struct rtas_update_flash_t *const uf = &rtas_update_flash_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) char msg[RTAS_MSG_MAXLEN];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) int status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) mutex_lock(&rtas_update_flash_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) status = uf->status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) mutex_unlock(&rtas_update_flash_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) /* Read as number */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) sprintf(msg, "%d\n", status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) return simple_read_from_buffer(buf, count, ppos, msg, strlen(msg));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) /* We could be much more efficient here. But to keep this function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) * simple we allocate a page to the block list no matter how small the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) * count is. If the system is low on memory it will be just as well
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) * that we fail....
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) static ssize_t rtas_flash_write(struct file *file, const char __user *buffer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) size_t count, loff_t *off)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) struct rtas_update_flash_t *const uf = &rtas_update_flash_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) char *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) int next_free, rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) struct flash_block_list *fl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) mutex_lock(&rtas_update_flash_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) if (uf->status == FLASH_AUTH || count == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) goto out; /* discard data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) /* In the case that the image is not ready for flashing, the memory
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) * allocated for the block list will be freed upon the release of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) * proc file
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) if (uf->flist == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) uf->flist = kmem_cache_zalloc(flash_block_cache, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) if (!uf->flist)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) goto nomem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) fl = uf->flist;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) while (fl->next)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) fl = fl->next; /* seek to last block_list for append */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) next_free = fl->num_blocks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) if (next_free == FLASH_BLOCKS_PER_NODE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) /* Need to allocate another block_list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) fl->next = kmem_cache_zalloc(flash_block_cache, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) if (!fl->next)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) goto nomem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) fl = fl->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) next_free = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) if (count > RTAS_BLK_SIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) count = RTAS_BLK_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) p = kmem_cache_zalloc(flash_block_cache, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) if (!p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) goto nomem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) if(copy_from_user(p, buffer, count)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) kmem_cache_free(flash_block_cache, p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) rc = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) fl->blocks[next_free].data = p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) fl->blocks[next_free].length = count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) fl->num_blocks++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) mutex_unlock(&rtas_update_flash_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) nomem:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) rc = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) mutex_unlock(&rtas_update_flash_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) * Flash management routines.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) static void manage_flash(struct rtas_manage_flash_t *args_buf, unsigned int op)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) s32 rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) rc = rtas_call(rtas_token("ibm,manage-flash-image"), 1, 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) NULL, op);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) } while (rtas_busy_delay(rc));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) args_buf->status = rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) static ssize_t manage_flash_read(struct file *file, char __user *buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) size_t count, loff_t *ppos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) struct rtas_manage_flash_t *const args_buf = &rtas_manage_flash_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) char msg[RTAS_MSG_MAXLEN];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) int msglen, status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) mutex_lock(&rtas_manage_flash_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) status = args_buf->status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) mutex_unlock(&rtas_manage_flash_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) msglen = sprintf(msg, "%d\n", status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) return simple_read_from_buffer(buf, count, ppos, msg, msglen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) static ssize_t manage_flash_write(struct file *file, const char __user *buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) size_t count, loff_t *off)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) struct rtas_manage_flash_t *const args_buf = &rtas_manage_flash_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) static const char reject_str[] = "0";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) static const char commit_str[] = "1";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) char stkbuf[10];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) int op, rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) mutex_lock(&rtas_manage_flash_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) if ((args_buf->status == MANAGE_AUTH) || (count == 0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) op = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) if (buf) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) if (count > 9) count = 9;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) rc = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) if (copy_from_user (stkbuf, buf, count))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) if (strncmp(stkbuf, reject_str, strlen(reject_str)) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) op = RTAS_REJECT_TMP_IMG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) else if (strncmp(stkbuf, commit_str, strlen(commit_str)) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) op = RTAS_COMMIT_TMP_IMG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) if (op == -1) { /* buf is empty, or contains invalid string */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) rc = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) manage_flash(args_buf, op);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) mutex_unlock(&rtas_manage_flash_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) mutex_unlock(&rtas_manage_flash_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) * Validation routines.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) static void validate_flash(struct rtas_validate_flash_t *args_buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) int token = rtas_token("ibm,validate-flash-image");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) int update_results;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) s32 rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) spin_lock(&rtas_data_buf_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) memcpy(rtas_data_buf, args_buf->buf, VALIDATE_BUF_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) rc = rtas_call(token, 2, 2, &update_results,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) (u32) __pa(rtas_data_buf), args_buf->buf_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) memcpy(args_buf->buf, rtas_data_buf, VALIDATE_BUF_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) spin_unlock(&rtas_data_buf_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) } while (rtas_busy_delay(rc));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) args_buf->status = rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) args_buf->update_results = update_results;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) static int get_validate_flash_msg(struct rtas_validate_flash_t *args_buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) char *msg, int msglen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) int n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) if (args_buf->status >= VALIDATE_TMP_UPDATE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) n = sprintf(msg, "%d\n", args_buf->update_results);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) if ((args_buf->update_results >= VALIDATE_CUR_UNKNOWN) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) (args_buf->update_results == VALIDATE_TMP_UPDATE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) n += snprintf(msg + n, msglen - n, "%s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) args_buf->buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) n = sprintf(msg, "%d\n", args_buf->status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) return n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) static ssize_t validate_flash_read(struct file *file, char __user *buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) size_t count, loff_t *ppos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) struct rtas_validate_flash_t *const args_buf =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) &rtas_validate_flash_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) char msg[VALIDATE_MSG_LEN];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) int msglen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) mutex_lock(&rtas_validate_flash_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) msglen = get_validate_flash_msg(args_buf, msg, VALIDATE_MSG_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) mutex_unlock(&rtas_validate_flash_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) return simple_read_from_buffer(buf, count, ppos, msg, msglen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) static ssize_t validate_flash_write(struct file *file, const char __user *buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) size_t count, loff_t *off)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) struct rtas_validate_flash_t *const args_buf =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) &rtas_validate_flash_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) mutex_lock(&rtas_validate_flash_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) /* We are only interested in the first 4K of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) * candidate image */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) if ((*off >= VALIDATE_BUF_SIZE) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) (args_buf->status == VALIDATE_AUTH)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) *off += count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) mutex_unlock(&rtas_validate_flash_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) if (*off + count >= VALIDATE_BUF_SIZE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) count = VALIDATE_BUF_SIZE - *off;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) args_buf->status = VALIDATE_READY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) args_buf->status = VALIDATE_INCOMPLETE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) if (!access_ok(buf, count)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) rc = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) if (copy_from_user(args_buf->buf + *off, buf, count)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) rc = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) *off += count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) rc = count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) done:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) mutex_unlock(&rtas_validate_flash_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) static int validate_flash_release(struct inode *inode, struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) struct rtas_validate_flash_t *const args_buf =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) &rtas_validate_flash_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) mutex_lock(&rtas_validate_flash_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) if (args_buf->status == VALIDATE_READY) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) args_buf->buf_size = VALIDATE_BUF_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) validate_flash(args_buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) mutex_unlock(&rtas_validate_flash_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) * On-reboot flash update applicator.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) static void rtas_flash_firmware(int reboot_type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) unsigned long image_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) struct flash_block_list *f, *next, *flist;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) unsigned long rtas_block_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) int i, status, update_token;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) if (rtas_firmware_flash_list == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) return; /* nothing to do */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) if (reboot_type != SYS_RESTART) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) printk(KERN_ALERT "FLASH: firmware flash requires a reboot\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) printk(KERN_ALERT "FLASH: the firmware image will NOT be flashed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) update_token = rtas_token("ibm,update-flash-64-and-reboot");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) if (update_token == RTAS_UNKNOWN_SERVICE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) printk(KERN_ALERT "FLASH: ibm,update-flash-64-and-reboot "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) "is not available -- not a service partition?\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) printk(KERN_ALERT "FLASH: firmware will not be flashed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) * Just before starting the firmware flash, cancel the event scan work
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) * to avoid any soft lockup issues.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) rtas_cancel_event_scan();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) * NOTE: the "first" block must be under 4GB, so we create
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) * an entry with no data blocks in the reserved buffer in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) * the kernel data segment.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) spin_lock(&rtas_data_buf_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) flist = (struct flash_block_list *)&rtas_data_buf[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) flist->num_blocks = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) flist->next = rtas_firmware_flash_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) rtas_block_list = __pa(flist);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) if (rtas_block_list >= 4UL*1024*1024*1024) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) printk(KERN_ALERT "FLASH: kernel bug...flash list header addr above 4GB\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) spin_unlock(&rtas_data_buf_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) printk(KERN_ALERT "FLASH: preparing saved firmware image for flash\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) /* Update the block_list in place. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) rtas_firmware_flash_list = NULL; /* too hard to backout on error */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) image_size = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) for (f = flist; f; f = next) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) /* Translate data addrs to absolute */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) for (i = 0; i < f->num_blocks; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) f->blocks[i].data = (char *)cpu_to_be64(__pa(f->blocks[i].data));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) image_size += f->blocks[i].length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) f->blocks[i].length = cpu_to_be64(f->blocks[i].length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) next = f->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) /* Don't translate NULL pointer for last entry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) if (f->next)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) f->next = (struct flash_block_list *)cpu_to_be64(__pa(f->next));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) f->next = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) /* make num_blocks into the version/length field */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) f->num_blocks = (FLASH_BLOCK_LIST_VERSION << 56) | ((f->num_blocks+1)*16);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) f->num_blocks = cpu_to_be64(f->num_blocks);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) printk(KERN_ALERT "FLASH: flash image is %ld bytes\n", image_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) printk(KERN_ALERT "FLASH: performing flash and reboot\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) rtas_progress("Flashing \n", 0x0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) rtas_progress("Please Wait... ", 0x0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) printk(KERN_ALERT "FLASH: this will take several minutes. Do not power off!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) status = rtas_call(update_token, 1, 1, NULL, rtas_block_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) switch (status) { /* should only get "bad" status */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) case 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) printk(KERN_ALERT "FLASH: success\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) case -1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) printk(KERN_ALERT "FLASH: hardware error. Firmware may not be not flashed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) case -3:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) printk(KERN_ALERT "FLASH: image is corrupt or not correct for this platform. Firmware not flashed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) case -4:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) printk(KERN_ALERT "FLASH: flash failed when partially complete. System may not reboot\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) printk(KERN_ALERT "FLASH: unknown flash return code %d\n", status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) spin_unlock(&rtas_data_buf_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) * Manifest of proc files to create
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) struct rtas_flash_file {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) const char *filename;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) const char *rtas_call_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) int *status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) const struct proc_ops ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) static const struct rtas_flash_file rtas_flash_files[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) .filename = "powerpc/rtas/" FIRMWARE_FLASH_NAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) .rtas_call_name = "ibm,update-flash-64-and-reboot",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) .status = &rtas_update_flash_data.status,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) .ops.proc_read = rtas_flash_read_msg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) .ops.proc_write = rtas_flash_write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) .ops.proc_release = rtas_flash_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) .ops.proc_lseek = default_llseek,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) .filename = "powerpc/rtas/" FIRMWARE_UPDATE_NAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) .rtas_call_name = "ibm,update-flash-64-and-reboot",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) .status = &rtas_update_flash_data.status,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) .ops.proc_read = rtas_flash_read_num,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) .ops.proc_write = rtas_flash_write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) .ops.proc_release = rtas_flash_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) .ops.proc_lseek = default_llseek,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) .filename = "powerpc/rtas/" VALIDATE_FLASH_NAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) .rtas_call_name = "ibm,validate-flash-image",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) .status = &rtas_validate_flash_data.status,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) .ops.proc_read = validate_flash_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) .ops.proc_write = validate_flash_write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) .ops.proc_release = validate_flash_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) .ops.proc_lseek = default_llseek,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) .filename = "powerpc/rtas/" MANAGE_FLASH_NAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) .rtas_call_name = "ibm,manage-flash-image",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) .status = &rtas_manage_flash_data.status,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) .ops.proc_read = manage_flash_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) .ops.proc_write = manage_flash_write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) .ops.proc_lseek = default_llseek,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) static int __init rtas_flash_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) if (rtas_token("ibm,update-flash-64-and-reboot") ==
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) RTAS_UNKNOWN_SERVICE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) pr_info("rtas_flash: no firmware flash support\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) rtas_validate_flash_data.buf = kzalloc(VALIDATE_BUF_SIZE, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) if (!rtas_validate_flash_data.buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) flash_block_cache = kmem_cache_create("rtas_flash_cache",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) RTAS_BLK_SIZE, RTAS_BLK_SIZE, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) if (!flash_block_cache) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) printk(KERN_ERR "%s: failed to create block cache\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) goto enomem_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) for (i = 0; i < ARRAY_SIZE(rtas_flash_files); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) const struct rtas_flash_file *f = &rtas_flash_files[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) int token;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) if (!proc_create(f->filename, 0600, NULL, &f->ops))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) goto enomem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) * This code assumes that the status int is the first member of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) * struct
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) token = rtas_token(f->rtas_call_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) if (token == RTAS_UNKNOWN_SERVICE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) *f->status = FLASH_AUTH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) *f->status = FLASH_NO_OP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) rtas_flash_term_hook = rtas_flash_firmware;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) enomem:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) while (--i >= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) const struct rtas_flash_file *f = &rtas_flash_files[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) remove_proc_entry(f->filename, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) kmem_cache_destroy(flash_block_cache);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) enomem_buf:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) kfree(rtas_validate_flash_data.buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) static void __exit rtas_flash_cleanup(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) rtas_flash_term_hook = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) if (rtas_firmware_flash_list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) free_flash_list(rtas_firmware_flash_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) rtas_firmware_flash_list = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) for (i = 0; i < ARRAY_SIZE(rtas_flash_files); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) const struct rtas_flash_file *f = &rtas_flash_files[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) remove_proc_entry(f->filename, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) kmem_cache_destroy(flash_block_cache);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) kfree(rtas_validate_flash_data.buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) module_init(rtas_flash_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) module_exit(rtas_flash_cleanup);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) MODULE_LICENSE("GPL");