summaryrefslogtreecommitdiff
path: root/sys/arch/landisk/dev/obio.c
blob: 4c7208a720da6fa70078cb903f1a398df4f2bcc4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
/*	$OpenBSD: obio.c,v 1.2 2006/10/11 20:34:19 miod Exp $	*/
/*	$NetBSD: obio.c,v 1.1 2006/09/01 21:26:18 uwe Exp $	*/

/*-
 * Copyright (c) 1998 The NetBSD Foundation, Inc.
 * All rights reserved.
 *
 * This code is derived from software contributed to The NetBSD Foundation
 * by Charles M. Hannum.
 *
 * 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.
 * 3. All advertising materials mentioning features or use of this software
 *    must display the following acknowledgement:
 *        This product includes software developed by the NetBSD
 *        Foundation, Inc. and its contributors.
 * 4. Neither the name of The NetBSD Foundation nor the names of its
 *    contributors may be used to endorse or promote products derived
 *    from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
 * ``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 FOUNDATION OR CONTRIBUTORS
 * 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/param.h>
#include <sys/systm.h>
#include <sys/device.h>

#include <uvm/uvm_extern.h>

#include <sh/devreg.h>
#include <sh/mmu.h>
#include <sh/pmap.h>
#include <sh/pte.h>

#include <machine/bus.h>
#include <machine/cpu.h>
#include <machine/intr.h>

#include <landisk/dev/obiovar.h>

int	obio_match(struct device *, void *, void *);
void	obio_attach(struct device *, struct device *, void *);
int	obio_print(void *, const char *);
int	obio_search(struct device *, void *, void *);

struct cfattach obio_ca = {
	sizeof(struct obio_softc), obio_match, obio_attach
};

struct cfdriver obio_cd = {
	0, "obio", DV_DULL
};

int
obio_match(struct device *parent, void *vcf, void *aux)
{
	struct obiobus_attach_args *oba = aux;

	if (strcmp(oba->oba_busname, obio_cd.cd_name) != 0)
		return (0);

	return (1);
}

void
obio_attach(struct device *parent, struct device *self, void *aux)
{
	struct obio_softc *sc = (struct obio_softc *)self;
	struct obiobus_attach_args *oba = aux;

	printf("\n");

	sc->sc_iot = oba->oba_iot;
	sc->sc_memt = oba->oba_memt;

	config_search(obio_search, self, NULL);
}

int
obio_search(struct device *parent, void *vcf, void *aux)
{
	struct obio_softc *sc = (struct obio_softc *)parent;
	struct cfdata *cf = vcf;
	struct obio_attach_args oa;
	struct obio_io res_io[1];
	struct obio_iomem res_mem[1];
	struct obio_irq res_irq[1];

	oa.oa_iot = sc->sc_iot;
	oa.oa_memt = sc->sc_memt;

	res_io[0].or_addr = cf->cf_iobase;
	res_io[0].or_size = cf->cf_iosize;

	res_mem[0].or_addr = cf->cf_maddr;
	res_mem[0].or_size = cf->cf_msize;

	res_irq[0].or_irq = cf->cf_irq;

	oa.oa_io = res_io;
	oa.oa_nio = 1;

	oa.oa_iomem = res_mem;
	oa.oa_niomem = 1;

	oa.oa_irq = res_irq;
	oa.oa_nirq = 1;

	if ((*cf->cf_attach->ca_match)(parent, cf, &oa) == 0)
		return (0);

	config_attach(parent, cf, &oa, obio_print);
	return (1);
}

int
obio_print(void *args, const char *name)
{
	struct obio_attach_args *oa = args;
	const char *sep;
	int i;

	if (oa->oa_nio) {
		sep = "";
		printf(" port ");
		for (i = 0; i < oa->oa_nio; i++) {
			if (oa->oa_io[i].or_size == 0)
				continue;
			printf("%s0x%x", sep, oa->oa_io[i].or_addr);
			if (oa->oa_io[i].or_size > 1)
				printf("-0x%x", oa->oa_io[i].or_addr +
				    oa->oa_io[i].or_size - 1);
			sep = ",";
		}
	}

	if (oa->oa_niomem) {
		sep = "";
		printf(" iomem ");
		for (i = 0; i < oa->oa_niomem; i++) {
			if (oa->oa_iomem[i].or_size == 0)
				continue;
			printf("%s0x%x", sep, oa->oa_iomem[i].or_addr);
			if (oa->oa_iomem[i].or_size > 1)
				printf("-0x%x", oa->oa_iomem[i].or_addr +
				    oa->oa_iomem[i].or_size - 1);
			sep = ",";
		}
	}

	if (oa->oa_nirq) {
		sep = "";
		printf(" irq ");
		for (i = 0; i < oa->oa_nirq; i++) {
			if (oa->oa_irq[i].or_irq == IRQUNK)
				continue;
			printf("%s%d", sep, oa->oa_irq[i].or_irq);
			sep = ",";
		}
	}

	return (UNCONF);
}

/*
 * Set up an interrupt handler to start being called.
 */
void *
obio_intr_establish(int irq, int level, int (*ih_fun)(void *), void *ih_arg,
    const char *ih_name)
{
	return extintr_establish(irq, level, ih_fun, ih_arg, ih_name);
}

/*
 * Deregister an interrupt handler.
 */
void
obio_intr_disestablish(void *arg)
{
	extintr_disestablish(arg);
}

/*
 * on-board I/O bus space
 */
#define	OBIO_IOMEM_IO		0	/* space is i/o space */
#define	OBIO_IOMEM_MEM		1	/* space is mem space */
#define	OBIO_IOMEM_PCMCIA_IO	2	/* PCMCIA IO space */
#define	OBIO_IOMEM_PCMCIA_MEM	3	/* PCMCIA Mem space */
#define	OBIO_IOMEM_PCMCIA_ATT	4	/* PCMCIA Attr space */
#define	OBIO_IOMEM_PCMCIA_8BIT	0x8000	/* PCMCIA BUS 8 BIT WIDTH */
#define	OBIO_IOMEM_PCMCIA_IO8 \
	    (OBIO_IOMEM_PCMCIA_IO|OBIO_IOMEM_PCMCIA_8BIT)
#define	OBIO_IOMEM_PCMCIA_MEM8 \
	    (OBIO_IOMEM_PCMCIA_MEM|OBIO_IOMEM_PCMCIA_8BIT)
#define	OBIO_IOMEM_PCMCIA_ATT8 \
	    (OBIO_IOMEM_PCMCIA_ATT|OBIO_IOMEM_PCMCIA_8BIT)

int obio_iomem_map(void *v, bus_addr_t bpa, bus_size_t size, int flags,
    bus_space_handle_t *bshp);
void obio_iomem_unmap(void *v, bus_space_handle_t bsh, bus_size_t size);
int obio_iomem_subregion(void *v, bus_space_handle_t bsh,
    bus_size_t offset, bus_size_t size, bus_space_handle_t *nbshp);
int obio_iomem_alloc(void *v, bus_addr_t rstart, bus_addr_t rend,
    bus_size_t size, bus_size_t alignment, bus_size_t boundary, int flags,
    bus_addr_t *bpap, bus_space_handle_t *bshp);
void obio_iomem_free(void *v, bus_space_handle_t bsh, bus_size_t size);

int obio_iomem_add_mapping(bus_addr_t, bus_size_t, int,
    bus_space_handle_t *);

int
obio_iomem_add_mapping(bus_addr_t bpa, bus_size_t size, int type,
    bus_space_handle_t *bshp)
{
	u_long pa, endpa;
	vaddr_t va;
	pt_entry_t *pte;
	unsigned int m = 0;
	int io_type = type & ~OBIO_IOMEM_PCMCIA_8BIT;

	pa = trunc_page(bpa);
	endpa = round_page(bpa + size);

#ifdef DIAGNOSTIC
	if (endpa <= pa)
		panic("obio_iomem_add_mapping: overflow");
#endif

	va = uvm_km_alloc(kernel_map, endpa - pa);
	if (va == 0){
		printf("obio_iomem_add_mapping: nomem\n");
		return (ENOMEM);
	}

	*bshp = (bus_space_handle_t)(va + (bpa & PGOFSET));

#define MODE(t, s)							\
	((t) & OBIO_IOMEM_PCMCIA_8BIT) ?				\
		_PG_PCMCIA_ ## s ## 8 :					\
		_PG_PCMCIA_ ## s ## 16
	switch (io_type) {
	default:
		panic("unknown pcmcia space.");
		/* NOTREACHED */
	case OBIO_IOMEM_PCMCIA_IO:
		m = MODE(type, IO);
		break;
	case OBIO_IOMEM_PCMCIA_MEM:
		m = MODE(type, MEM);
		break;
	case OBIO_IOMEM_PCMCIA_ATT:
		m = MODE(type, ATTR);
		break;
	}
#undef MODE

	for (; pa < endpa; pa += PAGE_SIZE, va += PAGE_SIZE) {
		pmap_kenter_pa(va, pa, VM_PROT_READ | VM_PROT_WRITE);
		pte = __pmap_kpte_lookup(va);
		KDASSERT(pte);
		*pte |= m;  /* PTEA PCMCIA assistant bit */
		sh_tlb_update(0, va, *pte);
	}

	return (0);
}

int
obio_iomem_map(void *v, bus_addr_t bpa, bus_size_t size,
    int flags, bus_space_handle_t *bshp)
{
	bus_addr_t addr = SH3_PHYS_TO_P2SEG(bpa);
	int error;

	KASSERT((bpa & SH3_PHYS_MASK) == bpa);

	if (bpa < 0x14000000 || bpa >= 0x1c000000) {
		/* CS0,1,2,3,4,7 */
		*bshp = (bus_space_handle_t)addr;
		return (0);
	}

	/* CS5,6 */
	error = obio_iomem_add_mapping(addr, size, (int)(u_long)v, bshp);

	return (error);
}

void
obio_iomem_unmap(void *v, bus_space_handle_t bsh, bus_size_t size)
{
	u_long va, endva;
	bus_addr_t bpa;

	if (bsh >= SH3_P2SEG_BASE && bsh <= SH3_P2SEG_END) {
		/* maybe CS0,1,2,3,4,7 */
		return;
	}

	/* CS5,6 */
	va = trunc_page(bsh);
	endva = round_page(bsh + size);

#ifdef DIAGNOSTIC
	if (endva <= va)
		panic("obio_io_unmap: overflow");
#endif

	pmap_extract(pmap_kernel(), va, &bpa);
	bpa += bsh & PGOFSET;

	pmap_kremove(va, endva - va);

	/*
	 * Free the kernel virtual mapping.
	 */
	uvm_km_free(kernel_map, va, endva - va);
}

int
obio_iomem_subregion(void *v, bus_space_handle_t bsh,
    bus_size_t offset, bus_size_t size, bus_space_handle_t *nbshp)
{
	*nbshp = bsh + offset;

	return (0);
}

int
obio_iomem_alloc(void *v, bus_addr_t rstart, bus_addr_t rend,
    bus_size_t size, bus_size_t alignment, bus_size_t boundary, int flags,
    bus_addr_t *bpap, bus_space_handle_t *bshp)
{
	*bshp = *bpap = rstart;

	return (0);
}

void
obio_iomem_free(void *v, bus_space_handle_t bsh, bus_size_t size)
{
	obio_iomem_unmap(v, bsh, size);
}

/*
 * on-board I/O bus space read/write
 */
uint8_t obio_iomem_read_1(void *v, bus_space_handle_t bsh, bus_size_t offset);
uint16_t obio_iomem_read_2(void *v, bus_space_handle_t bsh, bus_size_t offset);
uint32_t obio_iomem_read_4(void *v, bus_space_handle_t bsh, bus_size_t offset);
void obio_iomem_read_multi_1(void *v, bus_space_handle_t bsh,
    bus_size_t offset, uint8_t *addr, bus_size_t count);
void obio_iomem_read_multi_2(void *v, bus_space_handle_t bsh,
    bus_size_t offset, uint16_t *addr, bus_size_t count);
void obio_iomem_read_multi_4(void *v, bus_space_handle_t bsh,
    bus_size_t offset, uint32_t *addr, bus_size_t count);
void obio_iomem_read_raw_multi_2(void *v, bus_space_handle_t bsh,
    bus_size_t offset, uint8_t *addr, bus_size_t count);
void obio_iomem_read_raw_multi_4(void *v, bus_space_handle_t bsh,
    bus_size_t offset, uint8_t *addr, bus_size_t count);
void obio_iomem_read_region_1(void *v, bus_space_handle_t bsh,
    bus_size_t offset, uint8_t *addr, bus_size_t count);
void obio_iomem_read_region_2(void *v, bus_space_handle_t bsh,
    bus_size_t offset, uint16_t *addr, bus_size_t count);
void obio_iomem_read_region_4(void *v, bus_space_handle_t bsh,
    bus_size_t offset, uint32_t *addr, bus_size_t count);
void obio_iomem_read_raw_region_2(void *v, bus_space_handle_t bsh,
    bus_size_t offset, uint8_t *addr, bus_size_t count);
void obio_iomem_read_raw_region_4(void *v, bus_space_handle_t bsh,
    bus_size_t offset, uint8_t *addr, bus_size_t count);
void obio_iomem_write_1(void *v, bus_space_handle_t bsh, bus_size_t offset,
    uint8_t value);
void obio_iomem_write_2(void *v, bus_space_handle_t bsh, bus_size_t offset,
    uint16_t value);
void obio_iomem_write_4(void *v, bus_space_handle_t bsh, bus_size_t offset,
    uint32_t value);
void obio_iomem_write_multi_1(void *v, bus_space_handle_t bsh,
    bus_size_t offset, const uint8_t *addr, bus_size_t count);
void obio_iomem_write_multi_2(void *v, bus_space_handle_t bsh,
    bus_size_t offset, const uint16_t *addr, bus_size_t count);
void obio_iomem_write_multi_4(void *v, bus_space_handle_t bsh,
    bus_size_t offset, const uint32_t *addr, bus_size_t count);
void obio_iomem_write_raw_multi_2(void *v, bus_space_handle_t bsh,
    bus_size_t offset, const uint8_t *addr, bus_size_t count);
void obio_iomem_write_raw_multi_4(void *v, bus_space_handle_t bsh,
    bus_size_t offset, const uint8_t *addr, bus_size_t count);
void obio_iomem_write_region_1(void *v, bus_space_handle_t bsh,
    bus_size_t offset, const uint8_t *addr, bus_size_t count);
void obio_iomem_write_region_2(void *v, bus_space_handle_t bsh,
    bus_size_t offset, const uint16_t *addr, bus_size_t count);
void obio_iomem_write_region_4(void *v, bus_space_handle_t bsh,
    bus_size_t offset, const uint32_t *addr, bus_size_t count);
void obio_iomem_write_raw_region_2(void *v, bus_space_handle_t bsh,
    bus_size_t offset, const uint8_t *addr, bus_size_t count);
void obio_iomem_write_raw_region_4(void *v, bus_space_handle_t bsh,
    bus_size_t offset, const uint8_t *addr, bus_size_t count);
void obio_iomem_set_multi_1(void *v, bus_space_handle_t bsh, bus_size_t offset,
    uint8_t val, bus_size_t count);
void obio_iomem_set_multi_2(void *v, bus_space_handle_t bsh, bus_size_t offset,
    uint16_t val, bus_size_t count);
void obio_iomem_set_multi_4(void *v, bus_space_handle_t bsh, bus_size_t offset,
    uint32_t val, bus_size_t count);
void obio_iomem_set_region_1(void *v, bus_space_handle_t bsh,
    bus_size_t offset, uint8_t val, bus_size_t count);
void obio_iomem_set_region_2(void *v, bus_space_handle_t bsh,
    bus_size_t offset, uint16_t val, bus_size_t count);
void obio_iomem_set_region_4(void *v, bus_space_handle_t bsh,
    bus_size_t offset, uint32_t val, bus_size_t count);
void obio_iomem_copy_region_1(void *v, bus_space_handle_t h1, bus_size_t o1,
    bus_space_handle_t h2, bus_size_t o2, bus_size_t count);
void obio_iomem_copy_region_2(void *v, bus_space_handle_t h1, bus_size_t o1,
    bus_space_handle_t h2, bus_size_t o2, bus_size_t count);
void obio_iomem_copy_region_4(void *v, bus_space_handle_t h1, bus_size_t o1,
    bus_space_handle_t h2, bus_size_t o2, bus_size_t count);

struct _bus_space obio_bus_io =
{
	.bs_cookie = (void *)OBIO_IOMEM_PCMCIA_IO,

	.bs_map = obio_iomem_map,
	.bs_unmap = obio_iomem_unmap,
	.bs_subregion = obio_iomem_subregion,

	.bs_alloc = obio_iomem_alloc,
	.bs_free = obio_iomem_free,

	.bs_r_1 = obio_iomem_read_1,
	.bs_r_2 = obio_iomem_read_2,
	.bs_r_4 = obio_iomem_read_4,

	.bs_rm_1 = obio_iomem_read_multi_1,
	.bs_rm_2 = obio_iomem_read_multi_2,
	.bs_rm_4 = obio_iomem_read_multi_4,

	.bs_rrm_2 = obio_iomem_read_raw_multi_2,
	.bs_rrm_4 = obio_iomem_read_raw_multi_4,

	.bs_rr_1 = obio_iomem_read_region_1,
	.bs_rr_2 = obio_iomem_read_region_2,
	.bs_rr_4 = obio_iomem_read_region_4,

	.bs_rrr_2 = obio_iomem_read_raw_region_2,
	.bs_rrr_4 = obio_iomem_read_raw_region_4,

	.bs_w_1 = obio_iomem_write_1,
	.bs_w_2 = obio_iomem_write_2,
	.bs_w_4 = obio_iomem_write_4,

	.bs_wm_1 = obio_iomem_write_multi_1,
	.bs_wm_2 = obio_iomem_write_multi_2,
	.bs_wm_4 = obio_iomem_write_multi_4,

	.bs_wrm_2 = obio_iomem_write_raw_multi_2,
	.bs_wrm_4 = obio_iomem_write_raw_multi_4,

	.bs_wr_1 = obio_iomem_write_region_1,
	.bs_wr_2 = obio_iomem_write_region_2,
	.bs_wr_4 = obio_iomem_write_region_4,

	.bs_wrr_2 = obio_iomem_write_raw_region_2,
	.bs_wrr_4 = obio_iomem_write_raw_region_4,

	.bs_sm_1 = obio_iomem_set_multi_1,
	.bs_sm_2 = obio_iomem_set_multi_2,
	.bs_sm_4 = obio_iomem_set_multi_4,

	.bs_sr_1 = obio_iomem_set_region_1,
	.bs_sr_2 = obio_iomem_set_region_2,
	.bs_sr_4 = obio_iomem_set_region_4,

	.bs_c_1 = obio_iomem_copy_region_1,
	.bs_c_2 = obio_iomem_copy_region_2,
	.bs_c_4 = obio_iomem_copy_region_4,
};

struct _bus_space obio_bus_mem =
{
	.bs_cookie = (void *)OBIO_IOMEM_PCMCIA_MEM,

	.bs_map = obio_iomem_map,
	.bs_unmap = obio_iomem_unmap,
	.bs_subregion = obio_iomem_subregion,

	.bs_alloc = obio_iomem_alloc,
	.bs_free = obio_iomem_free,

	.bs_r_1 = obio_iomem_read_1,
	.bs_r_2 = obio_iomem_read_2,
	.bs_r_4 = obio_iomem_read_4,

	.bs_rm_1 = obio_iomem_read_multi_1,
	.bs_rm_2 = obio_iomem_read_multi_2,
	.bs_rm_4 = obio_iomem_read_multi_4,

	.bs_rrm_2 = obio_iomem_read_raw_multi_2,
	.bs_rrm_4 = obio_iomem_read_raw_multi_4,

	.bs_rr_1 = obio_iomem_read_region_1,
	.bs_rr_2 = obio_iomem_read_region_2,
	.bs_rr_4 = obio_iomem_read_region_4,

	.bs_rrr_2 = obio_iomem_read_raw_region_2,
	.bs_rrr_4 = obio_iomem_read_raw_region_4,

	.bs_w_1 = obio_iomem_write_1,
	.bs_w_2 = obio_iomem_write_2,
	.bs_w_4 = obio_iomem_write_4,

	.bs_wm_1 = obio_iomem_write_multi_1,
	.bs_wm_2 = obio_iomem_write_multi_2,
	.bs_wm_4 = obio_iomem_write_multi_4,

	.bs_wrm_2 = obio_iomem_write_raw_multi_2,
	.bs_wrm_4 = obio_iomem_write_raw_multi_4,

	.bs_wr_1 = obio_iomem_write_region_1,
	.bs_wr_2 = obio_iomem_write_region_2,
	.bs_wr_4 = obio_iomem_write_region_4,

	.bs_wrr_2 = obio_iomem_write_raw_region_2,
	.bs_wrr_4 = obio_iomem_write_raw_region_4,

	.bs_sm_1 = obio_iomem_set_multi_1,
	.bs_sm_2 = obio_iomem_set_multi_2,
	.bs_sm_4 = obio_iomem_set_multi_4,

	.bs_sr_1 = obio_iomem_set_region_1,
	.bs_sr_2 = obio_iomem_set_region_2,
	.bs_sr_4 = obio_iomem_set_region_4,

	.bs_c_1 = obio_iomem_copy_region_1,
	.bs_c_2 = obio_iomem_copy_region_2,
	.bs_c_4 = obio_iomem_copy_region_4,
};

/* read */
uint8_t
obio_iomem_read_1(void *v, bus_space_handle_t bsh, bus_size_t offset)
{
	return *(volatile uint8_t *)(bsh + offset);
}

uint16_t
obio_iomem_read_2(void *v, bus_space_handle_t bsh, bus_size_t offset)
{
	return *(volatile uint16_t *)(bsh + offset);
}

uint32_t
obio_iomem_read_4(void *v, bus_space_handle_t bsh, bus_size_t offset)
{
	return *(volatile uint32_t *)(bsh + offset);
}

void
obio_iomem_read_multi_1(void *v, bus_space_handle_t bsh,
    bus_size_t offset, uint8_t *addr, bus_size_t count)
{
	volatile uint8_t *p = (void *)(bsh + offset);

	while (count--) {
		*addr++ = *p;
	}
}

void
obio_iomem_read_multi_2(void *v, bus_space_handle_t bsh,
    bus_size_t offset, uint16_t *addr, bus_size_t count)
{
	volatile uint16_t *p = (void *)(bsh + offset);

	while (count--) {
		*addr++ = *p;
	}
}

void
obio_iomem_read_multi_4(void *v, bus_space_handle_t bsh,
    bus_size_t offset, uint32_t *addr, bus_size_t count)
{
	volatile uint32_t *p = (void *)(bsh + offset);

	while (count--) {
		*addr++ = *p;
	}
}

void
obio_iomem_read_raw_multi_2(void *v, bus_space_handle_t bsh,
    bus_size_t offset, uint8_t *addr, bus_size_t count)
{
	volatile uint16_t *p = (void *)(bsh + offset);

	count >>= 1;
	while (count--) {
		*(uint16_t *)addr = *p;
		addr += 2;
	}
}

void
obio_iomem_read_raw_multi_4(void *v, bus_space_handle_t bsh,
    bus_size_t offset, uint8_t *addr, bus_size_t count)
{
	volatile uint32_t *p = (void *)(bsh + offset);

	count >>= 2;
	while (count--) {
		*(uint32_t *)addr = *p;
		addr += 4;
	}
}

void
obio_iomem_read_region_1(void *v, bus_space_handle_t bsh,
    bus_size_t offset, uint8_t *addr, bus_size_t count)
{
	volatile uint8_t *p = (void *)(bsh + offset);

	while (count--) {
		*addr++ = *p++;
	}
}

void
obio_iomem_read_region_2(void *v, bus_space_handle_t bsh,
    bus_size_t offset, uint16_t *addr, bus_size_t count)
{
	volatile uint16_t *p = (void *)(bsh + offset);

	while (count--) {
		*addr++ = *p++;
	}
}

void
obio_iomem_read_region_4(void *v, bus_space_handle_t bsh,
    bus_size_t offset, uint32_t *addr, bus_size_t count)
{
	volatile uint32_t *p = (void *)(bsh + offset);

	while (count--) {
		*addr++ = *p++;
	}
}

void
obio_iomem_read_raw_region_2(void *v, bus_space_handle_t bsh,
    bus_size_t offset, uint8_t *addr, bus_size_t count)
{
	volatile uint16_t *p = (void *)(bsh + offset);

	count >>= 1;
	while (count--) {
		*(uint16_t *)addr = *p++;
		addr += 2;
	}
}

void
obio_iomem_read_raw_region_4(void *v, bus_space_handle_t bsh,
    bus_size_t offset, uint8_t *addr, bus_size_t count)
{
	volatile uint32_t *p = (void *)(bsh + offset);

	count >>= 2;
	while (count--) {
		*(uint32_t *)addr = *p++;
		addr += 4;
	}
}

/* write */
void
obio_iomem_write_1(void *v, bus_space_handle_t bsh, bus_size_t offset,
    uint8_t value)
{
	*(volatile uint8_t *)(bsh + offset) = value;
}

void
obio_iomem_write_2(void *v, bus_space_handle_t bsh, bus_size_t offset,
    uint16_t value)
{
	*(volatile uint16_t *)(bsh + offset) = value;
}

void
obio_iomem_write_4(void *v, bus_space_handle_t bsh, bus_size_t offset,
    uint32_t value)
{
	*(volatile uint32_t *)(bsh + offset) = value;
}

void
obio_iomem_write_multi_1(void *v, bus_space_handle_t bsh,
    bus_size_t offset, const uint8_t *addr, bus_size_t count)
{
	volatile uint8_t *p = (void *)(bsh + offset);

	while (count--) {
		*p = *addr++;
	}
}

void
obio_iomem_write_multi_2(void *v, bus_space_handle_t bsh,
    bus_size_t offset, const uint16_t *addr, bus_size_t count)
{
	volatile uint16_t *p = (void *)(bsh + offset);

	while (count--) {
		*p = *addr++;
	}
}

void
obio_iomem_write_multi_4(void *v, bus_space_handle_t bsh,
    bus_size_t offset, const uint32_t *addr, bus_size_t count)
{
	volatile uint32_t *p = (void *)(bsh + offset);

	while (count--) {
		*p = *addr++;
	}
}

void
obio_iomem_write_raw_multi_2(void *v, bus_space_handle_t bsh,
    bus_size_t offset, const uint8_t *addr, bus_size_t count)
{
	volatile uint16_t *p = (void *)(bsh + offset);

	count >>= 1;
	while (count--) {
		*p = *(uint16_t *)addr;
		addr += 2;
	}
}

void
obio_iomem_write_raw_multi_4(void *v, bus_space_handle_t bsh,
    bus_size_t offset, const uint8_t *addr, bus_size_t count)
{
	volatile uint32_t *p = (void *)(bsh + offset);

	count >>= 2;
	while (count--) {
		*p = *(uint32_t *)addr;
		addr += 4;
	}
}

void
obio_iomem_write_region_1(void *v, bus_space_handle_t bsh,
    bus_size_t offset, const uint8_t *addr, bus_size_t count)
{
	volatile uint8_t *p = (void *)(bsh + offset);

	while (count--) {
		*p++ = *addr++;
	}
}

void
obio_iomem_write_region_2(void *v, bus_space_handle_t bsh,
    bus_size_t offset, const uint16_t *addr, bus_size_t count)
{
	volatile uint16_t *p = (void *)(bsh + offset);

	while (count--) {
		*p++ = *addr++;
	}
}

void
obio_iomem_write_region_4(void *v, bus_space_handle_t bsh,
    bus_size_t offset, const uint32_t *addr, bus_size_t count)
{
	volatile uint32_t *p = (void *)(bsh + offset);

	while (count--) {
		*p++ = *addr++;
	}
}

void
obio_iomem_write_raw_region_2(void *v, bus_space_handle_t bsh,
    bus_size_t offset, const uint8_t *addr, bus_size_t count)
{
	volatile uint16_t *p = (void *)(bsh + offset);

	count >>= 1;
	while (count--) {
		*p++ = *(uint16_t *)addr;
		addr += 2;
	}
}

void
obio_iomem_write_raw_region_4(void *v, bus_space_handle_t bsh,
    bus_size_t offset, const uint8_t *addr, bus_size_t count)
{
	volatile uint32_t *p = (void *)(bsh + offset);

	count >>= 2;
	while (count--) {
		*p++ = *(uint32_t *)addr;
		addr += 4;
	}
}

void
obio_iomem_set_multi_1(void *v, bus_space_handle_t bsh,
    bus_size_t offset, uint8_t val, bus_size_t count)
{
	volatile uint8_t *p = (void *)(bsh + offset);

	while (count--) {
		*p = val;
	}
}

void
obio_iomem_set_multi_2(void *v, bus_space_handle_t bsh,
    bus_size_t offset, uint16_t val, bus_size_t count)
{
	volatile uint16_t *p = (void *)(bsh + offset);

	while (count--) {
		*p = val;
	}
}

void
obio_iomem_set_multi_4(void *v, bus_space_handle_t bsh,
    bus_size_t offset, uint32_t val, bus_size_t count)
{
	volatile uint32_t *p = (void *)(bsh + offset);

	while (count--) {
		*p = val;
	}
}

void
obio_iomem_set_region_1(void *v, bus_space_handle_t bsh,
    bus_size_t offset, uint8_t val, bus_size_t count)
{
	volatile uint8_t *addr = (void *)(bsh + offset);

	while (count--) {
		*addr++ = val;
	}
}

void
obio_iomem_set_region_2(void *v, bus_space_handle_t bsh,
    bus_size_t offset, uint16_t val, bus_size_t count)
{
	volatile uint16_t *addr = (void *)(bsh + offset);

	while (count--) {
		*addr++ = val;
	}
}

void
obio_iomem_set_region_4(void *v, bus_space_handle_t bsh,
    bus_size_t offset, uint32_t val, bus_size_t count)
{
	volatile uint32_t *addr = (void *)(bsh + offset);

	while (count--) {
		*addr++ = val;
	}
}

void
obio_iomem_copy_region_1(void *v, bus_space_handle_t h1, bus_size_t o1,
    bus_space_handle_t h2, bus_size_t o2, bus_size_t count)
{
	volatile uint8_t *addr1 = (void *)(h1 + o1);
	volatile uint8_t *addr2 = (void *)(h2 + o2);

	if (addr1 >= addr2) {	/* src after dest: copy forward */
		while (count--) {
			*addr2++ = *addr1++;
		}
	} else {		/* dest after src: copy backwards */
		addr1 += count - 1;
		addr2 += count - 1;
		while (count--) {
			*addr2-- = *addr1--;
		}
	}
}

void
obio_iomem_copy_region_2(void *v, bus_space_handle_t h1, bus_size_t o1,
    bus_space_handle_t h2, bus_size_t o2, bus_size_t count)
{
	volatile uint16_t *addr1 = (void *)(h1 + o1);
	volatile uint16_t *addr2 = (void *)(h2 + o2);

	if (addr1 >= addr2) {	/* src after dest: copy forward */
		while (count--) {
			*addr2++ = *addr1++;
		}
	} else {		/* dest after src: copy backwards */
		addr1 += count - 1;
		addr2 += count - 1;
		while (count--) {
			*addr2-- = *addr1--;
		}
	}
}

void
obio_iomem_copy_region_4(void *v, bus_space_handle_t h1, bus_size_t o1,
    bus_space_handle_t h2, bus_size_t o2, bus_size_t count)
{
	volatile uint32_t *addr1 = (void *)(h1 + o1);
	volatile uint32_t *addr2 = (void *)(h2 + o2);

	if (addr1 >= addr2) {	/* src after dest: copy forward */
		while (count--) {
			*addr2++ = *addr1++;
		}
	} else {		/* dest after src: copy backwards */
		addr1 += count - 1;
		addr2 += count - 1;
		while (count--) {
			*addr2-- = *addr1--;
		}
	}
}