aboutsummaryrefslogtreecommitdiffstats
path: root/ice40/arch.cc
diff options
context:
space:
mode:
authorwhitequark <whitequark@whitequark.org>2020-06-25 15:11:47 +0000
committerwhitequark <whitequark@whitequark.org>2020-06-26 08:36:07 +0000
commit89e0cc8078ecbb57ca450cc6c8a40f6b634b8c9c (patch)
treee34454964eff6bf4d14f40b4f1c271cadea6d1fa /ice40/arch.cc
parentdc209f6344545196de8bf4de7abff2fcbd55732e (diff)
downloadnextpnr-89e0cc8078ecbb57ca450cc6c8a40f6b634b8c9c.tar.gz
nextpnr-89e0cc8078ecbb57ca450cc6c8a40f6b634b8c9c.tar.bz2
nextpnr-89e0cc8078ecbb57ca450cc6c8a40f6b634b8c9c.zip
Simplify and improve chipdb embedding/loading.
Diffstat (limited to 'ice40/arch.cc')
-rw-r--r--ice40/arch.cc106
1 files changed, 35 insertions, 71 deletions
diff --git a/ice40/arch.cc b/ice40/arch.cc
index 545066ce..cdef91df 100644
--- a/ice40/arch.cc
+++ b/ice40/arch.cc
@@ -19,12 +19,12 @@
*/
#include <algorithm>
-#include <boost/iostreams/device/mapped_file.hpp>
#include <cmath>
#include "cells.h"
#include "gfx.h"
#include "log.h"
#include "nextpnr.h"
+#include "embed.h"
#include "placer1.h"
#include "placer_heap.h"
#include "router1.h"
@@ -44,75 +44,51 @@ void IdString::initialize_arch(const BaseCtx *ctx)
// -----------------------------------------------------------------------
-static const ChipInfoPOD *get_chip_info(const RelPtr<ChipInfoPOD> *ptr) { return ptr->get(); }
-
-#if defined(WIN32)
-void load_chipdb();
-#endif
-
-#if defined(EXTERNAL_CHIPDB_ROOT)
-const char *chipdb_blob_384 = nullptr;
-const char *chipdb_blob_1k = nullptr;
-const char *chipdb_blob_5k = nullptr;
-const char *chipdb_blob_u4k = nullptr;
-const char *chipdb_blob_8k = nullptr;
+static const ChipInfoPOD *get_chip_info(ArchArgs::ArchArgsTypes chip) {
+ std::string chipdb;
+ if (chip == ArchArgs::LP384) {
+ chipdb = "ice40/chipdb-384.bin";
+ } else if (chip == ArchArgs::LP1K || chip == ArchArgs::HX1K) {
+ chipdb = "ice40/chipdb-1k.bin";
+ } else if (chip == ArchArgs::U4K) {
+ chipdb = "ice40/chipdb-u4k.bin";
+ } else if (chip == ArchArgs::UP5K) {
+ chipdb = "ice40/chipdb-5k.bin";
+ } else if (chip == ArchArgs::LP8K || chip == ArchArgs::HX8K) {
+ chipdb = "ice40/chipdb-8k.bin";
+ } else {
+ log_error("Unknown chip\n");
+ }
-boost::iostreams::mapped_file blob_files[5];
+ auto ptr = reinterpret_cast<const RelPtr<ChipInfoPOD> *>(get_chipdb(chipdb));
+ if (ptr == nullptr)
+ return nullptr;
+ return ptr->get();
+}
-const char *mmap_file(int index, const char *filename)
+bool Arch::isAvailable(ArchArgs::ArchArgsTypes chip)
{
- try {
- blob_files[index].open(filename, boost::iostreams::mapped_file::priv);
- if (!blob_files[index].is_open())
- log_error("Unable to read chipdb %s\n", filename);
- return (const char *)blob_files[index].data();
- } catch (...) {
- log_error("Unable to read chipdb %s\n", filename);
- }
+ return get_chip_info(chip) != nullptr;
}
-void load_chipdb()
+std::vector<std::string> Arch::getSupportedPackages(ArchArgs::ArchArgsTypes chip)
{
- chipdb_blob_384 = mmap_file(0, EXTERNAL_CHIPDB_ROOT "/ice40/chipdb-384.bin");
- chipdb_blob_1k = mmap_file(1, EXTERNAL_CHIPDB_ROOT "/ice40/chipdb-1k.bin");
- chipdb_blob_5k = mmap_file(2, EXTERNAL_CHIPDB_ROOT "/ice40/chipdb-5k.bin");
- chipdb_blob_u4k = mmap_file(3, EXTERNAL_CHIPDB_ROOT "/ice40/chipdb-u4k.bin");
- chipdb_blob_8k = mmap_file(4, EXTERNAL_CHIPDB_ROOT "/ice40/chipdb-8k.bin");
+ const ChipInfoPOD *chip_info = get_chip_info(chip);
+ std::vector<std::string> packages;
+ for (int i = 0; i < chip_info->num_packages; i++)
+ packages.push_back(chip_info->packages_data[i].name.get());
+ return packages;
}
-#endif
+
+// -----------------------------------------------------------------------
+
Arch::Arch(ArchArgs args) : args(args)
{
-#if defined(WIN32) || defined(EXTERNAL_CHIPDB_ROOT)
- load_chipdb();
-#endif
+ fast_part = (args.type == ArchArgs::HX8K || args.type == ArchArgs::HX1K);
-#ifdef ICE40_HX1K_ONLY
- if (args.type == ArchArgs::HX1K) {
- fast_part = true;
- chip_info = get_chip_info(reinterpret_cast<const RelPtr<ChipInfoPOD> *>(chipdb_blob_1k));
- } else {
+ chip_info = get_chip_info(args.type);
+ if (chip_info == nullptr)
log_error("Unsupported iCE40 chip type.\n");
- }
-#else
- if (args.type == ArchArgs::LP384) {
- fast_part = false;
- chip_info = get_chip_info(reinterpret_cast<const RelPtr<ChipInfoPOD> *>(chipdb_blob_384));
- } else if (args.type == ArchArgs::LP1K || args.type == ArchArgs::HX1K) {
- fast_part = args.type == ArchArgs::HX1K;
- chip_info = get_chip_info(reinterpret_cast<const RelPtr<ChipInfoPOD> *>(chipdb_blob_1k));
- } else if (args.type == ArchArgs::UP5K) {
- fast_part = false;
- chip_info = get_chip_info(reinterpret_cast<const RelPtr<ChipInfoPOD> *>(chipdb_blob_5k));
- } else if (args.type == ArchArgs::U4K) {
- fast_part = false;
- chip_info = get_chip_info(reinterpret_cast<const RelPtr<ChipInfoPOD> *>(chipdb_blob_u4k));
- } else if (args.type == ArchArgs::LP8K || args.type == ArchArgs::HX8K) {
- fast_part = args.type == ArchArgs::HX8K;
- chip_info = get_chip_info(reinterpret_cast<const RelPtr<ChipInfoPOD> *>(chipdb_blob_8k));
- } else {
- log_error("Unsupported iCE40 chip type.\n");
- }
-#endif
package_info = nullptr;
for (int i = 0; i < chip_info->num_packages; i++) {
@@ -135,13 +111,6 @@ Arch::Arch(ArchArgs args) : args(args)
std::string Arch::getChipName() const
{
-#ifdef ICE40_HX1K_ONLY
- if (args.type == ArchArgs::HX1K) {
- return "Lattice LP1K";
- } else {
- log_error("Unsupported iCE40 chip type.\n");
- }
-#else
if (args.type == ArchArgs::LP384) {
return "Lattice LP384";
} else if (args.type == ArchArgs::LP1K) {
@@ -159,7 +128,6 @@ std::string Arch::getChipName() const
} else {
log_error("Unknown chip\n");
}
-#endif
}
// -----------------------------------------------------------------------
@@ -642,13 +610,10 @@ bool Arch::getBudgetOverride(const NetInfo *net_info, const PortRef &sink, delay
budget = 0;
else {
switch (args.type) {
-#ifndef ICE40_HX1K_ONLY
case ArchArgs::HX8K:
-#endif
case ArchArgs::HX1K:
budget = cin ? 190 : (same_y ? 260 : 560);
break;
-#ifndef ICE40_HX1K_ONLY
case ArchArgs::LP384:
case ArchArgs::LP1K:
case ArchArgs::LP8K:
@@ -658,7 +623,6 @@ bool Arch::getBudgetOverride(const NetInfo *net_info, const PortRef &sink, delay
case ArchArgs::U4K:
budget = cin ? 560 : (same_y ? 660 : 1220);
break;
-#endif
default:
log_error("Unsupported iCE40 chip type.\n");
}