1%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2% Copyright (c) 2009, 2011, 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, Universitaetstrasse 6, CH-8092 Zurich. Attn: Systems Group. 8%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 9 10bridge_programming(Plan, NrElements) :- 11 get_devices(Devices), 12 convert_devices(Devices,DeviceElements), 13 get_bridges(Bridges), 14 convert_bridges(Bridges,BridgeElements), 15 append(DeviceElements, BridgeElements, Plan), 16 length(Plan, NrElements). 17 18% note: device with addr(-1,-1,-1) will be removed because it has no 19% regions -> nuet. The clean way would be to really remove it which leads 20% to other prolog problems... (two solutions). 21convert_devices([], []). 22convert_devices([buselement(device, Addr ,Regions)|T], L) :- 23 subtract(Regions,[nuet],RegionsClean), 24 ( foreach(R,RegionsClean), 25 foreach(El,Elements), 26 param(Addr) 27 do 28 region(BAR,Base,Bits,Prefetch,Sz,MulL) = R, 29 ( MulL = b -> 30 Mul is 1 31 ; 32 MulL = k -> 33 Mul is 1024 34 ; 35 Mul is 1024 * 1024 36 ), 37 Size is Sz * Mul, 38 High is Base + Size, 39 El = buselement(device, Addr, BAR, Base, High, Size, mem, Prefetch, pcie, Bits), 40 assert(bar(Addr,BAR,_,Size,_,_,_)) 41 ), 42 convert_devices(T, L2), 43 append(L2, Elements, L). 44 45convert_bridges([], []). 46convert_bridges([buselement(bridge, _, _)|T], L) :- 47 convert_bridges(T, L). 48convert_bridges([buselement(bridge, Addr, S, m(B1,H1), p(B2, H2),_)|T], L) :- 49 ( H1 >= B1 -> 50 S1 is H1 - B1, 51 Bridge1 = [buselement(bridge, Addr, S, B1, H1, S1, mem, nonprefetchable, pcie, 0)]; 52 Bridge1 = [] 53 ), 54 ( H2 >= B2 -> 55 S2 is H2 - B2, 56 Bridge2 = [buselement(bridge, Addr, S, B2, H2, S2, mem, prefetchable, pcie, 0)]; 57 Bridge2 = [] 58 ), 59 append(Bridge1,Bridge2,BridgeList), 60 convert_bridges(T, L2), 61 append(L2, BridgeList, L). 62 63 64 65%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 66% tools 67%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 68 69 70base(buselement(_,_,_,Base,_,_,_,_,_,_),Base). 71high(buselement(_,_,_,_,High,_,_,_,_,_),High). 72size(buselement(_,_,_,_,_,Size,_,_,_,_),Size). 73 74 75