Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / sam / include / property.h
/*
* ========== Copyright Header Begin ==========================================
*
* OpenSPARC T2 Processor File: property.h
* Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES.
*
* The above named program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License version 2 as published by the Free Software Foundation.
*
* The above named program is distributed in the hope that 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.
*
* You should have received a copy of the GNU General Public
* License along with this work; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*
* ========== Copyright Header End ============================================
*/
#ifndef _FAKEPROM_PROPERTY_H
#define _FAKEPROM_PROPERTY_H
#include <inttypes.h>
//#include <pci.h>
#include <ctype.h>
#include "mem.h"
#include <strings.h>
extern memT *mm1;
#define ARRAY(what) sizeof (what), (caddr_t)&what
#define RARRAY(what) sizeof (what), (caddr_t)what
#define ZARRAY(what) 0, (caddr_t)&what
struct property {
char *name;
int size;
char* value;
void copyProp(const property *rhs){
if(rhs->name){
name = new char[strlen(rhs->name)+1];
strcpy(name,rhs->name);
}else
name = 0;
size = rhs->size;
value = rhs->value;
}
void setName(const char * nm){
name = new char[strlen(nm)+1];
strcpy(name,nm);
}
void setSize(int sz){ size = sz; }
void setValue(caddr_t vl){ value = vl;}
void print(){
printf("\nName - %s\n",name);
printf("Size - %d\n",size);
for(int i = 0; i < size; i++){
printf("%x(%c) ",(uint8_t)*(value+i),isprint(*(value+i))?*(value+i):' ');
}
}
};
struct property_list_elem {
property p;
property_list_elem *next;
};
struct property_list{
property_list_elem *head;
property_list_elem *tail;
int count;
static uint64_t fkprom_dtinbuf_pa;// = 0x50;
static int fkprom_dtinbuf_offset; //= 0; offset at which to write device property data
property_list()
{
head = tail = 0;
count =0;
}
void add(property * p) {
property_list_elem * e = new property_list_elem;
e->next = 0;
e->p.copyProp(p);
if (head == 0) {
head = tail = e;
} else {
tail->next = e;
tail = e;
}
count++;
}
void add_bunch(property *propbunch) {
do{
add(propbunch++);
}while(propbunch->name != 0);
add(propbunch); //add an empty property at end
add(propbunch); //add an empty property at end
}
~property_list(){
while(head){
property_list_elem * pptr = head->next;
delete head;
head = pptr;
}
}
void writeToFakeProm(){
//printf("start writing to fk buff\n" );
// add properties to fakeprom device tree input buffer
struct property_list_elem * e;
bool lastprop = false;
for (e=head; e != 0 && !lastprop; e=e->next) {
if (e->p.name != 0) {
memwrite8u_blk_nl(mm1,
fkprom_dtinbuf_pa+fkprom_dtinbuf_offset,
(unsigned char *) e->p.name,
(int) strlen(e->p.name)+1);
fkprom_dtinbuf_offset += (strlen(e->p.name)+1); // including null terminator
fkprom_dtinbuf_offset = (fkprom_dtinbuf_offset+3) & ~3u; // align 4-byte boundary
memwrite8u_blk_nl(mm1, fkprom_dtinbuf_pa+fkprom_dtinbuf_offset, (unsigned char *) &(e->p.size), sizeof(int));
fkprom_dtinbuf_offset += 4;
fkprom_dtinbuf_offset = (fkprom_dtinbuf_offset+7) & ~7u; // align 8-byte boundary
if (e->p.size) {
int fk_data_pa = (int)(fkprom_dtinbuf_offset+sizeof(caddr_t)+fkprom_dtinbuf_pa);
memwrite8u_blk_nl(mm1, fkprom_dtinbuf_pa+fkprom_dtinbuf_offset , (unsigned char *)&fk_data_pa, sizeof(caddr_t));
memwrite8u_blk_nl(mm1, fk_data_pa, (unsigned char *) e->p.value, e->p.size);
fkprom_dtinbuf_offset += (e->p.size+sizeof(caddr_t));
}
} else /* name is null - end of properties */ {
if (!lastprop) {
memwrite8u(mm1, fkprom_dtinbuf_pa+fkprom_dtinbuf_offset, 0);
fkprom_dtinbuf_offset++;
memwrite8u(mm1, fkprom_dtinbuf_pa+fkprom_dtinbuf_offset, 0); // write a null character at the next location in case this is the end
lastprop = true;
}
}
}
}
void print(){
#if 0
property_list_elem * e = head;
while(e && e->p.name ){
e->p.print();
e=e->next;
}
#endif
}
};
#endif