diff options
Diffstat (limited to 'drivers/staging/media/atomisp/pci/runtime/spctrl')
3 files changed, 300 insertions, 0 deletions
diff --git a/drivers/staging/media/atomisp/pci/runtime/spctrl/interface/ia_css_spctrl.h b/drivers/staging/media/atomisp/pci/runtime/spctrl/interface/ia_css_spctrl.h new file mode 100644 index 0000000000..efe6c4a82c --- /dev/null +++ b/drivers/staging/media/atomisp/pci/runtime/spctrl/interface/ia_css_spctrl.h @@ -0,0 +1,69 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Support for Intel Camera Imaging ISP subsystem. + * Copyright (c) 2010 - 2015, Intel Corporation. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + */ + +#ifndef __IA_CSS_SPCTRL_H__ +#define __IA_CSS_SPCTRL_H__ + +#include <system_global.h> +#include <ia_css_err.h> +#include "ia_css_spctrl_comm.h" + +typedef struct { + u32 ddr_data_offset; /** posistion of data in DDR */ + u32 dmem_data_addr; /** data segment address in dmem */ + u32 dmem_bss_addr; /** bss segment address in dmem */ + u32 data_size; /** data segment size */ + u32 bss_size; /** bss segment size */ + u32 spctrl_config_dmem_addr; /* <location of dmem_cfg in SP dmem */ + u32 spctrl_state_dmem_addr; /* < location of state in SP dmem */ + unsigned int sp_entry; /* < entry function ptr on SP */ + const void *code; /** location of firmware */ + u32 code_size; + char *program_name; /** not used on hardware, only for simulation */ +} ia_css_spctrl_cfg; + +/* Get the code addr in DDR of SP */ +ia_css_ptr get_sp_code_addr(sp_ID_t sp_id); + +/* ! Load firmware on to specfied SP +*/ +int ia_css_spctrl_load_fw(sp_ID_t sp_id, + ia_css_spctrl_cfg *spctrl_cfg); + +/* ISP2401 */ +/*! Setup registers for reloading FW */ +void sh_css_spctrl_reload_fw(sp_ID_t sp_id); + +/*! Unload/release any memory allocated to hold the firmware +*/ +int ia_css_spctrl_unload_fw(sp_ID_t sp_id); + +/*! Intilaize dmem_cfg in SP dmem and start SP program +*/ +int ia_css_spctrl_start(sp_ID_t sp_id); + +/*! stop spctrl +*/ +int ia_css_spctrl_stop(sp_ID_t sp_id); + +/*! Query the state of SP +*/ +ia_css_spctrl_sp_sw_state ia_css_spctrl_get_state(sp_ID_t sp_id); + +/*! Check if SP is idle/ready +*/ +int ia_css_spctrl_is_idle(sp_ID_t sp_id); + +#endif /* __IA_CSS_SPCTRL_H__ */ diff --git a/drivers/staging/media/atomisp/pci/runtime/spctrl/interface/ia_css_spctrl_comm.h b/drivers/staging/media/atomisp/pci/runtime/spctrl/interface/ia_css_spctrl_comm.h new file mode 100644 index 0000000000..78e0f3096f --- /dev/null +++ b/drivers/staging/media/atomisp/pci/runtime/spctrl/interface/ia_css_spctrl_comm.h @@ -0,0 +1,46 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Support for Intel Camera Imaging ISP subsystem. + * Copyright (c) 2010 - 2015, Intel Corporation. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + */ + +#ifndef __IA_CSS_SPCTRL_COMM_H__ +#define __IA_CSS_SPCTRL_COMM_H__ + +#include <type_support.h> + +/* state of SP */ +typedef enum { + IA_CSS_SP_SW_TERMINATED = 0, + IA_CSS_SP_SW_INITIALIZED, + IA_CSS_SP_SW_CONNECTED, + IA_CSS_SP_SW_RUNNING +} ia_css_spctrl_sp_sw_state; + +/* Structure to encapsulate required arguments for + * initialization of SP DMEM using the SP itself + */ +struct ia_css_sp_init_dmem_cfg { + ia_css_ptr ddr_data_addr; /** data segment address in ddr */ + u32 dmem_data_addr; /** data segment address in dmem */ + u32 dmem_bss_addr; /** bss segment address in dmem */ + u32 data_size; /** data segment size */ + u32 bss_size; /** bss segment size */ + sp_ID_t sp_id; /* <sp Id */ +}; + +#define SIZE_OF_IA_CSS_SP_INIT_DMEM_CFG_STRUCT \ + (1 * SIZE_OF_IA_CSS_PTR) + \ + (4 * sizeof(uint32_t)) + \ + (1 * sizeof(sp_ID_t)) + +#endif /* __IA_CSS_SPCTRL_COMM_H__ */ diff --git a/drivers/staging/media/atomisp/pci/runtime/spctrl/src/spctrl.c b/drivers/staging/media/atomisp/pci/runtime/spctrl/src/spctrl.c new file mode 100644 index 0000000000..c34bfc5f97 --- /dev/null +++ b/drivers/staging/media/atomisp/pci/runtime/spctrl/src/spctrl.c @@ -0,0 +1,185 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Support for Intel Camera Imaging ISP subsystem. + * Copyright (c) 2010 - 2015, Intel Corporation. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + */ + +#include "hmm.h" + +#include "ia_css_types.h" +#define __INLINE_SP__ +#include "sp.h" + +#include "assert_support.h" +#include "ia_css_spctrl.h" +#include "ia_css_debug.h" + +struct spctrl_context_info { + struct ia_css_sp_init_dmem_cfg dmem_config; + u32 spctrl_config_dmem_addr; /* location of dmem_cfg in SP dmem */ + u32 spctrl_state_dmem_addr; + unsigned int sp_entry; /* entry function ptr on SP */ + ia_css_ptr code_addr; /* sp firmware location in host mem-DDR*/ + u32 code_size; + char *program_name; /* used in case of PLATFORM_SIM */ +}; + +static struct spctrl_context_info spctrl_cofig_info[N_SP_ID]; +static bool spctrl_loaded[N_SP_ID] = {0}; + +/* Load firmware */ +int ia_css_spctrl_load_fw(sp_ID_t sp_id, ia_css_spctrl_cfg *spctrl_cfg) +{ + ia_css_ptr code_addr = mmgr_NULL; + struct ia_css_sp_init_dmem_cfg *init_dmem_cfg; + + if ((sp_id >= N_SP_ID) || (!spctrl_cfg)) + return -EINVAL; + + spctrl_cofig_info[sp_id].code_addr = mmgr_NULL; + + init_dmem_cfg = &spctrl_cofig_info[sp_id].dmem_config; + init_dmem_cfg->dmem_data_addr = spctrl_cfg->dmem_data_addr; + init_dmem_cfg->dmem_bss_addr = spctrl_cfg->dmem_bss_addr; + init_dmem_cfg->data_size = spctrl_cfg->data_size; + init_dmem_cfg->bss_size = spctrl_cfg->bss_size; + init_dmem_cfg->sp_id = sp_id; + + spctrl_cofig_info[sp_id].spctrl_config_dmem_addr = + spctrl_cfg->spctrl_config_dmem_addr; + spctrl_cofig_info[sp_id].spctrl_state_dmem_addr = + spctrl_cfg->spctrl_state_dmem_addr; + + /* store code (text + icache) and data to DDR + * + * Data used to be stored separately, because of access alignment constraints, + * fix the FW generation instead + */ + code_addr = hmm_alloc(spctrl_cfg->code_size); + if (code_addr == mmgr_NULL) + return -ENOMEM; + hmm_store(code_addr, spctrl_cfg->code, spctrl_cfg->code_size); + + if (sizeof(ia_css_ptr) > sizeof(hrt_data)) { + ia_css_debug_dtrace(IA_CSS_DEBUG_ERROR, + "size of ia_css_ptr can not be greater than hrt_data\n"); + hmm_free(code_addr); + code_addr = mmgr_NULL; + return -EINVAL; + } + + init_dmem_cfg->ddr_data_addr = code_addr + spctrl_cfg->ddr_data_offset; + if ((init_dmem_cfg->ddr_data_addr % HIVE_ISP_DDR_WORD_BYTES) != 0) { + ia_css_debug_dtrace(IA_CSS_DEBUG_ERROR, + "DDR address pointer is not properly aligned for DMA transfer\n"); + hmm_free(code_addr); + code_addr = mmgr_NULL; + return -EINVAL; + } + + spctrl_cofig_info[sp_id].sp_entry = spctrl_cfg->sp_entry; + spctrl_cofig_info[sp_id].code_addr = code_addr; + spctrl_cofig_info[sp_id].program_name = spctrl_cfg->program_name; + + /* now we program the base address into the icache and + * invalidate the cache. + */ + sp_ctrl_store(sp_id, SP_ICACHE_ADDR_REG, + (hrt_data)spctrl_cofig_info[sp_id].code_addr); + sp_ctrl_setbit(sp_id, SP_ICACHE_INV_REG, SP_ICACHE_INV_BIT); + spctrl_loaded[sp_id] = true; + return 0; +} + +/* ISP2401 */ +/* reload pre-loaded FW */ +void sh_css_spctrl_reload_fw(sp_ID_t sp_id) +{ + /* now we program the base address into the icache and + * invalidate the cache. + */ + sp_ctrl_store(sp_id, SP_ICACHE_ADDR_REG, + (hrt_data)spctrl_cofig_info[sp_id].code_addr); + sp_ctrl_setbit(sp_id, SP_ICACHE_INV_REG, SP_ICACHE_INV_BIT); + spctrl_loaded[sp_id] = true; +} + +ia_css_ptr get_sp_code_addr(sp_ID_t sp_id) +{ + return spctrl_cofig_info[sp_id].code_addr; +} + +int ia_css_spctrl_unload_fw(sp_ID_t sp_id) +{ + if ((sp_id >= N_SP_ID) || ((sp_id < N_SP_ID) && (!spctrl_loaded[sp_id]))) + return -EINVAL; + + /* freeup the resource */ + if (spctrl_cofig_info[sp_id].code_addr) { + hmm_free(spctrl_cofig_info[sp_id].code_addr); + spctrl_cofig_info[sp_id].code_addr = mmgr_NULL; + } + spctrl_loaded[sp_id] = false; + return 0; +} + +/* Initialize dmem_cfg in SP dmem and start SP program*/ +int ia_css_spctrl_start(sp_ID_t sp_id) +{ + if ((sp_id >= N_SP_ID) || ((sp_id < N_SP_ID) && (!spctrl_loaded[sp_id]))) + return -EINVAL; + + /* Set descr in the SP to initialize the SP DMEM */ + /* + * The FW stores user-space pointers to the FW, the ISP pointer + * is only available here + * + */ + assert(sizeof(unsigned int) <= sizeof(hrt_data)); + + sp_dmem_store(sp_id, + spctrl_cofig_info[sp_id].spctrl_config_dmem_addr, + &spctrl_cofig_info[sp_id].dmem_config, + sizeof(spctrl_cofig_info[sp_id].dmem_config)); + /* set the start address */ + sp_ctrl_store(sp_id, SP_START_ADDR_REG, + (hrt_data)spctrl_cofig_info[sp_id].sp_entry); + sp_ctrl_setbit(sp_id, SP_SC_REG, SP_RUN_BIT); + sp_ctrl_setbit(sp_id, SP_SC_REG, SP_START_BIT); + return 0; +} + +/* Query the state of SP1 */ +ia_css_spctrl_sp_sw_state ia_css_spctrl_get_state(sp_ID_t sp_id) +{ + ia_css_spctrl_sp_sw_state state = 0; + unsigned int HIVE_ADDR_sp_sw_state; + + if (sp_id >= N_SP_ID) + return IA_CSS_SP_SW_TERMINATED; + + HIVE_ADDR_sp_sw_state = spctrl_cofig_info[sp_id].spctrl_state_dmem_addr; + (void)HIVE_ADDR_sp_sw_state; /* Suppres warnings in CRUN */ + if (sp_id == SP0_ID) + state = sp_dmem_load_uint32(sp_id, (unsigned int)sp_address_of(sp_sw_state)); + return state; +} + +int ia_css_spctrl_is_idle(sp_ID_t sp_id) +{ + int state = 0; + + assert(sp_id < N_SP_ID); + + state = sp_ctrl_getbit(sp_id, SP_SC_REG, SP_IDLE_BIT); + return state; +} |