Changeset c4c8d3fd in rtems


Ignore:
Timestamp:
Jun 10, 2021, 11:25:26 AM (3 months ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
master
Children:
2c07f24
Parents:
f89a527
git-author:
Sebastian Huber <sebastian.huber@…> (06/10/21 11:25:26)
git-committer:
Sebastian Huber <sebastian.huber@…> (06/17/21 10:58:33)
Message:

grlib: Customizable allocation in ambapp_scan()

Make the memory allocations in ambapp_scan() customizable via the new struct
ambapp_context parameter which generalizes the memory copy handler.

Location:
bsps
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • bsps/include/grlib/ambapp.h

    rf89a527 rc4c8d3fd  
    1616#define __AMBAPP_H__
    1717
    18 /**
    19  * @defgroup amba AMBA
    20  *
    21  * @ingroup RTEMSBSPsSharedGRLIB
    22  *
    23  * @brief AMBA Plug & Play routines
    24  *
    25  * @{
    26  */
     18#include <stddef.h>
    2719
    2820/* Include VENDOR and DEVICE definitions */
     
    3224extern "C" {
    3325#endif
     26
     27/**
     28 * @defgroup amba AMBA
     29 *
     30 * @ingroup RTEMSBSPsSharedGRLIB
     31 *
     32 * @brief AMBA Plug & Play routines
     33 *
     34 * @{
     35 */
    3436
    3537/* Max supported AHB buses */
     
    182184        );
    183185
     186struct ambapp_context {
     187  ambapp_memcpy_t copy_from_device;
     188  void *(*alloc)(size_t);
     189};
     190
    184191/* Scan a AMBA Plug & Play bus and create all device structures describing the
    185192 * the devices. The devices will form a tree, where every node describes one
     
    189196 * that is located over PCI and SpaceWire etc.
    190197 *
     198 * \param abus     Resulting device node tree root is stored here.
    191199 * \param ioarea   The IO-AREA where Plug & Play information can be found.
    192  * \param parent   Used internally when recursing down a bridge. Set to NULL.
     200 * \param ctx      The scan context.  May be NULL.
    193201 * \param mmaps    Is used to perform address translation if needed.
    194  * \param root     Resulting device node tree root is stored here.
    195202 *
    196203 */
     
    198205        struct ambapp_bus *abus,
    199206        unsigned int ioarea,
    200         ambapp_memcpy_t memfunc,
     207        const struct ambapp_context *ctx,
    201208        struct ambapp_mmap *mmaps
    202209        );
  • bsps/shared/grlib/amba/ambapp.c

    rf89a527 rc4c8d3fd  
    2424
    2525/* Allocate one AMBA device */
    26 static struct ambapp_dev *ambapp_alloc_dev_struct(int dev_type)
     26static struct ambapp_dev *
     27ambapp_alloc_dev_struct(const struct ambapp_context *ctx, int dev_type)
    2728{
    2829  struct ambapp_dev *dev;
     
    3334  else
    3435    size += sizeof(struct ambapp_ahb_info); /* AHB */
    35   dev = grlib_calloc(1, size);
    36   if (dev != NULL)
     36  dev = (*ctx->alloc)(size);
     37  if (dev != NULL) {
     38    dev = memset(dev, 0, size);
    3739    dev->dev_type = dev_type;
     40  }
    3841  return dev;
    3942}
     
    146149  struct ambapp_bus *abus,
    147150  unsigned int ioarea,
    148   ambapp_memcpy_t memfunc,
     151  const struct ambapp_context *ctx,
    149152  struct ambapp_dev *parent,
    150153  struct ambapp_dev **root
     
    177180  ahb = (struct ambapp_pnp_ahb *) (ioarea | AMBA_CONF_AREA);
    178181  for (i = 0; i < maxloops; i++, ahb++) {
    179     memfunc(&ahb_buf, ahb, sizeof(struct ambapp_pnp_ahb), abus);
     182    (*ctx->copy_from_device)(&ahb_buf, ahb, sizeof(struct ambapp_pnp_ahb), abus);
    180183    if (ahb_buf.id == 0)
    181184      continue;
    182185
    183186    /* An AHB device present here */
    184     dev = ambapp_alloc_dev_struct(DEV_AHB_MST);
     187    dev = ambapp_alloc_dev_struct(ctx, DEV_AHB_MST);
    185188    if (!dev)
    186189      return -1;
     
    201204    (ioarea | AMBA_CONF_AREA | AMBA_AHB_SLAVE_CONF_AREA);
    202205  for (i = 0; i < maxloops; i++, ahb++) {
    203     memfunc(&ahb_buf, ahb, sizeof(struct ambapp_pnp_ahb), abus);
     206    (*ctx->copy_from_device)(&ahb_buf, ahb, sizeof(struct ambapp_pnp_ahb), abus);
    204207    if (ahb_buf.id == 0)
    205208      continue;
    206209
    207210    /* An AHB device present here */
    208     dev = ambapp_alloc_dev_struct(DEV_AHB_SLV);
     211    dev = ambapp_alloc_dev_struct(ctx, DEV_AHB_SLV);
    209212    if (!dev)
    210213      return -1;
     
    236239              ahb_info->custom[1]);
    237240        /* Scan next bus if not already scanned */
    238         if (ambapp_scan2(abus, bridge_adr, memfunc, dev,
     241        if (ambapp_scan2(abus, bridge_adr, ctx, dev,
    239242            &dev->children))
    240243          return -1;
     
    252255        (apbbase | AMBA_CONF_AREA);
    253256      for (j=0; j<AMBA_APB_SLAVES; j++, apb++) {
    254         memfunc(&apb_buf, apb, sizeof(*apb), abus);
     257        (*ctx->copy_from_device)(&apb_buf, apb, sizeof(*apb), abus);
    255258        if (apb_buf.id == 0)
    256259          continue;
    257260
    258         apbdev = ambapp_alloc_dev_struct(DEV_APB_SLV);
     261        apbdev = ambapp_alloc_dev_struct(ctx, DEV_APB_SLV);
    259262        if (!apbdev)
    260263          return -1;
     
    280283}
    281284
     285static const struct ambapp_context default_ctx = {
     286  .copy_from_device = (ambapp_memcpy_t)memcpy,
     287  .alloc = rtems_malloc
     288};
     289
    282290/* Build AMBA Plug & Play device graph */
    283291int ambapp_scan(
    284292  struct ambapp_bus *abus,
    285293  unsigned int ioarea,
    286   ambapp_memcpy_t memfunc,
     294  const struct ambapp_context *ctx,
    287295  struct ambapp_mmap *mmaps
    288296  )
    289297{
     298
    290299  memset(abus, 0, sizeof(*abus));
    291300  abus->mmaps = mmaps;
    292301
    293   /* Default to memcpy() */
    294   if (!memfunc)
    295     memfunc = (ambapp_memcpy_t)memcpy;
    296 
    297   return ambapp_scan2(abus, ioarea, memfunc, NULL, &abus->root);
     302  if (ctx == NULL) {
     303    ctx = &default_ctx;
     304  }
     305
     306  return ambapp_scan2(abus, ioarea, ctx, NULL, &abus->root);
    298307}
    299308
Note: See TracChangeset for help on using the changeset viewer.