[PATCH 4/6] add fb support for rpi bsp

Gedare Bloom gedare at gwu.edu
Tue Aug 25 02:30:53 UTC 2015


On Mon, Aug 24, 2015 at 1:50 PM, Pavel Pisa <pisa at cmp.felk.cvut.cz> wrote:
> Hello Giao, Joel and Gedare,
>
> there are more technical problems to discuss.
> But I start with question if RPi video support
> should be unconditional. I am not sure if VideoCore
> activation has some consequences to ARM system throughput
> but at least it slows down startup.
>
> So there can be resons to disable video initialization.
> We have two options now
>
>   --video=<W>x<H>
>   --console=fbdev
>
> If --video is not specified then VideoCore is initialized
> and best fitting mode for monitor is selected. That is great,
> but I suggest two more valid options for --video option.
> The value "off" should disable graphics even if monitor
> is connected. The option "auto" should behave as it behaves now.
> The default behavior then can be changed to even to not
> start video automatically but only when "--video" option is present.
> This is behavior of pc386 BSP for now. But default behavior with
> graphic enabled if monitor is connected is more appropriate
> for RPi. But disable option even in case of problem localization
> is important.
>
Yes that is good.

> The default console output to serial line is right according
> to me.
>
> The critical part is memory setup which has still some
> problems to solve. Comments inlined.
>
>
> On Thursday 13 of August 2015 00:08:03 YANG QIAO wrote:
>> From: YANG Qiao <yangqiao0505 at me.com>
>>
>> ---
>>  c/src/lib/libbsp/arm/raspberrypi/Makefile.am       |   5 +-
>>  c/src/lib/libbsp/arm/raspberrypi/console/fb.c      | 331
>> +++++++++++++++++++++ c/src/lib/libbsp/arm/raspberrypi/include/bsp.h     |
>>  2 +
>>  .../arm/raspberrypi/startup/bspgetworkarea.c       |  61 ++++
>>  c/src/lib/libbsp/arm/raspberrypi/startup/linkcmds  |   5 +-
>>  c/src/lib/libbsp/arm/raspberrypi/startup/mminit.c  |  42 +++
>>  6 files changed, 442 insertions(+), 4 deletions(-)
>>  create mode 100644 c/src/lib/libbsp/arm/raspberrypi/console/fb.c
>>  create mode 100644
>> c/src/lib/libbsp/arm/raspberrypi/startup/bspgetworkarea.c create mode
>> 100644 c/src/lib/libbsp/arm/raspberrypi/startup/mminit.c
>>
>> diff --git a/c/src/lib/libbsp/arm/raspberrypi/Makefile.am
>> b/c/src/lib/libbsp/arm/raspberrypi/Makefile.am index e0b4806..b4853a6
>> 100644
>> --- a/c/src/lib/libbsp/arm/raspberrypi/Makefile.am
>> +++ b/c/src/lib/libbsp/arm/raspberrypi/Makefile.am
>> @@ -79,7 +79,6 @@ libbsp_a_LIBADD =
>>  # Shared
>>  libbsp_a_SOURCES += ../../shared/bootcard.c
>>  libbsp_a_SOURCES += ../../shared/bspclean.c
>> -libbsp_a_SOURCES += ../../shared/bspgetworkarea.c
>>  libbsp_a_SOURCES += ../../shared/bsplibc.c
>>  libbsp_a_SOURCES += ../../shared/bsppost.c
>>  libbsp_a_SOURCES += ../../shared/bsppredriverhook.c
>> @@ -97,6 +96,7 @@ libbsp_a_SOURCES += ../shared/arm-cp15-set-ttb-entries.c
>>  libbsp_a_SOURCES += ../../shared/bspreset_loop.c
>>  libbsp_a_SOURCES += startup/bspstart.c
>>  libbsp_a_SOURCES += startup/cmdline.c
>> +libbsp_a_SOURCES += startup/bspgetworkarea.c
>>
>>  # IRQ
>>  libbsp_a_SOURCES += ../shared/arm-cp15-set-exception-handler.c
>> @@ -115,6 +115,7 @@ libbsp_a_SOURCES += ../../shared/console_select.c
>>  libbsp_a_SOURCES += ../../shared/console_write.c
>>  libbsp_a_SOURCES += console/console-config.c
>>  libbsp_a_SOURCES += console/usart.c
>> +libbsp_a_SOURCES += console/fb.c
>>
>>  # clock
>>  libbsp_a_SOURCES += clock/clockdrv.c ../../../shared/clockdrv_shell.h
>> @@ -147,7 +148,7 @@ libbsp_a_SOURCES += startup/bspstarthooks.c
>>
>>  # LIBMM
>>  libbsp_a_SOURCES += startup/mm_config_table.c
>> -libbsp_a_SOURCES += ../shared/mminit.c
>> +libbsp_a_SOURCES += startup/mminit.c
>>
>>
>> ###########################################################################
>>#### # Network                                                    #
>> diff --git a/c/src/lib/libbsp/arm/raspberrypi/console/fb.c
>> b/c/src/lib/libbsp/arm/raspberrypi/console/fb.c new file mode 100644
>> index 0000000..a83d560
>> --- /dev/null
>> +++ b/c/src/lib/libbsp/arm/raspberrypi/console/fb.c
>> @@ -0,0 +1,331 @@
>> +/**
>> + * @file
>> + *
>> + * @ingroup raspberrypi
>> + *
>> + * @brief framebuffer support.
>> + */
>> +
>> +/*
>> + * Copyright (c) 2015 Yang Qiao
>> + *
>> + *  The license and distribution terms for this file may be
>> + *  found in the file LICENSE in this distribution or at
>> + *
>> + *  http://www.rtems.org/license/LICENSE
>> + *
>> + */
>> +
>> +#include <stdlib.h>
>> +#include <stdio.h>
>> +#include <errno.h>
>> +#include <sys/types.h>
>> +
>> +#include <bsp.h>
>> +#include <bsp/raspberrypi.h>
>> +#include <bsp/mailbox.h>
>> +#include <bsp/vc.h>
>> +
>> +#include <rtems.h>
>> +#include <rtems/libio.h>
>> +#include <rtems/fb.h>
>> +#include <rtems/framebuffer.h>
>> +#include <rtems/score/atomic.h>
>> +
>> +#define SCREEN_WIDTH 1024
>> +#define SCREEN_HEIGHT 768
>> +#define BPP 32
>> +#define BUFFER_SIZE (SCREEN_WIDTH*SCREEN_HEIGHT*BPP/8)
>> +
>> +/* flag to limit driver to protect against multiple opens */
>> +static Atomic_Flag driver_mutex;
>> +
>> +/*
>> + * screen information for the driver (fb0).
>> + */
>> +
>> +static struct fb_var_screeninfo fb_var_info = {
>> +  .xres                = SCREEN_WIDTH,
>> +  .yres                = SCREEN_HEIGHT,
>> +  .bits_per_pixel      = BPP
>> +};
>> +
>> +static struct fb_fix_screeninfo fb_fix_info = {
>> +  .smem_start          = (void *) NULL,
>> +  .smem_len            = 0,
>> +  .type                = FB_TYPE_PACKED_PIXELS,
>> +  .visual              = FB_VISUAL_TRUECOLOR,
>> +  .line_length         = 0
>> +};
>> +
>> +int raspberrypi_get_fix_screen_info( struct fb_fix_screeninfo *info )
>> +{
>> +  *info = fb_fix_info;
>> +  return 0;
>> +}
>> +
>> +int raspberrypi_get_var_screen_info( struct fb_var_screeninfo *info )
>> +{
>> +  *info = fb_var_info;
>> +  return 0;
>> +}
>> +
>> +static int
>> +find_mode_from_cmdline(void)
>> +{
>> +  const char* opt;
>> +  char* endptr;
>> +  uint32_t width;
>> +  uint32_t height;
>> +  uint32_t bpp;
>> +  opt = rpi_cmdline_arg("--video=");
>> +  if (opt)
>> +  {
>> +      opt += sizeof("--video=")-1;
>> +      width = strtol(opt, &endptr, 10);
>> +      if (*endptr != 'x')
>> +      {
>> +          return -2;
>> +      }
>
> check there for "off" and "auto" and use some
> reasonable return values to control whether
> automatic mode selection  should be run later
> or display should be left off
>
>> +      opt = endptr+1;
>> +      height = strtol(opt, &endptr, 10);
>> +      switch (*endptr)
>> +      {
>> +          case '-':
>> +              opt = endptr+1;
>> +              if (strlen(opt) <= 2)
>> +                  bpp = strtol(opt, &endptr, 10);
>> +              else
>> +              {
>> +                  bpp = strtol(opt, &endptr, 10);
>> +                  if (*endptr != ' ')
>> +                  {
>> +                      return -4;
>> +                  }
>> +              }
>> +          case ' ':
>> +          case 0:
>> +              break;
>> +          default:
>> +              return -3;
>> +      }
>> +  }
>> +  else
>> +    return -1;
>> +
>> +  fb_var_info.xres    = width;
>> +  fb_var_info.yres    = height;
>> +
>> +  return 0;
>> +}
>> +
>> +static int
>> +find_mode_from_vc(void)
>> +{
>> +  bcm2835_get_display_size_entries entries;
>> +  bcm2835_mailbox_get_display_size(&entries);
>> +  unsigned int width = entries.width;
>> +  unsigned int height = entries.height;
>> +
>> +  if (width == 0 || height == 0)
>> +  {
>> +    fb_var_info.xres    = SCREEN_WIDTH;
>> +    fb_var_info.yres    = SCREEN_HEIGHT;
>> +  }
>> +  else
>> +  {
>> +    fb_var_info.xres     = width;
>> +    fb_var_info.yres     = height;
>> +  }
>> +
>> +  return 0;
>> +}
>> +
>> +static bool
>> +hdmi_is_present(void)
>> +{
>> +  bcm2835_get_display_size_entries entries;
>> +  bcm2835_mailbox_get_display_size(&entries);
>> +  if(entries.width == 0x290 && entries.height ==0x1A0 )
>> +  {
>> +    return false;
>> +  }
>> +  else
>> +  {
>> +    return true;
>> +  }
>> +}
>> +
>> +int
>> +fb_init(void)
>> +{
>> +  if (fb_fix_info.smem_start != NULL)
>> +  {
>> +    return -2;
>> +  }
>> +
>> +  if (hdmi_is_present() == false)
>> +  {
>> +    return -3;
>> +  }
>> +
>> +  if (find_mode_from_cmdline())
>> +  {
>> +    if(find_mode_from_vc())
>> +      return -1;
>> +  }
>> +
>> +  bcm2835_init_frame_buffer_entries  init_frame_buffer_entries;
>> +  init_frame_buffer_entries.xres = fb_var_info.xres;
>> +  init_frame_buffer_entries.yres = fb_var_info.yres;
>> +  init_frame_buffer_entries.xvirt = fb_var_info.xres;
>> +  init_frame_buffer_entries.yvirt = fb_var_info.yres;
>> +  init_frame_buffer_entries.depth = fb_var_info.bits_per_pixel;
>> +  init_frame_buffer_entries.pixel_order = bcm2835_mailbox_pixel_order_rgb;
>> +  init_frame_buffer_entries.alpha_mode =
>> bcm2835_mailbox_alpha_mode_0_opaque; +  init_frame_buffer_entries.voffset_x
>> = 0;
>> +  init_frame_buffer_entries.voffset_y = 0;
>> +  init_frame_buffer_entries.overscan_left = 0;
>> +  init_frame_buffer_entries.overscan_right = 0;
>> +  init_frame_buffer_entries.overscan_top = 0;
>> +  init_frame_buffer_entries.overscan_bottom = 0;
>> +  bcm2835_mailbox_init_frame_buffer(&init_frame_buffer_entries);
>> +
>> +  bcm2835_get_pitch_entries get_pitch_entries;
>> +  bcm2835_mailbox_get_pitch(&get_pitch_entries);
>> +
>> +  fb_var_info.xres = init_frame_buffer_entries.xres;
>> +  fb_var_info.yres = init_frame_buffer_entries.yres;
>> +  fb_var_info.bits_per_pixel = init_frame_buffer_entries.depth;
>> +  fb_fix_info.smem_start = init_frame_buffer_entries.base;
>> +  fb_fix_info.smem_len = init_frame_buffer_entries.size;
>> +  fb_fix_info.line_length = get_pitch_entries.pitch;
>> +
>> +  return 0;
>> +}
>> +
>> +
>> +/*
>> + * fbds device driver initialize entry point.
>> + */
>> +
>> +rtems_device_driver
>> +frame_buffer_initialize (rtems_device_major_number major,
>> +                 rtems_device_minor_number minor, void *arg)
>> +{
>> +  rtems_status_code status;
>> +
>> +  /* register the devices */
>> +  status = rtems_io_register_name (FRAMEBUFFER_DEVICE_0_NAME, major, 0);
>> +  if (status != RTEMS_SUCCESSFUL) {
>> +    printk ("[!] error registering framebuffer\n");
>> +    rtems_fatal_error_occurred (status);
>> +  }
>> +  _Atomic_Flag_clear(&driver_mutex, ATOMIC_ORDER_RELEASE);
>> +  return RTEMS_SUCCESSFUL;
>> +}
>> +
>> +/*
>> + * fbds device driver open operation.
>> + */
>> +
>> +rtems_device_driver
>> +frame_buffer_open (rtems_device_major_number major,
>> +           rtems_device_minor_number minor, void *arg)
>> +{
>> +  if (_Atomic_Flag_test_and_set(&driver_mutex, ATOMIC_ORDER_ACQUIRE) != 0
>> ) { +    printk( "FB_CIRRUS could not lock driver_mutex\n" );
>> +    return RTEMS_UNSATISFIED;
>> +  }
>> +
>> +  memset ((void *)fb_fix_info.smem_start, 0, fb_fix_info.smem_len);
>> +  return RTEMS_SUCCESSFUL;
>> +}
>> +
>> +/*
>> + * fbds device driver close operation.
>> + */
>> +
>> +rtems_device_driver
>> +frame_buffer_close (rtems_device_major_number major,
>> +            rtems_device_minor_number minor, void *arg)
>> +{
>> +  /* restore previous state.  for VGA this means return to text mode.
>> +   * leave out if graphics hardware has been initialized in
>> +   * frame_buffer_initialize() */
>> +  _Atomic_Flag_clear(&driver_mutex, ATOMIC_ORDER_RELEASE);
>> +  memset ((void *)fb_fix_info.smem_start, 0, fb_fix_info.smem_len);
>> +  return RTEMS_SUCCESSFUL;
>> +}
>> +
>> +/*
>> + * fbds device driver read operation.
>> + */
>> +
>> +rtems_device_driver
>> +frame_buffer_read (rtems_device_major_number major,
>> +           rtems_device_minor_number minor, void *arg)
>> +{
>> +  rtems_libio_rw_args_t *rw_args = (rtems_libio_rw_args_t *)arg;
>> +  rw_args->bytes_moved =
>> +    ((rw_args->offset + rw_args->count) > fb_fix_info.smem_len ) ?
>> +    (fb_fix_info.smem_len - rw_args->offset) :rw_args->count;
>> +  memcpy( rw_args->buffer,
>> +          (const void *) (fb_fix_info.smem_start + rw_args->offset),
>> +          rw_args->bytes_moved);
>> +  return RTEMS_SUCCESSFUL;
>> +}
>> +
>> +/*
>> + * fbds device driver write operation.
>> + */
>> +
>> +rtems_device_driver
>> +frame_buffer_write (rtems_device_major_number major,
>> +            rtems_device_minor_number minor, void *arg)
>> +{
>> +  rtems_libio_rw_args_t *rw_args = (rtems_libio_rw_args_t *)arg;
>> +  rw_args->bytes_moved =
>> +    ((rw_args->offset + rw_args->count) > fb_fix_info.smem_len ) ?
>> +    (fb_fix_info.smem_len - rw_args->offset) : rw_args->count;
>> +  memcpy( (void *) (fb_fix_info.smem_start + rw_args->offset),
>> +          rw_args->buffer,
>> +          rw_args->bytes_moved);
>> +  return RTEMS_SUCCESSFUL;
>> +}
>> +
>> +/*
>> + * ioctl entry point.
>> + */
>> +
>> +rtems_device_driver
>> +frame_buffer_control (rtems_device_major_number major,
>> +              rtems_device_minor_number minor, void *arg)
>> +{
>> +  rtems_libio_ioctl_args_t *args = arg;
>> +
>> +  /* XXX check minor */
>> +
>> +  switch (args->command) {
>> +  case FBIOGET_VSCREENINFO:
>> +    memcpy (args->buffer, &fb_var_info, sizeof (fb_var_info));
>> +    args->ioctl_return = 0;
>> +    break;
>> +  case FBIOGET_FSCREENINFO:
>> +    memcpy (args->buffer, &fb_fix_info, sizeof (fb_fix_info));
>> +    args->ioctl_return = 0;
>> +    break;
>> +  case FBIOGETCMAP:
>> +    args->ioctl_return = 0;
>> +    break;
>> +  case FBIOPUTCMAP:
>> +    args->ioctl_return = 0;
>> +    break;
>> +
>> +  default:
>> +    args->ioctl_return = 0;
>> +    break;
>> +
>> +  }
>> +  return RTEMS_SUCCESSFUL;
>> +}
>> diff --git a/c/src/lib/libbsp/arm/raspberrypi/include/bsp.h
>> b/c/src/lib/libbsp/arm/raspberrypi/include/bsp.h index 7cb9e70..0bc5f99
>> 100644
>> --- a/c/src/lib/libbsp/arm/raspberrypi/include/bsp.h
>> +++ b/c/src/lib/libbsp/arm/raspberrypi/include/bsp.h
>> @@ -34,6 +34,8 @@ extern "C" {
>>
>>  #define BSP_FEATURE_IRQ_EXTENSION
>>
>> +#define RPI_L2_CACHE_ENABLE 1
>> +
>>  #define BSP_GPIO_PIN_COUNT 32
>>  #define BSP_GPIO_PINS_PER_BANK 32
>>  #define BSP_GPIO_PINS_PER_SELECT_BANK 10
>> diff --git a/c/src/lib/libbsp/arm/raspberrypi/startup/bspgetworkarea.c
>> b/c/src/lib/libbsp/arm/raspberrypi/startup/bspgetworkarea.c new file mode
>> 100644
>> index 0000000..07a38e9
>> --- /dev/null
>> +++ b/c/src/lib/libbsp/arm/raspberrypi/startup/bspgetworkarea.c
>> @@ -0,0 +1,61 @@
>> +/**
>> + * @file
>> + *
>> + * @ingroup arm_start
>> + *
>> + * @brief Raspberry pi workarea initialization.
>> + *
>> + *  COPYRIGHT (c) 1989-2008.
>> + *  On-Line Applications Research Corporation (OAR).
>> + *
>> + *  Copyright (c) 2011-2012 embedded brains GmbH.
>> + *
>> + *  The license and distribution terms for this file may be
>> + *  found in the file LICENSE in this distribution or at
>> + *  http://www.rtems.org/license/LICENSE.
>> + *
>> + *  Copyright (c) 2015 YANG Qiao
>> + */
>> +
>> +#include <bsp.h>
>> +#include <bsp/bootcard.h>
>> +#include <bsp/vc.h>
>> +#ifdef BSP_INTERRUPT_STACK_AT_WORK_AREA_BEGIN
>> +  #include <rtems/config.h>
>> +#endif
>> +
>> +#if defined(HAS_UBOOT) && !defined(BSP_DISABLE_UBOOT_WORK_AREA_CONFIG)
>> +  #define USE_UBOOT
>> +#endif
>> +
>> +extern char WorkAreaBase[];
>> +
>> +#ifdef USE_UBOOT
>> +  #include <bsp/u-boot.h>
>> +#else
>> +  extern char RamBase[];
>> +  extern char RamSize[];
>> +#endif
>> +
>> +void bsp_work_area_initialize(void)
>> +{
>> +  uintptr_t work_base = (uintptr_t) WorkAreaBase;
>> +  uintptr_t ram_end;
>> +  bcm2835_get_arm_memory_entries arm_entry;
>> +  bcm2835_get_vc_memory_entries vc_entry;
>> +
>> +  #ifdef USE_UBOOT
>> +    ram_end = (uintptr_t) bsp_uboot_board_info.bi_memstart +
>> +                          bsp_uboot_board_info.bi_memsize;
>> +  #else
>> +    ram_end = (uintptr_t)RamBase + (uintptr_t)RamSize;
>> +  #endif
>> +
>> +  #ifdef BSP_INTERRUPT_STACK_AT_WORK_AREA_BEGIN
>> +    work_base += rtems_configuration_get_interrupt_stack_size();
>> +  #endif
>> +
>> +  bcm2835_mailbox_get_vc_memory(&vc_entry);
>> +  ram_end = ram_end>vc_entry.base? vc_entry.base: ram_end;
>> +  bsp_work_area_initialize_default( (void *) work_base, ram_end -
>> work_base ); +}
>
> OK, but there should be reflected space reserved
> for translation table table. It is defined as
>
>   bsp_translation_table_base = ORIGIN (RAM_MMU)
>
Yes, make sure ram_end is before the start of RAM_MMU here...

>> diff --git a/c/src/lib/libbsp/arm/raspberrypi/startup/linkcmds
>> b/c/src/lib/libbsp/arm/raspberrypi/startup/linkcmds index f1ad11c..81d4f8d
>> 100644
>> --- a/c/src/lib/libbsp/arm/raspberrypi/startup/linkcmds
>> +++ b/c/src/lib/libbsp/arm/raspberrypi/startup/linkcmds
>> @@ -37,8 +37,9 @@
>> --- a/c/src/lib/libbsp/arm/raspberrypi/startup/linkcmds
>> +++ b/c/src/lib/libbsp/arm/raspberrypi/startup/linkcmds
>> @@ -37,8 +37,9 @@
>>
>>  MEMORY {
>>         VECTOR_RAM     (AIW) : ORIGIN = 0x0       , LENGTH = 0x8000
>> -        RAM            (AIW) : ORIGIN = 0x00008000, LENGTH = 128M - 48K
>> -       RAM_MMU        (AIW) : ORIGIN = 128M - 16k, LENGTH = 16k
>> +        GPU_RAM        (AIW) : ORIGIN = 256M - 64M, LENGTH = 64M
>> +        RAM            (AIW) : ORIGIN = 0x00008000, LENGTH = 256M - 64M - 48K
>> +       RAM_MMU        (AIW) : ORIGIN = 256M - 64M - 16k, LENGTH = 16k
>> }
>
> There is significant problem in this LD script because you reserve
> space for translation table RAM_MMU at the end of the memory
> and if I understand to the VideoCore memory division right then
> it means that MMU translation table can be rewritten by VideoCore
I don't think so? The RAM_MMU gets the last 16K before the GPU_RAM.

> at any time. RAM_MMU has to be in the area owned by CPU for all cases.
> Because memory division is dynamic anyway I would left VideoCore memory
> out of the LD script. We can expect that VideoCore cannot take (cannot
> should not be configured) more than rest from 64 MB or left script intact
> if we consider that 128 has to be left for CPU.
>
> For 64 MB case
>
> MEMORY {
>        VECTOR_RAM     (AIW) : ORIGIN = 0x0       , LENGTH = 0x8000
>         RAM            (AIW) : ORIGIN = 0x00008000, LENGTH = 64M - 48K
>        RAM_MMU        (AIW) : ORIGIN = 64M - 16k, LENGTH = 16k
> }
>
> Then VideoCore is asked to provide its memory start address (CPU Limit)
> ten we know that  area
>   WorkAreaBase to 64M - 16k   can be used for work area
>   64M - 16k    to 64M         is reserved for page/translation table
>   64M          to ram_end     can again be added to workarea
>
> But that requires to register two separate blocks to memory allocator.
This can be done simply by not using unified heap/workspace. Or more
complex by using a rbheap allocator, but I don't know if that is the
best idea. Having the split memory managed as a single memory region
is not a great idea to me because it asks for trouble like bad memset
or pointer/bounds violations. I like your idea below better.

> Probably Joel or Gedare can guide us how that can be achieved
> but for case of configuration of separate objects for kernel
> and user heap regions that can get even more complicated.
>
> So I suggest next LD script change
>
> MEMORY {
>        VECTOR_RAM     (AIW) : ORIGIN = 0x0,         LENGTH = 0x4000
>        RAM_MMU        (AIW) : ORIGIN = 0x4000,      LENGTH = 16k
>        RAM            (AIW) : ORIGIN = 0x00008000,  LENGTH = 64M
> }
>
> The area from 0x4000 to 0x7fff should be available to RTEMS
> and even if ATAGs or device tree parsing is implemented then it
> should not be problem because these start by default at address
> 0x100 and biggest found device tree binary is bcm2709-rpi-2-b.dtb
> about 10 kB for now.
>
This makes sense to me.

> With this arrangement it is no problem to define
>   ram_end = vc_entry.base
> probably with a sanity check
>   if (ram_end > 1 GB)
>      ram_end = 1 GB;
>
> Then MMU should be setup for fixed part by
>   arm_cp15_start_setup_translation_table_and_enable_mmu_and_cache
>
> then rest of the found memory which can be used by CPU is added
>
>   arm_cp15_set_translation_table_entries for 64 M to ram_end
>         ARMV7_MMU_DATA_READ_WRITE_CACHED
>
> and last is added area shared with VideoCore
>
>   arm_cp15_set_translation_table_entries for 64 M to ram_end
>         ARMV7_MMU_DATA_READ_WRITE_CACHED
>       I am not sure if enabled cache is OK for this area.
>   It depends of state if mutual memory access coherence protocol
>   is defined between VideoCore and ARM core.
>
Seems unlikely, cache-coherent GPUs are still not common.

> The latst operation is
>
>   bsp_work_area_initialize_default( (void *) work_base, ram_end - work_base );
>
> By the way, it looks to me RAM_MMU region coverage is missing in all
> instances of arm_cp15_start_mmu_config_table[] used in different BSPs.
>
> This means that after switch to MMU enabled state the table cannot
> be accessed by CPU probably. Can somebody explain me/check if is
> the case?
>
I don't have time to investigate right now. May be worth filing a
ticket to look later. However, I don't think anyone has supported
changing the MMU table after setting it, so there wouldn't have been a
need to cover the area I guess.

Gedare

>>  REGION_ALIAS ("REGION_START", RAM);
>> diff --git a/c/src/lib/libbsp/arm/raspberrypi/startup/mminit.c
>> b/c/src/lib/libbsp/arm/raspberrypi/startup/mminit.c new file mode 100644
>> index 0000000..e012060
>> --- /dev/null
>> +++ b/c/src/lib/libbsp/arm/raspberrypi/startup/mminit.c
>> @@ -0,0 +1,42 @@
>> +/*
>> + * Copyright (c) 2015 Yang Qiao
>> + * based on work by:
>> + * Copyright (c) 2013 Hesham AL-Matary.
>> + *
>> + * The license and distribution terms for this file may be
>> + * found in the file LICENSE in this distribution or at
>> + * http://www.rtems.org/license/LICENSE.
>> + */
>> +
>> +#define ARM_CP15_TEXT_SECTION BSP_START_TEXT_SECTION
>> +
>> +#include <bsp/start.h>
>> +#include <bsp/arm-cp15-start.h>
>> +#include <bsp/linker-symbols.h>
>> +#include <bsp/mm.h>
>> +#include <rtems/fb.h>
>> +
>> +extern int raspberrypi_get_var_screen_info( struct fb_var_screeninfo *info
>> ); +
>> +BSP_START_TEXT_SECTION void bsp_memory_management_initialize(void)
>> +{
>> +  uint32_t ctrl = arm_cp15_get_control();
>> +
>> +  ctrl |= ARM_CP15_CTRL_AFE | ARM_CP15_CTRL_S | ARM_CP15_CTRL_XP;
>> +
>> +  struct fb_fix_screeninfo fb_fix_info;
>> +  raspberrypi_get_fix_screen_info(&fb_fix_info);
>> +
>> +  arm_cp15_start_setup_translation_table_and_enable_mmu_and_cache(
>> +    ctrl,
>> +    (uint32_t *) bsp_translation_table_base,
>> +    ARM_MMU_DEFAULT_CLIENT_DOMAIN,
>> +    &arm_cp15_start_mmu_config_table[0],
>> +    arm_cp15_start_mmu_config_table_size
>> +  );
>> +
>> +  arm_cp15_set_translation_table_entries(fb_fix_info.smem_start,
>> +                                        fb_fix_info.smem_start +
>> +                                        fb_fix_info.smem_len,
>> +                                        ARMV7_MMU_DATA_READ_WRITE_CACHED);
>> +}
>
> Best wishes,
>
>               Pavel
>


More information about the devel mailing list