metalsvm/arch/x86/scc/scc_init.c
2011-04-13 11:03:34 -07:00

98 lines
2.6 KiB
C

/*
* Copyright 2010 Stefan Lankes, Chair for Operating Systems,
* RWTH Aachen University
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR COND */
#include <metalsvm/stdio.h>
#include <metalsvm/errno.h>
#include <metalsvm/processor.h>
#include <metalsvm/errno.h>
#include <asm/io.h>
#include <asm/RCCE_lib.h>
#include <asm/SCC_API.h>
#ifdef CONFIG_ROCKCREEK
bootinfo_t* bootinfo = (bootinfo_t*) SCC_BOOTINFO;
/* PSE bit for Pentium+ equals MPE (message buffer enable) flag in RCK! So, use it to create _PAGE_MPB symbol... */
#define _CR4_MPE 0x00000800
/*
* This is the modified MPB program, which is part of the RCCE distribution (src/mpb.c).
*
* This function clears the local MPB and resets the test&set register.
*/
static int scc_clear(void)
{
int tmp, x, y, z, offset;
// Find out who I am...
tmp=ReadConfigReg(CRB_OWN+MYTILEID);
x=(tmp>>3) & 0x0f; // bits 06:03
y=(tmp>>7) & 0x0f; // bits 10:07
z=(tmp ) & 0x07; // bits 02:00
// Allocate Message Passing Buffer
t_vcharp MPB;
MPBalloc(&MPB, x, y, z, 1);
if (!MPB) {
kprintf("Unable to allocate MPB for core %d of Tile x=%d, y= %d! Exiting.\n", z, x, y);
return 255;
}
// zap own MPB
for (offset=0; offset < 0x2000; offset+=8)
*(volatile unsigned long long int*)(MPB+offset) = 0;
// Clear test&set register write. Next read-access will read "1" (lock granted).
SetConfigReg(CRB_ADDR(x,y)+((z)?LOCK1:LOCK0), 1);
return 0;
}
int scc_init(void)
{
int num_ranks;
int i, my_rank;
kprintf("Initialize Rock Creek!\n");
kprintf("address of the initrd: 0x%x\n", bootinfo->addr);
kprintf("size of the initrd: %d\n", bootinfo->size);
kprintf("rcce argc = %d\n", bootinfo->argc);
for(i=0; i<bootinfo->argc; i++)
kprintf("rcce argv[%d] = %s\n", i, bootinfo->argv[i]);
if (RCCE_init(&bootinfo->argc, &bootinfo->argv) != RCCE_SUCCESS)
return -ENODEV;
my_rank = RCCE_ue();
num_ranks = RCCE_num_ues();
kprintf("Got rank %d of %d ranks\n", my_rank, num_ranks);
/* Enable Messagepassing in CR4 */
uint32_t cr4 = read_cr4();
cr4 = cr4 | _CR4_MPE;
write_cr4(cr4);
i = ReadConfigReg(CRB_OWN+GLCFG0);
kprintf("glcfg0 0x%x\n", i);
/* synchronize before starting MetalSVM: */
//RCCE_barrier(&RCCE_COMM_WORLD);
kputs("Now, the SCC is initialized!\n");
return 0;
}
#endif