The Pedigree Project  0.1
modules/drivers/common/nvidia/main.cc
1 /*
2  * Copyright (c) 2008-2014, Pedigree Developers
3  *
4  * Please see the CONTRIB file in the root of the source tree for a full
5  * list of contributors.
6  *
7  * Permission to use, copy, modify, and distribute this software for any
8  * purpose with or without fee is hereby granted, provided that the above
9  * copyright notice and this permission notice appear in all copies.
10  *
11  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18  */
19 
20 #include "modules/Module.h"
21 #include "pedigree/kernel/Log.h"
22 #include "pedigree/kernel/machine/Display.h"
23 #include "pedigree/kernel/machine/Machine.h"
24 #include "pedigree/kernel/processor/MemoryMappedIo.h"
25 #include "pedigree/kernel/processor/Processor.h"
26 #include "pedigree/kernel/processor/types.h"
27 #include "pedigree/kernel/utilities/List.h"
28 #include "pedigree/kernel/utilities/StaticString.h"
29 
30 #include "Dma.h"
31 
32 static bool bFound = false;
33 
34 void probeDevice(Device *pDev)
35 {
36  NOTICE("Nvidia found");
37 
38  IoBase *pRegs = 0;
39  for (size_t i = 0; i < pDev->addresses().count(); i++)
40  if (!StringCompare(pDev->addresses()[i]->m_Name, "bar0"))
41  pRegs = pDev->addresses()[i]->m_Io;
42 
43  IoBase *pFb = 0;
44  for (size_t i = 0; i < pDev->addresses().count(); i++)
45  if (!StringCompare(pDev->addresses()[i]->m_Name, "bar1"))
46  pFb = pDev->addresses()[i]->m_Io;
47 
48  // I have an NV34 type, NV30A arch chip.
50  return;
51  uint32_t strapinfo = pRegs->read32(NV32_NV10STRAPINFO);
52  NOTICE(
53  "Strapinfo: " << Hex << strapinfo
54  << ", ram: " << ((strapinfo & 0x3ff00000) >> 20));
55  // Processor::breakpoint();
56  // Pink background to make sure we see any effects - engine may accidentally
57  // blit black pixels for example, and we won't pick that up on a black
58  // background.
59  for (int x = 0; x < 512; x++)
60  for (int y = 0; y < 512; y++)
61  pFb->write16(0xF00F, (y * 1024 + x) * 2);
62 
63  // Draw an image.
64  for (int x = 0; x < 128; x++)
65  for (int y = 256; y < 128 + 256; y++)
66  pFb->write16(0xFFFF, (y * 1024 + x) * 2);
67 
68  // Card detection is done but not coded yet - hardcoded to the device class
69  // in my testbed.
70  Dma *pDma = new Dma(
71  pRegs, pFb, NV40A, NV40 /*NV30A, NV34*/,
72  0x300000 /* Card RAM - hardcoded for now */);
73  pDma->init();
74  for (;;)
75  ;
76  pDma->screenToScreenBlit(0, 256, 400, 100, 100, 100);
77 
78  pDma->fillRectangle(600, 600, 100, 100);
79 
80  for (;;)
81  ;
82 
83  bFound = true;
84 }
85 
86 bool entry()
87 {
88  Device::searchByVendorId(0x10DE, probeDevice);
89 
90  return bFound;
91 }
92 
93 void exit()
94 {
95 }
96 
97 MODULE_INFO("nvidia", &entry, &exit, "pci");
virtual Vector< Address * > & addresses()
Definition: Device.h:256
Abstrace base class for hardware I/O capabilities.
Definition: IoBase.h:31
static void searchByVendorId(uint16_t vendorId, void(*callback)(Device *), Device *root=0)
Definition: Device.cc:182
Definition: Device.h:43
Definition: Dma.h:118
virtual void write16(uint16_t value, size_t offset=0)=0
virtual uint32_t read32(size_t offset=0)=0
#define NOTICE(text)
Definition: Log.h:74
Definition: Log.h:136