[coreboot-gerrit] New patch to review for coreboot: [WIP] arch/riscv: Remove HTIF and SBI related code

Jonathan Neuschäfer (j.neuschaefer@gmx.net) gerrit at coreboot.org
Tue Jun 21 19:45:44 CEST 2016


Jonathan Neuschäfer (j.neuschaefer at gmx.net) just uploaded a new patch set to gerrit, which you can find at https://review.coreboot.org/15289

-gerrit

commit 70cfab24812295fdf4dc938fa53779b059ef776d
Author: Jonathan Neuschäfer <j.neuschaefer at gmx.net>
Date:   Tue Jun 21 19:37:04 2016 +0200

    [WIP] arch/riscv: Remove HTIF and SBI related code
    
    Work in progress:
    - The HTIF is deprecated and we shouldn't use it anymore
    - An SBI (supervisor binary interface) implementation will be required
      to run Linux in the forseeable future. I'd rather have it in a payload
      than in non-payload coreboot, though.
    
    Change-Id: I13f01e45b714f1bd919e27b84aff8db772504b1f
    Signed-off-by: Jonathan Neuschäfer <j.neuschaefer at gmx.net>
---
 src/arch/riscv/trap_handler.c                    |  58 +-------
 src/mainboard/emulation/spike-riscv/spike_util.c | 171 -----------------------
 2 files changed, 1 insertion(+), 228 deletions(-)

diff --git a/src/arch/riscv/trap_handler.c b/src/arch/riscv/trap_handler.c
index 5b4d0b1..60cee59 100644
--- a/src/arch/riscv/trap_handler.c
+++ b/src/arch/riscv/trap_handler.c
@@ -29,61 +29,6 @@
 #define SET_TIMER 7
 #define QUERY_MEMORY 8
 
-int loopBreak2 = 1;
-
-void handle_supervisor_call(trapframe *tf) {
-	uintptr_t call = tf->gpr[17];
-	uintptr_t arg0 = tf->gpr[10];
-	uintptr_t arg1 = tf->gpr[11];
-	uintptr_t returnValue;
-	switch(call) {
-		case HART_ID:
-			printk(BIOS_DEBUG, "Getting hart id...\n");
-			returnValue = mcall_hart_id();
-			break;
-		case CONSOLE_PUT:
-			returnValue = mcall_console_putchar(arg0);
-			break;
-		case SEND_DEVICE_REQUEST:
-			printk(BIOS_DEBUG, "Sending device request...\n");
-			returnValue = mcall_dev_req((sbi_device_message*) arg0);
-			break;
-		case RECEIVE_DEVICE_RESPONSE:
-			printk(BIOS_DEBUG, "Getting device response...\n");
-			returnValue = mcall_dev_resp();
-			break;
-		case SEND_IPI:
-			printk(BIOS_DEBUG, "Sending IPI...\n");
-			returnValue = mcall_send_ipi(arg0);
-			break;
-		case CLEAR_IPI:
-			printk(BIOS_DEBUG, "Clearing IPI...\n");
-			returnValue = mcall_clear_ipi();
-			break;
-		case SHUTDOWN:
-			printk(BIOS_DEBUG, "Shutting down...\n");
-			returnValue = mcall_shutdown();
-			break;
-		case SET_TIMER:
-			printk(BIOS_DEBUG,
-			       "Setting timer to %p (current time is %p)...\n",
-			       (void *)arg0, (void *)rdtime());
-			returnValue = mcall_set_timer(arg0);
-			break;
-		case QUERY_MEMORY:
-			printk(BIOS_DEBUG, "Querying memory, CPU #%lld...\n", arg0);
-			returnValue = mcall_query_memory(arg0, (memory_block_info*) arg1);
-			break;
-		default:
-			printk(BIOS_DEBUG, "ERROR! Unrecognized system call\n");
-			returnValue = 0;
-			break; // note: system call we do not know how to handle
-	}
-	tf->gpr[10] = returnValue;
-	write_csr(mepc, read_csr(mepc) + 4);
-	asm volatile("j supervisor_call_return");
-}
-
 void trap_handler(trapframe *tf) {
 	write_csr(mscratch, tf);
 	uintptr_t cause;
@@ -141,8 +86,7 @@ void trap_handler(trapframe *tf) {
 			break;
 		case 9:
 			// Don't print so we make console putchar calls look the way they should
-			// printk(BIOS_DEBUG, "Trap: Environment call from S-mode\n");
-			handle_supervisor_call(tf);
+			printk(BIOS_DEBUG, "Trap: Environment call from S-mode (not implemented)\n");
 			break;
 		case 10:
 			printk(BIOS_DEBUG, "Trap: Environment call from H-mode\n");
diff --git a/src/mainboard/emulation/spike-riscv/spike_util.c b/src/mainboard/emulation/spike-riscv/spike_util.c
index fca7d56..8d43714 100644
--- a/src/mainboard/emulation/spike-riscv/spike_util.c
+++ b/src/mainboard/emulation/spike-riscv/spike_util.c
@@ -40,179 +40,8 @@ uintptr_t translate_address(uintptr_t vAddr) {
 	return translationResult;
 }
 
-uintptr_t mcall_query_memory(uintptr_t id, memory_block_info *p)
-{
-	uintptr_t physicalAddr = translate_address((uintptr_t) p);
-	memory_block_info *info = (memory_block_info*) physicalAddr;
-	if (id == 0) {
-		info->base = 0x1000000; // hard coded for now, but we can put these values somewhere later
-		info->size = 0x7F000000 - info->base;
-		return 0;
-	}
-
-	return -1;
-}
-
-uintptr_t mcall_send_ipi(uintptr_t recipient)
-{
-	//if (recipient >= num_harts)
-	//return -1;
-
-	if (atomic_swap(&OTHER_HLS(recipient)->ipi_pending, 1) == 0) {
-		mb();
-		write_csr(send_ipi, recipient);
-	}
-
-	return 0;
-}
-
-uintptr_t mcall_clear_ipi(void)
-{
-	// only clear SSIP if no other events are pending
-	if (HLS()->device_response_queue_head == NULL) {
-		clear_csr(mip, MIP_SSIP);
-		mb();
-	}
-
-	return atomic_swap(&HLS()->ipi_pending, 0);
-}
-
-uintptr_t mcall_shutdown(void)
-{
-	while (1) write_csr(mtohost, 1);
-	return 0;
-}
-
-uintptr_t mcall_set_timer(unsigned long long when)
-{
-	write_csr(mtimecmp, when);
-	clear_csr(mip, MIP_STIP);
-	set_csr(mie, MIP_MTIP);
-	return 0;
-}
-
-uintptr_t mcall_dev_req(sbi_device_message *m)
-{
-	if ((m->dev > 0xFFU) | (m->cmd > 0xFFU) | (m->data > 0x0000FFFFFFFFFFFFU)) return -EINVAL;
-
-	while (swap_csr(mtohost, TOHOST_CMD(m->dev, m->cmd, m->data)) != 0);
-
-	m->sbi_private_data = (uintptr_t)HLS()->device_request_queue_head;
-	HLS()->device_request_queue_head = m;
-	HLS()->device_request_queue_size++;
-
-	return 0;
-}
-
-uintptr_t mcall_dev_resp(void)
-{
-	htif_interrupt(0, 0);
-
-	sbi_device_message* m = HLS()->device_response_queue_head;
-	if (m) {
-		//printm("resp %p\n", m);
-		sbi_device_message* next = (void*)atomic_read(&m->sbi_private_data);
-		HLS()->device_response_queue_head = next;
-		if (!next) {
-			HLS()->device_response_queue_tail = 0;
-
-			// only clear SSIP if no other events are pending
-			clear_csr(mip, MIP_SSIP);
-			mb();
-			if (HLS()->ipi_pending) set_csr(mip, MIP_SSIP);
-		}
-	}
-	return (uintptr_t)m;
-}
-
-uintptr_t mcall_hart_id(void)
-{
-	return HLS()->hart_id;
-}
-
 void hls_init(uint32_t hart_id)
 {
 	memset(HLS(), 0, sizeof(*HLS()));
 	HLS()->hart_id = hart_id;
 }
-
-uintptr_t htif_interrupt(uintptr_t mcause, uintptr_t* regs) {
-	uintptr_t fromhost = swap_csr(mfromhost, 0);
-	if (!fromhost)
-	return 0;
-
-	uintptr_t dev = FROMHOST_DEV(fromhost);
-	uintptr_t cmd = FROMHOST_CMD(fromhost);
-	uintptr_t data = FROMHOST_DATA(fromhost);
-
-	sbi_device_message* m = HLS()->device_request_queue_head;
-	sbi_device_message* prev = 0x0;
-	unsigned long i, n;
-	for (i = 0, n = HLS()->device_request_queue_size; i < n; i++) {
-		/*
-		if (!supervisor_paddr_valid(m, sizeof(*m))
-		&& EXTRACT_FIELD(read_csr(mstatus), MSTATUS_PRV1) != PRV_M)
-		panic("htif: page fault");
-		*/
-
-		sbi_device_message* next = (void*)m->sbi_private_data;
-		if (m->dev == dev && m->cmd == cmd) {
-			m->data = data;
-
-			// dequeue from request queue
-			if (prev)
-			prev->sbi_private_data = (uintptr_t)next;
-			else
-			HLS()->device_request_queue_head = next;
-			HLS()->device_request_queue_size = n-1;
-			m->sbi_private_data = 0;
-
-			// enqueue to response queue
-			if (HLS()->device_response_queue_tail)
-			{
-				HLS()->device_response_queue_tail->sbi_private_data = (uintptr_t)m;
-			}
-			else
-			{
-				HLS()->device_response_queue_head = m;
-			}
-			HLS()->device_response_queue_tail = m;
-
-			// signal software interrupt
-			set_csr(mip, MIP_SSIP);
-			return 0;
-		}
-
-		prev = m;
-		m = (void*)atomic_read(&m->sbi_private_data);
-	}
-	//HLT();
-	return 0;
-	//panic("htif: no record");
-}
-
-uintptr_t mcall_console_putchar(uint8_t ch)
-{
-	while (swap_csr(mtohost, TOHOST_CMD(1, 1, ch)) != 0);
-	while (1) {
-		uintptr_t fromhost = read_csr(mfromhost);
-		if (FROMHOST_DEV(fromhost) != 1 || FROMHOST_CMD(fromhost) != 1) {
-		if (fromhost)
-		htif_interrupt(0, 0);
-		continue;
-	}
-	write_csr(mfromhost, 0);
-	break;
-	}
-	return 0;
-}
-
-void testPrint(void) {
-	/* Print a test command to check Spike console output */
-	mcall_console_putchar('h');
-	mcall_console_putchar('e');
-	mcall_console_putchar('l');
-	mcall_console_putchar('l');
-	mcall_console_putchar('o');
-	mcall_console_putchar('\n');
-}



More information about the coreboot-gerrit mailing list