source: rtems/tools/cpu/nios2/bridges.c @ 5f5f681

4.104.11
Last change on this file since 5f5f681 was 5f5f681, checked in by Ralf Corsepius <ralf.corsepius@…>, on Dec 10, 2009 at 7:20:06 AM

Whitespace removal.

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