Skip to content

Commit

Permalink
ExpandedBond, some bond refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
wanda-phi committed Aug 3, 2024
1 parent 2451047 commit 769fd16
Show file tree
Hide file tree
Showing 28 changed files with 1,010 additions and 188 deletions.
3 changes: 2 additions & 1 deletion prjcombine_ise_hammer/src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use prjcombine_toolchain::Toolchain;
use prjcombine_virtex_bitstream::{parse, KeyData, KeyDataAes, KeyDataDes, KeySeq};
use prjcombine_virtex_bitstream::{BitPos, BitTile, Bitstream, BitstreamGeom};
use prjcombine_xdl::{run_bitgen, Design, Instance, Net, NetPin, NetPip, NetType, Pcf, Placement};
use prjcombine_xilinx_geom::{Bond, Device, ExpandedDevice, GeomDb};
use prjcombine_xilinx_geom::{Bond, Device, ExpandedBond, ExpandedDevice, GeomDb};
use rand::prelude::*;
use std::collections::{hash_map, HashMap};
use std::fmt::{Debug, Write};
Expand All @@ -22,6 +22,7 @@ pub struct IseBackend<'a> {
pub bs_geom: &'a BitstreamGeom,
pub egrid: &'a ExpandedGrid<'a>,
pub edev: &'a ExpandedDevice<'a>,
pub ebonds: &'a HashMap<String, ExpandedBond<'a>>,
}

impl<'a> std::fmt::Debug for IseBackend<'a> {
Expand Down
126 changes: 56 additions & 70 deletions prjcombine_ise_hammer/src/fgen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ use prjcombine_int::{
};
use prjcombine_virtex2::expanded::IoPadKind;
use prjcombine_virtex_bitstream::{BitTile, Reg};
use prjcombine_xilinx_geom::{Bond, ExpandedDevice};
use prjcombine_xilinx_geom::{ExpandedBond, ExpandedDevice};
use rand::seq::SliceRandom;
use rand::thread_rng;
use std::collections::{BTreeSet, HashMap, HashSet};
use std::collections::{BTreeSet, HashMap};
use unnamed_entity::EntityId;

use prjcombine_hammer::{BatchValue, Fuzzer, FuzzerGen, FuzzerValue};
Expand Down Expand Up @@ -589,42 +589,6 @@ fn resolve_intf_delay<'a>(
))
}

pub fn get_bonded_ios_v2_pkg(
backend: &IseBackend,
pkg: &str,
) -> HashSet<prjcombine_virtex2::grid::IoCoord> {
let bond_id = backend
.device
.bonds
.values()
.find(|bond| bond.name == *pkg)
.unwrap()
.bond;
let Bond::Virtex2(ref bond) = backend.db.bonds[bond_id] else {
unreachable!()
};
bond.pins
.values()
.filter_map(|pin| {
if let prjcombine_virtex2::bond::BondPin::Io(io) = pin {
Some(*io)
} else {
None
}
})
.collect()
}

fn get_bonded_ios_v2(
backend: &IseBackend,
fuzzer: &Fuzzer<IseBackend>,
) -> HashSet<prjcombine_virtex2::grid::IoCoord> {
let FuzzerValue::Base(Value::String(pkg)) = &fuzzer.kv[&Key::Package] else {
unreachable!()
};
get_bonded_ios_v2_pkg(backend, pkg)
}

#[derive(Debug, Clone)]
pub enum TileKV<'a> {
Nop,
Expand Down Expand Up @@ -1777,35 +1741,45 @@ impl<'a> BelKV {
Key::BelMutex((loc.0, loc.1, loc.2, loc.3, bel), name.clone()),
val,
),
BelKV::IsVref => match backend.edev {
ExpandedDevice::Xc4k(_) => todo!(),
ExpandedDevice::Xc5200(_) => todo!(),
ExpandedDevice::Virtex(_) => todo!(),
ExpandedDevice::Virtex2(edev) => {
let crd = prjcombine_virtex2::grid::IoCoord {
col: loc.1,
row: loc.2,
iob: prjcombine_virtex2::grid::TileIobId::from_idx(bel.to_idx()),
};
if !edev.grid.vref.contains(&crd) {
return None;
}
let bonded_ios = get_bonded_ios_v2(backend, &fuzzer);
if !bonded_ios.contains(&crd) {
return None;
BelKV::IsVref => {
let FuzzerValue::Base(Value::String(pkg)) = &fuzzer.kv[&Key::Package] else {
unreachable!()
};
match &backend.ebonds[pkg] {
ExpandedBond::Xc4k(_) => todo!(),
ExpandedBond::Xc5200(_) => todo!(),
ExpandedBond::Virtex(_) => todo!(),
ExpandedBond::Virtex2(ebond) => {
let crd = prjcombine_virtex2::grid::IoCoord {
col: loc.1,
row: loc.2,
iob: prjcombine_virtex2::grid::TileIobId::from_idx(bel.to_idx()),
};
if !ebond.bond.vref.contains(&crd) {
return None;
}
if !ebond.ios.contains_key(&crd) {
return None;
}
fuzzer
}
fuzzer
ExpandedBond::Spartan6(_) => todo!(),
ExpandedBond::Virtex4(_) => todo!(),
ExpandedBond::Ultrascale(_) => todo!(),
ExpandedBond::Versal(_) => todo!(),
}
ExpandedDevice::Spartan6(_) => todo!(),
ExpandedDevice::Virtex4(_) => todo!(),
ExpandedDevice::Ultrascale(_) => todo!(),
ExpandedDevice::Versal(_) => todo!(),
},
}
BelKV::IsVr => match backend.edev {
ExpandedDevice::Xc4k(_) => todo!(),
ExpandedDevice::Xc5200(_) => todo!(),
ExpandedDevice::Virtex(_) => todo!(),
ExpandedDevice::Virtex2(edev) => {
let FuzzerValue::Base(Value::String(pkg)) = &fuzzer.kv[&Key::Package] else {
unreachable!()
};
let ExpandedBond::Virtex2(ref ebond) = backend.ebonds[pkg] else {
unreachable!()
};
let crd = prjcombine_virtex2::grid::IoCoord {
col: loc.1,
row: loc.2,
Expand Down Expand Up @@ -1841,8 +1815,7 @@ impl<'a> BelKV {
if !is_vr {
return None;
}
let bonded_ios = get_bonded_ios_v2(backend, &fuzzer);
if !bonded_ios.contains(&crd) {
if !ebond.ios.contains_key(&crd) {
return None;
}
fuzzer
Expand All @@ -1860,21 +1833,28 @@ impl<'a> BelKV {
ExpandedDevice::Xc5200(_) => todo!(),
ExpandedDevice::Virtex(_) => todo!(),
ExpandedDevice::Virtex2(edev) => {
let bonded_ios = get_bonded_ios_v2(backend, &fuzzer);
let FuzzerValue::Base(Value::String(pkg)) = &fuzzer.kv[&Key::Package]
else {
unreachable!()
};
let ExpandedBond::Virtex2(ref ebond) = backend.ebonds[pkg] else {
unreachable!()
};
let crd = prjcombine_virtex2::grid::IoCoord {
col: loc.1,
row: loc.2,
iob: prjcombine_virtex2::grid::TileIobId::from_idx(bel.to_idx()),
};
let orig_io = edev.get_io(crd);
for &io in &edev.bonded_ios {
let io_info = edev.get_io(io);
if io != crd
&& orig_io.bank == edev.get_io(io).bank
&& edev.get_io(io).pad_kind != IoPadKind::Clk
&& orig_io.bank == io_info.bank
&& io_info.pad_kind != IoPadKind::Clk
&& (!is_diff
|| edev.get_io(io).diff
|| io_info.diff
!= prjcombine_virtex2::expanded::IoDiffKind::None)
&& bonded_ios.contains(&io)
&& ebond.ios.contains_key(&io)
{
let node = backend
.egrid
Expand All @@ -1888,7 +1868,7 @@ impl<'a> BelKV {
fuzzer = fuzzer.base(
Key::SiteMode(site),
if is_diff {
match edev.get_io(io).diff {
match io_info.diff {
prjcombine_virtex2::expanded::IoDiffKind::P(_) => {
if edev.grid.kind.is_spartan3a() {
"DIFFMI_NDT"
Expand Down Expand Up @@ -1958,7 +1938,13 @@ impl<'a> BelKV {
ExpandedDevice::Xc5200(_) => todo!(),
ExpandedDevice::Virtex(_) => todo!(),
ExpandedDevice::Virtex2(edev) => {
let bonded_ios = get_bonded_ios_v2(backend, &fuzzer);
let FuzzerValue::Base(Value::String(pkg)) = &fuzzer.kv[&Key::Package]
else {
unreachable!()
};
let ExpandedBond::Virtex2(ref ebond) = backend.ebonds[pkg] else {
unreachable!()
};
let crd = prjcombine_virtex2::grid::IoCoord {
col: loc.1,
row: loc.2,
Expand All @@ -1985,7 +1971,7 @@ impl<'a> BelKV {
}
}
let io_info = edev.get_io(io);
if !bonded_ios.contains(&io)
if !ebond.ios.contains_key(&io)
|| io_info.bank != bank
|| io_info.pad_kind != IoPadKind::Io
{
Expand Down
7 changes: 3 additions & 4 deletions prjcombine_ise_hammer/src/io/virtex2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,9 @@ fn has_any_vref<'a>(
};
for pin in bond.pins.values() {
if let prjcombine_virtex2::bond::BondPin::Io(io) = pin {
bonded_ios.insert(io, &devbond.name[..]);
if bond.vref.contains(io) {
bonded_ios.insert(io, &devbond.name[..]);
}
}
}
}
Expand All @@ -311,9 +313,6 @@ fn has_any_vref<'a>(
row,
iob: TileIobId::from_idx(ioi_bel.to_idx()),
};
if !edev.grid.vref.contains(&crd) {
continue;
}
if let Some(&pkg) = bonded_ios.get(&crd) {
return Some(pkg);
}
Expand Down
6 changes: 6 additions & 0 deletions prjcombine_ise_hammer/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ fn main() -> Result<(), Box<dyn Error>> {
}
println!("part {name}", name = part.name);
let gedev = db.expand_grid(part);
let mut ebonds = HashMap::new();
for devbond in part.bonds.values() {
let bond = &db.bonds[devbond.bond];
ebonds.insert(devbond.name.clone(), bond.expand());
}
let backend = IseBackend {
debug: args.debug,
tc: &tc,
Expand All @@ -80,6 +85,7 @@ fn main() -> Result<(), Box<dyn Error>> {
bs_geom: gedev.bs_geom(),
egrid: gedev.egrid(),
edev: &gedev,
ebonds: &ebonds,
};
let mut hammer = Session::new(&backend);
hammer.debug = args.debug;
Expand Down
14 changes: 8 additions & 6 deletions prjcombine_ise_hammer/src/misc/virtex2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use prjcombine_virtex2::{
grid::GridKind,
};
use prjcombine_virtex_bitstream::{BitTile, Reg};
use prjcombine_xilinx_geom::ExpandedDevice;
use prjcombine_xilinx_geom::{ExpandedBond, ExpandedDevice};
use unnamed_entity::EntityId;

use crate::{
Expand All @@ -18,7 +18,7 @@ use crate::{
concat_bitvec, xlat_bit_wide, xlat_bitvec, xlat_bool, xlat_bool_default, xlat_enum,
xlat_enum_ocd, xlat_item_tile, CollectorCtx, Diff, OcdMode,
},
fgen::{get_bonded_ios_v2_pkg, TileBits, TileFuzzKV, TileFuzzerGen, TileKV},
fgen::{TileBits, TileFuzzKV, TileFuzzerGen, TileKV},
fuzz::FuzzCtx,
fuzz_enum, fuzz_inv, fuzz_multi, fuzz_one,
io::virtex2::{get_iostds, DciKind, DiffKind},
Expand Down Expand Up @@ -259,7 +259,9 @@ pub fn add_fuzzers<'a>(
bdata.pins.len()
})
.unwrap();
let bonded_io = get_bonded_ios_v2_pkg(backend, &package.name);
let ExpandedBond::Virtex2(ref ebond) = backend.ebonds[&package.name] else {
unreachable!()
};
if !edev.grid.kind.is_spartan3ea() {
for (tile_name, bel, bank) in [
(ul, 0, 7),
Expand Down Expand Up @@ -293,7 +295,7 @@ pub fn add_fuzzers<'a>(
let other_bank = if bank == 4 { 5 } else { 4 };
let mut io_vr = None;
if let Some(&(vrp, vrn)) = edev.grid.dci_io.get(&bank) {
if bonded_io.contains(&vrp) && bonded_io.contains(&vrn) {
if ebond.ios.contains_key(&vrp) && ebond.ios.contains_key(&vrn) {
io_vr = Some((vrp, vrn));
}
}
Expand All @@ -313,7 +315,7 @@ pub fn add_fuzzers<'a>(
btiles.push(edev.btile_btterm(io.col, io.row));
}
}
if bonded_io.contains(&io)
if ebond.ios.contains_key(&io)
&& matches!(ioinfo.diff, IoDiffKind::P(_))
&& ioinfo.pad_kind == IoPadKind::Io
&& io != io_vrp
Expand Down Expand Up @@ -776,7 +778,7 @@ pub fn add_fuzzers<'a>(
let mut ios = vec![];
for &io in edev.bonded_ios.iter().rev() {
let ioinfo = edev.get_io(io);
if bonded_io.contains(&io)
if ebond.ios.contains_key(&io)
&& matches!(ioinfo.diff, IoDiffKind::P(_))
&& ioinfo.pad_kind == IoPadKind::Io
&& ioinfo.bank == bank
Expand Down
35 changes: 31 additions & 4 deletions prjcombine_spartan6/src/bond.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use serde::{Deserialize, Serialize};
use std::collections::BTreeMap;
use std::collections::{BTreeMap, BTreeSet};

use crate::grid::IoCoord;

#[derive(Clone, Copy, Debug, Eq, PartialEq, Serialize, Deserialize)]
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Serialize, Deserialize)]
pub enum CfgPin {
Tck,
Tdi,
Expand All @@ -15,7 +15,7 @@ pub enum CfgPin {
Suspend,
}

#[derive(Copy, Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Serialize, Deserialize)]
pub enum GtPin {
TxP(u8),
TxN(u8),
Expand All @@ -31,7 +31,7 @@ pub enum GtPin {
AVttRCal,
}

#[derive(Copy, Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Serialize, Deserialize)]
pub enum BondPin {
Io(IoCoord),
Nc,
Expand All @@ -51,4 +51,31 @@ pub struct Bond {
pub pins: BTreeMap<String, BondPin>,
// device bank -> pkg bank
pub io_banks: BTreeMap<u32, u32>,
pub vref: BTreeSet<IoCoord>,
}

#[derive(Clone, Debug, Eq, PartialEq)]
pub struct ExpandedBond<'a> {
pub bond: &'a Bond,
pub ios: BTreeMap<IoCoord, String>,
pub gts: BTreeMap<(u32, GtPin), String>,
}

impl Bond {
pub fn expand(&self) -> ExpandedBond {
let mut ios = BTreeMap::new();
let mut gts = BTreeMap::new();
for (name, pad) in &self.pins {
match *pad {
BondPin::Io(io) => {
ios.insert(io, name.clone());
}
BondPin::Gt(bank, gtpin) => {
gts.insert((bank, gtpin), name.clone());
}
_ => (),
}
}
ExpandedBond { bond: self, ios, gts }
}
}
3 changes: 1 addition & 2 deletions prjcombine_spartan6/src/grid.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use prjcombine_int::grid::{ColId, RowId};
use serde::{Deserialize, Serialize};
use std::collections::{BTreeMap, BTreeSet};
use std::collections::BTreeMap;
use unnamed_entity::{entity_id, EntityId, EntityIds, EntityVec};

entity_id! {
Expand All @@ -22,7 +22,6 @@ pub struct Grid {
pub row_mcb_split: Option<RowId>,
pub gts: Gts,
pub mcbs: Vec<Mcb>,
pub vref: BTreeSet<IoCoord>,
pub cfg_io: BTreeMap<SharedCfgPin, IoCoord>,
pub has_encrypt: bool,
}
Expand Down
Loading

0 comments on commit 769fd16

Please sign in to comment.