/* * This file is part of the flashrom project. * * Copyright (C) 2009 Carl-Daniel Hailfinger * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; version 2 of the License. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * * * Header file for hardware access and OS abstraction. Included from flash.h. */ #ifndef __HWACCESS_H__ #define __HWACCESS_H__ 1 #if defined(__GLIBC__) #include #endif #if NEED_PCI == 1 #include #endif /* for iopl and outb under Solaris */ #if defined (__sun) && (defined(__i386) || defined(__amd64)) #include #include #include #include #endif #if (defined(__MACH__) && defined(__APPLE__)) #define __DARWIN__ #endif #if defined(__FreeBSD__) || defined(__DragonFly__) #include #define off64_t off_t #define lseek64 lseek #define OUTB(x, y) do { u_int tmp = (y); outb(tmp, (x)); } while (0) #define OUTW(x, y) do { u_int tmp = (y); outw(tmp, (x)); } while (0) #define OUTL(x, y) do { u_int tmp = (y); outl(tmp, (x)); } while (0) #define INB(x) __extension__ ({ u_int tmp = (x); inb(tmp); }) #define INW(x) __extension__ ({ u_int tmp = (x); inw(tmp); }) #define INL(x) __extension__ ({ u_int tmp = (x); inl(tmp); }) #else #if defined(__DARWIN__) #include #define off64_t off_t #define lseek64 lseek #endif #if defined (__sun) && (defined(__i386) || defined(__amd64)) /* Note different order for outb */ #define OUTB(x,y) outb(y, x) #define OUTW(x,y) outw(y, x) #define OUTL(x,y) outl(y, x) #define INB inb #define INW inw #define INL inl #else #define OUTB outb #define OUTW outw #define OUTL outl #define INB inb #define INW inw #define INL inl #endif #endif #if defined(__NetBSD__) #define off64_t off_t #define lseek64 lseek #if defined(__i386__) || defined(__x86_64__) #include #include #if defined(__i386__) #define iopl i386_iopl #elif defined(__x86_64__) #define iopl x86_64_iopl #endif #include static inline void outb(uint8_t value, uint16_t port) { asm volatile ("outb %b0,%w1": :"a" (value), "Nd" (port)); } static inline uint8_t inb(uint16_t port) { uint8_t value; asm volatile ("inb %w1,%0":"=a" (value):"Nd" (port)); return value; } static inline void outw(uint16_t value, uint16_t port) { asm volatile ("outw %w0,%w1": :"a" (value), "Nd" (port)); } static inline uint16_t inw(uint16_t port) { uint16_t value; asm volatile ("inw %w1,%0":"=a" (value):"Nd" (port)); return value; } static inline void outl(uint32_t value, uint16_t port) { asm volatile ("outl %0,%w1": :"a" (value), "Nd" (port)); } static inline uint32_t inl(uint16_t port) { uint32_t value; asm volatile ("inl %1,%0":"=a" (value):"Nd" (port)); return value; } #endif #endif #if defined(__FreeBSD__) || defined(__DragonFly__) extern int io_fd; #endif #if !defined(__DARWIN__) && !defined(__FreeBSD__) && !defined(__DragonFly__) typedef struct { uint32_t hi, lo; } msr_t; msr_t rdmsr(int addr); int wrmsr(int addr, msr_t msr); #endif #if defined(__FreeBSD__) || defined(__DragonFly__) /* FreeBSD already has conflicting definitions for wrmsr/rdmsr. */ #undef rdmsr #undef wrmsr #define rdmsr freebsd_rdmsr #define wrmsr freebsd_wrmsr typedef struct { uint32_t hi, lo; } msr_t; msr_t freebsd_rdmsr(int addr); int freebsd_wrmsr(int addr, msr_t msr); #endif #endif /* !__HWACCESS_H__ */ '#n39'>39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
/*
 *  nextpnr -- Next Generation Place and Route
 *
 *  Copyright (C) 2019  David Shah <david@symbioticeda.com>
 *
 *  Permission to use, copy, modify, and/or distribute this software for any
 *  purpose with or without fee is hereby granted, provided that the above
 *  copyright notice and this permission notice appear in all copies.
 *
 *  THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 *  WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 *  MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 *  ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 *  WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 *  ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 *  OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 *
 */

#include "nextpnr.h"

#ifndef GENERIC_CELLS_H
#define GENERIC_CELLS_H

NEXTPNR_NAMESPACE_BEGIN

// Create a generic arch cell and return it
// Name will be automatically assigned if not specified
std::unique_ptr<CellInfo> create_generic_cell(Context *ctx, IdString type, std::string name = "");

// Return true if a cell is a LUT
inline bool is_lut(const BaseCtx *ctx, const CellInfo *cell) { return cell->type == ctx->id("LUT"); }

// Return true if a cell is a flipflop
inline bool is_ff(const BaseCtx *ctx, const CellInfo *cell) { return cell->type == ctx->id("DFF"); }

inline bool is_lc(const BaseCtx *ctx, const CellInfo *cell) { return cell->type == ctx->id("GENERIC_SLICE"); }

// Convert a LUT primitive to (part of) an GENERIC_SLICE, swapping ports
// as needed. Set no_dff if a DFF is not being used, so that the output
// can be reconnected
void lut_to_lc(const Context *ctx, CellInfo *lut, CellInfo *lc, bool no_dff = true);

// Convert a DFF primitive to (part of) an GENERIC_SLICE, setting parameters
// and reconnecting signals as necessary. If pass_thru_lut is True, the LUT will
// be configured as pass through and D connected to I0, otherwise D will be
// ignored
void dff_to_lc(const Context *ctx, CellInfo *dff, CellInfo *lc, bool pass_thru_lut = false);

// Convert a nextpnr IO buffer to a GENERIC_IOB
void nxio_to_iob(Context *ctx, CellInfo *nxio, CellInfo *sbio, std::unordered_set<IdString> &todelete_cells);

NEXTPNR_NAMESPACE_END

#endif