No empty .Rs/.Re
[netbsd-mini2440.git] / sys / arch / sh3 / dev / shpcic.c
blob0f7caefbed8968eabdfd920722d3c1f4be2bf15c
1 /* $NetBSD: shpcic.c,v 1.12 2008/03/27 02:05:43 uwe Exp $ */
3 /*
4 * Copyright (c) 2005 NONAKA Kimihiro
5 * All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 #include <sys/cdefs.h>
29 __KERNEL_RCSID(0, "$NetBSD: shpcic.c,v 1.12 2008/03/27 02:05:43 uwe Exp $");
31 #include "opt_pci.h"
33 #include <sys/param.h>
34 #include <sys/systm.h>
35 #include <sys/kernel.h>
36 #include <sys/device.h>
37 #include <sys/extent.h>
38 #include <sys/malloc.h>
40 #include <dev/pci/pcireg.h>
41 #include <dev/pci/pcivar.h>
42 #include <dev/pci/pciconf.h>
43 #include <dev/pci/pcidevs.h>
45 #include <sh3/bscreg.h>
46 #include <sh3/cache.h>
47 #include <sh3/exception.h>
48 #include <sh3/pcicreg.h>
50 #include <machine/bus.h>
51 #include <machine/intr.h>
52 #include <machine/pci_machdep.h>
55 #if defined(DEBUG) && !defined(SHPCIC_DEBUG)
56 #define SHPCIC_DEBUG 0
57 #endif
58 #if defined(SHPCIC_DEBUG)
59 int shpcic_debug = SHPCIC_DEBUG + 0;
60 #define DPRINTF(arg) if (shpcic_debug) printf arg
61 #else
62 #define DPRINTF(arg)
63 #endif
65 #define PCI_MODE1_ENABLE 0x80000000UL
68 static int shpcic_match(device_t, cfdata_t, void *);
69 static void shpcic_attach(device_t, device_t, void *);
71 CFATTACH_DECL_NEW(shpcic, 0,
72 shpcic_match, shpcic_attach, NULL, NULL);
75 /* There can be only one. */
76 static int shpcic_found = 0;
78 /* PCIC intr priotiry */
79 static int shpcic_intr_priority[2] = { IPL_BIO, IPL_BIO };
82 static int
83 shpcic_match(device_t parent, cfdata_t cf, void *aux)
85 pcireg_t id;
87 if (shpcic_found)
88 return (0);
90 switch (cpu_product) {
91 case CPU_PRODUCT_7751:
92 case CPU_PRODUCT_7751R:
93 break;
95 default:
96 return (0);
100 id = _reg_read_4(SH4_PCICONF0);
102 switch (PCI_VENDOR(id)) {
103 case PCI_VENDOR_HITACHI:
104 break;
106 default:
107 return (0);
111 switch (PCI_PRODUCT(id)) {
112 case PCI_PRODUCT_HITACHI_SH7751: /* FALLTHROUGH */
113 case PCI_PRODUCT_HITACHI_SH7751R:
114 break;
116 default:
117 return (0);
120 if (_reg_read_2(SH4_BCR2) & BCR2_PORTEN)
121 return (0);
123 return (1);
126 static void
127 shpcic_attach(device_t parent, device_t self, void *aux)
129 struct pcibus_attach_args pba;
130 #ifdef PCI_NETBSD_CONFIGURE
131 struct extent *ioext, *memext;
132 #endif
133 pcireg_t id, class;
134 char devinfo[256];
136 shpcic_found = 1;
138 aprint_naive("\n");
140 id = _reg_read_4(SH4_PCICONF0);
141 class = _reg_read_4(SH4_PCICONF2);
142 pci_devinfo(id, class, 1, devinfo, sizeof(devinfo));
143 aprint_normal(": %s\n", devinfo);
145 /* allow PCIC request */
146 _reg_write_4(SH4_BCR1, _reg_read_4(SH4_BCR1) | BCR1_BREQEN);
148 /* Initialize PCIC */
149 _reg_write_4(SH4_PCICR, PCICR_BASE | PCICR_RSTCTL);
150 delay(10 * 1000);
151 _reg_write_4(SH4_PCICR, PCICR_BASE);
153 /* Class: Host-Bridge */
154 _reg_write_4(SH4_PCICONF2,
155 PCI_CLASS_CODE(PCI_CLASS_BRIDGE, PCI_SUBCLASS_BRIDGE_HOST, 0x00));
157 #if !defined(DONT_INIT_PCIBSC)
158 #if defined(PCIBCR_BCR1_VAL)
159 _reg_write_4(SH4_PCIBCR1, PCIBCR_BCR1_VAL);
160 #else
161 _reg_write_4(SH4_PCIBCR1, _reg_read_4(SH4_BCR1) | BCR1_MASTER);
162 #endif
163 #if defined(PCIBCR_BCR2_VAL)
164 _reg_write_4(SH4_PCIBCR2, PCIBCR_BCR2_VAL);
165 #else
166 _reg_write_4(SH4_PCIBCR2, _reg_read_2(SH4_BCR2));
167 #endif
168 #if defined(SH4) && defined(SH7751R)
169 if (cpu_product == CPU_PRODUCT_7751R) {
170 #if defined(PCIBCR_BCR3_VAL)
171 _reg_write_4(SH4_PCIBCR3, PCIBCR_BCR3_VAL);
172 #else
173 _reg_write_4(SH4_PCIBCR3, _reg_read_2(SH4_BCR3));
174 #endif
176 #endif /* SH4 && SH7751R && PCIBCR_BCR3_VAL */
177 #if defined(PCIBCR_WCR1_VAL)
178 _reg_write_4(SH4_PCIWCR1, PCIBCR_WCR1_VAL);
179 #else
180 _reg_write_4(SH4_PCIWCR1, _reg_read_4(SH4_WCR1));
181 #endif
182 #if defined(PCIBCR_WCR2_VAL)
183 _reg_write_4(SH4_PCIWCR2, PCIBCR_WCR2_VAL);
184 #else
185 _reg_write_4(SH4_PCIWCR2, _reg_read_4(SH4_WCR2));
186 #endif
187 #if defined(PCIBCR_WCR3_VAL)
188 _reg_write_4(SH4_PCIWCR3, PCIBCR_WCR3_VAL);
189 #else
190 _reg_write_4(SH4_PCIWCR3, _reg_read_4(SH4_WCR3));
191 #endif
192 #if defined(PCIBCR_MCR_VAL)
193 _reg_write_4(SH4_PCIMCR, PCIBCR_MCR_VAL);
194 #else
195 _reg_write_4(SH4_PCIMCR, _reg_read_4(SH4_MCR));
196 #endif
197 #endif /* !DONT_INIT_PCIBSC */
199 /* set PCI I/O, memory base address */
200 _reg_write_4(SH4_PCIIOBR, SH4_PCIC_IO);
201 _reg_write_4(SH4_PCIMBR, SH4_PCIC_MEM);
203 /* set PCI local address 0 */
204 _reg_write_4(SH4_PCILSR0, (64 - 1) << 20);
205 _reg_write_4(SH4_PCILAR0, 0xac000000);
206 _reg_write_4(SH4_PCICONF5, 0xac000000);
208 /* set PCI local address 1 */
209 _reg_write_4(SH4_PCILSR1, (64 - 1) << 20);
210 _reg_write_4(SH4_PCILAR1, 0xac000000);
211 _reg_write_4(SH4_PCICONF6, 0x8c000000);
213 /* Enable I/O, memory, bus-master */
214 _reg_write_4(SH4_PCICONF1, PCI_COMMAND_IO_ENABLE
215 | PCI_COMMAND_MEM_ENABLE
216 | PCI_COMMAND_MASTER_ENABLE
217 | PCI_COMMAND_STEPPING_ENABLE
218 | PCI_STATUS_DEVSEL_MEDIUM);
220 /* Initialize done. */
221 _reg_write_4(SH4_PCICR, PCICR_BASE | PCICR_CFINIT);
223 /* set PCI controller interrupt priority */
224 intpri_intr_priority(SH4_INTEVT_PCIERR, shpcic_intr_priority[0]);
225 intpri_intr_priority(SH4_INTEVT_PCISERR, shpcic_intr_priority[1]);
227 /* PCI bus */
228 #ifdef PCI_NETBSD_CONFIGURE
229 ioext = extent_create("pciio",
230 SH4_PCIC_IO, SH4_PCIC_IO + SH4_PCIC_IO_SIZE - 1,
231 M_DEVBUF, NULL, 0, EX_NOWAIT);
232 memext = extent_create("pcimem",
233 SH4_PCIC_MEM, SH4_PCIC_MEM + SH4_PCIC_MEM_SIZE - 1,
234 M_DEVBUF, NULL, 0, EX_NOWAIT);
236 pci_configure_bus(NULL, ioext, memext, NULL, 0, sh_cache_line_size);
238 extent_destroy(ioext);
239 extent_destroy(memext);
240 #endif
242 /* PCI bus */
243 memset(&pba, 0, sizeof(pba));
244 pba.pba_iot = shpcic_get_bus_io_tag();
245 pba.pba_memt = shpcic_get_bus_mem_tag();
246 pba.pba_dmat = shpcic_get_bus_dma_tag();
247 pba.pba_dmat64 = NULL;
248 pba.pba_pc = NULL;
249 pba.pba_bus = 0;
250 pba.pba_bridgetag = NULL;
251 pba.pba_flags = PCI_FLAGS_IO_ENABLED | PCI_FLAGS_MEM_ENABLED;
252 config_found(self, &pba, NULL);
256 shpcic_bus_maxdevs(void *v, int busno)
260 * Bus number is irrelevant. Configuration Mechanism 1 is in
261 * use, can have devices 0-32 (i.e. the `normal' range).
263 return (32);
266 pcitag_t
267 shpcic_make_tag(void *v, int bus, int device, int function)
269 pcitag_t tag;
271 if (bus >= 256 || device >= 32 || function >= 8)
272 panic("pci_make_tag: bad request");
274 tag = PCI_MODE1_ENABLE |
275 (bus << 16) | (device << 11) | (function << 8);
277 return (tag);
280 void
281 shpcic_decompose_tag(void *v, pcitag_t tag, int *bp, int *dp, int *fp)
284 if (bp != NULL)
285 *bp = (tag >> 16) & 0xff;
286 if (dp != NULL)
287 *dp = (tag >> 11) & 0x1f;
288 if (fp != NULL)
289 *fp = (tag >> 8) & 0x7;
292 pcireg_t
293 shpcic_conf_read(void *v, pcitag_t tag, int reg)
295 pcireg_t data;
296 int s;
298 s = splhigh();
299 _reg_write_4(SH4_PCIPAR, tag | reg);
300 data = _reg_read_4(SH4_PCIPDR);
301 _reg_write_4(SH4_PCIPAR, 0);
302 splx(s);
304 return data;
307 void
308 shpcic_conf_write(void *v, pcitag_t tag, int reg, pcireg_t data)
310 int s;
312 s = splhigh();
313 _reg_write_4(SH4_PCIPAR, tag | reg);
314 _reg_write_4(SH4_PCIPDR, data);
315 _reg_write_4(SH4_PCIPAR, 0);
316 splx(s);
320 shpcic_set_intr_priority(int intr, int level)
322 int evtcode;
324 if ((intr != 0) && (intr != 1)) {
325 return (-1);
327 if ((level < IPL_NONE) || (level > IPL_HIGH)) {
328 return (-1);
331 if (intr == 0) {
332 evtcode = SH4_INTEVT_PCIERR;
333 } else {
334 evtcode = SH4_INTEVT_PCISERR;
337 intpri_intr_priority(evtcode, shpcic_intr_priority[intr]);
338 shpcic_intr_priority[intr] = level;
340 return (0);
343 void *
344 shpcic_intr_establish(int evtcode, int (*ih_func)(void *), void *ih_arg)
346 int level;
348 switch (evtcode) {
349 case SH4_INTEVT_PCISERR:
350 level = shpcic_intr_priority[1];
351 break;
353 case SH4_INTEVT_PCIDMA3:
354 case SH4_INTEVT_PCIDMA2:
355 case SH4_INTEVT_PCIDMA1:
356 case SH4_INTEVT_PCIDMA0:
357 case SH4_INTEVT_PCIPWON:
358 case SH4_INTEVT_PCIPWDWN:
359 case SH4_INTEVT_PCIERR:
360 level = shpcic_intr_priority[0];
361 break;
363 default:
364 printf("shpcic_intr_establish: unknown evtcode = 0x%08x\n",
365 evtcode);
366 return NULL;
369 return intc_intr_establish(evtcode, IST_LEVEL, level, ih_func, ih_arg);
372 void
373 shpcic_intr_disestablish(void *ih)
376 intc_intr_disestablish(ih);
380 * shpcic bus space
383 shpcic_iomem_map(void *v, bus_addr_t bpa, bus_size_t size,
384 int flags, bus_space_handle_t *bshp)
387 *bshp = (bus_space_handle_t)bpa;
389 return (0);
392 void
393 shpcic_iomem_unmap(void *v, bus_space_handle_t bsh, bus_size_t size)
396 /* Nothing to do */
400 shpcic_iomem_subregion(void *v, bus_space_handle_t bsh,
401 bus_size_t offset, bus_size_t size, bus_space_handle_t *nbshp)
404 *nbshp = bsh + offset;
406 return (0);
410 shpcic_iomem_alloc(void *v, bus_addr_t rstart, bus_addr_t rend,
411 bus_size_t size, bus_size_t alignment, bus_size_t boundary, int flags,
412 bus_addr_t *bpap, bus_space_handle_t *bshp)
415 *bshp = *bpap = rstart;
417 return (0);
420 void
421 shpcic_iomem_free(void *v, bus_space_handle_t bsh, bus_size_t size)
424 /* Nothing to do */
427 paddr_t
428 shpcic_iomem_mmap(void *v, bus_addr_t addr, off_t off, int prot, int flags)
431 return (paddr_t)-1;
435 * shpcic bus space io/mem read/write
437 /* read */
438 static inline uint8_t __shpcic_io_read_1(bus_space_handle_t bsh,
439 bus_size_t offset);
440 static inline uint16_t __shpcic_io_read_2(bus_space_handle_t bsh,
441 bus_size_t offset);
442 static inline uint32_t __shpcic_io_read_4(bus_space_handle_t bsh,
443 bus_size_t offset);
444 static inline uint8_t __shpcic_mem_read_1(bus_space_handle_t bsh,
445 bus_size_t offset);
446 static inline uint16_t __shpcic_mem_read_2(bus_space_handle_t bsh,
447 bus_size_t offset);
448 static inline uint32_t __shpcic_mem_read_4(bus_space_handle_t bsh,
449 bus_size_t offset);
451 static inline uint8_t
452 __shpcic_io_read_1(bus_space_handle_t bsh, bus_size_t offset)
454 u_long adr = (u_long)(bsh + offset) & SH4_PCIC_IO_MASK;
456 return *(volatile uint8_t *)(SH4_PCIC_IO + adr);
459 static inline uint16_t
460 __shpcic_io_read_2(bus_space_handle_t bsh, bus_size_t offset)
462 u_long adr = (u_long)(bsh + offset) & SH4_PCIC_IO_MASK;
464 return *(volatile uint16_t *)(SH4_PCIC_IO + adr);
467 static inline uint32_t
468 __shpcic_io_read_4(bus_space_handle_t bsh, bus_size_t offset)
470 u_long adr = (u_long)(bsh + offset) & SH4_PCIC_IO_MASK;
472 return *(volatile uint32_t *)(SH4_PCIC_IO + adr);
475 static inline uint8_t
476 __shpcic_mem_read_1(bus_space_handle_t bsh, bus_size_t offset)
478 u_long adr = (u_long)(bsh + offset) & SH4_PCIC_MEM_MASK;
480 return *(volatile uint8_t *)(SH4_PCIC_MEM + adr);
483 static inline uint16_t
484 __shpcic_mem_read_2(bus_space_handle_t bsh, bus_size_t offset)
486 u_long adr = (u_long)(bsh + offset) & SH4_PCIC_MEM_MASK;
488 return *(volatile uint16_t *)(SH4_PCIC_MEM + adr);
491 static inline uint32_t
492 __shpcic_mem_read_4(bus_space_handle_t bsh, bus_size_t offset)
494 u_long adr = (u_long)(bsh + offset) & SH4_PCIC_MEM_MASK;
496 return *(volatile uint32_t *)(SH4_PCIC_MEM + adr);
500 * read single
502 uint8_t
503 shpcic_io_read_1(void *v, bus_space_handle_t bsh, bus_size_t offset)
505 uint8_t value;
507 value = __shpcic_io_read_1(bsh, offset);
509 return value;
512 uint16_t
513 shpcic_io_read_2(void *v, bus_space_handle_t bsh, bus_size_t offset)
515 uint16_t value;
517 value = __shpcic_io_read_2(bsh, offset);
519 return value;
522 uint32_t
523 shpcic_io_read_4(void *v, bus_space_handle_t bsh, bus_size_t offset)
525 uint32_t value;
527 value = __shpcic_io_read_4(bsh, offset);
529 return value;
532 uint8_t
533 shpcic_mem_read_1(void *v, bus_space_handle_t bsh, bus_size_t offset)
535 uint8_t value;
537 value = __shpcic_mem_read_1(bsh, offset);
539 return value;
542 uint16_t
543 shpcic_mem_read_2(void *v, bus_space_handle_t bsh, bus_size_t offset)
545 uint16_t value;
547 value = __shpcic_mem_read_2(bsh, offset);
549 return value;
552 uint32_t
553 shpcic_mem_read_4(void *v, bus_space_handle_t bsh, bus_size_t offset)
555 uint32_t value;
557 value = __shpcic_mem_read_4(bsh, offset);
559 return value;
563 * read multi
565 void
566 shpcic_io_read_multi_1(void *v, bus_space_handle_t bsh,
567 bus_size_t offset, uint8_t *addr, bus_size_t count)
570 while (count--) {
571 *addr++ = __shpcic_io_read_1(bsh, offset);
575 void
576 shpcic_io_read_multi_2(void *v, bus_space_handle_t bsh,
577 bus_size_t offset, uint16_t *addr, bus_size_t count)
580 while (count--) {
581 *addr++ = __shpcic_io_read_2(bsh, offset);
585 void
586 shpcic_io_read_multi_4(void *v, bus_space_handle_t bsh,
587 bus_size_t offset, uint32_t *addr, bus_size_t count)
590 while (count--) {
591 *addr++ = __shpcic_io_read_4(bsh, offset);
595 void
596 shpcic_mem_read_multi_1(void *v, bus_space_handle_t bsh,
597 bus_size_t offset, uint8_t *addr, bus_size_t count)
600 while (count--) {
601 *addr++ = __shpcic_mem_read_1(bsh, offset);
605 void
606 shpcic_mem_read_multi_2(void *v, bus_space_handle_t bsh,
607 bus_size_t offset, uint16_t *addr, bus_size_t count)
610 while (count--) {
611 *addr++ = __shpcic_mem_read_2(bsh, offset);
615 void
616 shpcic_mem_read_multi_4(void *v, bus_space_handle_t bsh,
617 bus_size_t offset, uint32_t *addr, bus_size_t count)
620 while (count--) {
621 *addr++ = __shpcic_mem_read_4(bsh, offset);
627 * read region
629 void
630 shpcic_io_read_region_1(void *v, bus_space_handle_t bsh,
631 bus_size_t offset, uint8_t *addr, bus_size_t count)
634 while (count--) {
635 *addr++ = __shpcic_io_read_1(bsh, offset);
636 offset += 1;
640 void
641 shpcic_io_read_region_2(void *v, bus_space_handle_t bsh,
642 bus_size_t offset, uint16_t *addr, bus_size_t count)
645 while (count--) {
646 *addr++ = __shpcic_io_read_2(bsh, offset);
647 offset += 2;
651 void
652 shpcic_io_read_region_4(void *v, bus_space_handle_t bsh,
653 bus_size_t offset, uint32_t *addr, bus_size_t count)
656 while (count--) {
657 *addr++ = __shpcic_io_read_4(bsh, offset);
658 offset += 4;
662 void
663 shpcic_mem_read_region_1(void *v, bus_space_handle_t bsh,
664 bus_size_t offset, uint8_t *addr, bus_size_t count)
667 while (count--) {
668 *addr++ = __shpcic_mem_read_1(bsh, offset);
669 offset += 1;
673 void
674 shpcic_mem_read_region_2(void *v, bus_space_handle_t bsh,
675 bus_size_t offset, uint16_t *addr, bus_size_t count)
678 while (count--) {
679 *addr++ = __shpcic_mem_read_2(bsh, offset);
680 offset += 2;
684 void
685 shpcic_mem_read_region_4(void *v, bus_space_handle_t bsh,
686 bus_size_t offset, uint32_t *addr, bus_size_t count)
689 while (count--) {
690 *addr++ = __shpcic_mem_read_4(bsh, offset);
691 offset += 4;
695 /* write */
696 static inline void __shpcic_io_write_1(bus_space_handle_t bsh,
697 bus_size_t offset, uint8_t value);
698 static inline void __shpcic_io_write_2(bus_space_handle_t bsh,
699 bus_size_t offset, uint16_t value);
700 static inline void __shpcic_io_write_4(bus_space_handle_t bsh,
701 bus_size_t offset, uint32_t value);
702 static inline void __shpcic_mem_write_1(bus_space_handle_t bsh,
703 bus_size_t offset, uint8_t value);
704 static inline void __shpcic_mem_write_2(bus_space_handle_t bsh,
705 bus_size_t offset, uint16_t value);
706 static inline void __shpcic_mem_write_4(bus_space_handle_t bsh,
707 bus_size_t offset, uint32_t value);
709 static inline void
710 __shpcic_io_write_1(bus_space_handle_t bsh, bus_size_t offset,
711 uint8_t value)
713 u_long adr = (u_long)(bsh + offset) & SH4_PCIC_IO_MASK;
715 *(volatile uint8_t *)(SH4_PCIC_IO + adr) = value;
718 static inline void
719 __shpcic_io_write_2(bus_space_handle_t bsh, bus_size_t offset,
720 uint16_t value)
722 u_long adr = (u_long)(bsh + offset) & SH4_PCIC_IO_MASK;
724 *(volatile uint16_t *)(SH4_PCIC_IO + adr) = value;
727 static inline void
728 __shpcic_io_write_4(bus_space_handle_t bsh, bus_size_t offset,
729 uint32_t value)
731 u_long adr = (u_long)(bsh + offset) & SH4_PCIC_IO_MASK;
733 *(volatile uint32_t *)(SH4_PCIC_IO + adr) = value;
736 static inline void
737 __shpcic_mem_write_1(bus_space_handle_t bsh, bus_size_t offset,
738 uint8_t value)
740 u_long adr = (u_long)(bsh + offset) & SH4_PCIC_MEM_MASK;
742 *(volatile uint8_t *)(SH4_PCIC_MEM + adr) = value;
745 static inline void
746 __shpcic_mem_write_2(bus_space_handle_t bsh, bus_size_t offset,
747 uint16_t value)
749 u_long adr = (u_long)(bsh + offset) & SH4_PCIC_MEM_MASK;
751 *(volatile uint16_t *)(SH4_PCIC_MEM + adr) = value;
754 static inline void
755 __shpcic_mem_write_4(bus_space_handle_t bsh, bus_size_t offset,
756 uint32_t value)
758 u_long adr = (u_long)(bsh + offset) & SH4_PCIC_MEM_MASK;
760 *(volatile uint32_t *)(SH4_PCIC_MEM + adr) = value;
764 * write single
766 void
767 shpcic_io_write_1(void *v, bus_space_handle_t bsh,
768 bus_size_t offset, uint8_t value)
771 __shpcic_io_write_1(bsh, offset, value);
774 void
775 shpcic_io_write_2(void *v, bus_space_handle_t bsh,
776 bus_size_t offset, uint16_t value)
779 __shpcic_io_write_2(bsh, offset, value);
782 void
783 shpcic_io_write_4(void *v, bus_space_handle_t bsh,
784 bus_size_t offset, uint32_t value)
787 __shpcic_io_write_4(bsh, offset, value);
790 void
791 shpcic_mem_write_1(void *v, bus_space_handle_t bsh,
792 bus_size_t offset, uint8_t value)
795 __shpcic_mem_write_1(bsh, offset, value);
798 void
799 shpcic_mem_write_2(void *v, bus_space_handle_t bsh,
800 bus_size_t offset, uint16_t value)
803 __shpcic_mem_write_2(bsh, offset, value);
806 void
807 shpcic_mem_write_4(void *v, bus_space_handle_t bsh,
808 bus_size_t offset, uint32_t value)
811 __shpcic_mem_write_4(bsh, offset, value);
815 * write multi
817 void
818 shpcic_io_write_multi_1(void *v, bus_space_handle_t bsh,
819 bus_size_t offset, const uint8_t *addr, bus_size_t count)
822 while (count--) {
823 __shpcic_io_write_1(bsh, offset, *addr++);
827 void
828 shpcic_io_write_multi_2(void *v, bus_space_handle_t bsh,
829 bus_size_t offset, const uint16_t *addr, bus_size_t count)
832 while (count--) {
833 __shpcic_io_write_2(bsh, offset, *addr++);
837 void
838 shpcic_io_write_multi_4(void *v, bus_space_handle_t bsh,
839 bus_size_t offset, const uint32_t *addr, bus_size_t count)
842 while (count--) {
843 __shpcic_io_write_4(bsh, offset, *addr++);
847 void
848 shpcic_mem_write_multi_1(void *v, bus_space_handle_t bsh,
849 bus_size_t offset, const uint8_t *addr, bus_size_t count)
852 while (count--) {
853 __shpcic_mem_write_1(bsh, offset, *addr++);
857 void
858 shpcic_mem_write_multi_2(void *v, bus_space_handle_t bsh,
859 bus_size_t offset, const uint16_t *addr, bus_size_t count)
862 while (count--) {
863 __shpcic_mem_write_2(bsh, offset, *addr++);
867 void
868 shpcic_mem_write_multi_4(void *v, bus_space_handle_t bsh,
869 bus_size_t offset, const uint32_t *addr, bus_size_t count)
872 while (count--) {
873 __shpcic_mem_write_4(bsh, offset, *addr++);
878 * write region
880 void
881 shpcic_io_write_region_1(void *v, bus_space_handle_t bsh,
882 bus_size_t offset, const uint8_t *addr, bus_size_t count)
885 while (count--) {
886 __shpcic_io_write_1(bsh, offset, *addr++);
887 offset += 1;
891 void
892 shpcic_io_write_region_2(void *v, bus_space_handle_t bsh,
893 bus_size_t offset, const uint16_t *addr, bus_size_t count)
896 while (count--) {
897 __shpcic_io_write_2(bsh, offset, *addr++);
898 offset += 2;
902 void
903 shpcic_io_write_region_4(void *v, bus_space_handle_t bsh,
904 bus_size_t offset, const uint32_t *addr, bus_size_t count)
907 while (count--) {
908 __shpcic_io_write_4(bsh, offset, *addr++);
909 offset += 4;
913 void
914 shpcic_mem_write_region_1(void *v, bus_space_handle_t bsh,
915 bus_size_t offset, const uint8_t *addr, bus_size_t count)
918 while (count--) {
919 __shpcic_mem_write_1(bsh, offset, *addr++);
920 offset += 1;
924 void
925 shpcic_mem_write_region_2(void *v, bus_space_handle_t bsh,
926 bus_size_t offset, const uint16_t *addr, bus_size_t count)
929 while (count--) {
930 __shpcic_mem_write_2(bsh, offset, *addr++);
931 offset += 2;
935 void
936 shpcic_mem_write_region_4(void *v, bus_space_handle_t bsh,
937 bus_size_t offset, const uint32_t *addr, bus_size_t count)
940 while (count--) {
941 __shpcic_mem_write_4(bsh, offset, *addr++);
942 offset += 4;
947 * set multi
949 void
950 shpcic_io_set_multi_1(void *v, bus_space_handle_t bsh,
951 bus_size_t offset, uint8_t value, bus_size_t count)
954 while (count--) {
955 __shpcic_io_write_1(bsh, offset, value);
959 void
960 shpcic_io_set_multi_2(void *v, bus_space_handle_t bsh,
961 bus_size_t offset, uint16_t value, bus_size_t count)
964 while (count--) {
965 __shpcic_io_write_2(bsh, offset, value);
969 void
970 shpcic_io_set_multi_4(void *v, bus_space_handle_t bsh,
971 bus_size_t offset, uint32_t value, bus_size_t count)
974 while (count--) {
975 __shpcic_io_write_4(bsh, offset, value);
979 void
980 shpcic_mem_set_multi_1(void *v, bus_space_handle_t bsh,
981 bus_size_t offset, uint8_t value, bus_size_t count)
984 while (count--) {
985 __shpcic_mem_write_1(bsh, offset, value);
989 void
990 shpcic_mem_set_multi_2(void *v, bus_space_handle_t bsh,
991 bus_size_t offset, uint16_t value, bus_size_t count)
994 while (count--) {
995 __shpcic_mem_write_2(bsh, offset, value);
999 void
1000 shpcic_mem_set_multi_4(void *v, bus_space_handle_t bsh,
1001 bus_size_t offset, uint32_t value, bus_size_t count)
1004 while (count--) {
1005 __shpcic_mem_write_4(bsh, offset, value);
1010 * set region
1012 void
1013 shpcic_io_set_region_1(void *v, bus_space_handle_t bsh,
1014 bus_size_t offset, uint8_t value, bus_size_t count)
1017 while (count--) {
1018 __shpcic_io_write_1(bsh, offset, value);
1019 offset += 1;
1023 void
1024 shpcic_io_set_region_2(void *v, bus_space_handle_t bsh,
1025 bus_size_t offset, uint16_t value, bus_size_t count)
1028 while (count--) {
1029 __shpcic_io_write_2(bsh, offset, value);
1030 offset += 2;
1034 void
1035 shpcic_io_set_region_4(void *v, bus_space_handle_t bsh,
1036 bus_size_t offset, uint32_t value, bus_size_t count)
1039 while (count--) {
1040 __shpcic_io_write_4(bsh, offset, value);
1041 offset += 4;
1045 void
1046 shpcic_mem_set_region_1(void *v, bus_space_handle_t bsh,
1047 bus_size_t offset, uint8_t value, bus_size_t count)
1050 while (count--) {
1051 __shpcic_mem_write_1(bsh, offset, value);
1052 offset += 1;
1056 void
1057 shpcic_mem_set_region_2(void *v, bus_space_handle_t bsh,
1058 bus_size_t offset, uint16_t value, bus_size_t count)
1061 while (count--) {
1062 __shpcic_mem_write_2(bsh, offset, value);
1063 offset += 2;
1067 void
1068 shpcic_mem_set_region_4(void *v, bus_space_handle_t bsh,
1069 bus_size_t offset, uint32_t value, bus_size_t count)
1072 while (count--) {
1073 __shpcic_mem_write_4(bsh, offset, value);
1074 offset += 4;
1079 * copy region
1081 void
1082 shpcic_io_copy_region_1(void *v, bus_space_handle_t bsh1,
1083 bus_size_t off1, bus_space_handle_t bsh2, bus_size_t off2, bus_size_t count)
1085 u_long addr1 = bsh1 + off1;
1086 u_long addr2 = bsh2 + off2;
1087 uint8_t value;
1089 if (addr1 >= addr2) { /* src after dest: copy forward */
1090 while (count--) {
1091 value = __shpcic_io_read_1(bsh1, off1);
1092 __shpcic_io_write_1(bsh2, off2, value);
1093 off1 += 1;
1094 off2 += 1;
1096 } else { /* dest after src: copy backwards */
1097 off1 += (count - 1) * 1;
1098 off2 += (count - 1) * 1;
1099 while (count--) {
1100 value = __shpcic_io_read_1(bsh1, off1);
1101 __shpcic_io_write_1(bsh2, off2, value);
1102 off1 -= 1;
1103 off2 -= 1;
1108 void
1109 shpcic_io_copy_region_2(void *v, bus_space_handle_t bsh1,
1110 bus_size_t off1, bus_space_handle_t bsh2, bus_size_t off2, bus_size_t count)
1112 u_long addr1 = bsh1 + off1;
1113 u_long addr2 = bsh2 + off2;
1114 uint16_t value;
1116 if (addr1 >= addr2) { /* src after dest: copy forward */
1117 while (count--) {
1118 value = __shpcic_io_read_2(bsh1, off1);
1119 __shpcic_io_write_2(bsh2, off2, value);
1120 off1 += 2;
1121 off2 += 2;
1123 } else { /* dest after src: copy backwards */
1124 off1 += (count - 1) * 2;
1125 off2 += (count - 1) * 2;
1126 while (count--) {
1127 value = __shpcic_io_read_2(bsh1, off1);
1128 __shpcic_io_write_2(bsh2, off2, value);
1129 off1 -= 2;
1130 off2 -= 2;
1135 void
1136 shpcic_io_copy_region_4(void *v, bus_space_handle_t bsh1,
1137 bus_size_t off1, bus_space_handle_t bsh2, bus_size_t off2, bus_size_t count)
1139 u_long addr1 = bsh1 + off1;
1140 u_long addr2 = bsh2 + off2;
1141 uint32_t value;
1143 if (addr1 >= addr2) { /* src after dest: copy forward */
1144 while (count--) {
1145 value = __shpcic_io_read_4(bsh1, off1);
1146 __shpcic_io_write_4(bsh2, off2, value);
1147 off1 += 4;
1148 off2 += 4;
1150 } else { /* dest after src: copy backwards */
1151 off1 += (count - 1) * 4;
1152 off2 += (count - 1) * 4;
1153 while (count--) {
1154 value = __shpcic_io_read_4(bsh1, off1);
1155 __shpcic_io_write_4(bsh2, off2, value);
1156 off1 -= 4;
1157 off2 -= 4;
1162 void
1163 shpcic_mem_copy_region_1(void *v, bus_space_handle_t bsh1,
1164 bus_size_t off1, bus_space_handle_t bsh2, bus_size_t off2, bus_size_t count)
1166 u_long addr1 = bsh1 + off1;
1167 u_long addr2 = bsh2 + off2;
1168 uint8_t value;
1170 if (addr1 >= addr2) { /* src after dest: copy forward */
1171 while (count--) {
1172 value = __shpcic_mem_read_1(bsh1, off1);
1173 __shpcic_mem_write_1(bsh2, off2, value);
1174 off1 += 1;
1175 off2 += 1;
1177 } else { /* dest after src: copy backwards */
1178 off1 += (count - 1) * 1;
1179 off2 += (count - 1) * 1;
1180 while (count--) {
1181 value = __shpcic_mem_read_1(bsh1, off1);
1182 __shpcic_mem_write_1(bsh2, off2, value);
1183 off1 -= 1;
1184 off2 -= 1;
1189 void
1190 shpcic_mem_copy_region_2(void *v, bus_space_handle_t bsh1,
1191 bus_size_t off1, bus_space_handle_t bsh2, bus_size_t off2, bus_size_t count)
1193 u_long addr1 = bsh1 + off1;
1194 u_long addr2 = bsh2 + off2;
1195 uint16_t value;
1197 if (addr1 >= addr2) { /* src after dest: copy forward */
1198 while (count--) {
1199 value = __shpcic_mem_read_2(bsh1, off1);
1200 __shpcic_mem_write_2(bsh2, off2, value);
1201 off1 += 2;
1202 off2 += 2;
1204 } else { /* dest after src: copy backwards */
1205 off1 += (count - 1) * 2;
1206 off2 += (count - 1) * 2;
1207 while (count--) {
1208 value = __shpcic_mem_read_2(bsh1, off1);
1209 __shpcic_mem_write_2(bsh2, off2, value);
1210 off1 -= 2;
1211 off2 -= 2;
1216 void
1217 shpcic_mem_copy_region_4(void *v, bus_space_handle_t bsh1,
1218 bus_size_t off1, bus_space_handle_t bsh2, bus_size_t off2, bus_size_t count)
1220 u_long addr1 = bsh1 + off1;
1221 u_long addr2 = bsh2 + off2;
1222 uint32_t value;
1224 if (addr1 >= addr2) { /* src after dest: copy forward */
1225 while (count--) {
1226 value = __shpcic_mem_read_4(bsh1, off1);
1227 __shpcic_mem_write_4(bsh2, off2, value);
1228 off1 += 4;
1229 off2 += 4;
1231 } else { /* dest after src: copy backwards */
1232 off1 += (count - 1) * 4;
1233 off2 += (count - 1) * 4;
1234 while (count--) {
1235 value = __shpcic_mem_read_4(bsh1, off1);
1236 __shpcic_mem_write_4(bsh2, off2, value);
1237 off1 -= 4;
1238 off2 -= 4;