From 39426bad550f340dcf2b544ae23f465fbbbc42f5 Mon Sep 17 00:00:00 2001 From: Benjamin Herrenschmidt Date: Fri, 3 Dec 2010 15:02:36 +1100 Subject: Initial qemu/KVM board support Added a new board for SLOF running on KVM/qemu. Signed-off-by: Benjamin Herrenschmidt Signed-off-by: Thomas Huth --- lib/Makefile | 2 +- lib/libbootmsg/Makefile | 6 +++- lib/libbootmsg/bootmsg_lvl.S | 4 +++ lib/libhvcall/Makefile | 53 +++++++++++++++++++++++++++ lib/libhvcall/hvcall.S | 86 ++++++++++++++++++++++++++++++++++++++++++++ lib/libhvcall/hvcall.code | 51 ++++++++++++++++++++++++++ lib/libhvcall/hvcall.in | 18 ++++++++++ lib/libhvcall/libhvcall.h | 65 +++++++++++++++++++++++++++++++++ lib/libnvram/Makefile | 3 +- lib/libnvram/nvram.c | 21 +++++++---- 10 files changed, 300 insertions(+), 9 deletions(-) create mode 100644 lib/libhvcall/Makefile create mode 100644 lib/libhvcall/hvcall.S create mode 100644 lib/libhvcall/hvcall.code create mode 100644 lib/libhvcall/hvcall.in create mode 100644 lib/libhvcall/libhvcall.h (limited to 'lib') diff --git a/lib/Makefile b/lib/Makefile index 34d3c23..ae03f8f 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -10,7 +10,7 @@ # * IBM Corporation - initial implementation # ****************************************************************************/ -SUBDIRS = libc libipmi libbootmsg libbases libnvram libelf +SUBDIRS = libc libipmi libbootmsg libbases libnvram libelf libhvcall all: subdirs diff --git a/lib/libbootmsg/Makefile b/lib/libbootmsg/Makefile index 6804b8d..891987e 100644 --- a/lib/libbootmsg/Makefile +++ b/lib/libbootmsg/Makefile @@ -33,12 +33,16 @@ ifeq ($(CPUARCH),p5) SRCS = SRCSS = bootmsg_lvl.S else +ifeq ($(CPUARCH),ppcp7) +SRCS = +SRCSS = bootmsg_lvl.S +else SRCS = bootmsg.c SRCSS = endif endif endif - +endif OBJS = $(SRCS:%.c=%.o) $(SRCSS:%.S=%.o) diff --git a/lib/libbootmsg/bootmsg_lvl.S b/lib/libbootmsg/bootmsg_lvl.S index 04ace12..65cf0c3 100644 --- a/lib/libbootmsg/bootmsg_lvl.S +++ b/lib/libbootmsg/bootmsg_lvl.S @@ -158,13 +158,16 @@ ENTRY(bootmsg_setlevel) andi. r3, r3, 0x7F add r6,r3,r6 // address | stb r4,0(r6) // store level |_ stwbrx r4,r3,r6 +#ifndef DISABLE_NVRAM LOAD64(r6, SB_NVRAM_FWONLY_adr + 8 ) add r6,r6,r3 stb r4,0(r6) +#endif mtlr r5 blr ENTRY(bootmsg_nvupdate) +#ifndef DISABLE_NVRAM mflr r10 LOAD64(r3, SB_NVRAM_FWONLY_adr) lwz r4, 0(r3) @@ -196,4 +199,5 @@ ENTRY(bootmsg_nvupdate) 2: // the end mtlr r10 +#endif blr diff --git a/lib/libhvcall/Makefile b/lib/libhvcall/Makefile new file mode 100644 index 0000000..41ee633 --- /dev/null +++ b/lib/libhvcall/Makefile @@ -0,0 +1,53 @@ +# ***************************************************************************** +# * Copyright (c) 2004, 2008 IBM Corporation +# * All rights reserved. +# * This program and the accompanying materials +# * are made available under the terms of the BSD License +# * which accompanies this distribution, and is available at +# * http://www.opensource.org/licenses/bsd-license.php +# * +# * Contributors: +# * IBM Corporation - initial implementation +# ****************************************************************************/ + +TOPCMNDIR ?= ../.. + +ASFLAGS = $(FLAG) $(RELEASE) $(CPUARCHDEF) -Wa,-mregnames +CPPFLAGS = -I../libc/include $(CPUARCHDEF) -I$(INCLBRDDIR) -I. -I../../include +LDFLAGS = -nostdlib + +TARGET = ../libhvcall.a + + +all: $(TARGET) + +SRCSS = hvcall.S + + +OBJS = $(SRCS:%.c=%.o) $(SRCSS:%.S=%.o) + +$(TARGET): $(OBJS) + $(AR) -rc $@ $(OBJS) + $(RANLIB) $@ + +%.o: %.S + $(CC) $(CPPFLAGS) $(ASFLAGS) -c $< -o $@ + +clean: + $(RM) $(TARGET) $(OBJS) + +distclean: clean + $(RM) Makefile.dep + + +# Rules for creating the dependency file: +depend: + $(RM) Makefile.dep + $(MAKE) Makefile.dep + +Makefile.dep: Makefile + $(CC) -MM $(CPPFLAGS) $(CFLAGS) $(SRCS) $(SRCSS) > Makefile.dep + +# Include dependency file if available: +-include Makefile.dep + diff --git a/lib/libhvcall/hvcall.S b/lib/libhvcall/hvcall.S new file mode 100644 index 0000000..5cc0bd7 --- /dev/null +++ b/lib/libhvcall/hvcall.S @@ -0,0 +1,86 @@ +#define _ASM +#define __ASSEMBLY__ +#include "macros.h" +#include "libhvcall.h" + +#define HVCALL .long 0x44000022 + + .text + .align 3 + +ENTRY(hv_generic) + HVCALL + blr + +ENTRY(hv_putchar) + sldi r6,r3,(24+32) + li r3,H_PUT_TERM_CHAR + li r4,0 + li r5,1 + HVCALL + blr + +ENTRY(hv_getchar) + mflr r10 + bl .hv_haschar + mtlr r10 + cmpwi cr0,r3,0 + beqlr + lis r9,inbuf@h + ori r9,r9,inbuf@l + lwz r4,20(r9) + lbzx r3,r4,r9 + addi r4,r4,1 + stw r4,20(r9) + blr + +ENTRY(hv_haschar) + li r3,-1 + lis r9,inbuf@h + ori r9,r9,inbuf@l + lwz r5,16(r9) + lwz r6,20(r9) + cmplw cr0,r5,r6 + bnelr + li r3,H_GET_TERM_CHAR + li r4,0 + HVCALL + lis r9,inbuf@h + ori r9,r9,inbuf@l + stw r4,16(r9) + li r3,0 + stw r3,20(r9) + cmplwi cr0,r4,0 + beqlr + li r3,-1 + std r5,0(r9) + std r6,8(r9) + blr + +ENTRY(hv_send_crq) + ld r5,0(r4) + ld r6,8(r4) + mr r4,r3 + li r3,H_SEND_CRQ + HVCALL + blr + +ENTRY(hv_send_logical_lan) + li r11,0 /* no continue token for now */ + mr r10,r9 + mr r9,r8 + mr r8,r7 + mr r7,r6 + mr r6,r5 + mr r5,r4 + mr r4,r3 + li r3,H_SEND_LOGICAL_LAN + HVCALL + blr + + .section ".bss" + inbuf: .space 16 +inlen: .space 4 +inpos: .space 4 + .text + \ No newline at end of file diff --git a/lib/libhvcall/hvcall.code b/lib/libhvcall/hvcall.code new file mode 100644 index 0000000..4e47c06 --- /dev/null +++ b/lib/libhvcall/hvcall.code @@ -0,0 +1,51 @@ +/****************************************************************************** + * Copyright (c) 2004, 2008 IBM Corporation + * All rights reserved. + * This program and the accompanying materials + * are made available under the terms of the BSD License + * which accompanies this distribution, and is available at + * http://www.opensource.org/licenses/bsd-license.php + * + * Contributors: + * IBM Corporation - initial implementation + *****************************************************************************/ +#include + +// : hv-putchar ( char -- ) +PRIM(hv_X2d_putchar) + char c = TOS.n; POP; + hv_putchar(c); +MIRP + +// : hv-getchar ( -- char ) +PRIM(hv_X2d_getchar) + PUSH; + TOS.n = hv_getchar(); +MIRP + +// : hv-haschar ( -- res ) +PRIM(hv_X2d_haschar) + PUSH; + TOS.n = hv_haschar(); +MIRP + +// : hv-reg-crq ( unit qaddr qsize -- res ) +PRIM(hv_X2d_reg_X2d_crq) + unsigned long qsize = TOS.u; POP; + unsigned long qaddr = TOS.u; POP; + unsigned int unit = TOS.u; + TOS.n = hv_reg_crq(unit, qaddr, qsize); +MIRP + +// : hv-free-crq ( unit -- ) +PRIM(hv_X2d_free_X2d_crq) + unsigned int unit = TOS.u; POP; + hv_free_crq(unit); +MIRP + +// : hv-send-crq ( unit msgaddr -- rc ) +PRIM(hv_X2d_send_X2d_crq) + uint64_t *msgaddr = (uint64_t *)TOS.u; POP; + unsigned int unit = TOS.u; + TOS.n = hv_send_crq(unit, msgaddr); +MIRP diff --git a/lib/libhvcall/hvcall.in b/lib/libhvcall/hvcall.in new file mode 100644 index 0000000..827aed4 --- /dev/null +++ b/lib/libhvcall/hvcall.in @@ -0,0 +1,18 @@ +/****************************************************************************** + * Copyright (c) 2004, 2008 IBM Corporation + * All rights reserved. + * This program and the accompanying materials + * are made available under the terms of the BSD License + * which accompanies this distribution, and is available at + * http://www.opensource.org/licenses/bsd-license.php + * + * Contributors: + * IBM Corporation - initial implementation + *****************************************************************************/ + +cod(hv-putchar) +cod(hv-getchar) +cod(hv-haschar) +cod(hv-reg-crq) +cod(hv-free-crq) +cod(hv-send-crq) diff --git a/lib/libhvcall/libhvcall.h b/lib/libhvcall/libhvcall.h new file mode 100644 index 0000000..db1d890 --- /dev/null +++ b/lib/libhvcall/libhvcall.h @@ -0,0 +1,65 @@ +#ifndef __LIBHVCALL_H__ +#define __LIBHVCALL_H__ + +#define H_SUCCESS 0 + +#define H_GET_TERM_CHAR 0x54 +#define H_PUT_TERM_CHAR 0x58 +#define H_REG_CRQ 0xFC +#define H_FREE_CRQ 0x100 +#define H_SEND_CRQ 0x108 +#define H_REGISTER_LOGICAL_LAN 0x114 +#define H_FREE_LOGICAL_LAN 0x118 +#define H_ADD_LOGICAL_LAN_BUFFER 0x11C +#define H_SEND_LOGICAL_LAN 0x120 + +#ifndef __ASSEMBLY__ + +extern long hv_generic(unsigned long opcode, ...); + +extern void hv_putchar(char c); +extern char hv_getchar(void); +extern char hv_haschar(void); + +extern int hv_send_crq(unsigned int unit, uint64_t *msgaddr); + +static inline long hv_reg_crq(unsigned int unit, unsigned long qaddr, + unsigned long qsize) +{ + return hv_generic(H_REG_CRQ, unit, qaddr, qsize); +} + +static inline void hv_free_crq(unsigned int unit) +{ + hv_generic(H_FREE_CRQ, unit); +} + +extern long hv_send_logical_lan(unsigned long unit_address, + unsigned long desc1, unsigned long desc2, + unsigned long desc3, unsigned long desc4, + unsigned long desc5, unsigned long desc6); + +static inline long h_register_logical_lan(unsigned long unit_address, + unsigned long buf_list, + unsigned long rec_q, + unsigned long filter_list, + unsigned long mac_address) +{ + return hv_generic(H_REGISTER_LOGICAL_LAN, unit_address, + buf_list, rec_q, filter_list, mac_address); +} + +static inline long h_free_logical_lan(unsigned long unit_address) +{ + return hv_generic(H_FREE_LOGICAL_LAN, unit_address); +} + +static inline long h_add_logical_lan_buffer(unsigned long unit_address, + unsigned long buffer) +{ + return hv_generic(H_ADD_LOGICAL_LAN_BUFFER, unit_address, buffer); +} + +#endif /* __ASSEMBLY__ */ + +#endif /* __LIBHVCALL_H__ */ diff --git a/lib/libnvram/Makefile b/lib/libnvram/Makefile index 6c9ec84..afd536f 100644 --- a/lib/libnvram/Makefile +++ b/lib/libnvram/Makefile @@ -15,7 +15,8 @@ SRCS = nvram.c envvar.c TOPCMNDIR ?= ../.. ASFLAGS = $(FLAG) $(RELEASE) $(CPUARCHDEF) -Wa,-mregnames -CPPFLAGS = -I../libc/include $(CPUARCHDEF) -I$(INCLBRDDIR) -I$(INCLCMNDIR)/$(CPUARCH) -I. -I../../include +CPPFLAGS = -I../libc/include $(CPUARCHDEF) $(FLAG) \ + -I$(INCLBRDDIR) -I$(INCLCMNDIR)/$(CPUARCH) -I. -I../../include LDFLAGS = -nostdlib TARGET = ../libnvram.a diff --git a/lib/libnvram/nvram.c b/lib/libnvram/nvram.c index a31bb53..e9500ec 100644 --- a/lib/libnvram/nvram.c +++ b/lib/libnvram/nvram.c @@ -23,9 +23,17 @@ #include #include +#ifndef NVRAM_LENGTH +#define NVRAM_LENGTH 0x10000 +#endif + void asm_cout(long Character,long UART,long NVRAM); -static volatile uint8_t *nvram=(volatile uint8_t *)SB_NVRAM_adr; +#if defined(DISABLE_NVRAM) +static volatile uint8_t nvram[NVRAM_LENGTH]; /* FAKE */ +#else +static volatile uint8_t *nvram = (volatile uint8_t *)SB_NVRAM_adr; +#endif /* This is extremely ugly, but still better than implementing * another sbrk() around it. @@ -490,13 +498,13 @@ void reset_nvram(void) erase_nvram(0, NVRAM_LENGTH); DEBUG("Creating CPU log partitions\n"); - *(uint32_t *)&(header[0]) = be32_to_cpu(LLFW_LOG_BE0_NAME_PREFIX); - *(uint64_t *)&(header[4]) = be64_to_cpu(LLFW_LOG_BE0_NAME); + *(uint32_t *)(char *)&(header[0]) = be32_to_cpu(LLFW_LOG_BE0_NAME_PREFIX); + *(uint64_t *)(char *)&(header[4]) = be64_to_cpu(LLFW_LOG_BE0_NAME); cpulog0=create_nvram_partition(LLFW_LOG_BE0_SIGNATURE, header, (LLFW_LOG_BE0_LENGTH*16)-PARTITION_HEADER_SIZE); - *(uint32_t *)&(header[0]) = be32_to_cpu(LLFW_LOG_BE1_NAME_PREFIX); - *(uint64_t *)&(header[4]) = be64_to_cpu(LLFW_LOG_BE1_NAME); + *(uint32_t *)(char *)&(header[0]) = be32_to_cpu(LLFW_LOG_BE1_NAME_PREFIX); + *(uint64_t *)(char *)&(header[4]) = be64_to_cpu(LLFW_LOG_BE1_NAME); cpulog1=create_nvram_partition(LLFW_LOG_BE1_SIGNATURE, header, (LLFW_LOG_BE1_LENGTH*16)-PARTITION_HEADER_SIZE); @@ -512,7 +520,8 @@ void reset_nvram(void) void nvram_debug(void) { +#if !defined(DISABLE_NVRAM) printf("\nNVRAM_BASE: %lx\n", (unsigned long)SB_NVRAM_adr); printf("NVRAM_LEN: %x\n", NVRAM_LENGTH); +#endif } - -- cgit v1.1