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
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
|
/* $OpenBSD: isabr.c,v 1.2 2007/01/14 17:54:45 miod Exp $ */
/*
* Copyright (c) 2007 Miodrag Vallat.
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice, this permission notice, and the disclaimer below
* appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/*
* HP 9000/4xx model `t' single ISA slot attachment
*/
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/device.h>
#include <sys/extent.h>
#include <sys/malloc.h>
#include <machine/autoconf.h>
#include <machine/bus.h>
#include <machine/cpu.h>
#include <machine/hp300spu.h>
#include <uvm/uvm_extern.h>
#include <dev/isa/isareg.h>
#include <dev/isa/isavar.h>
#include <hp300/dev/frodoreg.h>
#include <hp300/dev/frodovar.h>
#include <hp300/dev/isabrreg.h>
int isabr_match(struct device *, void *, void *);
void isabr_attach(struct device *, struct device *, void *);
int isabr_print(void *, const char *);
struct isabr_softc {
struct device sc_dev;
struct extent *sc_io_extent;
struct extent *sc_mem_extent;
};
struct cfattach isabr_ca = {
sizeof(struct isabr_softc), isabr_match, isabr_attach
};
struct cfdriver isabr_cd = {
NULL, "isabr", DV_DULL
};
struct isabr_softc *isabr;
int isabr_bus_space_setup(struct isabr_softc *, struct frodo_attach_args *,
struct isabus_attach_args *);
int
isabr_match(struct device *parent, void *match, void *aux)
{
struct frodo_attach_args *fa = aux;
static int isa_matched = 0;
if (isa_matched != 0)
return (0);
if (strcmp(fa->fa_name, isabr_cd.cd_name) != 0)
return (0);
/*
* We assume parent has checked our physical existence for us.
*/
return (isa_matched = 1);
}
void
isabr_attach(struct device *parent, struct device *self, void *aux)
{
struct isabus_attach_args iba;
struct isabr_softc *sc = (struct isabr_softc *)self;
struct frodo_attach_args *faa = (struct frodo_attach_args *)aux;
bzero(&iba, sizeof(iba));
if (isabr_bus_space_setup(sc, faa, &iba) != 0) {
printf(": can not initialize bus_space\n");
return;
}
printf("\n");
iba.iba_busname = "isa";
config_found(self, &iba, isabr_print);
}
int
isabr_print(void *aux, const char *pnp)
{
if (pnp)
printf("isa at %s", pnp);
return (UNCONF);
}
/*
* ISA support functions
*/
void
isa_attach_hook(struct device *parent, struct device *self,
struct isabus_attach_args *iba)
{
iba->iba_ic = parent; /* isabr0 */
}
/*
* Interrupt handling.
*
* We are currently registering ISA interrupt handlers as Frodo interrupt
* handlers directly. We can because model `t' only have a single slot.
*
* Eventually this should be replaced with an isabr interrupt dispatcher,
* allowing multiple interrupts on the same Frodo line. This would also
* move the ISA-specific acknowledge out of non-ISA Frodo lines processing.
* And this would allow a real intr_disestablish function.
*/
void *
isa_intr_establish(isa_chipset_tag_t ic, int irq, int type, int level,
int (*handler)(void *), void *arg, char *name)
{
struct isabr_softc *sc = (struct isabr_softc *)ic;
struct isr *isr;
int fline;
/*
* Frodo is configured for edge interrupts.
*/
if (type != IST_EDGE) {
#ifdef DIAGNOSTIC
printf("%s: non-edge interrupt type not supported on hp300\n",
name);
#endif
return (NULL);
}
switch (irq) {
case 3:
case 4:
case 5:
case 6:
fline = FRODO_INTR_ILOW;
break;
case 7:
case 9:
case 10:
case 11:
fline = FRODO_INTR_IMID;
break;
case 12:
case 14:
case 15:
fline = FRODO_INTR_IHI;
break;
default:
#ifdef DIAGNOSTIC
printf("%s: ISA irq %d not available on " MACHINE "\n", name);
#endif
return (NULL);
}
isr = (struct isr *)malloc(sizeof(struct isr), M_DEVBUF, M_NOWAIT);
if (isr == NULL)
return (NULL);
isr->isr_func = handler;
isr->isr_arg = arg;
isr->isr_priority = level;
if (frodo_intr_establish(sc->sc_dev.dv_parent, fline, isr, name) == 0)
return (isr);
free(isr, M_DEVBUF);
return (NULL);
}
void
isa_intr_disestablish(isa_chipset_tag_t ic, void *cookie)
{
#if 0
struct isabr_softc *sc = (struct isabr_softc *)ic;
struct isr *isr = cookie;
/* XXX how to find fline back? */
frodo_intr_disestablish(sc->dv_parent, fline);
free(isr, M_DEVBUF);
#else
panic("isa_intr_disestablish");
#endif
}
/*
* Implementation of bus_space mapping for the hp300 isa slot.
*
* Everything is memory mapped, but the I/O space is scattered for better
* userland access control granularity, should we ever provide iopl
* facilities, thus i/o space accesses need their own routines set, while
* memory space simply reuse the ``canonical'' bus_space routines.
*
* For the I/O space, all bus_space_map allocations are extended to a 8 ports
* granularity, so that they span entire, contiguous pages; the handle value
* however needs to keep track of the in-page offset if the first port is
* not aligned to a ``line'' boundary.
*
* I.e, a bus_space_map(0x302, 0xe) call will map the 0x300-0x30f area,
* and return a pointer the 0x302 port. Access routines will then, from
* this pointer, construct a (0x300, 0x02) tuple, which they can use to
* access the remainder of the range.
*/
/*
* ISA I/O space
*/
int hp300_isa_io_map(bus_addr_t, bus_size_t, int, bus_space_handle_t *);
void hp300_isa_io_unmap(bus_space_handle_t, bus_size_t);
int hp300_isa_io_subregion(bus_space_handle_t, bus_size_t, bus_size_t,
bus_space_handle_t *);
void * hp300_isa_io_vaddr(bus_space_handle_t);
u_int8_t hp300_isa_io_bsr1(bus_space_handle_t, bus_size_t);
u_int16_t hp300_isa_io_bsr2(bus_space_handle_t, bus_size_t);
u_int32_t hp300_isa_io_bsr4(bus_space_handle_t, bus_size_t);
u_int16_t __hp300_isa_io_bsr2(bus_space_handle_t, bus_size_t);
u_int32_t __hp300_isa_io_bsr4(bus_space_handle_t, bus_size_t);
void hp300_isa_io_bsrm1(bus_space_handle_t, bus_size_t, u_int8_t *, size_t);
void hp300_isa_io_bsrm2(bus_space_handle_t, bus_size_t, u_int16_t *, size_t);
void hp300_isa_io_bsrm4(bus_space_handle_t, bus_size_t, u_int32_t *, size_t);
void hp300_isa_io_bsrrm2(bus_space_handle_t, bus_size_t, u_int8_t *, size_t);
void hp300_isa_io_bsrrm4(bus_space_handle_t, bus_size_t, u_int8_t *, size_t);
void hp300_isa_io_bsrr1(bus_space_handle_t, bus_size_t, u_int8_t *, size_t);
void hp300_isa_io_bsrr2(bus_space_handle_t, bus_size_t, u_int16_t *, size_t);
void hp300_isa_io_bsrr4(bus_space_handle_t, bus_size_t, u_int32_t *, size_t);
void hp300_isa_io_bsrrr2(bus_space_handle_t, bus_size_t, u_int8_t *, size_t);
void hp300_isa_io_bsrrr4(bus_space_handle_t, bus_size_t, u_int8_t *, size_t);
void hp300_isa_io_bsw1(bus_space_handle_t, bus_size_t, u_int8_t);
void hp300_isa_io_bsw2(bus_space_handle_t, bus_size_t, u_int16_t);
void hp300_isa_io_bsw4(bus_space_handle_t, bus_size_t, u_int32_t);
void __hp300_isa_io_bsw2(bus_space_handle_t, bus_size_t, u_int16_t);
void __hp300_isa_io_bsw4(bus_space_handle_t, bus_size_t, u_int32_t);
void hp300_isa_io_bswm1(bus_space_handle_t, bus_size_t, const u_int8_t *, size_t);
void hp300_isa_io_bswm2(bus_space_handle_t, bus_size_t, const u_int16_t *, size_t);
void hp300_isa_io_bswm4(bus_space_handle_t, bus_size_t, const u_int32_t *, size_t);
void hp300_isa_io_bswrm2(bus_space_handle_t, bus_size_t, const u_int8_t *, size_t);
void hp300_isa_io_bswrm4(bus_space_handle_t, bus_size_t, const u_int8_t *, size_t);
void hp300_isa_io_bswr1(bus_space_handle_t, bus_size_t, const u_int8_t *, size_t);
void hp300_isa_io_bswr2(bus_space_handle_t, bus_size_t, const u_int16_t *, size_t);
void hp300_isa_io_bswr4(bus_space_handle_t, bus_size_t, const u_int32_t *, size_t);
void hp300_isa_io_bswrr2(bus_space_handle_t, bus_size_t, const u_int8_t *, size_t);
void hp300_isa_io_bswrr4(bus_space_handle_t, bus_size_t, const u_int8_t *, size_t);
void hp300_isa_io_bssm1(bus_space_handle_t, bus_size_t, u_int8_t, size_t);
void hp300_isa_io_bssm2(bus_space_handle_t, bus_size_t, u_int16_t, size_t);
void hp300_isa_io_bssm4(bus_space_handle_t, bus_size_t, u_int32_t, size_t);
void hp300_isa_io_bssr1(bus_space_handle_t, bus_size_t, u_int8_t, size_t);
void hp300_isa_io_bssr2(bus_space_handle_t, bus_size_t, u_int16_t, size_t);
void hp300_isa_io_bssr4(bus_space_handle_t, bus_size_t, u_int32_t, size_t);
struct hp300_bus_space_tag hp300_isa_io_tag = {
hp300_isa_io_map,
hp300_isa_io_unmap,
hp300_isa_io_subregion,
hp300_isa_io_vaddr,
hp300_isa_io_bsr1,
hp300_isa_io_bsr2,
hp300_isa_io_bsr4,
hp300_isa_io_bsrm1,
hp300_isa_io_bsrm2,
hp300_isa_io_bsrm4,
hp300_isa_io_bsrrm2,
hp300_isa_io_bsrrm4,
hp300_isa_io_bsrr1,
hp300_isa_io_bsrr2,
hp300_isa_io_bsrr4,
hp300_isa_io_bsrrr2,
hp300_isa_io_bsrrr4,
hp300_isa_io_bsw1,
hp300_isa_io_bsw2,
hp300_isa_io_bsw4,
hp300_isa_io_bswm1,
hp300_isa_io_bswm2,
hp300_isa_io_bswm4,
hp300_isa_io_bswrm2,
hp300_isa_io_bswrm4,
hp300_isa_io_bswr1,
hp300_isa_io_bswr2,
hp300_isa_io_bswr4,
hp300_isa_io_bswrr2,
hp300_isa_io_bswrr4,
hp300_isa_io_bssm1,
hp300_isa_io_bssm2,
hp300_isa_io_bssm4,
hp300_isa_io_bssr1,
hp300_isa_io_bssr2,
hp300_isa_io_bssr4
};
int
hp300_isa_io_map(bus_addr_t bpa, bus_size_t size, int flags,
bus_space_handle_t *bshp)
{
int error;
u_int iobase, iosize, npg;
vaddr_t va;
paddr_t pa;
#ifdef DEBUG
printf("isa_io_map(%04x, %04x)", bpa, size);
#endif
/*
* Reserve the range in the allocation extent.
*/
if (bpa < IO_ISABEGIN || bpa + size > IO_ISAEND + 1) {
#ifdef DEBUG
printf(" outside available range\n");
#endif
return (ERANGE);
}
error = extent_alloc_region(isabr->sc_io_extent, bpa, size,
EX_MALLOCOK);
if (error != 0) {
#ifdef DEBUG
printf(" overlaps extent\n");
#endif
return (error);
}
/*
* Round the allocation to a multiple of 8 bytes, to end up
* with entire pages.
*/
iobase = bpa & ~(ISABR_IOPORT_LINE - 1);
iosize = ((bpa + size + (ISABR_IOPORT_LINE - 1)) &
~(ISABR_IOPORT_LINE - 1)) - iobase;
/*
* Compute how many pages will be necessary to map this range.
*/
npg = iosize / ISABR_IOPORT_LINE;
#ifdef DEBUG
printf("->(%04x, %04x)=%d@", iobase, iosize, npg);
#endif
/*
* Allocate virtual address space to map this space in.
*/
va = uvm_km_valloc(kernel_map, ptoa(npg));
if (va == 0) {
#ifdef DEBUG
printf("NULL\n");
#endif
extent_free(isabr->sc_io_extent, bpa, size, EX_MALLOCOK);
return (ENOMEM);
}
*bshp = (bus_space_handle_t)(va + (bpa - iobase));
pa = ISABR_IOPORT_BASE + ISAADDR(iobase);
#ifdef DEBUG
printf("%08x (ret %08x) pa %08x\n", va, *bshp, pa);
#endif
while (npg != 0) {
pmap_kenter_cache(va, pa, PG_RW | PG_CI);
npg--;
va += PAGE_SIZE;
pa += PAGE_SIZE;
}
pmap_update(pmap_kernel());
return (0);
}
void
hp300_isa_io_unmap(bus_space_handle_t bsh, bus_size_t size)
{
u_int iobase, iosize, npg;
vaddr_t va;
paddr_t pa;
#ifdef DEBUG
printf("isa_io_unmap(%08x, %04x)", bsh, size);
#endif
/*
* Find the pa matching this allocation, and the I/O port base
* from it.
*/
va = (vaddr_t)bsh;
if (pmap_extract(pmap_kernel(), va, &pa) == FALSE) {
#ifdef DEBUG
printf("-> no pa\n");
#endif
return; /* XXX be vocal? */
}
#ifdef DEBUG
printf("-> pa %08x ", pa);
#endif
pa -= ISABR_IOPORT_BASE;
iobase = ISAPORT(pa);
if (iobase < IO_ISABEGIN || iobase > IO_ISAEND) {
#ifdef DEBUG
printf("iobase %08x???\n", iobase);
#endif
return; /* XXX be vocal? */
}
iosize = size + (iobase & (ISABR_IOPORT_LINE - 1)) +
(ISABR_IOPORT_LINE - 1);
npg = iosize / ISABR_IOPORT_LINE;
#ifdef DEBUG
printf(" range %04x-%04x: %d\n", iobase, size, npg);
#endif
pmap_kremove(va, ptoa(npg));
pmap_update(pmap_kernel());
uvm_km_free(kernel_map, va, ptoa(npg));
(void)extent_free(isabr->sc_io_extent, (u_long)iobase, size,
EX_MALLOCOK);
}
/*
* Round down an I/O space bus_space_handle, so that it points to the
* beginning of a page.
* This is gonna be hell when we support ports above 0x400.
*/
#define REALIGN_IO_HANDLE(h, o) \
do { \
u_int tmp; \
tmp = (h) & (ISABR_IOPORT_LINE - 1); \
(h) -= tmp; \
(o) += tmp; \
} while (0)
/* ARGSUSED */
int
hp300_isa_io_subregion(bus_space_handle_t bsh, bus_size_t offset,
bus_size_t size, bus_space_handle_t *nbshp)
{
REALIGN_IO_HANDLE(bsh, offset);
bsh += ISAADDR(offset);
*nbshp = bsh;
return (0);
}
void *
hp300_isa_io_vaddr(bus_space_handle_t h)
{
return (NULL);
}
/* bus_space_read_X */
u_int8_t
hp300_isa_io_bsr1(bus_space_handle_t bsh, bus_size_t offset)
{
vaddr_t va;
u_int8_t rc;
REALIGN_IO_HANDLE(bsh, offset);
va = (vaddr_t)bsh + ISAADDR(offset);
rc = *(volatile u_int8_t *)va;
#ifdef DEBUG
printf("R%03x(%x):%02x\t", offset, va, rc);
#endif
return (rc);
}
u_int16_t
__hp300_isa_io_bsr2(bus_space_handle_t bsh, bus_size_t offset)
{
u_int16_t rc;
vaddr_t va;
if (offset & 1) {
rc = hp300_isa_io_bsr1(bsh, offset + 1) << 8;
rc |= hp300_isa_io_bsr1(bsh, offset);
} else {
REALIGN_IO_HANDLE(bsh, offset);
va = (vaddr_t)bsh + ISAADDR(offset);
rc = *(volatile u_int16_t *)va;
}
#ifdef DEBUG
printf("R%03x:%04x\t", offset, rc);
#endif
return (rc);
}
u_int16_t
hp300_isa_io_bsr2(bus_space_handle_t bsh, bus_size_t offset)
{
u_int16_t rc;
rc = __hp300_isa_io_bsr2(bsh, offset);
return (letoh16(rc));
}
u_int32_t
__hp300_isa_io_bsr4(bus_space_handle_t bsh, bus_size_t offset)
{
u_int32_t rc;
vaddr_t va;
if (offset & 3) {
rc = hp300_isa_io_bsr1(bsh, offset + 3) << 24;
rc |= hp300_isa_io_bsr1(bsh, offset + 2) << 16;
rc |= hp300_isa_io_bsr1(bsh, offset + 1) << 8;
rc |= hp300_isa_io_bsr1(bsh, offset);
} else {
REALIGN_IO_HANDLE(bsh, offset);
va = (vaddr_t)bsh + ISAADDR(offset);
rc = *(volatile u_int32_t *)va;
}
#ifdef DEBUG
printf("R%03x:%08x\t", offset, rc);
#endif
return (rc);
}
u_int32_t
hp300_isa_io_bsr4(bus_space_handle_t bsh, bus_size_t offset)
{
u_int32_t rc;
rc = __hp300_isa_io_bsr4(bsh, offset);
return (letoh32(rc));
}
/* bus_space_read_multi_X */
void
hp300_isa_io_bsrm1(bus_space_handle_t h, bus_size_t offset,
u_int8_t *a, size_t c)
{
while ((int)--c >= 0)
*a++ = hp300_isa_io_bsr1(h, offset);
}
void
hp300_isa_io_bsrm2(bus_space_handle_t h, bus_size_t offset,
u_int16_t *a, size_t c)
{
while ((int)--c >= 0)
*a++ = hp300_isa_io_bsr2(h, offset);
}
void
hp300_isa_io_bsrm4(bus_space_handle_t h, bus_size_t offset,
u_int32_t *a, size_t c)
{
while ((int)--c >= 0)
*a++ = hp300_isa_io_bsr4(h, offset);
}
/* bus_space_read_raw_multi_X */
void
hp300_isa_io_bsrrm2(bus_space_handle_t h, bus_size_t offset,
u_int8_t *a, size_t c)
{
while ((int)--c >= 0) {
*(u_int16_t *)a = __hp300_isa_io_bsr2(h, offset);
a += 2;
}
}
void
hp300_isa_io_bsrrm4(bus_space_handle_t h, bus_size_t offset,
u_int8_t *a, size_t c)
{
while ((int)--c >= 0) {
*(u_int32_t *)a = __hp300_isa_io_bsr4(h, offset);
a += 4;
}
}
/* bus_space_read_region_X */
void
hp300_isa_io_bsrr1(bus_space_handle_t h, bus_size_t offset,
u_int8_t *a, size_t c)
{
while ((int)--c >= 0)
*a++ = hp300_isa_io_bsr1(h, offset++);
}
void
hp300_isa_io_bsrr2(bus_space_handle_t h, bus_size_t offset,
u_int16_t *a, size_t c)
{
while ((int)--c >= 0) {
*a++ = hp300_isa_io_bsr2(h, offset);
offset += 2;
}
}
void
hp300_isa_io_bsrr4(bus_space_handle_t h, bus_size_t offset,
u_int32_t *a, size_t c)
{
while ((int)--c >= 0) {
*a++ = hp300_isa_io_bsr4(h, offset);
offset += 4;
}
}
/* bus_space_read_raw_region_X */
void
hp300_isa_io_bsrrr2(bus_space_handle_t h, bus_size_t offset,
u_int8_t *a, size_t c)
{
c >>= 1;
while ((int)--c >= 0) {
*(u_int16_t *)a = __hp300_isa_io_bsr2(h, offset);
offset += 2;
a += 2;
}
}
void
hp300_isa_io_bsrrr4(bus_space_handle_t h, bus_size_t offset,
u_int8_t *a, size_t c)
{
c >>= 2;
while ((int)--c >= 0) {
*(u_int32_t *)a = __hp300_isa_io_bsr4(h, offset);
offset += 4;
a += 4;
}
}
/* bus_space_write_X */
void
hp300_isa_io_bsw1(bus_space_handle_t h, bus_size_t offset, u_int8_t v)
{
vaddr_t va;
REALIGN_IO_HANDLE(h, offset);
va = (vaddr_t)h + ISAADDR(offset);
*(volatile u_int8_t *)va = v;
#ifdef DEBUG
printf("W%03x:%02x\t", offset, v);
#endif
}
void
__hp300_isa_io_bsw2(bus_space_handle_t h, bus_size_t offset, u_int16_t v)
{
vaddr_t va;
if (offset & 1) {
hp300_isa_io_bsw1(h, offset + 1, v >> 8);
hp300_isa_io_bsw1(h, offset, v);
} else {
REALIGN_IO_HANDLE(h, offset);
va = (vaddr_t)h + ISAADDR(offset);
*(volatile u_int16_t *)va = v;
}
#ifdef DEBUG
printf("W%03x:%04x\t", offset, v);
#endif
}
void
hp300_isa_io_bsw2(bus_space_handle_t h, bus_size_t offset, u_int16_t v)
{
__hp300_isa_io_bsw2(h, offset, htole16(v));
}
void
__hp300_isa_io_bsw4(bus_space_handle_t h, bus_size_t offset, u_int32_t v)
{
vaddr_t va;
if (offset & 3) {
hp300_isa_io_bsw1(h, offset + 3, v >> 24);
hp300_isa_io_bsw1(h, offset + 2, v >> 16);
hp300_isa_io_bsw1(h, offset + 1, v >> 8);
hp300_isa_io_bsw1(h, offset, v);
} else {
REALIGN_IO_HANDLE(h, offset);
va = (vaddr_t)h + ISAADDR(offset);
*(volatile u_int32_t *)va = v;
}
#ifdef DEBUG
printf("W%03x:%08x\t", offset, v);
#endif
}
void
hp300_isa_io_bsw4(bus_space_handle_t h, bus_size_t offset, u_int32_t v)
{
__hp300_isa_io_bsw4(h, offset, htole32(v));
}
/* bus_space_write_multi_X */
void
hp300_isa_io_bswm1(bus_space_handle_t h, bus_size_t offset,
const u_int8_t *a, size_t c)
{
while ((int)--c >= 0)
hp300_isa_io_bsw1(h, offset, *a++);
}
void
hp300_isa_io_bswm2(bus_space_handle_t h, bus_size_t offset,
const u_int16_t *a, size_t c)
{
while ((int)--c >= 0)
hp300_isa_io_bsw2(h, offset, *a++);
}
void
hp300_isa_io_bswm4(bus_space_handle_t h, bus_size_t offset,
const u_int32_t *a, size_t c)
{
while ((int)--c >= 0)
hp300_isa_io_bsw4(h, offset, *a++);
}
/* bus_space_write_raw_multi_X */
void
hp300_isa_io_bswrm2(bus_space_handle_t h, bus_size_t offset,
const u_int8_t *a, size_t c)
{
while ((int)--c >= 0) {
__hp300_isa_io_bsw2(h, offset, *(u_int16_t *)a);
a += 2;
}
}
void
hp300_isa_io_bswrm4(bus_space_handle_t h, bus_size_t offset,
const u_int8_t *a, size_t c)
{
while ((int)--c >= 0) {
__hp300_isa_io_bsw4(h, offset, *(u_int32_t *)a);
a += 4;
}
}
/* bus_space_write_region_X */
void
hp300_isa_io_bswr1(bus_space_handle_t h, bus_size_t offset,
const u_int8_t *a, size_t c)
{
while ((int)--c >= 0)
hp300_isa_io_bsw1(h, offset++, *a++);
}
void
hp300_isa_io_bswr2(bus_space_handle_t h, bus_size_t offset,
const u_int16_t *a, size_t c)
{
while ((int)--c >= 0) {
hp300_isa_io_bsw2(h, offset, *a++);
offset += 2;
}
}
void
hp300_isa_io_bswr4(bus_space_handle_t h, bus_size_t offset,
const u_int32_t *a, size_t c)
{
while ((int)--c >= 0) {
hp300_isa_io_bsw4(h, offset, *a++);
offset += 4;
}
}
/* bus_space_write_raw_region_X */
void
hp300_isa_io_bswrr2(bus_space_handle_t h, bus_size_t offset,
const u_int8_t *a, size_t c)
{
c >>= 1;
while ((int)--c >= 0) {
__hp300_isa_io_bsw2(h, offset, *(u_int16_t *)a);
offset += 2;
a += 2;
}
}
void
hp300_isa_io_bswrr4(bus_space_handle_t h, bus_size_t offset,
const u_int8_t *a, size_t c)
{
c >>= 2;
while ((int)--c >= 0) {
__hp300_isa_io_bsw4(h, offset, *(u_int32_t *)a);
offset += 4;
a += 4;
}
}
/* bus_space_set_multi_X */
void
hp300_isa_io_bssm1(bus_space_handle_t h, bus_size_t offset,
u_int8_t v, size_t c)
{
while ((int)--c >= 0)
hp300_isa_io_bsw1(h, offset, v);
}
void
hp300_isa_io_bssm2(bus_space_handle_t h, bus_size_t offset,
u_int16_t v, size_t c)
{
while ((int)--c >= 0)
hp300_isa_io_bsw2(h, offset, v);
}
void
hp300_isa_io_bssm4(bus_space_handle_t h, bus_size_t offset,
u_int32_t v, size_t c)
{
while ((int)--c >= 0)
hp300_isa_io_bsw4(h, offset, v);
}
/* bus_space_set_region_X */
void
hp300_isa_io_bssr1(bus_space_handle_t h, bus_size_t offset,
u_int8_t v, size_t c)
{
while ((int)--c >= 0)
hp300_isa_io_bsw1(h, offset++, v);
}
void
hp300_isa_io_bssr2(bus_space_handle_t h, bus_size_t offset,
u_int16_t v, size_t c)
{
while ((int)--c >= 0) {
hp300_isa_io_bsw2(h, offset, v);
offset += 2;
}
}
void
hp300_isa_io_bssr4(bus_space_handle_t h, bus_size_t offset,
u_int32_t v, size_t c)
{
while ((int)--c >= 0) {
hp300_isa_io_bsw4(h, offset, v);
offset += 4;
}
}
/*
* ISA memory space
*/
int hp300_isa_mem_map(bus_addr_t, bus_size_t, int, bus_space_handle_t *);
void hp300_isa_mem_unmap(bus_space_handle_t, bus_size_t);
int
hp300_isa_mem_map(bus_addr_t bpa, bus_size_t size, int flags,
bus_space_handle_t *bshp)
{
int error;
bus_addr_t membase;
bus_size_t rsize;
vaddr_t va;
paddr_t pa;
pt_entry_t template;
/*
* Reserve the range in the allocation extent.
*/
if (bpa < IOM_BEGIN || bpa + size > IOM_END)
return (ERANGE);
error = extent_alloc_region(isabr->sc_mem_extent, bpa, size,
EX_MALLOCOK);
if (error != 0)
return (error);
/*
* Allocate virtual address space to map this space in.
*/
membase = trunc_page(bpa);
rsize = round_page(bpa + size) - membase;
va = uvm_km_valloc(kernel_map, rsize);
if (va == 0) {
extent_free(isabr->sc_mem_extent, bpa, size, EX_MALLOCOK);
return (ENOMEM);
}
*bshp = (bus_space_handle_t)(va + (bpa - membase));
pa = membase + (ISABR_IOMEM_BASE - IOM_BEGIN);
if (flags & BUS_SPACE_MAP_CACHEABLE)
template = PG_RW;
else
template = PG_RW | PG_CI;
while (rsize != 0) {
pmap_kenter_cache(va, pa, template);
rsize -= PAGE_SIZE;
va += PAGE_SIZE;
pa += PAGE_SIZE;
}
pmap_update(pmap_kernel());
return (0);
}
void
hp300_isa_mem_unmap(bus_space_handle_t bsh, bus_size_t size)
{
vaddr_t va;
vsize_t rsize;
va = trunc_page((vaddr_t)bsh);
rsize = round_page((vaddr_t)bsh + size) - va;
pmap_kremove(va, rsize);
pmap_update(pmap_kernel());
uvm_km_free(kernel_map, va, rsize);
(void)extent_free(isabr->sc_mem_extent, (u_long)bsh, size, EX_MALLOCOK);
}
struct hp300_bus_space_tag hp300_isa_mem_tag; /* will be filled in */
/*
* ISA bus_space initialization.
* This creates the necessary accounting elements and initializes the
* memory space bus_space_tag.
*/
int
isabr_bus_space_setup(struct isabr_softc *sc, struct frodo_attach_args *faa,
struct isabus_attach_args *iba)
{
/*
* Create the space extents.
* We only use them to prevent multiple allocations of the same areas.
*/
sc->sc_io_extent = extent_create("isa_io", IO_ISABEGIN,
IO_ISAEND + 1, M_DEVBUF, NULL, 0, EX_NOWAIT | EX_MALLOCOK);
if (sc->sc_io_extent == NULL)
return (ENOMEM);
sc->sc_mem_extent = extent_create("isa_mem", IOM_BEGIN,
IOM_END, M_DEVBUF, NULL, 0, EX_NOWAIT | EX_MALLOCOK);
if (sc->sc_mem_extent == NULL) {
extent_destroy(sc->sc_io_extent);
return (ENOMEM);
}
iba->iba_iot = &hp300_isa_io_tag;
bcopy(faa->fa_tag, &hp300_isa_mem_tag,
sizeof(struct hp300_bus_space_tag));
hp300_isa_mem_tag.bs_map = hp300_isa_mem_map;
hp300_isa_mem_tag.bs_unmap = hp300_isa_mem_unmap;
iba->iba_memt = &hp300_isa_mem_tag;
isabr = sc;
return (0);
}
|