Mon Jan 4 17:42:29 2021 UTC ()
malloc(9) -> kmem(9)


(thorpej)
diff -r1.6 -r1.7 src/sys/arch/mips/atheros/ar_intr.c
diff -r1.12 -r1.13 src/sys/arch/mips/atheros/dev/arspi.c
diff -r1.11 -r1.12 src/sys/arch/mips/atheros/dev/athflash.c

cvs diff -r1.6 -r1.7 src/sys/arch/mips/atheros/ar_intr.c (expand / switch to unified diff)

--- src/sys/arch/mips/atheros/ar_intr.c 2019/11/10 21:16:29 1.6
+++ src/sys/arch/mips/atheros/ar_intr.c 2021/01/04 17:42:29 1.7
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: ar_intr.c,v 1.6 2019/11/10 21:16:29 chs Exp $ */ 1/* $NetBSD: ar_intr.c,v 1.7 2021/01/04 17:42:29 thorpej Exp $ */
2/* 2/*
3 * Copyright (c) 2006 Urbana-Champaign Independent Media Center. 3 * Copyright (c) 2006 Urbana-Champaign Independent Media Center.
4 * Copyright (c) 2006 Garrett D'Amore. 4 * Copyright (c) 2006 Garrett D'Amore.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code was written by Garrett D'Amore for the Champaign-Urbana 7 * This code was written by Garrett D'Amore for the Champaign-Urbana
8 * Community Wireless Network Project. 8 * Community Wireless Network Project.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or 10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following 11 * without modification, are permitted provided that the following
12 * conditions are met: 12 * conditions are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -31,35 +31,35 @@ @@ -31,35 +31,35 @@
31 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 31 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
32 * ARE DISCLAIMED. IN NO EVENT SHALL THE URBANA-CHAMPAIGN INDEPENDENT 32 * ARE DISCLAIMED. IN NO EVENT SHALL THE URBANA-CHAMPAIGN INDEPENDENT
33 * MEDIA CENTER OR GARRETT D'AMORE BE LIABLE FOR ANY DIRECT, INDIRECT, 33 * MEDIA CENTER OR GARRETT D'AMORE BE LIABLE FOR ANY DIRECT, INDIRECT,
34 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 34 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
35 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 35 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
36 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 36 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
37 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 37 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
38 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 38 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
39 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 39 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
40 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 40 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
41 */ 41 */
42 42
43#include <sys/cdefs.h> 43#include <sys/cdefs.h>
44__KERNEL_RCSID(0, "$NetBSD: ar_intr.c,v 1.6 2019/11/10 21:16:29 chs Exp $"); 44__KERNEL_RCSID(0, "$NetBSD: ar_intr.c,v 1.7 2021/01/04 17:42:29 thorpej Exp $");
45 45
46#define __INTR_PRIVATE 46#define __INTR_PRIVATE
47 47
48#include <sys/param.h> 48#include <sys/param.h>
49#include <sys/intr.h> 49#include <sys/intr.h>
50#include <sys/cpu.h> 50#include <sys/cpu.h>
51#include <sys/kernel.h> 51#include <sys/kernel.h>
52#include <sys/malloc.h> 52#include <sys/kmem.h>
53 53
54#include <mips/cpuregs.h> 54#include <mips/cpuregs.h>
55#include <mips/locore.h> 55#include <mips/locore.h>
56#include <mips/atheros/include/platform.h> 56#include <mips/atheros/include/platform.h>
57 57
58#define REGVAL(x) *((volatile uint32_t *)(MIPS_PHYS_TO_KSEG1((x)))) 58#define REGVAL(x) *((volatile uint32_t *)(MIPS_PHYS_TO_KSEG1((x))))
59 59
60/* 60/*
61 * Only MISC interrupts are easily masked at the interrupt controller. 61 * Only MISC interrupts are easily masked at the interrupt controller.
62 * The others have to be masked at the source. 62 * The others have to be masked at the source.
63 */ 63 */
64 64
65#define NINTRS 7 /* MIPS INT2-INT4 (7 is clock interrupt) */ 65#define NINTRS 7 /* MIPS INT2-INT4 (7 is clock interrupt) */
@@ -100,27 +100,27 @@ misc_intmask_get(void) @@ -100,27 +100,27 @@ misc_intmask_get(void)
100 100
101static void 101static void
102misc_intmask_put(uint32_t v) 102misc_intmask_put(uint32_t v)
103{ 103{
104 REGVAL(platformsw->apsw_misc_intmask) = v; 104 REGVAL(platformsw->apsw_misc_intmask) = v;
105} 105}
106 106
107 107
108static void * 108static void *
109genath_cpu_intr_establish(int intr, int (*func)(void *), void *arg) 109genath_cpu_intr_establish(int intr, int (*func)(void *), void *arg)
110{ 110{
111 struct atheros_intrhand *ih; 111 struct atheros_intrhand *ih;
112 112
113 ih = malloc(sizeof(*ih), M_DEVBUF, M_WAITOK); 113 ih = kmem_alloc(sizeof(*ih), KM_SLEEP);
114 ih->ih_func = func; 114 ih->ih_func = func;
115 ih->ih_arg = arg; 115 ih->ih_arg = arg;
116 ih->ih_irq = intr; 116 ih->ih_irq = intr;
117 117
118 const int s = splhigh(); 118 const int s = splhigh();
119 119
120 LIST_INSERT_HEAD(&cpu_intrs[intr].intr_qh, ih, ih_q); 120 LIST_INSERT_HEAD(&cpu_intrs[intr].intr_qh, ih, ih_q);
121 121
122 /* 122 /*
123 * The MIPS CPU interrupts are enabled at boot time, so they 123 * The MIPS CPU interrupts are enabled at boot time, so they
124 * should pretty much always be ready to go. 124 * should pretty much always be ready to go.
125 */ 125 */
126 126
@@ -128,39 +128,39 @@ genath_cpu_intr_establish(int intr, int  @@ -128,39 +128,39 @@ genath_cpu_intr_establish(int intr, int
128 return (ih); 128 return (ih);
129} 129}
130 130
131static void 131static void
132genath_cpu_intr_disestablish(void *arg) 132genath_cpu_intr_disestablish(void *arg)
133{ 133{
134 struct atheros_intrhand * const ih = arg; 134 struct atheros_intrhand * const ih = arg;
135 135
136 const int s = splhigh(); 136 const int s = splhigh();
137 137
138 LIST_REMOVE(ih, ih_q); 138 LIST_REMOVE(ih, ih_q);
139 139
140 splx(s); 140 splx(s);
141 free(ih, M_DEVBUF); 141 kmem_free(ih, sizeof(*ih));
142} 142}
143 143
144static void * 144static void *
145genath_misc_intr_establish(int irq, int (*func)(void *), void *arg) 145genath_misc_intr_establish(int irq, int (*func)(void *), void *arg)
146{ 146{
147 struct atheros_intr * const intr = &misc_intrs[irq]; 147 struct atheros_intr * const intr = &misc_intrs[irq];
148 struct atheros_intrhand *ih; 148 struct atheros_intrhand *ih;
149 bool first; 149 bool first;
150 int s; 150 int s;
151 151
152 152
153 ih = malloc(sizeof(*ih), M_DEVBUF, M_WAITOK); 153 ih = kmem_alloc(sizeof(*ih), KM_SLEEP);
154 ih->ih_func = func; 154 ih->ih_func = func;
155 ih->ih_arg = arg; 155 ih->ih_arg = arg;
156 ih->ih_irq = irq; 156 ih->ih_irq = irq;
157 157
158 s = splhigh(); 158 s = splhigh();
159 159
160 first = LIST_EMPTY(&intr->intr_qh); 160 first = LIST_EMPTY(&intr->intr_qh);
161 161
162 LIST_INSERT_HEAD(&intr->intr_qh, ih, ih_q); 162 LIST_INSERT_HEAD(&intr->intr_qh, ih, ih_q);
163 163
164 if (first) { 164 if (first) {
165 const uint32_t mask = misc_intmask_get() | __BIT(irq); 165 const uint32_t mask = misc_intmask_get() | __BIT(irq);
166 misc_intmask_put(mask); 166 misc_intmask_put(mask);
@@ -178,27 +178,27 @@ genath_misc_intr_disestablish(void *arg) @@ -178,27 +178,27 @@ genath_misc_intr_disestablish(void *arg)
178 struct atheros_intrhand *ih = arg; 178 struct atheros_intrhand *ih = arg;
179 struct atheros_intr * const intr = &misc_intrs[ih->ih_irq]; 179 struct atheros_intr * const intr = &misc_intrs[ih->ih_irq];
180 180
181 const int s = splhigh(); 181 const int s = splhigh();
182 182
183 LIST_REMOVE(ih, ih_q); 183 LIST_REMOVE(ih, ih_q);
184 if (LIST_EMPTY(&intr->intr_qh)) { 184 if (LIST_EMPTY(&intr->intr_qh)) {
185 const uint32_t mask = misc_intmask_get() & ~__BIT(ih->ih_irq); 185 const uint32_t mask = misc_intmask_get() & ~__BIT(ih->ih_irq);
186 misc_intmask_put(mask); 186 misc_intmask_put(mask);
187 (void) misc_intmask_get(); /* flush wbuffer */ 187 (void) misc_intmask_get(); /* flush wbuffer */
188 } 188 }
189 189
190 splx(s); 190 splx(s);
191 free(ih, M_DEVBUF); 191 kmem_free(ih, sizeof(*ih));
192} 192}
193 193
194 194
195static int 195static int
196genath_misc_intr(void *arg) 196genath_misc_intr(void *arg)
197{ 197{
198 uint32_t isr; 198 uint32_t isr;
199 uint32_t mask; 199 uint32_t mask;
200 int rv = 0; 200 int rv = 0;
201 struct atheros_intr *intr = arg; 201 struct atheros_intr *intr = arg;
202 202
203 isr = misc_intstat_get(); 203 isr = misc_intstat_get();
204 mask = misc_intmask_get(); 204 mask = misc_intmask_get();

cvs diff -r1.12 -r1.13 src/sys/arch/mips/atheros/dev/arspi.c (expand / switch to unified diff)

--- src/sys/arch/mips/atheros/dev/arspi.c 2019/08/13 17:03:11 1.12
+++ src/sys/arch/mips/atheros/dev/arspi.c 2021/01/04 17:42:29 1.13
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: arspi.c,v 1.12 2019/08/13 17:03:11 tnn Exp $ */ 1/* $NetBSD: arspi.c,v 1.13 2021/01/04 17:42:29 thorpej Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2006 Urbana-Champaign Independent Media Center. 4 * Copyright (c) 2006 Urbana-Champaign Independent Media Center.
5 * Copyright (c) 2006 Garrett D'Amore. 5 * Copyright (c) 2006 Garrett D'Amore.
6 * All rights reserved. 6 * All rights reserved.
7 * 7 *
8 * Portions of this code were written by Garrett D'Amore for the 8 * Portions of this code were written by Garrett D'Amore for the
9 * Champaign-Urbana Community Wireless Network Project. 9 * Champaign-Urbana Community Wireless Network Project.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or 11 * Redistribution and use in source and binary forms, with or
12 * without modification, are permitted provided that the following 12 * without modification, are permitted provided that the following
13 * conditions are met: 13 * conditions are met:
14 * 1. Redistributions of source code must retain the above copyright 14 * 1. Redistributions of source code must retain the above copyright
@@ -32,37 +32,37 @@ @@ -32,37 +32,37 @@
32 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 32 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
33 * ARE DISCLAIMED. IN NO EVENT SHALL THE URBANA-CHAMPAIGN INDEPENDENT 33 * ARE DISCLAIMED. IN NO EVENT SHALL THE URBANA-CHAMPAIGN INDEPENDENT
34 * MEDIA CENTER OR GARRETT D'AMORE BE LIABLE FOR ANY DIRECT, INDIRECT, 34 * MEDIA CENTER OR GARRETT D'AMORE BE LIABLE FOR ANY DIRECT, INDIRECT,
35 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 35 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
36 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 36 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
37 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 37 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
38 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 38 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
40 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 40 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
41 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 41 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
42 */ 42 */
43 43
44#include <sys/cdefs.h> 44#include <sys/cdefs.h>
45__KERNEL_RCSID(0, "$NetBSD: arspi.c,v 1.12 2019/08/13 17:03:11 tnn Exp $"); 45__KERNEL_RCSID(0, "$NetBSD: arspi.c,v 1.13 2021/01/04 17:42:29 thorpej Exp $");
46 46
47#include "locators.h" 47#include "locators.h"
48 48
49#include <sys/param.h> 49#include <sys/param.h>
50#include <sys/bus.h> 50#include <sys/bus.h>
51#include <sys/cpu.h> 51#include <sys/cpu.h>
52#include <sys/device.h> 52#include <sys/device.h>
53#include <sys/errno.h> 53#include <sys/errno.h>
54#include <sys/kernel.h> 54#include <sys/kernel.h>
55#include <sys/malloc.h> 55#include <sys/kmem.h>
56#include <sys/proc.h> 56#include <sys/proc.h>
57#include <sys/systm.h> 57#include <sys/systm.h>
58 58
59#include <mips/atheros/include/ar5315reg.h> 59#include <mips/atheros/include/ar5315reg.h>
60#include <mips/atheros/include/arbusvar.h> 60#include <mips/atheros/include/arbusvar.h>
61 61
62#include <mips/atheros/dev/arspireg.h> 62#include <mips/atheros/dev/arspireg.h>
63 63
64#include <dev/spi/spiflash.h> 64#include <dev/spi/spiflash.h>
65#include <dev/spi/spivar.h> 65#include <dev/spi/spivar.h>
66 66
67/* 67/*
68 * This device is intended only to operate with specific SPI flash 68 * This device is intended only to operate with specific SPI flash
@@ -250,28 +250,29 @@ arspi_configure(void *cookie, int slave, @@ -250,28 +250,29 @@ arspi_configure(void *cookie, int slave,
250 return 0; 250 return 0;
251} 251}
252 252
253int 253int
254arspi_transfer(void *cookie, struct spi_transfer *st) 254arspi_transfer(void *cookie, struct spi_transfer *st)
255{ 255{
256 struct arspi_softc *sc = cookie; 256 struct arspi_softc *sc = cookie;
257 int rv; 257 int rv;
258 int s; 258 int s;
259 259
260 st->st_busprivate = NULL; 260 st->st_busprivate = NULL;
261 if ((rv = arspi_make_job(st)) != 0) { 261 if ((rv = arspi_make_job(st)) != 0) {
262 if (st->st_busprivate) { 262 if (st->st_busprivate) {
263 free(st->st_busprivate, M_DEVBUF); 263 struct arspi_job *job = st->st_busprivate;
264 st->st_busprivate = NULL; 264 st->st_busprivate = NULL;
 265 kmem_free(job, sizeof(*job));
265 } 266 }
266 spi_done(st, rv); 267 spi_done(st, rv);
267 return rv; 268 return rv;
268 } 269 }
269 270
270 s = splbio(); 271 s = splbio();
271 spi_transq_enqueue(&sc->sc_transq, st); 272 spi_transq_enqueue(&sc->sc_transq, st);
272 if (sc->sc_transfer == NULL) { 273 if (sc->sc_transfer == NULL) {
273 arspi_sched(sc); 274 arspi_sched(sc);
274 if (!sc->sc_interrupts) 275 if (!sc->sc_interrupts)
275 arspi_poll(sc); 276 arspi_poll(sc);
276 } 277 }
277 splx(s); 278 splx(s);
@@ -372,27 +373,27 @@ arspi_done(struct arspi_softc *sc, int e @@ -372,27 +373,27 @@ arspi_done(struct arspi_softc *sc, int e
372 * send WREN for each chunk. These flags facilitate 373 * send WREN for each chunk. These flags facilitate
373 * that. 374 * that.
374 */ 375 */
375 if (job->job_flags & JOB_WRITE) 376 if (job->job_flags & JOB_WRITE)
376 job->job_flags |= (JOB_WAIT | JOB_WREN); 377 job->job_flags |= (JOB_WAIT | JOB_WREN);
377 job->job_data = GETREG(sc, ARSPI_REG_DATA); 378 job->job_data = GETREG(sc, ARSPI_REG_DATA);
378 arspi_finish_job(st); 379 arspi_finish_job(st);
379 } 380 }
380 381
381 if (err || (job->job_flags & JOB_LAST)) { 382 if (err || (job->job_flags & JOB_LAST)) {
382 sc->sc_transfer = NULL; 383 sc->sc_transfer = NULL;
383 st->st_busprivate = NULL; 384 st->st_busprivate = NULL;
384 spi_done(st, err); 385 spi_done(st, err);
385 free(job, M_DEVBUF); 386 kmem_free(job, sizeof(*job));
386 } 387 }
387 } 388 }
388done: 389done:
389 arspi_sched(sc); 390 arspi_sched(sc);
390} 391}
391 392
392int 393int
393arspi_get_byte(struct spi_chunk **chunkp, uint8_t *bytep) 394arspi_get_byte(struct spi_chunk **chunkp, uint8_t *bytep)
394{ 395{
395 struct spi_chunk *chunk; 396 struct spi_chunk *chunk;
396 397
397 chunk = *chunkp; 398 chunk = *chunkp;
398 399
@@ -460,30 +461,27 @@ arspi_put_byte(struct spi_chunk **chunkp @@ -460,30 +461,27 @@ arspi_put_byte(struct spi_chunk **chunkp
460 461
461 *chunkp = chunk; 462 *chunkp = chunk;
462 return 0; 463 return 0;
463} 464}
464 465
465int 466int
466arspi_make_job(struct spi_transfer *st) 467arspi_make_job(struct spi_transfer *st)
467{ 468{
468 struct arspi_job *job; 469 struct arspi_job *job;
469 struct spi_chunk *chunk; 470 struct spi_chunk *chunk;
470 uint8_t byte; 471 uint8_t byte;
471 int i, rv; 472 int i, rv;
472 473
473 job = malloc(sizeof (struct arspi_job), M_DEVBUF, M_ZERO); 474 job = kmem_zalloc(sizeof (struct arspi_job), KM_SLEEP);
474 if (job == NULL) { 
475 return ENOMEM; 
476 } 
477 475
478 st->st_busprivate = job; 476 st->st_busprivate = job;
479 477
480 /* skip any leading empty chunks (should not be any!) */ 478 /* skip any leading empty chunks (should not be any!) */
481 chunk = st->st_chunks; 479 chunk = st->st_chunks;
482 480
483 /* get transfer opcode */ 481 /* get transfer opcode */
484 if ((rv = arspi_get_byte(&chunk, &byte)) != 0) 482 if ((rv = arspi_get_byte(&chunk, &byte)) != 0)
485 return rv; 483 return rv;
486 484
487 job->job_opcode = byte; 485 job->job_opcode = byte;
488 switch (job->job_opcode) { 486 switch (job->job_opcode) {
489 case SPIFLASH_CMD_WREN: 487 case SPIFLASH_CMD_WREN:

cvs diff -r1.11 -r1.12 src/sys/arch/mips/atheros/dev/athflash.c (expand / switch to unified diff)

--- src/sys/arch/mips/atheros/dev/athflash.c 2019/11/10 21:16:30 1.11
+++ src/sys/arch/mips/atheros/dev/athflash.c 2021/01/04 17:42:29 1.12
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: athflash.c,v 1.11 2019/11/10 21:16:30 chs Exp $ */ 1/* $NetBSD: athflash.c,v 1.12 2021/01/04 17:42:29 thorpej Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2006 Urbana-Champaign Independent Media Center. 4 * Copyright (c) 2006 Urbana-Champaign Independent Media Center.
5 * Copyright (c) 2006 Garrett D'Amore. 5 * Copyright (c) 2006 Garrett D'Amore.
6 * All rights reserved. 6 * All rights reserved.
7 * 7 *
8 * Portions of this code were written by Garrett D'Amore for the 8 * Portions of this code were written by Garrett D'Amore for the
9 * Champaign-Urbana Community Wireless Network Project. 9 * Champaign-Urbana Community Wireless Network Project.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or 11 * Redistribution and use in source and binary forms, with or
12 * without modification, are permitted provided that the following 12 * without modification, are permitted provided that the following
13 * conditions are met: 13 * conditions are met:
14 * 1. Redistributions of source code must retain the above copyright 14 * 1. Redistributions of source code must retain the above copyright
@@ -72,33 +72,33 @@ @@ -72,33 +72,33 @@
72/* 72/*
73 * Flash Memory Driver 73 * Flash Memory Driver
74 * 74 *
75 * XXX This primitive flash driver does *not* support boot sectored devices, 75 * XXX This primitive flash driver does *not* support boot sectored devices,
76 * XXX and only supports a fairly limited set of devices, that we are likely to 76 * XXX and only supports a fairly limited set of devices, that we are likely to
77 * XXX to find in an AP30. 77 * XXX to find in an AP30.
78 * XXX 78 * XXX
79 * XXX We also are only supporting flash widths of 16 _for the moment_, and 79 * XXX We also are only supporting flash widths of 16 _for the moment_, and
80 * XXX we are only supporting flash devices that use the AMD command sets. 80 * XXX we are only supporting flash devices that use the AMD command sets.
81 * XXX All this should be reviewed and improved to be much more generic. 81 * XXX All this should be reviewed and improved to be much more generic.
82 */ 82 */
83 83
84#include <sys/cdefs.h> 84#include <sys/cdefs.h>
85__KERNEL_RCSID(0, "$NetBSD: athflash.c,v 1.11 2019/11/10 21:16:30 chs Exp $"); 85__KERNEL_RCSID(0, "$NetBSD: athflash.c,v 1.12 2021/01/04 17:42:29 thorpej Exp $");
86 86
87#include <sys/param.h> 87#include <sys/param.h>
88#include <sys/conf.h> 88#include <sys/conf.h>
89#include <sys/device.h> 89#include <sys/device.h>
90#include <sys/kernel.h> 90#include <sys/kernel.h>
91#include <sys/malloc.h> 91#include <sys/kmem.h>
92#include <sys/proc.h> 92#include <sys/proc.h>
93#include <sys/systm.h> 93#include <sys/systm.h>
94 94
95#include <sys/bus.h> 95#include <sys/bus.h>
96 96
97#include <mips/atheros/include/arbusvar.h> 97#include <mips/atheros/include/arbusvar.h>
98 98
99#ifdef FLASH_DEBUG 99#ifdef FLASH_DEBUG
100int flash_debug = 0; 100int flash_debug = 0;
101#define DPRINTF(x) if (flash_debug) printf x 101#define DPRINTF(x) if (flash_debug) printf x
102#else 102#else
103#define DPRINTF(x) 103#define DPRINTF(x)
104#endif 104#endif
@@ -241,27 +241,27 @@ flash_attach(device_t parent, device_t s @@ -241,27 +241,27 @@ flash_attach(device_t parent, device_t s
241 241
242 KASSERT(flash_ids[i].name != NULL); 242 KASSERT(flash_ids[i].name != NULL);
243 printf(": %s", flash_ids[i].name); 243 printf(": %s", flash_ids[i].name);
244 if (humanize_number(nbuf, sizeof(nbuf), flash_ids[i].flash_size, "B", 244 if (humanize_number(nbuf, sizeof(nbuf), flash_ids[i].flash_size, "B",
245 1024) > 0) 245 1024) > 0)
246 printf(" (%s)", nbuf); 246 printf(" (%s)", nbuf);
247 247
248 /* 248 /*
249 * determine size of the largest block 249 * determine size of the largest block
250 */ 250 */
251 sc->sc_size = flash_ids[i].flash_size; 251 sc->sc_size = flash_ids[i].flash_size;
252 sc->sc_sector_size = flash_ids[i].sector_size; 252 sc->sc_sector_size = flash_ids[i].sector_size;
253 253
254 sc->sc_buf = malloc(sc->sc_sector_size, M_DEVBUF, M_WAITOK); 254 sc->sc_buf = kmem_alloc(sc->sc_sector_size, KM_SLEEP);
255 255
256 printf("\n"); 256 printf("\n");
257} 257}
258 258
259int 259int
260flashopen(dev_t dev, int flag, int mode, struct lwp *l) 260flashopen(dev_t dev, int flag, int mode, struct lwp *l)
261{ 261{
262 struct flash_softc *sc; 262 struct flash_softc *sc;
263 263
264 sc = device_lookup_private(&athflash_cd, minor(dev)); 264 sc = device_lookup_private(&athflash_cd, minor(dev));
265 if (sc == NULL) 265 if (sc == NULL)
266 return ENXIO; 266 return ENXIO;
267 if (sc->sc_status & FLASH_ST_BUSY) 267 if (sc->sc_status & FLASH_ST_BUSY)