Author: arty
Date: Sun Apr 29 13:12:55 2007
New Revision: 26578
URL:
http://svn.reactos.org/svn/reactos?rev=26578&view=rev
Log:
Some additions:
- Make sure translations are on after we set the new SDR
- Add some new prep hardware
Despite its weaknesses, I'm indebted to my thinkpad 860 for
teaching me about PCI controllers, and giving me confidence
on PPC hardware
Added:
branches/powerpc/reactos/boot/freeldr/freeldr/arch/powerpc/prep_pci.c
branches/powerpc/reactos/boot/freeldr/freeldr/arch/powerpc/prep_vga.c
Modified:
branches/powerpc/reactos/boot/freeldr/freeldr/arch/powerpc/mboot.c
branches/powerpc/reactos/boot/freeldr/freeldr/arch/powerpc/prep.c
branches/powerpc/reactos/boot/freeldr/freeldr/arch/powerpc/prep.h
branches/powerpc/reactos/tools/ppc.lost+found/link-freeldr
Modified: branches/powerpc/reactos/boot/freeldr/freeldr/arch/powerpc/mboot.c
URL:
http://svn.reactos.org/svn/reactos/branches/powerpc/reactos/boot/freeldr/fr…
==============================================================================
--- branches/powerpc/reactos/boot/freeldr/freeldr/arch/powerpc/mboot.c (original)
+++ branches/powerpc/reactos/boot/freeldr/freeldr/arch/powerpc/mboot.c Sun Apr 29 13:12:55
2007
@@ -210,8 +210,9 @@
(ULONG_PTR)MmAllocateMemory(128*1024);
DIRECTORY_ENTRY *Entry;
LoaderBlock.ArchExtra = (ULONG)LocalBootInfo;
-
- printf("Translation map: %x\n", TranslationMap);
+ int msr = GetMSR();
+
+ printf("Translation map: %x (msr %x)\n", TranslationMap, msr);
NewMapSdr = XROUNDUP(NewMapSdr,64*1024);
printf("New SDR1 value will be %x\n", NewMapSdr);
@@ -257,9 +258,12 @@
/* Tell them we're booting */
DrawNumber(LocalBootInfo,(ULONG)&LoaderBlock,10,100);
+
+ SetSDR1( NewMapSdr );
+ msr |= 0x30;
+ printf("About to set msr (%x)!!!\n", msr);
+ __asm__("mtmsr %0" : : "r" (msr) );
DrawNumber(LocalBootInfo,(ULONG)KernelEntryAddress,100,100);
-
- SetSDR1( NewMapSdr );
KernelEntryAddress( (void*)&LoaderBlock );
/* Nothing more */
while(1);
Modified: branches/powerpc/reactos/boot/freeldr/freeldr/arch/powerpc/prep.c
URL:
http://svn.reactos.org/svn/reactos/branches/powerpc/reactos/boot/freeldr/fr…
==============================================================================
--- branches/powerpc/reactos/boot/freeldr/freeldr/arch/powerpc/prep.c (original)
+++ branches/powerpc/reactos/boot/freeldr/freeldr/arch/powerpc/prep.c Sun Apr 29 13:12:55
2007
@@ -62,7 +62,9 @@
void PpcPrepVideoPrepareForReactOS()
{
+ pci_setup(&pci1_desc);
}
+
ULONG PpcPrepGetMemoryMap( PBIOS_MEMORY_MAP BiosMemoryMap,
ULONG MaxMemoryMapSize )
{
Modified: branches/powerpc/reactos/boot/freeldr/freeldr/arch/powerpc/prep.h
URL:
http://svn.reactos.org/svn/reactos/branches/powerpc/reactos/boot/freeldr/fr…
==============================================================================
--- branches/powerpc/reactos/boot/freeldr/freeldr/arch/powerpc/prep.h (original)
+++ branches/powerpc/reactos/boot/freeldr/freeldr/arch/powerpc/prep.h Sun Apr 29 13:12:55
2007
@@ -1,7 +1,12 @@
#ifndef FREELDR_ARCH_POWERPC_PREP_H
#define FREELDR_ARCH_POWERPC_PREP_H
+extern struct _pci_desc pci1_desc;
extern struct _idectl_desc ide1_desc;
+extern struct _vga_desc vga1_desc;
+struct _pci_bar {
+ unsigned long data;
+};
void sync();
void PpcPrepInit();
@@ -9,4 +14,11 @@
int ide_read( void *extension, char *buffer, int bytes );
void ide_setup( void *extension );
+void print_bar( struct _pci_bar *bar );
+void pci_setup( struct _pci_desc *pci_desc );
+void pci_read_bar( struct _pci_desc *pci_desc, int bus, int dev, int fn, int bar, struct
_pci_bar *bar_data );
+
+void vga_setup( struct _pci_desc *pci_desc, struct _vga_desc *vga_desc,
+ int bus, int dev, int fn );
+
#endif//FREELDR_ARCH_POWERPC_PREP_H
Added: branches/powerpc/reactos/boot/freeldr/freeldr/arch/powerpc/prep_pci.c
URL:
http://svn.reactos.org/svn/reactos/branches/powerpc/reactos/boot/freeldr/fr…
==============================================================================
--- branches/powerpc/reactos/boot/freeldr/freeldr/arch/powerpc/prep_pci.c (added)
+++ branches/powerpc/reactos/boot/freeldr/freeldr/arch/powerpc/prep_pci.c Sun Apr 29
13:12:55 2007
@@ -1,0 +1,127 @@
+#include <freeldr.h>
+#include "prep.h"
+
+typedef struct _pci_cfg {
+ unsigned long addr;
+ unsigned long data;
+} pci_cfg;
+
+typedef struct _pci_desc {
+ pci_cfg *cfg;
+} pci_desc;
+
+pci_desc pci1_desc = { (void *)0x80000cf8 };
+#define rev16(x) ((((x)>>8)&0xff)|(((x)&0xff)<<8))
+#define rev32(x)
((((x)>>24)&0xff)|(((x)>>8)&0xff00)|(((x)&0xff00)<<8)|(((x)&0xff)<<24))
+#define pci_addr(bus,dev,fn,reg) \
+ (0x80000000 | \
+ ((bus & 0xff) << 16) | \
+ ((dev & 0x1f) << 11) | \
+ ((fn & 7) << 8) | \
+ (reg & 0xfc))
+#if 0
+#define pci_cfg_addr(bus,dev,fn,reg) \
+ ((bus == 0) ? \
+ ((1 << (dev + 16)) | \
+ (dev << 11) | \
+ (fn << 8) | \
+ ((reg & 0xfc) | 1)) : pci_addr(bus,dev,fn,reg))
+#else
+#define pci_cfg_addr(bus,dev,fn,reg) pci_addr(bus,dev,fn,reg)
+#endif
+ unsigned long pci_read( pci_desc *desc, int bus, int dev, int fn, int reg, int len )
{
+ sync();
+ unsigned long save_state = desc->cfg->addr, ret = 0;
+ unsigned long addr = pci_cfg_addr(bus,dev,fn,reg);
+ unsigned long offset = reg & 3;
+ desc->cfg->addr = rev32(addr);
+ sync();
+ switch( len ) {
+ case 4:
+ ret = desc->cfg->data;
+ break;
+ case 2:
+ ret = desc->cfg->data;
+ ret = (ret >> (offset << 3)) & 0xffff;
+ break;
+ case 1:
+ ret = desc->cfg->data;
+ ret = (ret >> (offset << 3)) & 0xff;
+ break;
+ }
+ desc->cfg->addr = save_state;
+ sync();
+ return ret;
+ }
+
+void pci_read_bar( pci_desc *desc, int bus, int dev, int fn, int bar,
+ struct _pci_bar *bar_data ) {
+ bar_data->data = pci_read( desc, bus, dev, fn, 0x10 + (bar * 4), 4 );
+}
+
+/*
+ * Imagine: offset 3, len 1
+ * let oldval = 0x12345678 and val = 0xabcd1234;
+ * mask = ((1 << 8) - 1) << 24; // 0xff000000
+ * oldval = (0x12345678 & 0x00ffffff) | (0xabcd1234 & 0xff000000) = 0xab345678;
+ */
+void pci_write( pci_desc *desc, int bus, int dev, int fn, int reg, int len, int val ) {
+ unsigned long save_state = desc->cfg->addr;
+ unsigned long addr = pci_cfg_addr(bus,dev,fn,reg);
+ unsigned long offset = reg & 3;
+ unsigned long oldval = pci_read( desc, bus, dev, fn, reg & ~3, 4 );
+ unsigned long mask = ((1 << (len * 8)) - 1) << (offset << 3);
+ oldval = (oldval & ~mask) | ((val << (offset << 3)) & mask);
+ desc->cfg->addr = rev32(addr);
+ sync();
+ desc->cfg->data = rev32(oldval);
+ sync();
+ desc->cfg->addr = save_state;
+ sync();
+}
+
+void pci_write_bar( pci_desc *desc, int bus, int dev, int fn, int bar, struct _pci_bar
*bar_data ) {
+ pci_write( desc, bus, dev, fn, 0x10 + (bar * 4), 4, bar_data->data );
+}
+
+void print_bar( struct _pci_bar *bar ) {
+ printf("BAR: %x\n", bar->data);
+}
+
+#define PCI_VENDORID 0
+#define PCI_DEVICEID 2
+#define PCI_HEADER_TYPE 0xe
+#define PCI_BASECLASS 0xb
+
+void pci_setup( pci_desc *desc ) {
+ unsigned char type;
+ unsigned short vendor, device, devclass;
+ int funcs, bus, dev, fn;
+
+ pci1_desc.cfg = (pci_cfg *)0x80000cf8;
+
+ printf("PCI Bus:\n");
+ for( bus = 0; bus < 1; bus++ ) {
+ for( dev = 0; dev < 32; dev++ ) {
+ type = pci_read(desc,bus,dev,0,PCI_HEADER_TYPE,1);
+ vendor = pci_read(desc,bus,dev,0,PCI_VENDORID,2);
+ device = pci_read(desc,bus,dev,0,PCI_DEVICEID,2);
+
+ if(vendor == 0 || vendor == 0xffff) continue;
+ if(type & 0x80) funcs = 8; else funcs = 1;
+
+ for( fn = 0; fn < funcs; fn++ ) {
+ devclass = pci_read(desc,bus,dev,fn,PCI_BASECLASS,1);
+ printf(" %d:%d -> vendor:device:class %x:%x:%x\n",
+ bus, dev, vendor, device, devclass);
+
+ if( devclass == 3 ) {
+ printf("Setting up vga...\n");
+ vga_setup(desc,&vga1_desc,bus,dev,fn);
+ printf("Done with vga\n");
+ }
+ }
+ }
+ }
+ printf("^-- end PCI\n");
+}
Added: branches/powerpc/reactos/boot/freeldr/freeldr/arch/powerpc/prep_vga.c
URL:
http://svn.reactos.org/svn/reactos/branches/powerpc/reactos/boot/freeldr/fr…
==============================================================================
--- branches/powerpc/reactos/boot/freeldr/freeldr/arch/powerpc/prep_vga.c (added)
+++ branches/powerpc/reactos/boot/freeldr/freeldr/arch/powerpc/prep_vga.c Sun Apr 29
13:12:55 2007
@@ -1,0 +1,26 @@
+#include <freeldr.h>
+#include "prep.h"
+
+struct _vga_desc {
+ char *port;
+ char *addr;
+};
+
+#define VGA_WIDTH 1024
+#define VGA_HEIGHT 768
+struct _vga_desc vga1_desc = { (char *)0x800003c0 };
+
+void vga_setup( struct _pci_desc *desc, struct _vga_desc *vga_desc,
+ int bus, int dev, int fn ) {
+ struct _pci_bar bar_data;
+ int i;
+
+ for( i = 0; i < 6; i++ ) {
+ pci_read_bar( desc, bus, dev, fn, i, &bar_data );
+ print_bar( &bar_data );
+ if( (bar_data.data > 0x10000) || ((bar_data.data&1) == 1) ) {
+ vga_desc->addr = (char *)(0xc0000000 + (bar_data.data & ~0x7ff));
+ break;
+ }
+ }
+}
Modified: branches/powerpc/reactos/tools/ppc.lost+found/link-freeldr
URL:
http://svn.reactos.org/svn/reactos/branches/powerpc/reactos/tools/ppc.lost%…
==============================================================================
--- branches/powerpc/reactos/tools/ppc.lost+found/link-freeldr (original)
+++ branches/powerpc/reactos/tools/ppc.lost+found/link-freeldr Sun Apr 29 13:12:55 2007
@@ -55,6 +55,8 @@
obj-ppc/boot/freeldr/freeldr/arch/powerpc/mboot.o \
obj-ppc/boot/freeldr/freeldr/arch/powerpc/prep.o \
obj-ppc/boot/freeldr/freeldr/arch/powerpc/prep_ide.o \
+ obj-ppc/boot/freeldr/freeldr/arch/powerpc/prep_pci.o \
+ obj-ppc/boot/freeldr/freeldr/arch/powerpc/prep_vga.o \
obj-ppc/boot/freeldr/freeldr/bootmgr.o \
obj-ppc/boot/freeldr/freeldr/drivemap.o \
obj-ppc/boot/freeldr/freeldr/miscboot.o \