| 1 | /* |
| 2 | * ========== Copyright Header Begin ========================================== |
| 3 | * |
| 4 | * OpenSPARC T2 Processor File: property.h |
| 5 | * Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved. |
| 6 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES. |
| 7 | * |
| 8 | * The above named program is free software; you can redistribute it and/or |
| 9 | * modify it under the terms of the GNU General Public |
| 10 | * License version 2 as published by the Free Software Foundation. |
| 11 | * |
| 12 | * The above named program is distributed in the hope that it will be |
| 13 | * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 | * General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public |
| 18 | * License along with this work; if not, write to the Free Software |
| 19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. |
| 20 | * |
| 21 | * ========== Copyright Header End ============================================ |
| 22 | */ |
| 23 | #ifndef _FAKEPROM_PROPERTY_H |
| 24 | #define _FAKEPROM_PROPERTY_H |
| 25 | |
| 26 | #include <inttypes.h> |
| 27 | //#include <pci.h> |
| 28 | #include <ctype.h> |
| 29 | #include "mem.h" |
| 30 | #include <strings.h> |
| 31 | |
| 32 | |
| 33 | extern memT *mm1; |
| 34 | |
| 35 | #define ARRAY(what) sizeof (what), (caddr_t)&what |
| 36 | #define RARRAY(what) sizeof (what), (caddr_t)what |
| 37 | #define ZARRAY(what) 0, (caddr_t)&what |
| 38 | |
| 39 | struct property { |
| 40 | char *name; |
| 41 | int size; |
| 42 | char* value; |
| 43 | |
| 44 | void copyProp(const property *rhs){ |
| 45 | if(rhs->name){ |
| 46 | name = new char[strlen(rhs->name)+1]; |
| 47 | strcpy(name,rhs->name); |
| 48 | }else |
| 49 | name = 0; |
| 50 | size = rhs->size; |
| 51 | value = rhs->value; |
| 52 | |
| 53 | } |
| 54 | |
| 55 | void setName(const char * nm){ |
| 56 | name = new char[strlen(nm)+1]; |
| 57 | strcpy(name,nm); |
| 58 | } |
| 59 | |
| 60 | void setSize(int sz){ size = sz; } |
| 61 | |
| 62 | void setValue(caddr_t vl){ value = vl;} |
| 63 | |
| 64 | void print(){ |
| 65 | printf("\nName - %s\n",name); |
| 66 | printf("Size - %d\n",size); |
| 67 | for(int i = 0; i < size; i++){ |
| 68 | printf("%x(%c) ",(uint8_t)*(value+i),isprint(*(value+i))?*(value+i):' '); |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | }; |
| 73 | |
| 74 | struct property_list_elem { |
| 75 | property p; |
| 76 | property_list_elem *next; |
| 77 | }; |
| 78 | |
| 79 | struct property_list{ |
| 80 | property_list_elem *head; |
| 81 | property_list_elem *tail; |
| 82 | int count; |
| 83 | |
| 84 | static uint64_t fkprom_dtinbuf_pa;// = 0x50; |
| 85 | static int fkprom_dtinbuf_offset; //= 0; offset at which to write device property data |
| 86 | |
| 87 | property_list() |
| 88 | { |
| 89 | head = tail = 0; |
| 90 | count =0; |
| 91 | } |
| 92 | |
| 93 | void add(property * p) { |
| 94 | property_list_elem * e = new property_list_elem; |
| 95 | e->next = 0; |
| 96 | e->p.copyProp(p); |
| 97 | if (head == 0) { |
| 98 | head = tail = e; |
| 99 | } else { |
| 100 | tail->next = e; |
| 101 | tail = e; |
| 102 | } |
| 103 | count++; |
| 104 | } |
| 105 | |
| 106 | void add_bunch(property *propbunch) { |
| 107 | do{ |
| 108 | add(propbunch++); |
| 109 | }while(propbunch->name != 0); |
| 110 | add(propbunch); //add an empty property at end |
| 111 | add(propbunch); //add an empty property at end |
| 112 | } |
| 113 | ~property_list(){ |
| 114 | while(head){ |
| 115 | property_list_elem * pptr = head->next; |
| 116 | delete head; |
| 117 | head = pptr; |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | void writeToFakeProm(){ |
| 122 | //printf("start writing to fk buff\n" ); |
| 123 | // add properties to fakeprom device tree input buffer |
| 124 | struct property_list_elem * e; |
| 125 | bool lastprop = false; |
| 126 | for (e=head; e != 0 && !lastprop; e=e->next) { |
| 127 | if (e->p.name != 0) { |
| 128 | memwrite8u_blk_nl(mm1, |
| 129 | fkprom_dtinbuf_pa+fkprom_dtinbuf_offset, |
| 130 | (unsigned char *) e->p.name, |
| 131 | (int) strlen(e->p.name)+1); |
| 132 | fkprom_dtinbuf_offset += (strlen(e->p.name)+1); // including null terminator |
| 133 | |
| 134 | fkprom_dtinbuf_offset = (fkprom_dtinbuf_offset+3) & ~3u; // align 4-byte boundary |
| 135 | memwrite8u_blk_nl(mm1, fkprom_dtinbuf_pa+fkprom_dtinbuf_offset, (unsigned char *) &(e->p.size), sizeof(int)); |
| 136 | fkprom_dtinbuf_offset += 4; |
| 137 | fkprom_dtinbuf_offset = (fkprom_dtinbuf_offset+7) & ~7u; // align 8-byte boundary |
| 138 | if (e->p.size) { |
| 139 | int fk_data_pa = (int)(fkprom_dtinbuf_offset+sizeof(caddr_t)+fkprom_dtinbuf_pa); |
| 140 | memwrite8u_blk_nl(mm1, fkprom_dtinbuf_pa+fkprom_dtinbuf_offset , (unsigned char *)&fk_data_pa, sizeof(caddr_t)); |
| 141 | memwrite8u_blk_nl(mm1, fk_data_pa, (unsigned char *) e->p.value, e->p.size); |
| 142 | fkprom_dtinbuf_offset += (e->p.size+sizeof(caddr_t)); |
| 143 | } |
| 144 | } else /* name is null - end of properties */ { |
| 145 | if (!lastprop) { |
| 146 | memwrite8u(mm1, fkprom_dtinbuf_pa+fkprom_dtinbuf_offset, 0); |
| 147 | fkprom_dtinbuf_offset++; |
| 148 | memwrite8u(mm1, fkprom_dtinbuf_pa+fkprom_dtinbuf_offset, 0); // write a null character at the next location in case this is the end |
| 149 | lastprop = true; |
| 150 | } |
| 151 | } |
| 152 | } |
| 153 | } |
| 154 | void print(){ |
| 155 | #if 0 |
| 156 | property_list_elem * e = head; |
| 157 | while(e && e->p.name ){ |
| 158 | e->p.print(); |
| 159 | e=e->next; |
| 160 | } |
| 161 | #endif |
| 162 | } |
| 163 | |
| 164 | }; |
| 165 | |
| 166 | #endif |