revert between 56095 -> 55830 in arch
[AROS.git] / arch / arm-native / soc / broadcom / 2708 / hidd / vc4gfx / vc4gfx_init.c
blob4459ac6fcb189ab078fffa2f4545f7e18be7df64
1 /*
2 Copyright © 2013-2017, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: BCM VideoCore4 Gfx Hidd initialisation code
6 Lang: english
7 */
9 #define DEBUG 1
10 #include <aros/debug.h>
12 #define __OOP_NOATTRBASES__
14 #include <proto/exec.h>
15 #include <proto/graphics.h>
16 #include <proto/oop.h>
17 #include <proto/mbox.h>
18 #include <proto/kernel.h>
19 #include <proto/utility.h>
21 #include <exec/types.h>
22 #include <exec/lists.h>
23 #include <graphics/driver.h>
24 #include <graphics/gfxbase.h>
25 #include <hidd/gfx.h>
26 #include <oop/oop.h>
27 #include <utility/utility.h>
28 #include <aros/symbolsets.h>
30 #include "vc4gfx_hidd.h"
31 #include "vc4gfx_hardware.h"
33 #include LC_LIBDEFS_FILE
35 #ifdef MBoxBase
36 #undef MBoxBase
37 #endif
39 #define MBoxBase xsd->vcsd_MBoxBase
41 IPTR __arm_periiobase __attribute__((used)) = 0 ;
42 APTR KernelBase __attribute__((used)) = NULL;
44 static void FNAME_SUPPORT(FreeAttrBases)(const STRPTR *iftable, OOP_AttrBase *bases, ULONG num)
46 ULONG i;
48 for (i = 0; i < num; i++)
50 if (bases[i])
52 OOP_ReleaseAttrBase(iftable[i]);
53 bases[i] = (OOP_AttrBase)0;
58 static BOOL FNAME_SUPPORT(GetAttrBases)(const STRPTR *iftable, OOP_AttrBase *bases, ULONG num)
60 ULONG i;
62 for (i = 0; i < num; i++)
64 bases[i] = OOP_ObtainAttrBase(iftable[i]);
65 if (!bases[i])
67 FNAME_SUPPORT(FreeAttrBases)(iftable, bases, i);
68 return FALSE;
72 return TRUE;
75 static const STRPTR interfaces[] =
77 IID_Hidd_Gfx_VideoCore4,
78 IID_Hidd_BitMap_VideoCore4,
79 IID_Hidd_ChunkyBM,
80 IID_Hidd_BitMap,
81 IID_Hidd_PixFmt,
82 IID_Hidd_Sync,
83 IID_Hidd_Gfx,
84 IID_Hidd
87 static int FNAME_SUPPORT(Init)(LIBBASETYPEPTR LIBBASE)
89 struct VideoCoreGfx_staticdata *xsd = &LIBBASE->vsd;
90 int retval = FALSE;
92 KernelBase = OpenResource("kernel.resource");
93 __arm_periiobase = KrnGetSystemAttr(KATTR_PeripheralBase);
95 if (!FNAME_SUPPORT(GetAttrBases)(interfaces, xsd->vcsd_attrBases, ATTRBASES_NUM))
96 goto failure;
98 if (!(MBoxBase = OpenResource("mbox.resource")))
99 goto failure;
101 if (!(xsd->vcsd_MBoxBuff = (IPTR)AllocVec(16 + (sizeof(IPTR) * 2 * MAX_TAGS), MEMF_CLEAR)))
102 goto failure;
104 xsd->vcsd_MBoxMessage =
105 (unsigned int *)((xsd->vcsd_MBoxBuff + 0xF) & ~0x0000000F);
107 D(bug("[VideoCoreGfx] %s: VideoCore Mailbox resource @ 0x%p\n", __PRETTY_FUNCTION__, MBoxBase));
108 D(bug("[VideoCoreGfx] %s: VideoCore message buffer @ 0x%p\n", __PRETTY_FUNCTION__, xsd->vcsd_MBoxMessage));
111 xsd->vcsd_MBoxMessage[0] = AROS_LE2LONG(8 * 4);
112 xsd->vcsd_MBoxMessage[1] = AROS_LE2LONG(VCTAG_REQ);
113 xsd->vcsd_MBoxMessage[2] = AROS_LE2LONG(VCTAG_GETVCRAM);
114 xsd->vcsd_MBoxMessage[3] = AROS_LE2LONG(8);
115 xsd->vcsd_MBoxMessage[4] = 0;
117 xsd->vcsd_MBoxMessage[5] = 0;
118 xsd->vcsd_MBoxMessage[6] = 0;
120 xsd->vcsd_MBoxMessage[7] = 0; // terminate tag
122 MBoxWrite((void*)VCMB_BASE, VCMB_PROPCHAN, xsd->vcsd_MBoxMessage);
123 if (MBoxRead((void*)VCMB_BASE, VCMB_PROPCHAN) == xsd->vcsd_MBoxMessage)
125 if (FNAME_SUPPORT(InitMem)((void*)AROS_LE2LONG(xsd->vcsd_MBoxMessage[5]), AROS_LE2LONG(xsd->vcsd_MBoxMessage[6]), LIBBASE))
127 bug("[VideoCoreGfx] VideoCore GPU Found\n");
129 FNAME_HW(InitGfxHW)((APTR)xsd);
131 if ((GfxBase = (struct GfxBase *)OpenLibrary("graphics.library", 41)) != NULL)
133 LIBBASE->vsd.vcsd_basebm = OOP_FindClass(CLID_Hidd_BitMap);
134 if (AddDisplayDriver(LIBBASE->vsd.vcsd_VideoCoreGfxClass, NULL, DDRV_BootMode, TRUE, TAG_DONE) == DD_OK)
136 bug("[VideoCoreGfx] BootMode Display Driver Registered\n");
138 LIBBASE->library.lib_OpenCnt++;
139 retval = TRUE;
141 CloseLibrary(&GfxBase->LibNode);
146 failure:
147 if (!(retval))
149 bug("[VideoCoreGfx] No VideoCore GPU Found\n");
151 FreeVec((APTR)xsd->vcsd_MBoxBuff);
153 FNAME_SUPPORT(FreeAttrBases)(interfaces, xsd->vcsd_attrBases, ATTRBASES_NUM);
156 return retval;
159 ADD2INITLIB(FNAME_SUPPORT(Init), 0)