Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
2a8222b
working si_identify method
gummybuns Apr 24, 2026
1b4f438
got a char driver for gba to work
gummybuns Apr 24, 2026
03ded0a
refactored to have a common send for siiobuf
gummybuns Apr 28, 2026
9a69c81
refactor __siiobuf_send
gummybuns Apr 29, 2026
119611a
wip playing with multiboot
gummybuns May 12, 2026
ecdb265
trying to implement ioctl
gummybuns May 13, 2026
2d57051
return 0
gummybuns May 13, 2026
716db9c
actually got userland program with ioctl to work
gummybuns May 14, 2026
e44cc2e
got a multiboot solution to actually work
gummybuns May 17, 2026
725badc
starting to clean up
gummybuns May 18, 2026
22b526d
refactor the send routines and multiboot protocol
gummybuns May 19, 2026
a4fbc68
the great cleanup has begun
gummybuns May 28, 2026
afa5416
move to a generic gcport char device
gummybuns May 28, 2026
5d0b8e4
add a mutex and some todos
gummybuns May 29, 2026
7f72f91
remove a todo
gummybuns May 29, 2026
34a1839
remove a todo
gummybuns May 29, 2026
b95949c
device minor number reflects physical port
gummybuns May 31, 2026
6db34e6
rename a variable and try to get makedev to work
gummybuns May 31, 2026
b38e970
i think i need to include the actual calls in all
gummybuns May 31, 2026
b72303a
Update sys/arch/evbppc/nintendo/dev/si.c
gummybuns Jun 2, 2026
48ec656
update hierarchy si0 -> gcport -> uhid
gummybuns Jun 3, 2026
d38b8e1
got interrupt controller identification to work
gummybuns Jun 4, 2026
618f85c
it is not working but worth comitting
gummybuns Jun 6, 2026
a8e0c57
got workqueue to work
gummybuns Jun 6, 2026
34a4b1c
removed delay from the si_send
gummybuns Jun 6, 2026
ecc4b90
tried to handle todo
gummybuns Jun 7, 2026
376f879
Update sys/arch/evbppc/conf/NINTENDO
gummybuns Jun 7, 2026
4ca6ca6
Update sys/arch/evbppc/nintendo/dev/uhid_si.c
gummybuns Jun 7, 2026
c5a9209
Update sys/arch/evbppc/nintendo/dev/uhid_si.c
gummybuns Jun 7, 2026
b568099
update workqueue_create to use proper args
gummybuns Jun 7, 2026
1327b6a
remove the gcport_si softintr
gummybuns Jun 7, 2026
d3fd1a6
move send logic to si.c
gummybuns Jun 7, 2026
d0114a5
improve si_send / ioctl
gummybuns Jun 8, 2026
ef00c2e
fix si_print
gummybuns Jun 8, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions etc/etc.evbppc/MAKEDEV.conf
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ all_md)
makedev radio
makedev kttcp
makedev xlcom0
makedev gcport0 gcport1 gcport2 gcport3
makedev cfs
makedev virtio
;;
Expand All @@ -32,3 +33,8 @@ xlcom[0-9]*)
unit=${i#xlcom}
mkdev xlcom$unit c 99 $unit "" "" $u_uucp
;;

gcport[0-3]*)
unit=${i#gcport}
mkdev gcport$unit c 100 $unit "" "" $u_uucp
;;
Comment on lines +37 to +40

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

havent really been able to test this piece yet. still trying to figure out how to rebuild the MAKEDEV file i am guessing requires me to build a new img

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try $TOOLDIR/bin/nbmake-evbppc MAKEDEV from src/etc

6 changes: 5 additions & 1 deletion sys/arch/evbppc/conf/NINTENDO
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,11 @@ options WSDISPLAY_MULTICONS

ahb0 at mainbus0 irq 14
si0 at mainbus0 addr 0x0d006400 irq 3 # Serial interface
uhid* at si0
gcport* at si0
uhid0 at gcport0
uhid1 at gcport1
uhid2 at gcport2
uhid3 at gcport3
exi0 at mainbus0 addr 0x0d006800 irq 4 # External interface
rtcsram0 at exi0 # RTC/SRAM chip
gecko0 at exi0 # USB Gecko
Expand Down
2 changes: 2 additions & 0 deletions sys/arch/evbppc/conf/majors.evbppc
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ device-major twe char 76 twe
#device-major obsolete char 98 obsolete (nsmb)
device-major xlcom char 99 xlcom

device-major gcport char 100

# Majors up to 143 are reserved for machine-dependent drivers.
# New machine-independent driver majors are assigned in
# sys/conf/majors.
9 changes: 7 additions & 2 deletions sys/arch/evbppc/nintendo/dev/files.dev
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,16 @@ attach gecko at exi
file arch/evbppc/nintendo/dev/gecko.c gecko needs-flag

define si { }
device si: si, hid
device si: si
attach si at mainbus
file arch/evbppc/nintendo/dev/si.c si

attach uhid at si with uhid_si
define gcport { }
device gcport: gcport, hid
attach gcport at si with gcport_si
file arch/evbppc/nintendo/dev/gcport_si.c gcport_si

attach uhid at gcport with uhid_si
file arch/evbppc/nintendo/dev/uhid_si.c uhid_si

define ahb { [addr=-1], [irq=-1] }
Expand Down
277 changes: 277 additions & 0 deletions sys/arch/evbppc/nintendo/dev/gcport_si.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,277 @@
/* $NetBSD: gcport_si.c,v 1.0 2026/05/18 22:54:30 gummybuns Exp $ */

/*-
* Copyright (c) 2026 ZacBrown <gummybuns@protonmail.com>
* 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.
* 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.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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>
__KERNEL_RCSID(0, "$NetBSD: gcport_si.c,v 1.0 2026/05/18 22:53:30 gummybuns Exp $");

#include <sys/bus.h>
#include <sys/conf.h>
#include <sys/device.h>
#include <sys/ioccom.h>
#include <sys/kmem.h>
#include <sys/mutex.h>
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/tty.h>
#include <sys/types.h>

#include <dev/usb/usb.h>
#include <dev/hid/uhid.h>

#include "si.h"
#include "joybus.h"

struct si_payload {
uint32_t insize; /* bytes to receive. max 128 */
uint32_t outsize; /* bytes to send. max 128 */
uint32_t *status; /* sisr status for this channel */
void *in; /* buffer to store response */
void *out; /* buffer to send out to device */
};

extern struct cfdriver gcport_cd;

#define SI_SEND _IOWR(0, 1, struct si_payload)

static int gcport_si_match(device_t, cfdata_t, void *);
static void gcport_si_attach(device_t, device_t, void *);
static int gcport_si_print(void *, const char *);
static int gcport_si_rescan(device_t, const char *, const int *);
static int siioctl_send(struct si_channel *ch, struct si_payload *sp);
static void gcport_si_work(struct work *, void *);

dev_type_open(gcport_open);
dev_type_close(gcport_close);
dev_type_ioctl(gcport_ioctl);

const struct cdevsw gcport_cdevsw = {
.d_open = gcport_open,
.d_close = gcport_close,
.d_ioctl = gcport_ioctl,
.d_read = noread,
.d_write = nowrite,
.d_stop = nostop,
.d_tty = notty,
.d_poll = nopoll,
.d_mmap = nommap,
.d_kqfilter = nokqfilter,
.d_discard = nodiscard,
.d_flag = D_OTHER
};

CFATTACH_DECL_NEW(gcport_si, sizeof(struct gcport_softc),
gcport_si_match, gcport_si_attach, NULL, NULL);

static int
gcport_si_match(device_t parent, cfdata_t cf, void *aux)
{
return 1;
}

static void
gcport_si_attach(device_t parent, device_t self, void *aux)
{
struct si_softc * const psc = device_private(parent);
struct si_attach_args * const saa = aux;
struct gcport_softc * const sc = device_private(self);
struct si_channel *ch = &psc->sc_chan[saa->saa_index];
int err;

sc->sc_dev = self;
sc->ch = ch;
sc->sc_bst = psc->sc_bst;
sc->sc_bsh = psc->sc_bsh;
ch->ch_gcport_dev = self;

err = workqueue_create(&ch->ch_wqp, "gcport", gcport_si_work, ch,
PRI_NONE, IPL_VM, 0);
if (err != 0) {
aprint_normal("gcport_si: ch%d failed to create workqueue\n",
ch->ch_index);
ch->ch_wqp = NULL;
}
gcport_si_rescan(self, NULL, NULL);
}

static int
gcport_si_print(void *aux, const char *pnp)
{
struct si_attach_args *saa = aux;

if (pnp != NULL) {
aprint_normal("uhid at %s", pnp);
}

/*
* The Wii Operations Manual for RVL-001 refers to the controller
* ports as "Nintendo GameCube Controller Sockets".
*/
aprint_normal(" socket %d", saa->saa_index + 1);

return UNCONF;
}

int
gcport_open(dev_t dev, int flags, int mode, struct lwp *l)
{
struct gcport_softc *sc;
struct si_channel *ch;
int error;

sc = device_lookup_private(&gcport_cd, minor(dev));

if (sc == NULL) {
return ENXIO;
}

ch = sc->ch;
mutex_enter(&ch->ch_lock);

if (ISSET(ch->ch_state, SI_STATE_OPEN)) {
error = EBUSY;
goto unlock;
}

ch->ch_state |= SI_STATE_OPEN;
error = 0;
unlock:
mutex_exit(&ch->ch_lock);
return error;
}

int
gcport_close(dev_t dev, int flags, int mode, struct lwp *l)
{
struct gcport_softc *sc = device_lookup_private(&gcport_cd, minor(dev));
struct si_channel *ch = sc->ch;

mutex_enter(&ch->ch_lock);
ch->ch_state &= ~(SI_STATE_OPEN | SI_STATE_STOPPED);

/* cv_init is called in parent's si_attach */
cv_broadcast(&ch->ch_cv);

mutex_exit(&ch->ch_lock);
return 0;
}

static int
gcport_si_rescan(device_t self, const char *ifattr, const int *locs)
{
struct si_attach_args saa;
unsigned is_gcpad;
int res;
device_t uhid_dev;
struct gcport_softc * const gsc = device_private(self);
struct si_channel *ch = gsc->ch;
struct si_softc *sc = ch->ch_sc;

ch->ch_id = si_identify(sc, ch->ch_index);
is_gcpad = IS_GCPAD(ch->ch_id);

if (is_gcpad && ch->ch_uhid_dev == NULL) {
saa.saa_hidev = &ch->ch_hidev;
saa.saa_index = ch->ch_index;
uhid_dev = config_found(self, &saa, gcport_si_print, CFARGS_NONE);
ch->ch_uhid_dev = uhid_dev;
} else if (!is_gcpad && ch->ch_uhid_dev != NULL) {
res = config_detach_children(ch->ch_gcport_dev, 0);
if (res == 0) {
ch->ch_uhid_dev = NULL;
}
}

return 0;

}

void gcport_si_work(struct work *wk, void *arg)
{
struct si_channel *ch = arg;
gcport_si_rescan(ch->ch_gcport_dev, NULL, NULL);
}

int
gcport_ioctl(dev_t dev, u_long cmd, void *data, int flag, struct lwp *l)
{
struct gcport_softc *sc = device_lookup_private(&gcport_cd, minor(dev));
struct si_channel *ch = sc->ch;
int err;

switch(cmd) {
case SI_SEND:
err = siioctl_send(ch, (struct si_payload *)data);
break;
default:
err = EINVAL;
break;
}

return err;
}

static int
siioctl_send(struct si_channel *ch, struct si_payload *p)
{
int err, outsize_r, insize_r;
struct si_softc *sc;
struct siio_send sd;

err = 0;
sc = ch->ch_sc;

/* siiobuf must to be written in increments of 4 bytes */
outsize_r = roundup(p->outsize, 4);
insize_r = roundup(p->insize, 4);

sd.out = kmem_zalloc(outsize_r, KM_SLEEP);
sd.in = kmem_zalloc(insize_r, KM_SLEEP);
sd.chan = ch->ch_index;
sd.outsize = p->outsize;
sd.insize = p->insize;

if ((err = copyin(p->out, sd.out, sd.outsize)) != 0) {
goto si_send_cleanup;
}

if ((err = si_send(sc, &sd)) != 0) {
goto si_send_cleanup;
}

if ((err = copyout(sd.in, p->in, sd.insize)) != 0) {
goto si_send_cleanup;
}

if ((err = copyout(&sd.status, p->status, sizeof(uint32_t))) != 0) {
goto si_send_cleanup;
}
si_send_cleanup:
kmem_free(sd.out, outsize_r);
kmem_free(sd.in, insize_r);
return err;
}
Loading