close cache.

This commit is contained in:
TXuian 2024-03-15 10:36:29 +08:00
parent 3dc6d58bdb
commit 892613a0d5
8 changed files with 52 additions and 69 deletions

View File

@ -74,7 +74,7 @@ Modification:
#include "cortex_a9.h"
#define NR_CPU 4
#define NR_CPU 1
__attribute__((always_inline)) static inline uint32_t user_mode()
{

View File

@ -233,6 +233,7 @@ struct ICacheDone* hardkernel_icache_init(struct TraceTag* hardkernel_tag)
{
/* init icache */
icache_done.enable();
// icache_done.disable();
return &icache_done;
}
@ -240,5 +241,6 @@ struct DCacheDone* hardkernel_dcache_init(struct TraceTag* hardkernel_tag)
{
/* init dcache */
dcache_done.enable();
// dcache_done.disable();
return &dcache_done;
}

View File

@ -214,9 +214,12 @@ bool secondary_cpu_hardkernel_init(int cpu_id, struct TraceTag* _hardkernel_tag)
// secondary cpu init hardwares
// intr
p_intr_driver->sys_irq_init(cpu_id);
p_intr_driver->cpu_irq_disable();
// cache
p_icache_driver->enable();
p_dcache_driver->enable();
// p_icache_driver->enable();
// p_dcache_driver->enable();
p_icache_driver->disable();
p_dcache_driver->disable();
// clock
p_clock_driver->sys_clock_init();
p_intr_driver->single_irq_enable(p_clock_driver->get_clock_int(), cpu_id, 0);

View File

@ -496,31 +496,26 @@ void tracer_find_tag(struct TraceTag* target, struct TraceTag* const source, cha
bool AchieveResourceTag(struct TraceTag* target, struct TraceTag* owner, char* name)
{
spinlock_lock(&ac_tracer_lock);
tracer_find_tag(target, owner, name);
if (target->meta == NULL) {
return false;
}
spinlock_unlock(&ac_tracer_lock);
return true;
}
void* AchieveResource(struct TraceTag* target)
{
spinlock_lock(&ac_tracer_lock);
if (target->type == TRACER_OWNER) {
return NULL;
}
void* p_resource = NULL;
tracer_read_trace(target, (char*)&p_resource, 0, sizeof(void*));
assert(p_resource != NULL);
spinlock_unlock(&ac_tracer_lock);
return p_resource;
}
bool CreateResourceTag(struct TraceTag* new_tag, struct TraceTag* owner, char* name, tracemeta_ac_type type, void* p_resource)
{
// spinlock_lock(&ac_tracer_lock);
new_tag->type = type;
if (type == TRACER_OWNER) {
return tracer_create_trace(new_tag, owner, name, type);
@ -535,13 +530,10 @@ bool CreateResourceTag(struct TraceTag* new_tag, struct TraceTag* owner, char* n
return false;
}
bool ret = tracer_write_trace(new_tag, (char*)&p_resource, 0, sizeof(void*)) == sizeof(void*);
// spinlock_unlock(&ac_tracer_lock);
return ret;
}
bool DeleteResource(struct TraceTag* target, struct TraceTag* owner)
{
spinlock_lock(&ac_tracer_lock);
return tracer_delete_trace(target, owner);
spinlock_unlock(&ac_tracer_lock);
}

View File

@ -37,7 +37,10 @@ Modification:
#include "assert.h"
#include "task.h"
#include "trap_common.h"
#include "cache_common_ope.h"
extern uint32_t _binary_init_start[], _binary_default_fs_start[];
static struct TraceTag hardkernel_tag, softkernel_tag;
void configure_cpu(uint32_t cpu)
{
@ -55,6 +58,18 @@ void configure_cpu(uint32_t cpu)
// arm_icache_enable();
// arm_icache_invalidate();
struct TraceTag main_icache_tag, main_dcache_tag;
AchieveResourceTag(&main_icache_tag, &hardkernel_tag, "icache-ac-resource");
AchieveResourceTag(&main_dcache_tag, &hardkernel_tag, "dcache-ac-resource");
struct ICacheDone* p_icache_driver = AchieveResource(&main_icache_tag);
struct DCacheDone* p_dcache_driver = AchieveResource(&main_dcache_tag);
// p_dcache_driver->enable();
// p_dcache_driver->invalidateall();
// p_icache_driver->enable();
// p_icache_driver->invalidateall();
p_dcache_driver->disable();
p_icache_driver->disable();
// Invalidate SCU copy of TAG RAMs
scu_secure_invalidate(cpu, all_ways);
@ -63,59 +78,31 @@ void configure_cpu(uint32_t cpu)
scu_enable_maintenance_broadcast();
}
typedef void (*cpu_entry_point_t)(void* arg);
typedef struct _core_startup_info {
cpu_entry_point_t entry; //!< Function to call after starting a core.
void* arg; //!< Argument to pass core entry point.
} core_startup_info_t;
static core_startup_info_t s_core_info[NR_CPU] = { { 0 } };
static void common_cpu_entry(void)
{
uint32_t myCoreNumber = cpu_get_current();
core_startup_info_t* info = &s_core_info[myCoreNumber];
// Call the requested entry point for this CPU number.
if (info->entry) {
info->entry(info->arg);
}
}
extern void _boot_start();
void cpu_start_secondary(uint8_t coreNumber, cpu_entry_point_t entryPoint, void* arg)
void cpu_start_secondary(uint8_t coreNumber)
{
// Save entry point and arg.
s_core_info[coreNumber].entry = entryPoint;
s_core_info[coreNumber].arg = arg;
// Prepare pointers for ROM code. The entry point is always _start, which does some
// basic preparatory work and then calls the common_cpu_entry function, which itself
// calls the entry point saved in s_core_info.
switch (coreNumber) {
case 1:
HW_SRC_GPR3_WR((uint32_t)&_boot_start);
HW_SRC_SCR.B.CORE1_ENABLE = 1;
break;
case 2:
HW_SRC_GPR5_WR((uint32_t)&_boot_start);
HW_SRC_SCR.B.CORE2_ENABLE = 1;
break;
case 3:
HW_SRC_GPR7_WR((uint32_t)&_boot_start);
HW_SRC_SCR.B.CORE3_ENABLE = 1;
break;
}
}
extern uint32_t _binary_init_start[], _binary_default_fs_start[];
static struct TraceTag hardkernel_tag, softkernel_tag;
static bool init = false;
static int core_init_done = 0;
int main(void)
{
/* init tracer */
@ -135,21 +122,19 @@ int main(void)
return -1;
}
// scu_enable();
// configure_cpu(cpu_id);
spinlock_init(&whole_kernel_lock, "wklock");
} else {
configure_cpu(cpu_id);
DEBUG_PRINTF("CPU %d started init: %d(at %x).\n", cur_cpuid(), init, &init);
spinlock_lock(&whole_kernel_lock);
secondary_cpu_hardkernel_init(cpu_id, &hardkernel_tag);
DEBUG_PRINTF("CPU %d init done.\n", cur_cpuid());
spinlock_unlock(&whole_kernel_lock);
DEBUG_PRINTF("CPU %d started done.\n", cur_cpuid());
}
struct TraceTag main_intr_tag;
AchieveResourceTag(&main_intr_tag, &hardkernel_tag, "intr-ac-resource");
struct XiziTrapDriver* p_intr_driver = (struct XiziTrapDriver*)AchieveResource(&main_intr_tag);
p_intr_driver->cpu_irq_disable();
spinlock_lock(&whole_kernel_lock);
if (cpu_id == 0) {
/* init softkernel */
if (!softkernel_init(&hardkernel_tag, &softkernel_tag)) {
@ -158,11 +143,10 @@ int main(void)
show_xizi_bar();
int cpu_count = NR_CPU;
scu_enable();
configure_cpu(cpu_id);
;
for (int i = 1; i < cpu_count; i++) {
// start secondary cpus
cpu_start_secondary(i, NULL, 0);
cpu_start_secondary(i);
}
/* start first task */
@ -170,19 +154,19 @@ int main(void)
spawn_embedded_task((char*)_binary_init_start, "init", init_task_param);
char* fs_server_task_param[2] = { "/app/fs_server", 0 };
spawn_embedded_task((char*)_binary_default_fs_start, "memfs", fs_server_task_param);
init = true;
}
// p_intr_driver->cpu_irq_disable();
while (!init)
;
/* start scheduler */
struct SchedulerRightGroup scheduler_rights;
assert(AchieveResourceTag(&scheduler_rights.mmu_driver_tag, &hardkernel_tag, "mmu-ac-resource"));
assert(AchieveResourceTag(&scheduler_rights.intr_driver_tag, &hardkernel_tag, "intr-ac-resource"));
// while (true) { }
core_init_done |= (1 << cpu_id);
DEBUG("core_init_done: %x\n", core_init_done);
spinlock_unlock(&whole_kernel_lock);
while (core_init_done != (1 << NR_CPU) - 1)
;
xizi_task_manager.task_scheduler(scheduler_rights);
// never reached

View File

@ -299,6 +299,6 @@ void load_kern_pgdir(struct TraceTag* mmu_driver_tag, struct TraceTag* intr_driv
void secondary_cpu_load_kern_pgdir(struct TraceTag* mmu_driver_tag, struct TraceTag* intr_driver_tag)
{
// _p_pgtbl_mmu_access->LoadPgdir((uintptr_t)V2P(kern_pgdir.pd_addr));
_p_pgtbl_mmu_access->LoadPgdirCrit((uintptr_t)V2P(kern_pgdir.pd_addr), intr_driver_tag);
_p_pgtbl_mmu_access->LoadPgdir((uintptr_t)V2P(kern_pgdir.pd_addr));
// _p_pgtbl_mmu_access->LoadPgdirCrit((uintptr_t)V2P(kern_pgdir.pd_addr), intr_driver_tag);
}

View File

@ -65,8 +65,9 @@ void intr_irq_dispatch(struct trapframe* tf)
if ((int_info = p_intr_driver->hw_before_irq()) == 0) {
return;
}
spinlock_lock(&whole_kernel_lock);
// DEBUG("CPU %d in kernel %s %d\n", cur_cpuid(), __func__, __LINE__);
// spinlock_lock(&whole_kernel_lock);
DSB();
// DEBUG("CPU %d in\n", cur_cpuid());
struct TaskMicroDescriptor* current_task = cur_cpu()->task;
if (LIKELY(current_task != NULL)) {
@ -94,7 +95,7 @@ void intr_irq_dispatch(struct trapframe* tf)
}
assert(current_task == cur_cpu()->task);
// DEBUG("CPU %d out kernel %s %d\n", cur_cpuid(), __func__, __LINE__);
spinlock_unlock(&whole_kernel_lock);
// DEBUG("CPU %d out\n", cur_cpuid());
// spinlock_unlock(&whole_kernel_lock);
p_intr_driver->cpu_irq_enable();
}

View File

@ -52,8 +52,9 @@ void software_irq_dispatch(struct trapframe* tf)
assert(p_intr_driver != NULL);
p_intr_driver->cpu_irq_disable();
spinlock_lock(&whole_kernel_lock);
// DEBUG("CPU %d in kernel %s %d\n", cur_cpuid(), __func__, __LINE__);
// spinlock_lock(&whole_kernel_lock);
DSB();
// DEBUG("CPU %d in\n", cur_cpuid());
// get current task
struct TaskMicroDescriptor* cur_task = cur_cpu()->task;
/// @todo: Handle dead task
@ -80,7 +81,7 @@ void software_irq_dispatch(struct trapframe* tf)
ERROR("Exit reaches");
}
// DEBUG("CPU %d out kernel %s %d\n", cur_cpuid(), __func__, __LINE__);
spinlock_unlock(&whole_kernel_lock);
// DEBUG("CPU %d out\n", cur_cpuid());
// spinlock_unlock(&whole_kernel_lock);
p_intr_driver->cpu_irq_enable();
}