spike_util.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*
  2. * This file is part of the coreboot project.
  3. *
  4. * Copyright (C) 2013 The ChromiumOS Authors
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; version 2 of the License.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. */
  15. #ifndef _SPIKE_UTIL_H
  16. #define _SPIKE_UTIL_H
  17. #include <stdint.h>
  18. //#include <string.h>
  19. //#include <errno.h>
  20. #include <arch/encoding.h>
  21. #include <atomic.h>
  22. #define LOG_REGBYTES 3
  23. #define REGBYTES (1 << LOG_REGBYTES)
  24. #define STORE sd
  25. #define HLS_SIZE 64
  26. #define MENTRY_FRAME_SIZE HLS_SIZE
  27. #define TOHOST_CMD(dev, cmd, payload) \
  28. (((uint64_t)(dev) << 56) | ((uint64_t)(cmd) << 48) | (uint64_t)(payload))
  29. #define FROMHOST_DEV(fromhost_value) ((uint64_t)(fromhost_value) >> 56)
  30. #define FROMHOST_CMD(fromhost_value) ((uint64_t)(fromhost_value) << 8 >> 56)
  31. #define FROMHOST_DATA(fromhost_value) ((uint64_t)(fromhost_value) << 16 >> 16)
  32. typedef struct {
  33. unsigned long base;
  34. unsigned long size;
  35. unsigned long node_id;
  36. } memory_block_info;
  37. typedef struct {
  38. unsigned long dev;
  39. unsigned long cmd;
  40. unsigned long data;
  41. unsigned long sbi_private_data;
  42. } sbi_device_message;
  43. typedef struct {
  44. sbi_device_message* device_request_queue_head;
  45. unsigned long device_request_queue_size;
  46. sbi_device_message* device_response_queue_head;
  47. sbi_device_message* device_response_queue_tail;
  48. int hart_id;
  49. int ipi_pending;
  50. } hls_t;
  51. #define MACHINE_STACK_TOP() ({ \
  52. register uintptr_t sp asm ("sp"); \
  53. (void*)((sp + RISCV_PGSIZE) & -RISCV_PGSIZE); })
  54. // hart-local storage, at top of stack
  55. #define HLS() ((hls_t*)(MACHINE_STACK_TOP() - HLS_SIZE))
  56. #define OTHER_HLS(id) ((hls_t*)((void*)HLS() + RISCV_PGSIZE * ((id) - HLS()->hart_id)))
  57. #define MACHINE_STACK_SIZE RISCV_PGSIZE
  58. uintptr_t translate_address(uintptr_t vAddr);
  59. uintptr_t mcall_query_memory(uintptr_t id, memory_block_info *p);
  60. uintptr_t mcall_hart_id(void);
  61. uintptr_t htif_interrupt(uintptr_t mcause, uintptr_t* regs);
  62. uintptr_t mcall_console_putchar(uint8_t ch);
  63. void testPrint(void);
  64. uintptr_t mcall_dev_req(sbi_device_message *m);
  65. uintptr_t mcall_dev_resp(void);
  66. uintptr_t mcall_set_timer(unsigned long long when);
  67. uintptr_t mcall_clear_ipi(void);
  68. uintptr_t mcall_send_ipi(uintptr_t recipient);
  69. uintptr_t mcall_shutdown(void);
  70. void hls_init(uint32_t hart_id); // need to call this before launching linux
  71. #endif