vfs: check userland buffers before reading them.
[haiku.git] / src / add-ons / accelerants / 3dfx / 3dfx_init.cpp
blob4a1ad274501d321e456fcd727ce8d2e8c52899f2
1 /*
2 * Copyright 2010 Haiku, Inc. All rights reserved.
3 * Distributed under the terms of the MIT license.
5 * Authors:
6 * Gerald Zajac
7 */
9 #include "accelerant.h"
10 #include "3dfx.h"
14 uint32
15 TDFX_GetVideoMemorySize(void)
17 // Return the number of bytes of video memory.
19 uint32 chipSize; // size is in megabytes
20 uint32 dramInit0 = INREG32(DRAM_INIT0);
21 uint32 dramInit1 = INREG32(DRAM_INIT1);
22 uint32 numChips = (dramInit0 & SGRAM_NUM_CHIPSETS) ? 8 : 4;
23 int memType = (dramInit1 & MCTL_TYPE_SDRAM) ? MEM_TYPE_SDRAM : MEM_TYPE_SGRAM;
25 if (gInfo.sharedInfo->chipType == VOODOO_5) {
26 chipSize = 1 << ((dramInit0 >> 27) & 0x7);
27 } else {
28 // Banshee or Voodoo3
29 if (memType == MEM_TYPE_SDRAM)
30 chipSize = 2;
31 else
32 chipSize = (dramInit0 & SGRAM_TYPE) ? 2 : 1;
35 // Disable block writes for SDRAM.
37 uint32 miscInit1 = INREG32(MISC_INIT1);
38 if (memType == MEM_TYPE_SDRAM) {
39 miscInit1 |= DISABLE_2D_BLOCK_WRITE;
41 miscInit1 |= 1;
42 OUTREG32(MISC_INIT1, miscInit1);
44 return chipSize * numChips * 1024 * 1024;
48 status_t
49 TDFX_Init(void)
51 TRACE("TDFX_Init()\n");
53 SharedInfo& si = *gInfo.sharedInfo;
55 si.videoMemSize = TDFX_GetVideoMemorySize();
57 si.cursorOffset = 0;
58 si.frameBufferOffset = si.cursorOffset + CURSOR_BYTES;
59 si.maxFrameBufferSize = si.videoMemSize - si.frameBufferOffset;
61 TRACE("Video Memory size: %d MB\n", si.videoMemSize / 1024 / 1024);
62 TRACE("frameBufferOffset: 0x%x cursorOffset: 0x%x\n",
63 si.frameBufferOffset, si.cursorOffset);
65 switch (si.chipType) {
66 case BANSHEE:
67 si.maxPixelClock = 270000;
68 break;
69 case VOODOO_3:
70 si.maxPixelClock = 300000;
71 break;
72 case VOODOO_5:
73 si.maxPixelClock = 350000;
74 break;
75 default:
76 TRACE("Undefined chip type: %d\n", si.chipType);
77 return B_ERROR;
80 // Set up the array of color spaces supported by the 3dfx chips.
82 si.colorSpaces[0] = B_CMAP8;
83 si.colorSpaces[1] = B_RGB16;
84 si.colorSpaces[2] = B_RGB32;
85 si.colorSpaceCount = 3;
87 // Setup the mode list.
89 return CreateModeList(IsModeUsable);