162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
262306a36Sopenharmony_ci#ifndef __MCB_INTERNAL
362306a36Sopenharmony_ci#define __MCB_INTERNAL
462306a36Sopenharmony_ci
562306a36Sopenharmony_ci#include <linux/types.h>
662306a36Sopenharmony_ci
762306a36Sopenharmony_ci#define PCI_VENDOR_ID_MEN		0x1a88
862306a36Sopenharmony_ci#define PCI_DEVICE_ID_MEN_CHAMELEON	0x4d45
962306a36Sopenharmony_ci#define CHAMELEONV2_MAGIC		0xabce
1062306a36Sopenharmony_ci#define CHAM_HEADER_SIZE		0x200
1162306a36Sopenharmony_ci
1262306a36Sopenharmony_cienum chameleon_descriptor_type {
1362306a36Sopenharmony_ci	CHAMELEON_DTYPE_GENERAL = 0x0,
1462306a36Sopenharmony_ci	CHAMELEON_DTYPE_BRIDGE = 0x1,
1562306a36Sopenharmony_ci	CHAMELEON_DTYPE_CPU = 0x2,
1662306a36Sopenharmony_ci	CHAMELEON_DTYPE_BAR = 0x3,
1762306a36Sopenharmony_ci	CHAMELEON_DTYPE_END = 0xf,
1862306a36Sopenharmony_ci};
1962306a36Sopenharmony_ci
2062306a36Sopenharmony_cienum chameleon_bus_type {
2162306a36Sopenharmony_ci	CHAMELEON_BUS_WISHBONE,
2262306a36Sopenharmony_ci	CHAMELEON_BUS_AVALON,
2362306a36Sopenharmony_ci	CHAMELEON_BUS_LPC,
2462306a36Sopenharmony_ci	CHAMELEON_BUS_ISA,
2562306a36Sopenharmony_ci};
2662306a36Sopenharmony_ci
2762306a36Sopenharmony_ci/**
2862306a36Sopenharmony_ci * struct chameleon_fpga_header
2962306a36Sopenharmony_ci *
3062306a36Sopenharmony_ci * @revision:	Revison of Chameleon table in FPGA
3162306a36Sopenharmony_ci * @model:	Chameleon table model ASCII char
3262306a36Sopenharmony_ci * @minor:	Revision minor
3362306a36Sopenharmony_ci * @bus_type:	Bus type (usually %CHAMELEON_BUS_WISHBONE)
3462306a36Sopenharmony_ci * @magic:	Chameleon header magic number (0xabce for version 2)
3562306a36Sopenharmony_ci * @reserved:	Reserved
3662306a36Sopenharmony_ci * @filename:	Filename of FPGA bitstream
3762306a36Sopenharmony_ci */
3862306a36Sopenharmony_cistruct chameleon_fpga_header {
3962306a36Sopenharmony_ci	u8 revision;
4062306a36Sopenharmony_ci	char model;
4162306a36Sopenharmony_ci	u8 minor;
4262306a36Sopenharmony_ci	u8 bus_type;
4362306a36Sopenharmony_ci	u16 magic;
4462306a36Sopenharmony_ci	u16 reserved;
4562306a36Sopenharmony_ci	/* This one has no '\0' at the end!!! */
4662306a36Sopenharmony_ci	char filename[CHAMELEON_FILENAME_LEN];
4762306a36Sopenharmony_ci} __packed;
4862306a36Sopenharmony_ci#define HEADER_MAGIC_OFFSET 0x4
4962306a36Sopenharmony_ci
5062306a36Sopenharmony_ci/**
5162306a36Sopenharmony_ci * struct chameleon_gdd - Chameleon General Device Descriptor
5262306a36Sopenharmony_ci *
5362306a36Sopenharmony_ci * @irq:	the position in the FPGA's IRQ controller vector
5462306a36Sopenharmony_ci * @rev:	the revision of the variant's implementation
5562306a36Sopenharmony_ci * @var:	the variant of the IP core
5662306a36Sopenharmony_ci * @dev:	the device  the IP core is
5762306a36Sopenharmony_ci * @dtype:	device descriptor type
5862306a36Sopenharmony_ci * @bar:	BAR offset that must be added to module offset
5962306a36Sopenharmony_ci * @inst:	the instance number of the device, 0 is first instance
6062306a36Sopenharmony_ci * @group:	the group the device belongs to (0 = no group)
6162306a36Sopenharmony_ci * @reserved:	reserved
6262306a36Sopenharmony_ci * @offset:	beginning of the address window of desired module
6362306a36Sopenharmony_ci * @size:	size of the module's address window
6462306a36Sopenharmony_ci */
6562306a36Sopenharmony_cistruct chameleon_gdd {
6662306a36Sopenharmony_ci	__le32 reg1;
6762306a36Sopenharmony_ci	__le32 reg2;
6862306a36Sopenharmony_ci	__le32 offset;
6962306a36Sopenharmony_ci	__le32 size;
7062306a36Sopenharmony_ci
7162306a36Sopenharmony_ci} __packed;
7262306a36Sopenharmony_ci
7362306a36Sopenharmony_ci/* GDD Register 1 fields */
7462306a36Sopenharmony_ci#define GDD_IRQ(x) ((x) & 0x1f)
7562306a36Sopenharmony_ci#define GDD_REV(x) (((x) >> 5) & 0x3f)
7662306a36Sopenharmony_ci#define GDD_VAR(x) (((x) >> 11) & 0x3f)
7762306a36Sopenharmony_ci#define GDD_DEV(x) (((x) >> 18) & 0x3ff)
7862306a36Sopenharmony_ci#define GDD_DTY(x) (((x) >> 28) & 0xf)
7962306a36Sopenharmony_ci
8062306a36Sopenharmony_ci/* GDD Register 2 fields */
8162306a36Sopenharmony_ci#define GDD_BAR(x) ((x) & 0x7)
8262306a36Sopenharmony_ci#define GDD_INS(x) (((x) >> 3) & 0x3f)
8362306a36Sopenharmony_ci#define GDD_GRP(x) (((x) >> 9) & 0x3f)
8462306a36Sopenharmony_ci
8562306a36Sopenharmony_ci/**
8662306a36Sopenharmony_ci * struct chameleon_bdd - Chameleon Bridge Device Descriptor
8762306a36Sopenharmony_ci *
8862306a36Sopenharmony_ci * @irq:	the position in the FPGA's IRQ controller vector
8962306a36Sopenharmony_ci * @rev:	the revision of the variant's implementation
9062306a36Sopenharmony_ci * @var:	the variant of the IP core
9162306a36Sopenharmony_ci * @dev:	the device  the IP core is
9262306a36Sopenharmony_ci * @dtype:	device descriptor type
9362306a36Sopenharmony_ci * @bar:	BAR offset that must be added to module offset
9462306a36Sopenharmony_ci * @inst:	the instance number of the device, 0 is first instance
9562306a36Sopenharmony_ci * @dbar:	destination bar from the bus _behind_ the bridge
9662306a36Sopenharmony_ci * @chamoff:	offset within the BAR of the source bus
9762306a36Sopenharmony_ci * @offset:
9862306a36Sopenharmony_ci * @size:
9962306a36Sopenharmony_ci */
10062306a36Sopenharmony_cistruct chameleon_bdd {
10162306a36Sopenharmony_ci	unsigned int irq:6;
10262306a36Sopenharmony_ci	unsigned int rev:6;
10362306a36Sopenharmony_ci	unsigned int var:6;
10462306a36Sopenharmony_ci	unsigned int dev:10;
10562306a36Sopenharmony_ci	unsigned int dtype:4;
10662306a36Sopenharmony_ci	unsigned int bar:3;
10762306a36Sopenharmony_ci	unsigned int inst:6;
10862306a36Sopenharmony_ci	unsigned int dbar:3;
10962306a36Sopenharmony_ci	unsigned int group:6;
11062306a36Sopenharmony_ci	unsigned int reserved:14;
11162306a36Sopenharmony_ci	u32 chamoff;
11262306a36Sopenharmony_ci	u32 offset;
11362306a36Sopenharmony_ci	u32 size;
11462306a36Sopenharmony_ci} __packed;
11562306a36Sopenharmony_ci
11662306a36Sopenharmony_cistruct chameleon_bar {
11762306a36Sopenharmony_ci	u32 addr;
11862306a36Sopenharmony_ci	u32 size;
11962306a36Sopenharmony_ci};
12062306a36Sopenharmony_ci
12162306a36Sopenharmony_ci#define BAR_CNT(x) ((x) & 0x07)
12262306a36Sopenharmony_ci#define CHAMELEON_BAR_MAX	6
12362306a36Sopenharmony_ci#define BAR_DESC_SIZE(x)	((x) * sizeof(struct chameleon_bar) + sizeof(__le32))
12462306a36Sopenharmony_ci
12562306a36Sopenharmony_ciint chameleon_parse_cells(struct mcb_bus *bus, phys_addr_t mapbase,
12662306a36Sopenharmony_ci			  void __iomem *base);
12762306a36Sopenharmony_ci
12862306a36Sopenharmony_ci#endif
129