sbi_console.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /*
  2. * SPDX-License-Identifier: BSD-2-Clause
  3. *
  4. * Copyright (c) 2019 Western Digital Corporation or its affiliates.
  5. *
  6. * Authors:
  7. * Anup Patel <anup.patel@wdc.com>
  8. */
  9. #ifndef __SBI_CONSOLE_H__
  10. #define __SBI_CONSOLE_H__
  11. #include <sbi/sbi_types.h>
  12. struct sbi_console_device {
  13. /** Name of the console device */
  14. char name[32];
  15. /** Write a character to the console output */
  16. void (*console_putc)(char ch);
  17. /** Read a character from the console input */
  18. int (*console_getc)(void);
  19. };
  20. #define __printf(a, b) __attribute__((format(printf, a, b)))
  21. bool sbi_isprintable(char ch);
  22. int sbi_getc(void);
  23. void sbi_putc(char ch);
  24. void sbi_puts(const char *str);
  25. unsigned long sbi_nputs(const char *str, unsigned long len);
  26. void sbi_gets(char *s, int maxwidth, char endchar);
  27. unsigned long sbi_ngets(char *str, unsigned long len);
  28. int __printf(2, 3) sbi_sprintf(char *out, const char *format, ...);
  29. int __printf(3, 4) sbi_snprintf(char *out, u32 out_sz, const char *format, ...);
  30. int __printf(1, 2) sbi_printf(const char *format, ...);
  31. int __printf(1, 2) sbi_dprintf(const char *format, ...);
  32. void __printf(1, 2) __attribute__((noreturn)) sbi_panic(const char *format, ...);
  33. const struct sbi_console_device *sbi_console_get_device(void);
  34. void sbi_console_set_device(const struct sbi_console_device *dev);
  35. struct sbi_scratch;
  36. int sbi_console_init(struct sbi_scratch *scratch);
  37. #define SBI_ASSERT(cond, args) do { \
  38. if (unlikely(!(cond))) \
  39. sbi_panic args; \
  40. } while (0)
  41. #endif