spike_util.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. #define LOG_REGBYTES 3
  16. #define REGBYTES (1 << LOG_REGBYTES)
  17. #define STORE sd
  18. #define HLS_SIZE 64
  19. #define MENTRY_FRAME_SIZE HLS_SIZE
  20. #define TOHOST_CMD(dev, cmd, payload) \
  21. (((uint64_t)(dev) << 56) | ((uint64_t)(cmd) << 48) | (uint64_t)(payload))
  22. #define FROMHOST_DEV(fromhost_value) ((uint64_t)(fromhost_value) >> 56)
  23. #define FROMHOST_CMD(fromhost_value) ((uint64_t)(fromhost_value) << 8 >> 56)
  24. #define FROMHOST_DATA(fromhost_value) ((uint64_t)(fromhost_value) << 16 >> 16)
  25. typedef struct {
  26. unsigned long base;
  27. unsigned long size;
  28. unsigned long node_id;
  29. } memory_block_info;
  30. typedef struct {
  31. unsigned long dev;
  32. unsigned long cmd;
  33. unsigned long data;
  34. unsigned long sbi_private_data;
  35. } sbi_device_message;
  36. typedef struct {
  37. sbi_device_message* device_request_queue_head;
  38. unsigned long device_request_queue_size;
  39. sbi_device_message* device_response_queue_head;
  40. sbi_device_message* device_response_queue_tail;
  41. int hart_id;
  42. int ipi_pending;
  43. } hls_t;
  44. #define MACHINE_STACK_TOP() ({ \
  45. register uintptr_t sp __asm__ ("sp"); \
  46. (void*)((sp + RISCV_PGSIZE) & -RISCV_PGSIZE); })
  47. // hart-local storage, at top of stack
  48. #define HLS() ((hls_t*)(MACHINE_STACK_TOP() - HLS_SIZE))
  49. #define OTHER_HLS(id) ((hls_t*)((void*)HLS() + RISCV_PGSIZE * ((id) - HLS()->hart_id)))
  50. #define MACHINE_STACK_SIZE RISCV_PGSIZE
  51. uintptr_t translate_address(uintptr_t vAddr);
  52. uintptr_t mcall_query_memory(uintptr_t id, memory_block_info *p);
  53. uintptr_t mcall_hart_id(void);
  54. uintptr_t htif_interrupt(uintptr_t mcause, uintptr_t* regs);
  55. uintptr_t mcall_console_putchar(uint8_t ch);
  56. void testPrint(void);
  57. uintptr_t mcall_dev_req(sbi_device_message *m);
  58. uintptr_t mcall_dev_resp(void);
  59. uintptr_t mcall_set_timer(unsigned long long when);
  60. uintptr_t mcall_clear_ipi(void);
  61. uintptr_t mcall_send_ipi(uintptr_t recipient);
  62. uintptr_t mcall_shutdown(void);
  63. void hls_init(uint32_t hart_id); // need to call this before launching linux