Commit graph

2178 commits

Author SHA1 Message Date
cinap_lenrek 1180631421 devswap: improve setswapchan()
- check for unusable file types like directories and append-only files.
- we should eigther error without any side effects or succeed.
2021-10-23 15:12:27 +00:00
cinap_lenrek db971a6189 kernel: fix stat bugs
In a few places, we where using a fixed buffer of sizeof(Dir)+100
size for stat. This is not correct and fails if the name returned
in stat is long.

This results in being unable to seek to the end of file with a
long filename.

The kernel should do the same thing as dirfstat() from libc;
handling the conversion and buffer allocation and returning a
freeable Dir* pointer.

For this, a new dirchanstat() function was added.

The fstat syscall was not rewriting the name to the last path
element; fix it.

In addition, gracefully handle the mountfix case, reallocating
the buffer to accomidate the required stat length plus
size of the new name so dirsetname() does not fail.
2021-10-23 13:40:06 +00:00
cinap_lenrek 72d08816ab devtls: implement "hangup" ctl message
This makes devtls connection directories compatible to
hangup function (see dial(2)).
2021-10-16 15:07:39 +00:00
cinap_lenrek 20429fb04f kernel: call freebroken() for kproc() when out of processes 2021-10-16 13:14:14 +00:00
cinap_lenrek a557c515c8 kernel: dont block allocating kstack for new processes
Have newproc() fail returning nil if we can't allocate
the kernel stack instead of locking up in smalloc().
2021-10-16 13:12:59 +00:00
cinap_lenrek 3fe3e370e3 usbxhci: xhcirecover proc does not need to check status every 10ms
The timing loop is here for the case if the
controller doesnt produce an interrupt when
becoming broken. In normal case, we should
just get worken up from the interrupt.

In any case, 100 times a second polling is
not neccessary here, increase to 1 second.
2021-10-13 16:57:38 +00:00
cinap_lenrek 03d870e028 kernel: return error from sysrfork instead of waiting and retrying
The old strategy of wait and retry doesnt seem to
work very well as it keeps all the forking parents
stuck waiting in the kernel worsening the situation.

The idea with this change is to have rfork() return
error quickly; and without whining; as most callers
would just react with a sysfatal() which might be
better for surviving this.
2021-10-12 11:30:42 +00:00
cinap_lenrek b51d7ca3ba devip: improve tcp error handling for ipoput
The ipoput4() and ipoput6() functions can raise an error(),
which means before calling sndrst() or limbo() (from tcpiput()),
we have to get rid of our blist by calling freeblist(bp).

Makse sure to set the Block pointer to nil after freeing in
ipiput() to avoid accidents.

Fix wrong panic string in sndsynack, and make any sending
functions like sndrst(), sndsynack() and tcpsendka()
return the value of ipoput*(), so we can distinguish
"no route" error.

Add a Enoroute[] string constant.

Both htontcp4() and htontcp6() can never return nil,
as they will allocate new or resize the existing block.
Remove the misleading error handling code that assumes
that it can fail.

Unlock proto on error in limborexmit() which can
be raised from sndsynack() -> ipoput*() -> error().

Make sndsynack() pass a Routehint pointer to ipoput*()
as it already did the route lookup, so we dont have todo
it twice.
2021-10-11 15:55:46 +00:00
cinap_lenrek ad1ab7089d devip: add comment to ip.h explaining Routehint struct 2021-10-11 12:16:21 +00:00
cinap_lenrek 5484260b42 kernel: move waserror() macro to port/portfns.h 2021-10-11 11:52:37 +00:00
cinap_lenrek 365e63b36a devip: properly rlock() the routelock for v4lookup() and v6lookup()
i'm not confident about mutating the route tree
pointers and have concurrent readers walking the
pointer chains.

given that most route lookups are bypassed now
for non-routing case and we are not building a
high performance router here, lets play it safe.
2021-10-10 14:27:08 +00:00
cinap_lenrek e687d25478 devip: use top bit (type) | subnet-id for V6H() route hash macro
theres no structure in the lower 32 bits of an ipv6 address.

use the top bit to distinguish special stuff like multicast
and link-local addresses, and use the 16-bit subnet-id bits
for the rest.
2021-10-10 14:22:14 +00:00
cinap_lenrek 1a6324970d devip: cache arp entry in Routehint
Instead of having to do an arp hash table lookup for each
outgoing ip packet, forward the Routehint pointer to the
medium's bwrite() function and let it cache the arp entry
pointer.

This avoids route and arp hash table lookups for tcp, il
and connection oriented udp.

It also allows us to avoid multiple route and arp table
lookups for the retransmits once an arp/neighbour solicitation
response arrives.
2021-10-09 18:26:16 +00:00
cinap_lenrek 6ebb8b9e35 devip: use better hashipa() macro, use RWlock for arp cache 2021-10-03 15:58:58 +00:00
cinap_lenrek 55c3138c64 kernel: ensure that all accesses to Mhead.mount is done with Mhead.lock acquired
The Mhead structures have two sources of references to them:

- from Pgrp.mnthash hash-table
- from a channels Chan.umh pointer as returned by namec() for a union directory

Unless one holds the Mhead.lock RWLock, the Mhead.mount chain
can be mutated by eigther cmount(), cunmount() or closepgrp().

Readers, skipping acquiering the lock where:

mountfix(): responsible for rewriting directory entries for
union directory reads; was walking the Mhead.mount chain to
detect if the passed channel itself appears in the mount list.

cmount(): had a check and copy when "new" chan was a union itself
and if the MCREATE flag is set and would copy the mount table.
All this needs to be done with Mhead read-locked while copying
the mount entries.

devproc(): in the handler for reading /proc/n/ns file.

namec(): while checking if the Chan->umh should be initialized.

In addition to this, cmount() is changed to do the mountfree()
of the original mount chain when MREPL is done after releasing
the locks.

Also, some cosmetic changes...
2021-10-03 15:56:51 +00:00
cinap_lenrek d43d79bda4 devip: implement ipv4 arp timeout with icmp host unreachable notification
The IPv4 ARP cache used to indefinitely buffer packets in the Arpent hold list.
This is bad in case of a router, because it opens a 1 second
(retransmit time) window to leak all the to be forwarded packets.

This change makes the ipv4 arp code path similar to the IPv6 neighbour
solicitation path, using the retransmit process to time out old entries
(after 3 arp retransmits => 3 seconds).

A new function arpcontinue() has been added that unifies the point when
we schedule the (ipv6 sol retransmit) / (ipv4 arp timeout) and reduce
the hold queue to the last packet and unlock the cache.

As a bonus, we also now send a icmp host unreachable notification
for the dropped packets.
2021-09-26 18:43:29 +00:00
cinap_lenrek 1cff923af4 devtls: fix bwrite memory leak when channel stops being open
tlsbwrite() would call checkstate() before calling tlsrecwrite()
to make sure the channel is open. however, because checkstate()
only raises the error, the Block* passed wont be freed and
would result in a memory leak.

move the checkstate() call inside tlsrecwrite() to reuse the
error handling that frees the block on error.
2021-09-25 20:35:04 +00:00
nessabeene@gmail.com 3ac6d894d7 audiohda: Add DID for Intel 200 Series PCH HD Audio 2021-09-11 12:07:16 +00:00
Ori Bernstein 390abbd1c7 archacpi: leave acpi enabled with *acpi=
*acpi= was treated the same as *acpi=0, when we
want it to be treated the same as *acpi=1
2021-09-13 23:56:26 +00:00
Sigrid Solveig Haflínudóttir 4f310b8f51 devvmx: skip tsc offset writing if CPU doesn't support it 2021-09-13 22:54:05 +00:00
cinap_lenrek d1986d8c0e ether82598: add pci device id for ixgbe i52899 (thanks izaki) 2021-09-09 23:13:30 +00:00
Ori Bernstein d116b2d47c etheriwl: add did for Intel Centrino Advanced-N + WiMAX 6250 (thanks Nessa) 2021-09-05 00:16:22 +00:00
qwx bcdfdab41b ether82563: add pci id for i219-v on t490s 2021-09-04 23:55:20 +00:00
qwx 49b5319f76 audiohda: fix syntax error 2021-08-30 16:55:30 +00:00
Sigrid Solveig Haflínudóttir 7bdcdeafaf audiohda: add ztom z36*/z37* device id 2021-08-29 23:59:45 +00:00
Sigrid Solveig Haflínudóttir ec33d29cf6 ether8169: support rtl8402 variant 2021-08-29 23:12:33 +00:00
Ori Bernstein bcfee7b547 revert 8c228a123fa0c6062570964011854302bbf57242: accidental commit
was testing out the git/import tweaks and accidentally
pushed this commit. No comment on whether we want it,
but it definitely wasn't ready for merge.

Oops.
2021-08-22 17:47:38 +00:00
unobe@cpan.org 8c228a123f mk for only supported archs
http://fqa.9front.org/fqa1.html#1.2 states the supported archs.
However, clean and nuke also remove build files for 0 (spim) and q
(power).  'mk all' using those archs fails; 'mk kernels' also tries to
build all the kernels, even those which are not supported.  For
example, I tried to build the power arch (qc, qa, ql) and without
surprise it failed (when building dtracy): ...
mk dtracy
qc -FTVw dtracy.c
yacc -v -d -D1 parse.y
qc -FTVw cgen.c
qc -FTVw act.c
qc -FTVw type.c
 == regfree ==
REGISTER R0 <11> STRUCT DTAct cgen.c:302
 == regfree ==

REGISTER R0 <11> STRUCT DTAct act.c:266

 == regfree ==
qc -FTVw agg.c
cgen.c:299 unknown type in regalloc: STRUCT DTAct
cgen.c:299 bad opcode in gmove INT -> STRUCT DTAct
cgen.c:302 unknown type in regalloc: STRUCT DTAct
cgen.c:302 bad opcode in gmove INT -> STRUCT DTAct
cgen.c:302 error in regfree: 0 [0]
REGISTERmk: qc -FTVw cgen.c  : exit status=rc 387386: qc 387392: error R0
 <11> STRUCT DTAct act.c:269

act.c:250 unknown type in regalloc: STRUCT DTAct
act.c:250 bad opcode in gmove INT -> STRUCT DTAct
act.c:266 unknown type in regalloc: STRUCT DTAct
act.c:266 bad opcode in gmove INT -> STRUCT DTAct
act.c:266 error in regfree: 0 [0]
act.c:269 unknown type in regalloc: STRUCT DTAct
act.c:269 bad opcode in gmove INT -> STRUCT DTAct
act.c:269 error in regfree: 0 [0]
act.c:274 unknown type in regalloc: STRUCT DTAct
act.c:274 bad opcode in gmove INT -> STRUCT DTAct
act.c:274 error in regfree: 0 [0]
too many errors
mk: for(i in cc ...  : exit status=rc 382748: rc 387379: mk 387381: error
mk: date for (i ...  : exit status=rc 373781: rc 382226: mk 382227: error
cpu%

The patch below skips over non-supported architectures.  Is that
something we want?  This way, 'mk kernels' should work without a
problem (tested on amd64).  Then if someone works on getting those
architectures supported again in the future, they can be added back
in.
2021-08-17 14:00:47 +00:00
Sigrid Solveig Haflínudóttir 4e9f39a3ec ether82563: add 0x15bd i219-lm variant (thanks crab1) 2021-08-16 14:28:59 +00:00
Ori Bernstein a05d656054 qsort: ...forgot to include headers in the commit. 2021-08-11 13:10:14 +00:00
cinap_lenrek 5a15acc7f0 etheriwl: fix botched merge... 2021-08-06 10:05:23 +00:00
cinap_lenrek edfc72b500 [PATCH] Support for igfx on Celeron(R) 2957U (thanks Lorenzo Bivens)
> After some tinkering I managed to get igfx working on this device.
> hw cursor works.
> The only caveat is that I can only get video over hdmi...
> will revisit displayport later
2021-07-31 12:05:29 +00:00
cinap_lenrek 84b77568cd kernel: fix off by one for $cputype buffer (thanks anthony martin) 2021-07-28 22:55:17 +00:00
cinap_lenrek 37f5069426 kernel: increase bootfs.paq compression level and blocksize
With the intel wifi firmware, this saves around 3MB of the
kernel image size.
2021-07-28 00:38:00 +00:00
cinap_lenrek df04ea8d6c kernel: simplify /boot/boot: 28K down to less than 4K.
- avoid print() format routines (saves alot of code)
- avoid useless opens of /dev/cons (already done by initcode)
- avoid useless binds of /env and /dev (already done by initcode)
- do bind of /shr in bootrc, it is not needed by us
- we'r pid 1 so kernel will print the exit message for us
2021-07-27 18:21:08 +00:00
cinap_lenrek e4b5f170cf libc: change usize to 64-bit for amd64 and arm64, make memory(2) functions use usize 2021-07-25 15:54:22 +00:00
cinap_lenrek 8a8329ad95 bcm64: make the kernel use virtual timer counter register for cycles() 2021-07-25 14:12:17 +00:00
cinap_lenrek b7e67e9e36 kernel: page counts a ulong, not usize 2021-07-25 14:03:12 +00:00
cinap_lenrek c38fcb5dc3 arm64: use generic timer virtual counter for cycles()
We used to use performance cycle counter for cycles(),
but it is kind of useless in userspace as each core
has its own counter and hence not comparable between
cores. Also, the cycle counter stops counting when
the cores are idle.

Most callers expect cycles() to return a high resolution
timestamp instead, so do the best we can do here
and enable the userspace generic timer virtual counter.
2021-07-23 15:10:01 +00:00
cinap_lenrek 2c1727e55c /sys/src/9/mkfile: add bcm64 (thanks stuart morrow) 2021-07-22 18:30:38 +00:00
cinap_lenrek 006c4d7ffc archacpi: make *acpi=1 the default 2021-07-15 16:07:54 +00:00
cinap_lenrek 3b1c450cd5 ether82563: add pci id for i219-LM from ThinkPad P17 Gen1 Professional Mobile Workstation (thanks tschak909) 2021-07-15 07:50:56 +00:00
cinap_lenrek 4483500f62 pc, pc64: increase confmem slots to 64
Lenovo Thinkpad P17 Gen1 Professional Mobile Workstation
comes up with around 36 separate memory ranges.

ridiculous!
2021-07-14 17:06:28 +00:00
cinap_lenrek e8259861da virtio: set FeaturesOk flag after feature negotiation, and enable queues before DriverOk flag 2021-07-11 21:49:15 +00:00
cinap_lenrek f58d99aa7a virtio: add non-legacy virtio 1.0 drivers for disk and ethernet
The new interface uses pci capability structures to locate the
registers in a rather fine granular way making it more complicated
as they can be located anywhere in any pci bar at any offset.

As far as i can see, qemu (6.0.50) never uses i/o bars in
non-legacy mode, so only mmio is implemented for now.

The previous virtio drivers implemented the legacy interface only
which uses i/o ports for all register accesses. This is still
the preferred method (and also qemu default) as it is easier to
emulate and most likely faster.

However, some vps providers like vultr force the legacy interface
to disabled with qemu -device option "disable-legacy=on" resulting
on a system without a disk and ethernet.
2021-07-11 11:24:13 +00:00
cinap_lenrek c3589ef3cf kernel: export pcienumcaps() for custom capability enumeration in drivers (virtio)
This used to be a internal function, but virtio
uses multiple structures with the same cap type
to indicate the location of various register
blocks in the pci bars so export it.
2021-07-10 18:34:22 +00:00
cinap_lenrek c848ca6267 devmouse: default to no blanking instead of 30 minute blank timeout 2021-07-01 23:11:11 +00:00
Ori Bernstein c297482269 sdvirtio: accept multi-queue devices
Sdvirtio supports multiple queues per device.
We only use one queue, but we shouldn't skip the
devices because of that.
2021-05-31 10:59:45 -07:00
cinap_lenrek c2297ce5c1 kernel: use 64-bit virtual entry point for expanded header, document behaviour in a.out(6)
For 64-bit architectures, the a.out header has the HDR_MAGIC flag set
in the magic and is expanded by 8 bytes containing the 64-bit virtual
address of the programs entry point. While Exec.entry contains physical
address for kernel images.

Our sysexec() would always use Exec.entry, even for 64-bit a.out binaries,
which worked because PADDR(entry) == entry for userspace pointers.

This change fixes it, having the kernel use the 64-bit entry point
and document the behaviour in the manpage.
2021-05-29 14:18:35 +02:00
cinap_lenrek 15b903c4e1 pc64: avoid getcr3() in mmuflushtlb()
it turns out that calculating physical address of pml4 is faster
than reading the machine register, so pass it explicitely.
2021-05-12 22:40:51 +02:00
cinap_lenrek 18b3847aef devvmx: remove unncessary locking in gotcmd() sleep test function 2021-05-12 22:24:36 +02:00
cinap_lenrek c0d4498ab8 kernel: clean up Mach structure
Remove unused fields and factor common fields into a
new PMach struct in port/portdat.h.

The fields machno, splpc and proc are not moved to
PMach as they are part of the known offsets from
assembly (l.s).
2021-04-25 17:41:34 +02:00
cinap_lenrek 9f54c28317 bcm: try ATAGS/DTB pointer from R2 on entry 2021-04-25 17:36:11 +02:00
Sigrid 192c1fd73a nusbrc: rndis with csp 0104ef 2021-04-20 18:12:54 +02:00
cinap_lenrek 52a367f3ea devloopback: fix wrong device character (thanks romano)
devloopback was changed from using #X to #λ awhile ago; one bit was missed.
2021-04-18 16:20:04 +02:00
cinap_lenrek 777b1949b2 nusbrc: ignore rndis ethernet in /rc/bin/nusbed, handled by /sys/src/9/boot/nusbrc (thanks romano) 2021-04-08 21:57:24 +02:00
cinap_lenrek 295acd7e0d kernel: get rid of physical page bank array and use conf.mem[] instead
We can take advantage of the fact that xinit() allocates
kernel memory from conf.mem[] banks always at the beginning
of a bank, so the separate palloc.mem[] array can be eleminated
as we can calculate the amount of non-kernel memory like:

upages = cm->npage - (PGROUND(cm->klimit - cm->kbase)/BY2PG)

for the number of reserved kernel pages,
we provide the new function: ulong nkpages(Confmem*)

This eleminates the error case of running out of slots in
the array and avoids wasting memory in ports that have simple
memory configurations (compared to pc/pc64).
2021-04-02 20:23:25 +02:00
Romano a398a09783 [9front] [patch] nusb/ether -t rndis 2021-04-01 12:54:08 +02:00
cinap_lenrek a2ebe5c79a devfs: fix locking and ignore undocumented "fsdev:\n" configuration signature
The confstr was shared between readers so seprintconf() could
write concurrently to that buffer which is not safe.

This replaces the shared static confstr[Maxconf] buffer with a
pointer that is initially nil and a buffer that is alloced on
demand.

The new confstr pointer (and buffer) is now only updated while
wlock()ed from the new setconfstr() function.

This is now done by mconfig() / mdelctl() just before releasing
the wlock.

Now, rdconf() will check if confstr has been initialized, and
test for it again while wlock()ed; making sure the configuration
is read only once.

Also, rdconf() used to check for a undocumented "fsdev:\n" string
at the beginning of config data tho that was never documented.

This changes mconfig() to ignore that particular signature so
the example from the manpage will work as documented.
2021-03-31 17:49:10 +02:00
cinap_lenrek 3841a46421 kernel: remove ucalloc.c duplicates 2021-03-13 14:57:53 +01:00
cinap_lenrek 7c62c12701 kernel: use 64-bit mask to avoid compiler warning in port/pci.c 2021-03-13 14:20:00 +01:00
cinap_lenrek a0404ff582 devpccard, pci: fix pccard support and handle pci expansion roms
let pci.c deal with the special cardbus controller bar0 and
expansion roms.

handle apic interrupt routing for devices behind a cardbus slot.

do not free the pcidev on card removal, as the drivers
most certanly are not prepared to handle this yet.
instead, we provide a pcidevfree() function that just unlinks
the device from pcilist and the parent bridge.
2021-03-01 17:24:54 +01:00
cinap_lenrek be782ef435 bcm: change color chan to RGB24 (thanks p.kosyh)
p.kosyh writes:

Hello!  I finally bought rpi4 4Gb specially for 9front. It seems,
that default bpp of framebuffer is 16.  I changed it to 24 (via
cmdline.txt and config.txt) and found, that rendering is much faster!
(May be due removing overheads in 16->24 conversions?)

But on rpi4 r and b channels are swapped.  So, i changed BGR24 to
RGB24 in bcm/screen.c and now it works fine!
2021-02-28 13:31:49 +01:00
cinap_lenrek dab168e6bd ether82563: add pci id for i219-LM on thinkcenter (easypeasy, thanks hiro) 2021-02-20 19:06:59 +01:00
cinap_lenrek 8b817fd6c0 pc/devarch: use m->cpumhz instead of recalculatin it 2021-02-20 13:08:59 +01:00
cinap_lenrek d5f9514304 merge 2021-02-06 13:50:06 +01:00
cinap_lenrek efcfdd23d7 bcm64: get inbound and outbound pci window base address from device tree
On the pi400, the xhci reset firmware mailbox request
assumes that the pci windows match the ones specified
in the device tree. The inbound window (pcidmawin)
also varies now depending on the amount of memory
installed.

It is all pretty ridiculous, as the firmware could as
well just read the pci controllers hardware register
to determine the window configuration and the os could
keep a nice simple 1:1 mapping (with pci dma addresses
== physical addresses).
2021-02-06 13:47:45 +01:00
cinap_lenrek 0e381493bf pc: increase number of Conf.mem[] entries from 4 to 16 2021-02-06 13:33:58 +01:00
cinap_lenrek e9af397dc7 pc, pc64: warn when running out of conf.mem[] entries in meminit() 2021-02-06 13:33:27 +01:00
Michael Forney 49220af76e [9front] [PATCH] audiohda: add PCI ID for Intel C610/X99
---
Tested and seems to work fine.
2021-02-03 16:19:57 -08:00
cinap_lenrek 081f98de6c audiohda: Add AMD Starship/Matisse HD Audio Controller (thanks uramekus) 2021-01-18 00:51:20 +01:00
cinap_lenrek a05bab362f pc, pc64: add minimal HPET driver to measure LAPIC and TSC frequencies
This adds the new function pointer PCArch.clockinit(),
which is a timer dependent initialization routine.
It also takes over the job of guesscpuhz(). This way, the
architecture ident code can switch between different
timers (i8253, HPET and XEN timer).
2021-01-17 21:21:12 +01:00
cinap_lenrek 999e98b9b8 usbehci: use 64-bit base address, remove resetlck, simplify scanpci() 2021-01-17 11:55:39 +01:00
cinap_lenrek 3240008dd1 usbuhci: remove resetlk, simplify scanpci() 2021-01-17 11:53:50 +01:00
cinap_lenrek 87b1d454ed usbohci: use 64-bit io base address, disable interrupts before reset, remove resetlck 2021-01-17 11:51:59 +01:00
cinap_lenrek 069d27ba1d pc, pc64: revert addition of pcireset() call to pcicfginit()
Revert the change, as it causes system lockups on bootup
on some systems with USB OHCI controllers, suspected to be
caused by BIOS/SMM accessing the device as BIOS handover
has not been executed yet.

We might bring that back when the problem has is better
understood.
2021-01-10 20:44:58 +01:00
cinap_lenrek 806353ec9e devvga: implement screen tilting, remove panning and overlays
Tilting allows using left/right rotated or invetrted display orientation.
This can be changed at runtime such as: echo tilt right > /dev/vgactl
This removes the old panning and vga overlays as they are only implemented
with some ancient vga controllers.
2020-12-27 23:08:59 +01:00
cinap_lenrek ab103ba349 devproc: allow anyone to change user of its own processes to "none" 2020-12-23 13:09:31 +01:00
cinap_lenrek f11526708e kw: use ethermii.c from port/ (thanks stuart) 2020-12-22 22:17:44 +01:00
cinap_lenrek 29f60cace1 kernel: avoid palloc lock during mmurelease()
Previously, mmurelease() was always called with
palloc spinlock held.

This is unneccesary for some mmurelease()
implementations as they wont release pages
to the palloc pool.

This change removes pagechainhead() and
pagechaindone() and replaces them with just
freepages() call, which aquires the palloc
lock internally as needed.

freepages() avoids holding the palloc lock
while walking the linked list of pages,
avoding some lock contention.
2020-12-22 16:29:55 +01:00
cinap_lenrek 0ad4ceb8d0 kernel: make addbroken() static, remove misleading Proc* argument 2020-12-21 22:03:46 +01:00
cinap_lenrek 5a059477f8 pc, xen: move fpu setup/fork/save/restore handlers to pc/fpu.c 2020-12-21 15:04:48 +01:00
cinap_lenrek 932995bb27 kernel: update procsave() comment, we'r not holding up->rlock anymore 2020-12-21 14:41:10 +01:00
cinap_lenrek e4ce6aadac kernel: handle tos and per process pcycle counters in port/
we might as well handle the per process cycle
counter in the portable part instead of duplicating the code
in every arch and have inconsistent implementations.

we now have a portable kenter() and kexit() function,
that is ment to be used in trap/syscall from user,
which updates the counters.

some kernels missed initializing Mach.cyclefreq.
2020-12-20 22:34:41 +01:00
cinap_lenrek 58e6750401 kernel: remove Proc* argument from procsetuser() function 2020-12-19 18:07:12 +01:00
cinap_lenrek d919ad3b5e devsons: remove #c/pgrpid
The process group id is essentially a unique id
of the namespace but it was never well documented
nor is it used by any program.
2020-12-19 14:59:19 +01:00
cinap_lenrek 646c502b15 ether2114x: make sure pci bar0 is I/O 2020-12-17 21:02:11 +01:00
cinap_lenrek 318fe6a702 ether2114x: vetting the driver for pc64
the tulip driver is used in microsofts hypver-v
as the legacy ethernet adapter for pxe booting.

to make the driver work on pc64, we need to
store the Block* pointers in a separate array
instead of stuffing them into buffer address 2
of the hardware descriptor.

also, enable the driver in the pc64 kernel.
2020-12-17 20:55:59 +01:00
cinap_lenrek 0b33b3b8ad kernel: implement per file descriptor OCEXEC flag, reject ORCLOSE when opening /fd, /srv and /shr
The OCEXEC flag used to be maintained per channel,
making it shared between all the file desciptors.

This has a unexpected side effects with regard to
channel passing drivers such as devdup (/fd),
devsrv (/srv) and devshr (/shr).

For example, opening a /srv file with OCEXEC
makes it impossible to be remounted by exportfs
as it internally does a exec() to mount and
re-export it. There is no way to reset the flag.

This change makes the OCEXEC flag per file descriptor,
so a open with the OCEXEC flag only affects the fd
group of the calling process, and not the channel
itself.

On rfork(RFFDG), the per file descriptor flags get
copied.

On dup(), the per file descriptor flags are reset.

The second modification is that /fd, /srv and /shr
should reject the ORCLOSE flag, as the files that
are returned have already been opend.
2020-12-13 16:04:09 +01:00
cinap_lenrek b2b2d2cb4c sdiahci: assume 64-bit PCIWADDR() 2020-12-12 18:16:06 +01:00
cinap_lenrek 5ea540e75d sdiahci: enable pci busmaster before ahciconfigdrive() (fix qemu crash)
enable pci busmaster before set the fis-receive-enable
bit in the port command register.

not doing so triggers a crash in qemu like:

address_space_unmap: Assertion `mr != NULL' failed.

as qemu tries to process the dma command list as soon
as we set that flag and busmaster dma needs to be enabled
at this point.
2020-12-12 18:00:41 +01:00
cinap_lenrek fc0f08c651 pc, pc64: make sure write combining is supported in MTRR's before setting it 2020-12-11 15:23:03 +01:00
cinap_lenrek 658c994cff pc, pc64: ignore MTRR's when MTRRCap.vcnt and MTRRCap.fix are zero
Bhyve returns 0 in MTRRCap register, so we
can use that instead on relying on cpuid only
to see if MTRR's are supported.

That way we can get rid of the sanity check
in memory.c.
2020-12-11 15:21:44 +01:00
cinap_lenrek cef91f23e7 pc, pc64: work around bhyve all uncached MTRR's 2020-12-10 01:47:19 +01:00
cinap_lenrek 8efbd243e1 pc, pc64: cleanup cpuidentify() and some comments 2020-12-08 16:58:41 +01:00
cinap_lenrek b2ffb6ccc5 pc, pc64: add *nomtrr= kernel parameter 2020-12-08 16:34:36 +01:00
cinap_lenrek 263dc8093d pc64: preserve reserved bits in CR0/CR4 for amd64 in mtrr setstate()
On AMD64, CR0/CR4 are 64-bit registers, with
the upper half reserved. So use uintptr type
to store the register values to get 32 bit on 386
and 64 bit on AMD64.
2020-12-08 16:00:57 +01:00
cinap_lenrek 01eb04060b pc: move ldmxcsr() prototype to fpu.c 2020-12-08 12:42:36 +01:00
Sigrid 3d9abd96ae devmouse: remove redundant check 2020-12-08 11:21:18 +01:00
cinap_lenrek 23b52bbf23 pc64: assign fpsave/fprestore only once in fpuinit() 2020-12-06 22:05:00 +01:00
cinap_lenrek cd38d41356 pc64: AMD64 mandates SSE support, remove the check in fpuinit() 2020-12-06 21:44:26 +01:00
cinap_lenrek dcdb2bfb9a xen: use pc/fpu.c 2020-12-06 21:28:11 +01:00
cinap_lenrek 8c1bde46f0 pc, pc64: move all fpu specific code from main.c to fpu.c 2020-12-06 21:07:30 +01:00
Sigrid dbbae6d384 xen: fix for the last avx changes 2020-12-06 20:28:53 +01:00
Sigrid 97b3291533 amd64: FP: back to static size for allocation and copying 2020-12-06 19:40:57 +01:00
Sigrid 334c5e1134 amd64: FP: always use enough to fit AVX state and align to 64 bytes 2020-12-06 19:31:56 +01:00
Sigrid 66b6185845 amd64, vmx: support avx/avx2 for host/guest; use *noavx= in plan9.ini to disable 2020-12-06 18:48:32 +01:00
cinap_lenrek abcc56afef pc/dma, pc/sdide: use uintptr for physical address instead of ulong 2020-12-05 17:01:24 +01:00
cinap_lenrek 178a9d12c6 pc, pc64: allocate dma bounce buffer right after xinit() 2020-12-05 16:59:30 +01:00
cinap_lenrek 99696c414a pc, pc64: exclude memory regions with unusual MTRR cache attributes
Use the MTRR registers to exclude memory ranges that
do not have the expected cache attributes:

RAM -> writeback
UMB -> uncached
UPA -> uncached
2020-12-05 16:57:12 +01:00
cinap_lenrek 1d93a5628a pc, pc64, xen: rewrite interrupt handling code
This implements proper intrdisable() support for all
interrupt controllers.

For enable, (*arch->intrassign)(Vctl*) fills in the
Vctl.enable and Vctl.disable pointers with the
appropriate routines and returns the assigned
vector number.

Once the Vctl struct has been linked to its vector
chain, Vctl.enable(Vctl*, shared) gets called with a
flag if the vector has been already enabled (shared).

This order is important here as enabling the interrupt
on the controller before we have linked the chain can
cause spurious interrupts, expecially on mp system
where the interrupt can target a different cpu than
the caller of intrenable().

The intrdisable() case is the other way around.
We first disable the interrupt on the controller
and after that unlink the Vctl from the chain.
On a multiprocessor, the xfree() of the Vctl struct
is delayed to avoid freeing it while it is still
in use by another cpu.

The xen port now also uses pc/irq.c which has been
made generic enougth to handle xen's irq scheme.
Also, archgeneric is now a separate file to avoid
pulling in dependencies from the 8259 interrupt
controller code.
2020-11-29 17:43:22 +01:00
cinap_lenrek a041c90431 pc, pc64: move common irq handling code out of trap.c
Move the common irq handling code out of trap.c
into pc/irq.c so that it can be shared between 386
and amd64 ports.
2020-11-22 17:44:21 +01:00
cinap_lenrek 6dd605dbe2 pc, pc64: fix grub multiboot
It appears that our IDT overlaps with the data structures
passed from grub in multiboot load.

So defer setup of the interrupt table after the multiboot
parameters have been processed.
2020-11-21 23:15:19 +01:00
cinap_lenrek b438fd9d09 ether8169: fix interrupt panic before init, defer initialization until attach
The driver used to register the interrupt handler just
after reset, tho the Ctlr struct, including the buffer
descriptor arrays where only allocated on attach.

This moves most of the reset/init out of pnp
function and into attach. This also means we can
error out and even retry on the next attach.

The logic of the reseter kproc has been changed:
now it is only started once the first initialization
completely succeeded. This avoids the strange qlock
passing.

Implement a shutdown function so the device gets
halted for /dev/reboot.

Assume 64 bit physical addresses for dma.

Check that pci bar0 is actually I/O.
2020-11-21 22:03:13 +01:00
cinap_lenrek 0f56fefd45 pc, pc64: implement disabling of msi interrupts 2020-11-21 21:48:25 +01:00
cinap_lenrek 2594b99629 pc, pc64: new MTRR code supporting AMD TOM2 MSR and fixed mtrr ranges
The new MTRR code handles overlapping ranges
and supports AMD specific TOM2 MSR.

The format in /dev/archctl now only shows
the effective cache ranges only, without
exposing the low level registers.
2020-11-21 16:26:46 +01:00
cinap_lenrek e6684dbfda pc, pc64: disable all pci devices for /dev/reboot
Make sure all pci busmaster activity is disabled,
including MSI/MSI-X interrupts, before switching
control to the new kernel.
2020-11-21 16:17:20 +01:00
cinap_lenrek c5d08a602c pc, pc64: disable all pci devices in pcicfginit()
Make sure all pci busmaster activity is disabled,
including MSI/MSI-X interrupts. Drivers will later
reenable once taking control of a device.
2020-11-21 16:10:56 +01:00
cinap_lenrek 1376d39ef1 kernel: add portable pcimsienable()/pcimsidisable(), disable MSI/MSI-X on pcidisable()/pcireset()
This avoids some duplication in the pci support code and
allows pcireset() to diable MSI and MSI-X interrupts
when disabling or reseting a device.
2020-11-21 16:02:21 +01:00
cinap_lenrek cedded7b50 etherm10g: remove duplicated pci capability enum 2020-11-21 00:45:44 +01:00
cinap_lenrek da54e4bfc2 kernel: remove unused pcinextcap() function 2020-11-21 00:41:57 +01:00
cinap_lenrek 9f054063ec pc/l.s: remove unsued m0gdtptr/m0idtptr structs 2020-11-21 00:06:55 +01:00
cinap_lenrek 972f95aa63 pc, pc64: load idt early in trapinit0()
loading the interrupt vector table early allows
us to handle traps during bootup before mmuinit()
which gives better diagnostics for debugging.

we also can handle general protection fault on
rdmsr() and wrmsr() which helps during
cpuidentify() and archinit() when probing for
cpu features.
2020-11-17 23:30:09 +01:00
cinap_lenrek 8cb33f2f18 pc/l.s: load virtual gdt pointer after mmu switch
before removing the double map at 0, load our
initial gdt pointer with its new KZERO based
virtual address.

this is prerequisite for handling traps early during
bootup before mmuinit() loads the final gdt.
2020-11-17 23:18:08 +01:00
cinap_lenrek 3f835565d5 etheriwl: bring back recovery on flushq timeout 2020-11-15 14:54:09 +01:00
cinap_lenrek 2a946b24a6 audiohda: do not enable interrupts before intrenable()
When using /dev/reboot, the MSI vecor might have already
been setup causing interrupts to fire on the designated
cpu while we send the commands to the card.
2020-11-15 14:34:17 +01:00
cinap_lenrek 0c846e605b audiohda: reset irbsts bits in hdainterrupt() (thanks LordCreepity)
reseting irbsts bits in hdacmd() only works
while interrupts are disabled during hdareset().
once interrupts are enabled we need to reset the
irbsts bits in the interrupt handler or else the
interrupt never clears and locks up the system.
2020-11-11 00:55:53 +01:00
cinap_lenrek 6cc223ee56 pc/pc64: fix faulty mtrr slot reuse (thanks Fulton)
The change 3306:c5cf77167bfe made the code reuse MTRR slots
of the default memory type.

But this did not take overlapping ranges into account!

If two or more variable-range MTRRs overlap, the following rules apply:

a.	If the memory types are identical, then that memory type is used.
b.	If at least one of the memory types is UC, then UC memory type is used.
c.	If at least of of the memory types is WT. and the only other memory type
	is WB, then th WT memory type is used.
d.	If the combination of memory types is not listed above,
	then the memory type used in undefined.

It so happend that on a Dell Latitude E7450 that the BIOS defines
the default type as UC. and the first slot defines a 16GB range
of type WB. Then the rest of the ranges mark the PCI space back
as UC, but overlapping the first WB range! This works because
of rule (B) above.

When trying to make the framebuffer write-combining, we would
falsely reuse one of the UC sub-ranges and making the UC memory
into WB as a side effect.

Thanks to Fulton for his patience and providing debug logs and
doing experiments for us to narrow the problem down.
2020-11-04 23:08:52 +01:00
cinap_lenrek 0ba91ae22a pc, pc64: allocate i/o port space for unassigned pci bars, move ioalloc() to port/iomap.c
With some newer UEFI firmware, not all pci bars get
programmed and we have to assign them ourselfs.

This was already done for memory bars. This change
adds the same for i/o port space, by providing a
ioreservewin() function which can be used to allocate
port space within the parent pci-pci bridge window.

Also, the pci code now allocates the pci config
space i/o ports 0xCF8/0xCFC so userspace needs to
use devpnp to access pci config space now. (see
latest realemu change).

Also, this moves the ioalloc()/iofree() code out
of devarch into port/iomap.c as it can be shared
with the ppc mtx kernel.
2020-11-03 20:46:09 +01:00
cinap_lenrek aad55ccc2d mtx: fix pci access routines (see changeset 8012:78891f472fbf) 2020-11-02 20:53:20 +01:00
cinap_lenrek 0205392410 audiohda: make it work with qemu (thanks mischief)
the driver was not using irb interrupts
and was just polling the irb write pointer
to wait for command completion.

this is not supported by qemu.

qemu requires the use of irb interrupt handshake
and it refuses to accept the next command until we
acknowledge the irb interrupt.
2020-10-27 15:16:03 +01:00
cinap_lenrek 87385accde sdiahci: accept AHCI controllers from ASMedia vendor id (thanks mischief) 2020-10-19 01:20:29 +02:00
cinap_lenrek a5764f8181 pc, pc64: remove mystery "type" bits in pcicfgrw*raw() (fixes qemu, thanks mischief)
the access functions for pci config space in config mode #1
used to set bit 0 in the register offset if the access was
to a device on any bus different from 0.

it is completely unclear why this was done and i can't find
any documentation on this.

but for sure, this breaks all pci config spacess access to
pci devices behind a bridge on qemu. with -trace pci* it
was discovered that all config space register offsets on
devies behind pci brige where off by one.

on real hardware, setting bit 0 in the offset doesnt appear
to be an issue.

thanks mischief for reporting and providing a qemu demo
configuration to reproduce the problem.
2020-10-18 23:39:07 +02:00
cinap_lenrek d1604b5f9c sdnvme: use PCIWADDR() instead of PADDR() 2020-10-18 17:02:42 +02:00
cinap_lenrek 96e9f3707c etherbcm: handle 64-bit host addresses, use PCIWADDR() instead of PADDR() 2020-10-18 17:01:50 +02:00
cinap_lenrek 30417c12fd audiohda: use PCIWADDR() instead of PADDR(), handle 64-bit dma addresses 2020-10-18 17:00:04 +02:00
Ori Bernstein 83efe2f157 etheriwl: delay before crystal calibration
On my 6235 card, if we calibrate the crystal
immediately after disabling wimax, the the
firmware gets unhappy. A short nap before
sending the command prevents the command from
timing out.
2020-10-18 10:50:07 -04:00
cinap_lenrek 3cfa8326b8 etheriwl: don't break controller on command flush timeout
ori and echoline are reporting regression on some 6000 cards;
which sometimes time out on crystal calibration command;
which is expected by the driver. but the new code used
to force a device reset on any command timeout.

reverting to old behaviour until for now until we have
a chance investigating.
2020-10-18 03:05:35 +02:00
cinap_lenrek cf8ff0e713 sdnvme: handle machines with more cpu's than submit queues (thanks mischief)
We used to assume a 1:1 pairing of processors to submit queues.
With recent machines, we now got more cpu cores than what some
nvme drives support so we need to distribute the queues across
these cpu's which requires locking on command submission.

There is a feature get/set command to probe the number of submit
and completion queues, but we decided to just handling
submission queue create command error gracefully as it is simpler
and has less chance of regression with existing setups.

Thanks to mischief for investigating and writing the code.
2020-10-18 02:51:32 +02:00
cinap_lenrek c7598b18f3 kernel: get rid of unused ucallocb
the whole idea of a ucallocb() is bad, as even access to the
metadata header would be in uncached memory. also, it tuns out
that it was never used by anyone.
2020-10-09 22:05:32 +02:00
Ori Bernstein 53234798c0 etheriwl: add Wireless 8260 card
After the latest tweaks to the order of operations,
the card works.
2020-10-05 14:10:12 -07:00
cinap_lenrek d49b9e1b84 etheriwl: remove stations *after* disabling binding quotas, drain all queues in rxoff7000() 2020-10-05 22:42:13 +02:00
cinap_lenrek 2aff96f17c etheriwl: add for Intel Wireless-AC 9260
the 9000 series uses a new receive descriptor format
wich appears to reqire 4k aligned buffers. the old
format "halfworks" and just makes the firmware not
respond to any commands after the enable paging command.

the smartfifo command appears to causes problems.
but apparently not issuing it at all seems to work
fine on both the 8265 and 9260. so removing the code
for now.

issuing the bindingquota command before associated
makes association impossible. but enabling afterwards
works fine. (tested in 8265 and 9260).

the prph access functions now mask the address with
0xfffff. it is unclear why linux and openbsd drivers
specify addresses beyond that in ther register constants.

the timeevent change is interesting. the timeevent
needs to be restarted when it has stoped to make sure
probing/association packets are sent during the evnet.
2020-10-04 21:10:53 +02:00
kvik fa1d6ffd83 bootrc: allow kbmap to be set via plan9.ini (thanks Aaron Bieber) 2020-10-01 17:47:52 +02:00
cinap_lenrek 4f85115526 kernel: massive pci code rewrite
The new pci code is moved to port/pci.[hc] and shared by
all ports.

Each port has its own PCI controller implementation,
providing the pcicfgrw*() functions for low level pci
config space access. The locking for pcicfgrw*() is now
done by the caller (only port/pci.c).

Device drivers now need to include "../port/pci.h" in
addition to "io.h".

The new code now checks bridge windows and membars,
while enumerating the bus, giving the pc driver a chance
to re-assign them. This is needed because some UEFI
implementations fail to assign the bars for some devices,
so we need to do it outselfs. (See pcireservemem()).

While working on this, it was discovered that the pci
code assimed the smallest I/O bar size is 16 (pcibarsize()),
which is wrong. I/O bars can be as small as 4 bytes.
Bit 1 in an I/O bar is also reserved and should be masked off,
making the port mask: port = bar & ~3;
2020-09-13 20:33:17 +02:00
cinap_lenrek 693485e9c4 etheriwl: add support for Intel Wireless AC 8265 2020-09-06 16:53:39 +02:00
cinap_lenrek a87b6909bc wifi: add packet timestamping support 2020-09-06 16:51:02 +02:00
cinap_lenrek 603d9812a7 kernel: fix Abind cyclic reference and mounthead leaks (thanks Alex Musolino)
The Abind case in namec() needs to cunique() the chan
before attaching the umh mount head pointer onto it.

This is because we cannot give a reference to the mount
head to any of the mh->mount...->to channels, as they
will never go away until the mount head goes away.
This is a cyclic reference.

This could be reproduced with:

	@{rfork n; mount -a '#s/boot' /mnt/root; bind /mnt/root /}

Also, fix memory leaks around cunique(), which can
error, leaking the mount head we got from domount().

Move the umh != nil check inside cunique().
2020-08-23 05:07:30 +02:00
cinap_lenrek e1da4f1750 kernel: don't strip binaries in bootfs.paq 2020-08-04 16:31:24 +02:00
cinap_lenrek d913f652f5 devmnt: print chanpath for unexpected reply tag 2020-08-04 16:23:22 +02:00