Ticket #6105: 0001-Initial-OpenFirmware-frame-buffer-support.patch

File 0001-Initial-OpenFirmware-frame-buffer-support.patch, 9.6 KB (added by andreasf, 14 years ago)

draft patch

  • headers/private/kernel/boot/platform/openfirmware/platform_arch.h

    From 174fd3c1ae9cafb7113280b15b0f28662bda3497 Mon Sep 17 00:00:00 2001
    From: Andreas Faerber <andreas.faerber@web.de>
    Date: Mon, 31 May 2010 00:28:27 +0200
    Subject: [PATCH] Initial OpenFirmware frame buffer support
    
    ---
     .../boot/platform/openfirmware/platform_arch.h     |    4 +
     src/system/boot/platform/generic/video_blit.cpp    |    3 -
     src/system/boot/platform/generic/video_rle.cpp     |    2 -
     src/system/boot/platform/generic/video_splash.cpp  |    3 -
     src/system/boot/platform/openfirmware/Jamfile      |   12 ++-
     .../boot/platform/openfirmware/arch/ppc/mmu.cpp    |   19 ++++
     src/system/boot/platform/openfirmware/console.cpp  |    4 +
     src/system/boot/platform/openfirmware/video.cpp    |  106 +++++++++++++++++++-
     8 files changed, 139 insertions(+), 14 deletions(-)
    
    diff --git a/headers/private/kernel/boot/platform/openfirmware/platform_arch.h b/headers/private/kernel/boot/platform/openfirmware/platform_arch.h
    index 7d21e2a..c420aa7 100644
    a b extern "C" {  
    1616
    1717/* memory management */
    1818   
     19// For use with arch_mmu_map_physical_memory()
     20static const uint32 kDefaultPageMode = 0x3; // present, R/W
     21
    1922extern status_t arch_set_callback(void);
    2023extern void *arch_mmu_allocate(void *address, size_t size, uint8 protection,
    2124    bool exactAddress);
    2225extern status_t arch_mmu_free(void *address, size_t size);
    2326extern status_t arch_mmu_init(void);
     27extern addr_t arch_mmu_map_physical_memory(addr_t physicalAddress, size_t size, uint32 mode);
    2428
    2529/* CPU */
    2630
  • src/system/boot/platform/generic/video_blit.cpp

    diff --git a/src/system/boot/platform/generic/video_blit.cpp b/src/system/boot/platform/generic/video_blit.cpp
    index 56e45fb..b42ebc7 100644
    a b  
    66 */
    77
    88
    9 #include "video.h"
    10 
    119#include <arch/cpu.h>
    1210#include <boot/stage2.h>
    1311#include <boot/platform.h>
    14 #include <boot/menu.h>
    1512#include <boot/platform/generic/video.h>
    1613#include <boot/kernel_args.h>
    1714
  • src/system/boot/platform/generic/video_rle.cpp

    diff --git a/src/system/boot/platform/generic/video_rle.cpp b/src/system/boot/platform/generic/video_rle.cpp
    index 4708da0..b108e7f 100644
    a b  
    66 */
    77
    88
    9 #include "video.h"
    10 
    119#include <arch/cpu.h>
    1210#include <boot/stage2.h>
    1311#include <boot/platform.h>
  • src/system/boot/platform/generic/video_splash.cpp

    diff --git a/src/system/boot/platform/generic/video_splash.cpp b/src/system/boot/platform/generic/video_splash.cpp
    index 532c856..5b7db9e 100644
    a b  
    66 */
    77
    88
    9 #include "video.h"
    10 #include "mmu.h"
    11 
    129#include <arch/cpu.h>
    1310#include <boot/stage2.h>
    1411#include <boot/platform.h>
  • src/system/boot/platform/openfirmware/Jamfile

    diff --git a/src/system/boot/platform/openfirmware/Jamfile b/src/system/boot/platform/openfirmware/Jamfile
    index 00c2b6d..bf3785c 100644
    a b SubDir HAIKU_TOP src system boot platform openfirmware ;  
    22
    33SubDirC++Flags -D_BOOT_MODE -fno-rtti ;
    44
     5local genericPlatformSources =
     6    text_menu.cpp
     7    video_blit.cpp
     8    video_splash.cpp
     9    video_rle.cpp
     10;
     11
    512KernelMergeObject boot_platform_openfirmware.o :
    613    console.cpp
    714    debug.c
    KernelMergeObject boot_platform_openfirmware.o :  
    1926    openfirmware.cpp
    2027    openfirmware_devices.cpp
    2128
    22     # generic
    23     text_menu.cpp
     29    $(genericPlatformSources)
    2430    :
    2531    : boot_platform_openfirmware_$(TARGET_ARCH).a
    2632;
    2733
    28 SEARCH on [ FGristFiles text_menu.cpp ]
     34SEARCH on [ FGristFiles $(genericPlatformSources) ]
    2935    = [ FDirName $(HAIKU_TOP) src system boot platform generic ] ;
    3036SEARCH on [ FGristFiles openfirmware.cpp openfirmware_devices.cpp ]
    3137    = [ FDirName $(HAIKU_TOP) src system kernel platform openfirmware ] ;
  • src/system/boot/platform/openfirmware/arch/ppc/mmu.cpp

    diff --git a/src/system/boot/platform/openfirmware/arch/ppc/mmu.cpp b/src/system/boot/platform/openfirmware/arch/ppc/mmu.cpp
    index 48af378..4997b64 100644
    a b find_free_virtual_range(void *base, size_t size)  
    608608}
    609609
    610610
     611// TODO: This is a hack identity-mapping the physical memory
     612// since we don't seem to have the concept of next virtual addresses/pages in ppc (yet?)
     613extern "C" addr_t
     614arch_mmu_map_physical_memory(addr_t physicalAddress, size_t size, uint32 mode)
     615{
     616    addr_t address = physicalAddress/*sNextVirtualAddress*/;
     617    addr_t pageOffset = physicalAddress & (B_PAGE_SIZE - 1);
     618
     619    physicalAddress -= pageOffset;
     620    size += pageOffset;
     621
     622    for (addr_t offset = 0; offset < size; offset += B_PAGE_SIZE) {
     623        map_page((void*)(physicalAddress + offset)/*get_next_virtual_page()*/, (void*)(physicalAddress + offset), mode);
     624    }
     625
     626    return address /*+ pageOffset*/;
     627}
     628
     629
    611630extern "C" void *
    612631arch_mmu_allocate(void *_virtualAddress, size_t size, uint8 _protection,
    613632    bool exactAddress)
  • src/system/boot/platform/openfirmware/console.cpp

    diff --git a/src/system/boot/platform/openfirmware/console.cpp b/src/system/boot/platform/openfirmware/console.cpp
    index a639fea..9a9b5ac 100644
    a b  
    88#include <string.h>
    99#include <platform/openfirmware/openfirmware.h>
    1010#include <util/kernel_cpp.h>
     11#include <boot/stage2.h>
    1112
    1213#include "Handle.h"
    1314#include "console.h"
    ConsoleHandle::WriteAt(void */*cookie*/, off_t /*pos*/, const void *buffer,  
    6970{
    7071    const char *string = (const char *)buffer;
    7172
     73    if (gKernelArgs.frame_buffer.enabled)
     74        return bufferSize;
     75
    7276    // be nice to our audience and replace single "\n" with "\r\n"
    7377
    7478    while (bufferSize > 0) {
  • src/system/boot/platform/openfirmware/video.cpp

    diff --git a/src/system/boot/platform/openfirmware/video.cpp b/src/system/boot/platform/openfirmware/video.cpp
    index 6dbe494..418e57f 100644
    a b  
    11/*
    22 * Copyright 2004, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
     3 * Copyright 2010, Andreas Färber <andreas.faerber@web.de>
    34 * Distributed under the terms of the MIT License.
    45 */
    56
    67
     8#include <platform_arch.h>
     9#include <boot/stage2.h>
    710#include <boot/platform.h>
     11#include <boot/kernel_args.h>
     12#include <boot/platform/generic/video.h>
     13#include <platform/openfirmware/openfirmware.h>
     14#include <arch_mmu.h>
     15
     16
     17static int sScreen;
     18static addr_t sFrameBuffer;
     19
     20
     21void
     22platform_blit4(addr_t frameBuffer, const uint8 *data,
     23    uint16 width, uint16 height, uint16 imageWidth, uint16 left, uint16 top)
     24{
     25    if (!data)
     26        return;
     27    // TODO
     28}
     29
     30
     31extern "C" void
     32platform_set_palette(const uint8 *palette)
     33{
     34    switch (gKernelArgs.frame_buffer.depth) {
     35        case 8:
     36            // TODO try to optimize with set-colors
     37            for (int index = 0; index < 256; index++) {
     38                of_call_method(sScreen, "color!", 4, 0, index,
     39                    palette[index * 3 + 2],
     40                    palette[index * 3 + 1],
     41                    palette[index * 3 + 0]);
     42            }
     43            break;
     44        default:
     45            break;
     46    }
     47}
    848
    949
    1050extern "C" void
    1151platform_switch_to_logo(void)
    1252{
    13     // ToDo: implement me
     53    // in debug mode, we'll never show the logo
     54    if ((platform_boot_options() & BOOT_OPTION_DEBUG_OUTPUT) != 0)
     55        return;
     56    addr_t lastBase = gKernelArgs.frame_buffer.physical_buffer.start;
     57    size_t lastSize = gKernelArgs.frame_buffer.physical_buffer.size;
     58
     59    if (sScreen == OF_FAILED)
     60        return;
     61    int mode = 0x9;
     62    if (of_call_method(sScreen, "set-mode", 1, 0, mode) == OF_FAILED)
     63        dprintf("** mode not set!\n");
     64    int depth = 32;
     65    if (of_call_method(sScreen, "set-depth", 1, 0, depth) == OF_FAILED)
     66        dprintf("** depth not set!\n");
     67    int width, height;
     68    if (of_call_method(sScreen, "dimensions", 0, 2, &height, &width) == OF_FAILED)
     69        return;
     70    int package = of_instance_to_package(sScreen);
     71    if (package == OF_FAILED)
     72        return;
     73    int lineBytes;
     74    if (of_getprop(package, "linebytes", &lineBytes, sizeof(int)) == OF_FAILED)
     75        return;
     76    if (of_getprop(package, "address", &gKernelArgs.frame_buffer.physical_buffer.start, sizeof(int)) == OF_FAILED)
     77        return;
     78    gKernelArgs.frame_buffer.width = width;
     79    gKernelArgs.frame_buffer.height = height;
     80    gKernelArgs.frame_buffer.depth = depth;
     81    gKernelArgs.frame_buffer.bytes_per_row = lineBytes;
     82    gKernelArgs.frame_buffer.physical_buffer.size = lineBytes * height;
     83
     84    dprintf("video mode: %ux%ux%u\n", gKernelArgs.frame_buffer.width,
     85        gKernelArgs.frame_buffer.height, gKernelArgs.frame_buffer.depth);
     86
     87    gKernelArgs.frame_buffer.enabled = true;
     88
     89    // If the new frame buffer is either larger than the old one or located at
     90    // a different address, we need to remap it, so we first have to throw
     91    // away its previous mapping
     92    if (lastBase != 0
     93        && (lastBase != gKernelArgs.frame_buffer.physical_buffer.start
     94            || lastSize < gKernelArgs.frame_buffer.physical_buffer.size)) {
     95        arch_mmu_free((void *)sFrameBuffer, lastSize); // XXX not yet implemented
     96        lastBase = 0;
     97    }
     98    if (lastBase == 0) {
     99        // the graphics memory has not been mapped yet!
     100        sFrameBuffer = arch_mmu_map_physical_memory(
     101            gKernelArgs.frame_buffer.physical_buffer.start,
     102            gKernelArgs.frame_buffer.physical_buffer.size, kDefaultPageMode);
     103    }
     104
     105    video_display_splash(sFrameBuffer);
    14106}
    15107
    16108
    17109extern "C" void
    18110platform_switch_to_text_mode(void)
    19111{
    20     // ToDo: implement me
     112    if (!gKernelArgs.frame_buffer.enabled)
     113        return;
     114
     115    gKernelArgs.frame_buffer.enabled = 0;
    21116}
    22117
    23118
    24119extern "C" status_t
    25120platform_init_video(void)
    26121{
    27     // ToDo: implement me
     122    gKernelArgs.frame_buffer.enabled = 0;
     123
     124    sScreen = of_open("screen");
     125    if (sScreen == OF_FAILED)
     126        return B_NO_INIT;
     127
    28128    return B_OK;
    29129}
    30130