-
Notifications
You must be signed in to change notification settings - Fork 358
wii - char driver for gba / joybus devices #81
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
gummybuns
wants to merge
34
commits into
NetBSD:trunk
Choose a base branch
from
gummybuns:wii-identify
base: trunk
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
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 1b4f438
got a char driver for gba to work
gummybuns 03ded0a
refactored to have a common send for siiobuf
gummybuns 9a69c81
refactor __siiobuf_send
gummybuns 119611a
wip playing with multiboot
gummybuns ecdb265
trying to implement ioctl
gummybuns 2d57051
return 0
gummybuns 716db9c
actually got userland program with ioctl to work
gummybuns e44cc2e
got a multiboot solution to actually work
gummybuns 725badc
starting to clean up
gummybuns 22b526d
refactor the send routines and multiboot protocol
gummybuns a4fbc68
the great cleanup has begun
gummybuns afa5416
move to a generic gcport char device
gummybuns 5d0b8e4
add a mutex and some todos
gummybuns 7f72f91
remove a todo
gummybuns 34a1839
remove a todo
gummybuns b95949c
device minor number reflects physical port
gummybuns 6db34e6
rename a variable and try to get makedev to work
gummybuns b38e970
i think i need to include the actual calls in all
gummybuns b72303a
Update sys/arch/evbppc/nintendo/dev/si.c
gummybuns 48ec656
update hierarchy si0 -> gcport -> uhid
gummybuns d38b8e1
got interrupt controller identification to work
gummybuns 618f85c
it is not working but worth comitting
gummybuns a8e0c57
got workqueue to work
gummybuns 34a4b1c
removed delay from the si_send
gummybuns ecc4b90
tried to handle todo
gummybuns 376f879
Update sys/arch/evbppc/conf/NINTENDO
gummybuns 4ca6ca6
Update sys/arch/evbppc/nintendo/dev/uhid_si.c
gummybuns c5a9209
Update sys/arch/evbppc/nintendo/dev/uhid_si.c
gummybuns b568099
update workqueue_create to use proper args
gummybuns 1327b6a
remove the gcport_si softintr
gummybuns d3fd1a6
move send logic to si.c
gummybuns d0114a5
improve si_send / ioctl
gummybuns ef00c2e
fix si_print
gummybuns File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 MAKEDEVfrom src/etc