source: rtems/tools/cpu/nios2/bridges.c @ c499856

4.115
Last change on this file since c499856 was c499856, checked in by Chris Johns <chrisj@…>, on 03/20/14 at 21:10:47

Change all references of rtems.com to rtems.org.

  • Property mode set to 100644
File size: 3.3 KB
Line 
1/*
2 *  Copyright (c) 2006 Kolja Waschk rtemsdev/ixo.de
3 *
4 *  The license and distribution terms for this file may be
5 *  found in the file LICENSE in this distribution or at
6 *  http://www.rtems.org/license/LICENSE.
7 */
8
9/********************************************************/
10/* Find bus bridges */
11
12/* This part of the program builds a list with pairs of bus
13   master port names (each is "device name/master port name").
14   It is then possible to find if a given master is actually
15   available under a different master port name through bridges.
16 */
17
18/* Typical example with external SRAM that is slave of
19   tristate_bridge_0/tristate_master, and
20   tristate_bridge_0 itself is slave of cpu0/data_master, the
21   bridge information would be stored as this bus_bridge_pair:
22      mastered_by = "cpu0/data_master" and
23      bridges_to = "tristate_bridge_0/tristate_master".
24   That allows to deduce that SRAM is actually mastered by
25   cpu0/data_master. If there were any address or bus width
26   translations, it should be noted in the bridges list... For
27   now we simply assume that bridges never translate anything.
28 */
29
30#include <string.h>
31#include <stdlib.h>
32
33#include "ptf.h"
34#include "bridges.h"
35
36int is_bridged(
37  char *cpu_master,
38  char *dev_master,
39  bus_bridge_pair *bridges)
40{
41  char *curr_master;
42  bus_bridge_pair *bbp;
43
44  if(strcmp(cpu_master, dev_master) == 0) return 1; /* cpu directly masters dev */
45
46  for(bbp = bridges; bbp != NULL; bbp=bbp->next)
47  {
48    if(strcmp(cpu_master, bbp->mastered_by) == 0 &&
49       is_bridged(bbp->bridges_to, dev_master, bridges))
50    {
51      return 1; /* cpu masters dev via bridge */
52    }
53  };
54
55  return 0;
56}
57
58void add_bridge_master(struct ptf_item *pi, void *arg)
59{
60    struct { char *bt; bus_bridge_pair **bridges; } *binfo = arg;
61    bus_bridge_pair *new_pair;
62
63    if(binfo->bridges == 0) return;
64
65    new_pair = (bus_bridge_pair *)malloc(sizeof(bus_bridge_pair));
66    if(new_pair == NULL) return;
67
68    new_pair->bridges_to = binfo->bt;
69    new_pair->mastered_by = pi->item[pi->level]->value;
70    new_pair->next = *(binfo->bridges);
71    *(binfo->bridges) = new_pair;
72}
73
74void add_bridge_dest(struct ptf_item *pi, void *arg)
75{
76    struct ptf maby_section = { section, "MASTERED_BY", 0, 0, 0 };
77    struct ptf_item maby = { 1, &maby_section };
78
79    char *bridge_name = pi->item[1]->value;
80    char *bridge_dest = pi->item[pi->level]->value;
81    struct { char *bt; bus_bridge_pair **bridges; } binfo;
82
83    binfo.bridges = arg;
84    binfo.bt = (char*)malloc(strlen(bridge_name)+strlen(bridge_dest) + 2);
85    strcpy(binfo.bt, bridge_name);
86    strcat(binfo.bt, "/");
87    strcat(binfo.bt, bridge_dest);
88
89    ptf_match(pi->item[pi->level-1]->sub, &maby, add_bridge_master, &binfo);
90
91    /* binfo.bt is NOT freed here */
92}
93
94bus_bridge_pair *find_bridges(struct ptf *p)
95{
96    bus_bridge_pair *bridges = 0;
97
98    struct ptf system     = { section, "SYSTEM", 0, 0, 0 };
99    struct ptf module     = { section, "MODULE", 0, 0, 0 };
100    struct ptf slave      = { section, "SLAVE",  0, 0, 0 };
101    struct ptf syb        = { section, "SYSTEM_BUILDER_INFO", 0, 0, 0 };
102    struct ptf to         = { item,    "Bridges_To", 0, 0, 0 };
103    struct ptf_item brdg  = { 5, &system, &module, &slave, &syb, &to };
104
105    ptf_match(p, &brdg, add_bridge_dest, &bridges);
106
107    return bridges;
108}
109
110
111
112
Note: See TracBrowser for help on using the repository browser.