Commit Graph

79 Commits

Author SHA1 Message Date
Pedro F. Giffuni
718cf2ccb9 sys/dev: further adoption of SPDX licensing ID tags.
Mainly focus on files that use BSD 2-Clause license, however the tool I
was using misidentified many licenses so this was mostly a manual - error
prone - task.

The Software Package Data Exchange (SPDX) group provides a specification
to make it easier for automated tools to detect and summarize well known
opensource licenses. We are gradually adopting the specification, noting
that the tags are considered only advisory and do not, in any way,
superceed or replace the license texts.
2017-11-27 14:52:40 +00:00
Konstantin Belousov
be4bf62684 Write-combine framebuffer writes through user-space mappings, if possible.
Note that KVA mapping of the framebuffer already uses write-combining
mode, so the change, besides improving speed of user mode writes, also
satisfies requirement of the IA32 architecture of using consistent
caching modes for multiple mappings of the same page.

Reported and tested by:	bde
Sponsored by:	The FreeBSD Foundation
MFC after:	 1 week
2017-04-20 15:18:15 +00:00
Bruce Evans
ecb56aaf60 Attempt to determine the modes in which 8-bit wide characters are actually
9 wide.

I only need this to improve the mouse cursor, but it has always been
needed to select and/or adjust fonts.

This is complicated because there are no standard parameter tables
giving this bit of information directly, and the device register bit
giving the information can't be trusted even if it is read from the
hardware.  Use a heuristic to guess if the device register can be
trusted.  (The device register is normally read from the BIOS mode
table, but on my system where the device register is wrong, the mode
table doesn't match the hardware and is not used; the device registers
are used in this case.)
2017-04-20 13:46:55 +00:00
Bruce Evans
3a98d83edb Reset the DAC to 6-bit mode before calling the BIOS to set the screen
mode.  This works around bugs in at least 2 Intel BIOSes for our
subsequent setting of the DAC back to 8-bit mode.  The bug caused dark
(mostly 1/4-intensity) colors for all except the first setting to a
VESA graphics mode (including for settings to the current mode).

Remove restoration (with less bits) of the palette in vesa_unload()
after resetting the DAC to 6-bit mode.  Depend on the BIOS to keep
the palette consistent with the DAC for the simpler reset case like
we do everywhere else in places that are actually important.

Setting the video mode should reset everything to defaults, although
we usually don't want that.  Even the buggy BIOSes set the DAC to the
default 6-bit mode, and set the palette to a default that matches the
DAC.  We don't undo the reset for most things, but we do undo it for
the DAC (more precisely, we change to an 8-bit DAC if possible, and
this is the only way that we set to an 8-bit DAC; it is accidental
that if the DAC was in 8-bit mode from a previous mode switch then
setting it to 8-bit mode is an undo).  The buggy BIOSes are confused
by our setting of the DAC to 8-bit mode in the "undo" case.  They
should multiply palette entries by 4 to match, but they actually leave
all palette entries except #2 (green) and #248-255 (unused) untouched.
Green is mysteriously scaled from 0x2a to 0x6a, and #248-255 are scaled
correctly.

Our support for the 8-bit DAC had almost no effect except to enable
bugs.  Syscons barely supports 16 colors, so it doesn't benefit much
from having a palette with 16 million colors instead of only 256K.
Applications can manage the palette using FBIO_{GET,SET}PALETTE, but
the palette managed by this is only used in the less interesting modes
(text and non-truecolor graphics modes up to 8 bits wide), and the
kernel loses the changes on any mode switch (including to another vt
in a different mode).
2017-04-02 08:39:32 +00:00
John Baldwin
ab59c4d9f1 Use MTX_SYSINIT for the VESA lock.
vesa_init_done isn't a reliable guard for the mutex init.  If
vesa_configure() doesn't find valid VESA info it will not set
vesa_init_done, but the lock will remain initialized.  Revert r303076
and use MTX_SYSINIT to deterministically init the lock.

Reviewed by:	royger
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D7290
2016-07-23 14:38:09 +00:00
Roger Pau Monné
c397b61ea5 vesa: fix panic on suspend
Fix the following panic seen when migrating a FreeBSD guest on Xen:

panic: mtx_lock() of destroyed mutex @ /usr/src/sys/dev/fb/vesa.c:541
cpuid = 0
KDB: stack backtrace:
db_trace_self_wrapper() at db_trace_self_wrapper+0x2b/frame 0xfffffe001d2fa4f0
vpanic() at vpanic+0x182/frame 0xfffffe001d2fa570
kassert_panic() at kassert_panic+0x126/frame 0xfffffe001d2fa5e0
__mtx_lock_flags() at __mtx_lock_flags+0x15b/frame 0xfffffe001d2fa630
vesa_bios_save_restore() at vesa_bios_save_restore+0x78/frame 0xfffffe001d2fa680
vga_suspend() at vga_suspend+0xa3/frame 0xfffffe001d2fa6b0
isavga_suspend() at isavga_suspend+0x1d/frame 0xfffffe001d2fa6d0
bus_generic_suspend_child() at bus_generic_suspend_child+0x44/frame
[...]

This is caused because vga_sub_configure (which is called if the VGA adapter
is attached after VESA tried to initialize), points to vesa_configure, which
doesn't initialize the VESA mutex. In order to fix it, make sure
vga_sub_configure points to vesa_load, so that all the needed vesa
components are properly initialized.

Sponsored by:		Citrix Systems R&D
MFC after:		3 days
PR:			209203
Reviewed by:		dumbbell
Differential revision:	https://reviews.freebsd.org/D7196
2016-07-20 09:29:39 +00:00
Alexander Motin
0f85a96bbf Fix NULL-dereference panic if VESA reports zero modes.
MFC after:	1 week
2016-05-17 19:00:09 +00:00
Pedro F. Giffuni
4ed3c0e713 sys: Make use of our rounddown() macro when sys/param.h is available.
No functional change.
2016-04-30 14:41:18 +00:00
Pedro F. Giffuni
323b076e9c sys: use our nitems() macro when param.h is available.
This should cover all the remaining cases in the kernel.

Discussed in:	freebsd-current
2016-04-21 19:40:10 +00:00
Hans Petter Selasky
af3b2549c4 Pull in r267961 and r267973 again. Fix for issues reported will follow. 2014-06-28 03:56:17 +00:00
Glen Barber
37a107a407 Revert r267961, r267973:
These changes prevent sysctl(8) from returning proper output,
such as:

 1) no output from sysctl(8)
 2) erroneously returning ENOMEM with tools like truss(1)
    or uname(1)
 truss: can not get etype: Cannot allocate memory
2014-06-27 22:05:21 +00:00
Hans Petter Selasky
3da1cf1e88 Extend the meaning of the CTLFLAG_TUN flag to automatically check if
there is an environment variable which shall initialize the SYSCTL
during early boot. This works for all SYSCTL types both statically and
dynamically created ones, except for the SYSCTL NODE type and SYSCTLs
which belong to VNETs. A new flag, CTLFLAG_NOFETCH, has been added to
be used in the case a tunable sysctl has a custom initialisation
function allowing the sysctl to still be marked as a tunable. The
kernel SYSCTL API is mostly the same, with a few exceptions for some
special operations like iterating childrens of a static/extern SYSCTL
node. This operation should probably be made into a factored out
common macro, hence some device drivers use this. The reason for
changing the SYSCTL API was the need for a SYSCTL parent OID pointer
and not only the SYSCTL parent OID list pointer in order to quickly
generate the sysctl path. The motivation behind this patch is to avoid
parameter loading cludges inside the OFED driver subsystem. Instead of
adding special code to the OFED driver subsystem to post-load tunables
into dynamically created sysctls, we generalize this in the kernel.

Other changes:
- Corrected a possibly incorrect sysctl name from "hw.cbb.intr_mask"
to "hw.pcic.intr_mask".
- Removed redundant TUNABLE statements throughout the kernel.
- Some minor code rewrites in connection to removing not needed
TUNABLE statements.
- Added a missing SYSCTL_DECL().
- Wrapped two very long lines.
- Avoid malloc()/free() inside sysctl string handling, in case it is
called to initialize a sysctl from a tunable, hence malloc()/free() is
not ready when sysctls from the sysctl dataset are registered.
- Bumped FreeBSD version to indicate SYSCTL API change.

MFC after:	2 weeks
Sponsored by:	Mellanox Technologies
2014-06-27 16:33:43 +00:00
Jung-uk Kim
10f1472e41 Reduce diff against stable/9 slightly. 2013-08-28 20:10:56 +00:00
Jung-uk Kim
663593f19f Do not save/restore video memory if we are not using linear frame buffer.
Note this partially revert r233896.
2013-08-28 19:06:22 +00:00
Jung-uk Kim
b1bba126f0 Make sure to free stale buffer before allocating new one for safety. 2013-08-28 18:13:37 +00:00
Jung-uk Kim
7afb475f63 Avoid unnecessary signedness conversion. 2013-08-28 17:58:30 +00:00
Jung-uk Kim
ba9855e380 Limit the amount of video memory we map for the driver to the maximum value.
This basically restores the spirit of r203535, which was partially reverted
in r205557, while we still map fixed amount to work around transient issues
we experienced with r203535.

Prodded by:	avg
Tested by:	avg
MFC after:	1 week
2013-03-27 18:06:28 +00:00
Jung-uk Kim
4db9b6c3c6 Save and restore VGA display memory between suspend and resume. 2012-04-04 22:02:54 +00:00
Jung-uk Kim
4c7a7f266f Do not copy VESA state buffer if the VBE call has failed for any reason.
Do not unnecessarily clear the state buffer before calling the function.
2012-04-04 21:38:26 +00:00
Jung-uk Kim
cd283487cc Do not reuse the previous address when restoring linear frame buffer. 2012-03-19 17:14:12 +00:00
Jung-uk Kim
9f5242849d Save and restore linear frame buffer between suspend and resume.
MFC after:	1 week
2012-03-17 00:00:33 +00:00
Jung-uk Kim
0b01dbd70b Remove unnecessary static variable initializations and duplicate codes.
Consistently use bcopy(9) over memcpy(9).
2012-03-16 23:54:23 +00:00
Jung-uk Kim
b1a499f3d8 Do not unnecessarily clear display memory when switching modes.
MFC after:	3 days
2012-03-16 19:22:29 +00:00
Jung-uk Kim
7e330e8220 If the VBE implementation does not support save/restore function, defer to
VGA methods.  Unconditionally reset the VESA adapter before restoring state.
2012-02-23 20:54:22 +00:00
Jung-uk Kim
e7d5cd47c5 Update my copyright date. 2012-02-23 19:16:05 +00:00
Jung-uk Kim
257e5645da Probe supported states for save/restore function. Some VBE implementation
refuses to save/restore states if an unsupported bit is set.
2012-02-23 19:05:57 +00:00
Jung-uk Kim
3dd6e888c0 Fix a typo introduced in r231843. 2012-02-23 18:59:32 +00:00
Jung-uk Kim
1556e63481 Set the initial mode for the adapter after executing VESA BIOS POST.
There is no need to set initial mode for BIOS.
2012-02-16 22:51:44 +00:00
Jung-uk Kim
2f18ee9d47 Make sure the VESA mode number is between 256 and 511 inclusive. 2012-02-16 22:46:00 +00:00
Ed Schouten
6472ac3d8a Mark all SYSCTL_NODEs static that have no corresponding SYSCTL_DECLs.
The SYSCTL_NODE macro defines a list that stores all child-elements of
that node. If there's no SYSCTL_DECL macro anywhere else, there's no
reason why it shouldn't be static.
2011-11-07 15:43:11 +00:00
Jung-uk Kim
f6ff063a6e Fix segment:offset calculation of interrupt vector for relocated video BIOS
when the original offset is bigger than size of one page.  X86BIOS macros
cannot be used here because it is assumed address is only linear in a page.

Tested by:	netchild
2010-09-13 19:58:46 +00:00
Jung-uk Kim
90017de999 Disable video ROM shadowing by default as I originally intended. I found
a case where video ROM for an IGP is too tightly coupled with system BIOS
to get relocated.
2010-09-02 17:22:12 +00:00
Jung-uk Kim
c74dea9cc1 Make sure the interrupt entry point is within the video ROM range. We must
not change interrupt vector if it is not pointing the ROM itself.  Actually,
we just fail shadowing altogether if that is the case because the shadowed
copy will be useless for sure and POST may not be relocatable or useful.
While I'm here, fix a debugging message under bootverbose, really.  r211829
fixed one case but broke another.  Mea Culpa.
2010-08-31 20:21:52 +00:00
Jung-uk Kim
2b13785931 Fix a debugging message under bootverbose. This address is not linear. 2010-08-25 22:48:18 +00:00
Jung-uk Kim
a73f383ee9 Add an experimental feature to shadow video BIOS. Long ago, this trick was
supported by many BIOSes to improve performance of VESA BIOS calls for real
mode OSes but it is not our intention here.  However, this may help some
platforms where the video ROMs are inaccessible after suspend, for example.
Note it may consume up to 64K bytes of contiguous memory depending on video
controller model when it is enabled.  This feature can be disabled by
setting zero to 'debug.vesa.shadow_rom' loader tunable via loader(8) or
loader.conf(5).  The default is 1 (enabled), for now.
2010-08-25 22:09:02 +00:00
Jung-uk Kim
90f06c5eae Protect shared palette and state buffer with a mutex. Remove defunct
spltty() calls while I am here.
2010-08-07 05:46:04 +00:00
Jung-uk Kim
708358cdb6 Initialize a variable before its use. 2010-07-13 19:58:06 +00:00
Jung-uk Kim
917b850dce Preallocate buffers for palette and state. Do not save DAC registers as
we reset DAC mode and restore palette data while we are resuming always.
2010-07-13 19:48:20 +00:00
Jung-uk Kim
061b7e5463 Plug a possible memory leak.
Submitted by:	Yamagi Burmeister (lists at yamagi dot org)
2010-07-06 18:08:55 +00:00
Jung-uk Kim
c3cbd4125e Fix a possible null pointer dereference. A patch for -STABLE was
Submitted by:	Yamagi Burmeister (lists at yamagi dot org)
2010-07-06 18:05:05 +00:00
Jung-uk Kim
28ef508f86 Use M_WAITOK for VESA BIOS initialization consistently. 2010-06-23 23:34:56 +00:00
Jung-uk Kim
362487c0ba Let x86bios_alloc() pass contigmalloc(9) flags. Use it to set M_WAITOK
from VESA BIOS initialization.  All other malloc(9) uses in the function is
blocking any way.
2010-06-23 17:20:51 +00:00
Jung-uk Kim
a46dd0b9e2 Restore the previous VESA mode after BIOS POST, just in case. 2010-05-18 22:30:55 +00:00
Jung-uk Kim
842795abcc Remove unnecessary pointer increment. A wrong pointer may be passed to
free(9) and it can cause kernel panic when there are multiple graphics
controllers in the system.

Tested by:	Brandon Gooch (jamesbrandongooch at gmail dot com)
MFC after:	3 days
2010-05-18 18:28:17 +00:00
Jung-uk Kim
004e8bae43 Allocate memory for VBE info block with malloc(9), not as static local. 2010-04-07 21:38:42 +00:00
Jung-uk Kim
bb6ba5f6b9 Do not penalize correct or correctable VESA mode tables by calling another
VBE function.  Most problems should be corrected by the mode table sanity
check and we only need the paranoid in extremely rare cases.
2010-03-25 17:51:05 +00:00
Jung-uk Kim
1e161437f8 Teach VGA framebuffer about 8-bit palette format for VESA. 2010-03-24 15:37:47 +00:00
Jung-uk Kim
b266b96af9 Add my copyright here. It seems I have contributed enough code. :-) 2010-03-23 23:19:23 +00:00
Jung-uk Kim
3b56b13e8e Be extremely careful when we determine bytes per scan line information.
First, we compare mode table data against minimum value.  If the mode table
does not make sense, we set the minimum in the mode info.  When we actually
set the mode, we try VESA BIOS function and compare it against the previous
value.  If it makes more sense, update the information.
2010-03-23 23:10:17 +00:00
Jung-uk Kim
51cb3184fd Fall back to VGA palette functions if VESA function failed and DAC is still
in 6-bit mode.  Although we have to check non-VGA compatibility bit here,
it seems there are too many broken VESA BIOSes out to rely on it.
2010-03-23 22:50:22 +00:00