db892f443e9aea302571a7b1a7327a4b14afd778
[barrelfish] / usr / skb / programs / decodingNetQueries.pl
1 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2 % Copyright (c) 2017, ETH Zurich.
3 % All rights reserved.
4 %
5 % This file is distributed under the terms in the attached LICENSE file.
6 % If you do not find this file, copies can be found by writing to:
7 % ETH Zurich D-INFK, Universitaetsstrasse 6, CH-8092 Zurich.
8 % Attn: Systems Group.
9 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
10
11 :- module(decodingNetQueries).
12 :- export findTargetRegion/2.
13 :- export findOriginRegion/2.
14 :- export findDeviceRegion/3.
15 :- export findMemoryRegion/3.
16 :- export findSharedMemoryRegion/3.
17 :- export findDeviceId/3.
18 :- export findInterruptLine/3.
19
20 :- use_module(decodingNet).
21
22
23 %%%%%%%%%%%%%%%%%%%%%%%
24 %% Helper predicates %%
25 %%%%%%%%%%%%%%%%%%%%%%%
26 resolveToRegion(SrcName,DestName,SrcRegion,DestRegion) :-
27     resolve(SrcName,DestName),
28     toRegion(SrcName,SrcRegion),
29     toRegion(DestName,DestRegion).
30
31
32 %%%%%%%%%%%%%
33 %% Queries %%
34 %%%%%%%%%%%%%
35 findTargetRegion(NodeId,Result) :-
36     SrcName = name(NodeId,_),
37     resolveToRegion(SrcName,_,SrcRegion,DestRegion),
38     Result = (SrcRegion,DestRegion).
39
40 findOriginRegion(NodeId,Result) :-
41     DestName = name(NodeId,_),
42     resolveToRegion(_,DestName,SrcRegion,DestRegion),
43     Result = (SrcRegion,DestRegion).
44
45 %% Address space queries
46 findDeviceRegion(NodeId,DeviceId,Result) :-
47     SrcName = name(NodeId,_),
48     DestName = name(DeviceId,_),
49     net(DeviceId,node(device,_,_)),
50     resolveToRegion(SrcName,DestName,SrcRegion,DestRegion),
51     Result = (SrcRegion,DestRegion).
52
53 findMemoryRegion(NodeId,MemoryId,Result) :-
54     SrcName = name(NodeId,_),
55     DestName = name(MemoryId,_),
56     net(MemoryId,node(memory,_,_)),
57     resolveToRegion(SrcName,DestName,SrcRegion,DestRegion),
58     Result = (SrcRegion,DestRegion).
59
60 findSharedMemoryRegion(NodeId,DeviceId,Result) :-
61     NodeName = name(NodeId,_),
62     DeviceName = name(DeviceId,_),
63     SharedName = name(SharedId,_),
64     net(SharedId,node(memory,_,_)),
65     resolve(NodeName,SharedName),
66     resolve(DeviceName,SharedName),
67     toRegion(NodeName,NodeRegion),
68     toRegion(SharedName,SharedRegion),
69     toRegion(DeviceName,DeviceRegion),
70     Result = (NodeRegion,DeviceRegion,SharedRegion).
71
72 findDeviceId(NodeId,Addr,Result) :-
73     SrcName = name(NodeId,Addr),
74     resolve(SrcName,name(DeviceId,_)),
75     Result = DeviceId.
76
77 %% Interrupt queries
78 findInterruptLine(NodeId,DeviceId,Result) :-
79     SrcName = name(DeviceId,_),
80     DestName = name(NodeId,_),
81     resolveToRegion(SrcName,DestName,SrcRegion,DestRegion),
82     Result = (SrcRegion,DestRegion).