<commit_before>/*-
 * Copyright (c) 1999 <NAME> <<EMAIL>>
 * Copyright (c) 1992-1998 <NAME>
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer as
 *    the first lines of this file unmodified.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. The name of the author may not be used to endorse or promote products
 *    derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 */

#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");

#include "opt_vga.h"
#include "opt_fb.h"
#ifndef FB_DEBUG
#define	FB_DEBUG	0
#endif
#include "opt_syscons.h"	/* should be removed in the future, XXX */

#include <sys/param.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/conf.h>
#include <sys/fcntl.h>
#include <sys/malloc.h>
#include <sys/fbio.h>

#include <vm/vm.h>
#include <vm/vm_param.h>
#include <vm/pmap.h>

#include <machine/md_var.h>
#if defined(__i386__) || defined(__amd64__)
#include <machine/pc/bios.h>
#endif
#include <machine/bus.h>

#include <dev/fb/fbreg.h>
#include <dev/fb/vgareg.h>

#include <isa/isareg.h>

#ifndef VGA_DEBUG
#define VGA_DEBUG		0
#endif

/* XXX machine/pc/bios.h has got too much i386-specific stuff in it */
#ifndef BIOS_PADDRTOVADDR
#define	BIOS_PADDRTOVADDR(x)	(x)
#endif

int
vga_probe_unit(int unit, video_adapter_t *buf, int flags)
{
	video_adapter_t *adp;
	video_switch_t *sw;
	int error;

	sw = vid_get_switch(VGA_DRIVER_NAME);
	if (sw == NULL)
		return 0;
	error = (*sw->probe)(unit, &adp, NULL, flags);
	if (error)
		return error;
	bcopy(adp, buf, sizeof(*buf));
	return 0;
}

int
vga_attach_unit(int unit, vga_softc_t *sc, int flags)
{
	video_switch_t *sw;
	int error;

	sw = vid_get_switch(VGA_DRIVER_NAME);
	if (sw == NULL)
		return ENXIO;

	error = (*sw->probe)(unit, &sc->adp, NULL, flags);
	if (error)
		return error;
	return (*sw->init)(unit, sc->adp, flags);
}

/* cdev driver functions */

#ifdef FB_INSTALL_CDEV

int
vga_open(struct cdev *dev, vga_softc_t *sc, int flag, int mode, struct thread *td)
{
	if (sc == NULL)
		return ENXIO;
	if (mode & (O_CREAT | O_APPEND | O_TRUNC))
		return ENODEV;

	return genfbopen(&sc->gensc, sc->adp, flag, mode, td);
}

int
vga_close(struct cdev *dev, vga_softc_t *sc, int flag, int mode, struct thread *td)
{
	return genfbclose(&sc->gensc, sc->adp, flag, mode, td);
}

int
vga_read(struct cdev *dev, vga_softc_t *sc, struct uio *uio, int flag)
{
	return genfbread(&sc->gensc, sc->adp, uio, flag);
}

int
vga_write(struct cdev *dev, vga_softc_t *sc, struct uio *uio, int flag)
{
	return genfbread(&sc->gensc, sc->adp, uio, flag);
}

int
vga_ioctl(struct cdev *dev, vga_softc_t *sc, u_long cmd, caddr_t arg, int flag,
	  struct thread *td)
{
	return genfbioctl(&sc->gensc, sc->adp, cmd, arg, flag, td);
}

int
vga_mmap(struct cdev *dev, vga_softc_t *sc, vm_offset_t offset, vm_offset_t *paddr,
	 int prot)
{
	return genfbmmap(&sc->gensc, sc->adp, offset, paddr, prot);
}

#endif /* FB_INSTALL_CDEV */

/* LOW-LEVEL */

#include <isa/rtc.h>
#ifdef __i386__
#include <dev/fb/vesa.h>
#endif

#define probe_done(adp)		((adp)->va_flags & V_ADP_PROBED)
#define init_done(adp)		((adp)->va_flags & V_ADP_INITIALIZED)
#define config_done(adp)	((adp)->va_flags & V_ADP_REGISTERED)

/* for compatibility with old kernel options */
#ifdef SC_ALT_SEQACCESS
#undef SC_ALT_SEQACCESS
#undef VGA_ALT_SEQACCESS
#define VGA_ALT_SEQACCESS	1
#endif

#ifdef SLOW_VGA
#undef SLOW_VGA
#undef VGA_SLOW_IOACCESS
#define VGA_SLOW_IOACCESS
#endif

/* architecture dependent option */
#ifndef __i386__
#define VGA_NO_BIOS		1
#endif

/* this should really be in `rtc.h' */
#define RTC_EQUIPMENT           0x14
<commit_msg>Enable BIOS modes on amd64.<commit_after>/*-
 * Copyright (c) 1999 <NAME> <<EMAIL>>
 * Copyright (c) 1992-1998 <NAME>
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer as
 *    the first lines of this file unmodified.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. The name of the author may not be used to endorse or promote products
 *    derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 */

#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");

#include "opt_vga.h"
#include "opt_fb.h"
#ifndef FB_DEBUG
#define	FB_DEBUG	0
#endif
#include "opt_syscons.h"	/* should be removed in the future, XXX */

#include <sys/param.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/conf.h>
#include <sys/fcntl.h>
#include <sys/malloc.h>
#include <sys/fbio.h>

#include <vm/vm.h>
#include <vm/vm_param.h>
#include <vm/pmap.h>

#include <machine/md_var.h>
#if defined(__i386__) || defined(__amd64__)
#include <machine/pc/bios.h>
#endif
#include <machine/bus.h>

#include <dev/fb/fbreg.h>
#include <dev/fb/vgareg.h>

#include <isa/isareg.h>

#ifndef VGA_DEBUG
#define VGA_DEBUG		0
#endif

/* XXX machine/pc/bios.h has got too much i386-specific stuff in it */
#ifndef BIOS_PADDRTOVADDR
#define	BIOS_PADDRTOVADDR(x)	(x)
#endif

int
vga_probe_unit(int unit, video_adapter_t *buf, int flags)
{
	video_adapter_t *adp;
	video_switch_t *sw;
	int error;

	sw = vid_get_switch(VGA_DRIVER_NAME);
	if (sw == NULL)
		return 0;
	error = (*sw->probe)(unit, &adp, NULL, flags);
	if (error)
		return error;
	bcopy(adp, buf, sizeof(*buf));
	return 0;
}

int
vga_attach_unit(int unit, vga_softc_t *sc, int flags)
{
	video_switch_t *sw;
	int error;

	sw = vid_get_switch(VGA_DRIVER_NAME);
	if (sw == NULL)
		return ENXIO;

	error = (*sw->probe)(unit, &sc->adp, NULL, flags);
	if (error)
		return error;
	return (*sw->init)(unit, sc->adp, flags);
}

/* cdev driver functions */

#ifdef FB_INSTALL_CDEV

int
vga_open(struct cdev *dev, vga_softc_t *sc, int flag, int mode, struct thread *td)
{
	if (sc == NULL)
		return ENXIO;
	if (mode & (O_CREAT | O_APPEND | O_TRUNC))
		return ENODEV;

	return genfbopen(&sc->gensc, sc->adp, flag, mode, td);
}

int
vga_close(struct cdev *dev, vga_softc_t *sc, int flag, int mode, struct thread *td)
{
	return genfbclose(&sc->gensc, sc->adp, flag, mode, td);
}

int
vga_read(struct cdev *dev, vga_softc_t *sc, struct uio *uio, int flag)
{
	return genfbread(&sc->gensc, sc->adp, uio, flag);
}

int
vga_write(struct cdev *dev, vga_softc_t *sc, struct uio *uio, int flag)
{
	return genfbread(&sc->gensc, sc->adp, uio, flag);
}

int
vga_ioctl(struct cdev *dev, vga_softc_t *sc, u_long cmd, caddr_t arg, int flag,
	  struct thread *td)
{
	return genfbioctl(&sc->gensc, sc->adp, cmd, arg, flag, td);
}

int
vga_mmap(struct cdev *dev, vga_softc_t *sc, vm_offset_t offset, vm_offset_t *paddr,
	 int prot)
{
	return genfbmmap(&sc->gensc, sc->adp, offset, paddr, prot);
}

#endif /* FB_INSTALL_CDEV */

/* LOW-LEVEL */

#include <isa/rtc.h>
#ifdef __i386__
#include <dev/fb/vesa.h>
#endif

#define probe_done(adp)		((adp)->va_flags & V_ADP_PROBED)
#define init_done(adp)		((adp)->va_flags & V_ADP_INITIALIZED)
#define config_done(adp)	((adp)->va_flags & V_ADP_REGISTERED)

/* for compatibility with old kernel options */
#ifdef SC_ALT_SEQACCESS
#undef SC_ALT_SEQACCESS
#undef VGA_ALT_SEQACCESS
#define VGA_ALT_SEQACCESS	1
#endif

#ifdef SLOW_VGA
#undef SLOW_VGA
#undef VGA_SLOW_IOACCESS
#define VGA_SLOW_IOACCESS
#endif

/* architecture dependent option */
#if !defined(__i386__) && !defined(__amd64__)
#define VGA_NO_BIOS		1
#endif

/* this should really be in `rtc.h' */
#define RTC_EQUIPMENT           0x14

{'fraction_non_alphanumeric': 0.11792305286205818, 'fraction_numerical': 0.008341153164424981, 'mean_word_length': 4.518987341772152, 'pattern_counts': {'":': 0, '<': 49, '<?xml version=': 0, '>': 89, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2080812', 'n_tokens_mistral': 3714, 'n_tokens_neox': 3518, 'n_words': 1127}