xref: /openbsd/sys/dev/pci/drm/amd/include/atom-bits.h (revision fb4d8502)
1*fb4d8502Sjsg /*
2*fb4d8502Sjsg  * Copyright 2008 Advanced Micro Devices, Inc.
3*fb4d8502Sjsg  *
4*fb4d8502Sjsg  * Permission is hereby granted, free of charge, to any person obtaining a
5*fb4d8502Sjsg  * copy of this software and associated documentation files (the "Software"),
6*fb4d8502Sjsg  * to deal in the Software without restriction, including without limitation
7*fb4d8502Sjsg  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8*fb4d8502Sjsg  * and/or sell copies of the Software, and to permit persons to whom the
9*fb4d8502Sjsg  * Software is furnished to do so, subject to the following conditions:
10*fb4d8502Sjsg  *
11*fb4d8502Sjsg  * The above copyright notice and this permission notice shall be included in
12*fb4d8502Sjsg  * all copies or substantial portions of the Software.
13*fb4d8502Sjsg  *
14*fb4d8502Sjsg  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15*fb4d8502Sjsg  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16*fb4d8502Sjsg  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
17*fb4d8502Sjsg  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18*fb4d8502Sjsg  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19*fb4d8502Sjsg  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20*fb4d8502Sjsg  * OTHER DEALINGS IN THE SOFTWARE.
21*fb4d8502Sjsg  *
22*fb4d8502Sjsg  * Author: Stanislaw Skowronek
23*fb4d8502Sjsg  */
24*fb4d8502Sjsg 
25*fb4d8502Sjsg #ifndef ATOM_BITS_H
26*fb4d8502Sjsg #define ATOM_BITS_H
27*fb4d8502Sjsg 
get_u8(void * bios,int ptr)28*fb4d8502Sjsg static inline uint8_t get_u8(void *bios, int ptr)
29*fb4d8502Sjsg {
30*fb4d8502Sjsg     return ((unsigned char *)bios)[ptr];
31*fb4d8502Sjsg }
32*fb4d8502Sjsg #define U8(ptr) get_u8(ctx->ctx->bios, (ptr))
33*fb4d8502Sjsg #define CU8(ptr) get_u8(ctx->bios, (ptr))
get_u16(void * bios,int ptr)34*fb4d8502Sjsg static inline uint16_t get_u16(void *bios, int ptr)
35*fb4d8502Sjsg {
36*fb4d8502Sjsg     return get_u8(bios ,ptr)|(((uint16_t)get_u8(bios, ptr+1))<<8);
37*fb4d8502Sjsg }
38*fb4d8502Sjsg #define U16(ptr) get_u16(ctx->ctx->bios, (ptr))
39*fb4d8502Sjsg #define CU16(ptr) get_u16(ctx->bios, (ptr))
get_u32(void * bios,int ptr)40*fb4d8502Sjsg static inline uint32_t get_u32(void *bios, int ptr)
41*fb4d8502Sjsg {
42*fb4d8502Sjsg     return get_u16(bios, ptr)|(((uint32_t)get_u16(bios, ptr+2))<<16);
43*fb4d8502Sjsg }
44*fb4d8502Sjsg #define U32(ptr) get_u32(ctx->ctx->bios, (ptr))
45*fb4d8502Sjsg #define CU32(ptr) get_u32(ctx->bios, (ptr))
46*fb4d8502Sjsg #define CSTR(ptr) (((char *)(ctx->bios))+(ptr))
47*fb4d8502Sjsg 
48*fb4d8502Sjsg #endif
49