155d9950aSThomas Huth /*
255d9950aSThomas Huth * Common Hardware Reference Platform NVRAM functions.
355d9950aSThomas Huth *
455d9950aSThomas Huth * This code is free software; you can redistribute it and/or modify
555d9950aSThomas Huth * it under the terms of the GNU General Public License as published
655d9950aSThomas Huth * by the Free Software Foundation; either version 2 of the License,
755d9950aSThomas Huth * or (at your option) any later version.
855d9950aSThomas Huth *
955d9950aSThomas Huth * This program is distributed in the hope that it will be useful,
1055d9950aSThomas Huth * but WITHOUT ANY WARRANTY; without even the implied warranty of
1155d9950aSThomas Huth * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1255d9950aSThomas Huth * GNU General Public License for more details.
1355d9950aSThomas Huth *
1455d9950aSThomas Huth * You should have received a copy of the GNU General Public License
1555d9950aSThomas Huth * along with this program; if not, see <http://www.gnu.org/licenses/>.
1655d9950aSThomas Huth */
1755d9950aSThomas Huth
1855d9950aSThomas Huth #ifndef CHRP_NVRAM_H
1955d9950aSThomas Huth #define CHRP_NVRAM_H
2055d9950aSThomas Huth
21ec150c7eSMarkus Armbruster #include "qemu/bswap.h"
22ec150c7eSMarkus Armbruster
23ad723fe5SThomas Huth /* OpenBIOS NVRAM partition */
24ad723fe5SThomas Huth typedef struct {
25ad723fe5SThomas Huth uint8_t signature;
26ad723fe5SThomas Huth uint8_t checksum;
27ad723fe5SThomas Huth uint16_t len; /* Big endian, length divided by 16 */
28ad723fe5SThomas Huth char name[12];
29ad723fe5SThomas Huth } ChrpNvramPartHdr;
30ad723fe5SThomas Huth
31ad723fe5SThomas Huth #define CHRP_NVPART_SYSTEM 0x70
32ad723fe5SThomas Huth #define CHRP_NVPART_FREE 0x7f
33ad723fe5SThomas Huth
34ad723fe5SThomas Huth static inline void
chrp_nvram_finish_partition(ChrpNvramPartHdr * header,uint32_t size)35ad723fe5SThomas Huth chrp_nvram_finish_partition(ChrpNvramPartHdr *header, uint32_t size)
36ad723fe5SThomas Huth {
37ad723fe5SThomas Huth unsigned int i, sum;
38ad723fe5SThomas Huth uint8_t *tmpptr;
39ad723fe5SThomas Huth
40ad723fe5SThomas Huth /* Length divided by 16 */
41ad723fe5SThomas Huth header->len = cpu_to_be16(size >> 4);
42ad723fe5SThomas Huth
43ad723fe5SThomas Huth /* Checksum */
44ad723fe5SThomas Huth tmpptr = (uint8_t *)header;
45ad723fe5SThomas Huth sum = *tmpptr;
46ad723fe5SThomas Huth for (i = 0; i < 14; i++) {
47ad723fe5SThomas Huth sum += tmpptr[2 + i];
48ad723fe5SThomas Huth sum = (sum + ((sum & 0xff00) >> 8)) & 0xff;
49ad723fe5SThomas Huth }
50ad723fe5SThomas Huth header->checksum = sum & 0xff;
51ad723fe5SThomas Huth }
52ad723fe5SThomas Huth
53*37035df5SGreg Kurz /* chrp_nvram_create_system_partition() failure is fatal */
54*37035df5SGreg Kurz int chrp_nvram_create_system_partition(uint8_t *data, int min_len, int max_len);
5555d9950aSThomas Huth int chrp_nvram_create_free_partition(uint8_t *data, int len);
5655d9950aSThomas Huth
5755d9950aSThomas Huth #endif
58