On Wed, Jul 9, 2025 at 7:12 PM Andrius V <vezh...@gmail.com> wrote: > > Hi, > > I need some advice on how to manage the development of our viapcib > (lacks a man page) and viaenv (https://man.netbsd.org/viaenv.4) > drivers. > > These two drivers are somewhat related, as they both pertain to the > bus control and power management device controller (with SMBus > support), but they support different sets of chipsets. > > The viaenv(4) driver supports two older chipsets, the VT82C686A and > VT8231. It maps the power management I/O space, which, as far as I > currently understand, is used only to enable the device timecounter > (though I see potential to hook in sysctl options). The VT8231 also > features hardware monitoring, which is integrated through envstat. > This hardware monitor appears to be specific to this chipset only; > newer or older ones don't seem to have it, according to the > datasheets. Since the VT8231 was used in the PowerPC-based Pegasos II, > the driver is located in the architecture-independent dev/pci path. > > viapcib(4) is currently configured for the VT8235, VT8237(R), and > VT8237A. It maps the SMBus host I/O space and allows its control over > the iic framework. This driver is currently placed under the i386 > architecture. Since it's supported across all newer VIA chipsets, my > plan was to move it to x86 and add all of them to its identification. > > In reality, viaenv(4) chipsets also support SMBus under the same > device. At the same time, newer chipsets do support the power > management controller (with timecounter enabling control). The > difference is that older chipsets would have a separate device > function, while newer ones merged into function 0, the same as the > PCI-ISA bus. Additionally, this device may have more features > depending on the chipset (e.g., GPIO control), which could be > controlled and potentially added in the future (though these devices > are quite obsolete now, so it may never happen). > > Given all the above, I'd like to understand the best way forward: > > 1) Keep everything as is, just move viapcib(4), add a man page, and > perhaps copy the power management controller code to it (this doesn't > seem very relevant currently, as I believe the same timecounter is > attached using ACPI). Advantage of this approach that there's no need > to think how to attach device, same base address can be used between > all devices (no conditions for older chipsets). Minimal work is > required. viaenv(4) stays as is. > > 2) Move smbus code to viaenv(4) and attach to PCI or (via)pcib > depending on the chipset. The problem is the different base addresses > between old and "new" chipsets, conditionals or flags are needed, but > otherwise, viaenv code works on newer chipsets with minimal > adjustments. Also problem, that I don't have hardware for older > chipsets, can't test them. The advantage are smbus support for all, > code in one place. And it can be made as module I believe. > > 3) Separate drivers even more by function into "pseudo" devices such > as viapm, viasmb, viahwm, and viagpio, and attach them all somehow to > the same pci/viapcib? Handle them as required by the chipset. > Advantages I would see that user can control more what he needs, also > can be added as modules, driver are smaller and focused on "one > thing". > > 4) Please suggest... > > Please see some data from my experiments below. > > Timecounters if viaenv is attached: > > kern.timecounter.choice = TSC(q=-100, f=1600059000 Hz) > clockinterrupt(q=0, f=100 Hz) lapic(q=-100, f=200007000 Hz) > viaenv0(q=1000, f=3579545 Hz) hpet0(q=2000, f=14318180 Hz) > ACPI-Fast(q=1000, f=3579545 Hz) i8254(q=100, f=1193182 Hz) > dummy(q=-1000000, f=1000000 Hz) > > (take notice that viaenv and ACPI-Fast timecounters seem to be the > same ones, or at least they share same frequency and quality) > > viaenv from dmesg (adjusted for VX900 with a few changes (mainly > adjusting base addresses) and disabled viapcib/pcib so it would attach > to pci): > > viaenv0 at pci0 dev 17 function 0: VIA Technologies VX900 Power > Management Controller > timecounter: Timecounter "viaenv0" frequency 3579545 Hz quality 1000 > viaenv0: 24-bit timer > > viapcib dmesg with adjustments (moving to x86, adding to amd64 kernel > config, updating identification) and attaching spdmem (attaching > spdmem slows down boot considerably, taking time to get memory info): > > ECS VX900-I > viapcib0 at pci0 dev 17 function 0: VIA Technologies VX900 Bus Control > and Power Management (rev. 0x00) > viapcib0: SMBus found at 0x400 (revision 0x0) > iic0 at viapcib0: I2C bus > spdmem0 at iic0 addr 0x50: M0820031 > spdmem0: DDR3 SDRAM, no ECC, no temp-sensor, 1GB, 1067MHz (PC3-8533) > spdmem0: 13 rows, 10 cols, 8 log. banks, 2 phys. banks, 1.875ns cycle time > spdmem0: tAA-tRCD-tRP-tRAS: 7-7-7-20 > spdmem0: 1.5V operable > spdmem1 at iic0 addr 0x51: M0820031 > spdmem1: DDR3 SDRAM, no ECC, no temp-sensor, 1GB, 1067MHz (PC3-8533) > spdmem1: 13 rows, 10 cols, 8 log. banks, 2 phys. banks, 1.875ns cycle time > spdmem1: tAA-tRCD-tRP-tRAS: 7-7-7-20 > spdmem1: 1.5V operable > > Current code for reference: > https://nxr.netbsd.org/xref/src/sys/dev/pci/viaenv.c > nxr.netbsd.org/xref/src/sys/arch/i386/pci/viapcib.c > > Side question, iic devices were not available by default in /dev/. > Manual execution of MAKEDEV iic was required. Is it expected? > > Regards, > Andrius V
I guess I will try to rephrase my question with the hope to get some answers. It was not specifically about these two VIA drivers but more about the driver(s) design: How to write driver(s) for the device which: 1) has multipurpose registers to control different devices. 2) can connect to pci or pcib. 3) some controlled devices overlap and are backwards compatible between chipsets (smbus, iic, power management, gpio, etc) 4) some can have chipset specific devices to control (like hw monitor on VT8231) 5) newer chipsets may have more devices to control than older. 6) some controls may need to be exposed over sysctl. Regards, Andrius V