1*d6a257bbSX512 /*
2*d6a257bbSX512 * Copyright 2021, Haiku, Inc. All rights reserved.
3*d6a257bbSX512 * Distributed under the terms of the MIT License.
4*d6a257bbSX512 */
5*d6a257bbSX512
6*d6a257bbSX512
7*d6a257bbSX512 #include <Htif.h>
8*d6a257bbSX512
9*d6a257bbSX512
10*d6a257bbSX512 uint64
HtifCmd(uint32 device,uint8 cmd,uint32 arg)11*d6a257bbSX512 HtifCmd(uint32 device, uint8 cmd, uint32 arg)
12*d6a257bbSX512 {
13*d6a257bbSX512 if (gHtifRegs == 0)
14*d6a257bbSX512 return 0;
15*d6a257bbSX512
16*d6a257bbSX512 uint64 htifTohost = ((uint64)device << 56)
17*d6a257bbSX512 + ((uint64)cmd << 48) + arg;
18*d6a257bbSX512 gHtifRegs->toHostLo = htifTohost % ((uint64)1 << 32);
19*d6a257bbSX512 gHtifRegs->toHostHi = htifTohost / ((uint64)1 << 32);
20*d6a257bbSX512 return (uint64)gHtifRegs->fromHostLo
21*d6a257bbSX512 + ((uint64)gHtifRegs->fromHostHi << 32);
22*d6a257bbSX512 }
23*d6a257bbSX512
24*d6a257bbSX512
25*d6a257bbSX512 void
HtifShutdown()26*d6a257bbSX512 HtifShutdown()
27*d6a257bbSX512 {
28*d6a257bbSX512 HtifCmd(0, 0, 1);
29*d6a257bbSX512 }
30*d6a257bbSX512
31*d6a257bbSX512
32*d6a257bbSX512 void
HtifOutChar(char ch)33*d6a257bbSX512 HtifOutChar(char ch)
34*d6a257bbSX512 {
35*d6a257bbSX512 HtifCmd(1, 1, ch);
36*d6a257bbSX512 }
37*d6a257bbSX512
38*d6a257bbSX512
39*d6a257bbSX512 void
HtifOutString(const char * str)40*d6a257bbSX512 HtifOutString(const char *str)
41*d6a257bbSX512 {
42*d6a257bbSX512 for (; *str != '\0'; str++)
43*d6a257bbSX512 HtifOutChar(*str);
44*d6a257bbSX512 }
45*d6a257bbSX512
46*d6a257bbSX512
47*d6a257bbSX512 void
HtifOutString(const char * str,size_t len)48*d6a257bbSX512 HtifOutString(const char *str, size_t len)
49*d6a257bbSX512 {
50*d6a257bbSX512 for (; len > 0; str++, len--)
51*d6a257bbSX512 HtifOutChar(*str);
52*d6a257bbSX512 }
53