1a7fd8e5eSmacallan/* $OpenBSD: wsfb_driver.c,v 1.18 2003/04/02 16:42:13 jason Exp $ */
2a7fd8e5eSmacallan/*
3a7fd8e5eSmacallan * Copyright (c) 2024 Michael Lorenz
4a7fd8e5eSmacallan * All rights reserved.
5a7fd8e5eSmacallan *
6a7fd8e5eSmacallan * Redistribution and use in source and binary forms, with or without
7a7fd8e5eSmacallan * modification, are permitted provided that the following conditions
8a7fd8e5eSmacallan * are met:
9a7fd8e5eSmacallan *
10a7fd8e5eSmacallan *    - Redistributions of source code must retain the above copyright
11a7fd8e5eSmacallan *      notice, this list of conditions and the following disclaimer.
12a7fd8e5eSmacallan *    - Redistributions in binary form must reproduce the above
13a7fd8e5eSmacallan *      copyright notice, this list of conditions and the following
14a7fd8e5eSmacallan *      disclaimer in the documentation and/or other materials provided
15a7fd8e5eSmacallan *      with the distribution.
16a7fd8e5eSmacallan *
17a7fd8e5eSmacallan * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18a7fd8e5eSmacallan * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19a7fd8e5eSmacallan * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
20a7fd8e5eSmacallan * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
21a7fd8e5eSmacallan * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
22a7fd8e5eSmacallan * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
23a7fd8e5eSmacallan * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24a7fd8e5eSmacallan * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25a7fd8e5eSmacallan * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26a7fd8e5eSmacallan * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
27a7fd8e5eSmacallan * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28a7fd8e5eSmacallan * POSSIBILITY OF SUCH DAMAGE.
29a7fd8e5eSmacallan *
30a7fd8e5eSmacallan */
31a7fd8e5eSmacallan
32a7fd8e5eSmacallan#include <fcntl.h>
33a7fd8e5eSmacallan#include <sys/types.h>
34a7fd8e5eSmacallan#include <sys/time.h>
35a7fd8e5eSmacallan#include <dev/wscons/wsconsio.h>
36a7fd8e5eSmacallan
37727c6de2Smacallan#include "xorg-server.h"
38a7fd8e5eSmacallan#include "xf86.h"
39a7fd8e5eSmacallan#include "xf86_OSproc.h"
40727c6de2Smacallan#include "compiler.h"
41727c6de2Smacallan#include "xorgVersion.h"
42a7fd8e5eSmacallan#include "xf86Cursor.h"
43727c6de2Smacallan#include "exa.h"
44a7fd8e5eSmacallan#include "compat-api.h"
45a7fd8e5eSmacallan
46a7fd8e5eSmacallan#ifndef NGLE_H
47a7fd8e5eSmacallan#define NGLE_H
48a7fd8e5eSmacallan
49a7fd8e5eSmacallan/* private data */
50a7fd8e5eSmacallantypedef struct {
51a7fd8e5eSmacallan	int			fd;
52a7fd8e5eSmacallan	struct wsdisplayio_fbinfo fbi;
53a7fd8e5eSmacallan	unsigned char*		fbmem;
54a7fd8e5eSmacallan	size_t			fbmem_len;
55a7fd8e5eSmacallan	void			*regs;
567517da51Smacallan	size_t			reglen;
57a7fd8e5eSmacallan	Bool			HWCursor;
58a7fd8e5eSmacallan	CloseScreenProcPtr	CloseScreen;
59a7fd8e5eSmacallan	CreateScreenResourcesProcPtr CreateScreenResources;
60a7fd8e5eSmacallan	EntityInfoPtr		pEnt;
61a7fd8e5eSmacallan	struct wsdisplay_cursor cursor;
62a7fd8e5eSmacallan	int			maskoffset;
63a7fd8e5eSmacallan	xf86CursorInfoPtr	CursorInfoRec;
64a7fd8e5eSmacallan	OptionInfoPtr		Options;
65727c6de2Smacallan	ExaDriverPtr		pExa;
666d300f0aSchristos	GlyphsProcPtr		glyphs;
677a5287f7Smacallan	uint32_t		gid, buf, fbacc, creg;
6897ec0daeSmacallan	int 			offset, hwmode, offsetd;
69727c6de2Smacallan#define HW_FB	0
70727c6de2Smacallan#define HW_FILL	1
71727c6de2Smacallan#define HW_BLIT	2
72da676487Smacallan#define HW_BINC	3
739c037af6Smacallan	uint32_t		read_mode, write_mode;
749c037af6Smacallan	int			need_sync;
75a7fd8e5eSmacallan} NGLERec, *NGLEPtr;
76a7fd8e5eSmacallan
77a7fd8e5eSmacallan#define NGLEPTR(p) ((NGLEPtr)((p)->driverPrivate))
78a7fd8e5eSmacallan
79a7fd8e5eSmacallanBool NGLESetupCursor(ScreenPtr);
80727c6de2SmacallanBool NGLEInitAccel(ScreenPtr);
817a5287f7SmacallanBool SummitSetupCursor(ScreenPtr);
827517da51SmacallanBool SummitInitAccel(ScreenPtr);
837517da51Smacallan
847517da51Smacallanstatic inline void
857517da51SmacallanNGLEWrite4(NGLEPtr fPtr, int offset, uint32_t val)
867517da51Smacallan{
877517da51Smacallan	volatile uint32_t *ptr = (uint32_t *)((uint8_t *)fPtr->regs + offset);
887517da51Smacallan	*ptr = val;
897517da51Smacallan}
907517da51Smacallan
917517da51Smacallanstatic inline void
927517da51SmacallanNGLEWrite1(NGLEPtr fPtr, int offset, uint8_t val)
937517da51Smacallan{
947517da51Smacallan	volatile uint8_t *ptr = (uint8_t *)fPtr->regs + offset;
957517da51Smacallan	*ptr = val;
967517da51Smacallan}
977517da51Smacallan
987517da51Smacallanstatic inline uint32_t
997517da51SmacallanNGLERead4(NGLEPtr fPtr, int offset)
1007517da51Smacallan{
1017517da51Smacallan	volatile uint32_t *ptr = (uint32_t *)((uint8_t *)fPtr->regs + offset);
1027517da51Smacallan	return *ptr;
1037517da51Smacallan}
1047517da51Smacallan
1057517da51Smacallanstatic inline uint8_t
1067517da51SmacallanNGLERead1(NGLEPtr fPtr, int offset)
1077517da51Smacallan{
1087517da51Smacallan	volatile uint8_t *ptr = (uint8_t *)fPtr->regs + offset;
1097517da51Smacallan	return *ptr;
1107517da51Smacallan}
111a7fd8e5eSmacallan
112a7fd8e5eSmacallan#endif
113