-
Notifications
You must be signed in to change notification settings - Fork 357
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
20
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
20 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 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,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; | ||
| } |
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,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 |
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