Commit graph

240 commits

Author SHA1 Message Date
John Baldwin 9dbf5b0e68 new-bus: Remove the 'rid' and 'type' arguments from BUS_RELEASE_RESOURCE
The public bus_release_resource() API still accepts both forms, but
the internal kobj method no longer passes the arguments.
Implementations which need the rid or type now use rman_get_rid() or
rman_get_type() to fetch the value from the allocated resource.

Reviewed by:	imp
Differential Revision:	https://reviews.freebsd.org/D44131
2024-03-13 15:05:54 -07:00
John Baldwin 2baed46e85 new-bus: Remove the 'rid' and 'type' arguments from BUS_*ACTIVATE_RESOURCE
The public bus_activate/deactivate_resource() API still accepts both
forms, but the internal kobj methods no longer pass the arguments.
Implementations which need the rid or type now use rman_get_rid() or
rman_get_type() to fetch the value from the allocated resource.

Reviewed by:	imp
Differential Revision:	https://reviews.freebsd.org/D44130
2024-03-13 15:05:54 -07:00
John Baldwin 1587a9db92 pci_cfgreg: Add a PCI domain argument to the low-level register API
This commit changes the API of pci_cfgreg(read|write) to add a domain
argument (referred to as a segment in ACPI parlance) (note that this
is not the same as a NUMA domain, but something PCI-specific).  This
does not yet enable access to domains other than 0, but updates the
API to support domains.

Places that use hard-coded bus/slot/function addresses have been
updated to hardcode a domain of 0.  A few places that have the PCI
domain (segment) available such as the acpi_pcib_acpi.c Host-PCI
bridge driver pass the PCI domain.

The hpt27xx(4) and hptnr(4) drivers fail to attach to a device not on
domain 0 since they provide APIs to their binary blobs that only
permit bus/slot/function addressing.

The x86 non-ACPI PCI bus drivers all hardcode a domain of 0 as they do
not support multiple domains.

Reviewed by:	imp
Differential Revision:	https://reviews.freebsd.org/D42827
2023-11-29 10:31:47 -08:00
John Baldwin 71ac18a84d agp_amd64: Use <machine/pci_cfgreg.h> rather than bare prototypes
Reviewed by:	imp
Differential Revision:	https://reviews.freebsd.org/D42826
2023-11-29 10:31:16 -08:00
Warner Losh fdafd315ad sys: Automated cleanup of cdefs and other formatting
Apply the following automated changes to try to eliminate
no-longer-needed sys/cdefs.h includes as well as now-empty
blank lines in a row.

Remove /^#if.*\n#endif.*\n#include\s+<sys/cdefs.h>.*\n/
Remove /\n+#include\s+<sys/cdefs.h>.*\n+#if.*\n#endif.*\n+/
Remove /\n+#if.*\n#endif.*\n+/
Remove /^#if.*\n#endif.*\n/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/types.h>/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/param.h>/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/capsicum.h>/

Sponsored by:		Netflix
2023-11-26 22:24:00 -07:00
Warner Losh 031beb4e23 sys: Remove $FreeBSD$: one-line sh pattern
Remove /^\s*#[#!]?\s*\$FreeBSD\$.*$\n/
2023-08-16 11:54:58 -06:00
Warner Losh 685dc743dc sys: Remove $FreeBSD$: one-line .c pattern
Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/
2023-08-16 11:54:36 -06:00
Warner Losh 95ee2897e9 sys: Remove $FreeBSD$: two-line .h pattern
Remove /^\s*\*\n \*\s+\$FreeBSD\$$\n/
2023-08-16 11:54:11 -06:00
Warner Losh 4d846d260e spdx: The BSD-2-Clause-FreeBSD identifier is obsolete, drop -FreeBSD
The SPDX folks have obsoleted the BSD-2-Clause-FreeBSD identifier. Catch
up to that fact and revert to their recommended match of BSD-2-Clause.

Discussed with:		pfg
MFC After:		3 days
Sponsored by:		Netflix
2023-05-12 10:44:03 -06:00
John Baldwin f49fd63a6a kmem_malloc/free: Use void * instead of vm_offset_t for kernel pointers.
Reviewed by:	kib, markj
Sponsored by:	DARPA
Differential Revision:	https://reviews.freebsd.org/D36549
2022-09-22 15:09:19 -07:00
Dimitry Andric c0817e2aba Adjust agp_find_device() definition in agp.c to avoid clang 15 warning
With clang 15, the following -Werror warning is produced:

    sys/dev/agp/agp.c:910:16: error: a function declaration without a prototype is deprecated in all versions of C [-Werror,-Wstrict-prototypes]
    agp_find_device()
                   ^
                    void

This is because agp_find_device() is declared with a (void) argument
list, and defined with an empty argument list. Make the definition match
the declaration.

MFC after:	3 days
2022-07-16 16:46:21 +02:00
Mark Johnston 6b38974085 vm_object: Modify various drivers to allocate OBJT_SWAP objects
This is in preparation for removal of OBJT_DEFAULT.  In particular, it
is now cheap to check whether an OBJT_SWAP object has any swap blocks
allocated, so the benefit of having a separate OBJT_DEFAULT type is
quite marginal, and the OBJT_DEFAULT->SWAP transition is a source of
bugs.

Reviewed by:	alc, hselasky, kib
MFC after:	2 weeks
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D35779
2022-07-12 09:10:15 -04:00
John Baldwin 74f8498190 agp: Remove unused devclass arguments to DRIVER_MODULE. 2022-05-06 15:46:59 -07:00
John Baldwin eb13232e4b agp_nvidia: Replace a dummy variable to force a read with a void cast. 2022-04-08 17:30:14 -07:00
Mark Johnston 437ea82ce7 agp: Handle multiple devices more gracefully
Currently agp(4) effectively assumes that only one driver instance
exists, as the generic attach routine attempts to create /dev/agpgart
and triggers a panic if it already exists.  Instead, handle this
situation by creating /dev/agpgart<unit> and making /dev/agpgart an
alias of /dev/agpgart0 for compatibility.

PR:		187015
Reviewed by:	imp, kib
Tested by:	Yoshihiro Ota <ota@j.email.ne.jp> (earlier version)
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D33068
2021-11-25 11:36:33 -05:00
Mateusz Guzik cfe94aa8c1 agp: plug a set-but-not-unused var in agp_intel_gtt_map_memory
Sponsored by:	Rubicon Communications, LLC ("Netgate")
2021-11-24 16:25:50 +00:00
Ed Maste 9feff969a0 Remove "All Rights Reserved" from FreeBSD Foundation sys/ copyrights
These ones were unambiguous cases where the Foundation was the only
listed copyright holder (in the associated license block).

Sponsored by:	The FreeBSD Foundation
2021-08-08 10:42:24 -04:00
Mateusz Guzik 4ce60b6549 agp: clean up empty lines in .c and .h files 2020-09-01 21:35:39 +00:00
Warner Losh 4f8959b9f4 Remove support for FreeBSD 4.x and earlier from agp driver
Compile tested only, but do we still need this driver?
2020-02-26 19:39:52 +00:00
Mark Johnston b119329d81 Complete the removal of the "wire_count" field from struct vm_page.
Convert all remaining references to that field to "ref_count" and update
comments accordingly.  No functional change intended.

Reviewed by:	alc, kib
Sponsored by:	Intel, Netflix
Differential Revision:	https://reviews.freebsd.org/D21768
2019-09-25 16:11:35 +00:00
Mark Johnston fee2a2fa39 Change synchonization rules for vm_page reference counting.
There are several mechanisms by which a vm_page reference is held,
preventing the page from being freed back to the page allocator.  In
particular, holding the page's object lock is sufficient to prevent the
page from being freed; holding the busy lock or a wiring is sufficent as
well.  These references are protected by the page lock, which must
therefore be acquired for many per-page operations.  This results in
false sharing since the page locks are external to the vm_page
structures themselves and each lock protects multiple structures.

Transition to using an atomically updated per-page reference counter.
The object's reference is counted using a flag bit in the counter.  A
second flag bit is used to atomically block new references via
pmap_extract_and_hold() while removing managed mappings of a page.
Thus, the reference count of a page is guaranteed not to increase if the
page is unbusied, unmapped, and the object's write lock is held.  As
a consequence of this, the page lock no longer protects a page's
identity; operations which move pages between objects are now
synchronized solely by the objects' locks.

The vm_page_wire() and vm_page_unwire() KPIs are changed.  The former
requires that either the object lock or the busy lock is held.  The
latter no longer has a return value and may free the page if it releases
the last reference to that page.  vm_page_unwire_noq() behaves the same
as before; the caller is responsible for checking its return value and
freeing or enqueuing the page as appropriate.  vm_page_wire_mapped() is
introduced for use in pmap_extract_and_hold().  It fails if the page is
concurrently being unmapped, typically triggering a fallback to the
fault handler.  vm_page_wire() no longer requires the page lock and
vm_page_unwire() now internally acquires the page lock when releasing
the last wiring of a page (since the page lock still protects a page's
queue state).  In particular, synchronization details are no longer
leaked into the caller.

The change excises the page lock from several frequently executed code
paths.  In particular, vm_object_terminate() no longer bounces between
page locks as it releases an object's pages, and direct I/O and
sendfile(SF_NOCACHE) completions no longer require the page lock.  In
these latter cases we now get linear scalability in the common scenario
where different threads are operating on different files.

__FreeBSD_version is bumped.  The DRM ports have been updated to
accomodate the KPI changes.

Reviewed by:	jeff (earlier version)
Tested by:	gallatin (earlier version), pho
Sponsored by:	Netflix
Differential Revision:	https://reviews.freebsd.org/D20486
2019-09-09 21:32:42 +00:00
Alan Cox 49bfa624ac Eliminate the arena parameter to kmem_free(). Implicitly this corrects an
error in the function hypercall_memfree(), where the wrong arena was being
passed to kmem_free().

Introduce a per-page flag, VPO_KMEM_EXEC, to mark physical pages that are
mapped in kmem with execute permissions.  Use this flag to determine which
arena the kmem virtual addresses are returned to.

Eliminate UMA_SLAB_KRWX.  The introduction of VPO_KMEM_EXEC makes it
redundant.

Update the nearby comment for UMA_SLAB_KERNEL.

Reviewed by:	kib, markj
Discussed with:	jeff
Approved by:	re (marius)
Differential Revision:	https://reviews.freebsd.org/D16845
2018-08-25 19:38:08 +00:00
Alan Cox 44d0efb215 Eliminate kmem_alloc_contig()'s unused arena parameter.
Reviewed by:	hselasky, kib, markj
Discussed with:	jeff
Differential Revision:	https://reviews.freebsd.org/D16799
2018-08-20 15:57:27 +00:00
Alan Cox 94d0f0877d Oops. r338030 didn't eliminate the unused arena argument from all of
kmem_alloc_attr()'s callers.  Correct that mistake.
2018-08-18 22:35:19 +00:00
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
Mark Johnston 8ee96d1452 Add a helper function to agp(4) which installs a single GTT entry.
Submitted by:	dumbbell
MFC after:	1 week
2017-07-09 22:53:24 +00:00
Pedro F. Giffuni 4d24901ac9 sys/dev: Replace zero with NULL for pointers.
Makes things easier to read, plus architectures may set NULL to something
different than zero.

Found with:	devel/coccinelle
MFC after:	3 weeks
2017-02-20 03:43:12 +00:00
Gleb Smirnoff bfc8c24c73 Move bogus_page declaration to vm_page.h and initialization to vm_page.c.
Reviewed by:	kib
2017-01-04 22:27:19 +00:00
Pedro F. Giffuni d9c9c81c08 sys: use our roundup2/rounddown2() macros when param.h is available.
rounddown2 tends to produce longer lines than the original code
and when the code has a high indentation level it was not really
advantageous to do the replacement.

This tries to strike a balance between readability using the macros
and flexibility of having the expressions, so not everything is
converted.
2016-04-21 19:57:40 +00:00
Pedro F. Giffuni 4ec642f1d6 dev/agp: use our nitems() macro when it is avaliable through param.h.
Consistently capitalize the macros used in the driver.

No functional change.
2016-04-19 23:31:35 +00:00
Jean-Sébastien Pédron 85a60a7756 agp: Do not attach to Intel GEN6+
The i915 video driver doesn't depend on agp(4) anymore for Sandybridge
and later GPUs. Therefore, there is no need to attach agp(4) to those
devices.

While here, fix `agp_i965_res_spec` to include the aperture base for
GEN4 and GEN5.

Reviewed by:	kib
Approved by:	kib
Differential Revision:	https://reviews.freebsd.org/D5586
2016-03-12 09:44:23 +00:00
Jean-Sébastien Pédron 740be6d755 drm/i915: Update to match Linux 3.8.13
This update brings initial support for Haswell GPUs.

Tested by:	Many users of FreeBSD, PC-BSD and HardenedBSD
Relnotes:	yes
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D5554
2016-03-08 20:33:02 +00:00
Kevin Lo 128236c022 Remove break after return. 2015-01-23 15:14:30 +00:00
Konstantin Belousov a537a017e8 Initial attachment of the agp(4) to Haswell IGP. There is no handling
of cacheablility control bits in GTT PTEs yet.

Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
2014-11-11 12:56:30 +00:00
Konstantin Belousov d6fe56e5d7 Based on some BIOS configuration (GGC register in host bridge, bit 1),
IGP may declare subclass as either VGA-compatible, or non-VGA.  The
difference is that in the later case, IGP does not claim VGA cycles.
Other than that, the device functions normally, and agp_i810 should
attach to it.

Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
2014-11-11 12:52:45 +00:00
Konstantin Belousov a41f4046f5 On 965 and higher, map GTT as write-combining.
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
2014-11-11 12:37:13 +00:00
Konstantin Belousov 53dc09a8e6 Revert agp_intel.c part of the r274040 for now. There is a confusion
on my part about north bridge/GPU pci ids and use of aperture.

Leave the agp_intel.c out of static compilation on amd64, it makes the
things consistent with agp.ko.

Pointed out by:	tijl
Sponsored by:	The FreeBSD Foundation
MFC after:	13 days
2014-11-04 09:56:58 +00:00
Konstantin Belousov a0cc5254d9 agp_intel.c provides support for AGP on Intel chipsets from 440/BX to
875.  This intersects with the agp_i810.c, which supports all Intels
from i810 to Core i5/7.  Both agp_intel.c and agp_i810.c are compiled
into kernel when device agp is specified in config, and agp_i810
attach seems to be selected by chance due to linking order.

Strip support for 810 and later from agp_intel.c.  Since 440-class
chipsets do not support any long-mode capable CPUs, remove agp_intel.c
from amd64 kernel file list.  Note that agp_intel.c is not compiled
into agp.ko on amd64 already.

Sponsored by:	The FreeBSD Foundation
MFC after:	2 weeks
2014-11-03 11:49:35 +00:00
Tijl Coosemans 0de6ac2e3c - agp_generic_unbind_memory: flush AGP TLB before unwiring pages
- agp_bind_pages: assert that pages have been wired down

MFC after:	1 month
2014-11-02 11:47:40 +00:00
Tijl Coosemans a8ac51bbb6 In agp_amd_bind_page don't flush the AGP TLB. It's done by the calling
function.
2014-11-02 11:28:15 +00:00
Tijl Coosemans 4e612cddb9 In agp(4) avoid the need to flush all cpu caches with wbinvd between
updating the GTT and flushing the AGP TLB by storing the GTT in
write-combining memory.

On x86 flushing the AGP TLB is done by an I/O operation or a store to a
MMIO register in uncacheable memory.  Both cases imply that WC buffers are
flushed so no memory barriers are needed.

On powerpc there is no WC memory type.  It maps to uncacheable memory and
two stores to uncacheable memory, such as to the GTT and then to an MMIO
register, are strongly ordered, so no memory barriers are needed either.

MFC after:	1 month
2014-11-02 11:26:37 +00:00
Tijl Coosemans cf99ea5d13 Avoid possible overflow in agp_generic_alloc_memory.
MFC after:	1 week
2014-10-30 14:36:27 +00:00
Tijl Coosemans 903fb143cf Add two new functions to the AGP driver KPI to bind/unbind arbitrary sets
of pages into the GTT.

Reviewed by:	kib
MFC after:	1 month
2014-10-30 11:27:03 +00:00
Attilio Rao 3ae10f7477 - Modify vm_page_unwire() and vm_page_enqueue() to directly accept
the queue where to enqueue pages that are going to be unwired.
- Add stronger checks to the enqueue/dequeue for the pagequeues when
  adding and removing pages to them.

Of course, for unmanaged pages the queue parameter of vm_page_unwire() will
be ignored, just as the active parameter today.
This makes adding new pagequeues quicker.

This change effectively modifies the KPI.  __FreeBSD_version will be,
however, bumped just when the full cache of free pages will be
evicted.

Sponsored by:	EMC / Isilon storage division
Reviewed by:	alc
Tested by:	pho
2014-06-16 18:15:27 +00:00
Eitan Adler 7a22215c53 Fix undefined behavior: (1 << 31) is not defined as 1 is an int and this
shifts into the sign bit.  Instead use (1U << 31) which gets the
expected result.

This fix is not ideal as it assumes a 32 bit int, but does fix the issue
for most cases.

A similar change was made in OpenBSD.

Discussed with:	-arch, rdivacky
Reviewed by:	cperciva
2013-11-30 22:17:27 +00:00
Konstantin Belousov 5944de8ecd Remove the deprecated VM_ALLOC_RETRY flag for the vm_page_grab(9).
The flag was mandatory since r209792, where vm_page_grab(9) was
changed to only support the alloc retry semantic.

Suggested and reviewed by:	alc
Sponsored by:	The FreeBSD Foundation
2013-08-22 07:39:53 +00:00
Attilio Rao c7aebda8a1 The soft and hard busy mechanism rely on the vm object lock to work.
Unify the 2 concept into a real, minimal, sxlock where the shared
acquisition represent the soft busy and the exclusive acquisition
represent the hard busy.
The old VPO_WANTED mechanism becames the hard-path for this new lock
and it becomes per-page rather than per-object.
The vm_object lock becames an interlock for this functionality:
it can be held in both read or write mode.
However, if the vm_object lock is held in read mode while acquiring
or releasing the busy state, the thread owner cannot make any
assumption on the busy state unless it is also busying it.

Also:
- Add a new flag to directly shared busy pages while vm_page_alloc
  and vm_page_grab are being executed.  This will be very helpful
  once these functions happen under a read object lock.
- Move the swapping sleep into its own per-object flag

The KPI is heavilly changed this is why the version is bumped.
It is very likely that some VM ports users will need to change
their own code.

Sponsored by:	EMC / Isilon storage division
Discussed with:	alc
Reviewed by:	jeff, kib
Tested by:	gavin, bapt (older version)
Tested by:	pho, scottl
2013-08-09 11:11:11 +00:00
Attilio Rao 89f6b8632c Switch the vm_object mutex to be a rwlock. This will enable in the
future further optimizations where the vm_object lock will be held
in read mode most of the time the page cache resident pool of pages
are accessed for reading purposes.

The change is mostly mechanical but few notes are reported:
* The KPI changes as follow:
  - VM_OBJECT_LOCK() -> VM_OBJECT_WLOCK()
  - VM_OBJECT_TRYLOCK() -> VM_OBJECT_TRYWLOCK()
  - VM_OBJECT_UNLOCK() -> VM_OBJECT_WUNLOCK()
  - VM_OBJECT_LOCK_ASSERT(MA_OWNED) -> VM_OBJECT_ASSERT_WLOCKED()
    (in order to avoid visibility of implementation details)
  - The read-mode operations are added:
    VM_OBJECT_RLOCK(), VM_OBJECT_TRYRLOCK(), VM_OBJECT_RUNLOCK(),
    VM_OBJECT_ASSERT_RLOCKED(), VM_OBJECT_ASSERT_LOCKED()
* The vm/vm_pager.h namespace pollution avoidance (forcing requiring
  sys/mutex.h in consumers directly to cater its inlining functions
  using VM_OBJECT_LOCK()) imposes that all the vm/vm_pager.h
  consumers now must include also sys/rwlock.h.
* zfs requires a quite convoluted fix to include FreeBSD rwlocks into
  the compat layer because the name clash between FreeBSD and solaris
  versions must be avoided.
  At this purpose zfs redefines the vm_object locking functions
  directly, isolating the FreeBSD components in specific compat stubs.

The KPI results heavilly broken by this commit.  Thirdy part ports must
be updated accordingly (I can think off-hand of VirtualBox, for example).

Sponsored by:	EMC / Isilon storage division
Reviewed by:	jeff
Reviewed by:	pjd (ZFS specific review)
Discussed with:	alc
Tested by:	pho
2013-03-09 02:32:23 +00:00
Konstantin Belousov 5f451cd59b Fix reversed condition in the logic to wait for the chipset buffers
flush wait on the Gen2 chipsets.  Confirmed by the inspection of the
Linux agp code.

Submitted by:	Taku YAMAMOTO <taku@tackymt.homeip.net>
MFC after:	2 weeks
2013-01-27 09:31:11 +00:00
Antoine Brodin dfa4d7fdb9 Remove unneeded semicolons.
Reviewed by:	md5 of the object files
2013-01-01 18:16:49 +00:00