Changeset 3d3ad4dc in rtems


Ignore:
Timestamp:
Jul 31, 2016, 9:33:06 AM (4 years ago)
Author:
Pavel Pisa <pisa@…>
Branches:
master
Children:
912a1a90
Parents:
842005e4
Message:

arm/raspberrypi: VideoCore? access corrections in cache operation and more error checking.

The first, mistake in buffer size computation for cache flush
and invalidate has been corrected.

GCC attribute( ( aligned( 64 ) ) ) should work and works for local
variables. Code ensures right stack alignment. But attribute has
to be moved to type declaration to ensure that structure size is affected
by attribute. But even this seems to not work reliably for some reason.
May it be, the stack area between frame start and end of local variable buffer
accessed during context switch or some stack prefetch during resturn
such way that some cache lines belonging to buffer are filled to cache.
Extending buffer by one more cache line padding helps there.

In the longer term perspective, buffer should be moved to some static
area or cache aligned dynamic memory allocated. Concurrent calls
to the VideoCore? operations and access serialization should be added
too but problem is that some calls are required during workspace and MMU
setup so variant without need of mutex would be required as well.

Framebuffer setup code and other VideoCore? calls check more
precisely for errors and do not proceed forward with incorrect
data now.

Signed-off-by: Pavel Pisa <pisa@…>

Location:
c/src/lib/libbsp/arm/raspberrypi
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • c/src/lib/libbsp/arm/raspberrypi/console/fb.c

    r842005e4 r3d3ad4dc  
    163163static int find_mode_from_vc( void )
    164164{
     165  int res;
     166  unsigned int width;
     167  unsigned int height;
    165168  bcm2835_get_display_size_entries entries;
    166169
    167   bcm2835_mailbox_get_display_size( &entries );
    168   unsigned int width = entries.width;
    169   unsigned int height = entries.height;
     170  res = bcm2835_mailbox_get_display_size( &entries );
     171
     172  width = entries.width;
     173  height = entries.height;
    170174
    171175  if ( width == 0 || height == 0 ) {
     
    176180    fb_var_info.yres = height;
    177181  }
    178 
    179   return 0;
     182  printk("find_mode_from_vc %u x %u, res %d\n", width, height, res);
     183
     184  return res;
    180185}
    181186
     
    200205int rpi_fb_init( void )
    201206{
     207  int res;
    202208  int                               mode_from_cmdline;
    203209  bcm2835_init_frame_buffer_entries init_frame_buffer_entries;
     
    244250  init_frame_buffer_entries.overscan_top = 0;
    245251  init_frame_buffer_entries.overscan_bottom = 0;
    246   bcm2835_mailbox_init_frame_buffer( &init_frame_buffer_entries );
     252  printk("bcm2835_mailbox_init_frame_buffer ...\n");
     253  res = bcm2835_mailbox_init_frame_buffer( &init_frame_buffer_entries );
     254  printk("bcm2835_mailbox_init_frame_buffer returned %d\n", res);
     255  if (res != 0) {
     256    printk("bcm2835_mailbox_init_frame_buffer retry ...\n");
     257    res = bcm2835_mailbox_init_frame_buffer( &init_frame_buffer_entries );
     258    printk("bcm2835_mailbox_init_frame_buffer returned %d\n", res);
     259    if (res != 0)
     260      return RPI_FB_INIT_SETUP_FAILED;
     261  }
    247262
    248263  bcm2835_get_pitch_entries get_pitch_entries;
     
    258273  if ( fb_fix_info.smem_start == NULL )
    259274    return RPI_FB_INIT_START_ADDR_UNKNOWN;
     275
     276  printk("fb_fix_info.smem_start %p\n", fb_fix_info.smem_start);
    260277
    261278  arm_cp15_set_translation_table_entries( (void *) fb_fix_info.smem_start,
  • c/src/lib/libbsp/arm/raspberrypi/include/rpi-fb.h

    r842005e4 r3d3ad4dc  
    4242  RPI_FB_INIT_CMDLINE_NO_MODE_REQ = -5,
    4343  RPI_FB_INIT_MODE_PROBE_ERROR = -6,
    44   RPI_FB_INIT_START_ADDR_UNKNOWN = -7,
     44  RPI_FB_INIT_SETUP_FAILED = -7,
     45  RPI_FB_INIT_START_ADDR_UNKNOWN = -8,
    4546};
    4647
  • c/src/lib/libbsp/arm/raspberrypi/misc/vc.c

    r842005e4 r3d3ad4dc  
    3232#endif
    3333
     34#define BCM2835_VC_MEMORY_MAPPING_MASK 0x3fffffff
     35
    3436static inline bool bcm2835_mailbox_buffer_suceeded(
    3537  const bcm2835_mbox_buf_hdr *hdr )
     
    4143static inline int bcm2835_mailbox_send_read_buffer( void *buf )
    4244{
     45  RTEMS_COMPILER_MEMORY_BARRIER();
    4346  raspberrypi_mailbox_write( BCM2835_MBOX_CHANNEL_PROP_AVC,
    4447    (unsigned int) buf + BCM2835_VC_MEMORY_MAPPING );
    4548  raspberrypi_mailbox_read( BCM2835_MBOX_CHANNEL_PROP_AVC );
     49  RTEMS_COMPILER_MEMORY_BARRIER();
    4650  return 0;
    4751}
     
    6771  bcm2835_get_display_size_entries *_entries )
    6872{
    69   struct {
     73  struct BCM2835_MBOX_BUF_ALIGN_ATTRIBUTE {
    7074    bcm2835_mbox_buf_hdr hdr;
    7175    bcm2835_mbox_tag_display_size get_display_size;
    7276    uint32_t end_tag;
    73   } buffer BCM2835_MBOX_BUF_ALIGN_ATTRIBUTE;
     77    uint32_t padding_reserve[16];
     78  } buffer;
    7479  BCM2835_MBOX_INIT_BUF( &buffer );
    7580  BCM2835_MBOX_INIT_TAG_NO_REQ( &buffer.get_display_size,
    7681    BCM2835_MAILBOX_TAG_GET_DISPLAY_SIZE );
    77   bcm2835_mailbox_buffer_flush_and_invalidate( &buffer, sizeof( &buffer ) );
     82  bcm2835_mailbox_buffer_flush_and_invalidate( &buffer, sizeof( buffer ) );
    7883
    7984  if ( bcm2835_mailbox_send_read_buffer( &buffer ) )
     
    8691    return -2;
    8792
     93  if ( !BCM2835_MBOX_TAG_REPLY_IS_SET( &buffer.get_display_size ) )
     94    return -3;
     95
    8896  return 0;
    8997}
     
    92100  bcm2835_init_frame_buffer_entries *_entries )
    93101{
    94   struct {
     102  struct BCM2835_MBOX_BUF_ALIGN_ATTRIBUTE {
    95103    bcm2835_mbox_buf_hdr hdr;
    96104    bcm2835_mbox_tag_display_size set_display_size;
     
    104112    bcm2835_mbox_tag_get_pitch get_pitch;
    105113    uint32_t end_tag;
    106   } buffer BCM2835_MBOX_BUF_ALIGN_ATTRIBUTE;
     114    uint32_t padding_reserve[16];
     115  } buffer;
    107116  BCM2835_MBOX_INIT_BUF( &buffer );
    108117  BCM2835_MBOX_INIT_TAG( &buffer.set_display_size,
     
    138147  BCM2835_MBOX_INIT_TAG_NO_REQ( &buffer.get_pitch,
    139148    BCM2835_MAILBOX_TAG_GET_PITCH );
    140   bcm2835_mailbox_buffer_flush_and_invalidate( &buffer, sizeof( &buffer ) );
     149  bcm2835_mailbox_buffer_flush_and_invalidate( &buffer, sizeof( buffer ) );
    141150
    142151  if ( bcm2835_mailbox_send_read_buffer( &buffer ) )
     
    148157  _entries->yvirt = buffer.set_virtual_size.body.resp.vheight;
    149158  _entries->depth = buffer.set_depth.body.resp.depth;
    150 #if ( BSP_IS_RPI2 == 1 )
    151159  _entries->base = buffer.allocate_buffer.body.resp.base;
    152 #else
    153   _entries->base = buffer.allocate_buffer.body.resp.base -
    154                    BCM2835_VC_MEMORY_MAPPING;
    155 #endif
     160  _entries->base &= BCM2835_VC_MEMORY_MAPPING_MASK;
    156161  _entries->size = buffer.allocate_buffer.body.resp.size;
    157162  _entries->pixel_order = buffer.set_pixel_order.body.resp.pixel_order;
     
    167172    return -2;
    168173
     174  if ( !BCM2835_MBOX_TAG_REPLY_IS_SET( &buffer.allocate_buffer ) )
     175    return -3;
     176
     177  if ( _entries->base < 0x100000 )
     178    return -4;
     179
    169180  return 0;
    170181}
     
    172183int bcm2835_mailbox_get_pitch( bcm2835_get_pitch_entries *_entries )
    173184{
    174   struct {
     185  struct BCM2835_MBOX_BUF_ALIGN_ATTRIBUTE {
    175186    bcm2835_mbox_buf_hdr hdr;
    176187    bcm2835_mbox_tag_get_pitch get_pitch;
    177188    uint32_t end_tag;
    178   } buffer BCM2835_MBOX_BUF_ALIGN_ATTRIBUTE;
     189    uint32_t padding_reserve[16];
     190  } buffer;
    179191  BCM2835_MBOX_INIT_BUF( &buffer );
    180192  BCM2835_MBOX_INIT_TAG_NO_REQ( &buffer.get_pitch,
    181193    BCM2835_MAILBOX_TAG_GET_PITCH );
    182   bcm2835_mailbox_buffer_flush_and_invalidate( &buffer, sizeof( &buffer ) );
     194  bcm2835_mailbox_buffer_flush_and_invalidate( &buffer, sizeof( buffer ) );
    183195
    184196  if ( bcm2835_mailbox_send_read_buffer( &buffer ) )
     
    190202    return -2;
    191203
     204  if ( !BCM2835_MBOX_TAG_REPLY_IS_SET( &buffer.get_pitch ) )
     205    return -3;
     206
    192207  return 0;
    193208}
     
    197212  int i;
    198213
    199   struct {
     214  struct BCM2835_MBOX_BUF_ALIGN_ATTRIBUTE {
    200215    bcm2835_mbox_buf_hdr hdr;
    201216    bcm2835_mbox_tag_get_cmd_line get_cmd_line;
    202217    uint32_t end_tag;
    203   } buffer BCM2835_MBOX_BUF_ALIGN_ATTRIBUTE;
     218    uint32_t padding_reserve[16];
     219  } buffer;
    204220  BCM2835_MBOX_INIT_BUF( &buffer );
    205221  BCM2835_MBOX_INIT_TAG_NO_REQ( &buffer.get_cmd_line,
    206222    BCM2835_MAILBOX_TAG_GET_CMD_LINE );
    207   bcm2835_mailbox_buffer_flush_and_invalidate( &buffer, sizeof( &buffer ) );
     223  bcm2835_mailbox_buffer_flush_and_invalidate( &buffer, sizeof( buffer ) );
    208224
    209225  if ( bcm2835_mailbox_send_read_buffer( &buffer ) )
     
    221237    return -2;
    222238
     239  if ( !BCM2835_MBOX_TAG_REPLY_IS_SET( &buffer.get_cmd_line ) )
     240    return -3;
     241
    223242  return 0;
    224243}
     
    226245int bcm2835_mailbox_set_power_state( bcm2835_set_power_state_entries *_entries )
    227246{
    228   struct {
     247  struct BCM2835_MBOX_BUF_ALIGN_ATTRIBUTE {
    229248    bcm2835_mbox_buf_hdr hdr;
    230249    bcm2835_mbox_tag_power_state set_power_state;
    231250    uint32_t end_tag;
    232   } buffer BCM2835_MBOX_BUF_ALIGN_ATTRIBUTE;
     251    uint32_t padding_reserve[16];
     252  } buffer;
    233253  BCM2835_MBOX_INIT_BUF( &buffer );
    234254  BCM2835_MBOX_INIT_TAG( &buffer.set_power_state,
     
    236256  buffer.set_power_state.body.req.dev_id = _entries->dev_id;
    237257  buffer.set_power_state.body.req.state = _entries->state;
    238   bcm2835_mailbox_buffer_flush_and_invalidate( &buffer, sizeof( &buffer ) );
     258  bcm2835_mailbox_buffer_flush_and_invalidate( &buffer, sizeof( buffer ) );
    239259
    240260  if ( bcm2835_mailbox_send_read_buffer( &buffer ) )
     
    252272int bcm2835_mailbox_get_arm_memory( bcm2835_get_arm_memory_entries *_entries )
    253273{
    254   struct {
     274  struct BCM2835_MBOX_BUF_ALIGN_ATTRIBUTE {
    255275    bcm2835_mbox_buf_hdr hdr;
    256276    bcm2835_mbox_tag_get_arm_memory get_arm_memory;
    257277    uint32_t end_tag;
    258   } buffer BCM2835_MBOX_BUF_ALIGN_ATTRIBUTE;
     278    uint32_t padding_reserve[16];
     279  } buffer;
    259280  BCM2835_MBOX_INIT_BUF( &buffer );
    260281  BCM2835_MBOX_INIT_TAG_NO_REQ( &buffer.get_arm_memory,
    261282    BCM2835_MAILBOX_TAG_GET_ARM_MEMORY );
    262   bcm2835_mailbox_buffer_flush_and_invalidate( &buffer, sizeof( &buffer ) );
     283  bcm2835_mailbox_buffer_flush_and_invalidate( &buffer, sizeof( buffer ) );
    263284
    264285  if ( bcm2835_mailbox_send_read_buffer( &buffer ) )
     
    271292    return -2;
    272293
     294  if ( !BCM2835_MBOX_TAG_REPLY_IS_SET( &buffer.get_arm_memory ) )
     295    return -3;
     296
    273297  return 0;
    274298}
     
    276300int bcm2835_mailbox_get_vc_memory( bcm2835_get_vc_memory_entries *_entries )
    277301{
    278   struct {
     302  struct BCM2835_MBOX_BUF_ALIGN_ATTRIBUTE {
    279303    bcm2835_mbox_buf_hdr hdr;
    280304    bcm2835_mbox_tag_get_vc_memory get_vc_memory;
    281305    uint32_t end_tag;
    282   } buffer BCM2835_MBOX_BUF_ALIGN_ATTRIBUTE;
     306    uint32_t padding_reserve[16];
     307  } buffer;
    283308  BCM2835_MBOX_INIT_BUF( &buffer );
    284309  BCM2835_MBOX_INIT_TAG_NO_REQ( &buffer.get_vc_memory,
    285310    BCM2835_MAILBOX_TAG_GET_VC_MEMORY );
    286   bcm2835_mailbox_buffer_flush_and_invalidate( &buffer, sizeof( &buffer ) );
     311  bcm2835_mailbox_buffer_flush_and_invalidate( &buffer, sizeof( buffer ) );
    287312
    288313  if ( bcm2835_mailbox_send_read_buffer( &buffer ) )
     
    295320    return -2;
    296321
     322  if ( !BCM2835_MBOX_TAG_REPLY_IS_SET( &buffer.get_vc_memory ) )
     323    return -3;
     324
    297325  return 0;
    298326}
     
    301329  bcm2835_mailbox_get_fw_rev_entries *_entries )
    302330{
    303   struct {
     331  struct BCM2835_MBOX_BUF_ALIGN_ATTRIBUTE {
    304332    bcm2835_mbox_buf_hdr hdr;
    305333    bcm2835_mbox_tag_get_fw_rev get_fw_rev;
    306334    uint32_t end_tag;
    307   } buffer BCM2835_MBOX_BUF_ALIGN_ATTRIBUTE;
     335    uint32_t padding_reserve[16];
     336  } buffer;
    308337  BCM2835_MBOX_INIT_BUF( &buffer );
    309338  BCM2835_MBOX_INIT_TAG_NO_REQ( &buffer.get_fw_rev,
    310339    BCM2835_MAILBOX_TAG_FIRMWARE_REVISION );
    311   bcm2835_mailbox_buffer_flush_and_invalidate( &buffer, sizeof( &buffer ) );
     340  bcm2835_mailbox_buffer_flush_and_invalidate( &buffer, sizeof( buffer ) );
    312341
    313342  if ( bcm2835_mailbox_send_read_buffer( &buffer ) )
     
    319348    return -2;
    320349
     350  if ( !BCM2835_MBOX_TAG_REPLY_IS_SET( &buffer.get_fw_rev ) )
     351    return -3;
     352
    321353  return 0;
    322354}
     
    324356int bcm2835_mailbox_get_board_model( bcm2835_get_board_spec_entries *_entries )
    325357{
    326   struct {
     358  struct BCM2835_MBOX_BUF_ALIGN_ATTRIBUTE {
    327359    bcm2835_mbox_buf_hdr hdr;
    328360    bcm2835_mbox_tag_get_board_spec get_board_model;
    329361    uint32_t end_tag;
    330   } buffer BCM2835_MBOX_BUF_ALIGN_ATTRIBUTE;
     362    uint32_t padding_reserve[16];
     363  } buffer;
    331364  BCM2835_MBOX_INIT_BUF( &buffer );
    332365  BCM2835_MBOX_INIT_TAG_NO_REQ( &buffer.get_board_model,
    333366    BCM2835_MAILBOX_TAG_GET_BOARD_MODEL );
    334   bcm2835_mailbox_buffer_flush_and_invalidate( &buffer, sizeof( &buffer ) );
     367  bcm2835_mailbox_buffer_flush_and_invalidate( &buffer, sizeof( buffer ) );
    335368
    336369  if ( bcm2835_mailbox_send_read_buffer( &buffer ) )
     
    341374  if ( !bcm2835_mailbox_buffer_suceeded( &buffer.hdr ) )
    342375    return -2;
     376
     377  if ( !BCM2835_MBOX_TAG_REPLY_IS_SET( &buffer.get_board_model ) )
     378    return -3;
    343379
    344380  return 0;
     
    348384  bcm2835_get_board_spec_entries *_entries )
    349385{
    350   struct {
     386  struct BCM2835_MBOX_BUF_ALIGN_ATTRIBUTE {
    351387    bcm2835_mbox_buf_hdr hdr;
    352388    bcm2835_mbox_tag_get_board_spec get_board_revision;
    353389    uint32_t end_tag;
    354   } buffer BCM2835_MBOX_BUF_ALIGN_ATTRIBUTE;
     390    uint32_t padding_reserve[16];
     391  } buffer;
    355392  BCM2835_MBOX_INIT_BUF( &buffer );
    356393  BCM2835_MBOX_INIT_TAG_NO_REQ( &buffer.get_board_revision,
    357394    BCM2835_MAILBOX_TAG_GET_BOARD_VERSION );
    358   bcm2835_mailbox_buffer_flush_and_invalidate( &buffer, sizeof( &buffer ) );
     395  bcm2835_mailbox_buffer_flush_and_invalidate( &buffer, sizeof( buffer ) );
    359396
    360397  if ( bcm2835_mailbox_send_read_buffer( &buffer ) )
     
    366403    return -2;
    367404
    368   return 0;
    369 }
     405  if ( !BCM2835_MBOX_TAG_REPLY_IS_SET( &buffer.get_board_revision ) )
     406    return -3;
     407
     408  return 0;
     409}
  • c/src/lib/libbsp/arm/raspberrypi/misc/vc_defines.h

    r842005e4 r3d3ad4dc  
    9595} bcm2835_mbox_tag_hdr;
    9696
     97#define BCM2835_MBOX_TAG_REPLY_IS_SET( _t_ ) \
     98   ( ( _t_ )->tag_hdr.val_len & 0x80000000 )
     99
    97100#define BCM2835_MBOX_INIT_BUF( _m_ ) { \
    98     memset( ( _m_ ), 0, sizeof( *( _m_ ) ) ); \
    99     ( _m_ )->hdr.buf_size = sizeof( *( _m_ ) ); \
     101    memset( ( _m_ ), 0,  sizeof( *( _m_ ) ) ); \
     102    ( _m_ )->hdr.buf_size = (void *)&(( _m_ )->end_tag) + 4 - (void *)( _m_ ); \
    100103    ( _m_ )->hdr.buf_code = BCM2835_MBOX_BUF_CODE_PROCESS_REQUEST; \
    101104    ( _m_ )->end_tag = 0; \
  • c/src/lib/libbsp/arm/raspberrypi/startup/bspgetworkarea.c

    r842005e4 r3d3ad4dc  
    7171
    7272  memset( &vc_entry, 0, sizeof(vc_entry) );
    73   bcm2835_mailbox_get_vc_memory( &vc_entry );
    74   if (vc_entry.base != 0)
    75     ram_end = ram_end > vc_entry.base? vc_entry.base: ram_end;
     73  if (bcm2835_mailbox_get_vc_memory( &vc_entry ) >= 0) {
     74    if (vc_entry.base > 10 * 1024 *1024)
     75      ram_end = ram_end > vc_entry.base? vc_entry.base: ram_end;
     76  }
    7677  bsp_work_area_initialize_default( (void *) work_base, ram_end - work_base );
    7778}
  • c/src/lib/libbsp/arm/raspberrypi/startup/cmdline.c

    r842005e4 r3d3ad4dc  
    2727{
    2828  memset(&rpi_cmdline_entries, 0, sizeof(rpi_cmdline_entries));
    29   bcm2835_mailbox_get_cmdline(&rpi_cmdline_entries);
     29  if (bcm2835_mailbox_get_cmdline(&rpi_cmdline_entries) < 0)
     30     return NULL;
    3031  return rpi_cmdline_entries.cmdline;
    3132}
     
    3536  if (rpi_cmdline_ready <= 0) {
    3637    const char *line = rpi_cmdline_get_raw();
    37     strncpy(rpi_cmdline_cached, line, MAX_CMDLINE_LENGTH - 1);
     38    if (line != NULL)
     39      strncpy(rpi_cmdline_cached, line, MAX_CMDLINE_LENGTH - 1);
    3840    rpi_cmdline_cached[MAX_CMDLINE_LENGTH - 1] = 0;
    3941    rpi_cmdline_ready = 1;
Note: See TracChangeset for help on using the changeset viewer.