/* $Id$ * ffb_drv.h: Creator/Creator3D direct rendering driver. * * Copyright (C) 2000 David S. Miller (davem@redhat.com) */ /* Auxilliary clips. */ typedef struct { volatile unsigned int min; volatile unsigned int max; } ffb_auxclip, *ffb_auxclipPtr; /* FFB register set. */ typedef struct _ffb_fbc { /* Next vertex registers, on the right we list which drawops * use said register and the logical name the register has in * that context. */ /* DESCRIPTION DRAWOP(NAME) */ /*0x00*/unsigned int pad1[3]; /* Reserved */ /*0x0c*/volatile unsigned int alpha; /* ALPHA Transparency */ /*0x10*/volatile unsigned int red; /* RED */ /*0x14*/volatile unsigned int green; /* GREEN */ /*0x18*/volatile unsigned int blue; /* BLUE */ /*0x1c*/volatile unsigned int z; /* DEPTH */ /*0x20*/volatile unsigned int y; /* Y triangle(DOYF) */ /* aadot(DYF) */ /* ddline(DYF) */ /* aaline(DYF) */ /*0x24*/volatile unsigned int x; /* X triangle(DOXF) */ /* aadot(DXF) */ /* ddline(DXF) */ /* aaline(DXF) */ /*0x28*/unsigned int pad2[2]; /* Reserved */ /*0x30*/volatile unsigned int ryf; /* Y (alias to DOYF) ddline(RYF) */ /* aaline(RYF) */ /* triangle(RYF) */ /*0x34*/volatile unsigned int rxf; /* X ddline(RXF) */ /* aaline(RXF) */ /* triangle(RXF) */ /*0x38*/unsigned int pad3[2]; /* Reserved */ /*0x40*/volatile unsigned int dmyf; /* Y (alias to DOYF) triangle(DMYF) */ /*0x44*/volatile unsigned int dmxf; /* X triangle(DMXF) */ /*0x48*/unsigned int pad4[2]; /* Reserved */ /*0x50*/volatile unsigned int ebyi; /* Y (alias to RYI) polygon(EBYI) */ /*0x54*/volatile unsigned int ebxi; /* X polygon(EBXI) */ /*0x58*/unsigned int pad5[2]; /* Reserved */ /*0x60*/volatile unsigned int by; /* Y brline(RYI) */ /* fastfill(OP) */ /* polygon(YI) */ /* rectangle(YI) */ /* bcopy(SRCY) */ /* vscroll(SRCY) */ /*0x64*/volatile unsigned int bx; /* X brline(RXI) */ /* polygon(XI) */ /* rectangle(XI) */ /* bcopy(SRCX) */ /* vscroll(SRCX) */ /* fastfill(GO) */ /*0x68*/volatile unsigned int dy; /* destination Y fastfill(DSTY) */ /* bcopy(DSRY) */ /* vscroll(DSRY) */ /*0x6c*/volatile unsigned int dx; /* destination X fastfill(DSTX) */ /* bcopy(DSTX) */ /* vscroll(DSTX) */ /*0x70*/volatile unsigned int bh; /* Y (alias to RYI) brline(DYI) */ /* dot(DYI) */ /* polygon(ETYI) */ /* Height fastfill(H) */ /* bcopy(H) */ /* vscroll(H) */ /* Y count fastfill(NY) */ /*0x74*/volatile unsigned int bw; /* X dot(DXI) */ /* brline(DXI) */ /* polygon(ETXI) */ /* fastfill(W) */ /* bcopy(W) */ /* vscroll(W) */ /* fastfill(NX) */ /*0x78*/unsigned int pad6[2]; /* Reserved */ /*0x80*/unsigned int pad7[32]; /* Reserved */ /* Setup Unit's vertex state register */ /*100*/ volatile unsigned int suvtx; /*104*/ unsigned int pad8[63]; /* Reserved */ /* Frame Buffer Control Registers */ /*200*/ volatile unsigned int ppc; /* Pixel Processor Control */ /*204*/ volatile unsigned int wid; /* Current WID */ /*208*/ volatile unsigned int fg; /* FG data */ /*20c*/ volatile unsigned int bg; /* BG data */ /*210*/ volatile unsigned int consty; /* Constant Y */ /*214*/ volatile unsigned int constz; /* Constant Z */ /*218*/ volatile unsigned int xclip; /* X Clip */ /*21c*/ volatile unsigned int dcss; /* Depth Cue Scale Slope */ /*220*/ volatile unsigned int vclipmin; /* Viewclip XY Min Bounds */ /*224*/ volatile unsigned int vclipmax; /* Viewclip XY Max Bounds */ /*228*/ volatile unsigned int vclipzmin; /* Viewclip Z Min Bounds */ /*22c*/ volatile unsigned int vclipzmax; /* Viewclip Z Max Bounds */ /*230*/ volatile unsigned int dcsf; /* Depth Cue Scale Front Bound */ /*234*/ volatile unsigned int dcsb; /* Depth Cue Scale Back Bound */ /*238*/ volatile unsigned int dczf; /* Depth Cue Z Front */ /*23c*/ volatile unsigned int dczb; /* Depth Cue Z Back */ /*240*/ unsigned int pad9; /* Reserved */ /*244*/ volatile unsigned int blendc; /* Alpha Blend Control */ /*248*/ volatile unsigned int blendc1; /* Alpha Blend Color 1 */ /*24c*/ volatile unsigned int blendc2; /* Alpha Blend Color 2 */ /*250*/ volatile unsigned int fbramitc; /* FB RAM Interleave Test Control */ /*254*/ volatile unsigned int fbc; /* Frame Buffer Control */ /*258*/ volatile unsigned int rop; /* Raster OPeration */ /*25c*/ volatile unsigned int cmp; /* Frame Buffer Compare */ /*260*/ volatile unsigned int matchab; /* Buffer AB Match Mask */ /*264*/ volatile unsigned int matchc; /* Buffer C(YZ) Match Mask */ /*268*/ volatile unsigned int magnab; /* Buffer AB Magnitude Mask */ /*26c*/ volatile unsigned int magnc; /* Buffer C(YZ) Magnitude Mask */ /*270*/ volatile unsigned int fbcfg0; /* Frame Buffer Config 0 */ /*274*/ volatile unsigned int fbcfg1; /* Frame Buffer Config 1 */ /*278*/ volatile unsigned int fbcfg2; /* Frame Buffer Config 2 */ /*27c*/ volatile unsigned int fbcfg3; /* Frame Buffer Config 3 */ /*280*/ volatile unsigned int ppcfg; /* Pixel Processor Config */ /*284*/ volatile unsigned int pick; /* Picking Control */ /*288*/ volatile unsigned int fillmode; /* FillMode */ /*28c*/ volatile unsigned int fbramwac; /* FB RAM Write Address Control */ /*290*/ volatile unsigned int pmask; /* RGB PlaneMask */ /*294*/ volatile unsigned int xpmask; /* X PlaneMask */ /*298*/ volatile unsigned int ypmask; /* Y PlaneMask */ /*29c*/ volatile unsigned int zpmask; /* Z PlaneMask */ /*2a0*/ ffb_auxclip auxclip[4]; /* Auxilliary Viewport Clip */ /* New 3dRAM III support regs */ /*2c0*/ volatile unsigned int rawblend2; /*2c4*/ volatile unsigned int rawpreblend; /*2c8*/ volatile unsigned int rawstencil; /*2cc*/ volatile unsigned int rawstencilctl; /*2d0*/ volatile unsigned int threedram1; /*2d4*/ volatile unsigned int threedram2; /*2d8*/ volatile unsigned int passin; /*2dc*/ volatile unsigned int rawclrdepth; /*2e0*/ volatile unsigned int rawpmask; /*2e4*/ volatile unsigned int rawcsrc; /*2e8*/ volatile unsigned int rawmatch; /*2ec*/ volatile unsigned int rawmagn; /*2f0*/ volatile unsigned int rawropblend; /*2f4*/ volatile unsigned int rawcmp; /*2f8*/ volatile unsigned int rawwac; /*2fc*/ volatile unsigned int fbramid; /*300*/ volatile unsigned int drawop; /* Draw OPeration */ /*304*/ unsigned int pad10[2]; /* Reserved */ /*30c*/ volatile unsigned int lpat; /* Line Pattern control */ /*310*/ unsigned int pad11; /* Reserved */ /*314*/ volatile unsigned int fontxy; /* XY Font coordinate */ /*318*/ volatile unsigned int fontw; /* Font Width */ /*31c*/ volatile unsigned int fontinc; /* Font Increment */ /*320*/ volatile unsigned int font; /* Font bits */ /*324*/ unsigned int pad12[3]; /* Reserved */ /*330*/ volatile unsigned int blend2; /*334*/ volatile unsigned int preblend; /*338*/ volatile unsigned int stencil; /*33c*/ volatile unsigned int stencilctl; /*340*/ unsigned int pad13[4]; /* Reserved */ /*350*/ volatile unsigned int dcss1; /* Depth Cue Scale Slope 1 */ /*354*/ volatile unsigned int dcss2; /* Depth Cue Scale Slope 2 */ /*358*/ volatile unsigned int dcss3; /* Depth Cue Scale Slope 3 */ /*35c*/ volatile unsigned int widpmask; /*360*/ volatile unsigned int dcs2; /*364*/ volatile unsigned int dcs3; /*368*/ volatile unsigned int dcs4; /*36c*/ unsigned int pad14; /* Reserved */ /*370*/ volatile unsigned int dcd2; /*374*/ volatile unsigned int dcd3; /*378*/ volatile unsigned int dcd4; /*37c*/ unsigned int pad15; /* Reserved */ /*380*/ volatile unsigned int pattern[32]; /* area Pattern */ /*400*/ unsigned int pad16[8]; /* Reserved */ /*420*/ volatile unsigned int reset; /* chip RESET */ /*424*/ unsigned int pad17[247]; /* Reserved */ /*800*/ volatile unsigned int devid; /* Device ID */ /*804*/ unsigned int pad18[63]; /* Reserved */ /*900*/ volatile unsigned int ucsr; /* User Control & Status Register */ /*904*/ unsigned int pad19[31]; /* Reserved */ /*980*/ volatile unsigned int mer; /* Mode Enable Register */ /*984*/ unsigned int pad20[1439]; /* Reserved */ } ffb_fbc, *ffb_fbcPtr; struct ffb_hw_context { int is_2d_only; unsigned int ppc; unsigned int wid; unsigned int fg; unsigned int bg; unsigned int consty; unsigned int constz; unsigned int xclip; unsigned int dcss; unsigned int vclipmin; unsigned int vclipmax; unsigned int vclipzmin; unsigned int vclipzmax; unsigned int dcsf; unsigned int dcsb; unsigned int dczf; unsigned int dczb; unsigned int blendc; unsigned int blendc1; unsigned int blendc2; unsigned int fbc; unsigned int rop; unsigned int cmp; unsigned int matchab; unsigned int matchc; unsigned int magnab; unsigned int magnc; unsigned int pmask; unsigned int xpmask; unsigned int ypmask; unsigned int zpmask; unsigned int auxclip0min; unsigned int auxclip0max; unsigned int auxclip1min; unsigned int auxclip1max; unsigned int auxclip2min; unsigned int auxclip2max; unsigned int auxclip3min; unsigned int auxclip3max; unsigned int drawop; unsigned int lpat; unsigned int fontxy; unsigned int fontw; unsigned int fontinc; unsigned int area_pattern[32]; unsigned int ucsr; unsigned int stencil; unsigned int stencilctl; unsigned int dcss1; unsigned int dcss2; unsigned int dcss3; unsigned int dcs2; unsigned int dcs3; unsigned int dcs4; unsigned int dcd2; unsigned int dcd3; unsigned int dcd4; unsigned int mer; }; #define FFB_MAX_CTXS 32 enum ffb_chip_type { ffb1_prototype = 0, /* Early pre-FCS FFB */ ffb1_standard, /* First FCS FFB, 100Mhz UPA, 66MHz gclk */ ffb1_speedsort, /* Second FCS FFB, 100Mhz UPA, 75MHz gclk */ ffb2_prototype, /* Early pre-FCS vertical FFB2 */ ffb2_vertical, /* First FCS FFB2/vertical, 100Mhz UPA, 100MHZ gclk, 75(SingleBuffer)/83(DoubleBuffer) MHz fclk */ ffb2_vertical_plus, /* Second FCS FFB2/vertical, same timings */ ffb2_horizontal, /* First FCS FFB2/horizontal, same timings as FFB2/vert */ ffb2_horizontal_plus, /* Second FCS FFB2/horizontal, same timings */ afb_m3, /* FCS Elite3D, 3 float chips */ afb_m6 /* FCS Elite3D, 6 float chips */ }; typedef struct ffb_dev_priv { /* Misc software state. */ int prom_node; enum ffb_chip_type ffb_type; u64 card_phys_base; struct miscdevice miscdev; /* Controller registers. */ ffb_fbcPtr regs; /* Context table. */ struct ffb_hw_context *hw_state[FFB_MAX_CTXS]; } ffb_dev_priv_t; extern unsigned long ffb_get_unmapped_area(struct file *filp, unsigned long hint, unsigned long len, unsigned long pgoff, unsigned long flags); extern unsigned long ffb_driver_get_map_ofs(drm_map_t *map) extern unsigned long ffb_driver_get_reg_ofs(struct drm_device *dev) n248' href='#n248'>248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329
/* $Id$
 * ffb_drv.c: Creator/Creator3D direct rendering driver.
 *
 * Copyright (C) 2000 David S. Miller (davem@redhat.com)
 */

#include <linux/sched.h>
#include <linux/smp_lock.h>
#include <asm/shmparam.h>
#include <asm/oplib.h>
#include <asm/upa.h>

#include "drmP.h"
#include "ffb_drv.h"

#define DRIVER_AUTHOR		"David S. Miller"

#define DRIVER_NAME		"ffb"
#define DRIVER_DESC		"Creator/Creator3D"
#define DRIVER_DATE		"20000517"

#define DRIVER_MAJOR		0
#define DRIVER_MINOR		0
#define DRIVER_PATCHLEVEL	1

typedef struct _ffb_position_t {
	int node;
	int root;
} ffb_position_t;

static ffb_position_t *ffb_position;

static void get_ffb_type(ffb_dev_priv_t *ffb_priv, int instance)
{
	volatile unsigned char *strap_bits;
	unsigned char val;

	strap_bits = (volatile unsigned char *)
		(ffb_priv->card_phys_base + 0x00200000UL);

	/* Don't ask, you have to read the value twice for whatever
	 * reason to get correct contents.
	 */
	val = upa_readb(strap_bits);
	val = upa_readb(strap_bits);
	switch (val & 0x78) {
	case (0x0 << 5) | (0x0 << 3):
		ffb_priv->ffb_type = ffb1_prototype;
		printk("ffb%d: Detected FFB1 pre-FCS prototype\n", instance);
		break;
	case (0x0 << 5) | (0x1 << 3):
		ffb_priv->ffb_type = ffb1_standard;
		printk("ffb%d: Detected FFB1\n", instance);
		break;
	case (0x0 << 5) | (0x3 << 3):
		ffb_priv->ffb_type = ffb1_speedsort;
		printk("ffb%d: Detected FFB1-SpeedSort\n", instance);
		break;
	case (0x1 << 5) | (0x0 << 3):
		ffb_priv->ffb_type = ffb2_prototype;
		printk("ffb%d: Detected FFB2/vertical pre-FCS prototype\n", instance);
		break;
	case (0x1 << 5) | (0x1 << 3):
		ffb_priv->ffb_type = ffb2_vertical;
		printk("ffb%d: Detected FFB2/vertical\n", instance);
		break;
	case (0x1 << 5) | (0x2 << 3):
		ffb_priv->ffb_type = ffb2_vertical_plus;
		printk("ffb%d: Detected FFB2+/vertical\n", instance);
		break;
	case (0x2 << 5) | (0x0 << 3):
		ffb_priv->ffb_type = ffb2_horizontal;
		printk("ffb%d: Detected FFB2/horizontal\n", instance);
		break;
	case (0x2 << 5) | (0x2 << 3):
		ffb_priv->ffb_type = ffb2_horizontal;
		printk("ffb%d: Detected FFB2+/horizontal\n", instance);
		break;
	default:
		ffb_priv->ffb_type = ffb2_vertical;
		printk("ffb%d: Unknown boardID[%08x], assuming FFB2\n", instance, val);
		break;
	};
}

static void ffb_apply_upa_parent_ranges(int parent,
					struct linux_prom64_registers *regs)
{
	struct linux_prom64_ranges ranges[PROMREG_MAX];
	char name[128];
	int len, i;

	prom_getproperty(parent, "name", name, sizeof(name));
	if (strcmp(name, "upa") != 0)
		return;

	len = prom_getproperty(parent, "ranges", (void *) ranges, sizeof(ranges));
	if (len <= 0)
		return;

	len /= sizeof(struct linux_prom64_ranges);
	for (i = 0; i < len; i++) {
		struct linux_prom64_ranges *rng = &ranges[i];
		u64 phys_addr = regs->phys_addr;

		if (phys_addr >= rng->ot_child_base &&
		    phys_addr < (rng->ot_child_base + rng->or_size)) {
			regs->phys_addr -= rng->ot_child_base;
			regs->phys_addr += rng->ot_parent_base;
			return;
		}
	}

	return;
}

static int ffb_init_one(drm_device_t *dev, int prom_node, int parent_node,
			int instance)
{
	struct linux_prom64_registers regs[2*PROMREG_MAX];
	ffb_dev_priv_t *ffb_priv = (ffb_dev_priv_t *)dev->dev_private;
	int i;

	ffb_priv->prom_node = prom_node;
	if (prom_getproperty(ffb_priv->prom_node, "reg",
			     (void *)regs, sizeof(regs)) <= 0) {
		return -EINVAL;
	}
	ffb_apply_upa_parent_ranges(parent_node, &regs[0]);
	ffb_priv->card_phys_base = regs[0].phys_addr;
	ffb_priv->regs = (ffb_fbcPtr)
		(regs[0].phys_addr + 0x00600000UL);
	get_ffb_type(ffb_priv, instance);
	for (i = 0; i < FFB_MAX_CTXS; i++)
		ffb_priv->hw_state[i] = NULL;

	return 0;
}

static int __init ffb_count_siblings(int root)
{
	int node, child, count = 0;

	child = prom_getchild(root);
	for (node = prom_searchsiblings(child, "SUNW,ffb"); node;
	     node = prom_searchsiblings(prom_getsibling(node), "SUNW,ffb"))
		count++;

	return count;
}

static int __init ffb_scan_siblings(int root, int instance)
{
	int node, child;

	child = prom_getchild(root);
	for (node = prom_searchsiblings(child, "SUNW,ffb"); node;
	     node = prom_searchsiblings(prom_getsibling(node), "SUNW,ffb")) {
		ffb_position[instance].node = node;
		ffb_position[instance].root = root;
		instance++;
	}

	return instance;
}

static drm_map_t *ffb_find_map(struct file *filp, unsigned long off)
{
	drm_file_t	*priv	= filp->private_data;
	drm_device_t	*dev;
	drm_map_list_t  *r_list;
	struct list_head *list;
	drm_map_t	*map;

	if (!priv || (dev = priv->dev) == NULL)
		return NULL;

	list_for_each(list, &dev->maplist->head) {
		unsigned long uoff;

		r_list = (drm_map_list_t *)list;
		map = r_list->map;
		if (!map)
			continue;
		uoff = (map->offset & 0xffffffff);
		if (uoff == off)
			return map;
	}

	return NULL;
}

unsigned long ffb_get_unmapped_area(struct file *filp,
				    unsigned long hint,
				    unsigned long len,
				    unsigned long pgoff,
				    unsigned long flags)
{
	drm_map_t *map = ffb_find_map(filp, pgoff << PAGE_SHIFT);
	unsigned long addr = -ENOMEM;

	if (!map)