Skip to content
Open
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
35 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
58d9eaf
did the whole thing again pretty much
gummybuns Jun 12, 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

4 changes: 4 additions & 0 deletions sys/arch/evbppc/conf/NINTENDO
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@ options WSDISPLAY_MULTICONS
ahb0 at mainbus0 irq 14
si0 at mainbus0 addr 0x0d006400 irq 3 # Serial interface
uhid* at si0
gcport0 at si0
gcport1 at si0
gcport2 at si0
gcport3 at si0
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.
4 changes: 4 additions & 0 deletions sys/arch/evbppc/nintendo/dev/files.dev
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ file arch/evbppc/nintendo/dev/si.c si
attach uhid at si with uhid_si
file arch/evbppc/nintendo/dev/uhid_si.c uhid_si

device gcport
attach gcport at si with gcport_si
file arch/evbppc/nintendo/dev/gcport_si.c gcport_si

define ahb { [addr=-1], [irq=-1] }
device ahb: ahb
attach ahb at mainbus
Expand Down
233 changes: 233 additions & 0 deletions sys/arch/evbppc/nintendo/dev/gcport_si.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,233 @@
/* $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 */
long delay; /* delay the transaction (microsec) */
};

extern struct cfdriver gcport_cd;
struct gcport_softc {
device_t sc_dev;
struct si_channel *ch;
bus_space_tag_t sc_bst;
bus_space_handle_t sc_bsh;
};


#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 siioctl_send(struct si_channel *ch, struct si_payload *sp);

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)
{
struct si_softc * const sc = device_private(parent);
struct si_attach_args * const saa = aux;
struct si_channel *ch;
int unit;
unsigned chan;

chan = saa->saa_index;
ch = &sc->sc_chan[chan];
unit = cf->cf_unit;

if (chan == unit && ch->ch_id != 0 && !(IS_GCPAD(ch->ch_id))) {
aprint_normal("gcport: identified ch%d as a device 0x%08X\n",
chan, ch->ch_id);
return 1;
}

return 0;
}

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];

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

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;
}

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;
struct si_softc *sc;
struct siio_send sd;

err = 0;
sc = ch->ch_sc;
if (p->outsize > SIIOBUF_SIZE || p->insize > SIIOBUF_SIZE) {
return EINVAL;
}

sd.chan = ch->ch_index;
sd.outsize = p->outsize;
sd.insize = p->insize;
sd.out = kmem_alloc(p->outsize, KM_SLEEP);
sd.in = kmem_alloc(p->insize, KM_SLEEP);
sd.delay = p->delay;

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, sd.outsize);
kmem_free(sd.in, sd.insize);
return err;
}
71 changes: 71 additions & 0 deletions sys/arch/evbppc/nintendo/dev/joybus.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/* $NetBSD: joybus.h,v 1.0 2026/05/18 22:54:30 gummybuns Exp $ */

/*-
* Copyright (c) 2026 Zac Brown <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.
*/

#ifndef _JOYBUS_H_
#define _JOYBUS_H_

#include <sys/param.h>
#include "si.h"

#define JB_WIRELESS __BIT(15)
#define JB_WIRELESS_RECV __BIT(14)
#define JB_RUMBLE __BIT(13)
#define JB_CONTROLLER __BIT(11)
#define JB_WIRELESS_TYPE __BIT(10)
#define JB_WIRELESS_STATE __BIT(9)
#define JB_DOLPHIN __BIT(8)
#define JB_WIRELESS_ORIGIN __BIT(5)
#define JB_WIRELESS_FIXID __BIT(4)
#define JB_WIRELESS_NONCTRL __BIT(3)
#define JB_WIRELESS_LITE __BIT(2)

#define CMD_IDENTIFY 0x00000000 /* pad with zeros to clear siiobuf */
#define CMD_RESET 0xFF000000 /* pad with zeros to clear siiobuf */
#define CMD_GBA_READ 0x14
#define CMD_GBA_WRITE 0x15

#define JB_NONE 0x0000
#define JB_N64 0x0500
#define JB_N64MIC 0x0001
#define JB_N64KB 0x0002
#define JB_N64MS 0x0200
#define JB_GBA 0x0004
#define JB_GC 0x0900
#define JB_WAVEBRD_RECV 0xe960
#define JB_WAVEBRD JB_WIRELESS & JB_RUMBLE & JB_CONTROLLER
#define JB_GCKB 0x0802
#define JB_GCSTEER 0x0800
#define JB_GBABIOS 0x08 /* GBA BIOS actually sends a 1byte response and
* sets SISR to NOREP. The second byte will be
* whatever was in SIIOBUF before send */

#define IS_DOLPHIN(n) ISSET(n, JB_CONTROLLER)
#define IS_N64(n) !ISSET(n, JB_CONTROLLER)
#define IS_GCPAD(n) (((n) & (JB_CONTROLLER | JB_DOLPHIN)) == JB_GC) || \
ISSET(n, JB_WIRELESS)
#endif
Loading