OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-stable/] [gdb-7.2/] [sim/] [ppc/] [device_table.c] - Diff between revs 330 and 816

Go to most recent revision | Only display areas with differences | Details | Blame | View Log

Rev 330 Rev 816
/*  This file is part of the program psim.
/*  This file is part of the program psim.
 
 
    Copyright (C) 1994-1996, Andrew Cagney <cagney@highland.com.au>
    Copyright (C) 1994-1996, Andrew Cagney <cagney@highland.com.au>
 
 
    This program is free software; you can redistribute it and/or modify
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.
    (at your option) any later version.
 
 
    This program is distributed in the hope that it will be useful,
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.
    GNU General Public License for more details.
 
 
    You should have received a copy of the GNU General Public License
    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
 
    */
    */
 
 
 
 
#ifndef _DEVICE_TABLE_C_
#ifndef _DEVICE_TABLE_C_
#define _DEVICE_TABLE_C_
#define _DEVICE_TABLE_C_
 
 
#include "device_table.h"
#include "device_table.h"
 
 
#if HAVE_STDLIB_H
#if HAVE_STDLIB_H
#include <stdlib.h>
#include <stdlib.h>
#endif
#endif
 
 
#include <ctype.h>
#include <ctype.h>
 
 
 
 
/* Helper functions */
/* Helper functions */
 
 
 
 
/* Go through the devices various reg properties for those that
/* Go through the devices various reg properties for those that
   specify attach addresses */
   specify attach addresses */
 
 
 
 
void
void
generic_device_init_address(device *me)
generic_device_init_address(device *me)
{
{
  static const char *(reg_property_names[]) = {
  static const char *(reg_property_names[]) = {
    "attach-addresses",
    "attach-addresses",
    "assigned-addresses",
    "assigned-addresses",
    "reg",
    "reg",
    "alternate-reg" ,
    "alternate-reg" ,
    NULL
    NULL
  };
  };
  const char **reg_property_name;
  const char **reg_property_name;
  int nr_valid_reg_properties = 0;
  int nr_valid_reg_properties = 0;
  for (reg_property_name = reg_property_names;
  for (reg_property_name = reg_property_names;
       *reg_property_name != NULL;
       *reg_property_name != NULL;
       reg_property_name++) {
       reg_property_name++) {
    if (device_find_property(me, *reg_property_name) != NULL) {
    if (device_find_property(me, *reg_property_name) != NULL) {
      reg_property_spec reg;
      reg_property_spec reg;
      int reg_entry;
      int reg_entry;
      for (reg_entry = 0;
      for (reg_entry = 0;
           device_find_reg_array_property(me, *reg_property_name, reg_entry,
           device_find_reg_array_property(me, *reg_property_name, reg_entry,
                                          &reg);
                                          &reg);
           reg_entry++) {
           reg_entry++) {
        unsigned_word attach_address;
        unsigned_word attach_address;
        int attach_space;
        int attach_space;
        unsigned attach_size;
        unsigned attach_size;
        if (!device_address_to_attach_address(device_parent(me),
        if (!device_address_to_attach_address(device_parent(me),
                                              &reg.address,
                                              &reg.address,
                                              &attach_space, &attach_address,
                                              &attach_space, &attach_address,
                                              me))
                                              me))
          continue;
          continue;
        if (!device_size_to_attach_size(device_parent(me),
        if (!device_size_to_attach_size(device_parent(me),
                                        &reg.size,
                                        &reg.size,
                                        &attach_size, me))
                                        &attach_size, me))
          continue;
          continue;
        device_attach_address(device_parent(me),
        device_attach_address(device_parent(me),
                              attach_callback,
                              attach_callback,
                              attach_space, attach_address, attach_size,
                              attach_space, attach_address, attach_size,
                              access_read_write_exec,
                              access_read_write_exec,
                              me);
                              me);
        nr_valid_reg_properties++;
        nr_valid_reg_properties++;
      }
      }
      /* if first option matches don't try for any others */
      /* if first option matches don't try for any others */
      if (reg_property_name == reg_property_names)
      if (reg_property_name == reg_property_names)
        break;
        break;
    }
    }
  }
  }
}
}
 
 
int
int
generic_device_unit_decode(device *bus,
generic_device_unit_decode(device *bus,
                           const char *unit,
                           const char *unit,
                           device_unit *phys)
                           device_unit *phys)
{
{
  memset(phys, 0, sizeof(device_unit));
  memset(phys, 0, sizeof(device_unit));
  if (unit == NULL)
  if (unit == NULL)
    return 0;
    return 0;
  else {
  else {
    int nr_cells = 0;
    int nr_cells = 0;
    const int max_nr_cells = device_nr_address_cells(bus);
    const int max_nr_cells = device_nr_address_cells(bus);
    while (1) {
    while (1) {
      char *end = NULL;
      char *end = NULL;
      unsigned long val;
      unsigned long val;
      val = strtoul(unit, &end, 0);
      val = strtoul(unit, &end, 0);
      /* parse error? */
      /* parse error? */
      if (unit == end)
      if (unit == end)
        return -1;
        return -1;
      /* two many cells? */
      /* two many cells? */
      if (nr_cells >= max_nr_cells)
      if (nr_cells >= max_nr_cells)
        return -1;
        return -1;
      /* save it */
      /* save it */
      phys->cells[nr_cells] = val;
      phys->cells[nr_cells] = val;
      nr_cells++;
      nr_cells++;
      unit = end;
      unit = end;
      /* more to follow? */
      /* more to follow? */
      if (isspace(*unit) || *unit == '\0')
      if (isspace(*unit) || *unit == '\0')
        break;
        break;
      if (*unit != ',')
      if (*unit != ',')
        return -1;
        return -1;
      unit++;
      unit++;
    }
    }
    if (nr_cells < max_nr_cells) {
    if (nr_cells < max_nr_cells) {
      /* shift everything to correct position */
      /* shift everything to correct position */
      int i;
      int i;
      for (i = 1; i <= nr_cells; i++)
      for (i = 1; i <= nr_cells; i++)
        phys->cells[max_nr_cells - i] = phys->cells[nr_cells - i];
        phys->cells[max_nr_cells - i] = phys->cells[nr_cells - i];
      for (i = 0; i < (max_nr_cells - nr_cells); i++)
      for (i = 0; i < (max_nr_cells - nr_cells); i++)
        phys->cells[i] = 0;
        phys->cells[i] = 0;
    }
    }
    phys->nr_cells = max_nr_cells;
    phys->nr_cells = max_nr_cells;
    return max_nr_cells;
    return max_nr_cells;
  }
  }
}
}
 
 
int
int
generic_device_unit_encode(device *bus,
generic_device_unit_encode(device *bus,
                           const device_unit *phys,
                           const device_unit *phys,
                           char *buf,
                           char *buf,
                           int sizeof_buf)
                           int sizeof_buf)
{
{
  int i;
  int i;
  int len;
  int len;
  char *pos = buf;
  char *pos = buf;
  /* skip leading zero's */
  /* skip leading zero's */
  for (i = 0; i < phys->nr_cells; i++) {
  for (i = 0; i < phys->nr_cells; i++) {
    if (phys->cells[i] != 0)
    if (phys->cells[i] != 0)
      break;
      break;
  }
  }
  /* don't output anything if empty */
  /* don't output anything if empty */
  if (phys->nr_cells == 0) {
  if (phys->nr_cells == 0) {
    strcpy(pos, "");
    strcpy(pos, "");
    len = 0;
    len = 0;
  }
  }
  else if (i == phys->nr_cells) {
  else if (i == phys->nr_cells) {
    /* all zero */
    /* all zero */
    strcpy(pos, "0");
    strcpy(pos, "0");
    len = 1;
    len = 1;
  }
  }
  else {
  else {
    for (; i < phys->nr_cells; i++) {
    for (; i < phys->nr_cells; i++) {
      if (pos != buf) {
      if (pos != buf) {
        strcat(pos, ",");
        strcat(pos, ",");
        pos = strchr(pos, '\0');
        pos = strchr(pos, '\0');
      }
      }
      if (phys->cells[i] < 10)
      if (phys->cells[i] < 10)
        sprintf(pos, "%ld", (unsigned long)phys->cells[i]);
        sprintf(pos, "%ld", (unsigned long)phys->cells[i]);
      else
      else
        sprintf(pos, "0x%lx", (unsigned long)phys->cells[i]);
        sprintf(pos, "0x%lx", (unsigned long)phys->cells[i]);
      pos = strchr(pos, '\0');
      pos = strchr(pos, '\0');
    }
    }
    len = pos - buf;
    len = pos - buf;
  }
  }
  if (len >= sizeof_buf)
  if (len >= sizeof_buf)
    error("generic_unit_encode - buffer overflow\n");
    error("generic_unit_encode - buffer overflow\n");
  return len;
  return len;
}
}
 
 
int
int
generic_device_address_to_attach_address(device *me,
generic_device_address_to_attach_address(device *me,
                                         const device_unit *address,
                                         const device_unit *address,
                                         int *attach_space,
                                         int *attach_space,
                                         unsigned_word *attach_address,
                                         unsigned_word *attach_address,
                                         device *client)
                                         device *client)
{
{
  int i;
  int i;
  for (i = 0; i < address->nr_cells - 2; i++) {
  for (i = 0; i < address->nr_cells - 2; i++) {
    if (address->cells[i] != 0)
    if (address->cells[i] != 0)
      device_error(me, "Only 32bit addresses supported");
      device_error(me, "Only 32bit addresses supported");
  }
  }
  if (address->nr_cells >= 2)
  if (address->nr_cells >= 2)
    *attach_space = address->cells[address->nr_cells - 2];
    *attach_space = address->cells[address->nr_cells - 2];
  else
  else
    *attach_space = 0;
    *attach_space = 0;
  *attach_address = address->cells[address->nr_cells - 1];
  *attach_address = address->cells[address->nr_cells - 1];
  return 1;
  return 1;
}
}
 
 
int
int
generic_device_size_to_attach_size(device *me,
generic_device_size_to_attach_size(device *me,
                                   const device_unit *size,
                                   const device_unit *size,
                                   unsigned *nr_bytes,
                                   unsigned *nr_bytes,
                                   device *client)
                                   device *client)
{
{
  int i;
  int i;
  for (i = 0; i < size->nr_cells - 1; i++) {
  for (i = 0; i < size->nr_cells - 1; i++) {
    if (size->cells[i] != 0)
    if (size->cells[i] != 0)
      device_error(me, "Only 32bit sizes supported");
      device_error(me, "Only 32bit sizes supported");
  }
  }
  *nr_bytes = size->cells[0];
  *nr_bytes = size->cells[0];
  return *nr_bytes;
  return *nr_bytes;
}
}
 
 
 
 
/* ignore/passthrough versions of each function */
/* ignore/passthrough versions of each function */
 
 
void
void
passthrough_device_address_attach(device *me,
passthrough_device_address_attach(device *me,
                                  attach_type attach,
                                  attach_type attach,
                                  int space,
                                  int space,
                                  unsigned_word addr,
                                  unsigned_word addr,
                                  unsigned nr_bytes,
                                  unsigned nr_bytes,
                                  access_type access,
                                  access_type access,
                                  device *client) /*callback/default*/
                                  device *client) /*callback/default*/
{
{
  device_attach_address(device_parent(me), attach,
  device_attach_address(device_parent(me), attach,
                        space, addr, nr_bytes,
                        space, addr, nr_bytes,
                        access,
                        access,
                        client);
                        client);
}
}
 
 
void
void
passthrough_device_address_detach(device *me,
passthrough_device_address_detach(device *me,
                                  attach_type attach,
                                  attach_type attach,
                                  int space,
                                  int space,
                                  unsigned_word addr,
                                  unsigned_word addr,
                                  unsigned nr_bytes,
                                  unsigned nr_bytes,
                                  access_type access,
                                  access_type access,
                                  device *client) /*callback/default*/
                                  device *client) /*callback/default*/
{
{
  device_detach_address(device_parent(me), attach,
  device_detach_address(device_parent(me), attach,
                        space, addr, nr_bytes, access,
                        space, addr, nr_bytes, access,
                        client);
                        client);
}
}
 
 
unsigned
unsigned
passthrough_device_dma_read_buffer(device *me,
passthrough_device_dma_read_buffer(device *me,
                                   void *dest,
                                   void *dest,
                                   int space,
                                   int space,
                                   unsigned_word addr,
                                   unsigned_word addr,
                                   unsigned nr_bytes)
                                   unsigned nr_bytes)
{
{
  return device_dma_read_buffer(device_parent(me), dest,
  return device_dma_read_buffer(device_parent(me), dest,
                                space, addr, nr_bytes);
                                space, addr, nr_bytes);
}
}
 
 
unsigned
unsigned
passthrough_device_dma_write_buffer(device *me,
passthrough_device_dma_write_buffer(device *me,
                             const void *source,
                             const void *source,
                             int space,
                             int space,
                             unsigned_word addr,
                             unsigned_word addr,
                             unsigned nr_bytes,
                             unsigned nr_bytes,
                             int violate_read_only_section)
                             int violate_read_only_section)
{
{
  return device_dma_write_buffer(device_parent(me), source,
  return device_dma_write_buffer(device_parent(me), source,
                                 space, addr,
                                 space, addr,
                                 nr_bytes,
                                 nr_bytes,
                                 violate_read_only_section);
                                 violate_read_only_section);
}
}
 
 
int
int
ignore_device_unit_decode(device *me,
ignore_device_unit_decode(device *me,
                          const char *unit,
                          const char *unit,
                          device_unit *phys)
                          device_unit *phys)
{
{
  memset(phys, 0, sizeof(device_unit));
  memset(phys, 0, sizeof(device_unit));
  return 0;
  return 0;
}
}
 
 
 
 
static const device_callbacks passthrough_callbacks = {
static const device_callbacks passthrough_callbacks = {
  { NULL, }, /* init */
  { NULL, }, /* init */
  { passthrough_device_address_attach,
  { passthrough_device_address_attach,
    passthrough_device_address_detach, },
    passthrough_device_address_detach, },
  { NULL, }, /* IO */
  { NULL, }, /* IO */
  { passthrough_device_dma_read_buffer, passthrough_device_dma_write_buffer, },
  { passthrough_device_dma_read_buffer, passthrough_device_dma_write_buffer, },
  { NULL, }, /* interrupt */
  { NULL, }, /* interrupt */
  { generic_device_unit_decode,
  { generic_device_unit_decode,
    generic_device_unit_encode, },
    generic_device_unit_encode, },
};
};
 
 
 
 
static const device_descriptor ob_device_table[] = {
static const device_descriptor ob_device_table[] = {
  /* standard OpenBoot devices */
  /* standard OpenBoot devices */
  { "aliases", NULL, &passthrough_callbacks },
  { "aliases", NULL, &passthrough_callbacks },
  { "options", NULL, &passthrough_callbacks },
  { "options", NULL, &passthrough_callbacks },
  { "chosen", NULL, &passthrough_callbacks },
  { "chosen", NULL, &passthrough_callbacks },
  { "packages", NULL, &passthrough_callbacks },
  { "packages", NULL, &passthrough_callbacks },
  { "cpus", NULL, &passthrough_callbacks },
  { "cpus", NULL, &passthrough_callbacks },
  { "openprom", NULL, &passthrough_callbacks },
  { "openprom", NULL, &passthrough_callbacks },
  { "init", NULL, &passthrough_callbacks },
  { "init", NULL, &passthrough_callbacks },
  { NULL },
  { NULL },
};
};
 
 
const device_descriptor *const device_table[] = {
const device_descriptor *const device_table[] = {
  ob_device_table,
  ob_device_table,
#include "hw.c"
#include "hw.c"
  NULL,
  NULL,
};
};
 
 
 
 
#endif /* _DEVICE_TABLE_C_ */
#endif /* _DEVICE_TABLE_C_ */
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.