18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci#ifndef __MCB_INTERNAL
38c2ecf20Sopenharmony_ci#define __MCB_INTERNAL
48c2ecf20Sopenharmony_ci
58c2ecf20Sopenharmony_ci#include <linux/types.h>
68c2ecf20Sopenharmony_ci
78c2ecf20Sopenharmony_ci#define PCI_VENDOR_ID_MEN		0x1a88
88c2ecf20Sopenharmony_ci#define PCI_DEVICE_ID_MEN_CHAMELEON	0x4d45
98c2ecf20Sopenharmony_ci#define CHAMELEONV2_MAGIC		0xabce
108c2ecf20Sopenharmony_ci#define CHAM_HEADER_SIZE		0x200
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_cienum chameleon_descriptor_type {
138c2ecf20Sopenharmony_ci	CHAMELEON_DTYPE_GENERAL = 0x0,
148c2ecf20Sopenharmony_ci	CHAMELEON_DTYPE_BRIDGE = 0x1,
158c2ecf20Sopenharmony_ci	CHAMELEON_DTYPE_CPU = 0x2,
168c2ecf20Sopenharmony_ci	CHAMELEON_DTYPE_BAR = 0x3,
178c2ecf20Sopenharmony_ci	CHAMELEON_DTYPE_END = 0xf,
188c2ecf20Sopenharmony_ci};
198c2ecf20Sopenharmony_ci
208c2ecf20Sopenharmony_cienum chameleon_bus_type {
218c2ecf20Sopenharmony_ci	CHAMELEON_BUS_WISHBONE,
228c2ecf20Sopenharmony_ci	CHAMELEON_BUS_AVALON,
238c2ecf20Sopenharmony_ci	CHAMELEON_BUS_LPC,
248c2ecf20Sopenharmony_ci	CHAMELEON_BUS_ISA,
258c2ecf20Sopenharmony_ci};
268c2ecf20Sopenharmony_ci
278c2ecf20Sopenharmony_ci/**
288c2ecf20Sopenharmony_ci * struct chameleon_fpga_header
298c2ecf20Sopenharmony_ci *
308c2ecf20Sopenharmony_ci * @revision:	Revison of Chameleon table in FPGA
318c2ecf20Sopenharmony_ci * @model:	Chameleon table model ASCII char
328c2ecf20Sopenharmony_ci * @minor:	Revision minor
338c2ecf20Sopenharmony_ci * @bus_type:	Bus type (usually %CHAMELEON_BUS_WISHBONE)
348c2ecf20Sopenharmony_ci * @magic:	Chameleon header magic number (0xabce for version 2)
358c2ecf20Sopenharmony_ci * @reserved:	Reserved
368c2ecf20Sopenharmony_ci * @filename:	Filename of FPGA bitstream
378c2ecf20Sopenharmony_ci */
388c2ecf20Sopenharmony_cistruct chameleon_fpga_header {
398c2ecf20Sopenharmony_ci	u8 revision;
408c2ecf20Sopenharmony_ci	char model;
418c2ecf20Sopenharmony_ci	u8 minor;
428c2ecf20Sopenharmony_ci	u8 bus_type;
438c2ecf20Sopenharmony_ci	u16 magic;
448c2ecf20Sopenharmony_ci	u16 reserved;
458c2ecf20Sopenharmony_ci	/* This one has no '\0' at the end!!! */
468c2ecf20Sopenharmony_ci	char filename[CHAMELEON_FILENAME_LEN];
478c2ecf20Sopenharmony_ci} __packed;
488c2ecf20Sopenharmony_ci#define HEADER_MAGIC_OFFSET 0x4
498c2ecf20Sopenharmony_ci
508c2ecf20Sopenharmony_ci/**
518c2ecf20Sopenharmony_ci * struct chameleon_gdd - Chameleon General Device Descriptor
528c2ecf20Sopenharmony_ci *
538c2ecf20Sopenharmony_ci * @irq:	the position in the FPGA's IRQ controller vector
548c2ecf20Sopenharmony_ci * @rev:	the revision of the variant's implementation
558c2ecf20Sopenharmony_ci * @var:	the variant of the IP core
568c2ecf20Sopenharmony_ci * @dev:	the device  the IP core is
578c2ecf20Sopenharmony_ci * @dtype:	device descriptor type
588c2ecf20Sopenharmony_ci * @bar:	BAR offset that must be added to module offset
598c2ecf20Sopenharmony_ci * @inst:	the instance number of the device, 0 is first instance
608c2ecf20Sopenharmony_ci * @group:	the group the device belongs to (0 = no group)
618c2ecf20Sopenharmony_ci * @reserved:	reserved
628c2ecf20Sopenharmony_ci * @offset:	beginning of the address window of desired module
638c2ecf20Sopenharmony_ci * @size:	size of the module's address window
648c2ecf20Sopenharmony_ci */
658c2ecf20Sopenharmony_cistruct chameleon_gdd {
668c2ecf20Sopenharmony_ci	__le32 reg1;
678c2ecf20Sopenharmony_ci	__le32 reg2;
688c2ecf20Sopenharmony_ci	__le32 offset;
698c2ecf20Sopenharmony_ci	__le32 size;
708c2ecf20Sopenharmony_ci
718c2ecf20Sopenharmony_ci} __packed;
728c2ecf20Sopenharmony_ci
738c2ecf20Sopenharmony_ci/* GDD Register 1 fields */
748c2ecf20Sopenharmony_ci#define GDD_IRQ(x) ((x) & 0x1f)
758c2ecf20Sopenharmony_ci#define GDD_REV(x) (((x) >> 5) & 0x3f)
768c2ecf20Sopenharmony_ci#define GDD_VAR(x) (((x) >> 11) & 0x3f)
778c2ecf20Sopenharmony_ci#define GDD_DEV(x) (((x) >> 18) & 0x3ff)
788c2ecf20Sopenharmony_ci#define GDD_DTY(x) (((x) >> 28) & 0xf)
798c2ecf20Sopenharmony_ci
808c2ecf20Sopenharmony_ci/* GDD Register 2 fields */
818c2ecf20Sopenharmony_ci#define GDD_BAR(x) ((x) & 0x7)
828c2ecf20Sopenharmony_ci#define GDD_INS(x) (((x) >> 3) & 0x3f)
838c2ecf20Sopenharmony_ci#define GDD_GRP(x) (((x) >> 9) & 0x3f)
848c2ecf20Sopenharmony_ci
858c2ecf20Sopenharmony_ci/**
868c2ecf20Sopenharmony_ci * struct chameleon_bdd - Chameleon Bridge Device Descriptor
878c2ecf20Sopenharmony_ci *
888c2ecf20Sopenharmony_ci * @irq:	the position in the FPGA's IRQ controller vector
898c2ecf20Sopenharmony_ci * @rev:	the revision of the variant's implementation
908c2ecf20Sopenharmony_ci * @var:	the variant of the IP core
918c2ecf20Sopenharmony_ci * @dev:	the device  the IP core is
928c2ecf20Sopenharmony_ci * @dtype:	device descriptor type
938c2ecf20Sopenharmony_ci * @bar:	BAR offset that must be added to module offset
948c2ecf20Sopenharmony_ci * @inst:	the instance number of the device, 0 is first instance
958c2ecf20Sopenharmony_ci * @dbar:	destination bar from the bus _behind_ the bridge
968c2ecf20Sopenharmony_ci * @chamoff:	offset within the BAR of the source bus
978c2ecf20Sopenharmony_ci * @offset:
988c2ecf20Sopenharmony_ci * @size:
998c2ecf20Sopenharmony_ci */
1008c2ecf20Sopenharmony_cistruct chameleon_bdd {
1018c2ecf20Sopenharmony_ci	unsigned int irq:6;
1028c2ecf20Sopenharmony_ci	unsigned int rev:6;
1038c2ecf20Sopenharmony_ci	unsigned int var:6;
1048c2ecf20Sopenharmony_ci	unsigned int dev:10;
1058c2ecf20Sopenharmony_ci	unsigned int dtype:4;
1068c2ecf20Sopenharmony_ci	unsigned int bar:3;
1078c2ecf20Sopenharmony_ci	unsigned int inst:6;
1088c2ecf20Sopenharmony_ci	unsigned int dbar:3;
1098c2ecf20Sopenharmony_ci	unsigned int group:6;
1108c2ecf20Sopenharmony_ci	unsigned int reserved:14;
1118c2ecf20Sopenharmony_ci	u32 chamoff;
1128c2ecf20Sopenharmony_ci	u32 offset;
1138c2ecf20Sopenharmony_ci	u32 size;
1148c2ecf20Sopenharmony_ci} __packed;
1158c2ecf20Sopenharmony_ci
1168c2ecf20Sopenharmony_cistruct chameleon_bar {
1178c2ecf20Sopenharmony_ci	u32 addr;
1188c2ecf20Sopenharmony_ci	u32 size;
1198c2ecf20Sopenharmony_ci};
1208c2ecf20Sopenharmony_ci
1218c2ecf20Sopenharmony_ci#define BAR_CNT(x) ((x) & 0x07)
1228c2ecf20Sopenharmony_ci#define CHAMELEON_BAR_MAX	6
1238c2ecf20Sopenharmony_ci#define BAR_DESC_SIZE(x)	((x) * sizeof(struct chameleon_bar) + sizeof(__le32))
1248c2ecf20Sopenharmony_ci
1258c2ecf20Sopenharmony_ciint chameleon_parse_cells(struct mcb_bus *bus, phys_addr_t mapbase,
1268c2ecf20Sopenharmony_ci			  void __iomem *base);
1278c2ecf20Sopenharmony_ci
1288c2ecf20Sopenharmony_ci#endif
129